[ Index ]

PHP Cross Reference of Joomla 1.5.25

title

Body

[close]

/plugins/search/ -> categories.php (source)

   1  <?php
   2  /**
   3   * @version        $Id: categories.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', 'plgSearchCategories' );
  18  $mainframe->registerEvent( 'onSearchAreas', 'plgSearchCategoryAreas' );
  19  
  20  JPlugin::loadLanguage( 'plg_search_categories' );
  21  
  22  /**
  23   * @return array An array of search areas
  24   */
  25  function &plgSearchCategoryAreas()
  26  {
  27      static $areas = array(
  28          'categories' => 'Categories'
  29      );
  30      return $areas;
  31  }
  32  
  33  /**
  34   * Categories Search method
  35   *
  36   * The sql must return the following fields that are
  37   * used in a common display routine: href, title, section, created, text,
  38   * browsernav
  39   * @param string Target search string
  40   * @param string mathcing option, exact|any|all
  41   * @param string ordering option, newest|oldest|popular|alpha|category
  42   * @param mixed An array if restricted to areas, null if search all
  43   */
  44  function plgSearchCategories( $text, $phrase='', $ordering='', $areas=null )
  45  {
  46      $db        =& JFactory::getDBO();
  47      $user    =& JFactory::getUser();
  48      $searchText = $text;
  49  
  50      require_once (JPATH_SITE.DS.'components'.DS.'com_content'.DS.'helpers'.DS.'route.php');
  51  
  52      if (is_array( $areas )) {
  53          if (!array_intersect( $areas, array_keys( plgSearchCategoryAreas() ) )) {
  54              return array();
  55          }
  56      }
  57  
  58      // load plugin params info
  59       $plugin =& JPluginHelper::getPlugin('search', 'categories');
  60       $pluginParams = new JParameter( $plugin->params );
  61  
  62      $limit = $pluginParams->def( 'search_limit', 50 );
  63  
  64      $text = trim( $text );
  65      if ( $text == '' ) {
  66          return array();
  67      }
  68  
  69      switch ( $ordering ) {
  70          case 'alpha':
  71              $order = 'a.name ASC';
  72              break;
  73  
  74          case 'category':
  75          case 'popular':
  76          case 'newest':
  77          case 'oldest':
  78          default:
  79              $order = 'a.name DESC';
  80      }
  81  
  82      $text    = $db->Quote( '%'.$db->getEscaped( $text, true ).'%', false );
  83      $query    = 'SELECT a.title, a.description AS text, "" AS created, a.name,'
  84      . ' "2" AS browsernav,'
  85      . ' s.id AS secid, a.id AS catid,'
  86      . ' CASE WHEN CHAR_LENGTH(a.alias) THEN CONCAT_WS(":", a.id, a.alias) ELSE a.id END as slug'
  87      . ' FROM #__categories AS a'
  88      . ' INNER JOIN #__sections AS s ON s.id = a.section'
  89      . ' WHERE ( a.name LIKE '.$text
  90      . ' OR a.title LIKE '.$text
  91      . ' OR a.description LIKE '.$text.' )'
  92      . ' AND a.published = 1'
  93      . ' AND s.published = 1'
  94      . ' AND a.access <= '.(int) $user->get('aid')
  95      . ' AND s.access <= '.(int) $user->get('aid')
  96      . ' GROUP BY a.id'
  97      . ' ORDER BY '. $order
  98      ;
  99      $db->setQuery( $query, 0, $limit );
 100      $rows = $db->loadObjectList();
 101  
 102      $count = count( $rows );
 103      for ( $i = 0; $i < $count; $i++ ) {
 104          $rows[$i]->href = ContentHelperRoute::getCategoryRoute($rows[$i]->slug, $rows[$i]->secid);
 105          $rows[$i]->section     = JText::_( 'Category' );
 106      }
 107  
 108      $return = array();
 109      foreach($rows AS $key => $category) {
 110          if(searchHelper::checkNoHTML($category, $searchText, array('name', 'title', 'text'))) {
 111              $return[] = $category;
 112          }
 113      }
 114  
 115      return $return;
 116  }


Generated: Mon Nov 14 16:47:20 2011 Cross-referenced by PHPXref 0.7.1