| [ Index ] |
PHP Cross Reference of Joomla 2.5.4 DE |
[Summary view] [Print] [Text view]
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_content/helpers/route.php'; 11 12 /** 13 * Categories Search plugin 14 * 15 * @package Joomla.Plugin 16 * @subpackage Search.categories 17 * @since 1.6 18 */ 19 class plgSearchCategories 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 { 40 static $areas = array( 41 'categories' => 'PLG_SEARCH_CATEGORIES_CATEGORIES' 42 ); 43 return $areas; 44 } 45 46 /** 47 * Categories Search method 48 * 49 * The sql must return the following fields that are 50 * used in a common display routine: href, title, section, created, text, 51 * browsernav 52 * @param string Target search string 53 * @param string mathcing option, exact|any|all 54 * @param string ordering option, newest|oldest|popular|alpha|category 55 * @param mixed An array if restricted to areas, null if search all 56 */ 57 function onContentSearch($text, $phrase='', $ordering='', $areas=null) 58 { 59 $db = JFactory::getDbo(); 60 $user = JFactory::getUser(); 61 $app = JFactory::getApplication(); 62 $groups = implode(',', $user->getAuthorisedViewLevels()); 63 $searchText = $text; 64 65 if (is_array($areas)) { 66 if (!array_intersect($areas, array_keys($this->onContentSearchAreas()))) { 67 return array(); 68 } 69 } 70 71 $sContent = $this->params->get('search_content', 1); 72 $sArchived = $this->params->get('search_archived', 1); 73 $limit = $this->params->def('search_limit', 50); 74 $state = array(); 75 if ($sContent) { 76 $state[]=1; 77 } 78 if ($sArchived) { 79 $state[]=2; 80 } 81 82 83 $text = trim($text); 84 if ($text == '') { 85 return array(); 86 } 87 88 switch($phrase) { 89 case 'exact': 90 $text = $db->Quote('%'.$db->escape($text, true).'%', false); 91 $wheres2 = array(); 92 $wheres2[] = 'a.title LIKE '.$text; 93 $wheres2[] = 'a.description LIKE '.$text; 94 $where = '(' . implode(') OR (', $wheres2) . ')'; 95 break; 96 97 case 'any': 98 case 'all'; 99 default: 100 $words = explode(' ', $text); 101 $wheres = array(); 102 foreach ($words as $word) { 103 $word = $db->Quote('%'.$db->escape($word, true).'%', false); 104 $wheres2 = array(); 105 $wheres2[] = 'a.title LIKE '.$word; 106 $wheres2[] = 'a.description LIKE '.$word; 107 $wheres[] = implode(' OR ', $wheres2); 108 } 109 $where = '(' . implode(($phrase == 'all' ? ') AND (' : ') OR ('), $wheres) . ')'; 110 break; 111 } 112 113 switch ($ordering) { 114 case 'alpha': 115 $order = 'a.title ASC'; 116 break; 117 118 case 'category': 119 case 'popular': 120 case 'newest': 121 case 'oldest': 122 default: 123 $order = 'a.title DESC'; 124 } 125 126 $text = $db->Quote('%'.$db->escape($text, true).'%', false); 127 $query = $db->getQuery(true); 128 129 $return = array(); 130 if (!empty($state)) { 131 //sqlsrv changes 132 $case_when = ' CASE WHEN '; 133 $case_when .= $query->charLength('a.alias'); 134 $case_when .= ' THEN '; 135 $a_id = $query->castAsChar('a.id'); 136 $case_when .= $query->concatenate(array($a_id, 'a.alias'), ':'); 137 $case_when .= ' ELSE '; 138 $case_when .= $a_id.' END as slug'; 139 $query->select('a.title, a.description AS text, "" AS created, "2" AS browsernav, a.id AS catid, ' . $case_when); 140 $query->from('#__categories AS a'); 141 $query->where('(a.title LIKE '. $text .' OR a.description LIKE '. $text .') AND a.published IN ('.implode(',', $state).') AND a.extension = \'com_content\'' 142 .'AND a.access IN ('. $groups .')' ); 143 $query->group('a.id'); 144 $query->order($order); 145 if ($app->isSite() && $app->getLanguageFilter()) { 146 $query->where('a.language in (' . $db->Quote(JFactory::getLanguage()->getTag()) . ',' . $db->Quote('*') . ')'); 147 } 148 149 $db->setQuery($query, 0, $limit); 150 $rows = $db->loadObjectList(); 151 152 if ($rows) { 153 $count = count($rows); 154 for ($i = 0; $i < $count; $i++) { 155 $rows[$i]->href = ContentHelperRoute::getCategoryRoute($rows[$i]->slug); 156 $rows[$i]->section = JText::_('JCATEGORY'); 157 } 158 159 foreach($rows as $key => $category) { 160 if (searchHelper::checkNoHTML($category, $searchText, array('name', 'title', 'text'))) { 161 $return[] = $category; 162 } 163 } 164 } 165 } 166 return $return; 167 } 168 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Tue Apr 3 11:40:28 2012 | Cross-referenced by PHPXref 0.7.1 |