[ Index ]

PHP Cross Reference of Joomla 2.5.4 DE

title

Body

[close]

/plugins/search/weblinks/ -> weblinks.php (source)

   1  <?php
   2  /**
   3   * @copyright    Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
   4   * @license        GNU General Public License version 2 or later; see LICENSE.txt
   5   */
   6  
   7  // no direct access
   8  defined('_JEXEC') or die;
   9  
  10  require_once  JPATH_SITE.'/components/com_weblinks/helpers/route.php';
  11  
  12  /**
  13   * Weblinks Search plugin
  14   *
  15   * @package        Joomla.Plugin
  16   * @subpackage    Search.weblinks
  17   * @since        1.6
  18   */
  19  class plgSearchWeblinks extends JPlugin
  20  {
  21      /**
  22       * Constructor
  23       *
  24       * @access      protected
  25       * @param       object  $subject The object to observe
  26       * @param       array   $config  An array that holds the plugin configuration
  27       * @since       1.5
  28       */
  29  	public function __construct(& $subject, $config)
  30      {
  31          parent::__construct($subject, $config);
  32          $this->loadLanguage();
  33      }
  34  
  35      /**
  36       * @return array An array of search areas
  37       */
  38  	function onContentSearchAreas() {
  39          static $areas = array(
  40              'weblinks' => 'PLG_SEARCH_WEBLINKS_WEBLINKS'
  41              );
  42              return $areas;
  43      }
  44  
  45      /**
  46       * Weblink Search method
  47       *
  48       * The sql must return the following fields that are used in a common display
  49       * routine: href, title, section, created, text, browsernav
  50       * @param string Target search string
  51       * @param string mathcing option, exact|any|all
  52       * @param string ordering option, newest|oldest|popular|alpha|category
  53       * @param mixed An array if the search it to be restricted to areas, null if search all
  54       */
  55  	function onContentSearch($text, $phrase='', $ordering='', $areas=null)
  56      {
  57          $db        = JFactory::getDbo();
  58          $app    = JFactory::getApplication();
  59          $user    = JFactory::getUser();
  60          $groups    = implode(',', $user->getAuthorisedViewLevels());
  61  
  62          $searchText = $text;
  63  
  64          if (is_array($areas)) {
  65              if (!array_intersect($areas, array_keys($this->onContentSearchAreas()))) {
  66                  return array();
  67              }
  68          }
  69  
  70          $sContent        = $this->params->get('search_content',        1);
  71          $sArchived        = $this->params->get('search_archived',        1);
  72          $limit            = $this->params->def('search_limit',        50);
  73          $state = array();
  74          if ($sContent) {
  75              $state[]=1;
  76          }
  77          if ($sArchived) {
  78              $state[]=2;
  79          }
  80  
  81          $text = trim($text);
  82          if ($text == '') {
  83              return array();
  84          }
  85          $section    = JText::_('PLG_SEARCH_WEBLINKS');
  86  
  87          $wheres    = array();
  88          switch ($phrase)
  89          {
  90              case 'exact':
  91                  $text        = $db->Quote('%'.$db->escape($text, true).'%', false);
  92                  $wheres2    = array();
  93                  $wheres2[]    = 'a.url LIKE '.$text;
  94                  $wheres2[]    = 'a.description LIKE '.$text;
  95                  $wheres2[]    = 'a.title LIKE '.$text;
  96                  $where        = '(' . implode(') OR (', $wheres2) . ')';
  97                  break;
  98  
  99              case 'all':
 100              case 'any':
 101              default:
 102                  $words    = explode(' ', $text);
 103                  $wheres = array();
 104                  foreach ($words as $word)
 105                  {
 106                      $word        = $db->Quote('%'.$db->escape($word, true).'%', false);
 107                      $wheres2    = array();
 108                      $wheres2[]    = 'a.url LIKE '.$word;
 109                      $wheres2[]    = 'a.description LIKE '.$word;
 110                      $wheres2[]    = 'a.title LIKE '.$word;
 111                      $wheres[]    = implode(' OR ', $wheres2);
 112                  }
 113                  $where    = '(' . implode(($phrase == 'all' ? ') AND (' : ') OR ('), $wheres) . ')';
 114                  break;
 115          }
 116  
 117          switch ($ordering)
 118          {
 119              case 'oldest':
 120                  $order = 'a.created ASC';
 121                  break;
 122  
 123              case 'popular':
 124                  $order = 'a.hits DESC';
 125                  break;
 126  
 127              case 'alpha':
 128                  $order = 'a.title ASC';
 129                  break;
 130  
 131              case 'category':
 132                  $order = 'c.title ASC, a.title ASC';
 133                  break;
 134  
 135              case 'newest':
 136              default:
 137                  $order = 'a.created DESC';
 138          }
 139  
 140          $return = array();
 141          if (!empty($state)) {
 142              $query    = $db->getQuery(true);
 143              //sqlsrv changes
 144              $case_when = ' CASE WHEN ';
 145              $case_when .= $query->charLength('a.alias');
 146              $case_when .= ' THEN ';
 147              $a_id = $query->castAsChar('a.id');
 148              $case_when .= $query->concatenate(array($a_id, 'a.alias'), ':');
 149              $case_when .= ' ELSE ';
 150              $case_when .= $a_id.' END as slug';
 151  
 152              $case_when1 = ' CASE WHEN ';
 153              $case_when1 .= $query->charLength('c.alias');
 154              $case_when1 .= ' THEN ';
 155              $c_id = $query->castAsChar('c.id');
 156              $case_when1 .= $query->concatenate(array($c_id, 'c.alias'), ':');
 157              $case_when1 .= ' ELSE ';
 158              $case_when1 .= $c_id.' END as catslug';
 159  
 160              $query->select('a.title AS title, a.description AS text, a.created AS created, a.url, '
 161                          .$case_when.','.$case_when1.', '
 162                          .$query->concatenate(array($db->Quote($section), "c.title"), " / ").' AS section, \'1\' AS browsernav');
 163              $query->from('#__weblinks AS a');
 164              $query->innerJoin('#__categories AS c ON c.id = a.catid');
 165              $query->where('('.$where.')' . ' AND a.state in ('.implode(',', $state).') AND  c.published=1 AND  c.access IN ('.$groups.')');
 166              $query->order($order);
 167  
 168              // Filter by language
 169              if ($app->isSite() && $app->getLanguageFilter()) {
 170                  $tag = JFactory::getLanguage()->getTag();
 171                  $query->where('a.language in (' . $db->Quote($tag) . ',' . $db->Quote('*') . ')');
 172                  $query->where('c.language in (' . $db->Quote($tag) . ',' . $db->Quote('*') . ')');
 173              }
 174  
 175              $db->setQuery($query, 0, $limit);
 176              $rows = $db->loadObjectList();
 177  
 178              $return = array();
 179              if ($rows) {
 180                  foreach($rows as $key => $row) {
 181                      $rows[$key]->href = WeblinksHelperRoute::getWeblinkRoute($row->slug, $row->catslug);
 182                  }
 183  
 184                  foreach($rows as $key => $weblink) {
 185                      if (searchHelper::checkNoHTML($weblink, $searchText, array('url', 'text', 'title'))) {
 186                          $return[] = $weblink;
 187                      }
 188                  }
 189              }
 190          }
 191          return $return;
 192      }
 193  }


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