PHP Classes

File: admin/preferences.php

Recommend this page to a friend!
  Packages of Michael Beck   XOOPS Publisher Module   admin/preferences.php   Download  
File: admin/preferences.php
Role: Example script
Content type: text/plain
Description: Example script
Class: XOOPS Publisher Module
Publish static HTML content and article with XOOPS
Author: By
Last change: Insecure htmlspecialchars(...)
Merge branch 'master' of https://github.com/XoopsModules25x/publisher
Unsetting is not needed because it's not a reference.
streamline namespaces
Merge branch 'master' into master
Missing strict types declaration
Null coalescing operator
Date: 7 months ago
Size: 10,255 bytes
 

Contents

Class file image Download
<?php declare(strict_types=1); /* You may not change or alter any portion of this comment or credits 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. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. */ /** * @copyright The XUUPS Project http://sourceforge.net/projects/xuups/ * @license http://www.fsf.org/copyleft/gpl.html GNU public license * @since 1.0 * @author trabis <lusopoemas@gmail.com> * @author Kazumi Ono (AKA onokazu) */ use Xmf\Request; use XoopsModules\Publisher\{Helper, Utility }; require_once __DIR__ . '/admin_header.php'; $helper = Helper::getInstance(); $module = $helper->getModule(); $modId = $module->mid(); $modname = $module->name(); $dirName = $helper->getDirname(); /** @var \XoopsModuleHandler $moduleHandler */ $moduleHandler = xoops_getHandler('module'); $xoopsModule0 = $moduleHandler->getByDirname(basename(dirname(__DIR__))); global $xoopsModule; xoops_loadLanguage('admin', 'system'); xoops_loadLanguage('admin/preferences', 'system'); $op = 'showmod'; if (isset($_POST)) { foreach ($_POST as $k => $v) { ${$k} = $v; } } unset($k, $v); $op = Request::getString('op', $op, 'GET'); $configcat = Request::getString('configcat', '', 'GET'); if ('showmod' === $op) { /** @var \XoopsConfigHandler $configHandler */ $configHandler = xoops_getHandler('config'); $config = $configHandler->getConfigs(new \Criteria('conf_modid', $modId)); $count = count($config); if ($count < 1) { redirect_header($module->getInfo('adminindex'), 1); } $xv_configs = $module->getInfo('config'); $config_cats = $module->getInfo('configcat'); if (is_array($config_cats) && !array_key_exists('others', $config_cats)) { $config_cats['others'] = [ 'name' => _MI_PUBLISHER_CONFCAT_OTHERS, 'description' => _MI_PUBLISHER_CONFCAT_OTHERS_DSC, ]; } $cat_others_used = false; xoops_loadLanguage('modinfo', $module->getVar('dirname')); if (1 == $module->getVar('hascomments')) { xoops_loadLanguage('comment'); } if (1 == $module->getVar('hasnotification')) { xoops_loadLanguage('notification'); } xoops_load('XoopsFormLoader'); if (is_array($config_cats)) { foreach ($config_cats as $formCat => $info) { $$formCat = new \XoopsThemeForm($info['name'], 'pref_form_' . $formCat, 'preferences.php', 'post', true); } unset($formCat); } for ($i = 0; $i < $count; ++$i) { foreach ($xv_configs as $xv_config) { if ($config[$i]->getVar('conf_name') == $xv_config['name']) { break; } } $formCat = @$xv_config['category']; $formCat = $xv_config['category'] ?? ''; unset($xv_config); if (is_array($config_cats) && !array_key_exists($formCat, $config_cats)) { $formCat = 'others'; $cat_others_used = true; } $title = (!defined($config[$i]->getVar('conf_desc')) || '' == constant($config[$i]->getVar('conf_desc'))) ? constant($config[$i]->getVar('conf_title')) : constant($config[$i]->getVar('conf_title')) . '<br><br><span style="font-weight:normal;">' . constant($config[$i]->getVar('conf_desc')) . '</span>'; switch ($config[$i]->getVar('conf_formtype')) { case 'textarea': $myts = \MyTextSanitizer::getInstance(); if ('array' === $config[$i]->getVar('conf_valuetype')) { // this is exceptional.. only when value type is arrayneed a smarter way for this $ele = ('' != $config[$i]->getVar('conf_value')) ? new \XoopsFormTextArea($title, $config[$i]->getVar('conf_name'), htmlspecialchars(implode('|', $config[$i]->getConfValueForOutput()), ENT_QUOTES | ENT_HTML5), 5, 50) : new \XoopsFormTextArea($title, $config[$i]->getVar('conf_name'), '', 5, 50); } else { $ele = new \XoopsFormTextArea($title, $config[$i]->getVar('conf_name'), htmlspecialchars($config[$i]->getConfValueForOutput(), ENT_QUOTES | ENT_HTML5), 5, 50); } break; case 'select': $ele = new \XoopsFormSelect($title, $config[$i]->getVar('conf_name'), $config[$i]->getConfValueForOutput()); $options = $configHandler->getConfigOptions(new \Criteria('conf_id', $config[$i]->getVar('conf_id'))); $opcount = count($options); for ($j = 0; $j < $opcount; ++$j) { $optval = defined($options[$j]->getVar('confop_value')) ? constant($options[$j]->getVar('confop_value')) : $options[$j]->getVar('confop_value'); $optkey = defined($options[$j]->getVar('confop_name')) ? constant($options[$j]->getVar('confop_name')) : $options[$j]->getVar('confop_name'); $ele->addOption($optval, $optkey); } break; case 'select_multi': $ele = new \XoopsFormSelect($title, $config[$i]->getVar('conf_name'), $config[$i]->getConfValueForOutput(), 5, true); $options = $configHandler->getConfigOptions(new \Criteria('conf_id', $config[$i]->getVar('conf_id'))); $opcount = count($options); for ($j = 0; $j < $opcount; ++$j) { $optval = defined($options[$j]->getVar('confop_value')) ? constant($options[$j]->getVar('confop_value')) : $options[$j]->getVar('confop_value'); $optkey = defined($options[$j]->getVar('confop_name')) ? constant($options[$j]->getVar('confop_name')) : $options[$j]->getVar('confop_name'); $ele->addOption($optval, $optkey); } break; case 'yesno': $ele = new \XoopsFormRadioYN($title, $config[$i]->getVar('conf_name'), $config[$i]->getConfValueForOutput(), _YES, _NO); break; case 'group': require_once $GLOBALS['xoops']->path('class/xoopslists.php'); $ele = new \XoopsFormSelectGroup($title, $config[$i]->getVar('conf_name'), false, $config[$i]->getConfValueForOutput(), 1, false); break; case 'group_multi': require_once $GLOBALS['xoops']->path('class/xoopslists.php'); $ele = new \XoopsFormSelectGroup($title, $config[$i]->getVar('conf_name'), false, $config[$i]->getConfValueForOutput(), 5, true); break; case 'user': require_once $GLOBALS['xoops']->path('class/xoopslists.php'); $ele = new \XoopsFormSelectUser($title, $config[$i]->getVar('conf_name'), false, $config[$i]->getConfValueForOutput(), 1, false); break; case 'user_multi': require_once $GLOBALS['xoops']->path('class/xoopslists.php'); $ele = new \XoopsFormSelectUser($title, $config[$i]->getVar('conf_name'), false, $config[$i]->getConfValueForOutput(), 5, true); break; case 'password': $myts = \MyTextSanitizer::getInstance(); $ele = new \XoopsFormPassword($title, $config[$i]->getVar('conf_name'), 50, 255, htmlspecialchars($config[$i]->getConfValueForOutput(), ENT_QUOTES | ENT_HTML5)); break; case 'color': $myts = \MyTextSanitizer::getInstance(); $ele = new \XoopsFormColorPicker($title, $config[$i]->getVar('conf_name'), htmlspecialchars($config[$i]->getConfValueForOutput(), ENT_QUOTES | ENT_HTML5)); break; case 'hidden': $myts = \MyTextSanitizer::getInstance(); $ele = new \XoopsFormHidden($config[$i]->getVar('conf_name'), htmlspecialchars($config[$i]->getConfValueForOutput(), ENT_QUOTES | ENT_HTML5)); break; case 'textbox': default: $myts = \MyTextSanitizer::getInstance(); $ele = new \XoopsFormText($title, $config[$i]->getVar('conf_name'), 50, 255, htmlspecialchars($config[$i]->getConfValueForOutput(), ENT_QUOTES | ENT_HTML5)); break; } $hidden = new \XoopsFormHidden('conf_ids[]', $config[$i]->getVar('conf_id')); if (isset($$formCat) && null !== $$formCat) { $$formCat->addElement($ele); $$formCat->addElement($hidden); unset($ele, $hidden); } } Utility::cpHeader(); //publisher_adminMenu(5, _PREFERENCES); foreach ($config_cats as $formCat => $info) { if ('others' === $formCat && !$cat_others_used) { continue; } $$formCat->addElement(new \XoopsFormHidden('op', 'save')); $$formCat->addElement(new \XoopsFormButton('', 'button', _GO, 'submit')); Utility::openCollapsableBar($formCat . '_table', $formCat . '_icon', $info['name'], $info['description']); $$formCat->display(); Utility::closeCollapsableBar($formCat . '_table', $formCat . '_icon'); } unset($formCat); xoops_cp_footer(); exit(); } if ('save' === $op) { if (!$GLOBALS['xoopsSecurity']->check()) { redirect_header($module->getInfo('adminindex'), 3, implode('<br>', $GLOBALS['xoopsSecurity']->getErrors())); } $count = count($confIds); /** @var \XoopsConfigHandler $configHandler */ $configHandler = xoops_getHandler('config'); if ($count > 0) { for ($i = 0; $i < $count; ++$i) { $config = $configHandler->getConfig($confIds[$i]); $newValue = ${$config->getVar('conf_name')}; if (is_array($newValue) || $newValue != $config->getVar('conf_value')) { $config->setConfValueForInput($newValue); $configHandler->insertConfig($config); } unset($newValue); } } redirect_header('preferences.php', 2, _AM_DBUPDATED); }