C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\xoops\html\search.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
<?php
// $Id: search.php,v 1.17.4.2.2.6 2005/05/06 11:44:12 mithyt2 Exp $
//  ------------------------------------------------------------------------ //
//                XOOPS - PHP Content Management System                      //
//                    Copyright (c) 2000 XOOPS.org                           //
//                       <http://www.xoops.org/>                             //
//  ------------------------------------------------------------------------ //
//  This program is free software; you can redistribute it and/or modify     //
//  it under the terms of the GNU General Public License as published by     //
//  the Free Software Foundation; either version 2 of the License, or        //
//  (at your option) any later version.                                      //
//                                                                           //
//  You may not change or alter any portion of this comment or credits       //
//  of supporting developers from this source code or any supporting         //
//  source code which is considered copyrighted (c) material of the          //
//  original comment or credit authors.                                      //
//                                                                           //
//  This program is distributed in the hope that it will be useful,          //
//  but WITHOUT ANY WARRANTY; without even the implied warranty of           //
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            //
//  GNU General Public License for more details.                             //
//                                                                           //
//  You should have received a copy of the GNU General Public License        //
//  along with this program; if not, write to the Free Software              //
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA //
//  ------------------------------------------------------------------------ //

$xoopsOption['pagetype'] = "search";

include 
'mainfile.php';
$config_handler =& xoops_gethandler('config');
$xoopsConfigSearch =& $config_handler->getConfigsByCat(XOOPS_CONF_SEARCH);

if (
$xoopsConfigSearch['enable_search'] != 1) {
    
header('Location: '.XOOPS_URL.'/index.php');
    exit();
}
$action "search";
if (!empty(
$_GET['action'])) {
  
$action $_GET['action'];
} elseif (!empty(
$_POST['action'])) {
  
$action $_POST['action'];
}
$query "";
if (!empty(
$_GET['query'])) {
  
$query $_GET['query'];
} elseif (!empty(
$_POST['query'])) {
  
$query $_POST['query'];
}
$andor "AND";
if (!empty(
$_GET['andor'])) {
  
$andor $_GET['andor'];
} elseif (!empty(
$_POST['andor'])) {
  
$andor $_POST['andor'];
}
$mid $uid $start 0;
if ( !empty(
$_GET['mid']) ) {
  
$mid intval($_GET['mid']);
} elseif ( !empty(
$_POST['mid']) ) {
  
$mid intval($_POST['mid']);
}
if (!empty(
$_GET['uid'])) {
  
$uid intval($_GET['uid']);
} elseif (!empty(
$_POST['uid'])) {
  
$uid intval($_POST['uid']);
}
if (!empty(
$_GET['start'])) {
  
$start intval($_GET['start']);
} elseif (!empty(
$_POST['start'])) {
  
$start intval($_POST['start']);
}

$queries = array();

if (
$action == "results") {
    if (
$query == "") {
         
redirect_header("search.php",1,_SR_PLZENTER);
        exit();
    }
} elseif (
$action == "showall") {
    if (
$query == "" || empty($mid)) {
        
redirect_header("search.php",1,_SR_PLZENTER);
        exit();
    }
} elseif (
$action == "showallbyuser") {
    if (empty(
$mid) || empty($uid)) {
        
redirect_header("search.php",1,_SR_PLZENTER);
        exit();
    }
}

$groups = ( $xoopsUser ) ? $xoopsUser -> getGroups() : XOOPS_GROUP_ANONYMOUS;
$gperm_handler = & xoops_gethandler'groupperm' );
$available_modules $gperm_handler->getItemIds('module_read'$groups);

if (
$action == 'search') {
    include 
XOOPS_ROOT_PATH.'/header.php';
    include 
'include/searchform.php';
    
$search_form->display();
    include 
XOOPS_ROOT_PATH.'/footer.php';
    exit();
}

if ( 
$andor != "OR" && $andor != "exact" && $andor != "AND" ) {
    
$andor "AND";
}

$myts =& MyTextSanitizer::getInstance();
if (
$action != 'showallbyuser') {
    if ( 
$andor != "exact" ) {
        
$ignored_queries = array(); // holds kewords that are shorter than allowed minmum length
        
$temp_queries preg_split('/[\s,]+/'$query);
        foreach (
$temp_queries as $q) {
            
$q trim($q);
            if (
strlen($q) >= $xoopsConfigSearch['keyword_min']) {
                
$queries[] = $myts->addSlashes($q);
            } else {
                
$ignored_queries[] = $myts->addSlashes($q);
            }
        }
        if (
count($queries) == 0) {
            
redirect_header('search.php'2sprintf(_SR_KEYTOOSHORT$xoopsConfigSearch['keyword_min']));
            exit();
        }
    } else {
        
$query trim($query);
        if (
strlen($query) < $xoopsConfigSearch['keyword_min']) {
            
redirect_header('search.php'2sprintf(_SR_KEYTOOSHORT$xoopsConfigSearch['keyword_min']));
            exit();
        }
        
$queries = array($myts->addSlashes($query));
    }
}
switch (
$action) {
    case 
"results":
    
$module_handler =& xoops_gethandler('module');
    
$criteria = new CriteriaCompo(new Criteria('hassearch'1));
    
$criteria->add(new Criteria('isactive'1));
    
$criteria->add(new Criteria('mid'"(".implode(','$available_modules).")"'IN'));
    
$modules =& $module_handler->getObjects($criteriatrue);
    
$mids = isset($_REQUEST['mids']) ? $_REQUEST['mids'] : array();
    if (empty(
$mids) || !is_array($mids)) {
        unset(
$mids);
        
$mids array_keys($modules);
    }
    include 
XOOPS_ROOT_PATH."/header.php";
    echo 
"<h3>"._SR_SEARCHRESULTS."</h3>\n";
    echo 
_SR_KEYWORDS.':';
    if (
$andor != 'exact') {
        foreach (
$queries as $q) {
            echo 
' <b>'.htmlspecialchars(stripslashes($q)).'</b>';
        }
        if (!empty(
$ignored_queries)) {
            echo 
'<br />';
            
printf(_SR_IGNOREDWORDS$xoopsConfigSearch['keyword_min']);
            foreach (
$ignored_queries as $q) {
                echo 
' <b>'.htmlspecialchars(stripslashes($q)).'</b>';
            }
        }
    } else {
        echo 
' "<b>'.htmlspecialchars(stripslashes($queries[0])).'</b>"';
    }
    echo 
'<br />';
    foreach (
$mids as $mid) {
        
$mid intval($mid);
        if ( 
in_array($mid$available_modules) ) {
            
$module =& $modules[$mid];
            
$results =& $module->search($queries$andor50);
            
$count count($results);
            if (
is_array($results) && $count 0) {
                echo 
"<h4>".$myts->makeTboxData4Show($module->getVar('name'))."</h4>";
                for (
$i 0$i $count$i++) {
                    if (isset(
$results[$i]['image']) && $results[$i]['image'] != "") {
                        echo 
"<img src='modules/".$module->getVar('dirname')."/".$results[$i]['image']."' alt='".$myts->makeTboxData4Show($module->getVar('name'))."' />&nbsp;";
                    } else {
                        echo 
"<img src='images/icons/posticon2.gif' alt='".$myts->makeTboxData4Show($module->getVar('name'))."' width='26' height='26' />&nbsp;";
                    }
                    if (!
preg_match("/^http[s]*:\/\//i"$results[$i]['link'])) {
                        
$results[$i]['link'] = "modules/".$module->getVar('dirname')."/".$results[$i]['link'];
                    }
                    echo 
"<b><a href='".$results[$i]['link']."'>".$myts->makeTboxData4Show($results[$i]['title'])."</a></b><br />\n";
                    echo 
"<small>";
                    
$results[$i]['uid'] = intval($results[$i]['uid']);
                    if ( !empty(
$results[$i]['uid']) ) {
                        
$uname XoopsUser::getUnameFromId($results[$i]['uid']);
                        echo 
"&nbsp;&nbsp;<a href='".XOOPS_URL."/userinfo.php?uid=".$results[$i]['uid']."'>".$uname."</a>\n";
                    }
                    echo 
$results[$i]['time'] ? " ("formatTimestamp(intval($results[$i]['time'])).")" "";
                    echo 
"</small><br />\n";
                }
                if ( 
$count == ) {
                    
$search_url XOOPS_URL.'/search.php?query='.urlencode(stripslashes(implode(' '$queries)));
                    
$search_url .= "&mid=$mid&action=showall&andor=$andor";
                    echo 
'<br /><a href="'.$search_url.'">'._SR_SHOWALLR.'</a></p>';
                }
            }
        }
        unset(
$results);
        unset(
$module);
    }
    include 
"include/searchform.php";
    
$search_form->display();
    break;
    case 
"showall":
    case 
'showallbyuser':
    include 
XOOPS_ROOT_PATH."/header.php";
    
$module_handler =& xoops_gethandler('module');
    
$module =& $module_handler->get($mid);
    
$results =& $module->search($queries$andor20$start$uid);
    
$count count($results);
    if (
is_array($results) && $count 0) {
        
$next_results =& $module->search($queries$andor1$start 20$uid);
        
$next_count count($next_results);
        
$has_next false;
        if (
is_array($next_results) && $next_count == 1) {
            
$has_next true;
        }
        echo 
"<h4>"._SR_SEARCHRESULTS."</h4>\n";
        if (
$action == 'showall') {
            echo 
_SR_KEYWORDS.':';
            if (
$andor != 'exact') {
                foreach (
$queries as $q) {
                    echo 
' <b>'.htmlspecialchars(stripslashes($q)).'</b>';
                }
            } else {
                echo 
' "<b>'.htmlspecialchars(stripslashes($queries[0])).'</b>"';
            }
            echo 
'<br />';
        }
        
//    printf(_SR_FOUND,$count);
        //    echo "<br />";
        
printf(_SR_SHOWING$start+1$start $count);
        echo 
"<h5>".$myts->makeTboxData4Show($module->getVar('name'))."</h5>";
        for (
$i 0$i $count$i++) {
            if (isset(
$results[$i]['image']) && $results[$i]['image'] != '') {
                echo 
"<img src='modules/".$module->getVar('dirname')."/".$results[$i]['image']."' alt='".$myts->makeTboxData4Show($module->getVar('name'))."' />&nbsp;";
            } else {
                echo 
"<img src='images/icons/posticon2.gif' alt='".$myts->makeTboxData4Show($module->name())."' width='26' height='26' />&nbsp;";
            }
            if (!
preg_match("/^http[s]*:\/\//i"$results[$i]['link'])) {
                
$results[$i]['link'] = "modules/".$module->getVar('dirname')."/".$results[$i]['link'];
            }
            echo 
"<b><a href='".$results[$i]['link']."'>".$myts->makeTboxData4Show($results[$i]['title'])."</a></b><br />\n";
            echo 
"<small>";
            
$results[$i]['uid'] = intval($results[$i]['uid']);
            if ( !empty(
$results[$i]['uid']) ) {
                
$uname XoopsUser::getUnameFromId($results[$i]['uid']);
                echo 
"&nbsp;&nbsp;<a href='".XOOPS_URL."/userinfo.php?uid=".$results[$i]['uid']."'>".$uname."</a>\n";
            }
            echo 
$results[$i]['time'] ? " ("formatTimestamp(intval($results[$i]['time'])).")" "";
            echo 
"</small><br />\n";
        }
        echo 
'
        <table>
          <tr>
        '
;
        
$search_url XOOPS_URL.'/search.php?query='.urlencode(stripslashes(implode(' '$queries)));
        
$search_url .= "&mid=$mid&action=$action&andor=$andor";
        if (
$action=='showallbyuser') {
            
$search_url .= "&uid=$uid";
        }
        if ( 
$start ) {
            
$prev $start 20;
            echo 
'<td align="left">
            '
;
            
$search_url_prev $search_url."&start=$prev";
            echo 
'<a href="'.htmlspecialchars($search_url_prev).'">'._SR_PREVIOUS.'</a></td>
            '
;
        }
        echo 
'<td>&nbsp;&nbsp;</td>
        '
;
        if (
false != $has_next) {
            
$next $start 20;
            
$search_url_next $search_url."&start=$next";
            echo 
'<td align="right"><a href="'.htmlspecialchars($search_url_next).'">'._SR_NEXT.'</a></td>
            '
;
        }
        echo 
'
          </tr>
        </table>
        <p>
        '
;
    } else {
        echo 
'<p>'._SR_NOMATCH.'</p>';
    }
    include 
"include/searchform.php";
    
$search_form->display();
    echo 
'</p>
    '
;
    break;
}
include 
XOOPS_ROOT_PATH."/footer.php";
?>