Passed
Push — master ( 6d0bec...700d12 )
by Michael
05:09 queued 02:42
created

b_news_top_show()   F

Complexity

Conditions 102
Paths > 20000

Size

Total Lines 537
Code Lines 399

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 399
c 1
b 0
f 0
dl 0
loc 537
rs 0
cc 102
nc 1136950825
nop 1

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
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
 * @package
16
 * @since
17
 * @author         XOOPS Development Team
18
 */
19
20
use Xmf\Request;
21
use XoopsModules\News;
22
use XoopsModules\News\Helper;
23
use XoopsModules\News\NewsStory;
24
use XoopsModules\News\NewsTopic;
25
26
//require_once XOOPS_ROOT_PATH . '/modules/news/class/class.newsstory.php';
27
//require_once XOOPS_ROOT_PATH . '/modules/news/class/class.newstopic.php';
28
29
/**
30
 * Notes about the spotlight :
31
 * If you have restricted topics on index page (in fact if the program must completly respect the permissions) and if
32
 * the news you have selected to be viewed in the spotlight can't be viewed by someone then the spotlight is not visible !
33
 * This is available in the classical and in the tabbed view.
34
 * But if you have uncheck the option "Restrict topics on index page", then the news will be visible but users without
35
 * permissions will be rejected when they will try to read news content.
36
 *
37
 * Also, if you have selected a tabbed view and wanted to use the Spotlight but did not choosed a story, then the block
38
 * will switch to the "most recent news" mode (the visible news will be searched according to the permissions)
39
 * @param $options
40
 * @return array|string
41
 */
42
function b_news_top_show($options)
43
{
44
    global $xoopsConfig;
45
46
    /** @var Helper $helper */
47
    if (!class_exists(Helper::class)) {
48
        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...
49
    }
50
51
    $helper = Helper::getInstance();
52
53
    $helper->loadLanguage('main');
54
55
    $myts        = \MyTextSanitizer::getInstance();
56
    $block       = [];
57
    $displayname = News\Utility::getModuleOption('displayname');
58
    $tabskin     = News\Utility::getModuleOption('tabskin');
59
60
    $block['displayview'] = $options[8];
61
    $block['tabskin']     = $tabskin;
62
    $block['imagesurl']   = XOOPS_URL . '/modules/news/assets/images/';
63
64
    $restricted = News\Utility::getModuleOption('restrictindex');
65
    $dateformat = News\Utility::getModuleOption('dateformat');
66
    $infotips   = News\Utility::getModuleOption('infotips');
67
    $newsrating = News\Utility::getModuleOption('ratenews');
68
    if ('' == $dateformat) {
69
        $dateformat = 's';
70
    }
71
72
    $perm_verified = false;
73
    $news_visible  = true;
74
    // Is the spotlight visible ?
75
    if (1 == $options[4] && $restricted && 0 == $options[5]) {
76
        $perm_verified   = true;
77
        $permittedtopics = News\Utility::getMyItemIds();
78
        $permstory       = new NewsStory($options[6]);
79
        if (!in_array($permstory->topicid(), $permittedtopics)) {
80
            $usespotlight = false;
0 ignored issues
show
Unused Code introduced by
The assignment to $usespotlight is dead and can be removed.
Loading history...
81
            $news_visible = false;
82
            $topicstitles = [];
0 ignored issues
show
Unused Code introduced by
The assignment to $topicstitles is dead and can be removed.
Loading history...
83
        }
84
        0 == $options[4];
85
    }
86
    // Try to see what tabs are visibles (if we are in restricted view of course)
87
    if (2 == $options[8] && $restricted && 0 != $options[14]) {
88
        $topics2         = [];
89
        $permittedtopics = News\Utility::getMyItemIds();
90
        $topics          = array_slice($options, 14);
91
        foreach ($topics as $onetopic) {
92
            if (in_array($onetopic, $permittedtopics)) {
93
                $topics2[] = $onetopic;
94
            }
95
        }
96
        $before  = array_slice($options, 0, 14);
97
        $options = array_merge($before, $topics2);
98
    }
99
100
    if (2 == $options[8]) { // Tabbed view ********************************************************************************************
101
        $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...
102
        $defcolors[2] = ['#F90', '#FFFFFF', '#F90', '#AAA', '#666']; // Beveled
103
        $defcolors[3] = ['#F90', '#FFFFFF', '', '#789', '#789']; // Classic
104
        $defcolors[4] = ['#F90', '#FFFFFF', '', '', '']; // Folders
105
        $defcolors[5] = ['#F90', '#FFFFFF', '#CCC', 'inherit', '#999']; // MacOs
106
        $defcolors[6] = ['#F90', '#FFFFFF', '#FFF', '#DDD', '#999']; // Plain
107
        $defcolors[7] = ['#F90', '#FFFFFF', '', '', '']; // Rounded
108
        $defcolors[8] = ['#F90', '#FFFFFF', '#F90', '#930', '#C60']; // ZDnet
109
110
        $myurl = $_SERVER['SCRIPT_NAME'];
111
        if ('/' === mb_substr($myurl, mb_strlen($myurl) - 1, 1)) {
112
            $myurl .= 'index.php';
113
        }
114
        $myurl .= '?';
115
116
        foreach ($_GET as $key => $value) {
117
            if ('NewsTab' !== $key) {
118
                $myurl .= $key . '=' . $value . '&';
119
            }
120
        }
121
        $block['url'] = $myurl;
122
123
        $tabscount    = 0;
124
        $usespotlight = false;
125
126
        if (Request::hasVar('NewsTab', 'GET')) {
127
            $_SESSION['NewsTab'] = Request::getInt('NewsTab', 0, 'GET');
128
            $currenttab          = Request::getInt('NewsTab', 0, 'GET');
129
        } elseif (Request::hasVar('NewsTab', 'SESSION')) {
130
            $currenttab = Request::getInt('NewsTab', 0, 'SESSION');
131
        } else {
132
            $currenttab = 0;
133
        }
134
135
        $tmpstory     = new NewsStory();
136
        $topic        = new  NewsTopic();
137
        $topicstitles = [];
138
        if (1 == $options[4]) { // Spotlight enabled
139
            $topicstitles[0] = _MB_NEWS_SPOTLIGHT_TITLE;
140
            ++$tabscount;
141
            $usespotlight = true;
142
        }
143
144
        if (0 == $options[5] && $restricted) { // Use a specific news and we are in restricted mode
145
            if (!$perm_verified) {
146
                $permittedtopics = News\Utility::getMyItemIds();
147
                $permstory       = new NewsStory($options[6]);
148
                if (!in_array($permstory->topicid(), $permittedtopics)) {
149
                    $usespotlight = false;
150
                    $topicstitles = [];
151
                }
152
                //unset($permstory);
153
            } elseif (!$news_visible) {
154
                $usespotlight = false;
155
                $topicstitles = [];
156
            }
157
        }
158
159
        $block['use_spotlight'] = $usespotlight;
160
161
        if (isset($options[14]) && 0 != $options[14]) { // Topic to use
162
            $topics       = array_slice($options, 14);
163
            $tabscount    += count($topics);
164
            $topicstitles = $topic->getTopicTitleFromId($topics, $topicstitles);
165
        }
166
        $tabs = [];
167
        if ($usespotlight) {
168
            $tabs[] = ['id' => 0, 'title' => _MB_NEWS_SPOTLIGHT_TITLE];
169
        }
170
        if (count($topics) > 0) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $topics does not seem to be defined for all execution paths leading up to this point.
Loading history...
171
            foreach ($topics as $onetopic) {
172
                if (isset($topicstitles[$onetopic])) {
173
                    $tabs[] = [
174
                        'id'      => $onetopic,
175
                        'title'   => $topicstitles[$onetopic]['title'],
176
                        'picture' => $topicstitles[$onetopic]['picture'],
177
                    ];
178
                }
179
            }
180
        }
181
        $block['tabs']                 = $tabs;
182
        $block['current_is_spotlight'] = false;
183
        $block['current_tab']          = $currenttab;
184
        $block['use_rating']           = $newsrating;
185
186
        if (0 == $currenttab && $usespotlight) { // Spotlight or not ?
187
            $block['current_is_spotlight'] = true;
188
            if (0 == $options[5]
189
                && 0 == $options[6]) { // If the story to use was no selected then we switch to the "recent news" mode.
190
                $options[5] = 1;
191
            }
192
193
            if (0 == $options[5]) { // Use a specific news
194
                if (!isset($permstory)) {
195
                    $tmpstory = new NewsStory($options[6]);
196
                } else {
197
                    $tmpstory = $permstory;
198
                }
199
            } else { // Use the most recent news
200
                $stories = [];
0 ignored issues
show
Unused Code introduced by
The assignment to $stories is dead and can be removed.
Loading history...
201
                $stories = NewsStory::getAllPublished(1, 0, $restricted, 0, 1, true, $options[0]);
202
                if (count($stories) > 0) {
203
                    $firststory = $stories[0];
204
                    $tmpstory   = new NewsStory($firststory->storyid());
205
                } else {
206
                    $block['use_spotlight'] = false;
207
                }
208
            }
209
            $spotlight          = [];
210
            $spotlight['title'] = $tmpstory->title();
211
            if ('' !== $options[7]) {
212
                $spotlight['image'] = sprintf("<a href='%s'>%s</a>", XOOPS_URL . '/modules/news/article.php?storyid=' . $tmpstory->storyid(), $myts->displayTarea($options[7], $tmpstory->nohtml));
213
            }
214
            $spotlight['text'] = $tmpstory->hometext();
215
216
            // Added 16 february 2007 *****************************************
217
            $story_user = null;
0 ignored issues
show
Unused Code introduced by
The assignment to $story_user is dead and can be removed.
Loading history...
218
            $story_user = new \XoopsUser($tmpstory->uid());
219
            if (is_object($story_user)) {
220
                $spotlight['avatar'] = XOOPS_UPLOAD_URL . '/' . $story_user->getVar('user_avatar');
221
            }
222
            // ****************************************************************
223
            $spotlight['id']     = $tmpstory->storyid();
224
            $spotlight['date']   = formatTimestamp($tmpstory->published(), $dateformat);
225
            $spotlight['hits']   = $tmpstory->counter();
226
            $spotlight['rating'] = number_format($tmpstory->rating(), 2);
227
            $spotlight['votes']  = $tmpstory->votes();
228
            if ('' !== xoops_trim($tmpstory->bodytext())) {
229
                $spotlight['read_more'] = true;
230
            } else {
231
                $spotlight['read_more'] = false;
232
            }
233
234
            $spotlight['readmore']        = sprintf("<a href='%s'>%s</a>", XOOPS_URL . '/modules/news/article.php?storyid=' . $tmpstory->storyid(), _MB_READMORE);
235
            $spotlight['title_with_link'] = sprintf("<a href='%s'>%s</a>", XOOPS_URL . '/modules/news/article.php?storyid=' . $tmpstory->storyid(), $tmpstory->title());
236
            if (1 == $tmpstory->votes()) {
237
                $spotlight['number_votes'] = _NW_ONEVOTE;
238
            } else {
239
                $spotlight['number_votes'] = sprintf(_NW_NUMVOTES, $tmpstory->votes());
240
            }
241
242
            $spotlight['votes_with_text'] = sprintf(_NW_NUMVOTES, $tmpstory->votes());
243
            $spotlight['topicid']         = $tmpstory->topicid();
244
            $spotlight['topic_title']     = $tmpstory->topic_title();
245
            // Added, topic's image and description
246
            $spotlight['topic_image']       = XOOPS_URL . '/modules/news/assets/images/topics/' . $tmpstory->topic_imgurl();
247
            $spotlight['topic_description'] = $myts->displayTarea($tmpstory->topic_description, 1);
0 ignored issues
show
Bug introduced by
The property topic_description does not exist on XoopsModules\News\NewsStory. Did you mean description?
Loading history...
248
249
            if (3 != $displayname) {
250
                $spotlight['author']           = sprintf('%s %s', _POSTEDBY, $tmpstory->uname());
251
                $spotlight['author_with_link'] = sprintf("%s <a href='%s'>%s</a>", _POSTEDBY, XOOPS_URL . '/userinfo.php?uid=' . $tmpstory->uid(), $tmpstory->uname());
252
            } else {
253
                $spotlight['author']           = '';
254
                $spotlight['author_with_link'] = '';
255
            }
256
            $spotlight['author_id'] = $tmpstory->uid();
257
258
            // Create the summary table under the spotlight text
259
            if (isset($options[14]) && 0 == $options[14]) { // Use all topics
260
                $stories = NewsStory::getAllPublished($options[1], 0, $restricted, 0, 1, true, $options[0]);
261
            } else { // Use some topics
262
                $topics  = array_slice($options, 14);
263
                $stories = NewsStory::getAllPublished($options[1], 0, $restricted, $topics, 1, true, $options[0]);
0 ignored issues
show
Bug introduced by
$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

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