Passed
Push — master ( b109af...09294a )
by Michael
12:29 queued 11:57
created

archive.php (1 issue)

Labels
Severity
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
/*
19
 * Display a list of all the published articles by month
20
 *
21
 * This page is called from the module's main menu.
22
 * It will shows a list of all the articles by month. We use the module's
23
 * option named "restrictindex" to show or hide stories according
24
 * to users permissions
25
 *
26
 * @package News
27
 * @author Xoops Modules Dev Team
28
 * @copyright   (c) XOOPS Project (https://xoops.org)
29
 *
30
 * Parameters received by this page :
31
 * @page_param  int     year    Optional, the starting year
32
 * @page_param  int     month   Optional, the starting month
33
 *
34
 * @page_title          "News Archives" - Year - Month - Module's name
35
 *
36
 * @template_name       news_archive.html
37
 *
38
 * Template's variables :
39
 * @template_var    array   years           Contains all the years we have information for
40
 *                                          Structure :
41
 *                                              number  int     Year (2004 for example)
42
 *                                              months  array   moths in the year (months when we have some articles)
43
 *                                                  Structure :
44
 *                                                  string  string  Month's name
45
 *                                                  number  int     Month's number (between 1 and 12)
46
 * @template_var    boolean show_articles   true or false
47
 * @template_var    string  lang_articles   Fixed text "Articles"
48
 * @template_var    array   currentmonth    Label of each month (from january to december)
49
 * @template_var    int     currentyear     Starting year
50
 * @template_var    string  lang_actions    Fixed text "Actions"
51
 * @template_var    string  lang_date       Fixed text "Date"
52
 * @template_var    string  lang_views      Fixed text "Views"
53
 * @template_var    array   stories         Contains all the stories to display
54
 *                                          Structure :
55
 *                                          title       string  Contains a link to see the topic and a link (with the story's title) to read the full story
56
 *                                          counter     int     Number of views for this article
57
 *                                          date        string  Article's publish date
58
 *                                          print_link  string  A link to the story's printable version
59
 *                                          mail_link   string  A mailto link to mail the story to a friend
60
 * @template_var    string  lang_printer    Fixed text "Printer Friendly Page"
61
 * @template_var    string  lang_sendstory  Fixed text "Send this Story to a Friend"
62
 * @template_var    string  lang_storytotal Text "There are xx article(s) in total"
63
 */
64
######################################################################
65
# Original version:
66
# [11-may-2001] Kenneth Lee - https://www.nexgear.com/
67
######################################################################
68
69
use Xmf\Request;
70
use XoopsModules\News;
71
use XoopsModules\News\NewsStory;
72
73
require_once \dirname(__DIR__, 2) . '/mainfile.php';
74
$GLOBALS['xoopsOption']['template_main'] = 'news_archive.tpl';
75
require_once XOOPS_ROOT_PATH . '/header.php';
76
// require_once XOOPS_ROOT_PATH . '/modules/news/class/class.newsstory.php';
77
require_once XOOPS_ROOT_PATH . '/language/' . $xoopsConfig['language'] . '/calendar.php';
78
79
$lastyear  = 0;
80
$lastmonth = 0;
81
82
$months_arr = [
83
    1  => _CAL_JANUARY,
84
    2  => _CAL_FEBRUARY,
85
    3  => _CAL_MARCH,
86
    4  => _CAL_APRIL,
87
    5  => _CAL_MAY,
88
    6  => _CAL_JUNE,
89
    7  => _CAL_JULY,
90
    8  => _CAL_AUGUST,
91
    9  => _CAL_SEPTEMBER,
92
    10 => _CAL_OCTOBER,
93
    11 => _CAL_NOVEMBER,
94
    12 => _CAL_DECEMBER,
95
];
96
97
$fromyear  = Request::getInt('year', 0, 'GET');
98
$frommonth = Request::getInt('month', 0, 'GET');
99
100
$pgtitle = '';
101
if ($fromyear && $frommonth) {
102
    $pgtitle = sprintf(' - %d - %d', $fromyear, $frommonth);
103
}
104
$infotips   = News\Utility::getModuleOption('infotips');
105
$restricted = News\Utility::getModuleOption('restrictindex');
106
$dateformat = News\Utility::getModuleOption('dateformat');
107
if ('' === $dateformat) {
108
    $dateformat = 'm';
109
}
110
$myts = \MyTextSanitizer::getInstance();
111
$xoopsTpl->assign('xoops_pagetitle', htmlspecialchars(_NW_NEWSARCHIVES, ENT_QUOTES | ENT_HTML5) . $pgtitle . ' - ' . $xoopsModule->name('s'));
112
113
$useroffset = '';
114
if (is_object($xoopsUser)) {
115
    $timezone = $xoopsUser->timezone();
116
    if (isset($timezone)) {
117
        $useroffset = $xoopsUser->timezone();
118
    } else {
119
        $useroffset = $xoopsConfig['default_TZ'];
120
    }
121
}
122
$result = $xoopsDB->query('SELECT published FROM ' . $xoopsDB->prefix('news_stories') . ' WHERE (published>0 AND published<=' . time() . ') AND (expired = 0 OR expired <= ' . time() . ') ORDER BY published DESC');
123
if (!$result) {
124
    echo _ERRORS;
125
    exit();
126
}
127
$years  = [];
128
$months = [];
129
$i      = 0;
130
while ([$time] = $xoopsDB->fetchRow($result)) {
131
    $time = formatTimestamp($time, 'mysql', $useroffset);
132
    if (preg_match('/(\d{4})-(\d{1,2})-(\d{1,2}) (\d{1,2}):(\d{1,2}):(\d{1,2})/', $time, $datetime)) {
133
        $this_year  = (int)$datetime[1];
134
        $this_month = (int)$datetime[2];
135
        if (empty($lastyear)) {
136
            $lastyear = $this_year;
137
        }
138
        if (0 == $lastmonth) {
139
            $lastmonth                    = $this_month;
140
            $months[$lastmonth]['string'] = $months_arr[$lastmonth];
141
            $months[$lastmonth]['number'] = $lastmonth;
142
        }
143
        if ($lastyear != $this_year) {
144
            $years[$i]['number'] = $lastyear;
145
            $years[$i]['months'] = $months;
146
            $months              = [];
147
            $lastmonth           = 0;
148
            $lastyear            = $this_year;
149
            ++$i;
150
        }
151
        if ($lastmonth != $this_month) {
152
            $lastmonth                    = $this_month;
153
            $months[$lastmonth]['string'] = $months_arr[$lastmonth];
154
            $months[$lastmonth]['number'] = $lastmonth;
155
        }
156
    }
157
}
158
$years[$i]['number'] = $this_year;
159
$years[$i]['months'] = $months;
160
$xoopsTpl->assign('years', $years);
161
162
if (0 != $fromyear && 0 != $frommonth) {
163
    $xoopsTpl->assign('show_articles', true);
164
    $xoopsTpl->assign('lang_articles', _NW_ARTICLES);
165
    $xoopsTpl->assign('currentmonth', $months_arr[$frommonth]);
166
    $xoopsTpl->assign('currentyear', $fromyear);
167
    $xoopsTpl->assign('lang_actions', _NW_ACTIONS);
168
    $xoopsTpl->assign('lang_date', _NW_DATE);
169
    $xoopsTpl->assign('lang_views', _NW_VIEWS);
170
171
    // must adjust the selected time to server timestamp
172
    $timeoffset = $useroffset - $xoopsConfig['server_TZ'];
173
    $monthstart = mktime(0 - $timeoffset, 0, 0, $frommonth, 1, $fromyear);
174
    $monthend   = mktime(23 - $timeoffset, 59, 59, $frommonth + 1, 0, $fromyear);
175
    $monthend   = ($monthend > time()) ? time() : $monthend;
176
177
    $count      = 0;
178
    $news       = new NewsStory();
179
    $storyarray = $news->getArchive($monthstart, $monthend, $restricted);
180
    $count      = count($storyarray);
0 ignored issues
show
It seems like $storyarray can also be of type null; however, parameter $value of count() does only seem to accept Countable|array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

180
    $count      = count(/** @scrutinizer ignore-type */ $storyarray);
Loading history...
181
    if (is_array($storyarray) && $count > 0) {
182
        foreach ($storyarray as $article) {
183
            $story     = [];
184
            $htmltitle = '';
185
            if ($infotips > 0) {
186
                $story['infotips'] = News\Utility::makeInfotips($article->hometext());
187
                $htmltitle         = ' title="' . $story['infotips'] . '"';
188
            }
189
            $story['title']      = "<a href='"
190
                                   . XOOPS_URL
191
                                   . '/modules/news/index.php?storytopic='
192
                                   . $article->topicid()
193
                                   . "'>"
194
                                   . $article->topic_title()
195
                                   . "</a>: <a href='"
196
                                   . XOOPS_URL
197
                                   . '/modules/news/article.php?storyid='
198
                                   . $article->storyid()
199
                                   . "'"
200
                                   . $htmltitle
201
                                   . '>'
202
                                   . $article->title()
203
                                   . '</a>';
204
            $story['counter']    = $article->counter();
205
            $story['date']       = formatTimestamp($article->published(), $dateformat, $useroffset);
206
            $story['print_link'] = XOOPS_URL . '/modules/news/print.php?storyid=' . $article->storyid();
207
            $story['mail_link']  = 'mailto:?subject=' . sprintf(_NW_INTARTICLE, $xoopsConfig['sitename']) . '&amp;body=' . sprintf(_NW_INTARTFOUND, $xoopsConfig['sitename']) . ':  ' . XOOPS_URL . '/modules/' . $xoopsModule->dirname() . '/article.php?storyid=' . $article->storyid();
208
            $xoopsTpl->append('stories', $story);
209
        }
210
    }
211
    $xoopsTpl->assign('lang_printer', _NW_PRINTERFRIENDLY);
212
    $xoopsTpl->assign('lang_sendstory', _NW_SENDSTORY);
213
    $xoopsTpl->assign('lang_storytotal', sprintf(_NW_THEREAREINTOTAL, $count));
214
} else {
215
    $xoopsTpl->assign('show_articles', false);
216
}
217
218
$xoopsTpl->assign('lang_newsarchives', _NW_NEWSARCHIVES);
219
220
/**
221
 * Create the meta datas
222
 */
223
News\Utility::createMetaDatas();
224
225
require_once XOOPS_ROOT_PATH . '/footer.php';
226