Source for file helper.php

Documentation is available at helper.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Libraries
  4.  * @subpackage  Search
  5.  *
  6.  * @copyright   Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
  7.  * @license     GNU General Public License version 2 or later; see LICENSE.txt
  8.  */
  9.  
  10. defined('JPATH_PLATFORM'or die;
  11.  
  12. /**
  13.  * Helper class for Joomla! Search components
  14.  *
  15.  * @package     Joomla.Libraries
  16.  * @subpackage  Search
  17.  * @since       3.0
  18.  */
  19. {
  20.     /**
  21.      * Method to log search terms to the database
  22.      *
  23.      * @param   string  $term       The term being searched
  24.      * @param   string  $component  The component being used for the search
  25.      *
  26.      * @return  void 
  27.      *
  28.      * @since   3.0
  29.      */
  30.     public static function logSearch($term$component)
  31.     {
  32.         // Initialise our variables
  33.         $db JFactory::getDbo();
  34.         $query $db->getQuery(true);
  35.         $enable_log_searches JComponentHelper::getParams($component)->get('enabled');
  36.  
  37.         // Sanitise the term for the database
  38.         $search_term $db->escape(trim(strtolower($term)));
  39.  
  40.         if ($enable_log_searches)
  41.         {
  42.             // Query the table to determine if the term has been searched previously
  43.             $query->select($db->quoteName('hits'))
  44.                 ->from($db->quoteName('#__core_log_searches'))
  45.                 ->where($db->quoteName('search_term'' = ' $db->quote($search_term));
  46.             $db->setQuery($query);
  47.             $hits intval($db->loadResult());
  48.  
  49.             // Reset the $query object
  50.             $query->clear();
  51.  
  52.             // Update the table based on the results
  53.             if ($hits)
  54.             {
  55.                 $query->update($db->quoteName('#__core_log_searches'))
  56.                     ->set('hits = (hits + 1)')
  57.                     ->where($db->quoteName('search_term'' = ' $db->quote($search_term));
  58.             }
  59.             else
  60.             {
  61.                 $query->insert($db->quoteName('#__core_log_searches'))
  62.                     ->columns(array($db->quoteName('search_term')$db->quoteName('hits')))
  63.                     ->values($db->quote($search_term', 1');
  64.             }
  65.  
  66.             // Execute the update query
  67.             $db->setQuery($query);
  68.             $db->execute();
  69.         }
  70.     }
  71. }

Documentation generated on Tue, 19 Nov 2013 15:04:31 +0100 by phpDocumentor 1.4.3