Conditions | 78 |
Paths | 6145 |
Total Lines | 547 |
Code Lines | 374 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php declare(strict_types=1); |
||
810 | function xoops_module_update($dirname) |
||
811 | { |
||
812 | $errs = []; |
||
813 | $config_old = []; |
||
814 | $msgs = []; |
||
815 | global $xoopsUser, $xoopsConfig, $xoopsTpl; |
||
816 | $dirname = trim((string) $dirname); |
||
817 | // $xoopsDB = $GLOBALS['xoopsDB']; |
||
818 | $xoopsDB = \XoopsDatabaseFactory::getDatabaseConnection(); |
||
819 | |||
820 | $myts = \MyTextSanitizer::getInstance(); |
||
821 | |||
822 | $dirname = htmlspecialchars(trim($dirname), ENT_QUOTES | ENT_HTML5); |
||
823 | /** @var \XoopsModuleHandler $moduleHandler */ |
||
824 | $moduleHandler = xoops_getHandler('module'); |
||
825 | $module = $moduleHandler->getByDirname($dirname); |
||
826 | // Save current version for use in the update function |
||
827 | $prev_version = $module->getVar('version'); |
||
828 | $clearTpl = new \XoopsTpl(); |
||
829 | $clearTpl->clearCache($dirname); |
||
830 | |||
831 | // we don't want to change the module name set by admin |
||
832 | $temp_name = $module->getVar('name'); |
||
833 | $module->loadInfoAsVar($dirname); |
||
834 | $module->setVar('name', $temp_name); |
||
835 | $module->setVar('last_update', time()); |
||
836 | /* |
||
837 | // Call Header |
||
838 | // Define main template |
||
839 | $GLOBALS['xoopsOption']['template_main'] = 'system_header.html'; |
||
840 | // Call Header |
||
841 | xoops_cp_header(); |
||
842 | // Define Stylesheet |
||
843 | $xoTheme->addStylesheet(XOOPS_URL . '/modules/system/css/admin.css'); |
||
844 | // Define Breadcrumb and tips |
||
845 | $xoBreadCrumb->addLink(_AM_SYSTEM_MODULES_ADMIN, system_adminVersion('modulesadmin', 'adminpath')); |
||
846 | $xoBreadCrumb->addLink(_AM_SYSTEM_MODULES_UPDATE); |
||
847 | $xoBreadCrumb->addHelp(system_adminVersion('modulesadmin', 'help') . '#update');https://www.facebook.com/photo.php?v=10154358806675333 |
||
848 | $xoBreadCrumb->render(); |
||
849 | |||
850 | */ |
||
851 | if (!$moduleHandler->insert($module)) { |
||
852 | echo '<p>Could not update ' . $module->getVar('name') . '</p>'; |
||
853 | echo "<br><div class='center'><a href='admin.php?fct=modulesadmin'>" . _AM_SYSTEM_MODULES_BTOMADMIN . '</a></div>'; |
||
854 | } else { |
||
855 | $newmid = $module->getVar('mid'); |
||
856 | $msgs = []; |
||
857 | $msgs[] = '<div id="xo-module-log"><div class="header">'; |
||
858 | $msgs[] = $errs[] = '<h4>' . _AM_SYSTEM_MODULES_UPDATING . $module->getInfo('name', 's') . '</h4>'; |
||
859 | if (false !== $module->getInfo('image') && '' != trim((string) $module->getInfo('image'))) { |
||
860 | $msgs[] = '<img src="' . XOOPS_URL . '/modules/' . $dirname . '/' . trim((string) $module->getInfo('image')) . '" alt="">'; |
||
861 | } |
||
862 | $msgs[] = '<strong>' . _VERSION . ':</strong> ' . $module->getInfo('version') . ' ' . $module->getInfo('module_status'); |
||
863 | if (false !== $module->getInfo('author') && '' != trim((string) $module->getInfo('author'))) { |
||
864 | $msgs[] = '<strong>' . _AUTHOR . ':</strong> ' . htmlspecialchars(trim((string) $module->getInfo('author')), ENT_QUOTES | ENT_HTML5); |
||
865 | } |
||
866 | $msgs[] = '</div><div class="logger">'; |
||
867 | $msgs[] = _AM_SYSTEM_MODULES_MODULE_DATA_UPDATE; |
||
868 | /** @var \XoopsTplfileHandler $tplfileHandler */ |
||
869 | $tplfileHandler = xoops_getHandler('tplfile'); |
||
870 | // irmtfan bug fix: remove codes for delete templates |
||
871 | /* |
||
872 | $deltpl = $tplfileHandler->find('default', 'module', $module->getVar('mid')); |
||
873 | $delng = []; |
||
874 | if (is_array($deltpl)) { |
||
875 | // delete template file entry in db |
||
876 | $dcount = count($deltpl); |
||
877 | for ($i = 0; $i < $dcount; ++$i) { |
||
878 | if (!$tplfileHandler->delete($deltpl[$i])) { |
||
879 | $delng[] = $deltpl[$i]->getVar('tpl_file'); |
||
880 | } |
||
881 | } |
||
882 | } |
||
883 | */ |
||
884 | // irmtfan bug fix: remove codes for delete templates |
||
885 | $templates = $module->getInfo('templates'); |
||
886 | if (false !== $templates) { |
||
887 | $msgs[] = _AM_SYSTEM_MODULES_TEMPLATES_UPDATE; |
||
888 | foreach ($templates as $tpl) { |
||
889 | $tpl['file'] = trim((string) $tpl['file']); |
||
890 | // START irmtfan solve templates duplicate issue |
||
891 | // if (!in_array($tpl['file'], $delng)) { // irmtfan bug fix: remove codes for delete templates |
||
892 | $type = ($tpl['type'] ?? 'module'); |
||
893 | if (preg_match('/\.css$/i', $tpl['file'])) { |
||
894 | $type = 'css'; |
||
895 | } |
||
896 | $criteria = new \CriteriaCompo(); |
||
897 | $criteria->add(new \Criteria('tpl_refid', $newmid), 'AND'); |
||
898 | $criteria->add(new \Criteria('tpl_module', $dirname), 'AND'); |
||
899 | $criteria->add(new \Criteria('tpl_tplset', 'default'), 'AND'); |
||
900 | $criteria->add(new \Criteria('tpl_file', $tpl['file']), 'AND'); |
||
901 | $criteria->add(new \Criteria('tpl_type', $type), 'AND'); |
||
902 | $tplfiles = $tplfileHandler->getObjects($criteria); |
||
903 | |||
904 | $tpldata = xoops_module_gettemplate($dirname, $tpl['file'], $type); |
||
905 | $tplfile = empty($tplfiles) ? $tplfileHandler->create() : $tplfiles[0]; |
||
906 | // END irmtfan solve templates duplicate issue |
||
907 | $tplfile->setVar('tpl_refid', $newmid); |
||
908 | $tplfile->setVar('tpl_lastimported', 0); |
||
909 | $tplfile->setVar('tpl_lastmodified', time()); |
||
910 | $tplfile->setVar('tpl_type', $type); |
||
911 | $tplfile->setVar('tpl_source', $tpldata, true); |
||
912 | $tplfile->setVar('tpl_module', $dirname); |
||
913 | $tplfile->setVar('tpl_tplset', 'default'); |
||
914 | $tplfile->setVar('tpl_file', $tpl['file'], true); |
||
915 | $tplfile->setVar('tpl_desc', $tpl['description'], true); |
||
916 | if (!$tplfileHandler->insert($tplfile)) { |
||
917 | $msgs[] = ' <span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_ADD_ERROR, '<strong>' . $tpl['file'] . '</strong>') . '</span>'; |
||
918 | } else { |
||
919 | $newid = $tplfile->getVar('tpl_id'); |
||
920 | $msgs[] = ' ' . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_INSERT_DATA, '<strong>' . $tpl['file'] . '</strong>'); |
||
921 | if ('default' === $xoopsConfig['template_set']) { |
||
922 | if (!xoops_template_touch($newid)) { |
||
923 | $msgs[] = ' <span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_RECOMPILE_ERROR, '<strong>' . $tpl['file'] . '</strong>') . '</span>'; |
||
924 | } else { |
||
925 | $msgs[] = ' <span>' . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_RECOMPILE, '<strong>' . $tpl['file'] . '</strong>') . '</span>'; |
||
926 | } |
||
927 | } |
||
928 | } |
||
929 | unset($tpldata); |
||
930 | // irmtfan bug fix: remove codes for delete templates |
||
931 | /* |
||
932 | } else { |
||
933 | $msgs[] = ' <span style="color:#ff0000;">'.sprintf(_AM_SYSTEM_MODULES_TEMPLATE_DELETE_OLD_ERROR, "<strong>".$tpl['file']."</strong>").'</span>'; |
||
934 | } |
||
935 | */ |
||
936 | // irmtfan bug fix: remove codes for delete templates |
||
937 | } |
||
938 | } |
||
939 | $blocks = $module->getInfo('blocks'); |
||
940 | $msgs[] = _AM_SYSTEM_MODULES_BLOCKS_REBUILD; |
||
941 | if (false !== $blocks) { |
||
942 | $showfuncs = []; |
||
943 | $funcfiles = []; |
||
944 | foreach ($blocks as $i => $block) { |
||
945 | if (isset($block['show_func']) && '' != $block['show_func'] && isset($block['file']) |
||
946 | && '' != $block['file']) { |
||
947 | $editfunc = $block['edit_func'] ?? ''; |
||
948 | $showfuncs[] = $block['show_func']; |
||
949 | $funcfiles[] = $block['file']; |
||
950 | $template = ''; |
||
951 | if (isset($block['template']) && '' != trim((string) $block['template'])) { |
||
952 | $content = xoops_module_gettemplate($dirname, $block['template'], 'blocks'); |
||
953 | } |
||
954 | if (!$content) { |
||
955 | $content = ''; |
||
956 | } else { |
||
957 | $template = $block['template']; |
||
958 | } |
||
959 | $options = ''; |
||
960 | if (!empty($block['options'])) { |
||
961 | $options = $block['options']; |
||
962 | } |
||
963 | $sql = 'SELECT bid, name FROM ' . $xoopsDB->prefix('newblocks') . ' WHERE mid=' . $module->getVar('mid') . ' AND func_num=' . $i . " AND show_func='" . addslashes((string) $block['show_func']) . "' AND func_file='" . addslashes((string) $block['file']) . "'"; |
||
964 | $fresult = $xoopsDB->query($sql); |
||
965 | $fcount = 0; |
||
966 | while (false !== ($fblock = $xoopsDB->fetchArray($fresult))) { |
||
967 | ++$fcount; |
||
968 | $sql = 'UPDATE ' . $xoopsDB->prefix('newblocks') . " SET name='" . addslashes((string) $block['name']) . "', edit_func='" . addslashes((string) $editfunc) . "', content='', template='" . $template . "', last_modified=" . time() . ' WHERE bid=' . $fblock['bid']; |
||
969 | $result = $xoopsDB->query($sql); |
||
970 | if (!$result) { |
||
971 | $msgs[] = ' ' . sprintf(_AM_SYSTEM_MODULES_UPDATE_ERROR, $fblock['name']); |
||
972 | } else { |
||
973 | $msgs[] = ' ' . sprintf(_AM_SYSTEM_MODULES_BLOCK_UPDATE, $fblock['name']) . sprintf(_AM_SYSTEM_MODULES_BLOCK_ID, '<strong>' . $fblock['bid'] . '</strong>'); |
||
974 | if ('' != $template) { |
||
975 | $tplfile = $tplfileHandler->find('default', 'block', $fblock['bid']); |
||
976 | if (0 == (is_countable($tplfile) ? count($tplfile) : 0)) { |
||
977 | $tplfile_new = $tplfileHandler->create(); |
||
978 | $tplfile_new->setVar('tpl_module', $dirname); |
||
979 | $tplfile_new->setVar('tpl_refid', $fblock['bid']); |
||
980 | $tplfile_new->setVar('tpl_tplset', 'default'); |
||
981 | $tplfile_new->setVar('tpl_file', $block['template'], true); |
||
982 | $tplfile_new->setVar('tpl_type', 'block'); |
||
983 | } else { |
||
984 | $tplfile_new = $tplfile[0]; |
||
985 | } |
||
986 | $tplfile_new->setVar('tpl_source', $content, true); |
||
987 | $tplfile_new->setVar('tpl_desc', $block['description'], true); |
||
988 | $tplfile_new->setVar('tpl_lastmodified', time()); |
||
989 | $tplfile_new->setVar('tpl_lastimported', 0); |
||
990 | $tplfile_new->setVar('tpl_file', $block['template'], true); // irmtfan bug fix: block template file will not updated after update the module |
||
991 | if (!$tplfileHandler->insert($tplfile_new)) { |
||
992 | $msgs[] = ' <span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_UPDATE_ERROR, '<strong>' . $block['template'] . '</strong>') . '</span>'; |
||
993 | } else { |
||
994 | $msgs[] = ' ' . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_UPDATE, '<strong>' . $block['template'] . '</strong>'); |
||
995 | if ('default' === $xoopsConfig['template_set']) { |
||
996 | if (!xoops_template_touch($tplfile_new->getVar('tpl_id'))) { |
||
997 | $msgs[] = ' <span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_RECOMPILE_ERROR, '<strong>' . $block['template'] . '</strong>') . '</span>'; |
||
998 | } else { |
||
999 | $msgs[] = ' ' . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_RECOMPILE, '<strong>' . $block['template'] . '</strong>'); |
||
1000 | } |
||
1001 | } |
||
1002 | } |
||
1003 | } |
||
1004 | } |
||
1005 | } |
||
1006 | if (0 == $fcount) { |
||
1007 | $newbid = $xoopsDB->genId($xoopsDB->prefix('newblocks') . '_bid_seq'); |
||
1008 | $block_name = addslashes((string) $block['name']); |
||
1009 | $block_type = ('system' === $module->getVar('dirname')) ? 'S' : 'M'; |
||
1010 | $sql = 'INSERT INTO ' |
||
1011 | . $xoopsDB->prefix('newblocks') |
||
1012 | . ' (bid, mid, func_num, options, name, title, content, side, weight, visible, block_type, isactive, dirname, func_file, show_func, edit_func, template, last_modified) VALUES (' |
||
1013 | . $newbid |
||
1014 | . ', ' |
||
1015 | . $module->getVar( |
||
1016 | 'mid' |
||
1017 | ) |
||
1018 | . ', ' |
||
1019 | . $i |
||
1020 | . ",'" |
||
1021 | . addslashes((string) $options) |
||
1022 | . "','" |
||
1023 | . $block_name |
||
1024 | . "', '" |
||
1025 | . $block_name |
||
1026 | . "', '', 0, 0, 0, '{$block_type}', 1, '" |
||
1027 | . addslashes($dirname) |
||
1028 | . "', '" |
||
1029 | . addslashes((string) $block['file']) |
||
1030 | . "', '" |
||
1031 | . addslashes((string) $block['show_func']) |
||
1032 | . "', '" |
||
1033 | . addslashes((string) $editfunc) |
||
1034 | . "', '" |
||
1035 | . $template |
||
1036 | . "', " |
||
1037 | . time() |
||
1038 | . ')'; |
||
1039 | $result = $xoopsDB->query($sql); |
||
1040 | if (!$result) { |
||
1041 | $msgs[] = ' ' . sprintf(_AM_SYSTEM_MODULES_SQL_NOT_CREATE, $block['name']); |
||
1042 | echo $sql; |
||
1043 | } else { |
||
1044 | if (empty($newbid)) { |
||
1045 | $newbid = $xoopsDB->getInsertId(); |
||
1046 | } |
||
1047 | $groups = [XOOPS_GROUP_ADMIN]; |
||
1048 | if ($module->getInfo('hasMain')) { |
||
1049 | $groups = [XOOPS_GROUP_ADMIN, XOOPS_GROUP_USERS, XOOPS_GROUP_ANONYMOUS]; |
||
1050 | } |
||
1051 | /** @var \XoopsGroupPermHandler $grouppermHandler */ |
||
1052 | $grouppermHandler = xoops_getHandler('groupperm'); |
||
1053 | foreach ($groups as $mygroup) { |
||
1054 | $bperm = $grouppermHandler->create(); |
||
1055 | $bperm->setVar('gperm_groupid', $mygroup); |
||
1056 | $bperm->setVar('gperm_itemid', $newbid); |
||
1057 | $bperm->setVar('gperm_name', 'block_read'); |
||
1058 | $bperm->setVar('gperm_modid', 1); |
||
1059 | if (!$grouppermHandler->insert($bperm)) { |
||
1060 | $msgs[] = ' <span style="color:#ff0000;">' . _AM_SYSTEM_MODULES_BLOCK_ACCESS_ERROR . sprintf(_AM_SYSTEM_MODULES_BLOCK_ID, '<strong>' . $newbid . '</strong>') . sprintf(_AM_SYSTEM_MODULES_GROUP_ID, '<strong>' . $mygroup . '</strong>') . '</span>'; |
||
1061 | } else { |
||
1062 | $msgs[] = ' ' . _AM_SYSTEM_MODULES_BLOCK_ACCESS . sprintf(_AM_SYSTEM_MODULES_BLOCK_ID, '<strong>' . $newbid . '</strong>') . sprintf(_AM_SYSTEM_MODULES_GROUP_ID, '<strong>' . $mygroup . '</strong>'); |
||
1063 | } |
||
1064 | } |
||
1065 | |||
1066 | if ('' != $template) { |
||
1067 | $tplfile = $tplfileHandler->create(); |
||
1068 | $tplfile->setVar('tpl_module', $dirname); |
||
1069 | $tplfile->setVar('tpl_refid', $newbid); |
||
1070 | $tplfile->setVar('tpl_source', $content, true); |
||
1071 | $tplfile->setVar('tpl_tplset', 'default'); |
||
1072 | $tplfile->setVar('tpl_file', $block['template'], true); |
||
1073 | $tplfile->setVar('tpl_type', 'block'); |
||
1074 | $tplfile->setVar('tpl_lastimported', time()); |
||
1075 | $tplfile->setVar('tpl_lastmodified', time()); |
||
1076 | $tplfile->setVar('tpl_desc', $block['description'], true); |
||
1077 | if (!$tplfileHandler->insert($tplfile)) { |
||
1078 | $msgs[] = ' <span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_ADD_ERROR, '<strong>' . $block['template'] . '</strong>') . '</span>'; |
||
1079 | } else { |
||
1080 | $newid = $tplfile->getVar('tpl_id'); |
||
1081 | $msgs[] = ' ' . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_ADD_DATA, '<strong>' . $block['template'] . '</strong>'); |
||
1082 | if ('default' === $xoopsConfig['template_set']) { |
||
1083 | if (!xoops_template_touch($newid)) { |
||
1084 | $msgs[] = ' <span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_RECOMPILE_FAILD, '<strong>' . $block['template'] . '</strong>') . '</span>'; |
||
1085 | } else { |
||
1086 | $msgs[] = ' ' . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_RECOMPILE, '<strong>' . $block['template'] . '</strong>'); |
||
1087 | } |
||
1088 | } |
||
1089 | } |
||
1090 | } |
||
1091 | $msgs[] = ' ' . sprintf(_AM_SYSTEM_MODULES_BLOCK_CREATED, '<strong>' . $block['name'] . '</strong>') . sprintf(_AM_SYSTEM_MODULES_BLOCK_ID, '<strong>' . $newbid . '</strong>'); |
||
1092 | $sql = 'INSERT INTO ' . $xoopsDB->prefix('block_module_link') . ' (block_id, module_id) VALUES (' . $newbid . ', -1)'; |
||
1093 | $xoopsDB->query($sql); |
||
1094 | } |
||
1095 | } |
||
1096 | } |
||
1097 | } |
||
1098 | $block_arr = \XoopsBlock::getByModule($module->getVar('mid')); |
||
1099 | foreach ($block_arr as $block) { |
||
1100 | if (!in_array($block->getVar('show_func'), $showfuncs, true) |
||
1101 | || !in_array($block->getVar('func_file'), $funcfiles, true)) { |
||
1102 | $sql = sprintf('DELETE FROM `%s` WHERE bid = %u', $xoopsDB->prefix('newblocks'), $block->getVar('bid')); |
||
1103 | if (!$xoopsDB->query($sql)) { |
||
1104 | $msgs[] = ' <span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_BLOCK_DELETE_ERROR, '<strong>' . $block->getVar('name') . '</strong>') . sprintf(_AM_SYSTEM_MODULES_BLOCK_ID, '<strong>' . $block->getVar('bid') . '</strong>') . '</span>'; |
||
1105 | } else { |
||
1106 | $msgs[] = ' Block <strong>' . $block->getVar('name') . ' deleted. Block ID: <strong>' . $block->getVar('bid') . '</strong>'; |
||
1107 | if ('' != $block->getVar('template')) { |
||
1108 | $tplfiles = $tplfileHandler->find(null, 'block', $block->getVar('bid')); |
||
1109 | if (is_array($tplfiles)) { |
||
1110 | $btcount = count($tplfiles); |
||
1111 | for ($k = 0; $k < $btcount; ++$k) { |
||
1112 | if (!$tplfileHandler->delete($tplfiles[$k])) { |
||
1113 | $msgs[] = ' <span style="color:#ff0000;">' . _AM_SYSTEM_MODULES_BLOCK_DEPRECATED_ERROR . '(ID: <strong>' . $tplfiles[$k]->getVar('tpl_id') . '</strong>)</span>'; |
||
1114 | } else { |
||
1115 | $msgs[] = ' ' . sprintf(_AM_SYSTEM_MODULES_BLOCK_DEPRECATED, '<strong>' . $tplfiles[$k]->getVar('tpl_file') . '</strong>'); |
||
1116 | } |
||
1117 | } |
||
1118 | } |
||
1119 | } |
||
1120 | } |
||
1121 | } |
||
1122 | } |
||
1123 | } |
||
1124 | |||
1125 | // reset compile_id |
||
1126 | |||
1127 | // $xoTheme = $xoopsThemeFactory->createInstance(array('contentTemplate' => @$xoopsOption['template_main'])); |
||
1128 | // $xoopsTpl = $xoTheme->template; |
||
1129 | // $xoopsTpl->setCompileId(); |
||
1130 | |||
1131 | $template = $clearTpl; |
||
1132 | $template->setCompileId(); |
||
1133 | // $GLOBALS['xoopsTpl']->setCompileId(); |
||
1134 | // $xoopsTpl->setCompileId(); |
||
1135 | |||
1136 | // first delete all config entries |
||
1137 | /** @var \XoopsConfigHandler $configHandler */ |
||
1138 | $configHandler = xoops_getHandler('config'); |
||
1139 | $configs = $configHandler->getConfigs(new \Criteria('conf_modid', $module->getVar('mid'))); |
||
1140 | $confcount = is_countable($configs) ? count($configs) : 0; |
||
1141 | $config_delng = []; |
||
1142 | if ($confcount > 0) { |
||
1143 | $msgs[] = _AM_SYSTEM_MODULES_MODULE_DATA_DELETE; |
||
1144 | for ($i = 0; $i < $confcount; ++$i) { |
||
1145 | if (!$configHandler->deleteConfig($configs[$i])) { |
||
1146 | $msgs[] = ' <span style="color:#ff0000;">' . _AM_SYSTEM_MODULES_GONFIG_DATA_DELETE_ERROR . sprintf(_AM_SYSTEM_MODULES_GONFIG_ID, '<strong>' . $configs[$i]->getvar('conf_id') . '</strong>') . '</span>'; |
||
1147 | // save the name of config failed to delete for later use |
||
1148 | $config_delng[] = $configs[$i]->getvar('conf_name'); |
||
1149 | } else { |
||
1150 | $config_old[$configs[$i]->getvar('conf_name')]['value'] = $configs[$i]->getvar('conf_value', 'N'); |
||
1151 | $config_old[$configs[$i]->getvar('conf_name')]['formtype'] = $configs[$i]->getvar('conf_formtype'); |
||
1152 | $config_old[$configs[$i]->getvar('conf_name')]['valuetype'] = $configs[$i]->getvar('conf_valuetype'); |
||
1153 | $msgs[] = ' ' . _AM_SYSTEM_MODULES_GONFIG_DATA_DELETE . sprintf(_AM_SYSTEM_MODULES_GONFIG_ID, '<strong>' . $configs[$i]->getVar('conf_id') . '</strong>'); |
||
1154 | } |
||
1155 | } |
||
1156 | } |
||
1157 | |||
1158 | // now reinsert them with the new settings |
||
1159 | $configs = $module->getInfo('config'); |
||
1160 | if (false !== $configs) { |
||
1161 | if (0 != $module->getVar('hascomments')) { |
||
1162 | require XOOPS_ROOT_PATH . '/include/comment_constants.php'; |
||
1163 | $configs[] = [ |
||
1164 | 'name' => 'com_rule', |
||
1165 | 'title' => '_CM_COMRULES', |
||
1166 | 'description' => '', |
||
1167 | 'formtype' => 'select', |
||
1168 | 'valuetype' => 'int', |
||
1169 | 'default' => 1, |
||
1170 | 'options' => [ |
||
1171 | '_CM_COMNOCOM' => XOOPS_COMMENT_APPROVENONE, |
||
1172 | '_CM_COMAPPROVEALL' => XOOPS_COMMENT_APPROVEALL, |
||
1173 | '_CM_COMAPPROVEUSER' => XOOPS_COMMENT_APPROVEUSER, |
||
1174 | '_CM_COMAPPROVEADMIN' => XOOPS_COMMENT_APPROVEADMIN, |
||
1175 | ], |
||
1176 | ]; |
||
1177 | $configs[] = [ |
||
1178 | 'name' => 'com_anonpost', |
||
1179 | 'title' => '_CM_COMANONPOST', |
||
1180 | 'description' => '', |
||
1181 | 'formtype' => 'yesno', |
||
1182 | 'valuetype' => 'int', |
||
1183 | 'default' => 0, |
||
1184 | ]; |
||
1185 | } |
||
1186 | } elseif (0 != $module->getVar('hascomments')) { |
||
1187 | $configs = []; |
||
1188 | require XOOPS_ROOT_PATH . '/include/comment_constants.php'; |
||
1189 | $configs[] = [ |
||
1190 | 'name' => 'com_rule', |
||
1191 | 'title' => '_CM_COMRULES', |
||
1192 | 'description' => '', |
||
1193 | 'formtype' => 'select', |
||
1194 | 'valuetype' => 'int', |
||
1195 | 'default' => 1, |
||
1196 | 'options' => [ |
||
1197 | '_CM_COMNOCOM' => XOOPS_COMMENT_APPROVENONE, |
||
1198 | '_CM_COMAPPROVEALL' => XOOPS_COMMENT_APPROVEALL, |
||
1199 | '_CM_COMAPPROVEUSER' => XOOPS_COMMENT_APPROVEUSER, |
||
1200 | '_CM_COMAPPROVEADMIN' => XOOPS_COMMENT_APPROVEADMIN, |
||
1201 | ], |
||
1202 | ]; |
||
1203 | $configs[] = [ |
||
1204 | 'name' => 'com_anonpost', |
||
1205 | 'title' => '_CM_COMANONPOST', |
||
1206 | 'description' => '', |
||
1207 | 'formtype' => 'yesno', |
||
1208 | 'valuetype' => 'int', |
||
1209 | 'default' => 0, |
||
1210 | ]; |
||
1211 | } |
||
1212 | // RMV-NOTIFY |
||
1213 | if (0 != $module->getVar('hasnotification')) { |
||
1214 | if (empty($configs)) { |
||
1215 | $configs = []; |
||
1216 | } |
||
1217 | // Main notification options |
||
1218 | require_once XOOPS_ROOT_PATH . '/include/notification_constants.php'; |
||
1219 | require_once XOOPS_ROOT_PATH . '/include/notification_functions.php'; |
||
1220 | $options = []; |
||
1221 | $options['_NOT_CONFIG_DISABLE'] = XOOPS_NOTIFICATION_DISABLE; |
||
1222 | $options['_NOT_CONFIG_ENABLEBLOCK'] = XOOPS_NOTIFICATION_ENABLEBLOCK; |
||
1223 | $options['_NOT_CONFIG_ENABLEINLINE'] = XOOPS_NOTIFICATION_ENABLEINLINE; |
||
1224 | $options['_NOT_CONFIG_ENABLEBOTH'] = XOOPS_NOTIFICATION_ENABLEBOTH; |
||
1225 | |||
1226 | //$configs[] = array ('name' => 'notification_enabled', 'title' => '_NOT_CONFIG_ENABLED', 'description' => '_NOT_CONFIG_ENABLEDDSC', 'formtype' => 'yesno', 'valuetype' => 'int', 'default' => 1); |
||
1227 | $configs[] = [ |
||
1228 | 'name' => 'notification_enabled', |
||
1229 | 'title' => '_NOT_CONFIG_ENABLE', |
||
1230 | 'description' => '_NOT_CONFIG_ENABLEDSC', |
||
1231 | 'formtype' => 'select', |
||
1232 | 'valuetype' => 'int', |
||
1233 | 'default' => XOOPS_NOTIFICATION_ENABLEBOTH, |
||
1234 | 'options' => $options, |
||
1235 | ]; |
||
1236 | // Event specific notification options |
||
1237 | // FIXME: for some reason the default doesn't come up properly |
||
1238 | // initially is ok, but not when 'update' module.. |
||
1239 | $options = []; |
||
1240 | $categories = notificationCategoryInfo('', $module->getVar('mid')); |
||
1241 | foreach ($categories as $category) { |
||
1242 | $events = notificationEvents($category['name'], false, $module->getVar('mid')); |
||
1243 | foreach ($events as $event) { |
||
1244 | if (!empty($event['invisible'])) { |
||
1245 | continue; |
||
1246 | } |
||
1247 | $option_name = $category['title'] . ' : ' . $event['title']; |
||
1248 | $option_value = $category['name'] . '-' . $event['name']; |
||
1249 | $options[$option_name] = $option_value; |
||
1250 | //$configs[] = array ('name' => notificationGenerateConfig($category,$event,'name'), 'title' => notificationGenerateConfig($category,$event,'title_constant'), 'description' => notificationGenerateConfig($category,$event,'description_constant'), 'formtype' => 'yesno', 'valuetype' => 'int', 'default' => 1); |
||
1251 | } |
||
1252 | } |
||
1253 | $configs[] = [ |
||
1254 | 'name' => 'notification_events', |
||
1255 | 'title' => '_NOT_CONFIG_EVENTS', |
||
1256 | 'description' => '_NOT_CONFIG_EVENTSDSC', |
||
1257 | 'formtype' => 'select_multi', |
||
1258 | 'valuetype' => 'array', |
||
1259 | 'default' => array_values($options), |
||
1260 | 'options' => $options, |
||
1261 | ]; |
||
1262 | } |
||
1263 | |||
1264 | if (false !== $configs) { |
||
1265 | $msgs[] = 'Adding module config data...'; |
||
1266 | /** @var \XoopsConfigHandler $configHandler */ |
||
1267 | $configHandler = xoops_getHandler('config'); |
||
1268 | $order = 0; |
||
1269 | foreach ($configs as $config) { |
||
1270 | // only insert ones that have been deleted previously with success |
||
1271 | if (!in_array($config['name'], $config_delng, true)) { |
||
1272 | $confobj = $configHandler->createConfig(); |
||
1273 | $confobj->setVar('conf_modid', $newmid); |
||
1274 | $confobj->setVar('conf_catid', 0); |
||
1275 | $confobj->setVar('conf_name', $config['name']); |
||
1276 | $confobj->setVar('conf_title', $config['title'], true); |
||
1277 | $confobj->setVar('conf_desc', $config['description'], true); |
||
1278 | $confobj->setVar('conf_formtype', $config['formtype']); |
||
1279 | if (isset($config['valuetype'])) { |
||
1280 | $confobj->setVar('conf_valuetype', $config['valuetype']); |
||
1281 | } |
||
1282 | if (isset($config_old[$config['name']]['value']) |
||
1283 | && $config_old[$config['name']]['formtype'] == $config['formtype'] |
||
1284 | && $config_old[$config['name']]['valuetype'] == $config['valuetype']) { |
||
1285 | // preserver the old value if any |
||
1286 | // form type and value type must be the same |
||
1287 | $confobj->setVar('conf_value', $config_old[$config['name']]['value'], true); |
||
1288 | } else { |
||
1289 | $confobj->setConfValueForInput($config['default'], true); |
||
1290 | //$confobj->setVar('conf_value', $config['default'], true); |
||
1291 | } |
||
1292 | $confobj->setVar('conf_order', $order); |
||
1293 | $confop_msgs = ''; |
||
1294 | if (isset($config['options']) && is_array($config['options'])) { |
||
1295 | foreach ($config['options'] as $key => $value) { |
||
1296 | $confop = $configHandler->createConfigOption(); |
||
1297 | $confop->setVar('confop_name', $key, true); |
||
1298 | $confop->setVar('confop_value', $value, true); |
||
1299 | $confobj->setConfOptions($confop); |
||
1300 | $confop_msgs .= '<br> ' . _AM_SYSTEM_MODULES_CONFIG_ADD . _AM_SYSTEM_MODULES_NAME . ' <strong>' . (defined($key) ? constant($key) : $key) . '</strong> ' . _AM_SYSTEM_MODULES_VALUE . ' <strong>' . $value . '</strong> '; |
||
1301 | unset($confop); |
||
1302 | } |
||
1303 | } |
||
1304 | ++$order; |
||
1305 | if ($configHandler->insertConfig($confobj)) { |
||
1306 | //$msgs[] = ' Config <strong>'.$config['name'].'</strong> added to the database.'.$confop_msgs; |
||
1307 | $msgs[] = ' ' . sprintf(_AM_SYSTEM_MODULES_CONFIG_DATA_ADD, '<strong>' . $config['name'] . '</strong>') . $confop_msgs; |
||
1308 | } else { |
||
1309 | $msgs[] = ' <span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_CONFIG_DATA_ADD_ERROR, '<strong>' . $config['name'] . '</strong>') . '</span>'; |
||
1310 | } |
||
1311 | unset($confobj); |
||
1312 | } |
||
1313 | } |
||
1314 | unset($configs); |
||
1315 | } |
||
1316 | |||
1317 | // execute module specific update script if any |
||
1318 | $update_script = $module->getInfo('onUpdate'); |
||
1319 | if (false !== $update_script && '' != trim((string) $update_script)) { |
||
1320 | require_once XOOPS_ROOT_PATH . '/modules/' . $dirname . '/' . trim((string) $update_script); |
||
1321 | if (function_exists('xoops_module_update_' . $dirname)) { |
||
1322 | $func = 'xoops_module_update_' . $dirname; |
||
1323 | if (!$func($module, $prev_version)) { |
||
1324 | $msgs[] = '<p>' . sprintf(_AM_SYSTEM_MODULES_FAILED_EXECUTE, $func) . '</p>'; |
||
1325 | $msgs = array_merge($msgs, $module->getErrors()); |
||
1326 | } else { |
||
1327 | $msgs[] = '<p>' . sprintf(_AM_SYSTEM_MODULES_FAILED_SUCESS, '<strong>' . $func . '</strong>') . '</p>'; |
||
1328 | $msgs += $module->getErrors(); |
||
1329 | } |
||
1330 | } |
||
1331 | } |
||
1332 | $msgs[] = sprintf(_AM_SYSTEM_MODULES_OKUPD, '<strong>' . $module->getVar('name', 's') . '</strong>'); |
||
1333 | $msgs[] = '</div></div>'; |
||
1334 | $msgs[] = '<div class="center"><a href="admin.php?fct=modulesadmin">' . _AM_SYSTEM_MODULES_BTOMADMIN . '</a> | <a href="' . XOOPS_URL . '/modules/' . $module->getInfo('dirname', 'e') . '/' . $module->getInfo('adminindex') . '">' . _AM_SYSTEM_MODULES_ADMIN . '</a></div>'; |
||
1335 | // foreach ($msgs as $msg) { |
||
1336 | // echo $msg . '<br>'; |
||
1337 | // } |
||
1338 | } |
||
1339 | // Call Footer |
||
1340 | // xoops_cp_footer(); |
||
1341 | // Flush cache files for cpanel GUIs |
||
1342 | // xoops_load("cpanel", "system"); |
||
1343 | // XoopsSystemCpanel::flush(); |
||
1344 | // |
||
1345 | // require_once XOOPS_ROOT_PATH . '/modules/system/class/maintenance.php'; |
||
1346 | // $maintenance = new SystemMaintenance(); |
||
1347 | // $folder = array(1, 3); |
||
1348 | // $maintenance->CleanCache($folder); |
||
1349 | //Set active modules in cache folder |
||
1350 | // xoops_setActiveModules(); |
||
1351 | // break; |
||
1352 | //----------------------------------------------- |
||
1353 | |||
1354 | $ret = implode('<br>', $msgs); |
||
1355 | |||
1356 | return $ret; |
||
1357 | } |
||
1484 |
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.