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
|
|
|
* @copyright XOOPS Project (https://xoops.org) |
14
|
|
|
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU Public License |
15
|
|
|
* @package Mymenus |
16
|
|
|
* @since 1.0 |
17
|
|
|
* @author trabis <[email protected]>, bleekk <[email protected]> |
18
|
|
|
*/ |
19
|
|
|
|
20
|
|
|
use Xmf\Request; |
21
|
|
|
|
22
|
|
|
require_once __DIR__ . '/admin_header.php'; |
23
|
|
|
|
24
|
|
|
$currentFile = basename(__FILE__); |
25
|
|
|
|
26
|
|
|
$mymenusTpl = new XoopsTpl(); // will be removed??? |
27
|
|
|
$mymenusAdminPage = 'links.php'; // will be removed??? |
28
|
|
|
|
29
|
|
|
$menusCriteria = new CriteriaCompo(); |
30
|
|
|
$menusCriteria->setSort('id'); |
31
|
|
|
$menusCriteria->setOrder('ASC'); |
32
|
|
|
$menusList = $mymenus->getHandler('menus')->getList($menusCriteria); |
33
|
|
|
if (!$menusList) { |
34
|
|
|
redirect_header('menus.php', 1, _AM_MYMENUS_MSG_NOMENUS); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
$valid_menu_ids = array_keys($menusList); |
38
|
|
|
$mid = Request::getInt('mid', Request::getInt('mid', '', 'POST'), 'GET'); |
39
|
|
|
if ($mid && in_array($mid, $valid_menu_ids)) { |
40
|
|
|
$menuTitle = $menusList[$mid]; |
41
|
|
|
} else { |
42
|
|
|
$keys = array_keys($menusList); |
43
|
|
|
$mid = $valid_menu_ids[0]; //force menu id to first valid menu id in the list |
44
|
|
|
$menuTitle = $menusList[$mid]; // and get it's title |
45
|
|
|
} |
46
|
|
|
$mymenusTpl->assign('mid', $mid); |
47
|
|
|
$mymenusTpl->assign('menuTitle', $menuTitle); |
48
|
|
|
$mymenusTpl->assign('menus_list', $menusList); |
49
|
|
|
|
50
|
|
|
$id = Request::getInt('id', 0); |
51
|
|
|
$pid = Request::getInt('pid', 0); |
52
|
|
|
$start = Request::getInt('start', 0); |
53
|
|
|
$weight = Request::getInt('weight', 0); |
54
|
|
|
$visible = Request::getInt('visible', 0); |
55
|
|
|
|
56
|
|
|
$op = Request::getCmd('op', 'list'); |
57
|
|
|
switch ($op) { |
58
|
|
|
/* |
|
|
|
|
59
|
|
|
case 'form': |
60
|
|
|
xoops_cp_header(); |
61
|
|
|
$adminObject = \Xmf\Module\Admin::getInstance(); |
62
|
|
|
$adminObject->displayNavigation($currentFile); |
63
|
|
|
// |
64
|
|
|
echo mymenusAdminForm(null, $pid, $mid); |
65
|
|
|
// |
66
|
|
|
include __DIR__ . '/admin_footer.php'; |
67
|
|
|
break; |
68
|
|
|
*/ |
69
|
|
|
case 'edit': |
70
|
|
|
echo MymenusLinksUtility::mymenusAdminForm($id, null, $mid); |
71
|
|
|
break; |
72
|
|
|
|
73
|
|
|
case 'add': |
74
|
|
|
MymenusLinksUtility::mymenusAdminAdd($mid); |
75
|
|
|
break; |
76
|
|
|
|
77
|
|
|
case 'save': |
78
|
|
|
MymenusLinksUtility::mymenusAdminSave($id, $mid); |
79
|
|
|
break; |
80
|
|
|
|
81
|
|
|
case 'delete': |
82
|
|
|
$id = Request::getInt('id', null); |
83
|
|
|
$linksObj = $mymenus->getHandler('links')->get($id); |
84
|
|
|
if (Request::getBool('ok', false, 'POST') === true) { |
85
|
|
View Code Duplication |
if (!$GLOBALS['xoopsSecurity']->check()) { |
|
|
|
|
86
|
|
|
redirect_header($currentFile, 3, implode(',', $GLOBALS['xoopsSecurity']->getErrors())); |
87
|
|
|
} |
88
|
|
|
//get sub item |
89
|
|
|
$linksCriteria = new CriteriaCompo(); |
90
|
|
|
$linksCriteria->add(new Criteria('id', $id)); |
91
|
|
|
$linksCriteria->add(new Criteria('pid', $id), 'OR'); |
92
|
|
|
//first delete links level 2 |
93
|
|
|
$query = 'DELETE FROM ' . $GLOBALS['xoopsDB']->prefix('mymenus_links'); |
94
|
|
|
$query .= ' WHERE pid = (SELECT id FROM (SELECT * FROM ' . $GLOBALS['xoopsDB']->prefix('mymenus_links') . " WHERE pid = {$id}) AS sec);"; |
95
|
|
|
$result = $GLOBALS['xoopsDB']->queryF($query); |
96
|
|
|
//delete links level 0 and 1 |
97
|
|
View Code Duplication |
if (!$mymenus->getHandler('links')->deleteAll($linksCriteria)) { |
|
|
|
|
98
|
|
|
xoops_cp_header(); |
99
|
|
|
xoops_error(_AM_MYMENUS_MSG_ERROR, $linksObj->getVar('id')); |
100
|
|
|
xoops_cp_footer(); |
101
|
|
|
exit(); |
102
|
|
|
} |
103
|
|
|
redirect_header($currentFile, 3, _AM_MYMENUS_MSG_DELETE_LINK_SUCCESS); |
104
|
|
View Code Duplication |
} else { |
|
|
|
|
105
|
|
|
xoops_cp_header(); |
106
|
|
|
xoops_confirm(array('ok' => true, 'id' => $id, 'op' => 'delete'), // $_SERVER['REQUEST_URI'], |
|
|
|
|
107
|
|
|
Request::getString('REQUEST_URI', '', 'SERVER'), sprintf(_AM_MYMENUS_LINKS_SUREDEL, $linksObj->getVar('title'))); |
108
|
|
|
require_once __DIR__ . '/admin_footer.php'; |
109
|
|
|
} |
110
|
|
|
break; |
111
|
|
|
|
112
|
|
|
case 'move': |
113
|
|
|
xoops_cp_header(); |
114
|
|
|
$adminObject = \Xmf\Module\Admin::getInstance(); |
115
|
|
|
$adminObject->displayNavigation($currentFile); |
116
|
|
|
// |
117
|
|
|
MymenusLinksUtility::mymenusAdminMove($id, $weight); |
118
|
|
|
echo MymenusLinksUtility::mymenusAdminList($start, $mid); |
119
|
|
|
// |
120
|
|
|
include __DIR__ . '/admin_footer.php'; |
121
|
|
|
break; |
122
|
|
|
|
123
|
|
|
case 'toggle': |
124
|
|
|
MymenusLinksUtility::mymenusAdminToggle($id, $visible); |
125
|
|
|
break; |
126
|
|
|
|
127
|
|
|
case 'order': |
128
|
|
|
$test = array(); |
129
|
|
|
$order = Request::getString('mod', '', 'POST'); |
130
|
|
|
parse_str($order, $test); |
131
|
|
|
$i = 1; |
132
|
|
|
foreach ($test['mod'] as $order => $value) { |
133
|
|
|
$linksObj = $mymenus->getHandler('links')->get($order); |
134
|
|
|
$linksObj->setVar('weight', ++$i); |
135
|
|
|
// Set submenu |
136
|
|
|
if (isset($value)) { |
137
|
|
|
$linksObj->setVar('pid', $value); |
138
|
|
|
} else { |
139
|
|
|
$linksObj->setVar('pid', 0); |
140
|
|
|
} |
141
|
|
|
$mymenus->getHandler('links')->insert($linksObj); |
142
|
|
|
$mymenus->getHandler('links')->updateWeights($linksObj); |
143
|
|
|
} |
144
|
|
|
break; |
145
|
|
|
|
146
|
|
|
case 'list': |
147
|
|
|
default: |
148
|
|
|
xoops_cp_header(); |
149
|
|
|
$adminObject = \Xmf\Module\Admin::getInstance(); |
150
|
|
|
$adminObject->displayNavigation($currentFile); |
151
|
|
|
// Add module stylesheet |
152
|
|
|
$GLOBALS['xoTheme']->addStylesheet(XOOPS_URL . '/modules/system/css/ui/' . xoops_getModuleOption('jquery_theme', 'system') . '/ui.all.css'); |
153
|
|
|
$GLOBALS['xoTheme']->addStylesheet(XOOPS_URL . "/modules/{$mymenus->dirname}/assets/css/admin.css"); |
154
|
|
|
$GLOBALS['xoTheme']->addStylesheet(XOOPS_URL . '/Frameworks/moduleclasses/moduleadmin/css/admin.css'); |
155
|
|
|
// Define scripts |
156
|
|
|
$GLOBALS['xoTheme']->addScript('browse.php?Frameworks/jquery/plugins/jquery.ui.js'); |
157
|
|
|
$GLOBALS['xoTheme']->addScript(XOOPS_URL . "/modules/{$mymenus->dirname}/assets/js/nestedSortable.js"); |
158
|
|
|
//$GLOBALS['xoTheme']->addScript(XOOPS_URL . '/modules/{$mymenus->dirname}/assets/js/switchButton.js'); |
|
|
|
|
159
|
|
|
$GLOBALS['xoTheme']->addScript(XOOPS_URL . "/modules/{$mymenus->dirname}/assets/js/links.js"); |
160
|
|
|
echo MymenusLinksUtility::mymenusAdminList($start, $mid); |
161
|
|
|
// Disable xoops debugger in dialog window |
162
|
|
|
require_once $GLOBALS['xoops']->path('/class/logger/xoopslogger.php'); |
163
|
|
|
$xoopsLogger = XoopsLogger::getInstance(); |
164
|
|
|
$xoopsLogger->activated = true; |
165
|
|
|
error_reporting(-1); |
166
|
|
|
// |
167
|
|
|
include __DIR__ . '/admin_footer.php'; |
168
|
|
|
break; |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
/** |
172
|
|
|
* Class MymenusLinksUtility |
173
|
|
|
*/ |
174
|
|
|
class MymenusLinksUtility |
|
|
|
|
175
|
|
|
{ |
176
|
|
|
|
177
|
|
|
/** |
178
|
|
|
* Display the links in a menu |
179
|
|
|
* |
180
|
|
|
* @param integer $start |
181
|
|
|
* @param integer $mid |
182
|
|
|
* |
183
|
|
|
* @return bool|mixed|string |
184
|
|
|
*/ |
185
|
|
|
public static function mymenusAdminList($start = 0, $mid) |
|
|
|
|
186
|
|
|
{ |
187
|
|
|
$mymenus = MymenusMymenus::getInstance(); |
188
|
|
|
global $mymenusTpl; |
|
|
|
|
189
|
|
|
// |
190
|
|
|
$linksCriteria = new CriteriaCompo(new Criteria('mid', (int)$mid)); |
191
|
|
|
$linksCount = $mymenus->getHandler('links')->getCount($linksCriteria); |
192
|
|
|
$mymenusTpl->assign('count', $linksCount); |
193
|
|
|
// |
194
|
|
|
$linksCriteria->setSort('weight'); |
195
|
|
|
$linksCriteria->setOrder('ASC'); |
196
|
|
|
// |
197
|
|
|
// $menusArray = array(); |
|
|
|
|
198
|
|
|
if (($linksCount > 0) && ($linksCount >= (int)$start)) { |
199
|
|
|
$linksCriteria->setStart((int)$start); |
200
|
|
|
$linksArrays = $mymenus->getHandler('links')->getObjects($linksCriteria, false, false); // as array |
201
|
|
|
// |
202
|
|
|
require_once $GLOBALS['xoops']->path("modules/{$mymenus->dirname}/class/builder.php"); |
203
|
|
|
$menuBuilder = new MymenusBuilder($linksArrays); |
204
|
|
|
$menusArray = $menuBuilder->render(); |
205
|
|
|
$mymenusTpl->assign('menus', $menusArray); // not 'menus', 'links' shoult be better |
206
|
|
|
} |
207
|
|
|
// |
208
|
|
|
$mymenusTpl->assign('addform', MymenusLinksUtility::mymenusAdminForm(null, null, $mid)); |
|
|
|
|
209
|
|
|
|
210
|
|
|
// |
211
|
|
|
return $mymenusTpl->fetch($GLOBALS['xoops']->path("modules/{$mymenus->dirname}/templates/static/mymenus_admin_links.tpl")); |
212
|
|
|
} |
213
|
|
|
|
214
|
|
|
/** |
215
|
|
|
* @param $mid |
216
|
|
|
*/ |
217
|
|
|
public static function mymenusAdminAdd($mid) |
|
|
|
|
218
|
|
|
{ |
219
|
|
|
$mymenus = MymenusMymenus::getInstance(); |
220
|
|
|
// |
221
|
|
View Code Duplication |
if (!$GLOBALS['xoopsSecurity']->check()) { |
|
|
|
|
222
|
|
|
redirect_header($GLOBALS['mymenusAdminPage'], 3, implode('<br>', $GLOBALS['xoopsSecurity']->getErrors())); |
223
|
|
|
} |
224
|
|
|
if (!$mid) { |
225
|
|
|
redirect_header($GLOBALS['mymenusAdminPage'] . '?op=list', 2, _AM_MYMENUS_MSG_MENU_INVALID_ERROR); |
226
|
|
|
} |
227
|
|
|
// |
228
|
|
|
$linksCiteria = new CriteriaCompo(new Criteria('mid', $mid)); |
229
|
|
|
$linksCiteria->setSort('weight'); |
230
|
|
|
$linksCiteria->setOrder('DESC'); |
231
|
|
|
$linksCiteria->setLimit(1); |
232
|
|
|
$linksObjs = $mymenus->getHandler('links')->getObjects($linksCiteria); |
233
|
|
|
$weight = 1; |
234
|
|
|
if (isset($linksObjs[0]) && ($linksObjs[0] instanceof MymenusLinks)) { |
235
|
|
|
$weight = $linksObjs[0]->getVar('weight') + 1; |
236
|
|
|
} |
237
|
|
|
|
238
|
|
|
$newLinksObj = $mymenus->getHandler('links')->create(); |
239
|
|
|
// if (!isset($_POST['hooks'])) { |
|
|
|
|
240
|
|
|
// $_POST['hooks'] = array(); |
|
|
|
|
241
|
|
|
// } |
242
|
|
|
if (!Request::getArray('hooks', null, 'POST')) { |
243
|
|
|
$_POST['hooks'] = array(); |
244
|
|
|
} |
245
|
|
|
// @TODO: clean incoming POST vars |
246
|
|
|
$newLinksObj->setVars($_POST); |
247
|
|
|
$newLinksObj->setVar('weight', $weight); |
248
|
|
|
|
249
|
|
View Code Duplication |
if (!$mymenus->getHandler('links')->insert($newLinksObj)) { |
|
|
|
|
250
|
|
|
$msg = _AM_MYMENUS_MSG_ERROR; |
251
|
|
|
} else { |
252
|
|
|
$mymenus->getHandler('links')->updateWeights($newLinksObj); |
253
|
|
|
$msg = _AM_MYMENUS_MSG_SUCCESS; |
254
|
|
|
} |
255
|
|
|
|
256
|
|
|
redirect_header($GLOBALS['mymenusAdminPage'] . '?op=list&mid=' . $newLinksObj->getVar('mid'), 2, $msg); |
257
|
|
|
} |
258
|
|
|
|
259
|
|
|
/** |
260
|
|
|
* @param integer $id |
261
|
|
|
* @param integer $mid |
262
|
|
|
*/ |
263
|
|
|
public static function mymenusAdminSave($id, $mid) |
|
|
|
|
264
|
|
|
{ |
265
|
|
|
$mymenus = MymenusMymenus::getInstance(); |
266
|
|
|
// |
267
|
|
View Code Duplication |
if (!$GLOBALS['xoopsSecurity']->check()) { |
|
|
|
|
268
|
|
|
redirect_header($GLOBALS['mymenusAdminPage'], 3, implode('<br>', $GLOBALS['xoopsSecurity']->getErrors())); |
269
|
|
|
} |
270
|
|
|
if (!$mid) { |
271
|
|
|
redirect_header($GLOBALS['mymenusAdminPage'] . '?op=list', 2, _AM_MYMENUS_MSG_MENU_INVALID_ERROR); |
272
|
|
|
} |
273
|
|
|
// |
274
|
|
|
$mid = (int)$mid; |
275
|
|
|
$linksObj = $mymenus->getHandler('links')->get((int)$id); |
276
|
|
|
|
277
|
|
|
//if this was moved then parent could be in different menu, if so then set parent to top level |
278
|
|
|
if (Request::getInt('pid', '', 'POST')) { |
279
|
|
|
$parentLinksObj = $mymenus->getHandler('links')->get($linksObj->getVar('pid')); //get the parent object |
280
|
|
|
if (($parentLinksObj instanceof MylinksLinks) |
|
|
|
|
281
|
|
|
&& ($linksObj->getVar('mid') != $parentLinksObj->getVar('mid'))) { |
282
|
|
|
$linksObj->setVar('pid', 0); |
283
|
|
|
} |
284
|
|
|
} |
285
|
|
|
// Disable xoops debugger in dialog window |
286
|
|
|
require_once $GLOBALS['xoops']->path('/class/logger/xoopslogger.php'); |
287
|
|
|
$xoopsLogger = XoopsLogger::getInstance(); |
288
|
|
|
$xoopsLogger->activated = false; |
289
|
|
|
error_reporting(0); |
290
|
|
|
|
291
|
|
|
// @TODO: clean incoming POST vars |
292
|
|
|
$linksObj->setVars($_POST); |
293
|
|
|
|
294
|
|
View Code Duplication |
if (!$mymenus->getHandler('links')->insert($linksObj)) { |
|
|
|
|
295
|
|
|
$msg = _AM_MYMENUS_MSG_ERROR; |
296
|
|
|
} else { |
297
|
|
|
$msg = _AM_MYMENUS_MSG_SUCCESS; |
298
|
|
|
} |
299
|
|
|
|
300
|
|
|
redirect_header($GLOBALS['mymenusAdminPage'] . "?op=list&mid={$mid}", 2, $msg); |
301
|
|
|
} |
302
|
|
|
|
303
|
|
|
/** |
304
|
|
|
* @param null $id |
305
|
|
|
* @param null $pid |
306
|
|
|
* |
307
|
|
|
* @param null $mid |
308
|
|
|
* @return string |
309
|
|
|
*/ |
310
|
|
|
public static function mymenusAdminForm($id = null, $pid = null, $mid = null) |
|
|
|
|
311
|
|
|
{ |
312
|
|
|
$mymenus = MymenusMymenus::getInstance(); |
313
|
|
|
// |
314
|
|
|
// Disable xoops debugger in dialog window |
315
|
|
|
require_once $GLOBALS['xoops']->path('/class/logger/xoopslogger.php'); |
316
|
|
|
$xoopsLogger = XoopsLogger::getInstance(); |
317
|
|
|
$xoopsLogger->activated = false; |
318
|
|
|
error_reporting(0); |
319
|
|
|
|
320
|
|
|
$pathIcon16 = Xmf\Module\Admin::iconUrl('', 16); |
321
|
|
|
|
322
|
|
|
// $registry = MymenusRegistry::getInstance(); |
|
|
|
|
323
|
|
|
// $plugin = MymenusPlugin::getInstance(); |
|
|
|
|
324
|
|
|
|
325
|
|
|
$linksObj = $mymenus->getHandler('links')->get((int)$id); |
326
|
|
|
|
327
|
|
|
if ($linksObj->isNew()) { |
328
|
|
|
$formTitle = _ADD; |
329
|
|
|
if (isset($pid)) { |
330
|
|
|
$linksObj->setVar('pid', (int)$pid); |
331
|
|
|
} |
332
|
|
|
if (isset($mid)) { |
333
|
|
|
$linksObj->setVar('mid', (int)$mid); |
334
|
|
|
} |
335
|
|
|
} else { |
336
|
|
|
$formTitle = _EDIT; |
337
|
|
|
} |
338
|
|
|
$form = new XoopsThemeForm($formTitle, 'admin_form', $GLOBALS['mymenusAdminPage'], 'post', true); |
339
|
|
|
// links: title |
340
|
|
|
$formtitle = new XoopsFormText(_AM_MYMENUS_MENU_TITLE, 'title', 50, 255, $linksObj->getVar('title')); |
341
|
|
|
$form->addElement($formtitle, true); |
342
|
|
|
// links: alt_title |
343
|
|
|
$formalttitle = new XoopsFormText(_AM_MYMENUS_MENU_ALTTITLE, 'alt_title', 50, 255, $linksObj->getVar('alt_title')); |
344
|
|
|
$form->addElement($formalttitle); |
345
|
|
|
// links: mid |
346
|
|
|
$menusCriteria = new CriteriaCompo(); |
347
|
|
|
$menusCriteria->setSort('title'); |
348
|
|
|
$menusCriteria->setOrder('ASC'); |
349
|
|
|
$menusList = $mymenus->getHandler('menus')->getList($menusCriteria); |
350
|
|
|
if (count($menusList) > 1) { |
351
|
|
|
// display menu options (if more than 1 menu available |
352
|
|
|
if (!$linksObj->getVar('mid')) { // initial menu value not set |
353
|
|
|
// $menuValues = array_flip($menusList); |
|
|
|
|
354
|
|
|
$formmid = new XoopsFormSelect(_AM_MYMENUS_MENU_MENU, 'mid', $mid);//array_shift($menuValues)); |
|
|
|
|
355
|
|
|
} else { |
356
|
|
|
$formmid = new XoopsFormSelect(_AM_MYMENUS_MENU_MENU, 'mid', $linksObj->getVar('mid')); |
357
|
|
|
} |
358
|
|
|
$formmid->addOptionArray($menusList); |
359
|
|
|
} else { |
360
|
|
|
$menuKeys = array_keys($menusList); |
361
|
|
|
$menuTitle = array_shift($menusList); |
362
|
|
|
$formmid = new XoopsFormElementTray('Menu'); |
363
|
|
|
$formmid->addElement(new XoopsFormHidden('mid', $menuKeys[0])); |
364
|
|
|
$formmid->addElement(new XoopsFormLabel('', $menuTitle, 'menuTitle')); |
365
|
|
|
} |
366
|
|
|
$form->addElement($formmid); |
367
|
|
|
// links: link |
368
|
|
|
$formlink = new XoopsFormText(_AM_MYMENUS_MENU_LINK, 'link', 50, 255, $linksObj->getVar('link')); |
369
|
|
|
$form->addElement($formlink); |
370
|
|
|
// links: image |
371
|
|
|
$formimage = new XoopsFormText(_AM_MYMENUS_MENU_IMAGE, 'image', 50, 255, $linksObj->getVar('image')); |
372
|
|
|
$form->addElement($formimage); |
373
|
|
|
// |
374
|
|
|
//$form->addElement($formparent); |
|
|
|
|
375
|
|
|
// links: visible |
376
|
|
|
$statontxt = " <img src='{$pathIcon16}/1.png' alt='" . _YES . "'> " . _YES . ' '; |
377
|
|
|
$statofftxt = " <img src='{$pathIcon16}/0.png' alt='" . _NO . "'> " . _NO . ' '; |
378
|
|
|
$formvis = new XoopsFormRadioYN(_AM_MYMENUS_MENU_VISIBLE, 'visible', $linksObj->getVar('visible'), $statontxt, $statofftxt); |
379
|
|
|
$form->addElement($formvis); |
380
|
|
|
// links: target |
381
|
|
|
$formtarget = new XoopsFormSelect(_AM_MYMENUS_MENU_TARGET, 'target', $linksObj->getVar('target')); |
382
|
|
|
$formtarget->addOption('_self', _AM_MYMENUS_MENU_TARG_SELF); |
383
|
|
|
$formtarget->addOption('_blank', _AM_MYMENUS_MENU_TARG_BLANK); |
384
|
|
|
$formtarget->addOption('_parent', _AM_MYMENUS_MENU_TARG_PARENT); |
385
|
|
|
$formtarget->addOption('_top', _AM_MYMENUS_MENU_TARG_TOP); |
386
|
|
|
$form->addElement($formtarget); |
387
|
|
|
// links: groups |
388
|
|
|
$formgroups = new XoopsFormSelectGroup(_AM_MYMENUS_MENU_GROUPS, 'groups', true, $linksObj->getVar('groups'), 5, true); |
389
|
|
|
$formgroups->setDescription(_AM_MYMENUS_MENU_GROUPS_HELP); |
390
|
|
|
$form->addElement($formgroups); |
391
|
|
|
// @TODO: reintroduce hooks |
392
|
|
|
/* |
|
|
|
|
393
|
|
|
//links: hooks |
394
|
|
|
$formhooks = new XoopsFormSelect(_AM_MYMENUS_MENU_ACCESS_FILTER, "hooks", $linksObj->getVar('hooks'), 5, true); |
395
|
|
|
$plugin->triggerEvent('AccessFilter'); |
396
|
|
|
$results = $registry->getEntry('accessFilter'); |
397
|
|
|
if ($results) { |
398
|
|
|
foreach ($results as $result) { |
399
|
|
|
$formhooks->addOption($result['method'], $result['name']); |
400
|
|
|
} |
401
|
|
|
} |
402
|
|
|
$form->addElement($formhooks); |
403
|
|
|
*/ |
404
|
|
|
// links: css |
405
|
|
|
$formcss = new XoopsFormText(_AM_MYMENUS_MENU_CSS, 'css', 50, 255, $linksObj->getVar('css')); |
406
|
|
|
$form->addElement($formcss); |
407
|
|
|
// |
408
|
|
|
$buttonTray = new XoopsFormElementTray('', ''); |
409
|
|
|
$buttonTray->addElement(new XoopsFormButton('', 'submit_button', _SUBMIT, 'submit')); |
410
|
|
|
$button = new XoopsFormButton('', 'reset', _CANCEL, 'button'); |
411
|
|
|
if (isset($id)) { |
412
|
|
|
$button->setExtra("onclick=\"document.location.href='" . $GLOBALS['mymenusAdminPage'] . "?op=list&mid={$mid}'\""); |
413
|
|
|
} else { |
414
|
|
|
$button->setExtra("onclick=\"document.getElementById('addform').style.display = 'none'; return false;\""); |
415
|
|
|
} |
416
|
|
|
$buttonTray->addElement($button); |
417
|
|
|
$form->addElement($buttonTray); |
418
|
|
|
|
419
|
|
|
if (isset($id)) { |
420
|
|
|
$form->addElement(new XoopsFormHidden('op', 'save')); |
421
|
|
|
$form->addElement(new XoopsFormHidden('id', $id)); |
422
|
|
|
} else { |
423
|
|
|
$form->addElement(new XoopsFormHidden('op', 'add')); |
424
|
|
|
} |
425
|
|
|
|
426
|
|
|
return $form->render(); |
427
|
|
|
} |
428
|
|
|
|
429
|
|
|
/** |
430
|
|
|
* |
431
|
|
|
* Update the {@see MymenusLinks} weight (order) |
432
|
|
|
* |
433
|
|
|
* @param integer $id of links object |
434
|
|
|
* @param integer $weight |
435
|
|
|
*/ |
436
|
|
|
public static function mymenusAdminMove($id, $weight) |
437
|
|
|
{ |
438
|
|
|
$mymenus = MymenusMymenus::getInstance(); |
439
|
|
|
// |
440
|
|
|
$linksObj = $mymenus->getHandler('links')->get((int)$id); |
441
|
|
|
$linksObj->setVar('weight', (int)$weight); |
442
|
|
|
$mymenus->getHandler('links')->insert($linksObj); |
443
|
|
|
$mymenus->getHandler('links')->updateWeights($linksObj); |
444
|
|
|
} |
445
|
|
|
|
446
|
|
|
/** |
447
|
|
|
* @param $id |
448
|
|
|
* @param $visible |
449
|
|
|
*/ |
450
|
|
|
public static function mymenusAdminToggle($id, $visible) |
|
|
|
|
451
|
|
|
{ |
452
|
|
|
$mymenus = MymenusMymenus::getInstance(); |
453
|
|
|
// |
454
|
|
|
// Disable xoops debugger in dialog window |
455
|
|
|
require_once $GLOBALS['xoops']->path('/class/logger/xoopslogger.php'); |
456
|
|
|
$xoopsLogger = XoopsLogger::getInstance(); |
457
|
|
|
$xoopsLogger->activated = false; |
458
|
|
|
error_reporting(0); |
459
|
|
|
// |
460
|
|
|
$linksObj = $mymenus->getHandler('links')->get((int)$id); |
461
|
|
|
$visible = (1 === $linksObj->getVar('visible')) ? 0 : 1; |
462
|
|
|
$linksObj->setVar('visible', $visible); |
463
|
|
|
$mymenus->getHandler('links')->insert($linksObj); |
464
|
|
|
echo $linksObj->getVar('visible'); |
465
|
|
|
} |
466
|
|
|
} |
467
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.