| [ Index ] |
PHP Cross Reference of Joomla 1.5.25 |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * @version $Id: newsfeeds.php 14401 2010-01-26 14:10:00Z louis $ 4 * @package Joomla 5 * @copyright Copyright (C) 2005 - 2010 Open Source Matters. All rights reserved. 6 * @license GNU/GPL, see LICENSE.php 7 * Joomla! is free software. This version may have been modified pursuant 8 * to the GNU General Public License, and as distributed it includes or 9 * is derivative of works licensed under the GNU General Public License or 10 * other free or open source software licenses. 11 * See COPYRIGHT.php for copyright notices and details. 12 */ 13 14 // no direct access 15 defined( '_JEXEC' ) or die( 'Restricted access' ); 16 17 $mainframe->registerEvent( 'onSearch', 'plgSearchNewsfeedslinks' ); 18 $mainframe->registerEvent( 'onSearchAreas', 'plgSearchNewsfeedAreas' ); 19 20 JPlugin::loadLanguage( 'plg_search_newsfeeds' ); 21 22 /** 23 * @return array An array of search areas 24 */ 25 function &plgSearchNewsfeedAreas() 26 { 27 static $areas = array( 28 'newsfeeds' => 'Newsfeeds' 29 ); 30 return $areas; 31 } 32 33 /** 34 * Contacts Search method 35 * 36 * The sql must return the following fields that are used in a common display 37 * routine: href, title, section, created, text, browsernav 38 * @param string Target search string 39 * @param string mathcing option, exact|any|all 40 * @param string ordering option, newest|oldest|popular|alpha|category 41 * @param mixed An array if the search it to be restricted to areas, null if search all 42 */ 43 function plgSearchNewsfeedslinks( $text, $phrase='', $ordering='', $areas=null ) 44 { 45 $db =& JFactory::getDBO(); 46 $user =& JFactory::getUser(); 47 48 if (is_array( $areas )) { 49 if (!array_intersect( $areas, array_keys( plgSearchNewsfeedAreas() ) )) { 50 return array(); 51 } 52 } 53 54 // load plugin params info 55 $plugin =& JPluginHelper::getPlugin('search', 'newsfeeds'); 56 $pluginParams = new JParameter( $plugin->params ); 57 58 $limit = $pluginParams->def( 'search_limit', 50 ); 59 60 $text = trim( $text ); 61 if ($text == '') { 62 return array(); 63 } 64 65 $wheres = array(); 66 switch ($phrase) { 67 case 'exact': 68 $text = $db->Quote( '%'.$db->getEscaped( $text, true ).'%', false ); 69 $wheres2 = array(); 70 $wheres2[] = 'a.name LIKE '.$text; 71 $wheres2[] = 'a.link LIKE '.$text; 72 $where = '(' . implode( ') OR (', $wheres2 ) . ')'; 73 break; 74 75 case 'all': 76 case 'any': 77 default: 78 $words = explode( ' ', $text ); 79 $wheres = array(); 80 foreach ($words as $word) 81 { 82 $word = $db->Quote( '%'.$db->getEscaped( $word, true ).'%', false ); 83 $wheres2 = array(); 84 $wheres2[] = 'a.name LIKE '.$word; 85 $wheres2[] = 'a.link LIKE '.$word; 86 $wheres[] = implode( ' OR ', $wheres2 ); 87 } 88 $where = '(' . implode( ($phrase == 'all' ? ') AND (' : ') OR ('), $wheres ) . ')'; 89 break; 90 } 91 92 switch ( $ordering ) { 93 case 'alpha': 94 $order = 'a.name ASC'; 95 break; 96 97 case 'category': 98 $order = 'b.title ASC, a.name ASC'; 99 break; 100 101 case 'oldest': 102 case 'popular': 103 case 'newest': 104 default: 105 $order = 'a.name ASC'; 106 } 107 108 $searchNewsfeeds = JText::_( 'Newsfeeds' ); 109 110 $query = 'SELECT a.name AS title, "" AS created, a.link AS text,' 111 . ' CASE WHEN CHAR_LENGTH(a.alias) THEN CONCAT_WS(\':\', a.id, a.alias) ELSE a.id END as slug, ' 112 . ' CASE WHEN CHAR_LENGTH(b.alias) THEN CONCAT_WS(\':\', b.id, b.alias) ELSE b.id END as catslug, ' 113 . ' CONCAT_WS( " / ", '. $db->Quote($searchNewsfeeds) .', b.title )AS section,' 114 . ' "1" AS browsernav' 115 . ' FROM #__newsfeeds AS a' 116 . ' INNER JOIN #__categories AS b ON b.id = a.catid' 117 . ' WHERE ( '. $where .' )' 118 . ' AND a.published = 1' 119 . ' AND b.published = 1' 120 . ' AND b.access <= '. (int) $user->get( 'aid' ) 121 . ' ORDER BY '. $order 122 ; 123 $db->setQuery( $query, 0, $limit ); 124 $rows = $db->loadObjectList(); 125 126 foreach($rows as $key => $row) { 127 $rows[$key]->href = 'index.php?option=com_newsfeeds&view=newsfeed&catid='.$row->catslug.'&id='.$row->slug; 128 } 129 130 return $rows; 131 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Mon Nov 14 16:47:20 2011 | Cross-referenced by PHPXref 0.7.1 |