public function move_prune_users_module() { $sql = 'SELECT module_id FROM ' . MODULES_TABLE . "\n\t\t\tWHERE module_class = 'acp'\n\t\t\t\tAND module_basename = 'acp_prune'\n\t\t\t\tAND module_mode = 'users'"; $result = $this->db->sql_query($sql); $acp_prune_users_id = (int) $this->db->sql_fetchfield('module_id'); $this->db->sql_freeresult($result); $sql = 'SELECT module_id FROM ' . MODULES_TABLE . "\n\t\t\tWHERE module_class = 'acp'\n\t\t\t\tAND module_langname = 'ACP_CAT_USERS'"; $result = $this->db->sql_query($sql); $acp_cat_users_id = (int) $this->db->sql_fetchfield('module_id'); $this->db->sql_freeresult($result); if (!class_exists('\\acp_modules')) { include $this->src_root_path . 'includes/acp/acp_modules.' . $this->php_ext; } $module_manager = new \acp_modules(); $module_manager->module_class = 'acp'; $module_manager->move_module($acp_prune_users_id, $acp_cat_users_id); }
public function setUp() { global $db; parent::setUp(); $this->phpbb_extension_manager = $this->get_extension_manager(); $this->phpbb_extension_manager->enable('foo/bar'); $modules = new acp_modules(); $db = $this->get_db(); $sql = 'SELECT module_id FROM ' . MODULES_TABLE . "\n\t\t\tWHERE module_langname = 'acp'\n\t\t\t\tAND module_class = 'ACP_CAT_DOT_MODS'"; $result = $db->sql_query($sql); $module_id = (int) $db->sql_fetchfield('module_id'); $db->sql_freeresult($result); $parent_data = array('module_basename' => '', 'module_enabled' => 1, 'module_display' => 1, 'parent_id' => $module_id, 'module_class' => 'acp', 'module_langname' => 'ACP_FOOBAR_TITLE', 'module_mode' => '', 'module_auth' => ''); $modules->update_module_data($parent_data, true); $module_data = array('module_basename' => 'foo\\bar\\acp\\main_module', 'module_enabled' => 1, 'module_display' => 1, 'parent_id' => $parent_data['module_id'], 'module_class' => 'acp', 'module_langname' => 'ACP_FOOBAR_TITLE', 'module_mode' => 'mode', 'module_auth' => ''); $modules->update_module_data($module_data, true); $parent_data = array('module_basename' => '', 'module_enabled' => 1, 'module_display' => 1, 'parent_id' => 0, 'module_class' => 'ucp', 'module_langname' => 'UCP_FOOBAR_TITLE', 'module_mode' => '', 'module_auth' => ''); $modules->update_module_data($parent_data, true); $module_data = array('module_basename' => 'foo\\bar\\ucp\\main_module', 'module_enabled' => 1, 'module_display' => 1, 'parent_id' => $parent_data['module_id'], 'module_class' => 'ucp', 'module_langname' => 'UCP_FOOBAR_TITLE', 'module_mode' => 'mode', 'module_auth' => ''); $modules->update_module_data($module_data, true); $this->purge_cache(); }
public function move_customise_modules() { // Move language management to new location in the Customise tab // First get language module id $sql = 'SELECT module_id FROM ' . MODULES_TABLE . "\n\t\t\tWHERE module_basename = 'acp_language'"; $result = $this->db->sql_query($sql); $language_module_id = $this->db->sql_fetchfield('module_id'); $this->db->sql_freeresult($result); // Next get language management module id of the one just created $sql = 'SELECT module_id FROM ' . MODULES_TABLE . "\n\t\t\tWHERE module_langname = 'ACP_LANGUAGE'"; $result = $this->db->sql_query($sql); $language_management_module_id = $this->db->sql_fetchfield('module_id'); $this->db->sql_freeresult($result); if (!class_exists('acp_modules')) { include $this->phpbb_root_path . 'includes/acp/acp_modules.' . $this->php_ext; } // acp_modules calls adm_back_link, which is undefined at this point if (!function_exists('adm_back_link')) { include $this->phpbb_root_path . 'includes/functions_acp.' . $this->php_ext; } $module_manager = new \acp_modules(); $module_manager->module_class = 'acp'; $module_manager->move_module($language_module_id, $language_management_module_id); }
/** * Populate the module tables */ function add_modules($mode, $sub) { global $db, $lang, $phpbb_root_path, $phpEx; include_once($phpbb_root_path . 'includes/acp/acp_modules.' . $phpEx); $_module = new acp_modules(); $module_classes = array('acp', 'mcp', 'ucp'); // Add categories foreach ($module_classes as $module_class) { $categories = array(); // Set the module class $_module->module_class = $module_class; foreach ($this->module_categories[$module_class] as $cat_name => $subs) { $module_data = array( 'module_basename' => '', 'module_enabled' => 1, 'module_display' => 1, 'parent_id' => 0, 'module_class' => $module_class, 'module_langname' => $cat_name, 'module_mode' => '', 'module_auth' => '', ); // Add category $_module->update_module_data($module_data, true); // Check for last sql error happened if ($db->sql_error_triggered) { $error = $db->sql_error($db->sql_error_sql); $this->p_master->db_error($error['message'], $db->sql_error_sql, __LINE__, __FILE__); } $categories[$cat_name]['id'] = (int) $module_data['module_id']; $categories[$cat_name]['parent_id'] = 0; // Create sub-categories... if (is_array($subs)) { foreach ($subs as $level2_name) { $module_data = array( 'module_basename' => '', 'module_enabled' => 1, 'module_display' => 1, 'parent_id' => (int) $categories[$cat_name]['id'], 'module_class' => $module_class, 'module_langname' => $level2_name, 'module_mode' => '', 'module_auth' => '', ); $_module->update_module_data($module_data, true); // Check for last sql error happened if ($db->sql_error_triggered) { $error = $db->sql_error($db->sql_error_sql); $this->p_master->db_error($error['message'], $db->sql_error_sql, __LINE__, __FILE__); } $categories[$level2_name]['id'] = (int) $module_data['module_id']; $categories[$level2_name]['parent_id'] = (int) $categories[$cat_name]['id']; } } } // Get the modules we want to add... returned sorted by name $module_info = $_module->get_module_infos('', $module_class); foreach ($module_info as $module_basename => $fileinfo) { foreach ($fileinfo['modes'] as $module_mode => $row) { foreach ($row['cat'] as $cat_name) { if (!isset($categories[$cat_name])) { continue; } $module_data = array( 'module_basename' => $module_basename, 'module_enabled' => 1, 'module_display' => (isset($row['display'])) ? (int) $row['display'] : 1, 'parent_id' => (int) $categories[$cat_name]['id'], 'module_class' => $module_class, 'module_langname' => $row['title'], 'module_mode' => $module_mode, 'module_auth' => $row['auth'], ); $_module->update_module_data($module_data, true); // Check for last sql error happened if ($db->sql_error_triggered) { $error = $db->sql_error($db->sql_error_sql); $this->p_master->db_error($error['message'], $db->sql_error_sql, __LINE__, __FILE__); } } } } // Move some of the modules around since the code above will put them in the wrong place if ($module_class == 'acp') { // Move main module 4 up... $sql = 'SELECT * FROM ' . MODULES_TABLE . " WHERE module_basename = 'main' AND module_class = 'acp' AND module_mode = 'main'"; $result = $db->sql_query($sql); $row = $db->sql_fetchrow($result); $db->sql_freeresult($result); $_module->move_module_by($row, 'move_up', 4); // Move permissions intro screen module 4 up... $sql = 'SELECT * FROM ' . MODULES_TABLE . " WHERE module_basename = 'permissions' AND module_class = 'acp' AND module_mode = 'intro'"; $result = $db->sql_query($sql); $row = $db->sql_fetchrow($result); $db->sql_freeresult($result); $_module->move_module_by($row, 'move_up', 4); // Move manage users screen module 5 up... $sql = 'SELECT * FROM ' . MODULES_TABLE . " WHERE module_basename = 'users' AND module_class = 'acp' AND module_mode = 'overview'"; $result = $db->sql_query($sql); $row = $db->sql_fetchrow($result); $db->sql_freeresult($result); $_module->move_module_by($row, 'move_up', 5); } if ($module_class == 'ucp') { // Move attachment module 4 down... $sql = 'SELECT * FROM ' . MODULES_TABLE . " WHERE module_basename = 'attachments' AND module_class = 'ucp' AND module_mode = 'attachments'"; $result = $db->sql_query($sql); $row = $db->sql_fetchrow($result); $db->sql_freeresult($result); $_module->move_module_by($row, 'move_down', 4); } // And now for the special ones // (these are modules which appear in multiple categories and thus get added manually to some for more control) if (isset($this->module_extras[$module_class])) { foreach ($this->module_extras[$module_class] as $cat_name => $mods) { $sql = 'SELECT module_id, left_id, right_id FROM ' . MODULES_TABLE . " WHERE module_langname = '" . $db->sql_escape($cat_name) . "' AND module_class = '" . $db->sql_escape($module_class) . "'"; $result = $db->sql_query_limit($sql, 1); $row2 = $db->sql_fetchrow($result); $db->sql_freeresult($result); foreach ($mods as $mod_name) { $sql = 'SELECT * FROM ' . MODULES_TABLE . " WHERE module_langname = '" . $db->sql_escape($mod_name) . "' AND module_class = '" . $db->sql_escape($module_class) . "' AND module_basename <> ''"; $result = $db->sql_query_limit($sql, 1); $row = $db->sql_fetchrow($result); $db->sql_freeresult($result); $module_data = array( 'module_basename' => $row['module_basename'], 'module_enabled' => (int) $row['module_enabled'], 'module_display' => (int) $row['module_display'], 'parent_id' => (int) $row2['module_id'], 'module_class' => $row['module_class'], 'module_langname' => $row['module_langname'], 'module_mode' => $row['module_mode'], 'module_auth' => $row['module_auth'], ); $_module->update_module_data($module_data, true); // Check for last sql error happened if ($db->sql_error_triggered) { $error = $db->sql_error($db->sql_error_sql); $this->p_master->db_error($error['message'], $db->sql_error_sql, __LINE__, __FILE__); } } } } $_module->remove_cache_file(); } }
/** * Wrapper for \acp_modules::get_module_infos() * * @param string $class Module Class * @param string $basename Module Basename * @return array Module Information * @throws \src\db\migration\exception */ protected function get_module_info($class, $basename) { if (!class_exists('acp_modules')) { include $this->src_root_path . 'includes/acp/acp_modules.' . $this->php_ext; $this->user->add_lang('acp/modules'); } $acp_modules = new \acp_modules(); $module = $acp_modules->get_module_infos($basename, $class, true); if (empty($module)) { throw new \src\db\migration\exception('MODULE_INFO_FILE_NOT_EXIST', $class, $basename); } return array_pop($module); }
function _add_modules($modules_to_install) { global $phpbb_root_path, $phpEx, $db; include_once($phpbb_root_path . 'includes/acp/acp_modules.' . $phpEx); $_module = new acp_modules(); foreach ($modules_to_install as $module_mode => $module_data) { $_module->module_class = $module_data['class']; // Determine parent id first $sql = 'SELECT module_id FROM ' . MODULES_TABLE . " WHERE module_class = '" . $db->sql_escape($module_data['class']) . "' AND module_langname = '" . $db->sql_escape($module_data['cat']) . "' AND module_mode = '' AND module_basename = ''"; $result = $db->sql_query($sql); // There may be more than one categories with the same name $categories = array(); while ($row = $db->sql_fetchrow($result)) { $categories[] = (int) $row['module_id']; } $db->sql_freeresult($result); if (!sizeof($categories)) { continue; } // Add the module to all categories found foreach ($categories as $parent_id) { // Check if the module already exists $sql = 'SELECT * FROM ' . MODULES_TABLE . " WHERE module_basename = '" . $db->sql_escape($module_data['base']) . "' AND module_class = '" . $db->sql_escape($module_data['class']) . "' AND module_langname = '" . $db->sql_escape($module_data['title']) . "' AND module_mode = '" . $db->sql_escape($module_mode) . "' AND module_auth = '" . $db->sql_escape($module_data['auth']) . "' AND parent_id = {$parent_id}"; $result = $db->sql_query($sql); $row = $db->sql_fetchrow($result); $db->sql_freeresult($result); // If it exists, we simply continue with the next category if ($row) { continue; } // Build the module sql row $module_row = array( 'module_basename' => $module_data['base'], 'module_enabled' => (isset($module_data['enabled'])) ? (int) $module_data['enabled'] : 1, 'module_display' => (isset($module_data['display'])) ? (int) $module_data['display'] : 1, 'parent_id' => $parent_id, 'module_class' => $module_data['class'], 'module_langname' => $module_data['title'], 'module_mode' => $module_mode, 'module_auth' => $module_data['auth'], ); $_module->update_module_data($module_row, true); // Ok, do we need to re-order the module, move it up or down? if (!isset($module_data['after'])) { continue; } $after_mode = $module_data['after'][0]; $after_langname = $module_data['after'][1]; // First of all, get the module id for the module this one has to be placed after $sql = 'SELECT left_id FROM ' . MODULES_TABLE . " WHERE module_class = '" . $db->sql_escape($module_data['class']) . "' AND module_basename = '" . $db->sql_escape($module_data['base']) . "' AND module_langname = '" . $db->sql_escape($after_langname) . "' AND module_mode = '" . $db->sql_escape($after_mode) . "' AND parent_id = '{$parent_id}'"; $result = $db->sql_query($sql); $first_left_id = (int) $db->sql_fetchfield('left_id'); $db->sql_freeresult($result); if (!$first_left_id) { continue; } // Ok, count the number of modules between $after_mode and the added module $sql = 'SELECT COUNT(module_id) as num_modules FROM ' . MODULES_TABLE . " WHERE module_class = '" . $db->sql_escape($module_data['class']) . "' AND parent_id = {$parent_id} AND left_id BETWEEN {$first_left_id} AND {$module_row['left_id']} GROUP BY left_id ORDER BY left_id"; $result = $db->sql_query($sql); $steps = (int) $db->sql_fetchfield('num_modules'); $db->sql_freeresult($result); // We need to substract 2 $steps -= 2; if ($steps <= 0) { continue; } // Ok, move module up $num_modules times. ;) $_module->move_module_by($module_row, 'move_up', $steps); } } $_module->remove_cache_file(); }
/** * Module Remove * * Remove a module * * @param string $class The module class(acp|mcp|ucp) * @param int|string|bool $parent The parent module_id|module_langname (0 for no parent). Use false to ignore the parent check and check class wide. * @param int|string $module The module id|module_langname * @param string|bool $include_path If you would like to use a custom include path, specify that here */ function module_remove($class, $parent = 0, $module = '', $include_path = false) { global $cache, $user, $phpbb_root_path, $phpEx; // Multicall if (is_array($class)) { foreach ($class as $params) { call_user_func_array(array($this, 'module_remove'), $params); } return; } // Allows '' to be sent $parent = !$parent ? 0 : $parent; // Imitation of module_add's "automatic" and "manual" method so the uninstaller works from the same set of instructions for umil_auto if (is_array($module)) { if (isset($module['module_langname'])) { // Manual Method return $this->module_remove($class, $parent, $module['module_langname'], $include_path); } // Failed. if (!isset($module['module_basename'])) { $this->umil_start('MODULE_REMOVE', $class, 'UNKNOWN'); return $this->umil_end('FAIL'); } // Automatic method $basename = str_replace(array('/', '\\'), '', $module['module_basename']); $class = str_replace(array('/', '\\'), '', $class); $info_file = "{$class}/info/{$class}_{$basename}.{$phpEx}"; if (!file_exists(($include_path === false ? $phpbb_root_path . 'includes/' : $include_path) . $info_file)) { $this->umil_start('MODULE_REMOVE', $class, $info_file); return $this->umil_end('FAIL'); } $classname = "{$class}_{$basename}_info"; if (!class_exists($classname)) { include ($include_path === false ? $phpbb_root_path . 'includes/' : $include_path) . $info_file; } $info = new $classname(); $module_info = $info->module(); unset($info); $result = ''; foreach ($module_info['modes'] as $mode => $info) { if (!isset($module['modes']) || in_array($mode, $module['modes'])) { $result .= $this->module_remove($class, $parent, $info['title']) . '<br />'; } } return $result; } else { $class = $this->db->sql_escape($class); if (!$this->module_exists($class, $parent, $module)) { $this->umil_start('MODULE_REMOVE', $class, isset($user->lang[$module]) ? $user->lang[$module] : $module); return $this->umil_end('MODULE_NOT_EXIST'); } $parent_sql = ''; if ($parent !== false) { if (!is_numeric($parent)) { $sql = 'SELECT module_id FROM ' . MODULES_TABLE . "\n\t\t\t\t\t\tWHERE module_langname = '" . $this->db->sql_escape($parent) . "'\n\t\t\t\t\t\tAND module_class = '{$class}'"; $result = $this->db->sql_query($sql); $row = $this->db->sql_fetchrow($result); $this->db->sql_freeresult($result); // we know it exists from the module_exists check $parent_sql = 'AND parent_id = ' . (int) $row['module_id']; } else { $parent_sql = 'AND parent_id = ' . (int) $parent; } } $module_ids = array(); if (!is_numeric($module)) { $module = $this->db->sql_escape($module); $sql = 'SELECT module_id FROM ' . MODULES_TABLE . "\n\t\t\t\t\tWHERE module_langname = '{$module}'\n\t\t\t\t\tAND module_class = '{$class}'\n\t\t\t\t\t{$parent_sql}"; $result = $this->db->sql_query($sql); while ($row = $this->db->sql_fetchrow($result)) { $module_ids[] = (int) $row['module_id']; } $this->db->sql_freeresult($result); $module_name = $module; } else { $module = (int) $module; $sql = 'SELECT module_langname FROM ' . MODULES_TABLE . "\n\t\t\t\t\tWHERE module_id = {$module}\n\t\t\t\t\tAND module_class = '{$class}'\n\t\t\t\t\t{$parent_sql}"; $result = $this->db->sql_query($sql); $row = $this->db->sql_fetchrow($result); $this->db->sql_freeresult($result); $module_name = $row['module_langname']; $module_ids[] = $module; } $this->umil_start('MODULE_REMOVE', $class, isset($user->lang[$module_name]) ? $user->lang[$module_name] : $module_name); add_log('admin', 'LOG_MODULE_REMOVED', isset($user->lang[$module_name]) ? $user->lang[$module_name] : $module_name); if (!class_exists('acp_modules')) { include $phpbb_root_path . 'includes/acp/acp_modules.' . $phpEx; $user->add_lang('acp/modules'); } $acp_modules = new acp_modules(); $acp_modules->module_class = $class; foreach ($module_ids as $module_id) { $result = $acp_modules->delete_module($module_id); if (!empty($result)) { if ($this->result == (isset($user->lang['SUCCESS']) ? $user->lang['SUCCESS'] : 'SUCCESS')) { $this->result = implode('<br />', $result); } else { $this->result .= '<br />' . implode('<br />', $result); } } } $cache->destroy("_modules_{$class}"); return $this->umil_end(); } }
function remove_module($module_id, $module_class) { global $user; $modules = new acp_modules(); $modules->module_class = $module_class; $failed = $modules->delete_module($module_id); }
$phpEx = substr(strrchr(__FILE__, '.'), 1); include $phpbb_root_path . 'common.' . $phpEx; /** * Setup user session, authorisation & language */ $user->session_begin(); $auth->acl($user->data); $user->setup('mods/garage'); //Get Mode Required For Page $mode = request_var('mode', ''); $page_title = 'Manage phpBB Garage Modules'; // Output the page page_header($page_title); $template->set_filenames(array('body' => 'message_body.html')); require $phpbb_root_path . 'includes/acp/acp_modules.' . $phpEx; $modules = new acp_modules(); //Decide What Mode The User Is Doing switch ($mode) { case 'add': //Lets Add Automatically The Modules $module_data = $errors = array(); //Define ACP Garage Module Categories $module_data[] = array('module_basename' => '', 'module_enabled' => '1', 'module_display' => '1', 'parent_id' => '24', 'module_class' => 'acp', 'module_langname' => 'ACP_GARAGE_SETTINGS', 'module_mode' => '', 'module_auth' => ''); $module_data[] = array('module_basename' => '', 'module_enabled' => '1', 'module_display' => '1', 'parent_id' => '24', 'module_class' => 'acp', 'module_langname' => 'ACP_GARAGE_MANAGEMENT', 'module_mode' => '', 'module_auth' => ''); //Define MCP Garage Module Categories $module_data[] = array('module_basename' => '', 'module_enabled' => '1', 'module_display' => '1', 'parent_id' => '0', 'module_class' => 'mcp', 'module_langname' => 'MCP_GARAGE', 'module_mode' => '', 'module_auth' => ''); //Define UCP Garage Module Categories $module_data[] = array('module_basename' => '', 'module_enabled' => '1', 'module_display' => '1', 'parent_id' => '0', 'module_class' => 'ucp', 'module_langname' => 'UCP_GARAGE', 'module_mode' => '', 'module_auth' => ''); //Create All Required Module Categories & Reset create_modules($module_data); $module_data = null;
/** * remove_modules */ function remove_modules($mode, $sub) { global $db, $user, $phpbb_root_path, $phpEx; if (!class_exists('acp_modules')) { require $phpbb_root_path . 'includes/acp/acp_modules.' . $phpEx; } $_module = new acp_modules(); // Set the module class $module_classes = array_keys($this->module_categories); $_module->u_action = "phpbb_seo_install.{$phpEx}"; $cat_module_data = array(); $module_data = array(); $delete_module_data = array(); foreach ($module_classes as $module_class) { $_module->module_class = $module_class; foreach ($this->module_categories[$module_class] as $cat_name => $subs) { // If the cat is already uninstalled break for now if ($this->get_module_id($cat_name) < 1) { $url_mod = !empty($this->sub) ? '?mode=' . $this->mode : ''; $this->p_master->error(sprintf($user->lang['SEO_ERROR_UNINSTALLED'], $user->lang[$cat_name]) . '<br /><br />' . sprintf($user->lang['RETURN_PAGE'], '<a href="' . $this->p_master->module_url . $url_mod . '">', '</a>'), '', '', false, $user->lang['SEO_ERROR_INFO']); } $cat_module_data[$cat_name] = array('module_id' => $this->check_module_id($cat_name), 'module_basename' => '', 'module_enabled' => 1, 'module_display' => 1, 'parent_id' => 0, 'module_class' => $module_class, 'module_langname' => $cat_name, 'module_mode' => '', 'module_auth' => ''); if (is_array($subs)) { foreach ($subs as $sub_cat) { $sub_cat_module_data[$sub_cat] = array('module_id' => $this->check_module_id($sub_cat), 'module_basename' => '', 'module_enabled' => 1, 'module_display' => 1, 'parent_id' => (int) $cat_module_data[$cat_name]['module_id'], 'module_class' => $module_class, 'module_langname' => $sub_cat, 'module_mode' => '', 'module_auth' => ''); $branch = $_module->get_module_branch($sub_cat_module_data[$sub_cat]['module_id'], 'children', 'descending', false); if (sizeof($branch)) { foreach ($branch as $module) { $error = $_module->delete_module($module['module_id']); if (!sizeof($error)) { $_module->remove_cache_file(); $delete_module_data[$module['module_id']] = $module['module_langname'] . ' - id : ' . $module['module_id']; } else { $this->errors[] = implode(' ', $error); } } // End modules } if (!sizeof($this->errors)) { $error = $_module->delete_module($sub_cat_module_data[$sub_cat]['module_id']); if (!sizeof($error)) { $_module->remove_cache_file(); $delete_module_data[$sub_cat_module_data[$sub_cat]['module_id']] = $sub_cat_module_data[$sub_cat]['module_langname'] . ' - id : ' . $sub_cat_module_data[$sub_cat]['module_id']; } else { $this->errors[] = implode(' ', $error); } } } } // End sub categories if (!sizeof($this->errors)) { $branch = $_module->get_module_branch($cat_module_data[$cat_name]['module_id'], 'children', 'descending', false); if (empty($branch)) { $error = $_module->delete_module($cat_module_data[$cat_name]['module_id']); } if (!sizeof($error)) { $_module->remove_cache_file(); $delete_module_data[$cat_module_data[$cat_name]['module_id']] = $cat_module_data[$cat_name]['module_langname'] . ' - id : ' . $cat_module_data[$cat_name]['module_id']; } else { $this->errors[] = implode(' ', $error); } } } // End categories } // End classes return; }
/** * Populate the module tables */ function add_modules($mode, $sub) { global $db, $lang, $phpbb_root_path, $phpEx, $phpbb_extension_manager, $config, $phpbb_container; // modules require an extension manager if (empty($phpbb_extension_manager)) { $phpbb_extension_manager = $phpbb_container->get('ext.manager'); } include_once $phpbb_root_path . 'includes/acp/acp_modules.' . $phpEx; $_module = new acp_modules(); $module_classes = array('acp', 'mcp', 'ucp'); // Add categories foreach ($module_classes as $module_class) { $categories = array(); // Set the module class $_module->module_class = $module_class; foreach ($this->module_categories[$module_class] as $cat_name => $subs) { $basename = ''; // Check if this sub-category has a basename. If it has, use it. if (isset($this->module_categories_basenames[$cat_name])) { $basename = $this->module_categories_basenames[$cat_name]; } $module_data = array('module_basename' => $basename, 'module_enabled' => 1, 'module_display' => 1, 'parent_id' => 0, 'module_class' => $module_class, 'module_langname' => $cat_name, 'module_mode' => '', 'module_auth' => ''); // Add category $_module->update_module_data($module_data, true); // Check for last sql error happened if ($db->get_sql_error_triggered()) { $error = $db->sql_error($db->get_sql_error_sql()); $this->p_master->db_error($error['message'], $db->get_sql_error_sql(), __LINE__, __FILE__); } $categories[$cat_name]['id'] = (int) $module_data['module_id']; $categories[$cat_name]['parent_id'] = 0; // Create sub-categories... if (is_array($subs)) { foreach ($subs as $level2_name) { $basename = ''; // Check if this sub-category has a basename. If it has, use it. if (isset($this->module_categories_basenames[$level2_name])) { $basename = $this->module_categories_basenames[$level2_name]; } $module_data = array('module_basename' => $basename, 'module_enabled' => 1, 'module_display' => 1, 'parent_id' => (int) $categories[$cat_name]['id'], 'module_class' => $module_class, 'module_langname' => $level2_name, 'module_mode' => '', 'module_auth' => ''); $_module->update_module_data($module_data, true); // Check for last sql error happened if ($db->get_sql_error_triggered()) { $error = $db->sql_error($db->get_sql_error_sql()); $this->p_master->db_error($error['message'], $db->get_sql_error_sql(), __LINE__, __FILE__); } $categories[$level2_name]['id'] = (int) $module_data['module_id']; $categories[$level2_name]['parent_id'] = (int) $categories[$cat_name]['id']; } } } // Get the modules we want to add... returned sorted by name $module_info = $_module->get_module_infos('', $module_class); foreach ($module_info as $module_basename => $fileinfo) { foreach ($fileinfo['modes'] as $module_mode => $row) { foreach ($row['cat'] as $cat_name) { if (!isset($categories[$cat_name])) { continue; } $module_data = array('module_basename' => $module_basename, 'module_enabled' => 1, 'module_display' => isset($row['display']) ? (int) $row['display'] : 1, 'parent_id' => (int) $categories[$cat_name]['id'], 'module_class' => $module_class, 'module_langname' => $row['title'], 'module_mode' => $module_mode, 'module_auth' => $row['auth']); $_module->update_module_data($module_data, true); // Check for last sql error happened if ($db->get_sql_error_triggered()) { $error = $db->sql_error($db->get_sql_error_sql()); $this->p_master->db_error($error['message'], $db->get_sql_error_sql(), __LINE__, __FILE__); } } } } // Move some of the modules around since the code above will put them in the wrong place if ($module_class == 'acp') { // Move main module 4 up... $sql = 'SELECT * FROM ' . MODULES_TABLE . "\n\t\t\t\t\tWHERE module_basename = 'acp_main'\n\t\t\t\t\t\tAND module_class = 'acp'\n\t\t\t\t\t\tAND module_mode = 'main'"; $result = $db->sql_query($sql); $row = $db->sql_fetchrow($result); $db->sql_freeresult($result); $_module->move_module_by($row, 'move_up', 4); // Move permissions intro screen module 4 up... $sql = 'SELECT * FROM ' . MODULES_TABLE . "\n\t\t\t\t\tWHERE module_basename = 'acp_permissions'\n\t\t\t\t\t\tAND module_class = 'acp'\n\t\t\t\t\t\tAND module_mode = 'intro'"; $result = $db->sql_query($sql); $row = $db->sql_fetchrow($result); $db->sql_freeresult($result); $_module->move_module_by($row, 'move_up', 4); // Move manage users screen module 5 up... $sql = 'SELECT * FROM ' . MODULES_TABLE . "\n\t\t\t\t\tWHERE module_basename = 'acp_users'\n\t\t\t\t\t\tAND module_class = 'acp'\n\t\t\t\t\t\tAND module_mode = 'overview'"; $result = $db->sql_query($sql); $row = $db->sql_fetchrow($result); $db->sql_freeresult($result); $_module->move_module_by($row, 'move_up', 5); // Move extension management module 1 up... $sql = 'SELECT * FROM ' . MODULES_TABLE . "\n\t\t\t\t\tWHERE module_langname = 'ACP_EXTENSION_MANAGEMENT'\n\t\t\t\t\t\tAND module_class = 'acp'\n\t\t\t\t\t\tAND module_mode = ''\n\t\t\t\t\t\tAND module_basename = ''"; $result = $db->sql_query($sql); $row = $db->sql_fetchrow($result); $db->sql_freeresult($result); $_module->move_module_by($row, 'move_up', 1); } if ($module_class == 'mcp') { // Move pm report details module 3 down... $sql = 'SELECT * FROM ' . MODULES_TABLE . "\n\t\t\t\t\tWHERE module_basename = 'mcp_pm_reports'\n\t\t\t\t\t\tAND module_class = 'mcp'\n\t\t\t\t\t\tAND module_mode = 'pm_report_details'"; $result = $db->sql_query($sql); $row = $db->sql_fetchrow($result); $db->sql_freeresult($result); $_module->move_module_by($row, 'move_down', 3); // Move closed pm reports module 3 down... $sql = 'SELECT * FROM ' . MODULES_TABLE . "\n\t\t\t\t\tWHERE module_basename = 'mcp_pm_reports'\n\t\t\t\t\t\tAND module_class = 'mcp'\n\t\t\t\t\t\tAND module_mode = 'pm_reports_closed'"; $result = $db->sql_query($sql); $row = $db->sql_fetchrow($result); $db->sql_freeresult($result); $_module->move_module_by($row, 'move_down', 3); // Move open pm reports module 3 down... $sql = 'SELECT * FROM ' . MODULES_TABLE . "\n\t\t\t\t\tWHERE module_basename = 'mcp_pm_reports'\n\t\t\t\t\t\tAND module_class = 'mcp'\n\t\t\t\t\t\tAND module_mode = 'pm_reports'"; $result = $db->sql_query($sql); $row = $db->sql_fetchrow($result); $db->sql_freeresult($result); $_module->move_module_by($row, 'move_down', 3); } if ($module_class == 'ucp') { // Move attachment module 4 down... $sql = 'SELECT * FROM ' . MODULES_TABLE . "\n\t\t\t\t\tWHERE module_basename = 'ucp_attachments'\n\t\t\t\t\t\tAND module_class = 'ucp'\n\t\t\t\t\t\tAND module_mode = 'attachments'"; $result = $db->sql_query($sql); $row = $db->sql_fetchrow($result); $db->sql_freeresult($result); $_module->move_module_by($row, 'move_down', 4); // Move notification options module 4 down... $sql = 'SELECT * FROM ' . MODULES_TABLE . "\n\t\t\t\t\tWHERE module_basename = 'ucp_notifications'\n\t\t\t\t\t\tAND module_class = 'ucp'\n\t\t\t\t\t\tAND module_mode = 'notification_options'"; $result = $db->sql_query($sql); $row = $db->sql_fetchrow($result); $db->sql_freeresult($result); $_module->move_module_by($row, 'move_down', 4); // Move OAuth module 5 down... $sql = 'SELECT * FROM ' . MODULES_TABLE . "\n\t\t\t\t\tWHERE module_basename = 'ucp_auth_link'\n\t\t\t\t\t\tAND module_class = 'ucp'\n\t\t\t\t\t\tAND module_mode = 'auth_link'"; $result = $db->sql_query($sql); $row = $db->sql_fetchrow($result); $db->sql_freeresult($result); $_module->move_module_by($row, 'move_down', 5); } // And now for the special ones // (these are modules which appear in multiple categories and thus get added manually to some for more control) if (isset($this->module_extras[$module_class])) { foreach ($this->module_extras[$module_class] as $cat_name => $mods) { $sql = 'SELECT module_id, left_id, right_id FROM ' . MODULES_TABLE . "\n\t\t\t\t\t\tWHERE module_langname = '" . $db->sql_escape($cat_name) . "'\n\t\t\t\t\t\t\tAND module_class = '" . $db->sql_escape($module_class) . "'"; $result = $db->sql_query_limit($sql, 1); $row2 = $db->sql_fetchrow($result); $db->sql_freeresult($result); foreach ($mods as $mod_name) { $sql = 'SELECT * FROM ' . MODULES_TABLE . "\n\t\t\t\t\t\t\tWHERE module_langname = '" . $db->sql_escape($mod_name) . "'\n\t\t\t\t\t\t\t\tAND module_class = '" . $db->sql_escape($module_class) . "'\n\t\t\t\t\t\t\t\tAND module_basename <> ''"; $result = $db->sql_query_limit($sql, 1); $row = $db->sql_fetchrow($result); $db->sql_freeresult($result); $module_data = array('module_basename' => $row['module_basename'], 'module_enabled' => (int) $row['module_enabled'], 'module_display' => (int) $row['module_display'], 'parent_id' => (int) $row2['module_id'], 'module_class' => $row['module_class'], 'module_langname' => $row['module_langname'], 'module_mode' => $row['module_mode'], 'module_auth' => $row['module_auth']); $_module->update_module_data($module_data, true); // Check for last sql error happened if ($db->get_sql_error_triggered()) { $error = $db->sql_error($db->get_sql_error_sql()); $this->p_master->db_error($error['message'], $db->get_sql_error_sql(), __LINE__, __FILE__); } } } } $_module->remove_cache_file(); } }
/** * Delete ALL phpBB Garage Data */ function delete_garage_data($mode, $sub) { global $cache, $db, $phpbb_root_path, $phpEx, $table_prefix, $lang, $template; $this->page_title = $lang['STAGE_OPTIONAL']; //Setup $auth_admin class so we can remove permission options include $phpbb_root_path . '/includes/acp/auth.' . $phpEx; include $phpbb_root_path . '/includes/acp/acp_modules.' . $phpEx; $auth_admin = new auth_admin(); $module_admin = new acp_modules(); // lets get rid of phpBB Garage internal data first foreach ($this->garage_tables as $table) { $db->sql_query('DROP TABLE ' . $table_prefix . $table); } // lets get rid of phpBB Garage internal data first if ($db->sql_layer == 'postgres') { foreach ($this->garage_postgres_sequences as $sequence) { $db->sql_query('DROP SEQUENCE ' . $table_prefix . $sequence); } } // next for the chop is permisions we added foreach ($this->garage_permissions as $permission) { // get auth option id so we can remove it from any user, group or role $sql = $db->sql_build_query('SELECT', array('SELECT' => 'acl.auth_option_id', 'FROM' => array(ACL_OPTIONS_TABLE => 'acl'), 'WHERE' => "acl.auth_option = '{$permission}'")); $result = $db->sql_query($sql); $auth_option_id = (int) $db->sql_fetchfield('auth_option_id'); $db->sql_freeresult($result); // remove option from user $db->sql_query('DELETE FROM ' . ACL_USERS_TABLE . " WHERE auth_option_id = " . $auth_option_id); // remove option from group $db->sql_query('DELETE FROM ' . ACL_GROUPS_TABLE . " WHERE auth_option_id = " . $auth_option_id); // remove option from role $db->sql_query('DELETE FROM ' . ACL_ROLES_DATA_TABLE . " WHERE auth_option_id = " . $auth_option_id); // remove option itself now $db->sql_query('DELETE FROM ' . ACL_OPTIONS_TABLE . " WHERE auth_option_id = " . $auth_option_id); } // next for the chop is imageset data we added foreach ($this->garage_imageset as $image_name) { $db->sql_query('DELETE FROM ' . STYLES_IMAGESET_DATA_TABLE . " WHERE image_name = '" . $image_name . "'"); } // clear permissions cache now we have handled them all $cache->destroy('_acl_options'); $auth_admin->acl_clear_prefetch(); // next into the slaughter house is modules we added foreach ($this->garage_modules as $module_name => $module_class) { // get module id so we can remove it $sql = $db->sql_build_query('SELECT', array('SELECT' => 'm.*', 'FROM' => array(MODULES_TABLE => 'm'), 'WHERE' => "m.module_langname = '{$module_name}'\n\t\t\t\t\t\t\tAND m.module_class = '{$module_class}'")); // module may have been installed in multiple places per class ... delete them all $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { $module_id = (int) $row['module_id']; $branch = $module_admin->get_module_branch($module_id, 'children', 'descending', false); if (sizeof($branch)) { return array($user->lang['CANNOT_REMOVE_MODULE']); } // If not move $diff = 2; $sql = 'DELETE FROM ' . MODULES_TABLE . "\n\t\t\t\t\tWHERE module_class = '" . $module_class . "'\n\t\t\t\t\t\tAND module_id = {$module_id}"; $db->sql_query($sql); $row['right_id'] = (int) $row['right_id']; $row['left_id'] = (int) $row['left_id']; // Resync tree $sql = 'UPDATE ' . MODULES_TABLE . "\n\t\t\t\t\tSET right_id = right_id - {$diff}\n\t\t\t\t\tWHERE module_class = '" . $module_class . "'\n\t\t\t\t\t\tAND left_id < {$row['right_id']} AND right_id > {$row['right_id']}"; $db->sql_query($sql); $sql = 'UPDATE ' . MODULES_TABLE . "\n\t\t\t\t\tSET left_id = left_id - {$diff}, right_id = right_id - {$diff}\n\t\t\t\t\tWHERE module_class = '" . $module_class . "'\n\t\t\t\t\t\tAND left_id > {$row['right_id']}"; $db->sql_query($sql); } $db->sql_freeresult($result); } // module categories ... be no more foreach ($this->garage_module_categories as $module_category => $module_class) { // get module id so we can remove it $sql = $db->sql_build_query('SELECT', array('SELECT' => 'm.*', 'FROM' => array(MODULES_TABLE => 'm'), 'WHERE' => "m.module_langname = '{$module_category}'\n\t\t\t\t\t\t\tAND m.module_class = '{$module_class}'")); // we can only delete the categories we created... $result = $db->sql_query($sql); $row = $db->sql_fetchrow($result); $db->sql_freeresult($result); $module_id = (int) $row['module_id']; $branch = $module_admin->get_module_branch($module_id, 'children', 'descending', false); if (sizeof($branch)) { return array($user->lang['CANNOT_REMOVE_MODULE']); } // If not move $diff = 2; $sql = 'DELETE FROM ' . MODULES_TABLE . "\n\t\t\t\tWHERE module_class = '" . $module_class . "'\n\t\t\t\t\tAND module_id = {$module_id}"; $db->sql_query($sql); $row['right_id'] = (int) $row['right_id']; $row['left_id'] = (int) $row['left_id']; // Resync tree $sql = 'UPDATE ' . MODULES_TABLE . "\n\t\t\t\tSET right_id = right_id - {$diff}\n\t\t\t\tWHERE module_class = '" . $module_class . "'\n\t\t\t\t\tAND left_id < {$row['right_id']} AND right_id > {$row['right_id']}"; $db->sql_query($sql); $sql = 'UPDATE ' . MODULES_TABLE . "\n\t\t\t\tSET left_id = left_id - {$diff}, right_id = right_id - {$diff}\n\t\t\t\tWHERE module_class = '" . $module_class . "'\n\t\t\t\t\tAND left_id > {$row['right_id']}"; $db->sql_query($sql); } // clear module cache now we have handled them all $module_admin->remove_cache_file(); // and finally step forward data in $config foreach ($this->config_data as $config_data) { $db->sql_query('DELETE FROM ' . CONFIG_TABLE . " WHERE config_name = '{$config_data}'"); } $submit = $lang['NEXT_STEP']; $url = $this->p_master->module_url . "?mode={$mode}&sub=file_check"; $template->assign_vars(array('BODY' => $lang['STAGE_DATA_EXPLAIN'], 'L_SUBMIT' => $submit, 'U_ACTION' => $url)); }
function remove_modules() { $modules_to_delete = array('ACP_WPU_CATOTHER' => array('ACP_WPU_UNINSTALL', 'ACP_WPU_RESET', 'ACP_WPU_DEBUG'), 'ACP_WPU_CATSUPPORT' => array('ACP_WPU_DONATE'), 'ACP_WPU_CATMANAGE' => array('ACP_WPU_USERMAP', 'ACP_WPU_PERMISSIONS'), 'ACP_WPU_CATSETUP' => array('ACP_WPU_DETAILED', 'ACP_WPU_WIZARD'), 'ACP_WPU_CATMAIN' => array('ACP_WPU_MAINTITLE')); $cats = array('ACP_WPU_CATOTHER', 'ACP_WPU_CATSUPPORT', 'ACP_WPU_CATMANAGE', 'ACP_WPU_CATSETUP', 'ACP_WPU_CATMAIN'); $acp_modules = new acp_modules(); $acp_modules->module_class = 'acp'; $mainTab = $this->module_exists('ACP_WP_UNITED', 0); if ($mainTab) { //remove modules foreach ($modules_to_delete as $cat => $modules) { if ($parent = $this->module_exists($cat, $mainTab)) { foreach ($modules as $module) { if ($id = $this->module_exists($module, $parent)) { $errors .= $acp_modules->delete_module($id); } } //remove cat $errors .= $acp_modules->delete_module($parent); } } //remove main tab $acp_modules->delete_module($mainTab); } $acp_modules->remove_cache_file(); return $errors; }