Completed
Push — master ( 7c5656...a50592 )
by Michael
01:55
created

view.blogs.php (15 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: https://xoops.org                         //
25
// Project: Article Project                                                 //
26
// ------------------------------------------------------------------------ //
27
use Xmf\Request;
28
29
include __DIR__ . '/header.php';
30
31 View Code Duplication
if (preg_match("/\/notification_update\.php/i", Request::getUrl('REQUEST_URI', '', 'SERVER'), $matches)) {
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.

Loading history...
32
    include XOOPS_ROOT_PATH . '/include/notification_update.php';
33
    exit();
34
}
35
36 View Code Duplication
if ($REQUEST_URI_parsed = PlanetUtility::planetParseArguments($args_num, $args, $args_str)) {
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.

Loading history...
37
    $args['start'] = @$args_num[0];
38
    $args['sort']  = @$args_str[0];
39
}
40
41
/* Start */
42
$start = Request::getInt('start', @$args['start'], 'GET'); //(int)(empty($_GET['start']) ? @$args['start'] : $_GET['start']);
0 ignored issues
show
Unused Code Comprehensibility introduced by
71% 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...
43
/* Specified Category */
44
$category_id = Request::getInt('category', @$args['category'], 'GET'); //(int)(empty($_GET['category']) ? @$args['category'] : $_GET['category']);
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...
45
/* Specified Bookmar(Favorite) UID */
46
$uid = Request::getInt('uid', @$args['uid'], 'GET'); //(int)(empty($_GET['uid']) ? @$args['uid'] : $_GET['uid']);
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...
47
/* Sort by term */
48
$sort = Request::getString('sort', @$args['sort'], 'GET'); // empty($_GET['sort']) ? @$args['sort'] : $_GET['sort'];
0 ignored issues
show
Unused Code Comprehensibility introduced by
68% 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...
49
/* Display as list */
50
$list = Request::getInt('list', @$args['list'], 'GET'); //(int)(empty($_GET['list']) ? @$args['list'] : $_GET['list']);
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...
51
/*
52
// restore $_SERVER['REQUEST_URI']
53
if (!empty($REQUEST_URI_parsed)) {
54
    $args_REQUEST_URI = array();
55
    $_args =array("start", "sort", "uid", "list");
56
    foreach ($_args as $arg) {
57
        if (!empty(${$arg})) {
58
            $args_REQUEST_URI[] = $arg ."=". ${$arg};
59
        }
60
    }
61
    if (!empty($category_id)) {
62
        $args_REQUEST_URI[] = "category=". $category_id;
63
    }
64
    $_SERVER['REQUEST_URI'] = XOOPS_URL."/modules/".$GLOBALS["moddirname"]."/view.blogs.php".
65
        (empty($args_REQUEST_URI)?"":"?".implode("&",$args_REQUEST_URI));
66
}
67
*/
68
69
$xoopsOption['xoops_pagetitle'] = $xoopsModule->getVar('name') . ' - ' . planet_constant('MD_BLOGS');
70
$xoopsOption['template_main']   = PlanetUtility::planetGetTemplate('blogs');
71
require_once XOOPS_ROOT_PATH . '/header.php';
72
include XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/include/vars.php';
73
74
// Following part will not be executed after cache
75
$categoryHandler = xoops_getModuleHandler('category', $GLOBALS['moddirname']);
76
$blogHandler     = xoops_getModuleHandler('blog', $GLOBALS['moddirname']);
77
78
$limit = empty($list) ? $xoopsModuleConfig['articles_perpage'] : $xoopsModuleConfig['list_perpage'];
79
80
$query_type  = '';
81
$criteria    = new CriteriaCompo();
82
$blog_prefix = '';
83
/* Specific category */
84 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.

Loading history...
85
    $category_obj = $categoryHandler->get($category_id);
86
    $criteria->add(new Criteria('bc.cat_id', $category_id));
87
    $uid           = 0;
88
    $blog_id       = 0;
89
    $category_data = ['id' => $category_id, 'title' => $category_obj->getVar('cat_title')];
90
    $query_type    = 'category';
91
    $blog_prefix   = 'b.';
92
}
93
94
/* User bookmarks(favorites) */
95 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.

Loading history...
96
    $criteria->add(new Criteria('bm.bm_uid', $uid));
97
    $category_id     = 0;
98
    $blog_id         = 0;
99
    $bookmarkHandler = xoops_getModuleHandler('bookmark', $GLOBALS['moddirname']);
100
    $user_data       = [
101
        'uid'   => $uid,
102
        'name'  => XoopsUser::getUnameFromId($uid),
103
        'marks' => $bookmarkHandler->getCount(new Criteria('bm_uid', $uid))
104
    ];
105
    $query_type      = 'bookmark';
106
    $blog_prefix     = 'b.';
107
}
108
109
$criteria->add(new Criteria($blog_prefix . 'blog_status', 0, '>'));
110
111
/* Sort */
112
$order = 'DESC';
113
$sort  = empty($sort) ? 'default' : $sort;
114
switch ($sort) {
115
    case 'marks':
116
        $sortby = $blog_prefix . 'blog_marks';
117
        break;
118
    case 'rating':
119
        $sortby = $blog_prefix . 'blog_rating';
120
        break;
121
    case 'time':
122
        $sortby = $blog_prefix . 'blog_time';
123
        break;
124
    case 'default':
125
    default:
126
        $sort   = 'default';
127
        $sortby = $blog_prefix . 'blog_id';
128
        break;
129
}
130
$criteria->setSort($sortby);
131
$criteria->setOrder($order);
132
$criteria->setStart($start);
133
$criteria->setLimit($limit);
134
135
$tags = empty($list) ? '' : [$blog_prefix . 'blog_title', $blog_prefix . 'blog_time'];
136 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.

Loading history...
137
    case 'category':
138
        $blogs_obj  = $blogHandler->getByCategory($criteria, $tags);
139
        $count_blog = $blogHandler->getCountByCategory($criteria);
140
        break;
141
    case 'bookmark':
142
        $blogs_obj  = $blogHandler->getByBookmark($criteria, $tags);
143
        $count_blog = $blogHandler->getCountByBookmark($criteria);
144
        break;
145
    default:
146
        $blogs_obj  = $blogHandler->getAll($criteria, $tags);
147
        $count_blog = $blogHandler->getCount($criteria);
148
        break;
149
}
150
151
/* Objects to array */
152
$blogs = [];
153
foreach (array_keys($blogs_obj) as $id) {
154
    $_blog = [
155
        'id'    => $id,
156
        'title' => $blogs_obj[$id]->getVar('blog_title'),
157
        'time'  => $blogs_obj[$id]->getTime()
158
    ];
159
    if (empty($list)) {
160
        $_blog = array_merge($_blog, [
161
            'image' => $blogs_obj[$id]->getImage(),
162
            'feed'  => $blogs_obj[$id]->getVar('blog_feed'),
163
            'link'  => $blogs_obj[$id]->getVar('blog_link'),
164
            'desc'  => $blogs_obj[$id]->getVar('blog_desc'),
165
            'star'  => $blogs_obj[$id]->getStar(),
166
            'rates' => $blogs_obj[$id]->getVar('blog_rates'),
167
            'marks' => $blogs_obj[$id]->getVar('blog_marks')
168
        ]);
169
    }
170
    $blogs[] = $_blog;
171
    unset($_blog);
172
}
173
unset($blogs_obj);
174
175
if ($count_blog > $limit) {
176
    include XOOPS_ROOT_PATH . '/class/pagenav.php';
177
    $start_link = [];
178
    if ($sort) {
179
        $start_link[] = 'sort=' . $sort;
180
    }
181
    if ($category_id) {
182
        $start_link[] = 'category=' . $category_id;
183
    }
184
    if ($list) {
185
        $start_link[] = 'list=' . $list;
186
    }
187
    $nav     = new XoopsPageNav($count_blog, $limit, $start, 'start', implode('&amp;', $start_link));
188
    $pagenav = $nav->renderNav(4);
189
} else {
190
    $pagenav = '';
191
}
192
193
$xoopsTpl->assign('xoops_pagetitle', $xoopsOption['xoops_pagetitle']);
194
$xoopsTpl->assign('link_home', "<a href=\"" . XOOPS_URL . '/modules/' . $GLOBALS['moddirname'] . "/index.php\" title=\"" . planet_constant('MD_HOME') . "\" target=\"_self\">" . planet_constant('MD_HOME') . '</a>');
195
196
if ($category_id || $uid) {
197
    $xoopsTpl->assign('link_index', "<a href=\"" . XOOPS_URL . '/modules/' . $GLOBALS['moddirname'] . "/view.blogs.php\" title=\"" . planet_constant('MD_INDEX') . "\" target=\"_self\">" . planet_constant('MD_INDEX') . '</a>');
198
199
    $link_articles = "<a href=\"" . XOOPS_URL . '/modules/' . $GLOBALS['moddirname'] . '/index.php' . (empty($category_id) ? '' : '/c' . $category_id) . (empty($uid) ? '' : '/u' . $uid) . "\" title=\"" . planet_constant('MD_ARTICLES') . "\">" . planet_constant('MD_ARTICLES') . '</a>';
200
    $xoopsTpl->assign('link_articles', $link_articles);
201
}
202
203
$link_switch = "<a href=\""
204
               . XOOPS_URL
205
               . '/modules/'
206
               . $GLOBALS['moddirname']
207
               . '/view.blogs.php'
208
               . (empty($category_id) ? '' : '/c' . $category_id)
209
               . (empty($uid) ? '' : '/u' . $uid)
210
               . (empty($list) ? '/l1' : '')
211
               . "\" title=\""
212
               . (empty($list) ? planet_constant('MD_LISTVIEW') : planet_constant('MD_FULLVIEW'))
213
               . "\">"
214
               . (empty($list) ? planet_constant('MD_LISTVIEW') : planet_constant('MD_FULLVIEW'))
215
               . '</a>';
216
$xoopsTpl->assign('link_switch', $link_switch);
217
218 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.

Loading history...
219
    $xoopsTpl->assign('link_bookmark', "<a href=\"" . XOOPS_URL . '/modules/' . $GLOBALS['moddirname'] . '/view.blogs.php' . URL_DELIMITER . 'u' . $xoopsUser->getVar('uid') . "\" title=\"" . planet_constant('MD_BOOKMARKS') . "\" target=\"_self\">" . planet_constant('MD_BOOKMARKS') . '</a>');
220
}
221
222 View Code Duplication
if ($xoopsModuleConfig['newblog_submit'] == 1 || 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.

Loading history...
223
    $xoopsTpl->assign('link_submit', "<a href=\"" . XOOPS_URL . '/modules/' . $GLOBALS['moddirname'] . "/action.blog.php\" title=\"" . _SUBMIT . "\" target=\"_blank\">" . _SUBMIT . '</a>');
224
}
225
226
$xoopsTpl->assign('pagetitle', $xoopsModule->getVar('name') . '::' . planet_constant('MD_BLOGS'));
227
$xoopsTpl->assign('category', @$category_data);
228
$xoopsTpl->assign('user', @$user_data);
229
$xoopsTpl->assign('blogs', $blogs);
230
$xoopsTpl->assign('pagenav', $pagenav);
231
$xoopsTpl->assign('count_blog', $count_blog);
232
$xoopsTpl->assign('is_list', !empty($list));
233
234
$xoopsTpl->assign('user_level', !is_object($xoopsUser) ? 0 : ($xoopsUser->isAdmin() ? 2 : 1));
235 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.

Loading history...
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

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.

Loading history...
236
} elseif (!$list) {
237
    $xoopsTpl->assign('canrate', 1);
238
}
239
240
$sort_link = XOOPS_URL . '/modules/' . $GLOBALS['moddirname'] . '/view.blogs.php' . URL_DELIMITER;
241
$vars      = [];
242
if (!empty($category_id)) {
243
    $vars[] = 'c' . $category_id;
244
}
245
if (!empty($uid)) {
246
    $vars[] = 'u' . $uid;
247
}
248
if (!empty($list)) {
249
    $vars[] = 'li';
250
}
251
if (!empty($vars)) {
252
    $sort_link .= implode('/', $vars) . '/';
253
}
254
$sortlinks   = [];
255
$valid_sorts = [
256
    'marks'   => planet_constant('MD_BOOKMARKS'),
257
    'rating'  => planet_constant('MD_RATING'),
258
    'time'    => planet_constant('MD_TIME'),
259
    'default' => planet_constant('MD_DEFAULT')
260
];
261 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.

Loading history...
262
    if ($val == $sort) {
263
        continue;
264
    }
265
    $sortlinks[] = "<a href=\"" . $sort_link . $val . "\">" . $name . '</a>';
266
}
267
$xoopsTpl->assign('link_sort', implode(' | ', $sortlinks));
268
269
require_once __DIR__ . '/footer.php';
270