Passed
Push — master ( 5e790e...222087 )
by Michael
03:14
created

search.php (26 issues)

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
use Xmf\Request;
0 ignored issues
show
The type Xmf\Request was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
24
use XoopsModules\Adslight;
25
26
$moduleDirName = basename(__DIR__);
27
//@todo replace the following code - use Filters
28
foreach ($_REQUEST as $key => $val) {
29
    $val            = preg_replace("/[^_A-Za-z0-9-\.&=]/i", '', $val);
30
    $_REQUEST[$key] = $val;
31
}
32
33
$xoopsOption['pagetype'] = 'search';
34
35
include dirname(dirname(__DIR__)) . '/mainfile.php';
36
37
$xmid = $xoopsModule->getVar('mid');
38
/** @var XoopsConfigHandler $configHandler */
39
$configHandler     = xoops_getHandler('config');
0 ignored issues
show
The function xoops_getHandler was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

39
$configHandler     = /** @scrutinizer ignore-call */ xoops_getHandler('config');
Loading history...
40
$xoopsConfigSearch = $configHandler->getConfigsByCat(XOOPS_CONF_SEARCH);
0 ignored issues
show
The constant XOOPS_CONF_SEARCH was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
41
42
if (1 != $xoopsConfigSearch['enable_search']) {
43
    //    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...
44
    redirect_header('index.php', 1);
0 ignored issues
show
The function redirect_header was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

44
    /** @scrutinizer ignore-call */ 
45
    redirect_header('index.php', 1);
Loading history...
45
}
46
47
$action = Request::getString('action', 'search');
48
$query  = Request::getString('query', '');
49
$andor  = Request::getString('andor', 'AND');
50
$mid    = Request::getInt('mid', 0);
51
$uid    = Request::getInt('uid', 0);
52
$start  = Request::getInt('start', 0);
53
54
$queries = [];
55
56
if ('results' === $action) {
57
    if ('' === $query) {
58
        redirect_header('search.php', 1, _SR_PLZENTER);
0 ignored issues
show
The constant _SR_PLZENTER was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
59
    }
60
} elseif ('showall' === $action) {
61
    if ('' === $query || empty($mid)) {
62
        redirect_header('search.php', 1, _SR_PLZENTER);
63
    }
64
} elseif ('showallbyuser' === $action) {
65
    if (empty($mid) || empty($uid)) {
66
        redirect_header('search.php', 1, _SR_PLZENTER);
67
    }
68
}
69
70
$groups = is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->getGroups() : XOOPS_GROUP_ANONYMOUS;
0 ignored issues
show
The constant XOOPS_GROUP_ANONYMOUS was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
71
/** @var XoopsGroupPermHandler $gpermHandler */
72
$gpermHandler      = xoops_getHandler('groupperm');
73
$available_modules = $gpermHandler->getItemIds('module_read', $groups);
74
75
if ('search' === $action) {
76
    include XOOPS_ROOT_PATH . '/header.php';
0 ignored issues
show
The constant XOOPS_ROOT_PATH was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
77
    require_once __DIR__ . '/include/searchform.php';
78
    $search_form->display();
79
    include XOOPS_ROOT_PATH . '/footer.php';
80
    exit();
81
}
82
83
if ('OR' !== $andor && 'exact' !== $andor && 'AND' !== $andor) {
84
    $andor = 'AND';
85
}
86
87
$myts = \MyTextSanitizer::getInstance();
0 ignored issues
show
The type MyTextSanitizer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
88
if ('showallbyuser' !== $action) {
89
    if ('exact' !== $andor) {
90
        $ignored_queries = []; // holds keywords that are shorter than allowed mininum length
91
        $temp_queries    = preg_split('/[\s,]+/', $query);
92
        foreach ($temp_queries as $q) {
93
            $q = trim($q);
94
            if (strlen($q) >= $xoopsConfigSearch['keyword_min']) {
95
                $queries[] = $myts->addSlashes($q);
96
            } else {
97
                $ignored_queries[] = $myts->addSlashes($q);
98
            }
99
        }
100
        if (0 == count($queries)) {
101
            redirect_header('search.php', 2, sprintf(_SR_KEYTOOSHORT, $xoopsConfigSearch['keyword_min']));
0 ignored issues
show
The constant _SR_KEYTOOSHORT was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
102
        }
103
    } else {
104
        $query = trim($query);
105
        if (strlen($query) < $xoopsConfigSearch['keyword_min']) {
106
            redirect_header('search.php', 2, sprintf(_SR_KEYTOOSHORT, $xoopsConfigSearch['keyword_min']));
107
        }
108
        $queries = [$myts->addSlashes($query)];
109
    }
110
}
111
switch ($action) {
112
    case 'results':
113
        /** @var XoopsModuleHandler $moduleHandler */
114
        $moduleHandler = xoops_getHandler('module');
115
        $criteria      = new \CriteriaCompo(new \Criteria('hassearch', 1));
0 ignored issues
show
The type CriteriaCompo was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
The type Criteria was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
116
        $criteria->add(new \Criteria('isactive', 1));
117
        $criteria->add(new \Criteria('mid', '(' . implode(',', $available_modules) . ')', 'IN'));
118
        $modules = $moduleHandler->getObjects($criteria, true);
119
        $mids    = Request::getArray('mids', []);
120
        if (empty($mids) || !is_array($mids)) {
121
            unset($mids);
122
            $mids = array_keys($xmid);
123
        }
124
        include XOOPS_ROOT_PATH . '/header.php';
125
126
        // for xoops 2.2.x versions
127
        xoops_loadLanguage('main', $moduleDirName);
0 ignored issues
show
The function xoops_loadLanguage was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

127
        /** @scrutinizer ignore-call */ 
128
        xoops_loadLanguage('main', $moduleDirName);
Loading history...
128
        // end
129
130
        echo '<h3>' . _ADSLIGHT_SEARCHRESULTS . "</h3>\n";
131
        echo _SR_KEYWORDS . ':';
0 ignored issues
show
The constant _SR_KEYWORDS was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
132
        if ('exact' !== $andor) {
133
            foreach ($queries as $q) {
134
                echo ' <strong>' . htmlspecialchars(stripslashes($q)) . '</strong>';
135
            }
136
            if (!empty($ignored_queries)) {
137
                echo '<br>';
138
                printf(_SR_IGNOREDWORDS, $xoopsConfigSearch['keyword_min']);
0 ignored issues
show
The constant _SR_IGNOREDWORDS was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
139
                foreach ($ignored_queries as $q) {
140
                    echo ' <strong>' . htmlspecialchars(stripslashes($q)) . '</strong>';
141
                }
142
            }
143
        } else {
144
            echo ' "<strong>' . htmlspecialchars(stripslashes($queries[0])) . '</strong>"';
145
        }
146
        echo '<br>';
147
        foreach ($mids as $mid) {
148
            $mid = (int)$mid;
149
            if (in_array($mid, $available_modules)) {
150
                $module  = $modules[$mid];
151
                $results = $module->search($queries, $andor, 5, 0);
152
                $count   = 0;
153
                if (is_array($results)) {
154
                    $count = count($results);
155
                }
156
                if (!is_array($results) || 0 == $count) {
157
                    echo '<p>' . _SR_NOMATCH . '</p>';
0 ignored issues
show
The constant _SR_NOMATCH was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
158
                } else {
159
                    for ($i = 0; $i < $count; ++$i) {
160
                        echo '<style type="text/css" media="all">@import url(' . XOOPS_URL . '/modules/adslight/assets/css/adslight.css);</style>';
0 ignored issues
show
The constant XOOPS_URL was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
161
                        echo '<table width="100%" class="outer"><tr>';
162
                        echo '<td width="30%">';
163
                        echo '<strong>' . $myts->htmlSpecialChars($results[$i]['type']) . '</strong><br>';
164
                        if (isset($results[$i]['photo'])
165
                            && '' !== $results[$i]['photo']) {
166
                            echo "<a href='" . $results[$i]['link'] . "'><img class='thumb' src='" . $results[$i]['sphoto'] . "' alt='' width='100' ></a></td>&nbsp;";
167
                        } else {
168
                            echo "<a href='" . $results[$i]['link'] . "'><img class='thumb' src='" . $results[$i]['nophoto'] . "' alt='' width='100' ></a></td>&nbsp;";
169
                        }
170
                        if (!preg_match("/^http[s]*:\/\//i", $results[$i]['link'])) {
171
                            $results[$i]['link'] = '' . $results[$i]['link'];
172
                        }
173
                        echo '<td width="50%">';
174
175
                        echo "<strong><a href='" . $results[$i]['link'] . "'>" . $myts->htmlSpecialChars($results[$i]['title']) . '</a></strong><br><br>';
176
177
                        if (!XOOPS_USE_MULTIBYTES) {
0 ignored issues
show
The constant XOOPS_USE_MULTIBYTES was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
178
                            if (strlen($results[$i]['desctext']) >= 14) {
179
                                $results[$i]['desctext'] = $myts->displayTarea(substr($results[$i]['desctext'], 0, 90), 1, 1, 1, 1, 1) . '';
180
                            }
181
                        }
182
183
                        echo '' . $myts->displayTarea($results[$i]['desctext'], 1, 1, 1, 1, 1) . '';
184
185
                        echo '</td><td width="20%">';
186
                        echo '' . $GLOBALS['xoopsModuleConfig']['adslight_currency_symbol'] . '' . $myts->htmlSpecialChars($results[$i]['price']) . '</a>&nbsp;' . $myts->htmlSpecialChars($results[$i]['typeprice']) . '</a>';
187
188
                        echo '</td></tr><tr><td>';
189
                        echo '<small>';
190
                        $results[$i]['uid'] = @(int)$results[$i]['uid'];
191
                        if (!empty($results[$i]['uid'])) {
192
                            $uname = XoopsUser::getUnameFromId($results[$i]['uid']);
0 ignored issues
show
The type XoopsUser was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
193
                            echo '&nbsp;&nbsp;' . _ADSLIGHT_FROM . "<a href='" . XOOPS_URL . '/userinfo.php?uid=' . $results[$i]['uid'] . "'>" . $uname . "</a>\n";
194
                        }
195
                        echo !empty($results[$i]['time']) ? ' (' . formatTimestamp((int)$results[$i]['time']) . ')' : '';
0 ignored issues
show
The function formatTimestamp was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

195
                        echo !empty($results[$i]['time']) ? ' (' . /** @scrutinizer ignore-call */ formatTimestamp((int)$results[$i]['time']) . ')' : '';
Loading history...
196
                        echo '</small>';
197
                        echo '</td></tr></table><table>';
198
                    }
199
                    if ($count >= 5) {
200
                        $search_url = XOOPS_URL . '/modules/adslight/search.php?query=' . urlencode(stripslashes(implode(' ', $queries)));
201
                        $search_url .= "&mid=$mid&action=showall&andor=$andor";
202
                        echo '<br><a href="' . htmlspecialchars($search_url) . '">' . _SR_SHOWALLR . '</a>';
0 ignored issues
show
The constant _SR_SHOWALLR was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
203
                    }
204
                    echo '<table>';
205
                }
206
            }
207
            unset($results, $module);
208
        }
209
        require_once __DIR__ . '/include/searchform.php';
210
        $search_form->display();
211
        break;
212
    case 'showall':
213
    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...
214
215
        include XOOPS_ROOT_PATH . '/header.php';
216
217
        /** @var Adslight\Helper $helper */
218
        $helper = Adslight\Helper::getInstance();
219
        $helper->loadLanguage('admin');
220
221
        $GLOBALS['xoopsTpl']->assign('imgscss', XOOPS_URL . '/modules/adslight/assets/css/adslight.css');
222
        /** @var XoopsModuleHandler $moduleHandler */
223
        $moduleHandler = xoops_getHandler('module');
224
        $module        = $moduleHandler->get($mid);
225
        $results       =& $module->search($queries, $andor, 20, $start, $uid);
226
        $count         = 0;
227
        if (is_array($results)) {
228
            $count = count($results);
229
        }
230
        if ($count > 0) {
231
            $next_results =& $module->search($queries, $andor, 1, $start + 20, $uid);
232
            $count        = 0;
233
            if (is_array($next_results)) {
234
                $count = count($next_results);
235
            }
236
            $has_next = false;
237
            if (is_array($next_results) && 1 == $next_count) {
238
                $has_next = true;
239
            }
240
            echo '<h4>' . _ADSLIGHT_SEARCHRESULTS . "</h4>\n";
241
            if ('showall' === $action) {
242
                echo _SR_KEYWORDS . ':';
243
                if ('exact' !== $andor) {
244
                    foreach ($queries as $q) {
245
                        echo ' <strong>' . htmlspecialchars(stripslashes($q)) . '</strong>';
246
                    }
247
                } else {
248
                    echo ' "<strong>' . htmlspecialchars(stripslashes($queries[0])) . '</strong>"';
249
                }
250
                echo '<br><br>';
251
            }
252
            //    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...
253
            //    echo "<br>";
254
            printf(_SR_SHOWING, $start + 1, $start + $count);
0 ignored issues
show
The constant _SR_SHOWING was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
255
            for ($i = 0; $i < $count; ++$i) {
256
                echo '<table width="100%" class="outer"><tr>';
257
                echo '<td width="30%">';
258
                echo '<strong>' . $myts->htmlSpecialChars($results[$i]['type']) . '</strong><br>';
259
                if (isset($results[$i]['photo'])
260
                    && '' !== $results[$i]['photo']) {
261
                    echo "<a href='" . $results[$i]['link'] . "'><img class='thumb' src='" . $results[$i]['sphoto'] . "' alt='' width='100' ></a></td>&nbsp;";
262
                } else {
263
                    echo "<a href='" . $results[$i]['link'] . "'><img class='thumb' src='" . $results[$i]['nophoto'] . "' alt='' width='100' ></a></td>&nbsp;";
264
                }
265
                if (!preg_match("/^http[s]*:\/\//i", $results[$i]['link'])) {
266
                    $results[$i]['link'] = '' . $results[$i]['link'];
267
                }
268
                echo '<td width="50%">';
269
270
                echo "<strong><a href='" . $results[$i]['link'] . "'>" . $myts->htmlSpecialChars($results[$i]['title']) . '</a></strong><br><br>';
271
272
                if (!XOOPS_USE_MULTIBYTES) {
273
                    if (strlen($results[$i]['desctext']) >= 14) {
274
                        $results[$i]['desctext'] = substr($results[$i]['desctext'], 0, 90) . '...';
275
                    }
276
                }
277
278
                echo '' . $myts->htmlSpecialChars($results[$i]['desctext']) . '';
279
280
                echo '</td><td width="20%">';
281
                echo '' . $GLOBALS['xoopsModuleConfig']['adslight_currency_symbol'] . '
282
' . $myts->htmlSpecialChars($results[$i]['price']) . '</a>&nbsp;' . $myts->htmlSpecialChars($results[$i]['typeprice']) . '</a>';
283
284
                echo '</td></tr><tr><td>';
285
                echo '<small>';
286
                $results[$i]['uid'] = @(int)$results[$i]['uid'];
287
                if (!empty($results[$i]['uid'])) {
288
                    $uname = XoopsUser::getUnameFromId($results[$i]['uid']);
289
                    echo '&nbsp;&nbsp;' . _ADSLIGHT_FROM . "<a href='" . XOOPS_URL . '/userinfo.php?uid=' . $results[$i]['uid'] . "'>" . $uname . '</a><br>';
290
                }
291
                echo !empty($results[$i]['time']) ? ' (' . formatTimestamp((int)$results[$i]['time']) . ')' : '';
292
                echo '</small>';
293
                echo '</td></tr></table><table>';
294
            }
295
296
            echo '
297
        <table>
298
          <tr>
299
        ';
300
            $search_url = XOOPS_URL . '/modules/adslight/search.php?query=' . urlencode(stripslashes(implode(' ', $queries)));
301
            $search_url .= "&mid=$mid&action=$action&andor=$andor";
302
            if ('showallbyuser' === $action) {
303
                $search_url .= "&uid=$uid";
304
            }
305
            if ($start > 0) {
306
                $prev = $start - 20;
307
                echo '<td align="left">
308
            ';
309
                $search_url_prev = $search_url . "&start=$prev";
310
                echo '<a href="' . htmlspecialchars($search_url_prev) . '">' . _SR_PREVIOUS . '</a></td>
0 ignored issues
show
The constant _SR_PREVIOUS was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
311
            ';
312
            }
313
            echo '<td>&nbsp;&nbsp;</td>
314
        ';
315
            if (false !== $has_next) {
316
                $next            = $start + 20;
317
                $search_url_next = $search_url . "&start=$next";
318
                echo '<td align="right"><a href="' . htmlspecialchars($search_url_next) . '">' . _SR_NEXT . '</a></td>
0 ignored issues
show
The constant _SR_NEXT was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
319
            ';
320
            }
321
            echo '
322
          </tr>
323
        </table>
324
        <p>
325
        ';
326
        } else {
327
            echo '<p>' . _SR_NOMATCH . '</p>';
328
        }
329
        require_once __DIR__ . '/include/searchform.php';
330
        $search_form->display();
331
        echo '</p>
332
    ';
333
        break;
334
}
335
include XOOPS_ROOT_PATH . '/footer.php';
336