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

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 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']
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($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'
68
                              . (empty($args_REQUEST_URI) ? '' : '?' . implode('&', $args_REQUEST_URI));
69
}
70
71
$xoopsOption['template_main'] = planet_getTemplate('index');
72
$xoops_module_header          = '
73
    <link rel="alternate" type="application/rss+xml" title="' . $xoopsModule->getVar('name') . ' rss" href="'
74
                                . XOOPS_URL . '/modules/' . $GLOBALS['moddirname'] . '/xml.php".URL_DELIMITER."rss/c'
75
                                . $category_id . '/b' . $blog_id . '/u' . $uid . '" />
76
    <link rel="alternate" type="application/rss+xml" title="' . $xoopsModule->getVar('name') . ' rdf" href="'
77
                                . XOOPS_URL . '/modules/' . $GLOBALS['moddirname'] . '/xml.php".URL_DELIMITER."rdf/c'
78
                                . $category_id . '/b' . $blog_id . '/u' . $uid . '" />
79
    <link rel="alternate" type="application/atom+xml" title="' . $xoopsModule->getVar('name') . ' atom" href="'
80
                                . XOOPS_URL . '/modules/' . $GLOBALS['moddirname'] . '/xml.php".URL_DELIMITER."atom/c'
81
                                . $category_id . '/b' . $blog_id . '/u' . $uid . '" />
82
    ';
83
84
$xoopsOption['xoops_module_header'] = $xoops_module_header;
85
include_once XOOPS_ROOT_PATH . '/header.php';
86
include XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/include/vars.php';
87
88
// Following part will not be executed after cache
89
$category_handler = xoops_getModuleHandler('category', $GLOBALS['moddirname']);
90
$blog_handler     = xoops_getModuleHandler('blog', $GLOBALS['moddirname']);
91
$article_handler  = xoops_getModuleHandler('article', $GLOBALS['moddirname']);
92
93
$limit          = empty($list) ? $xoopsModuleConfig['articles_perpage'] : $xoopsModuleConfig['list_perpage'];
94
$query_type     = '';
95
$criteria       = new CriteriaCompo();
96
$article_prefix = '';
97
/* Specific category */
98 View Code Duplication
if ($category_id > 0) {
99
    $category_obj = $category_handler->get($category_id);
100
    $criteria->add(new Criteria('bc.cat_id', $category_id));
101
    $uid            = 0;
102
    $blog_id        = 0;
103
    $category_data  = array('id' => $category_id, 'title' => $category_obj->getVar('cat_title'));
104
    $query_type     = 'category';
105
    $article_prefix = 'a.';
106
}
107
/* Specific blog */
108
if ($blog_id > 0) {
109
    $blog_obj =& $blog_handler->get($blog_id);
110
    if ($blog_obj->getVar('blog_status')
111
        || (is_object($xoopsUser)
112
            && $xoopsUser->getVar('uid') == $blog_obj->getVar('blog_submitter'))
113
    ) {
114
        $criteria->add(new Criteria('blog_id', $blog_id));
115
        $category_id      = 0;
116
        $uid              = 0;
117
        $bookmark_handler = xoops_getModuleHandler('bookmark', $GLOBALS['moddirname']);
118
        $blog_data        = array(
119
            'id'    => $blog_id,
120
            'title' => $blog_obj->getVar('blog_title'),
121
            'image' => $blog_obj->getImage(),
122
            'title' => $blog_obj->getVar('blog_title'),
123
            'feed'  => $blog_obj->getVar('blog_feed'),
124
            'link'  => $blog_obj->getVar('blog_link'),
125
            'desc'  => $blog_obj->getVar('blog_desc'),
126
            'time'  => $blog_obj->getTime(),
127
            'star'  => $blog_obj->getStar(),
128
            'rates' => $blog_obj->getVar('blog_rates'),
129
            'marks' => $blog_obj->getVar('blog_marks')
130
        );
131
    }
132
    $query_type     = 'blog';
133
    $article_prefix = '';
134
}
135
/* User bookmarks(favorites) */
136 View Code Duplication
if ($uid > 0) {
137
    $criteria->add(new Criteria('bm.bm_uid', $uid));
138
    $category_id      = 0;
139
    $blog_id          = 0;
140
    $bookmark_handler = xoops_getModuleHandler('bookmark', $GLOBALS['moddirname']);
141
    $user_data        = array(
142
        'uid'   => $uid,
143
        'name'  => XoopsUser::getUnameFromId($uid),
144
        'marks' => $bookmark_handler->getCount(new Criteria('bm_uid', $uid))
145
    );
146
    $query_type       = 'bookmark';
147
    $article_prefix   = 'a.';
148
}
149
150
/* Sort */
151
$order = 'DESC';
152
$sort  = empty($sort) ? 'time' : $sort;
153
switch ($sort) {
154
    case 'views':
155
        $sortby = $article_prefix . 'art_views';
156
        break;
157
    case 'rating':
158
        $sortby = $article_prefix . 'art_rating';
159
        break;
160
    case 'time':
161
        $sortby = $article_prefix . 'art_time';
162
        break;
163
    case 'default':
164
    default:
165
        $sortby = '';
166
        break;
167
}
168
$criteria->setSort($sortby);
169
$criteria->setOrder($order);
170
$criteria->setStart($start);
171
$criteria->setLimit($limit);
172
173
$tags = empty($list) ? '' : array(
174
    $article_prefix . 'art_title',
175
    $article_prefix . 'blog_id',
176
    $article_prefix . 'art_time'
177
);
178 View Code Duplication
switch ($query_type) {
179
    case 'category':
180
        $articles_obj  =& $article_handler->getByCategory($criteria, $tags);
181
        $count_article = $article_handler->getCountByCategory($criteria);
182
        break;
183
    case 'bookmark':
184
        $articles_obj  =& $article_handler->getByBookmark($criteria, $tags);
185
        $count_article = $article_handler->getCountByBookmark($criteria);
186
        break;
187
    default:
188
        $articles_obj  =& $article_handler->getAll($criteria, $tags);
189
        $count_article = $article_handler->getCount($criteria);
190
        break;
191
}
192
193
if (!empty($blog_data)) {
194
    $blogs[$blog_data['id']] = $blog_data['title'];
195
} else {
196
    $blog_array = array();
197
    foreach (array_keys($articles_obj) as $id) {
198
        $blog_array[$articles_obj[$id]->getVar('blog_id')] = 1;
199
    }
200
    $criteria_blog = new Criteria('blog_id', '(' . implode(',', array_keys($blog_array)) . ')', 'IN');
201
    $blogs         = $blog_handler->getList($criteria_blog);
202
}
203
204
/* Objects to array */
205
$articles = array();
206
foreach (array_keys($articles_obj) as $id) {
207
    $_article = array(
208
        'id'    => $id,
209
        'title' => $articles_obj[$id]->getVar('art_title'),
210
        'time'  => $articles_obj[$id]->getTime(),
211
        'blog'  => array(
212
            'id'    => $articles_obj[$id]->getVar('blog_id'),
213
            'title' => $blogs[$articles_obj[$id]->getVar('blog_id')]
214
        )
215
    );
216
    if (empty($list)) {
217
        $_article = array_merge($_article, array(
218
            'author'   => $articles_obj[$id]->getVar('art_author'),
219
            'views'    => $articles_obj[$id]->getVar('art_views'),
220
            'comments' => $articles_obj[$id]->getVar('art_comments'),
221
            'star'     => $articles_obj[$id]->getStar(),
222
            'rates'    => $articles_obj[$id]->getVar('art_rates')
223
        ));
224
        if (!empty($xoopsModuleConfig['display_summary'])) {
225
            $_article['content'] = $articles_obj[$id]->getSummary();
226
        } else {
227
            $_article['content'] = $articles_obj[$id]->getVar('art_content');
228
        }
229
    }
230
    $articles[] = $_article;
231
    unset($_article);
232
}
233
unset($articles_obj);
234
235
if ($count_article > $limit) {
236
    include XOOPS_ROOT_PATH . '/class/pagenav.php';
237
    $start_link = array();
238
    if ($sort) {
239
        $start_link[] = 'sort=' . $sort;
240
    }
241
    if ($category_id) {
242
        $start_link[] = 'category=' . $category_id;
243
    }
244
    if ($blog_id) {
245
        $start_link[] = 'blog=' . $blog_id;
246
    }
247
    if ($list) {
248
        $start_link[] = 'list=' . $list;
249
    }
250
    $nav     = new XoopsPageNav($count_article, $limit, $start, 'start', implode('&amp;', $start_link));
251
    $pagenav = $nav->renderNav(4);
252
} else {
253
    $pagenav = '';
254
}
255
256
$xoopsTpl->assign('xoops_module_header', $xoops_module_header);
257
$xoopsTpl->assign('dirname', $GLOBALS['moddirname']);
258
259
if ($category_id || $blog_id || $uid) {
260
    $xoopsTpl->assign('link_index',
261
                      "<a href=\"" . XOOPS_URL . '/modules/' . $GLOBALS['moddirname'] . "/index.php\" title=\""
262
                      . planet_constant('MD_INDEX') . "\" target=\"_self\">" . planet_constant('MD_INDEX') . '</a>');
263
}
264
265
$link_switch = "<a href=\"" . XOOPS_URL . '/modules/' . $GLOBALS['moddirname'] . '/index.php'
266
               . (empty($category_id) ? '' : '/c' . $category_id) . (empty($uid) ? '' : '/u' . $uid)
267
               . (empty($blog_id) ? '' : '/b' . $blog_id) . (empty($list) ? '/l1' : '') . "\" title=\""
268
               . (empty($list) ? planet_constant('MD_LISTVIEW') : planet_constant('MD_FULLVIEW')) . "\">"
269
               . (empty($list) ? planet_constant('MD_LISTVIEW') : planet_constant('MD_FULLVIEW')) . '</a>';
270
$xoopsTpl->assign('link_switch', $link_switch);
271
272
$link_blogs = "<a href=\"" . XOOPS_URL . '/modules/' . $GLOBALS['moddirname'] . '/view.blogs.php'
273
              . (empty($category_id) ? '' : '/c' . $category_id) . (empty($uid) ? '' : '/u' . $uid) . "\" title=\""
274
              . planet_constant('MD_BLOGS') . "\">" . planet_constant('MD_BLOGS') . '</a>';
275
$xoopsTpl->assign('link_blogs', $link_blogs);
276
277 View Code Duplication
if (empty($uid) && is_object($xoopsUser)) {
278
    $xoopsTpl->assign('link_bookmark',
279
                      "<a href=\"" . XOOPS_URL . '/modules/' . $GLOBALS['moddirname'] . '/index.php' . URL_DELIMITER
280
                      . 'u' . $xoopsUser->getVar('uid') . "\" title=\"" . planet_constant('MD_BOOKMARKS')
281
                      . "\" target=\"_self\">" . planet_constant('MD_BOOKMARKS') . '</a>');
282
}
283
284 View Code Duplication
if ($xoopsModuleConfig['newblog_submit'] == 1 || is_object($xoopsUser)) {
285
    $xoopsTpl->assign('link_submit',
286
                      "<a href=\"" . XOOPS_URL . '/modules/' . $GLOBALS['moddirname'] . "/action.blog.php\" title=\""
287
                      . _SUBMIT . "\" target=\"_blank\">" . _SUBMIT . '</a>');
288
}
289
290
$xoopsTpl->assign('pagetitle', $xoopsModule->getVar('name') . '::' . planet_constant('MD_ARTICLES'));
291
$xoopsTpl->assign('category', @$category_data);
292
$xoopsTpl->assign('blog', @$blog_data);
293
$xoopsTpl->assign('user', @$user_data);
294
$xoopsTpl->assign('articles', $articles);
295
$xoopsTpl->assign('pagenav', $pagenav);
296
$xoopsTpl->assign('is_list', !empty($list));
297
298
$xoopsTpl->assign('user_level', !is_object($xoopsUser) ? 0 : ($xoopsUser->isAdmin() ? 2 : 1));
299 View Code Duplication
if (empty($xoopsModuleConfig['anonymous_rate']) && !is_object($xoopsUser)) {
300
} elseif ($blog_id > 0) {
301
    $xoopsTpl->assign('canrate', 1);
302
}
303
304
$sort_link   = XOOPS_URL . '/modules/' . $GLOBALS['moddirname'] . '/index.php' . (empty($category_id) ? '' : '/c'
305
                                                                                                             . $category_id)
306
               . (empty($uid) ? '' : '/u' . $uid) . (empty($blog_id) ? '' : '/b' . $blog_id)
307
               . (empty($list) ? '' : '/l1');
308
$valid_sorts = array(
309
    'views'   => planet_constant('MD_VIEWS'),
310
    'rating'  => planet_constant('MD_RATING'),
311
    'time'    => planet_constant('MD_TIME'),
312
    'default' => planet_constant('MD_DEFAULT')
313
);
314
$sortlinks   = array();
315 View Code Duplication
foreach ($valid_sorts as $val => $name) {
316
    if ($val == $sort) {
317
        continue;
318
    }
319
    $sortlinks[] = "<a href=\"" . $sort_link . '/' . $val . "\">" . $name . '</a>';
320
}
321
$xoopsTpl->assign('link_sort', implode(' | ', $sortlinks));
322
$xoopsTpl->assign('version', $xoopsModule->getVar('version'));
323
324
$xoopsTpl->assign('do_pseudocron', $xoopsModuleConfig['do_pseudocron']);
325
326
// for notification
327
if (!empty($blog_id)) {
328
    //$_SERVER['REQUEST_URI'] = XOOPS_URL."/modules/".$GLOBALS["moddirname"]."/index.php";
329
    $_GET['blog'] = $blog_id;
330
}
331
332
include_once __DIR__ . '/footer.php';
333