Passed
Branch master (c99b04)
by Michael
03:29
created

loadAdminConfig()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
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
/**
13
 * Publisher
14
 *
15
 * @copyright    The XOOPS Project (https://xoops.org)
16
 * @license      GNU GPL (http://www.gnu.org/licenses/gpl-2.0.html/)
17
 * @package      Publisher
18
 * @since        1.0
19
 * @author       Mage, Mamba
20
 */
21
22
use Xmf\Yaml;
23
use XoopsModules\Publisher;
24
use XoopsModules\Publisher\Common;
25
26
require_once __DIR__ . '/admin_header.php';
27
28
xoops_cp_header();
29
/** @var \XoopsModules\Publisher\Helper $helper */
30
$helper = \XoopsModules\Publisher\Helper::getInstance();
31
$helper->loadLanguage('main');
32
$helper->loadLanguage('admin');
33
$adminObject  = \Xmf\Module\Admin::getInstance();
34
$utility      = new Publisher\Utility();
35
$configurator = new Publisher\Common\Configurator();
36
37
/*
38
foreach (array_keys($GLOBALS['uploadFolders']) as $i) {
39
    Publisher\Utility::createFolder($uploadFolders[$i]);
40
    $adminObject->addConfigBoxLine($uploadFolders[$i], 'folder');
41
    //    $adminObject->addConfigBoxLine(array($folder[$i], '777'), 'chmod');
42
}
43
44
//copy blank.png files, if needed
45
$file = PUBLISHER_ROOT_PATH . '/assets/images/blank.png';
46
foreach (array_keys($copyFiles) as $i) {
47
    $dest = $copyFiles[$i] . '/blank.png';
48
    Publisher\Utility::copyFile($file, $dest);
49
}
50
*/
51
52
if (!is_file(XOOPS_ROOT_PATH . '/class/libraries/vendor/tecnickcom/tcpdf/tcpdf.php')) {
53
    $adminObject->addConfigBoxLine('<span style="color:#ff0000;"><img src="' . $pathIcon16 . '/0.png" alt="!">' . _MD_PUBLISHER_ERROR_NO_PDF . '</span>', 'default');
54
}
55
56
$modStats    = [];
57
$moduleStats = $utility->getModuleStats($configurator, $modStats);
58
59
$adminObject->addInfoBox(constant('CO_' . $moduleDirNameUpper . '_' . 'STATS_SUMMARY'));
60
if ($moduleStats && is_array($moduleStats)) {
61
    foreach ($moduleStats as $key => $value) {
62
        switch ($key) {
63
            case 'totalcategories':
64
                $ret = '<span style=\'font-weight: bold; color: green;\'>' . $value . '</span>';
65
                $adminObject->addInfoBoxLine(sprintf( $ret . ' ' . _AM_PUBLISHER_TOTALCAT ));
66
                break;
67
            case 'totalitems':
68
                $ret = '<span style=\'font-weight: bold; color: green;\'>' . $value . '</span>';
69
                $adminObject->addInfoBoxLine(sprintf($ret . ' ' . _AM_PUBLISHER_ITEMS ));
70
                break;
71
            case 'totaloffline':
72
                $ret = '<span style=\'font-weight: bold; color: red;\'>' . $value . '</span>';
73
                $adminObject->addInfoBoxLine(sprintf($ret . ' ' . _AM_PUBLISHER_TOTAL_OFFLINE ));
74
                break;
75
            case 'totalpublished':
76
                $ret = '<span style=\'font-weight: bold; color: green;\'>' . $value . '</span>';
77
                $adminObject->addInfoBoxLine(sprintf($ret . ' ' . _AM_PUBLISHER_TOTALPUBLISHED ));
78
                break;
79
            case 'totalrejected':
80
                $ret = '<span style=\'font-weight: bold; color: red;\'>' . $value . '</span>';
81
                $adminObject->addInfoBoxLine(sprintf($ret . ' ' . _AM_PUBLISHER_REJECTED ));
82
                break;
83
            case 'totalsubmitted':
84
                $ret = '<span style=\'font-weight: bold; color: green;\'>' . $value . '</span>';
85
                $adminObject->addInfoBoxLine(sprintf($ret . ' ' . _AM_PUBLISHER_TOTALSUBMITTED ));
86
                break;
87
        }
88
    }
89
}
90
91
$adminObject->displayNavigation(basename(__FILE__));
92
93
//check for latest release
94
$newRelease = $utility::checkVerModule($helper);
95
if (!empty($newRelease)) {
96
    $adminObject->addItemButton($newRelease[0], $newRelease[1], 'download', 'style="color : Red"');
97
}
98
99
//------------- Test Data ----------------------------
100
101
//if ($helper->getConfig('displaySampleButton')) {
102
//    xoops_loadLanguage('admin/modulesadmin', 'system');
103
//    require_once dirname(__DIR__) . '/testdata/index.php';
104
//    $adminObject->addItemButton(constant('CO_' . $moduleDirNameUpper . '_' . 'ADD_SAMPLEDATA'), './../testdata/index.php?op=load', 'add');
105
//    $adminObject->addItemButton(constant('CO_' . $moduleDirNameUpper . '_' . 'SAVE_SAMPLEDATA'), './../testdata/index.php?op=save', 'add');
106
//    //    $adminObject->addItemButton(constant('CO_' . $moduleDirNameUpper . '_' . 'EXPORT_SCHEMA'), './../testdata/index.php?op=exportschema', 'add');
107
//    $adminObject->displayButton('left', '');
108
//}
109
110
111
112
if ($helper->getConfig('displaySampleButton')) {
113
    $yamlFile            = dirname(__DIR__) . '/config/admin.yml';
114
    $config              = loadAdminConfig($yamlFile);
115
    $displaySampleButton = $config['displaySampleButton'];
116
117
    if (1 == $displaySampleButton) {
118
        xoops_loadLanguage('admin/modulesadmin', 'system');
119
        require __DIR__ . '/../testdata/index.php';
120
121
        $adminObject->addItemButton(constant('CO_' . $moduleDirNameUpper . '_' . 'ADD_SAMPLEDATA'), './../testdata/index.php?op=load', 'add');
122
        $adminObject->addItemButton(constant('CO_' . $moduleDirNameUpper . '_' . 'SAVE_SAMPLEDATA'), './../testdata/index.php?op=save', 'add');
123
        //    $adminObject->addItemButton(constant('CO_' . $moduleDirNameUpper . '_' . 'EXPORT_SCHEMA'), './../testdata/index.php?op=exportschema', 'add');
124
        $adminObject->addItemButton(constant('CO_' . $moduleDirNameUpper . '_' . 'HIDE_SAMPLEDATA_BUTTONS'), '?op=hide_buttons', 'delete');
125
    } else {
126
        $adminObject->addItemButton(constant('CO_' . $moduleDirNameUpper . '_' . 'SHOW_SAMPLEDATA_BUTTONS'), '?op=show_buttons', 'add');
127
        $displaySampleButton = $config['displaySampleButton'];
128
    }
129
    $adminObject->displayButton('left', '');
130
}
131
132
//------------- End Test Data ----------------------------
133
134
$adminObject->displayIndex();
135
136
function loadAdminConfig($yamlFile)
137
{
138
    $config = Yaml::loadWrapped($yamlFile); // work with phpmyadmin YAML dumps
139
    return $config;
140
}
141
142
function hideButtons($yamlFile)
143
{
144
    $app['displaySampleButton'] = 0;
0 ignored issues
show
Comprehensibility Best Practice introduced by
$app was never initialized. Although not strictly required by PHP, it is generally a good practice to add $app = array(); before regardless.
Loading history...
145
    Yaml::save($app, $yamlFile);
146
    redirect_header('index.php', 0, '');
147
}
148
149
function showButtons($yamlFile)
150
{
151
    $app['displaySampleButton'] = 1;
0 ignored issues
show
Comprehensibility Best Practice introduced by
$app was never initialized. Although not strictly required by PHP, it is generally a good practice to add $app = array(); before regardless.
Loading history...
152
    Yaml::save($app, $yamlFile);
153
    redirect_header('index.php', 0, '');
154
}
155
156
$op = \Xmf\Request::getString('op', 0, 'GET');
157
158
switch ($op) {
159
    case 'hide_buttons':
160
        hideButtons($yamlFile);
161
        break;
162
    case 'show_buttons':
163
        showButtons($yamlFile);
164
        break;
165
}
166
167
echo $utility::getServerStats();
168
169
require_once __DIR__ . '/admin_footer.php';
170