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 XoopsModules\News; |
19
|
|
|
use XoopsModules\News\Helper; |
20
|
|
|
use XoopsModules\News\NewsStory; |
21
|
|
|
|
22
|
|
|
// require_once XOOPS_ROOT_PATH . '/modules/news/class/class.newsstory.php'; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @param $options |
26
|
|
|
* |
27
|
|
|
* @return array|string |
28
|
|
|
*/ |
29
|
|
|
function b_news_randomnews_show($options) |
30
|
|
|
{ |
31
|
|
|
/** @var Helper $helper */ |
32
|
|
|
if (!class_exists(Helper::class)) { |
33
|
|
|
return false; |
|
|
|
|
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
$helper = Helper::getInstance(); |
|
|
|
|
37
|
|
|
|
38
|
|
|
$myts = \MyTextSanitizer::getInstance(); |
39
|
|
|
$block = []; |
40
|
|
|
$block['sort'] = $options[0]; |
41
|
|
|
|
42
|
|
|
$tmpstory = new NewsStory(); |
43
|
|
|
$restricted = News\Utility::getModuleOption('restrictindex'); |
44
|
|
|
$dateformat = News\Utility::getModuleOption('dateformat'); |
45
|
|
|
$infotips = News\Utility::getModuleOption('infotips'); |
46
|
|
|
if ('' == $dateformat) { |
47
|
|
|
$dateformat = 's'; |
48
|
|
|
} |
49
|
|
|
if (0 == $options[4]) { |
50
|
|
|
$stories = $tmpstory->getRandomNews((int)$options[1], 0, $restricted, 0, 1, $options[0]); |
51
|
|
|
} else { |
52
|
|
|
$topics = array_slice($options, 4); |
53
|
|
|
$stories = $tmpstory->getRandomNews((int)$options[1], 0, $restricted, $topics, 1, $options[0]); |
|
|
|
|
54
|
|
|
} |
55
|
|
|
unset($tmpstory); |
56
|
|
|
if (0 == count($stories)) { |
57
|
|
|
return ''; |
58
|
|
|
} |
59
|
|
|
foreach ($stories as $story) { |
60
|
|
|
$news = []; |
61
|
|
|
$title = $story->title(); |
62
|
|
|
if (mb_strlen($title) > $options[2]) { |
63
|
|
|
$title = xoops_substr($title, 0, $options[2] + 3); |
64
|
|
|
} |
65
|
|
|
$news['title'] = $title; |
66
|
|
|
$news['id'] = $story->storyid(); |
67
|
|
|
$news['date'] = formatTimestamp($story->published(), $dateformat); |
68
|
|
|
$news['hits'] = $story->counter(); |
69
|
|
|
$news['rating'] = $story->rating(); |
70
|
|
|
$news['votes'] = $story->votes(); |
71
|
|
|
$news['author'] = sprintf('%s %s', _POSTEDBY, $story->uname()); |
72
|
|
|
$news['topic_title'] = $story->topic_title(); |
73
|
|
|
$news['topic_color'] = '#' . $myts->displayTarea($story->topic_color); |
74
|
|
|
$news['picture'] = XOOPS_URL . '/uploads/news/image/' . $story->picture(); |
75
|
|
|
$news['pictureinfo'] = $story->pictureinfo(); |
76
|
|
|
|
77
|
|
|
if ($options[3] > 0) { |
78
|
|
|
$html = 1 == $story->nohtml() ? 0 : 1; |
79
|
|
|
$news['teaser'] = News\Utility::truncateTagSafe($myts->displayTarea($story->hometext, $html), $options[3] + 3); |
80
|
|
|
$news['infotips'] = ' title="' . $story->title() . '"'; |
81
|
|
|
} else { |
82
|
|
|
$news['teaser'] = ''; |
83
|
|
|
if ($infotips > 0) { |
84
|
|
|
$news['infotips'] = ' title="' . News\Utility::makeInfotips($story->hometext()) . '"'; |
85
|
|
|
} else { |
86
|
|
|
$news['infotips'] = ' title="' . $story->title() . '"'; |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
$block['stories'][] = $news; |
90
|
|
|
} |
91
|
|
|
$block['lang_read_more'] = _MB_READMORE; |
92
|
|
|
|
93
|
|
|
return $block; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @param $options |
98
|
|
|
* |
99
|
|
|
* @return string |
100
|
|
|
*/ |
101
|
|
|
function b_news_randomnews_edit($options) |
102
|
|
|
{ |
103
|
|
|
global $xoopsDB; |
104
|
|
|
$form = _MB_NEWS_ORDER . " <select name='options[]'>"; |
105
|
|
|
$form .= "<option value='published'"; |
106
|
|
|
if ('published' === $options[0]) { |
107
|
|
|
$form .= ' selected'; |
108
|
|
|
} |
109
|
|
|
$form .= '>' . _MB_NEWS_DATE . "</option>\n"; |
110
|
|
|
|
111
|
|
|
$form .= "<option value='counter'"; |
112
|
|
|
if ('counter' === $options[0]) { |
113
|
|
|
$form .= ' selected'; |
114
|
|
|
} |
115
|
|
|
$form .= '>' . _MB_NEWS_HITS . '</option>'; |
116
|
|
|
|
117
|
|
|
$form .= "<option value='rating'"; |
118
|
|
|
if ('rating' === $options[0]) { |
119
|
|
|
$form .= ' selected'; |
120
|
|
|
} |
121
|
|
|
$form .= '>' . _MB_NEWS_RATE . '</option>'; |
122
|
|
|
|
123
|
|
|
$form .= "</select>\n"; |
124
|
|
|
$form .= ' ' . _MB_NEWS_DISP . " <input type='text' name='options[]' value='" . $options[1] . "'> " . _MB_NEWS_ARTCLS; |
125
|
|
|
$form .= ' <br><br>' . _MB_NEWS_CHARS . " <input type='text' name='options[]' value='" . $options[2] . "'> " . _MB_NEWS_LENGTH . '<br><br>'; |
126
|
|
|
|
127
|
|
|
$form .= _MB_NEWS_TEASER . " <input type='text' name='options[]' value='" . $options[3] . "'>" . _MB_NEWS_LENGTH; |
128
|
|
|
$form .= '<br><br>' . _MB_SPOTLIGHT_TOPIC . "<br><select id='options[4]' name='options[]' multiple='multiple'>"; |
129
|
|
|
|
130
|
|
|
// require_once XOOPS_ROOT_PATH . '/modules/news/class/xoopsstory.php'; |
131
|
|
|
$xt = new \XoopsModules\News\XoopsTopic($xoopsDB->prefix('news_topics')); |
132
|
|
|
$alltopics = $xt->getTopicsList(); |
133
|
|
|
$alltopics[0]['title'] = _MB_SPOTLIGHT_ALL_TOPICS; |
134
|
|
|
ksort($alltopics); |
135
|
|
|
$size = count($options); |
136
|
|
|
foreach ($alltopics as $topicid => $topic) { |
137
|
|
|
$sel = ''; |
138
|
|
|
for ($i = 4; $i < $size; ++$i) { |
139
|
|
|
if ($options[$i] == $topicid) { |
140
|
|
|
$sel = ' selected'; |
141
|
|
|
} |
142
|
|
|
} |
143
|
|
|
$form .= "<option value='$topicid'$sel>" . $topic['title'] . '</option>'; |
144
|
|
|
} |
145
|
|
|
$form .= '</select><br>'; |
146
|
|
|
|
147
|
|
|
return $form; |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* @param $options |
152
|
|
|
*/ |
153
|
|
|
function b_news_randomnews_onthefly($options): void |
154
|
|
|
{ |
155
|
|
|
$options = explode('|', $options); |
156
|
|
|
$block = b_news_randomnews_show($options); |
157
|
|
|
|
158
|
|
|
$tpl = new \XoopsTpl(); |
159
|
|
|
$tpl->assign('block', $block); |
160
|
|
|
$tpl->display('db:news_block_moderate.tpl'); |
161
|
|
|
} |
162
|
|
|
|