Completed
Push — master ( 0424ea...923121 )
by Michael
03:57
created

search.php (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/*
3
-------------------------------------------------------------------------
4
                     ADSLIGHT 2 : Module for Xoops
5
6
        Redesigned and ameliorate By Luc Bizet user at www.frxoops.org
7
        Started with the Classifieds module and made MANY changes
8
        Website : http://www.luc-bizet.fr
9
        Contact : [email protected]
10
-------------------------------------------------------------------------
11
             Original credits below Version History
12
##########################################################################
13
#                    Classified Module for Xoops                         #
14
#  By John Mordo user jlm69 at www.xoops.org and www.jlmzone.com         #
15
#      Started with the MyAds module and made MANY changes               #
16
##########################################################################
17
 Original Author: Pascal Le Boustouller
18
 Author Website : [email protected]
19
 Licence Type   : GPL
20
-------------------------------------------------------------------------
21
*/
22
23
foreach ($_REQUEST as $key => $val) {
24
    $val            = preg_replace("/[^_A-Za-z0-9-\.&=]/i", '', $val);
25
    $_REQUEST[$key] = $val;
26
}
27
28
$xoopsOption['pagetype'] = "search";
29
30
include dirname(dirname(__DIR__)) . '/mainfile.php';
31
32
$xmid              = $xoopsModule->getVar('mid');
33
$config_handler    =& xoops_gethandler('config');
34
$xoopsConfigSearch =& $config_handler->getConfigsByCat(XOOPS_CONF_SEARCH);
35
36
if ($xoopsConfigSearch['enable_search'] != 1) {
37
    header("Location: '.XOOPS_URL.'modules/adslight/index.php");
38
    exit();
39
}
40
$action = "search";
41 View Code Duplication
if (!empty($_GET['action'])) {
42
    $action = $_GET['action'];
43
} elseif (!empty($_POST['action'])) {
44
    $action = $_POST['action'];
45
}
46
$query = "";
47
if (!empty($_GET['query'])) {
48
    $query = $_GET['query'];
49
} elseif (!empty($_POST['query'])) {
50
    $query = $_POST['query'];
51
}
52
$andor = "AND";
53
if (!empty($_GET['andor'])) {
54
    $andor = $_GET['andor'];
55
} elseif (!empty($_POST['andor'])) {
56
    $andor = $_POST['andor'];
57
}
58
$mid = $uid = $start = 0;
59 View Code Duplication
if (!empty($_GET['mid'])) {
60
    $mid = intval($_GET['mid']);
61
} elseif (!empty($_POST['mid'])) {
62
    $mid = intval($_POST['mid']);
63
}
64 View Code Duplication
if (!empty($_GET['uid'])) {
65
    $uid = intval($_GET['uid']);
66
} elseif (!empty($_POST['uid'])) {
67
    $uid = intval($_POST['uid']);
68
}
69 View Code Duplication
if (!empty($_GET['start'])) {
70
    $start = intval($_GET['start']);
71
} elseif (!empty($_POST['start'])) {
72
    $start = intval($_POST['start']);
73
}
74
$queries = array();
75
76
if ($action == "results") {
77
    if ($query == "") {
78
        redirect_header("search.php", 1, _SR_PLZENTER);
79
        exit();
80
    }
81
} elseif ($action == "showall") {
82
    if ($query == "" || empty($mid)) {
83
        redirect_header("search.php", 1, _SR_PLZENTER);
84
        exit();
85
    }
86
} elseif ($action == "showallbyuser") {
87
    if (empty($mid) || empty($uid)) {
88
        redirect_header("search.php", 1, _SR_PLZENTER);
89
        exit();
90
    }
91
}
92
93
$groups            = is_object($xoopsUser) ? $xoopsUser ->getGroups() : XOOPS_GROUP_ANONYMOUS;
94
$gperm_handler     = & xoops_gethandler('groupperm');
95
$available_modules = $gperm_handler->getItemIds('module_read', $groups);
96
97
if ($action == 'search') {
98
    include XOOPS_ROOT_PATH . '/header.php';
99
    include_once __DIR__ . '/include/searchform.php';
100
    $search_form->display();
101
    include XOOPS_ROOT_PATH . '/footer.php';
102
    exit();
103
}
104
105
if ($andor != "OR" && $andor != "exact" && $andor != "AND") {
106
    $andor = "AND";
107
}
108
109
$myts =& MyTextSanitizer::getInstance();
110
if ($action != 'showallbyuser') {
111
    if ($andor != "exact") {
112
        $ignored_queries = array(); // holds keywords that are shorter than allowed mininum length
113
        $temp_queries    = preg_split('/[\s,]+/', $query);
114
        foreach ($temp_queries as $q) {
115
            $q = trim($q);
116
            if (strlen($q) >= $xoopsConfigSearch['keyword_min']) {
117
                $queries[] = $myts->addSlashes($q);
118
            } else {
119
                $ignored_queries[] = $myts->addSlashes($q);
120
            }
121
        }
122
        if (count($queries) == 0) {
123
            redirect_header('search.php', 2, sprintf(_SR_KEYTOOSHORT, $xoopsConfigSearch['keyword_min']));
124
            exit();
125
        }
126
    } else {
127
        $query = trim($query);
128
        if (strlen($query) < $xoopsConfigSearch['keyword_min']) {
129
            redirect_header('search.php', 2, sprintf(_SR_KEYTOOSHORT, $xoopsConfigSearch['keyword_min']));
130
            exit();
131
        }
132
        $queries = array($myts->addSlashes($query));
133
    }
134
}
135
switch ($action) {
136
    case "results":
137
        $module_handler =& xoops_gethandler('module');
138
        $criteria       = new CriteriaCompo(new Criteria('hassearch', 1));
139
        $criteria->add(new Criteria('isactive', 1));
140
        $criteria->add(new Criteria('mid', "(" . implode(',', $available_modules) . ")", 'IN'));
141
        $modules =& $module_handler->getObjects($criteria, true);
142
        $mids    = isset($_REQUEST['mids']) ? $_REQUEST['mids'] : array();
143
        if (empty($mids) || !is_array($mids)) {
144
            unset($mids);
145
            $mids = array_keys($xmid);
146
        }
147
        include XOOPS_ROOT_PATH . "/header.php";
148
149
// for xoops 2.2.x versions
150
        xoops_loadLanguage('main', $moduleDirName);
151
// end
152
153
        echo "<h3>" . _ADSLIGHT_SEARCHRESULTS . "</h3>\n";
154
        echo _SR_KEYWORDS . ':';
155
        if ($andor != 'exact') {
156
            foreach ($queries as $q) {
157
                echo ' <strong>' . htmlspecialchars(stripslashes($q)) . '</strong>';
158
            }
159
            if (!empty($ignored_queries)) {
160
                echo '<br />';
161
                printf(_SR_IGNOREDWORDS, $xoopsConfigSearch['keyword_min']);
162
                foreach ($ignored_queries as $q) {
163
                    echo ' <strong>' . htmlspecialchars(stripslashes($q)) . '</strong>';
164
                }
165
            }
166
        } else {
167
            echo ' "<strong>' . htmlspecialchars(stripslashes($queries[0])) . '</strong>"';
168
        }
169
        echo '<br />';
170
        foreach ($mids as $mid) {
171
            $mid = intval($mid);
172
            if (in_array($mid, $available_modules)) {
173
                $module  =& $modules[$mid];
174
                $results =& $module->search($queries, $andor, 5, 0);
175
                $count   = count($results);
176
                if (!is_array($results) || $count == 0) {
177
                    echo "<p>" . _SR_NOMATCH . "</p>";
178
                } else {
179
                    for ($i = 0; $i < $count; ++$i) {
180
181
                        echo "<style type=\"text/css\" media=\"all\">@import url(" . XOOPS_URL . "/modules/adslight/style/adslight.css);</style>";
182
                        echo "<table width=\"100%\" class=\"outer\"><tr>";
183
                        echo "<td width=\"30%\">";
184
                        echo "<strong>" . $myts->htmlSpecialChars($results[$i]['type']) . "</strong><br />";
185 View Code Duplication
                        if (isset($results[$i]['photo']) && $results[$i]['photo'] != "") {
186
                            echo "<a href='" . $results[$i]['link'] . "'><img class='thumb' src='" . $results[$i]['sphoto'] . "' alt='' width='100' /></a></td>&nbsp;";
187
                        } else {
188
                            echo "<a href='" . $results[$i]['link'] . "'><img class='thumb' src='" . $results[$i]['nophoto'] . "' alt='' width='100' /></a></td>&nbsp;";
189
                        }
190 View Code Duplication
                        if (!preg_match("/^http[s]*:\/\//i", $results[$i]['link'])) {
191
                            $results[$i]['link'] = "" . $results[$i]['link'];
192
                        }
193
                        echo "<td width=\"50%\">";
194
195
                        echo "<strong><a href='" . $results[$i]['link'] . "'>" . $myts->htmlSpecialChars($results[$i]['title']) . "</a></strong><br /><br />";
196
197
                        if (!XOOPS_USE_MULTIBYTES) {
198
                            if (strlen($results[$i]['desctext']) >= 14) {
199
                                $results[$i]['desctext'] = $myts->displayTarea(substr($results[$i]['desctext'], 0, 90), 1, 1, 1, 1, 1) . "";
200
                            }
201
                        }
202
203
                        echo "" . $myts->displayTarea($results[$i]['desctext'], 1, 1, 1, 1, 1) . "";
204
205
                        echo "</td><td width=\"20%\">";
206
                        echo "" . $xoopsModuleConfig["adslight_money"] . "" . $myts->htmlSpecialChars($results[$i]['price']) . "</a>&nbsp;" . $myts->htmlSpecialChars($results[$i]['typeprice']) . "</a>";
207
208
                        echo "</td></tr><tr><td>";
209
                        echo "<small>";
210
                        $results[$i]['uid'] = @intval($results[$i]['uid']);
211 View Code Duplication
                        if (!empty($results[$i]['uid'])) {
212
                            $uname = XoopsUser::getUnameFromId($results[$i]['uid']);
213
                            echo "&nbsp;&nbsp;" . _ADSLIGHT_FROM . "<a href='" . XOOPS_URL . "/userinfo.php?uid=" . $results[$i]['uid'] . "'>" . $uname . "</a>\n";
214
                        }
215
                        echo !empty($results[$i]['time']) ? " (" . formatTimestamp(intval($results[$i]['time'])) . ")" : "";
216
                        echo "</small>";
217
                        echo "</td></tr></table><table>";
218
                    }
219
                    if ($count >= 5) {
220
                        $search_url = XOOPS_URL . "/modules/adslight/search.php?query=" . urlencode(stripslashes(implode(' ', $queries)));
221
                        $search_url .= "&mid=$mid&action=showall&andor=$andor";
222
                        echo '<br /><a href="' . htmlspecialchars($search_url) . '">' . _SR_SHOWALLR . '</a>';
223
                    }
224
                    echo "<table>";
225
                }
226
            }
227
            unset($results);
228
            unset($module);
229
        }
230
        include_once __DIR__ . '/include/searchform.php';
231
        $search_form->display();
232
        break;
233
    case "showall":
234
    case 'showallbyuser':
235
236
        include XOOPS_ROOT_PATH . "/header.php";
237
238
// for xoops 2.2.x versions
239
        if (file_exists(__DIR__ . '/language/' . $xoopsConfig['language'] . "/main.php")) {
240
            include_once __DIR__ . '/language/' . $xoopsConfig['language'] . "/main.php";
241
} else {
242
            include_once __DIR__ . '/language/english/main.php';
243
        }
244
// end
245
        $xoopsTpl->assign('imgscss', XOOPS_URL . "/modules/adslight/style/adslight.css");
246
        $module_handler =& xoops_gethandler('module');
247
        $module         =& $module_handler->get($mid);
248
        $results        =& $module->search($queries, $andor, 20, $start, $uid);
249
        $count          = count($results);
250
        if (is_array($results) && $count > 0) {
251
            $next_results =& $module->search($queries, $andor, 1, $start + 20, $uid);
252
            $next_count   = count($next_results);
253
            $has_next     = false;
254
            if (is_array($next_results) && $next_count == 1) {
255
                $has_next = true;
256
            }
257
            echo "<h4>" . _ADSLIGHT_SEARCHRESULTS . "</h4>\n";
258
            if ($action == 'showall') {
259
                echo _SR_KEYWORDS . ':';
260
                if ($andor != 'exact') {
261
                    foreach ($queries as $q) {
262
                        echo ' <strong>' . htmlspecialchars(stripslashes($q)) . '</strong>';
263
                    }
264
                } else {
265
                    echo ' "<strong>' . htmlspecialchars(stripslashes($queries[0])) . '</strong>"';
266
                }
267
                echo '<br /><br />';
268
            }
269
            //    printf(_SR_FOUND,$count);
0 ignored issues
show
Unused Code Comprehensibility introduced by
63% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
270
            //    echo "<br />";
271
            printf(_SR_SHOWING, $start + 1, $start + $count);
272
            for ($i = 0; $i < $count; ++$i) {
273
                echo "<table width=\"100%\" class=\"outer\"><tr>";
274
                echo "<td width=\"30%\">";
275
                echo "<strong>" . $myts->htmlSpecialChars($results[$i]['type']) . "</strong><br />";
276 View Code Duplication
                if (isset($results[$i]['photo']) && $results[$i]['photo'] != "") {
1 ignored issue
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
277
                    echo "<a href='" . $results[$i]['link'] . "'><img class='thumb' src='" . $results[$i]['sphoto'] . "' alt='' width='100' /></a></td>&nbsp;";
278
                } else {
279
                    echo "<a href='" . $results[$i]['link'] . "'><img class='thumb' src='" . $results[$i]['nophoto'] . "' alt='' width='100' /></a></td>&nbsp;";
280
                }
281 View Code Duplication
                if (!preg_match("/^http[s]*:\/\//i", $results[$i]['link'])) {
282
                    $results[$i]['link'] = "" . $results[$i]['link'];
283
                }
284
                echo "<td width=\"50%\">";
285
286
                echo "<strong><a href='" . $results[$i]['link'] . "'>" . $myts->htmlSpecialChars($results[$i]['title']) . "</a></strong><br /><br />";
287
288 View Code Duplication
                if (!XOOPS_USE_MULTIBYTES) {
289
                    if (strlen($results[$i]['desctext']) >= 14) {
290
                        $results[$i]['desctext'] = substr($results[$i]['desctext'], 0, 90) . "...";
291
                    }
292
                }
293
294
                echo "" . $myts->htmlSpecialChars($results[$i]['desctext']) . "";
295
296
                echo "</td><td width=\"20%\">";
297
                echo "" . $xoopsModuleConfig["adslight_money"] . "
298
" . $myts->htmlSpecialChars($results[$i]['price']) . "</a>&nbsp;" . $myts->htmlSpecialChars($results[$i]['typeprice']) . "</a>";
299
300
                echo "</td></tr><tr><td>";
301
                echo "<small>";
302
                $results[$i]['uid'] = @intval($results[$i]['uid']);
303 View Code Duplication
                if (!empty($results[$i]['uid'])) {
304
                    $uname = XoopsUser::getUnameFromId($results[$i]['uid']);
305
                    echo "&nbsp;&nbsp;" . _ADSLIGHT_FROM . "<a href='" . XOOPS_URL . "/userinfo.php?uid=" . $results[$i]['uid'] . "'>" . $uname . "</a><br />";
306
                }
307
                echo !empty($results[$i]['time']) ? " (" . formatTimestamp(intval($results[$i]['time'])) . ")" : "";
308
                echo "</small>";
309
                echo "</td></tr></table><table>";
310
            }
311
312
            echo '
313
        <table>
314
          <tr>
315
        ';
316
            $search_url = XOOPS_URL . "/modules/adslight/search.php?query=" . urlencode(stripslashes(implode(' ', $queries)));
317
            $search_url .= "&mid=$mid&action=$action&andor=$andor";
318
            if ($action == 'showallbyuser') {
319
                $search_url .= "&uid=$uid";
320
            }
321
            if ($start > 0) {
322
                $prev = $start - 20;
323
                echo '<td align="left">
324
            ';
325
                $search_url_prev = $search_url . "&start=$prev";
326
                echo '<a href="' . htmlspecialchars($search_url_prev) . '">' . _SR_PREVIOUS . '</a></td>
327
            ';
328
            }
329
            echo '<td>&nbsp;&nbsp;</td>
330
        ';
331
            if (false != $has_next) {
332
                $next            = $start + 20;
333
                $search_url_next = $search_url . "&start=$next";
334
                echo '<td align="right"><a href="' . htmlspecialchars($search_url_next) . '">' . _SR_NEXT . '</a></td>
335
            ';
336
            }
337
            echo '
338
          </tr>
339
        </table>
340
        <p>
341
        ';
342
        } else {
343
            echo '<p>' . _SR_NOMATCH . '</p>';
344
        }
345
        include_once __DIR__ . '/include/searchform.php';
346
        $search_form->display();
347
        echo '</p>
348
    ';
349
        break;
350
}
351
include XOOPS_ROOT_PATH . "/footer.php";
352