Skip to content

Commit

Permalink
Yoda, cosmetics, Unqualified function/constant reference, type hints
Browse files Browse the repository at this point in the history
  • Loading branch information
mambax7 committed Aug 8, 2021
1 parent b90e465 commit b6f523e
Show file tree
Hide file tree
Showing 72 changed files with 586 additions and 339 deletions.
2 changes: 1 addition & 1 deletion admin/about.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

/** @var Admin $adminObject */

require __DIR__ . '/admin_header.php';
require_once __DIR__ . '/admin_header.php';
xoops_cp_header();

$adminObject->displayNavigation(basename(__FILE__));
Expand Down
13 changes: 7 additions & 6 deletions admin/admin_header.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,24 @@
use XoopsModules\Publisher\Helper;
use XoopsModules\Publisher\Common\Configurator;

require dirname(__DIR__) . '/preloads/autoloader.php';
require \dirname(__DIR__) . '/preloads/autoloader.php';

require_once dirname(__DIR__, 3) . '/include/cp_header.php';
require \dirname(__DIR__, 3) . '/include/cp_header.php';
//require_once $GLOBALS['xoops']->path('www/class/xoopsformloader.php');

require_once dirname(__DIR__) . '/include/common.php';
require_once \dirname(__DIR__) . '/include/common.php';

$moduleDirName = basename(dirname(__DIR__));
$moduleDirName = \basename(\dirname(__DIR__));

$helper = Helper::getInstance();
/** @var Admin $adminObject */
$adminObject = Admin::getInstance();

$pathIcon16 = Admin::iconUrl('', 16);
$pathIcon32 = Admin::iconUrl('', 32);
if (is_object($helper->getModule())) {
$pathModIcon32 = $helper->getModule()->getInfo('modicons32');
$pathModIcon32 = XOOPS_URL . '/modules/' . $moduleDirName . '/assets/images/icons/32/';
if (is_object($helper->getModule()) && false !== $helper->getModule()->getInfo('modicons32')) {
$pathModIcon32 = $helper->url($helper->getModule()->getInfo('modicons32'));
}

// Load language files
Expand Down
38 changes: 23 additions & 15 deletions admin/blockform.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,26 @@
* of supporting developers from this source code or any supporting source code
* which is considered copyrighted (c) material of the original comment or credit authors.
*
* PHP version 5
*
* @category Module
* @author XOOPS Development Team
* @copyright XOOPS Project
* @link https://xoops.org
* @license GNU GPL 2 or later (https://www.gnu.org/licenses/gpl-2.0.html)
*/

use Xmf\Module\Admin;
use XoopsModules\Publisher\{
Helper
};

/** @var Admin $adminObject */
/** @var Helper $helper */

require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php';

$moduleDirName = basename(dirname(__DIR__));
$moduleDirNameUpper = mb_strtoupper($moduleDirName); //$capsDirName
$moduleDirName = \basename(\dirname(__DIR__));
$moduleDirNameUpper = \mb_strtoupper($moduleDirName);

$form = new \XoopsThemeForm($block['form_title'], 'blockform', 'blocksadmin.php', 'post', true);
if (isset($block['name'])) {
Expand Down Expand Up @@ -51,7 +59,7 @@
ksort($moduleList);
$moduleSelect->addOptionArray($moduleList);
$form->addElement($moduleSelect);
$form->addElement(new \XoopsFormText(constant('CO_' . $moduleDirNameUpper . '_' . 'TITLE'), 'btitle', 50, 255, $block['title']), false);
$form->addElement(new \XoopsFormText(_AM_SYSTEM_BLOCKS_TITLE, 'btitle', 50, 255, $block['title']), false);
if ($block['is_custom']) {
$textarea = new \XoopsFormDhtmlTextArea(_AM_SYSTEM_BLOCKS_CONTENT, 'bcontent', $block['content'], 15, 70);
$textarea->setDescription('<span style="font-size:x-small;font-weight:bold;">' . _AM_SYSTEM_BLOCKS_USEFULTAGS . '</span><br><span style="font-size:x-small;font-weight:normal;">' . sprintf(_AM_BLOCKTAG1, '{X_SITEURL}', XOOPS_URL . '/') . '</span>');
Expand Down Expand Up @@ -87,17 +95,17 @@
$cacheSelect = new \XoopsFormSelect(_AM_SYSTEM_BLOCKS_BCACHETIME, 'bcachetime', $block['bcachetime']);
$cacheSelect->addOptionArray(
[
'0' => _NOCACHE,
'30' => sprintf(_SECONDS, 30),
'60' => _MINUTE,
'300' => sprintf(_MINUTES, 5),
'1800' => sprintf(_MINUTES, 30),
'3600' => _HOUR,
'18000' => sprintf(_HOURS, 5),
'86400' => _DAY,
'259200' => sprintf(_DAYS, 3),
'604800' => _WEEK,
'2592000' => _MONTH,
0 => _NOCACHE,
30 => sprintf(_SECONDS, 30),
60 => _MINUTE,
300 => sprintf(_MINUTES, 5),
1800 => sprintf(_MINUTES, 30),
3600 => _HOUR,
18000 => sprintf(_HOURS, 5),
86400 => _DAY,
259200 => sprintf(_DAYS, 3),
604800 => _WEEK,
2592000 => _MONTH,
]
);
$form->addElement($cacheSelect);
Expand Down
110 changes: 58 additions & 52 deletions admin/blocksadmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
* of supporting developers from this source code or any supporting source code
* which is considered copyrighted (c) material of the original comment or credit authors.
*
* PHP version 5
*
* @category Module
* @author XOOPS Development Team
Expand All @@ -24,36 +23,35 @@
};

require __DIR__ . '/admin_header.php';
include_once $GLOBALS['xoops']->path('class/xoopsblock.php');
//include_once $GLOBALS['xoops']->path('class/xoopsblock.php');
require_once XOOPS_ROOT_PATH . '/kernel/block.php';

$moduleDirName = basename(dirname(__DIR__));
$moduleDirNameUpper = mb_strtoupper($moduleDirName); //$capsDirName
$moduleDirName = \basename(\dirname(__DIR__));
$moduleDirNameUpper = \mb_strtoupper($moduleDirName);

if (!is_object($xoopsModule) || !is_object($GLOBALS['xoopsUser'])
|| !$GLOBALS['xoopsUser']->isAdmin($xoopsModule->mid())) {
exit(constant('CO_' . $moduleDirNameUpper . '_' . 'ERROR403'));
}
if ($GLOBALS['xoopsUser']->isAdmin($xoopsModule->mid())) {
require_once XOOPS_ROOT_PATH . '/class/xoopsblock.php';
// require_once XOOPS_ROOT_PATH . '/kernel/block.php';
$op = 'list';
if (isset($_POST)) {
foreach ($_POST as $k => $v) {
${$k} = $v;
}
}
/*
if (Request::hasVar('op')) {
if ($_GET['op'] === "edit" || $_GET['op'] === "delete" || $_GET['op'] === "delete_ok" || $_GET['op'] === "clone"
|| $_GET['op'] === "edit"
) {
if (Request::hasVar('op', 'GET')) {
if ('edit' === $_GET['op'] || 'delete' === $_GET['op'] || 'delete_ok' === $_GET['op'] || 'clone' === $_GET['op']
|| 'edit' === $_GET['op']) {
$op = $_GET['op'];
$bid = Request::getInt('bid',0 ,'GET'); //isset($_GET['bid']) ? (int) $_GET['bid'] : 0;
}
$bid = Request::getInt('bid', 0, 'GET');
}
*/

$op = Request::getString('op', $op);
if (in_array($op, ['edit', 'delete', 'delete_ok', 'clone'], true)) {
if (in_array($op, ['edit', 'delete', 'delete_ok', 'clone'])) {
$bid = Request::getInt('bid', 0, 'GET');
}

Expand All @@ -62,11 +60,15 @@ function listBlocks()
global $xoopsModule, $pathIcon16;
// require_once XOOPS_ROOT_PATH . '/class/xoopslists.php';
xoops_load('xoopslist');
require_once XOOPS_ROOT_PATH . '/class/xoopsblock.php';
$moduleDirName = basename(dirname(__DIR__));
$moduleDirNameUpper = mb_strtoupper($moduleDirName); //$capsDirName
//require_once XOOPS_ROOT_PATH . '/kernel/block.php';
$moduleDirName = \basename(\dirname(__DIR__));
$moduleDirNameUpper = \mb_strtoupper($moduleDirName);
/** @var \XoopsMySQLDatabase $db */
$db = \XoopsDatabaseFactory::getDatabaseConnection();

$adminObject = Admin::getInstance();
$adminObject->displayNavigation(basename(__FILE__));

xoops_loadLanguage('admin', 'system');
xoops_loadLanguage('admin/blocksadmin', 'system');
xoops_loadLanguage('admin/groups', 'system');
Expand All @@ -93,7 +95,7 @@ function listBlocks()
echo $GLOBALS['xoopsSecurity']->getTokenHTML();
echo "<table width='100%' class='outer' cellpadding='4' cellspacing='1'>
<tr valign='middle'><th align='center'>"
. constant('CO_' . $moduleDirNameUpper . '_' . 'TITLE')
. _AM_SYSTEM_BLOCKS_TITLE
. "</th><th align='center' nowrap='nowrap'>"
. constant('CO_' . $moduleDirNameUpper . '_' . 'SIDE')
. '<br>'
Expand All @@ -103,9 +105,7 @@ function listBlocks()
. '-'
. _RIGHT
. "</th><th align='center'>"
. constant(
'CO_' . $moduleDirNameUpper . '_' . 'WEIGHT'
)
. constant('CO_' . $moduleDirNameUpper . '_' . 'WEIGHT')
. "</th><th align='center'>"
. constant('CO_' . $moduleDirNameUpper . '_' . 'VISIBLE')
. "</th><th align='center'>"
Expand All @@ -122,17 +122,17 @@ function listBlocks()
$blockCount = count($blockArray);
$class = 'even';
$cachetimes = [
'0' => _NOCACHE,
'30' => sprintf(_SECONDS, 30),
'60' => _MINUTE,
'300' => sprintf(_MINUTES, 5),
'1800' => sprintf(_MINUTES, 30),
'3600' => _HOUR,
'18000' => sprintf(_HOURS, 5),
'86400' => _DAY,
'259200' => sprintf(_DAYS, 3),
'604800' => _WEEK,
'2592000' => _MONTH,
0 => _NOCACHE,
30 => sprintf(_SECONDS, 30),
60 => _MINUTE,
300 => sprintf(_MINUTES, 5),
1800 => sprintf(_MINUTES, 30),
3600 => _HOUR,
18000 => sprintf(_HOURS, 5),
86400 => _DAY,
259200 => sprintf(_DAYS, 3),
604800 => _WEEK,
2592000 => _MONTH,
];
foreach ($blockArray as $i) {
$groupsPerms = $grouppermHandler->getGroupIds('block_read', $i->getVar('bid'));
Expand Down Expand Up @@ -248,13 +248,13 @@ function listBlocks()

echo "<td class='$class' align='center'><select size='5' name='bmodule[" . $i->getVar('bid') . "][]' id='bmodule[" . $i->getVar('bid') . "][]' multiple='multiple'>";
foreach ($moduleList as $k => $v) {
echo "<option value='$k'" . (in_array($k, $modules, true) ? " selected='selected'" : '') . ">$v</option>";
echo "<option value='$k'" . (in_array($k, $modules) ? 'selected' : '') . ">$v</option>";
}
echo '</select></td>';

echo "<td class='$class' align='center'><select size='5' name='groups[" . $i->getVar('bid') . "][]' id='groups[" . $i->getVar('bid') . "][]' multiple='multiple'>";
foreach ($groups as $grp) {
echo "<option value='" . $grp->getVar('groupid') . "' " . (in_array($grp->getVar('groupid'), $groupsPerms, true) ? " selected='selected'" : '') . '>' . $grp->getVar('name') . '</option>';
echo "<option value='" . $grp->getVar('groupid') . "' " . (in_array($grp->getVar('groupid'), $groupsPerms) ? 'selected' : '') . '>' . $grp->getVar('name') . '</option>';
}
echo '</select></td>';

Expand Down Expand Up @@ -295,21 +295,18 @@ function listBlocks()
*/
function cloneBlock($bid)
{
require_once __DIR__ . '/admin_header.php';

xoops_cp_header();

/** @var \Xmf\Module\Admin $adminObject */
$adminObject = Admin::getInstance();
$adminObject->displayNavigation(basename(__FILE__));
$moduleDirName = basename(dirname(__DIR__));
$moduleDirNameUpper = mb_strtoupper($moduleDirName); //$capsDirName
$moduleDirName = \basename(\dirname(__DIR__));
$moduleDirNameUpper = \mb_strtoupper($moduleDirName);

xoops_loadLanguage('admin', 'system');
xoops_loadLanguage('admin/blocksadmin', 'system');
xoops_loadLanguage('admin/groups', 'system');

// mpu_adm_menu();
$myblock = new \XoopsBlock($bid);
$db = \XoopsDatabaseFactory::getDatabaseConnection();
$sql = 'SELECT module_id FROM ' . $db->prefix('block_module_link') . ' WHERE block_id=' . (int)$bid;
Expand Down Expand Up @@ -361,11 +358,13 @@ function isBlockCloned($bid, $bside, $bweight, $bvisible, $bcachetime, $bmodule,
xoops_loadLanguage('admin/blocksadmin', 'system');
xoops_loadLanguage('admin/groups', 'system');

$moduleDirName = \basename(\dirname(__DIR__));
$moduleDirNameUpper = mb_strtoupper($moduleDirName);
$block = new \XoopsBlock($bid);
$clone = $block->xoopsClone();
if (empty($bmodule)) {
xoops_cp_header();
xoops_error(sprintf(_AM_NOTSELNG, _AM_VISIBLEIN));
xoops_error(sprintf(constant('CO_' . $moduleDirNameUpper . '_' . 'NOTSELNG'), constant('CO_' . $moduleDirNameUpper . '_' . 'VISIBLEIN')));
xoops_cp_footer();
exit();
}
Expand Down Expand Up @@ -413,7 +412,7 @@ function isBlockCloned($bid, $bside, $bweight, $bvisible, $bcachetime, $bmodule,
$sql = 'INSERT INTO ' . $db->prefix('group_permission') . ' (gperm_groupid, gperm_itemid, gperm_modid, gperm_name) VALUES (' . $iValue . ', ' . $newid . ", 1, 'block_read')";
$db->query($sql);
}
redirect_header('blocksadmin.php?op=listar', 1, _AM_DBUPDATED);
redirect_header('blocksadmin.php?op=listar', 1, _AM_SYSTEM_BLOCKS_DBUPDATED);
}

/**
Expand All @@ -433,21 +432,23 @@ function setOrder($bid, $title, $weight, $visible, $side, $bcachetime, $bmodule
$myblock->setVar('visible', $visible);
$myblock->setVar('side', $side);
$myblock->setVar('bcachetime', $bcachetime);
$myblock->store();
// $myblock->store();
/** @var \XoopsBlockHandler $blockHandler */
$blockHandler = xoops_getHandler('block');
return $blockHandler->insert($myblock);
}

/**
* @param int $bid
*/
function editBlock($bid)
{
require_once __DIR__ . '/admin_header.php';
xoops_cp_header();
/** @var \Xmf\Module\Admin $adminObject */
$adminObject = Admin::getInstance();
$adminObject->displayNavigation(basename(__FILE__));
$moduleDirName = basename(dirname(__DIR__));
$moduleDirNameUpper = mb_strtoupper($moduleDirName); //$capsDirName
$moduleDirName = \basename(\dirname(__DIR__));
$moduleDirNameUpper = \mb_strtoupper($moduleDirName);

xoops_loadLanguage('admin', 'system');
xoops_loadLanguage('admin/blocksadmin', 'system');
Expand Down Expand Up @@ -503,18 +504,18 @@ function editBlock($bid)

function updateBlock($bid, $btitle, $bside, $bweight, $bvisible, $bcachetime, $bmodule, $options, $groups)
{
$myblock = new XoopsBlock($bid);
$myblock = new \XoopsBlock($bid);
$myblock->setVar('title', $btitle);
$myblock->setVar('weight', $bweight);
$myblock->setVar('visible', $bvisible);
$myblock->setVar('side', $bside);
$myblock->setVar('bcachetime', $bcachetime);
$myblock->setVar('module', $bmodule);
$myblock->setVar('groups', $groups);
$helper = Helper::getInstance();
$helper->loadLanguage('common');
//update block options
if (isset($options)) {
$optionsCount = count($options);
if ($optionsCount > 0) {
if (is_array($options) && count($options) > 0) {
//Convert array values to comma-separated
foreach ($options as $i => $iValue) {
if (is_array($iValue)) {
Expand All @@ -524,10 +525,15 @@ function updateBlock($bid, $btitle, $bside, $bweight, $bvisible, $bcachetime, $b
$options = implode('|', $options);
$myblock->setVar('options', $options);
}
}
$myblock->store();
$moduleDirName = basename(dirname(__DIR__));
$moduleDirNameUpper = mb_strtoupper($moduleDirName);
// $myblock->store();
/** @var \XoopsBlockHandler $blockHandler */
$blockHandler = xoops_getHandler('block');
$blockHandler->insert($myblock);

global $xoopsDB;

$moduleDirName = \basename(\dirname(__DIR__));
$moduleDirNameUpper = \mb_strtoupper($moduleDirName);

if (!empty($bmodule) && count($bmodule) > 0) {
$sql = sprintf('DELETE FROM `%s` WHERE block_id = %u', $GLOBALS['xoopsDB']->prefix('block_module_link'), $bid);
Expand Down Expand Up @@ -555,7 +561,7 @@ function updateBlock($bid, $btitle, $bside, $bweight, $bvisible, $bcachetime, $b

if ('list' === $op) {
xoops_cp_header();
$adminObject->displayNavigation(basename(__FILE__));
//$adminObject->displayNavigation(basename(__FILE__));
listBlocks();
require_once __DIR__ . '/admin_footer.php';
exit();
Expand Down
4 changes: 2 additions & 2 deletions admin/feedback.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
use Xmf\Request;
use \XoopsModules\Publisher\Common\ModuleFeedback;

require __DIR__ . '/admin_header.php';
require_once __DIR__ . '/admin_header.php';

$adminObject = Admin::getInstance();

Expand Down Expand Up @@ -98,4 +98,4 @@

break;
}
require __DIR__ . '/admin_footer.php';
require_once __DIR__ . '/admin_footer.php';
Loading

0 comments on commit b6f523e

Please sign in to comment.