|
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\NewsTopic; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @param $options |
|
24
|
|
|
* |
|
25
|
|
|
* @return array|string |
|
26
|
|
|
*/ |
|
27
|
|
|
function b_news_topicsnav_show($options) |
|
28
|
|
|
{ |
|
29
|
|
|
/** @var Helper $helper */ |
|
30
|
|
|
if (!class_exists(Helper::class)) { |
|
31
|
|
|
return false; |
|
|
|
|
|
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
$helper = Helper::getInstance(); |
|
|
|
|
|
|
35
|
|
|
|
|
36
|
|
|
$myts = \MyTextSanitizer::getInstance(); |
|
37
|
|
|
$block = []; |
|
38
|
|
|
$newscountbytopic = []; |
|
39
|
|
|
$perms = ''; |
|
40
|
|
|
$xt = new NewsTopic(); |
|
41
|
|
|
$restricted = News\Utility::getModuleOption('restrictindex'); |
|
42
|
|
|
if ($restricted) { |
|
43
|
|
|
global $xoopsUser; |
|
44
|
|
|
/** @var \XoopsModuleHandler $moduleHandler */ |
|
45
|
|
|
$moduleHandler = xoops_getHandler('module'); |
|
46
|
|
|
$newsModule = $moduleHandler->getByDirname('news'); |
|
47
|
|
|
$groups = is_object($xoopsUser) ? $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS; |
|
48
|
|
|
/** @var \XoopsGroupPermHandler $grouppermHandler */ |
|
49
|
|
|
$grouppermHandler = xoops_getHandler('groupperm'); |
|
50
|
|
|
$topics = $grouppermHandler->getItemIds('news_view', $groups, $newsModule->getVar('mid')); |
|
51
|
|
|
if (count($topics) > 0) { |
|
52
|
|
|
$topics = implode(',', $topics); |
|
53
|
|
|
$perms = ' AND topic_id IN (' . $topics . ') '; |
|
54
|
|
|
} else { |
|
55
|
|
|
return ''; |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
$topics_arr = $xt->getChildTreeArray(0, 'topic_title', $perms); |
|
59
|
|
|
if (1 == $options[0]) { |
|
60
|
|
|
$newscountbytopic = $xt->getNewsCountByTopic(); |
|
61
|
|
|
} |
|
62
|
|
|
if (is_array($topics_arr) && count($topics_arr)) { |
|
63
|
|
|
foreach ($topics_arr as $onetopic) { |
|
64
|
|
|
if (1 == $options[0]) { |
|
65
|
|
|
$count = 0; |
|
66
|
|
|
if (array_key_exists($onetopic['topic_id'], $newscountbytopic)) { |
|
67
|
|
|
$count = $newscountbytopic[$onetopic['topic_id']]; |
|
68
|
|
|
} |
|
69
|
|
|
} else { |
|
70
|
|
|
$count = ''; |
|
71
|
|
|
} |
|
72
|
|
|
$block['topics'][] = [ |
|
73
|
|
|
'id' => $onetopic['topic_id'], |
|
74
|
|
|
'news_count' => $count, |
|
75
|
|
|
'topic_color' => '#' . $onetopic['topic_color'], |
|
76
|
|
|
'title' => $myts->displayTarea($onetopic['topic_title']), |
|
77
|
|
|
]; |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
return $block; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* @param $options |
|
86
|
|
|
* |
|
87
|
|
|
* @return string |
|
88
|
|
|
*/ |
|
89
|
|
|
function b_news_topicsnav_edit($options) |
|
90
|
|
|
{ |
|
91
|
|
|
$form = _MB_NEWS_SHOW_NEWS_COUNT . " <input type='radio' name='options[]' value='1'"; |
|
92
|
|
|
if (1 == $options[0]) { |
|
93
|
|
|
$form .= ' checked'; |
|
94
|
|
|
} |
|
95
|
|
|
$form .= '>' . _YES; |
|
96
|
|
|
$form .= "<input type='radio' name='options[]' value='0'"; |
|
97
|
|
|
if (0 == $options[0]) { |
|
98
|
|
|
$form .= ' checked'; |
|
99
|
|
|
} |
|
100
|
|
|
$form .= '>' . _NO; |
|
101
|
|
|
|
|
102
|
|
|
return $form; |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* @param $options |
|
107
|
|
|
*/ |
|
108
|
|
|
function b_news_topicsnav_onthefly($options): void |
|
109
|
|
|
{ |
|
110
|
|
|
$options = explode('|', $options); |
|
111
|
|
|
$block = b_news_topicsnav_show($options); |
|
112
|
|
|
|
|
113
|
|
|
$tpl = new \XoopsTpl(); |
|
114
|
|
|
$tpl->assign('block', $block); |
|
115
|
|
|
$tpl->display('db:news_block_topicnav.tpl'); |
|
116
|
|
|
} |
|
117
|
|
|
|