/** * Delete module * * @param int|string $id Module ID of the acp_portal module * @param string $mode Mode of the acp_portal module * @param string $action Current action of the acp_portal module * @param int $module_id ID of the module that should be deleted */ public function module_delete($id, $mode, $action, $module_id) { $module_data = $this->get_move_module_data($module_id); if ($module_data !== false) { $module_classname = $this->request->variable('module_classname', ''); $this->get_module($module_data['module_classname']); if (confirm_box(true)) { $this->module->uninstall($module_data['module_id'], $this->db); $sql = 'DELETE FROM ' . PORTAL_MODULES_TABLE . ' WHERE module_id = ' . (int) $module_id; $this->db->sql_query($sql); $sql = 'UPDATE ' . PORTAL_MODULES_TABLE . ' SET module_order = module_order - 1 WHERE module_column = ' . (int) $module_data['module_column'] . ' AND module_order > ' . (int) $module_data['module_order']; $this->db->sql_query($sql); $this->cache->purge(); // make sure we don't get errors after re-adding a module // Handle ajax request $this->handle_ajax_request(array('success' => true, 'MESSAGE_TITLE' => $this->user->lang['INFORMATION'], 'MESSAGE_TEXT' => $this->user->lang['SUCCESS_DELETE'])); trigger_error($this->user->lang['SUCCESS_DELETE'] . adm_back_link($this->u_action)); } else { if ($this->module->get_language()) { $this->controller_helper->load_module_language($this->module); } $confirm_text = isset($this->user->lang[$module_data['module_name']]) ? sprintf($this->user->lang['DELETE_MODULE_CONFIRM'], $this->user->lang[$module_data['module_name']]) : sprintf($this->user->lang['DELETE_MODULE_CONFIRM'], utf8_normalize_nfc($module_data['module_name'])); confirm_box(false, $confirm_text, build_hidden_fields(array('i' => $id, 'mode' => $mode, 'action' => $action, 'module_id' => $module_id, 'module_classname' => $module_classname))); } } $this->cache->destroy('sql', PORTAL_MODULES_TABLE); }
/** * Permission Remove * * Remove a permission (auth) option * * @param string $auth_option The name of the permission (auth) option * @param bool $global True for checking a global permission setting, * False for a local permission setting * @return null */ public function remove($auth_option, $global = true) { if (!$this->exists($auth_option, $global)) { return; } if ($global) { $type_sql = ' AND is_global = 1'; } else { $type_sql = ' AND is_local = 1'; } $sql = 'SELECT auth_option_id, is_global, is_local FROM ' . ACL_OPTIONS_TABLE . "\n\t\t\tWHERE auth_option = '" . $this->db->sql_escape($auth_option) . "'" . $type_sql; $result = $this->db->sql_query($sql); $row = $this->db->sql_fetchrow($result); $this->db->sql_freeresult($result); $id = (int) $row['auth_option_id']; // If it is a local and global permission, do not remove the row! :P if ($row['is_global'] && $row['is_local']) { $sql = 'UPDATE ' . ACL_OPTIONS_TABLE . ' SET ' . ($global ? 'is_global = 0' : 'is_local = 0') . ' WHERE auth_option_id = ' . $id; $this->db->sql_query($sql); } else { // Delete time $tables = array(ACL_GROUPS_TABLE, ACL_ROLES_DATA_TABLE, ACL_USERS_TABLE, ACL_OPTIONS_TABLE); foreach ($tables as $table) { $this->db->sql_query('DELETE FROM ' . $table . ' WHERE auth_option_id = ' . $id); } } // Purge the auth cache $this->cache->destroy('_acl_options'); $this->auth->acl_clear_prefetch(); }
/** * Purge all notifications of a certain type * * This should be called when an extension which has notification types * is purged so that all those notifications are removed * * @param string $notification_type_name Type identifier of the subscription */ public function purge_notifications($notification_type_name) { // If a notification is never used, its type will not be added to the database // nor its id cached. If this method is called by an extension during the // purge step, and that extension never used its notifications, // get_notification_type_id() will throw an exception. However, // because no notification type was added to the database, // there is nothing to delete, so we can silently drop the exception. try { $notification_type_id = $this->get_notification_type_id($notification_type_name); $sql = 'DELETE FROM ' . $this->notifications_table . ' WHERE notification_type_id = ' . (int) $notification_type_id; $this->db->sql_query($sql); $sql = 'DELETE FROM ' . $this->notification_types_table . ' WHERE notification_type_id = ' . (int) $notification_type_id; $this->db->sql_query($sql); $this->cache->destroy('notification_type_ids'); } catch (\phpbb\notification\exception $e) { // Continue } }
/** * 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 * specify that here * @return null * @throws \phpbb\db\migration\exception */ public function remove($class, $parent = 0, $module = '') { // 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->remove($class, $parent, $module['module_langname']); } // Failed. if (!isset($module['module_basename'])) { throw new \phpbb\db\migration\exception('MODULE_NOT_EXIST'); } // Automatic method $basename = $module['module_basename']; $module_info = $this->get_module_info($class, $basename); foreach ($module_info['modes'] as $mode => $info) { if (!isset($module['modes']) || in_array($mode, $module['modes'])) { $this->remove($class, $parent, $info['title']); } } } else { if (!$this->exists($class, $parent, $module)) { return; } $parent_sql = ''; if ($parent !== false) { // Allows '' to be sent as 0 $parent = $parent ?: 0; if (!is_numeric($parent)) { $sql = 'SELECT module_id FROM ' . $this->modules_table . "\n\t\t\t\t\t\tWHERE module_langname = '" . $this->db->sql_escape($parent) . "'\n\t\t\t\t\t\t\tAND module_class = '" . $this->db->sql_escape($class) . "'"; $result = $this->db->sql_query($sql); $module_id = $this->db->sql_fetchfield('module_id'); $this->db->sql_freeresult($result); // we know it exists from the module_exists check $parent_sql = 'AND parent_id = ' . (int) $module_id; } else { $parent_sql = 'AND parent_id = ' . (int) $parent; } } $module_ids = array(); if (!is_numeric($module)) { $sql = 'SELECT module_id FROM ' . $this->modules_table . "\n\t\t\t\t\tWHERE module_langname = '" . $this->db->sql_escape($module) . "'\n\t\t\t\t\t\tAND module_class = '" . $this->db->sql_escape($class) . "'\n\t\t\t\t\t\t{$parent_sql}"; $result = $this->db->sql_query($sql); while ($module_id = $this->db->sql_fetchfield('module_id')) { $module_ids[] = (int) $module_id; } $this->db->sql_freeresult($result); } else { $module_ids[] = (int) $module; } foreach ($module_ids as $module_id) { $this->module_manager->delete_module($module_id, $class); } $this->cache->destroy("_modules_{$class}"); } }
/** * Set points config value. Creates missing config entry. */ function set_points_config($config_name, $config_value, $is_dynamic = false) { $sql = 'UPDATE ' . $this->points_config_table . "\n\t\t\t\tSET config_value = '" . $this->db->sql_escape($config_value) . "'\n\t\t\t\tWHERE config_name = '" . $this->db->sql_escape($config_name) . "'"; $this->db->sql_query($sql); if (!$this->db->sql_affectedrows() && !isset($points_config[$config_name])) { $sql = 'INSERT INTO ' . $this->points_config_table . ' ' . $this->db->sql_build_array('INSERT', array('config_name' => $config_name, 'config_value' => $config_value, 'is_dynamic' => $is_dynamic ? 1 : 0)); $this->db->sql_query($sql); } $points_config[$config_name] = $config_value; if (!$is_dynamic) { $this->cache->destroy('config'); } }
/** * Update cat table * * @return null */ public function update() { if (!check_form_key($this->form_key)) { $this->update = false; $this->errors[] = $this->user->lang['FORM_INVALID']; } switch ($this->action) { case 'delete': $action_subcats = $this->request->variable('action_subcats', ''); $subcats_to_id = $this->request->variable('subcats_to_id', 0); $action_links = $this->request->variable('action_links', ''); $links_to_id = $this->request->variable('links_to_id', 0); try { $this->errors = $this->_delete_cat($action_links, $action_subcats, $links_to_id, $subcats_to_id); } catch (\Exception $e) { trigger_error($e->getMessage(), E_USER_WARNING); } if (sizeof($this->errors)) { break; } $this->cache->destroy('sql', DIR_CAT_TABLE); trigger_error($this->user->lang['DIR_CAT_DELETED'] . adm_back_link($this->u_action . '&parent_id=' . $this->parent_id)); break; case 'edit': $this->cat_data = array('cat_id' => $this->cat_id); // No break here // No break here case 'add': $this->cat_data += array('parent_id' => $this->request->variable('cat_parent_id', (int) $this->parent_id), 'cat_parents' => '', 'cat_name' => $this->request->variable('cat_name', '', true), 'cat_desc' => $this->request->variable('cat_desc', '', true), 'cat_desc_uid' => '', 'cat_desc_options' => 7, 'cat_desc_bitfield' => '', 'cat_icon' => $this->request->variable('cat_icon', ''), 'display_subcat_list' => $this->request->variable('display_on_index', false), 'cat_allow_comments' => $this->request->variable('allow_comments', 1), 'cat_allow_votes' => $this->request->variable('allow_votes', 1), 'cat_must_describe' => $this->request->variable('must_describe', 1), 'cat_count_all' => $this->request->variable('count_all', 0), 'cat_validate' => $this->request->variable('validate', 0), 'cat_link_back' => $this->request->variable('link_back', 0), 'cat_cron_enable' => $this->request->variable('cron_enable', 0), 'cat_cron_freq' => $this->request->variable('cron_every', 7), 'cat_cron_nb_check' => $this->request->variable('nb_check', 1)); // Get data for cat description if specified if ($this->cat_data['cat_desc']) { generate_text_for_storage($this->cat_data['cat_desc'], $this->cat_data['cat_desc_uid'], $this->cat_data['cat_desc_bitfield'], $this->cat_data['cat_desc_options'], $this->request->variable('desc_parse_bbcode', false), $this->request->variable('desc_parse_urls', false), $this->request->variable('desc_parse_smilies', false)); } try { $this->errors = $this->_update_cat_data(); } catch (\Exception $e) { trigger_error($e->getMessage(), E_USER_WARNING); } if (!sizeof($this->errors)) { $this->cache->destroy('sql', DIR_CAT_TABLE); $message = $this->action == 'add' ? $this->user->lang['DIR_CAT_CREATED'] : $this->user->lang['DIR_CAT_UPDATED']; trigger_error($message . adm_back_link($this->u_action . '&parent_id=' . $this->parent_id)); } break; } }
/** * Delete a flag * * @param int $flag_id The flag identifier to delete * @return null * @access public */ public function delete_flag($flag_id) { if (confirm_box(true)) { // Grab the flag name for the log... $sql = 'SELECT flag_name, flag_image FROM ' . $this->flags_table . ' WHERE flag_id = ' . (int) $flag_id; $result = $this->db->sql_query($sql); $flag_row = $this->db->sql_fetchrow($result); $this->db->sql_freeresult($result); // Delete the flag... $sql = 'DELETE FROM ' . $this->flags_table . ' WHERE flag_id = ' . (int) $flag_id; $this->db->sql_query($sql); // Reset the flag for users $sql = 'UPDATE ' . USERS_TABLE . ' SET user_flag = 0 WHERE user_flag = ' . (int) $flag_id; $this->db->sql_query($sql); $log = $this->container->get('log'); $log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_FLAGS_DELETED', time(), array($flag_row['flag_name'])); $this->cache->destroy('_user_flags'); $this->functions->cache_flags(); trigger_error($this->user->lang['MSG_FLAGS_DELETED'] . adm_back_link($this->u_action . "&mode=manage")); } else { // display a count of users who have this flag $sql = 'SELECT COUNT(user_flag) AS flag_count FROM ' . USERS_TABLE . ' WHERE user_flag = ' . (int) $flag_id; $result = $this->db->sql_query($sql); $row = $this->db->sql_fetchrow($result); $this->db->sql_freeresult($result); $message = $this->user->lang['MSG_CONFIRM']; if (!empty($row['flag_count'])) { $message .= $row['flag_count'] != 1 ? $this->user->lang('MSG_FLAGS_CONFIRM_DELETE', $row['flag_count']) : $this->user->lang('MSG_FLAG_CONFIRM_DELETE', $row['flag_count']); } confirm_box(false, $message, build_hidden_fields(array('id' => (int) $flag_id, 'mode' => 'manage', 'action' => 'delete'))); // Use a redirect to take the user back to the previous page // if the user chose not delete the flag from the confirmation page. redirect("{$this->u_action}"); } }
/** * Display the options a user can configure for this extension * * @return null * @access public */ public function display_options() { add_form_key('acp_mchat'); $mchat_row = array('location' => $this->request->variable('mchat_location', 0), 'refresh' => $this->request->variable('mchat_refresh', 0), 'message_limit' => $this->request->variable('mchat_message_limit', 0), 'message_num' => $this->request->variable('mchat_message_num', 0), 'archive_limit' => $this->request->variable('mchat_archive_limit', 0), 'flood_time' => $this->request->variable('mchat_flood_time', 0), 'max_message_lngth' => $this->request->variable('mchat_max_message_lngth', 0), 'custom_page' => $this->request->variable('mchat_custom_page', 0), 'date' => $this->request->variable('mchat_date', '', true), 'whois' => $this->request->variable('mchat_whois', 0), 'whois_refresh' => $this->request->variable('mchat_whois_refresh', 0), 'bbcode_disallowed' => utf8_normalize_nfc($this->request->variable('mchat_bbcode_disallowed', '', true)), 'prune_enable' => $this->request->variable('mchat_prune_enable', 0), 'prune_num' => $this->request->variable('mchat_prune_num', 0), 'index_height' => $this->request->variable('mchat_index_height', 0), 'custom_height' => $this->request->variable('mchat_custom_height', 0), 'static_message' => utf8_normalize_nfc($this->request->variable('mchat_static_message', '', true)), 'override_min_post_chars' => $this->request->variable('mchat_override_min_post_chars', 0), 'override_smilie_limit' => $this->request->variable('mchat_override_smilie_limit', 0), 'timeout' => $this->request->variable('mchat_timeout', 0), 'pause_on_input' => $this->request->variable('mchat_pause_on_input', 0), 'rules' => utf8_normalize_nfc($this->request->variable('mchat_rules', '', true)), 'avatars' => $this->request->variable('mchat_avatars', 0)); if ($this->request->is_set_post('submit')) { if (!function_exists('validate_data')) { include $this->phpbb_root_path . 'includes/functions_user.' . $this->php_ext; } // validate the entries...most of them anyway $mchat_array = array('static_message' => array('string', false, 0, 255), 'index_height' => array('num', false, 50, 1000), 'custom_height' => array('num', false, 50, 1000), 'whois_refresh' => array('num', false, 30, 300), 'refresh' => array('num', false, 5, 60), 'message_limit' => array('num', false, 10, 30), 'message_num' => array('num', false, 10, 50), 'archive_limit' => array('num', false, 25, 50), 'flood_time' => array('num', false, 0, 30), 'max_message_lngth' => array('num', false, 0, 500), 'timeout' => array('num', false, 0, (int) $this->config['session_length']), 'rules' => array('string', false, 0, 255)); $error = validate_data($mchat_row, $mchat_array); if (!check_form_key('acp_mchat')) { $error[] = 'FORM_INVALID'; } // Replace "error" strings with their real, localised form $error = preg_replace('#^([A-Z_]+)$#e', "(!empty(\$this->user->lang['\\1'])) ? \$this->user->lang['\\1'] : '\\1'", $error); if (!sizeof($error)) { foreach ($mchat_row as $config_name => $config_value) { $sql = 'UPDATE ' . $this->mchat_config_table . "\n\t\t\t\t\t\tSET config_value = '" . $this->db->sql_escape($config_value) . "'\n\t\t\t\t\t\tWHERE config_name = '" . $this->db->sql_escape($config_name) . "'"; $this->db->sql_query($sql); } // Set the options the user configured $this->set_options(); // and an entry into the log table $log = $this->container->get('log'); $log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_MCHAT_CONFIG_UPDATE'); // purge the cache $this->cache->destroy('_mchat_config'); // rebuild the cache $this->functions_mchat->mchat_cache(); trigger_error($this->user->lang['MCHAT_CONFIG_SAVED'] . adm_back_link($this->u_action)); } } // let's get it on $sql = 'SELECT * FROM ' . $this->mchat_config_table; $result = $this->db->sql_query($sql); $mchat_config = array(); while ($row = $this->db->sql_fetchrow($result)) { $mchat_config[$row['config_name']] = $row['config_value']; } $this->db->sql_freeresult($result); $mchat_enable = isset($this->config['mchat_enable']) ? $this->config['mchat_enable'] : 0; $mchat_on_index = isset($this->config['mchat_on_index']) ? $this->config['mchat_on_index'] : 0; $mchat_version = isset($this->config['mchat_version']) ? $this->config['mchat_version'] : ''; $mchat_new_posts = isset($this->config['mchat_new_posts']) ? $this->config['mchat_new_posts'] : 0; $mchat_new_posts_topic = isset($this->config['mchat_new_posts_topic']) ? $this->config['mchat_new_posts_topic'] : 0; $mchat_new_posts_reply = isset($this->config['mchat_new_posts_reply']) ? $this->config['mchat_new_posts_reply'] : 0; $mchat_new_posts_edit = isset($this->config['mchat_new_posts_edit']) ? $this->config['mchat_new_posts_edit'] : 0; $mchat_new_posts_quote = isset($this->config['mchat_new_posts_quote']) ? $this->config['mchat_new_posts_quote'] : 0; $mchat_stats_index = isset($this->config['mchat_stats_index']) ? $this->config['mchat_stats_index'] : 0; $mchat_message_top = isset($this->config['mchat_message_top']) ? $this->config['mchat_message_top'] : 0; $dateformat_options = ''; foreach ($this->user->lang['dateformats'] as $format => $null) { $dateformat_options .= '<option value="' . $format . '"' . ($format == $mchat_config['date'] ? ' selected="selected"' : '') . '>'; $dateformat_options .= $this->user->format_date(time(), $format, false) . (strpos($format, '|') !== false ? $this->user->lang['VARIANT_DATE_SEPARATOR'] . $this->user->format_date(time(), $format, true) : ''); $dateformat_options .= '</option>'; } $s_custom = false; $dateformat_options .= '<option value="custom"'; if (!isset($this->user->lang['dateformats'][$mchat_config['date']])) { $dateformat_options .= ' selected="selected"'; $s_custom = true; } $dateformat_options .= '>' . $this->user->lang['MCHAT_CUSTOM_DATEFORMAT'] . '</option>'; $this->template->assign_vars(array('MCHAT_ERROR' => isset($error) ? sizeof($error) ? implode('<br />', $error) : '' : '', 'MCHAT_VERSION' => $mchat_version, 'MCHAT_PRUNE' => !empty($mchat_row['prune_enable']) ? $mchat_row['prune_enable'] : $mchat_config['prune_enable'], 'MCHAT_PRUNE_NUM' => !empty($mchat_row['prune_num']) ? $mchat_row['prune_num'] : $mchat_config['prune_num'], 'MCHAT_ENABLE' => $mchat_enable ? true : false, 'MCHAT_ON_INDEX' => $mchat_on_index ? true : false, 'MCHAT_MESSAGE_TOP' => $mchat_message_top ? true : false, 'MCHAT_LOCATION' => !empty($mchat_row['location']) ? $mchat_row['location'] : $mchat_config['location'], 'MCHAT_REFRESH' => !empty($mchat_row['refresh']) ? $mchat_row['refresh'] : $mchat_config['refresh'], 'MCHAT_WHOIS_REFRESH' => !empty($mchat_row['whois_refresh']) ? $mchat_row['whois_refresh'] : $mchat_config['whois_refresh'], 'MCHAT_MESSAGE_LIMIT' => !empty($mchat_row['message_limit']) ? $mchat_row['message_limit'] : $mchat_config['message_limit'], 'MCHAT_MESSAGE_NUM' => !empty($mchat_row['message_num']) ? $mchat_row['message_num'] : $mchat_config['message_num'], 'MCHAT_ARCHIVE_LIMIT' => !empty($mchat_row['archive_limit']) ? $mchat_row['archive_limit'] : $mchat_config['archive_limit'], 'MCHAT_AVATARS' => !empty($mchat_row['avatars']) ? $mchat_row['avatars'] : $mchat_config['avatars'], 'MCHAT_FLOOD_TIME' => !empty($mchat_row['flood_time']) ? $mchat_row['flood_time'] : $mchat_config['flood_time'], 'MCHAT_MAX_MESSAGE_LNGTH' => !empty($mchat_row['max_message_lngth']) ? $mchat_row['max_message_lngth'] : $mchat_config['max_message_lngth'], 'MCHAT_CUSTOM_PAGE' => !empty($mchat_row['custom_page']) ? $mchat_row['custom_page'] : $mchat_config['custom_page'], 'MCHAT_DATE' => !empty($mchat_row['date']) ? $mchat_row['date'] : $mchat_config['date'], 'MCHAT_DEFAULT_DATEFORMAT' => $this->config['default_dateformat'], 'MCHAT_RULES' => !empty($mchat_row['rules']) ? $mchat_row['rules'] : $mchat_config['rules'], 'MCHAT_WHOIS' => !empty($mchat_row['whois']) ? $mchat_row['whois'] : $mchat_config['whois'], 'MCHAT_STATS_INDEX' => $mchat_stats_index ? true : false, 'MCHAT_BBCODE_DISALLOWED' => !empty($mchat_row['bbcode_disallowed']) ? $mchat_row['bbcode_disallowed'] : $mchat_config['bbcode_disallowed'], 'MCHAT_STATIC_MESSAGE' => !empty($mchat_row['static_message']) ? $mchat_row['static_message'] : $mchat_config['static_message'], 'MCHAT_INDEX_HEIGHT' => !empty($mchat_row['index_height']) ? $mchat_row['index_height'] : $mchat_config['index_height'], 'MCHAT_CUSTOM_HEIGHT' => !empty($mchat_row['custom_height']) ? $mchat_row['custom_height'] : $mchat_config['custom_height'], 'MCHAT_OVERRIDE_SMILIE_LIMIT' => !empty($mchat_row['override_smilie_limit']) ? $mchat_row['override_smilie_limit'] : $mchat_config['override_smilie_limit'], 'MCHAT_OVERRIDE_MIN_POST_CHARS' => !empty($mchat_row['override_min_post_chars']) ? $mchat_row['override_min_post_chars'] : $mchat_config['override_min_post_chars'], 'MCHAT_TIMEOUT' => !empty($mchat_row['timeout']) ? $mchat_row['timeout'] : $mchat_config['timeout'], 'MCHAT_NEW_POSTS' => $mchat_new_posts ? true : false, 'MCHAT_NEW_POSTS_TOPIC' => $mchat_new_posts_topic ? true : false, 'MCHAT_NEW_POSTS_REPLY' => $mchat_new_posts_reply ? true : false, 'MCHAT_NEW_POSTS_EDIT' => $mchat_new_posts_edit ? true : false, 'MCHAT_NEW_POSTS_QUOTE' => $mchat_new_posts_quote ? true : false, 'MCHAT_PAUSE_ON_INPUT' => !empty($mchat_row['pause_on_input']) ? $mchat_row['pause_on_input'] : $mchat_config['pause_on_input'], 'L_MCHAT_BBCODES_DISALLOWED_EXPLAIN' => sprintf($this->user->lang['MCHAT_BBCODES_DISALLOWED_EXPLAIN'], '<a href="' . append_sid("{$this->phpbb_root_path}index.{$this->php_ext}", 'i=bbcodes', true, $this->user->session_id) . '">', '</a>'), 'L_MCHAT_TIMEOUT_EXPLAIN' => sprintf($this->user->lang['MCHAT_USER_TIMEOUT_EXPLAIN'], '<a href="' . append_sid("{$this->phpbb_root_path}index.{$this->php_ext}", 'i=board&mode=load', true, $this->user->session_id) . '">', '</a>', $this->config['session_length']), 'S_MCHAT_DATEFORMAT_OPTIONS' => $dateformat_options, 'S_CUSTOM_DATEFORMAT' => $s_custom, 'U_ACTION' => $this->u_action)); }