Passed
Push — master ( 4761c2...696f77 )
by
unknown
05:50 queued 19s
created

admin/index.php (1 issue)

1
<?php
2
3
declare(strict_types=1);
4
/*
5
 You may not change or alter any portion of this comment or credits
6
 of supporting developers from this source code or any supporting source code
7
 which is considered copyrighted (c) material of the original comment or credit authors.
8
 
9
 This program is distributed in the hope that it will be useful,
10
 but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
 */
13
14
/**
15
 * @category        Module
16
 * @package         suico
17
 * @copyright       {@link https://xoops.org/ XOOPS Project}
18
 * @license         GNU GPL 2 or later (https://www.gnu.org/licenses/gpl-2.0.html)
19
 * @author          Marcello Brandão aka  Suico, Mamba, LioMJ  <https://xoops.org>
20
 */
21
22
use Xmf\Module\Admin;
23
use Xmf\Request;
24
use Xmf\Yaml;
25
use XoopsModules\Suico\Common;
26
27
require __DIR__ . '/admin_header.php';
28
// Display Admin header
29
xoops_cp_header();
30
$adminObject = Admin::getInstance();
31
//check or upload folders
32
$configurator = new Common\Configurator();
33
foreach (array_keys($configurator->uploadFolders) as $i) {
34
    $utility::createFolder($configurator->uploadFolders[$i]);
35
    $adminObject->addConfigBoxLine($configurator->uploadFolders[$i], 'folder');
36
}
37
//-------------------------------------
38
/*
39
//count "total quotes"
40
$quotesCount = $quotesHandler->getCount();
41
// InfoBox quotes
42
$adminObject->addInfoBox(_AM_SUICO_STATISTICS);
43
// InfoBox quotes
44
$adminObject->addInfoBoxLine(sprintf(_AM_SUICO_THEREARE_QUOTES, $quotesCount));
45
*/
46
//count "total Images"
47
/** @var XoopsPersistableObjectHandler $imageHandler */
48
$totalImages = $imageHandler->getCount();
49
//count "total Friendship"
50
$totalFriendship = $friendshipHandler->getCount();
51
//count "total Visitors"
52
$totalVisitors = $visitorsHandler->getCount();
53
//count "total Video"
54
$totalVideo = $videoHandler->getCount();
55
//count "total Friendrequest"
56
$totalFriendrequest = $friendrequestHandler->getCount();
57
//count "total Groups"
58
$totalGroups = $groupsHandler->getCount();
59
//count "total Relgroupuser"
60
$totalRelgroupuser = $relgroupuserHandler->getCount();
61
//count "total Notes"
62
$totalNotes = $notesHandler->getCount();
63
//count "total Configs"
64
$totalConfigs = $configsHandler->getCount();
65
//count "total Suspensions"
66
$totalSuspensions = $suspensionsHandler->getCount();
67
//count "total Audio"
68
$totalAudio = $audioHandler->getCount();
69
//count "total Privacy"
70
$totalPrivacy = $privacyHandler->getCount();
71
// InfoBox Statistics
72
$adminObject->addInfoBox(AM_SUICO_STATISTICS);
73
// InfoBox images
74
$adminObject->addInfoBoxLine(sprintf(AM_SUICO_THEREARE_IMAGES, $totalImages));
75
// InfoBox friendship
76
$adminObject->addInfoBoxLine(sprintf(AM_SUICO_THEREARE_FRIENDS, $totalFriendship));
77
// InfoBox friendrequest
78
$adminObject->addInfoBoxLine(
79
    sprintf(AM_SUICO_THEREARE_FRIENDREQUEST, $totalFriendrequest)
80
);
81
// InfoBox visitors
82
$adminObject->addInfoBoxLine(sprintf(AM_SUICO_THEREARE_VISITORS, $totalVisitors));
83
// InfoBox video
84
$adminObject->addInfoBoxLine(sprintf(AM_SUICO_THEREARE_VIDEO, $totalVideo));
85
// InfoBox friendrequest
86
$adminObject->addInfoBoxLine(sprintf(AM_SUICO_THEREARE_FRIENDREQUEST, $totalFriendrequest));
87
// InfoBox groups
88
$adminObject->addInfoBoxLine(sprintf(AM_SUICO_THEREARE_GROUPS, $totalGroups));
89
// InfoBox relgroupuser
90
$adminObject->addInfoBoxLine(sprintf(AM_SUICO_THEREARE_MEMBERS, $totalRelgroupuser));
91
// InfoBox notes
92
$adminObject->addInfoBoxLine(sprintf(AM_SUICO_THEREARE_NOTES, $totalNotes));
93
// InfoBox configs
94
$adminObject->addInfoBoxLine(sprintf(AM_SUICO_THEREARE_CONFIGS, $totalConfigs));
95
// InfoBox suspensions
96
$adminObject->addInfoBoxLine(sprintf(AM_SUICO_THEREARE_SUSPENSIONS, $totalSuspensions));
97
// InfoBox audio
98
$adminObject->addInfoBoxLine(sprintf(AM_SUICO_THEREARE_AUDIO, $totalAudio));
99
// InfoBox privacy
100
$adminObject->addInfoBoxLine(sprintf(AM_SUICO_THEREARE_PRIVACY, $totalPrivacy));
101
// Render Index
102
$adminObject->displayNavigation(basename(__FILE__));
103
//check for latest release
104
//$newRelease = $utility->checkVerModule($helper);
105
//if (!empty($newRelease)) {
106
//    $adminObject->addItemButton($newRelease[0], $newRelease[1], 'download', 'style="color : Red"');
107
//}
108
//------------- Test Data ----------------------------
109
if ($helper->getConfig('displaySampleButton')) {
110
    $yamlFile            = dirname(__DIR__) . '/config/admin.yml';
111
    $config              = loadAdminConfig($yamlFile);
112
    $displaySampleButton = $config['displaySampleButton'];
113
    if (1 === $displaySampleButton) {
114
        xoops_loadLanguage('admin/modulesadmin', 'system');
115
        require_once dirname(__DIR__) . '/testdata/index.php';
116
        $adminObject->addItemButton(
117
            constant('CO_' . $moduleDirNameUpper . '_' . 'ADD_SAMPLEDATA'),
118
            '__DIR__ . /../../testdata/index.php?op=load',
119
            'add'
120
        );
121
        $adminObject->addItemButton(
122
            constant('CO_' . $moduleDirNameUpper . '_' . 'SAVE_SAMPLEDATA'),
123
            '__DIR__ . /../../testdata/index.php?op=save',
124
            'add'
125
        );
126
        //    $adminObject->addItemButton(constant('CO_' . $moduleDirNameUpper . '_' . 'EXPORT_SCHEMA'), '__DIR__ . /../../testdata/index.php?op=exportschema', 'add');
127
        $adminObject->addItemButton(
128
            constant('CO_' . $moduleDirNameUpper . '_' . 'HIDE_SAMPLEDATA_BUTTONS'),
129
            '?op=hide_buttons',
130
            'delete'
131
        );
132
    } else {
133
        $adminObject->addItemButton(
134
            constant('CO_' . $moduleDirNameUpper . '_' . 'SHOW_SAMPLEDATA_BUTTONS'),
135
            '?op=show_buttons',
136
            'add'
137
        );
138
        $displaySampleButton = $config['displaySampleButton'];
139
    }
140
    $adminObject->displayButton('left', '');
141
}
142
//------------- End Test Data ----------------------------
143
$adminObject->displayIndex();
144
/**
145
 * @param $yamlFile
146
 * @return array|bool
147
 */
148
function loadAdminConfig($yamlFile)
149
{
150
    return Yaml::readWrapped($yamlFile); // work with phpmyadmin YAML dumps
151
}
152
153
/**
154
 * @param $yamlFile
155
 */
156
function hideButtons($yamlFile)
157
{
158
    $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...
159
    Yaml::save($app, $yamlFile);
160
    redirect_header('index.php', 0, '');
161
}
162
163
/**
164
 * @param $yamlFile
165
 */
166
function showButtons($yamlFile)
167
{
168
    $app                        = [];
169
    $app['displaySampleButton'] = 1;
170
    Yaml::save($app, $yamlFile);
171
    redirect_header('index.php', 0, '');
172
}
173
174
$op = Request::getString('op', 0, 'GET');
175
switch ($op) {
176
    case 'hide_buttons':
177
        hideButtons($yamlFile);
178
        break;
179
    case 'show_buttons':
180
        showButtons($yamlFile);
181
        break;
182
}
183
echo $utility::getServerStats();
184
require __DIR__ . '/admin_footer.php';
185