| [ Index ] |
|
Code source de Phorum 5.1.25 |
1 <?php 2 3 //////////////////////////////////////////////////////////////////////////////// 4 // // 5 // Copyright (C) 2006 Phorum Development Team // 6 // http://www.phorum.org // 7 // // 8 // This program is free software. You can redistribute it and/or modify // 9 // it under the terms of either the current Phorum License (viewable at // 10 // phorum.org) or the Phorum License that was distributed with this file // 11 // // 12 // This program is distributed in the hope that it will be useful, // 13 // but WITHOUT ANY WARRANTY, without even the implied warranty of // 14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. // 15 // // 16 // You should have received a copy of the Phorum License // 17 // along with this program. // 18 //////////////////////////////////////////////////////////////////////////////// 19 define('phorum_page','search'); 20 21 include_once ("./common.php"); 22 23 if(!phorum_check_read_common()) { 24 return; 25 } 26 27 include_once ("./include/format_functions.php"); 28 // set all our URL's 29 phorum_build_common_urls(); 30 31 $PHORUM["DATA"]["SEARCH"]["noresults"] = false; 32 $PHORUM["DATA"]["SEARCH"]["showresults"] = false; 33 $PHORUM["DATA"]["SEARCH"]["safe_search"] = ""; 34 35 function phorum_search_check_valid_vars() { 36 $PHORUM=$GLOBALS['PHORUM']; 37 $retval=true; 38 // these are valid values for some args 39 $valid_match_types=array("ALL","ANY","PHRASE","AUTHOR"); 40 $valid_match_forum=array("THISONE","ALL"); 41 42 if(!in_array($PHORUM["args"]["match_type"],$valid_match_types)) { 43 $retval=false; 44 } elseif(!in_array($PHORUM["args"]["match_forum"],$valid_match_forum)) { 45 $retval=false; 46 } elseif(!is_numeric($PHORUM["args"]["match_dates"])) { 47 $retval=false; 48 } 49 50 return $retval; 51 } 52 53 54 55 56 if(!empty($_GET["search"]) && !isset($PHORUM["args"]["page"])){ 57 $search_url = @phorum_get_url(PHORUM_SEARCH_URL, "search=" . urlencode($_GET["search"]), "page=1", "match_type=" . urlencode($_GET['match_type']), "match_dates=" . urlencode($_GET['match_dates']), "match_forum=" . urlencode($_GET['match_forum'])); 58 $PHORUM["DATA"]["MESSAGE"]=$PHORUM["DATA"]["LANG"]["SearchRunning"]; 59 $PHORUM["DATA"]["BACKMSG"]=$PHORUM["DATA"]["LANG"]["BackToSearch"]; 60 $PHORUM["DATA"]["URL"]["REDIRECT"]=$search_url; 61 $PHORUM["DATA"]["REDIRECT_TIME"]=1; 62 include phorum_get_template("header"); 63 phorum_hook("after_header"); 64 include phorum_get_template("message"); 65 phorum_hook("before_footer"); 66 include phorum_get_template("footer"); 67 return; 68 } 69 70 if(isset($PHORUM["args"]["search"])){ 71 $phorum_search = $PHORUM["args"]["search"]; 72 } 73 74 if(!isset($PHORUM["args"]["match_type"])) $PHORUM["args"]["match_type"]="ALL"; 75 if(!isset($PHORUM["args"]["match_dates"])) $PHORUM["args"]["match_dates"]="30"; 76 if(!isset($PHORUM["args"]["match_forum"])) $PHORUM["args"]["match_forum"]="ALL"; 77 78 if(!phorum_search_check_valid_vars()) { 79 $redir_url=phorum_get_url(PHORUM_LIST_URL); 80 phorum_redirect_by_url($redir_url); 81 } 82 83 // setup some stuff based on the url passed 84 if(!empty($phorum_search)){ 85 86 $PHORUM["DATA"]["SEARCH"]["safe_search"] = htmlspecialchars($phorum_search); 87 88 include_once ("./include/format_functions.php"); 89 90 $PHORUM["args"]["page"] = (int)$PHORUM["args"]["page"]; 91 92 $offset = (empty($PHORUM["args"]["page"])) ? 0 : $PHORUM["args"]["page"]-1; 93 94 if($offset < 0) 95 $offset = 0; 96 97 if(empty($PHORUM["list_length"])) $PHORUM["list_length"]=30; 98 99 $start = ($offset * $PHORUM["list_length"]); 100 101 settype($PHORUM["args"]["match_dates"], "int"); 102 103 // setup the needed data for an alternate search backend 104 // needs to get fed by posted messages 105 $search_request_data = array( 106 'search' => $phorum_search, 107 'offset' => $start, 108 'length' => $PHORUM["list_length"], 109 'match_type' => $PHORUM["args"]["match_type"], 110 'match_dates' => $PHORUM["args"]["match_dates"], 111 'match_forum' => $PHORUM["args"]["match_forum"], 112 'results' => array(), 113 'raw_body' => 0, 114 'totals' => 0, 115 'continue' => 1 116 ); 117 118 $search_request_data = phorum_hook('search_action',$search_request_data); 119 120 // only continue if our hook was either not run or didn't return a stop request 121 if($search_request_data['continue']) { 122 $arr = phorum_db_search($phorum_search, $offset, $PHORUM["list_length"], $PHORUM["args"]["match_type"], $PHORUM["args"]["match_dates"], $PHORUM["args"]["match_forum"]); 123 $raw_body = 0; 124 } else { 125 $arr['rows'] = $search_request_data['results']; 126 $arr['count']= $search_request_data['totals']; 127 $raw_body = $search_request_data['raw_body']; 128 } 129 130 if(count($arr["rows"])){ 131 132 $match_number = $start + 1; 133 134 $forums = phorum_db_get_forums(0, -1, $PHORUM["vroot"]); 135 136 // For announcements, we will put the current forum_id in the record. 137 // Else the message cannot be read (Phorum will redirect the user 138 // back to the index page if the forum id is zero). If the user came 139 // from the index page, no forum id will be set. In that case we 140 // use the first available forum id. 141 if ($PHORUM["forum_id"]) { 142 $announcement_forum_id = $PHORUM["forum_id"]; 143 } elseif (count($forums)) { 144 list ($f_id, $_data) = each($forums); 145 $announcement_forum_id = $f_id; 146 } else { 147 // No forums and still search results? Should not happen of course. 148 $announcement_forum_id = 0; 149 } 150 151 foreach($arr["rows"] as $key => $row){ 152 $arr["rows"][$key]["number"] = $match_number; 153 154 // Fake forum_id for folders (announcements can be linked to them). 155 if ($row["forum_id"] == 0 || $forums[$row["forum_id"]]["folder_flag"]) { 156 $row["forum_id"] = $announcement_forum_id; 157 } 158 159 $arr["rows"][$key]["url"] = phorum_get_url(PHORUM_FOREIGN_READ_URL, $row["forum_id"], $row["thread"], $row["message_id"]); 160 161 // strip HTML & BB Code 162 if(!$raw_body) { 163 $body = phorum_strip_body($arr["rows"][$key]["body"]); 164 $arr["rows"][$key]["short_body"] = substr($body, 0, 200); 165 $arr["rows"][$key]["short_body"] = htmlspecialchars($arr["rows"][$key]["short_body"]); 166 } 167 $arr["rows"][$key]["datestamp"] = phorum_date($PHORUM["short_date"], $row["datestamp"]); 168 $arr["rows"][$key]["author"] = htmlspecialchars($row["author"]); 169 170 $forum_ids[$row["forum_id"]] = $row["forum_id"]; 171 172 $match_number++; 173 } 174 175 foreach($arr["rows"] as $key => $row){ 176 // Skip folders (announcements can be linked to them). 177 if ($row["forum_id"] == 0 || $forums[$row["forum_id"]]["folder_flag"]) continue; 178 179 $arr["rows"][$key]["forum_url"] = phorum_get_url(PHORUM_LIST_URL, $row["forum_id"]); 180 181 $arr["rows"][$key]["forum_name"] = $forums[$row["forum_id"]]["name"]; 182 } 183 184 $PHORUM["DATA"]["RANGE_START"] = $start + 1; 185 $PHORUM["DATA"]["RANGE_END"] = $start + count($arr["rows"]); 186 $PHORUM["DATA"]["TOTAL"] = $arr["count"]; 187 $PHORUM["DATA"]["SEARCH"]["showresults"] = true; 188 // figure out paging 189 $pages = ceil($arr["count"] / $PHORUM["list_length"]); 190 $page = $offset + 1; 191 192 if ($pages <= 5){ 193 $page_start = 1; 194 }elseif ($pages - $page < 2){ 195 $page_start = $pages-4; 196 }elseif ($pages > 5 && $page > 3){ 197 $page_start = $page-2; 198 }else{ 199 $page_start = 1; 200 } 201 202 $pageno = 1; 203 for($x = 0;$x < 5 && $x < $pages;$x++){ 204 $pageno = $x + $page_start; 205 $PHORUM["DATA"]["PAGES"][] = array("pageno" => $pageno, 206 "url" => phorum_get_url(PHORUM_SEARCH_URL, "search=" . urlencode($phorum_search), "page=$pageno", "match_type={$PHORUM['args']['match_type']}", "match_dates={$PHORUM['args']['match_dates']}", "match_forum={$PHORUM['args']['match_forum']}") 207 ); 208 } 209 210 $PHORUM["DATA"]["CURRENTPAGE"] = $page; 211 $PHORUM["DATA"]["TOTALPAGES"] = $pages; 212 213 if ($page_start > 1){ 214 $PHORUM["DATA"]["URL"]["FIRSTPAGE"] = phorum_get_url(PHORUM_SEARCH_URL, "search=" . urlencode($phorum_search), "page=1", "match_type={$PHORUM['args']['match_type']}", "match_dates={$PHORUM['args']['match_dates']}", "match_forum={$PHORUM['args']['match_forum']}"); 215 } 216 217 if ($pageno < $pages){ 218 $PHORUM["DATA"]["URL"]["LASTPAGE"] = phorum_get_url(PHORUM_SEARCH_URL, "search=" . urlencode($phorum_search), "page=$pages", "match_type={$PHORUM['args']['match_type']}", "match_dates={$PHORUM['args']['match_dates']}", "match_forum={$PHORUM['args']['match_forum']}"); 219 } 220 221 if ($pages > $page){ 222 $nextpage = $page + 1; 223 $PHORUM["DATA"]["URL"]["NEXTPAGE"] = phorum_get_url(PHORUM_SEARCH_URL, "search=" . urlencode($phorum_search), "page=$nextpage", "match_type={$PHORUM['args']['match_type']}", "match_dates={$PHORUM['args']['match_dates']}", "match_forum={$PHORUM['args']['match_forum']}"); 224 } 225 if ($page > 1){ 226 $prevpage = $page-1; 227 $PHORUM["DATA"]["URL"]["PREVPAGE"] = phorum_get_url(PHORUM_SEARCH_URL, "search=" . urlencode($phorum_search), "page=$prevpage", "match_type={$PHORUM['args']['match_type']}", "match_dates={$PHORUM['args']['match_dates']}", "match_forum={$PHORUM['args']['match_forum']}"); 228 } 229 230 231 232 $arr["rows"] = phorum_hook("search", $arr["rows"]); 233 $arr["rows"] = phorum_format_messages($arr["rows"]); 234 $PHORUM["DATA"]["MATCHES"] = $arr["rows"]; 235 236 }else{ 237 $PHORUM["DATA"]["SEARCH"]["noresults"] = true; 238 $PHORUM["DATA"]["FOCUS_TO_ID"] = 'phorum_search_message'; 239 } 240 } else { 241 // Set cursor focus to message search entry. 242 $PHORUM["DATA"]["FOCUS_TO_ID"] = 'phorum_search_message'; 243 } 244 245 $PHORUM["DATA"]["URL"]["ACTION"] = phorum_get_url(PHORUM_SEARCH_ACTION_URL); 246 $PHORUM["DATA"]["SEARCH"]["forum_id"] = $PHORUM["forum_id"]; 247 $PHORUM["DATA"]["SEARCH"]["match_type"] = $PHORUM["args"]["match_type"]; 248 $PHORUM["DATA"]["SEARCH"]["match_dates"] = $PHORUM["args"]["match_dates"]; 249 $PHORUM["DATA"]["SEARCH"]["match_forum"] = $PHORUM["args"]["match_forum"]; 250 $PHORUM["DATA"]["SEARCH"]["allow_match_one_forum"] = $PHORUM["forum_id"]; 251 252 include phorum_get_template("header"); 253 phorum_hook("after_header"); 254 include phorum_get_template("search"); 255 phorum_hook("before_footer"); 256 include phorum_get_template("footer"); 257 258 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
| Généré le : Thu Nov 29 12:22:27 2007 | par Balluche grâce à PHPXref 0.7 |
|