Source for file query.php

Documentation is available at query.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Site
  4.  * @subpackage  com_finder
  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
  8.  */
  9.  
  10. defined('_JEXEC'or die;
  11.  
  12. /**
  13.  * Query HTML behavior class for Finder.
  14.  *
  15.  * @package     Joomla.Site
  16.  * @subpackage  com_finder
  17.  * @since       2.5
  18.  */
  19. abstract class JHtmlQuery
  20. {
  21.     /**
  22.      * Method to get the explained (human-readable) search query.
  23.      *
  24.      * @param   FinderIndexerQuery  $query  A FinderIndexerQuery object to explain.
  25.      *
  26.      * @return  mixed  String if there is data to explain, null otherwise.
  27.      *
  28.      * @since   2.5
  29.      */
  30.     public static function explained(FinderIndexerQuery $query)
  31.     {
  32.         $parts array();
  33.  
  34.         // Process the required tokens.
  35.         foreach ($query->included as $token)
  36.         {
  37.             if ($token->required && (!isset($token->derived|| $token->derived == false))
  38.             {
  39.                 $parts['<span class="query-required">' JText::sprintf('COM_FINDER_QUERY_TOKEN_REQUIRED'$token->term'</span>';
  40.             }
  41.         }
  42.  
  43.         // Process the optional tokens.
  44.         foreach ($query->included as $token)
  45.         {
  46.             if (!$token->required && (!isset($token->derived|| $token->derived == false))
  47.             {
  48.                 $parts['<span class="query-optional">' JText::sprintf('COM_FINDER_QUERY_TOKEN_OPTIONAL'$token->term'</span>';
  49.             }
  50.         }
  51.  
  52.         // Process the excluded tokens.
  53.         foreach ($query->excluded as $token)
  54.         {
  55.             if (!isset($token->derived|| $token->derived == false)
  56.             {
  57.                 $parts['<span class="query-excluded">' JText::sprintf('COM_FINDER_QUERY_TOKEN_EXCLUDED'$token->term'</span>';
  58.             }
  59.         }
  60.  
  61.         // Process the start date.
  62.         if ($query->date1)
  63.         {
  64.             $date JFactory::getDate($query->date1)->format(JText::_('DATE_FORMAT_LC'));
  65.             $parts['<span class="query-start-date">' JText::sprintf('COM_FINDER_QUERY_START_DATE'$query->when1$date'</span>';
  66.         }
  67.  
  68.         // Process the end date.
  69.         if ($query->date2)
  70.         {
  71.             $date JFactory::getDate($query->date2)->format(JText::_('DATE_FORMAT_LC'));
  72.             $parts['<span class="query-end-date">' JText::sprintf('COM_FINDER_QUERY_END_DATE'$query->when2$date'</span>';
  73.         }
  74.  
  75.         // Process the taxonomy filters.
  76.         if (!empty($query->filters))
  77.         {
  78.             // Get the filters in the request.
  79.             $t JFactory::getApplication()->input->request->get('t'array()'array');
  80.  
  81.             // Process the taxonomy branches.
  82.             foreach ($query->filters as $branch => $nodes)
  83.             {
  84.                 // Process the taxonomy nodes.
  85.                 $lang JFactory::getLanguage();
  86.                 foreach ($nodes as $title => $id)
  87.                 {
  88.                     // Translate the title for Types
  89.                     $key FinderHelperLanguage::branchPlural($title);
  90.                     if ($lang->hasKey($key))
  91.                     {
  92.                         $title JText::_($key);
  93.                     }
  94.  
  95.                     // Don't include the node if it is not in the request.
  96.                     if (!in_array($id$t))
  97.                     {
  98.                         continue;
  99.                     }
  100.  
  101.                     // Add the node to the explanation.
  102.                     $parts['<span class="query-taxonomy">'
  103.                         . JText::sprintf('COM_FINDER_QUERY_TAXONOMY_NODE'$titleJText::_(FinderHelperLanguage::branchSingular($branch)))
  104.                         . '</span>';
  105.                 }
  106.             }
  107.         }
  108.  
  109.         // Build the interpreted query.
  110.         return count($partsJText::sprintf('COM_FINDER_QUERY_TOKEN_INTERPRETED'implode(JText::_('COM_FINDER_QUERY_TOKEN_GLUE')$parts)) null;
  111.     }
  112.  
  113.     /**
  114.      * Method to get the suggested search query.
  115.      *
  116.      * @param   FinderIndexerQuery  $query  A FinderIndexerQuery object.
  117.      *
  118.      * @return  mixed  String if there is a suggestion, false otherwise.
  119.      *
  120.      * @since   2.5
  121.      */
  122.     public static function suggested(FinderIndexerQuery $query)
  123.     {
  124.         $suggested false;
  125.  
  126.         // Check if the query input is empty.
  127.         if (empty($query->input))
  128.         {
  129.             return $suggested;
  130.         }
  131.  
  132.         // Check if there were any ignored or included keywords.
  133.         if (count($query->ignored|| count($query->included))
  134.         {
  135.             $suggested $query->input;
  136.  
  137.             // Replace the ignored keyword suggestions.
  138.             foreach (array_reverse($query->ignoredas $token)
  139.             {
  140.                 if (isset($token->suggestion))
  141.                 {
  142.                     $suggested str_replace($token->term$token->suggestion$suggested);
  143.                 }
  144.             }
  145.  
  146.             // Replace the included keyword suggestions.
  147.             foreach (array_reverse($query->includedas $token)
  148.             {
  149.                 if (isset($token->suggestion))
  150.                 {
  151.                     $suggested str_replace($token->term$token->suggestion$suggested);
  152.                 }
  153.             }
  154.  
  155.             // Check if we made any changes.
  156.             if ($suggested == $query->input)
  157.             {
  158.                 $suggested false;
  159.             }
  160.         }
  161.  
  162.         return $suggested;
  163.     }
  164. }

Documentation generated on Tue, 19 Nov 2013 15:11:29 +0100 by phpDocumentor 1.4.3