loadAdminConfig()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 1
b 0
f 0
1
<?php
2
3
use Xmf\Module\Admin;
4
use XoopsModules\Wflinks\{Common,
5
    Helper,
6
    Utility
7
};
8
9
/** @var Admin $adminObject */
10
/** @var Helper $helper */
11
/** @var Utility $utility */
12
13
require_once __DIR__ . '/admin_header.php';
14
// Display Admin header
15
xoops_cp_header();
16
17
$adminObject = Admin::getInstance();
18
19
global $xoopsDB;
20
21
$start     = \Xmf\Request::getInt('start', 0);
22
$start1    = \Xmf\Request::getInt('start1', 0);
23
$start2    = \Xmf\Request::getInt('start2', 0);
24
$start3    = \Xmf\Request::getInt('start3', 0);
25
$start4    = \Xmf\Request::getInt('start4', 0);
26
$totalcats = Utility::getTotalCategory();
27
28
$result = $xoopsDB->query('SELECT COUNT(*) FROM ' . $xoopsDB->prefix('wflinks_broken'));
29
list($totalbrokenlinks) = $xoopsDB->fetchRow($result);
30
$result2 = $xoopsDB->query('SELECT COUNT(*) FROM ' . $xoopsDB->prefix('wflinks_mod'));
31
list($totalmodrequests) = $xoopsDB->fetchRow($result2);
32
$result3 = $xoopsDB->query('SELECT COUNT(*) FROM ' . $xoopsDB->prefix('wflinks_links') . ' WHERE published = 0');
33
list($totalnewlinks) = $xoopsDB->fetchRow($result3);
34
$result4 = $xoopsDB->query('SELECT COUNT(*) FROM ' . $xoopsDB->prefix('wflinks_links') . ' WHERE published > 0');
35
list($totallinks) = $xoopsDB->fetchRow($result4);
36
37
//$xxx='<a href="brokenvideo.php">' . _AM_XTUBE_SBROKENSUBMIT . '</a><b>';
38
39
$adminObject->addInfoBox(_AM_WFL_MINDEX_LINKSUMMARY);
40
if ($totalcats > 0) {
41
    $adminObject->addInfoBoxLine(sprintf('<infolabel>' . '<a href="category.php">' . _AM_WFL_SCATEGORY . '</a><b>' . '</infolabel>', $totalcats), '', 'Green');
42
} else {
43
    $adminObject->addInfoBoxLine(sprintf('<infolabel>' . _AM_WFL_SCATEGORY . '</infolabel>', $totalcats), '', 'Green');
44
}
45
46
if ($totallinks > 0) {
47
    $adminObject->addInfoBoxLine(sprintf('<infolabel>' . '<a href="main.php">' . _AM_WFL_SFILES . '</a><b>' . '</infolabel>', $totallinks), '', 'Green');
48
} else {
49
    $adminObject->addInfoBoxLine(sprintf('<infolabel>' . _AM_WFL_SFILES . '</infolabel>', $totallinks), '', 'Green');
50
}
51
52
if ($totalnewlinks > 0) {
53
    $adminObject->addInfoBoxLine(sprintf('<infolabel>' . '<a href="newlinks.php">' . _AM_WFL_SNEWFILESVAL . '</a><b>' . '</infolabel>', $totalnewlinks), '', 'Red');
54
} else {
55
    $adminObject->addInfoBoxLine(sprintf('<infolabel>' . _AM_WFL_SNEWFILESVAL . '</infolabel>', $totalnewlinks), '', 'Red');
56
}
57
if ($totalmodrequests > 0) {
58
    $adminObject->addInfoBoxLine(sprintf('<infolabel>' . '<a href="modifications.php">' . _AM_WFL_SMODREQUEST . '</a><b>' . '</infolabel>', $totalmodrequests), '', 'Red');
59
} else {
60
    $adminObject->addInfoBoxLine(sprintf('<infolabel>' . _AM_WFL_SMODREQUEST . '</infolabel>', $totalmodrequests), '', 'Red');
61
}
62
63
if ($totalbrokenlinks > 0) {
64
    $adminObject->addInfoBoxLine(sprintf('<infolabel>' . '<a href="brokenlink.php">' . _AM_WFL_SBROKENSUBMIT . '</a><b>' . '</infolabel><infotext>', $totalbrokenlinks . '</infotext>'), '', 'Red');
65
} else {
66
    $adminObject->addInfoBoxLine(sprintf('<infolabel>' . _AM_WFL_SBROKENSUBMIT . '</infolabel><infotext>', $totalbrokenlinks . '</infotext>'), '', 'Red');
67
}
68
69
//check or upload folders
70
$configurator = new Common\Configurator();
71
foreach (array_keys($configurator->uploadFolders) as $i) {
72
    $utility::createFolder($configurator->uploadFolders[$i]);
73
    $adminObject->addConfigBoxLine($configurator->uploadFolders[$i], 'folder');
74
}
75
76
$adminObject->displayNavigation(basename(__FILE__));
77
//------------- Test Data ----------------------------
78
79
if ($helper->getConfig('displaySampleButton')) {
80
    $yamlFile            = dirname(__DIR__) . '/config/admin.yml';
81
    $config              = loadAdminConfig($yamlFile);
82
    $displaySampleButton = $config['displaySampleButton'];
83
84
    if (1 == $displaySampleButton) {
85
        xoops_loadLanguage('admin/modulesadmin', 'system');
86
        require_once dirname(__DIR__) . '/testdata/index.php';
87
        $adminObject->addItemButton(constant('CO_' . $moduleDirNameUpper . '_' . 'ADD_SAMPLEDATA'), '__DIR__ . /../../testdata/index.php?op=load', 'add');
88
        $adminObject->addItemButton(constant('CO_' . $moduleDirNameUpper . '_' . 'SAVE_SAMPLEDATA'), '__DIR__ . /../../testdata/index.php?op=save', 'add');
89
        //    $adminObject->addItemButton(constant('CO_' . $moduleDirNameUpper . '_' . 'EXPORT_SCHEMA'), '__DIR__ . /../../testdata/index.php?op=exportschema', 'add');
90
        $adminObject->addItemButton(constant('CO_' . $moduleDirNameUpper . '_' . 'HIDE_SAMPLEDATA_BUTTONS'), '?op=hide_buttons', 'delete');
91
    } else {
92
        $adminObject->addItemButton(constant('CO_' . $moduleDirNameUpper . '_' . 'SHOW_SAMPLEDATA_BUTTONS'), '?op=show_buttons', 'add');
93
        $displaySampleButton = $config['displaySampleButton'];
94
    }
95
    $adminObject->displayButton('left', '');
96
}
97
98
//------------- End Test Data ----------------------------
99
100
$adminObject->displayIndex();
101
102
/**
103
 * @param $yamlFile
104
 * @return array|bool
105
 */
106
function loadAdminConfig($yamlFile)
107
{
108
    $config = \Xmf\Yaml::readWrapped($yamlFile); // work with phpmyadmin YAML dumps
109
    return $config;
110
}
111
112
/**
113
 * @param $yamlFile
114
 */
115
function hideButtons($yamlFile)
116
{
117
    $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...
118
    \Xmf\Yaml::save($app, $yamlFile);
119
    redirect_header('index.php', 0, '');
120
}
121
122
/**
123
 * @param $yamlFile
124
 */
125
function showButtons($yamlFile)
126
{
127
    $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...
128
    \Xmf\Yaml::save($app, $yamlFile);
129
    redirect_header('index.php', 0, '');
130
}
131
132
$op = \Xmf\Request::getString('op', 0, 'GET');
133
134
switch ($op) {
135
    case 'hide_buttons':
136
        hideButtons($yamlFile);
137
        break;
138
    case 'show_buttons':
139
        showButtons($yamlFile);
140
        break;
141
}
142
143
echo $utility::getServerStats();
144
145
require __DIR__ . '/admin_footer.php';
146