| [ 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 /** 11 * Contacts Search plugin 12 * 13 * @package Joomla.Plugin 14 * @subpackage Search.contacts 15 * @since 1.6 16 */ 17 class plgSearchContacts 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 'contacts' => 'PLG_SEARCH_CONTACTS_CONTACTS' 40 ); 41 return $areas; 42 } 43 44 /** 45 * Contacts 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 matching option, exact|any|all 51 * @param string ordering option, newest|oldest|popular|alpha|category 52 */ 53 function onContentSearch($text, $phrase='', $ordering='', $areas=null) 54 { 55 $db = JFactory::getDbo(); 56 $app = JFactory::getApplication(); 57 $user = JFactory::getUser(); 58 $groups = implode(',', $user->getAuthorisedViewLevels()); 59 60 if (is_array($areas)) { 61 if (!array_intersect($areas, array_keys($this->onContentSearchAreas()))) { 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 $state[]=1; 72 } 73 if ($sArchived) { 74 $state[]=2; 75 } 76 77 $text = trim($text); 78 if ($text == '') { 79 return array(); 80 } 81 82 $section = JText::_('PLG_SEARCH_CONTACTS_CONTACTS'); 83 84 switch ($ordering) { 85 case 'alpha': 86 $order = 'a.name ASC'; 87 break; 88 89 case 'category': 90 $order = 'c.title ASC, a.name ASC'; 91 break; 92 93 case 'popular': 94 case 'newest': 95 case 'oldest': 96 default: 97 $order = 'a.name DESC'; 98 } 99 100 $text = $db->Quote('%'.$db->escape($text, true).'%', false); 101 102 $rows = array(); 103 if (!empty($state)) { 104 $query = $db->getQuery(true); 105 //sqlsrv changes 106 $case_when = ' CASE WHEN '; 107 $case_when .= $query->charLength('a.alias'); 108 $case_when .= ' THEN '; 109 $a_id = $query->castAsChar('a.id'); 110 $case_when .= $query->concatenate(array($a_id, 'a.alias'), ':'); 111 $case_when .= ' ELSE '; 112 $case_when .= $a_id.' END as slug'; 113 114 $case_when1 = ' CASE WHEN '; 115 $case_when1 .= $query->charLength('c.alias'); 116 $case_when1 .= ' THEN '; 117 $c_id = $query->castAsChar('c.id'); 118 $case_when1 .= $query->concatenate(array($c_id, 'c.alias'), ':'); 119 $case_when1 .= ' ELSE '; 120 $case_when1 .= $c_id.' END as catslug'; 121 122 $query->select('a.name AS title, \'\' AS created, a.con_position, a.misc, ' 123 .$case_when.','.$case_when1.', ' 124 . $query->concatenate(array("a.name", "a.con_position", "a.misc"), ",").' AS text,' 125 . $query->concatenate(array($db->Quote($section), "c.title"), " / ").' AS section,' 126 . '\'2\' AS browsernav'); 127 $query->from('#__contact_details AS a'); 128 $query->innerJoin('#__categories AS c ON c.id = a.catid'); 129 $query->where('(a.name LIKE '. $text .'OR a.misc LIKE '. $text .'OR a.con_position LIKE '. $text 130 .'OR a.address LIKE '. $text .'OR a.suburb LIKE '. $text .'OR a.state LIKE '. $text 131 .'OR a.country LIKE '. $text .'OR a.postcode LIKE '. $text .'OR a.telephone LIKE '. $text 132 .'OR a.fax LIKE '. $text .') AND a.published IN ('.implode(',', $state).') AND c.published=1 ' 133 .'AND a.access IN ('. $groups. ') AND c.access IN ('. $groups. ')' ); 134 $query->group('a.id, a.con_position, a.misc'); 135 $query->order($order); 136 137 // Filter by language 138 if ($app->isSite() && $app->getLanguageFilter()) { 139 $tag = JFactory::getLanguage()->getTag(); 140 $query->where('a.language in (' . $db->Quote($tag) . ',' . $db->Quote('*') . ')'); 141 $query->where('c.language in (' . $db->Quote($tag) . ',' . $db->Quote('*') . ')'); 142 } 143 144 $db->setQuery($query, 0, $limit); 145 $rows = $db->loadObjectList(); 146 147 if ($rows) { 148 foreach($rows as $key => $row) { 149 $rows[$key]->href = 'index.php?option=com_contact&view=contact&id='.$row->slug.'&catid='.$row->catslug; 150 $rows[$key]->text = $row->title; 151 $rows[$key]->text .= ($row->con_position) ? ', '.$row->con_position : ''; 152 $rows[$key]->text .= ($row->misc) ? ', '.$row->misc : ''; 153 } 154 } 155 } 156 return $rows; 157 } 158 }
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 |