1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace XoopsModules\Modulebuilder\Files\Admin; |
4
|
|
|
|
5
|
|
|
use XoopsModules\Modulebuilder; |
6
|
|
|
use XoopsModules\Modulebuilder\Files; |
7
|
|
|
|
8
|
|
|
/* |
9
|
|
|
You may not change or alter any portion of this comment or credits |
10
|
|
|
of supporting developers from this source code or any supporting source code |
11
|
|
|
which is considered copyrighted (c) material of the original comment or credit authors. |
12
|
|
|
|
13
|
|
|
This program is distributed in the hope that it will be useful, |
14
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
15
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
16
|
|
|
*/ |
17
|
|
|
/** |
18
|
|
|
* modulebuilder module. |
19
|
|
|
* |
20
|
|
|
* @copyright XOOPS Project (https://xoops.org) |
21
|
|
|
* @license GNU GPL 2 (https://www.gnu.org/licenses/old-licenses/gpl-2.0.html) |
22
|
|
|
* |
23
|
|
|
* @since 2.5.0 |
24
|
|
|
* |
25
|
|
|
* @author Txmod Xoops https://xoops.org |
26
|
|
|
* Goffy https://myxoops.org |
27
|
|
|
* |
28
|
|
|
*/ |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Class AdminMenu. |
32
|
|
|
*/ |
33
|
|
|
class AdminMenu extends Files\CreateFile |
34
|
|
|
{ |
35
|
|
|
/** |
36
|
|
|
* @var mixed |
37
|
|
|
*/ |
38
|
|
|
private $xc = null; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @public function constructor |
42
|
|
|
* @param null |
43
|
|
|
*/ |
44
|
|
|
public function __construct() |
45
|
|
|
{ |
46
|
|
|
parent::__construct(); |
47
|
|
|
$this->xc = Modulebuilder\Files\CreateXoopsCode::getInstance(); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @static function getInstance |
52
|
|
|
* @param null |
53
|
|
|
* @return AdminMenu |
54
|
|
|
*/ |
55
|
|
|
public static function getInstance() |
56
|
|
|
{ |
57
|
|
|
static $instance = false; |
58
|
|
|
if (!$instance) { |
59
|
|
|
$instance = new self(); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
return $instance; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @public function write |
67
|
|
|
* @param string $module |
68
|
|
|
* @param string $filename |
69
|
|
|
*/ |
70
|
|
|
public function write($module, $filename) |
71
|
|
|
{ |
72
|
|
|
$this->setModule($module); |
73
|
|
|
$this->setFileName($filename); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @private function getAdminMenuArray |
78
|
|
|
* @param array $param |
79
|
|
|
* @param bool $adminObject |
80
|
|
|
* @return string |
81
|
|
|
*/ |
82
|
|
|
private function getAdminMenuArray($param = [], $adminObject = false) |
83
|
|
|
{ |
84
|
|
|
$ret = ''; |
85
|
|
|
if ($adminObject) { |
86
|
|
|
$ret .= $this->getSimpleString("\$adminmenu[] = ["); |
87
|
|
|
foreach ($param as $key => $value) { |
88
|
|
|
$ret .= $this->getSimpleString("\t'{$key}' => {$value},"); |
89
|
|
|
} |
90
|
|
|
$ret .= $this->getSimpleString("];"); |
91
|
|
|
} else { |
92
|
|
|
foreach ($param as $key => $value) { |
93
|
|
|
$ret .= $this->xc->getXcEqualsOperator((string)$key, (string)$value); |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
return $ret; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @private function getAdminMenuHeader |
102
|
|
|
* @param null |
103
|
|
|
* @return string |
104
|
|
|
*/ |
105
|
|
|
private function getAdminMenuHeader() |
106
|
|
|
{ |
107
|
|
|
$ret = $this->getSimpleString(''); |
108
|
|
|
$mod = [ |
109
|
|
|
'$dirname ' => '\basename(\dirname(__DIR__))', |
110
|
|
|
'$moduleHandler' => "\xoops_getHandler('module')", |
111
|
|
|
'$xoopsModule ' => 'XoopsModule::getByDirname($dirname)', |
112
|
|
|
'$moduleInfo ' => "\$moduleHandler->get(\$xoopsModule->getVar('mid'))", |
113
|
|
|
'$sysPathIcon32' => "\$moduleInfo->getInfo('sysicons32')", |
114
|
|
|
]; |
115
|
|
|
$ret .= $this->getAdminMenuArray($mod); |
116
|
|
|
$ret .= $this->getSimpleString(''); |
117
|
|
|
|
118
|
|
|
return $ret; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* @private function getAdminMenuDashboard |
123
|
|
|
* @param string $language |
124
|
|
|
* @param int $menu |
125
|
|
|
* |
126
|
|
|
* @return string |
127
|
|
|
*/ |
128
|
|
|
private function getAdminMenuDashboard($language, $menu) |
129
|
|
|
{ |
130
|
|
|
$param = ['title' => "{$language}{$menu}", 'link' => "'admin/index.php'", 'icon' => "\$sysPathIcon32.'/dashboard.png'"]; |
131
|
|
|
$ret = $this->getAdminMenuArray($param, true); |
132
|
|
|
|
133
|
|
|
return $ret; |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* @private function getAdminMenuList |
138
|
|
|
* @param string $module |
139
|
|
|
* @param string $language |
140
|
|
|
* @param string $langAbout |
141
|
|
|
* @param int $menu |
142
|
|
|
* |
143
|
|
|
* @return string |
144
|
|
|
*/ |
145
|
|
|
private function getAdminMenuList($module, $language, $langAbout, $menu) |
146
|
|
|
{ |
147
|
|
|
$ret = ''; |
148
|
|
|
$tables = $this->getTableTables($module->getVar('mod_id'), 'table_order'); |
149
|
|
|
$tablePermissions = []; |
150
|
|
|
$tableBroken = []; |
151
|
|
|
foreach (\array_keys($tables) as $t) { |
152
|
|
|
$tablePermissions[] = $tables[$t]->getVar('table_permissions'); |
153
|
|
|
$tableBroken[] = $tables[$t]->getVar('table_broken'); |
154
|
|
|
if (1 == $tables[$t]->getVar('table_admin')) { |
155
|
|
|
++$menu; |
156
|
|
|
$param1 = ['title' => "{$language}{$menu}", 'link' => "'admin/{$tables[$t]->getVar('table_name')}.php'", 'icon' => "'assets/icons/32/{$tables[$t]->getVar('table_image')}'"]; |
157
|
|
|
$ret .= $this->getAdminMenuArray($param1, true); |
158
|
|
|
} |
159
|
|
|
} |
160
|
|
|
if (\in_array(1, $tableBroken)) { |
161
|
|
|
++$menu; |
162
|
|
|
$param2 = ['title' => "{$language}{$menu}", 'link' => "'admin/broken.php'", 'icon' => "\$sysPathIcon32.'/brokenlink.png'"]; |
163
|
|
|
$ret .= $this->getAdminMenuArray($param2, true); |
164
|
|
|
} |
165
|
|
|
if (\in_array(1, $tablePermissions)) { |
166
|
|
|
++$menu; |
167
|
|
|
$param2 = ['title' => "{$language}{$menu}", 'link' => "'admin/permissions.php'", 'icon' => "\$sysPathIcon32.'/permissions.png'"]; |
168
|
|
|
$ret .= $this->getAdminMenuArray($param2, true); |
169
|
|
|
} |
170
|
|
|
++$menu; |
171
|
|
|
$param3 = ['title' => "{$language}{$menu}", 'link' => "'admin/clone.php'", 'icon' => "\$sysPathIcon32.'/page_copy.png'"]; |
172
|
|
|
$ret .= $this->getAdminMenuArray($param3, true); |
173
|
|
|
++$menu; |
174
|
|
|
$param3 = ['title' => "{$language}{$menu}", 'link' => "'admin/feedback.php'", 'icon' => "\$sysPathIcon32.'/mail_foward.png'"]; |
175
|
|
|
$ret .= $this->getAdminMenuArray($param3, true); |
176
|
|
|
unset($menu); |
177
|
|
|
$param3 = ['title' => (string)$langAbout, 'link' => "'admin/about.php'", 'icon' => "\$sysPathIcon32.'/about.png'"]; |
178
|
|
|
$ret .= $this->getAdminMenuArray($param3, true); |
179
|
|
|
|
180
|
|
|
return $ret; |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
/** |
184
|
|
|
* @public function render |
185
|
|
|
* @param null |
186
|
|
|
* @return bool|string |
187
|
|
|
*/ |
188
|
|
|
public function render() |
189
|
|
|
{ |
190
|
|
|
$module = $this->getModule(); |
191
|
|
|
$filename = $this->getFileName(); |
192
|
|
|
$moduleDirname = $module->getVar('mod_dirname'); |
193
|
|
|
$language = $this->getLanguage($moduleDirname, 'MI', 'ADMENU'); |
194
|
|
|
$langAbout = $this->getLanguage($moduleDirname, 'MI', 'ABOUT'); |
195
|
|
|
$menu = 1; |
196
|
|
|
$content = $this->getHeaderFilesComments($module); |
197
|
|
|
$content .= $this->getAdminMenuHeader(); |
198
|
|
|
$content .= $this->getAdminMenuDashboard($language, $menu); |
199
|
|
|
$content .= $this->getAdminMenuList($module, $language, $langAbout, $menu); |
200
|
|
|
|
201
|
|
|
$this->create($moduleDirname, 'admin', $filename, $content, \_AM_MODULEBUILDER_FILE_CREATED, \_AM_MODULEBUILDER_FILE_NOTCREATED); |
202
|
|
|
|
203
|
|
|
return $this->renderFile(); |
204
|
|
|
} |
205
|
|
|
} |
206
|
|
|
|