-
Notifications
You must be signed in to change notification settings - Fork 1
/
newsbythisauthor.php
218 lines (198 loc) · 9.57 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
209
210
211
212
213
214
215
216
217
218
<?php
/*
* 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 XOOPS Project https://xoops.org/
* @license GNU GPL 2 or later (https://www.gnu.org/licenses/gpl-2.0.html)
* @package
* @since
* @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) The Xoops Project - www.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 nw_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 an hyperlink pointing to userinfo.php (to see his "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 nw_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 XoopsModules\Xnews;
require_once __DIR__ . '/header.php';
require_once XNEWS_MODULE_PATH . '/class/NewsStory.php';
// require_once XNEWS_MODULE_PATH . '/class/NewsTopic.php';
// require_once XNEWS_MODULE_PATH . '/class/Files.php';
global $xoopsUser;
xoops_loadLanguage('modinfo', XNEWS_MODULE_DIRNAME);
$uid = \Xmf\Request::getInt('uid', 0, 'GET');
if (empty($uid)) {
redirect_header('index.php', 3, _ERRORS);
}
if (!$helper->getConfig('newsbythisauthor')) {
redirect_header('index.php', 3, _ERRORS);
}
$myts = \MyTextSanitizer::getInstance();
$articles = new Xnews\NewsStory();
$GLOBALS['xoopsOption']['template_main'] = 'xnews_by_this_author.tpl';
require_once XOOPS_ROOT_PATH . '/header.php';
$dateformat = $helper->getConfig('dateformat');
$infotips = $helper->getConfig('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_XNEWS_NEWSBYTHISAUTHOR . ' - ' . $authname);
$xoopsTpl->assign('lang_nw_by_this_author', _MI_XNEWS_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', _MD_XNEWS_DATE);
$xoopsTpl->assign('lang_hits', _MD_XNEWS_VIEWS);
$xoopsTpl->assign('lang_title', _MD_XNEWS_TITLE);
$xoopsTpl->assign('nw_rating', $helper->getConfig('ratenews'));
$xoopsTpl->assign('lang_rating', _MD_XNEWS_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;
// DNPROSSI SEO
$seo_enabled = $helper->getConfig('seo_enable');
if ($articlescount > 0) {
foreach ($articlelist as $article) {
if ($oldtopic != $article['topicid']) {
if (count($articlestpl) > 0) {
// DNPROSSI SEO
$cat_path = '';
if (0 != $seo_enabled) {
$cat_path = nw_remove_accents($oldtopictitle);
}
$topic_link = "<a href='" . nw_seo_UrlGenerator(_MD_XNEWS_SEO_TOPICS, $oldtopic, $cat_path) . "'>" . $oldtopictitle . '</a>';
$xoopsTpl->append(
'topics',
[
'topic_id' => $oldtopic,
'topic_count_articles' => sprintf(_AM_XNEWS_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="' . nw_make_infotips($article['hometext']) . '"';
}
$count_articles++;
$count_reads += $article['counter'];
// DNPROSSI SEO
$story_path = '';
if (0 != $seo_enabled) {
$story_path = nw_remove_accents($article['title']);
}
$storyTitle = "<a href='" . nw_seo_UrlGenerator(_MD_XNEWS_SEO_ARTICLES, $article['storyid'], $story_path) . "' " . $htmltitle . '>' . $article['title'] . '</a>';
$articlestpl[] = [
'id' => $article['storyid'],
'hometext' => $article['hometext'],
'title' => $article['title'],
'hits' => $article['counter'],
'created' => formatTimestamp($article['created'], $dateformat),
'article_link' => $storyTitle,
'published' => formatTimestamp($article['published'], $dateformat),
'rating' => $article['rating'],
];
}
}
// DNPROSSI SEO
$cat_path = '';
if (0 != $seo_enabled) {
$cat_path = nw_remove_accents($article['topic_title']);
}
$topic_link = "<a href='" . nw_seo_UrlGenerator(_MD_XNEWS_SEO_TOPICS, $oldtopic, $cat_path) . "'>" . $article['topic_title'] . '</a>';
$xoopsTpl->append('topics', ['topic_id' => $oldtopic, 'topic_title' => $oldtopictitle, 'topic_link' => $topic_link, 'news' => $articlestpl]);
$xoopsTpl->assign('xoops_pagetitle', _MI_XNEWS_NEWSBYTHISAUTHOR . ' - ' . $authname . ' - ' . $myts->htmlSpecialChars($xoopsModule->name()));
$xoopsTpl->assign('advertisement', $helper->getConfig('advertisement'));
/**
* Create the meta datas
*/
nw_CreateMetaDatas();
$meta_description = _MI_XNEWS_NEWSBYTHISAUTHOR . ' - ' . $authname . ' - ' . $myts->htmlSpecialChars($xoopsModule->name());
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_once XOOPS_ROOT_PATH . '/include/comment_view.php';
require_once XOOPS_ROOT_PATH . '/footer.php';