Source for file newsfeeds.php

Documentation is available at newsfeeds.php

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

Documentation generated on Tue, 19 Nov 2013 15:09:32 +0100 by phpDocumentor 1.4.3