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

search.php (4 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");
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% 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...
38
    redirect_header('index.php', 1);
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 = (int)$_GET['mid'];
61
} elseif (!empty($_POST['mid'])) {
62
    $mid = (int)$_POST['mid'];
63
}
64 View Code Duplication
if (!empty($_GET['uid'])) {
65
    $uid = (int)$_GET['uid'];
66
} elseif (!empty($_POST['uid'])) {
67
    $uid = (int)$_POST['uid'];
68
}
69 View Code Duplication
if (!empty($_GET['start'])) {
70
    $start = (int)$_GET['start'];
71
} elseif (!empty($_POST['start'])) {
72
    $start = (int)$_POST['start'];
73
}
74
$queries = array();
75
76
if ($action === 'results') {
77
    if ($query == '') {
78
        redirect_header('search.php', 1, _SR_PLZENTER);
79
    }
80
} elseif ($action === 'showall') {
81
    if ($query == '' || empty($mid)) {
82
        redirect_header('search.php', 1, _SR_PLZENTER);
83
    }
84
} elseif ($action === 'showallbyuser') {
85
    if (empty($mid) || empty($uid)) {
86
        redirect_header('search.php', 1, _SR_PLZENTER);
87
    }
88
}
89
90
$groups            = is_object($xoopsUser) ? $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS;
91
$gperm_handler     = xoops_getHandler('groupperm');
92
$available_modules = $gperm_handler->getItemIds('module_read', $groups);
93
94
if ('search' === $action) {
95
    include XOOPS_ROOT_PATH . '/header.php';
96
    include_once __DIR__ . '/include/searchform.php';
97
    $search_form->display();
98
    include XOOPS_ROOT_PATH . '/footer.php';
99
    exit();
100
}
101
102
if ($andor !== 'OR' && $andor !== 'exact' && $andor !== 'AND') {
103
    $andor = 'AND';
104
}
105
106
$myts = MyTextSanitizer::getInstance();
107
if ($action !== 'showallbyuser') {
108
    if ($andor !== 'exact') {
109
        $ignored_queries = array(); // holds keywords that are shorter than allowed mininum length
110
        $temp_queries    = preg_split('/[\s,]+/', $query);
111
        foreach ($temp_queries as $q) {
112
            $q = trim($q);
113
            if (strlen($q) >= $xoopsConfigSearch['keyword_min']) {
114
                $queries[] = $myts->addSlashes($q);
115
            } else {
116
                $ignored_queries[] = $myts->addSlashes($q);
117
            }
118
        }
119
        if (count($queries) == 0) {
120
            redirect_header('search.php', 2, sprintf(_SR_KEYTOOSHORT, $xoopsConfigSearch['keyword_min']));
121
        }
122
    } else {
123
        $query = trim($query);
124
        if (strlen($query) < $xoopsConfigSearch['keyword_min']) {
125
            redirect_header('search.php', 2, sprintf(_SR_KEYTOOSHORT, $xoopsConfigSearch['keyword_min']));
126
        }
127
        $queries = array($myts->addSlashes($query));
128
    }
129
}
130
switch ($action) {
131
    case 'results':
132
        $module_handler = xoops_getHandler('module');
133
        $criteria       = new CriteriaCompo(new Criteria('hassearch', 1));
134
        $criteria->add(new Criteria('isactive', 1));
135
        $criteria->add(new Criteria('mid', '(' . implode(',', $available_modules) . ')', 'IN'));
136
        $modules = $module_handler->getObjects($criteria, true);
137
        $mids    = isset($_REQUEST['mids']) ? $_REQUEST['mids'] : array();
138
        if (empty($mids) || !is_array($mids)) {
139
            unset($mids);
140
            $mids = array_keys($xmid);
141
        }
142
        include XOOPS_ROOT_PATH . '/header.php';
143
144
        // for xoops 2.2.x versions
145
        xoops_loadLanguage('main', $moduleDirName);
146
        // end
147
148
        echo '<h3>' . _ADSLIGHT_SEARCHRESULTS . "</h3>\n";
149
        echo _SR_KEYWORDS . ':';
150
        if ($andor !== 'exact') {
151
            foreach ($queries as $q) {
152
                echo ' <strong>' . htmlspecialchars(stripslashes($q)) . '</strong>';
153
            }
154
            if (!empty($ignored_queries)) {
155
                echo '<br>';
156
                printf(_SR_IGNOREDWORDS, $xoopsConfigSearch['keyword_min']);
157
                foreach ($ignored_queries as $q) {
158
                    echo ' <strong>' . htmlspecialchars(stripslashes($q)) . '</strong>';
159
                }
160
            }
161
        } else {
162
            echo ' "<strong>' . htmlspecialchars(stripslashes($queries[0])) . '</strong>"';
163
        }
164
        echo '<br>';
165
        foreach ($mids as $mid) {
166
            $mid = (int)$mid;
167
            if (in_array($mid, $available_modules)) {
168
                $module  =& $modules[$mid];
169
                $results =& $module->search($queries, $andor, 5, 0);
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
                        echo "<style type=\"text/css\" media=\"all\">@import url(" . XOOPS_URL . '/modules/adslight/style/adslight.css);</style>';
176
                        echo "<table width=\"100%\" class=\"outer\"><tr>";
177
                        echo "<td width=\"30%\">";
178
                        echo '<strong>' . $myts->htmlSpecialChars($results[$i]['type']) . '</strong><br>';
179 View Code Duplication
                        if (isset($results[$i]['photo']) && $results[$i]['photo'] != '') {
180
                            echo "<a href='" . $results[$i]['link'] . "'><img class='thumb' src='" . $results[$i]['sphoto'] . "' alt='' width='100' /></a></td>&nbsp;";
181
                        } else {
182
                            echo "<a href='" . $results[$i]['link'] . "'><img class='thumb' src='" . $results[$i]['nophoto'] . "' alt='' width='100' /></a></td>&nbsp;";
183
                        }
184 View Code Duplication
                        if (!preg_match("/^http[s]*:\/\//i", $results[$i]['link'])) {
185
                            $results[$i]['link'] = '' . $results[$i]['link'];
186
                        }
187
                        echo "<td width=\"50%\">";
188
189
                        echo "<strong><a href='" . $results[$i]['link'] . "'>" . $myts->htmlSpecialChars($results[$i]['title']) . '</a></strong><br><br>';
190
191
                        if (!XOOPS_USE_MULTIBYTES) {
192
                            if (strlen($results[$i]['desctext']) >= 14) {
193
                                $results[$i]['desctext'] = $myts->displayTarea(substr($results[$i]['desctext'], 0, 90), 1, 1, 1, 1, 1) . '';
194
                            }
195
                        }
196
197
                        echo '' . $myts->displayTarea($results[$i]['desctext'], 1, 1, 1, 1, 1) . '';
198
199
                        echo "</td><td width=\"20%\">";
200
                        echo '' .
201
                             $xoopsModuleConfig['adslight_money'] .
202
                             '' .
203
                             $myts->htmlSpecialChars($results[$i]['price']) .
204
                             '</a>&nbsp;' .
205
                             $myts->htmlSpecialChars($results[$i]['typeprice']) .
206
                             '</a>';
207
208
                        echo '</td></tr><tr><td>';
209
                        echo '<small>';
210
                        $results[$i]['uid'] = @(int)$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((int)$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':
0 ignored issues
show
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
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'] = @(int)$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((int)$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