[ Index ]

PHP Cross Reference of Joomla 1.5.26 DE

title

Body

[close]

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

   1  <?php
   2  /**
   3   * @version        $Id: weblinks.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', 'plgSearchWeblinks' );
  18  $mainframe->registerEvent( 'onSearchAreas', 'plgSearchWeblinksAreas' );
  19  
  20  JPlugin::loadLanguage( 'plg_search_weblinks' );
  21  
  22  /**
  23   * @return array An array of search areas
  24   */
  25  function &plgSearchWeblinksAreas() {
  26      static $areas = array(
  27          'weblinks' => 'Weblinks'
  28      );
  29      return $areas;
  30  }
  31  
  32  /**
  33  * Weblink Search method
  34  *
  35  * The sql must return the following fields that are used in a common display
  36  * routine: href, title, section, created, text, browsernav
  37  * @param string Target search string
  38  * @param string mathcing option, exact|any|all
  39  * @param string ordering option, newest|oldest|popular|alpha|category
  40   * @param mixed An array if the search it to be restricted to areas, null if search all
  41   */
  42  function plgSearchWeblinks( $text, $phrase='', $ordering='', $areas=null )
  43  {
  44      $db        =& JFactory::getDBO();
  45      $user    =& JFactory::getUser();
  46  
  47      $searchText = $text;
  48  
  49      require_once (JPATH_SITE.DS.'components'.DS.'com_weblinks'.DS.'helpers'.DS.'route.php');
  50  
  51      if (is_array( $areas )) {
  52          if (!array_intersect( $areas, array_keys( plgSearchWeblinksAreas() ) )) {
  53              return array();
  54          }
  55      }
  56  
  57      // load plugin params info
  58       $plugin =& JPluginHelper::getPlugin('search', 'weblinks');
  59       $pluginParams = new JParameter( $plugin->params );
  60  
  61      $limit = $pluginParams->def( 'search_limit', 50 );
  62  
  63      $text = trim( $text );
  64      if ($text == '') {
  65          return array();
  66      }
  67      $section     = JText::_( 'Web Links' );
  68  
  69      $wheres     = array();
  70      switch ($phrase)
  71      {
  72          case 'exact':
  73              $text        = $db->Quote( '%'.$db->getEscaped( $text, true ).'%', false );
  74              $wheres2     = array();
  75              $wheres2[]     = 'a.url LIKE '.$text;
  76              $wheres2[]     = 'a.description LIKE '.$text;
  77              $wheres2[]     = 'a.title LIKE '.$text;
  78              $where         = '(' . implode( ') OR (', $wheres2 ) . ')';
  79              break;
  80  
  81          case 'all':
  82          case 'any':
  83          default:
  84              $words     = explode( ' ', $text );
  85              $wheres = array();
  86              foreach ($words as $word)
  87              {
  88                  $word        = $db->Quote( '%'.$db->getEscaped( $word, true ).'%', false );
  89                  $wheres2     = array();
  90                  $wheres2[]     = 'a.url LIKE '.$word;
  91                  $wheres2[]     = 'a.description LIKE '.$word;
  92                  $wheres2[]     = 'a.title LIKE '.$word;
  93                  $wheres[]     = implode( ' OR ', $wheres2 );
  94              }
  95              $where     = '(' . implode( ($phrase == 'all' ? ') AND (' : ') OR ('), $wheres ) . ')';
  96              break;
  97      }
  98  
  99      switch ( $ordering )
 100      {
 101          case 'oldest':
 102              $order = 'a.date ASC';
 103              break;
 104  
 105          case 'popular':
 106              $order = 'a.hits DESC';
 107              break;
 108  
 109          case 'alpha':
 110              $order = 'a.title ASC';
 111              break;
 112  
 113          case 'category':
 114              $order = 'b.title ASC, a.title ASC';
 115              break;
 116  
 117          case 'newest':
 118          default:
 119              $order = 'a.date DESC';
 120      }
 121  
 122      $query = 'SELECT a.title AS title, a.description AS text, a.date AS created, a.url, '
 123      . ' CASE WHEN CHAR_LENGTH(a.alias) THEN CONCAT_WS(\':\', a.id, a.alias) ELSE a.id END as slug, '
 124      . ' CASE WHEN CHAR_LENGTH(b.alias) THEN CONCAT_WS(\':\', b.id, b.alias) ELSE b.id END as catslug, '
 125      . ' CONCAT_WS( " / ", '.$db->Quote($section).', b.title ) AS section,'
 126      . ' "1" AS browsernav'
 127      . ' FROM #__weblinks AS a'
 128      . ' INNER JOIN #__categories AS b ON b.id = a.catid'
 129      . ' WHERE ('. $where .')'
 130      . ' AND a.published = 1'
 131      . ' AND b.published = 1'
 132      . ' AND b.access <= '.(int) $user->get( 'aid' )
 133      . ' ORDER BY '. $order
 134      ;
 135      $db->setQuery( $query, 0, $limit );
 136      $rows = $db->loadObjectList();
 137  
 138      foreach($rows as $key => $row) {
 139          $rows[$key]->href = WeblinksHelperRoute::getWeblinkRoute($row->slug, $row->catslug);
 140      }
 141  
 142      $return = array();
 143      foreach($rows AS $key => $weblink) {
 144          if(searchHelper::checkNoHTML($weblink, $searchText, array('url', 'text', 'title'))) {
 145              $return[] = $weblink;
 146          }
 147      }
 148  
 149      return $return;
 150  }


Generated: Wed Mar 28 15:54:07 2012 Cross-referenced by PHPXref 0.7.1