[ Index ]

PHP Cross Reference of Joomla 1.5.26 DE

title

Body

[close]

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

   1  <?php
   2  /**
   3   * @version        $Id: contacts.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', 'plgSearchContacts' );
  18  $mainframe->registerEvent( 'onSearchAreas', 'plgSearchContactAreas' );
  19  
  20  JPlugin::loadLanguage( 'plg_search_contacts' );
  21  
  22  /**
  23   * @return array An array of search areas
  24   */
  25  function &plgSearchContactAreas()
  26  {
  27      static $areas = array(
  28          'contacts' => 'Contacts'
  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  */
  42  function plgSearchContacts( $text, $phrase='', $ordering='', $areas=null )
  43  {
  44      $db        =& JFactory::getDBO();
  45      $user    =& JFactory::getUser();
  46  
  47      if (is_array( $areas )) {
  48          if (!array_intersect( $areas, array_keys( plgSearchContactAreas() ) )) {
  49              return array();
  50          }
  51      }
  52  
  53      // load plugin params info
  54       $plugin =& JPluginHelper::getPlugin('search', 'contacts');
  55       $pluginParams = new JParameter( $plugin->params );
  56  
  57      $limit = $pluginParams->def( 'search_limit', 50 );
  58  
  59      $text = trim( $text );
  60      if ($text == '') {
  61          return array();
  62      }
  63  
  64      $section = JText::_( 'Contact' );
  65  
  66      switch ( $ordering ) {
  67          case 'alpha':
  68              $order = 'a.name ASC';
  69              break;
  70  
  71          case 'category':
  72              $order = 'b.title ASC, a.name ASC';
  73              break;
  74  
  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.name AS title, "" AS created,'
  84      . ' CASE WHEN CHAR_LENGTH(a.alias) THEN CONCAT_WS(\':\', a.id, a.alias) ELSE a.id END as slug, '
  85      . ' CASE WHEN CHAR_LENGTH(b.alias) THEN CONCAT_WS(\':\', b.id, b.alias) ELSE b.id END AS catslug, '
  86      . ' CONCAT_WS( ", ", a.name, a.con_position, a.misc ) AS text,'
  87      . ' CONCAT_WS( " / ", '.$db->Quote($section).', b.title ) AS section,'
  88      . ' "2" AS browsernav'
  89      . ' FROM #__contact_details AS a'
  90      . ' INNER JOIN #__categories AS b ON b.id = a.catid'
  91      . ' WHERE ( a.name LIKE '.$text
  92      . ' OR a.misc LIKE '.$text
  93      . ' OR a.con_position LIKE '.$text
  94      . ' OR a.address LIKE '.$text
  95      . ' OR a.suburb LIKE '.$text
  96      . ' OR a.state LIKE '.$text
  97      . ' OR a.country LIKE '.$text
  98      . ' OR a.postcode LIKE '.$text
  99      . ' OR a.telephone LIKE '.$text
 100      . ' OR a.fax LIKE '.$text.' )'
 101      . ' AND a.published = 1'
 102      . ' AND b.published = 1'
 103      . ' AND a.access <= '.(int) $user->get( 'aid' )
 104      . ' AND b.access <= '.(int) $user->get( 'aid' )
 105      . ' GROUP BY a.id'
 106      . ' ORDER BY '. $order
 107      ;
 108      $db->setQuery( $query, 0, $limit );
 109      $rows = $db->loadObjectList();
 110  
 111      foreach($rows as $key => $row) {
 112          $rows[$key]->href = 'index.php?option=com_contact&view=contact&id='.$row->slug.'&catid='.$row->catslug;
 113      }
 114  
 115      return $rows;
 116  }


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