Completed
Branch master (975d00)
by Michael
05:06 queued 01:53
created

search.php (1 issue)

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
//@todo replace the following code - use Filters
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
    redirect_header('index.php', 1);
39
}
40
xoops_load('XoopsRequest');
41
42
$action = XoopsRequest::getCmd('action', 'search');
43
$query  = XoopsRequest::getString('query', '');
44
$andor  = XoopsRequest::getString('andor', 'AND');
45
$mid    = XoopsRequest::getInt('mid', 0);
46
$uid    = XoopsRequest::getInt('uid', 0);
47
$start  = XoopsRequest::getInt('start', 0);
48
49
$queries = array();
50
51
if ($action === 'results') {
52
    if ($query == '') {
53
        redirect_header('search.php', 1, _SR_PLZENTER);
54
    }
55
} elseif ($action === 'showall') {
56
    if ($query == '' || empty($mid)) {
57
        redirect_header('search.php', 1, _SR_PLZENTER);
58
    }
59
} elseif ($action === 'showallbyuser') {
60
    if (empty($mid) || empty($uid)) {
61
        redirect_header('search.php', 1, _SR_PLZENTER);
62
    }
63
}
64
65
$groups            = is_object($xoopsUser) ? $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS;
66
$gperm_handler     = xoops_getHandler('groupperm');
67
$available_modules = $gperm_handler->getItemIds('module_read', $groups);
68
69
if ($action === 'search') {
70
    include XOOPS_ROOT_PATH . '/header.php';
71
    include_once __DIR__ . '/include/searchform.php';
72
    $search_form->display();
73
    include XOOPS_ROOT_PATH . '/footer.php';
74
    exit();
75
}
76
77
if ($andor !== 'OR' && $andor !== 'exact' && $andor !== 'AND') {
78
    $andor = 'AND';
79
}
80
81
$myts = MyTextSanitizer::getInstance();
82
if ($action !== 'showallbyuser') {
83
    if ($andor !== 'exact') {
84
        $ignored_queries = array(); // holds keywords that are shorter than allowed mininum length
85
        $temp_queries    = preg_split('/[\s,]+/', $query);
86
        foreach ($temp_queries as $q) {
87
            $q = trim($q);
88
            if (strlen($q) >= $xoopsConfigSearch['keyword_min']) {
89
                $queries[] = $myts->addSlashes($q);
90
            } else {
91
                $ignored_queries[] = $myts->addSlashes($q);
92
            }
93
        }
94
        if (count($queries) == 0) {
95
            redirect_header('search.php', 2, sprintf(_SR_KEYTOOSHORT, $xoopsConfigSearch['keyword_min']));
96
        }
97
    } else {
98
        $query = trim($query);
99
        if (strlen($query) < $xoopsConfigSearch['keyword_min']) {
100
            redirect_header('search.php', 2, sprintf(_SR_KEYTOOSHORT, $xoopsConfigSearch['keyword_min']));
101
        }
102
        $queries = array($myts->addSlashes($query));
103
    }
104
}
105
switch ($action) {
106
    case 'results':
107
        /** @var XoopsModuleHandler $moduleHandler */
108
        $moduleHandler = xoops_getHandler('module');
109
        $criteria      = new CriteriaCompo(new Criteria('hassearch', 1));
110
        $criteria->add(new Criteria('isactive', 1));
111
        $criteria->add(new Criteria('mid', '(' . implode(',', $available_modules) . ')', 'IN'));
112
        $modules = $moduleHandler->getObjects($criteria, true);
113
        $mids    = isset($_REQUEST['mids']) ? $_REQUEST['mids'] : array();
114
        if (empty($mids) || !is_array($mids)) {
115
            unset($mids);
116
            $mids = array_keys($xmid);
117
        }
118
        include XOOPS_ROOT_PATH . '/header.php';
119
120
        // for xoops 2.2.x versions
121
        xoops_loadLanguage('main', $moduleDirName);
122
        // end
123
124
        echo '<h3>' . _ADSLIGHT_SEARCHRESULTS . "</h3>\n";
125
        echo _SR_KEYWORDS . ':';
126
        if ($andor !== 'exact') {
127
            foreach ($queries as $q) {
128
                echo ' <strong>' . htmlspecialchars(stripslashes($q)) . '</strong>';
129
            }
130
            if (!empty($ignored_queries)) {
131
                echo '<br>';
132
                printf(_SR_IGNOREDWORDS, $xoopsConfigSearch['keyword_min']);
133
                foreach ($ignored_queries as $q) {
134
                    echo ' <strong>' . htmlspecialchars(stripslashes($q)) . '</strong>';
135
                }
136
            }
137
        } else {
138
            echo ' "<strong>' . htmlspecialchars(stripslashes($queries[0])) . '</strong>"';
139
        }
140
        echo '<br>';
141
        foreach ($mids as $mid) {
142
            $mid = (int)$mid;
143
            if (in_array($mid, $available_modules)) {
144
                $module  =& $modules[$mid];
145
                $results =& $module->search($queries, $andor, 5, 0);
146
                $count   = count($results);
147
                if (!is_array($results) || $count == 0) {
148
                    echo '<p>' . _SR_NOMATCH . '</p>';
149
                } else {
150
                    for ($i = 0; $i < $count; ++$i) {
151
                        echo "<style type=\"text/css\" media=\"all\">@import url(" . XOOPS_URL . '/modules/adslight/style/adslight.css);</style>';
152
                        echo "<table width=\"100%\" class=\"outer\"><tr>";
153
                        echo "<td width=\"30%\">";
154
                        echo '<strong>' . $myts->htmlSpecialChars($results[$i]['type']) . '</strong><br>';
155 View Code Duplication
                        if (isset($results[$i]['photo']) && $results[$i]['photo'] != '') {
156
                            echo "<a href='" . $results[$i]['link'] . "'><img class='thumb' src='" . $results[$i]['sphoto'] . "' alt='' width='100' /></a></td>&nbsp;";
157
                        } else {
158
                            echo "<a href='" . $results[$i]['link'] . "'><img class='thumb' src='" . $results[$i]['nophoto'] . "' alt='' width='100' /></a></td>&nbsp;";
159
                        }
160 View Code Duplication
                        if (!preg_match("/^http[s]*:\/\//i", $results[$i]['link'])) {
161
                            $results[$i]['link'] = '' . $results[$i]['link'];
162
                        }
163
                        echo "<td width=\"50%\">";
164
165
                        echo "<strong><a href='" . $results[$i]['link'] . "'>" . $myts->htmlSpecialChars($results[$i]['title']) . '</a></strong><br><br>';
166
167
                        if (!XOOPS_USE_MULTIBYTES) {
168
                            if (strlen($results[$i]['desctext']) >= 14) {
169
                                $results[$i]['desctext'] = $myts->displayTarea(substr($results[$i]['desctext'], 0, 90), 1, 1, 1, 1, 1) . '';
170
                            }
171
                        }
172
173
                        echo '' . $myts->displayTarea($results[$i]['desctext'], 1, 1, 1, 1, 1) . '';
174
175
                        echo "</td><td width=\"20%\">";
176
                        echo ''
177
                             . $xoopsModuleConfig['adslight_money']
178
                             . ''
179
                             . $myts->htmlSpecialChars($results[$i]['price'])
180
                             . '</a>&nbsp;'
181
                             . $myts->htmlSpecialChars($results[$i]['typeprice'])
182
                             . '</a>';
183
184
                        echo '</td></tr><tr><td>';
185
                        echo '<small>';
186
                        $results[$i]['uid'] = @(int)$results[$i]['uid'];
187 View Code Duplication
                        if (!empty($results[$i]['uid'])) {
188
                            $uname = XoopsUser::getUnameFromId($results[$i]['uid']);
189
                            echo '&nbsp;&nbsp;' . _ADSLIGHT_FROM . "<a href='" . XOOPS_URL . '/userinfo.php?uid=' . $results[$i]['uid'] . "'>" . $uname . "</a>\n";
190
                        }
191
                        echo !empty($results[$i]['time']) ? ' (' . formatTimestamp((int)$results[$i]['time']) . ')' : '';
192
                        echo '</small>';
193
                        echo '</td></tr></table><table>';
194
                    }
195
                    if ($count >= 5) {
196
                        $search_url = XOOPS_URL . '/modules/adslight/search.php?query=' . urlencode(stripslashes(implode(' ', $queries)));
197
                        $search_url .= "&mid=$mid&action=showall&andor=$andor";
198
                        echo '<br><a href="' . htmlspecialchars($search_url) . '">' . _SR_SHOWALLR . '</a>';
199
                    }
200
                    echo '<table>';
201
                }
202
            }
203
            unset($results);
204
            unset($module);
205
        }
206
        include_once __DIR__ . '/include/searchform.php';
207
        $search_form->display();
208
        break;
209
    case 'showall':
210
    case 'showallbyuser':
211
212
        include XOOPS_ROOT_PATH . '/header.php';
213
214
        // for xoops 2.2.x versions
215
        if (file_exists(__DIR__ . '/language/' . $xoopsConfig['language'] . '/main.php')) {
216
            include_once __DIR__ . '/language/' . $xoopsConfig['language'] . '/main.php';
217
        } else {
218
            include_once __DIR__ . '/language/english/main.php';
219
        }
220
        // end
221
        $xoopsTpl->assign('imgscss', XOOPS_URL . '/modules/adslight/style/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         = count($results);
227
        if (is_array($results) && $count > 0) {
228
            $next_results =& $module->search($queries, $andor, 1, $start + 20, $uid);
229
            $next_count   = count($next_results);
230
            $has_next     = false;
231
            if (is_array($next_results) && $next_count == 1) {
232
                $has_next = true;
233
            }
234
            echo '<h4>' . _ADSLIGHT_SEARCHRESULTS . "</h4>\n";
235
            if ($action === 'showall') {
236
                echo _SR_KEYWORDS . ':';
237
                if ($andor !== 'exact') {
238
                    foreach ($queries as $q) {
239
                        echo ' <strong>' . htmlspecialchars(stripslashes($q)) . '</strong>';
240
                    }
241
                } else {
242
                    echo ' "<strong>' . htmlspecialchars(stripslashes($queries[0])) . '</strong>"';
243
                }
244
                echo '<br><br>';
245
            }
246
            //    printf(_SR_FOUND,$count);
247
            //    echo "<br>";
248
            printf(_SR_SHOWING, $start + 1, $start + $count);
249
            for ($i = 0; $i < $count; ++$i) {
250
                echo "<table width=\"100%\" class=\"outer\"><tr>";
251
                echo "<td width=\"30%\">";
252
                echo '<strong>' . $myts->htmlSpecialChars($results[$i]['type']) . '</strong><br>';
253 View Code Duplication
                if (isset($results[$i]['photo']) && $results[$i]['photo'] != '') {
254
                    echo "<a href='" . $results[$i]['link'] . "'><img class='thumb' src='" . $results[$i]['sphoto'] . "' alt='' width='100' /></a></td>&nbsp;";
255
                } else {
256
                    echo "<a href='" . $results[$i]['link'] . "'><img class='thumb' src='" . $results[$i]['nophoto'] . "' alt='' width='100' /></a></td>&nbsp;";
257
                }
258 View Code Duplication
                if (!preg_match("/^http[s]*:\/\//i", $results[$i]['link'])) {
259
                    $results[$i]['link'] = '' . $results[$i]['link'];
260
                }
261
                echo "<td width=\"50%\">";
262
263
                echo "<strong><a href='" . $results[$i]['link'] . "'>" . $myts->htmlSpecialChars($results[$i]['title']) . '</a></strong><br><br>';
264
265 View Code Duplication
                if (!XOOPS_USE_MULTIBYTES) {
266
                    if (strlen($results[$i]['desctext']) >= 14) {
267
                        $results[$i]['desctext'] = substr($results[$i]['desctext'], 0, 90) . '...';
268
                    }
269
                }
270
271
                echo '' . $myts->htmlSpecialChars($results[$i]['desctext']) . '';
272
273
                echo "</td><td width=\"20%\">";
274
                echo '' . $xoopsModuleConfig['adslight_money'] . '
275
' . $myts->htmlSpecialChars($results[$i]['price']) . '</a>&nbsp;' . $myts->htmlSpecialChars($results[$i]['typeprice']) . '</a>';
276
277
                echo '</td></tr><tr><td>';
278
                echo '<small>';
279
                $results[$i]['uid'] = @(int)$results[$i]['uid'];
280 View Code Duplication
                if (!empty($results[$i]['uid'])) {
281
                    $uname = XoopsUser::getUnameFromId($results[$i]['uid']);
282
                    echo '&nbsp;&nbsp;' . _ADSLIGHT_FROM . "<a href='" . XOOPS_URL . '/userinfo.php?uid=' . $results[$i]['uid'] . "'>" . $uname . '</a><br>';
283
                }
284
                echo !empty($results[$i]['time']) ? ' (' . formatTimestamp((int)$results[$i]['time']) . ')' : '';
285
                echo '</small>';
286
                echo '</td></tr></table><table>';
287
            }
288
289
            echo '
290
        <table>
291
          <tr>
292
        ';
293
            $search_url = XOOPS_URL . '/modules/adslight/search.php?query=' . urlencode(stripslashes(implode(' ', $queries)));
294
            $search_url .= "&mid=$mid&action=$action&andor=$andor";
295
            if ($action === 'showallbyuser') {
296
                $search_url .= "&uid=$uid";
297
            }
298
            if ($start > 0) {
299
                $prev = $start - 20;
300
                echo '<td align="left">
301
            ';
302
                $search_url_prev = $search_url . "&start=$prev";
303
                echo '<a href="' . htmlspecialchars($search_url_prev) . '">' . _SR_PREVIOUS . '</a></td>
304
            ';
305
            }
306
            echo '<td>&nbsp;&nbsp;</td>
307
        ';
308
            if (false != $has_next) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison !== instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
309
                $next            = $start + 20;
310
                $search_url_next = $search_url . "&start=$next";
311
                echo '<td align="right"><a href="' . htmlspecialchars($search_url_next) . '">' . _SR_NEXT . '</a></td>
312
            ';
313
            }
314
            echo '
315
          </tr>
316
        </table>
317
        <p>
318
        ';
319
        } else {
320
            echo '<p>' . _SR_NOMATCH . '</p>';
321
        }
322
        include_once __DIR__ . '/include/searchform.php';
323
        $search_form->display();
324
        echo '</p>
325
    ';
326
        break;
327
}
328
include XOOPS_ROOT_PATH . '/footer.php';
329