/** * Controller for mChat actions called with Ajax requests * * @param $action The action to perform, one of add|edit|del|clean|refresh|whois * @return A Symfony JsonResponse object */ public function action($action) { if (!$this->request->is_ajax()) { throw new \phpbb\exception\http_exception(403, 'NO_AUTH_OPERATION'); } $data = call_user_func(array($this->mchat, 'action_' . $action)); return new JsonResponse($data); }
/** * {@inheritdoc} */ public function handle($forum_id) { // Throw an exception for non-AJAX requests or invalid link requests if (!$this->request->is_ajax() || !$this->is_valid($forum_id) || !check_link_hash($this->request->variable('hash', ''), 'collapsible_' . $forum_id)) { throw new \phpbb\exception\http_exception(403, 'NO_AUTH_OPERATION'); } // Update the user's collapsed category data for the given forum $response = $this->operator->set_user_categories($forum_id); // Return a JSON response return new \Symfony\Component\HttpFoundation\JsonResponse(array('success' => $response)); }
/** * Mentions controller accessed from the URL /mentions/user_list * * @return null * @access public */ public function get_userlist() { // Send a JSON response if an AJAX request was used if ($this->request->is_ajax()) { // If we have a query_string, we just get those usernames $query_string = $this->request->variable('term', '') ? $this->request->variable('term', '') : false; $user_list = $this->mentions->get_userlist($query_string); $user_list = array_values($user_list); $json_response = new \phpbb\json_response(); $json_response->send($user_list); } }
/** * Controller for mChat * * @return \Symfony\Component\HttpFoundation\Response A Symfony Response object */ public function handle() { $ret = $this->render_helper->render_data_for_page(); // If this was an ajax request, we just create an json_response and return that. It's not ours to handle here. if ($this->request->is_ajax() && is_array($ret) && isset($ret['json']) && $ret['json'] === true) { return new \Symfony\Component\HttpFoundation\JsonResponse($ret); } // If error occured, render it if (isset($ret['error']) && $ret['error'] == true) { return $this->helper->error($ret['error_text'], $ret['error_type']); } return $this->helper->render($ret['filename'], $ret['lang_title']); }
/** * Show user a result message if AJAX was used * * @param string $message Text message to show to the user * * @return null * @access protected */ protected function ajax_delete_result_message($message = '') { if ($this->request->is_ajax()) { $json_response = new \phpbb\json_response(); $json_response->send(array('MESSAGE_TITLE' => $this->user->lang['INFORMATION'], 'MESSAGE_TEXT' => $message, 'REFRESH_DATA' => array('time' => 3))); } }
/** * Post a new message to the shoutbox. * * @return \Symfony\Component\HttpFoundation\JsonResponse */ public function post() { // We always disallow guests to post in the shoutbox. if (!$this->auth->acl_get('u_shoutbox_post') || $this->user->data['user_id'] == ANONYMOUS) { return $this->error('AJAX_SHOUTBOX_ERROR', 'AJAX_SHOUTBOX_NO_PERMISSION', 403); } if ($this->request->is_ajax()) { $message = $msg = trim(utf8_normalize_nfc($this->request->variable('text_shoutbox', '', true))); if (empty($message)) { return $this->error('AJAX_SHOUTBOX_ERROR', 'AJAX_SHOUTBOX_MESSAGE_EMPTY', 500); } $uid = $bitfield = $options = ''; $allow_bbcode = $this->auth->acl_get('u_shoutbox_bbcode'); $allow_urls = $allow_smilies = true; if (!function_exists('generate_text_for_storage')) { include $this->root_path . 'includes/functions_content.' . $this->php_ext; } generate_text_for_storage($message, $uid, $bitfield, $options, $allow_bbcode, $allow_urls, $allow_smilies); $insert = array('post_message' => $message, 'post_time' => time(), 'user_id' => $this->user->data['user_id'], 'bbcode_options' => $options, 'bbcode_bitfield' => $bitfield, 'bbcode_uid' => $uid); $sql = 'INSERT INTO ' . $this->table . ' ' . $this->db->sql_build_array('INSERT', $insert); $this->db->sql_query($sql); if ($this->push->canPush()) { // User configured us to submit the shoutbox post to the iOS/Android app $this->push->post($msg, $insert['post_time'], $this->user->data['username'], $this->db->sql_nextid()); } return new JsonResponse(array('OK')); } else { return $this->error('AJAX_SHOUTBOX_ERROR', 'AJAX_SHOUTBOX_ONLY_AJAX', 500); } }
/** * BBCode wizard controller accessed with the URL /wizard/bbcode/{mode} * (where {mode} is a placeholder for a string of the bbcode tag name) * intended to be accessed via AJAX only * * @param string $mode Mode taken from the URL * @return \Symfony\Component\HttpFoundation\Response A Symfony Response object * @throws \phpbb\exception\http_exception An http exception * @access public */ public function bbcode_wizard($mode) { // Only allow AJAX requests if ($this->request->is_ajax()) { switch ($mode) { case 'bbvideo': $this->generate_bbvideo_wizard(); return $this->helper->render('abbc3_bbvideo_wizard.html'); break; case 'url': return $this->helper->render('abbc3_url_wizard.html'); break; } } throw new \phpbb\exception\http_exception(404, 'GENERAL_ERROR'); }
public function test_is_ajax_with_ajax() { $this->request->enable_super_globals(); $_SERVER['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest'; $this->request = new \phpbb\request\request($this->type_cast_helper); $this->assertTrue($this->request->is_ajax()); }
/** * Move order categories * * @return null */ public function action_move() { if (!$this->cat_id) { trigger_error($this->user->lang['DIR_NO_CAT'] . adm_back_link($this->u_action . '&parent_id=' . $this->parent_id), E_USER_WARNING); } $sql = 'SELECT cat_id, cat_name, parent_id, left_id, right_id FROM ' . DIR_CAT_TABLE . ' WHERE cat_id = ' . (int) $this->cat_id; $result = $this->db->sql_query($sql); $row = $this->db->sql_fetchrow($result); $this->db->sql_freeresult($result); if (!$row) { trigger_error($this->user->lang['DIR_NO_CAT'] . adm_back_link($this->u_action . '&parent_id=' . $this->parent_id), E_USER_WARNING); } try { $move_cat_name = $this->nestedset_category->{$this->action}($this->cat_id); } catch (\Exception $e) { trigger_error($e->getMessage(), E_USER_WARNING); } if ($move_cat_name !== false) { $this->phpbb_log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_DIR_CAT_' . strtoupper($this->action), time(), array($row['cat_name'], $move_cat_name)); $this->cache->destroy('sql', DIR_CAT_TABLE); } if ($this->request->is_ajax()) { $json_response = new \phpbb\json_response(); $json_response->send(array('success' => $move_cat_name !== false)); } }
/** * Удаление привязки к аккаунту соцсети в таблице ulogin_user для текущего пользователя */ protected function deleteAccount() { if (!$this->request->is_ajax()) { $redirect = "{$this->root_path}index.{$this->php_ext}"; $redirect = append_sid($redirect); redirect($redirect); } if (!$this->isUserLogined) { exit; } $user_id = $this->currentUserId; $network = $this->request->variable('network', '', false, \phpbb\request\request_interface::POST); if ($user_id > 0 && $network != '') { try { $this->model->deleteUloginUser(array('user_id' => $user_id, 'network' => $network)); $json_response = new \phpbb\json_response(); $json_response->send(array('title' => '', 'msg' => sprintf($this->user->lang['ULOGIN_DELETE_ACCOUNT_SUCCESS'], $network), 'type' => 'success')); exit; } catch (Exception $e) { $json_response = new \phpbb\json_response(); $json_response->send(array('title' => $this->user->lang['ULOGIN_DELETE_ACCOUNT_ERROR'], 'msg' => "Exception: " . $e->getMessage(), 'type' => 'error')); exit; } } exit; }
/** * Update BBCode order fields in the db on drag_drop * * @return null * @access public */ public function drag_drop() { if (!$this->request->is_ajax()) { return; } // Get the bbcodes html table's name $tablename = $this->request->variable('tablename', ''); // Fetch the posted list $bbcodes_list = $this->request->variable($tablename, array(0 => '')); $this->db->sql_transaction('begin'); // Run through the list foreach ($bbcodes_list as $order => $bbcode_id) { // First one is the header, skip it if ($order == 0) { continue; } // Update the db $sql = 'UPDATE ' . BBCODES_TABLE . ' SET bbcode_order = ' . $order . ' WHERE bbcode_id = ' . (int) $bbcode_id; $this->db->sql_query($sql); } $this->db->sql_transaction('commit'); // Resync bbcode_order $this->resynchronize_bbcode_order(); // return an AJAX JSON response $json_response = new \phpbb\json_response(); $json_response->send(array('success' => true)); }
/** * Clear user reputation * * @param int $uid User ID * @return null * @access public */ public function clear_user($uid) { $this->user->add_lang_ext('pico/reputation', 'reputation_system'); $is_ajax = $this->request->is_ajax(); $submit = false; $sql_array = array('SELECT' => 'r.*, ut.username AS username_to', 'FROM' => array($this->reputations_table => 'r'), 'LEFT_JOIN' => array(array('FROM' => array(USERS_TABLE => 'ut'), 'ON' => 'r.user_id_to = ut.user_id ')), 'WHERE' => 'r.user_id_to = ' . $uid); $sql = $this->db->sql_build_query('SELECT', $sql_array); $result = $this->db->sql_query($sql); $row = $this->db->sql_fetchrow($result); $this->db->sql_freeresult($result); //We couldn't find this reputation. May be it was deleted meanwhile? if (empty($row)) { $message = $this->user->lang('RS_NO_REPUTATION'); $json_data = array('error_msg' => $message); $redirect = append_sid("{$this->root_path}index.{$this->php_ext}"); $redirect_text = 'RETURN_INDEX'; $this->reputation_manager->response($message, $json_data, $redirect, $redirect_text, $is_ajax); } $redirect = $this->helper->route('reputation_details_controller', array('uid' => $uid)); if ($this->request->is_set_post('cancel')) { redirect($redirect); } $post_ids = array(); $post_type_id = (int) $this->reputation_manager->get_reputation_type_id('post'); $sql = 'SELECT reputation_item_id FROM ' . $this->reputations_table . "\n\t\t\tWHERE user_id_to = {$uid}\n\t\t\t\tAND reputation_type_id = {$post_type_id}\n\t\t\tGROUP BY reputation_item_id"; $result = $this->db->sql_query($sql); while ($post_row = $this->db->sql_fetchrow($result)) { $post_ids[] = $post_row['reputation_item_id']; } $this->db->sql_freeresult($result); $redirect_text = 'RETURN_PAGE'; if ($this->auth->acl_gets('m_rs_moderate')) { if ($is_ajax) { $submit = true; } else { $s_hidden_fields = build_hidden_fields(array('u' => $uid)); if (confirm_box(true)) { $submit = true; } else { confirm_box(false, $this->user->lang('RS_CLEAR_POST_CONFIRM'), $s_hidden_fields); } } } else { $message = $this->user->lang('RS_USER_CANNOT_DELETE'); $json_data = array('error_msg' => $message); $this->reputation_manager->response($message, $json_data, $redirect, $redirect_text, $is_ajax); } if ($submit) { try { $this->reputation_manager->clear_user_reputation($uid, $row, $post_ids); } catch (\pico\reputation\exception\base $e) { // Catch exception trigger_error($e->get_message($this->user)); } $message = $this->user->lang('RS_CLEARED_USER'); $json_data = array('clear_user' => true, 'post_ids' => $post_ids, 'poster_id' => $uid, 'user_reputation' => 0, 'post_reputation' => 0, 'reputation_class' => 'neutral'); $this->reputation_manager->response($message, $json_data, $redirect, $redirect_text, $is_ajax); } }
/** * date controller for return a date * * @return \phpbb\json_response A Json Response * @throws \phpbb\exception\http_exception */ public function return_date() { if (!$this->request->is_ajax()) { throw new \phpbb\exception\http_exception(403, 'DIR_ERROR_NOT_AUTH'); } $timestamp = $this->request->variable('timestamp', 0); $json_response = new \phpbb\json_response(); $json_response->send(array('success' => true, 'DATE' => $this->user->format_date((int) $timestamp))); }
/** * Display reputation overview * * @return null * @access public */ public function display_overview() { add_form_key('overview'); $errors = array(); $action = $this->request->variable('action', ''); if (!confirm_box(true)) { $confirm = false; switch ($action) { case 'sync': $confirm = true; $confirm_lang = 'RS_SYNC_REPUTATION_CONFIRM'; break; case 'truncate': $confirm = true; $confirm_lang = 'RS_TRUNCATE_CONFIRM'; break; } if ($confirm) { confirm_box(false, $this->user->lang($confirm_lang), build_hidden_fields(array('action' => $action))); } } else { switch ($action) { case 'sync': $this->config->set('rs_sync_step', 1, true); // Get sync module ID $sql = 'SELECT module_id FROM ' . MODULES_TABLE . "\n\t\t\t\t\t\tWHERE module_basename LIKE '%reputation%'\n\t\t\t\t\t\t\tAND module_mode = 'sync'"; $result = $this->db->sql_query($sql); $sync_module_id = (int) $this->db->sql_fetchfield('module_id'); $this->db->sql_freeresult($result); // Redirect to hidden sync module redirect(append_sid("{$this->phpbb_admin_path}index.{$this->php_ext}", "i={$sync_module_id}&mode=sync")); break; case 'truncate': $this->db->sql_query('UPDATE ' . USERS_TABLE . ' SET user_reputation = 0'); $this->db->sql_query('UPDATE ' . POSTS_TABLE . ' SET post_reputation = 0'); $this->db->sql_query('TRUNCATE ' . $this->reputations_table); add_log('admin', 'LOG_REPUTATION_TRUNCATE'); if ($this->request->is_ajax()) { trigger_error('RS_TRUNCATE_DONE'); } break; } } if ($this->request->is_set_post('submit')) { if (!check_form_key('overview')) { $errors[] = $this->user->lang('FORM_INVALID'); } if (empty($errors)) { $this->config->set('rs_enable', $this->request->variable('reputation_enable', 0)); } add_log('admin', 'REPUTATION_SETTINGS_CHANGED'); trigger_error($this->user->lang('REPUTATION_SETTINGS_CHANGED') . adm_back_link($this->u_action)); } $this->template->assign_vars(array('S_ERROR' => sizeof($errors) ? true : false, 'ERROR_MSG' => implode('<br />', $errors), 'S_REPUTATION_ENABLED' => $this->config['rs_enable'] ? true : false, 'S_FOUNDER' => $this->user->data['user_type'] == USER_FOUNDER ? true : false, 'U_ACTION' => $this->u_action)); }
/** * Alter preview output for ajax request * * @param object $event The event object * @return null * @access public */ public function output_ajax_post_preview($event) { if ($this->request->is_ajax() && $event['preview']) { if (empty($event['message_parser']->message)) { exit_handler(); } else { if (sizeof($event['error'])) { // seems to be the best HTTP code header('HTTP/1.1 412 Precondition Failed'); echo implode('<br />', $event['error']); exit_handler(); } else { $this->template->assign_vars($event['page_data']); // we can't use helper's render method, because it refreshes the page page_header(''); $this->template->set_filenames(array('body' => '@senky_ajaxbase/ajax_posting_preview.html')); page_footer(); } } } }
/** * Execute action requested * * @param string $action Requested action * @return null */ public function exec_action($action) { switch ($action) { case 'votes': switch ($this->db->get_sql_layer()) { case 'sqlite': case 'firebird': $this->db->sql_query('DELETE FROM ' . DIR_VOTE_TABLE); break; default: $this->db->sql_query('TRUNCATE TABLE ' . DIR_VOTE_TABLE); break; } $sql = 'UPDATE ' . DIR_LINK_TABLE . ' SET link_vote = 0, link_note = 0'; $this->db->sql_query($sql); if ($this->request->is_ajax()) { trigger_error('DIR_RESET_VOTES_SUCCESS'); } break; case 'comments': switch ($this->db->get_sql_layer()) { case 'sqlite': case 'firebird': $this->db->sql_query('DELETE FROM ' . DIR_COMMENT_TABLE); break; default: $this->db->sql_query('TRUNCATE TABLE ' . DIR_COMMENT_TABLE); break; } $sql = 'UPDATE ' . DIR_LINK_TABLE . ' SET link_comment = 0'; $this->db->sql_query($sql); if ($this->request->is_ajax()) { trigger_error('DIR_RESET_COMMENTS_SUCCESS'); } break; case 'clicks': $sql = 'UPDATE ' . DIR_LINK_TABLE . ' SET link_view = 0'; $this->db->sql_query($sql); if ($this->request->is_ajax()) { trigger_error('DIR_RESET_CLICKS_SUCCESS'); } break; case 'orphans': $this->_orphan_files(true); if ($this->request->is_ajax()) { trigger_error('DIR_DELETE_ORPHANS_SUCCESS'); } break; } }
/** * Category watching common code * * @param string $mode Watch or unwatch a category * @param array $s_watching An empty array, passed by reference * @param int $user_id The user ID * @param int $cat_id The category ID * @param string $notify_status User is watching the category? * @return null */ public function watch_categorie($mode, &$s_watching, $user_id, $cat_id, $notify_status) { // Is user watching this thread? if ($user_id != ANONYMOUS) { $can_watch = true; if (!is_null($notify_status) && $notify_status !== '') { if ($mode == 'unwatch') { $sql = 'DELETE FROM ' . DIR_WATCH_TABLE . "\n\t\t\t\t\t\tWHERE cat_id = {$cat_id}\n\t\t\t\t\t\t\tAND user_id = {$user_id}"; $this->db->sql_query($sql); $redirect_url = $this->helper->route('ernadoo_phpbbdirectory_page_controller', array('cat_id' => (int) $cat_id)); $message = $this->user->lang['DIR_NOT_WATCHING_CAT']; if (!$this->request->is_ajax()) { $message .= '<br /><br />' . $this->user->lang('DIR_CLICK_RETURN_CAT', '<a href="' . $redirect_url . '">', '</a>'); } meta_refresh(3, $redirect_url); return $message; } else { $is_watching = true; if ($notify_status != NOTIFY_YES) { $sql = 'UPDATE ' . DIR_WATCH_TABLE . ' SET notify_status = ' . NOTIFY_YES . "\n\t\t\t\t\t\t\tWHERE cat_id = {$cat_id}\n\t\t\t\t\t\t\t\tAND user_id = {$user_id}"; $this->db->sql_query($sql); } } } else { if ($mode == 'watch') { $sql = 'INSERT INTO ' . DIR_WATCH_TABLE . " (user_id, cat_id, notify_status)\n\t\t\t\t\t\tVALUES ({$user_id}, {$cat_id}, " . NOTIFY_YES . ')'; $this->db->sql_query($sql); $redirect_url = $this->helper->route('ernadoo_phpbbdirectory_page_controller', array('cat_id' => (int) $cat_id)); $message = $this->user->lang['DIR_ARE_WATCHING_CAT']; if (!$this->request->is_ajax()) { $message .= '<br /><br />' . $this->user->lang('DIR_CLICK_RETURN_CAT', '<a href="' . $redirect_url . '">', '</a>'); } meta_refresh(3, $redirect_url); return $message; } else { $is_watching = false; } } } else { $can_watch = false; $is_watching = false; } if ($can_watch) { $s_watching['link'] = $this->helper->route('ernadoo_phpbbdirectory_suscribe_controller', array('cat_id' => $cat_id, 'mode' => $is_watching ? 'unwatch' : 'watch')); $s_watching['link_toggle'] = $this->helper->route('ernadoo_phpbbdirectory_suscribe_controller', array('cat_id' => $cat_id, 'mode' => !$is_watching ? 'unwatch' : 'watch')); $s_watching['title'] = $this->user->lang[($is_watching ? 'DIR_STOP' : 'DIR_START') . '_WATCHING_CAT']; $s_watching['title_toggle'] = $this->user->lang[(!$is_watching ? 'DIR_STOP' : 'DIR_START') . '_WATCHING_CAT']; $s_watching['is_watching'] = $is_watching; } return; }
/** * User details controller * * @param int $uid User ID taken from the URL * @param string $sort_key Sort key: id|username|time|point|action (default: id) * @param string $sort_dir Sort direction: dsc|asc (descending|ascending) (default: dsc) * @return Symfony\Component\HttpFoundation\Response A Symfony Response object * @access public */ public function userdetails($uid, $sort_key, $sort_dir) { $this->user->add_lang_ext('pico/reputation', array('reputation_system', 'reputation_rating')); $is_ajax = $this->request->is_ajax(); $referer = $this->symfony_request->get('_referer'); if (empty($this->config['rs_enable'])) { if ($is_ajax) { $json_response = new \phpbb\json_response(); $json_data = array('error_msg' => $this->user->lang('RS_DISABLED')); $json_response->send($json_data); } redirect(append_sid("{$this->root_path}index.{$this->php_ext}")); } $sql = 'SELECT user_id, username, user_colour FROM ' . USERS_TABLE . ' WHERE user_type <> 2 AND user_id =' . (int) $uid; $result = $this->db->sql_query($sql); $user_row = $this->db->sql_fetchrow($result); $this->db->sql_freeresult($result); if (empty($user_row)) { $message = $this->user->lang('RS_NO_USER_ID'); $json_data = array('error_msg' => $message); $redirect = append_sid("{$this->root_path}index.{$this->php_ext}"); $redirect_text = 'RETURN_INDEX'; $this->reputation_manager->response($message, $json_data, $redirect, $redirect_text, $is_ajax); } if (!$this->auth->acl_get('u_rs_view')) { $message = $this->user->lang('RS_VIEW_DISALLOWED'); $json_data = array('error_msg' => $message); $redirect = append_sid("memberlist.{$this->php_ext}", 'mode=viewprofile&u=' . $uid); $redirect_text = 'RETURN_PAGE'; $this->reputation_manager->response($message, $json_data, $redirect, $redirect_text, $is_ajax); } $sort_key_sql = array('username' => 'u.username_clean', 'time' => 'r.reputation_time', 'point' => 'r.reputation_points', 'action' => 'rt.reputation_type_name', 'id' => 'r.reputation_id'); // Sql order depends on sort key $order_by = $sort_key_sql[$sort_key] . ' ' . ($sort_dir == 'dsc' ? 'DESC' : 'ASC'); $reputation_type_id = (int) $this->reputation_manager->get_reputation_type_id('post'); $sql_array = array('SELECT' => 'r.*, rt.reputation_type_name, u.username, u.user_colour, u.user_avatar, u.user_avatar_type, u.user_avatar_width, u.user_avatar_height, p.post_id, p.forum_id, p.post_subject', 'FROM' => array($this->reputations_table => 'r', $this->reputation_types_table => 'rt'), 'LEFT_JOIN' => array(array('FROM' => array(USERS_TABLE => 'u'), 'ON' => 'u.user_id = r.user_id_from'), array('FROM' => array(POSTS_TABLE => 'p'), 'ON' => 'p.post_id = r.reputation_item_id AND r.reputation_type_id = ' . $reputation_type_id)), 'WHERE' => 'r.user_id_to = ' . $uid . ' AND r.reputation_type_id = rt.reputation_type_id', 'ORDER_BY' => $order_by); $sql = $this->db->sql_build_query('SELECT', $sql_array); $result = $this->db->sql_query($sql); while ($row = $this->db->sql_fetchrow($result)) { $this->template->assign_block_vars('reputation', array('ID' => $row['reputation_id'], 'USERNAME' => get_username_string('full', $row['user_id_from'], $row['username'], $row['user_colour']), 'ACTION' => $this->user->lang('RS_' . strtoupper($row['reputation_type_name']) . '_RATING'), 'AVATAR' => phpbb_get_user_avatar($row), 'TIME' => $this->user->format_date($row['reputation_time']), 'COMMENT' => $row['reputation_comment'], 'POINTS' => $row['reputation_points'], 'POINTS_CLASS' => $this->reputation_helper->reputation_class($row['reputation_points']), 'POINTS_TITLE' => $this->user->lang('RS_POINTS_TITLE', $row['reputation_points']), 'U_DELETE' => $this->helper->route('reputation_delete_controller', array('rid' => $row['reputation_id'])), 'S_COMMENT' => !empty($row['reputation_comment']), 'S_DELETE' => $this->auth->acl_get('m_rs_moderate') || $row['user_id_from'] == $this->user->data['user_id'] && $this->auth->acl_get('u_rs_delete') ? true : false)); // Generate post url $this->reputation_manager->generate_post_link($row); } $this->db->sql_freeresult($result); $this->template->assign_vars(array('USER_ID' => $uid, 'U_USER_DETAILS' => $this->helper->route('reputation_details_controller', array('uid' => $uid)), 'U_SORT_USERNAME' => $this->helper->route('reputation_user_details_controller', array('uid' => $uid, 'sort_key' => 'username', 'sort_dir' => $sort_key == 'username' && $sort_dir == 'asc' ? 'dsc' : 'asc')), 'U_SORT_TIME' => $this->helper->route('reputation_user_details_controller', array('uid' => $uid, 'sort_key' => 'time', 'sort_dir' => $sort_key == 'time' && $sort_dir == 'asc' ? 'dsc' : 'asc')), 'U_SORT_POINT' => $this->helper->route('reputation_user_details_controller', array('uid' => $uid, 'sort_key' => 'point', 'sort_dir' => $sort_key == 'point' && $sort_dir == 'asc' ? 'dsc' : 'asc')), 'U_SORT_ACTION' => $this->helper->route('reputation_user_details_controller', array('uid' => $uid, 'sort_key' => 'action', 'sort_dir' => $sort_key == 'action' && $sort_dir == 'asc' ? 'dsc' : 'asc')), 'U_CLEAR' => $this->helper->route('reputation_clear_user_controller', array('uid' => $uid)), 'U_REPUTATION_REFERER' => $referer, 'L_RS_USER_REPUTATION' => $this->user->lang('RS_USER_REPUTATION', get_username_string('username', $user_row['user_id'], $user_row['username'], $user_row['user_colour'])), 'S_RS_AVATAR' => $this->config['rs_display_avatar'] ? true : false, 'S_RS_COMMENT' => $this->config['rs_enable_comment'] ? true : false, 'S_RS_POINTS_IMG' => $this->config['rs_point_type'] ? true : false, 'S_CLEAR' => $this->auth->acl_gets('m_rs_moderate') ? true : false, 'S_IS_AJAX' => $is_ajax ? true : false)); return $this->helper->render('userdetails.html'); }
/** * Gets suggestions for tags based on a ajax request, route: /tags/suggest * * @param php://input raw post data must contain a json-encoded object of this structure: {"query":"...", "exclude":["...", "...", ...]} */ public function suggest_tags() { if (false && $this->request->is_ajax()) { $data = json_decode(file_get_contents('php://input'), true); $query = $data['query']; $exclude = $data['exclude']; $tags = $this->tags_manager->get_tag_suggestions($query, $exclude, 5); $json_response = new json_response(); $json_response->send($tags); } // fake a 404 return $this->helper->error($this->user->lang('RH_TOPICTAGS_TAG_SUGGEST_TAG_ROUTE_ERROR', $this->helper->get_current_url()), 404); }
/** * Board Announcements controller accessed from the URL /boardannouncements/close * * @throws \phpbb\exception\http_exception An http exception * @return \Symfony\Component\HttpFoundation\JsonResponse A Symfony JSON Response object * @access public */ public function close_announcement() { // Check the link hash to protect against CSRF/XSRF attacks if (!check_link_hash($this->request->variable('hash', ''), 'close_boardannouncement') || !$this->config['board_announcements_dismiss']) { throw new \phpbb\exception\http_exception(403, 'NO_AUTH_OPERATION'); } // Set a cookie $response = $this->set_board_announcement_cookie(); // Close the announcement for registered users if ($this->user->data['is_registered']) { $response = $this->update_board_announcement_status(); } // Send a JSON response if an AJAX request was used if ($this->request->is_ajax()) { return new \Symfony\Component\HttpFoundation\JsonResponse(array('success' => $response)); } // Redirect the user back to their last viewed page (non-AJAX requests) $redirect = $this->request->variable('redirect', $this->user->data['session_page']); $redirect = reapply_sid($redirect); redirect($redirect); // We shouldn't get here, but throw an http exception just in case throw new \phpbb\exception\http_exception(500, 'GENERAL_ERROR'); }
/** * {@inheritdoc} */ public function delete_autogroup_rule($autogroups_id) { // Delete and auto group rule $sql = 'DELETE FROM ' . $this->autogroups_rules_table . ' WHERE autogroups_id = ' . (int) $autogroups_id; $this->db->sql_query($sql); // Log the action $this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'ACP_AUTOGROUPS_DELETE_LOG', time()); // If AJAX was used, show user a result message if ($this->request->is_ajax()) { $json_response = new \phpbb\json_response(); $json_response->send(array('MESSAGE_TITLE' => $this->user->lang('INFORMATION'), 'MESSAGE_TEXT' => $this->user->lang('ACP_AUTOGROUPS_DELETE_SUCCESS'), 'REFRESH_DATA' => array('time' => 3))); } }
/** * Ajax submit * * @param object $event The event object * @return array * @access public */ public function ajax_submit($event) { if ($this->config['qr_ajax_submit'] && $this->request->is_ajax() && $this->request->is_set_post('qr')) { $json_response = new \phpbb\json_response(); $data = $event['data']; if (!$this->auth->acl_get('f_noapprove', $data['forum_id']) && empty($data['force_approved_state']) || isset($data['force_approved_state']) && !$data['force_approved_state']) { // No approve $json_response->send(array('noapprove' => true, 'MESSAGE_TITLE' => $this->user->lang['INFORMATION'], 'MESSAGE_TEXT' => $this->user->lang['POST_STORED_MOD'] . ($this->user->data['user_id'] == ANONYMOUS ? '' : ' ' . $this->user->lang['POST_APPROVAL_NOTIFY']), 'REFRESH_DATA' => array('time' => 10))); } $qr_cur_post_id = $this->request->variable('qr_cur_post_id', 0); $url_hash = strpos($event['url'], '#'); $result_url = $url_hash !== false ? substr($event['url'], 0, $url_hash) : $event['url']; $json_response->send(array('success' => true, 'url' => $result_url, 'merged' => $qr_cur_post_id === $data['post_id'] ? 'merged' : 'not_merged')); } }
/** * Creates an ajax response or a normal response depending on the request. * * @param string $u_action phpbb acp-u_action * @param string $msg the message for the normal response * @param boolean $success whether the response is marked successful (default) or not * @param array $ajax_response optional values to response in ajax_response. If no values are * given the response will be for success==true: * <pre>array( * 'success' => true, * 'msg' => base64_encode(rawurlencode($msg)) * )</pre> * and for success==false: * <pre>array( * 'success' => false, * 'error_msg' => base64_encode(rawurlencode($msg)) * )</pre> */ private function simple_response($u_action, $msg, $success = true, array $ajax_response = array()) { if ($this->request->is_ajax()) { if (empty($ajax_response)) { $msg_key = $success ? 'msg' : 'error_msg'; $ajax_response = array('success' => $success, $msg_key => base64_encode(rawurlencode($msg))); } $response = new json_response(); $response->send($ajax_response); } if ($success) { trigger_error($msg . adm_back_link($u_action)); } else { trigger_error($msg . adm_back_link($u_action), E_USER_WARNING); } }
public function profile_side_switcher($event) { $topic_data = $event['topic_data']; $forum_id = $event['forum_id']; if ($this->request->is_set('pss')) { $pss_left = $this->request->variable('pss', 0); $sql = 'UPDATE ' . USERS_TABLE . ' SET allow_pss_left = ' . (int) $pss_left . ' WHERE user_id = ' . (int) $this->user->data['user_id']; $result = $this->db->sql_query($sql); if ($this->request->is_ajax()) { $json_response = new \phpbb\json_response(); $json_response->send(array('success' => $result ? true : false)); } $this->db->sql_freeresult($result); } $this->template->assign_vars(array('PSS_URL_LEFT' => append_sid("{$this->phpbb_root_path}viewtopic.{$this->php_ext}", 'f=' . $forum_id . '&t=' . $topic_data['topic_id'] . '&pss=1'), 'PSS_URL_RIGHT' => append_sid("{$this->phpbb_root_path}viewtopic.{$this->php_ext}", 'f=' . $forum_id . '&t=' . $topic_data['topic_id'] . '&pss=0'))); }
/** * Move a rule up/down * * @param int $rule_id The rule identifier to move * @param string $direction The direction (up|down) * @param int $amount The number of places to move the rule * @return null * @access public */ public function move_rule($rule_id, $direction, $amount = 1) { // If the link hash is invalid, stop and show an error message to the user if (!check_link_hash($this->request->variable('hash', ''), $direction . $rule_id)) { trigger_error($this->user->lang('FORM_INVALID') . adm_back_link($this->u_action), E_USER_WARNING); } // Move the rule $this->rule_operator->move($rule_id, $direction, $amount); // Send a JSON response if an AJAX request was used if ($this->request->is_ajax()) { $json_response = new \phpbb\json_response(); $json_response->send(array('success' => true)); } // Initiate and load the rule entity for no AJAX request /* @var $entity \phpbb\boardrules\entity\rule */ $entity = $this->container->get('phpbb.boardrules.entity')->load($rule_id); // Use a redirect to reload the current page redirect("{$this->u_action}&language={$entity->get_language()}&parent_id={$entity->get_parent_id()}"); }
/** * Delete a page * * @param int $page_id The page identifier to delete * @return null * @access public */ public function delete_page($page_id) { // Initiate and load the page entity /* @var $entity \phpbb\pages\entity\page */ $entity = $this->container->get('phpbb.pages.entity')->load($page_id); try { // Delete the page $this->page_operator->delete_page($page_id); } catch (\phpbb\pages\exception\base $e) { // Display an error message if delete failed trigger_error($this->user->lang('ACP_PAGES_DELETE_ERRORED') . adm_back_link($this->u_action), E_USER_WARNING); } // Log the action $this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'ACP_PAGES_DELETED_LOG', time(), array($entity->get_title())); // If AJAX was used, show user a result message if ($this->request->is_ajax()) { $json_response = new \phpbb\json_response(); $json_response->send(array('MESSAGE_TITLE' => $this->user->lang('INFORMATION'), 'MESSAGE_TEXT' => $this->user->lang('ACP_PAGES_DELETE_SUCCESS'), 'REFRESH_DATA' => array('time' => 3))); } }
/** * Add a vote in db, for a specifi link * * @param int $link_id Link_id from db * @return null */ public function add_vote($link_id) { $data = array('vote_link_id' => (int) $link_id, 'vote_user_id' => $this->user->data['user_id'], 'vote_note' => $this->request->variable('vote', 0)); $this->db->sql_transaction('begin'); $sql = 'INSERT INTO ' . DIR_VOTE_TABLE . ' ' . $this->db->sql_build_array('INSERT', $data); $this->db->sql_query($sql); $sql = 'UPDATE ' . DIR_LINK_TABLE . ' SET link_vote = link_vote + 1, link_note = link_note + ' . (int) $data['vote_note'] . ' WHERE link_id = ' . (int) $link_id; $this->db->sql_query($sql); $this->db->sql_transaction('commit'); if ($this->request->is_ajax()) { $sql = 'SELECT link_vote, link_note FROM ' . DIR_LINK_TABLE . ' WHERE link_id = ' . (int) $link_id; $result = $this->db->sql_query($sql); $data = $this->db->sql_fetchrow($result); $note = $this->display_note($data['link_note'], $data['link_vote'], true); $json_response = new \phpbb\json_response(); $json_response->send(array('success' => true, 'MESSAGE_TITLE' => $this->user->lang['INFORMATION'], 'MESSAGE_TEXT' => $this->user->lang['DIR_VOTE_OK'], 'NOTE' => $note, 'NB_VOTE' => $this->user->lang('DIR_NB_VOTES', (int) $data['link_vote']), 'LINK_ID' => $link_id)); } }
/** * prune function. * * @param string $value The value * @param string $key The key * @return string The formatted string of this item */ public function truncate_chat($value, $key) { if (!confirm_box(true)) { if ($this->u_action === 'truncate_chat') { confirm_box(false, $this->user->lang['CONFIRM_TRUNCATE_AJAXCHAT'], build_hidden_fields(['i' => $this->id, 'mode' => $this->mode, 'action' => $this->u_action])); } } else { if (!$this->auth->acl_get('a_board')) { trigger_error($this->user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING); } if ($this->u_action === 'truncate_chat') { $sql1 = 'TRUNCATE ' . CHAT_TABLE . ''; $this->db->sql_query($sql1); add_log('admin', 'TRUNCATE_LOG_AJAXCHAT'); if ($this->request->is_ajax()) { trigger_error($this->user->lang['TRUNCATE_CHAT_SUCESS']); } } } $this->id = str_replace("\\", "-", $this->id); $action = append_sid('?i=' . $this->id . '&mode=' . $this->mode . '&action=truncate_chat'); return '<a href="' . $action . '" data-ajax="true"><input class="button2" type="submit" id="' . $key . '_enable" name="' . $key . '_enable" value="' . $this->user->lang['TRUNCATE_NOW'] . '" /></a>'; }
/** * Display message to the user if there where failed login trys * * @param object $event The event object * @return null * @access public */ public function page_footer($event) { // clear failed_logins_count_last on user action if ($this->request->is_set('failedlogins_remove')) { if (check_form_key('failedlogins_remove')) { $sql = 'UPDATE ' . USERS_TABLE . ' SET failed_logins_count_last = 0 WHERE user_id = ' . (int) $this->user->data['user_id']; $this->db->sql_query($sql); if ($this->request->is_ajax()) { trigger_error('REMOVED_FAILED_LOGINS'); } } else { if ($this->request->is_ajax()) { trigger_error('FORM_INVALID', E_USER_WARNING); } } } // Display failed logins if ($this->user->data['failed_logins_count_last'] > 0) { add_form_key('failedlogins_remove'); $this->template->assign_vars(array('U_REMOVE_MESSAGE' => generate_board_url() . '/' . $this->user->page['page'], 'FAILED_LOGINS' => $this->user->data['failed_logins_count_last'] == 1 ? $this->user->lang['ONE_FAILED_LOGIN'] : sprintf($this->user->lang['FAILED_LOGINS_COUNT'], $this->user->data['failed_logins_count_last']))); } }
/** * 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']); }