[ Index ]

PHP Cross Reference of Joomla 2.5.4 DE

title

Body

[close]

/components/com_finder/helpers/html/ -> query.php (source)

   1  <?php
   2  /**
   3   * @package     Joomla.Site
   4   * @subpackage  com_finder
   5   *
   6   * @copyright   Copyright (C) 2005 - 2012 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                          $title = JText::_($key);
  92                      }
  93  
  94                      // Don't include the node if it is not in the request.
  95                      if (!in_array($id, $t))
  96                      {
  97                          continue;
  98                      }
  99  
 100                      // Add the node to the explanation.
 101                      $bv = JString::strtolower($branch);
 102                      $nv = JString::strtolower($title);
 103                      $parts[] = '<span class="query-taxonomy">' . JText::sprintf('COM_FINDER_QUERY_TAXONOMY_NODE', $title, JText::_(FinderHelperLanguage::branchSingular($branch))) . '</span>';
 104                  }
 105              }
 106          }
 107  
 108          // Build the interpreted query.
 109          return count($parts) ? JText::sprintf('COM_FINDER_QUERY_TOKEN_INTERPRETED', implode(JText::_('COM_FINDER_QUERY_TOKEN_GLUE'), $parts)) : null;
 110      }
 111  
 112      /**
 113       * Method to get the suggested search query.
 114       *
 115       * @param   FinderIndexerQuery  $query  A FinderIndexerQuery object.
 116       *
 117       * @return  mixed  String if there is a suggestion, false otherwise.
 118       *
 119       * @since   2.5
 120       */
 121  	public static function suggested(FinderIndexerQuery $query)
 122      {
 123          $suggested = false;
 124  
 125          // Check if the query input is empty.
 126          if (empty($query->input))
 127          {
 128              return $suggested;
 129          }
 130  
 131          // Check if there were any ignored or included keywords.
 132          if (count($query->ignored) || count($query->included))
 133          {
 134              $suggested = $query->input;
 135  
 136              // Replace the ignored keyword suggestions.
 137              foreach (array_reverse($query->ignored) as $token)
 138              {
 139                  if (isset($token->suggestion))
 140                  {
 141                      $suggested = str_replace($token->term, $token->suggestion, $suggested);
 142                  }
 143              }
 144  
 145              // Replace the included keyword suggestions.
 146              foreach (array_reverse($query->included) as $token)
 147              {
 148                  if (isset($token->suggestion))
 149                  {
 150                      $suggested = str_replace($token->term, $token->suggestion, $suggested);
 151                  }
 152              }
 153  
 154              // Check if we made any changes.
 155              if ($suggested == $query->input)
 156              {
 157                  $suggested = false;
 158              }
 159          }
 160  
 161          return $suggested;
 162      }
 163  }


Generated: Tue Apr 3 11:40:28 2012 Cross-referenced by PHPXref 0.7.1