Subversion Repositories Applications.papyrus

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
831 florian 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
    $offset = (empty($PHORUM["args"]["page"])) ? 0 : $PHORUM["args"]["page"]-1;
91
 
92
    if(empty($PHORUM["list_length"])) $PHORUM["list_length"]=30;
93
 
94
    $start = ($offset * $PHORUM["list_length"]);
95
 
96
    settype($PHORUM["args"]["match_dates"], "int");
97
 
98
    $arr = phorum_db_search($phorum_search, $offset, $PHORUM["list_length"], $PHORUM["args"]["match_type"], $PHORUM["args"]["match_dates"], $PHORUM["args"]["match_forum"]);
99
 
100
    if(count($arr["rows"])){
101
 
102
        $match_number = $start + 1;
103
 
104
        $forums = phorum_db_get_forums();
105
 
106
        // For announcements, we will put the current forum_id in the record.
107
        // Else the message cannot be read (Phorum will redirect the user
108
        // back to the index page if the forum id is zero). If the user came
109
        // from the index page, no forum id will be set. In that case we
110
        // use the first available forum id.
111
        $announcement_forum_id = 0;
112
        if ($PHORUM["forum_id"]) {
113
            $announcement_forum_id = $PHORUM["forum_id"];
114
        } elseif (count($forums)) {
115
            list ($f_id, $_data) = each($forums);
116
            $announcement_forum_id = $f_id;
117
        }
118
 
119
        foreach($arr["rows"] as $key => $row){
120
            $arr["rows"][$key]["number"] = $match_number;
121
 
122
            // Fake a forum_id for folders.
123
            if ($row["forum_id"] == 0) {
124
                $row["forum_id"] = $announcement_forum_id;
125
            }
126
 
127
            $arr["rows"][$key]["url"] = phorum_get_url(PHORUM_FOREIGN_READ_URL, $row["forum_id"], $row["thread"], $row["message_id"]);
128
 
129
            // strip HTML & BB Code
130
            $body = phorum_strip_body($arr["rows"][$key]["body"]);
131
            $arr["rows"][$key]["short_body"] = substr($body, 0, 200);
132
            $arr["rows"][$key]["datestamp"] = phorum_date($PHORUM["short_date"], $row["datestamp"]);
133
            $arr["rows"][$key]["author"] = htmlspecialchars($row["author"]);
134
            $arr["rows"][$key]["short_body"] = htmlspecialchars($arr["rows"][$key]["short_body"]);
135
 
136
            $forum_ids[$row["forum_id"]] = $row["forum_id"];
137
 
138
            $match_number++;
139
        }
140
 
141
        foreach($arr["rows"] as $key => $row){
142
            // Skip announcements "forum".
143
            if ($row["forum_id"] == 0) continue;
144
 
145
            $arr["rows"][$key]["forum_url"] = phorum_get_url(PHORUM_LIST_URL, $row["forum_id"]);
146
 
147
            $arr["rows"][$key]["forum_name"] = $forums[$row["forum_id"]]["name"];
148
        }
149
 
150
        $PHORUM["DATA"]["RANGE_START"] = $start + 1;
151
        $PHORUM["DATA"]["RANGE_END"] = $start + count($arr["rows"]);
152
        $PHORUM["DATA"]["TOTAL"] = $arr["count"];
153
        $PHORUM["DATA"]["SEARCH"]["showresults"] = true;
154
        // figure out paging
155
        $pages = ceil($arr["count"] / $PHORUM["list_length"]);
156
        $page = $offset + 1;
157
 
158
        if ($pages <= 5){
159
            $page_start = 1;
160
        }elseif ($pages - $page < 2){
161
            $page_start = $pages-4;
162
        }elseif ($pages > 5 && $page > 3){
163
            $page_start = $page-2;
164
        }else{
165
            $page_start = 1;
166
        }
167
 
168
        $pageno = 1;
169
        for($x = 0;$x < 5 && $x < $pages;$x++){
170
            $pageno = $x + $page_start;
171
            $PHORUM["DATA"]["PAGES"][] = array("pageno" => $pageno,
172
                "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']}")
173
                );
174
        }
175
 
176
        $PHORUM["DATA"]["CURRENTPAGE"] = $page;
177
           $PHORUM["DATA"]["TOTALPAGES"] = $pages;
178
 
179
        if ($page_start > 1){
180
            $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']}");
181
        }
182
 
183
        if ($pageno < $pages){
184
            $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']}");
185
        }
186
 
187
        if ($pages > $page){
188
            $nextpage = $page + 1;
189
            $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']}");
190
        }
191
        if ($page > 1){
192
            $prevpage = $page-1;
193
            $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']}");
194
        }
195
 
196
 
197
 
198
        $arr["rows"] = phorum_hook("search", $arr["rows"]);
199
        $arr["rows"] = phorum_format_messages($arr["rows"]);
200
        $PHORUM["DATA"]["MATCHES"] = $arr["rows"];
201
 
202
    }else{
203
        $PHORUM["DATA"]["SEARCH"]["noresults"] = true;
204
        $PHORUM["DATA"]["FOCUS_TO_ID"] = 'phorum_search_message';
205
    }
206
} else {
207
    // Set cursor focus to message search entry.
208
    $PHORUM["DATA"]["FOCUS_TO_ID"] = 'phorum_search_message';
209
}
210
 
211
$PHORUM["DATA"]["URL"]["ACTION"] = phorum_get_url(PHORUM_SEARCH_ACTION_URL);
212
$PHORUM["DATA"]["SEARCH"]["forum_id"] = $PHORUM["forum_id"];
213
$PHORUM["DATA"]["SEARCH"]["match_type"] = $PHORUM["args"]["match_type"];
214
$PHORUM["DATA"]["SEARCH"]["match_dates"] = $PHORUM["args"]["match_dates"];
215
$PHORUM["DATA"]["SEARCH"]["match_forum"] = $PHORUM["args"]["match_forum"];
216
$PHORUM["DATA"]["SEARCH"]["allow_match_one_forum"] = $PHORUM["forum_id"];
217
 
218
include phorum_get_template("header");
219
phorum_hook("after_header");
220
include phorum_get_template("search");
221
phorum_hook("before_footer");
222
include phorum_get_template("footer");
223
 
224
?>