Completed
Push — master ( 96da4e...7c5656 )
by Michael
04:52
created

view.blogs.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
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 = planet_parse_args($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...
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 Bookmar(Favorite) UID */
44
$uid = (int)(empty($_GET['uid']) ? @$args['uid'] : $_GET['uid']);
45
/* Sort by term */
46
$sort = empty($_GET['sort']) ? @$args['sort'] : $_GET['sort'];
47
/* Display as list */
48
$list = (int)(empty($_GET['list']) ? @$args['list'] : $_GET['list']);
49
/*
0 ignored issues
show
Unused Code Comprehensibility introduced by
65% 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...
50
// restore $_SERVER['REQUEST_URI']
51
if (!empty($REQUEST_URI_parsed)) {
52
    $args_REQUEST_URI = array();
53
    $_args =array("start", "sort", "uid", "list");
54
    foreach ($_args as $arg) {
55
        if (!empty(${$arg})) {
56
            $args_REQUEST_URI[] = $arg ."=". ${$arg};
57
        }
58
    }
59
    if (!empty($category_id)) {
60
        $args_REQUEST_URI[] = "category=". $category_id;
61
    }
62
    $_SERVER['REQUEST_URI'] = XOOPS_URL."/modules/".$GLOBALS["moddirname"]."/view.blogs.php".
63
        (empty($args_REQUEST_URI)?"":"?".implode("&",$args_REQUEST_URI));
64
}
65
*/
66
67
$xoopsOption['xoops_pagetitle'] = $xoopsModule->getVar('name') . ' - ' . planet_constant('MD_BLOGS');
68
$xoopsOption['template_main']   = planet_getTemplate('blogs');
69
include_once XOOPS_ROOT_PATH . '/header.php';
70
include XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/include/vars.php';
71
72
// Following part will not be executed after cache
73
$category_handler = xoops_getModuleHandler('category', $GLOBALS['moddirname']);
74
$blog_handler     = xoops_getModuleHandler('blog', $GLOBALS['moddirname']);
75
76
$limit = empty($list) ? $xoopsModuleConfig['articles_perpage'] : $xoopsModuleConfig['list_perpage'];
77
78
$query_type  = '';
79
$criteria    = new CriteriaCompo();
80
$blog_prefix = '';
81
/* Specific category */
82 View Code Duplication
if ($category_id > 0) {
83
    $category_obj = $category_handler->get($category_id);
84
    $criteria->add(new Criteria('bc.cat_id', $category_id));
85
    $uid           = 0;
86
    $blog_id       = 0;
87
    $category_data = array('id' => $category_id, 'title' => $category_obj->getVar('cat_title'));
88
    $query_type    = 'category';
89
    $blog_prefix   = 'b.';
90
}
91
92
/* User bookmarks(favorites) */
93 View Code Duplication
if ($uid > 0) {
94
    $criteria->add(new Criteria('bm.bm_uid', $uid));
95
    $category_id      = 0;
96
    $blog_id          = 0;
97
    $bookmark_handler = xoops_getModuleHandler('bookmark', $GLOBALS['moddirname']);
98
    $user_data        = array(
99
        'uid'   => $uid,
100
        'name'  => XoopsUser::getUnameFromId($uid),
101
        'marks' => $bookmark_handler->getCount(new Criteria('bm_uid', $uid))
102
    );
103
    $query_type       = 'bookmark';
104
    $blog_prefix      = 'b.';
105
}
106
107
$criteria->add(new Criteria($blog_prefix . 'blog_status', 0, '>'));
108
109
/* Sort */
110
$order = 'DESC';
111
$sort  = empty($sort) ? 'default' : $sort;
112
switch ($sort) {
113
    case 'marks':
114
        $sortby = $blog_prefix . 'blog_marks';
115
        break;
116
    case 'rating':
117
        $sortby = $blog_prefix . 'blog_rating';
118
        break;
119
    case 'time':
120
        $sortby = $blog_prefix . 'blog_time';
121
        break;
122
    case 'default':
123
    default:
124
        $sort   = 'default';
125
        $sortby = $blog_prefix . 'blog_id';
126
        break;
127
}
128
$criteria->setSort($sortby);
129
$criteria->setOrder($order);
130
$criteria->setStart($start);
131
$criteria->setLimit($limit);
132
133
$tags = empty($list) ? '' : array($blog_prefix . 'blog_title', $blog_prefix . 'blog_time');
134 View Code Duplication
switch ($query_type) {
135
    case 'category':
136
        $blogs_obj  =& $blog_handler->getByCategory($criteria, $tags);
137
        $count_blog = $blog_handler->getCountByCategory($criteria);
138
        break;
139
    case 'bookmark':
140
        $blogs_obj  =& $blog_handler->getByBookmark($criteria, $tags);
141
        $count_blog = $blog_handler->getCountByBookmark($criteria);
142
        break;
143
    default:
144
        $blogs_obj  =& $blog_handler->getAll($criteria, $tags);
145
        $count_blog = $blog_handler->getCount($criteria);
146
        break;
147
}
148
149
/* Objects to array */
150
$blogs = array();
151
foreach (array_keys($blogs_obj) as $id) {
152
    $_blog = array(
153
        'id'    => $id,
154
        'title' => $blogs_obj[$id]->getVar('blog_title'),
155
        'time'  => $blogs_obj[$id]->getTime()
156
    );
157
    if (empty($list)) {
158
        $_blog = array_merge($_blog, array(
159
            'image' => $blogs_obj[$id]->getImage(),
160
            'feed'  => $blogs_obj[$id]->getVar('blog_feed'),
161
            'link'  => $blogs_obj[$id]->getVar('blog_link'),
162
            'desc'  => $blogs_obj[$id]->getVar('blog_desc'),
163
            'star'  => $blogs_obj[$id]->getStar(),
164
            'rates' => $blogs_obj[$id]->getVar('blog_rates'),
165
            'marks' => $blogs_obj[$id]->getVar('blog_marks')
166
        ));
167
    }
168
    $blogs[] = $_blog;
169
    unset($_blog);
170
}
171
unset($blogs_obj);
172
173
if ($count_blog > $limit) {
174
    include XOOPS_ROOT_PATH . '/class/pagenav.php';
175
    $start_link = array();
176
    if ($sort) {
177
        $start_link[] = 'sort=' . $sort;
178
    }
179
    if ($category_id) {
180
        $start_link[] = 'category=' . $category_id;
181
    }
182
    if ($list) {
183
        $start_link[] = 'list=' . $list;
184
    }
185
    $nav     = new XoopsPageNav($count_blog, $limit, $start, 'start', implode('&amp;', $start_link));
186
    $pagenav = $nav->renderNav(4);
187
} else {
188
    $pagenav = '';
189
}
190
191
$xoopsTpl->assign('xoops_pagetitle', $xoopsOption['xoops_pagetitle']);
192
$xoopsTpl->assign('link_home', "<a href=\"" . XOOPS_URL . '/modules/' . $GLOBALS['moddirname'] . "/index.php\" title=\""
193
                               . planet_constant('MD_HOME') . "\" target=\"_self\">" . planet_constant('MD_HOME')
194
                               . '</a>');
195
196
if ($category_id || $uid) {
197
    $xoopsTpl->assign('link_index',
198
                      "<a href=\"" . XOOPS_URL . '/modules/' . $GLOBALS['moddirname'] . "/view.blogs.php\" title=\""
199
                      . planet_constant('MD_INDEX') . "\" target=\"_self\">" . planet_constant('MD_INDEX') . '</a>');
200
201
    $link_articles = "<a href=\"" . XOOPS_URL . '/modules/' . $GLOBALS['moddirname'] . '/index.php'
202
                     . (empty($category_id) ? '' : '/c' . $category_id) . (empty($uid) ? '' : '/u' . $uid)
203
                     . "\" title=\"" . planet_constant('MD_ARTICLES') . "\">" . planet_constant('MD_ARTICLES') . '</a>';
204
    $xoopsTpl->assign('link_articles', $link_articles);
205
}
206
207
$link_switch = "<a href=\"" . XOOPS_URL . '/modules/' . $GLOBALS['moddirname'] . '/view.blogs.php'
208
               . (empty($category_id) ? '' : '/c' . $category_id) . (empty($uid) ? '' : '/u' . $uid)
209
               . (empty($list) ? '/l1' : '') . "\" title=\""
210
               . (empty($list) ? planet_constant('MD_LISTVIEW') : planet_constant('MD_FULLVIEW')) . "\">"
211
               . (empty($list) ? planet_constant('MD_LISTVIEW') : planet_constant('MD_FULLVIEW')) . '</a>';
212
$xoopsTpl->assign('link_switch', $link_switch);
213
214 View Code Duplication
if (empty($uid) && is_object($xoopsUser)) {
215
    $xoopsTpl->assign('link_bookmark',
216
                      "<a href=\"" . XOOPS_URL . '/modules/' . $GLOBALS['moddirname'] . '/view.blogs.php'
217
                      . URL_DELIMITER . 'u' . $xoopsUser->getVar('uid') . "\" title=\""
218
                      . planet_constant('MD_BOOKMARKS') . "\" target=\"_self\">" . planet_constant('MD_BOOKMARKS')
219
                      . '</a>');
220
}
221
222 View Code Duplication
if ($xoopsModuleConfig['newblog_submit'] == 1 || is_object($xoopsUser)) {
223
    $xoopsTpl->assign('link_submit',
224
                      "<a href=\"" . XOOPS_URL . '/modules/' . $GLOBALS['moddirname'] . "/action.blog.php\" title=\""
225
                      . _SUBMIT . "\" target=\"_blank\">" . _SUBMIT . '</a>');
226
}
227
228
$xoopsTpl->assign('pagetitle', $xoopsModule->getVar('name') . '::' . planet_constant('MD_BLOGS'));
229
$xoopsTpl->assign('category', @$category_data);
230
$xoopsTpl->assign('user', @$user_data);
231
$xoopsTpl->assign('blogs', $blogs);
232
$xoopsTpl->assign('pagenav', $pagenav);
233
$xoopsTpl->assign('count_blog', $count_blog);
234
$xoopsTpl->assign('is_list', !empty($list));
235
236
$xoopsTpl->assign('user_level', !is_object($xoopsUser) ? 0 : ($xoopsUser->isAdmin() ? 2 : 1));
237 View Code Duplication
if (empty($xoopsModuleConfig['anonymous_rate']) && !is_object($xoopsUser)) {
238
} elseif (!$list) {
239
    $xoopsTpl->assign('canrate', 1);
240
}
241
242
$sort_link = XOOPS_URL . '/modules/' . $GLOBALS['moddirname'] . '/view.blogs.php' . URL_DELIMITER;
243
$vars      = array();
244
if (!empty($category_id)) {
245
    $vars[] = 'c' . $category_id;
246
}
247
if (!empty($uid)) {
248
    $vars[] = 'u' . $uid;
249
}
250
if (!empty($list)) {
251
    $vars[] = 'li';
252
}
253
if (!empty($vars)) {
254
    $sort_link .= implode('/', $vars) . '/';
255
}
256
$sortlinks   = array();
257
$valid_sorts = array(
258
    'marks'   => planet_constant('MD_BOOKMARKS'),
259
    'rating'  => planet_constant('MD_RATING'),
260
    'time'    => planet_constant('MD_TIME'),
261
    'default' => planet_constant('MD_DEFAULT')
262
);
263 View Code Duplication
foreach ($valid_sorts as $val => $name) {
264
    if ($val == $sort) {
265
        continue;
266
    }
267
    $sortlinks[] = "<a href=\"" . $sort_link . $val . "\">" . $name . '</a>';
268
}
269
$xoopsTpl->assign('link_sort', implode(' | ', $sortlinks));
270
271
include_once __DIR__ . '/footer.php';
272