Passed
Push — master ( ae2d71...17f88f )
by Michael
43s queued 14s
created

archive.php (1 issue)

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

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