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