Passed
Push — master ( d3e687...4990f6 )
by Michael
02:43
created

b_newbb_topic_edit()   F

Complexity

Conditions 13
Paths 4096

Size

Total Lines 74
Code Lines 55

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 13
eloc 55
nc 4096
nop 1
dl 0
loc 74
rs 2.2665
c 1
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 41 and the first side effect is on line 36.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
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
// defined('XOOPS_ROOT_PATH') || die('Restricted access');
32
// irmtfan use full path because block maybe used outside newbb
33
34
use XoopsModules\Newbb;
35
36
include_once $GLOBALS['xoops']->path('modules/newbb/include/functions.ini.php');
37
38
if (defined('NEWBB_BLOCK_DEFINED')) {
39
    return;
40
}
41
define('NEWBB_BLOCK_DEFINED', true);
42
43
/**
44
 * @param $var
45
 * @return bool
46
 */
47
function b_newbb_array_filter($var)
48
{
49
    return $var > 0;
50
}
51
52
// options[0] - Citeria valid: time(by default)
53
// options[1] - NumberToDisplay: any positive integer
54
// options[2] - TimeDuration: negative for hours, positive for days, for instance, -5 for 5 hours and 5 for 5 days
55
// options[3] - DisplayMode: 0-full view;1-compact view;2-lite view
56
// options[4] - Display Navigator: 1 (by default), 0 (No)
57
// options[5] - Title Length : 0 - no limit
58
// options[6] - SelectedForumIDs: null for all
59
60
/**
61
 * @param $options
62
 * @return array|bool
63
 */
64
function b_newbb_show($options)
65
{
66
    global $accessForums;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
67
    global $xoopsLogger;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
68
69
    include_once __DIR__ . '/../include/functions.config.php';
70
    include_once __DIR__ . '/../include/functions.time.php';
71
72
    $myts          = \MyTextSanitizer::getInstance();
0 ignored issues
show
Bug introduced by
The type MyTextSanitizer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
73
    $block         = [];
74
    $i             = 0;
0 ignored issues
show
Unused Code introduced by
The assignment to $i is dead and can be removed.
Loading history...
75
    $order         = '';
0 ignored issues
show
Unused Code introduced by
The assignment to $order is dead and can be removed.
Loading history...
76
    $extraCriteria = '';
77
    if (!empty($options[2])) {
78
        //include_once __DIR__ . '/../include/functions.time.php';
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% 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...
79
        $extraCriteria .= ' AND p.post_time>' . (time() - newbbGetSinceTime($options[2]));
80
    }
81
    switch ($options[0]) {
82
        case 'time':
83
        default:
84
            $order = 't.topic_last_post_id';
85
            break;
86
    }
87
88
    if (!isset($accessForums)) {
89
        /** var Newbb\PermissionHandler $permHandler */
90
        $permHandler = Newbb\Helper::getInstance()->getHandler('Permission');
91
        if (!$accessForums = $permHandler->getForums()) {
92
            return $block;
93
        }
94
    }
95
    if (!empty($options[6])) {
96
        $myallowedForums = array_filter(array_slice($options, 6), 'b_newbb_array_filter'); // get allowed forums
97
        $allowedForums   = array_intersect($myallowedForums, $accessForums);
98
    } else {
99
        $allowedForums = $accessForums;
100
    }
101
    if (empty($allowedForums)) {
102
        return $block;
103
    }
104
105
    $forumCriteria   = ' AND t.forum_id IN (' . implode(',', $allowedForums) . ')';
106
    $approveCriteria = ' AND t.approved = 1';
107
108
    $newbbConfig = newbbLoadConfig();
109
    if (!empty($newbbConfig['do_rewrite'])) {
110
        include_once $GLOBALS['xoops']->path('modules/newbb/seo_url.php');
111
    } else {
112
        if (!defined('SEO_MODULE_NAME')) {
113
            define('SEO_MODULE_NAME', 'modules/newbb');
114
        }
115
    }
116
117
    $query = 'SELECT'
118
             . '    t.topic_id, t.topic_replies, t.forum_id, t.topic_title, t.topic_views, t.type_id,'
119
             . '    f.forum_name,t.topic_status,'
120
             . '    p.post_id, p.post_time, p.icon, p.uid, p.poster_name'
121
             . '    FROM '
122
             . $GLOBALS['xoopsDB']->prefix('newbb_topics')
123
             . ' AS t '
124
             . '    LEFT JOIN '
125
             . $GLOBALS['xoopsDB']->prefix('newbb_posts')
126
             . ' AS p ON t.topic_last_post_id=p.post_id'
127
             . '    LEFT JOIN '
128
             . $GLOBALS['xoopsDB']->prefix('newbb_forums')
129
             . ' AS f ON f.forum_id=t.forum_id'
130
             . '    WHERE 1=1 '
131
             . $forumCriteria
132
             . $approveCriteria
133
             . $extraCriteria
134
             . ' ORDER BY '
135
             . $order
136
             . ' DESC';
137
138
    $result = $GLOBALS['xoopsDB']->query($query, $options[1], 0);
139
140
    if (!$result) {
141
        //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...
142
        return false;
143
    }
144
    $block['disp_mode'] = $options[3]; // 0 - full view; 1 - compact view; 2 - lite view;
145
    $rows               = [];
146
    $author             = [];
147
    $types              = [];
148
149
    while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($result))) {
150
        $rows[]              = $row;
151
        $author[$row['uid']] = 1;
152
        if ($row['type_id'] > 0) {
153
            $types[$row['type_id']] = 1;
154
        }
155
    }
156
157
    if (count($rows) < 1) {
158
        return $block;
159
    }
160
161
    include_once __DIR__ . '/../include/functions.user.php';
162
    $author_name = newbbGetUnameFromIds(array_keys($author), $newbbConfig['show_realname'], true);
163
164
    if (count($types) > 0) {
165
        /** @var Newbb\TypeHandler $typeHandler */
166
        $typeHandler = Newbb\Helper::getInstance()->getHandler('Type');
167
        $type_list   = $typeHandler->getList(new \Criteria('type_id', '(' . implode(', ', array_keys($types)) . ')', 'IN'));
0 ignored issues
show
Bug introduced by
The type Criteria was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
168
    }
169
170
    foreach ($rows as $arr) {
171
        // irmtfan add lastposticon - load main lang
172
        xoops_loadLanguage('main', 'newbb');
0 ignored issues
show
Bug introduced by
The function xoops_loadLanguage was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

172
        /** @scrutinizer ignore-call */ 
173
        xoops_loadLanguage('main', 'newbb');
Loading history...
173
        $topic                  = [];
174
        $topic_page_jump        = newbbDisplayImage('lastposticon', _MD_NEWBB_GOTOLASTPOST);
175
        $topic['topic_subject'] = empty($type_list[$arr['type_id']]) ? '' : '[' . $type_list[$arr['type_id']] . ']';
176
177
        $topic['post_id']      = $arr['post_id'];
178
        $topic['topic_status'] = $arr['topic_status'];
179
        $topic['forum_id']     = $arr['forum_id'];
180
        $topic['forum_name']   = $myts->htmlSpecialChars($arr['forum_name']);
181
        $topic['id']           = $arr['topic_id'];
182
183
        $title = $myts->htmlSpecialChars($arr['topic_title']);
184
        if (!empty($options[5])) {
185
            $title = xoops_substr($title, 0, $options[5]);
0 ignored issues
show
Bug introduced by
The function xoops_substr was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

185
            $title = /** @scrutinizer ignore-call */ xoops_substr($title, 0, $options[5]);
Loading history...
186
        }
187
        $topic['title']   = $topic['topic_subject'] . ' ' . $title;
188
        $topic['replies'] = $arr['topic_replies'];
189
        $topic['views']   = $arr['topic_views'];
190
        $topic['time']    = newbbFormatTimestamp($arr['post_time']);
191
        if (!empty($author_name[$arr['uid']])) {
192
            $topic_poster = $author_name[$arr['uid']];
193
        } else {
194
            $topic_poster = $myts->htmlSpecialChars($arr['poster_name'] ?: $GLOBALS['xoopsConfig']['anonymous']);
195
        }
196
        $topic['topic_poster']    = $topic_poster;
197
        $topic['topic_page_jump'] = $topic_page_jump;
198
        // START irmtfan remove hardcoded html in URLs - add $seo_topic_url
199
        $seo_url       = XOOPS_URL . '/' . SEO_MODULE_NAME . '/viewtopic.php?post_id=' . $topic['post_id'];
0 ignored issues
show
Bug introduced by
The constant XOOPS_URL was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
200
        $seo_topic_url = XOOPS_URL . '/' . SEO_MODULE_NAME . '/viewtopic.php?topic_id=' . $topic['id'];
201
        $seo_forum_url = XOOPS_URL . '/' . SEO_MODULE_NAME . '/viewforum.php?forum=' . $topic['forum_id'];
202
        if (!empty($newbbConfig['do_rewrite'])) {
203
            $topic['seo_url']       = seo_urls($seo_url);
204
            $topic['seo_topic_url'] = seo_urls($seo_topic_url);
205
            $topic['seo_forum_url'] = seo_urls($seo_forum_url);
206
        } else {
207
            $topic['seo_url']       = $seo_url;
208
            $topic['seo_topic_url'] = $seo_topic_url;
209
            $topic['seo_forum_url'] = $seo_forum_url;
210
        }
211
        // END irmtfan remove hardcoded html in URLs - add $seo_topic_url
212
        $block['topics'][] = $topic;
213
        unset($topic);
214
    }
215
    // START irmtfan remove hardcoded html in URLs
216
    $seo_top_allforums          = XOOPS_URL . '/' . SEO_MODULE_NAME;
217
    $block['seo_top_allforums'] = !empty($newbbConfig['do_rewrite']) ? seo_urls($seo_top_allforums) : $seo_top_allforums;
218
    $seo_top_allforums          = XOOPS_URL . '/' . SEO_MODULE_NAME . '/list.topic.php';
219
    $block['seo_top_alltopics'] = !empty($newbbConfig['do_rewrite']) ? seo_urls($seo_top_allforums) : $seo_top_allforums;
220
    $seo_top_allforums          = XOOPS_URL . '/' . SEO_MODULE_NAME . '/viewpost.php';
221
    $block['seo_top_allposts']  = !empty($newbbConfig['do_rewrite']) ? seo_urls($seo_top_allforums) : $seo_top_allforums;
222
    // END irmtfan remove hardcoded html in URLs
223
    $block['indexNav'] = (int)$options[4];
224
225
    return $block;
226
}
227
228
// options[0] - Citeria valid: time(by default), views, replies, digest, sticky
229
// options[1] - NumberToDisplay: any positive integer
230
// options[2] - TimeDuration: negative for hours, positive for days, for instance, -5 for 5 hours and 5 for 5 days
231
// options[3] - DisplayMode: 0-full view;1-compact view;2-lite view
232
// options[4] - Display Navigator: 1 (by default), 0 (No)
233
// options[5] - Title Length : 0 - no limit
234
// options[6] - SelectedForumIDs: null for all
235
236
/**
237
 * @param $options
238
 * @return array|bool
239
 */
240
function b_newbb_topic_show($options)
241
{
242
    global $accessForums;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
243
    include_once __DIR__ . '/../include/functions.time.php';
244
    $myts          = \MyTextSanitizer::getInstance();
245
    $block         = [];
246
    $i             = 0;
0 ignored issues
show
Unused Code introduced by
The assignment to $i is dead and can be removed.
Loading history...
247
    $order         = '';
248
    $extraCriteria = '';
249
    $time_criteria = null;
250
    if (!empty($options[2])) {
251
        $time_criteria = time() - newbbGetSinceTime($options[2]);
252
        $extraCriteria = ' AND t.topic_time>' . $time_criteria;
253
    }
254
    switch ($options[0]) {
255
        case 'views':
256
            $order = 't.topic_views';
257
            break;
258
        case 'replies':
259
            $order = 't.topic_replies';
260
            break;
261
        case 'digest':
262
            $order         = 't.digest_time';
263
            $extraCriteria = ' AND t.topic_digest=1';
264
            if (null !== $time_criteria) {
265
                $extraCriteria .= ' AND t.digest_time>' . $time_criteria;
266
            }
267
            break;
268
        case 'sticky':
269
            $order         = 't.topic_id';
270
            $extraCriteria .= ' AND t.topic_sticky=1';
271
            break;
272
        case 'time':
273
        default:
274
            $order = 't.topic_id';
275
            break;
276
    }
277
278
    $newbbConfig = newbbLoadConfig();
279
    if (!empty($newbbConfig['do_rewrite'])) {
280
        include_once $GLOBALS['xoops']->path('modules/newbb/seo_url.php');
281
    } else {
282
        if (!defined('SEO_MODULE_NAME')) {
283
            define('SEO_MODULE_NAME', 'modules/newbb');
284
        }
285
    }
286
287
    if (!isset($accessForums)) {
288
        /** var Newbb\PermissionHandler $permHandler */
289
        $permHandler = Newbb\Helper::getInstance()->getHandler('Permission');
290
        if (!$accessForums = $permHandler->getForums()) {
291
            return $block;
292
        }
293
    }
294
295
    if (!empty($options[6])) {
296
        $myallowedForums = array_filter(array_slice($options, 6), 'b_newbb_array_filter'); // get allowed forums
297
        $allowedForums   = array_intersect($myallowedForums, $accessForums);
298
    } else {
299
        $allowedForums = $accessForums;
300
    }
301
    if (empty($allowedForums)) {
302
        return false;
303
    }
304
305
    $forumCriteria   = ' AND t.forum_id IN (' . implode(',', $allowedForums) . ')';
306
    $approveCriteria = ' AND t.approved = 1';
307
308
    $query = 'SELECT'
309
             . '    t.topic_id, t.topic_replies, t.forum_id, t.topic_title, t.topic_views, t.type_id, t.topic_time, t.topic_poster, t.poster_name,'
310
             . '    f.forum_name'
311
             . '    FROM '
312
             . $GLOBALS['xoopsDB']->prefix('newbb_topics')
313
             . ' AS t '
314
             . '    LEFT JOIN '
315
             . $GLOBALS['xoopsDB']->prefix('newbb_forums')
316
             . ' AS f ON f.forum_id=t.forum_id'
317
             . '    WHERE 1=1 '
318
             . $forumCriteria
319
             . $approveCriteria
320
             . $extraCriteria
321
             . ' ORDER BY '
322
             . $order
323
             . ' DESC';
324
325
    $result = $GLOBALS['xoopsDB']->query($query, $options[1], 0);
326
327
    if (!$result) {
328
        //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...
329
        return $block;
330
    }
331
    $block['disp_mode'] = $options[3]; // 0 - full view; 1 - compact view; 2 - lite view;
332
    $rows               = [];
333
    $author             = [];
334
    $types              = [];
335
    while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($result))) {
336
        $rows[]                       = $row;
337
        $author[$row['topic_poster']] = 1;
338
        if ($row['type_id'] > 0) {
339
            $types[$row['type_id']] = 1;
340
        }
341
    }
342
    if (count($rows) < 1) {
343
        return $block;
344
    }
345
    include_once __DIR__ . '/../include/functions.user.php';
346
    $author_name = newbbGetUnameFromIds(array_keys($author), $newbbConfig['show_realname'], true);
347
    if (count($types) > 0) {
348
        /** @var Newbb\TypeHandler $typeHandler */
349
        $typeHandler = Newbb\Helper::getInstance()->getHandler('Type');
350
        $type_list   = $typeHandler->getList(new \Criteria('type_id', '(' . implode(', ', array_keys($types)) . ')', 'IN'));
351
    }
352
353
    foreach ($rows as $arr) {
354
        // irmtfan remove $topic_page_jump because there is no last post
355
        //$topic_page_jump = '';
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% 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...
356
        $topic                  = [];
357
        $topic['topic_subject'] = empty($type_list[$arr['type_id']]) ? '' : '[' . $type_list[$arr['type_id']] . '] ';
358
        $topic['forum_id']      = $arr['forum_id'];
359
        $topic['forum_name']    = $myts->htmlSpecialChars($arr['forum_name']);
360
        $topic['id']            = $arr['topic_id'];
361
362
        $title = $myts->htmlSpecialChars($arr['topic_title']);
363
        if (!empty($options[5])) {
364
            $title = xoops_substr($title, 0, $options[5]);
0 ignored issues
show
Bug introduced by
The function xoops_substr was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

364
            $title = /** @scrutinizer ignore-call */ xoops_substr($title, 0, $options[5]);
Loading history...
365
        }
366
        $topic['title']   = $topic['topic_subject'] . $title;
367
        $topic['replies'] = $arr['topic_replies'];
368
        $topic['views']   = $arr['topic_views'];
369
        $topic['time']    = newbbFormatTimestamp($arr['topic_time']);
370
        if (!empty($author_name[$arr['topic_poster']])) {
371
            $topic_poster = $author_name[$arr['topic_poster']];
372
        } else {
373
            $topic_poster = $myts->htmlSpecialChars($arr['poster_name'] ?: $GLOBALS['xoopsConfig']['anonymous']);
374
        }
375
        $topic['topic_poster'] = $topic_poster;
376
        // irmtfan remove $topic_page_jump because there is no last post
377
        //$topic['topic_page_jump'] = $topic_page_jump;
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...
378
        // START irmtfan remove hardcoded html in URLs - add $seo_topic_url
379
        $seo_topic_url = XOOPS_URL . '/' . SEO_MODULE_NAME . '/viewtopic.php?topic_id=' . $topic['id'];
0 ignored issues
show
Bug introduced by
The constant XOOPS_URL was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
380
        $seo_forum_url = XOOPS_URL . '/' . SEO_MODULE_NAME . '/viewforum.php?forum=' . $topic['forum_id'];
381
382
        if (!empty($newbbConfig['do_rewrite'])) {
383
            $topic['seo_topic_url'] = seo_urls($seo_topic_url);
384
            $topic['seo_forum_url'] = seo_urls($seo_forum_url);
385
        } else {
386
            $topic['seo_topic_url'] = $seo_topic_url;
387
            $topic['seo_forum_url'] = $seo_forum_url;
388
        }
389
        // END irmtfan remove hardcoded html in URLs - add $seo_topic_url
390
        $block['topics'][] = $topic;
391
        unset($topic);
392
    }
393
    // START irmtfan remove hardcoded html in URLs
394
    $seo_top_allforums          = XOOPS_URL . '/' . SEO_MODULE_NAME;
395
    $block['seo_top_allforums'] = !empty($newbbConfig['do_rewrite']) ? seo_urls($seo_top_allforums) : $seo_top_allforums;
396
    $seo_top_allforums          = XOOPS_URL . '/' . SEO_MODULE_NAME . '/list.topic.php';
397
    $block['seo_top_alltopics'] = !empty($newbbConfig['do_rewrite']) ? seo_urls($seo_top_allforums) : $seo_top_allforums;
398
    $seo_top_allforums          = XOOPS_URL . '/' . SEO_MODULE_NAME . '/viewpost.php';
399
    $block['seo_top_allposts']  = !empty($newbbConfig['do_rewrite']) ? seo_urls($seo_top_allforums) : $seo_top_allforums;
400
    // END irmtfan remove hardcoded html in URLs
401
    $block['indexNav'] = (int)$options[4];
402
403
    return $block;
404
}
405
406
// options[0] - Citeria valid: title(by default), text
407
// options[1] - NumberToDisplay: any positive integer
408
// options[2] - TimeDuration: negative for hours, positive for days, for instance, -5 for 5 hours and 5 for 5 days
409
// options[3] - DisplayMode: 0-full view;1-compact view;2-lite view; Only valid for "time"
410
// options[4] - Display Navigator: 1 (by default), 0 (No)
411
// options[5] - Title/Text Length : 0 - no limit
412
// options[6] - SelectedForumIDs: null for all
413
414
/**
415
 * @param $options
416
 * @return array
417
 */
418
function b_newbb_post_show($options)
419
{
420
    global $accessForums;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
421
    global $newbbConfig;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
422
423
    include_once __DIR__ . '/../include/functions.time.php';
424
    $myts          = \MyTextSanitizer::getInstance();
425
    $block         = [];
426
    $i             = 0;
0 ignored issues
show
Unused Code introduced by
The assignment to $i is dead and can be removed.
Loading history...
427
    $order         = '';
0 ignored issues
show
Unused Code introduced by
The assignment to $order is dead and can be removed.
Loading history...
428
    $extraCriteria = '';
429
    $time_criteria = null;
0 ignored issues
show
Unused Code introduced by
The assignment to $time_criteria is dead and can be removed.
Loading history...
430
    if (!empty($options[2])) {
431
        $time_criteria = time() - newbbGetSinceTime($options[2]);
432
        $extraCriteria = ' AND p.post_time>' . $time_criteria;
433
    }
434
435
    switch ($options[0]) {
436
        case 'text':
437
            if (!empty($newbbConfig['enable_karma'])) {
438
                $extraCriteria .= ' AND p.post_karma = 0';
439
            }
440
            if (!empty($newbbConfig['allow_require_reply'])) {
441
                $extraCriteria .= ' AND p.require_reply = 0';
442
            }
443
        // no break
444
        default:
445
            $order = 'p.post_id';
446
            break;
447
    }
448
449
    if (!isset($accessForums)) {
450
        /** var Newbb\PermissionHandler $permHandler */
451
        $permHandler = Newbb\Helper::getInstance()->getHandler('Permission');
452
        if (!$accessForums = $permHandler->getForums()) {
453
            return $block;
454
        }
455
    }
456
457
    $newbbConfig = newbbLoadConfig();
458
    if (!empty($newbbConfig['do_rewrite'])) {
459
        include_once $GLOBALS['xoops']->path('modules/newbb/seo_url.php');
460
    } else {
461
        if (!defined('SEO_MODULE_NAME')) {
462
            define('SEO_MODULE_NAME', 'modules/newbb');
463
        }
464
    }
465
466
    if (!empty($options[6])) {
467
        $myallowedForums = array_filter(array_slice($options, 6), 'b_newbb_array_filter'); // get allowed forums
468
        $allowedForums   = array_intersect($myallowedForums, $accessForums);
469
    } else {
470
        $allowedForums = $accessForums;
471
    }
472
    if (empty($allowedForums)) {
473
        return $block;
474
    }
475
476
    $forumCriteria   = ' AND p.forum_id IN (' . implode(',', $allowedForums) . ')';
477
    $approveCriteria = ' AND p.approved = 1';
478
479
    $query = 'SELECT';
480
    $query .= '    p.post_id, p.subject, p.post_time, p.icon, p.uid, p.poster_name,';
481
    if ('text' === $options[0]) {
482
        $query .= '    pt.dohtml, pt.dosmiley, pt.doxcode, pt.dobr, pt.post_text,';
483
    }
484
    $query .= '    f.forum_id, f.forum_name' . '    FROM ' . $GLOBALS['xoopsDB']->prefix('newbb_posts') . ' AS p ' . '    LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('newbb_forums') . ' AS f ON f.forum_id=p.forum_id';
485
    if ('text' === $options[0]) {
486
        $query .= '    LEFT JOIN ' . $GLOBALS['xoopsDB']->prefix('newbb_posts_text') . ' AS pt ON pt.post_id=p.post_id';
487
    }
488
    $query .= '    WHERE 1=1 ' . $forumCriteria . $approveCriteria . $extraCriteria . ' ORDER BY ' . $order . ' DESC';
489
490
    $result = $GLOBALS['xoopsDB']->query($query, $options[1], 0);
491
    if (!$result) {
492
        //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...
493
        return $block;
494
    }
495
    $block['disp_mode'] = ('text' === $options[0]) ? 3 : $options[3]; // 0 - full view; 1 - compact view; 2 - lite view;
496
    $rows               = [];
497
    $author             = [];
498
    while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($result))) {
499
        $rows[]              = $row;
500
        $author[$row['uid']] = 1;
501
    }
502
    if (count($rows) < 1) {
503
        return $block;
504
    }
505
    include_once __DIR__ . '/../include/functions.user.php';
506
    $author_name = newbbGetUnameFromIds(array_keys($author), $newbbConfig['show_realname'], true);
507
508
    foreach ($rows as $arr) {
509
        //if ($arr['icon'] && is_file($GLOBALS['xoops']->path('images/subject/' . $arr['icon']))) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
72% 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...
510
        if (!empty($arr['icon'])) {
511
            $last_post_icon = '<img src="' . XOOPS_URL . '/images/subject/' . htmlspecialchars($arr['icon']) . '" alt="" />';
0 ignored issues
show
Unused Code introduced by
The assignment to $last_post_icon is dead and can be removed.
Loading history...
Bug introduced by
The constant XOOPS_URL was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
512
        } else {
513
            $last_post_icon = '<img src="' . XOOPS_URL . '/images/subject/icon1.gif" alt="" />';
514
        }
515
        //$topic['jump_post'] = "<a href='" . XOOPS_URL . "/modules/newbb/viewtopic.php?post_id=" . $arr['post_id'] ."#forumpost" . $arr['post_id'] . "'>" . $last_post_icon . '</a>';
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...
516
        $topic               = [];
517
        $topic['forum_id']   = $arr['forum_id'];
518
        $topic['forum_name'] = $myts->htmlSpecialChars($arr['forum_name']);
519
        //$topic['id'] = $arr['topic_id'];
0 ignored issues
show
Unused Code Comprehensibility introduced by
75% 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...
520
521
        $title = $myts->htmlSpecialChars($arr['subject']);
522
        if ('text' !== $options[0] && !empty($options[5])) {
523
            $title = xoops_substr($title, 0, $options[5]);
0 ignored issues
show
Bug introduced by
The function xoops_substr was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

523
            $title = /** @scrutinizer ignore-call */ xoops_substr($title, 0, $options[5]);
Loading history...
524
        }
525
        $topic['title']   = $title;
526
        $topic['post_id'] = $arr['post_id'];
527
        $topic['time']    = newbbFormatTimestamp($arr['post_time']);
528
        if (!empty($author_name[$arr['uid']])) {
529
            $topic_poster = $author_name[$arr['uid']];
530
        } else {
531
            $topic_poster = $myts->htmlSpecialChars($arr['poster_name'] ?: $GLOBALS['xoopsConfig']['anonymous']);
532
        }
533
        $topic['topic_poster'] = $topic_poster;
534
535
        if ('text' === $options[0]) {
536
            $post_text = $myts->displayTarea($arr['post_text'], $arr['dohtml'], $arr['dosmiley'], $arr['doxcode'], 1, $arr['dobr']);
537
            if (!empty($options[5])) {
538
                $post_text = xoops_substr(strip_tags($post_text), 0, $options[5]);
539
            }
540
            $topic['post_text'] = $post_text;
541
        }
542
        // START irmtfan remove hardcoded html in URLs
543
        $seo_url       = XOOPS_URL . '/' . SEO_MODULE_NAME . '/viewtopic.php?post_id=' . $topic['post_id'];
544
        $seo_forum_url = XOOPS_URL . '/' . SEO_MODULE_NAME . '/viewforum.php?forum=' . $topic['forum_id'];
545
        // END irmtfan remove hardcoded html in URLs
546
        if (!empty($newbbConfig['do_rewrite'])) {
547
            $topic['seo_url']       = seo_urls($seo_url);
548
            $topic['seo_forum_url'] = seo_urls($seo_forum_url);
549
        } else {
550
            $topic['seo_url']       = $seo_url;
551
            $topic['seo_forum_url'] = $seo_forum_url;
552
        }
553
554
        $block['topics'][] = $topic;
555
        unset($topic);
556
    }
557
    // START irmtfan remove hardcoded html in URLs
558
    $seo_top_allforums          = XOOPS_URL . '/' . SEO_MODULE_NAME;
559
    $block['seo_top_allforums'] = !empty($newbbConfig['do_rewrite']) ? seo_urls($seo_top_allforums) : $seo_top_allforums;
560
    $seo_top_allforums          = XOOPS_URL . '/' . SEO_MODULE_NAME . '/list.topic.php';
561
    $block['seo_top_alltopics'] = !empty($newbbConfig['do_rewrite']) ? seo_urls($seo_top_allforums) : $seo_top_allforums;
562
    $seo_top_allforums          = XOOPS_URL . '/' . SEO_MODULE_NAME . '/viewpost.php';
563
    $block['seo_top_allposts']  = !empty($newbbConfig['do_rewrite']) ? seo_urls($seo_top_allforums) : $seo_top_allforums;
564
    // END irmtfan remove hardcoded html in URLs
565
566
    $block['indexNav'] = (int)$options[4];
567
568
    return $block;
569
}
570
571
// options[0] - Citeria valid: post(by default), topic, digest, sticky
572
// options[1] - NumberToDisplay: any positive integer
573
// options[2] - TimeDuration: negative for hours, positive for days, for instance, -5 for 5 hours and 5 for 5 days
574
// options[3] - DisplayMode: 0-full view;1-compact view;
575
// options[4] - Display Navigator: 1 (by default), 0 (No)
576
// options[5] - Title Length : 0 - no limit
577
// options[6] - SelectedForumIDs: null for all
578
579
/**
580
 * @param $options
581
 * @return array
582
 */
583
function b_newbb_author_show($options)
584
{
585
    global $accessForums;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
586
    global $newbbConfig;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
587
    $myts  = \MyTextSanitizer::getInstance();
588
    $block = [];
589
    //    $i              = 0;
0 ignored issues
show
Unused Code Comprehensibility introduced by
43% 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...
590
    $type          = 'topic';
591
    $order         = 'count';
592
    $extraCriteria = '';
593
    $time_criteria = null;
594
    if (!empty($options[2])) {
595
        include_once __DIR__ . '/../include/functions.time.php';
596
        $time_criteria = time() - newbbGetSinceTime($options[2]);
597
        $extraCriteria = ' AND topic_time > ' . $time_criteria;
598
    }
599
    switch ($options[0]) {
600
        case 'topic':
601
            break;
602
        case 'digest':
603
            $extraCriteria = ' AND topic_digest = 1';
604
            if (null !== $time_criteria) {
605
                $extraCriteria .= ' AND digest_time > ' . $time_criteria;
606
            }
607
            break;
608
        case 'sticky':
609
            $extraCriteria .= ' AND topic_sticky = 1';
610
            break;
611
        case 'post':
612
        default:
613
            $type = 'post';
614
            if (null !== $time_criteria) {
615
                $extraCriteria = ' AND post_time > ' . $time_criteria;
616
            }
617
            break;
618
    }
619
620
    if (!isset($accessForums)) {
621
        /** var Newbb\PermissionHandler $permHandler */
622
        $permHandler = Newbb\Helper::getInstance()->getHandler('Permission');
623
        if (!$accessForums = $permHandler->getForums()) {
624
            return $block;
625
        }
626
    }
627
628
    if (!empty($options[5])) {
629
        $myallowedForums = array_filter(array_slice($options, 5), 'b_newbb_array_filter'); // get allowed forums
630
        $allowedForums   = array_intersect($myallowedForums, $accessForums);
631
    } else {
632
        $allowedForums = $accessForums;
633
    }
634
    if (empty($allowedForums)) {
635
        return false;
0 ignored issues
show
Bug Best Practice introduced by
The expression return false returns the type false which is incompatible with the documented return type array.
Loading history...
636
    }
637
638
    if ('topic' === $type) {
639
        $forumCriteria   = ' AND forum_id IN (' . implode(',', $allowedForums) . ')';
640
        $approveCriteria = ' AND approved = 1';
641
        $query           = 'SELECT DISTINCT topic_poster AS author, COUNT(*) AS count
642
                    FROM ' . $GLOBALS['xoopsDB']->prefix('newbb_topics') . '
643
                    WHERE topic_poster>0 ' . $forumCriteria . $approveCriteria . $extraCriteria . ' GROUP BY topic_poster ORDER BY ' . $order . ' DESC';
644
    } else {
645
        $forumCriteria   = ' AND forum_id IN (' . implode(',', $allowedForums) . ')';
646
        $approveCriteria = ' AND approved = 1';
647
        $query           = 'SELECT DISTINCT uid AS author, COUNT(*) AS count
648
                    FROM ' . $GLOBALS['xoopsDB']->prefix('newbb_posts') . '
649
                    WHERE uid > 0 ' . $forumCriteria . $approveCriteria . $extraCriteria . ' GROUP BY uid ORDER BY ' . $order . ' DESC';
650
    }
651
652
    $result = $GLOBALS['xoopsDB']->query($query, $options[1], 0);
653
    if (!$result) {
654
        //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...
655
        return $block;
656
    }
657
    $author = [];
658
    while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($result))) {
659
        $author[$row['author']]['count'] = $row['count'];
660
    }
661
    if (count($author) < 1) {
662
        return $block;
663
    }
664
    include_once __DIR__ . '/../include/functions.user.php';
665
    $author_name = newbbGetUnameFromIds(array_keys($author), $newbbConfig['show_realname']);
666
    foreach (array_keys($author) as $uid) {
667
        $author[$uid]['name'] = $myts->htmlSpecialChars($author_name[$uid]);
668
    }
669
    $block['authors']   =& $author;
670
    $block['disp_mode'] = $options[3]; // 0 - full view; 1 - lite view;
671
    $block['indexNav']  = (int)$options[4];
672
673
    return $block;
674
}
675
676
/**
677
 * @param $options
678
 * @return string
679
 */
680
function b_newbb_edit($options)
681
{
682
    include_once __DIR__ . '/../include/functions.forum.php';
683
684
    $form = _MB_NEWBB_CRITERIA . "<select name='options[0]'>";
685
    $form .= "<option value='time'";
686
    if ('time' === $options[0]) {
687
        $form .= " selected='selected' ";
688
    }
689
    $form .= '>' . _MB_NEWBB_CRITERIA_TIME . '</option>';
690
    $form .= '</select>';
691
    $form .= '<br>' . _MB_NEWBB_DISPLAY . "<input type='text' name='options[1]' value='" . $options[1] . "' />";
692
    $form .= '<br>' . _MB_NEWBB_TIME . "<input type='text' name='options[2]' value='" . $options[2] . "' />";
693
    $form .= '<br>&nbsp;&nbsp;&nbsp;&nbsp;<small>' . _MB_NEWBB_TIME_DESC . '</small>';
694
    $form .= '<br>' . _MB_NEWBB_DISPLAYMODE . "<input type='radio' name='options[3]' value='0'";
695
    if (0 == $options[3]) {
696
        $form .= ' checked';
697
    }
698
    $form .= ' />&nbsp;' . _MB_NEWBB_DISPLAYMODE_FULL . "<input type='radio' name='options[3]' value='1'";
699
    if (1 == $options[3]) {
700
        $form .= ' checked';
701
    }
702
    $form .= ' />&nbsp;' . _MB_NEWBB_DISPLAYMODE_COMPACT . "<input type='radio' name='options[3]' value='2'";
703
    if (2 == $options[3]) {
704
        $form .= ' checked';
705
    }
706
    $form .= ' />&nbsp;' . _MB_NEWBB_DISPLAYMODE_LITE;
707
708
    $form .= '<br>' . _MB_NEWBB_INDEXNAV . '<input type="radio" name="options[4]" value="1"';
709
    if (1 == $options[4]) {
710
        $form .= ' checked';
711
    }
712
    $form .= ' />' . _YES . '<input type="radio" name="options[4]" value="0"';
0 ignored issues
show
Bug introduced by
The constant _YES was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
713
    if (0 == $options[4]) {
714
        $form .= ' checked';
715
    }
716
    $form .= ' />' . _NO;
0 ignored issues
show
Bug introduced by
The constant _NO was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
717
718
    $form .= '<br>' . _MB_NEWBB_TITLE_LENGTH . "<input type='text' name='options[5]' value='" . $options[5] . "' />";
719
720
    $form .= '<br><br>' . _MB_NEWBB_FORUMLIST;
721
722
    $optionsForum = array_filter(array_slice($options, 6), 'b_newbb_array_filter'); // get allowed forums
723
    $isAll        = (0 === count($optionsForum) || empty($optionsForum[0]));
724
    $form         .= '<br>&nbsp;&nbsp;<select name="options[]" multiple="multiple">';
725
    $form         .= '<option value="0" ';
726
    if ($isAll) {
727
        $form .= ' selected';
728
    }
729
    $form .= '>' . _ALL . '</option>';
0 ignored issues
show
Bug introduced by
The constant _ALL was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
730
    $form .= newbbForumSelectBox($optionsForum);
731
    $form .= '</select><br>';
732
733
    return $form;
734
}
735
736
/**
737
 * @param $options
738
 * @return string
739
 */
740
function b_newbb_topic_edit($options)
741
{
742
    include_once __DIR__ . '/../include/functions.forum.php';
743
    $form = _MB_NEWBB_CRITERIA . "<select name='options[0]'>";
744
    $form .= "<option value='time'";
745
    if ('time' === $options[0]) {
746
        $form .= " selected='selected' ";
747
    }
748
    $form .= '>' . _MB_NEWBB_CRITERIA_TIME . '</option>';
749
    $form .= "<option value='views'";
750
    if ('views' === $options[0]) {
751
        $form .= " selected='selected' ";
752
    }
753
    $form .= '>' . _MB_NEWBB_CRITERIA_VIEWS . '</option>';
754
    $form .= "<option value='replies'";
755
    if ('replies' === $options[0]) {
756
        $form .= " selected='selected' ";
757
    }
758
    $form .= '>' . _MB_NEWBB_CRITERIA_REPLIES . '</option>';
759
    $form .= "<option value='digest'";
760
    if ('digest' === $options[0]) {
761
        $form .= " selected='selected' ";
762
    }
763
    $form .= '>' . _MB_NEWBB_CRITERIA_DIGEST . '</option>';
764
    $form .= "<option value='sticky'";
765
    if ('sticky' === $options[0]) {
766
        $form .= " selected='selected' ";
767
    }
768
    $form .= '>' . _MB_NEWBB_CRITERIA_STICKY . '</option>';
769
    $form .= '</select>';
770
    $form .= '<br>' . _MB_NEWBB_DISPLAY . "<input type='text' name='options[1]' value='" . $options[1] . "' />";
771
    $form .= '<br>' . _MB_NEWBB_TIME . "<input type='text' name='options[2]' value='" . $options[2] . "' />";
772
    $form .= '<br>&nbsp;&nbsp;&nbsp;&nbsp;<small>' . _MB_NEWBB_TIME_DESC . '</small>';
773
    $form .= '<br>' . _MB_NEWBB_DISPLAYMODE . "<input type='radio' name='options[3]' value='0'";
774
    if (0 == $options[3]) {
775
        $form .= ' checked';
776
    }
777
    $form .= ' />&nbsp;' . _MB_NEWBB_DISPLAYMODE_FULL . "<input type='radio' name='options[3]' value='1'";
778
    if (1 == $options[3]) {
779
        $form .= ' checked';
780
    }
781
    $form .= ' />&nbsp;' . _MB_NEWBB_DISPLAYMODE_COMPACT . "<input type='radio' name='options[3]' value='2'";
782
    if (2 == $options[3]) {
783
        $form .= ' checked';
784
    }
785
    $form .= ' />&nbsp;' . _MB_NEWBB_DISPLAYMODE_LITE;
786
787
    $form .= '<br>' . _MB_NEWBB_INDEXNAV . '<input type="radio" name="options[4]" value="1"';
788
    if (1 == $options[4]) {
789
        $form .= ' checked';
790
    }
791
    $form .= ' />' . _YES . '<input type="radio" name="options[4]" value="0"';
0 ignored issues
show
Bug introduced by
The constant _YES was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
792
    if (0 == $options[4]) {
793
        $form .= ' checked';
794
    }
795
    $form .= ' />' . _NO;
0 ignored issues
show
Bug introduced by
The constant _NO was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
796
797
    $form .= '<br>' . _MB_NEWBB_TITLE_LENGTH . "<input type='text' name='options[5]' value='" . $options[5] . "' />";
798
799
    $form .= '<br><br>' . _MB_NEWBB_FORUMLIST;
800
801
    $optionsForum = array_filter(array_slice($options, 6), 'b_newbb_array_filter'); // get allowed forums
802
803
    $isAll = (0 === count($optionsForum) || empty($optionsForum[0]));
804
    $form  .= '<br>&nbsp;&nbsp;<select name="options[]" multiple="multiple">';
805
    $form  .= '<option value="0" ';
806
    if ($isAll) {
807
        $form .= ' selected="selected"';
808
    }
809
    $form .= '>' . _ALL . '</option>';
0 ignored issues
show
Bug introduced by
The constant _ALL was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
810
    $form .= newbbForumSelectBox($optionsForum);
811
    $form .= '</select><br>';
812
813
    return $form;
814
}
815
816
/**
817
 * @param $options
818
 * @return string
819
 */
820
function b_newbb_post_edit($options)
821
{
822
    include_once __DIR__ . '/../include/functions.forum.php';
823
    $form = _MB_NEWBB_CRITERIA . "<select name='options[0]'>";
824
    $form .= "<option value='title'";
825
    if ('title' === $options[0]) {
826
        $form .= " selected='selected' ";
827
    }
828
    $form .= '>' . _MB_NEWBB_CRITERIA_TITLE . '</option>';
829
    $form .= "<option value='text'";
830
    if ('text' === $options[0]) {
831
        $form .= " selected='selected' ";
832
    }
833
    $form .= '>' . _MB_NEWBB_CRITERIA_TEXT . '</option>';
834
    $form .= '</select>';
835
    $form .= '<br>' . _MB_NEWBB_DISPLAY . "<input type='text' name='options[1]' value='" . $options[1] . "' />";
836
    $form .= '<br>' . _MB_NEWBB_TIME . "<input type='text' name='options[2]' value='" . $options[2] . "' />";
837
    $form .= '<br>&nbsp;&nbsp;&nbsp;&nbsp;<small>' . _MB_NEWBB_TIME_DESC . '</small>';
838
    $form .= '<br>' . _MB_NEWBB_DISPLAYMODE . "<input type='radio' name='options[3]' value='0'";
839
    if (0 == $options[3]) {
840
        $form .= ' checked';
841
    }
842
    $form .= ' />&nbsp;' . _MB_NEWBB_DISPLAYMODE_FULL . "<input type='radio' name='options[3]' value='1'";
843
    if (1 == $options[3]) {
844
        $form .= ' checked';
845
    }
846
    $form .= ' />&nbsp;' . _MB_NEWBB_DISPLAYMODE_COMPACT . "<input type='radio' name='options[3]' value='2'";
847
    if (2 == $options[3]) {
848
        $form .= ' checked';
849
    }
850
    $form .= ' />&nbsp;' . _MB_NEWBB_DISPLAYMODE_LITE;
851
852
    $form .= '<br>' . _MB_NEWBB_INDEXNAV . '<input type="radio" name="options[4]" value="1"';
853
    if (1 == $options[4]) {
854
        $form .= ' checked';
855
    }
856
    $form .= ' />' . _YES . '<input type="radio" name="options[4]" value="0"';
0 ignored issues
show
Bug introduced by
The constant _YES was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
857
    if (0 == $options[4]) {
858
        $form .= ' checked';
859
    }
860
    $form .= ' />' . _NO;
0 ignored issues
show
Bug introduced by
The constant _NO was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
861
862
    $form .= '<br>' . _MB_NEWBB_TITLE_LENGTH . "<input type='text' name='options[5]' value='" . $options[5] . "' />";
863
864
    $form .= '<br><br>' . _MB_NEWBB_FORUMLIST;
865
866
    $optionsForum = array_filter(array_slice($options, 6), 'b_newbb_array_filter'); // get allowed forums
867
    $isAll        = (0 === count($optionsForum) || empty($optionsForum[0]));
868
    $form         .= '<br>&nbsp;&nbsp;<select name="options[]" multiple="multiple">';
869
    $form         .= '<option value="0" ';
870
    if ($isAll) {
871
        $form .= ' selected="selected"';
872
    }
873
    $form .= '>' . _ALL . '</option>';
0 ignored issues
show
Bug introduced by
The constant _ALL was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
874
    $form .= newbbForumSelectBox($optionsForum);
875
    $form .= '</select><br>';
876
877
    return $form;
878
}
879
880
/**
881
 * @param $options
882
 * @return string
883
 */
884
function b_newbb_author_edit($options)
885
{
886
    include_once __DIR__ . '/../include/functions.forum.php';
887
    $form = _MB_NEWBB_CRITERIA . "<select name='options[0]'>";
888
    $form .= "<option value='post'";
889
    if ('post' === $options[0]) {
890
        $form .= " selected='selected' ";
891
    }
892
    $form .= '>' . _MB_NEWBB_CRITERIA_POST . '</option>';
893
    $form .= "<option value='topic'";
894
    if ('topic' === $options[0]) {
895
        $form .= " selected='selected' ";
896
    }
897
    $form .= '>' . _MB_NEWBB_CRITERIA_TOPIC . '</option>';
898
    $form .= "<option value='digest'";
899
    if ('digest' === $options[0]) {
900
        $form .= " selected='selected' ";
901
    }
902
    $form .= '>' . _MB_NEWBB_CRITERIA_DIGESTS . '</option>';
903
    $form .= "<option value='sticky'";
904
    if ('sticky' === $options[0]) {
905
        $form .= " selected='selected' ";
906
    }
907
    $form .= '>' . _MB_NEWBB_CRITERIA_STICKYS . '</option>';
908
    $form .= '</select>';
909
    $form .= '<br>' . _MB_NEWBB_DISPLAY . "<input type='text' name='options[1]' value='" . $options[1] . "' />";
910
    $form .= '<br>' . _MB_NEWBB_TIME . "<input type='text' name='options[2]' value='" . $options[2] . "' />";
911
    $form .= '<br>&nbsp;&nbsp;&nbsp;&nbsp;<small>' . _MB_NEWBB_TIME_DESC . '</small>';
912
    $form .= '<br>' . _MB_NEWBB_DISPLAYMODE . "<input type='radio' name='options[3]' value='0'";
913
    if (0 == $options[3]) {
914
        $form .= ' checked';
915
    }
916
    $form .= ' />&nbsp;' . _MB_NEWBB_DISPLAYMODE_COMPACT . "<input type='radio' name='options[3]' value='1'";
917
    if (1 == $options[3]) {
918
        $form .= ' checked';
919
    }
920
    $form .= ' />&nbsp;' . _MB_NEWBB_DISPLAYMODE_LITE;
921
922
    $form .= '<br>' . _MB_NEWBB_INDEXNAV . '<input type="radio" name="options[4]" value="1"';
923
    if (1 == $options[4]) {
924
        $form .= ' checked';
925
    }
926
    $form .= ' />' . _YES . '<input type="radio" name="options[4]" value="0"';
0 ignored issues
show
Bug introduced by
The constant _YES was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
927
    if (0 == $options[4]) {
928
        $form .= ' checked';
929
    }
930
    $form .= ' />' . _NO;
0 ignored issues
show
Bug introduced by
The constant _NO was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
931
932
    $form .= '<br><br>' . _MB_NEWBB_FORUMLIST;
933
934
    $optionsForum = array_filter(array_slice($options, 5), 'b_newbb_array_filter'); // get allowed forums
935
    $isAll        = (0 === count($optionsForum) || empty($optionsForum[0]));
936
    $form         .= '<br>&nbsp;&nbsp;<select name="options[]" multiple="multiple">';
937
    $form         .= '<option value="0" ';
938
    if ($isAll) {
939
        $form .= ' selected="selected"';
940
    }
941
    $form .= '>' . _ALL . '</option>';
0 ignored issues
show
Bug introduced by
The constant _ALL was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
942
    $form .= newbbForumSelectBox($optionsForum);
943
    $form .= '</select><br>';
944
945
    return $form;
946
}
947
948
/**
949
 * @param $options
950
 * @return bool
951
 */
952
function b_newbb_custom($options)
953
{
954
    // if no newbb module block set, we have to include the language file
955
    if (is_readable($GLOBALS['xoops']->path('modules/newbb/language/' . $GLOBALS['xoopsConfig']['language'] . '/blocks.php'))) {
956
        include_once $GLOBALS['xoops']->path('modules/newbb/language/' . $GLOBALS['xoopsConfig']['language'] . '/blocks.php');
957
    } else {
958
        include_once $GLOBALS['xoops']->path('modules/newbb/language/english/blocks.php');
959
    }
960
961
    $options = explode('|', $options);
962
    $block   = b_newbb_show($options);
963
    if (count($block['topics']) < 1) {
964
        return false;
965
    }
966
967
    $tpl = new \XoopsTpl();
0 ignored issues
show
Bug introduced by
The type XoopsTpl was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
968
    $tpl->assign('block', $block);
969
    $tpl->display('db:newbb_block.tpl');
970
}
971
972
/**
973
 * @param $options
974
 * @return bool
975
 */
976
function b_newbb_custom_topic($options)
977
{
978
979
    // if no newbb module block set, we have to include the language file
980
    if (is_readable($GLOBALS['xoops']->path('modules/newbb/language/' . $GLOBALS['xoopsConfig']['language'] . '/blocks.php'))) {
981
        include_once $GLOBALS['xoops']->path('modules/newbb/language/' . $GLOBALS['xoopsConfig']['language'] . '/blocks.php');
982
    } else {
983
        include_once $GLOBALS['xoops']->path('modules/newbb/language/english/blocks.php');
984
    }
985
986
    $options = explode('|', $options);
987
    $block   = b_newbb_topic_show($options);
988
    if (count($block['topics']) < 1) {
989
        return false;
990
    }
991
992
    $tpl = new \XoopsTpl();
993
    $tpl->assign('block', $block);
994
    $tpl->display('db:newbb_block_topic.tpl');
995
}
996
997
/**
998
 * @param $options
999
 * @return bool
1000
 */
1001
function b_newbb_custom_post($options)
1002
{
1003
1004
    // if no newbb module block set, we have to include the language file
1005
    if (is_readable($GLOBALS['xoops']->path('modules/newbb/language/' . $GLOBALS['xoopsConfig']['language'] . '/blocks.php'))) {
1006
        include_once $GLOBALS['xoops']->path('modules/newbb/language/' . $GLOBALS['xoopsConfig']['language'] . '/blocks.php');
1007
    } else {
1008
        include_once $GLOBALS['xoops']->path('modules/newbb/language/english/blocks.php');
1009
    }
1010
1011
    $options = explode('|', $options);
1012
    $block   = b_newbb_post_show($options);
1013
    if (count($block['topics']) < 1) {
1014
        return false;
1015
    }
1016
1017
    $tpl = new \XoopsTpl();
1018
    $tpl->assign('block', $block);
1019
    $tpl->display('db:newbb_block_post.tpl');
1020
}
1021
1022
/**
1023
 * @param $options
1024
 * @return bool
1025
 */
1026
function b_newbb_custom_author($options)
1027
{
1028
    // if no newbb module block set, we have to include the language file
1029
    if (is_readable($GLOBALS['xoops']->path('modules/newbb/language/' . $GLOBALS['xoopsConfig']['language'] . '/blocks.php'))) {
1030
        include_once $GLOBALS['xoops']->path('modules/newbb/language/' . $GLOBALS['xoopsConfig']['language'] . '/blocks.php');
1031
    } else {
1032
        include_once $GLOBALS['xoops']->path('modules/newbb/language/english/blocks.php');
1033
    }
1034
1035
    $options = explode('|', $options);
1036
    $block   = b_newbb_author_show($options);
1037
    if (count($block['authors']) < 1) {
1038
        return false;
1039
    }
1040
1041
    $tpl = new \XoopsTpl();
1042
    $tpl->assign('block', $block);
1043
    $tpl->display('db:newbb_block_author.tpl');
1044
}
1045
1046
// irmtfan add local stylesheet and js footer.php
1047
include_once $GLOBALS['xoops']->path('modules/newbb/footer.php');
1048