Completed
Push — master ( fe4c2e...b05117 )
by Michael
12s
created

Admin   C

Complexity

Total Complexity 74

Size/Duplication

Total Lines 757
Duplicated Lines 14.66 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 0%

Importance

Changes 3
Bugs 2 Features 0
Metric Value
wmc 74
c 3
b 2
f 0
lcom 1
cbo 6
dl 111
loc 757
rs 5
ccs 0
cts 447
cp 0

26 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A addBreadcrumbLink() 0 8 2
D addConfigBoxLine() 57 109 16
A addConfigError() 0 4 1
A addConfigAccept() 0 4 1
A addConfigWarning() 0 4 1
B addConfigModuleVersion() 31 31 4
A addInfoBox() 0 8 1
A addInfoBoxLine() 0 14 3
A addItemButton() 9 9 1
A addTips() 0 4 1
A getTplPath() 0 4 1
A renderBreadcrumb() 0 6 1
A displayBreadcrumb() 0 4 1
A renderButton() 0 9 1
A displayButton() 0 4 1
A renderInfoBox() 0 6 1
A displayInfoBox() 0 4 1
F renderIndex() 7 131 16
A displayIndex() 0 4 1
B renderNavigation() 7 21 5
A displayNavigation() 0 7 2
A renderTips() 0 6 1
A displayTips() 0 4 1
C renderAbout() 0 71 8
A displayAbout() 0 4 1

How to fix   Duplicated Code    Complexity   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like Admin often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use Admin, and based on these observations, apply Extract Interface, too.

1
<?php
2
/*
3
 You may not change or alter any portion of this comment or credits
4
 of supporting developers from this source code or any supporting source code
5
 which is considered copyrighted (c) material of the original comment or credit authors.
6
7
 This program is distributed in the hope that it will be useful,
8
 but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10
*/
11
12
namespace Xoops\Module;
13
14
/**
15
 * Xoops ModuleAdmin Classes
16
 *
17
 * @category  Xoops\Module\Admin
18
 * @package   Admin
19
 * @author    Mage Grégory (AKA Mage)
20
 * @copyright 2013-2015 XOOPS Project (http://xoops.org)
21
 * @license   GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
22
 * @link      xoops.org
23
 * @since     2.6.0
24
 */
25
class Admin
26
{
27
    /**
28
     * Set module directory
29
     *
30
     * @var string
31
     */
32
    public $tplModule = 'system';
33
34
    /**
35
     * Template call for each render parts
36
     *
37
     * @var array
38
     */
39
    public $tplFile = array(
40
        'index' => 'admin_index.tpl',
41
        'about' => 'admin_about.tpl',
42
        'infobox' => 'admin_infobox.tpl',
43
        'bread' => 'admin_breadcrumb.tpl',
44
        'button' => 'admin_buttons.tpl',
45
        'tips' => 'admin_tips.tpl',
46
        'nav'   => 'admin_navigation.tpl',
47
    );
48
49
    /**
50
     * Tips to display in admin page
51
     *
52
     * @var string
53
     */
54
    private $tips = '';
55
56
    /**
57
     * List of button
58
     *
59
     * @var array
60
     */
61
    private $itemButton = array();
62
63
    /**
64
     * List of Info Box
65
     *
66
     * @var array
67
     */
68
    private $itemInfoBox = array();
69
70
    /**
71
     * List of line of an Info Box
72
     *
73
     * @var array
74
     */
75
    private $itemConfigBoxLine = array();
76
77
    /**
78
     * Breadcrumb data
79
     *
80
     * @var array
81
     */
82
    private $bread = array();
83
84
    /**
85
     * Current module object
86
     *
87
     * @var \Xoops\Core\Kernel\Handlers\XoopsModule $module
88
     */
89
    private $module = null;
90
91
    /**
92
     * Constructor
93
     */
94
    public function __construct()
95
    {
96
        $xoops = \Xoops::getInstance();
97
        $this->module = $xoops->module;
98
        $xoops->theme()->addStylesheet('media/xoops/css/moduladmin.css');
99
    }
100
101
    /**
102
     * Add breadcrumb menu
103
     *
104
     * @param string $title title
105
     * @param string $link  url
106
     * @param bool   $home  is home
107
     *
108
     * @return void
109
     */
110
    public function addBreadcrumbLink($title = '', $link = '', $home = false)
111
    {
112
        if ($title != '') {
113
            $this->bread[] = array(
114
                'link' => $link, 'title' => $title, 'home' => $home
115
            );
116
        }
117
    }
118
119
    /**
120
     * Add config line
121
     *
122
     * @param string $value line value - a string or array of values
123
     * @param string $type  type of line default, folder, chmod, extension, module
124
     *                       Or, type value for itemConfigBoxLine -- accept, warning, error
125
     *
126
     * @return bool
127
     */
128
    public function addConfigBoxLine($value = '', $type = 'default')
129
    {
130
        switch ($type) {
131
            default:
132
            case "default":
133
                $this->itemConfigBoxLine[] = array('type' => $type, 'text' => $value);
134
                break;
135
136
            case "folder":
137
                if (!is_dir($value)) {
138
                    $this->itemConfigBoxLine[] = array(
139
                        'type' => 'error', 'text' => sprintf(\XoopsLocale::EF_FOLDER_DOES_NOT_EXIST, $value)
140
                    );
141
                } else {
142
                    $this->itemConfigBoxLine[] = array(
143
                        'type' => 'accept', 'text' => sprintf(\XoopsLocale::SF_FOLDER_EXISTS, $value)
144
                    );
145
                }
146
                break;
147
148
            case "chmod":
149
                if (is_dir($value[0])) {
150
                    if (substr(decoct(fileperms($value[0])), 2) != $value[1]) {
151
                        $this->itemConfigBoxLine[] = array(
152
                            'type' => 'error',
153
                            'text' => sprintf(
154
                                \XoopsLocale::EF_FOLDER_MUST_BE_WITH_CHMOD,
155
                                $value[0],
156
                                $value[1],
157
                                substr(decoct(fileperms($value[0])), 2)
158
                            )
159
                        );
160
                    } else {
161
                        $this->itemConfigBoxLine[] = array(
162
                            'type' => 'accept',
163
                            'text' => sprintf(
164
                                \XoopsLocale::EF_FOLDER_MUST_BE_WITH_CHMOD,
165
                                $value[0],
166
                                $value[1],
167
                                substr(decoct(fileperms($value[0])), 2)
168
                            )
169
                        );
170
                    }
171
                }
172
                break;
173
174 View Code Duplication
            case "extension":
175
                $xoops = \Xoops::getInstance();
176
                if (is_array($value)) {
177
                    $text = $value[0];
178
                    $type = $value[1];
179
                } else {
180
                    $text = $value;
181
                    $type = 'error';
182
                }
183
                if ($xoops->isActiveModule($text) == false) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
184
                    $this->itemConfigBoxLine[] = array(
185
                        'type' => $type, 'text' => sprintf(\XoopsLocale::EF_EXTENSION_IS_NOT_INSTALLED, $text)
186
                    );
187
                } else {
188
                    $this->itemConfigBoxLine[] = array(
189
                        'type' => 'accept', 'text' => sprintf(\XoopsLocale::SF_EXTENSION_IS_INSTALLED, $text)
190
                    );
191
                }
192
                break;
193
194 View Code Duplication
            case "module":
195
                $xoops = \Xoops::getInstance();
196
                if (is_array($value)) {
197
                    $text = $value[0];
198
                    $type = $value[1];
199
                } else {
200
                    $text = $value;
201
                    $type = 'error';
202
                }
203
                if ($xoops->isActiveModule($text) == false) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
204
                    $this->itemConfigBoxLine[] = array(
205
                        'type' => $type, 'text' => sprintf(\XoopsLocale::F_MODULE_IS_NOT_INSTALLED, $text)
206
                    );
207
                } else {
208
                    $this->itemConfigBoxLine[] = array(
209
                        'type' => 'accept', 'text' => sprintf(\XoopsLocale::F_MODULE_IS_INSTALLED, $text)
210
                    );
211
                }
212
                break;
213
214 View Code Duplication
            case "service":
215
                $xoops = \Xoops::getInstance();
216
                if (is_array($value)) {
217
                    $text = $value[0];
218
                    $type = $value[1];
219
                } else {
220
                    $text = $value;
221
                    $type = 'error';
222
                }
223
                if ($xoops->service($text)->isAvailable()) {
224
                    $this->itemConfigBoxLine[] = array(
225
                        'type' => 'accept', 'text' => sprintf(\XoopsLocale::SF_SERVICE_IS_INSTALLED, $text)
226
                    );
227
                } else {
228
                    $this->itemConfigBoxLine[] = array(
229
                        'type' => $type, 'text' => sprintf(\XoopsLocale::EF_SERVICE_IS_NOT_INSTALLED, $text)
230
                    );
231
                }
232
                break;
233
234
        }
235
        return true;
236
    }
237
238
    // simplified config aliases
239
240
    /**
241
     * Add error to config box
242
     *
243
     * @param string $value the error message
244
     *
245
     * @return bool
246
     */
247
    public function addConfigError($value = '')
248
    {
249
        return $this->addConfigBoxLine($value, 'error');
250
    }
251
252
    /**
253
     * Add accept (OK) message to config box
254
     *
255
     * @param string $value the OK message
256
     *
257
     * @return bool
258
     */
259
    public function addConfigAccept($value = '')
260
    {
261
        return $this->addConfigBoxLine($value, 'accept');
262
    }
263
264
    /**
265
     * Add warning to config box
266
     *
267
     * @param string $value the warning message
268
     *
269
     * @return bool
270
     */
271
    public function addConfigWarning($value = '')
272
    {
273
        return $this->addConfigBoxLine($value, 'warning');
274
    }
275
276
    /**
277
     * Check for installed module and version and to configuration box
278
     *
279
     * @param string  $moddir     module directory name
280
     * @param integer $minversion minimum acceptable module version (100 = V1.00)
281
     *
282
     * @return bool true if requested version of the module is available
283
     */
284 View Code Duplication
    public function addConfigModuleVersion($moddir, $minversion)
285
    {
286
        $return=false;
287
        $helper= \Xoops::getInstance()->getModuleHelper($moddir);
288
        if (is_object($helper) && is_object($helper->getModule())) {
289
            $mod_modversion=$helper->getModule()->getVar('version');
290
            $mod_version_f = $mod_modversion/100;
291
            $min_version_f = $minversion/100;
292
            $value = sprintf(
293
                \XoopsLocale::EF_MODULE_VERSION,
294
                strtoupper($moddir),
295
                $min_version_f,
296
                $mod_version_f
297
            );
298
            if ($mod_modversion>=$minversion) {
299
                $this->addConfigAccept($value);
300
                $return=true;
301
            } else {
302
                $this->addConfigError($value);
303
            }
304
        } else {
305
            $value = sprintf(
306
                \XoopsLocale::EF_MODULE_NOTFOUND,
307
                strtoupper($moddir),
308
                $minversion/100
309
            );
310
            $this->addConfigError($value);
311
        }
312
313
        return $return;
314
    }
315
316
    /**
317
     * Add Info box
318
     * Template in htdocs/modules/system/templates/admin/admin_infobox.tpl
319
     *
320
     * @param string $title title
321
     * @param string $type  type  will be used as icon name in title in template
322
     * @param string $extra extra added to the div element that surrounds the box
323
     *
324
     * @return bool
325
     */
326
    public function addInfoBox($title, $type = 'default', $extra = '')
327
    {
328
        $ret['title'] = $title;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$ret was never initialized. Although not strictly required by PHP, it is generally a good practice to add $ret = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
329
        $ret['type'] = $type;
330
        $ret['extra'] = $extra;
331
        $this->itemInfoBox[] = $ret;
332
        return true;
333
    }
334
335
    /**
336
     * Add line to the info box
337
     *
338
     * @param string $text  title
339
     * @param string $type  type
340
     * @param string $color color
341
     *
342
     * @return bool
343
     */
344
    public function addInfoBoxLine($text = '', $type = 'default', $color = 'inherit')
345
    {
346
        $ret = array();
347
        $ret['text'] = $text;
348
        $ret['color'] = $color;
349
350
        foreach (array_keys($this->itemInfoBox) as $i) {
351
            if ($this->itemInfoBox[$i]['type'] == $type) {
352
                $this->itemInfoBox[$i]['line'][] = $ret;
353
                unset($ret);
354
            }
355
        }
356
        return true;
357
    }
358
359
    /**
360
     * Add Item button
361
     *
362
     * @param string $title title
363
     * @param string $link  link
364
     * @param string $icon  icon
365
     * @param string $extra extra
366
     *
367
     * @return bool
368
     */
369 View Code Duplication
    public function addItemButton($title, $link, $icon = 'add', $extra = '')
370
    {
371
        $ret['title'] = $title;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$ret was never initialized. Although not strictly required by PHP, it is generally a good practice to add $ret = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
372
        $ret['link'] = $link;
373
        $ret['icon'] = $icon;
374
        $ret['extra'] = $extra;
375
        $this->itemButton[] = $ret;
376
        return true;
377
    }
378
379
    /**
380
     * Add a tips
381
     *
382
     * @param string $text text
383
     *
384
     * @return void
385
     */
386
    public function addTips($text = '')
387
    {
388
        $this->tips = $text;
389
    }
390
391
    /**
392
     * Construct template path
393
     *
394
     * @param string $type type
395
     *
396
     * @return string
397
     */
398
    private function getTplPath($type = '')
399
    {
400
        return 'admin:' . $this->tplModule . '/' . $this->tplFile[$type];
401
    }
402
403
    /**
404
     * renderBreadcrumb
405
     *
406
     * @return string
407
     */
408
    public function renderBreadcrumb()
409
    {
410
        $xoops = \Xoops::getInstance();
411
        $xoops->tpl()->assign('xo_admin_breadcrumb', $this->bread);
412
        return $xoops->tpl()->fetch($this->getTplPath('bread'));
413
    }
414
415
    /**
416
     * displayBreadcrumb
417
     *
418
     * @return void
419
     */
420
    public function displayBreadcrumb()
421
    {
422
        echo $this->renderBreadcrumb();
423
    }
424
425
    /**
426
     * Render all items buttons
427
     *
428
     * @param string $position  position
429
     * @param string $delimiter delimiter
430
     *
431
     * @return string
432
     */
433
    public function renderButton($position = "floatright", $delimiter = "&nbsp;")
434
    {
435
        $xoops = \Xoops::getInstance();
436
437
        $xoops->tpl()->assign('xo_admin_buttons_position', $position);
438
        $xoops->tpl()->assign('xo_admin_buttons_delim', $delimiter);
439
        $xoops->tpl()->assign('xo_admin_buttons', $this->itemButton);
440
        return $xoops->tpl()->fetch($this->getTplPath('button'));
441
    }
442
443
    /**
444
     * displayButton
445
     *
446
     * @param string $position  position
447
     * @param string $delimiter delimiter
448
     *
449
     * @return void
450
     */
451
    public function displayButton($position = "floatright", $delimiter = "&nbsp;")
452
    {
453
        echo $this->renderButton($position, $delimiter);
454
    }
455
456
    /**
457
     * Render InfoBox
458
     *
459
     * @return string
460
     */
461
    public function renderInfoBox()
462
    {
463
        $xoops = \Xoops::getInstance();
464
        $xoops->tpl()->assign('xo_admin_box', $this->itemInfoBox);
465
        return $xoops->tpl()->fetch($this->getTplPath('infobox'));
466
    }
467
468
    /**
469
     * displayInfoBox
470
     *
471
     * @return void
472
     */
473
    public function displayInfoBox()
474
    {
475
        echo $this->renderInfoBox();
476
    }
477
478
    /**
479
     * Render index page for admin
480
     *
481
     * @return string
482
     */
483
    public function renderIndex()
484
    {
485
        $xoops = \Xoops::getInstance();
486
        $this->module->loadAdminMenu();
487
        foreach (array_keys($this->module->adminmenu) as $i) {
488 View Code Duplication
            if (\XoopsLoad::fileExists($xoops->path("media/xoops/images/icons/32/" . $this->module->adminmenu[$i]['icon']))) {
489
                $this->module->adminmenu[$i]['icon'] = $xoops->url("media/xoops/images/icons/32/" . $this->module->adminmenu[$i]['icon']);
490
            } elseif (\XoopsLoad::fileExists($xoops->path("modules/" . $xoops->module->dirname() . "/assets/icons/32/" . $this->module->adminmenu[$i]['icon']))) {
491
                $this->module->adminmenu[$i]['icon'] = $xoops->url("modules/" . $xoops->module->dirname() . "/assets/icons/32/" . $this->module->adminmenu[$i]['icon']);
492
            } else {
493
                $this->module->adminmenu[$i]['icon'] = $xoops->url("modules/" . $xoops->module->dirname() . "/icons/32/" . $this->module->adminmenu[$i]['icon']);
494
            }
495
            $xoops->tpl()->append('xo_admin_index_menu', $this->module->adminmenu[$i]);
496
        }
497
        if ($this->module->getInfo('help')) {
498
            $help = array();
499
            $help['link'] = '../system/help.php?mid=' . $this->module->getVar('mid', 's')
500
                . "&amp;" . $this->module->getInfo('help');
501
            $help['icon'] = $xoops->url("/media/xoops/images/icons/32/help.png");
502
            $help['title'] = \XoopsLocale::HELP;
503
            $xoops->tpl()->append('xo_admin_index_menu', $help);
504
        }
505
        $xoops->tpl()->assign('xo_admin_box', $this->itemInfoBox);
506
507
        // If you use a config label
508
        if ($this->module->getInfo('min_php') || $this->module->getInfo('min_xoops')
509
            || $this->module->getInfo('min_db') || !empty($this->itemConfigBoxLine)
510
        ) {
511
            // PHP version
512
            if ($this->module->getInfo('min_php')) {
513
                if (0 >= version_compare(phpversion(), $this->module->getInfo('min_php'))) {
514
                    $this->addConfigBoxLine(
515
                        sprintf(
516
                            \XoopsLocale::F_MINIMUM_PHP_VERSION_REQUIRED,
517
                            $this->module->getInfo('min_php'),
518
                            phpversion()
519
                        ),
520
                        'error'
521
                    );
522
                } else {
523
                    $this->addConfigBoxLine(
524
                        sprintf(
525
                            \XoopsLocale::F_MINIMUM_PHP_VERSION_REQUIRED,
526
                            $this->module->getInfo('min_php'),
527
                            phpversion()
528
                        ),
529
                        'accept'
530
                    );
531
                }
532
            }
533
534
            // Database version
535
            // Validate that the current system is acceptable for the module by checking a set of specific
536
            // databases and versions if specified in min_db key.
537
            //
538
            // An array of minimum versions keyed by platform can be optionally specified in xoops_version.php:
539
            //   $modversion['min_db'] = array('mysql' => '5.0.7', 'sqlite' => '3.0.8');
540
            //
541
            // If min_db is specified, and the current database is included in the array, the version will be
542
            // compared to the specified minimum. If the reported database version is equal or greater, an OK
543
            // message will be generated. If the version is lower, an error message will be issued.
544
            //
545
            // If min_db is specified, and the current platform is not included in the array, an error message
546
            // will indicate the module does not support the database current platform.
547
            //
548
            // If at all possible, modules should NOT specify this, as with Doctrine DBAL we should be able to
549
            // support many different databases, and thus portable modules are prefered. The supported databases
550
            // and versions are set by XoopsCore and Doctrine, and should not be restricted without reason.
551
552
            $dbarray = $this->module->getInfo('min_db');
553
            if ($dbarray !== false) {
554
                $dbCurrentPlatform = $xoops->db()->getDatabasePlatform()->getName();
555
                $dbCurrentVersion  = $xoops->db()->getWrappedConnection()->getServerVersion();
556
                if (isset($dbarray[$dbCurrentPlatform])) {
557
                    $dbRequiredVersion = $dbarray[$dbCurrentPlatform];
558
                    if (0 >= version_compare($dbCurrentVersion, $dbRequiredVersion)) {
559
                        $this->addConfigBoxLine(
560
                            sprintf(
561
                                strtoupper(\XoopsBaseConfig::get('db-type')) . ' '
562
                                . \XoopsLocale::F_MINIMUM_DATABASE_VERSION_REQUIRED,
563
                                $dbRequiredVersion,
564
                                $dbCurrentVersion
565
                            ),
566
                            'error'
567
                        );
568
                    } else {
569
                        $this->addConfigBoxLine(
570
                            sprintf(
571
                                strtoupper(\XoopsBaseConfig::get('db-type')) . ' ' . \XoopsLocale::F_MINIMUM_DATABASE_VERSION_REQUIRED,
572
                                $dbRequiredVersion,
573
                                $dbCurrentVersion
574
                            ),
575
                            'accept'
576
                        );
577
                    }
578
                } else {
579
                        $this->addConfigBoxLine(
580
                            sprintf(\XoopsLocale::EF_DATABASE_NOT_SUPPORTED, $dbCurrentPlatform),
581
                            'error'
582
                        );
583
                }
584
            }
585
586
            // xoops version
587
            if ($this->module->getInfo('min_xoops')) {
588
                $xoopsVersion = substr(\Xoops::VERSION, 6); // skip 'XOOPS ' prefix
589
                $xoopsCmpVersion = str_ireplace(['Alpha', 'Beta', 'RC'], ['0Alpha', '0Beta', '0RC'], $xoopsVersion);
590
                if (0 >= version_compare($xoopsCmpVersion, $this->module->getInfo('min_xoops'))) {
591
                    $this->addConfigBoxLine(
592
                        sprintf(
593
                            \XoopsLocale::F_MINIMUM_XOOPS_VERSION_REQUIRED,
594
                            $this->module->getInfo('min_xoops'),
595
                            $xoopsVersion
596
                        ),
597
                        'error'
598
                    );
599
                } else {
600
                    $this->addConfigBoxLine(
601
                        sprintf(
602
                            \XoopsLocale::F_MINIMUM_XOOPS_VERSION_REQUIRED,
603
                            $this->module->getInfo('min_xoops'),
604
                            $xoopsVersion
605
                        ),
606
                        'accept'
607
                    );
608
                }
609
            }
610
            $xoops->tpl()->assign('xo_admin_index_config', $this->itemConfigBoxLine);
611
        }
612
        return $xoops->tpl()->fetch($this->getTplPath('index'));
613
    }
614
615
    /**
616
     * displayIndex
617
     *
618
     * @return void
619
     */
620
    public function displayIndex()
621
    {
622
        echo $this->renderIndex();
623
    }
624
625
    /**
626
     * Render navigation to admin page
627
     *
628
     * @param string $menu current menu
629
     *
630
     * @return array
631
     */
632
    public function renderNavigation($menu = '')
633
    {
634
        $xoops = \Xoops::getInstance();
635
        $ret = array();
636
637
        $this->module->loadAdminMenu();
638
        foreach (array_keys($this->module->adminmenu) as $i) {
639
            if ($this->module->adminmenu[$i]['link'] == "admin/" . $menu) {
640 View Code Duplication
                if (\XoopsLoad::fileExists($xoops->path("media/xoops/images/icons/32/" . $this->module->adminmenu[$i]['icon']))) {
641
                    $this->module->adminmenu[$i]['icon'] = $xoops->url("media/xoops/images/icons/32/". $this->module->adminmenu[$i]['icon']);
642
                } elseif (\XoopsLoad::fileExists($xoops->path("modules/" . $xoops->module->dirname() . "/assets/icons/32/" . $this->module->adminmenu[$i]['icon']))) {
643
                    $this->module->adminmenu[$i]['icon'] = $xoops->url("modules/" . $xoops->module->dirname() . "/assets/icons/32/" . $this->module->adminmenu[$i]['icon']);
644
                } else {
645
                    $this->module->adminmenu[$i]['icon'] = $xoops->url("modules/" . $xoops->module->dirname() . "/icons/32/". $this->module->adminmenu[$i]['icon']);
646
                }
647
                $xoops->tpl()->assign('xo_sys_navigation', $this->module->adminmenu[$i]);
648
                $ret[] = $xoops->tpl()->fetch($this->getTplPath('nav'));
649
            }
650
        }
651
        return $ret;
652
    }
653
654
    /**
655
     * displayNavigation
656
     *
657
     * @param string $menu current menu
658
     *
659
     * @return void
660
     */
661
    public function displayNavigation($menu = '')
662
    {
663
        $items = $this->renderNavigation($menu);
664
        foreach ($items as $item) {
665
            echo $item;
666
        }
667
    }
668
669
    /**
670
     * Render tips to admin page
671
     *
672
     * @return string
673
     */
674
    public function renderTips()
675
    {
676
        $xoops = \Xoops::getInstance();
677
        $xoops->tpl()->assign('xo_admin_tips', $this->tips);
678
        return $xoops->tpl()->fetch($this->getTplPath('tips'));
679
    }
680
681
    /**
682
     * displayTips
683
     *
684
     * @return void
685
     */
686
    public function displayTips()
687
    {
688
        echo $this->renderTips();
689
    }
690
691
    /**
692
     * Render about page
693
     *
694
     * @param bool $logo_xoops show logo
695
     *
696
     * @return bool|mixed|string
697
     */
698
    public function renderAbout($logo_xoops = true)
699
    {
700
        $xoops = \Xoops::getInstance();
701
702
        $date = explode('/', $this->module->getInfo('release_date'));
703
        $author = explode(',', $this->module->getInfo('author'));
704
        $nickname = explode(',', $this->module->getInfo('nickname'));
705
        $release_date = \XoopsLocale::formatTimestamp(mktime(0, 0, 0, $date[1], $date[2], $date[0]), 's');
706
707
        $author_list = '';
708
        foreach (array_keys($author) as $i) {
709
            $author_list .= $author[$i];
710
            if (isset($nickname[$i]) && $nickname[$i] != '') {
711
                $author_list .= " (" . $nickname[$i] . "), ";
712
            } else {
713
                $author_list .= ", ";
714
            }
715
        }
716
        $changelog = '';
717
        $language = $xoops->getConfig('locale');
718
        if (!is_file(
719
            \XoopsBaseConfig::get('root-path') . "/modules/" . $this->module->getVar("dirname")
720
            . "/locale/" . $language . "/changelog.txt"
721
        )) {
722
            $language = 'en_US';
723
        }
724
        $file = \XoopsBaseConfig::get('root-path') . "/modules/" . $this->module->getVar("dirname")
725
            . "/locale/" . $language . "/changelog.txt";
726
        if (is_readable($file)) {
727
            $changelog = utf8_encode(implode("<br />", file($file))) . "\n";
728
        } else {
729
            $file = \XoopsBaseConfig::get('root-path') . "/modules/" . $this->module->getVar("dirname") . "/docs/changelog.txt";
730
            if (is_readable($file)) {
731
                $changelog = utf8_encode(implode("<br />", file($file))) . "\n";
732
            }
733
        }
734
        $author_list = substr($author_list, 0, -2);
735
736
        $this->module->setInfo('release_date', $release_date);
737
        $this->module->setInfo('author_list', $author_list);
738
        if (is_array($this->module->getInfo('paypal'))) {
739
            $this->module->setInfo('paypal', $this->module->getInfo('paypal'));
740
        }
741
        $this->module->setInfo('changelog', $changelog);
742
        $xoops->tpl()->assign('module', $this->module);
743
744
        $this->addInfoBox(\XoopsLocale::MODULE_INFORMATION, 'info', 'id="xo-about"');
745
        $this->addInfoBoxLine(
746
            \XoopsLocale::C_DESCRIPTION . ' ' . $this->module->getInfo("description"),
747
            'info'
748
        );
749
        $this->addInfoBoxLine(
750
            \XoopsLocale::C_UPDATE_DATE . ' <span class="bold">'
751
            . \XoopsLocale::formatTimestamp($this->module->getVar("last_update"), "m")
752
            . '</span>',
753
            'info'
754
        );
755
        $this->addInfoBoxLine(
756
            \XoopsLocale::C_WEBSITE . ' <a class="xo-tooltip" href="http://'
757
            . $this->module->getInfo("module_website_url")
758
            . '" rel="external" title="'
759
            . $this->module->getInfo("module_website_name") . ' - '
760
            . $this->module->getInfo("module_website_url") . '">'
761
            . $this->module->getInfo("module_website_name") . '</a>',
762
            'info'
763
        );
764
765
        $xoops->tpl()->assign('xoops_logo', $logo_xoops);
766
        $xoops->tpl()->assign('xo_admin_box', $this->itemInfoBox);
767
        return $xoops->tpl()->fetch($this->getTplPath('about'));
768
    }
769
770
    /**
771
     * displayAbout
772
     *
773
     * @param bool $logo_xoops display logo
774
     *
775
     * @return void
776
     */
777
    public function displayAbout($logo_xoops = true)
778
    {
779
        echo $this->renderAbout($logo_xoops);
780
    }
781
}
782