| [ Index ] |
PHP Cross Reference of Xoops v2.3.1 |
|
[Global whois Lookup] [Ranchi, Jharkhand, India website] [Hindi Magazine] [Desi Community website in tristate area] [B 4 Bollywood] [Internet nation of India] |
|
[Summary view] [Print] [Text view]
1 <?php 2 /* 3 You may not change or alter any portion of this comment or credits 4 of supporting developers from this source code or any supporting source code 5 which is considered copyrighted (c) material of the original comment or credit authors. 6 7 This program is distributed in the hope that it will be useful, 8 but WITHOUT ANY WARRANTY; without even the implied warranty of 9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 10 */ 11 12 /** 13 * XOOPS global search 14 * 15 * @copyright The XOOPS Project http://sourceforge.net/projects/xoops/ 16 * @license http://www.fsf.org/copyleft/gpl.html GNU public license 17 * @package kernel 18 * @since 2.0.0 19 * @author Kazumi Ono (AKA onokazu) 20 * @author Taiwen Jiang <phppp@users.sourceforge.net> 21 * @version $Id: search.php 1529 2008-05-01 08:14:55Z phppp $ 22 * @package core 23 * @todo Modularize; Both search algorithms and interface will be redesigned 24 */ 25 26 $xoopsOption['pagetype'] = "search"; 27 28 include 'mainfile.php'; 29 $config_handler =& xoops_gethandler('config'); 30 $xoopsConfigSearch = $config_handler->getConfigsByCat(XOOPS_CONF_SEARCH); 31 32 if ($xoopsConfigSearch['enable_search'] != 1) { 33 header('Location: '.XOOPS_URL.'/index.php'); 34 exit(); 35 } 36 $action = "search"; 37 if (!empty($_GET['action'])) { 38 $action = $_GET['action']; 39 } elseif (!empty($_POST['action'])) { 40 $action = $_POST['action']; 41 } 42 $query = ""; 43 if (!empty($_GET['query'])) { 44 $query = $_GET['query']; 45 } elseif (!empty($_POST['query'])) { 46 $query = $_POST['query']; 47 } 48 $andor = "AND"; 49 if (!empty($_GET['andor'])) { 50 $andor = $_GET['andor']; 51 } elseif (!empty($_POST['andor'])) { 52 $andor = $_POST['andor']; 53 } 54 $mid = $uid = $start = 0; 55 if ( !empty($_GET['mid']) ) { 56 $mid = intval($_GET['mid']); 57 } elseif ( !empty($_POST['mid']) ) { 58 $mid = intval($_POST['mid']); 59 } 60 if (!empty($_GET['uid'])) { 61 $uid = intval($_GET['uid']); 62 } elseif (!empty($_POST['uid'])) { 63 $uid = intval($_POST['uid']); 64 } 65 if (!empty($_GET['start'])) { 66 $start = intval($_GET['start']); 67 } elseif (!empty($_POST['start'])) { 68 $start = intval($_POST['start']); 69 } 70 71 $queries = array(); 72 73 if ($action == "results") { 74 if ($query == "") { 75 redirect_header("search.php", 1, _SR_PLZENTER); 76 exit(); 77 } 78 } elseif ($action == "showall") { 79 if ($query == "" || empty($mid)) { 80 redirect_header("search.php", 1, _SR_PLZENTER); 81 exit(); 82 } 83 } elseif ($action == "showallbyuser") { 84 if (empty($mid) || empty($uid)) { 85 redirect_header("search.php", 1, _SR_PLZENTER); 86 exit(); 87 } 88 } 89 90 $groups = is_object($xoopsUser) ? $xoopsUser -> getGroups() : XOOPS_GROUP_ANONYMOUS; 91 $gperm_handler = & xoops_gethandler( 'groupperm' ); 92 $available_modules = $gperm_handler->getItemIds('module_read', $groups); 93 94 if ($action == 'search') { 95 include XOOPS_ROOT_PATH.'/header.php'; 96 include 'include/searchform.php'; 97 $search_form->display(); 98 include XOOPS_ROOT_PATH.'/footer.php'; 99 exit(); 100 } 101 102 if ( $andor != "OR" && $andor != "exact" && $andor != "AND" ) { 103 $andor = "AND"; 104 } 105 106 $myts =& MyTextSanitizer::getInstance(); 107 if ($action != 'showallbyuser') { 108 if ( $andor != "exact" ) { 109 $ignored_queries = array(); // holds kewords that are shorter than allowed minmum length 110 $temp_queries = preg_split('/[\s,]+/', $query); 111 foreach ($temp_queries as $q) { 112 $q = trim($q); 113 if (strlen($q) >= $xoopsConfigSearch['keyword_min']) { 114 $queries[] = $myts->addSlashes($q); 115 } else { 116 $ignored_queries[] = $myts->addSlashes($q); 117 } 118 } 119 if (count($queries) == 0) { 120 redirect_header('search.php', 2, sprintf(_SR_KEYTOOSHORT, $xoopsConfigSearch['keyword_min'])); 121 exit(); 122 } 123 } else { 124 $query = trim($query); 125 if (strlen($query) < $xoopsConfigSearch['keyword_min']) { 126 redirect_header('search.php', 2, sprintf(_SR_KEYTOOSHORT, $xoopsConfigSearch['keyword_min'])); 127 exit(); 128 } 129 $queries = array($myts->addSlashes($query)); 130 } 131 } 132 switch ($action) { 133 case "results": 134 $module_handler =& xoops_gethandler('module'); 135 $criteria = new CriteriaCompo(new Criteria('hassearch', 1)); 136 $criteria->add(new Criteria('isactive', 1)); 137 $criteria->add(new Criteria('mid', "(".implode(',', $available_modules).")", 'IN')); 138 $modules = $module_handler->getObjects($criteria, true); 139 $mids = isset($_REQUEST['mids']) ? $_REQUEST['mids'] : array(); 140 if (empty($mids) || !is_array($mids)) { 141 unset($mids); 142 $mids = array_keys($modules); 143 } 144 include XOOPS_ROOT_PATH."/header.php"; 145 $nomatch = true; 146 echo "<h3>"._SR_SEARCHRESULTS."</h3>\n"; 147 echo _SR_KEYWORDS.':'; 148 if ($andor != 'exact') { 149 foreach ($queries as $q) { 150 echo ' <strong>'.htmlspecialchars(stripslashes($q)).'</strong>'; 151 } 152 if (!empty($ignored_queries)) { 153 echo '<br />'; 154 printf(_SR_IGNOREDWORDS, $xoopsConfigSearch['keyword_min']); 155 foreach ($ignored_queries as $q) { 156 echo ' <strong>'.htmlspecialchars(stripslashes($q)).'</strong>'; 157 } 158 } 159 } else { 160 echo ' "<strong>'.htmlspecialchars(stripslashes($queries[0])).'</strong>"'; 161 } 162 echo '<br />'; 163 foreach ($mids as $mid) { 164 $mid = intval($mid); 165 if ( in_array($mid, $available_modules) ) { 166 $module = $modules[$mid]; 167 $results = $module->search($queries, $andor, 5, 0); 168 $count = count($results); 169 if (is_array($results) && $count > 0) { 170 $nomatch = false; 171 echo "<h4>".$module->getVar('name')."</h4>"; 172 for ($i = 0; $i < $count; $i++) { 173 if (isset($results[$i]['image']) && $results[$i]['image'] != "") { 174 echo "<img src='modules/".$module->getVar('dirname')."/".$results[$i]['image']."' alt='" . $module->getVar('name') . "' /> "; 175 } else { 176 echo "<img src='images/icons/posticon2.gif' alt='" . $module->getVar('name') . "' width='26' height='26' /> "; 177 } 178 if (!preg_match("/^http[s]*:\/\//i", $results[$i]['link'])) { 179 $results[$i]['link'] = "modules/".$module->getVar('dirname')."/".$results[$i]['link']; 180 } 181 echo "<strong><a href='".$results[$i]['link']."'>" . $myts->htmlspecialchars($results[$i]['title']) . "</a></strong><br />\n"; 182 echo "<small>"; 183 $results[$i]['uid'] = @intval($results[$i]['uid']); 184 if ( !empty($results[$i]['uid']) ) { 185 $uname = XoopsUser::getUnameFromId($results[$i]['uid']); 186 echo " <a href='".XOOPS_URL."/userinfo.php?uid=".$results[$i]['uid']."'>".$uname."</a>\n"; 187 } 188 echo !empty($results[$i]['time']) ? " (". formatTimestamp(intval($results[$i]['time'])).")" : ""; 189 echo "</small><br />\n"; 190 } 191 if ( $count >= 5 ) { 192 $search_url = XOOPS_URL.'/search.php?query='.urlencode(stripslashes(implode(' ', $queries))); 193 $search_url .= "&mid=$mid&action=showall&andor=$andor"; 194 echo '<p><a href="'.htmlspecialchars($search_url).'" title="' . _SR_SHOWALLR . '">' . _SR_SHOWALLR . '</a></p>'; 195 } 196 } 197 } 198 unset($results); 199 unset($module); 200 } 201 if ($nomatch) { 202 echo "<p>"._SR_NOMATCH."</p>"; 203 } 204 include "include/searchform.php"; 205 $search_form->display(); 206 break; 207 208 case "showall": 209 case 'showallbyuser': 210 include XOOPS_ROOT_PATH."/header.php"; 211 $module_handler =& xoops_gethandler('module'); 212 $module =& $module_handler->get($mid); 213 $results = $module->search($queries, $andor, 20, $start, $uid); 214 $count = count($results); 215 if (is_array($results) && $count > 0) { 216 $next_results =& $module->search($queries, $andor, 1, $start + 20, $uid); 217 $next_count = count($next_results); 218 $has_next = false; 219 if (is_array($next_results) && $next_count == 1) { 220 $has_next = true; 221 } 222 echo "<h4>"._SR_SEARCHRESULTS."</h4>\n"; 223 if ($action == 'showall') { 224 echo _SR_KEYWORDS.':'; 225 if ($andor != 'exact') { 226 foreach ($queries as $q) { 227 echo ' <strong>'.htmlspecialchars(stripslashes($q)).'</strong>'; 228 } 229 } else { 230 echo ' "<strong>'.htmlspecialchars(stripslashes($queries[0])).'</strong>"'; 231 } 232 echo '<br />'; 233 } 234 printf(_SR_SHOWING, $start + 1, $start + $count); 235 echo "<h5>" . $module->getVar('name') . "</h5>"; 236 for ($i = 0; $i < $count; $i++) { 237 if (isset($results[$i]['image']) && $results[$i]['image'] != '') { 238 echo "<img src='modules/" . $module->getVar('dirname', "n") . "/".$results[$i]['image']."' alt='" . $module->getVar('name') . "' /> "; 239 } else { 240 echo "<img src='images/icons/posticon2.gif' alt='" . $module->getVar("name") . "' width='26' height='26' /> "; 241 } 242 if (!preg_match("/^http[s]*:\/\//i", $results[$i]['link'])) { 243 $results[$i]['link'] = "modules/".$module->getVar('dirname')."/".$results[$i]['link']; 244 } 245 echo "<strong><a href='".$results[$i]['link']."'>".$myts->htmlspecialchars($results[$i]['title'])."</a></strong><br />\n"; 246 echo "<small>"; 247 $results[$i]['uid'] = @intval($results[$i]['uid']); 248 if ( !empty($results[$i]['uid']) ) { 249 $uname = XoopsUser::getUnameFromId($results[$i]['uid']); 250 echo " <a href='".XOOPS_URL."/userinfo.php?uid=".$results[$i]['uid']."'>".$uname."</a>\n"; 251 } 252 echo !empty($results[$i]['time']) ? " (". formatTimestamp(intval($results[$i]['time'])).")" : ""; 253 echo "</small><br />\n"; 254 } 255 echo ' 256 <table> 257 <tr> 258 '; 259 $search_url = XOOPS_URL.'/search.php?query='.urlencode(stripslashes(implode(' ', $queries))); 260 $search_url .= "&mid=$mid&action=$action&andor=$andor"; 261 if ($action=='showallbyuser') { 262 $search_url .= "&uid=$uid"; 263 } 264 if ( $start > 0 ) { 265 $prev = $start - 20; 266 echo '<td align="left"> 267 '; 268 $search_url_prev = $search_url."&start=$prev"; 269 echo '<a href="'.htmlspecialchars($search_url_prev).'">'._SR_PREVIOUS.'</a></td> 270 '; 271 } 272 echo '<td> </td> 273 '; 274 if (false != $has_next) { 275 $next = $start + 20; 276 $search_url_next = $search_url."&start=$next"; 277 echo '<td align="right"><a href="'.htmlspecialchars($search_url_next).'">'._SR_NEXT.'</a></td> 278 '; 279 } 280 echo ' 281 </tr> 282 </table> 283 '; 284 } else { 285 echo '<p>'._SR_NOMATCH.'</p>'; 286 } 287 include "include/searchform.php"; 288 $search_form->display(); 289 break; 290 } 291 include XOOPS_ROOT_PATH."/footer.php"; 292 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
|
[ Xoops] [PhpNuke] [PostNuke] [Joomla] [Drupal] [E107] [NucleusCms] |
|||
|
[Php-Fusion] [PhpBB] [WordPress] [Typo3] |
|||
| Generated: Mon Oct 27 11:51:45 2008 | |||