Ejemplo n.º 1
0
 /**
  * Process incoming parameters and display the page.
  *
  * @return void
  * @access public
  */
 public function launch()
 {
     global $configArray;
     global $interface;
     // Assign basic values
     $interface->assign('googleKey', $configArray['GoogleSearch']['key']);
     $interface->assign('domain', $configArray['GoogleSearch']['domain']);
     $interface->assign('lookfor', $_GET['lookfor']);
     // Optional advanced value -- by using the queryAddition GET parameter,
     // you can append a string to the user's queries.  This can be useful
     // for filtering to a particular type of content or subsection of the
     // site using various advanced Google operators (i.e. inurl:example).
     $interface->assign('queryAddition', isset($_GET['queryAddition']) ? $_GET['queryAddition'] : false);
     // Load recommendation module settings -- default to CatalogResults if
     // no settings were found.
     $recSettings = isset($configArray['GoogleSearch']['side_recommend']) ? $configArray['GoogleSearch']['side_recommend'] : array('CatalogResults:lookfor');
     $recSettings = is_array($recSettings) ? $recSettings : array($recSettings);
     // Build recommendations modules based on the loaded settings:
     $recommendations = array();
     foreach ($recSettings as $current) {
         if (!empty($current)) {
             @(list($name, $params) = explode(':', $current, 2));
             $rec = RecommendationFactory::initRecommendation($name, null, $params);
             $rec->init();
             $rec->process();
             $recommendations[] = $rec->getTemplate();
         }
     }
     $interface->assign('recommendations', $recommendations);
     // Set up the page
     $interface->setPageTitle('Library Web Search');
     $interface->setTemplate('home.tpl');
     $interface->display('layout.tpl');
 }
Ejemplo n.º 2
0
 /**
  * Process incoming parameters and display recommendations.
  *
  * @return void
  * @access public
  */
 public function launch()
 {
     global $interface;
     header('Content-type: text/html');
     header('Cache-Control: no-cache, must-revalidate');
     // HTTP/1.1
     header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
     // Date in the past
     $moduleName = preg_replace('/[^\\w]/', '', $_REQUEST['mod']);
     $module = RecommendationFactory::initRecommendation($moduleName, null, $_REQUEST['params']);
     if ($module) {
         $module->init();
         $module->process();
         echo $interface->fetch($module->getTemplate());
     } else {
         echo translate('An error has occurred');
     }
 }
Ejemplo n.º 3
0
 /**
  * Initialize the recommendations module based on current searchTerms.
  *
  * @access  protected
  */
 protected function initRecommendations()
 {
     // If no settings were found, quit now:
     $settings = $this->getRecommendationSettings();
     if (empty($settings)) {
         $this->recommend = false;
         return;
     }
     // Process recommendations for each location:
     $this->recommend = array('top' => array(), 'side' => array());
     foreach ($settings as $location => $currentSet) {
         // If the current location is disabled, skip processing!
         if (empty($currentSet)) {
             continue;
         }
         // Make sure the current location's set of recommendations is an array;
         // if it's a single string, this normalization will simplify processing.
         if (!is_array($currentSet)) {
             $currentSet = array($currentSet);
         }
         // Now loop through all recommendation settings for the location.
         foreach ($currentSet as $current) {
             // Break apart the setting into module name and extra parameters:
             $current = explode(':', $current);
             $module = array_shift($current);
             $params = implode(':', $current);
             // Can we build a recommendation module with the provided settings?
             // If the factory throws an error, we'll assume for now it means we
             // tried to load a non-existent module, and we'll ignore it.
             $obj = RecommendationFactory::initRecommendation($module, $this, $params);
             if ($obj && !PEAR_Singleton::isError($obj)) {
                 $obj->init();
                 $this->recommend[$location][] = $obj;
             }
         }
     }
 }