Completed
Push — master ( 5eefd1...62af87 )
by Michael
14s
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
//                XOOPS - PHP Content Management System                      //
5
//                  Copyright (c) 2000-2016 XOOPS.org                        //
6
//                       <https://xoops.org/>                             //
7
//  ------------------------------------------------------------------------ //
8
//  This program is free software; you can redistribute it and/or modify     //
9
//  it under the terms of the GNU General Public License as published by     //
10
//  the Free Software Foundation; either version 2 of the License, or        //
11
//  (at your option) any later version.                                      //
12
//                                                                           //
13
//  You may not change or alter any portion of this comment or credits       //
14
//  of supporting developers from this source code or any supporting         //
15
//  source code which is considered copyrighted (c) material of the          //
16
//  original comment or credit authors.                                      //
17
//                                                                           //
18
//  This program is distributed in the hope that it will be useful,          //
19
//  but WITHOUT ANY WARRANTY; without even the implied warranty of           //
20
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            //
21
//  GNU General Public License for more details.                             //
22
//                                                                           //
23
//  You should have received a copy of the GNU General Public License        //
24
//  along with this program; if not, write to the Free Software              //
25
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA //
26
//  ------------------------------------------------------------------------ //
27
// Author: phppp (D.J., [email protected])                                  //
28
//  URL: https://xoops.org                                                    //
29
// Project: Article Project                                                 //
30
// ------------------------------------------------------------------------ //
31
32
use Xmf\Request;
33
34
include_once __DIR__ . '/header.php';
35
include_once $GLOBALS['xoops']->path('class/template.php');
36
include_once $GLOBALS['xoops']->path('modules/newbb/include/functions.rpc.php');
37
38
if (!empty($GLOBALS['xoopsModuleConfig']['do_rewrite'])) {
39
    include_once __DIR__ . '/seo_url.php';
40
}
41
/* for seo */
42
43
error_reporting(E_ALL);
44
$xoopsLogger->activated = false;
45
46
$forums   = [];
47
$category = Request::getInt('c', 0, 'GET');
48
$forumSet = Request::getString('f', '', 'GET');
49
if ('' !== $forumSet) {
50
    $forums = array_map('intval', array_map('trim', explode('|', $forumSet)));
51
}
52
53
///** @var \NewbbForumHandler $forumHandler */
0 ignored issues
show
Unused Code Comprehensibility introduced by
54% 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...
54
//$forumHandler = xoops_getModuleHandler('forum', 'newbb');
55
//$topicHandler = xoops_getModuleHandler('topic', 'newbb');
56
$validForums  = $forumHandler->getIdsByPermission(); // get all accessible forums
57
58
if (is_array($forums) && count($forums) > 0) {
59
    $validForums = array_intersect($forums, $validForums);
60
} elseif ($category > 0) {
61
    $crit_top = new CriteriaCompo(new Criteria('cat_id', $category));
0 ignored issues
show
$crit_top does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
62
    $crit_top->add(new Criteria('forum_id', '(' . implode(', ', $validForums) . ')', 'IN'));
0 ignored issues
show
$crit_top does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
63
    $forums_top  = $forumHandler->getIds($crit_top);
0 ignored issues
show
$forums_top does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
64
    $validForums = array_intersect($forums_top, $validForums);
0 ignored issues
show
$forums_top does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
65
}
66
if (0 === count($validForums)) {
67
    newbbTrackbackResponse(1, _NOPERM);
68
}
69
70
asort($validForums);
71
$forumSet = implode(',', $validForums);
72
73
$charset = 'UTF-8';
74
header('Content-Type:text/xml; charset=' . $charset);
75
76
$tpl                 = new XoopsTpl();
77
$tpl->caching        = 2;
78
$tpl->cache_lifetime = $GLOBALS['xoopsModuleConfig']['rss_cachetime'] * 60;
79
if (!empty($GLOBALS['xoopsConfig']['rewrite'])) {
80
    $tpl->load_filter('output', 'xoRewriteModule');
81
}
82
83
//mod_loadFunctions('cache');
84
$xoopsCachedTemplateId = "newbbb_rss_$forumSet";
85
$compile_id            = null;
0 ignored issues
show
$compile_id does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
86
if (!$tpl->is_cached('db:newbb_rss.tpl', $xoopsCachedTemplateId, $compile_id)) {
0 ignored issues
show
$compile_id does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
87
    include_once __DIR__ . '/include/functions.time.php';
88
89
//    /** @var \NewbbXmlrssHandler $xmlrssHandler */
0 ignored issues
show
Unused Code Comprehensibility introduced by
42% 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...
90
//    $xmlrssHandler = xoops_getModuleHandler('xmlrss', 'newbb');
91
    $rss           = $xmlrssHandler->create();
92
93
    $rss->setVarRss('channel_title', $GLOBALS['xoopsConfig']['sitename'] . ' :: ' . _MD_NEWBB_FORUM);
94
    $rss->channel_link = XOOPS_URL . '/';
95
    $rss->setVarRss('channel_desc', $GLOBALS['xoopsConfig']['slogan'] . ' :: ' . $xoopsModule->getInfo('description'));
96
    $rss->setVarRss('channel_lastbuild', formatTimestamp(time(), 'rss'));
97
    $rss->channel_webmaster = $GLOBALS['xoopsConfig']['adminmail'];
98
    $rss->channel_editor    = $GLOBALS['xoopsConfig']['adminmail'];
99
    $rss->setVarRss('channel_category', $xoopsModule->getVar('name'));
100
    $rss->channel_generator = 'NewBB ' . $xoopsModule->getInfo('version');
101
    $rss->channel_language  = _LANGCODE;
102
    $rss->xml_encoding      = $charset;
103
    $rss->image_url         = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/' . $xoopsModule->getInfo('image');
104
105
    $dimension = @getimagesize($GLOBALS['xoops']->path('modules/' . $xoopsModule->getVar('dirname') . '/' . $xoopsModule->getInfo('image')));
106 View Code Duplication
    if (empty($dimension[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...
107
        $width = 88;
108
    } else {
109
        $width = ($dimension[0] > 144) ? 144 : $dimension[0];
110
    }
111 View Code Duplication
    if (empty($dimension[1])) {
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...
112
        $height = 31;
113
    } else {
114
        $height = ($dimension[1] > 400) ? 400 : $dimension[1];
115
    }
116
    $rss->image_width  = $width;
117
    $rss->image_height = $height;
118
119
    $rss->max_items            = $GLOBALS['xoopsModuleConfig']['rss_maxitems'];
120
    $rss->max_item_description = $GLOBALS['xoopsModuleConfig']['rss_maxdescription'];
121
122
    $forumCriteria = ' AND t.forum_id IN (' . implode(',', $validForums) . ')';
123
    unset($validForums);
124
    $approveCriteria = ' AND t.approved = 1 AND p.approved = 1';
125
126
    $query = 'SELECT'
127
             . '    f.forum_id, f.forum_name,'
128
             . '    t.topic_id, t.topic_title, t.type_id,'
129
             . '    p.post_id, p.post_time, p.subject, p.uid, p.poster_name, p.post_karma, p.require_reply, '
130
             . '    pt.dohtml, pt.dosmiley, pt.doxcode, pt.dobr,'
131
             . '    pt.post_text'
132
             . '    FROM '
133
             . $GLOBALS['xoopsDB']->prefix('newbb_posts')
134
             . ' AS p'
135
             . '    LEFT JOIN '
136
             . $GLOBALS['xoopsDB']->prefix('newbb_topics')
137
             . ' AS t ON t.topic_last_post_id=p.post_id'
138
             . '    LEFT JOIN '
139
             . $GLOBALS['xoopsDB']->prefix('newbb_posts_text')
140
             . ' AS pt ON pt.post_id=p.post_id'
141
             . '    LEFT JOIN '
142
             . $GLOBALS['xoopsDB']->prefix('newbb_forums')
143
             . ' AS f ON f.forum_id=p.forum_id'
144
             . '    WHERE 1=1 '
145
             . $forumCriteria
146
             . $approveCriteria
147
             . ' ORDER BY p.post_id DESC';
148
    $limit = (int)($GLOBALS['xoopsModuleConfig']['rss_maxitems'] * 1.5);
149
    if (!$result = $GLOBALS['xoopsDB']->query($query, $limit)) {
150
        newbbTrackbackResponse(1, _MD_NEWBB_ERROR);
151
        //xoops_error($GLOBALS['xoopsDB']->error());
0 ignored issues
show
Unused Code Comprehensibility introduced by
84% 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...
152
        //return $xmlrssHandler->get($rss);
0 ignored issues
show
Unused Code Comprehensibility introduced by
78% 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...
153
    }
154
    $rows  = [];
155
    $types = [];
156 View Code Duplication
    while ($row = $GLOBALS['xoopsDB']->fetchArray($result)) {
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...
157
        $users[$row['uid']] = 1;
158
        if ($row['type_id'] > 0) {
159
            $types[$row['type_id']] = 1;
160
        }
161
        $rows[] = $row;
162
    }
163
164
    if (count($rows) < 1) {
165
        newbbTrackbackResponse(1, _MD_NEWBB_NORSS_DATA);
166
        //return $xmlrssHandler->get($rss);
0 ignored issues
show
Unused Code Comprehensibility introduced by
78% 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...
167
    }
168
    $users = newbbGetUnameFromIds(array_keys($users), $GLOBALS['xoopsModuleConfig']['show_realname']);
169 View Code Duplication
    if (count($types) > 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...
170
//        /** @var \NewbbTypeHandler $typeHandler */
0 ignored issues
show
Unused Code Comprehensibility introduced by
42% 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...
171
//        $typeHandler = xoops_getModuleHandler('type', 'newbb');
172
        $type_list   = $typeHandler->getList(new Criteria('type_id', '(' . implode(', ', array_keys($types)) . ')', 'IN'));
0 ignored issues
show
$type_list does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
173
    }
174
175
    foreach ($rows as $topic) {
176
        if ($topic['post_karma'] > 0 && $GLOBALS['xoopsModuleConfig']['enable_karma']) {
177
            continue;
178
        }
179
        if ($topic['require_reply'] && $GLOBALS['xoopsModuleConfig']['allow_require_reply']) {
180
            continue;
181
        }
182
        if (!empty($users[$topic['uid']])) {
183
            $topic['uname'] = $users[$topic['uid']];
184
        } else {
185
            $topic['uname'] = $topic['poster_name'] ? $myts->htmlSpecialChars($topic['poster_name']) : $myts->htmlSpecialChars($GLOBALS['xoopsConfig']['anonymous']);
186
        }
187
        $description            = $topic['forum_name'] . '::';
188
        $topic['topic_subject'] = empty($type_list[$topic['type_id']]) ? '' : '[' . $type_list[$topic['type_id']] . '] ';
0 ignored issues
show
$type_list does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
189
        $description            .= $topic['topic_subject'] . $topic['topic_title'] . "<br>\n";
190
        $description            .= $myts->displayTarea($topic['post_text'], $topic['dohtml'], $topic['dosmiley'], $topic['doxcode'], $topic['dobr']);
191
        $label                  = _MD_NEWBB_BY . ' ' . $topic['uname'];
192
        $time                   = formatTimestamp($topic['post_time'], 'rss');
193
        $link                   = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/viewtopic.php?post_id=' . $topic['post_id'] . '';
194
        if (!empty($GLOBALS['xoopsModuleConfig']['do_rewrite'])) {
195
            $link   = XOOPS_URL . '/' . REAL_MODULE_NAME . '/viewtopic.php?post_id=' . $topic['post_id'] . '';
196
            $oldurl = '<a href=\'' . $link . '\'>';
197
            $newurl = seo_urls($oldurl);
198
            $newurl = str_replace('<a href=\'', '', $newurl);
199
            $newurl = str_replace('\'>', '', $newurl);
200
            $link   = $newurl;
201
        }
202
        $title = $topic['subject'];
203
        if (!$rss->addItem($title, $link, $description, $label, $time)) {
204
            break;
205
        }
206
    }
207
208
    $rss_feed = $xmlrssHandler->get($rss);
0 ignored issues
show
$rss_feed does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
209
210
    $tpl->assign('rss', $rss_feed);
0 ignored issues
show
$rss_feed does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
211
    unset($rss);
212
}
213
$tpl->display('db:newbb_rss.tpl', $xoopsCachedTemplateId, $compile_id);
0 ignored issues
show
$compile_id does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
214