Completed
Push — master ( b610c1...53db9c )
by Michael
03:25 queued 01:39
created

index.php ➔ Stats()   F

Complexity

Conditions 21
Paths > 20000

Size

Total Lines 190
Code Lines 157

Duplication

Lines 41
Ratio 21.58 %

Importance

Changes 0
Metric Value
cc 21
eloc 157
nc 96228
nop 0
dl 41
loc 190
rs 2
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
B index.php ➔ getMetagen() 5 74 6
C index.php ➔ saveMetagenBlackList() 0 24 8
A index.php ➔ saveMetagenOptions() 0 6 1

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

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

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

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

Loading history...
2
//
3
// ------------------------------------------------------------------------ //
4
// XOOPS - PHP Content Management System                                    //
5
// Copyright (c) 2000-2016 XOOPS.org                                             //
6
// <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
require_once __DIR__ . '/../../../include/cp_header.php';
28
require_once __DIR__ . '/admin_header.php';
29
require_once XOOPS_ROOT_PATH . '/modules/news/class/xoopstopic.php';
30
require_once XOOPS_ROOT_PATH . '/class/xoopslists.php';
31
require_once XOOPS_ROOT_PATH . '/modules/news/config.php';
32
require_once XOOPS_ROOT_PATH . '/modules/news/class/class.newsstory.php';
33
require_once XOOPS_ROOT_PATH . '/modules/news/class/class.newstopic.php';
34
require_once XOOPS_ROOT_PATH . '/modules/news/class/class.sfiles.php';
35
require_once XOOPS_ROOT_PATH . '/modules/news/class/blacklist.php';
36
require_once XOOPS_ROOT_PATH . '/modules/news/class/registryfile.php';
37
require_once XOOPS_ROOT_PATH . '/class/uploader.php';
38
require_once XOOPS_ROOT_PATH . '/class/pagenav.php';
39
require_once XOOPS_ROOT_PATH . '/modules/news/admin/functions.php';
40
require_once XOOPS_ROOT_PATH . '/modules/news/class/utility.php';
41
require_once XOOPS_ROOT_PATH . '/modules/news/class/tree.php';
42
$dateformat  = NewsUtility::getModuleOption('dateformat');
43
$myts        = MyTextSanitizer::getInstance();
44
$topicscount = 0;
45
46
$storiesTableName = $xoopsDB->prefix('news_stories');
47
if (!NewsUtility::existField('picture', $storiesTableName)) {
48
    NewsUtility::addField('`picture` VARCHAR( 50 ) NOT NULL', $storiesTableName);
49
}
50
51
/**
52
 * Show new submissions
53
 *
54
 * This list can be view in the module's admin when you click on the tab named "Post/Edit News"
55
 * Submissions are news that was submit by users but who are not approved, so you need to edit
56
 * them to approve them.
57
 * Actually you can see the the story's title, the topic, the posted date, the author and a
58
 * link to delete the story. If you click on the story's title, you will be able to edit the news.
59
 * The table contains the last x new submissions.
60
 * The system's block called "Waiting Contents" is listing the number of those news.
61
 */
62
function newSubmissions()
0 ignored issues
show
Coding Style introduced by
newSubmissions uses the super-global variable $_GET which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
63
{
64
    global $dateformat, $pathIcon16;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
65
    $start       = isset($_GET['startnew']) ? (int)$_GET['startnew'] : 0;
66
    $newsubcount = NewsStory:: getAllStoriesCount(3, false);
67
    $storyarray  = NewsStory:: getAllSubmitted(NewsUtility::getModuleOption('storycountadmin'), true, NewsUtility::getModuleOption('restrictindex'), $start);
68
    if (count($storyarray) > 0) {
69
        $pagenav = new XoopsPageNav($newsubcount, NewsUtility::getModuleOption('storycountadmin'), $start, 'startnew', 'op=newarticle');
70
        news_collapsableBar('newsub', 'topnewsubicon');
71
        echo "<img onclick=\"toggle('toptable'); toggleIcon('toptableicon');\" id='topnewsubicon' name='topnewsubicon' src='" . $pathIcon16 . "/close12.gif' alt=''></a>&nbsp;" . _AM_NEWSUB . '</h4>';
72
        echo "<div id='newsub'>";
73
        echo '<br>';
74
        echo "<div class='center;'><table width='100%' cellspacing='1' cellpadding='3' border='0' class='outer'><tr class='bg3'><th align='center'>"
75
             . _AM_TITLE
76
             . "</th><th align='center'>"
77
             . _AM_TOPIC
78
             . "</th><th align='center'>"
79
             . _AM_POSTED
80
             . "</th><th align='center'>"
81
             . _AM_POSTER
82
             . "</th><th align='center'>"
83
             . _AM_NEWS_ACTION
84
             . "</th></tr>\n";
85
        $class = '';
86
        foreach ($storyarray as $newstory) {
87
            $class = ('even' === $class) ? 'odd' : 'even';
88
            echo "<tr class='" . $class . "'><td align='left'>\n";
89
            $title = $newstory->title();
90
            if (!isset($title) || ('' === $title)) {
91
                echo "<a href='" . XOOPS_URL . '/modules/news/admin/index.php?op=edit&amp;returnside=1&amp;storyid=' . $newstory->storyid() . "'>" . _MD_NEWS_NOSUBJECT . "</a>\n";
92
            } else {
93
                echo "&nbsp;<a href='" . XOOPS_URL . '/modules/news/submit.php?returnside=1&amp;op=edit&amp;storyid=' . $newstory->storyid() . "'>" . $title . "</a>\n";
94
            }
95
            echo '</td><td>'
96
                 . $newstory->topic_title()
97
                 . "</td><td align='center' class='nw'>"
98
                 . formatTimestamp($newstory->created(), $dateformat)
99
                 . "</td><td align='center'><a href='"
100
                 . XOOPS_URL
101
                 . '/userinfo.php?uid='
102
                 . $newstory->uid()
103
                 . "'>"
104
                 . $newstory->uname()
105
                 . "</a></td><td align='center'><a href='"
106
                 . XOOPS_URL
107
                 . '/modules/news/submit.php?returnside=1&amp;op=edit&amp;storyid='
108
                 . $newstory->storyid()
109
                 . "'><img src='"
110
                 . $pathIcon16
111
                 . "/edit.png' title='"
112
                 . _AM_EDIT
113
                 . "'></a><a href='"
114
                 . XOOPS_URL
115
                 . '/modules/news/admin/index.php?op=delete&amp;storyid='
116
                 . $newstory->storyid()
117
                 . "'><img src='"
118
                 . $pathIcon16
119
                 . "/delete.png' title='"
120
                 . _AM_DELETE
121
                 . "'></a></td></tr>\n";
122
        }
123
124
        echo '</table></div>';
125
        echo "<div align='right'>" . $pagenav->renderNav() . '</div><br>';
126
        echo '<br></div><br>';
127
    }
128
}
129
130
/**
131
 * Shows all automated stories
132
 *
133
 * Automated stories are stories that have a publication's date greater than "now"
134
 * This list can be view in the module's admin when you click on the tab named "Post/Edit News"
135
 * Actually you can see the story's ID, its title, the topic, the author, the
136
 * programmed date and time, the expiration's date  and two links. The first link is
137
 * used to edit the story while the second is used to remove the story.
138
 * The list only contains the last (x) automated news
139
 */
140
function autoStories()
0 ignored issues
show
Coding Style introduced by
autoStories uses the super-global variable $_GET which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
141
{
142
    global $dateformat, $pathIcon16;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
143
144
    $start        = isset($_GET['startauto']) ? (int)$_GET['startauto'] : 0;
145
    $storiescount = NewsStory:: getAllStoriesCount(2, false);
146
    $storyarray   = NewsStory:: getAllAutoStory(NewsUtility::getModuleOption('storycountadmin'), true, $start);
147
    $class        = '';
148
    if (count($storyarray) > 0) {
149
        $pagenav = new XoopsPageNav($storiescount, NewsUtility::getModuleOption('storycountadmin'), $start, 'startauto', 'op=newarticle');
150
        news_collapsableBar('autostories', 'topautostories');
151
        echo "<img onclick=\"toggle('toptable'); toggleIcon('toptableicon');\" id='topautostories' name='topautostories' src='" . $pathIcon16 . "/close12.gif' alt=''></a>&nbsp;" . _AM_AUTOARTICLES . '</h4>';
152
        echo "<div id='autostories'>";
153
        echo '<br>';
154
        echo "<div class='center;'>\n";
155
        echo "<table width='100%' cellspacing='1' cellpadding='3' border='0' class='outer'><tr class='bg3'><th align='center'>"
156
             . _AM_STORYID
157
             . "</th><th align='center'>"
158
             . _AM_TITLE
159
             . "</th><th align='center'>"
160
             . _AM_TOPIC
161
             . "</th><th align='center'>"
162
             . _AM_POSTER
163
             . "</th><th align='center' class='nw'>"
164
             . _AM_PROGRAMMED
165
             . "</th><th align='center' class='nw'>"
166
             . _AM_EXPIRED
167
             . "</th><th align='center'>"
168
             . _AM_NEWS_ACTION
169
             . '</th></tr>';
170 View Code Duplication
        foreach ($storyarray as $autostory) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
171
            $topic  = $autostory->topic();
172
            $expire = ($autostory->expired() > 0) ? formatTimestamp($autostory->expired(), $dateformat) : '';
173
            $class  = ('even' === $class) ? 'odd' : 'even';
174
            echo "<tr class='" . $class . "'>";
175
            echo "<td align='center'><b>"
176
                 . $autostory->storyid()
177
                 . "</b>
178
                </td><td align='left'><a href='"
179
                 . XOOPS_URL
180
                 . '/modules/news/article.php?storyid='
181
                 . $autostory->storyid()
182
                 . "'>"
183
                 . $autostory->title()
184
                 . "</a>
185
                </td><td align='center'>"
186
                 . $topic->topic_title()
187
                 . "
188
                </td><td align='center'><a href='"
189
                 . XOOPS_URL
190
                 . '/userinfo.php?uid='
191
                 . $autostory->uid()
192
                 . "'>"
193
                 . $autostory->uname()
194
                 . "</a></td><td align='center' class='nw'>"
195
                 . formatTimestamp($autostory->published(), $dateformat)
196
                 . "</td><td align='center'>"
197
                 . $expire
198
                 . "</td><td align='center'><a href='"
199
                 . XOOPS_URL
200
                 . '/modules/news/submit.php?returnside=1&amp;op=edit&amp;storyid='
201
                 . $autostory->storyid()
202
                 . "'><img src='"
203
                 . $pathIcon16
204
                 . "/edit.png' title="
205
                 . _AM_EDIT
206
                 . "> </a> <a href='"
207
                 . XOOPS_URL
208
                 . '/modules/news/admin/index.php?op=delete&amp;storyid='
209
                 . $autostory->storyid()
210
                 . "'><img src='"
211
                 . $pathIcon16
212
                 . "/delete.png' title='"
213
                 . _AM_DELETE
214
                 . "'></a>";
215
216
            echo "</td></tr>\n";
217
        }
218
        echo '</table></div>';
219
        echo "<div align='right'>" . $pagenav->renderNav() . '</div><br>';
220
        echo '</div><br>';
221
    }
222
}
223
224
/**
225
 * Shows last x published stories
226
 *
227
 * This list can be view in the module's admin when you click on the tab named "Post/Edit News"
228
 * Actually you can see the the story's ID, its title, the topic, the author, the number of hits
229
 * and two links. The first link is used to edit the story while the second is used to remove the story.
230
 * The table only contains the last X published stories.
231
 * You can modify the number of visible stories with the module's option named
232
 * "Number of new articles to display in admin area".
233
 * As the number of displayed stories is limited, below this list you can find a text box
234
 * that you can use to enter a story's Id, then with the scrolling list you can select
235
 * if you want to edit or delete the story.
236
 */
237
function lastStories()
0 ignored issues
show
Coding Style introduced by
lastStories uses the super-global variable $_GET which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
238
{
239
    global $dateformat, $pathIcon16;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
240
    news_collapsableBar('laststories', 'toplaststories');
241
    echo "<img onclick=\"toggle('toptable'); toggleIcon('toptableicon');\" id='toplaststories' name='toplaststories' src='" . $pathIcon16 . "/close12.gif' alt=''></a>&nbsp;" . sprintf(_AM_LAST10ARTS, NewsUtility::getModuleOption('storycountadmin')) . '</h4>';
242
    echo "<div id='laststories'>";
243
    echo '<br>';
244
    echo "<div class='center;'>";
245
    $start        = isset($_GET['start']) ? (int)$_GET['start'] : 0;
246
    $storyarray   = NewsStory:: getAllPublished(NewsUtility::getModuleOption('storycountadmin'), $start, false, 0, 1);
247
    $storiescount = NewsStory:: getAllStoriesCount(4, false);
248
    $pagenav      = new XoopsPageNav($storiescount, NewsUtility::getModuleOption('storycountadmin'), $start, 'start', 'op=newarticle');
249
    $class        = '';
250
    echo "<table width='100%' cellspacing='1' cellpadding='3' border='0' class='outer'><tr class='bg3'><th align='center'>"
251
         . _AM_STORYID
252
         . "</th><th align='center'>"
253
         . _AM_TITLE
254
         . "</th><th align='center'>"
255
         . _AM_TOPIC
256
         . "</th><th align='center'>"
257
         . _AM_POSTER
258
         . "</th><th align='center' class='nw'>"
259
         . _AM_PUBLISHED
260
         . "</th><th align='center' class='nw'>"
261
         . _AM_HITS
262
         . "</th><th align='center'>"
263
         . _AM_NEWS_ACTION
264
         . '</th></tr>';
265
    foreach ($storyarray as $eachstory) {
0 ignored issues
show
Bug introduced by
The expression $storyarray of type null|array is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
266
        $published = formatTimestamp($eachstory->published(), $dateformat);
267
        // $expired = ( $eachstory -> expired() > 0 ) ? formatTimestamp($eachstory->expired(),$dateformat) : '---';
0 ignored issues
show
Unused Code Comprehensibility introduced by
53% of this comment could be valid code. Did you maybe forget this after debugging?

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

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

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

Loading history...
268
        $topic = $eachstory->topic();
269
        $class = ('even' === $class) ? 'odd' : 'even';
270
        echo "<tr class='" . $class . "'>";
271
        echo "<td align='center'><b>" . $eachstory->storyid() . "</b>
272
            </td><td align='left'><a href='" . XOOPS_URL . '/modules/news/article.php?storyid=' . $eachstory->storyid() . "'>" . $eachstory->title() . "</a>
273
            </td><td align='center'>" . $topic->topic_title() . "
274
            </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'>
275
            <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>
276
            <a href='" . XOOPS_URL . '/modules/news/admin/index.php?op=delete&amp;storyid=' . $eachstory->storyid() . "'><img src='" . $pathIcon16 . "/delete.png' title='" . _AM_DELETE . "'></a>";
277
278
        echo "</td></tr>\n";
279
    }
280
    echo '</table><br>';
281
    echo "<div align='right'>" . $pagenav->renderNav() . '</div><br>';
282
283
    echo "<form action='index.php' method='get'>" . _AM_STORYID . " <input type='text' name='storyid' size='10'>
284
        <select name='op'>
285
            <option value='edit' selected>" . _AM_EDIT . "</option>
286
            <option value='delete'>" . _AM_DELETE . "</option>
287
        </select>
288
        <input type='hidden' name='returnside' value='1'>
289
        <input type='submit' value='" . _AM_GO . "'>
290
        </form>
291
    </div>";
292
    echo '</div><br>';
293
}
294
295
/**
296
 * Display a list of the expired stories
297
 *
298
 * This list can be view in the module's admin when you click on the tab named "Post/Edit News"
299
 * Actually you can see the story's ID, the title, the topic, the author,
300
 * the creation and expiration's date and you have two links, one to delete
301
 * the story and the other to edit the story.
302
 * The table only contains the last X expired stories.
303
 * You can modify the number of visible stories with the module's option named
304
 * "Number of new articles to display in admin area".
305
 * As the number of displayed stories is limited, below this list you can find a text box
306
 * that you can use to enter a story's Id, then with the scrolling list you can select
307
 * if you want to edit or delete the story.
308
 */
309
function expStories()
0 ignored issues
show
Coding Style introduced by
expStories uses the super-global variable $_GET which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
310
{
311
    global $dateformat, $pathIcon16;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
312
    $start        = isset($_GET['startexp']) ? (int)$_GET['startexp'] : 0;
313
    $expiredcount = NewsStory:: getAllStoriesCount(1, false);
314
    $storyarray   = NewsStory:: getAllExpired(NewsUtility::getModuleOption('storycountadmin'), $start, 0, 1);
315
    $pagenav      = new XoopsPageNav($expiredcount, NewsUtility::getModuleOption('storycountadmin'), $start, 'startexp', 'op=newarticle');
316
317
    if (count($storyarray) > 0) {
318
        $class = '';
319
        news_collapsableBar('expstories', 'topexpstories');
320
        echo "<img onclick=\"toggle('toptable'); toggleIcon('toptableicon');\" id='topexpstories' name='topexpstories' src='" . $pathIcon16 . "/close12.gif' alt=''></a>&nbsp;" . _AM_EXPARTS . '</h4>';
321
        echo "<div id='expstories'>";
322
        echo '<br>';
323
        echo "<div class='center;'>";
324
        echo "<table width='100%' cellspacing='1' cellpadding='3' border='0' class='outer'><tr class='bg3'><th align='center'>"
325
             . _AM_STORYID
326
             . "</th><th align='center'>"
327
             . _AM_TITLE
328
             . "</th><th align='center'>"
329
             . _AM_TOPIC
330
             . "</th><th align='center'>"
331
             . _AM_POSTER
332
             . "</th><th align='center' class='nw'>"
333
             . _AM_CREATED
334
             . "</th><th align='center' class='nw'>"
335
             . _AM_EXPIRED
336
             . "</th><th align='center'>"
337
             . _AM_NEWS_ACTION
338
             . '</th></tr>';
339 View Code Duplication
        foreach ($storyarray as $eachstory) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
340
            $created = formatTimestamp($eachstory->created(), $dateformat);
341
            $expired = formatTimestamp($eachstory->expired(), $dateformat);
342
            $topic   = $eachstory->topic();
343
            // added exired value field to table
344
            $class = ('even' === $class) ? 'odd' : 'even';
345
            echo "<tr class='" . $class . "'>";
346
            echo "<td align='center'><b>" . $eachstory->storyid() . "</b>
347
                </td><td align='left'><a href='" . XOOPS_URL . '/modules/news/article.php?returnside=1&amp;storyid=' . $eachstory->storyid() . "'>" . $eachstory->title() . "</a>
348
                </td><td align='center'>" . $topic->topic_title() . "
349
                </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'>
350
                <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>
351
                <a href='" . XOOPS_URL . '/modules/news/admin/index.php?op=delete&amp;storyid=' . $eachstory->storyid() . "'><img src='" . $pathIcon16 . "/delete.png' title='" . _AM_DELETE . "'></a>";
352
353
            echo "</td></tr>\n";
354
        }
355
        echo '</table><br>';
356
        echo "<div align='right'>" . $pagenav->renderNav() . '</div><br>';
357
        echo "<form action='index.php' method='get'>
358
            " . _AM_STORYID . " <input type='text' name='storyid' size='10'>
359
            <select name='op'>
360
                <option value='edit' selected>" . _AM_EDIT . "</option>
361
                <option value='delete'>" . _AM_DELETE . "</option>
362
            </select>
363
            <input type='hidden' name='returnside' value='1'>
364
            <input type='submit' value='" . _AM_GO . "'>
365
            </form>
366
        </div>";
367
        echo '</div><br>';
368
    }
369
}
370
371
/**
372
 * Delete (purge/prune) old stories
373
 *
374
 * You can use this function in the module's admin when you click on the tab named "Prune News"
375
 * It's useful to remove old stories. It is, of course, recommended
376
 * to backup (or export) your news before to purge news.
377
 * You must first specify a date. This date will be used as a reference, everything
378
 * that was published before this date will be deleted.
379
 * The option "Only remove stories who have expired" will enable you to only remove
380
 * expired stories published before the given date.
381
 * Finally, you can select the topics inside wich you will remove news.
382
 * Once you have set all the parameters, the script will first show you a confirmation's
383
 * message with the number of news that will be removed.
384
 * Note, the topics are not deleted (even if there are no more news inside them).
385
 */
386
function setPruneManager()
387
{
388
    require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
389
    xoops_cp_header();
390
    $adminObject = \Xmf\Module\Admin::getInstance();
391
    $adminObject->displayNavigation('index.php?op=prune');
392
    echo '<br><br><br>';
393
    $sform = new XoopsThemeForm(_AM_NEWS_PRUNENEWS, 'pruneform', XOOPS_URL . '/modules/news/admin/index.php', 'post', true);
394
    $sform->addElement(new XoopsFormTextDateSelect(_AM_NEWS_PRUNE_BEFORE, 'prune_date', 15, time()), true);
395
    $onlyexpired = new xoopsFormCheckBox('', 'onlyexpired');
396
    $onlyexpired->addOption(1, _AM_NEWS_PRUNE_EXPIREDONLY);
397
    $sform->addElement($onlyexpired, false);
398
    $sform->addElement(new XoopsFormHidden('op', 'confirmbeforetoprune'), false);
399
    $topiclist  = new XoopsFormSelect(_AM_NEWS_PRUNE_TOPICS, 'pruned_topics', '', 5, true);
400
    $topics_arr = [];
0 ignored issues
show
Unused Code introduced by
$topics_arr is not used, you could remove the assignment.

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

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

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

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

Loading history...
401
    $xt         = new NewsTopic();
402
    $allTopics  = $xt->getAllTopics(false); // The webmaster can see everything
403
    $topic_tree = new MyXoopsObjectTree($allTopics, 'topic_id', 'topic_pid');
404
    $topics_arr = $topic_tree->getAllChild(0);
405
    if (count($topics_arr)) {
406
        foreach ($topics_arr as $onetopic) {
407
            $topiclist->addOption($onetopic->topic_id(), $onetopic->topic_title());
408
        }
409
    }
410
    $topiclist->setDescription(_AM_NEWS_EXPORT_PRUNE_DSC);
411
    $sform->addElement($topiclist, false);
412
    $button_tray = new XoopsFormElementTray('', '');
413
    $submit_btn  = new XoopsFormButton('', 'post', _SUBMIT, 'submit');
414
    $button_tray->addElement($submit_btn);
415
    $sform->addElement($button_tray);
416
    $sform->display();
417
}
418
419
// A confirmation is asked before to prune stories
420
function confirmBeforePrune()
0 ignored issues
show
Coding Style introduced by
confirmBeforePrune uses the super-global variable $_POST which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
421
{
422
    global $dateformat;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
423
    $story = new NewsStory();
424
    xoops_cp_header();
425
    $topiclist = '';
426
    if (isset($_POST['pruned_topics'])) {
427
        $topiclist = implode(',', $_POST['pruned_topics']);
428
    }
429
    echo '<h4>' . _AM_NEWS_PRUNENEWS . '</h4>';
430
    $expired = 0;
431
    if (isset($_POST['onlyexpired'])) {
432
        $expired = (int)$_POST['onlyexpired'];
433
    }
434
    $date      = $_POST['prune_date'];
435
    $timestamp = mktime(0, 0, 0, (int)substr($date, 5, 2), (int)substr($date, 8, 2), (int)substr($date, 0, 4));
436
    $count     = $story->getCountStoriesPublishedBefore($timestamp, $expired, $topiclist);
437
    if ($count) {
438
        $displaydate = formatTimestamp($timestamp, $dateformat);
439
        $msg         = sprintf(_AM_NEWS_PRUNE_CONFIRM, $displaydate, $count);
440
        xoops_confirm([
441
                          'op'            => 'prunenews',
442
                          'expired'       => $expired,
443
                          'pruned_topics' => $topiclist,
444
                          'prune_date'    => $timestamp,
445
                          'ok'            => 1
446
                      ], 'index.php', $msg);
447
    } else {
448
        printf(_AM_NEWS_NOTHING_PRUNE);
449
    }
450
    unset($story);
451
}
452
453
// Effectively delete stories (published before a date), no more confirmation
454
function pruneNews()
0 ignored issues
show
Coding Style introduced by
pruneNews uses the super-global variable $_POST which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
455
{
456
    $story     = new NewsStory();
0 ignored issues
show
Unused Code introduced by
$story is not used, you could remove the assignment.

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

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

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

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

Loading history...
457
    $timestamp = (int)$_POST['prune_date'];
458
    $expired   = (int)$_POST['expired'];
459
    $topiclist = '';
460
    if (isset($_POST['pruned_topics'])) {
461
        $topiclist = $_POST['pruned_topics'];
462
    }
463
464
    if (1 == (int)$_POST['ok']) {
465
        $story = new NewsStory();
466
        xoops_cp_header();
467
        $count = $story->getCountStoriesPublishedBefore($timestamp, $expired, $topiclist);
468
        $msg   = sprintf(_AM_NEWS_PRUNE_DELETED, $count);
469
        $story->deleteBeforeDate($timestamp, $expired, $topiclist);
470
        unset($story);
471
        NewsUtility::updateCache();
472
        redirect_header('index.php', 3, $msg);
473
    }
474
}
475
476
/**
477
 * Newsletter's configuration
478
 *
479
 * You can create a newsletter's content from the admin part of the News module when you click on the tab named "Newsletter"
480
 * First, let be clear, this module'functionality will not send the newsletter but it will prepare its content for you.
481
 * To send the newsletter, you can use many specialized modules like evennews.
482
 * You first select a range of dates and if you want, a selection of topics to use for the search.
483
 * Once it's done, the script will use the file named /xoops/modules/language/yourlanguage/newsletter.php to create
484
 * the newsletter's content. When it's finished, the script generates a file in the upload folder.
485
 */
486
function createNewsletter()
487
{
488
    require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
489
    xoops_cp_header();
490
    $adminObject = \Xmf\Module\Admin::getInstance();
491
    $adminObject->displayNavigation('index.php?op=configurenewsletter');
492
    echo '<br><br><br>';
493
    $sform      = new XoopsThemeForm(_AM_NEWS_NEWSLETTER, 'newsletterform', XOOPS_URL . '/modules/news/admin/index.php', 'post', true);
494
    $dates_tray = new XoopsFormElementTray(_AM_NEWS_NEWSLETTER_BETWEEN);
495
    $date1      = new XoopsFormTextDateSelect('', 'date1', 15, time());
496
    $date2      = new XoopsFormTextDateSelect(_AM_NEWS_EXPORT_AND, 'date2', 15, time());
497
    $dates_tray->addElement($date1);
498
    $dates_tray->addElement($date2);
499
    $sform->addElement($dates_tray);
500
501
    $topiclist  = new XoopsFormSelect(_AM_NEWS_PRUNE_TOPICS, 'export_topics', '', 5, true);
502
    $topics_arr = [];
0 ignored issues
show
Unused Code introduced by
$topics_arr is not used, you could remove the assignment.

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

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

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

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

Loading history...
503
    $xt         = new NewsTopic();
504
    $allTopics  = $xt->getAllTopics(false); // The webmaster can see everything
505
    $topic_tree = new MyXoopsObjectTree($allTopics, 'topic_id', 'topic_pid');
506
    $topics_arr = $topic_tree->getAllChild(0);
507
    if (count($topics_arr)) {
508
        foreach ($topics_arr as $onetopic) {
509
            $topiclist->addOption($onetopic->topic_id(), $onetopic->topic_title());
510
        }
511
    }
512
    $topiclist->setDescription(_AM_NEWS_EXPORT_PRUNE_DSC);
513
    $sform->addElement($topiclist, false);
514
    $sform->addElement(new XoopsFormHidden('op', 'launchnewsletter'), false);
515
    $sform->addElement(new XoopsFormRadioYN(_AM_NEWS_REMOVE_BR, 'removebr', 1), false);
516
    $sform->addElement(new XoopsFormRadioYN(_AM_NEWS_NEWSLETTER_HTML_TAGS, 'removehtml', 0), false);
517
    $sform->addElement(new XoopsFormTextArea(_AM_NEWS_NEWSLETTER_HEADER, 'header', '', 4, 70), false);
518
    $sform->addElement(new XoopsFormTextArea(_AM_NEWS_NEWSLETTER_FOOTER, 'footer', '', 4, 70), false);
519
    $button_tray = new XoopsFormElementTray('', '');
520
    $submit_btn  = new XoopsFormButton('', 'post', _SUBMIT, 'submit');
521
    $button_tray->addElement($submit_btn);
522
    $sform->addElement($button_tray);
523
    $sform->display();
524
}
525
526
/**
527
 * Launch the creation of the newsletter's content
528
 */
529
function launchNewsletter()
0 ignored issues
show
Coding Style introduced by
launchNewsletter uses the super-global variable $_POST which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
530
{
531
    global $xoopsConfig, $dateformat;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
532
    xoops_cp_header();
533
    $adminObject = \Xmf\Module\Admin::getInstance();
534
    $adminObject->displayNavigation('index.php?op=configurenewsletter');
535
    $newslettertemplate = '';
536 View Code Duplication
    if (file_exists(XOOPS_ROOT_PATH . '/modules/news/language/' . $xoopsConfig['language'] . '/newsletter.php')) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
537
        require_once XOOPS_ROOT_PATH . '/modules/news/language/' . $xoopsConfig['language'] . '/newsletter.php';
538
    } else {
539
        require_once XOOPS_ROOT_PATH . '/modules/news/language/english/newsletter.php';
540
    }
541
    echo '<br>';
542
    $story           = new NewsStory();
543
    $exportedstories = [];
0 ignored issues
show
Unused Code introduced by
$exportedstories is not used, you could remove the assignment.

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

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

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

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

Loading history...
544
    $topiclist       = '';
545
    $removebr        = $removehtml = false;
0 ignored issues
show
Unused Code introduced by
$removehtml is not used, you could remove the assignment.

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

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

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

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

Loading history...
Unused Code introduced by
$removebr is not used, you could remove the assignment.

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

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

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

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

Loading history...
546
    $removebr        = isset($_POST['removebr']) ? (int)$_POST['removebr'] : 0;
547
    $removehtml      = isset($_POST['removehtml']) ? (int)$_POST['removehtml'] : 0;
548
    $header          = isset($_POST['header']) ? $_POST['header'] : '';
549
    $footer          = isset($_POST['footer']) ? $_POST['footer'] : '';
550
    $date1           = $_POST['date1'];
551
    $date2           = $_POST['date2'];
552
    $timestamp1      = mktime(0, 0, 0, (int)substr($date1, 5, 2), (int)substr($date1, 8, 2), (int)substr($date1, 0, 4));
553
    $timestamp2      = mktime(23, 59, 59, (int)substr($date2, 5, 2), (int)substr($date2, 8, 2), (int)substr($date2, 0, 4));
554
    if (isset($_POST['export_topics'])) {
555
        $topiclist = implode(',', $_POST['export_topics']);
556
    }
557
    $tbltopics       = [];
558
    $exportedstories = $story->exportNews($timestamp1, $timestamp2, $topiclist, 0, $tbltopics);
559
    $newsfile        = XOOPS_ROOT_PATH . '/uploads/news/letter.txt';
560
    if (count($exportedstories)) {
561
        $fp = fopen($newsfile, 'w');
562
        if (!$fp) {
563
            redirect_header('index.php', 4, sprintf(_AM_NEWS_EXPORT_ERROR, $newsfile));
564
        }
565
        if ('' !== xoops_trim($header)) {
566
            fwrite($fp, $header);
567
        }
568
        foreach ($exportedstories as $onestory) {
569
            $content         = $newslettertemplate;
570
            $search_pattern  = [
571
                '%title%',
572
                '%uname%',
573
                '%created%',
574
                '%published%',
575
                '%expired%',
576
                '%hometext%',
577
                '%bodytext%',
578
                '%description%',
579
                '%keywords%',
580
                '%reads%',
581
                '%topicid%',
582
                '%topic_title%',
583
                '%comments%',
584
                '%rating%',
585
                '%votes%',
586
                '%publisher%',
587
                '%publisher_id%',
588
                '%link%'
589
            ];
590
            $replace_pattern = [
591
                $onestory->title(),
592
                $onestory->uname(),
593
                formatTimestamp($onestory->created(), $dateformat),
594
                formatTimestamp($onestory->published(), $dateformat),
595
                formatTimestamp($onestory->expired(), $dateformat),
596
                $onestory->hometext(),
597
                $onestory->bodytext(),
598
                $onestory->description(),
599
                $onestory->keywords(),
600
                $onestory->counter(),
601
                $onestory->topicid(),
602
                $onestory->topic_title(),
603
                $onestory->comments(),
604
                $onestory->rating(),
605
                $onestory->votes(),
606
                $onestory->uname(),
607
                $onestory->uid(),
608
                XOOPS_URL . '/modules/news/article.php?storyid=' . $onestory->storyid()
609
            ];
610
            $content         = str_replace($search_pattern, $replace_pattern, $content);
611
            if ($removebr) {
612
                $content = str_replace('<br>', "\r\n", $content);
613
            }
614
            if ($removehtml) {
615
                $content = strip_tags($content);
616
            }
617
            fwrite($fp, $content);
618
        }
619
        if ('' !== xoops_trim($footer)) {
620
            fwrite($fp, $footer);
621
        }
622
        fclose($fp);
623
        $newsfile = XOOPS_URL . '/uploads/news/newsletter.txt';
624
        printf(_AM_NEWS_NEWSLETTER_READY, $newsfile, XOOPS_URL . '/modules/news/admin/index.php?op=deletefile&amp;type=newsletter');
625
    } else {
626
        printf(_AM_NEWS_NOTHING);
627
    }
628
}
629
630
/**
631
 * News export
632
 *
633
 * You can use this function in the module's admin when you click on the tab named "News Export"
634
 * First select a range of date, possibly a range of topics and if you want, check the option "Include Topics Definitions"
635
 * to also export the topics.
636
 * News, and topics, will be exported to the XML format.
637
 */
638
function exportNews()
639
{
640
    require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
641
    xoops_cp_header();
642
    $adminObject = \Xmf\Module\Admin::getInstance();
643
    $adminObject->displayNavigation('index.php?op=export');
644
    echo '<br><br><br>';
645
    $sform      = new XoopsThemeForm(_AM_NEWS_EXPORT_NEWS, 'exportform', XOOPS_URL . '/modules/news/admin/index.php', 'post', true);
646
    $dates_tray = new XoopsFormElementTray(_AM_NEWS_EXPORT_BETWEEN);
647
    $date1      = new XoopsFormTextDateSelect('', 'date1', 15, time());
648
    $date2      = new XoopsFormTextDateSelect(_AM_NEWS_EXPORT_AND, 'date2', 15, time());
649
    $dates_tray->addElement($date1);
650
    $dates_tray->addElement($date2);
651
    $sform->addElement($dates_tray);
652
653
    $topiclist  = new XoopsFormSelect(_AM_NEWS_PRUNE_TOPICS, 'export_topics', '', 5, true);
654
    $topics_arr = [];
0 ignored issues
show
Unused Code introduced by
$topics_arr is not used, you could remove the assignment.

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

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

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

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

Loading history...
655
    $xt         = new NewsTopic();
656
    $allTopics  = $xt->getAllTopics(false); // The webmaster can see everything
657
    $topic_tree = new MyXoopsObjectTree($allTopics, 'topic_id', 'topic_pid');
658
    $topics_arr = $topic_tree->getAllChild(0);
659
    if (count($topics_arr)) {
660
        foreach ($topics_arr as $onetopic) {
661
            $topiclist->addOption($onetopic->topic_id(), $onetopic->topic_title());
662
        }
663
    }
664
    $topiclist->setDescription(_AM_NEWS_EXPORT_PRUNE_DSC);
665
    $sform->addElement($topiclist, false);
666
    $sform->addElement(new XoopsFormRadioYN(_AM_NEWS_EXPORT_INCTOPICS, 'includetopics', 0), false);
667
    $sform->addElement(new XoopsFormHidden('op', 'launchexport'), false);
668
    $button_tray = new XoopsFormElementTray('', '');
669
    $submit_btn  = new XoopsFormButton('', 'post', _SUBMIT, 'submit');
670
    $button_tray->addElement($submit_btn);
671
    $sform->addElement($button_tray);
672
    $sform->display();
673
}
674
675
/**
676
 * @param $text
677
 *
678
 * @return string
679
 */
680
function news_utf8_encode($text)
681
{
682
    return xoops_utf8_encode($text);
683
}
684
685
// Launch stories export (to the xml's format)
686
function launchExport()
0 ignored issues
show
Coding Style introduced by
launchExport uses the super-global variable $_POST which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
687
{
688
    xoops_cp_header();
689
    $adminObject = \Xmf\Module\Admin::getInstance();
690
    $adminObject->displayNavigation('index.php?op=export');
691
    echo '<br>';
692
    $story           = new NewsStory();
693
    $topic           = new NewsTopic();
0 ignored issues
show
Unused Code introduced by
$topic is not used, you could remove the assignment.

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

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

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

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

Loading history...
694
    $exportedstories = [];
0 ignored issues
show
Unused Code introduced by
$exportedstories is not used, you could remove the assignment.

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

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

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

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

Loading history...
695
    $date1           = $_POST['date1'];
696
    $date2           = $_POST['date2'];
697
    $timestamp1      = mktime(0, 0, 0, (int)substr($date1, 5, 2), (int)substr($date1, 8, 2), (int)substr($date1, 0, 4));
698
    $timestamp2      = mktime(23, 59, 59, (int)substr($date2, 5, 2), (int)substr($date2, 8, 2), (int)substr($date2, 0, 4));
699
    $topiclist       = '';
700
    if (isset($_POST['export_topics'])) {
701
        $topiclist = implode(',', $_POST['export_topics']);
702
    }
703
    $topicsexport    = (int)$_POST['includetopics'];
704
    $tbltopics       = [];
705
    $exportedstories = $story->exportNews($timestamp1, $timestamp2, $topiclist, $topicsexport, $tbltopics);
706
    if (count($exportedstories)) {
707
        $xmlfile = XOOPS_ROOT_PATH . '/uploads/news/stories.xml';
708
        $fp      = fopen($xmlfile, 'w');
709
        if (!$fp) {
710
            redirect_header('index.php', 4, sprintf(_AM_NEWS_EXPORT_ERROR, $xmlfile));
711
        }
712
713
        fwrite($fp, news_utf8_encode("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"));
714
        fwrite($fp, news_utf8_encode("<news_stories>\n"));
715
        if ($topicsexport) {
716
            foreach ($tbltopics as $onetopic) {
717
                $topic   = new NewsTopic($onetopic);
718
                $content = "<news_topic>\n";
719
                $content .= sprintf("\t<topic_id>%u</topic_id>\n", $topic->topic_id());
720
                $content .= sprintf("\t<topic_pid>%u</topic_pid>\n", $topic->topic_pid());
721
                $content .= sprintf("\t<topic_imgurl>%s</topic_imgurl>\n", $topic->topic_imgurl());
722
                $content .= sprintf("\t<topic_title>%s</topic_title>\n", $topic->topic_title('F'));
723
                $content .= sprintf("\t<menu>%d</menu>\n", $topic->menu());
724
                $content .= sprintf("\t<topic_frontpage>%d</topic_frontpage>\n", $topic->topic_frontpage());
725
                $content .= sprintf("\t<topic_rssurl>%s</topic_rssurl>\n", $topic->topic_rssurl('E'));
726
                $content .= sprintf("\t<topic_description>%s</topic_description>\n", $topic->topic_description());
727
                $content .= sprintf("</news_topic>\n");
728
                $content = news_utf8_encode($content);
729
                fwrite($fp, $content);
730
            }
731
        }
732
733
        foreach ($exportedstories as $onestory) {
734
            $content = "<xoops_story>\n";
735
            $content .= sprintf("\t<storyid>%u</storyid>\n", $onestory->storyid());
736
            $content .= sprintf("\t<uid>%u</uid>\n", $onestory->uid());
737
            $content .= sprintf("\t<uname>%s</uname>\n", $onestory->uname());
738
            $content .= sprintf("\t<title>%s</title>\n", $onestory->title());
739
            $content .= sprintf("\t<created>%u</created>\n", $onestory->created());
740
            $content .= sprintf("\t<published>%u</published>\n", $onestory->published());
741
            $content .= sprintf("\t<expired>%u</expired>\n", $onestory->expired());
742
            $content .= sprintf("\t<hostname>%s</hostname>\n", $onestory->hostname());
743
            $content .= sprintf("\t<nohtml>%d</nohtml>\n", $onestory->nohtml());
744
            $content .= sprintf("\t<nosmiley>%d</nosmiley>\n", $onestory->nosmiley());
745
            $content .= sprintf("\t<hometext>%s</hometext>\n", $onestory->hometext());
746
            $content .= sprintf("\t<bodytext>%s</bodytext>\n", $onestory->bodytext());
747
            $content .= sprintf("\t<description>%s</description>\n", $onestory->description());
748
            $content .= sprintf("\t<keywords>%s</keywords>\n", $onestory->keywords());
749
            $content .= sprintf("\t<counter>%u</counter>\n", $onestory->counter());
750
            $content .= sprintf("\t<topicid>%u</topicid>\n", $onestory->topicid());
751
            $content .= sprintf("\t<ihome>%d</ihome>\n", $onestory->ihome());
752
            $content .= sprintf("\t<notifypub>%d</notifypub>\n", $onestory->notifypub());
753
            $content .= sprintf("\t<story_type>%s</story_type>\n", $onestory->type());
754
            $content .= sprintf("\t<topicdisplay>%d</topicdisplay>\n", $onestory->topicdisplay());
755
            $content .= sprintf("\t<topicalign>%s</topicalign>\n", $onestory->topicalign());
756
            $content .= sprintf("\t<comments>%u</comments>\n", $onestory->comments());
757
            $content .= sprintf("\t<rating>%f</rating>\n", $onestory->rating());
758
            $content .= sprintf("\t<votes>%u</votes>\n", $onestory->votes());
759
            $content .= sprintf("</xoops_story>\n");
760
            $content = news_utf8_encode($content);
761
            fwrite($fp, $content);
762
        }
763
        fwrite($fp, news_utf8_encode("</news_stories>\n"));
764
        fclose($fp);
765
        $xmlfile = XOOPS_URL . '/uploads/news/stories.xml';
766
        printf(_AM_NEWS_EXPORT_READY, $xmlfile, XOOPS_URL . '/modules/news/admin/index.php?op=deletefile&amp;type=xml');
767
    } else {
768
        printf(_AM_NEWS_EXPORT_NOTHING);
769
    }
770
}
771
772
/*
773
* Topics manager
774
*
775
* It's from here that you can list, add, modify an delete topics
776
* At first, you can see a list of all the topics in your databases. This list contains the topic's ID, its name,
777
* its parent topic, if it should be visible in the Xoops main menu and an action (Edit or Delete topic)
778
* Below this list you find the form used to create and edit the topics.
779
* use this form to :
780
* - Type the topic's title
781
* - Enter its description
782
* - Select its parent topic
783
* - Choose a color
784
* - Select if it must appear in the Xoops main menu
785
* - 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
786
* - And finally you ca select an image to represent the topic
787
* The text box called "URL of RSS feed" is, for this moment, not used.
788
*/
789
function topicsmanager()
0 ignored issues
show
Coding Style introduced by
topicsmanager uses the super-global variable $_GET which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
790
{
791
    global $xoopsDB, $xoopsConfig, $xoopsModule, $myts;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
792
    require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
793
    xoops_cp_header();
794
    $adminObject = \Xmf\Module\Admin::getInstance();
795
    $adminObject->displayNavigation('index.php?op=topicsmanager');
796
797
    global $pathIcon16;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
798
799
    $uploadfolder   = sprintf(_AM_UPLOAD_WARNING, XOOPS_URL . '/uploads/news/image');
0 ignored issues
show
Unused Code introduced by
$uploadfolder is not used, you could remove the assignment.

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

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

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

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

Loading history...
800
    $uploadirectory = '/uploads/news/image';
801
    $start          = isset($_GET['start']) ? (int)$_GET['start'] : 0;
802
803
    $xt          = new NewsTopic($xoopsDB->prefix('news_topics'), 'topic_id', 'topic_pid');
0 ignored issues
show
Unused Code introduced by
The call to NewsTopic::__construct() has too many arguments starting with 'topic_id'.

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.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
804
    $topics_arr  = $xt->getChildTreeArray(0, 'topic_title');
805
    $totaltopics = count($topics_arr);
806
    $class       = '';
807
808
    //echo '<h4>' . _AM_CONFIG . '</h4>';
809
    //news_collapsableBar('topicsmanager', 'toptopicsmanager');
0 ignored issues
show
Unused Code Comprehensibility introduced by
75% of this comment could be valid code. Did you maybe forget this after debugging?

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

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

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

Loading history...
810
811
    //echo "<img onclick=\"toggle('toptable'); toggleIcon('toptableicon');\" id='toptopicsmanager' name='toptopicsmanager' src='" . $pathIcon16."/close12.gif' alt=''></a>&nbsp;"._AM_TOPICSMNGR . ' (' . $totaltopics . ')'."</h4>";
0 ignored issues
show
Unused Code Comprehensibility introduced by
47% of this comment could be valid code. Did you maybe forget this after debugging?

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

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

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

Loading history...
812
813
    echo "<div id='topicsmanager'>";
814
    echo '<br>';
815
    echo "<div class='center;'>";
816
    echo "<table width='100%' cellspacing='1' cellpadding='3' border='0' class='outer'><tr class='bg3'><th align='center'>"
817
         . _AM_TOPIC
818
         . "</th><th align='left'>"
819
         . _AM_TOPICNAME
820
         . "</th><th align='center'>"
821
         . _AM_PARENTTOPIC
822
         . "</th><th align='center'>"
823
         . _AM_SUB_MENU_YESNO
824
         . "</th><th align='center'>"
825
         . _AM_NEWS_ACTION
826
         . '</th></tr>';
827
    if (is_array($topics_arr) && $totaltopics) {
828
        $cpt    = 1;
829
        $tmpcpt = $start;
830
        $ok     = true;
831
        $output = '';
832
        while ($ok) {
833
            if ($tmpcpt < $totaltopics) {
834
                $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>';
835
                $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>";
836
837
                $parent = '&nbsp;';
838
                if ($topics_arr[$tmpcpt]['topic_pid'] > 0) {
839
                    $xttmp  = new MyXoopsTopic($xoopsDB->prefix('news_topics'), $topics_arr[$tmpcpt]['topic_pid']);
840
                    $parent = $xttmp->topic_title();
841
                    unset($xttmp);
842
                }
843
                if (0 != $topics_arr[$tmpcpt]['topic_pid']) {
844
                    $topics_arr[$tmpcpt]['prefix'] = str_replace('.', '-', $topics_arr[$tmpcpt]['prefix']) . '&nbsp;';
845
                } else {
846
                    $topics_arr[$tmpcpt]['prefix'] = str_replace('.', '', $topics_arr[$tmpcpt]['prefix']);
847
                }
848
                $submenu = $topics_arr[$tmpcpt]['menu'] ? _YES : _NO;
849
                $class   = ('even' === $class) ? 'odd' : 'even';
850
851
                $output = $output
852
                          . "<tr class='"
853
                          . $class
854
                          . "'><td>"
855
                          . $topics_arr[$tmpcpt]['topic_id']
856
                          . "</td><td align='left'>"
857
                          . $topics_arr[$tmpcpt]['prefix']
858
                          . $myts->displayTarea($topics_arr[$tmpcpt]['topic_title'])
859
                          . "</td><td align='left'>"
860
                          . $parent
861
                          . "</td><td align='center'>"
862
                          . $submenu
863
                          . "</td><td align='center'>"
864
                          . $action_edit
865
                          . $action_delete
866
                          . '</td></tr>';
867
            } else {
868
                $ok = false;
869
            }
870
            if ($cpt >= NewsUtility::getModuleOption('storycountadmin')) {
871
                $ok = false;
872
            }
873
            ++$tmpcpt;
874
            ++$cpt;
875
        }
876
        echo $output;
877
    }
878
    $pagenav = new XoopsPageNav($totaltopics, NewsUtility::getModuleOption('storycountadmin'), $start, 'start', 'op=topicsmanager');
879
    echo "</table><div align='right'>" . $pagenav->renderNav() . '</div><br>';
880
    echo "</div></div><br>\n";
881
882
    $topic_id = isset($_GET['topic_id']) ? (int)$_GET['topic_id'] : 0;
883
    if ($topic_id > 0) {
884
        $xtmod             = new NewsTopic($topic_id);
885
        $topic_title       = $xtmod->topic_title('E');
886
        $topic_description = $xtmod->topic_description('E');
887
        $topic_rssfeed     = $xtmod->topic_rssurl('E');
0 ignored issues
show
Unused Code introduced by
$topic_rssfeed is not used, you could remove the assignment.

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

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

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

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

Loading history...
888
        $op                = 'modTopicS';
889
        if ('' !== xoops_trim($xtmod->topic_imgurl())) {
890
            $topicimage = $xtmod->topic_imgurl();
891
        } else {
892
            $topicimage = 'blank.png';
893
        }
894
        $btnlabel        = _AM_MODIFY;
895
        $parent          = $xtmod->topic_pid();
896
        $formlabel       = _AM_MODIFYTOPIC;
897
        $submenu         = $xtmod->menu();
898
        $topic_frontpage = $xtmod->topic_frontpage();
899
        $topic_color     = $xtmod->topic_color();
900
        unset($xtmod);
901
    } else {
902
        $topic_title       = '';
903
        $topic_frontpage   = 1;
904
        $topic_description = '';
905
        $op                = 'addTopic';
906
        $topicimage        = 'xoops.gif';
907
        $btnlabel          = _AM_ADD;
908
        $parent            = -1;
909
        $submenu           = 0;
910
        $topic_rssfeed     = '';
0 ignored issues
show
Unused Code introduced by
$topic_rssfeed is not used, you could remove the assignment.

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

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

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

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

Loading history...
911
        $formlabel         = _AM_ADD_TOPIC;
912
        $topic_color       = '000000';
913
    }
914
915
    $sform = new XoopsThemeForm($formlabel, 'topicform', XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/admin/index.php', 'post', true);
916
    $sform->setExtra('enctype="multipart/form-data"');
917
    $sform->addElement(new XoopsFormText(_AM_TOPICNAME, 'topic_title', 50, 255, $topic_title), true);
918
    $editor = NewsUtility::getWysiwygForm(_AM_TOPIC_DESCR, 'topic_description', $topic_description, 15, 60, 'hometext_hidden');
919
    if ($editor) {
920
        $sform->addElement($editor, false);
921
    }
922
923
    $sform->addElement(new XoopsFormHidden('op', $op), false);
924
    $sform->addElement(new XoopsFormHidden('topic_id', $topic_id), false);
925
926
    require_once XOOPS_ROOT_PATH . '/modules/news/class/class.newstopic.php';
927
    $xt = new NewsTopic();
928
    $sform->addElement(new XoopsFormLabel(_AM_PARENTTOPIC, $xt->makeMyTopicSelBox(1, $parent, 'topic_pid', '', false)));
929
    // Topic's color
930
    // Code stolen to Zoullou, thank you Zoullou ;-)
931
    $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";
932
    $color_values = [
933
        '000000',
934
        '000033',
935
        '000066',
936
        '000099',
937
        '0000CC',
938
        '0000FF',
939
        '003300',
940
        '003333',
941
        '003366',
942
        '0033CC',
943
        '0033FF',
944
        '006600',
945
        '006633',
946
        '006666',
947
        '006699',
948
        '0066CC',
949
        '0066FF',
950
        '009900',
951
        '009933',
952
        '009966',
953
        '009999',
954
        '0099CC',
955
        '0099FF',
956
        '00CC00',
957
        '00CC33',
958
        '00CC66',
959
        '00CC99',
960
        '00CCCC',
961
        '00CCFF',
962
        '00FF00',
963
        '00FF33',
964
        '00FF66',
965
        '00FF99',
966
        '00FFCC',
967
        '00FFFF',
968
        '330000',
969
        '330033',
970
        '330066',
971
        '330099',
972
        '3300CC',
973
        '3300FF',
974
        '333300',
975
        '333333',
976
        '333366',
977
        '333399',
978
        '3333CC',
979
        '3333FF',
980
        '336600',
981
        '336633',
982
        '336666',
983
        '336699',
984
        '3366CC',
985
        '3366FF',
986
        '339900',
987
        '339933',
988
        '339966',
989
        '339999',
990
        '3399CC',
991
        '3399FF',
992
        '33CC00',
993
        '33CC33',
994
        '33CC66',
995
        '33CC99',
996
        '33CCCC',
997
        '33CCFF',
998
        '33FF00',
999
        '33FF33',
1000
        '33FF66',
1001
        '33FF99',
1002
        '33FFCC',
1003
        '33FFFF',
1004
        '660000',
1005
        '660033',
1006
        '660066',
1007
        '660099',
1008
        '6600CC',
1009
        '6600FF',
1010
        '663300',
1011
        '663333',
1012
        '663366',
1013
        '663399',
1014
        '6633CC',
1015
        '6633FF',
1016
        '666600',
1017
        '666633',
1018
        '666666',
1019
        '666699',
1020
        '6666CC',
1021
        '6666FF',
1022
        '669900',
1023
        '669933',
1024
        '669966',
1025
        '669999',
1026
        '6699CC',
1027
        '6699FF',
1028
        '66CC00',
1029
        '66CC33',
1030
        '66CC66',
1031
        '66CC99',
1032
        '66CCCC',
1033
        '66CCFF',
1034
        '66FF00',
1035
        '66FF33',
1036
        '66FF66',
1037
        '66FF99',
1038
        '66FFCC',
1039
        '66FFFF',
1040
        '990000',
1041
        '990033',
1042
        '990066',
1043
        '990099',
1044
        '9900CC',
1045
        '9900FF',
1046
        '993300',
1047
        '993333',
1048
        '993366',
1049
        '993399',
1050
        '9933CC',
1051
        '9933FF',
1052
        '996600',
1053
        '996633',
1054
        '996666',
1055
        '996699',
1056
        '9966CC',
1057
        '9966FF',
1058
        '999900',
1059
        '999933',
1060
        '999966',
1061
        '999999',
1062
        '9999CC',
1063
        '9999FF',
1064
        '99CC00',
1065
        '99CC33',
1066
        '99CC66',
1067
        '99CC99',
1068
        '99CCCC',
1069
        '99CCFF',
1070
        '99FF00',
1071
        '99FF33',
1072
        '99FF66',
1073
        '99FF99',
1074
        '99FFCC',
1075
        '99FFFF',
1076
        'CC0000',
1077
        'CC0033',
1078
        'CC0066',
1079
        'CC0099',
1080
        'CC00CC',
1081
        'CC00FF',
1082
        'CC3300',
1083
        'CC3333',
1084
        'CC3366',
1085
        'CC3399',
1086
        'CC33CC',
1087
        'CC33FF',
1088
        'CC6600',
1089
        'CC6633',
1090
        'CC6666',
1091
        'CC6699',
1092
        'CC66CC',
1093
        'CC66FF',
1094
        'CC9900',
1095
        'CC9933',
1096
        'CC9966',
1097
        'CC9999',
1098
        'CC99CC',
1099
        'CC99FF',
1100
        'CCCC00',
1101
        'CCCC33',
1102
        'CCCC66',
1103
        'CCCC99',
1104
        'CCCCCC',
1105
        'CCCCFF',
1106
        'CCFF00',
1107
        'CCFF33',
1108
        'CCFF66',
1109
        'CCFF99',
1110
        'CCFFCC',
1111
        'CCFFFF',
1112
        'FF0000',
1113
        'FF0033',
1114
        'FF0066',
1115
        'FF0099',
1116
        'FF00CC',
1117
        'FF00FF',
1118
        'FF3300',
1119
        'FF3333',
1120
        'FF3366',
1121
        'FF3399',
1122
        'FF33CC',
1123
        'FF33FF',
1124
        'FF6600',
1125
        'FF6633',
1126
        'FF6666',
1127
        'FF6699',
1128
        'FF66CC',
1129
        'FF66FF',
1130
        'FF9900',
1131
        'FF9933',
1132
        'FF9966',
1133
        'FF9999',
1134
        'FF99CC',
1135
        'FF99FF',
1136
        'FFCC00',
1137
        'FFCC33',
1138
        'FFCC66',
1139
        'FFCC99',
1140
        'FFCCCC',
1141
        'FFCCFF',
1142
        'FFFF00',
1143
        'FFFF33',
1144
        'FFFF66',
1145
        'FFFF99',
1146
        'FFFFCC',
1147
        'FFFFFF'
1148
    ];
1149
1150
    foreach ($color_values as $color_value) {
1151
        if ($topic_color == $color_value) {
1152
            $selected = ' selected';
1153
        } else {
1154
            $selected = '';
1155
        }
1156
        $select_color .= '<option' . $selected . " value='" . $color_value . "' style='background-color:#" . $color_value . ';color:#' . $color_value . ";'>#" . $color_value . "</option>\n";
1157
    }
1158
1159
    $select_color .= "</select>&nbsp;\n<span id='NewsColorSelect'>&nbsp;&nbsp;&nbsp;&nbsp;</span>";
1160
    $sform->addElement(new XoopsFormLabel(_AM_NEWS_TOPIC_COLOR, $select_color));
1161
    // Sub menu ?
1162
    $sform->addElement(new XoopsFormRadioYN(_AM_SUB_MENU, 'submenu', $submenu, _YES, _NO));
1163
    $sform->addElement(new XoopsFormRadioYN(_AM_PUBLISH_FRONTPAGE, 'topic_frontpage', $topic_frontpage, _YES, _NO));
1164
    // Unused for this moment... sorry
1165
    //$sform->addElement(new XoopsFormText(_AM_NEWS_RSS_URL, 'topic_rssfeed', 50, 255, $topic_rssfeed), false);
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

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

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

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

Loading history...
1166
    // ********** Picture
1167
    $imgtray = new XoopsFormElementTray(_AM_TOPICIMG, '<br>');
1168
1169
    $imgpath      = sprintf(_AM_IMGNAEXLOC, 'uploads/news/image/');
1170
    $imageselect  = new XoopsFormSelect($imgpath, 'topic_imgurl', $topicimage);
1171
    $topics_array = XoopsLists:: getImgListAsArray(XOOPS_ROOT_PATH . '/uploads/news/image/');
1172
    foreach ($topics_array as $image) {
1173
        $imageselect->addOption("$image", $image);
1174
    }
1175
    $imageselect->setExtra("onchange='showImgSelected(\"image3\", \"topic_imgurl\", \"" . $uploadirectory . '", "", "' . XOOPS_URL . "\")'");
1176
    $imgtray->addElement($imageselect, false);
1177
    $imgtray->addElement(new XoopsFormLabel('', "<br><img src='" . XOOPS_URL . '/' . $uploadirectory . '/' . $topicimage . "' name='image3' id='image3' alt=''>"));
1178
1179
    $uploadfolder = sprintf(_AM_UPLOAD_WARNING, XOOPS_URL . '/uploads/news/image');
1180
    $fileseltray  = new XoopsFormElementTray('', '<br>');
1181
    $fileseltray->addElement(new XoopsFormFile(_AM_TOPIC_PICTURE, 'attachedfile', NewsUtility::getModuleOption('maxuploadsize')), false);
1182
    $fileseltray->addElement(new XoopsFormLabel($uploadfolder), false);
1183
    $imgtray->addElement($fileseltray);
1184
    $sform->addElement($imgtray);
1185
1186
    // Permissions
1187
    $memberHandler = xoops_getHandler('member');
1188
    $group_list    = $memberHandler->getGroupList();
1189
    $gpermHandler  = xoops_getHandler('groupperm');
1190
    $full_list     = array_keys($group_list);
1191
1192
    $groups_ids = [];
0 ignored issues
show
Unused Code introduced by
$groups_ids is not used, you could remove the assignment.

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

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

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

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

Loading history...
1193 View Code Duplication
    if ($topic_id > 0) { // Edit mode
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1194
        $groups_ids                       = $gpermHandler->getGroupIds('news_approve', $topic_id, $xoopsModule->getVar('mid'));
1195
        $groups_ids                       = array_values($groups_ids);
1196
        $groups_news_can_approve_checkbox = new XoopsFormCheckBox(_AM_APPROVEFORM, 'groups_news_can_approve[]', $groups_ids);
1197
    } else { // Creation mode
1198
        $groups_news_can_approve_checkbox = new XoopsFormCheckBox(_AM_APPROVEFORM, 'groups_news_can_approve[]', $full_list);
1199
    }
1200
    $groups_news_can_approve_checkbox->addOptionArray($group_list);
1201
    $sform->addElement($groups_news_can_approve_checkbox);
1202
1203
    $groups_ids = [];
0 ignored issues
show
Unused Code introduced by
$groups_ids is not used, you could remove the assignment.

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

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

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

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

Loading history...
1204 View Code Duplication
    if ($topic_id > 0) { // Edit mode
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1205
        $groups_ids                      = $gpermHandler->getGroupIds('news_submit', $topic_id, $xoopsModule->getVar('mid'));
1206
        $groups_ids                      = array_values($groups_ids);
1207
        $groups_news_can_submit_checkbox = new XoopsFormCheckBox(_AM_SUBMITFORM, 'groups_news_can_submit[]', $groups_ids);
1208
    } else { // Creation mode
1209
        $groups_news_can_submit_checkbox = new XoopsFormCheckBox(_AM_SUBMITFORM, 'groups_news_can_submit[]', $full_list);
1210
    }
1211
    $groups_news_can_submit_checkbox->addOptionArray($group_list);
1212
    $sform->addElement($groups_news_can_submit_checkbox);
1213
1214
    $groups_ids = [];
0 ignored issues
show
Unused Code introduced by
$groups_ids is not used, you could remove the assignment.

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

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

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

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

Loading history...
1215 View Code Duplication
    if ($topic_id > 0) { // Edit mode
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1216
        $groups_ids                    = $gpermHandler->getGroupIds('news_view', $topic_id, $xoopsModule->getVar('mid'));
1217
        $groups_ids                    = array_values($groups_ids);
1218
        $groups_news_can_view_checkbox = new XoopsFormCheckBox(_AM_VIEWFORM, 'groups_news_can_view[]', $groups_ids);
1219
    } else { // Creation mode
1220
        $groups_news_can_view_checkbox = new XoopsFormCheckBox(_AM_VIEWFORM, 'groups_news_can_view[]', $full_list);
1221
    }
1222
    $groups_news_can_view_checkbox->addOptionArray($group_list);
1223
    $sform->addElement($groups_news_can_view_checkbox);
1224
1225
    // Submit buttons
1226
    $button_tray = new XoopsFormElementTray('', '');
1227
    $submit_btn  = new XoopsFormButton('', 'post', $btnlabel, 'submit');
1228
    $button_tray->addElement($submit_btn);
1229
    $sform->addElement($button_tray);
1230
    $sform->display();
1231
    echo "<script type='text/javascript'>\n";
1232
    echo 'xoopsGetElementById("NewsColorSelect").style.backgroundColor = "#' . $topic_color . '";';
1233
    echo "</script>\n";
1234
}
1235
1236
// Save a topic after it has been modified
1237
function modTopicS()
0 ignored issues
show
Coding Style introduced by
modTopicS uses the super-global variable $_POST which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
Coding Style introduced by
modTopicS uses the super-global variable $_SESSION which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
Coding Style introduced by
modTopicS uses the super-global variable $_FILES which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
1238
{
1239
    global $xoopsDB, $xoopsModule, $xoopsModuleConfig;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
1240
1241
    $xt = new NewsTopic((int)$_POST['topic_id']);
1242
    if ((int)$_POST['topic_pid'] == (int)$_POST['topic_id']) {
1243
        redirect_header('index.php?op=topicsmanager', 2, _AM_ADD_TOPIC_ERROR1);
1244
    }
1245
    $xt->setTopicPid((int)$_POST['topic_pid']);
1246
    if (empty($_POST['topic_title'])) {
1247
        redirect_header('index.php?op=topicsmanager', 2, _AM_ERRORTOPICNAME);
1248
    }
1249
    if (isset($_SESSION['items_count'])) {
1250
        $_SESSION['items_count'] = -1;
1251
    }
1252
    $xt->setTopicTitle($_POST['topic_title']);
1253 View Code Duplication
    if (isset($_POST['topic_imgurl']) && '' !== $_POST['topic_imgurl']) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1254
        $xt->setTopicImgurl($_POST['topic_imgurl']);
1255
    }
1256
    $xt->setMenu((int)$_POST['submenu']);
1257
    $xt->setTopicFrontpage((int)$_POST['topic_frontpage']);
1258
    if (isset($_POST['topic_description'])) {
1259
        $xt->setTopicDescription($_POST['topic_description']);
1260
    } else {
1261
        $xt->setTopicDescription('');
1262
    }
1263
    //$xt->setTopicRssUrl($_POST['topic_rssfeed']);
0 ignored issues
show
Unused Code Comprehensibility introduced by
90% of this comment could be valid code. Did you maybe forget this after debugging?

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

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

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

Loading history...
1264
    $xt->setTopic_color($_POST['topic_color']);
1265
1266 View Code Duplication
    if (isset($_POST['xoops_upload_file'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1267
        $fldname = $_FILES[$_POST['xoops_upload_file'][0]];
1268
        $fldname = $fldname['name'];
1269
        if (xoops_trim('' !== $fldname)) {
1270
            $sfiles         = new sFiles();
1271
            $dstpath        = XOOPS_ROOT_PATH . '/uploads/news/image';
1272
            $destname       = $sfiles->createUploadName($dstpath, $fldname, true);
1273
            $permittedtypes = ['image/gif', 'image/jpeg', 'image/pjpeg', 'image/x-png', 'image/png'];
1274
            $uploader       = new XoopsMediaUploader($dstpath, $permittedtypes, $xoopsModuleConfig['maxuploadsize']);
1275
            $uploader->setTargetFileName($destname);
1276
            if ($uploader->fetchMedia($_POST['xoops_upload_file'][0])) {
1277
                if ($uploader->upload()) {
1278
                    $xt->setTopicImgurl(basename($destname));
1279
                } else {
1280
                    echo _AM_UPLOAD_ERROR . ' ' . $uploader->getErrors();
1281
                }
1282
            } else {
1283
                echo $uploader->getErrors();
1284
            }
1285
        }
1286
    }
1287
    $xt->store();
1288
1289
    // Permissions
1290
    $gpermHandler = xoops_getHandler('groupperm');
1291
    $criteria     = new CriteriaCompo();
1292
    $criteria->add(new Criteria('gperm_itemid', $xt->topic_id(), '='));
1293
    $criteria->add(new Criteria('gperm_modid', $xoopsModule->getVar('mid'), '='));
1294
    $criteria->add(new Criteria('gperm_name', 'news_approve', '='));
1295
    $gpermHandler->deleteAll($criteria);
1296
1297
    $criteria = new CriteriaCompo();
1298
    $criteria->add(new Criteria('gperm_itemid', $xt->topic_id(), '='));
1299
    $criteria->add(new Criteria('gperm_modid', $xoopsModule->getVar('mid'), '='));
1300
    $criteria->add(new Criteria('gperm_name', 'news_submit', '='));
1301
    $gpermHandler->deleteAll($criteria);
1302
1303
    $criteria = new CriteriaCompo();
1304
    $criteria->add(new Criteria('gperm_itemid', $xt->topic_id(), '='));
1305
    $criteria->add(new Criteria('gperm_modid', $xoopsModule->getVar('mid'), '='));
1306
    $criteria->add(new Criteria('gperm_name', 'news_view', '='));
1307
    $gpermHandler->deleteAll($criteria);
1308
1309 View Code Duplication
    if (isset($_POST['groups_news_can_approve'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1310
        foreach ($_POST['groups_news_can_approve'] as $onegroup_id) {
1311
            $gpermHandler->addRight('news_approve', $xt->topic_id(), $onegroup_id, $xoopsModule->getVar('mid'));
1312
        }
1313
    }
1314
1315 View Code Duplication
    if (isset($_POST['groups_news_can_submit'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1316
        foreach ($_POST['groups_news_can_submit'] as $onegroup_id) {
1317
            $gpermHandler->addRight('news_submit', $xt->topic_id(), $onegroup_id, $xoopsModule->getVar('mid'));
1318
        }
1319
    }
1320
1321 View Code Duplication
    if (isset($_POST['groups_news_can_view'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1322
        foreach ($_POST['groups_news_can_view'] as $onegroup_id) {
1323
            $gpermHandler->addRight('news_view', $xt->topic_id(), $onegroup_id, $xoopsModule->getVar('mid'));
1324
        }
1325
    }
1326
1327
    NewsUtility::updateCache();
1328
    redirect_header('index.php?op=topicsmanager', 1, _AM_DBUPDATED);
1329
}
1330
1331
// Delete a topic and its subtopics and its stories and the related stories
1332
function delTopic()
0 ignored issues
show
Coding Style introduced by
delTopic uses the super-global variable $_POST which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
Coding Style introduced by
delTopic uses the super-global variable $_GET which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
Coding Style introduced by
delTopic uses the super-global variable $_SESSION which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
1333
{
1334
    global $xoopsDB, $xoopsModule;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
1335
    if (!isset($_POST['ok'])) {
1336
        xoops_cp_header();
1337
        echo '<h4>' . _AM_CONFIG . '</h4>';
1338
        $xt = new MyXoopsTopic($xoopsDB->prefix('news_topics'), (int)$_GET['topic_id']);
1339
        xoops_confirm(['op' => 'delTopic', 'topic_id' => (int)$_GET['topic_id'], 'ok' => 1], 'index.php', _AM_WAYSYWTDTTAL . '<br>' . $xt->topic_title('S'));
1340
    } else {
1341
        xoops_cp_header();
1342
        $xt = new MyXoopsTopic($xoopsDB->prefix('news_topics'), (int)$_POST['topic_id']);
1343
        if (isset($_SESSION['items_count'])) {
1344
            $_SESSION['items_count'] = -1;
1345
        }
1346
        // get all subtopics under the specified topic
1347
        $topic_arr = $xt->getAllChildTopics();
1348
        array_push($topic_arr, $xt);
1349
        foreach ($topic_arr as $eachtopic) {
1350
            // get all stories in each topic
1351
            $story_arr = NewsStory:: getByTopic($eachtopic->topic_id());
1352
            foreach ($story_arr as $eachstory) {
1353
                if (false !== $eachstory->delete()) {
1354
                    xoops_comment_delete($xoopsModule->getVar('mid'), $eachstory->storyid());
1355
                    xoops_notification_deletebyitem($xoopsModule->getVar('mid'), 'story', $eachstory->storyid());
1356
                }
1357
            }
1358
            // all stories for each topic is deleted, now delete the topic data
1359
            $eachtopic->delete();
1360
            // Delete also the notifications and permissions
1361
            xoops_notification_deletebyitem($xoopsModule->getVar('mid'), 'category', $eachtopic->topic_id);
1362
            xoops_groupperm_deletebymoditem($xoopsModule->getVar('mid'), 'news_approve', $eachtopic->topic_id);
1363
            xoops_groupperm_deletebymoditem($xoopsModule->getVar('mid'), 'news_submit', $eachtopic->topic_id);
1364
            xoops_groupperm_deletebymoditem($xoopsModule->getVar('mid'), 'news_view', $eachtopic->topic_id);
1365
        }
1366
        NewsUtility::updateCache();
1367
        redirect_header('index.php?op=topicsmanager', 1, _AM_DBUPDATED);
1368
    }
1369
}
1370
1371
// Add a new topic
1372
function addTopic()
0 ignored issues
show
Coding Style introduced by
addTopic uses the super-global variable $_POST which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
Coding Style introduced by
addTopic uses the super-global variable $_SESSION which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
Coding Style introduced by
addTopic uses the super-global variable $_FILES which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
1373
{
1374
    global $xoopsDB, $xoopsModule, $xoopsModuleConfig;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
1375
    $topicpid = isset($_POST['topic_pid']) ? (int)$_POST['topic_pid'] : 0;
1376
    $xt       = new NewsTopic();
1377
    if (!$xt->topicExists($topicpid, $_POST['topic_title'])) {
1378
        $xt->setTopicPid($topicpid);
1379
        if (empty($_POST['topic_title']) || '' == xoops_trim($_POST['topic_title'])) {
1380
            redirect_header('index.php?op=topicsmanager', 2, _AM_ERRORTOPICNAME);
1381
        }
1382
        $xt->setTopicTitle($_POST['topic_title']);
1383
        //$xt->setTopicRssUrl($_POST['topic_rssfeed']);
0 ignored issues
show
Unused Code Comprehensibility introduced by
90% of this comment could be valid code. Did you maybe forget this after debugging?

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

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

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

Loading history...
1384
        $xt->setTopic_color($_POST['topic_color']);
1385 View Code Duplication
        if (isset($_POST['topic_imgurl']) && '' !== $_POST['topic_imgurl']) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1386
            $xt->setTopicImgurl($_POST['topic_imgurl']);
1387
        }
1388
        $xt->setMenu((int)$_POST['submenu']);
1389
        $xt->setTopicFrontpage((int)$_POST['topic_frontpage']);
1390
        if (isset($_SESSION['items_count'])) {
1391
            $_SESSION['items_count'] = -1;
1392
        }
1393 View Code Duplication
        if (isset($_POST['xoops_upload_file'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1394
            $fldname = $_FILES[$_POST['xoops_upload_file'][0]];
1395
            $fldname = $fldname['name'];
1396
            if (xoops_trim('' !== $fldname)) {
1397
                $sfiles         = new sFiles();
1398
                $dstpath        = XOOPS_ROOT_PATH . '/uploads/news/image';
1399
                $destname       = $sfiles->createUploadName($dstpath, $fldname, true);
1400
                $permittedtypes = ['image/gif', 'image/jpeg', 'image/pjpeg', 'image/x-png', 'image/png'];
1401
                $uploader       = new XoopsMediaUploader($dstpath, $permittedtypes, $xoopsModuleConfig['maxuploadsize']);
1402
                $uploader->setTargetFileName($destname);
1403
                if ($uploader->fetchMedia($_POST['xoops_upload_file'][0])) {
1404
                    if ($uploader->upload()) {
1405
                        $xt->setTopicImgurl(basename($destname));
1406
                    } else {
1407
                        echo _AM_UPLOAD_ERROR . ' ' . $uploader->getErrors();
1408
                    }
1409
                } else {
1410
                    echo $uploader->getErrors();
1411
                }
1412
            }
1413
        }
1414
        if (isset($_POST['topic_description'])) {
1415
            $xt->setTopicDescription($_POST['topic_description']);
1416
        } else {
1417
            $xt->setTopicDescription('');
1418
        }
1419
        $xt->store();
1420
        // Permissions
1421
        $gpermHandler = xoops_getHandler('groupperm');
1422 View Code Duplication
        if (isset($_POST['groups_news_can_approve'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1423
            foreach ($_POST['groups_news_can_approve'] as $onegroup_id) {
1424
                $gpermHandler->addRight('news_approve', $xt->topic_id(), $onegroup_id, $xoopsModule->getVar('mid'));
1425
            }
1426
        }
1427
1428 View Code Duplication
        if (isset($_POST['groups_news_can_submit'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1429
            foreach ($_POST['groups_news_can_submit'] as $onegroup_id) {
1430
                $gpermHandler->addRight('news_submit', $xt->topic_id(), $onegroup_id, $xoopsModule->getVar('mid'));
1431
            }
1432
        }
1433
1434 View Code Duplication
        if (isset($_POST['groups_news_can_view'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1435
            foreach ($_POST['groups_news_can_view'] as $onegroup_id) {
1436
                $gpermHandler->addRight('news_view', $xt->topic_id(), $onegroup_id, $xoopsModule->getVar('mid'));
1437
            }
1438
        }
1439
        NewsUtility::updateCache();
1440
1441
        $notificationHandler = xoops_getHandler('notification');
1442
        $tags                = [];
1443
        $tags['TOPIC_NAME']  = $_POST['topic_title'];
1444
        $notificationHandler->triggerEvent('global', 0, 'new_category', $tags);
1445
        redirect_header('index.php?op=topicsmanager', 1, _AM_DBUPDATED);
1446
    } else {
1447
        redirect_header('index.php?op=topicsmanager', 2, _AM_ADD_TOPIC_ERROR);
1448
    }
1449
}
1450
1451
/**
1452
 * Statistics about stories, topics and authors
1453
 *
1454
 * You can reach the statistics from the admin part of the news module by clicking on the "Statistics" tabs
1455
 * The number of visible elements in each table is equal to the module's option called "storycountadmin"
1456
 * There are 3 kind of different statistics :
1457
 * - Topics statistics
1458
 *   For each topic you can see its number of articles, the number of time each topics was viewed, the number
1459
 *   of attached files, the number of expired articles and the number of unique authors.
1460
 * - Articles statistics
1461
 *   This part is decomposed in 3 tables :
1462
 *   a) Most readed articles
1463
 *      This table resumes, for all the news in your database, the most readed articles.
1464
 *      The table contains, for each news, its topic, its title, the author and the number of views.
1465
 *   b) Less readed articles
1466
 *      That's the opposite action of the previous table and its content is the same
1467
 *   c) Best rated articles
1468
 *      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
1469
 * - Authors statistics
1470
 *   This part is also decomposed in 3 tables
1471
 *   a) Most readed authors
1472
 *        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
1473
 *   b) Best rated authors
1474
 *      To created this table's content, the program compute the rating's average of each author and create a table
1475
 *   c) Biggest contributors
1476
 *      The goal of this table is to know who is creating the biggest number of articles.
1477
 */
1478
function getStats()
1479
{
1480
    global $xoopsModule, $xoopsConfig;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
1481
    xoops_cp_header();
1482
    $myts = MyTextSanitizer::getInstance();
1483 View Code Duplication
    if (file_exists(XOOPS_ROOT_PATH . '/modules/news/language/' . $xoopsConfig['language'] . '/main.php')) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1484
        require_once XOOPS_ROOT_PATH . '/modules/news/language/' . $xoopsConfig['language'] . '/main.php';
1485
    } else {
1486
        require_once XOOPS_ROOT_PATH . '/modules/news/language/english/main.php';
1487
    }
1488
    $adminObject = \Xmf\Module\Admin::getInstance();
1489
    $adminObject->displayNavigation('index.php?op=stats');
1490
    $news   = new NewsStory();
1491
    $stats  = [];
0 ignored issues
show
Unused Code introduced by
$stats is not used, you could remove the assignment.

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

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

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

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

Loading history...
1492
    $stats  = $news->getStats(NewsUtility::getModuleOption('storycountadmin'));
1493
    $totals = [0, 0, 0, 0, 0];
1494
    //printf("<h1>%s</h1>\n",_AM_NEWS_STATS);
0 ignored issues
show
Unused Code Comprehensibility introduced by
72% of this comment could be valid code. Did you maybe forget this after debugging?

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

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

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

Loading history...
1495
1496
    // First part of the stats, everything about topics
1497
    $storiespertopic = $stats['storiespertopic'];
1498
    $readspertopic   = $stats['readspertopic'];
1499
    $filespertopic   = $stats['filespertopic'];
1500
    $expiredpertopic = $stats['expiredpertopic'];
1501
    $authorspertopic = $stats['authorspertopic'];
1502
    $class           = '';
1503
1504
    echo "<div class='center;'><b>" . _AM_NEWS_STATS0 . "</b><br>\n";
1505
    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>';
1506
    foreach ($storiespertopic as $topicid => $data) {
1507
        $url   = XOOPS_URL . '/modules/' . $xoopsModule->dirname() . '/index.php?storytopic=' . $topicid;
1508
        $views = 0;
1509
        if (array_key_exists($topicid, $readspertopic)) {
1510
            $views = $readspertopic[$topicid];
1511
        }
1512
        $attachedfiles = 0;
1513
        if (array_key_exists($topicid, $filespertopic)) {
1514
            $attachedfiles = $filespertopic[$topicid];
1515
        }
1516
        $expired = 0;
1517
        if (array_key_exists($topicid, $expiredpertopic)) {
1518
            $expired = $expiredpertopic[$topicid];
1519
        }
1520
        $authors = 0;
1521
        if (array_key_exists($topicid, $authorspertopic)) {
1522
            $authors = $authorspertopic[$topicid];
1523
        }
1524
        $articles = $data['cpt'];
1525
1526
        $totals[0] += $articles;
1527
        $totals[1] += $views;
1528
        $totals[2] += $attachedfiles;
1529
        $totals[3] += $expired;
1530
        $class     = ('even' === $class) ? 'odd' : 'even';
1531
        printf(
1532
            "<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",
1533
            $url,
1534
            $myts->displayTarea($data['topic_title']),
1535
            $articles,
1536
               $views,
1537
            $attachedfiles,
1538
            $expired,
1539
            $authors
1540
        );
1541
    }
1542
    $class = ('even' === $class) ? 'odd' : 'even';
1543
    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]);
1544
    echo '</table></div><br><br><br>';
1545
1546
    // Second part of the stats, everything about stories
1547
    // a) Most readed articles
1548
    $mostreadednews = $stats['mostreadednews'];
1549
    echo "<div class='center;'><b>" . _AM_NEWS_STATS3 . '</b><br><br>' . _AM_NEWS_STATS4 . "<br>\n";
1550
    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";
1551 View Code Duplication
    foreach ($mostreadednews as $storyid => $data) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1552
        $url1  = XOOPS_URL . '/modules/' . $xoopsModule->dirname() . '/index.php?storytopic=' . $data['topicid'];
1553
        $url2  = XOOPS_URL . '/modules/' . $xoopsModule->dirname() . '/article.php?storyid=' . $storyid;
1554
        $url3  = XOOPS_URL . '/userinfo.php?uid=' . $data['uid'];
1555
        $class = ('even' === $class) ? 'odd' : 'even';
1556
        printf(
1557
            "<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",
1558
            $url1,
1559
            $myts->displayTarea($data['topic_title']),
1560
            $url2,
1561
               $myts->displayTarea($data['title']),
1562
            $url3,
1563
            $myts->htmlSpecialChars($news->uname($data['uid'])),
1564
            $data['counter']
1565
        );
1566
    }
1567
    echo '</table>';
1568
1569
    // b) Less readed articles
1570
    $lessreadednews = $stats['lessreadednews'];
1571
    echo '<br><br>' . _AM_NEWS_STATS5;
1572
    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";
1573 View Code Duplication
    foreach ($lessreadednews as $storyid => $data) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1574
        $url1  = XOOPS_URL . '/modules/' . $xoopsModule->dirname() . '/index.php?storytopic=' . $data['topicid'];
1575
        $url2  = XOOPS_URL . '/modules/' . $xoopsModule->dirname() . '/article.php?storyid=' . $storyid;
1576
        $url3  = XOOPS_URL . '/userinfo.php?uid=' . $data['uid'];
1577
        $class = ('even' === $class) ? 'odd' : 'even';
1578
        printf(
1579
            "<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",
1580
            $url1,
1581
            $myts->displayTarea($data['topic_title']),
1582
            $url2,
1583
               $myts->displayTarea($data['title']),
1584
            $url3,
1585
            $myts->htmlSpecialChars($news->uname($data['uid'])),
1586
            $data['counter']
1587
        );
1588
    }
1589
    echo '</table>';
1590
1591
    // c) Best rated articles (this is an average)
1592
    $besratednews = $stats['besratednews'];
1593
    echo '<br><br>' . _AM_NEWS_STATS6;
1594
    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";
1595 View Code Duplication
    foreach ($besratednews as $storyid => $data) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1596
        $url1  = XOOPS_URL . '/modules/' . $xoopsModule->dirname() . '/index.php?storytopic=' . $data['topicid'];
1597
        $url2  = XOOPS_URL . '/modules/' . $xoopsModule->dirname() . '/article.php?storyid=' . $storyid;
1598
        $url3  = XOOPS_URL . '/userinfo.php?uid=' . $data['uid'];
1599
        $class = ('even' === $class) ? 'odd' : 'even';
1600
        printf(
1601
            "<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",
1602
            $url1,
1603
            $myts->displayTarea($data['topic_title']),
1604
            $url2,
1605
               $myts->displayTarea($data['title']),
1606
            $url3,
1607
            $myts->htmlSpecialChars($news->uname($data['uid'])),
1608
            number_format($data['rating'], 2)
1609
        );
1610
    }
1611
    echo '</table></div><br><br><br>';
1612
1613
    // Last part of the stats, everything about authors
1614
    // a) Most readed authors
1615
    $mostreadedauthors = $stats['mostreadedauthors'];
1616
    echo "<div class='center;'><b>" . _AM_NEWS_STATS10 . '</b><br><br>' . _AM_NEWS_STATS7 . "<br>\n";
1617
    echo "<table border='0' width='100%'><tr class='bg3'><th>" . _AM_POSTER . '</th><th>' . _NW_VIEWS . "</th></tr>\n";
1618 View Code Duplication
    foreach ($mostreadedauthors as $uid => $reads) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1619
        $url   = XOOPS_URL . '/userinfo.php?uid=' . $uid;
1620
        $class = ('even' === $class) ? 'odd' : 'even';
1621
        printf("<tr class='" . $class . "'><td align='left'><a href='%s' target ='_blank'>%s</a></td><td align='right'>%u</td></tr>\n", $url, $myts->htmlSpecialChars($news->uname($uid)), $reads);
1622
    }
1623
    echo '</table>';
1624
1625
    // b) Best rated authors
1626
    $bestratedauthors = $stats['bestratedauthors'];
1627
    echo '<br><br>' . _AM_NEWS_STATS8;
1628
    echo "<table border='0' width='100%'><tr class='bg3'><th>" . _AM_POSTER . '</th><th>' . _NW_RATING . "</th></tr>\n";
1629 View Code Duplication
    foreach ($bestratedauthors as $uid => $rating) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1630
        $url   = XOOPS_URL . '/userinfo.php?uid=' . $uid;
1631
        $class = ('even' === $class) ? 'odd' : 'even';
1632
        printf("<tr class='" . $class . "'><td align='left'><a href='%s' target ='_blank'>%s</a></td><td align='right'>%u</td></tr>\n", $url, $myts->htmlSpecialChars($news->uname($uid)), $rating);
1633
    }
1634
    echo '</table>';
1635
1636
    // c) Biggest contributors
1637
    $biggestcontributors = $stats['biggestcontributors'];
1638
    echo '<br><br>' . _AM_NEWS_STATS9;
1639
    echo "<table border='0' width='100%'><tr class='bg3'><th>" . _AM_POSTER . '</th><th>' . _AM_NEWS_STATS11 . "</th></tr>\n";
1640 View Code Duplication
    foreach ($biggestcontributors as $uid => $count) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1641
        $url   = XOOPS_URL . '/userinfo.php?uid=' . $uid;
1642
        $class = ('even' === $class) ? 'odd' : 'even';
1643
        printf("<tr class='" . $class . "'><td align='left'><a href='%s' target ='_blank'>%s</a></td><td align='right'>%u</td></tr>\n", $url, $myts->htmlSpecialChars($news->uname($uid)), $count);
1644
    }
1645
    echo '</table></div><br>';
1646
}
1647
1648
/**
1649
 * Metagen
1650
 *
1651
 * Metagen is a system that can help you to have your page best indexed by search engines.
1652
 * Except if you type meta keywords and meta descriptions yourself, the module will automatically create them.
1653
 * From here you can also manage some other options like the maximum number of meta keywords to create and
1654
 * the keywords apparition's order.
1655
 */
1656
function getMetagen()
1657
{
1658
    require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
1659
    global $xoopsModule, $xoopsConfig, $xoopsModuleConfig, $cfg;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
1660
    xoops_cp_header();
1661
    $myts = MyTextSanitizer::getInstance();
0 ignored issues
show
Unused Code introduced by
$myts is not used, you could remove the assignment.

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

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

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

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

Loading history...
1662 View Code Duplication
    if (file_exists(XOOPS_ROOT_PATH . '/modules/news/language/' . $xoopsConfig['language'] . '/main.php')) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1663
        require_once XOOPS_ROOT_PATH . '/modules/news/language/' . $xoopsConfig['language'] . '/main.php';
1664
    } else {
1665
        require_once XOOPS_ROOT_PATH . '/modules/news/language/english/main.php';
1666
    }
1667
    $adminObject = \Xmf\Module\Admin::getInstance();
1668
    $adminObject->displayNavigation('index.php?op=metagen');
1669
    //echo "<h1>"._AM_NEWS_METAGEN."</h1>";
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

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

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

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

Loading history...
1670
    echo _AM_NEWS_METAGEN_DESC . '<br><br>';
1671
1672
    // Metagen Options
1673
    $registry = new news_registryfile('news_metagen_options.txt');
1674
    $content  = '';
0 ignored issues
show
Unused Code introduced by
$content is not used, you could remove the assignment.

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

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

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

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

Loading history...
1675
    $content  = $registry->getfile();
1676
    if ('' !== xoops_trim($content)) {
1677
        list($keywordscount, $keywordsorder) = explode(',', $content);
1678
    } else {
1679
        $keywordscount = $cfg['meta_keywords_count'];
1680
        $keywordsorder = $cfg['meta_keywords_order'];
1681
    }
1682
    $sform = new XoopsThemeForm(_OPTIONS, 'metagenoptions', XOOPS_URL . '/modules/news/admin/index.php', 'post', true);
1683
    $sform->addElement(new XoopsFormHidden('op', 'metagenoptions'), false);
1684
    $sform->addElement(new XoopsFormText(_AM_NEWS_META_KEYWORDS_CNT, 'keywordscount', 4, 6, $keywordscount), true);
1685
    $keywordsorder = new XoopsFormRadio(_AM_NEWS_META_KEYWORDS_ORDER, 'keywordsorder', $keywordsorder);
1686
    $keywordsorder->addOption(0, _AM_NEWS_META_KEYWORDS_INTEXT);
1687
    $keywordsorder->addOption(1, _AM_NEWS_META_KEYWORDS_FREQ1);
1688
    $keywordsorder->addOption(2, _AM_NEWS_META_KEYWORDS_FREQ2);
1689
    $sform->addElement($keywordsorder, false);
1690
    $button_tray = new XoopsFormElementTray('', '');
1691
    $submit_btn  = new XoopsFormButton('', 'post', _AM_MODIFY, 'submit');
1692
    $button_tray->addElement($submit_btn);
1693
    $sform->addElement($button_tray);
1694
    $sform->display();
1695
1696
    // Blacklist
1697
    $sform = new XoopsThemeForm(_AM_NEWS_BLACKLIST, 'metagenblacklist', XOOPS_URL . '/modules/news/admin/index.php', 'post', true);
1698
    $sform->addElement(new XoopsFormHidden('op', 'metagenblacklist'), false);
1699
1700
    // Remove words
1701
    $remove_tray = new XoopsFormElementTray(_AM_NEWS_BLACKLIST);
1702
    $remove_tray->setDescription(_AM_NEWS_BLACKLIST_DESC);
1703
    $blacklist = new XoopsFormSelect('', 'blacklist', '', 5, true);
1704
    $words     = [];
0 ignored issues
show
Unused Code introduced by
$words is not used, you could remove the assignment.

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

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

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

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

Loading history...
1705
1706
    $metablack = new news_blacklist();
1707
    $words     = $metablack->getAllKeywords();
1708
    if (is_array($words) && count($words) > 0) {
1709
        foreach ($words as $key => $value) {
1710
            $blacklist->addOption($key, $value);
1711
        }
1712
    }
1713
1714
    $blacklist->setDescription(_AM_NEWS_BLACKLIST_DESC);
1715
    $remove_tray->addElement($blacklist, false);
1716
    $remove_btn = new XoopsFormButton('', 'go', _AM_DELETE, 'submit');
1717
    $remove_tray->addElement($remove_btn, false);
1718
    $sform->addElement($remove_tray);
1719
1720
    // Add some words
1721
    $add_tray = new XoopsFormElementTray(_AM_NEWS_BLACKLIST_ADD);
1722
    $add_tray->setDescription(_AM_NEWS_BLACKLIST_ADD_DSC);
1723
    $add_field = new XoopsFormTextArea('', 'keywords', '', 5, 70);
1724
    $add_tray->addElement($add_field, false);
1725
    $add_btn = new XoopsFormButton('', 'go', _AM_ADD, 'submit');
1726
    $add_tray->addElement($add_btn, false);
1727
    $sform->addElement($add_tray);
1728
    $sform->display();
1729
}
1730
1731
/**
1732
 * Save metagen's blacklist words
1733
 */
1734
function saveMetagenBlackList()
0 ignored issues
show
Coding Style introduced by
saveMetagenBlackList uses the super-global variable $_POST which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
1735
{
1736
    $blacklist = new news_blacklist();
1737
    $words     = $blacklist->getAllKeywords();
0 ignored issues
show
Unused Code introduced by
$words is not used, you could remove the assignment.

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

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

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

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

Loading history...
1738
1739
    if (isset($_POST['go']) && _AM_DELETE == $_POST['go']) {
1740
        foreach ($_POST['blacklist'] as $black_id) {
1741
            $blacklist->delete($black_id);
1742
        }
1743
        $blacklist->store();
1744
    } else {
1745
        if (isset($_POST['go']) && _AM_ADD == $_POST['go']) {
1746
            $p_keywords = $_POST['keywords'];
1747
            $keywords   = explode("\n", $p_keywords);
1748
            foreach ($keywords as $keyword) {
1749
                if ('' !== xoops_trim($keyword)) {
1750
                    $blacklist->addkeywords(xoops_trim($keyword));
1751
                }
1752
            }
1753
            $blacklist->store();
1754
        }
1755
    }
1756
    redirect_header('index.php?op=metagen', 0, _AM_DBUPDATED);
1757
}
1758
1759
/**
1760
 * Save Metagen Options
1761
 */
1762
function saveMetagenOptions()
0 ignored issues
show
Coding Style introduced by
saveMetagenOptions uses the super-global variable $_POST which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
1763
{
1764
    $registry = new news_registryfile('news_metagen_options.txt');
1765
    $registry->savefile((int)$_POST['keywordscount'] . ',' . (int)$_POST['keywordsorder']);
1766
    redirect_header('index.php?op=metagen', 0, _AM_DBUPDATED);
1767
}
1768
1769
// **********************************************************************************************************************************************
1770
// **** Main
1771
// **********************************************************************************************************************************************
1772
$op = 'default';
1773
if (isset($_POST['op'])) {
1774
    $op = $_POST['op'];
1775
} elseif (isset($_GET['op'])) {
1776
    $op = $_GET['op'];
1777
}
1778
$adminObject = \Xmf\Module\Admin::getInstance();
1779
switch ($op) {
1780
    case 'deletefile':
1781
        xoops_cp_header();
1782
        if ('newsletter' === $_GET['type']) {
1783
            $newsfile = XOOPS_ROOT_PATH . '/uploads/news/newsletter.txt';
1784 View Code Duplication
            if (unlink($newsfile)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1785
                redirect_header('index.php', 2, _AM_NEWS_DELETED_OK);
1786
            } else {
1787
                redirect_header('index.php', 2, _AM_NEWS_DELETED_PB);
1788
            }
1789
        } else {
1790
            if ('xml' === $_GET['type']) {
1791
                $xmlfile = XOOPS_ROOT_PATH . '/uploads/news/stories.xml';
1792 View Code Duplication
                if (unlink($xmlfile)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1793
                    redirect_header('index.php', 2, _AM_NEWS_DELETED_OK);
1794
                } else {
1795
                    redirect_header('index.php', 2, _AM_NEWS_DELETED_PB);
1796
                }
1797
            }
1798
        }
1799
        break;
1800
1801
    case 'newarticle':
1802
        xoops_cp_header();
1803
        $adminObject->displayNavigation('index.php?op=newarticle');
1804
        echo '<h4>' . _AM_CONFIG . '</h4>';
1805
        require_once XOOPS_ROOT_PATH . '/class/module.textsanitizer.php';
1806
        newSubmissions();
1807
        autoStories();
1808
        lastStories();
1809
        expStories();
1810
        echo '<br>';
1811
        echo '<h4>' . _AM_POSTNEWARTICLE . '</h4>';
1812
        $type         = 'admin';
1813
        $title        = '';
1814
        $topicdisplay = 0;
1815
        $topicalign   = 'R';
1816
        $ihome        = 0;
1817
        $hometext     = '';
1818
        $bodytext     = '';
1819
        $notifypub    = 1;
1820
        $nohtml       = 0;
1821
        $approve      = 0;
1822
        $nosmiley     = 0;
1823
        $autodate     = '';
1824
        $expired      = '';
1825
        $topicid      = 0;
1826
        $returnside   = 1;
1827
        $published    = 0;
1828
        $description  = '';
1829
        $keywords     = '';
1830 View Code Duplication
        if (file_exists(XOOPS_ROOT_PATH . '/modules/news/language/' . $xoopsConfig['language'] . '/main.php')) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1831
            require_once XOOPS_ROOT_PATH . '/modules/news/language/' . $xoopsConfig['language'] . '/main.php';
1832
        } else {
1833
            require_once XOOPS_ROOT_PATH . '/modules/news/language/english/main.php';
1834
        }
1835
1836
        if (1 == $xoopsModuleConfig['autoapprove']) {
1837
            $approve = 1;
1838
        }
1839
        $approveprivilege = 1;
1840
        require_once XOOPS_ROOT_PATH . '/modules/news/include/storyform.original.php';
1841
        break;
1842
1843
    case 'delete':
1844
        $storyid = 0;
1845 View Code Duplication
        if (isset($_GET['storyid'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1846
            $storyid = (int)$_GET['storyid'];
1847
        } elseif (isset($_POST['storyid'])) {
1848
            $storyid = (int)$_POST['storyid'];
1849
        }
1850
1851
        if (!empty($_POST['ok'])) {
1852
            if (empty($storyid)) {
1853
                redirect_header('index.php?op=newarticle', 2, _AM_EMPTYNODELETE);
1854
            }
1855
            $story = new NewsStory($storyid);
1856
            $story->delete();
1857
            $sfiles   = new sFiles();
1858
            $filesarr = [];
1859
            $filesarr = $sfiles->getAllbyStory($storyid);
1860
            if (count($filesarr) > 0) {
1861
                foreach ($filesarr as $onefile) {
1862
                    $onefile->delete();
1863
                }
1864
            }
1865
            xoops_comment_delete($xoopsModule->getVar('mid'), $storyid);
1866
            xoops_notification_deletebyitem($xoopsModule->getVar('mid'), 'story', $storyid);
1867
            NewsUtility::updateCache();
1868
            redirect_header('index.php?op=newarticle', 1, _AM_DBUPDATED);
1869
        } else {
1870
            $story = new NewsStory($storyid);
1871
            xoops_cp_header();
1872
            echo '<h4>' . _AM_CONFIG . '</h4>';
1873
            xoops_confirm(['op' => 'delete', 'storyid' => $storyid, 'ok' => 1], 'index.php', _AM_RUSUREDEL . '<br>' . $story->title());
1874
        }
1875
        break;
1876
1877
    case 'topicsmanager':
1878
        topicsmanager();
1879
        break;
1880
1881
    case 'addTopic':
1882
        addTopic();
1883
        break;
1884
1885
    case 'delTopic':
1886
        delTopic();
1887
        break;
1888
1889
    case 'modTopicS':
1890
        modTopicS();
1891
        break;
1892
1893
    case 'edit':
1894 View Code Duplication
        if (file_exists(XOOPS_ROOT_PATH . '/modules/news/language/' . $xoopsConfig['language'] . '/main.php')) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1895
            require_once XOOPS_ROOT_PATH . '/modules/news/language/' . $xoopsConfig['language'] . '/main.php';
1896
        } else {
1897
            require_once XOOPS_ROOT_PATH . '/modules/news/language/english/main.php';
1898
        }
1899
        require_once XOOPS_ROOT_PATH . '/modules/news/submit.php';
1900
        break;
1901
1902
    case 'prune':
1903
        setPruneManager();
1904
        break;
1905
1906
    case 'confirmbeforetoprune':
1907
        confirmBeforePrune();
1908
        break;
1909
1910
    case 'prunenews':
1911
        pruneNews();
1912
        break;
1913
1914
    case 'export':
1915
        exportNews();
1916
        break;
1917
1918
    case 'launchexport':
1919
        launchExport();
1920
        break;
1921
1922
    case 'configurenewsletter':
1923
        createNewsletter();
1924
        break;
1925
1926
    case 'launchnewsletter':
1927
        launchNewsletter();
1928
        break;
1929
1930
    case 'stats':
1931
        getStats();
1932
        break;
1933
1934
    case 'metagen':
1935
        getMetagen();
1936
        break;
1937
1938
    case 'metagenoptions':
1939
        saveMetagenOptions();
1940
        break;
1941
1942
    case 'metagenblacklist':
1943
        saveMetagenBlackList();
1944
        break;
1945
1946
    case 'verifydb':
1947
        xoops_cp_header();
1948
        //news_adminmenu();
1949
        $tbllist = $xoopsDB->prefix('news_stories') . ',' . $xoopsDB->prefix('news_topics') . ',' . $xoopsDB->prefix('news_stories_files') . ',' . $xoopsDB->prefix('news_stories_votedata');
1950
        $xoopsDB->queryF('OPTIMIZE TABLE ' . $tbllist);
1951
        $xoopsDB->queryF('CHECK TABLE ' . $tbllist);
1952
        $xoopsDB->queryF('ANALYZE TABLE ' . $tbllist);
1953
        redirect_header('index.php', 3, _AM_DBUPDATED);
1954
        break;
1955
1956
    case 'default':
1957
    default:
1958
        xoops_cp_header();
1959
1960
        $folder = [
1961
            XOOPS_ROOT_PATH . '/uploads/news/',
1962
            XOOPS_ROOT_PATH . '/uploads/news/file',
1963
            XOOPS_ROOT_PATH . '/uploads/news/image'
1964
        ];
1965
1966
        $topicsHandler  = xoops_getModuleHandler('news_topics', 'news');
1967
        $storiesHandler = xoops_getModuleHandler('news_stories', 'news');
1968
1969
        //compte "total"
1970
        $count_stories = $storiesHandler->getCount();
1971
        //compte "attente"
1972
        $criteria = new CriteriaCompo();
1973
        $criteria->add(new Criteria('ihome', 1));
1974
        $stories_ihome = $storiesHandler->getCount($criteria);
1975
1976
        $criteria = new CriteriaCompo();
1977
        $criteria->add(new Criteria('published', 0, '>'));
1978
        $stories_published = $storiesHandler->getCount($criteria);
1979
1980
        $stories_need_approval = $count_stories - $stories_published;
1981
1982
        $criteria = new CriteriaCompo();
1983
        $criteria->add(new Criteria('expired', 0, '>'));
1984
        $criteria->add(new Criteria('expired', time(), '<'));
1985
        $stories_expired = $storiesHandler->getCount($criteria);
1986
1987
        $criteria = new CriteriaCompo();
1988
        $criteria->add(new Criteria('expired', 0, '>'));
1989
        $criteria->add(new Criteria('expired', time(), '>'));
1990
        $stories_expired_soon = $storiesHandler->getCount($criteria);
1991
1992
        //compte "total"
1993
        $count_topics = $topicsHandler->getCount();
1994
        //compte "attente"
1995
        $criteria = new CriteriaCompo();
1996
        $criteria->add(new Criteria('menu', 1));
1997
        $topics_menu = $topicsHandler->getCount($criteria);
1998
1999
        $clr_count_stories = (0 == $count_stories) ? 'red' : 'green';
2000
        $clr_count_topics  = (0 == $count_topics) ? 'red' : 'green';
2001
        $clr_ihome_stories = (0 == $stories_ihome) ? 'red' : 'green';
2002
        $clr_menu_topics   = (0 == $topics_menu) ? 'red' : 'green';
2003
2004
        $clr_published_stories         = (0 == $stories_published) ? 'red' : 'green';
2005
        $clr_need_approval_stories     = (0 == $stories_need_approval) ? 'green' : 'red';
2006
        $clr_expired_stories           = (0 == $stories_expired) ? 'red' : 'green';
2007
        $clr_need_expired_soon_stories = (0 == $stories_expired_soon) ? 'red' : 'green';
2008
2009
        $adminObject->addInfoBox(_AM_NEWS_STATISTICS);
2010
        $adminObject->addInfoBoxLine(sprintf(_AM_NEWS_THEREARE_TOPICS, $count_topics), '', $clr_count_topics);
2011
        $adminObject->addInfoBoxLine(sprintf(_AM_NEWS_THEREARE_TOPICS_ONLINE, $topics_menu), '', $clr_menu_topics);
2012
        $adminObject->addInfoBoxLine(sprintf(_AM_NEWS_THEREARE_STORIES, $count_stories), '', $clr_count_stories);
2013
        $adminObject->addInfoBoxLine(sprintf(_AM_NEWS_THEREARE_STORIES_ONLINE, $stories_ihome), '', $clr_ihome_stories);
2014
2015
        $adminObject->addInfoBoxLine(sprintf(_AM_NEWS_THEREARE_STORIES_APPROVED, $stories_published), '', $clr_ihome_stories);
2016
        $adminObject->addInfoBoxLine(sprintf(_AM_NEWS_THEREARE_STORIES_NEED_APPROVAL, $stories_need_approval), '', $clr_need_approval_stories);
2017
        $adminObject->addInfoBoxLine(sprintf(_AM_NEWS_THEREARE_STORIES_EXPIRED, $stories_expired), '', $clr_expired_stories);
2018
        $adminObject->addInfoBoxLine(sprintf(_AM_NEWS_THEREARE_STORIES_EXPIRED_SOON, $stories_expired_soon), '', $clr_need_expired_soon_stories);
2019
2020
        foreach (array_keys($folder) as $i) {
2021
            $adminObject->addConfigBoxLine($folder[$i], 'folder');
2022
            $adminObject->addConfigBoxLine([$folder[$i], '777'], 'chmod');
2023
        }
2024
2025
        $adminObject->displayNavigation(basename(__FILE__));
2026
        $adminObject->displayIndex();
2027
2028
        break;
2029
2030
}
2031
require_once __DIR__ . '/admin_footer.php';
2032