18
18
19
19
use Xmf \Module \Admin ;
20
20
use Xmf \Request ;
21
+ use XoopsModules \Publisher \{
22
+ Common \Configurator ,
23
+ Helper
24
+ };
21
25
22
26
require __DIR__ . '/admin_header.php ' ;
27
+ include_once $ GLOBALS ['xoops ' ]->path ('class/xoopsblock.php ' );
23
28
24
29
$ moduleDirName = basename (dirname (__DIR__ ));
25
30
$ moduleDirNameUpper = mb_strtoupper ($ moduleDirName ); //$capsDirName
@@ -66,6 +71,9 @@ function listBlocks()
66
71
xoops_loadLanguage ('admin/blocksadmin ' , 'system ' );
67
72
xoops_loadLanguage ('admin/groups ' , 'system ' );
68
73
74
+ $ configurator = new Configurator ();
75
+ $ icons = $ configurator ->icons ;
76
+
69
77
/** @var \XoopsModuleHandler $moduleHandler */
70
78
$ moduleHandler = xoops_getHandler ('module ' );
71
79
/** @var \XoopsMemberHandler $memberHandler */
@@ -81,8 +89,7 @@ function listBlocks()
81
89
ksort ($ moduleList );
82
90
echo "
83
91
<h4 style='text-align:left;'> " . constant ('CO_ ' . $ moduleDirNameUpper . '_ ' . 'BADMIN ' ) . '</h4> ' ;
84
- // $moduleHandler = xoops_getHandler('module');
85
- echo "<form action=' " . \Xmf \Request::getString ('SCRIPT_NAME ' , '' , 'SERVER ' ) . "' name='blockadmin' method='post'> " ;
92
+ echo "<form action=' " . Request::getString ('SCRIPT_NAME ' , '' , 'SERVER ' ) . "' name='blockadmin' method='post'> " ;
86
93
echo $ GLOBALS ['xoopsSecurity ' ]->getTokenHTML ();
87
94
echo "<table width='100%' class='outer' cellpadding='4' cellspacing='1'>
88
95
<tr valign='middle'><th align='center'> "
@@ -111,10 +118,10 @@ function listBlocks()
111
118
. constant ('CO_ ' . $ moduleDirNameUpper . '_ ' . 'ACTION ' )
112
119
. '</th></tr>
113
120
' ;
114
- $ blockArray = \XoopsBlock::getByModule ($ xoopsModule ->mid ());
121
+ $ blockArray = \XoopsBlock::getByModule ($ xoopsModule ->mid ());
115
122
$ blockCount = count ($ blockArray );
116
- $ class = 'even ' ;
117
- $ cachetimes = [
123
+ $ class = 'even ' ;
124
+ $ cachetimes = [
118
125
'0 ' => _NOCACHE ,
119
126
'30 ' => sprintf (_SECONDS , 30 ),
120
127
'60 ' => _MINUTE ,
@@ -129,9 +136,9 @@ function listBlocks()
129
136
];
130
137
foreach ($ blockArray as $ i ) {
131
138
$ groupsPerms = $ grouppermHandler ->getGroupIds ('block_read ' , $ i ->getVar ('bid ' ));
132
- $ sql = 'SELECT module_id FROM ' . $ db ->prefix ('block_module_link ' ) . ' WHERE block_id= ' . $ i ->getVar ('bid ' );
133
- $ result = $ db ->query ($ sql );
134
- $ modules = [];
139
+ $ sql = 'SELECT module_id FROM ' . $ db ->prefix ('block_module_link ' ) . ' WHERE block_id= ' . $ i ->getVar ('bid ' );
140
+ $ result = $ db ->query ($ sql );
141
+ $ modules = [];
135
142
while (false !== ($ row = $ db ->fetchArray ($ result ))) {
136
143
$ modules [] = (int )$ row ['module_id ' ];
137
144
}
@@ -257,12 +264,10 @@ function listBlocks()
257
264
258
265
// Actions
259
266
260
- echo "<td class=' $ class' align='center'><a href='blocksadmin.php?op=edit&bid= " . $ i ->getVar ('bid ' ) . "'><img src= " . $ pathIcon16 . '/edit.png ' . " alt=' " . _EDIT . "' title=' " . _EDIT . "'>
261
- </a> <a href='blocksadmin.php?op=clone&bid= " . $ i ->getVar ('bid ' ) . "'><img src= " . $ pathIcon16 . '/editcopy.png ' . " alt=' " . _CLONE . "' title=' " . _CLONE . "'>
267
+ echo "<td class=' $ class' align='center'><a href='blocksadmin.php?op=edit&bid= " . $ i ->getVar ('bid ' ) . "'> " . $ icons ->edit . "</a> <a href='blocksadmin.php?op=clone&bid= " . $ i ->getVar ('bid ' ) . "'><img src= " . $ pathIcon16 . '/editcopy.png ' . " alt=' " . _CLONE . "' title=' " . _CLONE . "'>
262
268
</a> " ;
263
- if ('S ' !== $ i ->getVar ('block_type ' ) && 'M ' !== $ i ->getVar ('block_type ' )) {
264
- echo " <a href=' " . XOOPS_URL . '/modules/system/admin.php?fct=blocksadmin&op=delete&bid= ' . $ i ->getVar ('bid ' ) . "'><img src= " . $ pathIcon16 . '/delete.png ' . " alt=' " . _DELETE . "' title=' " . _DELETE . "'>
265
- </a> " ;
269
+ if (!in_array ($ i ->getVar ('block_type ' ), ['S ' , 'M ' ])) {
270
+ echo " <a href=' " . XOOPS_URL . '/modules/system/admin.php?fct=blocksadmin&op=delete&bid= ' . $ i ->getVar ('bid ' ) . "'> " . $ icons ->delete . '</a> ' ;
266
271
}
267
272
echo "
268
273
<input type='hidden' name='oldtitle[ " . $ i ->getVar ('bid ' ) . "]' value=' " . $ i ->getVar ('title ' ) . "'>
@@ -313,8 +318,8 @@ function cloneBlock($bid)
313
318
while (false !== ($ row = $ db ->fetchArray ($ result ))) {
314
319
$ modules [] = (int )$ row ['module_id ' ];
315
320
}
316
- $ isCustom = ( ' C ' === $ myblock ->getVar ('block_type ' ) || ' E ' === $ myblock -> getVar ( ' block_type ' ));
317
- $ block = [
321
+ $ isCustom = ( in_array ( $ myblock ->getVar ('block_type ' ), [ ' C ' , ' E ' ] ));
322
+ $ block = [
318
323
'title ' => $ myblock ->getVar ('title ' ) . ' Clone ' ,
319
324
'form_title ' => constant ('CO_ ' . $ moduleDirNameUpper . '_ ' . 'BLOCKS_CLONEBLOCK ' ),
320
325
'name ' => $ myblock ->getVar ('name ' ),
@@ -375,7 +380,7 @@ function isBlockCloned($bid, $bside, $bweight, $bvisible, $bcachetime, $bmodule,
375
380
$ clone ->setVar ('options ' , $ options );
376
381
}
377
382
$ clone ->setVar ('bid ' , 0 );
378
- if (' C ' === $ block ->getVar ('block_type ' ) || ' E ' === $ block -> getVar ( ' block_type ' )) {
383
+ if (in_array ( $ block ->getVar ('block_type ' ), [ ' C ' , ' E ' ] )) {
379
384
$ clone ->setVar ('block_type ' , 'E ' );
380
385
} else {
381
386
$ clone ->setVar ('block_type ' , 'D ' );
@@ -404,9 +409,8 @@ function isBlockCloned($bid, $bside, $bweight, $bvisible, $bcachetime, $bmodule,
404
409
$ db ->query ($ sql );
405
410
}
406
411
$ groups = &$ GLOBALS ['xoopsUser ' ]->getGroups ();
407
- $ count = count ($ groups );
408
- for ($ i = 0 ; $ i < $ count ; ++$ i ) {
409
- $ sql = 'INSERT INTO ' . $ db ->prefix ('group_permission ' ) . ' (gperm_groupid, gperm_itemid, gperm_modid, gperm_name) VALUES ( ' . $ groups [$ i ] . ', ' . $ newid . ", 1, 'block_read') " ;
412
+ foreach ($ groups as $ iValue ) {
413
+ $ sql = 'INSERT INTO ' . $ db ->prefix ('group_permission ' ) . ' (gperm_groupid, gperm_itemid, gperm_modid, gperm_name) VALUES ( ' . $ iValue . ', ' . $ newid . ", 1, 'block_read') " ;
410
414
$ db ->query ($ sql );
411
415
}
412
416
redirect_header ('blocksadmin.php?op=listar ' , 1 , _AM_DBUPDATED );
@@ -419,8 +423,9 @@ function isBlockCloned($bid, $bside, $bweight, $bvisible, $bcachetime, $bmodule,
419
423
* @param bool $visible
420
424
* @param string $side
421
425
* @param int $bcachetime
426
+ * @param null $bmodule
422
427
*/
423
- function setOrder ($ bid , $ title , $ weight , $ visible , $ side , $ bcachetime )
428
+ function setOrder ($ bid , $ title , $ weight , $ visible , $ side , $ bcachetime, $ bmodule = null )
424
429
{
425
430
$ myblock = new \XoopsBlock ($ bid );
426
431
$ myblock ->setVar ('title ' , $ title );
@@ -456,8 +461,8 @@ function editBlock($bid)
456
461
while (false !== ($ row = $ db ->fetchArray ($ result ))) {
457
462
$ modules [] = (int )$ row ['module_id ' ];
458
463
}
459
- $ isCustom = ( ' C ' === $ myblock ->getVar ('block_type ' ) || ' E ' === $ myblock -> getVar ( ' block_type ' ));
460
- $ block = [
464
+ $ isCustom = ( in_array ( $ myblock ->getVar ('block_type ' ), [ ' C ' , ' E ' ] ));
465
+ $ block = [
461
466
'title ' => $ myblock ->getVar ('title ' ),
462
467
'form_title ' => constant ('CO_ ' . $ moduleDirNameUpper . '_ ' . 'BLOCKS_EDITBLOCK ' ),
463
468
// 'name' => $myblock->getVar('name'),
@@ -504,14 +509,16 @@ function updateBlock($bid, $btitle, $bside, $bweight, $bvisible, $bcachetime, $b
504
509
$ myblock ->setVar ('visible ' , $ bvisible );
505
510
$ myblock ->setVar ('side ' , $ bside );
506
511
$ myblock ->setVar ('bcachetime ' , $ bcachetime );
512
+ $ helper = Helper::getInstance ();
513
+ $ helper ->loadLanguage ('common ' );
507
514
//update block options
508
515
if (isset ($ options )) {
509
516
$ optionsCount = count ($ options );
510
517
if ($ optionsCount > 0 ) {
511
518
//Convert array values to comma-separated
512
- for ($ i = 0 ; $ i < $ optionsCount ; ++ $ i ) {
513
- if (is_array ($ options [ $ i ] )) {
514
- $ options [$ i ] = implode (', ' , $ options [ $ i ] );
519
+ foreach ($ options as $ i => $ iValue ) {
520
+ if (is_array ($ iValue )) {
521
+ $ options [$ i ] = implode (', ' , $ iValue );
515
522
}
516
523
}
517
524
$ options = implode ('| ' , $ options );
@@ -562,7 +569,7 @@ function updateBlock($bid, $btitle, $bside, $bweight, $bvisible, $bcachetime, $b
562
569
if ($ oldtitle [$ i ] !== $ title [$ i ] || $ oldweight [$ i ] !== $ weight [$ i ] || $ oldvisible [$ i ] !== $ visible [$ i ]
563
570
|| $ oldside [$ i ] !== $ side [$ i ]
564
571
|| $ oldbcachetime [$ i ] !== $ bcachetime [$ i ]) {
565
- setOrder ($ bid [$ i ], $ title [$ i ], $ weight [$ i ], $ visible [$ i ], $ side [$ i ], $ bcachetime [$ i ], $ bmodule [$ i ]= null );
572
+ setOrder ($ bid [$ i ], $ title [$ i ], $ weight [$ i ], $ visible [$ i ], $ side [$ i ], $ bcachetime [$ i ], $ bmodule [$ i ]);
566
573
}
567
574
if (!empty ($ bmodule [$ i ]) && count ($ bmodule [$ i ]) > 0 ) {
568
575
$ sql = sprintf ('DELETE FROM `%s` WHERE block_id = %u ' , $ GLOBALS ['xoopsDB ' ]->prefix ('block_module_link ' ), $ bid [$ i ]);
0 commit comments