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: https://xoops.org // |
||
25 | // Project: Article Project // |
||
26 | // ------------------------------------------------------------------------ // |
||
27 | include __DIR__ . '/header.php'; |
||
28 | |||
29 | if (preg_match("/\/notification_update\.php/i", $_SERVER['REQUEST_URI'], $matches)) { |
||
30 | include XOOPS_ROOT_PATH . '/include/notification_update.php'; |
||
31 | exit(); |
||
32 | } |
||
33 | |||
34 | View Code Duplication | if ($REQUEST_URI_parsed = PlanetUtility::planetParseArguments($args_num, $args, $args_str)) { |
|
0 ignored issues
–
show
|
|||
35 | $args['start'] = @$args_num[0]; |
||
36 | $args['sort'] = @$args_str[0]; |
||
37 | } |
||
38 | |||
39 | /* Start */ |
||
40 | $start = (int)(empty($_GET['start']) ? @$args['start'] : $_GET['start']); |
||
41 | /* Specified Category */ |
||
42 | $category_id = (int)(empty($_GET['category']) ? @$args['category'] : $_GET['category']); |
||
43 | /* Specified Blog */ |
||
44 | $blog_id = (int)(empty($_GET['blog']) ? @$args['blog'] : $_GET['blog']); |
||
45 | /* Specified Bookmar(Favorite) UID */ |
||
46 | $uid = (int)(empty($_GET['uid']) ? @$args['uid'] : $_GET['uid']); |
||
47 | /* Sort by term */ |
||
48 | $sort = empty($_GET['sort']) ? @$args['sort'] : $_GET['sort']; |
||
49 | /* Display as list */ |
||
50 | $list = (int)(empty($_GET['list']) ? @$args['list'] : $_GET['list']); |
||
51 | |||
52 | // restore $_SERVER['REQUEST_URI'] |
||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
58% 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. ![]() |
|||
53 | if (!empty($REQUEST_URI_parsed)) { |
||
54 | $args_REQUEST_URI = []; |
||
55 | $_args = ['start', 'sort', 'uid', 'list']; |
||
56 | foreach ($_args as $arg) { |
||
57 | if (!empty(${$arg})) { |
||
58 | $args_REQUEST_URI[] = $arg . '=' . ${$arg}; |
||
59 | } |
||
60 | } |
||
61 | if (!empty($blog_id)) { |
||
62 | $args_REQUEST_URI[] = 'blog=' . $blog_id; |
||
63 | } |
||
64 | if (!empty($category_id)) { |
||
65 | $args_REQUEST_URI[] = 'category=' . $category_id; |
||
66 | } |
||
67 | $_SERVER['REQUEST_URI'] = XOOPS_URL . '/modules/' . $GLOBALS['moddirname'] . '/index.php' . (empty($args_REQUEST_URI) ? '' : '?' . implode('&', $args_REQUEST_URI)); |
||
68 | } |
||
69 | |||
70 | $GLOBALS['xoopsOption']['template_main'] = PlanetUtility::planetGetTemplate('index'); |
||
71 | $xoops_module_header = ' |
||
72 | <link rel="alternate" type="application/rss+xml" title="' . $xoopsModule->getVar('name') . ' rss" href="' . XOOPS_URL . '/modules/' . $GLOBALS['moddirname'] . '/xml.php".URL_DELIMITER."rss/c' . $category_id . '/b' . $blog_id . '/u' . $uid . '"> |
||
73 | <link rel="alternate" type="application/rss+xml" title="' . $xoopsModule->getVar('name') . ' rdf" href="' . XOOPS_URL . '/modules/' . $GLOBALS['moddirname'] . '/xml.php".URL_DELIMITER."rdf/c' . $category_id . '/b' . $blog_id . '/u' . $uid . '"> |
||
74 | <link rel="alternate" type="application/atom+xml" title="' . $xoopsModule->getVar('name') . ' atom" href="' . XOOPS_URL . '/modules/' . $GLOBALS['moddirname'] . '/xml.php".URL_DELIMITER."atom/c' . $category_id . '/b' . $blog_id . '/u' . $uid . '"> |
||
75 | '; |
||
76 | |||
77 | $xoopsOption['xoops_module_header'] = $xoops_module_header; |
||
78 | require_once XOOPS_ROOT_PATH . '/header.php'; |
||
79 | include XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/include/vars.php'; |
||
80 | |||
81 | // Following part will not be executed after cache |
||
82 | $categoryHandler = xoops_getModuleHandler('category', $GLOBALS['moddirname']); |
||
83 | $blogHandler = xoops_getModuleHandler('blog', $GLOBALS['moddirname']); |
||
84 | $articleHandler = xoops_getModuleHandler('article', $GLOBALS['moddirname']); |
||
85 | |||
86 | $limit = empty($list) ? $xoopsModuleConfig['articles_perpage'] : $xoopsModuleConfig['list_perpage']; |
||
87 | $query_type = ''; |
||
88 | $criteria = new CriteriaCompo(); |
||
89 | $article_prefix = ''; |
||
90 | /* Specific category */ |
||
91 | View Code Duplication | if ($category_id > 0) { |
|
0 ignored issues
–
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. ![]() |
|||
92 | $category_obj = $categoryHandler->get($category_id); |
||
93 | $criteria->add(new Criteria('bc.cat_id', $category_id)); |
||
94 | $uid = 0; |
||
95 | $blog_id = 0; |
||
96 | $category_data = ['id' => $category_id, 'title' => $category_obj->getVar('cat_title')]; |
||
97 | $query_type = 'category'; |
||
98 | $article_prefix = 'a.'; |
||
99 | } |
||
100 | /* Specific blog */ |
||
101 | if ($blog_id > 0) { |
||
102 | $blog_obj = $blogHandler->get($blog_id); |
||
103 | if ($blog_obj->getVar('blog_status') |
||
104 | || (is_object($xoopsUser) |
||
105 | && $xoopsUser->getVar('uid') == $blog_obj->getVar('blog_submitter'))) { |
||
106 | $criteria->add(new Criteria('blog_id', $blog_id)); |
||
107 | $category_id = 0; |
||
108 | $uid = 0; |
||
109 | $bookmarkHandler = xoops_getModuleHandler('bookmark', $GLOBALS['moddirname']); |
||
110 | $blog_data = [ |
||
111 | 'id' => $blog_id, |
||
112 | 'title' => $blog_obj->getVar('blog_title'), |
||
113 | 'image' => $blog_obj->getImage(), |
||
114 | 'title' => $blog_obj->getVar('blog_title'), |
||
115 | 'feed' => $blog_obj->getVar('blog_feed'), |
||
116 | 'link' => $blog_obj->getVar('blog_link'), |
||
117 | 'desc' => $blog_obj->getVar('blog_desc'), |
||
118 | 'time' => $blog_obj->getTime(), |
||
119 | 'star' => $blog_obj->getStar(), |
||
120 | 'rates' => $blog_obj->getVar('blog_rates'), |
||
121 | 'marks' => $blog_obj->getVar('blog_marks') |
||
122 | ]; |
||
123 | } |
||
124 | $query_type = 'blog'; |
||
125 | $article_prefix = ''; |
||
126 | } |
||
127 | /* User bookmarks(favorites) */ |
||
128 | View Code Duplication | if ($uid > 0) { |
|
0 ignored issues
–
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. ![]() |
|||
129 | $criteria->add(new Criteria('bm.bm_uid', $uid)); |
||
130 | $category_id = 0; |
||
131 | $blog_id = 0; |
||
132 | $bookmarkHandler = xoops_getModuleHandler('bookmark', $GLOBALS['moddirname']); |
||
133 | $user_data = [ |
||
134 | 'uid' => $uid, |
||
135 | 'name' => XoopsUser::getUnameFromId($uid), |
||
136 | 'marks' => $bookmarkHandler->getCount(new Criteria('bm_uid', $uid)) |
||
137 | ]; |
||
138 | $query_type = 'bookmark'; |
||
139 | $article_prefix = 'a.'; |
||
140 | } |
||
141 | |||
142 | /* Sort */ |
||
143 | $order = 'DESC'; |
||
144 | $sort = empty($sort) ? 'time' : $sort; |
||
145 | switch ($sort) { |
||
146 | case 'views': |
||
147 | $sortby = $article_prefix . 'art_views'; |
||
148 | break; |
||
149 | case 'rating': |
||
150 | $sortby = $article_prefix . 'art_rating'; |
||
151 | break; |
||
152 | case 'time': |
||
153 | $sortby = $article_prefix . 'art_time'; |
||
154 | break; |
||
155 | case 'default': |
||
156 | default: |
||
157 | $sortby = ''; |
||
158 | break; |
||
159 | } |
||
160 | $criteria->setSort($sortby); |
||
161 | $criteria->setOrder($order); |
||
162 | $criteria->setStart($start); |
||
163 | $criteria->setLimit($limit); |
||
164 | |||
165 | $tags = empty($list) ? '' : [ |
||
166 | $article_prefix . 'art_title', |
||
167 | $article_prefix . 'blog_id', |
||
168 | $article_prefix . 'art_time' |
||
169 | ]; |
||
170 | View Code Duplication | switch ($query_type) { |
|
0 ignored issues
–
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. ![]() |
|||
171 | case 'category': |
||
172 | $articles_obj = $articleHandler->getByCategory($criteria, $tags); |
||
173 | $count_article = $articleHandler->getCountByCategory($criteria); |
||
174 | break; |
||
175 | case 'bookmark': |
||
176 | $articles_obj = $articleHandler->getByBookmark($criteria, $tags); |
||
177 | $count_article = $articleHandler->getCountByBookmark($criteria); |
||
178 | break; |
||
179 | default: |
||
180 | $articles_obj = $articleHandler->getAll($criteria, $tags); |
||
181 | $count_article = $articleHandler->getCount($criteria); |
||
182 | break; |
||
183 | } |
||
184 | |||
185 | if (!empty($blog_data)) { |
||
186 | $blogs[$blog_data['id']] = $blog_data['title']; |
||
187 | } else { |
||
188 | $blog_array = []; |
||
189 | foreach (array_keys($articles_obj) as $id) { |
||
190 | $blog_array[$articles_obj[$id]->getVar('blog_id')] = 1; |
||
191 | } |
||
192 | $criteria_blog = new Criteria('blog_id', '(' . implode(',', array_keys($blog_array)) . ')', 'IN'); |
||
193 | $blogs = $blogHandler->getList($criteria_blog); |
||
194 | } |
||
195 | |||
196 | /* Objects to array */ |
||
197 | $articles = []; |
||
198 | foreach (array_keys($articles_obj) as $id) { |
||
199 | $_article = [ |
||
200 | 'id' => $id, |
||
201 | 'title' => $articles_obj[$id]->getVar('art_title'), |
||
202 | 'time' => $articles_obj[$id]->getTime(), |
||
203 | 'blog' => [ |
||
204 | 'id' => $articles_obj[$id]->getVar('blog_id'), |
||
205 | 'title' => $blogs[$articles_obj[$id]->getVar('blog_id')] |
||
206 | ] |
||
207 | ]; |
||
208 | if (empty($list)) { |
||
209 | $_article = array_merge($_article, [ |
||
210 | 'author' => $articles_obj[$id]->getVar('art_author'), |
||
211 | 'views' => $articles_obj[$id]->getVar('art_views'), |
||
212 | 'comments' => $articles_obj[$id]->getVar('art_comments'), |
||
213 | 'star' => $articles_obj[$id]->getStar(), |
||
214 | 'rates' => $articles_obj[$id]->getVar('art_rates') |
||
215 | ]); |
||
216 | if (!empty($xoopsModuleConfig['display_summary'])) { |
||
217 | $_article['content'] = $articles_obj[$id]->getSummary(); |
||
218 | } else { |
||
219 | $_article['content'] = $articles_obj[$id]->getVar('art_content'); |
||
220 | } |
||
221 | } |
||
222 | $articles[] = $_article; |
||
223 | unset($_article); |
||
224 | } |
||
225 | unset($articles_obj); |
||
226 | |||
227 | if ($count_article > $limit) { |
||
228 | include XOOPS_ROOT_PATH . '/class/pagenav.php'; |
||
229 | $start_link = []; |
||
230 | if ($sort) { |
||
231 | $start_link[] = 'sort=' . $sort; |
||
232 | } |
||
233 | if ($category_id) { |
||
234 | $start_link[] = 'category=' . $category_id; |
||
235 | } |
||
236 | if ($blog_id) { |
||
237 | $start_link[] = 'blog=' . $blog_id; |
||
238 | } |
||
239 | if ($list) { |
||
240 | $start_link[] = 'list=' . $list; |
||
241 | } |
||
242 | $nav = new XoopsPageNav($count_article, $limit, $start, 'start', implode('&', $start_link)); |
||
243 | $pagenav = $nav->renderNav(4); |
||
244 | } else { |
||
245 | $pagenav = ''; |
||
246 | } |
||
247 | |||
248 | $xoopsTpl->assign('xoops_module_header', $xoops_module_header); |
||
249 | $xoopsTpl->assign('dirname', $GLOBALS['moddirname']); |
||
250 | |||
251 | if ($category_id || $blog_id || $uid) { |
||
252 | $xoopsTpl->assign('link_index', "<a href=\"" . XOOPS_URL . '/modules/' . $GLOBALS['moddirname'] . "/index.php\" title=\"" . planet_constant('MD_INDEX') . "\" target=\"_self\">" . planet_constant('MD_INDEX') . '</a>'); |
||
253 | } |
||
254 | |||
255 | $link_switch = "<a href=\"" |
||
256 | . XOOPS_URL |
||
257 | . '/modules/' |
||
258 | . $GLOBALS['moddirname'] |
||
259 | . '/index.php' |
||
260 | . (empty($category_id) ? '' : '/c' . $category_id) |
||
261 | . (empty($uid) ? '' : '/u' . $uid) |
||
262 | . (empty($blog_id) ? '' : '/b' . $blog_id) |
||
263 | . (empty($list) ? '/l1' : '') |
||
264 | . "\" title=\"" |
||
265 | . (empty($list) ? planet_constant('MD_LISTVIEW') : planet_constant('MD_FULLVIEW')) |
||
266 | . "\">" |
||
267 | . (empty($list) ? planet_constant('MD_LISTVIEW') : planet_constant('MD_FULLVIEW')) |
||
268 | . '</a>'; |
||
269 | $xoopsTpl->assign('link_switch', $link_switch); |
||
270 | |||
271 | $link_blogs = "<a href=\"" . XOOPS_URL . '/modules/' . $GLOBALS['moddirname'] . '/view.blogs.php' . (empty($category_id) ? '' : '/c' . $category_id) . (empty($uid) ? '' : '/u' . $uid) . "\" title=\"" . planet_constant('MD_BLOGS') . "\">" . planet_constant('MD_BLOGS') . '</a>'; |
||
272 | $xoopsTpl->assign('link_blogs', $link_blogs); |
||
273 | |||
274 | View Code Duplication | if (empty($uid) && is_object($xoopsUser)) { |
|
0 ignored issues
–
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. ![]() |
|||
275 | $xoopsTpl->assign('link_bookmark', "<a href=\"" . XOOPS_URL . '/modules/' . $GLOBALS['moddirname'] . '/index.php' . URL_DELIMITER . 'u' . $xoopsUser->getVar('uid') . "\" title=\"" . planet_constant('MD_BOOKMARKS') . "\" target=\"_self\">" . planet_constant('MD_BOOKMARKS') . '</a>'); |
||
276 | } |
||
277 | |||
278 | View Code Duplication | if (1 == $xoopsModuleConfig['newblog_submit'] || is_object($xoopsUser)) { |
|
0 ignored issues
–
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. ![]() |
|||
279 | $xoopsTpl->assign('link_submit', "<a href=\"" . XOOPS_URL . '/modules/' . $GLOBALS['moddirname'] . "/action.blog.php\" title=\"" . _SUBMIT . "\" target=\"_blank\">" . _SUBMIT . '</a>'); |
||
280 | } |
||
281 | |||
282 | $xoopsTpl->assign('pagetitle', $xoopsModule->getVar('name') . '::' . planet_constant('MD_ARTICLES')); |
||
283 | $xoopsTpl->assign('category', @$category_data); |
||
284 | $xoopsTpl->assign('blog', @$blog_data); |
||
285 | $xoopsTpl->assign('user', @$user_data); |
||
286 | $xoopsTpl->assign('articles', $articles); |
||
287 | $xoopsTpl->assign('pagenav', $pagenav); |
||
288 | $xoopsTpl->assign('is_list', !empty($list)); |
||
289 | |||
290 | $xoopsTpl->assign('user_level', !is_object($xoopsUser) ? 0 : ($xoopsUser->isAdmin() ? 2 : 1)); |
||
291 | View Code Duplication | if (empty($xoopsModuleConfig['anonymous_rate']) && !is_object($xoopsUser)) { |
|
0 ignored issues
–
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. ![]() This
if statement is empty and can be removed.
This check looks for the bodies of These if (rand(1, 6) > 3) {
//print "Check failed";
} else {
print "Check succeeded";
}
could be turned into if (rand(1, 6) <= 3) {
print "Check succeeded";
}
This is much more concise to read. ![]() |
|||
292 | } elseif ($blog_id > 0) { |
||
293 | $xoopsTpl->assign('canrate', 1); |
||
294 | } |
||
295 | |||
296 | $sort_link = XOOPS_URL . '/modules/' . $GLOBALS['moddirname'] . '/index.php' . (empty($category_id) ? '' : '/c' . $category_id) . (empty($uid) ? '' : '/u' . $uid) . (empty($blog_id) ? '' : '/b' . $blog_id) . (empty($list) ? '' : '/l1'); |
||
297 | $valid_sorts = [ |
||
298 | 'views' => planet_constant('MD_VIEWS'), |
||
299 | 'rating' => planet_constant('MD_RATING'), |
||
300 | 'time' => planet_constant('MD_TIME'), |
||
301 | 'default' => planet_constant('MD_DEFAULT') |
||
302 | ]; |
||
303 | $sortlinks = []; |
||
304 | View Code Duplication | foreach ($valid_sorts as $val => $name) { |
|
0 ignored issues
–
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. ![]() |
|||
305 | if ($val == $sort) { |
||
306 | continue; |
||
307 | } |
||
308 | $sortlinks[] = "<a href=\"" . $sort_link . '/' . $val . "\">" . $name . '</a>'; |
||
309 | } |
||
310 | $xoopsTpl->assign('link_sort', implode(' | ', $sortlinks)); |
||
311 | $xoopsTpl->assign('version', $xoopsModule->getVar('version')); |
||
312 | |||
313 | $xoopsTpl->assign('do_pseudocron', $xoopsModuleConfig['do_pseudocron']); |
||
314 | |||
315 | // for notification |
||
316 | if (!empty($blog_id)) { |
||
317 | //$_SERVER['REQUEST_URI'] = XOOPS_URL."/modules/".$GLOBALS["moddirname"]."/index.php"; |
||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
62% 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. ![]() |
|||
318 | $_GET['blog'] = $blog_id; |
||
319 | } |
||
320 | |||
321 | require_once __DIR__ . '/footer.php'; |
||
322 |
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.