[ Index ]

PHP Cross Reference of Mambo 4.6.5

[ Variables ]     [ Functions ]     [ Classes ]     [ Constants ]     [ Statistics ]

title

Body

[close]

/mambots/search/ -> content.searchbot.php (source)

   1  <?php
   2  /**
   3  * @package Mambo
   4  * @author Mambo Foundation Inc see README.php
   5  * @copyright (C) 2000 - 2009 Mambo Foundation Inc.
   6  * See COPYRIGHT.php for copyright notices and details.
   7  * @license GNU/GPL Version 2, see LICENSE.php
   8  *
   9  * Redistributions of files must retain the above copyright notice.
  10  *
  11  * Mambo is free software; you can redistribute it and/or
  12  * modify it under the terms of the GNU General Public License
  13  * as published by the Free Software Foundation; version 2 of the License.
  14  */
  15  
  16  /** ensure this file is being included by a parent file */
  17  defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );
  18  
  19  $_MAMBOTS->registerFunction( 'onSearch', 'botSearchContent' );
  20  
  21  /**
  22  * Content Search method
  23  *
  24  * The sql must return the following fields that are used in a common display
  25  * routine: href, title, section, created, text, browsernav
  26  * @param string Target search string
  27  * @param string mathcing option, exact|any|all
  28  * @param string ordering option, newest|oldest|popular|alpha|category
  29  */
  30  function botSearchContent( $text, $phrase='', $ordering='' ) {
  31      global $my, $database;
  32      global $mosConfig_absolute_path, $mosConfig_offset;
  33  
  34      $_SESSION['searchword'] = $text;
  35  
  36      $now = date( "Y-m-d H:i:s", time()+$mosConfig_offset*60*60 );
  37  
  38      $text = trim( $text );
  39      if ($text == '') {
  40          return array();
  41      }
  42  
  43      $wheres = array();
  44      switch ($phrase) {
  45          case 'exact':
  46              $wheres2 = array();
  47              $wheres2[] = "LOWER(a.title) LIKE '%$text%'";
  48              $wheres2[] = "LOWER(a.introtext) LIKE '%$text%'";
  49              $wheres2[] = "LOWER(a.fulltext) LIKE '%$text%'";
  50              $wheres2[] = "LOWER(a.metakey) LIKE '%$text%'";
  51              $wheres2[] = "LOWER(a.metadesc) LIKE '%$text%'";
  52              $where = '(' . implode( ') OR (', $wheres2 ) . ')';
  53              break;
  54          case 'all':
  55          case 'any':
  56          default:
  57              $words = preg_split( '/\s+|,/', $text );
  58              $wheres = array();
  59              foreach ($words as $word) {
  60                  $wheres2 = array();
  61                  $wheres2[] = "LOWER(a.title) LIKE '%$word%'";
  62                  $wheres2[] = "LOWER(a.introtext) LIKE '%$word%'";
  63                  $wheres2[] = "LOWER(a.fulltext) LIKE '%$word%'";
  64                  $wheres2[] = "LOWER(a.metakey) LIKE '%$word%'";
  65                  $wheres2[] = "LOWER(a.metadesc) LIKE '%$word%'";
  66                  $wheres[] = implode( ' OR ', $wheres2 );
  67              }
  68              $where = '(' . implode( ($phrase == 'all' ? ') AND (' : ') OR ('), $wheres ) . ')';
  69              break;
  70      }
  71  
  72      $morder = '';
  73      switch ($ordering) {
  74          case 'newest':
  75          default:
  76              $order = 'a.created DESC';
  77              break;
  78          case 'oldest':
  79              $order = 'a.created ASC';
  80              break;
  81          case 'popular':
  82              $order = 'a.hits DESC';
  83              break;
  84          case 'alpha':
  85              $order = 'a.title ASC';
  86              break;
  87          case 'category':
  88              $order = 'b.title ASC, a.title ASC';
  89              $morder = 'a.title ASC';
  90              break;
  91      }
  92  
  93      $sql = "SELECT a.title AS title,"
  94      . "\n a.created AS created,"
  95      . "\n CONCAT(a.introtext, a.fulltext) AS text,"
  96      . "\n CONCAT_WS( '/', u.title, b.title ) AS section,";
  97      $sql .= "\n CONCAT( 'index.php?option=com_content&task=view&id=', a.id ) AS href,";
  98      $sql .= "\n '2' AS browsernav"
  99      . "\n FROM #__content AS a"
 100      . "\n INNER JOIN #__categories AS b ON b.id=a.catid AND b.access <= '$my->gid'"
 101      . "\n LEFT JOIN #__sections AS u ON u.id = a.sectionid"
 102      . "\n WHERE ( $where )"
 103      . "\n AND a.state = '1'"
 104      . "\n AND a.access <= '$my->gid'"
 105      . "\n AND u.published = '1'"
 106      . "\n AND b.published = '1'"
 107      . "\n AND ( publish_up = '0000-00-00 00:00:00' OR publish_up <= '$now' )"
 108      . "\n AND ( publish_down = '0000-00-00 00:00:00' OR publish_down >= '$now' )"
 109      . "\n ORDER BY $order";
 110  
 111      $database->setQuery( $sql );
 112  
 113      $list = $database->loadObjectList();
 114  
 115      // search typed content
 116      $database->setQuery( "SELECT a.title AS title, a.created AS created,"
 117      . "\n a.introtext AS text,"
 118      . "\n CONCAT( 'index.php?option=com_content&task=view&id=', a.id, '&Itemid=', m.id ) AS href,"
 119      . "\n '2' as browsernav, 'Menu' AS section"
 120      . "\n FROM #__content AS a"
 121      . "\n LEFT JOIN #__menu AS m ON m.componentid = a.id"
 122      . "\n WHERE ($where)"
 123      . "\n AND a.state='1' AND a.access<='$my->gid' AND m.type='content_typed'"
 124      . "\n AND ( publish_up = '0000-00-00 00:00:00' OR publish_up <= '$now' )"
 125      . "\n AND ( publish_down = '0000-00-00 00:00:00' OR publish_down >= '$now' )"
 126      . "\n ORDER BY " . ($morder ? $morder : $order)
 127      );
 128      $list2 = $database->loadObjectList();
 129  
 130      // search archived content
 131      $database->setQuery( "SELECT a.title AS title,"
 132      . "\n a.created AS created,"
 133      . "\n a.introtext AS text,"
 134      . "\n CONCAT_WS( '/', 'Archived ', u.title, b.title ) AS section,"
 135      . "\n CONCAT('index.php?option=com_content&task=view&id=',a.id) AS href,"
 136      . "\n '2' AS browsernav"
 137      . "\n FROM #__content AS a"
 138      . "\n INNER JOIN #__categories AS b ON b.id=a.catid AND b.access <='$my->gid'"
 139      . "\n LEFT JOIN #__sections AS u ON u.id = a.sectionid"
 140      . "\n WHERE ( $where )"
 141      . "\n AND a.state = '-1' AND a.access <= '$my->gid'"
 142      . "\n AND ( publish_up = '0000-00-00 00:00:00' OR publish_up <= '$now' )"
 143      . "\n AND ( publish_down = '0000-00-00 00:00:00' OR publish_down >= '$now' )"
 144      . "\n ORDER BY $order"
 145      );
 146      $list3 = $database->loadObjectList();
 147  
 148      $result = array();
 149      if ($list) $result = array_merge($result, $list);
 150      if ($list2) $result = array_merge($result, $list2);
 151      if ($list3) $result = array_merge($result, $list3);
 152  
 153      return $result;
 154  }
 155  ?>