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