Advertisement
gilzow

Sample GSA Search

Dec 13th, 2013
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.41 KB | None | 0 0
  1. <?php
  2. /**
  3. * From configuration settings.
  4. */
  5. /**
  6.  * At a minimum, change the sitesearch value to the new site's domain
  7.  */
  8. define('GSA_SEARCH_PARAMS',  serialize(array(
  9.     'site'            => 'default_collection',
  10.     'proxystylesheet' => 'wc_standard',
  11.     'client'          => 'wc_standard',
  12.     'output'          => 'xml_no_dtd',
  13.     'sitesearch'      => 'subdomain-to-search.missouri.edu'
  14. )));
  15.  
  16. /**
  17. * GSA's site search url
  18. */
  19. define('GSA_SEARCH_URL','http://search.missouri.edu/search?');
  20. ?>
  21.  
  22. <?php
  23.  /**
  24.  * Template Name: Search
  25.  *
  26.  * Displays search results from the GSA. Also doubles as the the template to
  27.  * be attached to the Search page created in wordpress.  
  28.  *
  29.  * @package WordPress
  30.  * @subpackage SITENAME
  31.  * @category theme
  32.  * @category template
  33.  * @author Paul F. Gilzow, Web Communications, University of Missouri
  34.  * @copyright 2013 Curators of the University of Missouri
  35.  */
  36.  
  37. $arySearchParams = unserialize(GSA_SEARCH_PARAMS);
  38. /**
  39. * Doesnt matter if s or q has been used as the search parameter, we want to use either to invoke a gsa search
  40. */
  41. if ( (isset( $_GET['q'] ) && $_GET['q'] != '') || (isset($_GET['s']) && $_GET['s'] != '')) {
  42.  
  43.     // Add search inputs to query array
  44.     $arySearchParams['q'] = (isset($_GET['q'])) ? $_GET['q'] : $_GET['s'];
  45.     if(is_array($arySearchParams['q'])) $arySearchParams['q'] = implode (' ', $arySearchParams['q']);
  46.     if ( isset($_GET['start']) && $_GET['start'] != '') $arySearchParams['start']  = $_GET['start'];
  47.     if ( isset($_GET['sort']) && $_GET['sort'] != '') $arySearchParams['sort']   = $_GET['sort'];
  48.     if ( isset($_GET['filter']) && $_GET['filter']  != '') $arySearchParams['filter'] = $_GET['filter'];
  49.    
  50.  
  51.     $arySearchParams['q'] = stripcslashes($arySearchParams['q']);
  52.  
  53.     $strResults = file_get_contents(GSA_SEARCH_URL.http_build_query($arySearchParams));
  54.    
  55. }
  56. $boolNoResults = (!isset($strResults) || $strResults == '') ? true : false;
  57. get_header();
  58.  ?>
  59.  
  60.         <div id="default">
  61.             <?php get_template_part('aside','example'); ?>
  62.  
  63.                 <h2 id="skip">Search<?php if(!$boolNoResults) echo ' Results'; ?></h2>
  64.  
  65.                     <?php if($boolNoResults): ?>
  66.                         <?php get_search_form(); ?>
  67.                     <?php else :?>
  68.                         <?php echo $strResults;?>
  69.                     <?php endif;?>
  70.         </div><!-- #default -->
  71. <?php get_footer(); ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement