Completed
Push — master ( 6452b0...d576ea )
by Michael
05:58 queued 03:02
created

archive.php (3 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
// 
3
//  ------------------------------------------------------------------------ //
4
//                XOOPS - PHP Content Management System                      //
5
//                  Copyright (c) 2000-2016 XOOPS.org                        //
6
//                       <http://xoops.org/>                             //
7
// ------------------------------------------------------------------------- //
8
//  This program is free software; you can redistribute it and/or modify     //
9
//  it under the terms of the GNU General Public License as published by     //
10
//  the Free Software Foundation; either version 2 of the License, or        //
11
//  (at your option) any later version.                                      //
12
//                                                                           //
13
//  You may not change or alter any portion of this comment or credits       //
14
//  of supporting developers from this source code or any supporting         //
15
//  source code which is considered copyrighted (c) material of the          //
16
//  original comment or credit authors.                                      //
17
//                                                                           //
18
//  This program is distributed in the hope that it will be useful,          //
19
//  but WITHOUT ANY WARRANTY; without even the implied warranty of           //
20
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            //
21
//  GNU General Public License for more details.                             //
22
//                                                                           //
23
//  You should have received a copy of the GNU General Public License        //
24
//  along with this program; if not, write to the Free Software              //
25
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA //
26
//  ------------------------------------------------------------------------ //
27
/*
28
 * Display a list of all the published articles by month
29
 *
30
 * This page is called from the module's main menu.
31
 * It will shows a list of all the articles by month. We use the module's
32
 * option named "restrictindex" to show or hide stories according
33
 * to users permissions
34
 *
35
 * @package News
36
 * @author Xoops Modules Dev Team
37
 * @copyright   (c) XOOPS Project (http://xoops.org)
38
 *
39
 * Parameters received by this page :
40
 * @page_param  int     year    Optional, the starting year
41
 * @page_param  int     month   Optional, the starting month
42
 *
43
 * @page_title          "News Archives" - Year - Month - Module's name
44
 *
45
 * @template_name       news_archive.html
46
 *
47
 * Template's variables :
48
 * @template_var    array   years           Contains all the years we have information for
49
 *                                          Structure :
50
 *                                              number  int     Year (2004 for example)
51
 *                                              months  array   moths in the year (months when we have some articles)
52
 *                                                  Structure :
53
 *                                                  string  string  Month's name
54
 *                                                  number  int     Month's number (between 1 and 12)
55
 * @template_var    boolean show_articles   true or false
56
 * @template_var    string  lang_articles   Fixed text "Articles"
57
 * @template_var    array   currentmonth    Label of each month (from january to december)
58
 * @template_var    int     currentyear     Starting year
59
 * @template_var    string  lang_actions    Fixed text "Actions"
60
 * @template_var    string  lang_date       Fixed text "Date"
61
 * @template_var    string  lang_views      Fixed text "Views"
62
 * @template_var    array   stories         Contains all the stories to display
63
 *                                          Structure :
64
 *                                          title       string  Contains a link to see the topic and a link (with the story's title) to read the full story
65
 *                                          counter     int     Number of views for this article
66
 *                                          date        string  Article's publish date
67
 *                                          print_link  string  A link to the story's printable version
68
 *                                          mail_link   string  A mailto link to mail the story to a friend
69
 * @template_var    string  lang_printer    Fixed text "Printer Friendly Page"
70
 * @template_var    string  lang_sendstory  Fixed text "Send this Story to a Friend"
71
 * @template_var    string  lang_storytotal Text "There are xx article(s) in total"
72
 */
73
######################################################################
74
# Original version:
75
# [11-may-2001] Kenneth Lee - http://www.nexgear.com/
76
######################################################################
77
78
include dirname(dirname(__DIR__)) . '/mainfile.php';
79
$xoopsOption['template_main'] = 'news_archive.tpl';
80
include_once XOOPS_ROOT_PATH . '/header.php';
81
include_once XOOPS_ROOT_PATH . '/modules/news/class/class.newsstory.php';
82
include_once XOOPS_ROOT_PATH . '/language/' . $xoopsConfig['language'] . '/calendar.php';
83
include_once XOOPS_ROOT_PATH . '/modules/news/include/functions.php';
84
$lastyear  = 0;
85
$lastmonth = 0;
86
87
$months_arr = array(
88
    1  => _CAL_JANUARY,
89
    2  => _CAL_FEBRUARY,
90
    3  => _CAL_MARCH,
91
    4  => _CAL_APRIL,
92
    5  => _CAL_MAY,
93
    6  => _CAL_JUNE,
94
    7  => _CAL_JULY,
95
    8  => _CAL_AUGUST,
96
    9  => _CAL_SEPTEMBER,
97
    10 => _CAL_OCTOBER,
98
    11 => _CAL_NOVEMBER,
99
    12 => _CAL_DECEMBER);
100
101
$fromyear  = isset($_GET['year']) ? (int)$_GET['year'] : 0;
102
$frommonth = isset($_GET['month']) ? (int)$_GET['month'] : 0;
103
104
$pgtitle = '';
105
if ($fromyear && $frommonth) {
106
    $pgtitle = sprintf(' - %d - %d', $fromyear, $frommonth);
107
}
108
$infotips   = news_getmoduleoption('infotips');
109
$restricted = news_getmoduleoption('restrictindex');
110
$dateformat = news_getmoduleoption('dateformat');
111
if ($dateformat == '') {
112
    $dateformat = 'm';
113
}
114
$myts = MyTextSanitizer::getInstance();
115
$xoopsTpl->assign('xoops_pagetitle', $myts->htmlSpecialChars(_NW_NEWSARCHIVES) . $pgtitle . ' - ' . $xoopsModule->name('s'));
116
117
$useroffset = '';
118
if (is_object($xoopsUser)) {
119
    $timezone = $xoopsUser->timezone();
120
    if (isset($timezone)) {
121
        $useroffset = $xoopsUser->timezone();
122
    } else {
123
        $useroffset = $xoopsConfig['default_TZ'];
124
    }
125
}
126
$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');
127
if (!$result) {
128
    echo _ERRORS;
129
    exit();
130
} else {
131
    $years  = array();
132
    $months = array();
133
    $i      = 0;
134
    while (list($time) = $xoopsDB->fetchRow($result)) {
135
        $time = formatTimestamp($time, 'mysql', $useroffset);
136
        if (preg_match('/(\d{4})-(\d{1,2})-(\d{1,2}) (\d{1,2}):(\d{1,2}):(\d{1,2})/', $time, $datetime)) {
137
            $this_year  = (int)$datetime[1];
138
            $this_month = (int)$datetime[2];
139
            if (empty($lastyear)) {
140
                $lastyear = $this_year;
141
            }
142 View Code Duplication
            if ($lastmonth == 0) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
143
                $lastmonth                    = $this_month;
144
                $months[$lastmonth]['string'] = $months_arr[$lastmonth];
145
                $months[$lastmonth]['number'] = $lastmonth;
146
            }
147
            if ($lastyear != $this_year) {
148
                $years[$i]['number'] = $lastyear;
149
                $years[$i]['months'] = $months;
150
                $months              = array();
151
                $lastmonth           = 0;
152
                $lastyear            = $this_year;
153
                ++$i;
154
            }
155 View Code Duplication
            if ($lastmonth != $this_month) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
156
                $lastmonth                    = $this_month;
157
                $months[$lastmonth]['string'] = $months_arr[$lastmonth];
158
                $months[$lastmonth]['number'] = $lastmonth;
159
            }
160
        }
161
    }
162
    $years[$i]['number'] = $this_year;
163
    $years[$i]['months'] = $months;
164
    $xoopsTpl->assign('years', $years);
165
}
166
167
if ($fromyear != 0 && $frommonth != 0) {
168
    $xoopsTpl->assign('show_articles', true);
169
    $xoopsTpl->assign('lang_articles', _NW_ARTICLES);
170
    $xoopsTpl->assign('currentmonth', $months_arr[$frommonth]);
171
    $xoopsTpl->assign('currentyear', $fromyear);
172
    $xoopsTpl->assign('lang_actions', _NW_ACTIONS);
173
    $xoopsTpl->assign('lang_date', _NW_DATE);
174
    $xoopsTpl->assign('lang_views', _NW_VIEWS);
175
176
    // must adjust the selected time to server timestamp
177
    $timeoffset = $useroffset - $xoopsConfig['server_TZ'];
178
    $monthstart = mktime(0 - $timeoffset, 0, 0, $frommonth, 1, $fromyear);
179
    $monthend   = mktime(23 - $timeoffset, 59, 59, $frommonth + 1, 0, $fromyear);
180
    $monthend   = ($monthend > time()) ? time() : $monthend;
181
182
    $count      = 0;
183
    $news       = new NewsStory();
184
    $storyarray = $news->getArchive($monthstart, $monthend, $restricted);
185
    $count      = count($storyarray);
186
    if (is_array($storyarray) && $count > 0) {
187
        foreach ($storyarray as $article) {
188
            $story     = array();
189
            $htmltitle = '';
190
            if ($infotips > 0) {
191
                $story['infotips'] = news_make_infotips($article->hometext());
0 ignored issues
show
Are you sure the assignment to $story['infotips'] is correct as news_make_infotips($article->hometext()) (which targets news_make_infotips()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
192
                $htmltitle         = ' title="' . $story['infotips'] . '"';
193
            }
194
            $story['title']      = "<a href='" . XOOPS_URL . '/modules/news/index.php?storytopic=' . $article->topicid() . "'>" . $article->topic_title() . "</a>: <a href='" . XOOPS_URL . '/modules/news/article.php?storyid=' . $article->storyid() . "'" . $htmltitle . '>' . $article->title() . '</a>';
195
            $story['counter']    = $article->counter();
196
            $story['date']       = formatTimestamp($article->published(), $dateformat, $useroffset);
197
            $story['print_link'] = XOOPS_URL . '/modules/news/print.php?storyid=' . $article->storyid();
198
            $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();
199
            $xoopsTpl->append('stories', $story);
200
        }
201
    }
202
    $xoopsTpl->assign('lang_printer', _NW_PRINTERFRIENDLY);
203
    $xoopsTpl->assign('lang_sendstory', _NW_SENDSTORY);
204
    $xoopsTpl->assign('lang_storytotal', sprintf(_NW_THEREAREINTOTAL, $count));
205
} else {
206
    $xoopsTpl->assign('show_articles', false);
207
}
208
209
$xoopsTpl->assign('lang_newsarchives', _NW_NEWSARCHIVES);
210
211
/**
212
 * Create the meta datas
213
 */
214
news_CreateMetaDatas();
215
216
include_once XOOPS_ROOT_PATH . '/footer.php';
217