[ Index ]

PHP Cross Reference of Joomla 2.5.4 DE

title

Body

[close]

/plugins/search/newsfeeds/ -> newsfeeds.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  /**
  11   * Newsfeeds Search plugin
  12   *
  13   * @package        Joomla.Plugin
  14   * @subpackage    Search.content
  15   * @since        1.6
  16   */
  17  class plgSearchNewsfeeds extends JPlugin
  18  {
  19      /**
  20       * Constructor
  21       *
  22       * @access      protected
  23       * @param       object  $subject The object to observe
  24       * @param       array   $config  An array that holds the plugin configuration
  25       * @since       1.5
  26       */
  27  	public function __construct(& $subject, $config)
  28      {
  29          parent::__construct($subject, $config);
  30          $this->loadLanguage();
  31      }
  32  
  33      /**
  34       * @return array An array of search areas
  35       */
  36  	function onContentSearchAreas()
  37      {
  38          static $areas = array(
  39              'newsfeeds' => 'PLG_SEARCH_NEWSFEEDS_NEWSFEEDS'
  40              );
  41              return $areas;
  42      }
  43  
  44      /**
  45       * Newsfeeds Search method
  46       *
  47       * The sql must return the following fields that are used in a common display
  48       * routine: href, title, section, created, text, browsernav
  49       * @param string Target search string
  50       * @param string mathcing option, exact|any|all
  51       * @param string ordering option, newest|oldest|popular|alpha|category
  52       * @param mixed An array if the search it to be restricted to areas, null if search all
  53       */
  54  	function onContentSearch($text, $phrase='', $ordering='', $areas=null)
  55      {
  56          $db        = JFactory::getDbo();
  57          $app    = JFactory::getApplication();
  58          $user    = JFactory::getUser();
  59          $groups    = implode(',', $user->getAuthorisedViewLevels());
  60  
  61          if (is_array($areas)) {
  62              if (!array_intersect($areas, array_keys($this->onContentSearchAreas()))) {
  63                  return array();
  64              }
  65          }
  66  
  67          $sContent        = $this->params->get('search_content',        1);
  68          $sArchived        = $this->params->get('search_archived',        1);
  69          $limit            = $this->params->def('search_limit',        50);
  70          $state = array();
  71          if ($sContent) {
  72              $state[]=1;
  73          }
  74          if ($sArchived) {
  75              $state[]=2;
  76          }
  77  
  78          $text = trim($text);
  79          if ($text == '') {
  80              return array();
  81          }
  82  
  83          switch ($phrase) {
  84              case 'exact':
  85                  $text        = $db->Quote('%'.$db->escape($text, true).'%', false);
  86                  $wheres2    = array();
  87                  $wheres2[]    = 'a.name LIKE '.$text;
  88                  $wheres2[]    = 'a.link LIKE '.$text;
  89                  $where        = '(' . implode(') OR (', $wheres2) . ')';
  90                  break;
  91  
  92              case 'all':
  93              case 'any':
  94              default:
  95                  $words    = explode(' ', $text);
  96                  $wheres = array();
  97                  foreach ($words as $word)
  98                  {
  99                      $word        = $db->Quote('%'.$db->escape($word, true).'%', false);
 100                      $wheres2    = array();
 101                      $wheres2[]    = 'a.name LIKE '.$word;
 102                      $wheres2[]    = 'a.link LIKE '.$word;
 103                      $wheres[]    = implode(' OR ', $wheres2);
 104                  }
 105                  $where = '(' . implode(($phrase == 'all' ? ') AND (' : ') OR ('), $wheres) . ')';
 106                  break;
 107          }
 108  
 109          switch ($ordering) {
 110              case 'alpha':
 111                  $order = 'a.name ASC';
 112                  break;
 113  
 114              case 'category':
 115                  $order = 'c.title ASC, a.name ASC';
 116                  break;
 117  
 118              case 'oldest':
 119              case 'popular':
 120              case 'newest':
 121              default:
 122                  $order = 'a.name ASC';
 123          }
 124  
 125          $searchNewsfeeds = JText::_('PLG_SEARCH_NEWSFEEDS_NEWSFEEDS');
 126  
 127          $rows = array();
 128          if (!empty($state)) {
 129              $query    = $db->getQuery(true);
 130              //sqlsrv changes
 131              $case_when = ' CASE WHEN ';
 132              $case_when .= $query->charLength('a.alias');
 133              $case_when .= ' THEN ';
 134              $a_id = $query->castAsChar('a.id');
 135              $case_when .= $query->concatenate(array($a_id, 'a.alias'), ':');
 136              $case_when .= ' ELSE ';
 137              $case_when .= $a_id.' END as slug';
 138  
 139              $case_when1 = ' CASE WHEN ';
 140              $case_when1 .= $query->charLength('c.alias');
 141              $case_when1 .= ' THEN ';
 142              $c_id = $query->castAsChar('c.id');
 143              $case_when1 .= $query->concatenate(array($c_id, 'c.alias'), ':');
 144              $case_when1 .= ' ELSE ';
 145              $case_when1 .= $c_id.' END as catslug';
 146  
 147              $query->select('a.name AS title, "" AS created, a.link AS text, ' . $case_when."," . $case_when1);
 148              $query->select($query->concatenate(array($db->Quote($searchNewsfeeds), 'c.title'), " / ").' AS section');
 149              $query->select('"1" AS browsernav');
 150              $query->from('#__newsfeeds AS a');
 151              $query->innerJoin('#__categories as c ON c.id = a.catid');
 152              $query->where('('. $where .')' . 'AND a.published IN ('.implode(',', $state).') AND c.published = 1 AND c.access IN ('. $groups .')');
 153              $query->order($order);
 154  
 155              // Filter by language
 156              if ($app->isSite() && $app->getLanguageFilter()) {
 157                  $tag = JFactory::getLanguage()->getTag();
 158                  $query->where('a.language in (' . $db->Quote($tag) . ',' . $db->Quote('*') . ')');
 159                  $query->where('c.language in (' . $db->Quote($tag) . ',' . $db->Quote('*') . ')');
 160              }
 161  
 162              $db->setQuery($query, 0, $limit);
 163              $rows = $db->loadObjectList();
 164  
 165              if ($rows) {
 166                  foreach($rows as $key => $row) {
 167                      $rows[$key]->href = 'index.php?option=com_newsfeeds&view=newsfeed&catid='.$row->catslug.'&id='.$row->slug;
 168                  }
 169              }
 170          }
 171          return $rows;
 172      }
 173  }


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