Exemple #1
0
 public function modify_posting($event)
 {
     if ($event['mode'] == 'post' && !$event['forum_id']) {
         $forum_ary = array();
         $forum_read_ary = $this->auth->acl_getf('f_read');
         foreach ($forum_read_ary as $forum_id => $allowed) {
             if ($allowed['f_read'] && $this->auth->acl_get('f_post', $forum_id)) {
                 if (!$this->exclude_forum($forum_id, $this->config['newtopic_forum'])) {
                     continue;
                 }
                 $forum_ary[] = (int) $forum_id;
             }
         }
         if (sizeof($forum_ary)) {
             // Fetching topics of public forums
             $sql = 'SELECT forum_id, forum_name, forum_type FROM ' . FORUMS_TABLE . "\n\t\t\t\t\tWHERE " . $this->db->sql_in_set('forum_id', $forum_ary) . "\n\t\t\t\t\t\tAND forum_type != " . FORUM_LINK;
             $result = $this->db->sql_query($sql);
             $forumrow = $this->db->sql_fetchrowset($result);
             $this->db->sql_freeresult($result);
             $s_forum_options = '<select id="f" name="f" onchange="this.form.submit();">';
             foreach ($forumrow as $row) {
                 $s_forum_options .= '<option value="' . $row['forum_id'] . '"' . ($row['forum_id'] == $forum_id ? ' selected="selected"' : '') . '' . ($row['forum_type'] == FORUM_CAT ? ' disabled="disabled" class="disabled-option"' : '') . '>' . ($row['forum_type'] != FORUM_CAT ? '&nbsp;&nbsp;' : '') . $row['forum_name'] . '</option>';
                 $forum_id = $row['forum_type'] == FORUM_POST ? $row['forum_id'] : '';
             }
             $s_forum_options .= '</select>';
             $this->template->assign_vars(array('S_FORUM_OPTIONS' => $s_forum_options, 'S_FORUM_OPT_TRUE' => $forum_id ? true : false));
             $event['forum_id'] = $forum_id;
         }
     }
 }
 /**
  * {@inheritdoc}
  */
 protected function get_records_by_range($min_id, $max_id)
 {
     $sql = $this->get_records_by_range_query($min_id, $max_id);
     $result = $this->db->sql_query($sql);
     $records = $this->db->sql_fetchrowset($result);
     $this->db->sql_freeresult($result);
     return $records;
 }
Exemple #3
0
 /**
  * {@inheritdoc}
  */
 public function get_group_rules($type = '')
 {
     $sql_array = array('SELECT' => 'agr.*, agt.autogroups_type_name', 'FROM' => array($this->autogroups_rules_table => 'agr', $this->autogroups_types_table => 'agt'), 'WHERE' => 'agr.autogroups_type_id = agt.autogroups_type_id' . ($type ? " AND agt.autogroups_type_name = '" . $this->db->sql_escape($type) . "'" : ''));
     $sql = $this->db->sql_build_query('SELECT', $sql_array);
     $result = $this->db->sql_query($sql, 7200);
     $rows = $this->db->sql_fetchrowset($result);
     $this->db->sql_freeresult($result);
     return $rows;
 }
    /**
     * Get batch.
     *
     * @return array
     */
    protected function get_batch()
    {
        $sql = 'SELECT DISTINCT topic_id, post_user_id
			FROM ' . $this->posts_table . '
			WHERE post_approved = 1
				AND post_deleted = 0';
        $result = $this->db->sql_query_limit($sql, $this->limit, $this->start);
        $rows = $this->db->sql_fetchrowset($result);
        $this->db->sql_freeresult($result);
        return $rows;
    }
Exemple #5
0
    /**
     * {@inheritdoc}
     */
    protected function get_records_by_range($min_id, $max_id)
    {
        $sql = 'SELECT o.topic_id, o.poll_option_id, o.poll_option_text AS text, p.enable_bbcode, p.enable_smilies, p.enable_magic_url, p.bbcode_uid
			FROM ' . POLL_OPTIONS_TABLE . ' o, ' . TOPICS_TABLE . ' t, ' . POSTS_TABLE . ' p
			WHERE o.topic_id BETWEEN ' . $min_id . ' AND ' . $max_id . '
				AND t.topic_id = o.topic_id
				AND p.post_id = t.topic_first_post_id';
        $result = $this->db->sql_query($sql);
        $records = $this->db->sql_fetchrowset($result);
        $this->db->sql_freeresult($result);
        return $records;
    }
    /**
     * Display the flags
     *
     * @return null
     * @access public
     */
    public function display_flags()
    {
        $start = $this->request->variable('start', 0);
        $pagination_url = $this->u_action;
        $this->user->add_lang_ext('rmcgirr83/nationalflags', 'common');
        $sql = 'SELECT f.*, COUNT(u.user_flag) as user_count
			FROM ' . $this->flags_table . ' f
				LEFT JOIN ' . USERS_TABLE . " u on f.flag_id = u.user_flag\n\t\t\tGROUP BY f.flag_id\n\t\t\tORDER BY f.flag_name ASC";
        $result = $this->db->sql_query_limit($sql, $this->config['topics_per_page'], $start);
        // for counting of all the flags
        // used for pagination
        $result2 = $this->db->sql_query($sql);
        $row2 = $this->db->sql_fetchrowset($result2);
        $total_count = (int) sizeof($row2);
        $this->db->sql_freeresult($result2);
        unset($row2);
        while ($row = $this->db->sql_fetchrow($result)) {
            $user_count = $this->user->lang('FLAG_USERS', (int) $row['user_count']);
            $this->template->assign_block_vars('flags', array('FLAG_NAME' => $row['flag_name'], 'FLAG_IMG' => $this->ext_path_web . 'flags/' . strtolower($row['flag_image']), 'FLAG_ID' => $row['flag_id'], 'USER_COUNT' => $user_count, 'U_FLAG' => $this->helper->route('rmcgirr83_nationalflags_getflags', array('flag_id' => $row['flag_id'])), 'U_EDIT' => $this->u_action . "&amp;flag_id={$row['flag_id']}&amp;action=edit", 'U_DELETE' => $this->u_action . "&amp;flag_id={$row['flag_id']}&amp;action=delete"));
        }
        $this->db->sql_freeresult($result);
        $start = $this->pagination->validate_start($start, $this->config['topics_per_page'], $total_count);
        $this->pagination->generate_template_pagination($pagination_url, 'pagination', 'start', $total_count, $this->config['topics_per_page'], $start);
        $this->template->assign_vars(array('TOTAL_FLAGS' => $total_count, 'S_FLAGS' => true));
    }
    /**
     * Returns an array of message IDs that have been deleted from the message table
     */
    public function mchat_missing_ids($start_id, $end_id)
    {
        if ($this->config['mchat_edit_delete_limit']) {
            $sql_where = 'message_time < ' . (time() - $this->config['mchat_edit_delete_limit']);
            $cache_ttl = 0;
        } else {
            $sql_where = 'message_id < ' . (int) $start_id;
            $cache_ttl = 3600;
        }
        $sql = 'SELECT message_id
			FROM ' . $this->mchat_table . '
			WHERE ' . $sql_where . '
			ORDER BY message_id DESC';
        $result = $this->db->sql_query_limit($sql, 1, 0, $cache_ttl);
        $earliest_id = (int) $this->db->sql_fetchfield('message_id');
        $this->db->sql_freeresult($result);
        if (!$earliest_id) {
            $sql = 'SELECT MIN(message_id) as earliest_id
				FROM ' . $this->mchat_table;
            $result = $this->db->sql_query($sql, 3600);
            $earliest_id = $this->db->sql_fetchfield('earliest_id');
            $this->db->sql_freeresult($result);
        }
        if (!$earliest_id) {
            return range($start_id, $end_id);
        }
        $sql = 'SELECT (t1.message_id + 1) AS start, (
			SELECT MIN(t3.message_id) - 1
			FROM ' . $this->mchat_table . ' t3
			WHERE t3.message_id > t1.message_id
		) AS end
		FROM ' . $this->mchat_table . ' t1
		WHERE t1.message_id > ' . (int) $earliest_id . ' AND NOT EXISTS (
			SELECT t2.message_id
			FROM ' . $this->mchat_table . ' t2
			WHERE t2.message_id = t1.message_id + 1
		)';
        $result = $this->db->sql_query($sql);
        $rows = $this->db->sql_fetchrowset($result);
        $this->db->sql_freeresult($result);
        $missing_ids = array();
        if ($start_id < $earliest_id && !$this->config['mchat_edit_delete_limit']) {
            $missing_ids[] = range($start_id, $earliest_id - 1);
        }
        foreach ($rows as $row) {
            if ($row['end']) {
                $missing_ids[] = range($row['start'], $row['end']);
            } else {
                $latest_message = $row['start'] - 1;
                if ($end_id > $latest_message) {
                    $missing_ids[] = range($latest_message + 1, $end_id);
                }
            }
        }
        // Flatten
        if (!empty($missing_ids)) {
            $missing_ids = call_user_func_array('array_merge', $missing_ids);
        }
        return $missing_ids;
    }
Exemple #8
0
    /**
     * {@inheritdoc}
     */
    public function get_auth_link_data($user_id = 0)
    {
        $block_vars = array();
        // Get all external accounts tied to the current user
        $data = array('user_id' => $user_id <= 0 ? (int) $this->user->data['user_id'] : (int) $user_id);
        $sql = 'SELECT oauth_provider_id, provider FROM ' . $this->auth_provider_oauth_token_account_assoc . '
			WHERE ' . $this->db->sql_build_array('SELECT', $data);
        $result = $this->db->sql_query($sql);
        $rows = $this->db->sql_fetchrowset($result);
        $this->db->sql_freeresult($result);
        $oauth_user_ids = array();
        if ($rows !== false && sizeof($rows)) {
            foreach ($rows as $row) {
                $oauth_user_ids[$row['provider']] = $row['oauth_provider_id'];
            }
        }
        unset($rows);
        foreach ($this->service_providers as $service_name => $service_provider) {
            // Only include data if the credentials are set
            $credentials = $service_provider->get_service_credentials();
            if ($credentials['key'] && $credentials['secret']) {
                $actual_name = str_replace('auth.provider.oauth.service.', '', $service_name);
                $block_vars[$service_name] = array('HIDDEN_FIELDS' => array('link' => !isset($oauth_user_ids[$actual_name]), 'oauth_service' => $actual_name), 'SERVICE_NAME' => $this->user->lang['AUTH_PROVIDER_OAUTH_SERVICE_' . strtoupper($actual_name)], 'UNIQUE_ID' => isset($oauth_user_ids[$actual_name]) ? $oauth_user_ids[$actual_name] : null);
            }
        }
        return array('BLOCK_VAR_NAME' => 'oauth', 'BLOCK_VARS' => $block_vars, 'TEMPLATE_FILE' => 'ucp_auth_link_oauth.html');
    }
Exemple #9
0
 /**
  * Return the list of censored words
  *
  * @return array
  */
 public function get_censored_words()
 {
     $sql = 'SELECT word, replacement FROM ' . $this->words_table;
     $result = $this->db->sql_query($sql);
     $rows = $this->db->sql_fetchrowset($result);
     $this->db->sql_freeresult($result);
     return $rows;
 }
Exemple #10
0
    /**
     * Lists all styles
     *
     * @return array Rows with styles data
     */
    protected function get_styles()
    {
        $sql = 'SELECT *
			FROM ' . STYLES_TABLE;
        $result = $this->db->sql_query($sql);
        $rows = $this->db->sql_fetchrowset($result);
        $this->db->sql_freeresult($result);
        return $rows;
    }
Exemple #11
0
    /**
     * Get attachments
     *
     * @param string $conditions	SQL conditions
     * @return array
     */
    protected function get_attachments($conditions)
    {
        $sql = 'SELECT *
			FROM ' . TITANIA_ATTACHMENTS_TABLE . "\n\t\t\tWHERE {$conditions}";
        $result = $this->db->sql_query_limit($sql, 25);
        $attachments = $this->db->sql_fetchrowset($result);
        $this->db->sql_freeresult($result);
        return $attachments;
    }
    /**
     * Get style data from the styles table
     *
     * @return	Array of style data
     * @access	protected
     */
    protected function get_styles()
    {
        $sql = 'SELECT style_id, style_name, topic_preview_theme
			FROM ' . STYLES_TABLE . '
			WHERE style_active = 1';
        $result = $this->db->sql_query($sql);
        $rows = $this->db->sql_fetchrowset($result);
        $this->db->sql_freeresult($result);
        return $rows;
    }
    /**
     * Get batch of rows to process.
     *
     * @return array
     */
    protected function get_batch()
    {
        $sql_ary = array('SELECT' => 'c.contrib_id, c.contrib_type, c.contrib_status, c.contrib_user_id, ca.user_id', 'FROM' => array($this->contribs_table => 'c'), 'LEFT_JOIN' => array(array('FROM' => array($this->contrib_coauthors_table => 'ca'), 'ON' => 'ca.contrib_id = c.contrib_id')), 'WHERE' => 'c.contrib_visible = 1
				AND ' . $this->db->sql_in_set('c.contrib_status', $this->valid_statuses), 'ORDER_BY' => 'c.contrib_id');
        $sql = $this->db->sql_build_query('SELECT', $sql_ary);
        $result = $this->db->sql_query_limit($sql, $this->limit, $this->start);
        $rows = $this->db->sql_fetchrowset($result);
        $this->db->sql_freeresult($result);
        return $rows;
    }
    /**
     * Get all auto group rules from the database
     *
     * @return array Array of auto group rules and their associated data
     * @access public
     */
    protected function get_all_autogroups()
    {
        $sql_array = array('SELECT' => 'agr.*, agt.autogroups_type_name, g.group_name', 'FROM' => array($this->autogroups_rules_table => 'agr', $this->autogroups_types_table => 'agt', GROUPS_TABLE => 'g'), 'WHERE' => 'agr.autogroups_type_id = agt.autogroups_type_id
				AND agr.autogroups_group_id = g.group_id', 'ORDER_BY' => 'g.group_name ASC, autogroups_min_value ASC');
        $sql = $this->db->sql_build_query('SELECT', $sql_array);
        $result = $this->db->sql_query($sql);
        $rows = $this->db->sql_fetchrowset($result);
        $this->db->sql_freeresult($result);
        return $rows;
    }
Exemple #15
0
    /**
     * Get page link location names and identifiers
     *
     * @return array Array of page link location names and identifiers
     * @access public
     */
    public function get_link_locations()
    {
        $sql = 'SELECT page_link_id, page_link_location
			FROM ' . $this->pages_links_table . '
			ORDER BY page_link_id ASC';
        $result = $this->db->sql_query($sql);
        $rows = $this->db->sql_fetchrowset($result);
        $this->db->sql_freeresult($result);
        return $rows;
    }
Exemple #16
0
    /**
     * Add & read action
     *
     * @return bool
     */
    private function addAction()
    {
        $this->get = true;
        $message = utf8_normalize_nfc($this->request->variable('message', '', true));
        if (!$message) {
            return;
        }
        $this->clean_message($message);
        $uid = $bitfield = $options = '';
        $allow_bbcode = $this->auth->acl_get('u_ajaxchat_bbcode');
        $allow_urls = $allow_smilies = true;
        generate_text_for_storage($message, $uid, $bitfield, $options, $allow_bbcode, $allow_urls, $allow_smilies);
        $sql_ary = ['chat_id' => 1, 'user_id' => $this->user->data['user_id'], 'username' => $this->user->data['username'], 'user_colour' => $this->user->data['user_colour'], 'message' => $message, 'bbcode_bitfield' => $bitfield, 'bbcode_uid' => $uid, 'bbcode_options' => $options, 'time' => time()];
        $sql = 'INSERT INTO ' . CHAT_TABLE . ' ' . $this->db->sql_build_array('INSERT', $sql_ary);
        $this->db->sql_query($sql);
        $sql_ary2 = ['username' => $this->user->data['username'], 'user_colour' => $this->user->data['user_colour'], 'user_lastpost' => time(), 'user_lastupdate' => time()];
        $sql = 'UPDATE ' . CHAT_SESSIONS_TABLE . ' SET ' . $this->db->sql_build_array('UPDATE', $sql_ary2) . " WHERE user_id = {$this->user->data['user_id']}";
        $result = $this->db->sql_query($sql);
        $sql = 'SELECT c.*, p.post_visibility, u.user_avatar, u.user_avatar_type, u.user_avatar_width, u.user_avatar_height
				FROM ' . CHAT_TABLE . ' as c
				LEFT JOIN ' . USERS_TABLE . ' as u ON c.user_id = u.user_id
				LEFT JOIN ' . POSTS_TABLE . ' as p ON c.post_id = p.post_id
				WHERE c.message_id > ' . $this->last_id . '
				ORDER BY c.message_id DESC';
        $result = $this->db->sql_query_limit($sql, (int) $this->config['ajax_chat_chat_amount']);
        $rows = $this->db->sql_fetchrowset($result);
        if (!sizeof($rows) && time() - 60 < $this->last_time) {
            exit;
        }
        foreach ($rows as $row) {
            if ($row['forum_id'] && !$row['post_visibility'] == ITEM_APPROVED && !$this->auth->acl_get('m_approve', $row['forum_id'])) {
                continue;
            }
            if ($row['forum_id'] && !$this->auth->acl_get('f_read', $row['forum_id'])) {
                continue;
            }
            $avatar = ['avatar' => $row['user_avatar'], 'avatar_type' => $row['user_avatar_type'], 'avatar_height' => $row['user_avatar_height'], 'avatar_width' => $row['user_avatar_width']];
            $avatar_thumb = ['avatar' => $row['user_avatar'], 'avatar_type' => $row['user_avatar_type'], 'avatar_height' => '', 'avatar_width' => 35];
            $row['avatar'] = $this->user->optionget('viewavatars') ? phpbb_get_avatar($avatar, '') : '';
            $row['avatar_thumb'] = $this->user->optionget('viewavatars') ? phpbb_get_avatar($avatar_thumb, '') : '';
            if ($this->count++ == 0) {
                $this->last_id = $row['message_id'];
                $this->template->assign_vars(['SOUND_ENABLED' => true, 'SOUND_FILE' => 'soundout']);
            }
            if ($this->config['ajax_chat_time_setting']) {
                $time = $this->config['ajax_chat_time_setting'];
            } else {
                $time = $this->user->data['user_dateformat'];
            }
            $this->template->assign_block_vars('chatrow', ['MESSAGE_ID' => $row['message_id'], 'USERNAME_FULL' => $this->clean_username(get_username_string('full', $row['user_id'], $row['username'], $row['user_colour'], $this->user->lang['GUEST'])), 'USERNAME_A' => $row['username'], 'USER_COLOR' => $row['user_colour'], 'MESSAGE' => generate_text_for_display($row['message'], $row['bbcode_uid'], $row['bbcode_bitfield'], $row['bbcode_options']), 'TIME' => $this->user->format_date($row['time'], $time), 'CLASS' => $row['message_id'] % 2 ? 1 : 2, 'USER_AVATAR' => $row['avatar'], 'USER_AVATAR_THUMB' => $row['avatar_thumb']]);
        }
        $this->db->sql_freeresult($result);
        return;
    }
    /**
     * Get forums list
     *
     * @return array	forum data rows
     * @access protected
     */
    protected function get_forum_list()
    {
        $sql = 'SELECT forum_id, forum_name, similar_topic_forums
			FROM ' . FORUMS_TABLE . '
			WHERE forum_type = ' . FORUM_POST . '
			ORDER BY left_id ASC';
        $result = $this->db->sql_query($sql);
        $forum_list = $this->db->sql_fetchrowset($result);
        $this->db->sql_freeresult($result);
        return $forum_list;
    }
Exemple #18
0
    /**
     * Load attachments by id.
     *
     * Note that this will not check the object type or id.
     * 
     * @param array $ids
     * @return $this
     */
    public function load_from_ids(array $ids)
    {
        if (!$ids) {
            return $this;
        }
        $sql = 'SELECT *
			FROM ' . $this->attachments_table . '
			WHERE ' . $this->db->sql_in_set('attachment_id', array_map('intval', $ids));
        $result = $this->db->sql_query($sql);
        $this->store($this->db->sql_fetchrowset($result));
        $this->db->sql_freeresult($result);
        return $this;
    }
    /**
     * Regenerate left/right ids from parent/child relationship
     *
     * This method regenerates the left/right ids for the tree based on
     * the parent/child relations. This function executes three queries per
     * item, so it should only be called, when the set has one of the following
     * problems:
     *	- The set has a duplicated value inside the left/right id chain
     *	- The set has a missing value inside the left/right id chain
     *	- The set has items that do not have a left/right id set
     *
     * When regenerating the items, the items are sorted by parent id and their
     * current left id, so the current child/parent relationships are kept
     * and running the function on a working set will not change the order.
     *
     * @param int	$new_id		First left_id to be used (should start with 1)
     * @param int	$parent_id	parent_id of the current set (default = 0)
     * @param bool	$reset_ids	Should we reset all left_id/right_id on the first call?
     * @return	int		$new_id		The next left_id/right_id that should be used
     */
    public function regenerate_left_right_ids($new_id, $parent_id = 0, $reset_ids = false)
    {
        if ($acquired_new_lock = $this->acquire_lock()) {
            $this->db->sql_transaction('begin');
            if (!$reset_ids) {
                $sql = 'UPDATE ' . $this->table_name . '
					SET ' . $this->column_item_parents . " = ''\n\t\t\t\t\t" . $this->get_sql_where('WHERE');
                $this->db->sql_query($sql);
            }
        }
        if ($reset_ids) {
            $sql = 'UPDATE ' . $this->table_name . '
				SET ' . $this->db->sql_build_array('UPDATE', array($this->column_left_id => 0, $this->column_right_id => 0, $this->column_item_parents => '')) . '
				' . $this->get_sql_where('WHERE');
            $this->db->sql_query($sql);
        }
        $sql = 'SELECT *
			FROM ' . $this->table_name . '
			WHERE ' . $this->column_parent_id . ' = ' . (int) $parent_id . '
				' . $this->get_sql_where('AND') . '
			ORDER BY ' . $this->column_left_id . ', ' . $this->column_item_id . ' ASC';
        $result = $this->db->sql_query($sql);
        $rows = $this->db->sql_fetchrowset($result);
        $this->db->sql_freeresult($result);
        foreach ($rows as $row) {
            // First we update the left_id for this module
            if ($row[$this->column_left_id] != $new_id) {
                $sql = 'UPDATE ' . $this->table_name . '
					SET ' . $this->db->sql_build_array('UPDATE', array($this->column_left_id => $new_id)) . '
					WHERE ' . $this->column_item_id . ' = ' . (int) $row[$this->column_item_id];
                $this->db->sql_query($sql);
            }
            $new_id++;
            // Then we go through any children and update their left/right id's
            $new_id = $this->regenerate_left_right_ids($new_id, $row[$this->column_item_id]);
            // Then we come back and update the right_id for this module
            if ($row[$this->column_right_id] != $new_id) {
                $sql = 'UPDATE ' . $this->table_name . '
					SET ' . $this->db->sql_build_array('UPDATE', array($this->column_right_id => $new_id)) . '
					WHERE ' . $this->column_item_id . ' = ' . (int) $row[$this->column_item_id];
                $this->db->sql_query($sql);
            }
            $new_id++;
        }
        if ($acquired_new_lock) {
            $this->db->sql_transaction('commit');
            $this->lock->release();
        }
        return $new_id;
    }
    /**
     * Get batch to process.
     *
     * @param array $types
     * @return array
     */
    protected function get_batch(array $types)
    {
        // Grab our batch
        $sql_ary = array('SELECT' => 'c.contrib_id, c.contrib_user_id, c.contrib_type, c.contrib_name,
				c.contrib_name_clean, c.contrib_desc, c.contrib_desc_uid, c.contrib_release_topic_id,
				t.topic_first_post_id, u.user_id, u.username, u.username_clean, u.user_colour', 'FROM' => array($this->contribs_table => 'c', $this->users_table => 'u'), 'LEFT_JOIN' => array(array('FROM' => array($this->phpbb_topics_table => 't'), 'ON' => 't.topic_id = c.contrib_release_topic_id')), 'GROUP_BY' => 'c.contrib_id', 'WHERE' => $this->db->sql_in_set('c.contrib_status', array(TITANIA_CONTRIB_APPROVED, TITANIA_CONTRIB_DOWNLOAD_DISABLED)) . '
				AND u.user_id = c.contrib_user_id
				AND ' . $this->db->sql_in_set('contrib_type', $types), 'ORDER_BY' => 'c.contrib_id DESC');
        $sql = $this->db->sql_build_query('SELECT', $sql_ary);
        $result = $this->db->sql_query_limit($sql, $this->limit, $this->start);
        $rows = $this->db->sql_fetchrowset($result);
        $this->db->sql_freeresult($result);
        return $rows;
    }
Exemple #21
0
    /**
     * Get extensions from database
     *
     * @return array List of extensions
     */
    private function get_extensions()
    {
        $sql = 'SELECT *
			FROM ' . $this->extension_table;
        $result = $this->db->sql_query($sql);
        $extensions_row = $this->db->sql_fetchrowset($result);
        $this->db->sql_freeresult($result);
        $extensions = array();
        foreach ($extensions_row as $extension) {
            $extensions[$extension['ext_name']] = $extension;
        }
        ksort($extensions);
        return $extensions;
    }
Exemple #22
0
 /**
  * Refresher Read action
  *
  * @return bool
  */
 private function readAction()
 {
     $sql = 'SELECT c.*, u.user_avatar, u.user_avatar_type, u.user_avatar_width, u.user_avatar_height
             FROM ' . CHAT_TABLE . ' as c
             LEFT JOIN ' . USERS_TABLE . ' as u
             ON c.user_id = u.user_id
             WHERE c.message_id > ' . $this->last_id . '
             ORDER BY message_id DESC';
     $result = $this->db->sql_query_limit($sql, (int) $this->config['ajax_chat_archive_amount']);
     $rows = $this->db->sql_fetchrowset($result);
     if (!sizeof($rows) && time() - 60 < $this->last_time) {
         return;
     }
     foreach ($rows as $row) {
         if ($row['forum_id'] && !$this->auth->acl_get('f_read', $row['forum_id'])) {
             continue;
         }
         $avatar = ['avatar' => $row['user_avatar'], 'avatar_type' => $row['user_avatar_type'], 'avatar_height' => $row['user_avatar_height'], 'avatar_width' => $row['user_avatar_width']];
         $avatar_thumb = ['avatar' => $row['user_avatar'], 'avatar_type' => $row['user_avatar_type'], 'avatar_height' => '', 'avatar_width' => 35];
         $row['avatar'] = $this->user->optionget('viewavatars') ? phpbb_get_avatar($avatar, '') : '';
         $row['avatar_thumb'] = $this->user->optionget('viewavatars') ? phpbb_get_avatar($avatar_thumb, '') : '';
         if ($this->count++ === 0) {
             if ($row['message_id'] !== null) {
                 $this->last_id = $row['message_id'];
             } else {
                 $this->last_id = 0;
             }
             $this->template->assign_vars(['SOUND_ENABLED' => true, 'SOUND_FILE' => 'sound']);
         }
         if ($this->config['ajax_chat_time_setting']) {
             $time = $this->config['ajax_chat_time_setting'];
         } else {
             $time = $this->user->data['user_dateformat'];
         }
         $this->template->assign_block_vars('chatrow', ['MESSAGE_ID' => $row['message_id'], 'USERNAME_FULL' => $this->clean_username(get_username_string('full', $row['user_id'], $row['username'], $row['user_colour'], $this->user->lang['GUEST'])), 'USERNAME_A' => $row['username'], 'USER_COLOR' => $row['user_colour'], 'MESSAGE' => make_clickable(generate_text_for_display($row['message'], $row['bbcode_uid'], $row['bbcode_bitfield'], $row['bbcode_options'])), 'TIME' => $this->user->format_date($row['time'], $time), 'CLASS' => $row['message_id'] % 2 ? 1 : 2, 'USER_AVATAR' => $row['avatar'], 'USER_AVATAR_THUMB' => $row['avatar_thumb']]);
     }
     $this->db->sql_freeresult($result);
     if (time() - 60 > $this->last_time) {
         $sql_ary = ['username' => $this->user->data['username'], 'user_colour' => $this->user->data['user_colour'], 'user_lastupdate' => time()];
         $sql = 'UPDATE ' . CHAT_SESSIONS_TABLE . '
         SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . "\n            WHERE user_id = {$this->user->data['user_id']}";
         $result = $this->db->sql_query($sql);
     }
     $this->get = true;
     return;
 }
Exemple #23
0
    public function view_versions($article)
    {
        if (!$this->auth->acl_get('u_wiki_versions')) {
            trigger_error('NOT_AUTHORISED');
        }
        $sql = 'SELECT *
			FROM ' . $this->article_table . '
			WHERE article_url = "' . $this->db->sql_escape($article) . '"
			ORDER BY article_last_edit DESC';
        $result = $this->db->sql_query_limit($sql, 1);
        $this->data = $this->db->sql_fetchrow($result);
        $this->db->sql_freeresult($result);
        $this->template->assign_vars(array('ARTICLE_TITLE' => $this->data['article_title'], 'S_SET_ACTIVE' => $this->auth->acl_get('u_wiki_set_active'), 'S_DELETE' => $this->auth->acl_get('m_wiki_delete'), 'S_DELETE_ARTICLE' => $this->auth->acl_get('m_wiki_delete_article'), 'U_ACTION' => $this->helper->route('tas2580_wiki_article', array('article' => $article, 'action' => 'compare')), 'U_DELETE_ARTICLE' => $this->helper->route('tas2580_wiki_article', array('article' => $article, 'action' => 'detele_article')), 'U_SET_INACTIV' => $this->helper->route('tas2580_wiki_article', array('article' => $article, 'action' => 'deactivate'))));
        if (!empty($article)) {
            $this->template->assign_block_vars('navlinks', array('FORUM_NAME' => $this->data['article_title'], 'U_VIEW_FORUM' => $this->helper->route('tas2580_wiki_article', array('article' => $article))));
        }
        $start = $this->request->variable('start', 0);
        $sql_array = array('SELECT' => 'a.article_id, a.article_title, a.article_last_edit, a.article_approved, a.article_edit_reason, u.user_id, u.username, u.user_colour', 'FROM' => array($this->article_table => 'a'), 'LEFT_JOIN' => array(array('FROM' => array(USERS_TABLE => 'u'), 'ON' => 'u.user_id = a.article_user_id')), 'WHERE' => 'article_url = "' . $this->db->sql_escape($article) . '"', 'ORDER_BY' => 'a.article_last_edit DESC');
        $sql = $this->db->sql_build_query('SELECT', $sql_array);
        $result = $this->db->sql_query_limit($sql, $this->config['topics_per_page'], $start);
        $result2 = $this->db->sql_query($sql);
        $row2 = $this->db->sql_fetchrowset($result2);
        $total_count = (int) sizeof($row2);
        $this->db->sql_freeresult($result2);
        unset($row2);
        $i = 1;
        $has_active_version = false;
        while ($this->data = $this->db->sql_fetchrow($result)) {
            if (!$has_active_version) {
                $has_active_version = $this->data['article_approved'] == 1 ? true : false;
            }
            $this->template->assign_block_vars('version_list', array('ID' => $this->data['article_id'], 'NR' => $i++, 'ARTICLE_TITLE' => $this->data['article_title'], 'EDIT_REASON' => $this->data['article_edit_reason'], 'S_ACTIVE' => $this->data['article_approved'] == 1 ? true : false, 'USER' => get_username_string('full', $this->data['user_id'], $this->data['username'], $this->data['user_colour']), 'EDIT_TIME' => $this->user->format_date($this->data['article_last_edit']), 'U_VERSION' => $this->helper->route('tas2580_wiki_article', array('id' => $this->data['article_id'])), 'U_DELETE' => $this->helper->route('tas2580_wiki_article', array('action' => 'delete', 'id' => $this->data['article_id'])), 'U_SET_ACTIVE' => $this->helper->route('tas2580_wiki_article', array('action' => 'active', 'id' => $this->data['article_id']))));
        }
        $this->db->sql_freeresult($result);
        // No active versions and no right to view inactive articles
        if (!$has_active_version && !$this->auth->acl_get('m_wiki_view_inactive')) {
            trigger_error('NOT_AUTHORISED');
        }
        $pagination_url = $this->helper->route('tas2580_wiki_article', array('article' => $article, 'action' => 'versions'));
        $start = $this->pagination->validate_start($start, $this->config['topics_per_page'], $total_count);
        $this->pagination->generate_template_pagination($pagination_url, 'pagination', 'start', $total_count, $this->config['topics_per_page'], $start);
        $this->template->assign_vars(array('TOTAL_ITEMS' => $this->user->lang('TOTAL_ITEMS', (int) $total_count)));
        return $this->helper->render('article_versions.html', $this->user->lang['VERSIONS_WIKI']);
    }
Exemple #24
0
    /**
     * @dataProvider delete_data
     */
    public function test_delete_data($mode, $expected_users, $expected_zebra, $expected_ban, $expected_sessions, $expected_logs, $expected_pms)
    {
        $this->assertFalse(user_delete($mode, 2));
        $sql = 'SELECT user_id, user_posts
			FROM ' . USERS_TABLE . '
			ORDER BY user_id ASC';
        $result = $this->db->sql_query($sql);
        $this->assertEquals($expected_users, $this->db->sql_fetchrowset($result), 'User table content is mismatching after deleting a user.');
        $this->db->sql_freeresult($result);
        $sql = 'SELECT user_id, zebra_id
			FROM ' . ZEBRA_TABLE . '
			ORDER BY user_id ASC, zebra_id ASC';
        $result = $this->db->sql_query($sql);
        $this->assertEquals($expected_zebra, $this->db->sql_fetchrowset($result), 'Zebra table content is mismatching after deleting a user.');
        $this->db->sql_freeresult($result);
        $sql = 'SELECT ban_id
			FROM ' . BANLIST_TABLE . '
			ORDER BY ban_id ASC';
        $result = $this->db->sql_query($sql);
        $this->assertEquals($expected_ban, $this->db->sql_fetchrowset($result), 'Ban table content is mismatching after deleting a user.');
        $this->db->sql_freeresult($result);
        $sql = 'SELECT session_id
			FROM ' . SESSIONS_TABLE . '
			ORDER BY session_id ASC';
        $result = $this->db->sql_query($sql);
        $this->assertEquals($expected_sessions, $this->db->sql_fetchrowset($result), 'Session table content is mismatching after deleting a user.');
        $this->db->sql_freeresult($result);
        $sql = 'SELECT log_id, user_id, reportee_id
			FROM ' . LOG_TABLE . '
			ORDER BY log_id ASC';
        $result = $this->db->sql_query($sql);
        $this->assertEquals($expected_logs, $this->db->sql_fetchrowset($result), 'Log table content is mismatching after deleting a user.');
        $this->db->sql_freeresult($result);
        $sql = 'SELECT msg_id, author_id, message_edit_user
			FROM ' . PRIVMSGS_TABLE . '
			ORDER BY msg_id ASC';
        $result = $this->db->sql_query($sql);
        $this->assertEquals($expected_pms, $this->db->sql_fetchrowset($result), 'Private messages table content is mismatching after deleting a user.');
        $this->db->sql_freeresult($result);
    }
    /**
     * Display the language selection
     *
     * Display the available languages to add/manage board rules from.
     * If there is only one board language, this will just call display_rules().
     *
     * @return null
     * @access public
     */
    public function display_language_selection()
    {
        // Check if there are any available languages
        $sql = 'SELECT lang_id, lang_iso, lang_local_name
			FROM ' . LANG_TABLE . '
			ORDER BY lang_english_name';
        $result = $this->db->sql_query($sql);
        $rows = $this->db->sql_fetchrowset($result);
        $this->db->sql_freeresult($result);
        // If there are some, build option fields
        if (sizeof($rows) > 1) {
            foreach ($rows as $row) {
                $this->template->assign_block_vars('options', array('S_LANG_DEFAULT' => $row['lang_iso'] == $this->config['default_lang'], 'LANG_ID' => $row['lang_id'], 'LANG_LOCAL_NAME' => $row['lang_local_name']));
            }
            // Set u_action variable for the template form
            $this->template->assign_var('U_ACTION', $this->u_action);
        } else {
            // If there is only one available language its index is 0
            // and that language is the default board language.
            // We do not need any loops here to get its id.
            $this->display_rules($rows[0]['lang_id']);
        }
    }
Exemple #26
0
 public function medal_row($user_id)
 {
     $s_nominate = false;
     if ($this->auth->acl_get('u_nominate_medals') && $user_id != $this->user->data['user_id']) {
         $s_nominate = true;
     }
     $is_mod = $this->user->data['user_type'] == USER_FOUNDER || $this->auth->acl_get('u_award_medals') ? true : false;
     $uid = $bitfield = '';
     // will be modified by generate_text_for_storage
     $allow_bbcode = $allow_smilies = true;
     $allow_urls = false;
     $m_flags = '3';
     // 1 is bbcode, 2 is smiles, 4 is urls (add together to turn on more than one)
     //
     // Category
     //
     $sql = "SELECT id, name\n\t\t\tFROM " . $this->tb_medals_cats . "\n\t\t\tORDER BY order_id";
     if (!($result = $this->db->sql_query($sql))) {
         message_die(GENERAL_ERROR, 'Could not query medal categories list', '', __LINE__, __FILE__, $sql);
     }
     $category_rows = array();
     while ($row = $this->db->sql_fetchrow($result)) {
         $category_rows[] = $row;
     }
     $this->db->sql_freeresult($result);
     $sql = "SELECT m.medal_id, m.user_id\n\t\t\tFROM " . $this->tb_medals_awarded . " m\n\t\t\tWHERE m.user_id = {$user_id}\n\t\t\t\tAND m.nominated = 0";
     if ($result = $this->db->sql_query($sql)) {
         $medal_list = $this->db->sql_fetchrowset($result);
         $medal_count = count($medal_list);
         if ($medal_count) {
             $this->template->assign_block_vars('switch_display_medal', array());
             $this->template->assign_block_vars('switch_display_medal.medal', array('MEDAL_BUTTON' => '<input type="button" class="button2" onclick="hdr_toggle(\'toggle_medal\',\'medal_open_close\')" value="' . $this->user->lang['MEDALS_VIEW_BUTTON'] . '"/>'));
         }
     }
     $u_nominate = '';
     if ($s_nominate) {
         $u_nominate = $this->helper->route('bb3mobi_medals_controller', array('m' => 'nominate', 'u' => $user_id));
     }
     $u_can_award = '';
     if ($this->auth->acl_get('a_user') || $is_mod) {
         $u_can_award = $this->helper->route('bb3mobi_medals_controller', array('m' => 'award', 'u' => $user_id));
     }
     $this->template->assign_vars(array('USER_ID' => $user_id, 'U_NOMINATE' => $u_nominate, 'U_CAN_AWARD_MEDALS' => $u_can_award, 'L_USER_MEDAL' => $this->user->lang['MEDALS'], 'USER_MEDAL_COUNT' => $medal_count, 'L_MEDAL_INFORMATION' => $this->user->lang['MEDAL_INFORMATION'], 'L_MEDAL_NAME' => $this->user->lang['MEDAL'], 'L_MEDAL_DETAIL' => $this->user->lang['MEDAL_DETAIL']));
     for ($i = 0; $i < count($category_rows); $i++) {
         $cat_id = $category_rows[$i]['id'];
         $sql = "SELECT m.id, m.name, m.description, m.image, m.device, m.dynamic, m.parent,\n\t\t\t\t\t\tma.nominated_reason, ma.time, ma.awarder_id, ma.awarder_un, ma.awarder_color, ma.bbuid, ma.bitfield,\n\t\t\t\t\t\tc.id as cat_id, c.name as cat_name\n\t\t\t\t\tFROM " . $this->tb_medal . " m, " . $this->tb_medals_awarded . " ma, " . $this->tb_medals_cats . " c\n\t\t\t\t\tWHERE ma.user_id = {$user_id}\n\t\t\t\t\t\tAND m.parent = c.id\n\t\t\t\t\t\tAND m.id = ma.medal_id\n\t\t\t\t\t\tAND ma.nominated = 0\n\t\t\t\t\tORDER BY c.order_id, m.order_id, ma.time";
         if ($result = $this->db->sql_query($sql)) {
             $row = array();
             $rowset = array();
             $medal_time = $this->user->lang['AWARD_TIME'] . ':&nbsp;';
             $medal_reason = $this->user->lang['MEDAL_AWARD_REASON'] . ':&nbsp;';
             while ($row = $this->db->sql_fetchrow($result)) {
                 if (empty($rowset[$row['name']])) {
                     $rowset[$row['name']]['cat_id'] = $row['cat_id'];
                     $rowset[$row['name']]['cat_name'] = $row['cat_name'];
                     if (isset($rowset[$row['name']]['description'])) {
                         $rowset[$row['name']]['description'] .= $row['description'];
                     } else {
                         $rowset[$row['name']]['description'] = $row['description'];
                     }
                     $rowset[$row['name']]['image'] = $this->phpbb_root_path . 'images/medals/' . $row['image'];
                     $rowset[$row['name']]['device'] = $this->phpbb_root_path . 'images/medals/devices/' . $row['device'];
                     $rowset[$row['name']]['dynamic'] = $row['dynamic'];
                 }
                 $row['nominated_reason'] = $row['nominated_reason'] ? $row['nominated_reason'] : $lang['Medal_no_reason'];
                 $awarder_name = "";
                 if ($row['awarder_id']) {
                     $awarder_name = "<br />" . $this->user->lang['AWARDED_BY'] . ": " . get_username_string('full', $row['awarder_id'], $row['awarder_un'], $row['awarder_color'], $row['awarder_un']);
                 }
                 //generate_text_for_storage($row['nominated_reason'], $uid, $bitfield, $m_flags, $allow_bbcode, $allow_urls, $allow_smilies);
                 $reason = generate_text_for_display($row['nominated_reason'], $row['bbuid'], $row['bitfield'], $m_flags);
                 if (isset($rowset[$row['name']]['medal_issue'])) {
                     $rowset[$row['name']]['medal_issue'] .= $medal_time . $this->user->format_date($row['time']) . $awarder_name . '</td></tr><tr><td>' . $medal_reason . '<div class="content">' . $reason . '</div><hr />';
                 } else {
                     $rowset[$row['name']]['medal_issue'] = $medal_time . $this->user->format_date($row['time']) . $awarder_name . '</td></tr><tr><td>' . $medal_reason . '<div class="content">' . $reason . '</div><hr />';
                 }
                 if (isset($rowset[$row['name']]['medal_count'])) {
                     $rowset[$row['name']]['medal_count'] += '1';
                 } else {
                     $rowset[$row['name']]['medal_count'] = '1';
                 }
             }
             $medal_width = $this->config['medal_small_img_width'] ? ' width="' . $this->config['medal_small_img_width'] . '"' : '';
             $medal_height = $this->config['medal_small_img_ht'] ? ' height="' . $this->config['medal_small_img_ht'] . '"' : '';
             $medal_name = array();
             $data = array();
             //
             // Should we display this category/medal set?
             //
             $display_medal = 0;
             $numberofmedals = 0;
             $after_first_cat = 0;
             $newcat = 1;
             while (list($medal_name, $data) = @each($rowset)) {
                 if ($cat_id == $data['cat_id']) {
                     $display_medal = 1;
                 }
                 $display_across = $this->config['medal_profile_across'] ? $this->config['medal_profile_across'] : 5;
                 if ($numberofmedals == $display_across) {
                     $break = '<br />';
                     $numberofmedals = 0;
                 } else {
                     $break = '';
                 }
                 if (!empty($newcat) && !empty($after_first_cat)) {
                     $break = '<hr />&nbsp;';
                     $numberofmedals = 0;
                 }
                 $numberofmedals++;
                 if (!empty($display_medal)) {
                     if ($data['medal_count'] > 1) {
                         if ($data['dynamic']) {
                             $img_medals = $this->helper->route('bb3mobi_medals_controller', array('m' => 'mi', 'med' => $data['image'], 'd' => $data['device'] . '-' . ($data['medal_count'] - 1) . '.gif'));
                             $image = '<img src="' . $img_medals . '" alt="' . $medal_name . '" title="' . $medal_name . '" />';
                             $small_image = $break . '<img src="' . $img_medals . '" alt="' . $medal_name . '" title="' . $medal_name . '"' . $medal_width . $medal_height . ' />';
                         } else {
                             $cluster = '-' . $data['medal_count'];
                             $device_image = substr_replace($data['image'], $cluster, -4) . substr($data['image'], -4);
                             if (file_exists($device_image)) {
                                 $data['image'] = $device_image;
                             }
                             $image = '<img src="' . $data['image'] . '" alt="' . $medal_name . '" title="' . $medal_name . '" />';
                             $small_image = $break . '<img src="' . $data['image'] . '" alt="' . $medal_name . '" title="' . $medal_name . '"' . $medal_width . $medal_height . ' />';
                         }
                     } else {
                         $image = '<img src="' . $data['image'] . '" alt="' . $medal_name . '" title="' . $medal_name . '" />';
                         $small_image = $break . '<img src="' . $data['image'] . '" alt="' . $medal_name . '" title="' . $medal_name . '"' . $medal_width . $medal_height . ' />';
                     }
                     $this->template->assign_block_vars('switch_display_medal.details', array('ISMEDAL_CAT' => $newcat, 'MEDAL_CAT' => $data['cat_name'], 'MEDAL_NAME' => $medal_name, 'MEDAL_DESCRIPTION' => $data['description'], 'MEDAL_IMAGE' => $image, 'MEDAL_IMAGE_SMALL' => $small_image, 'MEDAL_ISSUE' => $data['medal_issue'], 'MEDAL_COUNT' => $this->user->lang['MEDAL_AMOUNT'] . ': ' . $data['medal_count']));
                     $display_medal = 0;
                     $newcat = 0;
                 } else {
                     // New category lets put an hr between
                     $newcat = 1;
                     $after_first_cat = 1;
                 }
             }
         }
     }
 }
Exemple #27
0
    /**
     * 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('"', '&quot;', $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("'", "&#146;", $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&amp;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&amp;mode=compose&amp;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&amp;mode=compose&amp;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&amp;mode=setting_user_global&amp;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('"', '&quot;', $message_edit);
                    $message_edit = mb_ereg_replace("'", "&#146;", $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("'", "&#146;", $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&amp;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&amp;mode=compose&amp;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&amp;mode=compose&amp;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&amp;mode=setting_user_global&amp;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>&nbsp;' . $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'] . '&nbsp;(' . $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('\'', '&rsquo;', $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('\'', '&rsquo;', $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('"', '&quot;', $message_edit);
                // Edit Fix ;)
                $message_edit = mb_ereg_replace("'", "&#146;", $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&amp;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&amp;mode=compose&amp;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&amp;mode=compose&amp;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&amp;mode=setting_user_global&amp;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&amp;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('"', '&quot;', $message_edit);
                        // Edit Fix ;)
                        $message_edit = mb_ereg_replace("'", "&#146;", $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("'", "&#146;", $row['username']);
                        $message = str_replace('\'', '&rsquo;', $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&amp;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&amp;mode=compose&amp;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&amp;mode=compose&amp;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&amp;mode=setting_user_global&amp;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']);
    }
Exemple #28
0
 /**
  * Load common consim language files during user setup and add the newsbar and history hint
  *
  * @param object $event The event object
  * @return void
  * @access public
  */
 public function load_language_on_setup($event)
 {
     $lang_set_ext = $event['lang_set_ext'];
     $lang_set_ext[] = array('ext_name' => 'consim/core', 'lang_set' => 'consim_common');
     $event['lang_set_ext'] = $lang_set_ext;
     // Add the Newsbar
     $groups = $channel = $anniversary = array();
     $newsbar = false;
     //Catch all groups from the database where the user is a member of
     $sql = 'SELECT group_id FROM ' . USER_GROUP_TABLE . ' WHERE user_id = ' . $this->user->data['user_id'];
     $result = $this->db->sql_query($sql);
     $row = $this->db->sql_fetchrowset($result);
     foreach ($row as $value) {
         $groups[] = $value['group_id'];
     }
     // Catch the first channel from the database where the user is a member of the group
     $csql = 'SELECT * FROM phpbb_consim_news_channel';
     $cresult = $this->db->sql_query($csql);
     while ($crow = $this->db->sql_fetchrow($cresult)) {
         if (in_array($crow['group_id'], $groups)) {
             $channel['id'] = $crow['channel_id'];
             $channel['name'] = $crow['channel_name'];
             $channel['vRefresh'] = $crow['vRefresh'];
             $channel['background'] = $crow['background_color'];
             $channel['color'] = $crow['color'];
             break;
         }
     }
     if (isset($channel['id']) && $channel['id'] != "") {
         // Catch all news from the database
         $nsql = "SELECT n.news_id, n.content, t.topic_name\n\t\t\t\tFROM phpbb_consim_news n \n\t\t\t\tINNER JOIN phpbb_consim_news_topics t\n\t\t\t\tON t.topic_id = n.topic_id\n\t\t\t\tWHERE n.channel_id = " . $channel['id'] . " \n\t\t\t\tORDER BY n.topic_id";
         $nresult = $this->db->sql_query($nsql);
         while ($nrow = $this->db->sql_fetchrow($nresult)) {
             $newsbar = true;
             $this->template->assign_block_vars('allNews', array('TOPIC' => $nrow['topic_name'], 'CONTENT' => $nrow['content']));
         }
     }
     // Add the history hint
     $anniversary['today'] = $anniversary['tomorrow'] = "";
     $sql = "SELECT event, day, year, link\n\t\t\tFROM phpbb_consim_anniversary\n\t\t\tWHERE month = " . date('m');
     $result = $this->db->sql_query($sql);
     while ($row = $this->db->sql_fetchrow($result)) {
         $event = ($row['year'] != 0 ? date("Y") - (int) $row['year'] . ". " : "") . $row['event'];
         if ($row['day'] == date("j")) {
             if ($anniversary['today'] != "") {
                 $anniversary['today'] .= $row['link'] != "http://" ? '<a href="' . $row['link'] . '">' . $event . '</a>' : $event;
             } else {
                 $anniversary['today'] = $row['link'] != "http://" ? '<a href="' . $row['link'] . '">' . $event . '</a>' : $event;
             }
         }
         if ($row['day'] == (new \DateTime('tomorrow'))->format('j')) {
             if ($anniversary['tomorrow'] != "") {
                 $anniversary['today'] .= $row['link'] != "http://" ? '<a href="' . $row['link'] . '">' . $event . '</a>' : $event;
             } else {
                 $anniversary['tomorrow'] = $row['link'] != "http://" ? '<a href="' . $row['link'] . '">' . $event . '</a>' : $event;
             }
         }
     }
     // Pass the data to the template
     $this->template->assign_vars(array('S_NEWSTICKER' => isset($channel['id']) && $newsbar ? true : false, 'CHANNEL' => isset($channel['name']) ? $channel['name'] . ' ' . date('H:i') : "", 'VREFRESH' => isset($channel['vRefresh']) ? $channel['vRefresh'] : 0, 'CHANNEL_BACKGROUND' => isset($channel['background']) ? $channel['background'] : "", 'CHANNEL_COLOR' => isset($channel['color']) ? $channel['color'] : "", 'ANNIVERSARY_TODAY' => $anniversary['today'], 'ANNIVERSARY_TOMORROW' => $anniversary['tomorrow']));
 }
Exemple #29
0
 /**
  * Modifies the forum index to add the chat
  */
 public function index()
 {
     if ($this->config['prune_ajax_chat'] === true) {
         $this->prune();
     }
     if (!defined('PHPBB_USE_BOARD_URL_PATH')) {
         define('PHPBB_USE_BOARD_URL_PATH', true);
     }
     $this->user->add_lang('posting');
     $this->user->add_lang_ext('spaceace/ajaxchat', 'ajax_chat');
     if (!defined('CHAT_TABLE')) {
         $chat_table = $this->table_prefix . 'ajax_chat';
         define('CHAT_TABLE', $chat_table);
     }
     if (!defined('CHAT_SESSIONS_TABLE')) {
         $chat_session_table = $this->table_prefix . 'ajax_chat_sessions';
         define('CHAT_SESSIONS_TABLE', $chat_session_table);
     }
     include_once $this->root_path . 'includes/functions_posting.' . $this->php_ext;
     include_once $this->root_path . 'includes/functions_display.' . $this->php_ext;
     $this->mode = $this->request->variable('mode', 'default');
     $this->last_id = $this->request->variable('last_id', 0);
     $this->last_time = $this->request->variable('last_time', 0);
     $this->post_time = $this->request->variable('last_post', 0);
     $this->times = ['online' => $this->config['status_online_chat'], 'idle' => $this->config['status_idle_chat'], 'offline' => $this->config['status_offline_chat']];
     $sql = 'SELECT c.*, u.user_avatar, u.user_avatar_type, u.user_avatar_width, u.user_avatar_height
             FROM ' . CHAT_TABLE . ' as c
             LEFT JOIN ' . USERS_TABLE . ' as u
             ON c.user_id = u.user_id
             ORDER BY message_id DESC';
     $result = $this->db->sql_query_limit($sql, (int) $this->config['ajax_chat_index_amount']);
     $rows = $this->db->sql_fetchrowset($result);
     if (!sizeof($rows) && time() - 60 < $this->last_time) {
         return;
     }
     foreach ($rows as $row) {
         if ($row['forum_id'] && !$this->auth->acl_get('f_read', $row['forum_id'])) {
             continue;
         }
         $avatar = ['avatar' => $row['user_avatar'], 'avatar_type' => $row['user_avatar_type'], 'avatar_height' => $row['user_avatar_height'], 'avatar_width' => $row['user_avatar_width']];
         $avatar_thumb = ['avatar' => $row['user_avatar'], 'avatar_type' => $row['user_avatar_type'], 'avatar_height' => '', 'avatar_width' => 35];
         $row['avatar'] = $this->user->optionget('viewavatars') ? phpbb_get_avatar($avatar, '') : '';
         $row['avatar_thumb'] = $this->user->optionget('viewavatars') ? phpbb_get_avatar($avatar_thumb, '') : '';
         if ($this->count++ == 0) {
             $this->last_id = $row['message_id'];
         }
         if ($this->config['ajax_chat_time_setting']) {
             $time = $this->config['ajax_chat_time_setting'];
         } else {
             $time = $this->user->data['user_dateformat'];
         }
         $this->template->assign_block_vars('chatrow', ['MESSAGE_ID' => $row['message_id'], 'USERNAME_FULL' => $this->clean_username(get_username_string('full', $row['user_id'], $row['username'], $row['user_colour'], $this->user->lang['GUEST'])), 'USERNAME_A' => $row['username'], 'USER_COLOR' => $row['user_colour'], 'MESSAGE' => make_clickable(generate_text_for_display($row['message'], $row['bbcode_uid'], $row['bbcode_bitfield'], $row['bbcode_options'])), 'TIME' => $this->user->format_date($row['time'], $time), 'CLASS' => $row['message_id'] % 2 ? 1 : 2, 'USER_AVATAR' => $row['avatar'], 'USER_AVATAR_THUMB' => $row['avatar_thumb']]);
     }
     $this->db->sql_freeresult($result);
     if ($this->user->data['user_type'] == USER_FOUNDER || $this->user->data['user_type'] == USER_NORMAL) {
         $sql = 'SELECT * FROM ' . CHAT_SESSIONS_TABLE . " WHERE user_id = {$this->user->data['user_id']}";
         $result1 = $this->db->sql_query($sql);
         $row = $this->db->sql_fetchrow($result1);
         $this->db->sql_freeresult($result1);
         if ($row['user_id'] != $this->user->data['user_id']) {
             $sql_ary = ['user_id' => $this->user->data['user_id'], 'username' => $this->user->data['username'], 'user_colour' => $this->user->data['user_colour'], 'user_login' => time(), 'user_lastupdate' => time()];
             $sql = 'INSERT INTO ' . CHAT_SESSIONS_TABLE . ' ' . $this->db->sql_build_array('INSERT', $sql_ary);
             $this->db->sql_query($sql);
         } else {
             $sql_ary = ['username' => $this->user->data['username'], 'user_colour' => $this->user->data['user_colour'], 'user_login' => time(), 'user_lastupdate' => time()];
             $sql = 'UPDATE ' . CHAT_SESSIONS_TABLE . ' SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . " WHERE user_id = {$this->user->data['user_id']}";
             $this->db->sql_query($sql);
         }
     }
     $bbcode_status = $this->config['allow_bbcode'] && $this->config['auth_bbcode_pm'] && $this->auth->acl_get('u_ajaxchat_bbcode') ? true : false;
     $smilies_status = $this->config['allow_smilies'] && $this->config['auth_smilies_pm'] && $this->auth->acl_get('u_pm_smilies') ? true : false;
     $img_status = $this->config['auth_img_pm'] && $this->auth->acl_get('u_pm_img') ? true : false;
     $flash_status = $this->config['auth_flash_pm'] && $this->auth->acl_get('u_pm_flash') ? true : false;
     $url_status = $this->config['allow_post_links'] ? true : false;
     $this->mode = strtoupper($this->mode);
     $sql = 'SELECT `user_lastpost` FROM ' . CHAT_SESSIONS_TABLE . " WHERE user_id = {$this->user->data['user_id']}";
     $result1 = $this->db->sql_query($sql);
     $row = $this->db->sql_fetchrow($result1);
     $this->db->sql_freeresult($result1);
     if ($this->get_status($row['user_lastpost']) === 'online') {
         $refresh = $this->config['refresh_online_chat'];
     } else {
         if ($this->get_status($row['user_lastpost']) === 'idle') {
             $refresh = $this->config['refresh_idle_chat'];
         } else {
             if ($this->user->data['user_id'] === ANONYMOUS || $this->get_status($row['user_lastpost']) === 'offline') {
                 $refresh = $this->config['refresh_offline_chat'];
             } else {
                 $refresh = $this->config['refresh_offline_chat'];
             }
         }
     }
     if ($this->user->data['user_id'] === ANONYMOUS || $row['user_lastpost'] === null) {
         $last_post = 0;
     } else {
         $last_post = $row['user_lastpost'];
     }
     //Assign the features template variable
     $this->template->assign_vars(['BBCODE_STATUS' => $bbcode_status ? sprintf($this->user->lang['BBCODE_IS_ON'], '<a href="' . append_sid("{$this->root_path}faq.{$this->php_ext}", 'mode=bbcode') . '">', '</a>') : sprintf($this->user->lang['BBCODE_IS_OFF'], '<a href="' . append_sid("{$this->root_path}faq.{$this->php_ext}", 'mode=bbcode') . '">', '</a>'), 'IMG_STATUS' => $img_status ? $this->user->lang['IMAGES_ARE_ON'] : $this->user->lang['IMAGES_ARE_OFF'], 'FLASH_STATUS' => $flash_status ? $this->user->lang['FLASH_IS_ON'] : $this->user->lang['FLASH_IS_OFF'], 'SMILIES_STATUS' => $smilies_status ? $this->user->lang['SMILIES_ARE_ON'] : $this->user->lang['SMILIES_ARE_OFF'], 'URL_STATUS' => $url_status ? $this->user->lang['URL_IS_ON'] : $this->user->lang['URL_IS_OFF'], 'S_COMPOSE_PM' => true, 'S_BBCODE_ALLOWED' => $bbcode_status, 'S_SMILIES_ALLOWED' => $smilies_status, 'S_BBCODE_IMG' => $img_status, 'S_BBCODE_FLASH' => $flash_status, 'S_BBCODE_QUOTE' => false, 'S_BBCODE_URL' => $url_status, 'REFRESH_TIME' => $refresh, 'LAST_ID' => $this->last_id, 'LAST_POST' => $last_post, 'TIME' => time(), 'STYLE_PATH' => generate_board_url() . '/styles/' . $this->user->style['style_path'], 'EXT_STYLE_PATH' => '' . $this->ext_path_web . 'styles/', 'FILENAME' => $this->helper->route('spaceace_ajaxchat_chat'), 'S_GET_CHAT' => $this->get ? true : false, 'S_' . $this->mode => true]);
     // Generate smiley listing
     \generate_smilies('inline', 0);
     // Build custom bbcodes array
     \display_custom_bbcodes();
     $this->whois_online();
 }
 public function activedate_set(\Symfony\Component\EventDispatcher\Event $event)
 {
     $topic_data = $event['topic_data'];
     $first_post = intval($topic_data['topic_first_post_id']);
     if (0 == $event['set_active']) {
         $sql = 'DELETE FROM ' . $this->cal_table . ' WHERE post_id = ' . $first_post;
         $this->db->sql_query($sql);
         $sql = 'DELETE FROM ' . $this->cal_participants_table . ' WHERE post_id = ' . $first_post;
         $this->db->sql_query($sql);
     } else {
         // Copy Date & entries
         if ($this->hookup->topic_id != $event['topic_id']) {
             if ($this->hookup->topic_id != 0) {
                 $this->hookup = new hookup();
             }
             $this->hookup->load_hookup($event['topic_id']);
         }
         $set_date = isset($this->hookup->hookup_dates[$event['set_active']]) ? isset($this->hookup->hookup_dates[$event['set_active']]['date_time']) ? $this->hookup->hookup_dates[$event['set_active']]['date_time'] : 0 : 0;
         if (!$set_date) {
             // We can't enter a text without date
             return;
         }
         // Quick & dirty: The event
         $sql = 'SELECT id FROM ' . $this->cal_event_table . ' WHERE event = \'hookup\'';
         $result = $this->db->sql_query_limit($sql, 1);
         $event_id = $this->db->sql_fetchfield('id');
         $this->db->sql_freeresult($result);
         if (!$event_id) {
             $sql_ary = array('event' => 'hookup', 'participants' => 1);
             $sql = 'INSERT INTO ' . $this->cal_event_table . ' ' . $this->db->sql_build_array('INSERT', $sql_ary);
             $this->db->sql_query($sql);
             $event_id = $this->db->sql_nextid();
         }
         $sql = 'SELECT count(*) as cnt FROM ' . $this->cal_table . ' WHERE post_id = ' . $topic_data['topic_first_post_id'];
         $result = $this->db->sql_query($sql);
         $cnt = $this->db->sql_fetchfield('cnt');
         $this->db->sql_freeresult($result);
         $sql_ary = array('post_id' => $topic_data['topic_first_post_id'], 'event_id' => $event_id, 'event_name' => $topic_data['topic_title'], 'date_from' => date('Y-m-d', $set_date));
         if ($cnt) {
             $sql = 'UPDATE ' . $this->cal_table . ' SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . ' WHERE post_id = ' . $topic_data['topic_first_post_id'];
         } else {
             $sql = 'INSERT INTO ' . $this->cal_table . ' ' . $this->db->sql_build_array('INSERT', $sql_ary);
         }
         $this->db->sql_query($sql);
         // Participants
         $part_ary = $this->part_ary;
         // Already entered?
         $entered_users = array();
         if ($cnt) {
             $sql = 'SELECT user_id FROM ' . $this->cal_participants_table . ' WHERE ' . $this->db->sql_in_set('user_id', array_keys($this->hookup->hookup_users));
             $result = $this->db->sql_query($sql);
             $entered_users = $this->db->sql_fetchrowset($result);
             $this->db->sql_freeresult($result);
         }
         $sql_ary = array();
         foreach ($this->hookup->hookup_users as $user_id => $userdata) {
             // Did the user enter anything for this date?
             if (!isset($this->hookup->hookup_availables[$user_id][$event['set_active']]) || $this->hookup->hookup_availables[$user_id][$event['set_active']] == hookup::HOOKUP_UNSET) {
                 continue;
             }
             if (in_array($user_id, $entered_users)) {
                 // Update instead:
                 $sql = 'UPDATE ' . $this->cal_participants_table . ' SET ' . $this->db->sql_build_array('UPDATE', array('participants' => $part_ary[$this->hookup->hookup_availables[$user_id][$event['set_active']]], 'comment' => $userdata['comment'], 'date' => date('Y-m-d-H-i'))) . " WHERE user_id = {$user_id} AND post_id = {$topic_data['topic_first_post_id']}";
                 $this->db->sql_query($sql);
                 continue;
             }
             $sql_ary[] = array('post_id' => $topic_data['topic_first_post_id'], 'user_id' => $user_id, 'participants' => $part_ary[$this->hookup->hookup_availables[$user_id][$event['set_active']]], 'comments' => $userdata['comment'], 'date' => date('Y-m-d-H-i'));
         }
         $this->db->sql_multi_insert($this->cal_participants_table, $sql_ary);
     }
 }