/** * Assigns whois and stats at the bottom of the index page */ protected function assign_whois() { if ($this->config['mchat_whois'] || $this->config['mchat_stats_index'] && $this->user->data['user_mchat_stats_index']) { $mchat_stats = $this->functions_mchat->mchat_active_users(); $this->template->assign_vars(array('MCHAT_INDEX_STATS' => $this->config['mchat_stats_index'] && $this->user->data['user_mchat_stats_index'], 'MCHAT_USERS_COUNT' => $mchat_stats['mchat_users_count'], 'MCHAT_USERS_LIST' => !empty($mchat_stats['online_userlist']) ? $mchat_stats['online_userlist'] : '', 'MCHAT_ONLINE_EXPLAIN' => $mchat_stats['refresh_message'])); } }
function main($id, $mode) { global $cache, $config, $db, $user, $auth, $template, $phpbb_root_path, $phpEx, $request; global $phpbb_container; $this->functions_mchat = $phpbb_container->get('dmzx.mchat.functions_mchat'); // $user->add_lang('mods/mchat_lang'); $submit = isset($_POST['submit']) ? true : false; $error = $data = array(); switch ($mode) { case 'configuration': $data = array('user_mchat_index' => $request->variable('user_mchat_index', (bool) $user->data['user_mchat_index']), 'user_mchat_sound' => $request->variable('user_mchat_sound', (bool) $user->data['user_mchat_sound']), 'user_mchat_stats_index' => $request->variable('user_mchat_stats_index', (bool) $user->data['user_mchat_stats_index']), 'user_mchat_topics' => $request->variable('user_mchat_topics', (bool) $user->data['user_mchat_topics']), 'user_mchat_avatars' => $request->variable('user_mchat_avatars', (bool) $user->data['user_mchat_avatars']), 'user_mchat_input_area' => $request->variable('user_mchat_input_area', (bool) $user->data['user_mchat_input_area'])); add_form_key('ucp_mchat'); if ($submit) { if (!check_form_key('ucp_mchat')) { $error[] = 'FORM_INVALID'; } if (!sizeof($error)) { $sql_ary = array('user_mchat_index' => $data['user_mchat_index'], 'user_mchat_sound' => $data['user_mchat_sound'], 'user_mchat_stats_index' => $data['user_mchat_stats_index'], 'user_mchat_topics' => $data['user_mchat_topics'], 'user_mchat_avatars' => $data['user_mchat_avatars'], 'user_mchat_input_area' => $data['user_mchat_input_area']); if (sizeof($sql_ary)) { $sql = 'UPDATE ' . USERS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . ' WHERE user_id = ' . (int) $user->data['user_id']; $db->sql_query($sql); } meta_refresh(3, $this->u_action); $message = $user->lang['PROFILE_UPDATED'] . '<br /><br />' . sprintf($user->lang['RETURN_UCP'], '<a href="' . $this->u_action . '">', '</a>'); trigger_error($message); } // Replace "error" strings with their real, localised form $error = preg_replace('#^([A-Z_]+)$#e', "(!empty(\$user->lang['\\1'])) ? \$user->lang['\\1'] : '\\1'", $error); } if (($mchat_cache = $cache->get('_mchat_config')) === false) { $this->functions_mchat->mchat_cache(); } $mchat_cache = $cache->get('_mchat_config'); $template->assign_vars(array('ERROR' => sizeof($error) ? implode('<br />', $error) : '', 'S_DISPLAY_MCHAT' => $data['user_mchat_index'], 'S_SOUND_MCHAT' => $data['user_mchat_sound'], 'S_STATS_MCHAT' => $data['user_mchat_stats_index'], 'S_TOPICS_MCHAT' => $data['user_mchat_topics'], 'S_AVATARS_MCHAT' => $data['user_mchat_avatars'], 'S_INPUT_MCHAT' => $data['user_mchat_input_area'], 'S_MCHAT_TOPICS' => $config['mchat_new_posts'], 'S_MCHAT_INDEX' => $config['mchat_on_index'] || $config['mchat_stats_index'] ? true : false, 'S_MCHAT_AVATARS' => $mchat_cache['avatars'])); break; } $template->assign_vars(array('L_TITLE' => $user->lang['UCP_PROFILE_MCHAT'], 'S_UCP_ACTION' => $this->u_action)); // Set desired template $this->tpl_name = 'ucp_mchat'; $this->page_title = 'UCP_PROFILE_MCHAT'; }
/** * Method to render the page data * * @var bool Bool if the rendering is only for index * @return array Data for page rendering */ public function render_data_for_page($only_for_index = false) { $include_on_index = $only_for_index === true; // Add lang file $this->user->add_lang('posting'); //chat enabled if (!$this->config['mchat_enable']) { trigger_error($this->user->lang['MCHAT_ENABLE'], E_USER_NOTICE); } // avatars if (!function_exists('get_user_avatar')) { include $this->phpbb_root_path . 'includes/functions_display.' . $this->phpEx; } if (($this->config_mchat = $this->cache->get('_mchat_config')) === false) { $this->functions_mchat->mchat_cache(); } $this->config_mchat = $this->cache->get('_mchat_config'); // Access rights $mchat_allow_bbcode = $this->config['allow_bbcode'] && $this->auth->acl_get('u_mchat_bbcode') ? true : false; $mchat_smilies = $this->config['allow_smilies'] && $this->auth->acl_get('u_mchat_smilies') ? true : false; $mchat_urls = $this->config['allow_post_links'] && $this->auth->acl_get('u_mchat_urls') ? true : false; $mchat_ip = $this->auth->acl_get('u_mchat_ip') ? true : false; $mchat_pm = $this->auth->acl_get('u_mchat_pm') ? true : false; $mchat_like = $this->auth->acl_get('u_mchat_like') ? true : false; $mchat_quote = $this->auth->acl_get('u_mchat_quote') ? true : false; $mchat_add_mess = $this->auth->acl_get('u_mchat_use') ? true : false; $mchat_view = $this->auth->acl_get('u_mchat_view') ? true : false; $mchat_no_flood = $this->auth->acl_get('u_mchat_flood_ignore') ? true : false; $mchat_read_archive = $this->auth->acl_get('u_mchat_archive') ? true : false; $mchat_founder = $this->user->data['user_type'] == USER_FOUNDER ? true : false; $mchat_session_time = !empty($this->config_mchat['timeout']) ? $this->config_mchat['timeout'] : (!empty($this->config['load_online_time']) ? $this->config['load_online_time'] * 60 : $this->config['session_length']); $mchat_rules = !empty($this->config_mchat['rules']) || isset($this->user->lang[strtoupper('mchat_rules')]) ? true : false; $mchat_avatars = !empty($this->config_mchat['avatars']) && $this->user->optionget('viewavatars') && $this->user->data['user_mchat_avatars'] ? true : false; // needed variables // Request options. $mchat_mode = $this->request->variable('mode', ''); $mchat_read_mode = $mchat_archive_mode = $mchat_custom_page = $mchat_no_message = false; // set redirect if on index or custom page $on_page = $include_on_index ? 'index' : 'mchat'; // grab fools..uhmmm, foes the user has $foes_array = array(); $sql = 'SELECT * FROM ' . ZEBRA_TABLE . ' WHERE user_id = ' . $this->user->data['user_id'] . ' AND foe = 1'; $result = $this->db->sql_query($sql); while ($row = $this->db->sql_fetchrow($result)) { $foes_array[] = $row['zebra_id']; } $this->db->sql_freeresult($result); // Request mode... switch ($mchat_mode) { // rules popup.. case 'rules': // If the rules are defined in the language file use them, else just use the entry in the database if ($mchat_rules || isset($this->user->lang[strtoupper('mchat_rules')])) { if (isset($this->user->lang[strtoupper('mchat_rules')])) { $this->template->assign_var('MCHAT_RULES', $this->user->lang[strtoupper('mchat_rules')]); } else { $mchat_rules = $this->config_mchat['rules']; $mchat_rules = explode("\n", $mchat_rules); foreach ($mchat_rules as $mchat_rule) { $mchat_rule = utf8_htmlspecialchars($mchat_rule); $this->template->assign_block_vars('rule', array('MCHAT_RULE' => $mchat_rule)); } } // Output the page // Return for: \$this->helper->render(filename, lang_title); return array('filename' => 'mchat_rules.html', 'lang_title' => $this->user->lang['MCHAT_HELP']); } else { // Show no rules trigger_error('MCHAT_NO_RULES', E_USER_NOTICE); } break; // whois function.. // whois function.. case 'whois': // Must have auths if ($mchat_mode == 'whois' && $mchat_ip) { // function already exists.. if (!function_exists('user_ipwhois')) { include $this->phpbb_root_path . 'includes/functions_user.' . $this->phpEx; } $this->user_ip = $this->request->variable('ip', ''); $this->template->assign_var('WHOIS', user_ipwhois($this->user_ip)); // Output the page // Return for: \$this->helper->render(filename, lang_title); return array('filename' => 'viewonline_whois.html', 'lang_title' => $this->user->lang['WHO_IS_ONLINE']); } else { // Show not authorized trigger_error('NO_AUTH_OPERATION', E_USER_NOTICE); } break; // Clean function... // Clean function... case 'clean': // User logged in? if (!$this->user->data['is_registered'] || !$mchat_founder) { if (!$this->user->data['is_registered']) { // Login box... login_box('', $this->user->lang['LOGIN']); } else { if (!$mchat_founder) { // Show not authorized trigger_error('NO_AUTH_OPERATION', E_USER_NOTICE); } } } $mchat_redirect = $this->request->variable('redirect', ''); $mchat_redirect = $mchat_redirect == 'index' ? append_sid("{$this->phpbb_root_path}index.{$this->phpEx}") : $this->helper->route('dmzx_mchat_controller', array('#mChat')); if (confirm_box(true)) { // Run cleaner $sql = 'TRUNCATE TABLE ' . $this->mchat_table; $this->db->sql_query($sql); meta_refresh(3, $mchat_redirect); trigger_error($this->user->lang['MCHAT_CLEANED'] . '<br /><br />' . sprintf($this->user->lang['RETURN_PAGE'], '<a href="' . $mchat_redirect . '">', '</a>')); } else { // Display confirm box confirm_box(false, $this->user->lang['MCHAT_DELALLMESS']); } $this->phpbb_log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_MCHAT_TABLE_PRUNED'); redirect($mchat_redirect); break; // Archive function... // Archive function... case 'archive': if (!$mchat_read_archive || !$mchat_view) { // redirect to correct page $mchat_redirect = append_sid("{$this->phpbb_root_path}index.{$this->phpEx}"); // Redirect to previous page meta_refresh(3, $mchat_redirect); trigger_error($this->user->lang['MCHAT_NOACCESS_ARCHIVE'] . '<br /><br />' . sprintf($this->user->lang['RETURN_PAGE'], '<a href="' . $mchat_redirect . '">', '</a>')); } if ($this->config['mchat_enable'] && $mchat_read_archive && $mchat_view) { // how many chats do we have? $sql = 'SELECT COUNT(message_id) AS messages FROM ' . $this->mchat_table; $result = $this->db->sql_query($sql); $mchat_total_messages = $this->db->sql_fetchfield('messages'); $this->db->sql_freeresult($result); // prune the chats if necessary and amount in ACP not empty if ($this->config_mchat['prune_enable'] && ($mchat_total_messages > $this->config_mchat['prune_num'] && $this->config_mchat['prune_num'] > 0)) { $this->functions_mchat->mchat_prune((int) $this->config_mchat['prune_num']); } // Reguest... $mchat_archive_start = $this->request->variable('start', 0); $sql_where = $this->user->data['user_mchat_topics'] ? '' : 'WHERE m.forum_id = 0'; // Message row $sql = 'SELECT m.*, u.username, u.user_colour, u.user_avatar, u.user_avatar_type, u.user_avatar_width, u.user_avatar_height, u.user_allow_pm FROM ' . $this->mchat_table . ' m LEFT JOIN ' . USERS_TABLE . ' u ON m.user_id = u.user_id ' . $sql_where . ' ORDER BY m.message_id DESC'; $result = $this->db->sql_query_limit($sql, (int) $this->config_mchat['archive_limit'], $mchat_archive_start); $rows = $this->db->sql_fetchrowset($result); $this->db->sql_freeresult($result); foreach ($rows as $row) { // auth check if ($row['forum_id'] != 0 && !$this->auth->acl_get('f_read', $row['forum_id'])) { continue; } // edit, delete and permission auths $mchat_ban = $this->auth->acl_get('a_authusers') && $this->user->data['user_id'] != $row['user_id'] ? true : false; $mchat_edit = $this->auth->acl_get('u_mchat_edit') && ($this->auth->acl_get('m_') || $this->user->data['user_id'] == $row['user_id']) ? true : false; $mchat_del = $this->auth->acl_get('u_mchat_delete') && ($this->auth->acl_get('m_') || $this->user->data['user_id'] == $row['user_id']) ? true : false; $mchat_avatar = $row['user_avatar'] ? get_user_avatar($row['user_avatar'], $row['user_avatar_type'], $row['user_avatar_width'] > $row['user_avatar_height'] ? 40 : 40 / $row['user_avatar_height'] * $row['user_avatar_width'], $row['user_avatar_height'] > $row['user_avatar_width'] ? 40 : 40 / $row['user_avatar_width'] * $row['user_avatar_height']) : ''; $message_edit = $row['message']; decode_message($message_edit, $row['bbcode_uid']); $message_edit = str_replace('"', '"', $message_edit); // Edit Fix ;) if (sizeof($foes_array)) { if (in_array($row['user_id'], $foes_array)) { $row['message'] = sprintf($this->user->lang['MCHAT_FOE'], get_username_string('full', $row['user_id'], $row['username'], $row['user_colour'], $this->user->lang['GUEST'])); } } $row['username'] = mb_ereg_replace("'", "’", $row['username']); $this->template->assign_block_vars('mchatrow', array('MCHAT_ALLOW_BAN' => $mchat_ban, 'MCHAT_ALLOW_EDIT' => $mchat_edit, 'MCHAT_ALLOW_DEL' => $mchat_del, 'MCHAT_USER_AVATAR' => $mchat_avatar, 'U_VIEWPROFILE' => $row['user_id'] != ANONYMOUS ? append_sid("{$this->phpbb_root_path}memberlist.{$this->phpEx}", 'mode=viewprofile&u=' . $row['user_id']) : '', 'U_USER_IDS' => $row['user_id'] != ANONYMOUS && $this->user->data['user_id'] != $row['user_id'] ? append_sid("{$this->phpbb_root_path}ucp.{$this->phpEx}", 'i=pm&mode=compose&u=' . $row['user_id']) : '', 'BOT_USER_ID' => $row['user_id'] != '1', 'U_USER_ID' => $row['user_id'] != ANONYMOUS && $this->config['allow_privmsg'] && $this->auth->acl_get('u_sendpm') && $this->user->data['user_id'] != $row['user_id'] && $row['user_id'] != '1' && ($row['user_allow_pm'] || $this->auth->acl_gets('a_', 'm_') || $this->auth->acl_getf_global('m_')) ? append_sid("{$this->phpbb_root_path}ucp.{$this->phpEx}", 'i=pm&mode=compose&u=' . $row['user_id']) : '', 'MCHAT_MESSAGE_EDIT' => $message_edit, 'MCHAT_MESSAGE_ID' => $row['message_id'], 'MCHAT_USERNAME_FULL' => get_username_string('full', $row['user_id'], $row['username'], $row['user_colour'], $this->user->lang['GUEST']), 'MCHAT_USERNAME' => get_username_string('username', $row['user_id'], $row['username'], $row['user_colour'], $this->user->lang['GUEST']), 'MCHAT_USERNAME_COLOR' => get_username_string('colour', $row['user_id'], $row['username'], $row['user_colour'], $this->user->lang['GUEST']), 'MCHAT_USER_IP' => $row['user_ip'], 'MCHAT_U_WHOIS' => $this->helper->route('dmzx_mchat_controller', array('mode' => 'whois', 'ip' => $row['user_ip'])), 'MCHAT_U_BAN' => append_sid("{$this->phpbb_root_path}adm/index.{$this->phpEx}", 'i=permissions&mode=setting_user_global&user_id[0]=' . $row['user_id'], true, $this->user->session_id), 'MCHAT_MESSAGE' => generate_text_for_display($row['message'], $row['bbcode_uid'], $row['bbcode_bitfield'], $row['bbcode_options']), 'MCHAT_TIME' => $this->user->format_date($row['message_time'], $this->config_mchat['date']), 'MCHAT_CLASS' => $row['message_id'] % 2 ? 1 : 2)); } // Write no message if (empty($rows)) { $mchat_no_message = true; } } // Run query again to get the total message rows... $sql = 'SELECT COUNT(message_id) AS mess_id FROM ' . $this->mchat_table; $result = $this->db->sql_query($sql); $mchat_total_message = $this->db->sql_fetchfield('mess_id'); $this->db->sql_freeresult($result); // Page list function... $pagination_url = $this->helper->route('dmzx_mchat_controller', array('mode' => 'archive')); $start = $this->request->variable('start', 0); $this->pagination->generate_template_pagination($pagination_url, 'pagination', 'start', $mchat_total_message, (int) $this->config_mchat['archive_limit'], $mchat_archive_start); $this->template->assign_vars(array('MCHAT_TOTAL_MESSAGES' => sprintf($this->user->lang['MCHAT_TOTALMESSAGES'], $mchat_total_message))); //add to navlinks $this->template->assign_block_vars('navlinks', array('FORUM_NAME' => $this->user->lang['MCHAT_ARCHIVE_PAGE'], 'U_VIEW_FORUM' => $this->helper->route('dmzx_mchat_controller', array('mode' => 'archive')))); // If archive mode request set true $mchat_archive_mode = true; $old_mode = 'archive'; break; // Read function... // Read function... case 'read': // If mChat disabled or user can't view the chat if (!$this->config['mchat_enable'] || !$mchat_view) { // Forbidden (for jQ AJAX request) throw new \phpbb\exception\http_exception(403, 'MCHAT_ERROR_FORBIDDEN'); } // if we're reading on the custom page, then we are chatting if ($mchat_custom_page) { // insert user into the mChat sessions table $this->functions_mchat->mchat_sessions($mchat_session_time, true); } // Request $mchat_message_last_id = $this->request->variable('message_last_id', 0); $sql_and = $this->user->data['user_mchat_topics'] ? '' : 'AND m.forum_id = 0'; $sql = 'SELECT m.*, u.username, u.user_colour, u.user_avatar, u.user_avatar_type, u.user_avatar_width, u.user_avatar_height, u.user_allow_pm FROM ' . $this->mchat_table . ' m, ' . USERS_TABLE . ' u WHERE m.user_id = u.user_id AND m.message_id > ' . (int) $mchat_message_last_id . ' ' . $sql_and . ' ORDER BY m.message_id DESC'; $result = $this->db->sql_query_limit($sql, (int) $this->config_mchat['message_limit']); $rows = $this->db->sql_fetchrowset($result); $this->db->sql_freeresult($result); // Reverse the array wanting messages appear in reverse if ($this->config['mchat_message_top']) { $rows = array_reverse($rows); } foreach ($rows as $row) { // auth check if ($row['forum_id'] != 0 && !$this->auth->acl_get('f_read', $row['forum_id'])) { continue; } // edit auths if ($this->user->data['user_id'] == ANONYMOUS && $this->user->data['user_id'] == $row['user_id']) { $chat_auths = $this->user->data['session_ip'] == $row['user_ip'] ? true : false; } else { $chat_auths = $this->user->data['user_id'] == $row['user_id'] ? true : false; } // edit, delete and permission auths $mchat_ban = $this->auth->acl_get('a_authusers') && $this->user->data['user_id'] != $row['user_id'] ? true : false; $mchat_edit = $this->auth->acl_get('u_mchat_edit') && ($this->auth->acl_get('m_') || $chat_auths) ? true : false; $mchat_del = $this->auth->acl_get('u_mchat_delete') && ($this->auth->acl_get('m_') || $chat_auths) ? true : false; $mchat_avatar = $row['user_avatar'] ? get_user_avatar($row['user_avatar'], $row['user_avatar_type'], $row['user_avatar_width'] > $row['user_avatar_height'] ? 40 : 40 / $row['user_avatar_height'] * $row['user_avatar_width'], $row['user_avatar_height'] > $row['user_avatar_width'] ? 40 : 40 / $row['user_avatar_width'] * $row['user_avatar_height']) : ''; $message_edit = $row['message']; decode_message($message_edit, $row['bbcode_uid']); $message_edit = str_replace('"', '"', $message_edit); $message_edit = mb_ereg_replace("'", "’", $message_edit); // Edit Fix ;) if (sizeof($foes_array)) { if (in_array($row['user_id'], $foes_array)) { $row['message'] = sprintf($this->user->lang['MCHAT_FOE'], get_username_string('full', $row['user_id'], $row['username'], $row['user_colour'], $this->user->lang['GUEST'])); } } $row['username'] = mb_ereg_replace("'", "’", $row['username']); $this->template->assign_block_vars('mchatrow', array('MCHAT_ALLOW_BAN' => $mchat_ban, 'MCHAT_ALLOW_EDIT' => $mchat_edit, 'MCHAT_ALLOW_DEL' => $mchat_del, 'MCHAT_USER_AVATAR' => $mchat_avatar, 'U_VIEWPROFILE' => $row['user_id'] != ANONYMOUS ? append_sid("{$this->phpbb_root_path}memberlist.{$this->phpEx}", 'mode=viewprofile&u=' . $row['user_id']) : '', 'U_USER_IDS' => $row['user_id'] != ANONYMOUS && $this->user->data['user_id'] != $row['user_id'] ? append_sid("{$this->phpbb_root_path}ucp.{$this->phpEx}", 'i=pm&mode=compose&u=' . $row['user_id']) : '', 'BOT_USER_ID' => $row['user_id'] != '1', 'U_USER_ID' => $row['user_id'] != ANONYMOUS && $this->config['allow_privmsg'] && $this->auth->acl_get('u_sendpm') && $this->user->data['user_id'] != $row['user_id'] && $row['user_id'] != '1' && ($row['user_allow_pm'] || $this->auth->acl_gets('a_', 'm_') || $this->auth->acl_getf_global('m_')) ? append_sid("{$this->phpbb_root_path}ucp.{$this->phpEx}", 'i=pm&mode=compose&u=' . $row['user_id']) : '', 'MCHAT_MESSAGE_EDIT' => $message_edit, 'MCHAT_MESSAGE_ID' => $row['message_id'], 'MCHAT_USERNAME_FULL' => get_username_string('full', $row['user_id'], $row['username'], $row['user_colour'], $this->user->lang['GUEST']), 'MCHAT_USERNAME' => get_username_string('username', $row['user_id'], $row['username'], $row['user_colour'], $this->user->lang['GUEST']), 'MCHAT_USERNAME_COLOR' => get_username_string('colour', $row['user_id'], $row['username'], $row['user_colour'], $this->user->lang['GUEST']), 'MCHAT_USER_IP' => $row['user_ip'], 'MCHAT_U_WHOIS' => $this->helper->route('dmzx_mchat_controller', array('mode' => 'whois', 'ip' => $row['user_ip'])), 'MCHAT_U_BAN' => append_sid("{$this->phpbb_root_path}adm/index.{$this->phpEx}", 'i=permissions&mode=setting_user_global&user_id[0]=' . $row['user_id'], true, $this->user->session_id), 'MCHAT_MESSAGE' => generate_text_for_display($row['message'], $row['bbcode_uid'], $row['bbcode_bitfield'], $row['bbcode_options']), 'MCHAT_TIME' => $this->user->format_date($row['message_time'], $this->config_mchat['date']), 'MCHAT_CLASS' => $row['message_id'] % 2 ? 1 : 2)); } // Write no message if (empty($rows)) { $mchat_no_message = true; } // If read mode request set true $mchat_read_mode = true; break; // Stats function... // Stats function... case 'stats': // If mChat disabled or user can't view the chat if (!$this->config['mchat_enable'] || !$mchat_view || !$this->config_mchat['whois']) { // Forbidden (for jQ AJAX request) throw new \phpbb\exception\http_exception(403, 'MCHAT_ERROR_FORBIDDEN'); } $mchat_stats = $this->functions_mchat->mchat_users($mchat_session_time); if (!empty($mchat_stats['online_userlist'])) { $message = '<div class="mChatStats" id="mChatStats"><a href="#" onclick="mChat.toggle(\'UserList\'); return false;">' . $mchat_stats['mchat_users_count'] . '</a> ' . $mchat_stats['refresh_message'] . '<br /><span id="mChatUserList" style="display: none; float: left;">' . $mchat_stats['online_userlist'] . '</span></div>'; } else { $message = '<div class="mChatStats" id="Div1">' . $this->user->lang['MCHAT_NO_CHATTERS'] . ' (' . $mchat_stats['refresh_message'] . ')</div>'; } if ($this->request->is_ajax()) { // Return for: \Symfony\Component\HttpFoundation\JsonResponse return array('json' => true, 'message' => $message); } else { throw new \phpbb\exception\http_exception(501, 'MCHAT_ERROR_NOT_IMPLEMENTED'); } break; // Add function... // Add function... case 'add': // If mChat disabled if (!$this->config['mchat_enable'] || !$mchat_add_mess || !check_form_key('mchat_posting', -1)) { // Forbidden (for jQ AJAX request) if ($this->request->is_ajax()) { // FOR DEBUG throw new \phpbb\exception\http_exception(403, 'MCHAT_ERROR_FORBIDDEN'); } } // Reguest... $message = utf8_ucfirst(utf8_normalize_nfc($this->request->variable('message', '', true))); // must have something other than bbcode in the message if (empty($mchatregex)) { //let's strip all the bbcode $mchatregex = '#\\[/?[^\\[\\]]+\\]#mi'; } $message_chars = preg_replace($mchatregex, '', $message); $message_chars = utf8_strlen(trim($message_chars)) > 0 ? true : false; if (!$message || !$message_chars) { // Not Implemented (for jQ AJAX request) throw new \phpbb\exception\http_exception(501, 'MCHAT_ERROR_NOT_IMPLEMENTED'); } // Flood control if (!$mchat_no_flood && $this->config_mchat['flood_time']) { $mchat_flood_current_time = time(); $sql = 'SELECT message_time FROM ' . $this->mchat_table . ' WHERE user_id = ' . (int) $this->user->data['user_id'] . ' ORDER BY message_time DESC'; $result = $this->db->sql_query_limit($sql, 1); $row = $this->db->sql_fetchrow($result); $this->db->sql_freeresult($result); if ($row['message_time'] > 0 && $mchat_flood_current_time - $row['message_time'] < (int) $this->config_mchat['flood_time']) { // Locked (for jQ AJAX request) throw new \phpbb\exception\http_exception(400, 'MCHAT_BAD_REQUEST'); } } // insert user into the mChat sessions table $this->functions_mchat->mchat_sessions($mchat_session_time, true); // we override the $this->config['min_post_chars'] entry? if ($this->config_mchat['override_min_post_chars']) { $old_cfg['min_post_chars'] = $this->config['min_post_chars']; $this->config['min_post_chars'] = 0; } //we do the same for the max number of smilies? if ($this->config_mchat['override_smilie_limit']) { $old_cfg['max_post_smilies'] = $this->config['max_post_smilies']; $this->config['max_post_smilies'] = 0; } // Add function part code from http://wiki.phpbb.com/Parsing_text $uid = $bitfield = $options = ''; // will be modified by generate_text_for_storage generate_text_for_storage($message, $uid, $bitfield, $options, $mchat_allow_bbcode, $mchat_urls, $mchat_smilies); // Not allowed bbcodes if (!$mchat_allow_bbcode || $this->config_mchat['bbcode_disallowed']) { if (!$mchat_allow_bbcode) { $bbcode_remove = '#\\[/?[^\\[\\]]+\\]#Usi'; $message = preg_replace($bbcode_remove, '', $message); } else { if ($this->config_mchat['bbcode_disallowed']) { if (empty($bbcode_replace)) { $bbcode_replace = array('#\\[(' . $this->config_mchat['bbcode_disallowed'] . ')[^\\[\\]]+\\]#Usi', '#\\[/(' . $this->config_mchat['bbcode_disallowed'] . ')[^\\[\\]]+\\]#Usi'); } $message = preg_replace($bbcode_replace, '', $message); } } } $sql_ary = array('forum_id' => 0, 'post_id' => 0, 'user_id' => $this->user->data['user_id'], 'user_ip' => $this->user->data['session_ip'], 'message' => str_replace('\'', '’', $message), 'bbcode_bitfield' => $bitfield, 'bbcode_uid' => $uid, 'bbcode_options' => $options, 'message_time' => time()); $sql = 'INSERT INTO ' . $this->mchat_table . ' ' . $this->db->sql_build_array('INSERT', $sql_ary); $this->db->sql_query($sql); // reset the config settings if (isset($old_cfg['min_post_chars'])) { $this->config['min_post_chars'] = $old_cfg['min_post_chars']; unset($old_cfg['min_post_chars']); } if (isset($old_cfg['max_post_smilies'])) { $this->config['max_post_smilies'] = $old_cfg['max_post_smilies']; unset($old_cfg['max_post_smilies']); } // Stop run code! if ($this->request->is_ajax()) { // Return for: \Symfony\Component\HttpFoundation\JsonResponse return array('json' => true, 'success' => true); } else { exit_handler(); } break; // Edit function... // Edit function... case 'edit': $message_id = $this->request->variable('message_id', 0); // If mChat disabled and not edit if (!$this->config['mchat_enable'] || !$message_id) { // Forbidden (for jQ AJAX request) throw new \phpbb\exception\http_exception(403, 'MCHAT_ERROR_FORBIDDEN'); } // check for the correct user $sql = 'SELECT * FROM ' . $this->mchat_table . ' WHERE message_id = ' . (int) $message_id; $result = $this->db->sql_query($sql); $row = $this->db->sql_fetchrow($result); $this->db->sql_freeresult($result); // edit and delete auths $mchat_edit = $this->auth->acl_get('u_mchat_edit') && ($this->auth->acl_get('m_') || $this->user->data['user_id'] == $row['user_id']) ? true : false; $mchat_del = $this->auth->acl_get('u_mchat_delete') && ($this->auth->acl_get('m_') || $this->user->data['user_id'] == $row['user_id']) ? true : false; // If mChat disabled and not edit if (!$mchat_edit) { // Forbidden (for jQ AJAX request) throw new \phpbb\exception\http_exception(403, 'MCHAT_ERROR_FORBIDDEN'); } // Reguest... $message = $this->request->variable('message', '', true); // must have something other than bbcode in the message if (empty($mchatregex)) { //let's strip all the bbcode $mchatregex = '#\\[/?[^\\[\\]]+\\]#mi'; } $message_chars = preg_replace($mchatregex, '', $message); $message_chars = utf8_strlen(trim($message_chars)) > 0 ? true : false; if (!$message || !$message_chars) { // Not Implemented (for jQ AJAX request) throw new \phpbb\exception\http_exception(501, 'MCHAT_ERROR_NOT_IMPLEMENTED'); } // Message limit $message = $this->config_mchat['max_message_lngth'] != 0 && utf8_strlen($message) >= $this->config_mchat['max_message_lngth'] + 3 ? utf8_substr($message, 0, $this->config_mchat['max_message_lngth']) . '...' : $message; // we override the $this->config['min_post_chars'] entry? if ($this->config_mchat['override_min_post_chars']) { $old_cfg['min_post_chars'] = $this->config['min_post_chars']; $this->config['min_post_chars'] = 0; } //we do the same for the max number of smilies? if ($this->config_mchat['override_smilie_limit']) { $old_cfg['max_post_smilies'] = $this->config['max_post_smilies']; $this->config['max_post_smilies'] = 0; } // Edit function part code from http://wiki.phpbb.com/Parsing_text $uid = $bitfield = $options = ''; // will be modified by generate_text_for_storage generate_text_for_storage($message, $uid, $bitfield, $options, $mchat_allow_bbcode, $mchat_urls, $mchat_smilies); // Not allowed bbcodes if (!$mchat_allow_bbcode || $this->config_mchat['bbcode_disallowed']) { if (!$mchat_allow_bbcode) { $bbcode_remove = '#\\[/?[^\\[\\]]+\\]#Usi'; $message = preg_replace($bbcode_remove, '', $message); } else { if ($this->config_mchat['bbcode_disallowed']) { if (empty($bbcode_replace)) { $bbcode_replace = array('#\\[(' . $this->config_mchat['bbcode_disallowed'] . ')[^\\[\\]]+\\]#Usi', '#\\[/(' . $this->config_mchat['bbcode_disallowed'] . ')[^\\[\\]]+\\]#Usi'); } $message = preg_replace($bbcode_replace, '', $message); } } } $sql_ary = array('message' => str_replace('\'', '’', $message), 'bbcode_bitfield' => $bitfield, 'bbcode_uid' => $uid, 'bbcode_options' => $options); $sql = 'UPDATE ' . $this->mchat_table . ' SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . ' WHERE message_id = ' . (int) $message_id; $this->db->sql_query($sql); // Message edited...now read it $sql = 'SELECT m.*, u.username, u.user_colour, u.user_avatar, u.user_avatar_type, u.user_avatar_width, u.user_avatar_height, u.user_allow_pm FROM ' . $this->mchat_table . ' m, ' . USERS_TABLE . ' u WHERE m.user_id = u.user_id AND m.message_id = ' . (int) $message_id . ' ORDER BY m.message_id DESC'; $result = $this->db->sql_query($sql); $row = $this->db->sql_fetchrow($result); $this->db->sql_freeresult($result); $message_edit = $row['message']; decode_message($message_edit, $row['bbcode_uid']); $message_edit = str_replace('"', '"', $message_edit); // Edit Fix ;) $message_edit = mb_ereg_replace("'", "’", $message_edit); // Edit Fix ;) $mchat_ban = $this->auth->acl_get('a_authusers') && $this->user->data['user_id'] != $row['user_id'] ? true : false; $mchat_avatar = $row['user_avatar'] ? get_user_avatar($row['user_avatar'], $row['user_avatar_type'], $row['user_avatar_width'] > $row['user_avatar_height'] ? 40 : 40 / $row['user_avatar_height'] * $row['user_avatar_width'], $row['user_avatar_height'] > $row['user_avatar_width'] ? 40 : 40 / $row['user_avatar_width'] * $row['user_avatar_height']) : ''; $this->template->assign_block_vars('mchatrow', array('MCHAT_ALLOW_BAN' => $mchat_ban, 'MCHAT_ALLOW_EDIT' => $mchat_edit, 'MCHAT_ALLOW_DEL' => $mchat_del, 'MCHAT_MESSAGE_EDIT' => $message_edit, 'MCHAT_USER_AVATAR' => $mchat_avatar, 'U_VIEWPROFILE' => $row['user_id'] != ANONYMOUS ? append_sid("{$this->phpbb_root_path}memberlist.{$this->phpEx}", 'mode=viewprofile&u=' . $row['user_id']) : '', 'U_USER_IDS' => $row['user_id'] != ANONYMOUS && $this->user->data['user_id'] != $row['user_id'] ? append_sid("{$this->phpbb_root_path}ucp.{$this->phpEx}", 'i=pm&mode=compose&u=' . $row['user_id']) : '', 'BOT_USER_ID' => $row['user_id'] != '1', 'U_USER_ID' => $row['user_id'] != ANONYMOUS && $this->config['allow_privmsg'] && $this->auth->acl_get('u_sendpm') && $this->user->data['user_id'] != $row['user_id'] && $row['user_id'] != '1' && ($row['user_allow_pm'] || $this->auth->acl_gets('a_', 'm_') || $this->auth->acl_getf_global('m_')) ? append_sid("{$this->phpbb_root_path}ucp.{$this->phpEx}", 'i=pm&mode=compose&u=' . $row['user_id']) : '', 'MCHAT_MESSAGE_ID' => $row['message_id'], 'MCHAT_USERNAME_FULL' => get_username_string('full', $row['user_id'], $row['username'], $row['user_colour'], $this->user->lang['GUEST']), 'MCHAT_USERNAME' => get_username_string('username', $row['user_id'], $row['username'], $row['user_colour'], $this->user->lang['GUEST']), 'MCHAT_USERNAME_COLOR' => get_username_string('colour', $row['user_id'], $row['username'], $row['user_colour'], $this->user->lang['GUEST']), 'MCHAT_USER_IP' => $row['user_ip'], 'MCHAT_U_WHOIS' => $this->helper->route('dmzx_mchat_controller', array('mode' => 'whois', 'ip' => $row['user_ip'])), 'MCHAT_U_BAN' => append_sid("{$this->phpbb_root_path}adm/index.{$this->phpEx}", 'i=permissions&mode=setting_user_global&user_id[0]=' . $row['user_id'], true, $this->user->session_id), 'MCHAT_MESSAGE' => censor_text(generate_text_for_display($row['message'], $row['bbcode_uid'], $row['bbcode_bitfield'], $row['bbcode_options'])), 'MCHAT_TIME' => $this->user->format_date($row['message_time'], $this->config_mchat['date']), 'MCHAT_CLASS' => $row['message_id'] % 2 ? 1 : 2)); // reset the config settings if (isset($old_cfg['min_post_chars'])) { $this->config['min_post_chars'] = $old_cfg['min_post_chars']; unset($old_cfg['min_post_chars']); } if (isset($old_cfg['max_post_smilies'])) { $this->config['max_post_smilies'] = $old_cfg['max_post_smilies']; unset($old_cfg['max_post_smilies']); } //adds a log // $message_author = get_username_string('no_profile', $row['user_id'], $row['username'], $row['user_colour'], $this->user->lang['GUEST']); // add_log('admin', 'LOG_EDITED_MCHAT', $message_author); $this->phpbb_log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_EDITED_MCHAT', false, array($row['username'])); // insert user into the mChat sessions table $this->functions_mchat->mchat_sessions($mchat_session_time, true); // If read mode request set true $mchat_read_mode = true; break; // Delete function... // Delete function... case 'delete': $message_id = $this->request->variable('message_id', 0); // If mChat disabled if (!$this->config['mchat_enable'] || !$message_id) { // Forbidden (for jQ AJAX request) throw new \phpbb\exception\http_exception(403, 'MCHAT_ERROR_FORBIDDEN'); } // check for the correct user $sql = 'SELECT m.*, u.username, u.user_colour FROM ' . $this->mchat_table . ' m LEFT JOIN ' . USERS_TABLE . ' u ON m.user_id = u.user_id WHERE m.message_id = ' . (int) $message_id; $result = $this->db->sql_query($sql); $row = $this->db->sql_fetchrow($result); $this->db->sql_freeresult($result); // edit and delete auths $mchat_edit = $this->auth->acl_get('u_mchat_edit') && ($this->auth->acl_get('m_') || $this->user->data['user_id'] == $row['user_id']) ? true : false; $mchat_del = $this->auth->acl_get('u_mchat_delete') && ($this->auth->acl_get('m_') || $this->user->data['user_id'] == $row['user_id']) ? true : false; // If mChat disabled if (!$mchat_del) { // Forbidden (for jQ AJAX request) throw new \phpbb\exception\http_exception(403, 'MCHAT_ERROR_FORBIDDEN'); } // Run delete! $sql = 'DELETE FROM ' . $this->mchat_table . ' WHERE message_id = ' . (int) $message_id; $this->db->sql_query($sql); //adds a log $this->phpbb_log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_DELETED_MCHAT', false, array($row['username'])); // insert user into the mChat sessions table $this->functions_mchat->mchat_sessions($mchat_session_time, true); // Stop running code if ($this->request->is_ajax()) { // Return for: \Symfony\Component\HttpFoundation\JsonResponse return array('json' => true, 'success' => true); } else { exit_handler(); } break; // Default function... // Default function... default: // If not include in index.php set mchat.php page true if (!$include_on_index) { // Yes its custom page... $mchat_custom_page = true; // If custom page false mchat.php page redirect to index... if (!$this->config_mchat['custom_page'] && $mchat_custom_page) { $mchat_redirect = append_sid("{$this->phpbb_root_path}index.{$this->phpEx}"); // Redirect to previous page meta_refresh(3, $mchat_redirect); trigger_error($this->user->lang['MCHAT_NO_CUSTOM_PAGE'] . '<br /><br />' . sprintf($this->user->lang['RETURN_PAGE'], '<a href="' . $mchat_redirect . '">', '</a>')); } // user has permissions to view the custom chat? if (!$mchat_view && $mchat_custom_page) { trigger_error('NOT_AUTHORISED', E_USER_NOTICE); } // if whois true if ($this->config_mchat['whois']) { // Grab group details for legend display for who is online on the custom page. $order_legend = $this->config['legend_sort_groupname'] ? 'group_name' : 'group_legend'; if ($this->auth->acl_gets('a_group', 'a_groupadd', 'a_groupdel')) { $sql = 'SELECT group_id, group_name, group_colour, group_type FROM ' . GROUPS_TABLE . ' WHERE group_legend <> 0 ORDER BY ' . $order_legend . ' ASC'; } else { $sql = 'SELECT g.group_id, g.group_name, g.group_colour, g.group_type FROM ' . GROUPS_TABLE . ' g LEFT JOIN ' . USER_GROUP_TABLE . ' ug ON (g.group_id = ug.group_id AND ug.user_id = ' . $this->user->data['user_id'] . ' AND ug.user_pending = 0) WHERE g.group_legend <> 0 AND (g.group_type <> ' . GROUP_HIDDEN . ' OR ug.user_id = ' . (int) $this->user->data['user_id'] . ') ORDER BY g.' . $order_legend . ' ASC'; } $result = $this->db->sql_query($sql); $legend = array(); while ($row = $this->db->sql_fetchrow($result)) { $colour_text = $row['group_colour'] ? ' style="color:#' . $row['group_colour'] . '"' : ''; $group_name = $row['group_type'] == GROUP_SPECIAL ? $this->user->lang['G_' . $row['group_name']] : $row['group_name']; if ($row['group_name'] == 'BOTS' || $this->user->data['user_id'] != ANONYMOUS && !$this->auth->acl_get('u_viewprofile')) { $legend[] = '<span' . $colour_text . '>' . $group_name . '</span>'; } else { $legend[] = '<a' . $colour_text . ' href="' . append_sid("{$this->phpbb_root_path}memberlist.{$this->phpEx}", 'mode=group&g=' . $row['group_id']) . '">' . $group_name . '</a>'; } } $this->db->sql_freeresult($result); $legend = implode(', ', $legend); // Assign index specific vars $this->template->assign_vars(array('LEGEND' => $legend)); } $this->template->assign_block_vars('navlinks', array('FORUM_NAME' => $this->user->lang['MCHAT_TITLE'], 'U_VIEW_FORUM' => $this->helper->route('dmzx_mchat_controller'))); } // Run code... if ($mchat_view) { $message_number = $mchat_custom_page ? $this->config_mchat['message_limit'] : $this->config_mchat['message_num']; $sql_where = $this->user->data['user_mchat_topics'] ? '' : 'WHERE m.forum_id = 0'; // Message row $sql = 'SELECT m.*, u.username, u.user_colour, u.user_avatar, u.user_avatar_type, u.user_avatar_width, u.user_avatar_height, u.user_allow_pm FROM ' . $this->mchat_table . ' m LEFT JOIN ' . USERS_TABLE . ' u ON m.user_id = u.user_id ' . $sql_where . ' ORDER BY message_id DESC'; $result = $this->db->sql_query_limit($sql, $message_number); $rows = $this->db->sql_fetchrowset($result); $this->db->sql_freeresult($result); if ($this->config['mchat_message_top']) { $rows = array_reverse($rows, true); } foreach ($rows as $row) { // auth check if ($row['forum_id'] != 0 && !$this->auth->acl_get('f_read', $row['forum_id'])) { continue; } // edit, delete and permission auths $mchat_ban = $this->auth->acl_get('a_authusers') && $this->user->data['user_id'] != $row['user_id'] ? true : false; // edit auths if ($this->user->data['user_id'] == ANONYMOUS && $this->user->data['user_id'] == $row['user_id']) { $chat_auths = $this->user->data['session_ip'] == $row['user_ip'] ? true : false; } else { $chat_auths = $this->user->data['user_id'] == $row['user_id'] ? true : false; } $mchat_edit = $this->auth->acl_get('u_mchat_edit') && ($this->auth->acl_get('m_') || $chat_auths) ? true : false; $mchat_del = $this->auth->acl_get('u_mchat_delete') && ($this->auth->acl_get('m_') || $chat_auths) ? true : false; $mchat_avatar = $row['user_avatar'] ? get_user_avatar($row['user_avatar'], $row['user_avatar_type'], $row['user_avatar_width'] > $row['user_avatar_height'] ? 40 : 40 / $row['user_avatar_height'] * $row['user_avatar_width'], $row['user_avatar_height'] > $row['user_avatar_width'] ? 40 : 40 / $row['user_avatar_width'] * $row['user_avatar_height']) : ''; $message_edit = $row['message']; decode_message($message_edit, $row['bbcode_uid']); $message_edit = str_replace('"', '"', $message_edit); // Edit Fix ;) $message_edit = mb_ereg_replace("'", "’", $message_edit); if (sizeof($foes_array)) { if (in_array($row['user_id'], $foes_array)) { $row['message'] = sprintf($this->user->lang['MCHAT_FOE'], get_username_string('full', $row['user_id'], $row['username'], $row['user_colour'], $this->user->lang['GUEST'])); } } $row['username'] = mb_ereg_replace("'", "’", $row['username']); $message = str_replace('\'', '’', $row['message']); $this->template->assign_block_vars('mchatrow', array('MCHAT_ALLOW_BAN' => $mchat_ban, 'MCHAT_ALLOW_EDIT' => $mchat_edit, 'MCHAT_ALLOW_DEL' => $mchat_del, 'MCHAT_USER_AVATAR' => $mchat_avatar, 'U_VIEWPROFILE' => $row['user_id'] != ANONYMOUS ? append_sid("{$this->phpbb_root_path}memberlist.{$this->phpEx}", 'mode=viewprofile&u=' . $row['user_id']) : '', 'U_USER_IDS' => $row['user_id'] != ANONYMOUS && $this->user->data['user_id'] != $row['user_id'] ? append_sid("{$this->phpbb_root_path}ucp.{$this->phpEx}", 'i=pm&mode=compose&u=' . $row['user_id']) : '', 'BOT_USER_ID' => $row['user_id'] != '1', 'U_USER_ID' => $row['user_id'] != ANONYMOUS && $this->config['allow_privmsg'] && $this->auth->acl_get('u_sendpm') && $this->user->data['user_id'] != $row['user_id'] && $row['user_id'] != '1' && ($row['user_allow_pm'] || $this->auth->acl_gets('a_', 'm_') || $this->auth->acl_getf_global('m_')) ? append_sid("{$this->phpbb_root_path}ucp.{$this->phpEx}", 'i=pm&mode=compose&u=' . $row['user_id']) : '', 'MCHAT_MESSAGE_EDIT' => $message_edit, 'MCHAT_MESSAGE_ID' => $row['message_id'], 'MCHAT_USERNAME_FULL' => get_username_string('full', $row['user_id'], $row['username'], $row['user_colour'], $this->user->lang['GUEST']), 'MCHAT_USERNAME' => get_username_string('username', $row['user_id'], $row['username'], $row['user_colour'], $this->user->lang['GUEST']), 'MCHAT_USERNAME_COLOR' => get_username_string('colour', $row['user_id'], $row['username'], $row['user_colour'], $this->user->lang['GUEST']), 'MCHAT_USER_IP' => $row['user_ip'], 'MCHAT_U_WHOIS' => $this->helper->route('dmzx_mchat_controller', array('mode' => 'whois', 'ip' => $row['user_ip'])), 'MCHAT_U_BAN' => append_sid("{$this->phpbb_root_path}adm/index.{$this->phpEx}", 'i=permissions&mode=setting_user_global&user_id[0]=' . $row['user_id'], true, $this->user->session_id), 'MCHAT_MESSAGE' => generate_text_for_display($message, $row['bbcode_uid'], $row['bbcode_bitfield'], $row['bbcode_options']), 'MCHAT_TIME' => $this->user->format_date($row['message_time'], $this->config_mchat['date']), 'MCHAT_CLASS' => $row['message_id'] % 2 ? 1 : 2)); } // Write no message if (empty($rows)) { $mchat_no_message = true; } // display custom bbcodes if ($mchat_allow_bbcode && $this->config['allow_bbcode']) { $this->functions_mchat->display_mchat_bbcodes(); } // Smile row if ($mchat_smilies) { if (!function_exists('generate_smilies')) { include $this->phpbb_root_path . 'includes/functions_posting.' . $this->phpEx; } generate_smilies('inline', 0); } // If the static message is defined in the language file use it, else just use the entry in the database if (isset($this->user->lang[strtoupper('static_message')]) || !empty($this->config_mchat['static_message'])) { $this->config_mchat['static_message'] = $this->config_mchat['static_message']; if (isset($this->user->lang[strtoupper('static_message')])) { $this->config_mchat['static_message'] = $this->user->lang[strtoupper('static_message')]; } } // If the static message is defined in the language file use it, else just use the entry in the database if (isset($this->user->lang[strtoupper('mchat_rules')]) || !empty($this->config_mchat['rules'])) { if (isset($this->user->lang[strtoupper('mchat_rules')])) { $this->config_mchat['rules'] = $this->user->lang[strtoupper('mchat_rules')]; } } // a list of users using the chat if ($mchat_custom_page) { $mchat_users = $this->functions_mchat->mchat_users($mchat_session_time, true); } else { $mchat_users = $this->functions_mchat->mchat_users($mchat_session_time); } $this->template->assign_vars(array('MCHAT_USERS_COUNT' => $mchat_users['mchat_users_count'], 'MCHAT_USERS_LIST' => $mchat_users['online_userlist'])); } break; } // show index stats if (!empty($this->config['mchat_stats_index']) && !empty($this->user->data['user_mchat_stats_index'])) { // stats display $mchat_session_time = !empty($this->config_mchat['timeout']) ? $this->config_mchat['timeout'] : $this->config['session_length']; $mchat_stats = $this->functions_mchat->mchat_users($mchat_session_time); $this->template->assign_vars(array('MCHAT_INDEX_STATS' => true, 'MCHAT_INDEX_USERS_COUNT' => $mchat_stats['mchat_users_count'], 'MCHAT_INDEX_USERS_LIST' => !empty($mchat_stats['online_userlist']) ? $mchat_stats['online_userlist'] : '', 'L_MCHAT_ONLINE_EXPLAIN' => $mchat_stats['refresh_message'])); } $copyright = base64_decode('PGEgaHJlZj0iaHR0cDovL3JtY2dpcnI4My5vcmciPlJNY0dpcnI4MzwvYT4gJmNvcHk7IDxhIGhyZWY9Imh0dHA6Ly93d3cuZG16eC13ZWIubmV0IiB0aXRsZT0id3d3LmRtengtd2ViLm5ldCI+ZG16eDwvYT4='); add_form_key('mchat_posting'); // Template function... $this->template->assign_vars(array('MCHAT_FILE_NAME' => $this->helper->route('dmzx_mchat_controller'), 'MCHAT_REFRESH_JS' => 1000 * $this->config_mchat['refresh'], 'MCHAT_ADD_MESSAGE' => $mchat_add_mess, 'MCHAT_READ_MODE' => $mchat_read_mode, 'MCHAT_ARCHIVE_MODE' => $mchat_archive_mode, 'MCHAT_INPUT_TYPE' => $this->user->data['user_mchat_input_area'], 'MCHAT_RULES' => $mchat_rules, 'MCHAT_ALLOW_SMILES' => $mchat_smilies, 'MCHAT_ALLOW_IP' => $mchat_ip, 'MCHAT_ALLOW_PM' => $mchat_pm, 'MCHAT_ALLOW_LIKE' => $mchat_like, 'MCHAT_ALLOW_QUOTE' => $mchat_quote, 'MCHAT_NOMESSAGE_MODE' => $mchat_no_message, 'MCHAT_ALLOW_BBCODES' => $mchat_allow_bbcode && $this->config['allow_bbcode'] ? true : false, 'MCHAT_MESSAGE_TOP' => $this->config['mchat_message_top'] ? true : false, 'MCHAT_ENABLE' => $this->config['mchat_enable'], 'MCHAT_ARCHIVE_URL' => $this->helper->route('dmzx_mchat_controller', array('mode' => 'archive')), 'MCHAT_CUSTOM_PAGE' => $mchat_custom_page, 'MCHAT_INDEX_HEIGHT' => $this->config_mchat['index_height'], 'MCHAT_CUSTOM_HEIGHT' => $this->config_mchat['custom_height'], 'MCHAT_READ_ARCHIVE_BUTTON' => $mchat_read_archive, 'MCHAT_FOUNDER' => $mchat_founder, 'MCHAT_CLEAN_URL' => $this->helper->route('dmzx_mchat_controller', array('mode' => 'clean', 'redirect' => $on_page)), 'MCHAT_STATIC_MESS' => !empty($this->config_mchat['static_message']) ? htmlspecialchars_decode($this->config_mchat['static_message']) : '', 'L_MCHAT_COPYRIGHT' => $copyright, 'MCHAT_WHOIS' => $this->config_mchat['whois'], 'MCHAT_MESSAGE_LNGTH' => $this->config_mchat['max_message_lngth'], 'L_MCHAT_MESSAGE_LNGTH_EXPLAIN' => intval($this->config_mchat['max_message_lngth']) ? sprintf($this->user->lang['MCHAT_MESSAGE_LNGTH_EXPLAIN'], intval($this->config_mchat['max_message_lngth'])) : '', 'MCHAT_MESS_LONG' => sprintf($this->user->lang['MCHAT_MESS_LONG'], $this->config_mchat['max_message_lngth']), 'MCHAT_USER_TIMEOUT' => $this->config_mchat['timeout'] ? 1000 * $this->config_mchat['timeout'] : false, 'MCHAT_WHOIS_REFRESH' => 1000 * $this->config_mchat['whois_refresh'], 'MCHAT_PAUSE_ON_INPUT' => $this->config_mchat['pause_on_input'] ? true : false, 'L_MCHAT_ONLINE_EXPLAIN' => $this->functions_mchat->mchat_session_time($mchat_session_time), 'MCHAT_REFRESH_YES' => sprintf($this->user->lang['MCHAT_REFRESH_YES'], $this->config_mchat['refresh']), 'L_MCHAT_WHOIS_REFRESH_EXPLAIN' => sprintf($this->user->lang['WHO_IS_REFRESH_EXPLAIN'], $this->config_mchat['whois_refresh']), 'S_MCHAT_AVATARS' => $mchat_avatars, 'S_MCHAT_LOCATION' => $this->config_mchat['location'], 'S_MCHAT_SOUND_YES' => $this->user->data['user_mchat_sound'], 'S_MCHAT_INDEX_STATS' => $this->user->data['user_mchat_stats_index'], 'U_MORE_SMILIES' => append_sid("{$this->phpbb_root_path}posting.{$this->phpEx}", 'mode=smilies'), 'U_MCHAT_RULES' => $this->helper->route('dmzx_mchat_controller', array('mode' => 'rules')), 'S_MCHAT_ON_INDEX' => $this->config['mchat_on_index'] && !empty($this->user->data['user_mchat_index']) ? true : false)); // Return for: \$this->helper->render(filename, lang_title); return array('filename' => 'mchat_body.html', 'lang_title' => $this->user->lang['MCHAT_TITLE']); }
/** * */ public function posting_modify_submit_post_after($event) { $this->functions_mchat->mchat_insert_posting($event['mode'], array('forum_id' => $event['forum_id'], 'forum_name' => $event['post_data']['forum_name'], 'post_id' => $event['data']['post_id'], 'post_subject' => $event['post_data']['post_subject'])); }
/** * 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)); }