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

admin/index.php (11 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
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 62 and the first side effect is on line 27.

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
// ------------------------------------------------------------------------ //
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
include_once dirname(dirname(dirname(__DIR__))) . '/include/cp_header.php';
28
include_once __DIR__ . '/admin_header.php';
29
include_once XOOPS_ROOT_PATH . '/modules/news/class/xoopstopic.php';
30
include_once XOOPS_ROOT_PATH . '/class/xoopslists.php';
31
include_once XOOPS_ROOT_PATH . '/modules/news/config.php';
32
include_once XOOPS_ROOT_PATH . '/modules/news/class/class.newsstory.php';
33
include_once XOOPS_ROOT_PATH . '/modules/news/class/class.newstopic.php';
34
include_once XOOPS_ROOT_PATH . '/modules/news/class/class.sfiles.php';
35
include_once XOOPS_ROOT_PATH . '/modules/news/class/blacklist.php';
36
include_once XOOPS_ROOT_PATH . '/modules/news/class/registryfile.php';
37
include_once XOOPS_ROOT_PATH . '/class/uploader.php';
38
include_once XOOPS_ROOT_PATH . '/class/pagenav.php';
39
include_once XOOPS_ROOT_PATH . '/modules/news/admin/functions.php';
40
include_once XOOPS_ROOT_PATH . '/modules/news/include/functions.php';
41
include_once XOOPS_ROOT_PATH . '/modules/news/class/tree.php';
42
$dateformat  = news_getmoduleoption('dateformat');
43
$myts        = MyTextSanitizer::getInstance();
44
$topicscount = 0;
45
46
$storiesTableName = $xoopsDB->prefix('news_stories');
47
if (!news_FieldExists('picture', $storiesTableName)) {
48
    news_AddField('`picture` VARCHAR( 50 ) NOT NULL', $storiesTableName);
49
}
50
51
/**
52
 * Show new submissions
53
 *
54
 * This list can be view in the module's admin when you click on the tab named "Post/Edit News"
55
 * Submissions are news that was submit by users but who are not approved, so you need to edit
56
 * them to approve them.
57
 * Actually you can see the the story's title, the topic, the posted date, the author and a
58
 * link to delete the story. If you click on the story's title, you will be able to edit the news.
59
 * The table contains the last x new submissions.
60
 * The system's block called "Waiting Contents" is listing the number of those news.
61
 */
62
function newSubmissions()
63
{
64
    global $dateformat, $pathIcon16;
65
    $start       = isset($_GET['startnew']) ? (int)$_GET['startnew'] : 0;
66
    $newsubcount = NewsStory:: getAllStoriesCount(3, false);
67
    $storyarray  = NewsStory:: getAllSubmitted(news_getmoduleoption('storycountadmin'), true, news_getmoduleoption('restrictindex'), $start);
68
    if (count($storyarray) > 0) {
69
        $pagenav = new XoopsPageNav($newsubcount, news_getmoduleoption('storycountadmin'), $start, 'startnew', 'op=newarticle');
70
        news_collapsableBar('newsub', 'topnewsubicon');
71
        echo "<img onclick=\"toggle('toptable'); toggleIcon('toptableicon');\" id='topnewsubicon' name='topnewsubicon' src='" . $pathIcon16 . "/close12.gif' alt='' /></a>&nbsp;" . _AM_NEWSUB . '</h4>';
72
        echo "<div id='newsub'>";
73
        echo '<br />';
74
        echo "<div style='text-align: center;'><table width='100%' cellspacing='1' cellpadding='3' border='0' class='outer'><tr class='bg3'><th align='center'>" . _AM_TITLE . "</th><th align='center'>" . _AM_TOPIC . "</th><th align='center'>" . _AM_POSTED . "</th><th align='center'>" . _AM_POSTER . "</th><th align='center'>" . _AM_NEWS_ACTION . "</th></tr>\n";
75
        $class = '';
76
        foreach ($storyarray as $newstory) {
77
            $class = ($class === 'even') ? 'odd' : 'even';
78
            echo "<tr class='" . $class . "'><td align='left'>\n";
79
            $title = $newstory->title();
80
            if (!isset($title) || ($title == '')) {
81
                echo "<a href='" . XOOPS_URL . '/modules/news/admin/index.php?op=edit&amp;returnside=1&amp;storyid=' . $newstory->storyid() . "'>" . _MD_NEWS_NOSUBJECT . "</a>\n";
82
            } else {
83
                echo "&nbsp;<a href='" . XOOPS_URL . '/modules/news/submit.php?returnside=1&amp;op=edit&amp;storyid=' . $newstory->storyid() . "'>" . $title . "</a>\n";
84
            }
85
            echo '</td><td>' . $newstory->topic_title() . "</td><td align='center' class='nw'>" . formatTimestamp($newstory->created(), $dateformat) . "</td><td align='center'><a href='" . XOOPS_URL . '/userinfo.php?uid=' . $newstory->uid() . "'>" . $newstory->uname() . "</a></td><td align='center'><a href='" . XOOPS_URL . '/modules/news/submit.php?returnside=1&amp;op=edit&amp;storyid=' . $newstory->storyid() . "'><img src='" . $pathIcon16 . "/edit.png' title='" . _AM_EDIT . "'></a><a href='" . XOOPS_URL . '/modules/news/admin/index.php?op=delete&amp;storyid=' . $newstory->storyid() . "'><img src='" . $pathIcon16 . "/delete.png' title='" . _AM_DELETE . "'></a></td></tr>\n";
86
        }
87
88
        echo '</table></div>';
89
        echo "<div align='right'>" . $pagenav->renderNav() . '</div><br />';
90
        echo '<br /></div><br />';
91
    }
92
}
93
94
/**
95
 * Shows all automated stories
96
 *
97
 * Automated stories are stories that have a publication's date greater than "now"
98
 * This list can be view in the module's admin when you click on the tab named "Post/Edit News"
99
 * Actually you can see the story's ID, its title, the topic, the author, the
100
 * programmed date and time, the expiration's date  and two links. The first link is
101
 * used to edit the story while the second is used to remove the story.
102
 * The list only contains the last (x) automated news
103
 */
104
function autoStories()
105
{
106
    global $dateformat, $pathIcon16;
107
108
    $start        = isset($_GET['startauto']) ? (int)$_GET['startauto'] : 0;
109
    $storiescount = NewsStory:: getAllStoriesCount(2, false);
110
    $storyarray   = NewsStory:: getAllAutoStory(news_getmoduleoption('storycountadmin'), true, $start);
111
    $class        = '';
112
    if (count($storyarray) > 0) {
113
        $pagenav = new XoopsPageNav($storiescount, news_getmoduleoption('storycountadmin'), $start, 'startauto', 'op=newarticle');
114
        news_collapsableBar('autostories', 'topautostories');
115
        echo "<img onclick=\"toggle('toptable'); toggleIcon('toptableicon');\" id='topautostories' name='topautostories' src='" . $pathIcon16 . "/close12.gif' alt='' /></a>&nbsp;" . _AM_AUTOARTICLES . '</h4>';
116
        echo "<div id='autostories'>";
117
        echo '<br />';
118
        echo "<div style='text-align: center;'>\n";
119
        echo "<table width='100%' cellspacing='1' cellpadding='3' border='0' class='outer'><tr class='bg3'><th align='center'>" . _AM_STORYID . "</th><th align='center'>" . _AM_TITLE . "</th><th align='center'>" . _AM_TOPIC . "</th><th align='center'>" . _AM_POSTER . "</th><th align='center' class='nw'>" . _AM_PROGRAMMED . "</th><th align='center' class='nw'>" . _AM_EXPIRED . "</th><th align='center'>" . _AM_NEWS_ACTION . '</th></tr>';
120 View Code Duplication
        foreach ($storyarray as $autostory) {
121
            $topic  = $autostory->topic();
122
            $expire = ($autostory->expired() > 0) ? formatTimestamp($autostory->expired(), $dateformat) : '';
123
            $class  = ($class === 'even') ? 'odd' : 'even';
124
            echo "<tr class='" . $class . "'>";
125
            echo "<td align='center'><b>" . $autostory->storyid() . "</b>
126
                </td><td align='left'><a href='" . XOOPS_URL . '/modules/news/article.php?storyid=' . $autostory->storyid() . "'>" . $autostory->title() . "</a>
127
                </td><td align='center'>" . $topic->topic_title() . "
128
                </td><td align='center'><a href='" . XOOPS_URL . '/userinfo.php?uid=' . $autostory->uid() . "'>" . $autostory->uname() . "</a></td><td align='center' class='nw'>" . formatTimestamp($autostory->published(), $dateformat) . "</td><td align='center'>" . $expire . "</td><td align='center'><a href='" . XOOPS_URL . '/modules/news/submit.php?returnside=1&amp;op=edit&amp;storyid=' . $autostory->storyid() . "'><img src='" . $pathIcon16 . "/edit.png' title=" . _AM_EDIT . "> </a> <a href='" . XOOPS_URL . '/modules/news/admin/index.php?op=delete&amp;storyid=' . $autostory->storyid() . "'><img src='" . $pathIcon16 . "/delete.png' title='" . _AM_DELETE . "'></a>";
129
130
            echo "</td></tr>\n";
131
        }
132
        echo '</table></div>';
133
        echo "<div align='right'>" . $pagenav->renderNav() . '</div><br />';
134
        echo '</div><br />';
135
    }
136
}
137
138
/**
139
 * Shows last x published stories
140
 *
141
 * This list can be view in the module's admin when you click on the tab named "Post/Edit News"
142
 * Actually you can see the the story's ID, its title, the topic, the author, the number of hits
143
 * and two links. The first link is used to edit the story while the second is used to remove the story.
144
 * The table only contains the last X published stories.
145
 * You can modify the number of visible stories with the module's option named
146
 * "Number of new articles to display in admin area".
147
 * As the number of displayed stories is limited, below this list you can find a text box
148
 * that you can use to enter a story's Id, then with the scrolling list you can select
149
 * if you want to edit or delete the story.
150
 */
151
function lastStories()
152
{
153
    global $dateformat, $pathIcon16;
154
    news_collapsableBar('laststories', 'toplaststories');
155
    echo "<img onclick=\"toggle('toptable'); toggleIcon('toptableicon');\" id='toplaststories' name='toplaststories' src='" . $pathIcon16 . "/close12.gif' alt='' /></a>&nbsp;" . sprintf(_AM_LAST10ARTS, news_getmoduleoption('storycountadmin')) . '</h4>';
156
    echo "<div id='laststories'>";
157
    echo '<br />';
158
    echo "<div style='text-align: center;'>";
159
    $start        = isset($_GET['start']) ? (int)$_GET['start'] : 0;
160
    $storyarray   = NewsStory:: getAllPublished(news_getmoduleoption('storycountadmin'), $start, false, 0, 1);
161
    $storiescount = NewsStory:: getAllStoriesCount(4, false);
162
    $pagenav      = new XoopsPageNav($storiescount, news_getmoduleoption('storycountadmin'), $start, 'start', 'op=newarticle');
163
    $class        = '';
164
    echo "<table width='100%' cellspacing='1' cellpadding='3' border='0' class='outer'><tr class='bg3'><th align='center'>" . _AM_STORYID . "</th><th align='center'>" . _AM_TITLE . "</th><th align='center'>" . _AM_TOPIC . "</th><th align='center'>" . _AM_POSTER . "</th><th align='center' class='nw'>" . _AM_PUBLISHED . "</th><th align='center' class='nw'>" . _AM_HITS . "</th><th align='center'>" . _AM_NEWS_ACTION . '</th></tr>';
165
    foreach ($storyarray as $eachstory) {
166
        $published = formatTimestamp($eachstory->published(), $dateformat);
167
        // $expired = ( $eachstory -> expired() > 0 ) ? formatTimestamp($eachstory->expired(),$dateformat) : '---';
0 ignored issues
show
Unused Code Comprehensibility introduced by
53% 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...
168
        $topic = $eachstory->topic();
169
        $class = ($class === 'even') ? 'odd' : 'even';
170
        echo "<tr class='" . $class . "'>";
171
        echo "<td align='center'><b>" . $eachstory->storyid() . "</b>
172
            </td><td align='left'><a href='" . XOOPS_URL . '/modules/news/article.php?storyid=' . $eachstory->storyid() . "'>" . $eachstory->title() . "</a>
173
            </td><td align='center'>" . $topic->topic_title() . "
174
            </td><td align='center'><a href='" . XOOPS_URL . '/userinfo.php?uid=' . $eachstory->uid() . "'>" . $eachstory->uname() . "</a></td><td align='center' class='nw'>" . $published . "</td><td align='center'>" . $eachstory->counter() . "</td><td align='center'>
175
            <a href='" . XOOPS_URL . '/modules/news/submit.php?returnside=1&amp;op=edit&amp;storyid=' . $eachstory->storyid() . "'> <img src='" . $pathIcon16 . "/edit.png' title=" . _AM_EDIT . "> </a>
176
            <a href='" . XOOPS_URL . '/modules/news/admin/index.php?op=delete&amp;storyid=' . $eachstory->storyid() . "'><img src='" . $pathIcon16 . "/delete.png' title='" . _AM_DELETE . "'></a>";
177
178
        echo "</td></tr>\n";
179
    }
180
    echo '</table><br />';
181
    echo "<div align='right'>" . $pagenav->renderNav() . '</div><br />';
182
183
    echo "<form action='index.php' method='get'>" . _AM_STORYID . " <input type='text' name='storyid' size='10' />
184
        <select name='op'>
185
            <option value='edit' selected='selected'>" . _AM_EDIT . "</option>
186
            <option value='delete'>" . _AM_DELETE . "</option>
187
        </select>
188
        <input type='hidden' name='returnside' value='1'>
189
        <input type='submit' value='" . _AM_GO . "' />
190
        </form>
191
    </div>";
192
    echo '</div><br />';
193
}
194
195
/**
196
 * Display a list of the expired stories
197
 *
198
 * This list can be view in the module's admin when you click on the tab named "Post/Edit News"
199
 * Actually you can see the story's ID, the title, the topic, the author,
200
 * the creation and expiration's date and you have two links, one to delete
201
 * the story and the other to edit the story.
202
 * The table only contains the last X expired stories.
203
 * You can modify the number of visible stories with the module's option named
204
 * "Number of new articles to display in admin area".
205
 * As the number of displayed stories is limited, below this list you can find a text box
206
 * that you can use to enter a story's Id, then with the scrolling list you can select
207
 * if you want to edit or delete the story.
208
 */
209
function expStories()
210
{
211
    global $dateformat, $pathIcon16;
212
    $start        = isset($_GET['startexp']) ? (int)$_GET['startexp'] : 0;
213
    $expiredcount = NewsStory:: getAllStoriesCount(1, false);
214
    $storyarray   = NewsStory:: getAllExpired(news_getmoduleoption('storycountadmin'), $start, 0, 1);
215
    $pagenav      = new XoopsPageNav($expiredcount, news_getmoduleoption('storycountadmin'), $start, 'startexp', 'op=newarticle');
216
217
    if (count($storyarray) > 0) {
218
        $class = '';
219
        news_collapsableBar('expstories', 'topexpstories');
220
        echo "<img onclick=\"toggle('toptable'); toggleIcon('toptableicon');\" id='topexpstories' name='topexpstories' src='" . $pathIcon16 . "/close12.gif' alt='' /></a>&nbsp;" . _AM_EXPARTS . '</h4>';
221
        echo "<div id='expstories'>";
222
        echo '<br />';
223
        echo "<div style='text-align: center;'>";
224
        echo "<table width='100%' cellspacing='1' cellpadding='3' border='0' class='outer'><tr class='bg3'><th align='center'>" . _AM_STORYID . "</th><th align='center'>" . _AM_TITLE . "</th><th align='center'>" . _AM_TOPIC . "</th><th align='center'>" . _AM_POSTER . "</th><th align='center' class='nw'>" . _AM_CREATED . "</th><th align='center' class='nw'>" . _AM_EXPIRED . "</th><th align='center'>" . _AM_NEWS_ACTION . '</th></tr>';
225 View Code Duplication
        foreach ($storyarray as $eachstory) {
226
            $created = formatTimestamp($eachstory->created(), $dateformat);
227
            $expired = formatTimestamp($eachstory->expired(), $dateformat);
228
            $topic   = $eachstory->topic();
229
            // added exired value field to table
230
            $class = ($class === 'even') ? 'odd' : 'even';
231
            echo "<tr class='" . $class . "'>";
232
            echo "<td align='center'><b>" . $eachstory->storyid() . "</b>
233
                </td><td align='left'><a href='" . XOOPS_URL . '/modules/news/article.php?returnside=1&amp;storyid=' . $eachstory->storyid() . "'>" . $eachstory->title() . "</a>
234
                </td><td align='center'>" . $topic->topic_title() . "
235
                </td><td align='center'><a href='" . XOOPS_URL . '/userinfo.php?uid=' . $eachstory->uid() . "'>" . $eachstory->uname() . "</a></td><td align='center' class='nw'>" . $created . "</td><td align='center' class='nw'>" . $expired . "</td><td align='center'>
236
                <a href='" . XOOPS_URL . '/modules/news/submit.php?returnside=1&amp;op=edit&amp;storyid=' . $eachstory->storyid() . "'> <img src='" . $pathIcon16 . "/edit.png' title=" . _AM_EDIT . "></a>
237
                <a href='" . XOOPS_URL . '/modules/news/admin/index.php?op=delete&amp;storyid=' . $eachstory->storyid() . "'><img src='" . $pathIcon16 . "/delete.png' title='" . _AM_DELETE . "'></a>";
238
239
            echo "</td></tr>\n";
240
        }
241
        echo '</table><br />';
242
        echo "<div align='right'>" . $pagenav->renderNav() . '</div><br />';
243
        echo "<form action='index.php' method='get'>
244
            " . _AM_STORYID . " <input type='text' name='storyid' size='10' />
245
            <select name='op'>
246
                <option value='edit' selected='selected'>" . _AM_EDIT . "</option>
247
                <option value='delete'>" . _AM_DELETE . "</option>
248
            </select>
249
            <input type='hidden' name='returnside' value='1'>
250
            <input type='submit' value='" . _AM_GO . "' />
251
            </form>
252
        </div>";
253
        echo '</div><br />';
254
    }
255
}
256
257
/**
258
 * Delete (purge/prune) old stories
259
 *
260
 * You can use this function in the module's admin when you click on the tab named "Prune News"
261
 * It's useful to remove old stories. It is, of course, recommended
262
 * to backup (or export) your news before to purge news.
263
 * You must first specify a date. This date will be used as a reference, everything
264
 * that was published before this date will be deleted.
265
 * The option "Only remove stories who have expired" will enable you to only remove
266
 * expired stories published before the given date.
267
 * Finally, you can select the topics inside wich you will remove news.
268
 * Once you have set all the parameters, the script will first show you a confirmation's
269
 * message with the number of news that will be removed.
270
 * Note, the topics are not deleted (even if there are no more news inside them).
271
 */
272
function PruneManager()
273
{
274
    include_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
275
    xoops_cp_header();
276
    $pruneAdmin = new ModuleAdmin();
277
    echo $pruneAdmin->addNavigation('index.php?op=prune');
278
    echo '<br /><br /><br />';
279
    $sform = new XoopsThemeForm(_AM_NEWS_PRUNENEWS, 'pruneform', XOOPS_URL . '/modules/news/admin/index.php', 'post');
280
    $sform->addElement(new XoopsFormTextDateSelect(_AM_NEWS_PRUNE_BEFORE, 'prune_date', 15, time()), true);
281
    $onlyexpired = new xoopsFormCheckBox('', 'onlyexpired');
282
    $onlyexpired->addOption(1, _AM_NEWS_PRUNE_EXPIREDONLY);
283
    $sform->addElement($onlyexpired, false);
284
    $sform->addElement(new XoopsFormHidden('op', 'confirmbeforetoprune'), false);
285
    $topiclist  = new XoopsFormSelect(_AM_NEWS_PRUNE_TOPICS, 'pruned_topics', '', 5, true);
286
    $topics_arr = array();
287
    $xt         = new NewsTopic();
288
    $allTopics  = $xt->getAllTopics(false); // The webmaster can see everything
289
    $topic_tree = new MyXoopsObjectTree($allTopics, 'topic_id', 'topic_pid');
290
    $topics_arr = $topic_tree->getAllChild(0);
291
    if (count($topics_arr)) {
292
        foreach ($topics_arr as $onetopic) {
293
            $topiclist->addOption($onetopic->topic_id(), $onetopic->topic_title());
294
        }
295
    }
296
    $topiclist->setDescription(_AM_NEWS_EXPORT_PRUNE_DSC);
297
    $sform->addElement($topiclist, false);
298
    $button_tray = new XoopsFormElementTray('', '');
299
    $submit_btn  = new XoopsFormButton('', 'post', _SUBMIT, 'submit');
300
    $button_tray->addElement($submit_btn);
301
    $sform->addElement($button_tray);
302
    $sform->display();
303
}
304
305
// A confirmation is asked before to prune stories
306
function ConfirmBeforeToPrune()
307
{
308
    global $dateformat;
309
    $story = new NewsStory();
310
    xoops_cp_header();
311
    $topiclist = '';
312
    if (isset($_POST['pruned_topics'])) {
313
        $topiclist = implode(',', $_POST['pruned_topics']);
314
    }
315
    echo '<h4>' . _AM_NEWS_PRUNENEWS . '</h4>';
316
    $expired = 0;
317
    if (isset($_POST['onlyexpired'])) {
318
        $expired = (int)$_POST['onlyexpired'];
319
    }
320
    $date      = $_POST['prune_date'];
321
    $timestamp = mktime(0, 0, 0, (int)substr($date, 5, 2), (int)substr($date, 8, 2), (int)substr($date, 0, 4));
322
    $count     = $story->GetCountStoriesPublishedBefore($timestamp, $expired, $topiclist);
323
    if ($count) {
324
        $displaydate = formatTimestamp($timestamp, $dateformat);
325
        $msg         = sprintf(_AM_NEWS_PRUNE_CONFIRM, $displaydate, $count);
326
        xoops_confirm(array('op' => 'prunenews', 'expired' => $expired, 'pruned_topics' => $topiclist, 'prune_date' => $timestamp, 'ok' => 1), 'index.php', $msg);
327
    } else {
328
        printf(_AM_NEWS_NOTHING_PRUNE);
329
    }
330
    unset($story);
331
}
332
333
// Effectively delete stories (published before a date), no more confirmation
334
function PruneNews()
335
{
336
    $story     = new NewsStory();
337
    $timestamp = (int)$_POST['prune_date'];
338
    $expired   = (int)$_POST['expired'];
339
    $topiclist = '';
340
    if (isset($_POST['pruned_topics'])) {
341
        $topiclist = $_POST['pruned_topics'];
342
    }
343
344
    if ((int)$_POST['ok'] == 1) {
345
        $story = new NewsStory();
346
        xoops_cp_header();
347
        $count = $story->GetCountStoriesPublishedBefore($timestamp, $expired, $topiclist);
348
        $msg   = sprintf(_AM_NEWS_PRUNE_DELETED, $count);
349
        $story->DeleteBeforeDate($timestamp, $expired, $topiclist);
350
        unset($story);
351
        news_updateCache();
352
        redirect_header('index.php', 3, $msg);
353
    }
354
}
355
356
/**
357
 * Newsletter's configuration
358
 *
359
 * You can create a newsletter's content from the admin part of the News module when you click on the tab named "Newsletter"
360
 * First, let be clear, this module'functionality will not send the newsletter but it will prepare its content for you.
361
 * To send the newsletter, you can use many specialized modules like evennews.
362
 * You first select a range of dates and if you want, a selection of topics to use for the search.
363
 * Once it's done, the script will use the file named /xoops/modules/language/yourlanguage/newsletter.php to create
364
 * the newsletter's content. When it's finished, the script generates a file in the upload folder.
365
 */
366
function Newsletter()
367
{
368
    include_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
369
    xoops_cp_header();
370
    $newsletterAdmin = new ModuleAdmin();
371
    echo $newsletterAdmin->addNavigation('index.php?op=configurenewsletter');
372
    echo '<br /><br /><br />';
373
    $sform      = new XoopsThemeForm(_AM_NEWS_NEWSLETTER, 'newsletterform', XOOPS_URL . '/modules/news/admin/index.php', 'post');
374
    $dates_tray = new XoopsFormElementTray(_AM_NEWS_NEWSLETTER_BETWEEN);
375
    $date1      = new XoopsFormTextDateSelect('', 'date1', 15, time());
376
    $date2      = new XoopsFormTextDateSelect(_AM_NEWS_EXPORT_AND, 'date2', 15, time());
377
    $dates_tray->addElement($date1);
378
    $dates_tray->addElement($date2);
379
    $sform->addElement($dates_tray);
380
381
    $topiclist  = new XoopsFormSelect(_AM_NEWS_PRUNE_TOPICS, 'export_topics', '', 5, true);
382
    $topics_arr = array();
383
    $xt         = new NewsTopic();
384
    $allTopics  = $xt->getAllTopics(false); // The webmaster can see everything
385
    $topic_tree = new MyXoopsObjectTree($allTopics, 'topic_id', 'topic_pid');
386
    $topics_arr = $topic_tree->getAllChild(0);
387
    if (count($topics_arr)) {
388
        foreach ($topics_arr as $onetopic) {
389
            $topiclist->addOption($onetopic->topic_id(), $onetopic->topic_title());
390
        }
391
    }
392
    $topiclist->setDescription(_AM_NEWS_EXPORT_PRUNE_DSC);
393
    $sform->addElement($topiclist, false);
394
    $sform->addElement(new XoopsFormHidden('op', 'launchnewsletter'), false);
395
    $sform->addElement(new XoopsFormRadioYN(_AM_NEWS_REMOVE_BR, 'removebr', 1), false);
396
    $sform->addElement(new XoopsFormRadioYN(_AM_NEWS_NEWSLETTER_HTML_TAGS, 'removehtml', 0), false);
397
    $sform->addElement(new XoopsFormTextArea(_AM_NEWS_NEWSLETTER_HEADER, 'header', '', 4, 70), false);
398
    $sform->addElement(new XoopsFormTextArea(_AM_NEWS_NEWSLETTER_FOOTER, 'footer', '', 4, 70), false);
399
    $button_tray = new XoopsFormElementTray('', '');
400
    $submit_btn  = new XoopsFormButton('', 'post', _SUBMIT, 'submit');
401
    $button_tray->addElement($submit_btn);
402
    $sform->addElement($button_tray);
403
    $sform->display();
404
}
405
406
/**
407
 * Launch the creation of the newsletter's content
408
 */
409
function LaunchNewsletter()
410
{
411
    global $xoopsConfig, $dateformat;
412
    xoops_cp_header();
413
    $newsletterAdmin = new ModuleAdmin();
414
    echo $newsletterAdmin->addNavigation('index.php?op=configurenewsletter');
415
    $newslettertemplate = '';
416 View Code Duplication
    if (file_exists(XOOPS_ROOT_PATH . '/modules/news/language/' . $xoopsConfig['language'] . '/newsletter.php')) {
417
        include_once XOOPS_ROOT_PATH . '/modules/news/language/' . $xoopsConfig['language'] . '/newsletter.php';
418
    } else {
419
        include_once XOOPS_ROOT_PATH . '/modules/news/language/english/newsletter.php';
420
    }
421
    echo '<br />';
422
    $story           = new NewsStory();
423
    $exportedstories = array();
424
    $topiclist       = '';
425
    $removebr        = $removehtml = false;
426
    $removebr        = isset($_POST['removebr']) ? (int)$_POST['removebr'] : 0;
427
    $removehtml      = isset($_POST['removehtml']) ? (int)$_POST['removehtml'] : 0;
428
    $header          = isset($_POST['header']) ? $_POST['header'] : '';
429
    $footer          = isset($_POST['footer']) ? $_POST['footer'] : '';
430
    $date1           = $_POST['date1'];
431
    $date2           = $_POST['date2'];
432
    $timestamp1      = mktime(0, 0, 0, (int)substr($date1, 5, 2), (int)substr($date1, 8, 2), (int)substr($date1, 0, 4));
433
    $timestamp2      = mktime(23, 59, 59, (int)substr($date2, 5, 2), (int)substr($date2, 8, 2), (int)substr($date2, 0, 4));
434
    if (isset($_POST['export_topics'])) {
435
        $topiclist = implode(',', $_POST['export_topics']);
436
    }
437
    $tbltopics       = array();
438
    $exportedstories = $story->NewsExport($timestamp1, $timestamp2, $topiclist, 0, $tbltopics);
439
    $newsfile        = XOOPS_ROOT_PATH . '/uploads/news/letter.txt';
440
    if (count($exportedstories)) {
441
        $fp = fopen($newsfile, 'w');
442
        if (!$fp) {
443
            redirect_header('index.php', 4, sprintf(_AM_NEWS_EXPORT_ERROR, $newsfile));
444
        }
445
        if (xoops_trim($header) != '') {
446
            fwrite($fp, $header);
447
        }
448
        foreach ($exportedstories as $onestory) {
449
            $content         = $newslettertemplate;
450
            $search_pattern  = array(
451
                '%title%',
452
                '%uname%',
453
                '%created%',
454
                '%published%',
455
                '%expired%',
456
                '%hometext%',
457
                '%bodytext%',
458
                '%description%',
459
                '%keywords%',
460
                '%reads%',
461
                '%topicid%',
462
                '%topic_title%',
463
                '%comments%',
464
                '%rating%',
465
                '%votes%',
466
                '%publisher%',
467
                '%publisher_id%',
468
                '%link%');
469
            $replace_pattern = array(
470
                $onestory->title(),
471
                $onestory->uname(),
472
                formatTimestamp($onestory->created(), $dateformat),
473
                formatTimestamp($onestory->published(), $dateformat),
474
                formatTimestamp($onestory->expired(), $dateformat),
475
                $onestory->hometext(),
476
                $onestory->bodytext(),
477
                $onestory->description(),
478
                $onestory->keywords(),
479
                $onestory->counter(),
480
                $onestory->topicid(),
481
                $onestory->topic_title(),
482
                $onestory->comments(),
483
                $onestory->rating(),
484
                $onestory->votes(),
485
                $onestory->uname(),
486
                $onestory->uid(),
487
                XOOPS_URL . '/modules/news/article.php?storyid=' . $onestory->storyid());
488
            $content         = str_replace($search_pattern, $replace_pattern, $content);
489
            if ($removebr) {
490
                $content = str_replace('<br />', "\r\n", $content);
491
            }
492
            if ($removehtml) {
493
                $content = strip_tags($content);
494
            }
495
            fwrite($fp, $content);
496
        }
497
        if (xoops_trim($footer) != '') {
498
            fwrite($fp, $footer);
499
        }
500
        fclose($fp);
501
        $newsfile = XOOPS_URL . '/uploads/news/newsletter.txt';
502
        printf(_AM_NEWS_NEWSLETTER_READY, $newsfile, XOOPS_URL . '/modules/news/admin/index.php?op=deletefile&amp;type=newsletter');
503
    } else {
504
        printf(_AM_NEWS_NOTHING);
505
    }
506
}
507
508
/**
509
 * News export
510
 *
511
 * You can use this function in the module's admin when you click on the tab named "News Export"
512
 * First select a range of date, possibly a range of topics and if you want, check the option "Include Topics Definitions"
513
 * to also export the topics.
514
 * News, and topics, will be exported to the XML format.
515
 */
516
function NewsExport()
517
{
518
    include_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
519
    xoops_cp_header();
520
    $exportAdmin = new ModuleAdmin();
521
    echo $exportAdmin->addNavigation('index.php?op=export');
522
    echo '<br /><br /><br />';
523
    $sform      = new XoopsThemeForm(_AM_NEWS_EXPORT_NEWS, 'exportform', XOOPS_URL . '/modules/news/admin/index.php', 'post');
524
    $dates_tray = new XoopsFormElementTray(_AM_NEWS_EXPORT_BETWEEN);
525
    $date1      = new XoopsFormTextDateSelect('', 'date1', 15, time());
526
    $date2      = new XoopsFormTextDateSelect(_AM_NEWS_EXPORT_AND, 'date2', 15, time());
527
    $dates_tray->addElement($date1);
528
    $dates_tray->addElement($date2);
529
    $sform->addElement($dates_tray);
530
531
    $topiclist  = new XoopsFormSelect(_AM_NEWS_PRUNE_TOPICS, 'export_topics', '', 5, true);
532
    $topics_arr = array();
533
    $xt         = new NewsTopic();
534
    $allTopics  = $xt->getAllTopics(false); // The webmaster can see everything
535
    $topic_tree = new MyXoopsObjectTree($allTopics, 'topic_id', 'topic_pid');
536
    $topics_arr = $topic_tree->getAllChild(0);
537
    if (count($topics_arr)) {
538
        foreach ($topics_arr as $onetopic) {
539
            $topiclist->addOption($onetopic->topic_id(), $onetopic->topic_title());
540
        }
541
    }
542
    $topiclist->setDescription(_AM_NEWS_EXPORT_PRUNE_DSC);
543
    $sform->addElement($topiclist, false);
544
    $sform->addElement(new XoopsFormRadioYN(_AM_NEWS_EXPORT_INCTOPICS, 'includetopics', 0), false);
545
    $sform->addElement(new XoopsFormHidden('op', 'launchexport'), false);
546
    $button_tray = new XoopsFormElementTray('', '');
547
    $submit_btn  = new XoopsFormButton('', 'post', _SUBMIT, 'submit');
548
    $button_tray->addElement($submit_btn);
549
    $sform->addElement($button_tray);
550
    $sform->display();
551
}
552
553
/**
554
 * @param $text
555
 *
556
 * @return string
557
 */
558
function news_utf8_encode($text)
559
{
560
    return xoops_utf8_encode($text);
561
}
562
563
// Launch stories export (to the xml's format)
564
function LaunchExport()
565
{
566
    xoops_cp_header();
567
    $exportAdmin = new ModuleAdmin();
568
    echo $exportAdmin->addNavigation('index.php?op=export');
569
    echo '<br />';
570
    $story           = new NewsStory();
571
    $topic           = new NewsTopic();
572
    $exportedstories = array();
573
    $date1           = $_POST['date1'];
574
    $date2           = $_POST['date2'];
575
    $timestamp1      = mktime(0, 0, 0, (int)substr($date1, 5, 2), (int)substr($date1, 8, 2), (int)substr($date1, 0, 4));
576
    $timestamp2      = mktime(23, 59, 59, (int)substr($date2, 5, 2), (int)substr($date2, 8, 2), (int)substr($date2, 0, 4));
577
    $topiclist       = '';
578
    if (isset($_POST['export_topics'])) {
579
        $topiclist = implode(',', $_POST['export_topics']);
580
    }
581
    $topicsexport    = (int)$_POST['includetopics'];
582
    $tbltopics       = array();
583
    $exportedstories = $story->NewsExport($timestamp1, $timestamp2, $topiclist, $topicsexport, $tbltopics);
584
    if (count($exportedstories)) {
585
        $xmlfile = XOOPS_ROOT_PATH . '/uploads/news/stories.xml';
586
        $fp      = fopen($xmlfile, 'w');
587
        if (!$fp) {
588
            redirect_header('index.php', 4, sprintf(_AM_NEWS_EXPORT_ERROR, $xmlfile));
589
        }
590
591
        fwrite($fp, news_utf8_encode("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"));
592
        fwrite($fp, news_utf8_encode("<news_stories>\n"));
593
        if ($topicsexport) {
594
            foreach ($tbltopics as $onetopic) {
595
                $topic->NewsTopic($onetopic);
596
                $content = "<news_topic>\n";
597
                $content .= sprintf("\t<topic_id>%u</topic_id>\n", $topic->topic_id());
598
                $content .= sprintf("\t<topic_pid>%u</topic_pid>\n", $topic->topic_pid());
599
                $content .= sprintf("\t<topic_imgurl>%s</topic_imgurl>\n", $topic->topic_imgurl());
600
                $content .= sprintf("\t<topic_title>%s</topic_title>\n", $topic->topic_title('F'));
601
                $content .= sprintf("\t<menu>%d</menu>\n", $topic->menu());
602
                $content .= sprintf("\t<topic_frontpage>%d</topic_frontpage>\n", $topic->topic_frontpage());
603
                $content .= sprintf("\t<topic_rssurl>%s</topic_rssurl>\n", $topic->topic_rssurl('E'));
604
                $content .= sprintf("\t<topic_description>%s</topic_description>\n", $topic->topic_description());
605
                $content .= sprintf("</news_topic>\n");
606
                $content = news_utf8_encode($content);
607
                fwrite($fp, $content);
608
            }
609
        }
610
611
        foreach ($exportedstories as $onestory) {
612
            $content = "<xoops_story>\n";
613
            $content .= sprintf("\t<storyid>%u</storyid>\n", $onestory->storyid());
614
            $content .= sprintf("\t<uid>%u</uid>\n", $onestory->uid());
615
            $content .= sprintf("\t<uname>%s</uname>\n", $onestory->uname());
616
            $content .= sprintf("\t<title>%s</title>\n", $onestory->title());
617
            $content .= sprintf("\t<created>%u</created>\n", $onestory->created());
618
            $content .= sprintf("\t<published>%u</published>\n", $onestory->published());
619
            $content .= sprintf("\t<expired>%u</expired>\n", $onestory->expired());
620
            $content .= sprintf("\t<hostname>%s</hostname>\n", $onestory->hostname());
621
            $content .= sprintf("\t<nohtml>%d</nohtml>\n", $onestory->nohtml());
622
            $content .= sprintf("\t<nosmiley>%d</nosmiley>\n", $onestory->nosmiley());
623
            $content .= sprintf("\t<hometext>%s</hometext>\n", $onestory->hometext());
624
            $content .= sprintf("\t<bodytext>%s</bodytext>\n", $onestory->bodytext());
625
            $content .= sprintf("\t<description>%s</description>\n", $onestory->description());
626
            $content .= sprintf("\t<keywords>%s</keywords>\n", $onestory->keywords());
627
            $content .= sprintf("\t<counter>%u</counter>\n", $onestory->counter());
628
            $content .= sprintf("\t<topicid>%u</topicid>\n", $onestory->topicid());
629
            $content .= sprintf("\t<ihome>%d</ihome>\n", $onestory->ihome());
630
            $content .= sprintf("\t<notifypub>%d</notifypub>\n", $onestory->notifypub());
631
            $content .= sprintf("\t<story_type>%s</story_type>\n", $onestory->type());
632
            $content .= sprintf("\t<topicdisplay>%d</topicdisplay>\n", $onestory->topicdisplay());
633
            $content .= sprintf("\t<topicalign>%s</topicalign>\n", $onestory->topicalign());
634
            $content .= sprintf("\t<comments>%u</comments>\n", $onestory->comments());
635
            $content .= sprintf("\t<rating>%f</rating>\n", $onestory->rating());
636
            $content .= sprintf("\t<votes>%u</votes>\n", $onestory->votes());
637
            $content .= sprintf("</xoops_story>\n");
638
            $content = news_utf8_encode($content);
639
            fwrite($fp, $content);
640
        }
641
        fwrite($fp, news_utf8_encode("</news_stories>\n"));
642
        fclose($fp);
643
        $xmlfile = XOOPS_URL . '/uploads/news/stories.xml';
644
        printf(_AM_NEWS_EXPORT_READY, $xmlfile, XOOPS_URL . '/modules/news/admin/index.php?op=deletefile&amp;type=xml');
645
    } else {
646
        printf(_AM_NEWS_EXPORT_NOTHING);
647
    }
648
}
649
650
/*
651
* Topics manager
652
*
653
* It's from here that you can list, add, modify an delete topics
654
* At first, you can see a list of all the topics in your databases. This list contains the topic's ID, its name,
655
* its parent topic, if it should be visible in the Xoops main menu and an action (Edit or Delete topic)
656
* Below this list you find the form used to create and edit the topics.
657
* use this form to :
658
* - Type the topic's title
659
* - Enter its description
660
* - Select its parent topic
661
* - Choose a color
662
* - Select if it must appear in the Xoops main menu
663
* - Choose if you want to see in the front page. If it's not the case, visitors will have to use the navigation box to see it
664
* - And finally you ca select an image to represent the topic
665
* The text box called "URL of RSS feed" is, for this moment, not used.
666
*/
667
function topicsmanager()
668
{
669
    global $xoopsDB, $xoopsConfig, $xoopsModule, $myts;
670
    include_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
671
    xoops_cp_header();
672
    $topicAdmin = new ModuleAdmin();
673
    echo $topicAdmin->addNavigation('index.php?op=topicsmanager');
674
675
    global $pathIcon16;
676
677
    $uploadfolder   = sprintf(_AM_UPLOAD_WARNING, XOOPS_URL . '/uploads/news/image');
678
    $uploadirectory = '/uploads/news/image';
679
    $start          = isset($_GET['start']) ? (int)$_GET['start'] : 0;
680
681
    $xt          = new NewsTopic($xoopsDB->prefix('news_topics'), 'topic_id', 'topic_pid');
682
    $topics_arr  = $xt->getChildTreeArray(0, 'topic_title');
683
    $totaltopics = count($topics_arr);
684
    $class       = '';
685
686
    //echo '<h4>' . _AM_CONFIG . '</h4>';
687
    //news_collapsableBar('topicsmanager', 'toptopicsmanager');
0 ignored issues
show
Unused Code Comprehensibility introduced by
75% 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...
688
689
    //echo "<img onclick=\"toggle('toptable'); toggleIcon('toptableicon');\" id='toptopicsmanager' name='toptopicsmanager' src='" . $pathIcon16."/close12.gif' alt='' /></a>&nbsp;"._AM_TOPICSMNGR . ' (' . $totaltopics . ')'."</h4>";
0 ignored issues
show
Unused Code Comprehensibility introduced by
47% 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...
690
691
    echo "<div id='topicsmanager'>";
692
    echo '<br />';
693
    echo "<div style='text-align: center;'>";
694
    echo "<table width='100%' cellspacing='1' cellpadding='3' border='0' class='outer'><tr class='bg3'><th align='center'>" . _AM_TOPIC . "</th><th align='left'>" . _AM_TOPICNAME . "</th><th align='center'>" . _AM_PARENTTOPIC . "</th><th align='center'>" . _AM_SUB_MENU_YESNO . "</th><th align='center'>" . _AM_NEWS_ACTION . '</th></tr>';
695
    if (is_array($topics_arr) && $totaltopics) {
696
        $cpt    = 1;
697
        $tmpcpt = $start;
698
        $ok     = true;
699
        $output = '';
700
        while ($ok) {
701
            if ($tmpcpt < $totaltopics) {
702
                $action_edit   = '<a href=index.php?op=topicsmanager&amp;topic_id=' . $topics_arr[$tmpcpt]['topic_id'] . '><img src=' . $pathIcon16 . '/edit.png title=' . _AM_EDIT . '></a>';
703
                $action_delete = '<a href=index.php?op=delTopic&amp;topic_id=' . $topics_arr[$tmpcpt]['topic_id'] . '><img src=' . $pathIcon16 . '/delete.png title=' . _AM_DELETE . "'></a>";
704
705
                $parent = '&nbsp;';
706
                if ($topics_arr[$tmpcpt]['topic_pid'] > 0) {
707
                    $xttmp  = new MyXoopsTopic($xoopsDB->prefix('news_topics'), $topics_arr[$tmpcpt]['topic_pid']);
708
                    $parent = $xttmp->topic_title();
709
                    unset($xttmp);
710
                }
711
                if ($topics_arr[$tmpcpt]['topic_pid'] != 0) {
712
                    $topics_arr[$tmpcpt]['prefix'] = str_replace('.', '-', $topics_arr[$tmpcpt]['prefix']) . '&nbsp;';
713
                } else {
714
                    $topics_arr[$tmpcpt]['prefix'] = str_replace('.', '', $topics_arr[$tmpcpt]['prefix']);
715
                }
716
                $submenu = $topics_arr[$tmpcpt]['menu'] ? _YES : _NO;
717
                $class   = ($class === 'even') ? 'odd' : 'even';
718
719
                $output = $output . "<tr class='" . $class . "'><td>" . $topics_arr[$tmpcpt]['topic_id'] . "</td><td align='left'>" . $topics_arr[$tmpcpt]['prefix'] . $myts->displayTarea($topics_arr[$tmpcpt]['topic_title']) . "</td><td align='left'>" . $parent . "</td><td align='center'>" . $submenu . "</td><td align='center'>" . $action_edit . $action_delete . '</td></tr>';
720
            } else {
721
                $ok = false;
722
            }
723
            if ($cpt >= news_getmoduleoption('storycountadmin')) {
724
                $ok = false;
725
            }
726
            ++$tmpcpt;
727
            ++$cpt;
728
        }
729
        echo $output;
730
    }
731
    $pagenav = new XoopsPageNav($totaltopics, news_getmoduleoption('storycountadmin'), $start, 'start', 'op=topicsmanager');
732
    echo "</table><div align='right'>" . $pagenav->renderNav() . '</div><br />';
733
    echo "</div></div><br />\n";
734
735
    $topic_id = isset($_GET['topic_id']) ? (int)$_GET['topic_id'] : 0;
736
    if ($topic_id > 0) {
737
        $xtmod             = new NewsTopic($topic_id);
738
        $topic_title       = $xtmod->topic_title('E');
739
        $topic_description = $xtmod->topic_description('E');
740
        $topic_rssfeed     = $xtmod->topic_rssurl('E');
741
        $op                = 'modTopicS';
742
        if (xoops_trim($xtmod->topic_imgurl()) != '') {
743
            $topicimage = $xtmod->topic_imgurl();
744
        } else {
745
            $topicimage = 'blank.png';
746
        }
747
        $btnlabel        = _AM_MODIFY;
748
        $parent          = $xtmod->topic_pid();
749
        $formlabel       = _AM_MODIFYTOPIC;
750
        $submenu         = $xtmod->menu();
751
        $topic_frontpage = $xtmod->topic_frontpage();
752
        $topic_color     = $xtmod->topic_color();
753
        unset($xtmod);
754
    } else {
755
        $topic_title       = '';
756
        $topic_frontpage   = 1;
757
        $topic_description = '';
758
        $op                = 'addTopic';
759
        $topicimage        = 'xoops.gif';
760
        $btnlabel          = _AM_ADD;
761
        $parent            = -1;
762
        $submenu           = 0;
763
        $topic_rssfeed     = '';
764
        $formlabel         = _AM_ADD_TOPIC;
765
        $topic_color       = '000000';
766
    }
767
768
    $sform = new XoopsThemeForm($formlabel, 'topicform', XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/admin/index.php', 'post');
769
    $sform->setExtra('enctype="multipart/form-data"');
770
    $sform->addElement(new XoopsFormText(_AM_TOPICNAME, 'topic_title', 50, 255, $topic_title), true);
771
    $editor = news_getWysiwygForm(_AM_TOPIC_DESCR, 'topic_description', $topic_description, 15, 60, 'hometext_hidden');
772
    if ($editor) {
773
        $sform->addElement($editor, false);
774
    }
775
776
    $sform->addElement(new XoopsFormHidden('op', $op), false);
777
    $sform->addElement(new XoopsFormHidden('topic_id', $topic_id), false);
778
779
    include_once XOOPS_ROOT_PATH . '/modules/news/class/class.newstopic.php';
780
    $xt = new NewsTopic();
781
    $sform->addElement(new XoopsFormLabel(_AM_PARENTTOPIC, $xt->MakeMyTopicSelBox(1, $parent, 'topic_pid', '', false)));
782
    // Topic's color
783
    // Code stolen to Zoullou, thank you Zoullou ;-)
784
    $select_color = "\n<select name='topic_color'  onchange='xoopsGetElementById(\"NewsColorSelect\").style.backgroundColor = \"#\" + this.options[this.selectedIndex].value;'>\n<option value='000000'>" . _AM_NEWS_COLOR . "</option>\n";
785
    $color_values = array(
786
        '000000',
787
        '000033',
788
        '000066',
789
        '000099',
790
        '0000CC',
791
        '0000FF',
792
        '003300',
793
        '003333',
794
        '003366',
795
        '0033CC',
796
        '0033FF',
797
        '006600',
798
        '006633',
799
        '006666',
800
        '006699',
801
        '0066CC',
802
        '0066FF',
803
        '009900',
804
        '009933',
805
        '009966',
806
        '009999',
807
        '0099CC',
808
        '0099FF',
809
        '00CC00',
810
        '00CC33',
811
        '00CC66',
812
        '00CC99',
813
        '00CCCC',
814
        '00CCFF',
815
        '00FF00',
816
        '00FF33',
817
        '00FF66',
818
        '00FF99',
819
        '00FFCC',
820
        '00FFFF',
821
        '330000',
822
        '330033',
823
        '330066',
824
        '330099',
825
        '3300CC',
826
        '3300FF',
827
        '333300',
828
        '333333',
829
        '333366',
830
        '333399',
831
        '3333CC',
832
        '3333FF',
833
        '336600',
834
        '336633',
835
        '336666',
836
        '336699',
837
        '3366CC',
838
        '3366FF',
839
        '339900',
840
        '339933',
841
        '339966',
842
        '339999',
843
        '3399CC',
844
        '3399FF',
845
        '33CC00',
846
        '33CC33',
847
        '33CC66',
848
        '33CC99',
849
        '33CCCC',
850
        '33CCFF',
851
        '33FF00',
852
        '33FF33',
853
        '33FF66',
854
        '33FF99',
855
        '33FFCC',
856
        '33FFFF',
857
        '660000',
858
        '660033',
859
        '660066',
860
        '660099',
861
        '6600CC',
862
        '6600FF',
863
        '663300',
864
        '663333',
865
        '663366',
866
        '663399',
867
        '6633CC',
868
        '6633FF',
869
        '666600',
870
        '666633',
871
        '666666',
872
        '666699',
873
        '6666CC',
874
        '6666FF',
875
        '669900',
876
        '669933',
877
        '669966',
878
        '669999',
879
        '6699CC',
880
        '6699FF',
881
        '66CC00',
882
        '66CC33',
883
        '66CC66',
884
        '66CC99',
885
        '66CCCC',
886
        '66CCFF',
887
        '66FF00',
888
        '66FF33',
889
        '66FF66',
890
        '66FF99',
891
        '66FFCC',
892
        '66FFFF',
893
        '990000',
894
        '990033',
895
        '990066',
896
        '990099',
897
        '9900CC',
898
        '9900FF',
899
        '993300',
900
        '993333',
901
        '993366',
902
        '993399',
903
        '9933CC',
904
        '9933FF',
905
        '996600',
906
        '996633',
907
        '996666',
908
        '996699',
909
        '9966CC',
910
        '9966FF',
911
        '999900',
912
        '999933',
913
        '999966',
914
        '999999',
915
        '9999CC',
916
        '9999FF',
917
        '99CC00',
918
        '99CC33',
919
        '99CC66',
920
        '99CC99',
921
        '99CCCC',
922
        '99CCFF',
923
        '99FF00',
924
        '99FF33',
925
        '99FF66',
926
        '99FF99',
927
        '99FFCC',
928
        '99FFFF',
929
        'CC0000',
930
        'CC0033',
931
        'CC0066',
932
        'CC0099',
933
        'CC00CC',
934
        'CC00FF',
935
        'CC3300',
936
        'CC3333',
937
        'CC3366',
938
        'CC3399',
939
        'CC33CC',
940
        'CC33FF',
941
        'CC6600',
942
        'CC6633',
943
        'CC6666',
944
        'CC6699',
945
        'CC66CC',
946
        'CC66FF',
947
        'CC9900',
948
        'CC9933',
949
        'CC9966',
950
        'CC9999',
951
        'CC99CC',
952
        'CC99FF',
953
        'CCCC00',
954
        'CCCC33',
955
        'CCCC66',
956
        'CCCC99',
957
        'CCCCCC',
958
        'CCCCFF',
959
        'CCFF00',
960
        'CCFF33',
961
        'CCFF66',
962
        'CCFF99',
963
        'CCFFCC',
964
        'CCFFFF',
965
        'FF0000',
966
        'FF0033',
967
        'FF0066',
968
        'FF0099',
969
        'FF00CC',
970
        'FF00FF',
971
        'FF3300',
972
        'FF3333',
973
        'FF3366',
974
        'FF3399',
975
        'FF33CC',
976
        'FF33FF',
977
        'FF6600',
978
        'FF6633',
979
        'FF6666',
980
        'FF6699',
981
        'FF66CC',
982
        'FF66FF',
983
        'FF9900',
984
        'FF9933',
985
        'FF9966',
986
        'FF9999',
987
        'FF99CC',
988
        'FF99FF',
989
        'FFCC00',
990
        'FFCC33',
991
        'FFCC66',
992
        'FFCC99',
993
        'FFCCCC',
994
        'FFCCFF',
995
        'FFFF00',
996
        'FFFF33',
997
        'FFFF66',
998
        'FFFF99',
999
        'FFFFCC',
1000
        'FFFFFF');
1001
1002
    foreach ($color_values as $color_value) {
1003
        if ($topic_color == $color_value) {
1004
            $selected = " selected='selected'";
1005
        } else {
1006
            $selected = '';
1007
        }
1008
        $select_color .= '<option' . $selected . " value='" . $color_value . "' style='background-color:#" . $color_value . ';color:#' . $color_value . ";'>#" . $color_value . "</option>\n";
1009
    }
1010
1011
    $select_color .= "</select>&nbsp;\n<span id='NewsColorSelect'>&nbsp;&nbsp;&nbsp;&nbsp;</span>";
1012
    $sform->addElement(new XoopsFormLabel(_AM_NEWS_TOPIC_COLOR, $select_color));
1013
    // Sub menu ?
1014
    $sform->addElement(new XoopsFormRadioYN(_AM_SUB_MENU, 'submenu', $submenu, _YES, _NO));
1015
    $sform->addElement(new XoopsFormRadioYN(_AM_PUBLISH_FRONTPAGE, 'topic_frontpage', $topic_frontpage, _YES, _NO));
1016
    // Unused for this moment... sorry
1017
    //$sform->addElement(new XoopsFormText(_AM_NEWS_RSS_URL, 'topic_rssfeed', 50, 255, $topic_rssfeed), false);
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% 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...
1018
    // ********** Picture
1019
    $imgtray = new XoopsFormElementTray(_AM_TOPICIMG, '<br />');
1020
1021
    $imgpath      = sprintf(_AM_IMGNAEXLOC, 'uploads/news/image/');
1022
    $imageselect  = new XoopsFormSelect($imgpath, 'topic_imgurl', $topicimage);
1023
    $topics_array = XoopsLists:: getImgListAsArray(XOOPS_ROOT_PATH . '/uploads/news/image/');
1024
    foreach ($topics_array as $image) {
1025
        $imageselect->addOption("$image", $image);
1026
    }
1027
    $imageselect->setExtra("onchange='showImgSelected(\"image3\", \"topic_imgurl\", \"" . $uploadirectory . "\", \"\", \"" . XOOPS_URL . "\")'");
1028
    $imgtray->addElement($imageselect, false);
1029
    $imgtray->addElement(new XoopsFormLabel('', "<br /><img src='" . XOOPS_URL . '/' . $uploadirectory . '/' . $topicimage . "' name='image3' id='image3' alt='' />"));
1030
1031
    $uploadfolder = sprintf(_AM_UPLOAD_WARNING, XOOPS_URL . '/uploads/news/image');
1032
    $fileseltray  = new XoopsFormElementTray('', '<br />');
1033
    $fileseltray->addElement(new XoopsFormFile(_AM_TOPIC_PICTURE, 'attachedfile', news_getmoduleoption('maxuploadsize')), false);
1034
    $fileseltray->addElement(new XoopsFormLabel($uploadfolder), false);
1035
    $imgtray->addElement($fileseltray);
1036
    $sform->addElement($imgtray);
1037
1038
    // Permissions
1039
    $member_handler = xoops_getHandler('member');
1040
    $group_list     = $member_handler->getGroupList();
1041
    $gperm_handler  = xoops_getHandler('groupperm');
1042
    $full_list      = array_keys($group_list);
1043
1044
    $groups_ids = array();
1045 View Code Duplication
    if ($topic_id > 0) { // Edit mode
1046
        $groups_ids                       = $gperm_handler->getGroupIds('news_approve', $topic_id, $xoopsModule->getVar('mid'));
1047
        $groups_ids                       = array_values($groups_ids);
1048
        $groups_news_can_approve_checkbox = new XoopsFormCheckBox(_AM_APPROVEFORM, 'groups_news_can_approve[]', $groups_ids);
1049
    } else { // Creation mode
1050
        $groups_news_can_approve_checkbox = new XoopsFormCheckBox(_AM_APPROVEFORM, 'groups_news_can_approve[]', $full_list);
1051
    }
1052
    $groups_news_can_approve_checkbox->addOptionArray($group_list);
1053
    $sform->addElement($groups_news_can_approve_checkbox);
1054
1055
    $groups_ids = array();
1056 View Code Duplication
    if ($topic_id > 0) { // Edit mode
1057
        $groups_ids                      = $gperm_handler->getGroupIds('news_submit', $topic_id, $xoopsModule->getVar('mid'));
1058
        $groups_ids                      = array_values($groups_ids);
1059
        $groups_news_can_submit_checkbox = new XoopsFormCheckBox(_AM_SUBMITFORM, 'groups_news_can_submit[]', $groups_ids);
1060
    } else { // Creation mode
1061
        $groups_news_can_submit_checkbox = new XoopsFormCheckBox(_AM_SUBMITFORM, 'groups_news_can_submit[]', $full_list);
1062
    }
1063
    $groups_news_can_submit_checkbox->addOptionArray($group_list);
1064
    $sform->addElement($groups_news_can_submit_checkbox);
1065
1066
    $groups_ids = array();
1067 View Code Duplication
    if ($topic_id > 0) { // Edit mode
1068
        $groups_ids                    = $gperm_handler->getGroupIds('news_view', $topic_id, $xoopsModule->getVar('mid'));
1069
        $groups_ids                    = array_values($groups_ids);
1070
        $groups_news_can_view_checkbox = new XoopsFormCheckBox(_AM_VIEWFORM, 'groups_news_can_view[]', $groups_ids);
1071
    } else { // Creation mode
1072
        $groups_news_can_view_checkbox = new XoopsFormCheckBox(_AM_VIEWFORM, 'groups_news_can_view[]', $full_list);
1073
    }
1074
    $groups_news_can_view_checkbox->addOptionArray($group_list);
1075
    $sform->addElement($groups_news_can_view_checkbox);
1076
1077
    // Submit buttons
1078
    $button_tray = new XoopsFormElementTray('', '');
1079
    $submit_btn  = new XoopsFormButton('', 'post', $btnlabel, 'submit');
1080
    $button_tray->addElement($submit_btn);
1081
    $sform->addElement($button_tray);
1082
    $sform->display();
1083
    echo "<script type='text/javascript'>\n";
1084
    echo 'xoopsGetElementById("NewsColorSelect").style.backgroundColor = "#' . $topic_color . '";';
1085
    echo "</script>\n";
1086
}
1087
1088
// Save a topic after it has been modified
1089
function modTopicS()
1090
{
1091
    global $xoopsDB, $xoopsModule, $xoopsModuleConfig;
1092
1093
    $xt = new NewsTopic((int)$_POST['topic_id']);
1094
    if ((int)$_POST['topic_pid'] == (int)$_POST['topic_id']) {
1095
        redirect_header('index.php?op=topicsmanager', 2, _AM_ADD_TOPIC_ERROR1);
1096
    }
1097
    $xt->setTopicPid((int)$_POST['topic_pid']);
1098
    if (empty($_POST['topic_title'])) {
1099
        redirect_header('index.php?op=topicsmanager', 2, _AM_ERRORTOPICNAME);
1100
    }
1101
    if (isset($_SESSION['items_count'])) {
1102
        $_SESSION['items_count'] = -1;
1103
    }
1104
    $xt->setTopicTitle($_POST['topic_title']);
1105 View Code Duplication
    if (isset($_POST['topic_imgurl']) && $_POST['topic_imgurl'] != '') {
1106
        $xt->setTopicImgurl($_POST['topic_imgurl']);
1107
    }
1108
    $xt->setMenu((int)$_POST['submenu']);
1109
    $xt->setTopicFrontpage((int)$_POST['topic_frontpage']);
1110
    if (isset($_POST['topic_description'])) {
1111
        $xt->setTopicDescription($_POST['topic_description']);
1112
    } else {
1113
        $xt->setTopicDescription('');
1114
    }
1115
    //$xt->Settopic_rssurl($_POST['topic_rssfeed']);
0 ignored issues
show
Unused Code Comprehensibility introduced by
90% 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...
1116
    $xt->setTopic_color($_POST['topic_color']);
1117
1118 View Code Duplication
    if (isset($_POST['xoops_upload_file'])) {
1119
        $fldname = $_FILES[$_POST['xoops_upload_file'][0]];
1120
        $fldname = $fldname['name'];
1121
        if (xoops_trim($fldname != '')) {
1122
            $sfiles         = new sFiles();
1123
            $dstpath        = XOOPS_ROOT_PATH . '/uploads/news/image';
1124
            $destname       = $sfiles->createUploadName($dstpath, $fldname, true);
1125
            $permittedtypes = array('image/gif', 'image/jpeg', 'image/pjpeg', 'image/x-png', 'image/png');
1126
            $uploader       = new XoopsMediaUploader($dstpath, $permittedtypes, $xoopsModuleConfig['maxuploadsize']);
1127
            $uploader->setTargetFileName($destname);
1128
            if ($uploader->fetchMedia($_POST['xoops_upload_file'][0])) {
1129
                if ($uploader->upload()) {
1130
                    $xt->setTopicImgurl(basename($destname));
1131
                } else {
1132
                    echo _AM_UPLOAD_ERROR . ' ' . $uploader->getErrors();
1133
                }
1134
            } else {
1135
                echo $uploader->getErrors();
1136
            }
1137
        }
1138
    }
1139
    $xt->store();
1140
1141
    // Permissions
1142
    $gperm_handler = xoops_getHandler('groupperm');
1143
    $criteria      = new CriteriaCompo();
1144
    $criteria->add(new Criteria('gperm_itemid', $xt->topic_id(), '='));
1145
    $criteria->add(new Criteria('gperm_modid', $xoopsModule->getVar('mid'), '='));
1146
    $criteria->add(new Criteria('gperm_name', 'news_approve', '='));
1147
    $gperm_handler->deleteAll($criteria);
1148
1149
    $criteria = new CriteriaCompo();
1150
    $criteria->add(new Criteria('gperm_itemid', $xt->topic_id(), '='));
1151
    $criteria->add(new Criteria('gperm_modid', $xoopsModule->getVar('mid'), '='));
1152
    $criteria->add(new Criteria('gperm_name', 'news_submit', '='));
1153
    $gperm_handler->deleteAll($criteria);
1154
1155
    $criteria = new CriteriaCompo();
1156
    $criteria->add(new Criteria('gperm_itemid', $xt->topic_id(), '='));
1157
    $criteria->add(new Criteria('gperm_modid', $xoopsModule->getVar('mid'), '='));
1158
    $criteria->add(new Criteria('gperm_name', 'news_view', '='));
1159
    $gperm_handler->deleteAll($criteria);
1160
1161 View Code Duplication
    if (isset($_POST['groups_news_can_approve'])) {
1162
        foreach ($_POST['groups_news_can_approve'] as $onegroup_id) {
1163
            $gperm_handler->addRight('news_approve', $xt->topic_id(), $onegroup_id, $xoopsModule->getVar('mid'));
1164
        }
1165
    }
1166
1167 View Code Duplication
    if (isset($_POST['groups_news_can_submit'])) {
1168
        foreach ($_POST['groups_news_can_submit'] as $onegroup_id) {
1169
            $gperm_handler->addRight('news_submit', $xt->topic_id(), $onegroup_id, $xoopsModule->getVar('mid'));
1170
        }
1171
    }
1172
1173 View Code Duplication
    if (isset($_POST['groups_news_can_view'])) {
1174
        foreach ($_POST['groups_news_can_view'] as $onegroup_id) {
1175
            $gperm_handler->addRight('news_view', $xt->topic_id(), $onegroup_id, $xoopsModule->getVar('mid'));
1176
        }
1177
    }
1178
1179
    news_updateCache();
1180
    redirect_header('index.php?op=topicsmanager', 1, _AM_DBUPDATED);
1181
}
1182
1183
// Delete a topic and its subtopics and its stories and the related stories
1184
function delTopic()
1185
{
1186
    global $xoopsDB, $xoopsModule;
1187
    if (!isset($_POST['ok'])) {
1188
        xoops_cp_header();
1189
        echo '<h4>' . _AM_CONFIG . '</h4>';
1190
        $xt = new MyXoopsTopic($xoopsDB->prefix('news_topics'), (int)$_GET['topic_id']);
1191
        xoops_confirm(array('op' => 'delTopic', 'topic_id' => (int)$_GET['topic_id'], 'ok' => 1), 'index.php', _AM_WAYSYWTDTTAL . '<br />' . $xt->topic_title('S'));
1192
    } else {
1193
        xoops_cp_header();
1194
        $xt = new MyXoopsTopic($xoopsDB->prefix('news_topics'), (int)$_POST['topic_id']);
1195
        if (isset($_SESSION['items_count'])) {
1196
            $_SESSION['items_count'] = -1;
1197
        }
1198
        // get all subtopics under the specified topic
1199
        $topic_arr = $xt->getAllChildTopics();
1200
        array_push($topic_arr, $xt);
1201
        foreach ($topic_arr as $eachtopic) {
1202
            // get all stories in each topic
1203
            $story_arr = NewsStory:: getByTopic($eachtopic->topic_id());
1204
            foreach ($story_arr as $eachstory) {
1205
                if (false != $eachstory->delete()) {
1206
                    xoops_comment_delete($xoopsModule->getVar('mid'), $eachstory->storyid());
1207
                    xoops_notification_deletebyitem($xoopsModule->getVar('mid'), 'story', $eachstory->storyid());
1208
                }
1209
            }
1210
            // all stories for each topic is deleted, now delete the topic data
1211
            $eachtopic->delete();
1212
            // Delete also the notifications and permissions
1213
            xoops_notification_deletebyitem($xoopsModule->getVar('mid'), 'category', $eachtopic->topic_id);
1214
            xoops_groupperm_deletebymoditem($xoopsModule->getVar('mid'), 'news_approve', $eachtopic->topic_id);
1215
            xoops_groupperm_deletebymoditem($xoopsModule->getVar('mid'), 'news_submit', $eachtopic->topic_id);
1216
            xoops_groupperm_deletebymoditem($xoopsModule->getVar('mid'), 'news_view', $eachtopic->topic_id);
1217
        }
1218
        news_updateCache();
1219
        redirect_header('index.php?op=topicsmanager', 1, _AM_DBUPDATED);
1220
    }
1221
}
1222
1223
// Add a new topic
1224
function addTopic()
1225
{
1226
    global $xoopsDB, $xoopsModule, $xoopsModuleConfig;
1227
    $topicpid = isset($_POST['topic_pid']) ? (int)$_POST['topic_pid'] : 0;
1228
    $xt       = new NewsTopic();
1229
    if (!$xt->topicExists($topicpid, $_POST['topic_title'])) {
1230
        $xt->setTopicPid($topicpid);
1231
        if (empty($_POST['topic_title']) || xoops_trim($_POST['topic_title']) == '') {
1232
            redirect_header('index.php?op=topicsmanager', 2, _AM_ERRORTOPICNAME);
1233
        }
1234
        $xt->setTopicTitle($_POST['topic_title']);
1235
        //$xt->Settopic_rssurl($_POST['topic_rssfeed']);
0 ignored issues
show
Unused Code Comprehensibility introduced by
90% 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...
1236
        $xt->setTopic_color($_POST['topic_color']);
1237 View Code Duplication
        if (isset($_POST['topic_imgurl']) && $_POST['topic_imgurl'] != '') {
1238
            $xt->setTopicImgurl($_POST['topic_imgurl']);
1239
        }
1240
        $xt->setMenu((int)$_POST['submenu']);
1241
        $xt->setTopicFrontpage((int)$_POST['topic_frontpage']);
1242
        if (isset($_SESSION['items_count'])) {
1243
            $_SESSION['items_count'] = -1;
1244
        }
1245 View Code Duplication
        if (isset($_POST['xoops_upload_file'])) {
1246
            $fldname = $_FILES[$_POST['xoops_upload_file'][0]];
1247
            $fldname = $fldname['name'];
1248
            if (xoops_trim($fldname != '')) {
1249
                $sfiles         = new sFiles();
1250
                $dstpath        = XOOPS_ROOT_PATH . '/uploads/news/image';
1251
                $destname       = $sfiles->createUploadName($dstpath, $fldname, true);
1252
                $permittedtypes = array('image/gif', 'image/jpeg', 'image/pjpeg', 'image/x-png', 'image/png');
1253
                $uploader       = new XoopsMediaUploader($dstpath, $permittedtypes, $xoopsModuleConfig['maxuploadsize']);
1254
                $uploader->setTargetFileName($destname);
1255
                if ($uploader->fetchMedia($_POST['xoops_upload_file'][0])) {
1256
                    if ($uploader->upload()) {
1257
                        $xt->setTopicImgurl(basename($destname));
1258
                    } else {
1259
                        echo _AM_UPLOAD_ERROR . ' ' . $uploader->getErrors();
1260
                    }
1261
                } else {
1262
                    echo $uploader->getErrors();
1263
                }
1264
            }
1265
        }
1266
        if (isset($_POST['topic_description'])) {
1267
            $xt->setTopicDescription($_POST['topic_description']);
1268
        } else {
1269
            $xt->setTopicDescription('');
1270
        }
1271
        $xt->store();
1272
        // Permissions
1273
        $gperm_handler = xoops_getHandler('groupperm');
1274 View Code Duplication
        if (isset($_POST['groups_news_can_approve'])) {
1275
            foreach ($_POST['groups_news_can_approve'] as $onegroup_id) {
1276
                $gperm_handler->addRight('news_approve', $xt->topic_id(), $onegroup_id, $xoopsModule->getVar('mid'));
1277
            }
1278
        }
1279
1280 View Code Duplication
        if (isset($_POST['groups_news_can_submit'])) {
1281
            foreach ($_POST['groups_news_can_submit'] as $onegroup_id) {
1282
                $gperm_handler->addRight('news_submit', $xt->topic_id(), $onegroup_id, $xoopsModule->getVar('mid'));
1283
            }
1284
        }
1285
1286 View Code Duplication
        if (isset($_POST['groups_news_can_view'])) {
1287
            foreach ($_POST['groups_news_can_view'] as $onegroup_id) {
1288
                $gperm_handler->addRight('news_view', $xt->topic_id(), $onegroup_id, $xoopsModule->getVar('mid'));
1289
            }
1290
        }
1291
        news_updateCache();
1292
1293
        $notification_handler = xoops_getHandler('notification');
1294
        $tags                 = array();
1295
        $tags['TOPIC_NAME']   = $_POST['topic_title'];
1296
        $notification_handler->triggerEvent('global', 0, 'new_category', $tags);
1297
        redirect_header('index.php?op=topicsmanager', 1, _AM_DBUPDATED);
1298
    } else {
1299
        redirect_header('index.php?op=topicsmanager', 2, _AM_ADD_TOPIC_ERROR);
1300
    }
1301
}
1302
1303
/**
1304
 * Statistics about stories, topics and authors
1305
 *
1306
 * You can reach the statistics from the admin part of the news module by clicking on the "Statistics" tabs
1307
 * The number of visible elements in each table is equal to the module's option called "storycountadmin"
1308
 * There are 3 kind of different statistics :
1309
 * - Topics statistics
1310
 *   For each topic you can see its number of articles, the number of time each topics was viewed, the number
1311
 *   of attached files, the number of expired articles and the number of unique authors.
1312
 * - Articles statistics
1313
 *   This part is decomposed in 3 tables :
1314
 *   a) Most readed articles
1315
 *      This table resumes, for all the news in your database, the most readed articles.
1316
 *      The table contains, for each news, its topic, its title, the author and the number of views.
1317
 *   b) Less readed articles
1318
 *      That's the opposite action of the previous table and its content is the same
1319
 *   c) Best rated articles
1320
 *      You will find here the best rated articles, the content is the same that the previous tables, the last column is just changing and contains the article's rating
1321
 * - Authors statistics
1322
 *   This part is also decomposed in 3 tables
1323
 *   a) Most readed authors
1324
 *        To create this table, the program compute the total number of reads per author and displays the most readed author and the number of views
1325
 *   b) Best rated authors
1326
 *      To created this table's content, the program compute the rating's average of each author and create a table
1327
 *   c) Biggest contributors
1328
 *      The goal of this table is to know who is creating the biggest number of articles.
1329
 */
1330
function Stats()
1331
{
1332
    global $xoopsModule, $xoopsConfig;
1333
    xoops_cp_header();
1334
    $myts = MyTextSanitizer::getInstance();
1335 View Code Duplication
    if (file_exists(XOOPS_ROOT_PATH . '/modules/news/language/' . $xoopsConfig['language'] . '/main.php')) {
1336
        include_once XOOPS_ROOT_PATH . '/modules/news/language/' . $xoopsConfig['language'] . '/main.php';
1337
    } else {
1338
        include_once XOOPS_ROOT_PATH . '/modules/news/language/english/main.php';
1339
    }
1340
    $statsAdmin = new ModuleAdmin();
1341
    echo $statsAdmin->addNavigation('index.php?op=stats');
1342
    $news   = new NewsStory();
1343
    $stats  = array();
1344
    $stats  = $news->GetStats(news_getmoduleoption('storycountadmin'));
1345
    $totals = array(0, 0, 0, 0, 0);
1346
    //printf("<h1>%s</h1>\n",_AM_NEWS_STATS);
0 ignored issues
show
Unused Code Comprehensibility introduced by
72% 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...
1347
1348
    // First part of the stats, everything about topics
1349
    $storiespertopic = $stats['storiespertopic'];
1350
    $readspertopic   = $stats['readspertopic'];
1351
    $filespertopic   = $stats['filespertopic'];
1352
    $expiredpertopic = $stats['expiredpertopic'];
1353
    $authorspertopic = $stats['authorspertopic'];
1354
    $class           = '';
1355
1356
    echo "<div style='text-align: center;'><b>" . _AM_NEWS_STATS0 . "</b><br />\n";
1357
    echo "<table border='0' width='100%'><tr class='bg3'><th align='center'>" . _AM_TOPIC . "</th><th align='center'>" . _NW_ARTICLES . '</th><th>' . _NW_VIEWS . '</th><th>' . _AM_UPLOAD_ATTACHFILE . '</th><th>' . _AM_EXPARTS . '</th><th>' . _AM_NEWS_STATS1 . '</th></tr>';
1358
    foreach ($storiespertopic as $topicid => $data) {
1359
        $url   = XOOPS_URL . '/modules/' . $xoopsModule->dirname() . '/index.php?storytopic=' . $topicid;
1360
        $views = 0;
1361
        if (array_key_exists($topicid, $readspertopic)) {
1362
            $views = $readspertopic[$topicid];
1363
        }
1364
        $attachedfiles = 0;
1365
        if (array_key_exists($topicid, $filespertopic)) {
1366
            $attachedfiles = $filespertopic[$topicid];
1367
        }
1368
        $expired = 0;
1369
        if (array_key_exists($topicid, $expiredpertopic)) {
1370
            $expired = $expiredpertopic[$topicid];
1371
        }
1372
        $authors = 0;
1373
        if (array_key_exists($topicid, $authorspertopic)) {
1374
            $authors = $authorspertopic[$topicid];
1375
        }
1376
        $articles = $data['cpt'];
1377
1378
        $totals[0] += $articles;
1379
        $totals[1] += $views;
1380
        $totals[2] += $attachedfiles;
1381
        $totals[3] += $expired;
1382
        $class = ($class === 'even') ? 'odd' : 'even';
1383
        printf("<tr class='" . $class . "'><td align='left'><a href='%s' target ='_blank'>%s</a></td><td align='right'>%u</td><td align='right'>%u</td><td align='right'>%u</td><td align='right'>%u</td><td align='right'>%u</td></tr>\n", $url, $myts->displayTarea($data['topic_title']), $articles, $views, $attachedfiles, $expired, $authors);
1384
    }
1385
    $class = ($class === 'even') ? 'odd' : 'even';
1386
    printf("<tr class='" . $class . "'><td align='center'><b>%s</b></td><td align='right'><b>%u</b></td><td align='right'><b>%u</b></td><td align='right'><b>%u</b></td><td align='right'><b>%u</b></td><td>&nbsp;</td>\n", _AM_NEWS_STATS2, $totals[0], $totals[1], $totals[2], $totals[3]);
1387
    echo '</table></div><br /><br /><br />';
1388
1389
    // Second part of the stats, everything about stories
1390
    // a) Most readed articles
1391
    $mostreadednews = $stats['mostreadednews'];
1392
    echo "<div style='text-align: center;'><b>" . _AM_NEWS_STATS3 . '</b><br /><br />' . _AM_NEWS_STATS4 . "<br />\n";
1393
    echo "<table border='0' width='100%'><tr class='bg3'><th align='center'>" . _AM_TOPIC . "</th><th align='center'>" . _AM_TITLE . '</th><th>' . _AM_POSTER . '</th><th>' . _NW_VIEWS . "</th></tr>\n";
1394 View Code Duplication
    foreach ($mostreadednews as $storyid => $data) {
1395
        $url1  = XOOPS_URL . '/modules/' . $xoopsModule->dirname() . '/index.php?storytopic=' . $data['topicid'];
1396
        $url2  = XOOPS_URL . '/modules/' . $xoopsModule->dirname() . '/article.php?storyid=' . $storyid;
1397
        $url3  = XOOPS_URL . '/userinfo.php?uid=' . $data['uid'];
1398
        $class = ($class === 'even') ? 'odd' : 'even';
1399
        printf("<tr class='" . $class . "'><td align='left'><a href='%s' target ='_blank'>%s</a></td><td align='left'><a href='%s' target='_blank'>%s</a></td><td><a href='%s' target='_blank'>%s</a></td><td align='right'>%u</td></tr>\n", $url1, $myts->displayTarea($data['topic_title']), $url2, $myts->displayTarea($data['title']), $url3, $myts->htmlSpecialChars($news->uname($data['uid'])), $data['counter']);
1400
    }
1401
    echo '</table>';
1402
1403
    // b) Less readed articles
1404
    $lessreadednews = $stats['lessreadednews'];
1405
    echo '<br /><br />' . _AM_NEWS_STATS5;
1406
    echo "<table border='0' width='100%'><tr class='bg3'><th align='center'>" . _AM_TOPIC . "</th><th align='center'>" . _AM_TITLE . '</th><th>' . _AM_POSTER . '</th><th>' . _NW_VIEWS . "</th></tr>\n";
1407 View Code Duplication
    foreach ($lessreadednews as $storyid => $data) {
1408
        $url1  = XOOPS_URL . '/modules/' . $xoopsModule->dirname() . '/index.php?storytopic=' . $data['topicid'];
1409
        $url2  = XOOPS_URL . '/modules/' . $xoopsModule->dirname() . '/article.php?storyid=' . $storyid;
1410
        $url3  = XOOPS_URL . '/userinfo.php?uid=' . $data['uid'];
1411
        $class = ($class === 'even') ? 'odd' : 'even';
1412
        printf("<tr class='" . $class . "'><td align='left'><a href='%s' target ='_blank'>%s</a></td><td align='left'><a href='%s' target='_blank'>%s</a></td><td><a href='%s' target='_blank'>%s</a></td><td align='right'>%u</td></tr>\n", $url1, $myts->displayTarea($data['topic_title']), $url2, $myts->displayTarea($data['title']), $url3, $myts->htmlSpecialChars($news->uname($data['uid'])), $data['counter']);
1413
    }
1414
    echo '</table>';
1415
1416
    // c) Best rated articles (this is an average)
1417
    $besratednews = $stats['besratednews'];
1418
    echo '<br /><br />' . _AM_NEWS_STATS6;
1419
    echo "<table border='0' width='100%'><tr class='bg3'><th align='center'>" . _AM_TOPIC . "</th><th align='center'>" . _AM_TITLE . '</th><th>' . _AM_POSTER . '</th><th>' . _NW_RATING . "</th></tr>\n";
1420 View Code Duplication
    foreach ($besratednews as $storyid => $data) {
1421
        $url1  = XOOPS_URL . '/modules/' . $xoopsModule->dirname() . '/index.php?storytopic=' . $data['topicid'];
1422
        $url2  = XOOPS_URL . '/modules/' . $xoopsModule->dirname() . '/article.php?storyid=' . $storyid;
1423
        $url3  = XOOPS_URL . '/userinfo.php?uid=' . $data['uid'];
1424
        $class = ($class === 'even') ? 'odd' : 'even';
1425
        printf("<tr class='" . $class . "'><td align='left'><a href='%s' target ='_blank'>%s</a></td><td align='left'><a href='%s' target='_blank'>%s</a></td><td><a href='%s' target='_blank'>%s</a></td><td align='right'>%s</td></tr>\n", $url1, $myts->displayTarea($data['topic_title']), $url2, $myts->displayTarea($data['title']), $url3, $myts->htmlSpecialChars($news->uname($data['uid'])), number_format($data['rating'], 2));
1426
    }
1427
    echo '</table></div><br /><br /><br />';
1428
1429
    // Last part of the stats, everything about authors
1430
    // a) Most readed authors
1431
    $mostreadedauthors = $stats['mostreadedauthors'];
1432
    echo "<div style='text-align: center;'><b>" . _AM_NEWS_STATS10 . '</b><br /><br />' . _AM_NEWS_STATS7 . "<br />\n";
1433
    echo "<table border='0' width='100%'><tr class='bg3'><th>" . _AM_POSTER . '</th><th>' . _NW_VIEWS . "</th></tr>\n";
1434 View Code Duplication
    foreach ($mostreadedauthors as $uid => $reads) {
1435
        $url   = XOOPS_URL . '/userinfo.php?uid=' . $uid;
1436
        $class = ($class === 'even') ? 'odd' : 'even';
1437
        printf("<tr class='" . $class . "'><td align='left'><a href='%s' target ='_blank'>%s</a></td><td align='right'>%u</td></tr>\n", $url, $myts->htmlSpecialChars($news->uname($uid)), $reads);
1438
    }
1439
    echo '</table>';
1440
1441
    // b) Best rated authors
1442
    $bestratedauthors = $stats['bestratedauthors'];
1443
    echo '<br /><br />' . _AM_NEWS_STATS8;
1444
    echo "<table border='0' width='100%'><tr class='bg3'><th>" . _AM_POSTER . '</th><th>' . _NW_RATING . "</th></tr>\n";
1445 View Code Duplication
    foreach ($bestratedauthors as $uid => $rating) {
1446
        $url   = XOOPS_URL . '/userinfo.php?uid=' . $uid;
1447
        $class = ($class === 'even') ? 'odd' : 'even';
1448
        printf("<tr class='" . $class . "'><td align='left'><a href='%s' target ='_blank'>%s</a></td><td align='right'>%u</td></tr>\n", $url, $myts->htmlSpecialChars($news->uname($uid)), $rating);
1449
    }
1450
    echo '</table>';
1451
1452
    // c) Biggest contributors
1453
    $biggestcontributors = $stats['biggestcontributors'];
1454
    echo '<br /><br />' . _AM_NEWS_STATS9;
1455
    echo "<table border='0' width='100%'><tr class='bg3'><th>" . _AM_POSTER . '</th><th>' . _AM_NEWS_STATS11 . "</th></tr>\n";
1456 View Code Duplication
    foreach ($biggestcontributors as $uid => $count) {
1457
        $url   = XOOPS_URL . '/userinfo.php?uid=' . $uid;
1458
        $class = ($class === 'even') ? 'odd' : 'even';
1459
        printf("<tr class='" . $class . "'><td align='left'><a href='%s' target ='_blank'>%s</a></td><td align='right'>%u</td></tr>\n", $url, $myts->htmlSpecialChars($news->uname($uid)), $count);
1460
    }
1461
    echo '</table></div><br />';
1462
}
1463
1464
/**
1465
 * Metagen
1466
 *
1467
 * Metagen is a system that can help you to have your page best indexed by search engines.
1468
 * Except if you type meta keywords and meta descriptions yourself, the module will automatically create them.
1469
 * From here you can also manage some other options like the maximum number of meta keywords to create and
1470
 * the keywords apparition's order.
1471
 */
1472
function Metagen()
1473
{
1474
    include_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
1475
    global $xoopsModule, $xoopsConfig, $xoopsModuleConfig, $cfg;
1476
    xoops_cp_header();
1477
    $myts = MyTextSanitizer::getInstance();
0 ignored issues
show
$myts is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
1478 View Code Duplication
    if (file_exists(XOOPS_ROOT_PATH . '/modules/news/language/' . $xoopsConfig['language'] . '/main.php')) {
1479
        include_once XOOPS_ROOT_PATH . '/modules/news/language/' . $xoopsConfig['language'] . '/main.php';
1480
    } else {
1481
        include_once XOOPS_ROOT_PATH . '/modules/news/language/english/main.php';
1482
    }
1483
    $metagenAdmin = new ModuleAdmin();
1484
    echo $metagenAdmin->addNavigation('index.php?op=metagen');
1485
    //echo "<h1>"._AM_NEWS_METAGEN."</h1>";
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% 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...
1486
    echo _AM_NEWS_METAGEN_DESC . '<br /><br />';
1487
1488
    // Metagen Options
1489
    $registry = new news_registryfile('news_metagen_options.txt');
1490
    $content  = '';
1491
    $content  = $registry->getfile();
1492 View Code Duplication
    if (xoops_trim($content) != '') {
1493
        list($keywordscount, $keywordsorder) = explode(',', $content);
1494
    } else {
1495
        $keywordscount = $cfg['meta_keywords_count'];
1496
        $keywordsorder = $cfg['meta_keywords_order'];
1497
    }
1498
    $sform = new XoopsThemeForm(_OPTIONS, 'metagenoptions', XOOPS_URL . '/modules/news/admin/index.php', 'post');
1499
    $sform->addElement(new XoopsFormHidden('op', 'metagenoptions'), false);
1500
    $sform->addElement(new XoopsFormText(_AM_NEWS_META_KEYWORDS_CNT, 'keywordscount', 4, 6, $keywordscount), true);
1501
    $keywordsorder = new XoopsFormRadio(_AM_NEWS_META_KEYWORDS_ORDER, 'keywordsorder', $keywordsorder);
1502
    $keywordsorder->addOption(0, _AM_NEWS_META_KEYWORDS_INTEXT);
1503
    $keywordsorder->addOption(1, _AM_NEWS_META_KEYWORDS_FREQ1);
1504
    $keywordsorder->addOption(2, _AM_NEWS_META_KEYWORDS_FREQ2);
1505
    $sform->addElement($keywordsorder, false);
1506
    $button_tray = new XoopsFormElementTray('', '');
1507
    $submit_btn  = new XoopsFormButton('', 'post', _AM_MODIFY, 'submit');
1508
    $button_tray->addElement($submit_btn);
1509
    $sform->addElement($button_tray);
1510
    $sform->display();
1511
1512
    // Blacklist
1513
    $sform = new XoopsThemeForm(_AM_NEWS_BLACKLIST, 'metagenblacklist', XOOPS_URL . '/modules/news/admin/index.php', 'post');
1514
    $sform->addElement(new XoopsFormHidden('op', 'metagenblacklist'), false);
1515
1516
    // Remove words
1517
    $remove_tray = new XoopsFormElementTray(_AM_NEWS_BLACKLIST);
1518
    $remove_tray->setDescription(_AM_NEWS_BLACKLIST_DESC);
1519
    $blacklist = new XoopsFormSelect('', 'blacklist', '', 5, true);
1520
    $words     = array();
1521
1522
    $metablack = new news_blacklist();
1523
    $words     = $metablack->getAllKeywords();
1524
    if (is_array($words) && count($words) > 0) {
1525
        foreach ($words as $key => $value) {
1526
            $blacklist->addOption($key, $value);
1527
        }
1528
    }
1529
1530
    $blacklist->setDescription(_AM_NEWS_BLACKLIST_DESC);
1531
    $remove_tray->addElement($blacklist, false);
1532
    $remove_btn = new XoopsFormButton('', 'go', _AM_DELETE, 'submit');
1533
    $remove_tray->addElement($remove_btn, false);
1534
    $sform->addElement($remove_tray);
1535
1536
    // Add some words
1537
    $add_tray = new XoopsFormElementTray(_AM_NEWS_BLACKLIST_ADD);
1538
    $add_tray->setDescription(_AM_NEWS_BLACKLIST_ADD_DSC);
1539
    $add_field = new XoopsFormTextArea('', 'keywords', '', 5, 70);
1540
    $add_tray->addElement($add_field, false);
1541
    $add_btn = new XoopsFormButton('', 'go', _AM_ADD, 'submit');
1542
    $add_tray->addElement($add_btn, false);
1543
    $sform->addElement($add_tray);
1544
    $sform->display();
1545
}
1546
1547
/**
1548
 * Save metagen's blacklist words
1549
 */
1550
function MetagenBlackList()
1551
{
1552
    $blacklist = new news_blacklist();
1553
    $words     = $blacklist->getAllKeywords();
1554
1555
    if (isset($_POST['go']) && $_POST['go'] == _AM_DELETE) {
1556
        foreach ($_POST['blacklist'] as $black_id) {
1557
            $blacklist->delete($black_id);
1558
        }
1559
        $blacklist->store();
1560
    } else {
1561
        if (isset($_POST['go']) && $_POST['go'] == _AM_ADD) {
1562
            $p_keywords = $_POST['keywords'];
1563
            $keywords   = explode("\n", $p_keywords);
1564
            foreach ($keywords as $keyword) {
1565
                if (xoops_trim($keyword) != '') {
1566
                    $blacklist->addkeywords(xoops_trim($keyword));
1567
                }
1568
            }
1569
            $blacklist->store();
1570
        }
1571
    }
1572
    redirect_header('index.php?op=metagen', 0, _AM_DBUPDATED);
1573
}
1574
1575
/**
1576
 * Save Metagen Options
1577
 */
1578
function MetagenSaveOptions()
1579
{
1580
    $registry = new news_registryfile('news_metagen_options.txt');
1581
    $registry->savefile((int)$_POST['keywordscount'] . ',' . (int)$_POST['keywordsorder']);
1582
    redirect_header('index.php?op=metagen', 0, _AM_DBUPDATED);
1583
}
1584
1585
// **********************************************************************************************************************************************
1586
// **** Main
1587
// **********************************************************************************************************************************************
1588
$op = 'default';
1589
if (isset($_POST['op'])) {
1590
    $op = $_POST['op'];
1591
} elseif (isset($_GET['op'])) {
1592
    $op = $_GET['op'];
1593
}
1594
$indexAdmin = new ModuleAdmin();
1595
switch ($op) {
1596
    case 'deletefile':
1597
        xoops_cp_header();
1598
        if ($_GET['type'] === 'newsletter') {
1599
            $newsfile = XOOPS_ROOT_PATH . '/uploads/news/newsletter.txt';
1600 View Code Duplication
            if (unlink($newsfile)) {
1601
                redirect_header('index.php', 2, _AM_NEWS_DELETED_OK);
1602
            } else {
1603
                redirect_header('index.php', 2, _AM_NEWS_DELETED_PB);
1604
            }
1605
        } else {
1606
            if ($_GET['type'] === 'xml') {
1607
                $xmlfile = XOOPS_ROOT_PATH . '/uploads/news/stories.xml';
1608 View Code Duplication
                if (unlink($xmlfile)) {
1609
                    redirect_header('index.php', 2, _AM_NEWS_DELETED_OK);
1610
                } else {
1611
                    redirect_header('index.php', 2, _AM_NEWS_DELETED_PB);
1612
                }
1613
            }
1614
        }
1615
        break;
1616
1617
    case 'newarticle':
1618
        xoops_cp_header();
1619
        echo $indexAdmin->addNavigation('index.php?op=newarticle');
1620
        echo '<h4>' . _AM_CONFIG . '</h4>';
1621
        include_once XOOPS_ROOT_PATH . '/class/module.textsanitizer.php';
1622
        newSubmissions();
1623
        autoStories();
1624
        lastStories();
1625
        expStories();
1626
        echo '<br />';
1627
        echo '<h4>' . _AM_POSTNEWARTICLE . '</h4>';
1628
        $type         = 'admin';
1629
        $title        = '';
1630
        $topicdisplay = 0;
1631
        $topicalign   = 'R';
1632
        $ihome        = 0;
1633
        $hometext     = '';
1634
        $bodytext     = '';
1635
        $notifypub    = 1;
1636
        $nohtml       = 0;
1637
        $approve      = 0;
1638
        $nosmiley     = 0;
1639
        $autodate     = '';
1640
        $expired      = '';
1641
        $topicid      = 0;
1642
        $returnside   = 1;
1643
        $published    = 0;
1644
        $description  = '';
1645
        $keywords     = '';
1646 View Code Duplication
        if (file_exists(XOOPS_ROOT_PATH . '/modules/news/language/' . $xoopsConfig['language'] . '/main.php')) {
1647
            include_once XOOPS_ROOT_PATH . '/modules/news/language/' . $xoopsConfig['language'] . '/main.php';
1648
        } else {
1649
            include_once XOOPS_ROOT_PATH . '/modules/news/language/english/main.php';
1650
        }
1651
1652
        if ($xoopsModuleConfig['autoapprove'] == 1) {
1653
            $approve = 1;
1654
        }
1655
        $approveprivilege = 1;
1656
        include_once XOOPS_ROOT_PATH . '/modules/news/include/storyform.original.php';
1657
        break;
1658
1659
    case 'delete':
1660
        $storyid = 0;
1661 View Code Duplication
        if (isset($_GET['storyid'])) {
1662
            $storyid = (int)$_GET['storyid'];
1663
        } elseif (isset($_POST['storyid'])) {
1664
            $storyid = (int)$_POST['storyid'];
1665
        }
1666
1667
        if (!empty($_POST['ok'])) {
1668
            if (empty($storyid)) {
1669
                redirect_header('index.php?op=newarticle', 2, _AM_EMPTYNODELETE);
1670
            }
1671
            $story = new NewsStory($storyid);
1672
            $story->delete();
1673
            $sfiles   = new sFiles();
1674
            $filesarr = array();
1675
            $filesarr = $sfiles->getAllbyStory($storyid);
1676
            if (count($filesarr) > 0) {
1677
                foreach ($filesarr as $onefile) {
1678
                    $onefile->delete();
1679
                }
1680
            }
1681
            xoops_comment_delete($xoopsModule->getVar('mid'), $storyid);
1682
            xoops_notification_deletebyitem($xoopsModule->getVar('mid'), 'story', $storyid);
1683
            news_updateCache();
1684
            redirect_header('index.php?op=newarticle', 1, _AM_DBUPDATED);
1685
        } else {
1686
            $story = new NewsStory($storyid);
1687
            xoops_cp_header();
1688
            echo '<h4>' . _AM_CONFIG . '</h4>';
1689
            xoops_confirm(array('op' => 'delete', 'storyid' => $storyid, 'ok' => 1), 'index.php', _AM_RUSUREDEL . '<br />' . $story->title());
1690
        }
1691
        break;
1692
1693
    case 'topicsmanager':
1694
        topicsmanager();
1695
        break;
1696
1697
    case 'addTopic':
1698
        addTopic();
1699
        break;
1700
1701
    case 'delTopic':
1702
        delTopic();
1703
        break;
1704
1705
    case 'modTopicS':
1706
        modTopicS();
1707
        break;
1708
1709
    case 'edit':
1710 View Code Duplication
        if (file_exists(XOOPS_ROOT_PATH . '/modules/news/language/' . $xoopsConfig['language'] . '/main.php')) {
1711
            include_once XOOPS_ROOT_PATH . '/modules/news/language/' . $xoopsConfig['language'] . '/main.php';
1712
        } else {
1713
            include_once XOOPS_ROOT_PATH . '/modules/news/language/english/main.php';
1714
        }
1715
        include_once XOOPS_ROOT_PATH . '/modules/news/submit.php';
1716
        break;
1717
1718
    case 'prune':
1719
        PruneManager();
1720
        break;
1721
1722
    case 'confirmbeforetoprune':
1723
        ConfirmBeforeToPrune();
1724
        break;
1725
1726
    case 'prunenews';
0 ignored issues
show
CASE statements must be defined using a colon

As per the PSR-2 coding standard, case statements should not be wrapped in curly braces. There is no need for braces, since each case is terminated by the next break.

switch ($expr) {
    case "A": { //wrong
        doSomething();
        break;
    }
    case "B": //right
        doSomething();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
1727
        PruneNews();
1728
        break;
1729
1730
    case 'export':
1731
        NewsExport();
1732
        break;
1733
1734
    case 'launchexport':
1735
        LaunchExport();
1736
        break;
1737
1738
    case 'configurenewsletter':
1739
        Newsletter();
1740
        break;
1741
1742
    case 'launchnewsletter':
1743
        LaunchNewsletter();
1744
        break;
1745
1746
    case 'stats':
1747
        Stats();
1748
        break;
1749
1750
    case 'metagen':
1751
        Metagen();
1752
        break;
1753
1754
    case 'metagenoptions':
1755
        MetagenSaveOptions();
1756
        break;
1757
1758
    case 'metagenblacklist':
1759
        MetagenBlackList();
1760
        break;
1761
1762
    case 'verifydb':
1763
        xoops_cp_header();
1764
        //news_adminmenu();
1765
        $tbllist = $xoopsDB->prefix('news_stories') . ',' . $xoopsDB->prefix('news_topics') . ',' . $xoopsDB->prefix('news_stories_files') . ',' . $xoopsDB->prefix('news_stories_votedata');
1766
        $xoopsDB->queryF('OPTIMIZE TABLE ' . $tbllist);
1767
        $xoopsDB->queryF('CHECK TABLE ' . $tbllist);
1768
        $xoopsDB->queryF('ANALYZE TABLE ' . $tbllist);
1769
        redirect_header('index.php', 3, _AM_DBUPDATED);
1770
        exit;
1771
        break;
1772
1773
    case 'default':
1774
    default:
1775
        xoops_cp_header();
1776
1777
        $folder = array(
1778
            XOOPS_ROOT_PATH . '/uploads/news/',
1779
            XOOPS_ROOT_PATH . '/uploads/news/file',
1780
            XOOPS_ROOT_PATH . '/uploads/news/image');
1781
1782
        $topicsHandler  = xoops_getModuleHandler('news_topics', 'news');
1783
        $storiesHandler = xoops_getModuleHandler('news_stories', 'news');
1784
1785
        //compte "total"
1786
        $count_stories = $storiesHandler->getCount();
1787
        //compte "attente"
1788
        $criteria = new CriteriaCompo();
1789
        $criteria->add(new Criteria('ihome', 1));
1790
        $stories_ihome = $storiesHandler->getCount($criteria);
1791
1792
        $criteria = new CriteriaCompo();
1793
        $criteria->add(new Criteria('published', 0, '>'));
1794
        $stories_published = $storiesHandler->getCount($criteria);
1795
1796
        $stories_need_approval = $count_stories - $stories_published;
1797
1798
        $criteria = new CriteriaCompo();
1799
        $criteria->add(new Criteria('expired', 0, '>'));
1800
        $criteria->add(new Criteria('expired', time(), '<'));
1801
        $stories_expired = $storiesHandler->getCount($criteria);
1802
1803
        $criteria = new CriteriaCompo();
1804
        $criteria->add(new Criteria('expired', 0, '>'));
1805
        $criteria->add(new Criteria('expired', time(), '>'));
1806
        $stories_expired_soon = $storiesHandler->getCount($criteria);
1807
1808
        //compte "total"
1809
        $count_topics = $topicsHandler->getCount();
1810
        //compte "attente"
1811
        $criteria = new CriteriaCompo();
1812
        $criteria->add(new Criteria('menu', 1));
1813
        $topics_menu = $topicsHandler->getCount($criteria);
1814
1815
        $clr_count_stories = ($count_stories == 0) ? 'red' : 'green';
1816
        $clr_count_topics  = ($count_topics == 0) ? 'red' : 'green';
1817
        $clr_ihome_stories = ($stories_ihome == 0) ? 'red' : 'green';
1818
        $clr_menu_topics   = ($topics_menu == 0) ? 'red' : 'green';
1819
1820
        $clr_published_stories         = ($stories_published == 0) ? 'red' : 'green';
1821
        $clr_need_approval_stories     = ($stories_need_approval == 0) ? 'green' : 'red';
1822
        $clr_expired_stories           = ($stories_expired == 0) ? 'red' : 'green';
1823
        $clr_need_expired_soon_stories = ($stories_expired_soon == 0) ? 'red' : 'green';
1824
1825
        $indexAdmin->addInfoBox(_AM_NEWS_STATISTICS);
1826
        $indexAdmin->addInfoBoxLine(_AM_NEWS_STATISTICS, _AM_NEWS_THEREARE_TOPICS, $count_topics, $clr_count_topics);
1827
        $indexAdmin->addInfoBoxLine(_AM_NEWS_STATISTICS, _AM_NEWS_THEREARE_TOPICS_ONLINE, $topics_menu, $clr_menu_topics);
1828
        $indexAdmin->addInfoBoxLine(_AM_NEWS_STATISTICS, _AM_NEWS_THEREARE_STORIES, $count_stories, $clr_count_stories);
1829
        $indexAdmin->addInfoBoxLine(_AM_NEWS_STATISTICS, _AM_NEWS_THEREARE_STORIES_ONLINE, $stories_ihome, $clr_ihome_stories);
1830
1831
        $indexAdmin->addInfoBoxLine(_AM_NEWS_STATISTICS, _AM_NEWS_THEREARE_STORIES_APPROVED, $stories_published, $clr_ihome_stories);
1832
        $indexAdmin->addInfoBoxLine(_AM_NEWS_STATISTICS, _AM_NEWS_THEREARE_STORIES_NEED_APPROVAL, $stories_need_approval, $clr_need_approval_stories);
1833
        $indexAdmin->addInfoBoxLine(_AM_NEWS_STATISTICS, _AM_NEWS_THEREARE_STORIES_EXPIRED, $stories_expired, $clr_expired_stories);
1834
        $indexAdmin->addInfoBoxLine(_AM_NEWS_STATISTICS, _AM_NEWS_THEREARE_STORIES_EXPIRED_SOON, $stories_expired_soon, $clr_need_expired_soon_stories);
1835
1836
        foreach (array_keys($folder) as $i) {
1837
            $indexAdmin->addConfigBoxLine($folder[$i], 'folder');
1838
            $indexAdmin->addConfigBoxLine(array($folder[$i], '777'), 'chmod');
1839
        }
1840
1841
        echo $indexAdmin->addNavigation(basename(__FILE__));
1842
        echo $indexAdmin->renderIndex();
1843
1844
        break;
1845
1846
}
1847
include_once __DIR__ . '/admin_footer.php';
1848