-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathnewsbythisauthor.php
208 lines (191 loc) · 9.7 KB
/
newsbythisauthor.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
<?php declare(strict_types=1);
/*
* You may not change or alter any portion of this comment or credits
* of supporting developers from this source code or any supporting source code
* which is considered copyrighted (c) material of the original comment or credit authors.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
/**
* @copyright {@link https://xoops.org/ XOOPS Project}
* @license {@link https://www.gnu.org/licenses/gpl-2.0.html GNU GPL 2 or later}
* @author XOOPS Development Team
*/
/*
* Display all the news by the author of a certain story
*
* This page is called from the page "article.php" and it will
* show all the articles writen by an author. We use the module's
* option named "restrictindex" to show or hide stories according
* to users permissions and this page can only be called if the
* module's option "newsbythisauthor" is set to "Yes"
*
* @package News
* @author Xoops Modules Dev Team
* @copyright (c) XOOPS Project (https://xoops.org)
*
* Parameters received by this page :
* @page_param int uid Id of the user you want to treat
*
* @page_title "News by the same author" - Author's name - Module's name
*
* @template_name news_by_this_author.html
*
* Template's variables :
* @template_var string lang_page_title contains "News by the same author"
* @template_var int author_id contains the user ID
* @template_var string author_name Name of the author (according to the user preferences (username or full name or nothing))
* @template_var string author_name_with_link Name of the author with a hyperlink pointing to userinfo.php (to see their "identity")
* @template_var int articles_count Total number of visibles articles (for the current user and according to the permissions)
* @template_var string lang_date Fixed string, "Date"
* @template_var string lang_hits Fixed string, 'Views'
* @template_var string lang_title Fixed string, 'Title'
* @template_var int articles_count Total number of articles by this author (permissions are used)
* @template_var boolean news_rating News are rated ?
* @template_var string lang_rating Fixed text "Rating"
* @template_var array topics Contains all the topics where the author have written some articles.
* Structure :
* topic_id int Topic's ID
* topic_title string Topic's title
* topic_color string Topic's color
* topic_link string Link to see all the articles in this topic + topic's title
* news array List of all the articles from this author for this topic
* Structure :
* int id Article's Id
* string hometext The scoop
* string title Article's title
* int hits Counter of visits
* string created Date of creation formated (according to user's prefs)
* string article_link Link to see the article + article's title
* string published Date of publication formated (according to user's prefs)
* int rating Rating for this news
*/
use Xmf\Request;
use XoopsModules\News;
use XoopsModules\News\NewsStory;
require_once \dirname(__DIR__, 2) . '/mainfile.php';
//require_once XOOPS_ROOT_PATH . '/modules/news/class/class.newsstory.php';
//require_once XOOPS_ROOT_PATH . '/modules/news/class/class.newstopic.php';
//require_once XOOPS_ROOT_PATH . '/modules/news/class/class.sfiles.php';
/** @var News\Helper $helper */
$helper = News\Helper::getInstance();
global $xoopsUser;
$helper = News\Helper::getInstance();
$helper->loadLanguage('modinfo');
$uid = Request::getInt('uid', 0, 'GET');
if (empty($uid)) {
redirect_header('index.php', 2, _ERRORS);
}
if (!News\Utility::getModuleOption('newsbythisauthor')) {
redirect_header('index.php', 2, _ERRORS);
}
$myts = \MyTextSanitizer::getInstance();
$articles = new NewsStory();
$GLOBALS['xoopsOption']['template_main'] = 'news_by_this_author.tpl';
require_once XOOPS_ROOT_PATH . '/header.php';
$dateformat = News\Utility::getModuleOption('dateformat');
$infotips = News\Utility::getModuleOption('infotips');
$thisuser = new \XoopsUser($uid);
switch ($helper->getConfig('displayname')) {
case 1: // Username
$authname = $thisuser->getVar('uname');
break;
case 2: // Display full name (if it is not empty)
if ('' == xoops_trim($thisuser->getVar('name'))) {
$authname = $thisuser->getVar('uname');
} else {
$authname = $thisuser->getVar('name');
}
break;
case 3: // Nothing
$authname = '';
break;
}
$xoopsTpl->assign('lang_page_title', _MI_NEWSBYTHISAUTHOR . ' - ' . $authname);
$xoopsTpl->assign('lang_news_by_this_author', _MI_NEWSBYTHISAUTHOR);
$xoopsTpl->assign('author_id', $uid);
$xoopsTpl->assign('user_avatarurl', XOOPS_URL . '/uploads/' . $thisuser->getVar('user_avatar'));
$xoopsTpl->assign('author_name', $authname);
$xoopsTpl->assign('lang_date', _NW_DATE);
$xoopsTpl->assign('lang_hits', _NW_VIEWS);
$xoopsTpl->assign('lang_title', _NW_TITLE);
$xoopsTpl->assign('news_rating', News\Utility::getModuleOption('ratenews'));
$xoopsTpl->assign('lang_rating', _NW_RATING);
$xoopsTpl->assign('author_name_with_link', sprintf("<a href='%s'>%s</a>", XOOPS_URL . '/userinfo.php?uid=' . $uid, $authname));
$oldtopic = -1;
$oldtopictitle = '';
$oldtopiccolor = '';
$articlelist = [];
$articlestpl = [];
$articlelist = $articles->getAllPublishedByAuthor($uid, $helper->getConfig('restrictindex'), false);
$articlescount = count($articlelist);
$xoopsTpl->assign('articles_count', $articlescount);
$count_articles = $count_reads = 0;
if ($articlescount > 0) {
foreach ($articlelist as $article) {
if ($oldtopic != $article['topicid']) {
if (count($articlestpl) > 0) {
$topic_link = sprintf("<a href='%s'>%s</a>", XOOPS_URL . '/modules/news/index.php?storytopic=' . $oldtopic, $oldtopictitle);
$xoopsTpl->append(
'topics',
[
'topic_id' => $oldtopic,
'topic_count_articles' => sprintf(_AM_NEWS_TOTAL, $count_articles),
'topic_count_reads' => $count_reads,
'topic_color' => $oldtopiccolor,
'topic_title' => $oldtopictitle,
'topic_link' => $topic_link,
'news' => $articlestpl,
]
);
}
$oldtopic = $article['topicid'];
$oldtopictitle = $article['topic_title'];
$oldtopiccolor = '#' . $myts->displayTarea($article['topic_color']);
$articlestpl = [];
$count_articles = $count_reads = 0;
}
$htmltitle = '';
if ($infotips > 0) {
$htmltitle = ' title="' . News\Utility::makeInfotips($article['hometext']) . '"';
}
++$count_articles;
$count_reads += $article['counter'];
$articlestpl[] = [
'id' => $article['storyid'],
'hometext' => $article['hometext'],
'title' => $article['title'],
'hits' => $article['counter'],
'created' => formatTimestamp($article['created'], $dateformat),
'article_link' => sprintf("<a href='%s'%s>%s</a>", XOOPS_URL . '/modules/news/article.php?storyid=' . $article['storyid'], $htmltitle, $article['title']),
'published' => formatTimestamp($article['published'], $dateformat),
'rating' => $article['rating'],
];
}
}
$topic_link = sprintf("<a href='%s'>%s</a>", XOOPS_URL . '/modules/news/index.php?storytopic=' . $oldtopic, $oldtopictitle);
$xoopsTpl->append(
'topics',
[
'topic_id' => $oldtopic,
'topic_title' => $oldtopictitle,
'topic_link' => $topic_link,
'news' => $articlestpl,
]
);
$xoopsTpl->assign('xoops_pagetitle', _MI_NEWSBYTHISAUTHOR . ' - ' . $authname . ' - ' . htmlspecialchars($xoopsModule->name(), ENT_QUOTES | ENT_HTML5));
$xoopsTpl->assign('advertisement', News\Utility::getModuleOption('advertisement'));
/**
* Create the meta datas
*/
News\Utility::createMetaDatas();
$meta_description = _MI_NEWSBYTHISAUTHOR . ' - ' . $authname . ' - ' . $xoopsModule->name('s');
if (isset($xoTheme) && is_object($xoTheme)) {
$xoTheme->addMeta('meta', 'description', $meta_description);
} else { // Compatibility for old Xoops versions
$xoopsTpl->assign('xoops_meta_description', $meta_description);
}
require XOOPS_ROOT_PATH . '/include/comment_view.php';
require_once XOOPS_ROOT_PATH . '/footer.php';