Completed
Push — master ( b610c1...53db9c )
by Michael
03:25 queued 01:39
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 35 and the first side effect is on line 20.

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
 * 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 http://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
require_once XOOPS_ROOT_PATH . '/modules/news/class/class.newsstory.php';
21
22
/**
23
 * Display archives
24
 *
25
 * @param array $options :
26
 *                       0 = sort order (0=older first, 1=newer first)
27
 *                       1 = Starting date, year
28
 *                       2 = Starting date, month
29
 *                       3 = Ending date, year
30
 *                       4 = Ending date, month
31
 *                       5 = until today ?
32
 *
33
 * @return array|string
34
 */
35
function b_news_archives_show($options)
36
{
37
    global $xoopsDB, $xoopsConfig;
38
    require_once XOOPS_ROOT_PATH . '/modules/news/class/class.newsstory.php';
39
    require_once XOOPS_ROOT_PATH . '/modules/news/class/utility.php';
40
    require_once XOOPS_ROOT_PATH . '/language/' . $xoopsConfig['language'] . '/calendar.php';
41 View Code Duplication
    if (file_exists(XOOPS_ROOT_PATH . '/modules/news/language/' . $xoopsConfig['language'] . '/main.php')) {
42
        require_once XOOPS_ROOT_PATH . '/modules/news/language/' . $xoopsConfig['language'] . '/main.php';
43
    } else {
44
        require_once XOOPS_ROOT_PATH . '/modules/news/language/english/main.php';
45
    }
46
47
    $months_arr    = [
48
        1  => _CAL_JANUARY,
49
        2  => _CAL_FEBRUARY,
50
        3  => _CAL_MARCH,
51
        4  => _CAL_APRIL,
52
        5  => _CAL_MAY,
53
        6  => _CAL_JUNE,
54
        7  => _CAL_JULY,
55
        8  => _CAL_AUGUST,
56
        9  => _CAL_SEPTEMBER,
57
        10 => _CAL_OCTOBER,
58
        11 => _CAL_NOVEMBER,
59
        12 => _CAL_DECEMBER
60
    ];
61
    $block         = [];
62
    $sort_order    = 0 == $options[0] ? 'ASC' : 'DESC';
63
    $starting_date = mktime(0, 0, 0, (int)$options[2], 1, (int)$options[1]);
64
    if (1 != (int)$options[5]) {
65
        $ending_date = mktime(23, 59, 59, (int)$options[4], 28, (int)$options[3]);
66
    } else {
67
        $ending_date = time();
68
    }
69
    $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;
70
    $result = $xoopsDB->query($sql);
71
    if (!$result) {
72
        return '';
73
    }
74
    while ($myrow = $xoopsDB->fetchArray($result)) {
75
        $year                = (int)substr($myrow['published'], 0, 4);
76
        $month               = (int)substr($myrow['published'], 5, 2);
77
        $formated_month      = $months_arr[$month];
78
        $block['archives'][] = ['month' => $month, 'year' => $year, 'formated_month' => $formated_month];
79
    }
80
81
    return $block;
82
}
83
84
/**
85
 * @param $options
86
 *
87
 * @return string
88
 */
89
function b_news_archives_edit($options)
90
{
91
    global $xoopsDB;
92
    $syear    = $smonth = $eyear = $emonth = $older = $recent = 0;
93
    $selsyear = $selsmonth = $seleyear = $selemonth = 0;
94
    $form     = '';
95
96
    $selsyear  = $options[1];
97
    $selsmonth = $options[2];
98
    $seleyear  = $options[3];
99
    $selemonth = $options[4];
100
101
    $tmpstory = new NewsStory;
102
    $tmpstory->getOlderRecentNews($older, $recent); // We are searching for the module's older and more recent article's date
103
104
    // Min and max value for the two dates selectors
105
    // We are going to use the older news for the starting date
106
    $syear  = date('Y', $older);
107
    $smonth = date('n', $older);
108
    $eyear  = date('Y', $recent);
109
    $emonth = date('n', $recent);
110
    // Verify parameters
111
    if (0 == $selsyear && 0 == $selsmonth) {
112
        $selsyear  = $syear;
113
        $selsmonth = $smonth;
114
    }
115
    if (0 == $seleyear && 0 == $selemonth) {
116
        $seleyear  = $eyear;
117
        $selemonth = $emonth;
118
    }
119
120
    // Sort order *************************************************************
121
    // (0=older first, 1=newer first)
122
    $form .= '<b>' . _MB_NEWS_ORDER . "</b>&nbsp;<select name='options[]'>";
123
    $form .= "<option value='0'";
124
    if (0 == $options[0]) {
125
        $form .= ' selected';
126
    }
127
    $form .= '>' . _MB_NEWS_OLDER_FIRST . "</option>\n";
128
    $form .= "<option value='1'";
129
    if (1 == $options[0]) {
130
        $form .= ' selected';
131
    }
132
    $form .= '>' . _MB_NEWS_RECENT_FIRST . '</option>';
133
    $form .= "</select>\n";
134
135
    // Starting and ending dates **********************************************
136
    $form .= '<br><br><b>' . _MB_NEWS_STARTING_DATE . '</b><br>';
137
    $form .= _MB_NEWS_CAL_YEAR . "&nbsp;<select name='options[]'>";
138 View Code Duplication
    for ($i = $syear; $i <= $eyear; ++$i) {
139
        $selected = ($i == $selsyear) ? 'selected' : '';
140
        $form     .= "<option value='" . $i . "'" . $selected . '>' . $i . '</option>';
141
    }
142
    $form .= '</select>&nbsp;' . _MB_NEWS_CAL_MONTH . "&nbsp;<select name='options[]'>";
143 View Code Duplication
    for ($i = 1; $i <= 12; ++$i) {
144
        $selected = ($i == $selsmonth) ? 'selected' : '';
145
        $form     .= "<option value='" . $i . "'" . $selected . '>' . $i . '</option>';
146
    }
147
    $form .= '</select>';
148
149
    $form .= '<br><br><b>' . _MB_NEWS_ENDING_DATE . '</b><br>';
150
    $form .= _MB_NEWS_CAL_YEAR . "&nbsp;<select name='options[]'>";
151 View Code Duplication
    for ($i = $syear; $i <= $eyear; ++$i) {
152
        $selected = ($i == $seleyear) ? 'selected' : '';
153
        $form     .= "<option value='" . $i . "'" . $selected . '>' . $i . '</option>';
154
    }
155
    $form .= '</select>&nbsp;' . _MB_NEWS_CAL_MONTH . "&nbsp;<select name='options[]'>";
156 View Code Duplication
    for ($i = 1; $i <= 12; ++$i) {
157
        $selected = ($i == $selemonth) ? 'selected' : '';
158
        $form     .= "<option value='" . $i . "'" . $selected . '>' . $i . '</option>';
159
    }
160
    $form .= '</select>';
161
162
    // Or until today *********************************************************
163
    $form    .= '<br>';
164
    $checked = 1 == $options[5] ? ' checked' : '';
165
    $form    .= "<input type='checkbox' value='1' name='options[]'" . $checked . '>';
166
    $form    .= ' <b>' . _MB_NEWS_UNTIL_TODAY . '</b>';
167
168
    return $form;
169
}
170
171
/**
172
 * @param $options
173
 */
174 View Code Duplication
function b_news_archives_onthefly($options)
175
{
176
    $options = explode('|', $options);
177
    $block   = &b_news_archives_show($options);
178
179
    $tpl = new XoopsTpl();
180
    $tpl->assign('block', $block);
181
    $tpl->display('db:news_block_archives.tpl');
182
}
183