[ Index ] |
|
Code source de XOOPS 2.0.17.1 |
1 <?php 2 // $Id: search.php 506 2006-05-26 23:10:37Z skalpa $ 3 // ------------------------------------------------------------------------ // 4 // XOOPS - PHP Content Management System // 5 // Copyright (c) 2000 XOOPS.org // 6 // <http://www.xoops.org/> // 7 // ------------------------------------------------------------------------ // 8 // This program is free software; you can redistribute it and/or modify // 9 // it under the terms of the GNU General Public License as published by // 10 // the Free Software Foundation; either version 2 of the License, or // 11 // (at your option) any later version. // 12 // // 13 // You may not change or alter any portion of this comment or credits // 14 // of supporting developers from this source code or any supporting // 15 // source code which is considered copyrighted (c) material of the // 16 // original comment or credit authors. // 17 // // 18 // This program is distributed in the hope that it will be useful, // 19 // but WITHOUT ANY WARRANTY; without even the implied warranty of // 20 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // 21 // GNU General Public License for more details. // 22 // // 23 // You should have received a copy of the GNU General Public License // 24 // along with this program; if not, write to the Free Software // 25 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // 26 // ------------------------------------------------------------------------ // 27 28 $xoopsOption['pagetype'] = "search"; 29 30 include 'mainfile.php'; 31 $config_handler =& xoops_gethandler('config'); 32 $xoopsConfigSearch =& $config_handler->getConfigsByCat(XOOPS_CONF_SEARCH); 33 34 if ($xoopsConfigSearch['enable_search'] != 1) { 35 header('Location: '.XOOPS_URL.'/index.php'); 36 exit(); 37 } 38 $action = "search"; 39 if (!empty($_GET['action'])) { 40 $action = $_GET['action']; 41 } elseif (!empty($_POST['action'])) { 42 $action = $_POST['action']; 43 } 44 $query = ""; 45 if (!empty($_GET['query'])) { 46 $query = $_GET['query']; 47 } elseif (!empty($_POST['query'])) { 48 $query = $_POST['query']; 49 } 50 $andor = "AND"; 51 if (!empty($_GET['andor'])) { 52 $andor = $_GET['andor']; 53 } elseif (!empty($_POST['andor'])) { 54 $andor = $_POST['andor']; 55 } 56 $mid = $uid = $start = 0; 57 if ( !empty($_GET['mid']) ) { 58 $mid = intval($_GET['mid']); 59 } elseif ( !empty($_POST['mid']) ) { 60 $mid = intval($_POST['mid']); 61 } 62 if (!empty($_GET['uid'])) { 63 $uid = intval($_GET['uid']); 64 } elseif (!empty($_POST['uid'])) { 65 $uid = intval($_POST['uid']); 66 } 67 if (!empty($_GET['start'])) { 68 $start = intval($_GET['start']); 69 } elseif (!empty($_POST['start'])) { 70 $start = intval($_POST['start']); 71 } 72 73 $queries = array(); 74 75 if ($action == "results") { 76 if ($query == "") { 77 redirect_header("search.php",1,_SR_PLZENTER); 78 exit(); 79 } 80 } elseif ($action == "showall") { 81 if ($query == "" || empty($mid)) { 82 redirect_header("search.php",1,_SR_PLZENTER); 83 exit(); 84 } 85 } elseif ($action == "showallbyuser") { 86 if (empty($mid) || empty($uid)) { 87 redirect_header("search.php",1,_SR_PLZENTER); 88 exit(); 89 } 90 } 91 92 $groups = is_object($xoopsUser) ? $xoopsUser -> getGroups() : XOOPS_GROUP_ANONYMOUS; 93 $gperm_handler = & xoops_gethandler( 'groupperm' ); 94 $available_modules = $gperm_handler->getItemIds('module_read', $groups); 95 96 if ($action == 'search') { 97 include XOOPS_ROOT_PATH.'/header.php'; 98 include 'include/searchform.php'; 99 $search_form->display(); 100 include XOOPS_ROOT_PATH.'/footer.php'; 101 exit(); 102 } 103 104 if ( $andor != "OR" && $andor != "exact" && $andor != "AND" ) { 105 $andor = "AND"; 106 } 107 108 $myts =& MyTextSanitizer::getInstance(); 109 if ($action != 'showallbyuser') { 110 if ( $andor != "exact" ) { 111 $ignored_queries = array(); // holds kewords that are shorter than allowed minmum length 112 $temp_queries = preg_split('/[\s,]+/', $query); 113 foreach ($temp_queries as $q) { 114 $q = trim($q); 115 if (strlen($q) >= $xoopsConfigSearch['keyword_min']) { 116 $queries[] = $myts->addSlashes($q); 117 } else { 118 $ignored_queries[] = $myts->addSlashes($q); 119 } 120 } 121 if (count($queries) == 0) { 122 redirect_header('search.php', 2, sprintf(_SR_KEYTOOSHORT, $xoopsConfigSearch['keyword_min'])); 123 exit(); 124 } 125 } else { 126 $query = trim($query); 127 if (strlen($query) < $xoopsConfigSearch['keyword_min']) { 128 redirect_header('search.php', 2, sprintf(_SR_KEYTOOSHORT, $xoopsConfigSearch['keyword_min'])); 129 exit(); 130 } 131 $queries = array($myts->addSlashes($query)); 132 } 133 } 134 switch ($action) { 135 case "results": 136 $module_handler =& xoops_gethandler('module'); 137 $criteria = new CriteriaCompo(new Criteria('hassearch', 1)); 138 $criteria->add(new Criteria('isactive', 1)); 139 $criteria->add(new Criteria('mid', "(".implode(',', $available_modules).")", 'IN')); 140 $modules =& $module_handler->getObjects($criteria, true); 141 $mids = isset($_REQUEST['mids']) ? $_REQUEST['mids'] : array(); 142 if (empty($mids) || !is_array($mids)) { 143 unset($mids); 144 $mids = array_keys($modules); 145 } 146 include XOOPS_ROOT_PATH."/header.php"; 147 echo "<h3>"._SR_SEARCHRESULTS."</h3>\n"; 148 echo _SR_KEYWORDS.':'; 149 if ($andor != 'exact') { 150 foreach ($queries as $q) { 151 echo ' <b>'.htmlspecialchars(stripslashes($q)).'</b>'; 152 } 153 if (!empty($ignored_queries)) { 154 echo '<br />'; 155 printf(_SR_IGNOREDWORDS, $xoopsConfigSearch['keyword_min']); 156 foreach ($ignored_queries as $q) { 157 echo ' <b>'.htmlspecialchars(stripslashes($q)).'</b>'; 158 } 159 } 160 } else { 161 echo ' "<b>'.htmlspecialchars(stripslashes($queries[0])).'</b>"'; 162 } 163 echo '<br />'; 164 foreach ($mids as $mid) { 165 $mid = intval($mid); 166 if ( in_array($mid, $available_modules) ) { 167 $module =& $modules[$mid]; 168 $results =& $module->search($queries, $andor, 5, 0); 169 echo "<h4>".$myts->makeTboxData4Show($module->getVar('name'))."</h4>"; 170 $count = count($results); 171 if (!is_array($results) || $count == 0) { 172 echo "<p>"._SR_NOMATCH."</p>"; 173 } else { 174 for ($i = 0; $i < $count; $i++) { 175 if (isset($results[$i]['image']) && $results[$i]['image'] != "") { 176 echo "<img src='modules/".$module->getVar('dirname')."/".$results[$i]['image']."' alt='".$myts->makeTboxData4Show($module->getVar('name'))."' /> "; 177 } else { 178 echo "<img src='images/icons/posticon2.gif' alt='".$myts->makeTboxData4Show($module->getVar('name'))."' width='26' height='26' /> "; 179 } 180 if (!preg_match("/^http[s]*:\/\//i", $results[$i]['link'])) { 181 $results[$i]['link'] = "modules/".$module->getVar('dirname')."/".$results[$i]['link']; 182 } 183 echo "<b><a href='".$results[$i]['link']."'>".$myts->makeTboxData4Show($results[$i]['title'])."</a></b><br />\n"; 184 echo "<small>"; 185 $results[$i]['uid'] = @intval($results[$i]['uid']); 186 if ( !empty($results[$i]['uid']) ) { 187 $uname = XoopsUser::getUnameFromId($results[$i]['uid']); 188 echo " <a href='".XOOPS_URL."/userinfo.php?uid=".$results[$i]['uid']."'>".$uname."</a>\n"; 189 } 190 echo !empty($results[$i]['time']) ? " (". formatTimestamp(intval($results[$i]['time'])).")" : ""; 191 echo "</small><br />\n"; 192 } 193 if ( $count >= 5 ) { 194 $search_url = XOOPS_URL.'/search.php?query='.urlencode(stripslashes(implode(' ', $queries))); 195 $search_url .= "&mid=$mid&action=showall&andor=$andor"; 196 echo '<br /><a href="'.htmlspecialchars($search_url).'">'._SR_SHOWALLR.'</a></p>'; 197 } 198 } 199 } 200 unset($results); 201 unset($module); 202 } 203 include "include/searchform.php"; 204 $search_form->display(); 205 break; 206 case "showall": 207 case 'showallbyuser': 208 include XOOPS_ROOT_PATH."/header.php"; 209 $module_handler =& xoops_gethandler('module'); 210 $module =& $module_handler->get($mid); 211 $results =& $module->search($queries, $andor, 20, $start, $uid); 212 $count = count($results); 213 if (is_array($results) && $count > 0) { 214 $next_results =& $module->search($queries, $andor, 1, $start + 20, $uid); 215 $next_count = count($next_results); 216 $has_next = false; 217 if (is_array($next_results) && $next_count == 1) { 218 $has_next = true; 219 } 220 echo "<h4>"._SR_SEARCHRESULTS."</h4>\n"; 221 if ($action == 'showall') { 222 echo _SR_KEYWORDS.':'; 223 if ($andor != 'exact') { 224 foreach ($queries as $q) { 225 echo ' <b>'.htmlspecialchars(stripslashes($q)).'</b>'; 226 } 227 } else { 228 echo ' "<b>'.htmlspecialchars(stripslashes($queries[0])).'</b>"'; 229 } 230 echo '<br />'; 231 } 232 // printf(_SR_FOUND,$count); 233 // echo "<br />"; 234 printf(_SR_SHOWING, $start+1, $start + $count); 235 echo "<h5>".$myts->makeTboxData4Show($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')."/".$results[$i]['image']."' alt='".$myts->makeTboxData4Show($module->getVar('name'))."' /> "; 239 } else { 240 echo "<img src='images/icons/posticon2.gif' alt='".$myts->makeTboxData4Show($module->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 "<b><a href='".$results[$i]['link']."'>".$myts->makeTboxData4Show($results[$i]['title'])."</a></b><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 <p> 284 '; 285 } else { 286 echo '<p>'._SR_NOMATCH.'</p>'; 287 } 288 include "include/searchform.php"; 289 $search_form->display(); 290 echo '</p> 291 '; 292 break; 293 } 294 include XOOPS_ROOT_PATH."/footer.php"; 295 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Nov 25 11:44:32 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |