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

blocks/news_archives.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
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 43 and the first side effect is on line 28.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
//  ------------------------------------------------------------------------ //
3
//                XOOPS - PHP Content Management System                      //
4
//                  Copyright (c) 2000-2016 XOOPS.org                        //
5
//                       <http://xoops.org/>                             //
6
// ------------------------------------------------------------------------- //
7
//  This program is free software; you can redistribute it and/or modify     //
8
//  it under the terms of the GNU General Public License as published by     //
9
//  the Free Software Foundation; either version 2 of the License, or        //
10
//  (at your option) any later version.                                      //
11
//                                                                           //
12
//  You may not change or alter any portion of this comment or credits       //
13
//  of supporting developers from this source code or any supporting         //
14
//  source code which is considered copyrighted (c) material of the          //
15
//  original comment or credit authors.                                      //
16
//                                                                           //
17
//  This program is distributed in the hope that it will be useful,          //
18
//  but WITHOUT ANY WARRANTY; without even the implied warranty of           //
19
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            //
20
//  GNU General Public License for more details.                             //
21
//                                                                           //
22
//  You should have received a copy of the GNU General Public License        //
23
//  along with this program; if not, write to the Free Software              //
24
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA //
25
//  ------------------------------------------------------------------------ //
26
// defined('XOOPS_ROOT_PATH') || exit('XOOPS root path not defined');
27
28
include_once XOOPS_ROOT_PATH . '/modules/news/class/class.newsstory.php';
29
30
/**
31
 * Display archives
32
 *
33
 * @param array $options :
34
 *                       0 = sort order (0=older first, 1=newer first)
35
 *                       1 = Starting date, year
36
 *                       2 = Starting date, month
37
 *                       3 = Ending date, year
38
 *                       4 = Ending date, month
39
 *                       5 = until today ?
40
 *
41
 * @return array
42
 */
43
function b_news_archives_show($options)
44
{
45
    global $xoopsDB, $xoopsConfig;
46
    include_once XOOPS_ROOT_PATH . '/modules/news/class/class.newsstory.php';
47
    include_once XOOPS_ROOT_PATH . '/modules/news/include/functions.php';
48
    include_once XOOPS_ROOT_PATH . '/language/' . $xoopsConfig['language'] . '/calendar.php';
49 View Code Duplication
    if (file_exists(XOOPS_ROOT_PATH . '/modules/news/language/' . $xoopsConfig['language'] . '/main.php')) {
50
        include_once XOOPS_ROOT_PATH . '/modules/news/language/' . $xoopsConfig['language'] . '/main.php';
51
    } else {
52
        include_once XOOPS_ROOT_PATH . '/modules/news/language/english/main.php';
53
    }
54
55
    $months_arr    = array(
56
        1  => _CAL_JANUARY,
57
        2  => _CAL_FEBRUARY,
58
        3  => _CAL_MARCH,
59
        4  => _CAL_APRIL,
60
        5  => _CAL_MAY,
61
        6  => _CAL_JUNE,
62
        7  => _CAL_JULY,
63
        8  => _CAL_AUGUST,
64
        9  => _CAL_SEPTEMBER,
65
        10 => _CAL_OCTOBER,
66
        11 => _CAL_NOVEMBER,
67
        12 => _CAL_DECEMBER);
68
    $block         = array();
69
    $sort_order    = $options[0] == 0 ? 'ASC' : 'DESC';
70
    $starting_date = mktime(0, 0, 0, (int)$options[2], 1, (int)$options[1]);
71
    if ((int)$options[5] != 1) {
72
        $ending_date = mktime(23, 59, 59, (int)$options[4], 28, (int)$options[3]);
73
    } else {
74
        $ending_date = time();
75
    }
76
    $sql    = "SELECT distinct(FROM_UNIXTIME(published,'%Y-%m')) as published FROM " . $xoopsDB->prefix('news_stories') . ' WHERE published>=' . $starting_date . ' AND published<=' . $ending_date . ' ORDER BY published ' . $sort_order;
77
    $result = $xoopsDB->query($sql);
78
    if (!$result) {
79
        return '';
80
    }
81
    while ($myrow = $xoopsDB->fetchArray($result)) {
82
        $year                = (int)substr($myrow['published'], 0, 4);
83
        $month               = (int)substr($myrow['published'], 5, 2);
84
        $formated_month      = $months_arr[$month];
85
        $block['archives'][] = array('month' => $month, 'year' => $year, 'formated_month' => $formated_month);
86
    }
87
88
    return $block;
89
}
90
91
/**
92
 * @param $options
93
 *
94
 * @return string
95
 */
96
function b_news_archives_edit($options)
97
{
98
    global $xoopsDB;
99
    $syear    = $smonth = $eyear = $emonth = $older = $recent = 0;
100
    $selsyear = $selsmonth = $seleyear = $selemonth = 0;
101
    $form     = '';
102
103
    $selsyear  = $options[1];
104
    $selsmonth = $options[2];
105
    $seleyear  = $options[3];
106
    $selemonth = $options[4];
107
108
    $tmpstory = new NewsStory;
109
    $tmpstory->GetOlderRecentNews($older, $recent); // We are searching for the module's older and more recent article's date
110
111
    // Min and max value for the two dates selectors
112
    // We are going to use the older news for the starting date
113
    $syear  = date('Y', $older);
114
    $smonth = date('n', $older);
115
    $eyear  = date('Y', $recent);
116
    $emonth = date('n', $recent);
117
    // Verify parameters
118
    if ($selsyear == 0 && $selsmonth == 0) {
119
        $selsyear  = $syear;
120
        $selsmonth = $smonth;
121
    }
122
    if ($seleyear == 0 && $selemonth == 0) {
123
        $seleyear  = $eyear;
124
        $selemonth = $emonth;
125
    }
126
127
    // Sort order *************************************************************
128
    // (0=older first, 1=newer first)
129
    $form .= '<b>' . _MB_NEWS_ORDER . "</b>&nbsp;<select name='options[]'>";
130
    $form .= "<option value='0'";
131
    if ($options[0] == 0) {
132
        $form .= " selected='selected'";
133
    }
134
    $form .= '>' . _MB_NEWS_OLDER_FIRST . "</option>\n";
135
    $form .= "<option value='1'";
136
    if ($options[0] == 1) {
137
        $form .= " selected='selected'";
138
    }
139
    $form .= '>' . _MB_NEWS_RECENT_FIRST . '</option>';
140
    $form .= "</select>\n";
141
142
    // Starting and ending dates **********************************************
143
    $form .= '<br /><br /><b>' . _MB_NEWS_STARTING_DATE . '</b><br />';
144
    $form .= _MB_NEWS_CAL_YEAR . "&nbsp;<select name='options[]'>";
145 View Code Duplication
    for ($i = $syear; $i <= $eyear; ++$i) {
146
        $selected = ($i == $selsyear) ? "selected='selected'" : '';
147
        $form .= "<option value='" . $i . "'" . $selected . '>' . $i . '</option>';
148
    }
149
    $form .= '</select>&nbsp;' . _MB_NEWS_CAL_MONTH . "&nbsp;<select name='options[]'>";
150 View Code Duplication
    for ($i = 1; $i <= 12; ++$i) {
151
        $selected = ($i == $selsmonth) ? "selected='selected'" : '';
152
        $form .= "<option value='" . $i . "'" . $selected . '>' . $i . '</option>';
153
    }
154
    $form .= '</select>';
155
156
    $form .= '<br /><br /><b>' . _MB_NEWS_ENDING_DATE . '</b><br />';
157
    $form .= _MB_NEWS_CAL_YEAR . "&nbsp;<select name='options[]'>";
158 View Code Duplication
    for ($i = $syear; $i <= $eyear; ++$i) {
159
        $selected = ($i == $seleyear) ? "selected='selected'" : '';
160
        $form .= "<option value='" . $i . "'" . $selected . '>' . $i . '</option>';
161
    }
162
    $form .= '</select>&nbsp;' . _MB_NEWS_CAL_MONTH . "&nbsp;<select name='options[]'>";
163 View Code Duplication
    for ($i = 1; $i <= 12; ++$i) {
164
        $selected = ($i == $selemonth) ? "selected='selected'" : '';
165
        $form .= "<option value='" . $i . "'" . $selected . '>' . $i . '</option>';
166
    }
167
    $form .= '</select>';
168
169
    // Or until today *********************************************************
170
    $form .= '<br />';
171
    $checked = $options[5] == 1 ? " checked='checked'" : '';
172
    $form .= "<input type='checkbox' value='1' name='options[]'" . $checked . '>';
173
    $form .= ' <b>' . _MB_NEWS_UNTIL_TODAY . '</b>';
174
175
    return $form;
176
}
177
178
/**
179
 * @param $options
180
 */
181 View Code Duplication
function b_news_archives_onthefly($options)
182
{
183
    $options = explode('|', $options);
184
    $block   = &b_news_archives_show($options);
185
186
    $tpl = new XoopsTpl();
187
    $tpl->assign('block', $block);
188
    $tpl->display('db:news_block_archives.tpl');
189
}
190