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