Completed
Push — master ( 15a86c...ff0242 )
by Michael
03:23
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
// This program is free software; you can redistribute it and/or modify     //
5
// it under the terms of the GNU General Public License as published by     //
6
// the Free Software Foundation; either version 2 of the License, or        //
7
// (at your option) any later version.                                      //
8
//                                                                          //
9
// You may not change or alter any portion of this comment or credits       //
10
// of supporting developers from this source code or any supporting         //
11
// source code which is considered copyrighted (c) material of the          //
12
// original comment or credit authors.                                      //
13
//                                                                          //
14
// This program is distributed in the hope that it will be useful,          //
15
// but WITHOUT ANY WARRANTY; without even the implied warranty of           //
16
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            //
17
// GNU General Public License for more details.                             //
18
//                                                                          //
19
// You should have received a copy of the GNU General Public License        //
20
// along with this program; if not, write to the Free Software              //
21
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA //
22
// ------------------------------------------------------------------------ //
23
// Author: phppp (D.J., [email protected])                                  //
24
// URL: http://xoops.org                         //
25
// Project: Article Project                                                 //
26
// ------------------------------------------------------------------------ //
27
28
$xoopsOption['pagetype'] = 'search';
29
include __DIR__ . '/header.php';
30
$xoopsModule->loadLanguage('main');
31
$config_handler    = xoops_getHandler('config');
32
$xoopsConfigSearch =& $config_handler->getConfigsByCat(XOOPS_CONF_SEARCH);
33
if (empty($xoopsConfigSearch['enable_search'])) {
34
    redirect_header(XOOPS_URL . '/modules/' . $GLOBALS['moddirname'] . '/index.php', 2, planet_constant('MD_NOACCESS'));
35
}
36
37
$xoopsConfig['module_cache'][$xoopsModule->getVar('mid')] = 0;
38
$xoopsOption['template_main']                             = planet_getTemplate('search');
39
include XOOPS_ROOT_PATH . '/header.php';
40
include XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/include/vars.php';
41
42
include_once XOOPS_ROOT_PATH . '/modules/' . $GLOBALS['moddirname'] . '/include/search.inc.php';
43
$limit = $xoopsModuleConfig['articles_perpage'];
44
45
$queries  = array();
46
$andor    = isset($_POST['andor']) ? $_POST['andor'] : (isset($_GET['andor']) ? $_GET['andor'] : '');
47
$start    = isset($_GET['start']) ? $_GET['start'] : 0;
48
$category = (int)(isset($_POST['category']) ? $_POST['category'] : (isset($_GET['category']) ? $_GET['category'] : null));
49
$blog     = (int)(isset($_POST['blog']) ? $_POST['blog'] : (isset($_GET['blog']) ? $_GET['blog'] : null));
50
$uid      = (int)(isset($_POST['uid']) ? $_POST['uid'] : (isset($_GET['uid']) ? $_GET['uid'] : null));
51
$searchin = isset($_POST['searchin']) ? $_POST['searchin'] : (isset($_GET['searchin']) ? explode('|',
52
                                                                                                 $_GET['searchin']) : array());
53
$sortby   = isset($_POST['sortby']) ? $_POST['sortby'] : (isset($_GET['sortby']) ? $_GET['sortby'] : null);
54
$term     = isset($_POST['term']) ? $_POST['term'] : (isset($_GET['term']) ? $_GET['term'] : '');
55
56
$andor  = in_array(strtoupper($andor), array('OR', 'AND', 'EXACT')) ? strtoupper($andor) : 'OR';
57
$sortby = in_array(strtolower($sortby), array(
58
    'a.art_id desc',
59
    'a.art_time desc',
60
    'a.art_title',
61
    'a.blog_id',
62
    'b.blog_id',
63
    'b.blog_feed',
64
    'b.blog_title',
65
    'b.blog_time'
66
)) ? strtolower($sortby) : '';
67
68
if (!(empty($_POST['submit']) && empty($_GET['term']))) {
69
    $next_search['category'] = $category;
70
    $next_search['blog']     = $blog;
71
    $next_search['uid']      = $uid;
72
    $next_search['andor']    = $andor;
73
74
    $next_search['term'] = $term;
75
    $query               = trim($term);
76
77
    if ($andor !== 'EXACT') {
78
        $ignored_queries = array(); // holds kewords that are shorter than allowed minmum length
79
        $temp_queries    = preg_split("/[\s,]+/", $query);
80
        foreach ($temp_queries as $q) {
81
            $q = trim($q);
82
            if (strlen($q) >= $xoopsConfigSearch['keyword_min']) {
83
                $queries[] = $myts->addSlashes($q);
84
            } else {
85
                $ignored_queries[] = $myts->addSlashes($q);
86
            }
87
        }
88 View Code Duplication
        if (count($queries) == 0) {
89
            redirect_header(XOOPS_URL . '/modules/' . $GLOBALS['moddirname'] . '/search.php', 2,
90
                            sprintf(_SR_KEYTOOSHORT, $xoopsConfigSearch['keyword_min']));
91
        }
92
    } else {
93 View Code Duplication
        if (strlen($query) < $xoopsConfigSearch['keyword_min']) {
94
            redirect_header(XOOPS_URL . '/modules/' . $GLOBALS['moddirname'] . '/search.php', 2,
95
                            sprintf(_SR_KEYTOOSHORT, $xoopsConfigSearch['keyword_min']));
96
        }
97
        $queries = array($myts->addSlashes($query));
98
    }
99
100
    $next_search['sortby']   = $sortby;
101
    $next_search['searchin'] = implode('|', $searchin);
102
103
    /* To be added: year-month
104
     * see view.archive.php
105
     */
106
    if (!empty($time)) {
107
        $extra = '';
108
    } else {
109
        $extra = '';
110
    }
111
112
    $results = planet_search($queries, $andor, $limit, $start, $uid, $category, $blog, $sortby, $searchin, $extra);
113
114
    /*
0 ignored issues
show
Unused Code Comprehensibility introduced by
52% 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...
115
    if ( count($results) < 1 ) {
116
        redirect_header("javascript:history.go(-1);", 2, _SR_NOMATCH);
117
    } else
118
    */
119
    {
120
        $xoopsTpl->assign('results', $results);
121
122
        if (count($next_search) > 0) {
123
            $items = array();
124
            foreach ($next_search as $para => $val) {
125
                if (!empty($val)) {
126
                    $items[] = "$para=$val";
127
                }
128
            }
129
            if (count($items) > 0) {
130
                $paras = implode('&', $items);
131
            }
132
            unset($next_search);
133
            unset($items);
134
        }
135
        $search_url = XOOPS_URL . '/modules/' . $GLOBALS['moddirname'] . '/search.php?' . $paras;
136
137
        /*
0 ignored issues
show
Unused Code Comprehensibility introduced by
55% 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...
138
         $next_results =& planet_search($queries, $andor, 1, $start + $limit, $uid, $category, $sortby, $searchin, $extra);
139
      $next_count = count($next_results);
140
      $has_next = false;
141
      if (is_array($next_results) && $next_count >0) {
142
          $has_next = true;
143
      }
144
      if (false != $has_next)
145
      */
146
        if (count($results)) {
147
            $next            = $start + $limit;
148
            $queries         = implode(',', $queries);
149
            $search_url_next = $search_url . "&start=$next";
150
            $search_next     = "<a href=\"" . htmlspecialchars($search_url_next) . "\">" . _SR_NEXT . '</a>';
151
            $xoopsTpl->assign('search_next', $search_next);
152
        }
153
        if ($start > 0) {
154
            $prev            = $start - $limit;
155
            $search_url_prev = $search_url . "&start=$prev";
156
            $search_prev     = "<a href=\"" . htmlspecialchars($search_url_prev) . "\">" . _SR_PREVIOUS . '</a>';
157
            $xoopsTpl->assign('search_prev', $search_prev);
158
        }
159
    }
160
161
    unset($results);
162
    $search_info = _SR_KEYWORDS . ': ' . $myts->htmlSpecialChars($term);
163
    $xoopsTpl->assign('search_info', $search_info);
164
}
165
166
/* type */
167
$type_select = "<select name=\"andor\">";
168
$type_select .= "<option value=\"OR\"";
169
if ('OR' === $andor) {
170
    $type_select .= " selected=\"selected\"";
171
}
172
$type_select .= '>' . _SR_ANY . '</option>';
173
$type_select .= "<option value=\"AND\"";
174
if ('AND' === $andor) {
175
    $type_select .= " selected=\"selected\"";
176
}
177
$type_select .= '>' . _SR_ALL . '</option>';
178
$type_select .= "<option value=\"EXACT\"";
179
if ('exact' === $andor) {
180
    $type_select .= " selected=\"selected\"";
181
}
182
$type_select .= '>' . _SR_EXACT . '</option>';
183
$type_select .= '</select>';
184
185
/* scope */
186
$searchin_select = '';
187
$searchin_select .= "<input type=\"checkbox\" name=\"searchin[]\" value=\"title\"";
188
if (in_array('title', $searchin)) {
189
    $searchin_select .= ' checked';
190
}
191
$searchin_select .= ' />' . planet_constant('MD_TITLE') . '&nbsp;&nbsp;';
192
$searchin_select .= "<input type=\"checkbox\" name=\"searchin[]\" value=\"text\"";
193
if (in_array('text', $searchin)) {
194
    $searchin_select .= ' checked';
195
}
196
$searchin_select .= ' />' . planet_constant('MD_BODY') . '&nbsp;&nbsp;||&nbsp;&nbsp;';
197
$searchin_select .= "<input type=\"checkbox\" name=\"searchin[]\" value=\"blog\"";
198
if (in_array('blog', $searchin)) {
199
    $searchin_select .= ' checked';
200
}
201
$searchin_select .= ' />' . planet_constant('MD_BLOG') . '&nbsp;&nbsp;';
202
$searchin_select .= "<input type=\"checkbox\" name=\"searchin[]\" value=\"feed\"";
203
if (in_array('feed', $searchin)) {
204
    $searchin_select .= ' checked';
205
}
206
$searchin_select .= ' />' . planet_constant('MD_FEED') . '&nbsp;&nbsp;';
207
$searchin_select .= "<input type=\"checkbox\" name=\"searchin[]\" value=\"desc\"";
208
if (in_array('desc', $searchin)) {
209
    $searchin_select .= ' checked';
210
}
211
$searchin_select .= ' />' . planet_constant('MD_DESC') . '&nbsp;&nbsp;';
212
$searchin_select .= "<input type=\"checkbox\" name=\"searchin[]\" value=\"all\"";
213
if (empty($searchin)) {
214
    $searchin_select .= ' checked';
215
}
216
$searchin_select .= ' />' . _ALL . '&nbsp;&nbsp;';
217
218
/* sortby */
219
$sortby_select = "<select name=\"sortby\">";
220
$sortby_select .= "<option value=\"\"";
221
if (empty($sortby)) {
222
    $sortby_select .= " selected=\"selected\"";
223
}
224
$sortby_select .= '>' . _NONE . '</option>';
225
$sortby_select .= "<option value=\"a.art_time\"";
226
if ('a.art_time' === $sortby) {
227
    $sortby_select .= " selected=\"selected\"";
228
}
229
$sortby_select .= '>' . planet_constant('MD_TIME') . '</option>';
230
$sortby_select .= "<option value=\"a.art_title\"";
231
if ('a.art_title' === $sortby) {
232
    $sortby_select .= " selected=\"selected\"";
233
}
234
$sortby_select .= '>' . planet_constant('MD_TITLE') . '</option>';
235
$sortby_select .= "<option value=\"\">&nbsp;&nbsp;----&nbsp;&nbsp;</option>";
236
$sortby_select .= "<option value=\"a.blog_title\"";
237
if ('a.blog_title' === $sortby) {
238
    $sortby_select .= " selected=\"selected\"";
239
}
240
$sortby_select .= '>' . planet_constant('MD_BLOG') . '</option>';
241
$sortby_select .= "<option value=\"a.blog_time\"";
242
if ('b.blog_time' === $sortby) {
243
    $sortby_select .= " selected=\"selected\"";
244
}
245
$sortby_select .= '>' . planet_constant('MD_UPDATE') . '</option>';
246
$sortby_select .= '</select>';
247
248
$xoopsTpl->assign('type_select', $type_select);
249
$xoopsTpl->assign('searchin_select', $searchin_select);
250
$xoopsTpl->assign('sortby_select', $sortby_select);
251
$xoopsTpl->assign('search_term', $term);
252
253
$xoopsTpl->assign('modname', $xoopsModule->getVar('name'));
254
255
$xoopsTpl->assign('category', $category);
256
$xoopsTpl->assign('blog', $blog);
257
$xoopsTpl->assign('uid', $uid);
258
259
if ($xoopsConfigSearch['keyword_min'] > 0) {
260
    $xoopsTpl->assign('search_rule', sprintf(_SR_KEYIGNORE, $xoopsConfigSearch['keyword_min']));
261
}
262
263
include XOOPS_ROOT_PATH . '/footer.php';
264