-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Main: Add a WordPress.org/Search page template.
See WordPress/wporg-mu-plugins#38 git-svn-id: https://meta.svn.wordpress.org/sites/trunk@11427 74240141-8908-4e6f-9713-ba540dce6ec7
- Loading branch information
Showing
8 changed files
with
181 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
wordpress.org/public_html/wp-content/themes/pub/wporg-main/css/components/_page-search.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
body.page-search { | ||
table, | ||
table td { | ||
border: none; | ||
padding: 0; | ||
margin: 0; | ||
} | ||
|
||
main { | ||
min-height: 30em; | ||
} | ||
|
||
input.gsc-input { | ||
box-shadow: none; | ||
} | ||
|
||
.entry-content.google-custom-search { | ||
padding: 0; | ||
|
||
* { | ||
box-sizing: initial; | ||
} | ||
} | ||
|
||
} |
2 changes: 1 addition & 1 deletion
2
wordpress.org/public_html/wp-content/themes/pub/wporg-main/css/style-rtl.css
Large diffs are not rendered by default.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
wordpress.org/public_html/wp-content/themes/pub/wporg-main/css/style.css
Large diffs are not rendered by default.
Oops, something went wrong.
3 changes: 2 additions & 1 deletion
3
wordpress.org/public_html/wp-content/themes/pub/wporg-main/css/style.css.map
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
140 changes: 140 additions & 0 deletions
140
wordpress.org/public_html/wp-content/themes/pub/wporg-main/page-search.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
<?php | ||
|
||
/** | ||
* Template Name: Global Search | ||
* | ||
* @package WordPressdotorg\MainTheme | ||
*/ | ||
|
||
namespace WordPressdotorg\MainTheme; | ||
|
||
// Prevent Jetpack from looking for a non-existent featured image. | ||
add_filter( 'jetpack_images_pre_get_images', function() { | ||
return new \WP_Error(); | ||
} ); | ||
|
||
/* See inc/page-meta-descriptions.php for the meta description for this page. */ | ||
|
||
wp_enqueue_script( 'jquery' ); | ||
|
||
get_header( 'top-level-page' ); | ||
the_post(); | ||
|
||
$terms = urldecode( wp_unslash( $_GET['s'] ) ); | ||
$terms = htmlspecialchars_decode( $terms ); | ||
$terms = explode( '?', $terms )[0]; | ||
$terms = trim( $terms, "/ \r\n\t" ); | ||
|
||
$search_config = array( | ||
'div' => 'gsce-search', | ||
'gname' => 'wordpressorg-search', | ||
'attributes' => array( | ||
'queryParameterName' => 'search', | ||
'linkTarget' => '_parent', | ||
'enableHistory' => false, | ||
'enableOrderBy' => true, | ||
), | ||
); | ||
|
||
if ( isset( $_REQUEST['in'] ) && in_array( $_REQUEST['in'], [ 'support_forums', 'support_docs', 'developer_documentation' ] ) ) { | ||
$search_config['attributes']['defaultToRefinement'] = $_REQUEST['in']; | ||
} | ||
|
||
?> | ||
|
||
<main id="main" class="site-main col-12" role="main"> | ||
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>> | ||
<div id="gsce-search" class="entry-content col-12 google-custom-search"> | ||
<p>Loading..</p> | ||
</div> | ||
</article> | ||
</main> | ||
|
||
<script> | ||
window.__gcse = { | ||
parsetags: 'explicit', | ||
callback: function() { | ||
var executeSearch = function() { | ||
document.getElementById( 'gsce-search' ).innerHTML = ''; | ||
google.search.cse.element.render(<?php echo json_encode( $search_config, true ); ?>); | ||
google.search.cse.element.getElement('wordpressorg-search').execute( <?php echo json_encode( $terms ); ?> ); | ||
} | ||
|
||
if ( document.readyState == 'complete' ) { | ||
executeSearch(); | ||
} else { | ||
google.setOnLoadCallback(function() { | ||
executeSearch(); | ||
}, true); | ||
} | ||
|
||
}, | ||
searchCallbacks: { | ||
web: { | ||
starting: function( gname, searchTerm ) { | ||
wporg_search_update_url( searchTerm, jQuery('.gsc-refinementBlock .gsc-tabhActive') ); | ||
}, | ||
rendered: function( gname, searchTerm ) { | ||
jQuery('.gsc-refinementBlock .gsc-tabHeader') | ||
.off( 'click.refinement, keypress.refinement' ) | ||
.on( 'click.refinement, keypress.refinement', function() { | ||
wporg_search_update_url( searchTerm, jQuery( this ) ); | ||
} ); | ||
} | ||
} | ||
} | ||
}; | ||
|
||
function wporg_search_update_url( term, refinement_obj = false ) { | ||
var refinement = 'all', | ||
state; | ||
if ( refinement_obj && refinement_obj.length ) { | ||
refinement = refinement_obj.text().trim().toLowerCase().replace( /[^a-z]/g, '_' ); | ||
} | ||
if ( 'all' === refinement ) { | ||
refinement = ''; | ||
} | ||
|
||
state = { | ||
'search': term, | ||
'refinement': refinement | ||
}; | ||
|
||
if ( | ||
! window.history.state || | ||
window.history.state.search != state.search || | ||
window.history.state.refinement != state.refinement | ||
) { | ||
wporg_record_search( term, refinement ); | ||
} | ||
|
||
window.history.replaceState( | ||
state, | ||
document.title, | ||
'/search/' + | ||
encodeURIComponent( term ).replace( /%20/g, '+' ) + '/' + | ||
( refinement ? '?in=' + refinement : '' ) | ||
); | ||
} | ||
|
||
function wporg_record_search( term, refinement ) { | ||
jQuery.post( | ||
'https://api.wordpress.org/search/1.0/', | ||
{ | ||
term: term, | ||
in: refinement | ||
} | ||
); | ||
} | ||
|
||
(function() { | ||
var cx = '012566942813864066925:bnbfebp99hs'; | ||
var gcse = document.createElement('script'); gcse.type = 'text/javascript'; gcse.async = true; | ||
gcse.src = 'https://cse.google.com/cse.js?cx=' + cx; | ||
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(gcse, s); | ||
})(); | ||
</script> | ||
|
||
<?php | ||
|
||
get_footer(); |