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