functions_mchat = $container->get('dmzx.mchat.functions_mchat'); $this->config = $config; $this->template = $template; $this->user = $user; $this->container = $container; $this->db = $db; $this->cache = $cache; $this->request = $request; $this->phpbb_extension_manager = $phpbb_extension_manager; $this->phpbb_root_path = $phpbb_root_path; $this->php_ext = $phpEx; $this->table_prefix = $container->getParameter('core.table_prefix'); $this->mchat_config_table = $mchat_config_table; $this->config_text = $container->get('config_text'); } /** * 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' => $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' => $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' => $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 . " SET config_value = '" . $this->db->sql_escape($config_value) . "' WHERE 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 .= ''; } $s_custom = false; $dateformat_options .= ''; $this->template->assign_vars(array( 'MCHAT_ERROR' => isset($error) ? ((sizeof($error)) ? implode('
', $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'], 'phpbb_root_path}index.$this->php_ext", 'i=bbcodes', true, $this->user->session_id) . '">', ''), 'L_MCHAT_TIMEOUT_EXPLAIN' => sprintf($this->user->lang['MCHAT_USER_TIMEOUT_EXPLAIN'],'phpbb_root_path}index.$this->php_ext", 'i=board&mode=load', true, $this->user->session_id) . '">', '', $this->config['session_length']), 'S_MCHAT_DATEFORMAT_OPTIONS' => $dateformat_options, 'S_CUSTOM_DATEFORMAT' => $s_custom, 'U_ACTION' => $this->u_action) ); // Version check $this->user->add_lang(array('install', 'acp/extensions', 'migrator')); $ext_name = 'dmzx/mchat'; $md_manager = new \phpbb\extension\metadata_manager($ext_name, $this->config, $this->phpbb_extension_manager, $this->template, $this->user, $this->phpbb_root_path); try { $this->metadata = $md_manager->get_metadata('all'); } catch(\phpbb\extension\exception $e) { trigger_error($e, E_USER_WARNING); } $md_manager->output_template_data(); try { $updates_available = $this->version_check($md_manager, $this->request->variable('versioncheck_force', false)); $this->template->assign_vars(array( 'S_UP_TO_DATE' => empty($updates_available), 'S_VERSIONCHECK' => true, 'UP_TO_DATE_MSG' => $this->user->lang(empty($updates_available) ? 'UP_TO_DATE' : 'NOT_UP_TO_DATE', $md_manager->get_metadata('display-name')), )); foreach ($updates_available as $branch => $version_data) { $this->template->assign_block_vars('updates_available', $version_data); } } catch (\RuntimeException $e) { $this->template->assign_vars(array( 'S_VERSIONCHECK_STATUS' => $e->getCode(), 'VERSIONCHECK_FAIL_REASON' => ($e->getMessage() !== $this->user->lang('VERSIONCHECK_FAIL')) ? $e->getMessage() : '', )); } } /** * Set the options a user can configure * * @return null * @access protected */ protected function set_options() { //update setting in config table for mod enabled or not $this->config->set('mchat_enable', $this->request->variable('mchat_enable', 0)); // update setting in config table for allowing on index or not $this->config->set('mchat_on_index', $this->request->variable('mchat_on_index', 0)); // update setting in config table to enable posts to display or not $this->config->set('mchat_new_posts', $this->request->variable('mchat_new_posts', 0)); // update setting in config table to allow topic to display or not $this->config->set('mchat_new_posts_topic', $this->request->variable('mchat_new_posts_topic', 0)); // update setting in config table to allow replies to display or not $this->config->set('mchat_new_posts_reply', $this->request->variable('mchat_new_posts_reply', 0)); // update setting in config table to allow edit posts to display or not $this->config->set('mchat_new_posts_edit', $this->request->variable('mchat_new_posts_edit', 0)); // update setting in config table to allow quoted posts to display or not $this->config->set('mchat_new_posts_quote', $this->request->variable('mchat_new_posts_quote', 0)); // update setting in config table for stats on index $this->config->set('mchat_stats_index', $this->request->variable('mchat_stats_index', 0)); // update setting in config table for message on top $this->config->set('mchat_message_top', $this->request->variable('mchat_message_top', 0)); } protected function version_check(\phpbb\extension\metadata_manager $md_manager, $force_update = false, $force_cache = false) { $meta = $md_manager->get_metadata('all'); if (!isset($meta['extra']['version-check'])) { throw new \RuntimeException($this->user->lang('NO_VERSIONCHECK'), 1); } $version_check = $meta['extra']['version-check']; $version_helper = new \phpbb\version_helper($this->cache, $this->config, new \phpbb\file_downloader(), $this->user); $version_helper->set_current_version($meta['version']); $version_helper->set_file_location($version_check['host'], $version_check['directory'], $version_check['filename']); $version_helper->force_stability($this->config['extension_force_unstable'] ? 'unstable' : null); return $updates = $version_helper->get_suggested_updates($force_update, $force_cache); } /** * Set page url * * @param string $u_action Custom form action * @return null * @access public */ public function set_page_url($u_action) { $this->u_action = $u_action; } }