Passed
Push — master ( 6d0bec...700d12 )
by Michael
05:09 queued 02:42
created

index.php ➔ modTopicS()   F

Complexity

Conditions 17
Paths 1280

Size

Total Lines 93

Duplication

Lines 39
Ratio 41.94 %

Importance

Changes 0
Metric Value
cc 17
nc 1280
nop 0
dl 39
loc 93
rs 0.9927
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
//
3
// ------------------------------------------------------------------------ //
4
// XOOPS - PHP Content Management System                                    //
5
// Copyright (c) 2000-2020 XOOPS.org                                             //
6
// <https://xoops.org>                                                  //
7
// ------------------------------------------------------------------------ //
8
// This program is free software; you can redistribute it and/or modify     //
9
// it under the terms of the GNU General Public License as published by     //
10
// the Free Software Foundation; either version 2 of the License, or        //
11
// (at your option) any later version.                                      //
12
//                                                                          //
13
// You may not change or alter any portion of this comment or credits       //
14
// of supporting developers from this source code or any supporting         //
15
// source code which is considered copyrighted (c) material of the          //
16
// original comment or credit authors.                                      //
17
//                                                                          //
18
// This program is distributed in the hope that it will be useful,          //
19
// but WITHOUT ANY WARRANTY; without even the implied warranty of           //
20
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            //
21
// GNU General Public License for more details.                             //
22
//                                                                          //
23
// You should have received a copy of the GNU General Public License        //
24
// along with this program; if not, write to the Free Software              //
25
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA //
26
// ------------------------------------------------------------------------ //
27
28
use Xmf\Module\Admin;
29
use Xmf\Request;
30
use XoopsModules\News;
31
use XoopsModules\News\Blacklist;
32
use XoopsModules\News\Files;
33
use XoopsModules\News\Helper;
34
use XoopsModules\News\NewsStory;
35
use XoopsModules\News\NewsTopic;
36
use XoopsModules\News\Registryfile;
37
38
require_once __DIR__ . '/admin_header.php';
39
// require_once XOOPS_ROOT_PATH . '/modules/news/class/xoopstopic.php';
40
require_once XOOPS_ROOT_PATH . '/class/xoopslists.php';
41
require_once XOOPS_ROOT_PATH . '/modules/news/config.php';
42
//require_once XOOPS_ROOT_PATH . '/modules/news/class/class.newsstory.php';
43
//require_once XOOPS_ROOT_PATH . '/modules/news/class/class.newstopic.php';
44
//require_once XOOPS_ROOT_PATH . '/modules/news/class/class.sfiles.php';
45
//require_once XOOPS_ROOT_PATH . '/modules/news/class/blacklist.php';
46
//require_once XOOPS_ROOT_PATH . '/modules/news/class/registryfile.php';
47
require_once XOOPS_ROOT_PATH . '/class/uploader.php';
48
require_once XOOPS_ROOT_PATH . '/class/pagenav.php';
49
require_once XOOPS_ROOT_PATH . '/modules/news/admin/functions.php';
50
51
/** @var \XoopsModules\News\Helper $helper */
52
$helper = Helper::getInstance();
53
54
// require_once XOOPS_ROOT_PATH . '/modules/news/class/tree.php';
55
$dateformat  = News\Utility::getModuleOption('dateformat');
56
$myts        = \MyTextSanitizer::getInstance();
57
$topicscount = 0;
58
59
$storiesTableName = $xoopsDB->prefix('news_stories');
60
if (!News\Utility::existField('picture', $storiesTableName)) {
61
    News\Utility::addField('`picture` VARCHAR( 50 ) NOT NULL', $storiesTableName);
62
}
63
64
/**
65
 * Show new submissions
66
 *
67
 * This list can be view in the module's admin when you click on the tab named "Post/Edit News"
68
 * Submissions are news that was submit by users but who are not approved, so you need to edit
69
 * them to approve them.
70
 * Actually you can see the the story's title, the topic, the posted date, the author and a
71
 * link to delete the story. If you click on the story's title, you will be able to edit the news.
72
 * The table contains the last x new submissions.
73
 * The system's block called "Waiting Contents" is listing the number of those news.
74
 */
75
function newSubmissions()
76
{
77
    global $dateformat, $pathIcon16;
78
    $start       = Request::getInt('startnew', 0, 'GET');
79
    $newsubcount = NewsStory:: getAllStoriesCount(3, false);
80
    $storyarray  = NewsStory:: getAllSubmitted(News\Utility::getModuleOption('storycountadmin'), true, News\Utility::getModuleOption('restrictindex'), $start);
0 ignored issues
show
Bug introduced by
It seems like XoopsModules\News\Utilit...tion('storycountadmin') can also be of type boolean; however, parameter $limit of XoopsModules\News\NewsStory::getAllSubmitted() does only seem to accept integer, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

80
    $storyarray  = NewsStory:: getAllSubmitted(/** @scrutinizer ignore-type */ News\Utility::getModuleOption('storycountadmin'), true, News\Utility::getModuleOption('restrictindex'), $start);
Loading history...
81
    if (count($storyarray) > 0) {
82
        $pagenav = new \XoopsPageNav($newsubcount, News\Utility::getModuleOption('storycountadmin'), $start, 'startnew', 'op=newarticle');
0 ignored issues
show
Bug introduced by
It seems like XoopsModules\News\Utilit...tion('storycountadmin') can also be of type boolean; however, parameter $items_perpage of XoopsPageNav::__construct() does only seem to accept integer, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

82
        $pagenav = new \XoopsPageNav($newsubcount, /** @scrutinizer ignore-type */ News\Utility::getModuleOption('storycountadmin'), $start, 'startnew', 'op=newarticle');
Loading history...
83
        news_collapsableBar('newsub', 'topnewsubicon');
84
        echo "<img onclick=\"toggle('toptable'); toggleIcon('toptableicon');\" id='topnewsubicon' name='topnewsubicon' src='" . $pathIcon16 . "/close12.gif' alt=''></a>&nbsp;" . _AM_NEWSUB . '</h4>';
85
        echo "<div id='newsub'>";
86
        echo '<br>';
87
        echo "<div class='center;'><table width='100%' cellspacing='1' cellpadding='3' border='0' class='outer'><tr class='bg3'><th align='center'>"
88
             . _AM_TITLE
89
             . "</th><th align='center'>"
90
             . _AM_TOPIC
91
             . "</th><th align='center'>"
92
             . _AM_POSTED
93
             . "</th><th align='center'>"
94
             . _AM_POSTER
95
             . "</th><th align='center'>"
96
             . _AM_NEWS_ACTION
97
             . "</th></tr>\n";
98
        $class = '';
99
        foreach ($storyarray as $newstory) {
100
            $class = ('even' === $class) ? 'odd' : 'even';
101
            echo "<tr class='" . $class . "'><td align='left'>\n";
102
            $title = $newstory->title();
103
            if (!isset($title) || ('' === $title)) {
104
                echo "<a href='" . XOOPS_URL . '/modules/news/admin/index.php?op=edit&amp;returnside=1&amp;storyid=' . $newstory->storyid() . "'>" . _MD_NEWS_NOSUBJECT . "</a>\n";
105
            } else {
106
                echo "&nbsp;<a href='" . XOOPS_URL . '/modules/news/submit.php?returnside=1&amp;op=edit&amp;storyid=' . $newstory->storyid() . "'>" . $title . "</a>\n";
107
            }
108
            echo '</td><td>'
109
                 . $newstory->topic_title()
110
                 . "</td><td align='center' class='nw'>"
111
                 . formatTimestamp($newstory->created(), $dateformat)
112
                 . "</td><td align='center'><a href='"
113
                 . XOOPS_URL
114
                 . '/userinfo.php?uid='
115
                 . $newstory->uid()
116
                 . "'>"
117
                 . $newstory->uname()
118
                 . "</a></td><td align='center'><a href='"
119
                 . XOOPS_URL
120
                 . '/modules/news/submit.php?returnside=1&amp;op=edit&amp;storyid='
121
                 . $newstory->storyid()
122
                 . "'><img src='"
123
                 . $pathIcon16
124
                 . "/edit.png' title='"
125
                 . _AM_EDIT
126
                 . "'></a><a href='"
127
                 . XOOPS_URL
128
                 . '/modules/news/admin/index.php?op=delete&amp;storyid='
129
                 . $newstory->storyid()
130
                 . "'><img src='"
131
                 . $pathIcon16
132
                 . "/delete.png' title='"
133
                 . _AM_DELETE
134
                 . "'></a></td></tr>\n";
135
        }
136
137
        echo '</table></div>';
138
        echo "<div align='right'>" . $pagenav->renderNav() . '</div><br>';
139
        echo '<br></div><br>';
140
    }
141
}
142
143
/**
144
 * Shows all automated stories
145
 *
146
 * Automated stories are stories that have a publication's date greater than "now"
147
 * This list can be view in the module's admin when you click on the tab named "Post/Edit News"
148
 * Actually you can see the story's ID, its title, the topic, the author, the
149
 * programmed date and time, the expiration's date  and two links. The first link is
150
 * used to edit the story while the second is used to remove the story.
151
 * The list only contains the last (x) automated news
152
 */
153
function autoStories()
154
{
155
    global $dateformat, $pathIcon16;
156
157
    $start        = Request::getInt('startauto', 0, 'GET');
158
    $storiescount = NewsStory:: getAllStoriesCount(2, false);
159
    $storyarray   = NewsStory:: getAllAutoStory(News\Utility::getModuleOption('storycountadmin'), true, $start);
0 ignored issues
show
Bug introduced by
It seems like XoopsModules\News\Utilit...tion('storycountadmin') can also be of type boolean; however, parameter $limit of XoopsModules\News\NewsStory::getAllAutoStory() does only seem to accept integer, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

159
    $storyarray   = NewsStory:: getAllAutoStory(/** @scrutinizer ignore-type */ News\Utility::getModuleOption('storycountadmin'), true, $start);
Loading history...
160
    $class        = '';
161
    if (count($storyarray) > 0) {
162
        $pagenav = new \XoopsPageNav($storiescount, News\Utility::getModuleOption('storycountadmin'), $start, 'startauto', 'op=newarticle');
0 ignored issues
show
Bug introduced by
It seems like XoopsModules\News\Utilit...tion('storycountadmin') can also be of type boolean; however, parameter $items_perpage of XoopsPageNav::__construct() does only seem to accept integer, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

162
        $pagenav = new \XoopsPageNav($storiescount, /** @scrutinizer ignore-type */ News\Utility::getModuleOption('storycountadmin'), $start, 'startauto', 'op=newarticle');
Loading history...
163
        news_collapsableBar('autostories', 'topautostories');
164
        echo "<img onclick=\"toggle('toptable'); toggleIcon('toptableicon');\" id='topautostories' name='topautostories' src='" . $pathIcon16 . "/close12.gif' alt=''></a>&nbsp;" . _AM_AUTOARTICLES . '</h4>';
165
        echo "<div id='autostories'>";
166
        echo '<br>';
167
        echo "<div class='center;'>\n";
168
        echo "<table width='100%' cellspacing='1' cellpadding='3' border='0' class='outer'><tr class='bg3'><th align='center'>"
169
             . _AM_STORYID
170
             . "</th><th align='center'>"
171
             . _AM_TITLE
172
             . "</th><th align='center'>"
173
             . _AM_TOPIC
174
             . "</th><th align='center'>"
175
             . _AM_POSTER
176
             . "</th><th align='center' class='nw'>"
177
             . _AM_PROGRAMMED
178
             . "</th><th align='center' class='nw'>"
179
             . _AM_EXPIRED
180
             . "</th><th align='center'>"
181
             . _AM_NEWS_ACTION
182
             . '</th></tr>';
183
        foreach ($storyarray as $autostory) {
184
            $topic  = $autostory->topic();
185
            $expire = ($autostory->expired() > 0) ? formatTimestamp($autostory->expired(), $dateformat) : '';
186
            $class  = ('even' === $class) ? 'odd' : 'even';
187
            echo "<tr class='" . $class . "'>";
188
            echo "<td align='center'><b>"
189
                 . $autostory->storyid()
190
                 . "</b>
191
                </td><td align='left'><a href='"
192
                 . XOOPS_URL
193
                 . '/modules/news/article.php?storyid='
194
                 . $autostory->storyid()
195
                 . "'>"
196
                 . $autostory->title()
197
                 . "</a>
198
                </td><td align='center'>"
199
                 . $topic->topic_title()
200
                 . "
201
                </td><td align='center'><a href='"
202
                 . XOOPS_URL
203
                 . '/userinfo.php?uid='
204
                 . $autostory->uid()
205
                 . "'>"
206
                 . $autostory->uname()
207
                 . "</a></td><td align='center' class='nw'>"
208
                 . formatTimestamp($autostory->published(), $dateformat)
209
                 . "</td><td align='center'>"
210
                 . $expire
211
                 . "</td><td align='center'><a href='"
212
                 . XOOPS_URL
213
                 . '/modules/news/submit.php?returnside=1&amp;op=edit&amp;storyid='
214
                 . $autostory->storyid()
215
                 . "'><img src='"
216
                 . $pathIcon16
217
                 . "/edit.png' title="
218
                 . _AM_EDIT
219
                 . "> </a> <a href='"
220
                 . XOOPS_URL
221
                 . '/modules/news/admin/index.php?op=delete&amp;storyid='
222
                 . $autostory->storyid()
223
                 . "'><img src='"
224
                 . $pathIcon16
225
                 . "/delete.png' title='"
226
                 . _AM_DELETE
227
                 . "'></a>";
228
229
            echo "</td></tr>\n";
230
        }
231
        echo '</table></div>';
232
        echo "<div align='right'>" . $pagenav->renderNav() . '</div><br>';
233
        echo '</div><br>';
234
    }
235
}
236
237
/**
238
 * Shows last x published stories
239
 *
240
 * This list can be view in the module's admin when you click on the tab named "Post/Edit News"
241
 * Actually you can see the the story's ID, its title, the topic, the author, the number of hits
242
 * and two links. The first link is used to edit the story while the second is used to remove the story.
243
 * The table only contains the last X published stories.
244
 * You can modify the number of visible stories with the module's option named
245
 * "Number of new articles to display in admin area".
246
 * As the number of displayed stories is limited, below this list you can find a text box
247
 * that you can use to enter a story's Id, then with the scrolling list you can select
248
 * if you want to edit or delete the story.
249
 */
250
function lastStories()
251
{
252
    global $dateformat, $pathIcon16;
253
    news_collapsableBar('laststories', 'toplaststories');
254
    echo "<img onclick=\"toggle('toptable'); toggleIcon('toptableicon');\" id='toplaststories' name='toplaststories' src='" . $pathIcon16 . "/close12.gif' alt=''></a>&nbsp;" . sprintf(_AM_LAST10ARTS, News\Utility::getModuleOption('storycountadmin')) . '</h4>';
255
    echo "<div id='laststories'>";
256
    echo '<br>';
257
    echo "<div class='center;'>";
258
    $start        = Request::getInt('start', 0, 'GET');
259
    $storyarray   = NewsStory:: getAllPublished(News\Utility::getModuleOption('storycountadmin'), $start, false, 0, 1);
0 ignored issues
show
Bug introduced by
It seems like XoopsModules\News\Utilit...tion('storycountadmin') can also be of type boolean; however, parameter $limit of XoopsModules\News\NewsStory::getAllPublished() does only seem to accept integer, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

259
    $storyarray   = NewsStory:: getAllPublished(/** @scrutinizer ignore-type */ News\Utility::getModuleOption('storycountadmin'), $start, false, 0, 1);
Loading history...
260
    $storiescount = NewsStory:: getAllStoriesCount(4, false);
261
    $pagenav      = new \XoopsPageNav($storiescount, News\Utility::getModuleOption('storycountadmin'), $start, 'start', 'op=newarticle');
0 ignored issues
show
Bug introduced by
It seems like XoopsModules\News\Utilit...tion('storycountadmin') can also be of type boolean; however, parameter $items_perpage of XoopsPageNav::__construct() does only seem to accept integer, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

261
    $pagenav      = new \XoopsPageNav($storiescount, /** @scrutinizer ignore-type */ News\Utility::getModuleOption('storycountadmin'), $start, 'start', 'op=newarticle');
Loading history...
262
    $class        = '';
263
    echo "<table width='100%' cellspacing='1' cellpadding='3' border='0' class='outer'><tr class='bg3'><th align='center'>"
264
         . _AM_STORYID
265
         . "</th><th align='center'>"
266
         . _AM_TITLE
267
         . "</th><th align='center'>"
268
         . _AM_TOPIC
269
         . "</th><th align='center'>"
270
         . _AM_POSTER
271
         . "</th><th align='center' class='nw'>"
272
         . _AM_PUBLISHED
273
         . "</th><th align='center' class='nw'>"
274
         . _AM_HITS
275
         . "</th><th align='center'>"
276
         . _AM_NEWS_ACTION
277
         . '</th></tr>';
278
    foreach ($storyarray as $eachstory) {
279
        $published = formatTimestamp($eachstory->published(), $dateformat);
280
        // $expired = ( $eachstory -> expired() > 0 ) ? formatTimestamp($eachstory->expired(),$dateformat) : '---';
281
        $topic = $eachstory->topic();
282
        $class = ('even' === $class) ? 'odd' : 'even';
283
        echo "<tr class='" . $class . "'>";
284
        echo "<td align='center'><b>" . $eachstory->storyid() . "</b>
285
            </td><td align='left'><a href='" . XOOPS_URL . '/modules/news/article.php?storyid=' . $eachstory->storyid() . "'>" . $eachstory->title() . "</a>
286
            </td><td align='center'>" . $topic->topic_title() . "
287
            </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'>
288
            <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>
289
            <a href='" . XOOPS_URL . '/modules/news/admin/index.php?op=delete&amp;storyid=' . $eachstory->storyid() . "'><img src='" . $pathIcon16 . "/delete.png' title='" . _AM_DELETE . "'></a>";
290
291
        echo "</td></tr>\n";
292
    }
293
    echo '</table><br>';
294
    echo "<div align='right'>" . $pagenav->renderNav() . '</div><br>';
295
296
    echo "<form action='index.php' method='get'>" . _AM_STORYID . " <input type='text' name='storyid' size='10'>
297
        <select name='op'>
298
            <option value='edit' selected>" . _AM_EDIT . "</option>
299
            <option value='delete'>" . _AM_DELETE . "</option>
300
        </select>
301
        <input type='hidden' name='returnside' value='1'>
302
        <input type='submit' value='" . _AM_GO . "'>
303
        </form>
304
    </div>";
305
    echo '</div><br>';
306
}
307
308
/**
309
 * Display a list of the expired stories
310
 *
311
 * This list can be view in the module's admin when you click on the tab named "Post/Edit News"
312
 * Actually you can see the story's ID, the title, the topic, the author,
313
 * the creation and expiration's date and you have two links, one to delete
314
 * the story and the other to edit the story.
315
 * The table only contains the last X expired stories.
316
 * You can modify the number of visible stories with the module's option named
317
 * "Number of new articles to display in admin area".
318
 * As the number of displayed stories is limited, below this list you can find a text box
319
 * that you can use to enter a story's Id, then with the scrolling list you can select
320
 * if you want to edit or delete the story.
321
 */
322
function expStories()
323
{
324
    global $dateformat, $pathIcon16;
325
    $start        = Request::getInt('startexp', 0, 'GET');
326
    $expiredcount = NewsStory:: getAllStoriesCount(1, false);
327
    $storyarray   = NewsStory:: getAllExpired(News\Utility::getModuleOption('storycountadmin'), $start, 0, 1);
0 ignored issues
show
Bug introduced by
It seems like XoopsModules\News\Utilit...tion('storycountadmin') can also be of type boolean; however, parameter $limit of XoopsModules\News\NewsStory::getAllExpired() does only seem to accept integer, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

327
    $storyarray   = NewsStory:: getAllExpired(/** @scrutinizer ignore-type */ News\Utility::getModuleOption('storycountadmin'), $start, 0, 1);
Loading history...
328
    $pagenav      = new \XoopsPageNav($expiredcount, News\Utility::getModuleOption('storycountadmin'), $start, 'startexp', 'op=newarticle');
0 ignored issues
show
Bug introduced by
It seems like XoopsModules\News\Utilit...tion('storycountadmin') can also be of type boolean; however, parameter $items_perpage of XoopsPageNav::__construct() does only seem to accept integer, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

328
    $pagenav      = new \XoopsPageNav($expiredcount, /** @scrutinizer ignore-type */ News\Utility::getModuleOption('storycountadmin'), $start, 'startexp', 'op=newarticle');
Loading history...
329
330
    if (count($storyarray) > 0) {
331
        $class = '';
332
        news_collapsableBar('expstories', 'topexpstories');
333
        echo "<img onclick=\"toggle('toptable'); toggleIcon('toptableicon');\" id='topexpstories' name='topexpstories' src='" . $pathIcon16 . "/close12.gif' alt=''></a>&nbsp;" . _AM_EXPARTS . '</h4>';
334
        echo "<div id='expstories'>";
335
        echo '<br>';
336
        echo "<div class='center;'>";
337
        echo "<table width='100%' cellspacing='1' cellpadding='3' border='0' class='outer'><tr class='bg3'><th align='center'>"
338
             . _AM_STORYID
339
             . "</th><th align='center'>"
340
             . _AM_TITLE
341
             . "</th><th align='center'>"
342
             . _AM_TOPIC
343
             . "</th><th align='center'>"
344
             . _AM_POSTER
345
             . "</th><th align='center' class='nw'>"
346
             . _AM_CREATED
347
             . "</th><th align='center' class='nw'>"
348
             . _AM_EXPIRED
349
             . "</th><th align='center'>"
350
             . _AM_NEWS_ACTION
351
             . '</th></tr>';
352
        foreach ($storyarray as $eachstory) {
353
            $created = formatTimestamp($eachstory->created(), $dateformat);
354
            $expired = formatTimestamp($eachstory->expired(), $dateformat);
355
            $topic   = $eachstory->topic();
356
            // added exired value field to table
357
            $class = ('even' === $class) ? 'odd' : 'even';
358
            echo "<tr class='" . $class . "'>";
359
            echo "<td align='center'><b>" . $eachstory->storyid() . "</b>
360
                </td><td align='left'><a href='" . XOOPS_URL . '/modules/news/article.php?returnside=1&amp;storyid=' . $eachstory->storyid() . "'>" . $eachstory->title() . "</a>
361
                </td><td align='center'>" . $topic->topic_title() . "
362
                </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'>
363
                <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>
364
                <a href='" . XOOPS_URL . '/modules/news/admin/index.php?op=delete&amp;storyid=' . $eachstory->storyid() . "'><img src='" . $pathIcon16 . "/delete.png' title='" . _AM_DELETE . "'></a>";
365
366
            echo "</td></tr>\n";
367
        }
368
        echo '</table><br>';
369
        echo "<div align='right'>" . $pagenav->renderNav() . '</div><br>';
370
        echo "<form action='index.php' method='get'>
371
            " . _AM_STORYID . " <input type='text' name='storyid' size='10'>
372
            <select name='op'>
373
                <option value='edit' selected>" . _AM_EDIT . "</option>
374
                <option value='delete'>" . _AM_DELETE . "</option>
375
            </select>
376
            <input type='hidden' name='returnside' value='1'>
377
            <input type='submit' value='" . _AM_GO . "'>
378
            </form>
379
        </div>";
380
        echo '</div><br>';
381
    }
382
}
383
384
/**
385
 * Delete (purge/prune) old stories
386
 *
387
 * You can use this function in the module's admin when you click on the tab named "Prune News"
388
 * It's useful to remove old stories. It is, of course, recommended
389
 * to backup (or export) your news before to purge news.
390
 * You must first specify a date. This date will be used as a reference, everything
391
 * that was published before this date will be deleted.
392
 * The option "Only remove stories who have expired" will enable you to only remove
393
 * expired stories published before the given date.
394
 * Finally, you can select the topics inside wich you will remove news.
395
 * Once you have set all the parameters, the script will first show you a confirmation's
396
 * message with the number of news that will be removed.
397
 * Note, the topics are not deleted (even if there are no more news inside them).
398
 */
399
function setPruneManager()
400
{
401
    require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
402
    xoops_cp_header();
403
    $adminObject = Admin::getInstance();
404
    $adminObject->displayNavigation('index.php?op=prune');
405
    echo '<br><br><br>';
406
    $sform = new \XoopsThemeForm(_AM_NEWS_PRUNENEWS, 'pruneform', XOOPS_URL . '/modules/news/admin/index.php', 'post', true);
407
    $sform->addElement(new \XoopsFormTextDateSelect(_AM_NEWS_PRUNE_BEFORE, 'prune_date', 15, time()), true);
408
    $onlyexpired = new \XoopsFormCheckBox('', 'onlyexpired');
409
    $onlyexpired->addOption(1, _AM_NEWS_PRUNE_EXPIREDONLY);
410
    $sform->addElement($onlyexpired, false);
411
    $sform->addElement(new \XoopsFormHidden('op', 'confirmbeforetoprune'), false);
412
    $topiclist  = new \XoopsFormSelect(_AM_NEWS_PRUNE_TOPICS, 'pruned_topics', '', 5, true);
413
    $topics_arr = [];
0 ignored issues
show
Unused Code introduced by
The assignment to $topics_arr is dead and can be removed.
Loading history...
414
    $xt         = new NewsTopic();
415
    $allTopics  = $xt->getAllTopics(false); // The webmaster can see everything
416
    $topic_tree = new \XoopsModules\News\ObjectTree($allTopics, 'topic_id', 'topic_pid');
417
    $topics_arr = $topic_tree->getAllChild(0);
418
    if (count($topics_arr)) {
419
        foreach ($topics_arr as $onetopic) {
420
            $topiclist->addOption($onetopic->topic_id(), $onetopic->topic_title());
421
        }
422
    }
423
    $topiclist->setDescription(_AM_NEWS_EXPORT_PRUNE_DSC);
424
    $sform->addElement($topiclist, false);
425
    $buttonTray = new \XoopsFormElementTray('', '');
426
    $submit_btn = new \XoopsFormButton('', 'post', _SUBMIT, 'submit');
427
    $buttonTray->addElement($submit_btn);
428
    $sform->addElement($buttonTray);
429
    $sform->display();
430
}
431
432
// A confirmation is asked before to prune stories
433
function confirmBeforePrune()
434
{
435
    global $dateformat;
436
    $story = new NewsStory();
437
    xoops_cp_header();
438
    $topiclist = '';
439
    if (Request::hasVar('pruned_topics', 'POST')) {
440
        $topiclist = implode(',', $_POST['pruned_topics']);
441
    }
442
    echo '<h4>' . _AM_NEWS_PRUNENEWS . '</h4>';
443
    $expired = 0;
444
    if (Request::hasVar('onlyexpired', 'POST')) {
445
        $expired = Request::getInt('onlyexpired', 0, 'POST');
446
    }
447
    $date      = $_POST['prune_date'];
448
    $timestamp = mktime(0, 0, 0, (int)mb_substr($date, 5, 2), (int)mb_substr($date, 8, 2), (int)mb_substr($date, 0, 4));
449
    $count     = $story->getCountStoriesPublishedBefore($timestamp, $expired, $topiclist);
450
    if ($count) {
451
        $displaydate = formatTimestamp($timestamp, $dateformat);
452
        $msg         = sprintf(_AM_NEWS_PRUNE_CONFIRM, $displaydate, $count);
453
        xoops_confirm(
454
            [
455
                          'op'            => 'prunenews',
456
                          'expired'       => $expired,
457
                          'pruned_topics' => $topiclist,
458
                          'prune_date'    => $timestamp,
459
                'ok'            => 1,
460
            ],
461
            'index.php',
462
            $msg
463
        );
464
    } else {
465
        printf(_AM_NEWS_NOTHING_PRUNE);
466
    }
467
    unset($story);
468
}
469
470
// Effectively delete stories (published before a date), no more confirmation
471
function pruneNews()
472
{
473
    $story     = new NewsStory();
0 ignored issues
show
Unused Code introduced by
The assignment to $story is dead and can be removed.
Loading history...
474
    $timestamp = Request::getInt('prune_date', 0, 'POST');
475
    $expired   = Request::getInt('expired', 0, 'POST');
476
    $topiclist = '';
477
    if (Request::hasVar('pruned_topics', 'POST')) {
478
        $topiclist = $_POST['pruned_topics'];
479
    }
480
481
    if (1 == Request::getInt('ok', 0, 'POST')) {
482
        $story = new NewsStory();
483
        xoops_cp_header();
484
        $count = $story->getCountStoriesPublishedBefore($timestamp, $expired, $topiclist);
485
        $msg   = sprintf(_AM_NEWS_PRUNE_DELETED, $count);
486
        $story->deleteBeforeDate($timestamp, $expired, $topiclist);
487
        unset($story);
488
        News\Utility::updateCache();
489
        redirect_header('index.php', 3, $msg);
490
    }
491
}
492
493
/**
494
 * Newsletter's configuration
495
 *
496
 * You can create a newsletter's content from the admin part of the News module when you click on the tab named "Newsletter"
497
 * First, let be clear, this module'functionality will not send the newsletter but it will prepare its content for you.
498
 * To send the newsletter, you can use many specialized modules like evennews.
499
 * You first select a range of dates and if you want, a selection of topics to use for the search.
500
 * Once it's done, the script will use the file named /xoops/modules/language/yourlanguage/newsletter.php to create
501
 * the newsletter's content. When it's finished, the script generates a file in the upload folder.
502
 */
503
function createNewsletter()
504
{
505
    require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
506
    xoops_cp_header();
507
    $adminObject = Admin::getInstance();
508
    $adminObject->displayNavigation('index.php?op=configurenewsletter');
509
    echo '<br><br><br>';
510
    $sform      = new \XoopsThemeForm(_AM_NEWS_NEWSLETTER, 'newsletterform', XOOPS_URL . '/modules/news/admin/index.php', 'post', true);
511
    $dates_tray = new \XoopsFormElementTray(_AM_NEWS_NEWSLETTER_BETWEEN);
512
    $date1      = new \XoopsFormTextDateSelect('', 'date1', 15, time());
513
    $date2      = new \XoopsFormTextDateSelect(_AM_NEWS_EXPORT_AND, 'date2', 15, time());
514
    $dates_tray->addElement($date1);
515
    $dates_tray->addElement($date2);
516
    $sform->addElement($dates_tray);
517
518
    $topiclist  = new \XoopsFormSelect(_AM_NEWS_PRUNE_TOPICS, 'export_topics', '', 5, true);
519
    $topics_arr = [];
0 ignored issues
show
Unused Code introduced by
The assignment to $topics_arr is dead and can be removed.
Loading history...
520
    $xt         = new NewsTopic();
521
    $allTopics  = $xt->getAllTopics(false); // The webmaster can see everything
522
    $topic_tree = new \XoopsModules\News\ObjectTree($allTopics, 'topic_id', 'topic_pid');
523
    $topics_arr = $topic_tree->getAllChild(0);
524
    if (count($topics_arr)) {
525
        foreach ($topics_arr as $onetopic) {
526
            $topiclist->addOption($onetopic->topic_id(), $onetopic->topic_title());
527
        }
528
    }
529
    $topiclist->setDescription(_AM_NEWS_EXPORT_PRUNE_DSC);
530
    $sform->addElement($topiclist, false);
531
    $sform->addElement(new \XoopsFormHidden('op', 'launchnewsletter'), false);
532
    $sform->addElement(new \XoopsFormRadioYN(_AM_NEWS_REMOVE_BR, 'removebr', 1), false);
533
    $sform->addElement(new \XoopsFormRadioYN(_AM_NEWS_NEWSLETTER_HTML_TAGS, 'removehtml', 0), false);
534
    $sform->addElement(new \XoopsFormTextArea(_AM_NEWS_NEWSLETTER_HEADER, 'header', '', 4, 70), false);
535
    $sform->addElement(new \XoopsFormTextArea(_AM_NEWS_NEWSLETTER_FOOTER, 'footer', '', 4, 70), false);
536
    $buttonTray = new \XoopsFormElementTray('', '');
537
    $submit_btn = new \XoopsFormButton('', 'post', _SUBMIT, 'submit');
538
    $buttonTray->addElement($submit_btn);
539
    $sform->addElement($buttonTray);
540
    $sform->display();
541
}
542
543
/**
544
 * Launch the creation of the newsletter's content
545
 */
546
function launchNewsletter()
547
{
548
    global $xoopsConfig, $dateformat;
549
    xoops_cp_header();
550
    $adminObject = Admin::getInstance();
551
    $adminObject->displayNavigation('index.php?op=configurenewsletter');
552
    $newslettertemplate = '';
553
    /** @var News\Helper $helper */
554
    $helper = Helper::getInstance();
555
    $helper->loadLanguage('newsletter');
556
    echo '<br>';
557
    $story           = new NewsStory();
558
    $exportedstories = [];
0 ignored issues
show
Unused Code introduced by
The assignment to $exportedstories is dead and can be removed.
Loading history...
559
    $topiclist       = '';
560
    $removebr        = $removehtml = false;
0 ignored issues
show
Unused Code introduced by
The assignment to $removebr is dead and can be removed.
Loading history...
Unused Code introduced by
The assignment to $removehtml is dead and can be removed.
Loading history...
561
    $removebr        = Request::getInt('removebr', 0, 'POST');
562
    $removehtml      = Request::getInt('removehtml', 0, 'POST');
563
    $header          = Request::getString('header', '', 'POST');
564
    $footer          = Request::getString('footer', '', 'POST');
565
    $date1           = $_POST['date1'];
566
    $date2           = $_POST['date2'];
567
    $timestamp1      = mktime(0, 0, 0, (int)mb_substr($date1, 5, 2), (int)mb_substr($date1, 8, 2), (int)mb_substr($date1, 0, 4));
568
    $timestamp2      = mktime(23, 59, 59, (int)mb_substr($date2, 5, 2), (int)mb_substr($date2, 8, 2), (int)mb_substr($date2, 0, 4));
569
    if (Request::hasVar('export_topics', 'POST')) {
570
        $topiclist = implode(',', $_POST['export_topics']);
571
    }
572
    $tbltopics       = [];
573
    $exportedstories = $story->exportNews($timestamp1, $timestamp2, $topiclist, 0, $tbltopics);
574
    $newsfile        = XOOPS_ROOT_PATH . '/uploads/news/letter.txt';
575
    if (count($exportedstories)) {
576
        $fp = fopen($newsfile, 'wb');
577
        if (!$fp) {
0 ignored issues
show
introduced by
$fp is of type false|resource, thus it always evaluated to false.
Loading history...
578
            redirect_header('index.php', 4, sprintf(_AM_NEWS_EXPORT_ERROR, $newsfile));
579
        }
580
        if ('' !== xoops_trim($header)) {
581
            fwrite($fp, $header);
582
        }
583
        foreach ($exportedstories as $onestory) {
584
            $content         = $newslettertemplate;
585
            $search_pattern  = [
586
                '%title%',
587
                '%uname%',
588
                '%created%',
589
                '%published%',
590
                '%expired%',
591
                '%hometext%',
592
                '%bodytext%',
593
                '%description%',
594
                '%keywords%',
595
                '%reads%',
596
                '%topicid%',
597
                '%topic_title%',
598
                '%comments%',
599
                '%rating%',
600
                '%votes%',
601
                '%publisher%',
602
                '%publisher_id%',
603
                '%link%',
604
            ];
605
            $replace_pattern = [
606
                $onestory->title(),
607
                $onestory->uname(),
608
                formatTimestamp($onestory->created(), $dateformat),
609
                formatTimestamp($onestory->published(), $dateformat),
610
                formatTimestamp($onestory->expired(), $dateformat),
611
                $onestory->hometext(),
612
                $onestory->bodytext(),
613
                $onestory->description(),
614
                $onestory->keywords(),
615
                $onestory->counter(),
616
                $onestory->topicid(),
617
                $onestory->topic_title(),
618
                $onestory->comments(),
619
                $onestory->rating(),
620
                $onestory->votes(),
621
                $onestory->uname(),
622
                $onestory->uid(),
623
                XOOPS_URL . '/modules/news/article.php?storyid=' . $onestory->storyid(),
624
            ];
625
            $content         = str_replace($search_pattern, $replace_pattern, $content);
626
            if ($removebr) {
627
                $content = str_replace('<br>', "\r\n", $content);
628
            }
629
            if ($removehtml) {
630
                $content = strip_tags($content);
631
            }
632
            fwrite($fp, $content);
633
        }
634
        if ('' !== xoops_trim($footer)) {
635
            fwrite($fp, $footer);
636
        }
637
        fclose($fp);
638
        $newsfile = XOOPS_URL . '/uploads/news/newsletter.txt';
639
        printf(_AM_NEWS_NEWSLETTER_READY, $newsfile, XOOPS_URL . '/modules/news/admin/index.php?op=deletefile&amp;type=newsletter');
640
    } else {
641
        printf(_AM_NEWS_NOTHING);
642
    }
643
}
644
645
/**
646
 * News export
647
 *
648
 * You can use this function in the module's admin when you click on the tab named "News Export"
649
 * First select a range of date, possibly a range of topics and if you want, check the option "Include Topics Definitions"
650
 * to also export the topics.
651
 * News, and topics, will be exported to the XML format.
652
 */
653
function exportNews()
654
{
655
    require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
656
    xoops_cp_header();
657
    $adminObject = Admin::getInstance();
658
    $adminObject->displayNavigation('index.php?op=export');
659
    echo '<br><br><br>';
660
    $sform      = new \XoopsThemeForm(_AM_NEWS_EXPORT_NEWS, 'exportform', XOOPS_URL . '/modules/news/admin/index.php', 'post', true);
661
    $dates_tray = new \XoopsFormElementTray(_AM_NEWS_EXPORT_BETWEEN);
662
    $date1      = new \XoopsFormTextDateSelect('', 'date1', 15, time());
663
    $date2      = new \XoopsFormTextDateSelect(_AM_NEWS_EXPORT_AND, 'date2', 15, time());
664
    $dates_tray->addElement($date1);
665
    $dates_tray->addElement($date2);
666
    $sform->addElement($dates_tray);
667
668
    $topiclist  = new \XoopsFormSelect(_AM_NEWS_PRUNE_TOPICS, 'export_topics', '', 5, true);
669
    $topics_arr = [];
0 ignored issues
show
Unused Code introduced by
The assignment to $topics_arr is dead and can be removed.
Loading history...
670
    $xt         = new NewsTopic();
671
    $allTopics  = $xt->getAllTopics(false); // The webmaster can see everything
672
    $topic_tree = new \XoopsModules\News\ObjectTree($allTopics, 'topic_id', 'topic_pid');
673
    $topics_arr = $topic_tree->getAllChild(0);
674
    if (count($topics_arr)) {
675
        foreach ($topics_arr as $onetopic) {
676
            $topiclist->addOption($onetopic->topic_id(), $onetopic->topic_title());
677
        }
678
    }
679
    $topiclist->setDescription(_AM_NEWS_EXPORT_PRUNE_DSC);
680
    $sform->addElement($topiclist, false);
681
    $sform->addElement(new \XoopsFormRadioYN(_AM_NEWS_EXPORT_INCTOPICS, 'includetopics', 0), false);
682
    $sform->addElement(new \XoopsFormHidden('op', 'launchexport'), false);
683
    $buttonTray = new \XoopsFormElementTray('', '');
684
    $submit_btn = new \XoopsFormButton('', 'post', _SUBMIT, 'submit');
685
    $buttonTray->addElement($submit_btn);
686
    $sform->addElement($buttonTray);
687
    $sform->display();
688
}
689
690
/**
691
 * @param $text
692
 *
693
 * @return string
694
 */
695
function news_utf8_encode($text)
696
{
697
    return xoops_utf8_encode($text);
698
}
699
700
// Launch stories export (to the xml's format)
701
function launchExport()
702
{
703
    xoops_cp_header();
704
    $adminObject = Admin::getInstance();
705
    $adminObject->displayNavigation('index.php?op=export');
706
    echo '<br>';
707
    $story           = new NewsStory();
708
    $topic           = new NewsTopic();
0 ignored issues
show
Unused Code introduced by
The assignment to $topic is dead and can be removed.
Loading history...
709
    $exportedstories = [];
0 ignored issues
show
Unused Code introduced by
The assignment to $exportedstories is dead and can be removed.
Loading history...
710
    $date1           = $_POST['date1'];
711
    $date2           = $_POST['date2'];
712
    $timestamp1      = mktime(0, 0, 0, (int)mb_substr($date1, 5, 2), (int)mb_substr($date1, 8, 2), (int)mb_substr($date1, 0, 4));
713
    $timestamp2      = mktime(23, 59, 59, (int)mb_substr($date2, 5, 2), (int)mb_substr($date2, 8, 2), (int)mb_substr($date2, 0, 4));
714
    $topiclist       = '';
715
    if (Request::hasVar('export_topics', 'POST')) {
716
        $topiclist = implode(',', $_POST['export_topics']);
717
    }
718
    $topicsexport    = Request::getInt('includetopics', 0, 'POST');
719
    $tbltopics       = [];
720
    $exportedstories = $story->exportNews($timestamp1, $timestamp2, $topiclist, $topicsexport, $tbltopics);
721
    if (count($exportedstories)) {
722
        $xmlfile = XOOPS_ROOT_PATH . '/uploads/news/stories.xml';
723
        $fp      = fopen($xmlfile, 'wb');
724
        if (!$fp) {
0 ignored issues
show
introduced by
$fp is of type false|resource, thus it always evaluated to false.
Loading history...
725
            redirect_header('index.php', 4, sprintf(_AM_NEWS_EXPORT_ERROR, $xmlfile));
726
        }
727
728
        fwrite($fp, news_utf8_encode("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"));
729
        fwrite($fp, news_utf8_encode("<news_stories>\n"));
730
        if ($topicsexport) {
731
            foreach ($tbltopics as $onetopic) {
732
                $topic   = new NewsTopic($onetopic);
733
                $content = "<news_topic>\n";
734
                $content .= sprintf("\t<topic_id>%u</topic_id>\n", $topic->topic_id());
735
                $content .= sprintf("\t<topic_pid>%u</topic_pid>\n", $topic->topic_pid());
736
                $content .= sprintf("\t<topic_imgurl>%s</topic_imgurl>\n", $topic->topic_imgurl());
737
                $content .= sprintf("\t<topic_title>%s</topic_title>\n", $topic->topic_title('F'));
738
                $content .= sprintf("\t<menu>%d</menu>\n", $topic->menu());
739
                $content .= sprintf("\t<topic_frontpage>%d</topic_frontpage>\n", $topic->topic_frontpage());
740
                $content .= sprintf("\t<topic_rssurl>%s</topic_rssurl>\n", $topic->topic_rssurl('E'));
741
                $content .= sprintf("\t<topic_description>%s</topic_description>\n", $topic->topic_description());
742
                $content .= sprintf("</news_topic>\n");
743
                $content = news_utf8_encode($content);
744
                fwrite($fp, $content);
745
            }
746
        }
747
748
        foreach ($exportedstories as $onestory) {
749
            $content = "<xoops_story>\n";
750
            $content .= sprintf("\t<storyid>%u</storyid>\n", $onestory->storyid());
751
            $content .= sprintf("\t<uid>%u</uid>\n", $onestory->uid());
752
            $content .= sprintf("\t<uname>%s</uname>\n", $onestory->uname());
753
            $content .= sprintf("\t<title>%s</title>\n", $onestory->title());
754
            $content .= sprintf("\t<created>%u</created>\n", $onestory->created());
755
            $content .= sprintf("\t<published>%u</published>\n", $onestory->published());
756
            $content .= sprintf("\t<expired>%u</expired>\n", $onestory->expired());
757
            $content .= sprintf("\t<hostname>%s</hostname>\n", $onestory->hostname());
758
            $content .= sprintf("\t<nohtml>%d</nohtml>\n", $onestory->nohtml());
759
            $content .= sprintf("\t<nosmiley>%d</nosmiley>\n", $onestory->nosmiley());
760
            $content .= sprintf("\t<hometext>%s</hometext>\n", $onestory->hometext());
761
            $content .= sprintf("\t<bodytext>%s</bodytext>\n", $onestory->bodytext());
762
            $content .= sprintf("\t<description>%s</description>\n", $onestory->description());
763
            $content .= sprintf("\t<keywords>%s</keywords>\n", $onestory->keywords());
764
            $content .= sprintf("\t<counter>%u</counter>\n", $onestory->counter());
765
            $content .= sprintf("\t<topicid>%u</topicid>\n", $onestory->topicid());
766
            $content .= sprintf("\t<ihome>%d</ihome>\n", $onestory->ihome());
767
            $content .= sprintf("\t<notifypub>%d</notifypub>\n", $onestory->notifypub());
768
            $content .= sprintf("\t<story_type>%s</story_type>\n", $onestory->type());
769
            $content .= sprintf("\t<topicdisplay>%d</topicdisplay>\n", $onestory->topicdisplay());
770
            $content .= sprintf("\t<topicalign>%s</topicalign>\n", $onestory->topicalign());
771
            $content .= sprintf("\t<comments>%u</comments>\n", $onestory->comments());
772
            $content .= sprintf("\t<rating>%f</rating>\n", $onestory->rating());
773
            $content .= sprintf("\t<votes>%u</votes>\n", $onestory->votes());
774
            $content .= sprintf("</xoops_story>\n");
775
            $content = news_utf8_encode($content);
776
            fwrite($fp, $content);
777
        }
778
        fwrite($fp, news_utf8_encode("</news_stories>\n"));
779
        fclose($fp);
780
        $xmlfile = XOOPS_URL . '/uploads/news/stories.xml';
781
        printf(_AM_NEWS_EXPORT_READY, $xmlfile, XOOPS_URL . '/modules/news/admin/index.php?op=deletefile&amp;type=xml');
782
    } else {
783
        printf(_AM_NEWS_EXPORT_NOTHING);
784
    }
785
}
786
787
/*
788
* Topics manager
789
*
790
* It's from here that you can list, add, modify an delete topics
791
* At first, you can see a list of all the topics in your databases. This list contains the topic's ID, its name,
792
* its parent topic, if it should be visible in the Xoops main menu and an action (Edit or Delete topic)
793
* Below this list you find the form used to create and edit the topics.
794
* use this form to :
795
* - Type the topic's title
796
* - Enter its description
797
* - Select its parent topic
798
* - Choose a color
799
* - Select if it must appear in the Xoops main menu
800
* - 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
801
* - And finally you ca select an image to represent the topic
802
* The text box called "URL of RSS feed" is, for this moment, not used.
803
*/
804
function topicsmanager()
805
{
806
    global $xoopsDB, $xoopsConfig, $xoopsModule, $myts;
807
    require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
808
    xoops_cp_header();
809
    $adminObject = Admin::getInstance();
810
    $adminObject->displayNavigation('index.php?op=topicsmanager');
811
812
    global $pathIcon16;
813
814
    $uploadfolder   = sprintf(_AM_UPLOAD_WARNING, XOOPS_URL . '/uploads/news/image');
0 ignored issues
show
Unused Code introduced by
The assignment to $uploadfolder is dead and can be removed.
Loading history...
815
    $uploadirectory = '/uploads/news/image';
816
    $start          = Request::getInt('start', 0, 'GET');
817
818
    $xt          = new NewsTopic($xoopsDB->prefix('news_topics'), 'topic_id', 'topic_pid');
0 ignored issues
show
Unused Code introduced by
The call to XoopsModules\News\NewsTopic::__construct() has too many arguments starting with 'topic_id'. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

818
    $xt          = /** @scrutinizer ignore-call */ new NewsTopic($xoopsDB->prefix('news_topics'), 'topic_id', 'topic_pid');

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
819
    $topics_arr  = $xt->getChildTreeArray(0, 'topic_title');
820
    $totaltopics = count($topics_arr);
821
    $class       = '';
822
823
    //echo '<h4>' . _AM_CONFIG . '</h4>';
824
    //news_collapsableBar('topicsmanager', 'toptopicsmanager');
825
826
    //echo "<img onclick=\"toggle('toptable'); toggleIcon('toptableicon');\" id='toptopicsmanager' name='toptopicsmanager' src='" . $pathIcon16."/close12.gif' alt=''></a>&nbsp;"._AM_TOPICSMNGR . ' (' . $totaltopics . ')'."</h4>";
827
828
    echo "<div id='topicsmanager'>";
829
    echo '<br>';
830
    echo "<div class='center;'>";
831
    echo "<table width='100%' cellspacing='1' cellpadding='3' border='0' class='outer'><tr class='bg3'><th align='center'>"
832
         . _AM_TOPIC
833
         . "</th><th align='left'>"
834
         . _AM_TOPICNAME
835
         . "</th><th align='center'>"
836
         . _AM_PARENTTOPIC
837
         . "</th><th align='center'>"
838
         . _AM_SUB_MENU_YESNO
839
         . "</th><th align='center'>"
840
         . _AM_NEWS_ACTION
841
         . '</th></tr>';
842
    if (is_array($topics_arr) && $totaltopics) {
843
        $cpt    = 1;
844
        $tmpcpt = $start;
845
        $ok     = true;
846
        $output = '';
847
        while ($ok) {
848
            if ($tmpcpt < $totaltopics) {
849
                $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>';
850
                $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>";
851
852
                $parent = '&nbsp;';
853
                if ($topics_arr[$tmpcpt]['topic_pid'] > 0) {
854
                    $xttmp  = new \XoopsModules\News\XoopsTopic($xoopsDB->prefix('news_topics'), $topics_arr[$tmpcpt]['topic_pid']);
855
                    $parent = $xttmp->topic_title();
856
                    unset($xttmp);
857
                }
858
                if (0 != $topics_arr[$tmpcpt]['topic_pid']) {
859
                    $topics_arr[$tmpcpt]['prefix'] = str_replace('.', '-', $topics_arr[$tmpcpt]['prefix']) . '&nbsp;';
860
                } else {
861
                    $topics_arr[$tmpcpt]['prefix'] = str_replace('.', '', $topics_arr[$tmpcpt]['prefix']);
862
                }
863
                $submenu = $topics_arr[$tmpcpt]['menu'] ? _YES : _NO;
864
                $class   = ('even' === $class) ? 'odd' : 'even';
865
866
                $output = $output
867
                          . "<tr class='"
868
                          . $class
869
                          . "'><td>"
870
                          . $topics_arr[$tmpcpt]['topic_id']
871
                          . "</td><td align='left'>"
872
                          . $topics_arr[$tmpcpt]['prefix']
873
                          . $myts->displayTarea($topics_arr[$tmpcpt]['topic_title'])
874
                          . "</td><td align='left'>"
875
                          . $parent
876
                          . "</td><td align='center'>"
877
                          . $submenu
878
                          . "</td><td align='center'>"
879
                          . $action_edit
880
                          . $action_delete
881
                          . '</td></tr>';
882
            } else {
883
                $ok = false;
884
            }
885
            if ($cpt >= News\Utility::getModuleOption('storycountadmin')) {
886
                $ok = false;
887
            }
888
            ++$tmpcpt;
889
            ++$cpt;
890
        }
891
        echo $output;
892
    }
893
    $pagenav = new \XoopsPageNav($totaltopics, News\Utility::getModuleOption('storycountadmin'), $start, 'start', 'op=topicsmanager');
0 ignored issues
show
Bug introduced by
It seems like XoopsModules\News\Utilit...tion('storycountadmin') can also be of type boolean; however, parameter $items_perpage of XoopsPageNav::__construct() does only seem to accept integer, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

893
    $pagenav = new \XoopsPageNav($totaltopics, /** @scrutinizer ignore-type */ News\Utility::getModuleOption('storycountadmin'), $start, 'start', 'op=topicsmanager');
Loading history...
894
    echo "</table><div align='right'>" . $pagenav->renderNav() . '</div><br>';
895
    echo "</div></div><br>\n";
896
897
    $topic_id = Request::getInt('topic_id', 0, 'GET');
898
    if ($topic_id > 0) {
899
        $xtmod             = new NewsTopic($topic_id);
900
        $topic_title       = $xtmod->topic_title('E');
901
        $topic_description = $xtmod->topic_description('E');
902
        $topic_rssfeed     = $xtmod->topic_rssurl('E');
0 ignored issues
show
Unused Code introduced by
The assignment to $topic_rssfeed is dead and can be removed.
Loading history...
903
        $op                = 'modTopicS';
904
        if ('' !== xoops_trim($xtmod->topic_imgurl())) {
905
            $topicimage = $xtmod->topic_imgurl();
906
        } else {
907
            $topicimage = 'blank.png';
908
        }
909
        $btnlabel        = _AM_MODIFY;
910
        $parent          = $xtmod->topic_pid();
911
        $formlabel       = _AM_MODIFYTOPIC;
912
        $submenu         = $xtmod->menu();
913
        $topic_frontpage = $xtmod->topic_frontpage();
914
        $topic_color     = $xtmod->topic_color();
915
        unset($xtmod);
916
    } else {
917
        $topic_title       = '';
918
        $topic_frontpage   = 1;
919
        $topic_description = '';
920
        $op                = 'addTopic';
921
        $topicimage        = 'xoops.gif';
922
        $btnlabel          = _AM_ADD;
923
        $parent            = -1;
924
        $submenu           = 0;
925
        $topic_rssfeed     = '';
926
        $formlabel         = _AM_ADD_TOPIC;
927
        $topic_color       = '000000';
928
    }
929
930
    $sform = new \XoopsThemeForm($formlabel, 'topicform', XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/admin/index.php', 'post', true);
931
    $sform->setExtra('enctype="multipart/form-data"');
932
    $sform->addElement(new \XoopsFormText(_AM_TOPICNAME, 'topic_title', 50, 255, $topic_title), true);
933
    $editor = News\Utility::getWysiwygForm(_AM_TOPIC_DESCR, 'topic_description', $topic_description, 15, 60, 'hometext_hidden');
934
    if ($editor) {
935
        $sform->addElement($editor, false);
936
    }
937
938
    $sform->addElement(new \XoopsFormHidden('op', $op), false);
939
    $sform->addElement(new \XoopsFormHidden('topic_id', $topic_id), false);
940
941
    //    require_once XOOPS_ROOT_PATH . '/modules/news/class/class.newstopic.php';
942
    $xt = new NewsTopic();
943
    $sform->addElement(new \XoopsFormLabel(_AM_PARENTTOPIC, $xt->makeMyTopicSelBox(1, $parent, 'topic_pid', '', false)));
944
    // Topic's color
945
    // Code stolen to Zoullou, thank you Zoullou ;-)
946
    $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";
947
    $color_values = [
948
        '000000',
949
        '000033',
950
        '000066',
951
        '000099',
952
        '0000CC',
953
        '0000FF',
954
        '003300',
955
        '003333',
956
        '003366',
957
        '0033CC',
958
        '0033FF',
959
        '006600',
960
        '006633',
961
        '006666',
962
        '006699',
963
        '0066CC',
964
        '0066FF',
965
        '009900',
966
        '009933',
967
        '009966',
968
        '009999',
969
        '0099CC',
970
        '0099FF',
971
        '00CC00',
972
        '00CC33',
973
        '00CC66',
974
        '00CC99',
975
        '00CCCC',
976
        '00CCFF',
977
        '00FF00',
978
        '00FF33',
979
        '00FF66',
980
        '00FF99',
981
        '00FFCC',
982
        '00FFFF',
983
        '330000',
984
        '330033',
985
        '330066',
986
        '330099',
987
        '3300CC',
988
        '3300FF',
989
        '333300',
990
        '333333',
991
        '333366',
992
        '333399',
993
        '3333CC',
994
        '3333FF',
995
        '336600',
996
        '336633',
997
        '336666',
998
        '336699',
999
        '3366CC',
1000
        '3366FF',
1001
        '339900',
1002
        '339933',
1003
        '339966',
1004
        '339999',
1005
        '3399CC',
1006
        '3399FF',
1007
        '33CC00',
1008
        '33CC33',
1009
        '33CC66',
1010
        '33CC99',
1011
        '33CCCC',
1012
        '33CCFF',
1013
        '33FF00',
1014
        '33FF33',
1015
        '33FF66',
1016
        '33FF99',
1017
        '33FFCC',
1018
        '33FFFF',
1019
        '660000',
1020
        '660033',
1021
        '660066',
1022
        '660099',
1023
        '6600CC',
1024
        '6600FF',
1025
        '663300',
1026
        '663333',
1027
        '663366',
1028
        '663399',
1029
        '6633CC',
1030
        '6633FF',
1031
        '666600',
1032
        '666633',
1033
        '666666',
1034
        '666699',
1035
        '6666CC',
1036
        '6666FF',
1037
        '669900',
1038
        '669933',
1039
        '669966',
1040
        '669999',
1041
        '6699CC',
1042
        '6699FF',
1043
        '66CC00',
1044
        '66CC33',
1045
        '66CC66',
1046
        '66CC99',
1047
        '66CCCC',
1048
        '66CCFF',
1049
        '66FF00',
1050
        '66FF33',
1051
        '66FF66',
1052
        '66FF99',
1053
        '66FFCC',
1054
        '66FFFF',
1055
        '990000',
1056
        '990033',
1057
        '990066',
1058
        '990099',
1059
        '9900CC',
1060
        '9900FF',
1061
        '993300',
1062
        '993333',
1063
        '993366',
1064
        '993399',
1065
        '9933CC',
1066
        '9933FF',
1067
        '996600',
1068
        '996633',
1069
        '996666',
1070
        '996699',
1071
        '9966CC',
1072
        '9966FF',
1073
        '999900',
1074
        '999933',
1075
        '999966',
1076
        '999999',
1077
        '9999CC',
1078
        '9999FF',
1079
        '99CC00',
1080
        '99CC33',
1081
        '99CC66',
1082
        '99CC99',
1083
        '99CCCC',
1084
        '99CCFF',
1085
        '99FF00',
1086
        '99FF33',
1087
        '99FF66',
1088
        '99FF99',
1089
        '99FFCC',
1090
        '99FFFF',
1091
        'CC0000',
1092
        'CC0033',
1093
        'CC0066',
1094
        'CC0099',
1095
        'CC00CC',
1096
        'CC00FF',
1097
        'CC3300',
1098
        'CC3333',
1099
        'CC3366',
1100
        'CC3399',
1101
        'CC33CC',
1102
        'CC33FF',
1103
        'CC6600',
1104
        'CC6633',
1105
        'CC6666',
1106
        'CC6699',
1107
        'CC66CC',
1108
        'CC66FF',
1109
        'CC9900',
1110
        'CC9933',
1111
        'CC9966',
1112
        'CC9999',
1113
        'CC99CC',
1114
        'CC99FF',
1115
        'CCCC00',
1116
        'CCCC33',
1117
        'CCCC66',
1118
        'CCCC99',
1119
        'CCCCCC',
1120
        'CCCCFF',
1121
        'CCFF00',
1122
        'CCFF33',
1123
        'CCFF66',
1124
        'CCFF99',
1125
        'CCFFCC',
1126
        'CCFFFF',
1127
        'FF0000',
1128
        'FF0033',
1129
        'FF0066',
1130
        'FF0099',
1131
        'FF00CC',
1132
        'FF00FF',
1133
        'FF3300',
1134
        'FF3333',
1135
        'FF3366',
1136
        'FF3399',
1137
        'FF33CC',
1138
        'FF33FF',
1139
        'FF6600',
1140
        'FF6633',
1141
        'FF6666',
1142
        'FF6699',
1143
        'FF66CC',
1144
        'FF66FF',
1145
        'FF9900',
1146
        'FF9933',
1147
        'FF9966',
1148
        'FF9999',
1149
        'FF99CC',
1150
        'FF99FF',
1151
        'FFCC00',
1152
        'FFCC33',
1153
        'FFCC66',
1154
        'FFCC99',
1155
        'FFCCCC',
1156
        'FFCCFF',
1157
        'FFFF00',
1158
        'FFFF33',
1159
        'FFFF66',
1160
        'FFFF99',
1161
        'FFFFCC',
1162
        'FFFFFF',
1163
    ];
1164
1165
    foreach ($color_values as $color_value) {
1166
        if ($topic_color == $color_value) {
1167
            $selected = ' selected';
1168
        } else {
1169
            $selected = '';
1170
        }
1171
        $select_color .= '<option' . $selected . " value='" . $color_value . "' style='background-color:#" . $color_value . ';color:#' . $color_value . ";'>#" . $color_value . "</option>\n";
1172
    }
1173
1174
    $select_color .= "</select>&nbsp;\n<span id='NewsColorSelect'>&nbsp;&nbsp;&nbsp;&nbsp;</span>";
1175
    $sform->addElement(new \XoopsFormLabel(_AM_NEWS_TOPIC_COLOR, $select_color));
1176
    // Sub menu ?
1177
    $sform->addElement(new \XoopsFormRadioYN(_AM_SUB_MENU, 'submenu', $submenu, _YES, _NO));
1178
    $sform->addElement(new \XoopsFormRadioYN(_AM_PUBLISH_FRONTPAGE, 'topic_frontpage', $topic_frontpage, _YES, _NO));
1179
    // Unused for this moment... sorry
1180
    //$sform->addElement(new \XoopsFormText(_AM_NEWS_RSS_URL, 'topic_rssfeed', 50, 255, $topic_rssfeed), false);
1181
    // ********** Picture
1182
    $imgtray = new \XoopsFormElementTray(_AM_TOPICIMG, '<br>');
1183
1184
    $imgpath      = sprintf(_AM_IMGNAEXLOC, 'uploads/news/image/');
1185
    $imageselect  = new \XoopsFormSelect($imgpath, 'topic_imgurl', $topicimage);
1186
    $topics_array = \XoopsLists:: getImgListAsArray(XOOPS_ROOT_PATH . '/uploads/news/image/');
1187
    foreach ($topics_array as $image) {
1188
        $imageselect->addOption((string)$image, $image);
1189
    }
1190
    $imageselect->setExtra("onchange='showImgSelected(\"image3\", \"topic_imgurl\", \"" . $uploadirectory . '", "", "' . XOOPS_URL . "\")'");
1191
    $imgtray->addElement($imageselect, false);
1192
    $imgtray->addElement(new XoopsFormLabel('', "<br><img src='" . XOOPS_URL . $uploadirectory . '/' . $topicimage . "' name='image3' id='image3' alt=''>"));
1193
1194
    $uploadfolder = sprintf(_AM_UPLOAD_WARNING, XOOPS_URL . '/uploads/news/image');
1195
    $fileseltray  = new \XoopsFormElementTray('', '<br>');
1196
    $fileseltray->addElement(new \XoopsFormFile(_AM_TOPIC_PICTURE, 'attachedfile', News\Utility::getModuleOption('maxuploadsize')), false);
0 ignored issues
show
Bug introduced by
It seems like XoopsModules\News\Utilit...Option('maxuploadsize') can also be of type boolean; however, parameter $maxfilesize of XoopsFormFile::__construct() does only seem to accept integer, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

1196
    $fileseltray->addElement(new \XoopsFormFile(_AM_TOPIC_PICTURE, 'attachedfile', /** @scrutinizer ignore-type */ News\Utility::getModuleOption('maxuploadsize')), false);
Loading history...
1197
    $fileseltray->addElement(new \XoopsFormLabel($uploadfolder), false);
1198
    $imgtray->addElement($fileseltray);
1199
    $sform->addElement($imgtray);
1200
1201
    // Permissions
1202
    /** @var \XoopsMemberHandler $memberHandler */
1203
    $memberHandler = xoops_getHandler('member');
1204
    $group_list    = $memberHandler->getGroupList();
1205
    /** @var \XoopsGroupPermHandler $grouppermHandler */
1206
    $grouppermHandler = xoops_getHandler('groupperm');
1207
    $full_list     = array_keys($group_list);
1208
1209
    $groups_ids = [];
1210
    if ($topic_id > 0) { // Edit mode
1211
        $groups_ids                       = $grouppermHandler->getGroupIds('news_approve', $topic_id, $xoopsModule->getVar('mid'));
1212
        $groups_ids                       = array_values($groups_ids);
1213
        $groups_news_can_approve_checkbox = new \XoopsFormCheckBox(_AM_APPROVEFORM, 'groups_news_can_approve[]', $groups_ids);
1214
    } else { // Creation mode
1215
        $groups_news_can_approve_checkbox = new \XoopsFormCheckBox(_AM_APPROVEFORM, 'groups_news_can_approve[]', $full_list);
1216
    }
1217
    $groups_news_can_approve_checkbox->addOptionArray($group_list);
1218
    $sform->addElement($groups_news_can_approve_checkbox);
1219
1220
    $groups_ids = [];
1221
    if ($topic_id > 0) { // Edit mode
1222
        $groups_ids                      = $grouppermHandler->getGroupIds('news_submit', $topic_id, $xoopsModule->getVar('mid'));
1223
        $groups_ids                      = array_values($groups_ids);
1224
        $groups_news_can_submit_checkbox = new \XoopsFormCheckBox(_AM_SUBMITFORM, 'groups_news_can_submit[]', $groups_ids);
1225
    } else { // Creation mode
1226
        $groups_news_can_submit_checkbox = new \XoopsFormCheckBox(_AM_SUBMITFORM, 'groups_news_can_submit[]', $full_list);
1227
    }
1228
    $groups_news_can_submit_checkbox->addOptionArray($group_list);
1229
    $sform->addElement($groups_news_can_submit_checkbox);
1230
1231
    $groups_ids = [];
0 ignored issues
show
Unused Code introduced by
The assignment to $groups_ids is dead and can be removed.
Loading history...
1232
    if ($topic_id > 0) { // Edit mode
1233
        $groups_ids                    = $grouppermHandler->getGroupIds('news_view', $topic_id, $xoopsModule->getVar('mid'));
1234
        $groups_ids                    = array_values($groups_ids);
1235
        $groups_news_can_view_checkbox = new \XoopsFormCheckBox(_AM_VIEWFORM, 'groups_news_can_view[]', $groups_ids);
1236
    } else { // Creation mode
1237
        $groups_news_can_view_checkbox = new \XoopsFormCheckBox(_AM_VIEWFORM, 'groups_news_can_view[]', $full_list);
1238
    }
1239
    $groups_news_can_view_checkbox->addOptionArray($group_list);
1240
    $sform->addElement($groups_news_can_view_checkbox);
1241
1242
    // Submit buttons
1243
    $buttonTray = new \XoopsFormElementTray('', '');
1244
    $submit_btn = new \XoopsFormButton('', 'post', $btnlabel, 'submit');
1245
    $buttonTray->addElement($submit_btn);
1246
    $sform->addElement($buttonTray);
1247
    $sform->display();
1248
    echo "<script type='text/javascript'>\n";
1249
    echo 'xoopsGetElementById("NewsColorSelect").style.backgroundColor = "#' . $topic_color . '";';
1250
    echo "</script>\n";
1251
}
1252
1253
// Save a topic after it has been modified
1254
function modTopicS()
1255
{
1256
    global $xoopsDB, $xoopsModule;
1257
    /** @var News\Helper $helper */
1258
    $helper = Helper::getInstance();
1259
1260
    $xt = new NewsTopic(Request::getInt('topic_id', 0, 'POST'));
1261
    if (Request::getInt('topic_pid', 0, 'POST') == Request::getInt('topic_id', 0, 'POST')) {
1262
        redirect_header('index.php?op=topicsmanager', 2, _AM_ADD_TOPIC_ERROR1);
1263
    }
1264
    $xt->setTopicPid(Request::getInt('topic_pid', 0, 'POST'));
1265
    if (empty($_POST['topic_title'])) {
1266
        redirect_header('index.php?op=topicsmanager', 2, _AM_ERRORTOPICNAME);
1267
    }
1268
    if (Request::hasVar('items_count', 'SESSION')) {
1269
        $_SESSION['items_count'] = -1;
1270
    }
1271
    $xt->setTopicTitle($_POST['topic_title']);
1272
    if (Request::hasVar('topic_imgurl', 'POST') && '' !== $_POST['topic_imgurl']) {
1273
        $xt->setTopicImgurl($_POST['topic_imgurl']);
1274
    }
1275
    $xt->setMenu(Request::getInt('submenu', 0, 'POST'));
1276
    $xt->setTopicFrontpage(Request::getInt('topic_frontpage', 0, 'POST'));
1277
    if (Request::hasVar('topic_description', 'POST')) {
1278
        $xt->setTopicDescription($_POST['topic_description']);
1279
    } else {
1280
        $xt->setTopicDescription('');
1281
    }
1282
    //$xt->setTopicRssUrl($_POST['topic_rssfeed']);
1283
    $xt->setTopic_color($_POST['topic_color']);
1284
1285
    if (Request::hasVar('xoops_upload_file', 'POST')) {
1286
        $fldname = $_FILES[$_POST['xoops_upload_file'][0]];
1287
        $fldname = $fldname['name'];
1288
        if (xoops_trim('' !== $fldname)) {
1289
            $sfiles         = new Files();
1290
            $dstpath        = XOOPS_ROOT_PATH . '/uploads/news/image';
1291
            $destname       = $sfiles->createUploadName($dstpath, $fldname, true);
1292
            $permittedtypes = ['image/gif', 'image/jpeg', 'image/pjpeg', 'image/x-png', 'image/png'];
1293
            $uploader       = new \XoopsMediaUploader($dstpath, $permittedtypes, $helper->getConfig('maxuploadsize'));
1294
            $uploader->setTargetFileName($destname);
1295
            if ($uploader->fetchMedia($_POST['xoops_upload_file'][0])) {
1296
                if ($uploader->upload()) {
1297
                    $xt->setTopicImgurl(basename($destname));
1298
                } else {
1299
                    echo _AM_UPLOAD_ERROR . ' ' . $uploader->getErrors();
1300
                }
1301
            } else {
1302
                echo $uploader->getErrors();
1303
            }
1304
        }
1305
    }
1306
    $xt->store();
1307
1308
    // Permissions
1309
    /** @var \XoopsGroupPermHandler $grouppermHandler */
1310
    $grouppermHandler = xoops_getHandler('groupperm');
1311
    $criteria         = new \CriteriaCompo();
1312
    $criteria->add(new \Criteria('gperm_itemid', $xt->topic_id(), '='));
1313
    $criteria->add(new \Criteria('gperm_modid', $xoopsModule->getVar('mid'), '='));
1314
    $criteria->add(new \Criteria('gperm_name', 'news_approve', '='));
1315
    $grouppermHandler->deleteAll($criteria);
1316
1317
    $criteria = new \CriteriaCompo();
1318
    $criteria->add(new \Criteria('gperm_itemid', $xt->topic_id(), '='));
1319
    $criteria->add(new \Criteria('gperm_modid', $xoopsModule->getVar('mid'), '='));
1320
    $criteria->add(new \Criteria('gperm_name', 'news_submit', '='));
1321
    $grouppermHandler->deleteAll($criteria);
1322
1323
    $criteria = new \CriteriaCompo();
1324
    $criteria->add(new \Criteria('gperm_itemid', $xt->topic_id(), '='));
1325
    $criteria->add(new \Criteria('gperm_modid', $xoopsModule->getVar('mid'), '='));
1326
    $criteria->add(new \Criteria('gperm_name', 'news_view', '='));
1327
    $grouppermHandler->deleteAll($criteria);
1328
1329
    if (Request::hasVar('groups_news_can_approve', 'POST')) {
1330
        foreach ($_POST['groups_news_can_approve'] as $onegroup_id) {
1331
            $grouppermHandler->addRight('news_approve', $xt->topic_id(), $onegroup_id, $xoopsModule->getVar('mid'));
1332
        }
1333
    }
1334
1335
    if (Request::hasVar('groups_news_can_submit', 'POST')) {
1336
        foreach ($_POST['groups_news_can_submit'] as $onegroup_id) {
1337
            $grouppermHandler->addRight('news_submit', $xt->topic_id(), $onegroup_id, $xoopsModule->getVar('mid'));
1338
        }
1339
    }
1340
1341
    if (Request::hasVar('groups_news_can_view', 'POST')) {
1342
        foreach ($_POST['groups_news_can_view'] as $onegroup_id) {
1343
            $grouppermHandler->addRight('news_view', $xt->topic_id(), $onegroup_id, $xoopsModule->getVar('mid'));
1344
        }
1345
    }
1346
1347
    News\Utility::updateCache();
1348
    redirect_header('index.php?op=topicsmanager', 1, _AM_DBUPDATED);
1349
}
1350
1351
// Delete a topic and its subtopics and its stories and the related stories
1352
function delTopic()
1353
{
1354
    global $xoopsDB, $xoopsModule;
1355
    if (!isset($_POST['ok'])) {
1356
        xoops_cp_header();
1357
        echo '<h4>' . _AM_CONFIG . '</h4>';
1358
        $xt = new \XoopsModules\News\XoopsTopic($xoopsDB->prefix('news_topics'), Request::getInt('topic_id', 0, 'GET'));
1359
        xoops_confirm(['op' => 'delTopic', 'topic_id' => Request::getInt('topic_id', 0, 'GET'), 'ok' => 1], 'index.php', _AM_WAYSYWTDTTAL . '<br>' . $xt->topic_title('S'));
1360
    } else {
1361
        xoops_cp_header();
1362
        $xt = new \XoopsTopic($xoopsDB->prefix('news_topics'), Request::getInt('topic_id', 0, 'POST'));
1363
        if (Request::hasVar('items_count', 'SESSION')) {
1364
            $_SESSION['items_count'] = -1;
1365
        }
1366
        // get all subtopics under the specified topic
1367
        $topic_arr = $xt->getAllChildTopics();
1368
        $topic_arr[] = $xt;
1369
        foreach ($topic_arr as $eachtopic) {
1370
            // get all stories in each topic
1371
            $story_arr = NewsStory:: getByTopic($eachtopic->topic_id());
1372
            foreach ($story_arr as $eachstory) {
1373
                if (false !== $eachstory->delete()) {
1374
                    xoops_comment_delete($xoopsModule->getVar('mid'), $eachstory->storyid());
1375
                    xoops_notification_deletebyitem($xoopsModule->getVar('mid'), 'story', $eachstory->storyid());
1376
                }
1377
            }
1378
            // all stories for each topic is deleted, now delete the topic data
1379
            $eachtopic->delete();
1380
            // Delete also the notifications and permissions
1381
            xoops_notification_deletebyitem($xoopsModule->getVar('mid'), 'category', $eachtopic->topic_id);
1382
            xoops_groupperm_deletebymoditem($xoopsModule->getVar('mid'), 'news_approve', $eachtopic->topic_id);
1383
            xoops_groupperm_deletebymoditem($xoopsModule->getVar('mid'), 'news_submit', $eachtopic->topic_id);
1384
            xoops_groupperm_deletebymoditem($xoopsModule->getVar('mid'), 'news_view', $eachtopic->topic_id);
1385
        }
1386
        News\Utility::updateCache();
1387
        redirect_header('index.php?op=topicsmanager', 1, _AM_DBUPDATED);
1388
    }
1389
}
1390
1391
// Add a new topic
1392
function addTopic()
1393
{
1394
    global $xoopsDB, $xoopsModule;
1395
    /** @var News\Helper $helper */
1396
    $helper = Helper::getInstance();
1397
1398
    $topicpid = Request::getInt('topic_pid', 0, 'POST');
1399
    $xt       = new NewsTopic();
1400
    if (!$xt->topicExists($topicpid, $_POST['topic_title'])) {
1401
        $xt->setTopicPid($topicpid);
1402
        if (empty($_POST['topic_title']) || '' == xoops_trim($_POST['topic_title'])) {
1403
            redirect_header('index.php?op=topicsmanager', 2, _AM_ERRORTOPICNAME);
1404
        }
1405
        $xt->setTopicTitle($_POST['topic_title']);
1406
        //$xt->setTopicRssUrl($_POST['topic_rssfeed']);
1407
        $xt->setTopic_color($_POST['topic_color']);
1408
        if (Request::hasVar('topic_imgurl', 'POST') && '' !== $_POST['topic_imgurl']) {
1409
            $xt->setTopicImgurl($_POST['topic_imgurl']);
1410
        }
1411
        $xt->setMenu(Request::getInt('submenu', 0, 'POST'));
1412
        $xt->setTopicFrontpage(Request::getInt('topic_frontpage', 0, 'POST'));
1413
        if (Request::hasVar('items_count', 'SESSION')) {
1414
            $_SESSION['items_count'] = -1;
1415
        }
1416
        if (Request::hasVar('xoops_upload_file', 'POST')) {
1417
            $fldname = $_FILES[$_POST['xoops_upload_file'][0]];
1418
            $fldname = $fldname['name'];
1419
            if ('' !== xoops_trim($fldname)) {
1420
                $sfiles         = new Files();
1421
                $dstpath        = XOOPS_ROOT_PATH . '/uploads/news/image';
1422
                $destname       = $sfiles->createUploadName($dstpath, $fldname, true);
1423
                $permittedtypes = ['image/gif', 'image/jpeg', 'image/pjpeg', 'image/x-png', 'image/png'];
1424
                $uploader       = new \XoopsMediaUploader($dstpath, $permittedtypes, $helper->getConfig('maxuploadsize'));
1425
                $uploader->setTargetFileName($destname);
1426
                if ($uploader->fetchMedia($_POST['xoops_upload_file'][0])) {
1427
                    if ($uploader->upload()) {
1428
                        $xt->setTopicImgurl(basename($destname));
1429
                    } else {
1430
                        echo _AM_UPLOAD_ERROR . ' ' . $uploader->getErrors();
1431
                    }
1432
                } else {
1433
                    echo $uploader->getErrors();
1434
                }
1435
            }
1436
        }
1437
        if (Request::hasVar('topic_description', 'POST')) {
1438
            $xt->setTopicDescription($_POST['topic_description']);
1439
        } else {
1440
            $xt->setTopicDescription('');
1441
        }
1442
        $xt->store();
1443
        // Permissions
1444
        /** @var \XoopsGroupPermHandler $grouppermHandler */
1445
        $grouppermHandler = xoops_getHandler('groupperm');
1446
        if (Request::hasVar('groups_news_can_approve', 'POST')) {
1447
            foreach ($_POST['groups_news_can_approve'] as $onegroup_id) {
1448
                $grouppermHandler->addRight('news_approve', $xt->topic_id(), $onegroup_id, $xoopsModule->getVar('mid'));
1449
            }
1450
        }
1451
1452
        if (Request::hasVar('groups_news_can_submit', 'POST')) {
1453
            foreach ($_POST['groups_news_can_submit'] as $onegroup_id) {
1454
                $grouppermHandler->addRight('news_submit', $xt->topic_id(), $onegroup_id, $xoopsModule->getVar('mid'));
1455
            }
1456
        }
1457
1458
        if (Request::hasVar('groups_news_can_view', 'POST')) {
1459
            foreach ($_POST['groups_news_can_view'] as $onegroup_id) {
1460
                $grouppermHandler->addRight('news_view', $xt->topic_id(), $onegroup_id, $xoopsModule->getVar('mid'));
1461
            }
1462
        }
1463
        News\Utility::updateCache();
1464
        /** @var \XoopsNotificationHandler $notificationHandler */
1465
        $notificationHandler = xoops_getHandler('notification');
1466
        $tags                = [];
1467
        $tags['TOPIC_NAME']  = $_POST['topic_title'];
1468
        $notificationHandler->triggerEvent('global', 0, 'new_category', $tags);
1469
        redirect_header('index.php?op=topicsmanager', 1, _AM_DBUPDATED);
1470
    } else {
1471
        redirect_header('index.php?op=topicsmanager', 2, _AM_ADD_TOPIC_ERROR);
1472
    }
1473
}
1474
1475
/**
1476
 * Statistics about stories, topics and authors
1477
 *
1478
 * You can reach the statistics from the admin part of the news module by clicking on the "Statistics" tabs
1479
 * The number of visible elements in each table is equal to the module's option called "storycountadmin"
1480
 * There are 3 kind of different statistics :
1481
 * - Topics statistics
1482
 *   For each topic you can see its number of articles, the number of time each topics was viewed, the number
1483
 *   of attached files, the number of expired articles and the number of unique authors.
1484
 * - Articles statistics
1485
 *   This part is decomposed in 3 tables :
1486
 *   a) Most readed articles
1487
 *      This table resumes, for all the news in your database, the most readed articles.
1488
 *      The table contains, for each news, its topic, its title, the author and the number of views.
1489
 *   b) Less readed articles
1490
 *      That's the opposite action of the previous table and its content is the same
1491
 *   c) Best rated articles
1492
 *      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
1493
 * - Authors statistics
1494
 *   This part is also decomposed in 3 tables
1495
 *   a) Most readed authors
1496
 *        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
1497
 *   b) Best rated authors
1498
 *      To created this table's content, the program compute the rating's average of each author and create a table
1499
 *   c) Biggest contributors
1500
 *      The goal of this table is to know who is creating the biggest number of articles.
1501
 */
1502
function getStats()
1503
{
1504
    global $xoopsModule, $xoopsConfig;
1505
    xoops_cp_header();
1506
    $myts = \MyTextSanitizer::getInstance();
1507
    /** @var News\Helper $helper */
1508
    $helper = Helper::getInstance();
1509
    $helper->loadLanguage('main');
1510
1511
    $adminObject = Admin::getInstance();
1512
    $adminObject->displayNavigation('index.php?op=stats');
1513
    $news   = new NewsStory();
1514
    $stats  = [];
0 ignored issues
show
Unused Code introduced by
The assignment to $stats is dead and can be removed.
Loading history...
1515
    $stats  = $news->getStats(News\Utility::getModuleOption('storycountadmin'));
1516
    $totals = [0, 0, 0, 0, 0];
1517
    //printf("<h1>%s</h1>\n",_AM_NEWS_STATS);
1518
1519
    // First part of the stats, everything about topics
1520
    $storiespertopic = $stats['storiespertopic'];
1521
    $readspertopic   = $stats['readspertopic'];
1522
    $filespertopic   = $stats['filespertopic'];
1523
    $expiredpertopic = $stats['expiredpertopic'];
1524
    $authorspertopic = $stats['authorspertopic'];
1525
    $class           = '';
1526
1527
    echo "<div class='center;'><b>" . _AM_NEWS_STATS0 . "</b><br>\n";
1528
    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>';
1529
    foreach ($storiespertopic as $topicid => $data) {
1530
        $url   = XOOPS_URL . '/modules/' . $xoopsModule->dirname() . '/index.php?storytopic=' . $topicid;
1531
        $views = 0;
1532
        if (array_key_exists($topicid, $readspertopic)) {
1533
            $views = $readspertopic[$topicid];
1534
        }
1535
        $attachedfiles = 0;
1536
        if (array_key_exists($topicid, $filespertopic)) {
1537
            $attachedfiles = $filespertopic[$topicid];
1538
        }
1539
        $expired = 0;
1540
        if (array_key_exists($topicid, $expiredpertopic)) {
1541
            $expired = $expiredpertopic[$topicid];
1542
        }
1543
        $authors = 0;
1544
        if (array_key_exists($topicid, $authorspertopic)) {
1545
            $authors = $authorspertopic[$topicid];
1546
        }
1547
        $articles = $data['cpt'];
1548
1549
        $totals[0] += $articles;
1550
        $totals[1] += $views;
1551
        $totals[2] += $attachedfiles;
1552
        $totals[3] += $expired;
1553
        $class     = ('even' === $class) ? 'odd' : 'even';
1554
        printf(
1555
            "<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",
1556
            $url,
1557
            $myts->displayTarea($data['topic_title']),
1558
            $articles,
1559
               $views,
1560
            $attachedfiles,
1561
            $expired,
1562
            $authors
1563
        );
1564
    }
1565
    $class = ('even' === $class) ? 'odd' : 'even';
1566
    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]);
1567
    echo '</table></div><br><br><br>';
1568
1569
    // Second part of the stats, everything about stories
1570
    // a) Most readed articles
1571
    $mostreadednews = $stats['mostreadednews'];
1572
    echo "<div class='center;'><b>" . _AM_NEWS_STATS3 . '</b><br><br>' . _AM_NEWS_STATS4 . "<br>\n";
1573
    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";
1574
    foreach ($mostreadednews as $storyid => $data) {
1575
        $url1  = XOOPS_URL . '/modules/' . $xoopsModule->dirname() . '/index.php?storytopic=' . $data['topicid'];
1576
        $url2  = XOOPS_URL . '/modules/' . $xoopsModule->dirname() . '/article.php?storyid=' . $storyid;
1577
        $url3  = XOOPS_URL . '/userinfo.php?uid=' . $data['uid'];
1578
        $class = ('even' === $class) ? 'odd' : 'even';
1579
        printf(
1580
            "<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",
1581
            $url1,
1582
            $myts->displayTarea($data['topic_title']),
1583
            $url2,
1584
               $myts->displayTarea($data['title']),
1585
            $url3,
1586
            htmlspecialchars($news->uname($data['uid']), ENT_QUOTES | ENT_HTML5),
1587
            $data['counter']
1588
        );
1589
    }
1590
    echo '</table>';
1591
1592
    // b) Less readed articles
1593
    $lessreadednews = $stats['lessreadednews'];
1594
    echo '<br><br>' . _AM_NEWS_STATS5;
1595
    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";
1596
    foreach ($lessreadednews as $storyid => $data) {
1597
        $url1  = XOOPS_URL . '/modules/' . $xoopsModule->dirname() . '/index.php?storytopic=' . $data['topicid'];
1598
        $url2  = XOOPS_URL . '/modules/' . $xoopsModule->dirname() . '/article.php?storyid=' . $storyid;
1599
        $url3  = XOOPS_URL . '/userinfo.php?uid=' . $data['uid'];
1600
        $class = ('even' === $class) ? 'odd' : 'even';
1601
        printf(
1602
            "<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",
1603
            $url1,
1604
            $myts->displayTarea($data['topic_title']),
1605
            $url2,
1606
               $myts->displayTarea($data['title']),
1607
            $url3,
1608
            htmlspecialchars($news->uname($data['uid']), ENT_QUOTES | ENT_HTML5),
1609
            $data['counter']
1610
        );
1611
    }
1612
    echo '</table>';
1613
1614
    // c) Best rated articles (this is an average)
1615
    $besratednews = $stats['besratednews'];
1616
    echo '<br><br>' . _AM_NEWS_STATS6;
1617
    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";
1618
    foreach ($besratednews as $storyid => $data) {
1619
        $url1  = XOOPS_URL . '/modules/' . $xoopsModule->dirname() . '/index.php?storytopic=' . $data['topicid'];
1620
        $url2  = XOOPS_URL . '/modules/' . $xoopsModule->dirname() . '/article.php?storyid=' . $storyid;
1621
        $url3  = XOOPS_URL . '/userinfo.php?uid=' . $data['uid'];
1622
        $class = ('even' === $class) ? 'odd' : 'even';
1623
        printf(
1624
            "<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",
1625
            $url1,
1626
            $myts->displayTarea($data['topic_title']),
1627
            $url2,
1628
               $myts->displayTarea($data['title']),
1629
            $url3,
1630
            htmlspecialchars($news->uname($data['uid']), ENT_QUOTES | ENT_HTML5),
1631
            number_format($data['rating'], 2)
1632
        );
1633
    }
1634
    echo '</table></div><br><br><br>';
1635
1636
    // Last part of the stats, everything about authors
1637
    // a) Most readed authors
1638
    $mostreadedauthors = $stats['mostreadedauthors'];
1639
    echo "<div class='center;'><b>" . _AM_NEWS_STATS10 . '</b><br><br>' . _AM_NEWS_STATS7 . "<br>\n";
1640
    echo "<table border='0' width='100%'><tr class='bg3'><th>" . _AM_POSTER . '</th><th>' . _NW_VIEWS . "</th></tr>\n";
1641
    foreach ($mostreadedauthors as $uid => $reads) {
1642
        $url   = XOOPS_URL . '/userinfo.php?uid=' . $uid;
1643
        $class = ('even' === $class) ? 'odd' : 'even';
1644
        printf("<tr class='" . $class . "'><td align='left'><a href='%s' target ='_blank'>%s</a></td><td align='right'>%u</td></tr>\n", $url, htmlspecialchars($news->uname($uid), ENT_QUOTES | ENT_HTML5), $reads);
1645
    }
1646
    echo '</table>';
1647
1648
    // b) Best rated authors
1649
    $bestratedauthors = $stats['bestratedauthors'];
1650
    echo '<br><br>' . _AM_NEWS_STATS8;
1651
    echo "<table border='0' width='100%'><tr class='bg3'><th>" . _AM_POSTER . '</th><th>' . _NW_RATING . "</th></tr>\n";
1652
    foreach ($bestratedauthors as $uid => $rating) {
1653
        $url   = XOOPS_URL . '/userinfo.php?uid=' . $uid;
1654
        $class = ('even' === $class) ? 'odd' : 'even';
1655
        printf("<tr class='" . $class . "'><td align='left'><a href='%s' target ='_blank'>%s</a></td><td align='right'>%u</td></tr>\n", $url, htmlspecialchars($news->uname($uid), ENT_QUOTES | ENT_HTML5), $rating);
1656
    }
1657
    echo '</table>';
1658
1659
    // c) Biggest contributors
1660
    $biggestcontributors = $stats['biggestcontributors'];
1661
    echo '<br><br>' . _AM_NEWS_STATS9;
1662
    echo "<table border='0' width='100%'><tr class='bg3'><th>" . _AM_POSTER . '</th><th>' . _AM_NEWS_STATS11 . "</th></tr>\n";
1663
    foreach ($biggestcontributors as $uid => $count) {
1664
        $url   = XOOPS_URL . '/userinfo.php?uid=' . $uid;
1665
        $class = ('even' === $class) ? 'odd' : 'even';
1666
        printf("<tr class='" . $class . "'><td align='left'><a href='%s' target ='_blank'>%s</a></td><td align='right'>%u</td></tr>\n", $url, htmlspecialchars($news->uname($uid), ENT_QUOTES | ENT_HTML5), $count);
1667
    }
1668
    echo '</table></div><br>';
1669
}
1670
1671
/**
1672
 * Metagen
1673
 *
1674
 * Metagen is a system that can help you to have your page best indexed by search engines.
1675
 * Except if you type meta keywords and meta descriptions yourself, the module will automatically create them.
1676
 * From here you can also manage some other options like the maximum number of meta keywords to create and
1677
 * the keywords apparition's order.
1678
 */
1679
function getMetagen()
1680
{
1681
    require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
1682
    global $xoopsModule, $xoopsConfig, $cfg;
1683
    /** @var News\Helper $helper */
1684
    $helper = Helper::getInstance();
0 ignored issues
show
Unused Code introduced by
The assignment to $helper is dead and can be removed.
Loading history...
1685
1686
    xoops_cp_header();
1687
    $myts = \MyTextSanitizer::getInstance();
0 ignored issues
show
Unused Code introduced by
The assignment to $myts is dead and can be removed.
Loading history...
1688
    /** @var News\Helper $helper */
1689
    $helper = Helper::getInstance();
1690
    $helper->loadLanguage('main');
1691
1692
    $adminObject = Admin::getInstance();
1693
    $adminObject->displayNavigation('index.php?op=metagen');
1694
    //echo "<h1>"._AM_NEWS_METAGEN."</h1>";
1695
    echo _AM_NEWS_METAGEN_DESC . '<br><br>';
1696
1697
    // Metagen Options
1698
    $registry = new Registryfile('news_metagen_options.txt');
1699
    $content  = '';
0 ignored issues
show
Unused Code introduced by
The assignment to $content is dead and can be removed.
Loading history...
1700
    $content  = $registry->getfile();
1701
    if ('' !== xoops_trim($content)) {
1702
        [$keywordscount, $keywordsorder] = explode(',', $content);
1703
    } else {
1704
        $keywordscount = $cfg['meta_keywords_count'];
1705
        $keywordsorder = $cfg['meta_keywords_order'];
1706
    }
1707
    $sform = new \XoopsThemeForm(_OPTIONS, 'metagenoptions', XOOPS_URL . '/modules/news/admin/index.php', 'post', true);
1708
    $sform->addElement(new \XoopsFormHidden('op', 'metagenoptions'), false);
1709
    $sform->addElement(new \XoopsFormText(_AM_NEWS_META_KEYWORDS_CNT, 'keywordscount', 4, 6, $keywordscount), true);
1710
    $keywordsorder = new \XoopsFormRadio(_AM_NEWS_META_KEYWORDS_ORDER, 'keywordsorder', $keywordsorder);
1711
    $keywordsorder->addOption(0, _AM_NEWS_META_KEYWORDS_INTEXT);
1712
    $keywordsorder->addOption(1, _AM_NEWS_META_KEYWORDS_FREQ1);
1713
    $keywordsorder->addOption(2, _AM_NEWS_META_KEYWORDS_FREQ2);
1714
    $sform->addElement($keywordsorder, false);
1715
    $buttonTray = new \XoopsFormElementTray('', '');
1716
    $submit_btn = new \XoopsFormButton('', 'post', _AM_MODIFY, 'submit');
1717
    $buttonTray->addElement($submit_btn);
1718
    $sform->addElement($buttonTray);
1719
    $sform->display();
1720
1721
    // Blacklist
1722
    $sform = new \XoopsThemeForm(_AM_NEWS_BLACKLIST, 'metagenblacklist', XOOPS_URL . '/modules/news/admin/index.php', 'post', true);
1723
    $sform->addElement(new \XoopsFormHidden('op', 'metagenblacklist'), false);
1724
1725
    // Remove words
1726
    $remove_tray = new \XoopsFormElementTray(_AM_NEWS_BLACKLIST);
1727
    $remove_tray->setDescription(_AM_NEWS_BLACKLIST_DESC);
1728
    $blacklist = new \XoopsFormSelect('', 'blacklist', '', 5, true);
1729
    $words     = [];
0 ignored issues
show
Unused Code introduced by
The assignment to $words is dead and can be removed.
Loading history...
1730
1731
    $metablack = new Blacklist();
1732
    $words     = $metablack->getAllKeywords();
1733
    if ($words && is_array($words)) {
1734
        foreach ($words as $key => $value) {
1735
            $blacklist->addOption($key, $value);
1736
        }
1737
    }
1738
1739
    $blacklist->setDescription(_AM_NEWS_BLACKLIST_DESC);
1740
    $remove_tray->addElement($blacklist, false);
1741
    $remove_btn = new \XoopsFormButton('', 'go', _AM_DELETE, 'submit');
1742
    $remove_tray->addElement($remove_btn, false);
1743
    $sform->addElement($remove_tray);
1744
1745
    // Add some words
1746
    $add_tray = new \XoopsFormElementTray(_AM_NEWS_BLACKLIST_ADD);
1747
    $add_tray->setDescription(_AM_NEWS_BLACKLIST_ADD_DSC);
1748
    $add_field = new \XoopsFormTextArea('', 'keywords', '', 5, 70);
1749
    $add_tray->addElement($add_field, false);
1750
    $add_btn = new \XoopsFormButton('', 'go', _AM_ADD, 'submit');
1751
    $add_tray->addElement($add_btn, false);
1752
    $sform->addElement($add_tray);
1753
    $sform->display();
1754
}
1755
1756
/**
1757
 * Save metagen's blacklist words
1758
 */
1759
function saveMetagenBlackList()
1760
{
1761
    $blacklist = new Blacklist();
1762
    $words     = $blacklist->getAllKeywords();
0 ignored issues
show
Unused Code introduced by
The assignment to $words is dead and can be removed.
Loading history...
1763
1764
    if (Request::hasVar('go', 'POST') && _AM_DELETE == $_POST['go']) {
1765
        foreach ($_POST['blacklist'] as $black_id) {
1766
            $blacklist->delete($black_id);
1767
        }
1768
        $blacklist->store();
1769
    } elseif (Request::hasVar('go', 'POST') && _AM_ADD == $_POST['go']) {
1770
            $p_keywords = $_POST['keywords'];
1771
            $keywords   = explode("\n", $p_keywords);
1772
            foreach ($keywords as $keyword) {
1773
                if ('' !== xoops_trim($keyword)) {
1774
                    $blacklist->addkeywords(xoops_trim($keyword));
1775
                }
1776
            }
1777
            $blacklist->store();
1778
        }
1779
    redirect_header('index.php?op=metagen', 0, _AM_DBUPDATED);
1780
}
1781
1782
/**
1783
 * Save Metagen Options
1784
 */
1785
function saveMetagenOptions()
1786
{
1787
    $registry = new Registryfile('news_metagen_options.txt');
1788
    $registry->savefile(Request::getInt('keywordscount', 0, 'POST') . ',' . Request::getInt('keywordsorder', 0, 'POST'));
1789
    redirect_header('index.php?op=metagen', 0, _AM_DBUPDATED);
1790
}
1791
1792
// **********************************************************************************************************************************************
1793
// **** Main
1794
// **********************************************************************************************************************************************
1795
$op          = Request::getString('op', 'default');
1796
$adminObject = Admin::getInstance();
1797
switch ($op) {
1798
    case 'deletefile':
1799
        xoops_cp_header();
1800
        if ('newsletter' === $_GET['type']) {
1801
            $newsfile = XOOPS_ROOT_PATH . '/uploads/news/newsletter.txt';
1802
            if (unlink($newsfile)) {
1803
                redirect_header('index.php', 2, _AM_NEWS_DELETED_OK);
1804
            } else {
1805
                redirect_header('index.php', 2, _AM_NEWS_DELETED_PB);
1806
            }
1807
        } elseif ('xml' === $_GET['type']) {
1808
                $xmlfile = XOOPS_ROOT_PATH . '/uploads/news/stories.xml';
1809
                if (unlink($xmlfile)) {
1810
                    redirect_header('index.php', 2, _AM_NEWS_DELETED_OK);
1811
                } else {
1812
                    redirect_header('index.php', 2, _AM_NEWS_DELETED_PB);
1813
                }
1814
            }
1815
        break;
1816
    case 'newarticle':
1817
        xoops_cp_header();
1818
        $adminObject->displayNavigation('index.php?op=newarticle');
1819
        echo '<h4>' . _AM_CONFIG . '</h4>';
1820
        require_once XOOPS_ROOT_PATH . '/class/module.textsanitizer.php';
1821
        newSubmissions();
1822
        autoStories();
1823
        lastStories();
1824
        expStories();
1825
        echo '<br>';
1826
        echo '<h4>' . _AM_POSTNEWARTICLE . '</h4>';
1827
        $type         = 'admin';
1828
        $title        = '';
1829
        $topicdisplay = 0;
1830
        $topicalign   = 'R';
1831
        $ihome        = 0;
1832
        $hometext     = '';
1833
        $bodytext     = '';
1834
        $notifypub    = 1;
1835
        $nohtml       = 0;
1836
        $approve      = 0;
1837
        $nosmiley     = 0;
1838
        $autodate     = '';
1839
        $expired      = '';
1840
        $topicid      = 0;
1841
        $returnside   = 1;
1842
        $published    = 0;
1843
        $description  = '';
1844
        $keywords     = '';
1845
        /** @var News\Helper $helper */
1846
        $helper = Helper::getInstance();
1847
        $helper->loadLanguage('main');
1848
1849
        if (1 == $helper->getConfig('autoapprove')) {
1850
            $approve = 1;
1851
        }
1852
        $approveprivilege = 1;
1853
        require_once XOOPS_ROOT_PATH . '/modules/news/include/storyform.original.php';
1854
        break;
1855
    case 'delete':
1856
        $storyid = 0;
1857
        if (Request::hasVar('storyid', 'GET')) {
1858
            $storyid = Request::getInt('storyid', 0, 'GET');
1859
        } elseif (Request::hasVar('storyid', 'POST')) {
1860
            $storyid = Request::getInt('storyid', 0, 'POST');
1861
        }
1862
1863
        if (Request::hasVar('ok', 'POST')) {
1864
            if (empty($storyid)) {
1865
                redirect_header('index.php?op=newarticle', 2, _AM_EMPTYNODELETE);
1866
            }
1867
            $story = new NewsStory($storyid);
1868
            $story->delete();
1869
            $sfiles   = new Files();
1870
            $filesarr = [];
1871
            $filesarr = $sfiles->getAllbyStory($storyid);
1872
            if (count($filesarr) > 0) {
1873
                foreach ($filesarr as $onefile) {
1874
                    $onefile->delete();
1875
                }
1876
            }
1877
            xoops_comment_delete($xoopsModule->getVar('mid'), $storyid);
1878
            xoops_notification_deletebyitem($xoopsModule->getVar('mid'), 'story', $storyid);
1879
            News\Utility::updateCache();
1880
            redirect_header('index.php?op=newarticle', 1, _AM_DBUPDATED);
1881
        } else {
1882
            $story = new NewsStory($storyid);
1883
            xoops_cp_header();
1884
            echo '<h4>' . _AM_CONFIG . '</h4>';
1885
            xoops_confirm(['op' => 'delete', 'storyid' => $storyid, 'ok' => 1], 'index.php', _AM_RUSUREDEL . '<br>' . $story->title());
1886
        }
1887
        break;
1888
    case 'topicsmanager':
1889
        topicsmanager();
1890
        break;
1891
    case 'addTopic':
1892
        addTopic();
1893
        break;
1894
    case 'delTopic':
1895
        delTopic();
1896
        break;
1897
    case 'modTopicS':
1898
        modTopicS();
1899
        break;
1900
    case 'edit':
1901
        /** @var News\Helper $helper */
1902
        $helper = Helper::getInstance();
1903
        $helper->loadLanguage('main');
1904
        require_once XOOPS_ROOT_PATH . '/modules/news/submit.php';
1905
        break;
1906
    case 'prune':
1907
        setPruneManager();
1908
        break;
1909
    case 'confirmbeforetoprune':
1910
        confirmBeforePrune();
1911
        break;
1912
    case 'prunenews':
1913
        pruneNews();
1914
        break;
1915
    case 'export':
1916
        exportNews();
1917
        break;
1918
    case 'launchexport':
1919
        launchExport();
1920
        break;
1921
    case 'configurenewsletter':
1922
        createNewsletter();
1923
        break;
1924
    case 'launchnewsletter':
1925
        launchNewsletter();
1926
        break;
1927
    case 'stats':
1928
        getStats();
1929
        break;
1930
    case 'metagen':
1931
        getMetagen();
1932
        break;
1933
    case 'metagenoptions':
1934
        saveMetagenOptions();
1935
        break;
1936
    case 'metagenblacklist':
1937
        saveMetagenBlackList();
1938
        break;
1939
    case 'verifydb':
1940
        xoops_cp_header();
1941
        //news_adminmenu();
1942
        $tbllist = $xoopsDB->prefix('news_stories') . ',' . $xoopsDB->prefix('news_topics') . ',' . $xoopsDB->prefix('news_stories_files') . ',' . $xoopsDB->prefix('news_stories_votedata');
1943
        $xoopsDB->queryF('OPTIMIZE TABLE ' . $tbllist);
1944
        $xoopsDB->queryF('CHECK TABLE ' . $tbllist);
1945
        $xoopsDB->queryF('ANALYZE TABLE ' . $tbllist);
1946
        redirect_header('index.php', 3, _AM_DBUPDATED);
1947
        break;
1948
    case 'default':
1949
    default:
1950
        xoops_cp_header();
1951
1952
        $folder = [
1953
            XOOPS_ROOT_PATH . '/uploads/news/',
1954
            XOOPS_ROOT_PATH . '/uploads/news/file',
1955
            XOOPS_ROOT_PATH . '/uploads/news/image',
1956
        ];
1957
1958
        $topicsHandler  = $helper->getHandler('NewsTopics');
1959
        $storiesHandler = $helper->getHandler('NewsStories');
1960
1961
        //compte "total"
1962
        $count_stories = $storiesHandler->getCount();
1963
        //compte "attente"
1964
        $criteria = new \CriteriaCompo();
1965
        $criteria->add(new \Criteria('ihome', 1));
1966
        $stories_ihome = $storiesHandler->getCount($criteria);
1967
1968
        $criteria = new \CriteriaCompo();
1969
        $criteria->add(new \Criteria('published', 0, '>'));
1970
        $stories_published = $storiesHandler->getCount($criteria);
1971
1972
        $stories_need_approval = $count_stories - $stories_published;
1973
1974
        $criteria = new \CriteriaCompo();
1975
        $criteria->add(new \Criteria('expired', 0, '>'));
1976
        $criteria->add(new \Criteria('expired', time(), '<'));
1977
        $stories_expired = $storiesHandler->getCount($criteria);
1978
1979
        $criteria = new \CriteriaCompo();
1980
        $criteria->add(new \Criteria('expired', 0, '>'));
1981
        $criteria->add(new \Criteria('expired', time(), '>'));
1982
        $stories_expired_soon = $storiesHandler->getCount($criteria);
1983
1984
        //compte "total"
1985
        $count_topics = $topicsHandler->getCount();
1986
        //compte "attente"
1987
        $criteria = new \CriteriaCompo();
1988
        $criteria->add(new \Criteria('menu', 1));
1989
        $topics_menu = $topicsHandler->getCount($criteria);
1990
1991
        $clr_count_stories = (0 == $count_stories) ? 'red' : 'green';
1992
        $clr_count_topics  = (0 == $count_topics) ? 'red' : 'green';
1993
        $clr_ihome_stories = (0 == $stories_ihome) ? 'red' : 'green';
1994
        $clr_menu_topics   = (0 == $topics_menu) ? 'red' : 'green';
1995
1996
        $clr_published_stories         = (0 == $stories_published) ? 'red' : 'green';
1997
        $clr_need_approval_stories     = (0 == $stories_need_approval) ? 'green' : 'red';
1998
        $clr_expired_stories           = (0 == $stories_expired) ? 'red' : 'green';
1999
        $clr_need_expired_soon_stories = (0 == $stories_expired_soon) ? 'red' : 'green';
2000
2001
        $adminObject->addInfoBox(_AM_NEWS_STATISTICS);
2002
        $adminObject->addInfoBoxLine(sprintf(_AM_NEWS_THEREARE_TOPICS, $count_topics), '', $clr_count_topics);
2003
        $adminObject->addInfoBoxLine(sprintf(_AM_NEWS_THEREARE_TOPICS_ONLINE, $topics_menu), '', $clr_menu_topics);
2004
        $adminObject->addInfoBoxLine(sprintf(_AM_NEWS_THEREARE_STORIES, $count_stories), '', $clr_count_stories);
2005
        $adminObject->addInfoBoxLine(sprintf(_AM_NEWS_THEREARE_STORIES_ONLINE, $stories_ihome), '', $clr_ihome_stories);
2006
2007
        $adminObject->addInfoBoxLine(sprintf(_AM_NEWS_THEREARE_STORIES_APPROVED, $stories_published), '', $clr_ihome_stories);
2008
        $adminObject->addInfoBoxLine(sprintf(_AM_NEWS_THEREARE_STORIES_NEED_APPROVAL, $stories_need_approval), '', $clr_need_approval_stories);
2009
        $adminObject->addInfoBoxLine(sprintf(_AM_NEWS_THEREARE_STORIES_EXPIRED, $stories_expired), '', $clr_expired_stories);
2010
        $adminObject->addInfoBoxLine(sprintf(_AM_NEWS_THEREARE_STORIES_EXPIRED_SOON, $stories_expired_soon), '', $clr_need_expired_soon_stories);
2011
2012
        foreach (array_keys($folder) as $i) {
2013
            $adminObject->addConfigBoxLine($folder[$i], 'folder');
2014
            $adminObject->addConfigBoxLine([$folder[$i], '777'], 'chmod');
2015
        }
2016
2017
        $adminObject->displayNavigation(basename(__FILE__));
2018
2019
        //check for latest release
2020
        //$newRelease = $utility::checkVerModule($helper);
2021
        //if (!empty($newRelease)) {
2022
        //    $adminObject->addItemButton($newRelease[0], $newRelease[1], 'download', 'style="color : Red"');
2023
        //}
2024
2025
        //------------- Test Data ----------------------------
2026
2027
        if ($helper->getConfig('displaySampleButton')) {
2028
            xoops_loadLanguage('admin/modulesadmin', 'system');
2029
            require dirname(__DIR__) . '/testdata/index.php';
2030
2031
            $adminObject->addItemButton(constant('CO_' . $moduleDirNameUpper . '_' . 'ADD_SAMPLEDATA'), './../testdata/index.php?op=load', 'add');
2032
2033
            $adminObject->addItemButton(constant('CO_' . $moduleDirNameUpper . '_' . 'SAVE_SAMPLEDATA'), './../testdata/index.php?op=save', 'add');
2034
2035
            //    $adminObject->addItemButton(constant('CO_' . $moduleDirNameUpper . '_' . 'EXPORT_SCHEMA'), './../testdata/index.php?op=exportschema', 'add');
2036
2037
            $adminObject->displayButton('left', '');
2038
        }
2039
2040
        //------------- End Test Data ----------------------------
2041
2042
        $adminObject->displayIndex();
2043
2044
        echo $utility::getServerStats();
2045
2046
        break;
2047
}
2048
require_once __DIR__ . '/admin_footer.php';
2049