Completed
Push — master ( 70d8b1...741c06 )
by Michael
02:57
created

blocks/news_top.php (1 issue)

Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
//
3
//  ------------------------------------------------------------------------ //
4
//                XOOPS - PHP Content Management System                      //
5
//                  Copyright (c) 2000-2016 XOOPS.org                        //
6
//                       <http://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
// defined('XOOPS_ROOT_PATH') || exit('XOOPS root path not defined');
28
29
include_once XOOPS_ROOT_PATH . '/modules/news/class/class.newsstory.php';
30
include_once XOOPS_ROOT_PATH . '/modules/news/class/class.newstopic.php';
31
32
/**
33
 * Notes about the spotlight :
34
 * If you have restricted topics on index page (in fact if the program must completly respect the permissions) and if
35
 * the news you have selected to be viewed in the spotlight can't be viewed by someone then the spotlight is not visible !
36
 * This is available in the classical and in the tabbed view.
37
 * But if you have uncheck the option "Restrict topics on index page", then the news will be visible but users without
38
 * permissions will be rejected when they will try to read news content.
39
 *
40
 * Also, if you have selected a tabbed view and wanted to use the Spotlight but did not choosed a story, then the block
41
 * will switch to the "most recent news" mode (the visible news will be searched according to the permissions)
42
 * @param $options
43
 * @return array
44
 */
45
function b_news_top_show($options)
46
{
47
    global $xoopsConfig;
48
    include_once XOOPS_ROOT_PATH . '/modules/news/include/functions.php';
49
    $myts        = MyTextSanitizer::getInstance();
50
    $block       = array();
51
    $displayname = news_getmoduleoption('displayname');
52
    $tabskin     = news_getmoduleoption('tabskin');
53
54 View Code Duplication
    if (file_exists(XOOPS_ROOT_PATH . '/modules/news/language/' . $xoopsConfig['language'] . '/main.php')) {
55
        include_once XOOPS_ROOT_PATH . '/modules/news/language/' . $xoopsConfig['language'] . '/main.php';
56
    } else {
57
        include_once XOOPS_ROOT_PATH . '/modules/news/language/english/main.php';
58
    }
59
60
    $block['displayview'] = $options[8];
61
    $block['tabskin']     = $tabskin;
62
    $block['imagesurl']   = XOOPS_URL . '/modules/news/assets/images/';
63
64
    $restricted = news_getmoduleoption('restrictindex');
65
    $dateformat = news_getmoduleoption('dateformat');
66
    $infotips   = news_getmoduleoption('infotips');
67
    $newsrating = news_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 ($options[4] == 1 && $restricted && $options[5] == 0) {
76
        $perm_verified   = true;
77
        $permittedtopics = news_MygetItemIds();
78
        $permstory       = new NewsStory($options[6]);
79
        if (!in_array($permstory->topicid(), $permittedtopics)) {
80
            $usespotlight = false;
81
            $news_visible = false;
82
            $topicstitles = array();
83
        }
84
        $options[4] == 0;
85
    }
86
    // Try to see what tabs are visibles (if we are in restricted view of course)
87
    if ($options[8] == 2 && $restricted && $options[14] != 0) {
88
        $topics2         = array();
89
        $permittedtopics = news_MygetItemIds();
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 ($options[8] == 2) { // Tabbed view ********************************************************************************************
101
        $defcolors[1] = array('#F90', '#FFFFFF', '#F90', '#C60', '#999'); // Bar Style
102
        $defcolors[2] = array('#F90', '#FFFFFF', '#F90', '#AAA', '#666'); // Beveled
103
        $defcolors[3] = array('#F90', '#FFFFFF', '', '#789', '#789'); // Classic
104
        $defcolors[4] = array('#F90', '#FFFFFF', '', '', ''); // Folders
105
        $defcolors[5] = array('#F90', '#FFFFFF', '#CCC', 'inherit', '#999'); // MacOs
106
        $defcolors[6] = array('#F90', '#FFFFFF', '#FFF', '#DDD', '#999'); // Plain
107
        $defcolors[7] = array('#F90', '#FFFFFF', '', '', ''); // Rounded
108
        $defcolors[8] = array('#F90', '#FFFFFF', '#F90', '#930', '#C60'); // ZDnet
109
110
        $myurl = $_SERVER['PHP_SELF'];
111
        if (substr($myurl, strlen($myurl) - 1, 1) === '/') {
112
            $myurl .= 'index.php';
113
        }
114
        $myurl .= '?';
115
116
        foreach ($_GET as $key => $value) {
117
            if ($key !== 'NewsTab') {
118
                $myurl .= $key . '=' . $value . '&';
119
            }
120
        }
121
        $block['url'] = $myurl;
122
123
        $tabscount    = 0;
124
        $usespotlight = false;
125
126
        if (isset($_GET['NewsTab'])) {
127
            $_SESSION['NewsTab'] = (int)$_GET['NewsTab'];
128
            $currenttab          = (int)$_GET['NewsTab'];
129
        } elseif (isset($_SESSION['NewsTab'])) {
130
            $currenttab = (int)$_SESSION['NewsTab'];
131
        } else {
132
            $currenttab = 0;
133
        }
134
135
        $tmpstory     = new NewsStory();
136
        $topic        = new NewsTopic();
137
        $topicstitles = array();
138
        if ($options[4] == 1) { // Spotlight enabled
139
            $topicstitles[0] = _MB_NEWS_SPOTLIGHT_TITLE;
140
            ++$tabscount;
141
            $usespotlight = true;
142
        }
143
144
        if ($options[5] == 0 && $restricted) { // Use a specific news and we are in restricted mode
145
            if (!$perm_verified) {
146
                $permittedtopics = news_MygetItemIds();
147
                $permstory       = new NewsStory($options[6]);
148
                if (!in_array($permstory->topicid(), $permittedtopics)) {
149
                    $usespotlight = false;
150
                    $topicstitles = array();
151
                }
152
                //unset($permstory);
153
            } else {
154
                if (!$news_visible) {
155
                    $usespotlight = false;
156
                    $topicstitles = array();
157
                }
158
            }
159
        }
160
161
        $block['use_spotlight'] = $usespotlight;
162
163
        if (isset($options[14]) && $options[14] != 0) { // Topic to use
164
            $topics = array_slice($options, 14);
165
            $tabscount += count($topics);
166
            $topicstitles = $topic->getTopicTitleFromId($topics, $topicstitles);
167
        }
168
        $tabs = array();
169
        if ($usespotlight) {
170
            $tabs[] = array('id' => 0, 'title' => _MB_NEWS_SPOTLIGHT_TITLE);
171
        }
172
        if (count($topics) > 0) {
173
            foreach ($topics as $onetopic) {
174
                if (isset($topicstitles[$onetopic])) {
175
                    $tabs[] = array(
176
                        'id'      => $onetopic,
177
                        'title'   => $topicstitles[$onetopic]['title'],
178
                        'picture' => $topicstitles[$onetopic]['picture']
179
                    );
180
                }
181
            }
182
        }
183
        $block['tabs']                 = $tabs;
184
        $block['current_is_spotlight'] = false;
185
        $block['current_tab']          = $currenttab;
186
        $block['use_rating']           = $newsrating;
187
188
        if ($currenttab == 0 && $usespotlight) { // Spotlight or not ?
189
            $block['current_is_spotlight'] = true;
190
            if ($options[5] == 0
191
                && $options[6] == 0
192
            ) { // If the story to use was no selected then we switch to the "recent news" mode.
193
                $options[5] = 1;
194
            }
195
196
            if ($options[5] == 0) { // Use a specific news
197
                if (!isset($permstory)) {
198
                    $tmpstory->NewsStory($options[6]);
199
                } else {
200
                    $tmpstory = $permstory;
201
                }
202 View Code Duplication
            } else { // Use the most recent news
203
                $stories = array();
204
                $stories = NewsStory::getAllPublished(1, 0, $restricted, 0, 1, true, $options[0]);
205
                if (count($stories) > 0) {
206
                    $firststory = $stories[0];
207
                    $tmpstory->NewsStory($firststory->storyid());
208
                } else {
209
                    $block['use_spotlight'] = false;
210
                }
211
            }
212
            $spotlight          = array();
213
            $spotlight['title'] = $tmpstory->title();
214 View Code Duplication
            if ($options[7] !== '') {
215
                $spotlight['image'] = sprintf("<a href='%s'>%s</a>", XOOPS_URL . '/modules/news/article.php?storyid=' . $tmpstory->storyid(),
216
                                              $myts->displayTarea($options[7], $tmpstory->nohtml));
217
            }
218
            $spotlight['text'] = $tmpstory->hometext();
219
220
            // Added 16 february 2007 *****************************************
221
            $story_user = null;
222
            $story_user = new XoopsUser($tmpstory->uid());
223 View Code Duplication
            if (is_object($story_user)) {
224
                $spotlight['avatar'] = XOOPS_UPLOAD_URL . '/' . $story_user->getVar('user_avatar');
225
            }
226
            // ****************************************************************
227
            $spotlight['id']     = $tmpstory->storyid();
228
            $spotlight['date']   = formatTimestamp($tmpstory->published(), $dateformat);
229
            $spotlight['hits']   = $tmpstory->counter();
230
            $spotlight['rating'] = number_format($tmpstory->rating(), 2);
231
            $spotlight['votes']  = $tmpstory->votes();
232 View Code Duplication
            if (strlen(xoops_trim($tmpstory->bodytext())) > 0) {
233
                $spotlight['read_more'] = true;
234
            } else {
235
                $spotlight['read_more'] = false;
236
            }
237
238
            $spotlight['readmore']        = sprintf("<a href='%s'>%s</a>", XOOPS_URL . '/modules/news/article.php?storyid=' . $tmpstory->storyid(),
239
                                                    _MB_READMORE);
240
            $spotlight['title_with_link'] = sprintf("<a href='%s'>%s</a>", XOOPS_URL . '/modules/news/article.php?storyid=' . $tmpstory->storyid(),
241
                                                    $tmpstory->title());
242 View Code Duplication
            if ($tmpstory->votes() == 1) {
243
                $spotlight['number_votes'] = _NW_ONEVOTE;
244
            } else {
245
                $spotlight['number_votes'] = sprintf(_NW_NUMVOTES, $tmpstory->votes());
246
            }
247
248
            $spotlight['votes_with_text'] = sprintf(_NW_NUMVOTES, $tmpstory->votes());
249
            $spotlight['topicid']         = $tmpstory->topicid();
250
            $spotlight['topic_title']     = $tmpstory->topic_title();
251
            // Added, topic's image and description
252
            $spotlight['topic_image']       = XOOPS_URL . '/modules/news/assets/images/topics/' . $tmpstory->topic_imgurl();
253
            $spotlight['topic_description'] = $myts->displayTarea($tmpstory->topic_description, 1);
254
255
            if ($displayname != 3) {
256
                $spotlight['author']           = sprintf('%s %s', _POSTEDBY, $tmpstory->uname());
257
                $spotlight['author_with_link'] = sprintf("%s <a href='%s'>%s</a>", _POSTEDBY, XOOPS_URL . '/userinfo.php?uid=' . $tmpstory->uid(),
258
                                                         $tmpstory->uname());
259
            } else {
260
                $spotlight['author']           = '';
261
                $spotlight['author_with_link'] = '';
262
            }
263
            $spotlight['author_id'] = $tmpstory->uid();
264
265
            // Create the summary table under the spotlight text
266 View Code Duplication
            if (isset($options[14]) && $options[14] == 0) { // Use all topics
267
                $stories = NewsStory::getAllPublished($options[1], 0, $restricted, 0, 1, true, $options[0]);
268
            } else { // Use some topics
269
                $topics  = array_slice($options, 14);
270
                $stories = NewsStory::getAllPublished($options[1], 0, $restricted, $topics, 1, true, $options[0]);
271
            }
272
            if (count($stories) > 0) {
273
                foreach ($stories as $key => $story) {
274
                    $news  = array();
275
                    $title = $story->title();
276 View Code Duplication
                    if (strlen($title) > $options[2]) {
277
                        $title = xoops_substr($title, 0, $options[2] + 3);
278
                    }
279
                    $news['title']       = $title;
280
                    $news['id']          = $story->storyid();
281
                    $news['date']        = formatTimestamp($story->published(), $dateformat);
282
                    $news['hits']        = $story->counter();
283
                    $news['rating']      = number_format($story->rating(), 2);
284
                    $news['votes']       = $story->votes();
285
                    $news['topicid']     = $story->topicid();
286
                    $news['topic_title'] = $story->topic_title();
287
                    $news['topic_color'] = '#' . $myts->displayTarea($story->topic_color);
288
                    $news['picture']     = XOOPS_URL . '/uploads/news/image/' . $story->picture();
289
                    $news['pictureinfo'] = $story->pictureinfo();
290 View Code Duplication
                    if ($displayname != 3) {
291
                        $news['author'] = sprintf('%s %s', _POSTEDBY, $story->uname());
292
                    } else {
293
                        $news['author'] = '';
294
                    }
295 View Code Duplication
                    if ($options[3] > 0) {
296
                        $html           = $story->nohtml() == 1 ? 0 : 1;
297
                        $news['teaser'] = news_truncate_tagsafe($myts->displayTarea($story->hometext(), $html), $options[3] + 3);
298
                    } else {
299
                        $news['teaser'] = '';
300
                    }
301
                    if ($infotips > 0) {
302
                        $news['infotips'] = ' title="' . news_make_infotips($story->hometext()) . '"';
303
                    } else {
304
                        $news['infotips'] = '';
305
                    }
306
307
                    $news['title_with_link'] = sprintf("<a href='%s'%s>%s</a>", XOOPS_URL . '/modules/news/article.php?storyid=' . $story->storyid(),
308
                                                       $news['infotips'], $title);
309
                    $spotlight['news'][]     = $news;
310
                }
311
            }
312
313
            $block['spotlight'] = $spotlight;
314
        } else {
315
            if ($tabscount > 0) {
316
                $topics   = array_slice($options, 14);
317
                $thetopic = $currenttab;
318
                $stories  = NewsStory::getAllPublished($options[1], 0, $restricted, $thetopic, 1, true, $options[0]);
319
320
                $topic->getTopic($thetopic);
321
                // Added, topic's image and description
322
                $block['topic_image']       = XOOPS_URL . '/modules/news/assets/images/topics/' . $topic->topic_imgurl();
323
                $block['topic_description'] = $topic->topic_description();
324
325
                $smallheader   = array();
326
                $stats         = $topic->getTopicMiniStats($thetopic);
327
                $smallheader[] = sprintf("<a href='%s'>%s</a>", XOOPS_URL . '/modules/news/index.php?storytopic=' . $thetopic, _MB_READMORE);
328
                $smallheader[] = sprintf('%u %s', $stats['count'], _NW_ARTICLES);
329
                $smallheader[] = sprintf('%u %s', $stats['reads'], _READS);
330
                if (count($stories) > 0) {
331
                    foreach ($stories as $key => $story) {
332
                        $news  = array();
333
                        $title = $story->title();
334
                        if (strlen($title) > $options[2]) {
335
                            $title = news_truncate_tagsafe($title, $options[2] + 3);
336
                        }
337 View Code Duplication
                        if ($options[7] !== '') {
338
                            $news['image'] = sprintf("<a href='%s'>%s</a>", XOOPS_URL . '/modules/news/article.php?storyid=' . $story->storyid(),
339
                                                     $myts->displayTarea($options[7], $story->nohtml));
340
                        }
341 View Code Duplication
                        if ($options[3] > 0) {
342
                            $html         = $story->nohtml() == 1 ? 0 : 1;
343
                            $news['text'] = news_truncate_tagsafe($myts->displayTarea($story->hometext(), $html), $options[3] + 3);
344
                        } else {
345
                            $news['text'] = '';
346
                        }
347
348 View Code Duplication
                        if ($story->votes() == 1) {
349
                            $news['number_votes'] = _NW_ONEVOTE;
350
                        } else {
351
                            $news['number_votes'] = sprintf(_NW_NUMVOTES, $story->votes());
352
                        }
353
                        if ($infotips > 0) {
354
                            $news['infotips'] = ' title="' . news_make_infotips($story->hometext()) . '"';
355
                        } else {
356
                            $news['infotips'] = '';
357
                        }
358
                        $news['title']       = sprintf("<a href='%s' %s>%s</a>", XOOPS_URL . '/modules/news/article.php?storyid=' . $story->storyid(),
359
                                                       $news['infotips'], $title);
360
                        $news['id']          = $story->storyid();
361
                        $news['date']        = formatTimestamp($story->published(), $dateformat);
362
                        $news['hits']        = $story->counter();
363
                        $news['rating']      = number_format($story->rating(), 2);
364
                        $news['votes']       = $story->votes();
365
                        $news['topicid']     = $story->topicid();
366
                        $news['topic_title'] = $story->topic_title();
367
                        $news['topic_color'] = '#' . $myts->displayTarea($story->topic_color);
368
                        $news['picture']     = XOOPS_URL . '/uploads/news/image/' . $story->picture();
369
                        $news['pictureinfo'] = $story->pictureinfo();
370
371 View Code Duplication
                        if ($displayname != 3) {
372
                            $news['author'] = sprintf('%s %s', _POSTEDBY, $story->uname());
373
                        } else {
374
                            $news['author'] = '';
375
                        }
376
                        $news['title_with_link'] = sprintf("<a href='%s'%s>%s</a>",
377
                                                           XOOPS_URL . '/modules/news/article.php?storyid=' . $story->storyid(), $news['infotips'],
378
                                                           $title);
379
                        $block['news'][]         = $news;
380
                    }
381
                    $block['smallheader'] = $smallheader;
382
                }
383
            }
384
        }
385
        $block['lang_on']    = _ON; // on
386
        $block['lang_reads'] = _READS; // reads
387
        // Default values
388
        $block['color1'] = $defcolors[$tabskin][0];
389
        $block['color2'] = $defcolors[$tabskin][1];
390
        $block['color3'] = $defcolors[$tabskin][2];
391
        $block['color4'] = $defcolors[$tabskin][3];
392
        $block['color5'] = $defcolors[$tabskin][4];
393
394
        if (xoops_trim($options[9]) !== '') {
395
            $block['color1'] = $options[9];
396
        }
397
        if (xoops_trim($options[10]) !== '') {
398
            $block['color2'] = $options[10];
399
        }
400
        if (xoops_trim($options[11]) !== '') {
401
            $block['color3'] = $options[11];
402
        }
403
        if (xoops_trim($options[12]) !== '') {
404
            $block['color4'] = $options[12];
405
        }
406
        if (xoops_trim($options[13]) !== '') {
407
            $block['color5'] = $options[13];
408
        }
409
    } else { // ************************ Classical view **************************************************************************************************************
410
        $tmpstory = new NewsStory;
0 ignored issues
show
$tmpstory is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
411 View Code Duplication
        if (isset($options[14]) && $options[14] == 0) {
412
            $stories = NewsStory::getAllPublished($options[1], 0, $restricted, 0, 1, true, $options[0]);
413
        } else {
414
            $topics  = array_slice($options, 14);
415
            $stories = NewsStory::getAllPublished($options[1], 0, $restricted, $topics, 1, true, $options[0]);
416
        }
417
418
        if (!count($stories)) {
419
            return '';
420
        }
421
        $topic = new NewsTopic();
422
423
        foreach ($stories as $key => $story) {
424
            $news  = array();
425
            $title = $story->title();
426 View Code Duplication
            if (strlen($title) > $options[2]) {
427
                $title = xoops_substr($title, 0, $options[2] + 3);
428
            }
429
430
            //if spotlight is enabled and this is either the first article or the selected one
431
            if (($options[5] == 0) && ($options[4] == 1)
432
                && (($options[6] > 0 && $options[6] == $story->storyid())
433
                    || ($options[6] == 0 && $key == 0))
434
            ) {
435
                $spotlight = array();
436
                $visible   = true;
437
                if ($restricted) {
438
                    $permittedtopics = news_MygetItemIds();
439
                    if (!in_array($story->topicid(), $permittedtopics)) {
440
                        $visible = false;
441
                    }
442
                }
443
444
                if ($visible) {
445
                    $spotlight['title'] = $title;
446 View Code Duplication
                    if ($options[7] !== '') {
447
                        $spotlight['image'] = sprintf("<a href='%s'>%s</a>", XOOPS_URL . '/modules/news/article.php?storyid=' . $story->storyid(),
448
                                                      $myts->displayTarea($options[7], $story->nohtml));
449
                    }
450
                    // Added 16 february 2007 *****************************************
451
                    $story_user = null;
452
                    $story_user = new XoopsUser($story->uid());
453 View Code Duplication
                    if (is_object($story_user)) {
454
                        $spotlight['avatar'] = XOOPS_UPLOAD_URL . '/' . $story_user->getVar('user_avatar');
455
                    }
456
                    // ****************************************************************
457
                    $spotlight['text']        = $story->hometext();
458
                    $spotlight['id']          = $story->storyid();
459
                    $spotlight['date']        = formatTimestamp($story->published(), $dateformat);
460
                    $spotlight['hits']        = $story->counter();
461
                    $spotlight['rating']      = $story->rating();
462
                    $spotlight['votes']       = $story->votes();
463
                    $spotlight['topicid']     = $story->topicid();
464
                    $spotlight['topic_title'] = $story->topic_title();
465
                    $spotlight['topic_color'] = '#' . $myts->displayTarea($story->topic_color);
466
                    // Added, topic's image and description
467
                    $spotlight['topic_image']       = XOOPS_URL . '/modules/news/assets/images/topics/' . $story->topic_imgurl();
468
                    $spotlight['topic_description'] = $myts->displayTarea($story->topic_description, 1);
469 View Code Duplication
                    if (strlen(xoops_trim($story->bodytext())) > 0) {
470
                        $spotlight['read_more'] = true;
471
                    } else {
472
                        $spotlight['read_more'] = false;
473
                    }
474
475 View Code Duplication
                    if ($displayname != 3) {
476
                        $spotlight['author'] = sprintf('%s %s', _POSTEDBY, $story->uname());
477
                    } else {
478
                        $spotlight['author'] = '';
479
                    }
480
                }
481
                $block['spotlight'] = $spotlight;
482
            } else {
483
                $news['title']       = $title;
484
                $news['id']          = $story->storyid();
485
                $news['date']        = formatTimestamp($story->published(), $dateformat);
486
                $news['hits']        = $story->counter();
487
                $news['rating']      = $story->rating();
488
                $news['votes']       = $story->votes();
489
                $news['topicid']     = $story->topicid();
490
                $news['topic_title'] = $story->topic_title();
491
                $news['topic_color'] = '#' . $myts->displayTarea($story->topic_color);
492
                $news['picture']     = XOOPS_URL . '/uploads/news/image/' . $story->picture();
493
                $news['pictureinfo'] = $story->pictureinfo();
494
495 View Code Duplication
                if ($displayname != 3) {
496
                    $news['author'] = sprintf('%s %s', _POSTEDBY, $story->uname());
497
                } else {
498
                    $news['author'] = '';
499
                }
500
                if ($options[3] > 0) {
501
                    $html             = $story->nohtml() == 1 ? 0 : 1;
502
                    $news['teaser']   = news_truncate_tagsafe($myts->displayTarea($story->hometext(), $html), $options[3] + 3);
503
                    $news['infotips'] = '';
504
                } else {
505
                    $news['teaser'] = '';
506
                    if ($infotips > 0) {
507
                        $news['infotips'] = ' title="' . news_make_infotips($story->hometext()) . '"';
508
                    } else {
509
                        $news['infotips'] = '';
510
                    }
511
                }
512
                $block['stories'][] = $news;
513
            }
514
        }
515
516
        // If spotlight article was not in the fetched stories
517
        if (!isset($spotlight) && $options[4]) {
518
            $block['use_spotlight'] = true;
519
            $visible                = true;
520
            if ($options[5] == 0 && $restricted) { // Use a specific news and we are in restricted mode
521
                $permittedtopics = news_MygetItemIds();
522
                $permstory       = new NewsStory($options[6]);
523
                if (!in_array($permstory->topicid(), $permittedtopics)) {
524
                    $visible = false;
525
                }
526
                unset($permstory);
527
            }
528
529
            if ($options[5] == 0) { // Use a specific news
530
                if ($visible) {
531
                    $spotlightArticle = new NewsStory($options[6]);
532
                } else {
533
                    $block['use_spotlight'] = false;
534
                }
535 View Code Duplication
            } else { // Use the most recent news
536
                $stories = array();
537
                $stories = NewsStory::getAllPublished(1, 0, $restricted, 0, 1, true, $options[0]);
538
                if (count($stories) > 0) {
539
                    $firststory       = $stories[0];
540
                    $spotlightArticle = new NewsStory($firststory->storyid());
541
                } else {
542
                    $block['use_spotlight'] = false;
543
                }
544
            }
545
            if ($block['use_spotlight'] == true) {
546
                $spotlight          = array();
547
                $spotlight['title'] = xoops_substr($spotlightArticle->title(), 0, $options[2] - 1);
548 View Code Duplication
                if ($options[7] !== '') {
549
                    $spotlight['image'] = sprintf("<a href='%s'>%s</a>",
550
                                                  XOOPS_URL . '/modules/news/article.php?storyid=' . $spotlightArticle->storyid(),
551
                                                  $myts->displayTarea($options[7], $spotlightArticle->nohtml));
552
                }
553
                // Added 16 february 2007 *****************************************
554
                $story_user = null;
555
                $story_user = new XoopsUser($spotlightArticle->uid());
556 View Code Duplication
                if (is_object($story_user)) {
557
                    $spotlight['avatar'] = XOOPS_UPLOAD_URL . '/' . $story_user->getVar('user_avatar');
558
                }
559
                // ****************************************************************
560
                $spotlight['topicid']     = $spotlightArticle->topicid();
561
                $spotlight['topic_title'] = $spotlightArticle->topic_title();
562
                $spotlight['topic_color'] = '#' . $myts->displayTarea($spotlightArticle->topic_color);
563
                $spotlight['text']        = $spotlightArticle->hometext();
564
                $spotlight['id']          = $spotlightArticle->storyid();
565
                $spotlight['date']        = formatTimestamp($spotlightArticle->published(), $dateformat);
566
                $spotlight['hits']        = $spotlightArticle->counter();
567
                $spotlight['rating']      = $spotlightArticle->rating();
568
                $spotlight['votes']       = $spotlightArticle->votes();
569
                // Added, topic's image and description
570
                $spotlight['topic_image']       = XOOPS_URL . '/modules/news/assets/images/topics/' . $spotlightArticle->topic_imgurl();
571
                $spotlight['topic_description'] = $myts->displayTarea($spotlightArticle->topic_description, 1);
572 View Code Duplication
                if ($displayname != 3) {
573
                    $spotlight['author'] = sprintf('%s %s', _POSTEDBY, $spotlightArticle->uname());
574
                } else {
575
                    $spotlight['author'] = '';
576
                }
577 View Code Duplication
                if (strlen(xoops_trim($spotlightArticle->bodytext())) > 0) {
578
                    $spotlight['read_more'] = true;
579
                } else {
580
                    $spotlight['read_more'] = false;
581
                }
582
                $block['spotlight'] = $spotlight;
583
            }
584
        }
585
    }
586
    if (isset($permstory)) {
587
        unset($permstory);
588
    }
589
    $block['lang_read_more']      = $myts->htmlSpecialChars(_MB_READMORE); // Read More...
590
    $block['lang_orderby']        = $myts->htmlSpecialChars(_MB_NEWS_ORDER); // "Order By"
591
    $block['lang_orderby_date']   = $myts->htmlSpecialChars(_MB_NEWS_DATE); // Published date
592
    $block['lang_orderby_hits']   = $myts->htmlSpecialChars(_MB_NEWS_HITS); // Number of Hits
593
    $block['lang_orderby_rating'] = $myts->htmlSpecialChars(_MB_NEWS_RATE); // Rating
594
    $block['sort']                = $options[0]; // "published" or "counter" or "rating"
595
596
    return $block;
597
}
598
599
/**
600
 * Function used to edit the block
601
 * @param $options
602
 * @return string
603
 */
604
function b_news_top_edit($options)
605
{
606
    global $xoopsDB;
607
    $tmpstory = new NewsStory;
608
    $form     = _MB_NEWS_ORDER . "&nbsp;<select name='options[]'>";
609
    $form .= "<option value='published'";
610
    if ($options[0] === 'published') {
611
        $form .= ' selected';
612
    }
613
    $form .= '>' . _MB_NEWS_DATE . "</option>\n";
614
615
    $form .= "<option value='counter'";
616
    if ($options[0] === 'counter') {
617
        $form .= ' selected';
618
    }
619
    $form .= '>' . _MB_NEWS_HITS . '</option>';
620
    $form .= "<option value='rating'";
621
    if ($options[0] === 'rating') {
622
        $form .= ' selected';
623
    }
624
    $form .= '>' . _MB_NEWS_RATE . '</option>';
625
    $form .= "</select>\n";
626
627
    $form .= '&nbsp;' . _MB_NEWS_DISP . "&nbsp;<input type='text' name='options[]' value='" . $options[1] . "'/>&nbsp;" . _MB_NEWS_ARTCLS;
628
    $form .= '&nbsp;<br><br>'
629
             . _MB_NEWS_CHARS
630
             . "&nbsp;<input type='text' name='options[]' value='"
631
             . $options[2]
632
             . "'/>&nbsp;"
633
             . _MB_NEWS_LENGTH
634
             . '<br><br>';
635
636
    $form .= _MB_NEWS_TEASER . " <input type='text' name='options[]' value='" . $options[3] . "' />" . _MB_NEWS_LENGTH;
637
    $form .= '<br><br>';
638
639
    $form .= _MB_NEWS_SPOTLIGHT . " <input type='radio' name='options[]' value='1'";
640
    if ($options[4] == 1) {
641
        $form .= ' checked';
642
    }
643
    $form .= ' />' . _YES;
644
    $form .= "<input type='radio' name='options[]' value='0'";
645
    if ($options[4] == 0) {
646
        $form .= ' checked';
647
    }
648
    $form .= ' />' . _NO . '<br><br>';
649
650
    $form .= _MB_NEWS_WHAT_PUBLISH . " <select name='options[]'><option value='1'";
651
    if ($options[5] == 1) {
652
        $form .= ' selected';
653
    }
654
    $form .= ' />' . _MB_NEWS_RECENT_NEWS;
655
    $form .= "</option><option value='0'";
656
    if ($options[5] == 0) {
657
        $form .= ' selected';
658
    }
659
    $form .= ' />' . _MB_NEWS_RECENT_SPECIFIC . '</option></select>';
660
661
    $form .= '<br><br>' . _MB_NEWS_SPOTLIGHT_ARTICLE . '<br>';
662
    $articles = NewsStory::getAllPublished(200, 0, false, 0, 0, false); // I have limited the listbox to the last 200 articles
663
    $form .= "<select name ='options[]'>";
664
    $form .= "<option value='0'>" . _MB_NEWS_FIRST . '</option>';
665
    foreach ($articles as $storyid => $storytitle) {
666
        $sel = '';
667
        if ($options[6] == $storyid) {
668
            $sel = ' selected';
669
        }
670
        $form .= "<option value='$storyid'$sel>" . $storytitle . '</option>';
671
    }
672
    $form .= '</select><br><br>';
673
674
    $form .= _MB_NEWS_IMAGE . "&nbsp;<input type='text' id='spotlightimage' name='options[]' value='" . $options[7] . "' size='50'/>";
675
    $form .= "&nbsp;<img align='middle' onmouseover='style.cursor=\"hand\"' onclick='javascript:openWithSelfMain(\""
676
             . XOOPS_URL
677
             . "/imagemanager.php?target=spotlightimage\",\"imgmanager\",400,430);' src='"
678
             . XOOPS_URL
679
             . "/images/image.gif' alt='image' title='image' />";
680
    $form .= '<br><br>' . _MB_NEWS_DISP . "&nbsp;<select name='options[]'><option value='1' ";
681
    if ($options[8] == 1) {
682
        $form .= 'selected';
683
    }
684
    $form .= '>' . _MB_NEWS_VIEW_TYPE1 . "</option><option value='2' ";
685
    if ($options[8] == 2) {
686
        $form .= 'selected';
687
    }
688
    $form .= '>' . _MB_NEWS_VIEW_TYPE2 . '</option></select><br><br>';
689
690
    $form .= "<table border=0>\n";
691
    $form .= "<tr><td colspan='2' align='center'><u>" . _MB_NEWS_DEFAULT_COLORS . '</u></td></tr>';
692
    $form .= '<tr><td>' . _MB_NEWS_TAB_COLOR1 . "</td><td><input type='text' name='options[]' value='" . $options[9] . "' size=7></td></tr>";
693
    $form .= '<tr><td>' . _MB_NEWS_TAB_COLOR2 . "</td><td><input type='text' name='options[]' value='" . $options[10] . "' size=7></td></tr>";
694
    $form .= '<tr><td>' . _MB_NEWS_TAB_COLOR3 . "</td><td><input type='text' name='options[]' value='" . $options[11] . "' size=7></td></tr>";
695
    $form .= '<tr><td>' . _MB_NEWS_TAB_COLOR4 . "</td><td><input type='text' name='options[]' value='" . $options[12] . "' size=7></td></tr>";
696
    $form .= '<tr><td>' . _MB_NEWS_TAB_COLOR5 . "</td><td><input type='text' name='options[]' value='" . $options[13] . "' size=7></td></tr>";
697
    $form .= "</table>\n";
698
699
    $form .= '<br><br>' . _MB_SPOTLIGHT_TOPIC . "<br><select name='options[]' multiple='multiple'>";
700
    include_once XOOPS_ROOT_PATH . '/modules/news/class/class.newstopic.php';
701
    $topics_arr = array();
702
    include_once XOOPS_ROOT_PATH . '/modules/news/class/xoopstree.php';
703
    $xt         = new MyXoopsTree($xoopsDB->prefix('news_topics'), 'topic_id', 'topic_pid');
704
    $topics_arr = $xt->getChildTreeArray(0, 'topic_title');
705
    $size       = count($options);
706
    foreach ($topics_arr as $onetopic) {
707
        $sel = '';
708 View Code Duplication
        if ($onetopic['topic_pid'] != 0) {
709
            $onetopic['prefix'] = str_replace('.', '-', $onetopic['prefix']) . '&nbsp;';
710
        } else {
711
            $onetopic['prefix'] = str_replace('.', '', $onetopic['prefix']);
712
        }
713
        for ($i = 14; $i < $size; ++$i) {
714
            if ($options[$i] == $onetopic['topic_id']) {
715
                $sel = ' selected';
716
            }
717
        }
718
        $form .= "<option value='" . $onetopic['topic_id'] . "'$sel>" . $onetopic['prefix'] . $onetopic['topic_title'] . '</option>';
719
    }
720
    $form .= '</select><br>';
721
722
    return $form;
723
}
724
725
/**
726
 * @param $options
727
 */
728 View Code Duplication
function b_news_top_onthefly($options)
729
{
730
    $options = explode('|', $options);
731
    $block   = &b_news_top_show($options);
732
733
    $tpl = new XoopsTpl();
734
    $tpl->assign('block', $block);
735
    $tpl->display('db:news_block_top.tpl');
736
}
737