Annotation of /mambo/branches/4.5.3h/mambots/search/content.searchbot.php
Parent Directory
|
Revision Log
Revision 22 - (view) (download)
| 1 : | root | 1 | <?php |
| 2 : | /** | ||
| 3 : | * @version $Id: content.searchbot.php,v 1.2 2005/10/13 05:03:24 cauld Exp $ | ||
| 4 : | * @package Mambo | ||
| 5 : | * @copyright (C) 2000 - 2005 Miro International Pty Ltd | ||
| 6 : | * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL | ||
| 7 : | * Mambo is Free Software | ||
| 8 : | */ | ||
| 9 : | |||
| 10 : | /** ensure this file is being included by a parent file */ | ||
| 11 : | defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' ); | ||
| 12 : | |||
| 13 : | $_MAMBOTS->registerFunction( 'onSearch', 'botSearchContent' ); | ||
| 14 : | |||
| 15 : | /** | ||
| 16 : | * Content Search method | ||
| 17 : | * | ||
| 18 : | * The sql must return the following fields that are used in a common display | ||
| 19 : | * routine: href, title, section, created, text, browsernav | ||
| 20 : | * @param string Target search string | ||
| 21 : | * @param string mathcing option, exact|any|all | ||
| 22 : | * @param string ordering option, newest|oldest|popular|alpha|category | ||
| 23 : | */ | ||
| 24 : | function botSearchContent( $text, $phrase='', $ordering='' ) { | ||
| 25 : | global $my, $database; | ||
| 26 : | global $mosConfig_absolute_path, $mosConfig_offset; | ||
| 27 : | |||
| 28 : | $_SESSION['searchword'] = $text; | ||
| 29 : | |||
| 30 : | $now = date( "Y-m-d H:i:s", time()+$mosConfig_offset*60*60 ); | ||
| 31 : | |||
| 32 : | $text = trim( $text ); | ||
| 33 : | if ($text == '') { | ||
| 34 : | return array(); | ||
| 35 : | } | ||
| 36 : | |||
| 37 : | $wheres = array(); | ||
| 38 : | switch ($phrase) { | ||
| 39 : | case 'exact': | ||
| 40 : | $wheres2 = array(); | ||
| 41 : | $wheres2[] = "LOWER(a.title) LIKE '%$text%'"; | ||
| 42 : | $wheres2[] = "LOWER(a.introtext) LIKE '%$text%'"; | ||
| 43 : | $wheres2[] = "LOWER(a.fulltext) LIKE '%$text%'"; | ||
| 44 : | $wheres2[] = "LOWER(a.metakey) LIKE '%$text%'"; | ||
| 45 : | $wheres2[] = "LOWER(a.metadesc) LIKE '%$text%'"; | ||
| 46 : | $where = '(' . implode( ') OR (', $wheres2 ) . ')'; | ||
| 47 : | break; | ||
| 48 : | case 'all': | ||
| 49 : | case 'any': | ||
| 50 : | default: | ||
| 51 : | $words = explode( ' ', $text ); | ||
| 52 : | $wheres = array(); | ||
| 53 : | foreach ($words as $word) { | ||
| 54 : | $wheres2 = array(); | ||
| 55 : | $wheres2[] = "LOWER(a.title) LIKE '%$word%'"; | ||
| 56 : | $wheres2[] = "LOWER(a.introtext) LIKE '%$word%'"; | ||
| 57 : | $wheres2[] = "LOWER(a.fulltext) LIKE '%$word%'"; | ||
| 58 : | $wheres2[] = "LOWER(a.metakey) LIKE '%$word%'"; | ||
| 59 : | $wheres2[] = "LOWER(a.metadesc) LIKE '%$word%'"; | ||
| 60 : | $wheres[] = implode( ' OR ', $wheres2 ); | ||
| 61 : | } | ||
| 62 : | $where = '(' . implode( ($phrase == 'all' ? ') AND (' : ') OR ('), $wheres ) . ')'; | ||
| 63 : | break; | ||
| 64 : | } | ||
| 65 : | |||
| 66 : | $morder = ''; | ||
| 67 : | switch ($ordering) { | ||
| 68 : | case 'newest': | ||
| 69 : | default: | ||
| 70 : | $order = 'a.created DESC'; | ||
| 71 : | break; | ||
| 72 : | case 'oldest': | ||
| 73 : | $order = 'a.created ASC'; | ||
| 74 : | break; | ||
| 75 : | case 'popular': | ||
| 76 : | $order = 'a.hits DESC'; | ||
| 77 : | break; | ||
| 78 : | case 'alpha': | ||
| 79 : | $order = 'a.title ASC'; | ||
| 80 : | break; | ||
| 81 : | case 'category': | ||
| 82 : | $order = 'b.title ASC, a.title ASC'; | ||
| 83 : | $morder = 'a.title ASC'; | ||
| 84 : | break; | ||
| 85 : | } | ||
| 86 : | |||
| 87 : | $sql = "SELECT a.title AS title," | ||
| 88 : | . "\n a.created AS created," | ||
| 89 : | . "\n CONCAT(a.introtext, a.fulltext) AS text," | ||
| 90 : | . "\n CONCAT_WS( '/', u.title, b.title ) AS section,"; | ||
| 91 : | $sql .= "\n CONCAT( 'index.php?option=com_content&task=view&id=', a.id ) AS href,"; | ||
| 92 : | $sql .= "\n '2' AS browsernav" | ||
| 93 : | . "\n FROM #__content AS a" | ||
| 94 : | . "\n INNER JOIN #__categories AS b ON b.id=a.catid AND b.access <= '$my->gid'" | ||
| 95 : | . "\n LEFT JOIN #__sections AS u ON u.id = a.sectionid" | ||
| 96 : | . "\n WHERE ( $where )" | ||
| 97 : | . "\n AND a.state = '1'" | ||
| 98 : | . "\n AND a.access <= '$my->gid'" | ||
| 99 : | . "\n AND u.published = '1'" | ||
| 100 : | . "\n AND b.published = '1'" | ||
| 101 : | . "\n AND ( publish_up = '0000-00-00 00:00:00' OR publish_up <= '$now' )" | ||
| 102 : | . "\n AND ( publish_down = '0000-00-00 00:00:00' OR publish_down >= '$now' )" | ||
| 103 : | . "\n ORDER BY $order"; | ||
| 104 : | |||
| 105 : | $database->setQuery( $sql ); | ||
| 106 : | |||
| 107 : | $list = $database->loadObjectList(); | ||
| 108 : | |||
| 109 : | // search typed content | ||
| 110 : | $database->setQuery( "SELECT a.title AS title, a.created AS created," | ||
| 111 : | . "\n a.introtext AS text," | ||
| 112 : | . "\n CONCAT( 'index.php?option=com_content&task=view&id=', a.id, '&Itemid=', m.id ) AS href," | ||
| 113 : | . "\n '2' as browsernav, 'Menu' AS section" | ||
| 114 : | . "\n FROM #__content AS a" | ||
| 115 : | . "\n LEFT JOIN #__menu AS m ON m.componentid = a.id" | ||
| 116 : | . "\n WHERE ($where)" | ||
| 117 : | . "\n AND a.state='1' AND a.access<='$my->gid' AND m.type='content_typed'" | ||
| 118 : | . "\n AND ( publish_up = '0000-00-00 00:00:00' OR publish_up <= '$now' )" | ||
| 119 : | . "\n AND ( publish_down = '0000-00-00 00:00:00' OR publish_down >= '$now' )" | ||
| 120 : | . "\n ORDER BY " . ($morder ? $morder : $order) | ||
| 121 : | ); | ||
| 122 : | $list2 = $database->loadObjectList(); | ||
| 123 : | |||
| 124 : | // search archived content | ||
| 125 : | $database->setQuery( "SELECT a.title AS title," | ||
| 126 : | . "\n a.created AS created," | ||
| 127 : | . "\n a.introtext AS text," | ||
| 128 : | . "\n CONCAT_WS( '/', 'Archived ', u.title, b.title ) AS section," | ||
| 129 : | . "\n CONCAT('index.php?option=com_content&task=view&id=',a.id) AS href," | ||
| 130 : | . "\n '2' AS browsernav" | ||
| 131 : | . "\n FROM #__content AS a" | ||
| 132 : | . "\n INNER JOIN #__categories AS b ON b.id=a.catid AND b.access <='$my->gid'" | ||
| 133 : | . "\n LEFT JOIN #__sections AS u ON u.id = a.sectionid" | ||
| 134 : | . "\n WHERE ( $where )" | ||
| 135 : | . "\n AND a.state = '-1' AND a.access <= '$my->gid'" | ||
| 136 : | . "\n AND ( publish_up = '0000-00-00 00:00:00' OR publish_up <= '$now' )" | ||
| 137 : | . "\n AND ( publish_down = '0000-00-00 00:00:00' OR publish_down >= '$now' )" | ||
| 138 : | . "\n ORDER BY $order" | ||
| 139 : | ); | ||
| 140 : | $list3 = $database->loadObjectList(); | ||
| 141 : | |||
| 142 : | return array_merge( $list, $list2, $list3 ); | ||
| 143 : | } | ||
| 144 : | ?> |
| ViewVC Help | |
| Powered by ViewVC 1.0.0 |
Web Hosting provided by Network Redux.

