| Conditions | 70 |
| Paths | > 20000 |
| Total Lines | 516 |
| Code Lines | 407 |
| 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 declare(strict_types=1); |
||
| 30 | function xoops_module_install($dirname) |
||
| 31 | { |
||
| 32 | $pieces = null; |
||
| 33 | global $xoopsUser, $xoopsConfig; |
||
| 34 | $dirname = trim((string) $dirname); |
||
| 35 | // $db = $GLOBALS['xoopsDB']; |
||
| 36 | $db = \XoopsDatabaseFactory::getDatabaseConnection(); |
||
| 37 | $reservedTables = [ |
||
| 38 | 'avatar', |
||
| 39 | 'avatar_users_link', |
||
| 40 | 'block_module_link', |
||
| 41 | 'xoopscomments', |
||
| 42 | 'config', |
||
| 43 | 'configcategory', |
||
| 44 | 'configoption', |
||
| 45 | 'image', |
||
| 46 | 'imagebody', |
||
| 47 | 'imagecategory', |
||
| 48 | 'imgset', |
||
| 49 | 'imgset_tplset_link', |
||
| 50 | 'imgsetimg', |
||
| 51 | 'groups', |
||
| 52 | 'groups_users_link', |
||
| 53 | 'group_permission', |
||
| 54 | 'online', |
||
| 55 | 'bannerclient', |
||
| 56 | 'banner', |
||
| 57 | 'bannerfinish', |
||
| 58 | 'priv_msgs', |
||
| 59 | 'ranks', |
||
| 60 | 'session', |
||
| 61 | 'smiles', |
||
| 62 | 'users', |
||
| 63 | 'newblocks', |
||
| 64 | 'modules', |
||
| 65 | 'tplfile', |
||
| 66 | 'tplset', |
||
| 67 | 'tplsource', |
||
| 68 | 'xoopsnotifications', |
||
| 69 | 'banner', |
||
| 70 | 'bannerclient', |
||
| 71 | 'bannerfinish', |
||
| 72 | ]; |
||
| 73 | /** @var \XoopsModuleHandler $moduleHandler */ |
||
| 74 | $moduleHandler = xoops_getHandler('module'); |
||
| 75 | if (0 == $moduleHandler->getCount(new \Criteria('dirname', $dirname))) { |
||
| 76 | $module = $moduleHandler->create(); |
||
| 77 | $module->loadInfoAsVar($dirname); |
||
| 78 | $module->setVar('weight', 1); |
||
| 79 | $module->setVar('isactive', 1); |
||
| 80 | $module->setVar('last_update', time()); |
||
| 81 | $error = false; |
||
| 82 | $errs = []; |
||
| 83 | $msgs = []; |
||
| 84 | |||
| 85 | $msgs[] = '<div id="xo-module-log"><div class="header">'; |
||
| 86 | $msgs[] = $errs[] = '<h4>' . _AM_SYSTEM_MODULES_INSTALLING . $module->getInfo('name', 's') . '</h4>'; |
||
| 87 | if (false !== $module->getInfo('image') && '' != trim((string) $module->getInfo('image'))) { |
||
| 88 | $msgs[] = '<a href="' . XOOPS_URL . '/modules/' . $module->getInfo('dirname', 'e') . '/' . $module->getInfo('adminindex') . '"><img src="' . XOOPS_URL . '/modules/' . $dirname . '/' . trim((string) $module->getInfo('image')) . '" alt=""></a>'; |
||
| 89 | } |
||
| 90 | $msgs[] = '<strong>' . _VERSION . ':</strong> ' . $module->getInfo('version') . ' ' . $module->getInfo('module_status'); |
||
| 91 | if (false !== $module->getInfo('author') && '' != trim((string) $module->getInfo('author'))) { |
||
| 92 | $msgs[] = '<strong>' . _AUTHOR . ':</strong> ' . htmlspecialchars(trim((string) $module->getInfo('author')), ENT_QUOTES | ENT_HTML5); |
||
| 93 | } |
||
| 94 | $msgs[] = '</div><div class="logger">'; |
||
| 95 | // Load module specific install script if any |
||
| 96 | $install_script = $module->getInfo('onInstall'); |
||
| 97 | if ($install_script && '' != trim((string) $install_script)) { |
||
| 98 | require_once XOOPS_ROOT_PATH . '/modules/' . $dirname . '/' . trim((string) $install_script); |
||
| 99 | } |
||
| 100 | $func = "xoops_module_pre_install_{$dirname}"; |
||
| 101 | // If pre install function is defined, execute |
||
| 102 | if (function_exists($func)) { |
||
| 103 | $result = $func($module); |
||
| 104 | if (!$result) { |
||
| 105 | $error = true; |
||
| 106 | $errs[] = '<p>' . sprintf(_AM_SYSTEM_MODULES_FAILED_EXECUTE, $func) . '</p>'; |
||
| 107 | $errs = array_merge($errs, $module->getErrors()); |
||
| 108 | } else { |
||
| 109 | $msgs[] = '<p>' . sprintf(_AM_SYSTEM_MODULES_FAILED_SUCESS, "<strong>{$func}</strong>") . '</p>'; |
||
| 110 | $msgs += $module->getErrors(); |
||
| 111 | } |
||
| 112 | } |
||
| 113 | |||
| 114 | if (!$error) { |
||
| 115 | $sqlfile = $module->getInfo('sqlfile'); |
||
| 116 | if (is_array($sqlfile) && !empty($sqlfile[XOOPS_DB_TYPE])) { |
||
| 117 | $sql_file_path = XOOPS_ROOT_PATH . '/modules/' . $dirname . '/' . $sqlfile[XOOPS_DB_TYPE]; |
||
| 118 | if (!is_file($sql_file_path)) { |
||
| 119 | $errs[] = '<p>' . sprintf(_AM_SYSTEM_MODULES_SQL_NOT_FOUND, "<strong>{$sql_file_path}</strong>"); |
||
| 120 | $error = true; |
||
| 121 | } else { |
||
| 122 | $msgs[] = '<p>' . sprintf(_AM_SYSTEM_MODULES_SQL_FOUND, "<strong>{$sql_file_path}</strong>") . '<br >' . _AM_SYSTEM_MODULES_CREATE_TABLES; |
||
| 123 | require_once XOOPS_ROOT_PATH . '/class/database/sqlutility.php'; |
||
| 124 | $sql_query = fread(fopen($sql_file_path, 'rb'), filesize($sql_file_path)); |
||
| 125 | $sql_query = trim($sql_query); |
||
| 126 | SqlUtility::splitMySqlFile($pieces, $sql_query); |
||
| 127 | $created_tables = []; |
||
| 128 | foreach ($pieces as $piece) { |
||
| 129 | // [0] contains the prefixed query |
||
| 130 | // [4] contains unprefixed table name |
||
| 131 | $prefixed_query = SqlUtility::prefixQuery($piece, $db->prefix()); |
||
| 132 | if (!$prefixed_query) { |
||
| 133 | $errs[] = '<p>' . sprintf(_AM_SYSTEM_MODULES_SQL_NOT_VALID, '<strong>' . $piece . '</strong>'); |
||
| 134 | $error = true; |
||
| 135 | break; |
||
| 136 | } |
||
| 137 | // check if the table name is reserved |
||
| 138 | if (!in_array($prefixed_query[4], $reservedTables, true)) { |
||
| 139 | // not reserved, so try to create one |
||
| 140 | if (!$db->query($prefixed_query[0])) { |
||
| 141 | $errs[] = $db->error(); |
||
| 142 | $error = true; |
||
| 143 | break; |
||
| 144 | } |
||
| 145 | if (!in_array($prefixed_query[4], $created_tables, true)) { |
||
| 146 | $msgs[] = ' ' . sprintf(_AM_SYSTEM_MODULES_TABLE_CREATED, '<strong>' . $db->prefix($prefixed_query[4]) . '</strong>'); |
||
| 147 | $created_tables[] = $prefixed_query[4]; |
||
| 148 | } else { |
||
| 149 | $msgs[] = ' ' . sprintf(_AM_SYSTEM_MODULES_INSERT_DATA, '<strong>' . $db->prefix($prefixed_query[4]) . '</strong>'); |
||
| 150 | } |
||
| 151 | } else { |
||
| 152 | // the table name is reserved, so halt the installation |
||
| 153 | $errs[] = ' ' . sprintf(_AM_SYSTEM_MODULES_TABLE_RESERVED, '<strong>' . $prefixed_query[4] . '</strong>'); |
||
| 154 | $error = true; |
||
| 155 | break; |
||
| 156 | } |
||
| 157 | } |
||
| 158 | // if there was an error, delete the tables created so far, so the next installation will not fail |
||
| 159 | if ($error) { |
||
| 160 | foreach ($created_tables as $ct) { |
||
| 161 | $db->query('DROP TABLE ' . $db->prefix($ct)); |
||
| 162 | } |
||
| 163 | } |
||
| 164 | } |
||
| 165 | } |
||
| 166 | } |
||
| 167 | // if no error, save the module info and blocks info associated with it |
||
| 168 | if (false === $error) { |
||
| 169 | if (!$moduleHandler->insert($module)) { |
||
| 170 | $errs[] = '<p>' . sprintf(_AM_SYSTEM_MODULES_INSERT_DATA_FAILD, '<strong>' . $module->getVar('name') . '</strong>'); |
||
| 171 | foreach ($created_tables as $ct) { |
||
| 172 | $db->query('DROP TABLE ' . $db->prefix($ct)); |
||
| 173 | } |
||
| 174 | $ret = '<p>' . sprintf(_AM_SYSTEM_MODULES_FAILINS, '<strong>' . $module->name() . '</strong>') . ' ' . _AM_SYSTEM_MODULES_ERRORSC . '<br>'; |
||
| 175 | foreach ($errs as $err) { |
||
| 176 | $ret .= ' - ' . $err . '<br>'; |
||
| 177 | } |
||
| 178 | $ret .= '</p>'; |
||
| 179 | unset($module, $created_tables, $errs, $msgs); |
||
| 180 | |||
| 181 | return $ret; |
||
| 182 | } |
||
| 183 | $newmid = $module->getVar('mid'); |
||
| 184 | unset($created_tables); |
||
| 185 | $msgs[] = '<p>' . _AM_SYSTEM_MODULES_INSERT_DATA_DONE . sprintf(_AM_SYSTEM_MODULES_MODULEID, '<strong>' . $newmid . '</strong>'); |
||
| 186 | /** @var \XoopsTplfileHandler $tplfileHandler */ |
||
| 187 | $tplfileHandler = xoops_getHandler('tplfile'); |
||
| 188 | $templates = $module->getInfo('templates'); |
||
| 189 | if (false !== $templates) { |
||
| 190 | $msgs[] = _AM_SYSTEM_MODULES_TEMPLATES_ADD; |
||
| 191 | foreach ($templates as $tpl) { |
||
| 192 | $tplfile = $tplfileHandler->create(); |
||
| 193 | $type = ($tpl['type'] ?? 'module'); |
||
| 194 | $tpldata = xoops_module_gettemplate($dirname, $tpl['file'], $type); |
||
| 195 | $tplfile->setVar('tpl_source', $tpldata, true); |
||
| 196 | $tplfile->setVar('tpl_refid', $newmid); |
||
| 197 | |||
| 198 | $tplfile->setVar('tpl_tplset', 'default'); |
||
| 199 | $tplfile->setVar('tpl_file', $tpl['file']); |
||
| 200 | $tplfile->setVar('tpl_desc', $tpl['description'], true); |
||
| 201 | $tplfile->setVar('tpl_module', $dirname); |
||
| 202 | $tplfile->setVar('tpl_lastmodified', time()); |
||
| 203 | $tplfile->setVar('tpl_lastimported', time()); |
||
| 204 | $tplfile->setVar('tpl_type', $type); |
||
| 205 | if (!$tplfileHandler->insert($tplfile)) { |
||
| 206 | $msgs[] = ' <span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_ADD_ERROR, '<strong>' . $tpl['file'] . '</strong>') . '</span>'; |
||
| 207 | } else { |
||
| 208 | $newtplid = $tplfile->getVar('tpl_id'); |
||
| 209 | $msgs[] = ' ' . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_ADD_DATA, '<strong>' . $tpl['file'] . '</strong>') . '(ID: <strong>' . $newtplid . '</strong>)'; |
||
| 210 | // generate compiled file |
||
| 211 | require_once XOOPS_ROOT_PATH . '/class/template.php'; |
||
| 212 | if (!xoops_template_touch($newtplid)) { |
||
| 213 | $msgs[] = ' <span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_COMPILED_FAILED, '<strong>' . $tpl['file'] . '</strong>') . '</span>'; |
||
| 214 | } else { |
||
| 215 | $msgs[] = ' ' . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_COMPILED, '<strong>' . $tpl['file'] . '</strong>'); |
||
| 216 | } |
||
| 217 | } |
||
| 218 | unset($tplfile, $tpldata); |
||
| 219 | } |
||
| 220 | } |
||
| 221 | require_once XOOPS_ROOT_PATH . '/class/template.php'; |
||
| 222 | xoops_template_clear_module_cache($newmid); |
||
| 223 | $blocks = $module->getInfo('blocks'); |
||
| 224 | if (false !== $blocks) { |
||
| 225 | $msgs[] = _AM_SYSTEM_MODULES_BLOCKS_ADD; |
||
| 226 | foreach ($blocks as $blockkey => $block) { |
||
| 227 | // break the loop if missing block config |
||
| 228 | if (!isset($block['file']) || !isset($block['show_func'])) { |
||
| 229 | break; |
||
| 230 | } |
||
| 231 | $options = ''; |
||
| 232 | if (!empty($block['options'])) { |
||
| 233 | $options = trim((string) $block['options']); |
||
| 234 | } |
||
| 235 | $newbid = $db->genId($db->prefix('newblocks') . '_bid_seq'); |
||
| 236 | $edit_func = isset($block['edit_func']) ? trim((string) $block['edit_func']) : ''; |
||
| 237 | $template = ''; |
||
| 238 | if (isset($block['template']) && '' != trim((string) $block['template'])) { |
||
| 239 | $content = xoops_module_gettemplate($dirname, $block['template'], 'blocks'); |
||
| 240 | } |
||
| 241 | if (empty($content)) { |
||
| 242 | $content = ''; |
||
| 243 | } else { |
||
| 244 | $template = trim((string) $block['template']); |
||
| 245 | } |
||
| 246 | $block_name = addslashes(trim((string) $block['name'])); |
||
| 247 | $sql = 'INSERT INTO ' |
||
| 248 | . $db->prefix('newblocks') |
||
| 249 | . " (bid, mid, func_num, options, name, title, content, side, weight, visible, block_type, c_type, isactive, dirname, func_file, show_func, edit_func, template, bcachetime, last_modified) VALUES ($newbid, $newmid, " |
||
| 250 | . (int)$blockkey |
||
| 251 | . ", '$options', '" |
||
| 252 | . $block_name |
||
| 253 | . "','" |
||
| 254 | . $block_name |
||
| 255 | . "', '', 0, 0, 0, 'M', 'H', 1, '" |
||
| 256 | . addslashes($dirname) |
||
| 257 | . "', '" |
||
| 258 | . addslashes(trim((string) $block['file'])) |
||
| 259 | . "', '" |
||
| 260 | . addslashes(trim((string) $block['show_func'])) |
||
| 261 | . "', '" |
||
| 262 | . addslashes($edit_func) |
||
| 263 | . "', '" |
||
| 264 | . $template |
||
| 265 | . "', 0, " |
||
| 266 | . time() |
||
| 267 | . ')'; |
||
| 268 | if (!$db->query($sql)) { |
||
| 269 | $msgs[] = ' <span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_BLOCK_ADD_ERROR, '<strong>' . $block['name'] . '</strong>') . sprintf(_AM_SYSTEM_MODULES_BLOCK_ADD_ERROR_DATABASE, '<strong>' . $db->error() . '</strong>') . '</span>'; |
||
| 270 | } else { |
||
| 271 | if (empty($newbid)) { |
||
| 272 | $newbid = $db->getInsertId(); |
||
| 273 | } |
||
| 274 | $msgs[] = ' ' . sprintf(_AM_SYSTEM_MODULES_BLOCK_ADD, '<strong>' . $block['name'] . '</strong>') . sprintf(_AM_SYSTEM_MODULES_BLOCK_ID, '<strong>' . $newbid . '</strong>'); |
||
| 275 | $sql = 'INSERT INTO ' . $db->prefix('block_module_link') . ' (block_id, module_id) VALUES (' . $newbid . ', -1)'; |
||
| 276 | $db->query($sql); |
||
| 277 | if ('' != $template) { |
||
| 278 | $tplfile = $tplfileHandler->create(); |
||
| 279 | $tplfile->setVar('tpl_refid', $newbid); |
||
| 280 | $tplfile->setVar('tpl_source', $content, true); |
||
| 281 | $tplfile->setVar('tpl_tplset', 'default'); |
||
| 282 | $tplfile->setVar('tpl_file', $block['template']); |
||
| 283 | $tplfile->setVar('tpl_module', $dirname); |
||
| 284 | $tplfile->setVar('tpl_type', 'block'); |
||
| 285 | $tplfile->setVar('tpl_desc', $block['description'], true); |
||
| 286 | $tplfile->setVar('tpl_lastimported', 0); |
||
| 287 | $tplfile->setVar('tpl_lastmodified', time()); |
||
| 288 | if (!$tplfileHandler->insert($tplfile)) { |
||
| 289 | $msgs[] = ' <span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_ADD_ERROR, '<strong>' . $block['template'] . '</strong>') . '</span>'; |
||
| 290 | } else { |
||
| 291 | $newtplid = $tplfile->getVar('tpl_id'); |
||
| 292 | $msgs[] = ' ' . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_ADD_DATA, '<strong>' . $block['template'] . '</strong>') . ' (ID: <strong>' . $newtplid . '</strong>)'; |
||
| 293 | // generate compiled file |
||
| 294 | require_once XOOPS_ROOT_PATH . '/class/template.php'; |
||
| 295 | if (!xoops_template_touch($newtplid)) { |
||
| 296 | $msgs[] = ' <span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_COMPILED_FAILED, '<strong>' . $block['template'] . '</strong>') . '</span>'; |
||
| 297 | } else { |
||
| 298 | $msgs[] = ' ' . sprintf(_AM_SYSTEM_MODULES_TEMPLATE_COMPILED, '<strong>' . $block['template'] . '</strong>'); |
||
| 299 | } |
||
| 300 | } |
||
| 301 | unset($tplfile); |
||
| 302 | } |
||
| 303 | } |
||
| 304 | unset($content); |
||
| 305 | } |
||
| 306 | unset($blocks); |
||
| 307 | } |
||
| 308 | $configs = $module->getInfo('config'); |
||
| 309 | if (false !== $configs) { |
||
| 310 | if (0 != $module->getVar('hascomments')) { |
||
| 311 | require XOOPS_ROOT_PATH . '/include/comment_constants.php'; |
||
| 312 | $configs[] = [ |
||
| 313 | 'name' => 'com_rule', |
||
| 314 | 'title' => '_CM_COMRULES', |
||
| 315 | 'description' => '', |
||
| 316 | 'formtype' => 'select', |
||
| 317 | 'valuetype' => 'int', |
||
| 318 | 'default' => 1, |
||
| 319 | 'options' => [ |
||
| 320 | '_CM_COMNOCOM' => XOOPS_COMMENT_APPROVENONE, |
||
| 321 | '_CM_COMAPPROVEALL' => XOOPS_COMMENT_APPROVEALL, |
||
| 322 | '_CM_COMAPPROVEUSER' => XOOPS_COMMENT_APPROVEUSER, |
||
| 323 | '_CM_COMAPPROVEADMIN' => XOOPS_COMMENT_APPROVEADMIN, |
||
| 324 | ], |
||
| 325 | ]; |
||
| 326 | $configs[] = [ |
||
| 327 | 'name' => 'com_anonpost', |
||
| 328 | 'title' => '_CM_COMANONPOST', |
||
| 329 | 'description' => '', |
||
| 330 | 'formtype' => 'yesno', |
||
| 331 | 'valuetype' => 'int', |
||
| 332 | 'default' => 0, |
||
| 333 | ]; |
||
| 334 | } |
||
| 335 | } elseif (0 != $module->getVar('hascomments')) { |
||
| 336 | $configs = []; |
||
| 337 | require XOOPS_ROOT_PATH . '/include/comment_constants.php'; |
||
| 338 | $configs[] = [ |
||
| 339 | 'name' => 'com_rule', |
||
| 340 | 'title' => '_CM_COMRULES', |
||
| 341 | 'description' => '', |
||
| 342 | 'formtype' => 'select', |
||
| 343 | 'valuetype' => 'int', |
||
| 344 | 'default' => 1, |
||
| 345 | 'options' => [ |
||
| 346 | '_CM_COMNOCOM' => XOOPS_COMMENT_APPROVENONE, |
||
| 347 | '_CM_COMAPPROVEALL' => XOOPS_COMMENT_APPROVEALL, |
||
| 348 | '_CM_COMAPPROVEUSER' => XOOPS_COMMENT_APPROVEUSER, |
||
| 349 | '_CM_COMAPPROVEADMIN' => XOOPS_COMMENT_APPROVEADMIN, |
||
| 350 | ], |
||
| 351 | ]; |
||
| 352 | $configs[] = [ |
||
| 353 | 'name' => 'com_anonpost', |
||
| 354 | 'title' => '_CM_COMANONPOST', |
||
| 355 | 'description' => '', |
||
| 356 | 'formtype' => 'yesno', |
||
| 357 | 'valuetype' => 'int', |
||
| 358 | 'default' => 0, |
||
| 359 | ]; |
||
| 360 | } |
||
| 361 | // RMV-NOTIFY |
||
| 362 | if (0 != $module->getVar('hasnotification')) { |
||
| 363 | if (empty($configs)) { |
||
| 364 | $configs = []; |
||
| 365 | } |
||
| 366 | // Main notification options |
||
| 367 | require_once XOOPS_ROOT_PATH . '/include/notification_constants.php'; |
||
| 368 | require_once XOOPS_ROOT_PATH . '/include/notification_functions.php'; |
||
| 369 | $options = []; |
||
| 370 | $options['_NOT_CONFIG_DISABLE'] = XOOPS_NOTIFICATION_DISABLE; |
||
| 371 | $options['_NOT_CONFIG_ENABLEBLOCK'] = XOOPS_NOTIFICATION_ENABLEBLOCK; |
||
| 372 | $options['_NOT_CONFIG_ENABLEINLINE'] = XOOPS_NOTIFICATION_ENABLEINLINE; |
||
| 373 | $options['_NOT_CONFIG_ENABLEBOTH'] = XOOPS_NOTIFICATION_ENABLEBOTH; |
||
| 374 | |||
| 375 | $configs[] = [ |
||
| 376 | 'name' => 'notification_enabled', |
||
| 377 | 'title' => '_NOT_CONFIG_ENABLE', |
||
| 378 | 'description' => '_NOT_CONFIG_ENABLEDSC', |
||
| 379 | 'formtype' => 'select', |
||
| 380 | 'valuetype' => 'int', |
||
| 381 | 'default' => XOOPS_NOTIFICATION_ENABLEBOTH, |
||
| 382 | 'options' => $options, |
||
| 383 | ]; |
||
| 384 | // Event-specific notification options |
||
| 385 | // FIXME: doesn't work when update module... can't read back the array of options properly... " changing to " |
||
| 386 | $options = []; |
||
| 387 | $categories = notificationCategoryInfo('', $module->getVar('mid')); |
||
| 388 | foreach ($categories as $category) { |
||
| 389 | $events = notificationEvents($category['name'], false, $module->getVar('mid')); |
||
| 390 | foreach ($events as $event) { |
||
| 391 | if (!empty($event['invisible'])) { |
||
| 392 | continue; |
||
| 393 | } |
||
| 394 | $option_name = $category['title'] . ' : ' . $event['title']; |
||
| 395 | $option_value = $category['name'] . '-' . $event['name']; |
||
| 396 | $options[$option_name] = $option_value; |
||
| 397 | } |
||
| 398 | unset($events); |
||
| 399 | } |
||
| 400 | unset($categories); |
||
| 401 | $configs[] = [ |
||
| 402 | 'name' => 'notification_events', |
||
| 403 | 'title' => '_NOT_CONFIG_EVENTS', |
||
| 404 | 'description' => '_NOT_CONFIG_EVENTSDSC', |
||
| 405 | 'formtype' => 'select_multi', |
||
| 406 | 'valuetype' => 'array', |
||
| 407 | 'default' => array_values($options), |
||
| 408 | 'options' => $options, |
||
| 409 | ]; |
||
| 410 | } |
||
| 411 | |||
| 412 | if (false !== $configs) { |
||
| 413 | $msgs[] = _AM_SYSTEM_MODULES_MODULE_DATA_ADD; |
||
| 414 | /** @var \XoopsConfigHandler $configHandler */ |
||
| 415 | $configHandler = xoops_getHandler('config'); |
||
| 416 | $order = 0; |
||
| 417 | foreach ($configs as $config) { |
||
| 418 | $confobj = $configHandler->createConfig(); |
||
| 419 | $confobj->setVar('conf_modid', $newmid); |
||
| 420 | $confobj->setVar('conf_catid', 0); |
||
| 421 | $confobj->setVar('conf_name', $config['name']); |
||
| 422 | $confobj->setVar('conf_title', $config['title'], true); |
||
| 423 | $confobj->setVar('conf_desc', $config['description'] ?? '', true); |
||
| 424 | $confobj->setVar('conf_formtype', $config['formtype']); |
||
| 425 | $confobj->setVar('conf_valuetype', $config['valuetype']); |
||
| 426 | $confobj->setConfValueForInput($config['default'], true); |
||
| 427 | $confobj->setVar('conf_order', $order); |
||
| 428 | $confop_msgs = ''; |
||
| 429 | if (isset($config['options']) && is_array($config['options'])) { |
||
| 430 | foreach ($config['options'] as $key => $value) { |
||
| 431 | $confop = $configHandler->createConfigOption(); |
||
| 432 | $confop->setVar('confop_name', $key, true); |
||
| 433 | $confop->setVar('confop_value', $value, true); |
||
| 434 | $confobj->setConfOptions($confop); |
||
| 435 | $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> '; |
||
| 436 | unset($confop); |
||
| 437 | } |
||
| 438 | } |
||
| 439 | ++$order; |
||
| 440 | if ($configHandler->insertConfig($confobj)) { |
||
| 441 | $msgs[] = ' ' . sprintf(_AM_SYSTEM_MODULES_CONFIG_DATA_ADD, '<strong>' . $config['name'] . '</strong>') . $confop_msgs; |
||
| 442 | } else { |
||
| 443 | $msgs[] = ' <span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_CONFIG_DATA_ADD_ERROR, '<strong>' . $config['name'] . '</strong>') . '</span>'; |
||
| 444 | } |
||
| 445 | unset($confobj); |
||
| 446 | } |
||
| 447 | unset($configs); |
||
| 448 | } |
||
| 449 | |||
| 450 | $groups = [XOOPS_GROUP_ADMIN]; |
||
| 451 | if ($module->getInfo('hasMain')) { |
||
| 452 | $groups = [XOOPS_GROUP_ADMIN, XOOPS_GROUP_USERS, XOOPS_GROUP_ANONYMOUS]; |
||
| 453 | } |
||
| 454 | // retrieve all block ids for this module |
||
| 455 | $blocks = \XoopsBlock::getByModule($newmid, false); |
||
| 456 | $msgs[] = _AM_SYSTEM_MODULES_GROUP_SETTINGS_ADD; |
||
| 457 | /** @var \XoopsGroupPermHandler $grouppermHandler */ |
||
| 458 | $grouppermHandler = xoops_getHandler('groupperm'); |
||
| 459 | foreach ($groups as $mygroup) { |
||
| 460 | if ($grouppermHandler->checkRight('module_admin', 0, $mygroup)) { |
||
| 461 | $mperm = $grouppermHandler->create(); |
||
| 462 | $mperm->setVar('gperm_groupid', $mygroup); |
||
| 463 | $mperm->setVar('gperm_itemid', $newmid); |
||
| 464 | $mperm->setVar('gperm_name', 'module_admin'); |
||
| 465 | $mperm->setVar('gperm_modid', 1); |
||
| 466 | if (!$grouppermHandler->insert($mperm)) { |
||
| 467 | $msgs[] = ' <span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_ACCESS_ADMIN_ADD_ERROR, '<strong>' . $mygroup . '</strong>') . '</span>'; |
||
| 468 | } else { |
||
| 469 | $msgs[] = ' ' . sprintf(_AM_SYSTEM_MODULES_ACCESS_ADMIN_ADD, '<strong>' . $mygroup . '</strong>'); |
||
| 470 | } |
||
| 471 | unset($mperm); |
||
| 472 | } |
||
| 473 | $mperm = $grouppermHandler->create(); |
||
| 474 | $mperm->setVar('gperm_groupid', $mygroup); |
||
| 475 | $mperm->setVar('gperm_itemid', $newmid); |
||
| 476 | $mperm->setVar('gperm_name', 'module_read'); |
||
| 477 | $mperm->setVar('gperm_modid', 1); |
||
| 478 | if (!$grouppermHandler->insert($mperm)) { |
||
| 479 | $msgs[] = ' <span style="color:#ff0000;">' . sprintf(_AM_SYSTEM_MODULES_ACCESS_USER_ADD_ERROR, '<strong>' . $mygroup . '</strong>') . '</span>'; |
||
| 480 | } else { |
||
| 481 | $msgs[] = ' ' . sprintf(_AM_SYSTEM_MODULES_ACCESS_USER_ADD_ERROR, '<strong>' . $mygroup . '</strong>'); |
||
| 482 | } |
||
| 483 | unset($mperm); |
||
| 484 | foreach ($blocks as $blc) { |
||
| 485 | $bperm = $grouppermHandler->create(); |
||
| 486 | $bperm->setVar('gperm_groupid', $mygroup); |
||
| 487 | $bperm->setVar('gperm_itemid', $blc); |
||
| 488 | $bperm->setVar('gperm_name', 'block_read'); |
||
| 489 | $bperm->setVar('gperm_modid', 1); |
||
| 490 | if (!$grouppermHandler->insert($bperm)) { |
||
| 491 | $msgs[] = ' <span style="color:#ff0000;">' . _AM_SYSTEM_MODULES_BLOCK_ACCESS_ERROR . ' Block ID: <strong>' . $blc . '</strong> Group ID: <strong>' . $mygroup . '</strong></span>'; |
||
| 492 | } else { |
||
| 493 | $msgs[] = ' ' . _AM_SYSTEM_MODULES_BLOCK_ACCESS . sprintf(_AM_SYSTEM_MODULES_BLOCK_ID, '<strong>' . $blc . '</strong>') . sprintf(_AM_SYSTEM_MODULES_GROUP_ID, '<strong>' . $mygroup . '</strong>'); |
||
| 494 | } |
||
| 495 | unset($bperm); |
||
| 496 | } |
||
| 497 | } |
||
| 498 | unset($blocks, $groups); |
||
| 499 | |||
| 500 | // execute module specific install script if any |
||
| 501 | $func = "xoops_module_install_{$dirname}"; |
||
| 502 | if (function_exists($func)) { |
||
| 503 | if (!$lastmsg = $func($module)) { |
||
| 504 | $msgs[] = '<p>' . sprintf(_AM_SYSTEM_MODULES_FAILED_EXECUTE, $func) . '</p>'; |
||
| 505 | } else { |
||
| 506 | $msgs[] = '<p>' . sprintf(_AM_SYSTEM_MODULES_FAILED_SUCESS, "<strong>{$func}</strong>") . '</p>'; |
||
| 507 | if (is_string($lastmsg)) { |
||
| 508 | $msgs[] = $lastmsg; |
||
| 509 | } |
||
| 510 | } |
||
| 511 | } |
||
| 512 | |||
| 513 | $msgs[] = sprintf(_AM_SYSTEM_MODULES_OKINS, '<strong>' . $module->getVar('name', 's') . '</strong>'); |
||
| 514 | $msgs[] = '</div></div>'; |
||
| 515 | |||
| 516 | $blocks = $module->getInfo('blocks'); |
||
| 517 | $msgs[] = '<div class="noininstall center"><a href="admin.php?fct=modulesadmin">' . _AM_SYSTEM_MODULES_BTOMADMIN . '</a> | |
||
| 518 | <a href="admin.php?fct=modulesadmin&op=installlist">' . _AM_SYSTEM_MODULES_TOINSTALL . '</a> | '; |
||
| 519 | $msgs[] = '<br><span class="red bold">' . _AM_SYSTEM_MODULES_MODULE . ' ' . $module->getInfo('name') . ': </span></div>'; |
||
| 520 | if (false !== $blocks) { |
||
| 521 | $msgs[] = '<div class="center"><a href="admin.php?fct=blocksadmin&op=list&filter=1&selgen=' . $newmid . '&selmod=-2&selgrp=-1&selvis=-1&filsave=1">' . _AM_SYSTEM_BLOCKS . '</a></div>'; |
||
| 522 | } |
||
| 523 | |||
| 524 | $msgs[] = '<div class="noininstall center"><a href="admin.php?fct=preferences&op=showmod&mod=' . $newmid . '">' . _AM_SYSTEM_PREF . '</a>'; |
||
| 525 | $msgs[] = '<a href="' . XOOPS_URL . '/modules/' . $module->getInfo('dirname', 'e') . '/' . $module->getInfo('adminindex') . '">' . _AM_SYSTEM_MODULES_ADMIN . '</a>'; |
||
| 526 | |||
| 527 | $testdataDirectory = XOOPS_ROOT_PATH . '/modules/' . $module->getInfo('dirname', 'e') . '/testdata'; |
||
| 528 | if (file_exists($testdataDirectory)) { |
||
| 529 | $msgs[] = '<a href="' . XOOPS_URL . '/modules/' . $module->getInfo('dirname', 'e') . '/testdata/index.php' . '">' . _AM_SYSTEM_MODULES_INSTALL_TESTDATA . '</a></div>'; |
||
| 530 | } else { |
||
| 531 | $msgs[] = '</div>'; |
||
| 532 | } |
||
| 533 | |||
| 534 | $ret = implode('<br>', $msgs); |
||
| 535 | unset($blocks, $msgs, $errs, $module); |
||
| 536 | |||
| 537 | return $ret; |
||
| 538 | } |
||
| 539 | $ret = '<p>' . sprintf(_AM_SYSTEM_MODULES_FAILINS, '<strong>' . $dirname . '</strong>') . ' ' . _AM_SYSTEM_MODULES_ERRORSC . '<br>' . implode('<br>', $errs) . '</p>'; |
||
| 540 | unset($msgs, $errs); |
||
| 541 | |||
| 542 | return $ret; |
||
| 543 | } |
||
| 544 | |||
| 545 | return '<p>' . sprintf(_AM_SYSTEM_MODULES_FAILINS, '<strong>' . $dirname . '</strong>') . ' ' . _AM_SYSTEM_MODULES_ERRORSC . '<br> ' . sprintf(_AM_SYSTEM_MODULES_ALEXISTS, $dirname) . '</p>'; |
||
| 546 | } |
||
| 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.