Completed
Pull Request — master (#4)
by Michael
03:05
created

archive.php (1 issue)

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
// $Id: archive.php 9572 2012-05-22 11:13:40Z beckmi $
3
//  ------------------------------------------------------------------------ //
4
//                XOOPS - PHP Content Management System                      //
5
//                    Copyright (c) 2000 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
######################################################################
0 ignored issues
show
Unused Code Comprehensibility introduced by
40% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
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
102
$fromyear  = (isset($_GET['year'])) ? (int)($_GET['year']) : 0;
103
$frommonth = (isset($_GET['month'])) ? (int)($_GET['month']) : 0;
104
105
$pgtitle = '';
106
if ($fromyear && $frommonth) {
107
    $pgtitle = sprintf(" - %d - %d", $fromyear, $frommonth);
108
}
109
$infotips   = news_getmoduleoption('infotips');
110
$restricted = news_getmoduleoption('restrictindex');
111
$dateformat = news_getmoduleoption('dateformat');
112
if ($dateformat == '') {
113
    $dateformat = 'm';
114
}
115
$myts =& MyTextSanitizer::getInstance();
116
$xoopsTpl->assign('xoops_pagetitle', $myts->htmlSpecialChars(_NW_NEWSARCHIVES) . $pgtitle . ' - ' . $xoopsModule->name('s'));
117
118
$useroffset = '';
119
if (is_object($xoopsUser)) {
120
    $timezone = $xoopsUser->timezone();
121
    if (isset($timezone)) {
122
        $useroffset = $xoopsUser->timezone();
123
    } else {
124
        $useroffset = $xoopsConfig['default_TZ'];
125
    }
126
}
127
$result = $xoopsDB->query(
128
    'SELECT published FROM ' . $xoopsDB->prefix('news_stories') . ' WHERE (published>0 AND published<=' . time() . ') AND (expired = 0 OR expired <= ' . time() . ') ORDER BY published DESC'
129
);
130
if (!$result) {
131
    echo _ERRORS;
132
    exit();
133
} else {
134
    $years  = array();
135
    $months = array();
136
    $i      = 0;
137
    while (list($time) = $xoopsDB->fetchRow($result)) {
138
        $time = formatTimestamp($time, 'mysql', $useroffset);
139
        if (preg_match("/([0-9]{4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})/", $time, $datetime)) {
140
            $this_year  = (int)($datetime[1]);
141
            $this_month = (int)($datetime[2]);
142
            if (empty($lastyear)) {
143
                $lastyear = $this_year;
144
            }
145 View Code Duplication
            if ($lastmonth == 0) {
146
                $lastmonth                    = $this_month;
147
                $months[$lastmonth]['string'] = $months_arr[$lastmonth];
148
                $months[$lastmonth]['number'] = $lastmonth;
149
            }
150
            if ($lastyear != $this_year) {
151
                $years[$i]['number'] = $lastyear;
152
                $years[$i]['months'] = $months;
153
                $months              = array();
154
                $lastmonth           = 0;
155
                $lastyear            = $this_year;
156
                ++$i;
157
            }
158 View Code Duplication
            if ($lastmonth != $this_month) {
159
                $lastmonth                    = $this_month;
160
                $months[$lastmonth]['string'] = $months_arr[$lastmonth];
161
                $months[$lastmonth]['number'] = $lastmonth;
162
            }
163
        }
164
    }
165
    $years[$i]['number'] = $this_year;
166
    $years[$i]['months'] = $months;
167
    $xoopsTpl->assign('years', $years);
168
}
169
170
if ($fromyear != 0 && $frommonth != 0) {
171
    $xoopsTpl->assign('show_articles', true);
172
    $xoopsTpl->assign('lang_articles', _NW_ARTICLES);
173
    $xoopsTpl->assign('currentmonth', $months_arr[$frommonth]);
174
    $xoopsTpl->assign('currentyear', $fromyear);
175
    $xoopsTpl->assign('lang_actions', _NW_ACTIONS);
176
    $xoopsTpl->assign('lang_date', _NW_DATE);
177
    $xoopsTpl->assign('lang_views', _NW_VIEWS);
178
179
    // must adjust the selected time to server timestamp
180
    $timeoffset = $useroffset - $xoopsConfig['server_TZ'];
181
    $monthstart = mktime(0 - $timeoffset, 0, 0, $frommonth, 1, $fromyear);
182
    $monthend   = mktime(23 - $timeoffset, 59, 59, $frommonth + 1, 0, $fromyear);
183
    $monthend   = ($monthend > time()) ? time() : $monthend;
184
185
    $count      = 0;
186
    $news       = new NewsStory();
187
    $storyarray = $news->getArchive($monthstart, $monthend, $restricted);
188
    $count      = count($storyarray);
189
    if (is_array($storyarray) && $count > 0) {
190
        foreach ($storyarray as $article) {
191
            $story     = array();
192
            $htmltitle = '';
193
            if ($infotips > 0) {
194
                $story['infotips'] = news_make_infotips($article->hometext());
195
                $htmltitle         = ' title="' . $story['infotips'] . '"';
196
            }
197
            $story['title']      = "<a href='" . XOOPS_URL . '/modules/news/index.php?storytopic=' . $article->topicid() . "'>" . $article->topic_title() . "</a>: <a href='" . XOOPS_URL
198
                . "/modules/news/article.php?storyid=" . $article->storyid() . "'" . $htmltitle . ">" . $article->title() . "</a>";
199
            $story['counter']    = $article->counter();
200
            $story['date']       = formatTimestamp($article->published(), $dateformat, $useroffset);
201
            $story['print_link'] = XOOPS_URL . '/modules/news/print.php?storyid=' . $article->storyid();
202
            $story['mail_link']
203
                                 =
204
                'mailto:?subject=' . sprintf(_NW_INTARTICLE, $xoopsConfig['sitename']) . '&amp;body=' . sprintf(_NW_INTARTFOUND, $xoopsConfig['sitename']) . ':  ' . XOOPS_URL . '/modules/'
205
                . $xoopsModule->dirname() . '/article.php?storyid=' . $article->storyid();
206
            $xoopsTpl->append('stories', $story);
207
        }
208
    }
209
    $xoopsTpl->assign('lang_printer', _NW_PRINTERFRIENDLY);
210
    $xoopsTpl->assign('lang_sendstory', _NW_SENDSTORY);
211
    $xoopsTpl->assign('lang_storytotal', sprintf(_NW_THEREAREINTOTAL, $count));
212
} else {
213
    $xoopsTpl->assign('show_articles', false);
214
}
215
216
$xoopsTpl->assign('lang_newsarchives', _NW_NEWSARCHIVES);
217
218
/**
219
 * Create the meta datas
220
 */
221
news_CreateMetaDatas();
222
223
include_once XOOPS_ROOT_PATH . '/footer.php';
224