Issues (384)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  Header Injection
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

blocks/news_top.php (15 issues)

1
<?php declare(strict_types=1);
2
/*
3
 * You may not change or alter any portion of this comment or credits
4
 * of supporting developers from this source code or any supporting source code
5
 * which is considered copyrighted (c) material of the original comment or credit authors.
6
 *
7
 * This program is distributed in the hope that it will be useful,
8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10
 */
11
12
/**
13
 * @copyright      {@link https://xoops.org/ XOOPS Project}
14
 * @license        {@link https://www.gnu.org/licenses/gpl-2.0.html GNU GPL 2 or later}
15
 * @author         XOOPS Development Team
16
 */
17
18
use Xmf\Request;
0 ignored issues
show
This use statement conflicts with another class in this namespace, Request. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
19
use XoopsModules\News\{
20
    Helper,
21
    NewsStory,
22
    NewsTopic,
23
    XoopsTree,
24
    Utility
25
};
26
27
28
//require_once XOOPS_ROOT_PATH . '/modules/news/class/class.newsstory.php';
29
//require_once XOOPS_ROOT_PATH . '/modules/news/class/class.newstopic.php';
30
31
/**
32
 * Notes about the spotlight :
33
 * If you have restricted topics on index page (in fact if the program must completly respect the permissions) and if
34
 * the news you have selected to be viewed in the spotlight can't be viewed by someone then the spotlight is not visible !
35
 * This is available in the classical and in the tabbed view.
36
 * But if you have uncheck the option "Restrict topics on index page", then the news will be visible but users without
37
 * permissions will be rejected when they will try to read news content.
38
 *
39
 * Also, if you have selected a tabbed view and wanted to use the Spotlight but did not choosed a story, then the block
40
 * will switch to the "most recent news" mode (the visible news will be searched according to the permissions)
41
 * @param $options
42
 * @return array|string
43
 */
44
function b_news_top_show($options)
45
{
46
    global $xoopsConfig;
47
48
    /** @var Helper $helper */
49
    if (!class_exists(Helper::class)) {
50
        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|string.
Loading history...
51
    }
52
53
    $helper = Helper::getInstance();
54
55
    $helper->loadLanguage('main');
56
57
    $myts        = \MyTextSanitizer::getInstance();
58
    $block       = [];
59
    $displayname = Utility::getModuleOption('displayname');
60
    $tabskin     = Utility::getModuleOption('tabskin');
61
62
    $block['displayview'] = $options[8];
63
    $block['tabskin']     = $tabskin;
64
    $block['imagesurl']   = XOOPS_URL . '/modules/news/assets/images/';
65
66
    $restricted = Utility::getModuleOption('restrictindex');
67
    $dateformat = Utility::getModuleOption('dateformat');
68
    $infotips   = Utility::getModuleOption('infotips');
69
    $newsrating = Utility::getModuleOption('ratenews');
70
    if ('' == $dateformat) {
71
        $dateformat = 's';
72
    }
73
74
    $perm_verified = false;
75
    $news_visible  = true;
76
    // Is the spotlight visible ?
77
    if (1 == $options[4] && $restricted && 0 == $options[5]) {
78
        $perm_verified   = true;
79
        $permittedtopics = Utility::getMyItemIds();
80
        $permstory       = new NewsStory($options[6]);
81
        if (!in_array($permstory->topicid(), $permittedtopics, true)) {
82
            $usespotlight = false;
0 ignored issues
show
The assignment to $usespotlight is dead and can be removed.
Loading history...
83
            $news_visible = false;
84
            $topicstitles = [];
0 ignored issues
show
The assignment to $topicstitles is dead and can be removed.
Loading history...
85
        }
86
        0 == $options[4];
87
    }
88
    // Try to see what tabs are visibles (if we are in restricted view of course)
89
    if (2 == $options[8] && $restricted && 0 != $options[14]) {
90
        $topics2         = [];
91
        $permittedtopics = Utility::getMyItemIds();
92
        $topics          = array_slice($options, 14);
93
        foreach ($topics as $onetopic) {
94
            if (in_array($onetopic, $permittedtopics, true)) {
95
                $topics2[] = $onetopic;
96
            }
97
        }
98
        $before  = array_slice($options, 0, 14);
99
        $options = array_merge($before, $topics2);
100
    }
101
102
    if (2 == $options[8]) { // Tabbed view ********************************************************************************************
103
        $defcolors[1] = ['#F90', '#FFFFFF', '#F90', '#C60', '#999']; // Bar Style
0 ignored issues
show
Comprehensibility Best Practice introduced by
$defcolors was never initialized. Although not strictly required by PHP, it is generally a good practice to add $defcolors = array(); before regardless.
Loading history...
104
        $defcolors[2] = ['#F90', '#FFFFFF', '#F90', '#AAA', '#666']; // Beveled
105
        $defcolors[3] = ['#F90', '#FFFFFF', '', '#789', '#789']; // Classic
106
        $defcolors[4] = ['#F90', '#FFFFFF', '', '', '']; // Folders
107
        $defcolors[5] = ['#F90', '#FFFFFF', '#CCC', 'inherit', '#999']; // MacOs
108
        $defcolors[6] = ['#F90', '#FFFFFF', '#FFF', '#DDD', '#999']; // Plain
109
        $defcolors[7] = ['#F90', '#FFFFFF', '', '', '']; // Rounded
110
        $defcolors[8] = ['#F90', '#FFFFFF', '#F90', '#930', '#C60']; // ZDnet
111
112
        $myurl = $_SERVER['SCRIPT_NAME'];
113
        if ('/' === mb_substr($myurl, mb_strlen($myurl) - 1, 1)) {
114
            $myurl .= 'index.php';
115
        }
116
        $myurl .= '?';
117
118
        foreach ($_GET as $key => $value) {
119
            if ('NewsTab' !== $key) {
120
                $myurl .= $key . '=' . $value . '&';
121
            }
122
        }
123
        $block['url'] = $myurl;
124
125
        $tabscount    = 0;
126
        $usespotlight = false;
127
128
        if (Request::hasVar('NewsTab', 'GET')) {
129
            $_SESSION['NewsTab'] = Request::getInt('NewsTab', 0, 'GET');
130
            $currenttab          = Request::getInt('NewsTab', 0, 'GET');
131
        } elseif (Request::hasVar('NewsTab', 'SESSION')) {
132
            $currenttab = Request::getInt('NewsTab', 0, 'SESSION');
133
        } else {
134
            $currenttab = 0;
135
        }
136
137
        $tmpstory     = new NewsStory();
138
        $topic        = new NewsTopic();
139
        $topics = [];
140
        $topicstitles = [];
141
        if (1 == $options[4]) { // Spotlight enabled
142
            $topicstitles[0] = _MB_NEWS_SPOTLIGHT_TITLE;
143
            ++$tabscount;
144
            $usespotlight = true;
145
        }
146
147
        if (0 == $options[5] && $restricted) { // Use a specific news and we are in restricted mode
148
            if (!$perm_verified) {
149
                $permittedtopics = Utility::getMyItemIds();
150
                $permstory       = new NewsStory($options[6]);
151
                if (!in_array($permstory->topicid(), $permittedtopics, true)) {
152
                    $usespotlight = false;
153
                    $topicstitles = [];
154
                }
155
                //unset($permstory);
156
            } elseif (!$news_visible) {
157
                $usespotlight = false;
158
                $topicstitles = [];
159
            }
160
        }
161
162
        $block['use_spotlight'] = $usespotlight;
163
164
        if (isset($options[14]) && 0 != $options[14]) { // Topic to use
165
            $topics       = array_slice($options, 14);
166
            $tabscount    += count($topics);
167
            $topicstitles = $topic->getTopicTitleFromId($topics, $topicstitles);
168
        }
169
        $tabs = [];
170
        if ($usespotlight) {
171
            $tabs[] = ['id' => 0, 'title' => _MB_NEWS_SPOTLIGHT_TITLE];
172
        }
173
        if (count($topics) > 0) {
174
            foreach ($topics as $onetopic) {
175
                if (isset($topicstitles[$onetopic])) {
176
                    $tabs[] = [
177
                        'id'      => $onetopic,
178
                        'title'   => $topicstitles[$onetopic]['title'],
179
                        'picture' => $topicstitles[$onetopic]['picture'],
180
                    ];
181
                }
182
            }
183
        }
184
        $block['tabs']                 = $tabs;
185
        $block['current_is_spotlight'] = false;
186
        $block['current_tab']          = $currenttab;
187
        $block['use_rating']           = $newsrating;
188
189
        if (0 == $currenttab && $usespotlight) { // Spotlight or not ?
190
            $block['current_is_spotlight'] = true;
191
            if (0 == $options[5]
192
                && 0 == $options[6]) { // If the story to use was no selected then we switch to the "recent news" mode.
193
                $options[5] = 1;
194
            }
195
196
            if (0 == $options[5]) { // Use a specific news
197
                $tmpstory = $permstory ?? new NewsStory($options[6]);
198
            } else { // Use the most recent news
199
                $stories = [];
0 ignored issues
show
The assignment to $stories is dead and can be removed.
Loading history...
200
                $stories = NewsStory::getAllPublished(1, 0, $restricted, 0, 1, true, $options[0]);
201
                if (count($stories) > 0) {
0 ignored issues
show
It seems like $stories can also be of type null; however, parameter $value of count() does only seem to accept Countable|array, maybe add an additional type check? ( Ignorable by Annotation )

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

201
                if (count(/** @scrutinizer ignore-type */ $stories) > 0) {
Loading history...
202
                    $firststory = $stories[0];
203
                    $tmpstory   = new NewsStory($firststory->storyid());
204
                } else {
205
                    $block['use_spotlight'] = false;
206
                }
207
            }
208
            $spotlight          = [];
209
            $spotlight['title'] = $tmpstory->title();
210
            if ('' !== $options[7]) {
211
                $spotlight['image'] = sprintf("<a href='%s'>%s</a>", XOOPS_URL . '/modules/news/article.php?storyid=' . $tmpstory->storyid(), $myts->displayTarea($options[7], $tmpstory->nohtml));
212
            }
213
            $spotlight['text'] = $tmpstory->hometext();
214
215
            // Added 16 february 2007 *****************************************
216
            $story_user = null;
0 ignored issues
show
The assignment to $story_user is dead and can be removed.
Loading history...
217
            $story_user = new \XoopsUser($tmpstory->uid());
218
            if (is_object($story_user)) {
219
                $spotlight['avatar'] = XOOPS_UPLOAD_URL . '/' . $story_user->getVar('user_avatar');
220
            }
221
            // ****************************************************************
222
            $spotlight['id']     = $tmpstory->storyid();
223
            $spotlight['date']   = formatTimestamp($tmpstory->published(), $dateformat);
224
            $spotlight['hits']   = $tmpstory->counter();
225
            $spotlight['rating'] = number_format($tmpstory->rating(), 2);
226
            $spotlight['votes']  = $tmpstory->votes();
227
            if ('' !== xoops_trim($tmpstory->bodytext())) {
228
                $spotlight['read_more'] = true;
229
            } else {
230
                $spotlight['read_more'] = false;
231
            }
232
233
            $spotlight['readmore']        = sprintf("<a href='%s'>%s</a>", XOOPS_URL . '/modules/news/article.php?storyid=' . $tmpstory->storyid(), _MB_READMORE);
234
            $spotlight['title_with_link'] = sprintf("<a href='%s'>%s</a>", XOOPS_URL . '/modules/news/article.php?storyid=' . $tmpstory->storyid(), $tmpstory->title());
235
            if (1 == $tmpstory->votes()) {
236
                $spotlight['number_votes'] = _NW_ONEVOTE;
237
            } else {
238
                $spotlight['number_votes'] = sprintf(_NW_NUMVOTES, $tmpstory->votes());
239
            }
240
241
            $spotlight['votes_with_text'] = sprintf(_NW_NUMVOTES, $tmpstory->votes());
242
            $spotlight['topicid']         = $tmpstory->topicid();
243
            $spotlight['topic_title']     = $tmpstory->topic_title();
244
            // Added, topic's image and description
245
            $spotlight['topic_image']       = XOOPS_URL . '/modules/news/assets/images/topics/' . $tmpstory->topic_imgurl();
246
            $spotlight['topic_description'] = $myts->displayTarea($tmpstory->topic_description, 1);
247
248
            if (3 != $displayname) {
249
                $spotlight['author']           = sprintf('%s %s', _POSTEDBY, $tmpstory->uname());
250
                $spotlight['author_with_link'] = sprintf("%s <a href='%s'>%s</a>", _POSTEDBY, XOOPS_URL . '/userinfo.php?uid=' . $tmpstory->uid(), $tmpstory->uname());
251
            } else {
252
                $spotlight['author']           = '';
253
                $spotlight['author_with_link'] = '';
254
            }
255
            $spotlight['author_id'] = $tmpstory->uid();
256
257
            // Create the summary table under the spotlight text
258
            if (isset($options[14]) && 0 == $options[14]) { // Use all topics
259
                $stories = NewsStory::getAllPublished($options[1], 0, $restricted, 0, 1, true, $options[0]);
260
            } else { // Use some topics
261
                $topics  = array_slice($options, 14);
262
                $stories = NewsStory::getAllPublished($options[1], 0, $restricted, $topics, 1, true, $options[0]);
0 ignored issues
show
$topics of type array is incompatible with the type integer expected by parameter $topic of XoopsModules\News\NewsStory::getAllPublished(). ( Ignorable by Annotation )

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

262
                $stories = NewsStory::getAllPublished($options[1], 0, $restricted, /** @scrutinizer ignore-type */ $topics, 1, true, $options[0]);
Loading history...
263
            }
264
            if (count($stories) > 0) {
265
                foreach ($stories as $key => $story) {
266
                    $news  = [];
267
                    $title = $story->title();
268
                    if (mb_strlen($title) > $options[2]) {
269
                        $title = xoops_substr($title, 0, $options[2] + 3);
270
                    }
271
                    $news['title']       = $title;
272
                    $news['id']          = $story->storyid();
273
                    $news['date']        = formatTimestamp($story->published(), $dateformat);
274
                    $news['hits']        = $story->counter();
275
                    $news['rating']      = number_format($story->rating(), 2);
276
                    $news['votes']       = $story->votes();
277
                    $news['topicid']     = $story->topicid();
278
                    $news['topic_title'] = $story->topic_title();
279
                    $news['topic_color'] = '#' . $myts->displayTarea($story->topic_color);
280
                    $news['picture']     = XOOPS_URL . '/uploads/news/image/' . $story->picture();
281
                    $news['pictureinfo'] = $story->pictureinfo();
282
                    if (3 != $displayname) {
283
                        $news['author'] = sprintf('%s %s', _POSTEDBY, $story->uname());
284
                    } else {
285
                        $news['author'] = '';
286
                    }
287
                    if ($options[3] > 0) {
288
                        $html           = 1 == $story->nohtml() ? 0 : 1;
289
                        $news['teaser'] = Utility::truncateTagSafe($myts->displayTarea($story->hometext(), $html), $options[3] + 3);
290
                    } else {
291
                        $news['teaser'] = '';
292
                    }
293
                    if ($infotips > 0) {
294
                        $news['infotips'] = ' title="' . Utility::makeInfotips($story->hometext()) . '"';
295
                    } else {
296
                        $news['infotips'] = '';
297
                    }
298
299
                    $news['title_with_link'] = sprintf("<a href='%s'%s>%s</a>", XOOPS_URL . '/modules/news/article.php?storyid=' . $story->storyid(), $news['infotips'], $title);
300
                    $spotlight['news'][]     = $news;
301
                }
302
            }
303
304
            $block['spotlight'] = $spotlight;
305
        } elseif ($tabscount > 0) {
306
            $topics   = array_slice($options, 14);
0 ignored issues
show
The assignment to $topics is dead and can be removed.
Loading history...
307
            $thetopic = $currenttab;
308
            $stories  = NewsStory::getAllPublished($options[1], 0, $restricted, $thetopic, 1, true, $options[0]);
309
310
            $topic->getTopic($thetopic);
311
            // Added, topic's image and description
312
            $block['topic_image']       = XOOPS_URL . '/modules/news/assets/images/topics/' . $topic->topic_imgurl();
313
            $block['topic_description'] = $topic->topic_description();
314
315
            $smallheader   = [];
316
            $stats         = $topic->getTopicMiniStats($thetopic);
317
            $smallheader[] = sprintf("<a href='%s'>%s</a>", XOOPS_URL . '/modules/news/index.php?storytopic=' . $thetopic, _MB_READMORE);
318
            $smallheader[] = sprintf('%u %s', $stats['count'], _NW_ARTICLES);
319
            $smallheader[] = sprintf('%u %s', $stats['reads'], _READS);
320
            if (count($stories) > 0) {
321
                foreach ($stories as $key => $story) {
322
                    $news  = [];
323
                    $title = $story->title();
324
                    if (mb_strlen($title) > $options[2]) {
325
                        $title = Utility::truncateTagSafe($title, $options[2] + 3);
326
                    }
327
                    if ('' !== $options[7]) {
328
                        $news['image'] = sprintf("<a href='%s'>%s</a>", XOOPS_URL . '/modules/news/article.php?storyid=' . $story->storyid(), $myts->displayTarea($options[7], $story->nohtml));
329
                    }
330
                    if ($options[3] > 0) {
331
                        $html         = 1 == $story->nohtml() ? 0 : 1;
332
                        $news['text'] = Utility::truncateTagSafe($myts->displayTarea($story->hometext(), $html), $options[3] + 3);
333
                    } else {
334
                        $news['text'] = '';
335
                    }
336
337
                    if (1 == $story->votes()) {
338
                        $news['number_votes'] = _NW_ONEVOTE;
339
                    } else {
340
                        $news['number_votes'] = sprintf(_NW_NUMVOTES, $story->votes());
341
                    }
342
                    if ($infotips > 0) {
343
                        $news['infotips'] = ' title="' . Utility::makeInfotips($story->hometext()) . '"';
344
                    } else {
345
                        $news['infotips'] = '';
346
                    }
347
                    $news['title']       = sprintf("<a href='%s' %s>%s</a>", XOOPS_URL . '/modules/news/article.php?storyid=' . $story->storyid(), $news['infotips'], $title);
348
                    $news['id']          = $story->storyid();
349
                    $news['date']        = formatTimestamp($story->published(), $dateformat);
350
                    $news['hits']        = $story->counter();
351
                    $news['rating']      = number_format($story->rating(), 2);
352
                    $news['votes']       = $story->votes();
353
                    $news['topicid']     = $story->topicid();
354
                    $news['topic_title'] = $story->topic_title();
355
                    $news['topic_color'] = '#' . $myts->displayTarea($story->topic_color);
356
                    $news['picture']     = XOOPS_URL . '/uploads/news/image/' . $story->picture();
357
                    $news['pictureinfo'] = $story->pictureinfo();
358
359
                    if (3 != $displayname) {
360
                        $news['author'] = sprintf('%s %s', _POSTEDBY, $story->uname());
361
                    } else {
362
                        $news['author'] = '';
363
                    }
364
                    $news['title_with_link'] = sprintf("<a href='%s'%s>%s</a>", XOOPS_URL . '/modules/news/article.php?storyid=' . $story->storyid(), $news['infotips'], $title);
365
                    $block['news'][]         = $news;
366
                }
367
                $block['smallheader'] = $smallheader;
368
            }
369
        }
370
        $block['lang_on']    = _ON; // on
371
        $block['lang_reads'] = _READS; // reads
372
        // Default values
373
        $block['color1'] = $defcolors[$tabskin][0];
374
        $block['color2'] = $defcolors[$tabskin][1];
375
        $block['color3'] = $defcolors[$tabskin][2];
376
        $block['color4'] = $defcolors[$tabskin][3];
377
        $block['color5'] = $defcolors[$tabskin][4];
378
379
        if ('' !== xoops_trim($options[9])) {
380
            $block['color1'] = $options[9];
381
        }
382
        if ('' !== xoops_trim($options[10])) {
383
            $block['color2'] = $options[10];
384
        }
385
        if ('' !== xoops_trim($options[11])) {
386
            $block['color3'] = $options[11];
387
        }
388
        if ('' !== xoops_trim($options[12])) {
389
            $block['color4'] = $options[12];
390
        }
391
        if ('' !== xoops_trim($options[13])) {
392
            $block['color5'] = $options[13];
393
        }
394
    } else { // ************************ Classical view **************************************************************************************************************
395
        $tmpstory = new NewsStory();
0 ignored issues
show
The assignment to $tmpstory is dead and can be removed.
Loading history...
396
        if (isset($options[14]) && 0 == (int)$options[14]) {
397
            $stories = NewsStory::getAllPublished($options[1], 0, $restricted, 0, 1, true, $options[0]);
398
        } else {
399
            $topics  = array_slice($options, 14);
400
            $stories = NewsStory::getAllPublished($options[1], 0, $restricted, $topics, 1, true, $options[0]);
401
        }
402
403
        if (!$stories) {
404
            return '';
405
        }
406
        $topic = new NewsTopic();
0 ignored issues
show
The assignment to $topic is dead and can be removed.
Loading history...
407
408
        foreach ($stories as $key => $story) {
409
            $news  = [];
410
            $title = $story->title();
411
            if (mb_strlen($title) > $options[2]) {
412
                $title = xoops_substr($title, 0, $options[2] + 3);
413
            }
414
415
            //if spotlight is enabled and this is either the first article or the selected one
416
            if ((0 == $options[5]) && (1 == $options[4])
417
                && (($options[6] > 0 && $options[6] == $story->storyid())
418
                    || (0 == $options[6] && 0 == $key))) {
419
                $spotlight = [];
420
                $visible   = true;
421
                if ($restricted) {
422
                    $permittedtopics = Utility::getMyItemIds();
423
                    if (!in_array($story->topicid(), $permittedtopics, true)) {
424
                        $visible = false;
425
                    }
426
                }
427
428
                if ($visible) {
429
                    $spotlight['title'] = $title;
430
                    if ('' !== $options[7]) {
431
                        $spotlight['image'] = sprintf("<a href='%s'>%s</a>", XOOPS_URL . '/modules/news/article.php?storyid=' . $story->storyid(), $myts->displayTarea($options[7], $story->nohtml));
432
                    }
433
                    // Added 16 february 2007 *****************************************
434
                    $story_user = null;
435
                    $story_user = new \XoopsUser($story->uid());
436
                    if (is_object($story_user)) {
437
                        $spotlight['avatar'] = XOOPS_UPLOAD_URL . '/' . $story_user->getVar('user_avatar');
438
                    }
439
                    // ****************************************************************
440
                    $spotlight['text']        = $story->hometext();
441
                    $spotlight['id']          = $story->storyid();
442
                    $spotlight['date']        = formatTimestamp($story->published(), $dateformat);
443
                    $spotlight['hits']        = $story->counter();
444
                    $spotlight['rating']      = $story->rating();
445
                    $spotlight['votes']       = $story->votes();
446
                    $spotlight['topicid']     = $story->topicid();
447
                    $spotlight['topic_title'] = $story->topic_title();
448
                    $spotlight['topic_color'] = '#' . $myts->displayTarea($story->topic_color);
449
                    // Added, topic's image and description
450
                    $spotlight['topic_image']       = XOOPS_URL . '/modules/news/assets/images/topics/' . $story->topic_imgurl();
451
                    $spotlight['topic_description'] = $myts->displayTarea($story->topic_description, 1);
452
                    if ('' !== xoops_trim($story->bodytext())) {
453
                        $spotlight['read_more'] = true;
454
                    } else {
455
                        $spotlight['read_more'] = false;
456
                    }
457
458
                    if (3 != $displayname) {
459
                        $spotlight['author'] = sprintf('%s %s', _POSTEDBY, $story->uname());
460
                    } else {
461
                        $spotlight['author'] = '';
462
                    }
463
                }
464
                $block['spotlight'] = $spotlight;
465
            } else {
466
                $news['title']       = $title;
467
                $news['id']          = $story->storyid();
468
                $news['date']        = formatTimestamp($story->published(), $dateformat);
469
                $news['hits']        = $story->counter();
470
                $news['rating']      = $story->rating();
471
                $news['votes']       = $story->votes();
472
                $news['topicid']     = $story->topicid();
473
                $news['topic_title'] = $story->topic_title();
474
                $news['topic_color'] = '#' . $myts->displayTarea($story->topic_color);
475
                $news['picture']     = XOOPS_URL . '/uploads/news/image/' . $story->picture();
476
                $news['pictureinfo'] = $story->pictureinfo();
477
478
                if (3 != $displayname) {
479
                    $news['author'] = sprintf('%s %s', _POSTEDBY, $story->uname());
480
                } else {
481
                    $news['author'] = '';
482
                }
483
                if ($options[3] > 0) {
484
                    $html             = 1 == $story->nohtml() ? 0 : 1;
485
                    $news['teaser']   = Utility::truncateTagSafe($myts->displayTarea($story->hometext(), $html), $options[3] + 3);
486
                    $news['infotips'] = '';
487
                } else {
488
                    $news['teaser'] = '';
489
                    if ($infotips > 0) {
490
                        $news['infotips'] = ' title="' . Utility::makeInfotips($story->hometext()) . '"';
491
                    } else {
492
                        $news['infotips'] = '';
493
                    }
494
                }
495
                $block['stories'][] = $news;
496
            }
497
        }
498
499
        // If spotlight article was not in the fetched stories
500
        if (!isset($spotlight) && $options[4]) {
501
            $block['use_spotlight'] = true;
502
            $visible                = true;
503
            if (0 == $options[5] && $restricted) { // Use a specific news and we are in restricted mode
504
                $permittedtopics = Utility::getMyItemIds();
505
                $permstory       = new NewsStory($options[6]);
506
                if (!in_array($permstory->topicid(), $permittedtopics, true)) {
507
                    $visible = false;
508
                }
509
                unset($permstory);
510
            }
511
512
            if (0 == $options[5]) { // Use a specific news
513
                if ($visible) {
514
                    $spotlightArticle = new NewsStory($options[6]);
515
                } else {
516
                    $block['use_spotlight'] = false;
517
                }
518
            } else { // Use the most recent news
519
                $stories = [];
520
                $stories = NewsStory::getAllPublished(1, 0, $restricted, 0, 1, true, $options[0]);
521
                if (count($stories) > 0) {
522
                    $firststory       = $stories[0];
523
                    $spotlightArticle = new NewsStory($firststory->storyid());
524
                } else {
525
                    $block['use_spotlight'] = false;
526
                }
527
            }
528
            if ($block['use_spotlight']) {
529
                $spotlight          = [];
530
                $spotlight['title'] = xoops_substr($spotlightArticle->title(), 0, $options[2] - 1);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $spotlightArticle does not seem to be defined for all execution paths leading up to this point.
Loading history...
531
                if ('' !== $options[7]) {
532
                    $spotlight['image'] = sprintf("<a href='%s'>%s</a>", XOOPS_URL . '/modules/news/article.php?storyid=' . $spotlightArticle->storyid(), $myts->displayTarea($options[7], $spotlightArticle->nohtml));
533
                }
534
                // Added 16 february 2007 *****************************************
535
                $story_user = null;
536
                $story_user = new \XoopsUser($spotlightArticle->uid());
537
                if (is_object($story_user)) {
538
                    $spotlight['avatar'] = XOOPS_UPLOAD_URL . '/' . $story_user->getVar('user_avatar');
539
                }
540
                // ****************************************************************
541
                $spotlight['topicid']     = $spotlightArticle->topicid();
542
                $spotlight['topic_title'] = $spotlightArticle->topic_title();
543
                $spotlight['topic_color'] = '#' . $myts->displayTarea($spotlightArticle->topic_color);
544
                $spotlight['text']        = $spotlightArticle->hometext();
545
                $spotlight['id']          = $spotlightArticle->storyid();
546
                $spotlight['date']        = formatTimestamp($spotlightArticle->published(), $dateformat);
547
                $spotlight['hits']        = $spotlightArticle->counter();
548
                $spotlight['rating']      = $spotlightArticle->rating();
549
                $spotlight['votes']       = $spotlightArticle->votes();
550
                // Added, topic's image and description
551
                $spotlight['topic_image']       = XOOPS_URL . '/modules/news/assets/images/topics/' . $spotlightArticle->topic_imgurl();
552
                $spotlight['topic_description'] = $myts->displayTarea($spotlightArticle->topic_description, 1);
553
                if (3 != $displayname) {
554
                    $spotlight['author'] = sprintf('%s %s', _POSTEDBY, $spotlightArticle->uname());
555
                } else {
556
                    $spotlight['author'] = '';
557
                }
558
                if ('' !== xoops_trim($spotlightArticle->bodytext())) {
559
                    $spotlight['read_more'] = true;
560
                } else {
561
                    $spotlight['read_more'] = false;
562
                }
563
                $block['spotlight'] = $spotlight;
564
            }
565
        }
566
    }
567
    if (isset($permstory)) {
568
        unset($permstory);
569
    }
570
    $block['lang_read_more']      = htmlspecialchars(_MB_READMORE, ENT_QUOTES | ENT_HTML5); // Read More...
571
    $block['lang_orderby']        = htmlspecialchars(_MB_NEWS_ORDER, ENT_QUOTES | ENT_HTML5); // "Order By"
572
    $block['lang_orderby_date']   = htmlspecialchars(_MB_NEWS_DATE, ENT_QUOTES | ENT_HTML5); // Published date
573
    $block['lang_orderby_hits']   = htmlspecialchars(_MB_NEWS_HITS, ENT_QUOTES | ENT_HTML5); // Number of Hits
574
    $block['lang_orderby_rating'] = htmlspecialchars(_MB_NEWS_RATE, ENT_QUOTES | ENT_HTML5); // Rating
575
    $block['sort']                = $options[0]; // "published" or "counter" or "rating"
576
577
    return $block;
578
}
579
580
/**
581
 * Function used to edit the block
582
 * @param $options
583
 * @return string
584
 */
585
function b_news_top_edit($options)
586
{
587
    global $xoopsDB;
588
    $tmpstory = new NewsStory();
0 ignored issues
show
The assignment to $tmpstory is dead and can be removed.
Loading history...
589
    $form     = _MB_NEWS_ORDER . "&nbsp;<select name='options[]'>";
590
    $form     .= "<option value='published'";
591
    if ('published' === $options[0]) {
592
        $form .= ' selected';
593
    }
594
    $form .= '>' . _MB_NEWS_DATE . "</option>\n";
595
596
    $form .= "<option value='counter'";
597
    if ('counter' === $options[0]) {
598
        $form .= ' selected';
599
    }
600
    $form .= '>' . _MB_NEWS_HITS . '</option>';
601
    $form .= "<option value='rating'";
602
    if ('rating' === $options[0]) {
603
        $form .= ' selected';
604
    }
605
    $form .= '>' . _MB_NEWS_RATE . '</option>';
606
    $form .= "</select>\n";
607
608
    $form .= '&nbsp;' . _MB_NEWS_DISP . "&nbsp;<input type='text' name='options[]' value='" . $options[1] . "'>&nbsp;" . _MB_NEWS_ARTCLS;
609
    $form .= '&nbsp;<br><br>' . _MB_NEWS_CHARS . "&nbsp;<input type='text' name='options[]' value='" . $options[2] . "'>&nbsp;" . _MB_NEWS_LENGTH . '<br><br>';
610
611
    $form .= _MB_NEWS_TEASER . " <input type='text' name='options[]' value='" . $options[3] . "'>" . _MB_NEWS_LENGTH;
612
    $form .= '<br><br>';
613
614
    $form .= _MB_NEWS_SPOTLIGHT . " <input type='radio' name='options[]' value='1'";
615
    if (1 == $options[4]) {
616
        $form .= ' checked';
617
    }
618
    $form .= '>' . _YES;
619
    $form .= "<input type='radio' name='options[]' value='0'";
620
    if (0 == $options[4]) {
621
        $form .= ' checked';
622
    }
623
    $form .= '>' . _NO . '<br><br>';
624
625
    $form .= _MB_NEWS_WHAT_PUBLISH . " <select name='options[]'><option value='1'";
626
    if (1 == $options[5]) {
627
        $form .= ' selected';
628
    }
629
    $form .= '>' . _MB_NEWS_RECENT_NEWS;
630
    $form .= "</option><option value='0'";
631
    if (0 == $options[5]) {
632
        $form .= ' selected';
633
    }
634
    $form .= '>' . _MB_NEWS_RECENT_SPECIFIC . '</option></select>';
635
636
    $form     .= '<br><br>' . _MB_NEWS_SPOTLIGHT_ARTICLE . '<br>';
637
    $articles = NewsStory::getAllPublished(200, 0, false, 0, 0, false); // I have limited the listbox to the last 200 articles
638
    $form     .= "<select name ='options[]'>";
639
    $form     .= "<option value='0'>" . _MB_NEWS_FIRST . '</option>';
640
    foreach ($articles as $storyid => $storytitle) {
641
        $sel = '';
642
        if ($options[6] == $storyid) {
643
            $sel = ' selected';
644
        }
645
        $form .= "<option value='$storyid'$sel>" . $storytitle . '</option>';
646
    }
647
    $form .= '</select><br><br>';
648
649
    $form .= _MB_NEWS_IMAGE . "&nbsp;<input type='text' id='spotlightimage' name='options[]' value='" . $options[7] . "' size='50'>";
650
    $form .= "&nbsp;<img align='middle' onmouseover='style.cursor=\"hand\"' onclick='javascript:openWithSelfMain(\"" . XOOPS_URL . "/imagemanager.php?target=spotlightimage\",\"imgmanager\",400,430);' src='" . XOOPS_URL . "/images/image.gif' alt='image' title='image'>";
651
    $form .= '<br><br>' . _MB_NEWS_DISP . "&nbsp;<select name='options[]'><option value='1' ";
652
    if (1 == $options[8]) {
653
        $form .= 'selected';
654
    }
655
    $form .= '>' . _MB_NEWS_VIEW_TYPE1 . "</option><option value='2' ";
656
    if (2 == $options[8]) {
657
        $form .= 'selected';
658
    }
659
    $form .= '>' . _MB_NEWS_VIEW_TYPE2 . '</option></select><br><br>';
660
661
    $form .= "<table border=0>\n";
662
    $form .= "<tr><td colspan='2' align='center'><u>" . _MB_NEWS_DEFAULT_COLORS . '</u></td></tr>';
663
    $form .= '<tr><td>' . _MB_NEWS_TAB_COLOR1 . "</td><td><input type='text' name='options[]' value='" . $options[9] . "' size=7></td></tr>";
664
    $form .= '<tr><td>' . _MB_NEWS_TAB_COLOR2 . "</td><td><input type='text' name='options[]' value='" . $options[10] . "' size=7></td></tr>";
665
    $form .= '<tr><td>' . _MB_NEWS_TAB_COLOR3 . "</td><td><input type='text' name='options[]' value='" . $options[11] . "' size=7></td></tr>";
666
    $form .= '<tr><td>' . _MB_NEWS_TAB_COLOR4 . "</td><td><input type='text' name='options[]' value='" . $options[12] . "' size=7></td></tr>";
667
    $form .= '<tr><td>' . _MB_NEWS_TAB_COLOR5 . "</td><td><input type='text' name='options[]' value='" . $options[13] . "' size=7></td></tr>";
668
    $form .= "</table>\n";
669
670
    $form .= '<br><br>' . _MB_SPOTLIGHT_TOPIC . "<br><select name='options[]' multiple='multiple'>";
671
    //    require_once XOOPS_ROOT_PATH . '/modules/news/class/class.newstopic.php';
672
    $topics_arr = [];
0 ignored issues
show
The assignment to $topics_arr is dead and can be removed.
Loading history...
673
    //    require_once XOOPS_ROOT_PATH . '/modules/news/class/xoopstree.php';
674
    $xt         = new XoopsTree($xoopsDB->prefix('news_topics'), 'topic_id', 'topic_pid');
675
    $topics_arr = $xt->getChildTreeArray(0, 'topic_title');
676
    $size       = count($options);
677
    foreach ($topics_arr as $onetopic) {
678
        $sel = '';
679
        if (0 != $onetopic['topic_pid']) {
680
            $onetopic['prefix'] = str_replace('.', '-', $onetopic['prefix']) . '&nbsp;';
681
        } else {
682
            $onetopic['prefix'] = str_replace('.', '', $onetopic['prefix']);
683
        }
684
        for ($i = 14; $i < $size; ++$i) {
685
            if ($options[$i] == $onetopic['topic_id']) {
686
                $sel = ' selected';
687
            }
688
        }
689
        $form .= "<option value='" . $onetopic['topic_id'] . "'$sel>" . $onetopic['prefix'] . $onetopic['topic_title'] . '</option>';
690
    }
691
    $form .= '</select><br>';
692
693
    return $form;
694
}
695
696
/**
697
 * @param $options
698
 */
699
function b_news_top_onthefly($options): void
700
{
701
    $options = explode('|', $options);
702
    $block   = b_news_top_show($options);
703
704
    $tpl = new \XoopsTpl();
705
    $tpl->assign('block', $block);
706
    $tpl->display('db:news_block_top.tpl');
707
}
708