Inheritance: extends bbcode_firstpass
Example #1
4
 /**
  * Show bbcodes and smilies in the quickreply
  * Template data for Ajax submit
  *
  * @param object $event The event object
  * @return null
  * @access public
  */
 public function viewtopic_modify_data($event)
 {
     $forum_id = $event['forum_id'];
     $topic_data = $event['topic_data'];
     $post_list = $event['post_list'];
     $topic_id = $topic_data['topic_id'];
     $s_quick_reply = false;
     if (($this->user->data['is_registered'] || $this->config['qr_allow_for_guests']) && $this->config['allow_quick_reply'] && $topic_data['forum_flags'] & FORUM_FLAG_QUICK_REPLY && $this->auth->acl_get('f_reply', $forum_id)) {
         // Quick reply enabled forum
         $s_quick_reply = $topic_data['forum_status'] == ITEM_UNLOCKED && $topic_data['topic_status'] == ITEM_UNLOCKED || $this->auth->acl_get('m_edit', $forum_id) ? true : false;
     }
     if (!$this->user->data['is_registered'] && $s_quick_reply) {
         add_form_key('posting');
         $s_attach_sig = $this->config['allow_sig'] && $this->user->optionget('attachsig') && $this->auth->acl_get('f_sigs', $forum_id) && $this->auth->acl_get('u_sig');
         $s_smilies = $this->config['allow_smilies'] && $this->user->optionget('smilies') && $this->auth->acl_get('f_smilies', $forum_id);
         $s_bbcode = $this->config['allow_bbcode'] && $this->user->optionget('bbcode') && $this->auth->acl_get('f_bbcode', $forum_id);
         $s_notify = false;
         $qr_hidden_fields = array('topic_cur_post_id' => (int) $topic_data['topic_last_post_id'], 'lastclick' => (int) time(), 'topic_id' => (int) $topic_data['topic_id'], 'forum_id' => (int) $forum_id);
         // Originally we use checkboxes and check with isset(), so we only provide them if they would be checked
         !$s_bbcode ? $qr_hidden_fields['disable_bbcode'] = 1 : true;
         !$s_smilies ? $qr_hidden_fields['disable_smilies'] = 1 : true;
         !$this->config['allow_post_links'] ? $qr_hidden_fields['disable_magic_url'] = 1 : true;
         $s_attach_sig ? $qr_hidden_fields['attach_sig'] = 1 : true;
         $s_notify ? $qr_hidden_fields['notify'] = 1 : true;
         $topic_data['topic_status'] == ITEM_LOCKED ? $qr_hidden_fields['lock_topic'] = 1 : true;
         $this->template->assign_vars(array('S_QUICK_REPLY' => true, 'U_QR_ACTION' => append_sid("{$this->phpbb_root_path}posting.{$this->php_ext}", "mode=reply&f={$forum_id}&t={$topic_id}"), 'QR_HIDDEN_FIELDS' => build_hidden_fields($qr_hidden_fields), 'USERNAME' => $this->request->variable('username', '', true)));
         if ($this->config['enable_post_confirm']) {
             $captcha = $this->captcha->get_instance($this->config['captcha_plugin']);
             $captcha->init(CONFIRM_POST);
         }
         if ($this->config['enable_post_confirm'] && (isset($captcha) && $captcha->is_solved() === false)) {
             $this->template->assign_vars(array('S_CONFIRM_CODE' => true, 'CAPTCHA_TEMPLATE' => $captcha->get_template()));
         }
         // Add the confirm id/code pair to the hidden fields, else an error is displayed on next submit/preview
         if (isset($captcha) && $captcha->is_solved() !== false) {
             $this->template->append_var('QR_HIDDEN_FIELDS', build_hidden_fields($captcha->get_hidden_fields()));
         }
     }
     // Ajaxify viewtopic data
     if ($this->request->is_ajax() && $this->request->is_set('qr_request')) {
         if (!$this->user->data['is_registered'] && $this->config['enable_post_confirm']) {
             $captcha = $this->captcha->get_instance($this->config['captcha_plugin']);
             $captcha->init(CONFIRM_POST);
             // Add the confirm id/code pair to the hidden fields, else an error is displayed on next submit/preview
             if (isset($captcha) && $captcha->is_solved() !== false) {
                 $this->template->append_var('QR_HIDDEN_FIELDS', build_hidden_fields($captcha->get_hidden_fields()));
             }
         }
         // Fix issues if the inserted post is not the first.
         if ($this->qr_insert && !$this->qr_first) {
             $this->template->alter_block_array('postrow', array('S_FIRST_ROW' => false), false, 'change');
         }
         $page_title = $event['page_title'];
         $this->template->assign_vars(array('S_QUICKREPLY_REQUEST' => true, 'S_QR_NO_FIRST_POST' => $this->qr_insert, 'S_QR_FULL_QUOTE' => $this->config['qr_full_quote']));
         $this->template->append_var('QR_HIDDEN_FIELDS', build_hidden_fields(array('qr' => 1, 'qr_cur_post_id' => (int) max($post_list))));
         // Output the page
         page_header($page_title, false, $forum_id);
         page_footer(false, false, false);
         $json_response = new \phpbb\json_response();
         $json_response->send(array('success' => true, 'result' => $this->template->assign_display('@tatiana5_quickreply/quickreply_template.html', '', true), 'insert' => $this->qr_insert));
     }
     if ($s_quick_reply) {
         include_once $this->phpbb_root_path . 'includes/functions_posting.' . $this->php_ext;
         // HTML, BBCode, Smilies, Images and Flash status
         $bbcode_status = $this->config['allow_bbcode'] && $this->config['qr_bbcode'] && $this->auth->acl_get('f_bbcode', $forum_id) ? true : false;
         $smilies_status = $this->config['allow_smilies'] && $this->config['qr_smilies'] && $this->auth->acl_get('f_smilies', $forum_id) ? true : false;
         $img_status = $bbcode_status && $this->auth->acl_get('f_img', $forum_id) ? true : false;
         $url_status = $this->config['allow_post_links'] ? true : false;
         $flash_status = $bbcode_status && $this->auth->acl_get('f_flash', $forum_id) && $this->config['allow_post_flash'] ? true : false;
         $quote_status = true;
         // Build custom bbcodes array
         if ($bbcode_status) {
             display_custom_bbcodes();
         }
         // Generate smiley listing
         if ($smilies_status) {
             generate_smilies('inline', $forum_id);
         }
         // Show attachment box for adding attachments if true
         $form_enctype = @ini_get('file_uploads') == '0' || strtolower(@ini_get('file_uploads')) == 'off' || !$this->config['allow_attachments'] || !$this->auth->acl_get('u_attach') || !$this->auth->acl_get('f_attach', $forum_id) ? '' : '" enctype="multipart/form-data';
         $allowed = $this->auth->acl_get('f_attach', $forum_id) && $this->auth->acl_get('u_attach') && $this->config['allow_attachments'] && $form_enctype;
         $attachment_data = false;
         if ($bbcode_status || $smilies_status || $this->config['qr_attach'] && $allowed) {
             $this->user->add_lang('posting');
         }
         if ($this->config['qr_attach'] && $allowed) {
             $this->template->assign_vars(array('U_QR_ACTION' => append_sid("{$this->phpbb_root_path}posting.{$this->php_ext}", "mode=reply&f={$forum_id}&t={$topic_id}") . $form_enctype));
             include_once $this->phpbb_root_path . 'includes/message_parser.' . $this->php_ext;
             $message_parser = new \parse_message();
             $message_parser->set_plupload($this->plupload);
             $message_parser->set_mimetype_guesser($this->mimetype_guesser);
             $message_parser->get_submitted_attachment_data($this->user->data['user_id']);
             $attachment_data = $message_parser->attachment_data;
             $filename_data = $message_parser->filename_data;
             posting_gen_inline_attachments($attachment_data);
             $max_files = $this->auth->acl_get('a_') || $this->auth->acl_get('m_', $forum_id) ? 0 : (int) $this->config['max_attachments'];
             $topic_id = $topic_data['topic_id'];
             $s_action = append_sid("{$this->phpbb_root_path}posting.{$this->php_ext}", "mode=reply&f={$forum_id}&t={$topic_id}");
             $this->plupload->configure($this->cache, $this->template, $s_action, $forum_id, $max_files);
             posting_gen_attachment_entry($attachment_data, $filename_data, $allowed);
         }
         $this->template->append_var('QR_HIDDEN_FIELDS', build_hidden_fields(array('qr' => 1, 'qr_cur_post_id' => (int) max($post_list))));
         if ($this->phpbb_extension_manager->is_enabled('rxu/PostsMerging') && $this->user->data['is_registered'] && $this->config['merge_interval']) {
             // Always show the checkbox if PostsMerging extension is installed.
             $this->user->add_lang_ext('rxu/PostsMerging', 'posts_merging');
             $this->template->assign_var('POSTS_MERGING_OPTION', true);
         }
         $this->template->assign_vars(array('S_QR_COLOUR_NICKNAME' => $this->config['qr_color_nickname'], 'S_QR_NOT_CHANGE_SUBJECT' => $this->auth->acl_get('f_qr_change_subject', $forum_id) ? false : true, 'S_QR_COMMA_ENABLE' => $this->config['qr_comma'], 'S_QR_QUICKNICK_ENABLE' => $this->config['qr_quicknick'], 'S_QR_QUICKNICK_REF' => $this->config['qr_quicknick_ref'], 'S_QR_QUICKNICK_PM' => $this->config['qr_quicknick_pm'], 'S_QR_QUICKQUOTE_ENABLE' => $this->config['qr_quickquote'], 'S_QR_QUICKQUOTE_LINK' => $this->config['qr_quickquote_link'], 'S_QR_FULL_QUOTE' => $this->config['qr_full_quote'], 'S_QR_CE_ENABLE' => $this->config['qr_ctrlenter'], 'QR_SOURCE_POST' => $this->config['qr_source_post'], 'S_DISPLAY_USERNAME' => !$this->user->data['is_registered'], 'S_BBCODE_ALLOWED' => $bbcode_status ? 1 : 0, 'S_SMILIES_ALLOWED' => $smilies_status, 'S_BBCODE_IMG' => $img_status, 'S_LINKS_ALLOWED' => $url_status, 'S_BBCODE_FLASH' => $flash_status, 'S_BBCODE_QUOTE' => $quote_status, 'MESSAGE' => $this->request->variable('message', '', true), 'READ_POST_IMG' => $this->user->img('icon_post_target', 'POST'), 'S_QR_CAPS_ENABLE' => $this->config['qr_capslock_transfer'], 'S_QR_SHOW_BUTTON_TRANSLIT' => $this->config['qr_show_button_translit'], 'L_FULL_EDITOR' => $this->config['qr_ajax_submit'] ? $this->user->lang['PREVIEW'] : $this->user->lang['FULL_EDITOR'], 'S_QR_AJAX_SUBMIT' => $this->config['qr_ajax_submit'], 'S_QR_AJAX_PAGINATION' => $this->config['qr_ajax_pagination'] && $this->user->data['ajax_pagination'], 'S_QR_ENABLE_SCROLL' => $this->user->data['qr_enable_scroll'], 'S_QR_SCROLL_INTERVAL' => $this->config['qr_scroll_time'], 'S_QR_SOFT_SCROLL' => $this->config['qr_scroll_time'] && $this->user->data['qr_soft_scroll'], 'S_QR_ALLOWED_GUEST' => $this->config['qr_allow_for_guests'] && $this->user->data['user_id'] == ANONYMOUS, 'S_ABBC3_INSTALLED' => $this->phpbb_extension_manager->is_enabled('vse/abbc3'), 'S_QR_SHOW_ATTACH_BOX' => $this->config['qr_attach'] && $allowed, 'S_ATTACH_DATA' => $attachment_data ? json_encode($attachment_data) : '[]'));
         $add_re = $this->config['qr_enable_re'] ? 'Re: ' : '';
         $this->template->assign_var('SUBJECT', $this->request->variable('subject', $add_re . censor_text($topic_data['topic_title']), true));
     }
     $this->template->assign_vars(array('QR_HIDE_POSTS_SUBJECT' => $this->config['qr_show_subjects'] ? false : true));
 }
Example #2
0
 /**
  * Insert the image into the database
  */
 public static function upload_image(&$image_data, $album_id)
 {
     global $user, $db;
     $sql_ary = array('image_filename' => $image_data['filename'], 'image_name' => $image_data['image_name'], 'image_name_clean' => utf8_clean_string($image_data['image_name']), 'image_user_id' => $user->data['user_id'], 'image_user_colour' => $user->data['user_colour'], 'image_username' => $image_data['username'], 'image_username_clean' => utf8_clean_string($image_data['username']), 'image_user_ip' => $user->ip, 'image_time' => $image_data['image_time'], 'image_album_id' => $image_data['image_album_id'], 'image_status' => phpbb_gallery::$auth->acl_check('i_approve', $album_id) ? phpbb_gallery_image::STATUS_APPROVED : phpbb_gallery_image::STATUS_UNAPPROVED, 'filesize_upload' => $image_data['image_filesize'], 'image_contest' => $image_data['image_contest'], 'image_exif_data' => $image_data['image_exif_data'], 'image_has_exif' => $image_data['image_has_exif']);
     $message_parser = new parse_message();
     $message_parser->message = utf8_normalize_nfc($image_data['image_desc']);
     if ($message_parser->message) {
         $message_parser->parse(true, true, true, true, false, true, true, true);
         $sql_ary['image_desc'] = $message_parser->message;
         $sql_ary['image_desc_uid'] = $message_parser->bbcode_uid;
         $sql_ary['image_desc_bitfield'] = $message_parser->bbcode_bitfield;
     } else {
         $sql_ary['image_desc'] = '';
         $sql_ary['image_desc_uid'] = '';
         $sql_ary['image_desc_bitfield'] = '';
     }
     $sql = 'INSERT INTO ' . GALLERY_IMAGES_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary);
     $db->sql_query($sql);
     $image_id = $db->sql_nextid();
     if (phpbb_gallery::$user->get_data('watch_own')) {
         $sql_ary = array('image_id' => $image_id, 'user_id' => $user->data['user_id']);
         $sql = 'INSERT INTO ' . GALLERY_WATCH_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary);
         $db->sql_query($sql);
     }
     return array('image_id' => $image_id, 'image_name' => $image_data['image_name']);
 }
Example #3
0
 /**
  * @dataProvider get_test_polls
  */
 public function test_parse_poll($poll, $expected, $warn_msg = array())
 {
     $this->prepare_s9e_services();
     $message_parser = new parse_message('Me[i]s[/i]sage');
     // Add some default values
     $poll += array('poll_length' => 123, 'poll_start' => 123, 'poll_last_vote' => 123, 'poll_vote_change' => true, 'enable_bbcode' => true, 'enable_urls' => true, 'enable_smilies' => true, 'img_status' => true);
     $message_parser->parse_poll($poll);
     $this->assertSame($expected, array_intersect_key($poll, $expected));
     $this->assertSame('<r>Me<I><s>[i]</s>s<e>[/i]</e></I>sage</r>', $message_parser->parse(true, true, true, true, true, true, true, false));
     $this->assertSame($warn_msg, $message_parser->warn_msg);
 }
Example #4
0
 /**
  * Parse BBCode in a message
  *
  * @param string $message Message to parse
  * @return string Parsed message
  */
 public function parse_message($message)
 {
     if (empty($this->bbcode_data)) {
         return '';
     }
     if (!is_object($this->message_parser)) {
         if (!class_exists('\\bbcode')) {
             require $this->phpbb_root_path . 'includes/bbcode.' . $this->php_ext;
         }
         if (!class_exists('\\parse_message')) {
             require $this->phpbb_root_path . 'includes/message_parser.' . $this->php_ext;
         }
         $this->message_parser = new \parse_message();
     }
     $this->message_parser->parse_message($message);
     $this->bbcode_data['regexp'] = array($this->bbcode_data['first_pass_match'] => str_replace('$uid', $this->message_parser->bbcode_uid, $this->bbcode_data['first_pass_replace']));
     $this->message_parser->bbcodes = array($this->bbcode_data['bbcode_tag'] => $this->bbcode_data);
     $this->message_parser->parse_bbcode();
     return $this->message_parser->message;
 }
		// Topic data
		'topic_poster'			=> $row['bug_reporter'],
		'topic_replies_real'	=> null,
		'topic_first_post_id'	=> null,
		'topic_last_post_id'	=> null,
	
		// Post data
		'post_id'			=> null,
		'poster_id'			=> $row['bug_reporter'],
		'post_time'			=> $row['bug_time'],
		'post_edit_reason'	=> null,
		'post_edit_locked'	=> 0,
	);
	
	// Parse text
	$message_parser = new parse_message();
	$message_parser->message = $report_data['report_desc'];
	$message_parser->parse(true, $report_data['enable_magic_url'], $report_data['enable_smilies'], true, true, true, true);

	// Just to make sure (easier development; although not every database (or table) engine support it )
	$db->sql_transaction('begin');
	
	// Insert into (our own) bug database (if adding: without the topic id for the time being)
	$sql_ary = array(
		'project_id'		=> $report_data['project_id'],
		'report_id'			=> $report_data['report_id'], // Only here
		'report_title'		=> $report_data['report_title'],
		'report_desc'		=> $message_parser->message,
		'report_component'	=> $report_data['report_component'],
		'report_version'	=> $report_data['report_version'],
		'report_status'		=> $report_data['report_status'],
Example #6
0
    function main($id, $mode)
    {
        global $config, $db, $user, $auth, $template, $cache;
        global $phpbb_root_path, $phpbb_admin_path, $phpEx, $table_prefix, $file_uploads;
        $user->add_lang(array('posting', 'ucp', 'acp/users'));
        $this->tpl_name = 'acp_users';
        $this->page_title = 'ACP_USER_' . strtoupper($mode);
        $error = array();
        $username = utf8_normalize_nfc(request_var('username', '', true));
        $user_id = request_var('u', 0);
        $action = request_var('action', '');
        $submit = isset($_POST['update']) && !isset($_POST['cancel']) ? true : false;
        $form_name = 'acp_users';
        add_form_key($form_name);
        // Whois (special case)
        if ($action == 'whois') {
            include $phpbb_root_path . 'includes/functions_user.' . $phpEx;
            $this->page_title = 'WHOIS';
            $this->tpl_name = 'simple_body';
            $user_ip = request_var('user_ip', '');
            $domain = gethostbyaddr($user_ip);
            $ipwhois = user_ipwhois($user_ip);
            $template->assign_vars(array('MESSAGE_TITLE' => sprintf($user->lang['IP_WHOIS_FOR'], $domain), 'MESSAGE_TEXT' => nl2br($ipwhois)));
            return;
        }
        // Show user selection mask
        if (!$username && !$user_id) {
            $this->page_title = 'SELECT_USER';
            $template->assign_vars(array('U_ACTION' => $this->u_action, 'ANONYMOUS_USER_ID' => ANONYMOUS, 'S_SELECT_USER' => true, 'U_FIND_USERNAME' => append_sid("{$phpbb_root_path}memberlist.{$phpEx}", 'mode=searchuser&amp;form=select_user&amp;field=username&amp;select_single=true')));
            return;
        }
        if (!$user_id) {
            $sql = 'SELECT user_id
				FROM ' . USERS_TABLE . "\n\t\t\t\tWHERE username_clean = '" . $db->sql_escape(utf8_clean_string($username)) . "'";
            $result = $db->sql_query($sql);
            $user_id = (int) $db->sql_fetchfield('user_id');
            $db->sql_freeresult($result);
            if (!$user_id) {
                trigger_error($user->lang['NO_USER'] . adm_back_link($this->u_action), E_USER_WARNING);
            }
        }
        // Generate content for all modes
        $sql = 'SELECT u.*, s.*
			FROM ' . USERS_TABLE . ' u
				LEFT JOIN ' . SESSIONS_TABLE . ' s ON (s.session_user_id = u.user_id)
			WHERE u.user_id = ' . $user_id . '
			ORDER BY s.session_time DESC';
        $result = $db->sql_query_limit($sql, 1);
        $user_row = $db->sql_fetchrow($result);
        $db->sql_freeresult($result);
        if (!$user_row) {
            trigger_error($user->lang['NO_USER'] . adm_back_link($this->u_action), E_USER_WARNING);
        }
        // Generate overall "header" for user admin
        $s_form_options = '';
        // Build modes dropdown list
        $sql = 'SELECT module_mode, module_auth
			FROM ' . MODULES_TABLE . "\n\t\t\tWHERE module_basename = 'users'\n\t\t\t\tAND module_enabled = 1\n\t\t\t\tAND module_class = 'acp'\n\t\t\tORDER BY left_id, module_mode";
        $result = $db->sql_query($sql);
        $dropdown_modes = array();
        while ($row = $db->sql_fetchrow($result)) {
            if (!$this->p_master->module_auth($row['module_auth'])) {
                continue;
            }
            $dropdown_modes[$row['module_mode']] = true;
        }
        $db->sql_freeresult($result);
        foreach ($dropdown_modes as $module_mode => $null) {
            $selected = $mode == $module_mode ? ' selected="selected"' : '';
            $s_form_options .= '<option value="' . $module_mode . '"' . $selected . '>' . $user->lang['ACP_USER_' . strtoupper($module_mode)] . '</option>';
        }
        $template->assign_vars(array('U_BACK' => $this->u_action, 'U_MODE_SELECT' => append_sid("{$phpbb_admin_path}index.{$phpEx}", "i={$id}&amp;u={$user_id}"), 'U_ACTION' => $this->u_action . '&amp;u=' . $user_id, 'S_FORM_OPTIONS' => $s_form_options, 'MANAGED_USERNAME' => $user_row['username']));
        // Prevent normal users/admins change/view founders if they are not a founder by themselves
        if ($user->data['user_type'] != USER_FOUNDER && $user_row['user_type'] == USER_FOUNDER) {
            trigger_error($user->lang['NOT_MANAGE_FOUNDER'] . adm_back_link($this->u_action), E_USER_WARNING);
        }
        switch ($mode) {
            case 'overview':
                include $phpbb_root_path . 'includes/functions_user.' . $phpEx;
                $user->add_lang('acp/ban');
                $delete = request_var('delete', 0);
                $delete_type = request_var('delete_type', '');
                $ip = request_var('ip', 'ip');
                if ($submit) {
                    // You can't delete the founder
                    if ($delete && $user_row['user_type'] != USER_FOUNDER) {
                        if (!$auth->acl_get('a_userdel')) {
                            trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
                        }
                        // Check if the user wants to remove himself or the guest user account
                        if ($user_id == ANONYMOUS) {
                            trigger_error($user->lang['CANNOT_REMOVE_ANONYMOUS'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
                        }
                        if ($user_id == $user->data['user_id']) {
                            trigger_error($user->lang['CANNOT_REMOVE_YOURSELF'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
                        }
                        if ($delete_type) {
                            if (confirm_box(true)) {
                                user_delete($delete_type, $user_id, $user_row['username']);
                                add_log('admin', 'LOG_USER_DELETED', $user_row['username']);
                                trigger_error($user->lang['USER_DELETED'] . adm_back_link($this->u_action));
                            } else {
                                confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array('u' => $user_id, 'i' => $id, 'mode' => $mode, 'action' => $action, 'update' => true, 'delete' => 1, 'delete_type' => $delete_type)));
                            }
                        } else {
                            trigger_error($user->lang['NO_MODE'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
                        }
                    }
                    // Handle quicktool actions
                    switch ($action) {
                        case 'banuser':
                        case 'banemail':
                        case 'banip':
                            if ($user_id == $user->data['user_id']) {
                                trigger_error($user->lang['CANNOT_BAN_YOURSELF'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
                            }
                            if ($user_id == ANONYMOUS) {
                                trigger_error($user->lang['CANNOT_BAN_ANONYMOUS'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
                            }
                            if ($user_row['user_type'] == USER_FOUNDER) {
                                trigger_error($user->lang['CANNOT_BAN_FOUNDER'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
                            }
                            if (!check_form_key($form_name)) {
                                trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
                            }
                            $ban = array();
                            switch ($action) {
                                case 'banuser':
                                    $ban[] = $user_row['username'];
                                    $reason = 'USER_ADMIN_BAN_NAME_REASON';
                                    $log = 'LOG_USER_BAN_USER';
                                    break;
                                case 'banemail':
                                    $ban[] = $user_row['user_email'];
                                    $reason = 'USER_ADMIN_BAN_EMAIL_REASON';
                                    $log = 'LOG_USER_BAN_EMAIL';
                                    break;
                                case 'banip':
                                    $ban[] = $user_row['user_ip'];
                                    $sql = 'SELECT DISTINCT poster_ip
										FROM ' . POSTS_TABLE . "\n\t\t\t\t\t\t\t\t\t\tWHERE poster_id = {$user_id}";
                                    $result = $db->sql_query($sql);
                                    while ($row = $db->sql_fetchrow($result)) {
                                        $ban[] = $row['poster_ip'];
                                    }
                                    $db->sql_freeresult($result);
                                    $reason = 'USER_ADMIN_BAN_IP_REASON';
                                    $log = 'LOG_USER_BAN_IP';
                                    break;
                            }
                            $ban_reason = utf8_normalize_nfc(request_var('ban_reason', $user->lang[$reason], true));
                            $ban_give_reason = utf8_normalize_nfc(request_var('ban_give_reason', '', true));
                            // Log not used at the moment, we simply utilize the ban function.
                            $result = user_ban(substr($action, 3), $ban, 0, 0, 0, $ban_reason, $ban_give_reason);
                            trigger_error(($result === false ? $user->lang['BAN_ALREADY_ENTERED'] : $user->lang['BAN_SUCCESSFUL']) . adm_back_link($this->u_action . '&amp;u=' . $user_id));
                            break;
                        case 'reactivate':
                            if ($user_id == $user->data['user_id']) {
                                trigger_error($user->lang['CANNOT_FORCE_REACT_YOURSELF'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
                            }
                            if (!check_form_key($form_name)) {
                                trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
                            }
                            if ($user_row['user_type'] == USER_FOUNDER) {
                                trigger_error($user->lang['CANNOT_FORCE_REACT_FOUNDER'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
                            }
                            if ($user_row['user_type'] == USER_IGNORE) {
                                trigger_error($user->lang['CANNOT_FORCE_REACT_BOT'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
                            }
                            if ($config['email_enable']) {
                                include_once $phpbb_root_path . 'includes/functions_messenger.' . $phpEx;
                                $server_url = generate_board_url();
                                $user_actkey = gen_rand_string(mt_rand(6, 10));
                                $email_template = $user_row['user_type'] == USER_NORMAL ? 'user_reactivate_account' : 'user_resend_inactive';
                                if ($user_row['user_type'] == USER_NORMAL) {
                                    user_active_flip('deactivate', $user_id, INACTIVE_REMIND);
                                    $sql = 'UPDATE ' . USERS_TABLE . "\n\t\t\t\t\t\t\t\t\t\tSET user_actkey = '" . $db->sql_escape($user_actkey) . "'\n\t\t\t\t\t\t\t\t\t\tWHERE user_id = {$user_id}";
                                    $db->sql_query($sql);
                                } else {
                                    // Grabbing the last confirm key - we only send a reminder
                                    $sql = 'SELECT user_actkey
										FROM ' . USERS_TABLE . '
										WHERE user_id = ' . $user_id;
                                    $result = $db->sql_query($sql);
                                    $user_actkey = (string) $db->sql_fetchfield('user_actkey');
                                    $db->sql_freeresult($result);
                                }
                                $messenger = new messenger(false);
                                $messenger->template($email_template, $user_row['user_lang']);
                                $messenger->to($user_row['user_email'], $user_row['username']);
                                $messenger->headers('X-AntiAbuse: Board servername - ' . $config['server_name']);
                                $messenger->headers('X-AntiAbuse: User_id - ' . $user->data['user_id']);
                                $messenger->headers('X-AntiAbuse: Username - ' . $user->data['username']);
                                $messenger->headers('X-AntiAbuse: User IP - ' . $user->ip);
                                $messenger->assign_vars(array('WELCOME_MSG' => htmlspecialchars_decode(sprintf($user->lang['WELCOME_SUBJECT'], $config['sitename'])), 'USERNAME' => htmlspecialchars_decode($user_row['username']), 'U_ACTIVATE' => "{$server_url}/ucp.{$phpEx}?mode=activate&u={$user_row['user_id']}&k={$user_actkey}"));
                                $messenger->send(NOTIFY_EMAIL);
                                add_log('admin', 'LOG_USER_REACTIVATE', $user_row['username']);
                                add_log('user', $user_id, 'LOG_USER_REACTIVATE_USER');
                                trigger_error($user->lang['FORCE_REACTIVATION_SUCCESS'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
                            }
                            break;
                        case 'active':
                            if ($user_id == $user->data['user_id']) {
                                // It is only deactivation since the user is already activated (else he would not have reached this page)
                                trigger_error($user->lang['CANNOT_DEACTIVATE_YOURSELF'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
                            }
                            if (!check_form_key($form_name)) {
                                trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
                            }
                            if ($user_row['user_type'] == USER_FOUNDER) {
                                trigger_error($user->lang['CANNOT_DEACTIVATE_FOUNDER'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
                            }
                            if ($user_row['user_type'] == USER_IGNORE) {
                                trigger_error($user->lang['CANNOT_DEACTIVATE_BOT'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
                            }
                            user_active_flip('flip', $user_id);
                            if ($user_row['user_type'] == USER_INACTIVE) {
                                if ($config['require_activation'] == USER_ACTIVATION_ADMIN) {
                                    include_once $phpbb_root_path . 'includes/functions_messenger.' . $phpEx;
                                    $messenger = new messenger(false);
                                    $messenger->template('admin_welcome_activated', $user_row['user_lang']);
                                    $messenger->to($user_row['user_email'], $user_row['username']);
                                    $messenger->headers('X-AntiAbuse: Board servername - ' . $config['server_name']);
                                    $messenger->headers('X-AntiAbuse: User_id - ' . $user->data['user_id']);
                                    $messenger->headers('X-AntiAbuse: Username - ' . $user->data['username']);
                                    $messenger->headers('X-AntiAbuse: User IP - ' . $user->ip);
                                    $messenger->assign_vars(array('USERNAME' => htmlspecialchars_decode($user_row['username'])));
                                    $messenger->send(NOTIFY_EMAIL);
                                }
                            }
                            $message = $user_row['user_type'] == USER_INACTIVE ? 'USER_ADMIN_ACTIVATED' : 'USER_ADMIN_DEACTIVED';
                            $log = $user_row['user_type'] == USER_INACTIVE ? 'LOG_USER_ACTIVE' : 'LOG_USER_INACTIVE';
                            add_log('admin', $log, $user_row['username']);
                            add_log('user', $user_id, $log . '_USER');
                            trigger_error($user->lang[$message] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
                            break;
                        case 'delsig':
                            if (!check_form_key($form_name)) {
                                trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
                            }
                            $sql_ary = array('user_sig' => '', 'user_sig_bbcode_uid' => '', 'user_sig_bbcode_bitfield' => '');
                            $sql = 'UPDATE ' . USERS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . "\n\t\t\t\t\t\t\t\tWHERE user_id = {$user_id}";
                            $db->sql_query($sql);
                            add_log('admin', 'LOG_USER_DEL_SIG', $user_row['username']);
                            add_log('user', $user_id, 'LOG_USER_DEL_SIG_USER');
                            trigger_error($user->lang['USER_ADMIN_SIG_REMOVED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
                            break;
                        case 'delavatar':
                            if (!check_form_key($form_name)) {
                                trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
                            }
                            $sql_ary = array('user_avatar' => '', 'user_avatar_type' => 0, 'user_avatar_width' => 0, 'user_avatar_height' => 0);
                            $sql = 'UPDATE ' . USERS_TABLE . '
								SET ' . $db->sql_build_array('UPDATE', $sql_ary) . "\n\t\t\t\t\t\t\t\tWHERE user_id = {$user_id}";
                            $db->sql_query($sql);
                            // Delete old avatar if present
                            if ($user_row['user_avatar'] && $user_row['user_avatar_type'] != AVATAR_GALLERY) {
                                avatar_delete('user', $user_row);
                            }
                            add_log('admin', 'LOG_USER_DEL_AVATAR', $user_row['username']);
                            add_log('user', $user_id, 'LOG_USER_DEL_AVATAR_USER');
                            trigger_error($user->lang['USER_ADMIN_AVATAR_REMOVED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
                            break;
                        case 'delposts':
                            if (confirm_box(true)) {
                                // Delete posts, attachments, etc.
                                delete_posts('poster_id', $user_id);
                                add_log('admin', 'LOG_USER_DEL_POSTS', $user_row['username']);
                                trigger_error($user->lang['USER_POSTS_DELETED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
                            } else {
                                confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array('u' => $user_id, 'i' => $id, 'mode' => $mode, 'action' => $action, 'update' => true)));
                            }
                            break;
                        case 'delattach':
                            if (confirm_box(true)) {
                                delete_attachments('user', $user_id);
                                add_log('admin', 'LOG_USER_DEL_ATTACH', $user_row['username']);
                                trigger_error($user->lang['USER_ATTACHMENTS_REMOVED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
                            } else {
                                confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array('u' => $user_id, 'i' => $id, 'mode' => $mode, 'action' => $action, 'update' => true)));
                            }
                            break;
                        case 'deloutbox':
                            if (confirm_box(true)) {
                                $msg_ids = array();
                                $lang = 'EMPTY';
                                $sql = 'SELECT msg_id
									FROM ' . PRIVMSGS_TO_TABLE . "\n\t\t\t\t\t\t\t\t\tWHERE author_id = {$user_id}\n\t\t\t\t\t\t\t\t\t\tAND folder_id = " . PRIVMSGS_OUTBOX;
                                $result = $db->sql_query($sql);
                                if ($row = $db->sql_fetchrow($result)) {
                                    if (!function_exists('delete_pm')) {
                                        include $phpbb_root_path . 'includes/functions_privmsgs.' . $phpEx;
                                    }
                                    do {
                                        $msg_ids[] = (int) $row['msg_id'];
                                    } while ($row = $db->sql_fetchrow($result));
                                    $db->sql_freeresult($result);
                                    delete_pm($user_id, $msg_ids, PRIVMSGS_OUTBOX);
                                    add_log('admin', 'LOG_USER_DEL_OUTBOX', $user_row['username']);
                                    $lang = 'EMPTIED';
                                }
                                $db->sql_freeresult($result);
                                trigger_error($user->lang['USER_OUTBOX_' . $lang] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
                            } else {
                                confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array('u' => $user_id, 'i' => $id, 'mode' => $mode, 'action' => $action, 'update' => true)));
                            }
                            break;
                        case 'moveposts':
                            if (!check_form_key($form_name)) {
                                trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
                            }
                            $user->add_lang('acp/forums');
                            $new_forum_id = request_var('new_f', 0);
                            if (!$new_forum_id) {
                                $this->page_title = 'USER_ADMIN_MOVE_POSTS';
                                $template->assign_vars(array('S_SELECT_FORUM' => true, 'U_ACTION' => $this->u_action . "&amp;action={$action}&amp;u={$user_id}", 'U_BACK' => $this->u_action . "&amp;u={$user_id}", 'S_FORUM_OPTIONS' => make_forum_select(false, false, false, true)));
                                return;
                            }
                            // Is the new forum postable to?
                            $sql = 'SELECT forum_name, forum_type
								FROM ' . FORUMS_TABLE . "\n\t\t\t\t\t\t\t\tWHERE forum_id = {$new_forum_id}";
                            $result = $db->sql_query($sql);
                            $forum_info = $db->sql_fetchrow($result);
                            $db->sql_freeresult($result);
                            if (!$forum_info) {
                                trigger_error($user->lang['NO_FORUM'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
                            }
                            if ($forum_info['forum_type'] != FORUM_POST) {
                                trigger_error($user->lang['MOVE_POSTS_NO_POSTABLE_FORUM'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
                            }
                            // Two stage?
                            // Move topics comprising only posts from this user
                            $topic_id_ary = $move_topic_ary = $move_post_ary = $new_topic_id_ary = array();
                            $forum_id_ary = array($new_forum_id);
                            $sql = 'SELECT topic_id, COUNT(post_id) AS total_posts
								FROM ' . POSTS_TABLE . "\n\t\t\t\t\t\t\t\tWHERE poster_id = {$user_id}\n\t\t\t\t\t\t\t\t\tAND forum_id <> {$new_forum_id}\n\t\t\t\t\t\t\t\tGROUP BY topic_id";
                            $result = $db->sql_query($sql);
                            while ($row = $db->sql_fetchrow($result)) {
                                $topic_id_ary[$row['topic_id']] = $row['total_posts'];
                            }
                            $db->sql_freeresult($result);
                            if (sizeof($topic_id_ary)) {
                                $sql = 'SELECT topic_id, forum_id, topic_title, topic_replies, topic_replies_real, topic_attachment
									FROM ' . TOPICS_TABLE . '
									WHERE ' . $db->sql_in_set('topic_id', array_keys($topic_id_ary));
                                $result = $db->sql_query($sql);
                                while ($row = $db->sql_fetchrow($result)) {
                                    if (max($row['topic_replies'], $row['topic_replies_real']) + 1 == $topic_id_ary[$row['topic_id']]) {
                                        $move_topic_ary[] = $row['topic_id'];
                                    } else {
                                        $move_post_ary[$row['topic_id']]['title'] = $row['topic_title'];
                                        $move_post_ary[$row['topic_id']]['attach'] = $row['topic_attachment'] ? 1 : 0;
                                    }
                                    $forum_id_ary[] = $row['forum_id'];
                                }
                                $db->sql_freeresult($result);
                            }
                            // Entire topic comprises posts by this user, move these topics
                            if (sizeof($move_topic_ary)) {
                                move_topics($move_topic_ary, $new_forum_id, false);
                            }
                            if (sizeof($move_post_ary)) {
                                // Create new topic
                                // Update post_ids, report_ids, attachment_ids
                                foreach ($move_post_ary as $topic_id => $post_ary) {
                                    // Create new topic
                                    $sql = 'INSERT INTO ' . TOPICS_TABLE . ' ' . $db->sql_build_array('INSERT', array('topic_poster' => $user_id, 'topic_time' => time(), 'forum_id' => $new_forum_id, 'icon_id' => 0, 'topic_approved' => 1, 'topic_title' => $post_ary['title'], 'topic_first_poster_name' => $user_row['username'], 'topic_type' => POST_NORMAL, 'topic_time_limit' => 0, 'topic_attachment' => $post_ary['attach']));
                                    $db->sql_query($sql);
                                    $new_topic_id = $db->sql_nextid();
                                    // Move posts
                                    $sql = 'UPDATE ' . POSTS_TABLE . "\n\t\t\t\t\t\t\t\t\t\tSET forum_id = {$new_forum_id}, topic_id = {$new_topic_id}\n\t\t\t\t\t\t\t\t\t\tWHERE topic_id = {$topic_id}\n\t\t\t\t\t\t\t\t\t\t\tAND poster_id = {$user_id}";
                                    $db->sql_query($sql);
                                    if ($post_ary['attach']) {
                                        $sql = 'UPDATE ' . ATTACHMENTS_TABLE . "\n\t\t\t\t\t\t\t\t\t\t\tSET topic_id = {$new_topic_id}\n\t\t\t\t\t\t\t\t\t\t\tWHERE topic_id = {$topic_id}\n\t\t\t\t\t\t\t\t\t\t\t\tAND poster_id = {$user_id}";
                                        $db->sql_query($sql);
                                    }
                                    $new_topic_id_ary[] = $new_topic_id;
                                }
                            }
                            $forum_id_ary = array_unique($forum_id_ary);
                            $topic_id_ary = array_unique(array_merge(array_keys($topic_id_ary), $new_topic_id_ary));
                            if (sizeof($topic_id_ary)) {
                                sync('topic_reported', 'topic_id', $topic_id_ary);
                                sync('topic', 'topic_id', $topic_id_ary);
                            }
                            if (sizeof($forum_id_ary)) {
                                sync('forum', 'forum_id', $forum_id_ary, false, true);
                            }
                            add_log('admin', 'LOG_USER_MOVE_POSTS', $user_row['username'], $forum_info['forum_name']);
                            add_log('user', $user_id, 'LOG_USER_MOVE_POSTS_USER', $forum_info['forum_name']);
                            trigger_error($user->lang['USER_POSTS_MOVED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
                            break;
                        case 'leave_nr':
                            if (confirm_box(true)) {
                                remove_newly_registered($user_id, $user_row);
                                add_log('admin', 'LOG_USER_REMOVED_NR', $user_row['username']);
                                trigger_error($user->lang['USER_LIFTED_NR'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
                            } else {
                                confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array('u' => $user_id, 'i' => $id, 'mode' => $mode, 'action' => $action, 'update' => true)));
                            }
                            break;
                    }
                    // Handle registration info updates
                    $data = array('username' => utf8_normalize_nfc(request_var('user', $user_row['username'], true)), 'user_founder' => request_var('user_founder', $user_row['user_type'] == USER_FOUNDER ? 1 : 0), 'email' => strtolower(request_var('user_email', $user_row['user_email'])), 'email_confirm' => strtolower(request_var('email_confirm', '')), 'new_password' => request_var('new_password', '', true), 'password_confirm' => request_var('password_confirm', '', true));
                    // Validation data - we do not check the password complexity setting here
                    $check_ary = array('new_password' => array(array('string', true, $config['min_pass_chars'], $config['max_pass_chars']), array('password')), 'password_confirm' => array('string', true, $config['min_pass_chars'], $config['max_pass_chars']));
                    // Check username if altered
                    if ($data['username'] != $user_row['username']) {
                        $check_ary += array('username' => array(array('string', false, $config['min_name_chars'], $config['max_name_chars']), array('username', $user_row['username'])));
                    }
                    // Check email if altered
                    if ($data['email'] != $user_row['user_email']) {
                        $check_ary += array('email' => array(array('string', false, 6, 60), array('email', $user_row['user_email'])), 'email_confirm' => array('string', true, 6, 60));
                    }
                    $error = validate_data($data, $check_ary);
                    if ($data['new_password'] && $data['password_confirm'] != $data['new_password']) {
                        $error[] = 'NEW_PASSWORD_ERROR';
                    }
                    if ($data['email'] != $user_row['user_email'] && $data['email_confirm'] != $data['email']) {
                        $error[] = 'NEW_EMAIL_ERROR';
                    }
                    if (!check_form_key($form_name)) {
                        $error[] = 'FORM_INVALID';
                    }
                    // Which updates do we need to do?
                    $update_username = $user_row['username'] != $data['username'] ? $data['username'] : false;
                    $update_password = $data['new_password'] && !phpbb_check_hash($user_row['user_password'], $data['new_password']) ? true : false;
                    $update_email = $data['email'] != $user_row['user_email'] ? $data['email'] : false;
                    if (!sizeof($error)) {
                        $sql_ary = array();
                        if ($user_row['user_type'] != USER_FOUNDER || $user->data['user_type'] == USER_FOUNDER) {
                            // Only allow founders updating the founder status...
                            if ($user->data['user_type'] == USER_FOUNDER) {
                                // Setting a normal member to be a founder
                                if ($data['user_founder'] && $user_row['user_type'] != USER_FOUNDER) {
                                    // Make sure the user is not setting an Inactive or ignored user to be a founder
                                    if ($user_row['user_type'] == USER_IGNORE) {
                                        trigger_error($user->lang['CANNOT_SET_FOUNDER_IGNORED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
                                    }
                                    if ($user_row['user_type'] == USER_INACTIVE) {
                                        trigger_error($user->lang['CANNOT_SET_FOUNDER_INACTIVE'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
                                    }
                                    $sql_ary['user_type'] = USER_FOUNDER;
                                } else {
                                    if (!$data['user_founder'] && $user_row['user_type'] == USER_FOUNDER) {
                                        // Check if at least one founder is present
                                        $sql = 'SELECT user_id
										FROM ' . USERS_TABLE . '
										WHERE user_type = ' . USER_FOUNDER . '
											AND user_id <> ' . $user_id;
                                        $result = $db->sql_query_limit($sql, 1);
                                        $row = $db->sql_fetchrow($result);
                                        $db->sql_freeresult($result);
                                        if ($row) {
                                            $sql_ary['user_type'] = USER_NORMAL;
                                        } else {
                                            trigger_error($user->lang['AT_LEAST_ONE_FOUNDER'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
                                        }
                                    }
                                }
                            }
                        }
                        if ($update_username !== false) {
                            $sql_ary['username'] = $update_username;
                            $sql_ary['username_clean'] = utf8_clean_string($update_username);
                            add_log('user', $user_id, 'LOG_USER_UPDATE_NAME', $user_row['username'], $update_username);
                        }
                        if ($update_email !== false) {
                            $sql_ary += array('user_email' => $update_email, 'user_email_hash' => phpbb_email_hash($update_email));
                            add_log('user', $user_id, 'LOG_USER_UPDATE_EMAIL', $user_row['username'], $user_row['user_email'], $update_email);
                        }
                        if ($update_password) {
                            $sql_ary += array('user_password' => phpbb_hash($data['new_password']), 'user_passchg' => time(), 'user_pass_convert' => 0);
                            $user->reset_login_keys($user_id);
                            add_log('user', $user_id, 'LOG_USER_NEW_PASSWORD', $user_row['username']);
                        }
                        if (sizeof($sql_ary)) {
                            $sql = 'UPDATE ' . USERS_TABLE . '
								SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
								WHERE user_id = ' . $user_id;
                            $db->sql_query($sql);
                        }
                        if ($update_username) {
                            user_update_name($user_row['username'], $update_username);
                        }
                        // Let the users permissions being updated
                        $auth->acl_clear_prefetch($user_id);
                        add_log('admin', 'LOG_USER_USER_UPDATE', $data['username']);
                        trigger_error($user->lang['USER_OVERVIEW_UPDATED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
                    }
                    // Replace "error" strings with their real, localised form
                    $error = preg_replace('#^([A-Z_]+)$#e', "(!empty(\$user->lang['\\1'])) ? \$user->lang['\\1'] : '\\1'", $error);
                }
                if ($user_id == $user->data['user_id']) {
                    $quick_tool_ary = array('delsig' => 'DEL_SIG', 'delavatar' => 'DEL_AVATAR', 'moveposts' => 'MOVE_POSTS', 'delposts' => 'DEL_POSTS', 'delattach' => 'DEL_ATTACH', 'deloutbox' => 'DEL_OUTBOX');
                    if ($user_row['user_new']) {
                        $quick_tool_ary['leave_nr'] = 'LEAVE_NR';
                    }
                } else {
                    $quick_tool_ary = array();
                    if ($user_row['user_type'] != USER_FOUNDER) {
                        $quick_tool_ary += array('banuser' => 'BAN_USER', 'banemail' => 'BAN_EMAIL', 'banip' => 'BAN_IP');
                    }
                    if ($user_row['user_type'] != USER_FOUNDER && $user_row['user_type'] != USER_IGNORE) {
                        $quick_tool_ary += array('active' => $user_row['user_type'] == USER_INACTIVE ? 'ACTIVATE' : 'DEACTIVATE');
                    }
                    $quick_tool_ary += array('delsig' => 'DEL_SIG', 'delavatar' => 'DEL_AVATAR', 'moveposts' => 'MOVE_POSTS', 'delposts' => 'DEL_POSTS', 'delattach' => 'DEL_ATTACH', 'deloutbox' => 'DEL_OUTBOX');
                    if ($config['email_enable'] && ($user_row['user_type'] == USER_NORMAL || $user_row['user_type'] == USER_INACTIVE)) {
                        $quick_tool_ary['reactivate'] = 'FORCE';
                    }
                    if ($user_row['user_new']) {
                        $quick_tool_ary['leave_nr'] = 'LEAVE_NR';
                    }
                }
                $s_action_options = '<option class="sep" value="">' . $user->lang['SELECT_OPTION'] . '</option>';
                foreach ($quick_tool_ary as $value => $lang) {
                    $s_action_options .= '<option value="' . $value . '">' . $user->lang['USER_ADMIN_' . $lang] . '</option>';
                }
                if ($config['load_onlinetrack']) {
                    $sql = 'SELECT MAX(session_time) AS session_time, MIN(session_viewonline) AS session_viewonline
						FROM ' . SESSIONS_TABLE . "\n\t\t\t\t\t\tWHERE session_user_id = {$user_id}";
                    $result = $db->sql_query($sql);
                    $row = $db->sql_fetchrow($result);
                    $db->sql_freeresult($result);
                    $user_row['session_time'] = isset($row['session_time']) ? $row['session_time'] : 0;
                    $user_row['session_viewonline'] = isset($row['session_viewonline']) ? $row['session_viewonline'] : 0;
                    unset($row);
                }
                $last_visit = !empty($user_row['session_time']) ? $user_row['session_time'] : $user_row['user_lastvisit'];
                $inactive_reason = '';
                if ($user_row['user_type'] == USER_INACTIVE) {
                    $inactive_reason = $user->lang['INACTIVE_REASON_UNKNOWN'];
                    switch ($user_row['user_inactive_reason']) {
                        case INACTIVE_REGISTER:
                            $inactive_reason = $user->lang['INACTIVE_REASON_REGISTER'];
                            break;
                        case INACTIVE_PROFILE:
                            $inactive_reason = $user->lang['INACTIVE_REASON_PROFILE'];
                            break;
                        case INACTIVE_MANUAL:
                            $inactive_reason = $user->lang['INACTIVE_REASON_MANUAL'];
                            break;
                        case INACTIVE_REMIND:
                            $inactive_reason = $user->lang['INACTIVE_REASON_REMIND'];
                            break;
                    }
                }
                // Posts in Queue
                $sql = 'SELECT COUNT(post_id) as posts_in_queue
					FROM ' . POSTS_TABLE . '
					WHERE poster_id = ' . $user_id . '
						AND post_approved = 0';
                $result = $db->sql_query($sql);
                $user_row['posts_in_queue'] = (int) $db->sql_fetchfield('posts_in_queue');
                $db->sql_freeresult($result);
                $template->assign_vars(array('L_NAME_CHARS_EXPLAIN' => sprintf($user->lang[$config['allow_name_chars'] . '_EXPLAIN'], $config['min_name_chars'], $config['max_name_chars']), 'L_CHANGE_PASSWORD_EXPLAIN' => sprintf($user->lang[$config['pass_complex'] . '_EXPLAIN'], $config['min_pass_chars'], $config['max_pass_chars']), 'L_POSTS_IN_QUEUE' => $user->lang('NUM_POSTS_IN_QUEUE', $user_row['posts_in_queue']), 'S_FOUNDER' => $user->data['user_type'] == USER_FOUNDER ? true : false, 'S_OVERVIEW' => true, 'S_USER_IP' => $user_row['user_ip'] ? true : false, 'S_USER_FOUNDER' => $user_row['user_type'] == USER_FOUNDER ? true : false, 'S_ACTION_OPTIONS' => $s_action_options, 'S_OWN_ACCOUNT' => $user_id == $user->data['user_id'] ? true : false, 'S_USER_INACTIVE' => $user_row['user_type'] == USER_INACTIVE ? true : false, 'U_SHOW_IP' => $this->u_action . "&amp;u={$user_id}&amp;ip=" . ($ip == 'ip' ? 'hostname' : 'ip'), 'U_WHOIS' => $this->u_action . "&amp;action=whois&amp;user_ip={$user_row['user_ip']}", 'U_MCP_QUEUE' => $auth->acl_getf_global('m_approve') ? append_sid("{$phpbb_root_path}mcp.{$phpEx}", 'i=queue', true, $user->session_id) : '', 'U_SWITCH_PERMISSIONS' => $auth->acl_get('a_switchperm') && $user->data['user_id'] != $user_row['user_id'] ? append_sid("{$phpbb_root_path}ucp.{$phpEx}", "mode=switch_perm&amp;u={$user_row['user_id']}&amp;hash=" . generate_link_hash('switchperm')) : '', 'POSTS_IN_QUEUE' => $user_row['posts_in_queue'], 'USER' => $user_row['username'], 'USER_REGISTERED' => $user->format_date($user_row['user_regdate']), 'REGISTERED_IP' => $ip == 'hostname' ? gethostbyaddr($user_row['user_ip']) : $user_row['user_ip'], 'USER_LASTACTIVE' => $last_visit ? $user->format_date($last_visit) : ' - ', 'USER_EMAIL' => $user_row['user_email'], 'USER_WARNINGS' => $user_row['user_warnings'], 'USER_POSTS' => $user_row['user_posts'], 'USER_INACTIVE_REASON' => $inactive_reason));
                break;
            case 'feedback':
                $user->add_lang('mcp');
                // Set up general vars
                $start = request_var('start', 0);
                $deletemark = isset($_POST['delmarked']) ? true : false;
                $deleteall = isset($_POST['delall']) ? true : false;
                $marked = request_var('mark', array(0));
                $message = utf8_normalize_nfc(request_var('message', '', true));
                // Sort keys
                $sort_days = request_var('st', 0);
                $sort_key = request_var('sk', 't');
                $sort_dir = request_var('sd', 'd');
                // Delete entries if requested and able
                if (($deletemark || $deleteall) && $auth->acl_get('a_clearlogs')) {
                    if (!check_form_key($form_name)) {
                        trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
                    }
                    $where_sql = '';
                    if ($deletemark && $marked) {
                        $sql_in = array();
                        foreach ($marked as $mark) {
                            $sql_in[] = $mark;
                        }
                        $where_sql = ' AND ' . $db->sql_in_set('log_id', $sql_in);
                        unset($sql_in);
                    }
                    if ($where_sql || $deleteall) {
                        $sql = 'DELETE FROM ' . LOG_TABLE . '
							WHERE log_type = ' . LOG_USERS . "\n\t\t\t\t\t\t\tAND reportee_id = {$user_id}\n\t\t\t\t\t\t\t{$where_sql}";
                        $db->sql_query($sql);
                        add_log('admin', 'LOG_CLEAR_USER', $user_row['username']);
                    }
                }
                if ($submit && $message) {
                    if (!check_form_key($form_name)) {
                        trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
                    }
                    add_log('admin', 'LOG_USER_FEEDBACK', $user_row['username']);
                    add_log('mod', 0, 0, 'LOG_USER_FEEDBACK', $user_row['username']);
                    add_log('user', $user_id, 'LOG_USER_GENERAL', $message);
                    trigger_error($user->lang['USER_FEEDBACK_ADDED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
                }
                // Sorting
                $limit_days = array(0 => $user->lang['ALL_ENTRIES'], 1 => $user->lang['1_DAY'], 7 => $user->lang['7_DAYS'], 14 => $user->lang['2_WEEKS'], 30 => $user->lang['1_MONTH'], 90 => $user->lang['3_MONTHS'], 180 => $user->lang['6_MONTHS'], 365 => $user->lang['1_YEAR']);
                $sort_by_text = array('u' => $user->lang['SORT_USERNAME'], 't' => $user->lang['SORT_DATE'], 'i' => $user->lang['SORT_IP'], 'o' => $user->lang['SORT_ACTION']);
                $sort_by_sql = array('u' => 'u.username_clean', 't' => 'l.log_time', 'i' => 'l.log_ip', 'o' => 'l.log_operation');
                $s_limit_days = $s_sort_key = $s_sort_dir = $u_sort_param = '';
                gen_sort_selects($limit_days, $sort_by_text, $sort_days, $sort_key, $sort_dir, $s_limit_days, $s_sort_key, $s_sort_dir, $u_sort_param);
                // Define where and sort sql for use in displaying logs
                $sql_where = $sort_days ? time() - $sort_days * 86400 : 0;
                $sql_sort = $sort_by_sql[$sort_key] . ' ' . ($sort_dir == 'd' ? 'DESC' : 'ASC');
                // Grab log data
                $log_data = array();
                $log_count = 0;
                view_log('user', $log_data, $log_count, $config['topics_per_page'], $start, 0, 0, $user_id, $sql_where, $sql_sort);
                $template->assign_vars(array('S_FEEDBACK' => true, 'S_ON_PAGE' => on_page($log_count, $config['topics_per_page'], $start), 'PAGINATION' => generate_pagination($this->u_action . "&amp;u={$user_id}&amp;{$u_sort_param}", $log_count, $config['topics_per_page'], $start, true), 'S_LIMIT_DAYS' => $s_limit_days, 'S_SORT_KEY' => $s_sort_key, 'S_SORT_DIR' => $s_sort_dir, 'S_CLEARLOGS' => $auth->acl_get('a_clearlogs')));
                foreach ($log_data as $row) {
                    $template->assign_block_vars('log', array('USERNAME' => $row['username_full'], 'IP' => $row['ip'], 'DATE' => $user->format_date($row['time']), 'ACTION' => nl2br($row['action']), 'ID' => $row['id']));
                }
                break;
            case 'warnings':
                $user->add_lang('mcp');
                // Set up general vars
                $start = request_var('start', 0);
                $deletemark = isset($_POST['delmarked']) ? true : false;
                $deleteall = isset($_POST['delall']) ? true : false;
                $confirm = isset($_POST['confirm']) ? true : false;
                $marked = request_var('mark', array(0));
                $message = utf8_normalize_nfc(request_var('message', '', true));
                // Sort keys
                $sort_days = request_var('st', 0);
                $sort_key = request_var('sk', 't');
                $sort_dir = request_var('sd', 'd');
                // Delete entries if requested and able
                if ($deletemark || $deleteall || $confirm) {
                    if (confirm_box(true)) {
                        $where_sql = '';
                        $deletemark = request_var('delmarked', 0);
                        $deleteall = request_var('delall', 0);
                        if ($deletemark && $marked) {
                            $where_sql = ' AND ' . $db->sql_in_set('warning_id', array_values($marked));
                        }
                        if ($where_sql || $deleteall) {
                            $sql = 'DELETE FROM ' . WARNINGS_TABLE . "\n\t\t\t\t\t\t\t\tWHERE user_id = {$user_id}\n\t\t\t\t\t\t\t\t\t{$where_sql}";
                            $db->sql_query($sql);
                            if ($deleteall) {
                                $log_warnings = $deleted_warnings = 0;
                            } else {
                                $num_warnings = (int) $db->sql_affectedrows();
                                $deleted_warnings = ' user_warnings - ' . $num_warnings;
                                $log_warnings = $num_warnings > 2 ? 2 : $num_warnings;
                            }
                            $sql = 'UPDATE ' . USERS_TABLE . "\n\t\t\t\t\t\t\t\tSET user_warnings = {$deleted_warnings}\n\t\t\t\t\t\t\t\tWHERE user_id = {$user_id}";
                            $db->sql_query($sql);
                            switch ($log_warnings) {
                                case 2:
                                    add_log('admin', 'LOG_WARNINGS_DELETED', $user_row['username'], $num_warnings);
                                    break;
                                case 1:
                                    add_log('admin', 'LOG_WARNING_DELETED', $user_row['username']);
                                    break;
                                default:
                                    add_log('admin', 'LOG_WARNINGS_DELETED_ALL', $user_row['username']);
                                    break;
                            }
                        }
                    } else {
                        $s_hidden_fields = array('i' => $id, 'mode' => $mode, 'u' => $user_id, 'mark' => $marked);
                        if (isset($_POST['delmarked'])) {
                            $s_hidden_fields['delmarked'] = 1;
                        }
                        if (isset($_POST['delall'])) {
                            $s_hidden_fields['delall'] = 1;
                        }
                        if (isset($_POST['delall']) || isset($_POST['delmarked']) && sizeof($marked)) {
                            confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields($s_hidden_fields));
                        }
                    }
                }
                $sql = 'SELECT w.warning_id, w.warning_time, w.post_id, l.log_operation, l.log_data, l.user_id AS mod_user_id, m.username AS mod_username, m.user_colour AS mod_user_colour
					FROM ' . WARNINGS_TABLE . ' w
					LEFT JOIN ' . LOG_TABLE . ' l
						ON (w.log_id = l.log_id)
					LEFT JOIN ' . USERS_TABLE . ' m
						ON (l.user_id = m.user_id)
					WHERE w.user_id = ' . $user_id . '
					ORDER BY w.warning_time DESC';
                $result = $db->sql_query($sql);
                while ($row = $db->sql_fetchrow($result)) {
                    if (!$row['log_operation']) {
                        // We do not have a log-entry anymore, so there is no data available
                        $row['action'] = $user->lang['USER_WARNING_LOG_DELETED'];
                    } else {
                        $row['action'] = isset($user->lang[$row['log_operation']]) ? $user->lang[$row['log_operation']] : '{' . ucfirst(str_replace('_', ' ', $row['log_operation'])) . '}';
                        if (!empty($row['log_data'])) {
                            $log_data_ary = @unserialize($row['log_data']);
                            $log_data_ary = $log_data_ary === false ? array() : $log_data_ary;
                            if (isset($user->lang[$row['log_operation']])) {
                                // Check if there are more occurrences of % than arguments, if there are we fill out the arguments array
                                // It doesn't matter if we add more arguments than placeholders
                                if (substr_count($row['action'], '%') - sizeof($log_data_ary) > 0) {
                                    $log_data_ary = array_merge($log_data_ary, array_fill(0, substr_count($row['action'], '%') - sizeof($log_data_ary), ''));
                                }
                                $row['action'] = vsprintf($row['action'], $log_data_ary);
                                $row['action'] = bbcode_nl2br(censor_text($row['action']));
                            } else {
                                if (!empty($log_data_ary)) {
                                    $row['action'] .= '<br />' . implode('', $log_data_ary);
                                }
                            }
                        }
                    }
                    $template->assign_block_vars('warn', array('ID' => $row['warning_id'], 'USERNAME' => $row['log_operation'] ? get_username_string('full', $row['mod_user_id'], $row['mod_username'], $row['mod_user_colour']) : '-', 'ACTION' => make_clickable($row['action']), 'DATE' => $user->format_date($row['warning_time'])));
                }
                $db->sql_freeresult($result);
                $template->assign_vars(array('S_WARNINGS' => true));
                break;
            case 'profile':
                include $phpbb_root_path . 'includes/functions_user.' . $phpEx;
                include $phpbb_root_path . 'includes/functions_profile_fields.' . $phpEx;
                $cp = new custom_profile();
                $cp_data = $cp_error = array();
                $sql = 'SELECT lang_id
					FROM ' . LANG_TABLE . "\n\t\t\t\t\tWHERE lang_iso = '" . $db->sql_escape($user->data['user_lang']) . "'";
                $result = $db->sql_query($sql);
                $row = $db->sql_fetchrow($result);
                $db->sql_freeresult($result);
                $user_row['iso_lang_id'] = $row['lang_id'];
                $data = array('icq' => request_var('icq', $user_row['user_icq']), 'aim' => request_var('aim', $user_row['user_aim']), 'msn' => request_var('msn', $user_row['user_msnm']), 'yim' => request_var('yim', $user_row['user_yim']), 'jabber' => utf8_normalize_nfc(request_var('jabber', $user_row['user_jabber'], true)), 'website' => request_var('website', $user_row['user_website']), 'location' => utf8_normalize_nfc(request_var('location', $user_row['user_from'], true)), 'occupation' => utf8_normalize_nfc(request_var('occupation', $user_row['user_occ'], true)), 'interests' => utf8_normalize_nfc(request_var('interests', $user_row['user_interests'], true)), 'bday_day' => 0, 'bday_month' => 0, 'bday_year' => 0);
                if ($user_row['user_birthday']) {
                    list($data['bday_day'], $data['bday_month'], $data['bday_year']) = explode('-', $user_row['user_birthday']);
                }
                $data['bday_day'] = request_var('bday_day', $data['bday_day']);
                $data['bday_month'] = request_var('bday_month', $data['bday_month']);
                $data['bday_year'] = request_var('bday_year', $data['bday_year']);
                $data['user_birthday'] = sprintf('%2d-%2d-%4d', $data['bday_day'], $data['bday_month'], $data['bday_year']);
                if ($submit) {
                    $error = validate_data($data, array('icq' => array(array('string', true, 3, 15), array('match', true, '#^[0-9]+$#i')), 'aim' => array('string', true, 3, 255), 'msn' => array('string', true, 5, 255), 'jabber' => array(array('string', true, 5, 255), array('jabber')), 'yim' => array('string', true, 5, 255), 'website' => array(array('string', true, 12, 255), array('match', true, '#^http[s]?://(.*?\\.)*?[a-z0-9\\-]+\\.[a-z]{2,4}#i')), 'location' => array('string', true, 2, 100), 'occupation' => array('string', true, 2, 500), 'interests' => array('string', true, 2, 500), 'bday_day' => array('num', true, 1, 31), 'bday_month' => array('num', true, 1, 12), 'bday_year' => array('num', true, 1901, gmdate('Y', time())), 'user_birthday' => array('date', true)));
                    // validate custom profile fields
                    $cp->submit_cp_field('profile', $user_row['iso_lang_id'], $cp_data, $cp_error);
                    if (sizeof($cp_error)) {
                        $error = array_merge($error, $cp_error);
                    }
                    if (!check_form_key($form_name)) {
                        $error[] = 'FORM_INVALID';
                    }
                    if (!sizeof($error)) {
                        $sql_ary = array('user_icq' => $data['icq'], 'user_aim' => $data['aim'], 'user_msnm' => $data['msn'], 'user_yim' => $data['yim'], 'user_jabber' => $data['jabber'], 'user_website' => $data['website'], 'user_from' => $data['location'], 'user_occ' => $data['occupation'], 'user_interests' => $data['interests'], 'user_birthday' => $data['user_birthday']);
                        $sql = 'UPDATE ' . USERS_TABLE . '
							SET ' . $db->sql_build_array('UPDATE', $sql_ary) . "\n\t\t\t\t\t\t\tWHERE user_id = {$user_id}";
                        $db->sql_query($sql);
                        // Update Custom Fields
                        $cp->update_profile_field_data($user_id, $cp_data);
                        trigger_error($user->lang['USER_PROFILE_UPDATED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
                    }
                    // Replace "error" strings with their real, localised form
                    $error = preg_replace('#^([A-Z_]+)$#e', "(!empty(\$user->lang['\\1'])) ? \$user->lang['\\1'] : '\\1'", $error);
                }
                $s_birthday_day_options = '<option value="0"' . (!$data['bday_day'] ? ' selected="selected"' : '') . '>--</option>';
                for ($i = 1; $i < 32; $i++) {
                    $selected = $i == $data['bday_day'] ? ' selected="selected"' : '';
                    $s_birthday_day_options .= "<option value=\"{$i}\"{$selected}>{$i}</option>";
                }
                $s_birthday_month_options = '<option value="0"' . (!$data['bday_month'] ? ' selected="selected"' : '') . '>--</option>';
                for ($i = 1; $i < 13; $i++) {
                    $selected = $i == $data['bday_month'] ? ' selected="selected"' : '';
                    $s_birthday_month_options .= "<option value=\"{$i}\"{$selected}>{$i}</option>";
                }
                $s_birthday_year_options = '';
                $now = getdate();
                $s_birthday_year_options = '<option value="0"' . (!$data['bday_year'] ? ' selected="selected"' : '') . '>--</option>';
                for ($i = $now['year'] - 100; $i <= $now['year']; $i++) {
                    $selected = $i == $data['bday_year'] ? ' selected="selected"' : '';
                    $s_birthday_year_options .= "<option value=\"{$i}\"{$selected}>{$i}</option>";
                }
                unset($now);
                $template->assign_vars(array('ICQ' => $data['icq'], 'YIM' => $data['yim'], 'AIM' => $data['aim'], 'MSN' => $data['msn'], 'JABBER' => $data['jabber'], 'WEBSITE' => $data['website'], 'LOCATION' => $data['location'], 'OCCUPATION' => $data['occupation'], 'INTERESTS' => $data['interests'], 'S_BIRTHDAY_DAY_OPTIONS' => $s_birthday_day_options, 'S_BIRTHDAY_MONTH_OPTIONS' => $s_birthday_month_options, 'S_BIRTHDAY_YEAR_OPTIONS' => $s_birthday_year_options, 'S_PROFILE' => true));
                // Get additional profile fields and assign them to the template block var 'profile_fields'
                $user->get_profile_fields($user_id);
                $cp->generate_profile_fields('profile', $user_row['iso_lang_id']);
                break;
            case 'prefs':
                include $phpbb_root_path . 'includes/functions_user.' . $phpEx;
                $data = array('dateformat' => utf8_normalize_nfc(request_var('dateformat', $user_row['user_dateformat'], true)), 'lang' => basename(request_var('lang', $user_row['user_lang'])), 'tz' => request_var('tz', (double) $user_row['user_timezone']), 'style' => request_var('style', $user_row['user_style']), 'dst' => request_var('dst', $user_row['user_dst']), 'viewemail' => request_var('viewemail', $user_row['user_allow_viewemail']), 'massemail' => request_var('massemail', $user_row['user_allow_massemail']), 'hideonline' => request_var('hideonline', !$user_row['user_allow_viewonline']), 'notifymethod' => request_var('notifymethod', $user_row['user_notify_type']), 'notifypm' => request_var('notifypm', $user_row['user_notify_pm']), 'popuppm' => request_var('popuppm', $this->optionget($user_row, 'popuppm')), 'allowpm' => request_var('allowpm', $user_row['user_allow_pm']), 'topic_sk' => request_var('topic_sk', $user_row['user_topic_sortby_type'] ? $user_row['user_topic_sortby_type'] : 't'), 'topic_sd' => request_var('topic_sd', $user_row['user_topic_sortby_dir'] ? $user_row['user_topic_sortby_dir'] : 'd'), 'topic_st' => request_var('topic_st', $user_row['user_topic_show_days'] ? $user_row['user_topic_show_days'] : 0), 'post_sk' => request_var('post_sk', $user_row['user_post_sortby_type'] ? $user_row['user_post_sortby_type'] : 't'), 'post_sd' => request_var('post_sd', $user_row['user_post_sortby_dir'] ? $user_row['user_post_sortby_dir'] : 'a'), 'post_st' => request_var('post_st', $user_row['user_post_show_days'] ? $user_row['user_post_show_days'] : 0), 'view_images' => request_var('view_images', $this->optionget($user_row, 'viewimg')), 'view_flash' => request_var('view_flash', $this->optionget($user_row, 'viewflash')), 'view_smilies' => request_var('view_smilies', $this->optionget($user_row, 'viewsmilies')), 'view_sigs' => request_var('view_sigs', $this->optionget($user_row, 'viewsigs')), 'view_avatars' => request_var('view_avatars', $this->optionget($user_row, 'viewavatars')), 'view_wordcensor' => request_var('view_wordcensor', $this->optionget($user_row, 'viewcensors')), 'bbcode' => request_var('bbcode', $this->optionget($user_row, 'bbcode')), 'smilies' => request_var('smilies', $this->optionget($user_row, 'smilies')), 'sig' => request_var('sig', $this->optionget($user_row, 'attachsig')), 'notify' => request_var('notify', $user_row['user_notify']));
                if ($submit) {
                    $error = validate_data($data, array('dateformat' => array('string', false, 1, 30), 'lang' => array('match', false, '#^[a-z_\\-]{2,}$#i'), 'tz' => array('num', false, -14, 14), 'topic_sk' => array('string', false, 1, 1), 'topic_sd' => array('string', false, 1, 1), 'post_sk' => array('string', false, 1, 1), 'post_sd' => array('string', false, 1, 1)));
                    if (!check_form_key($form_name)) {
                        $error[] = 'FORM_INVALID';
                    }
                    if (!sizeof($error)) {
                        $this->optionset($user_row, 'popuppm', $data['popuppm']);
                        $this->optionset($user_row, 'viewimg', $data['view_images']);
                        $this->optionset($user_row, 'viewflash', $data['view_flash']);
                        $this->optionset($user_row, 'viewsmilies', $data['view_smilies']);
                        $this->optionset($user_row, 'viewsigs', $data['view_sigs']);
                        $this->optionset($user_row, 'viewavatars', $data['view_avatars']);
                        $this->optionset($user_row, 'viewcensors', $data['view_wordcensor']);
                        $this->optionset($user_row, 'bbcode', $data['bbcode']);
                        $this->optionset($user_row, 'smilies', $data['smilies']);
                        $this->optionset($user_row, 'attachsig', $data['sig']);
                        $sql_ary = array('user_options' => $user_row['user_options'], 'user_allow_pm' => $data['allowpm'], 'user_allow_viewemail' => $data['viewemail'], 'user_allow_massemail' => $data['massemail'], 'user_allow_viewonline' => !$data['hideonline'], 'user_notify_type' => $data['notifymethod'], 'user_notify_pm' => $data['notifypm'], 'user_dst' => $data['dst'], 'user_dateformat' => $data['dateformat'], 'user_lang' => $data['lang'], 'user_timezone' => $data['tz'], 'user_style' => $data['style'], 'user_topic_sortby_type' => $data['topic_sk'], 'user_post_sortby_type' => $data['post_sk'], 'user_topic_sortby_dir' => $data['topic_sd'], 'user_post_sortby_dir' => $data['post_sd'], 'user_topic_show_days' => $data['topic_st'], 'user_post_show_days' => $data['post_st'], 'user_notify' => $data['notify']);
                        $sql = 'UPDATE ' . USERS_TABLE . '
							SET ' . $db->sql_build_array('UPDATE', $sql_ary) . "\n\t\t\t\t\t\t\tWHERE user_id = {$user_id}";
                        $db->sql_query($sql);
                        // Check if user has an active session
                        if ($user_row['session_id']) {
                            // We'll update the session if user_allow_viewonline has changed and the user is a bot
                            // Or if it's a regular user and the admin set it to hide the session
                            if ($user_row['user_allow_viewonline'] != $sql_ary['user_allow_viewonline'] && $user_row['user_type'] == USER_IGNORE || $user_row['user_allow_viewonline'] && !$sql_ary['user_allow_viewonline']) {
                                // We also need to check if the user has the permission to cloak.
                                $user_auth = new auth();
                                $user_auth->acl($user_row);
                                $session_sql_ary = array('session_viewonline' => $user_auth->acl_get('u_hideonline') ? $sql_ary['user_allow_viewonline'] : true);
                                $sql = 'UPDATE ' . SESSIONS_TABLE . '
									SET ' . $db->sql_build_array('UPDATE', $session_sql_ary) . "\n\t\t\t\t\t\t\t\t\tWHERE session_user_id = {$user_id}";
                                $db->sql_query($sql);
                                unset($user_auth);
                            }
                        }
                        trigger_error($user->lang['USER_PREFS_UPDATED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
                    }
                    // Replace "error" strings with their real, localised form
                    $error = preg_replace('#^([A-Z_]+)$#e', "(!empty(\$user->lang['\\1'])) ? \$user->lang['\\1'] : '\\1'", $error);
                }
                $dateformat_options = '';
                foreach ($user->lang['dateformats'] as $format => $null) {
                    $dateformat_options .= '<option value="' . $format . '"' . ($format == $data['dateformat'] ? ' selected="selected"' : '') . '>';
                    $dateformat_options .= $user->format_date(time(), $format, false) . (strpos($format, '|') !== false ? $user->lang['VARIANT_DATE_SEPARATOR'] . $user->format_date(time(), $format, true) : '');
                    $dateformat_options .= '</option>';
                }
                $s_custom = false;
                $dateformat_options .= '<option value="custom"';
                if (!isset($user->lang['dateformats'][$data['dateformat']])) {
                    $dateformat_options .= ' selected="selected"';
                    $s_custom = true;
                }
                $dateformat_options .= '>' . $user->lang['CUSTOM_DATEFORMAT'] . '</option>';
                $sort_dir_text = array('a' => $user->lang['ASCENDING'], 'd' => $user->lang['DESCENDING']);
                // Topic ordering options
                $limit_topic_days = array(0 => $user->lang['ALL_TOPICS'], 1 => $user->lang['1_DAY'], 7 => $user->lang['7_DAYS'], 14 => $user->lang['2_WEEKS'], 30 => $user->lang['1_MONTH'], 90 => $user->lang['3_MONTHS'], 180 => $user->lang['6_MONTHS'], 365 => $user->lang['1_YEAR']);
                $sort_by_topic_text = array('a' => $user->lang['AUTHOR'], 't' => $user->lang['POST_TIME'], 'r' => $user->lang['REPLIES'], 's' => $user->lang['SUBJECT'], 'v' => $user->lang['VIEWS']);
                // Post ordering options
                $limit_post_days = array(0 => $user->lang['ALL_POSTS'], 1 => $user->lang['1_DAY'], 7 => $user->lang['7_DAYS'], 14 => $user->lang['2_WEEKS'], 30 => $user->lang['1_MONTH'], 90 => $user->lang['3_MONTHS'], 180 => $user->lang['6_MONTHS'], 365 => $user->lang['1_YEAR']);
                $sort_by_post_text = array('a' => $user->lang['AUTHOR'], 't' => $user->lang['POST_TIME'], 's' => $user->lang['SUBJECT']);
                $_options = array('topic', 'post');
                foreach ($_options as $sort_option) {
                    ${'s_limit_' . $sort_option . '_days'} = '<select name="' . $sort_option . '_st">';
                    foreach (${'limit_' . $sort_option . '_days'} as $day => $text) {
                        $selected = $data[$sort_option . '_st'] == $day ? ' selected="selected"' : '';
                        ${'s_limit_' . $sort_option . '_days'} .= '<option value="' . $day . '"' . $selected . '>' . $text . '</option>';
                    }
                    ${'s_limit_' . $sort_option . '_days'} .= '</select>';
                    ${'s_sort_' . $sort_option . '_key'} = '<select name="' . $sort_option . '_sk">';
                    foreach (${'sort_by_' . $sort_option . '_text'} as $key => $text) {
                        $selected = $data[$sort_option . '_sk'] == $key ? ' selected="selected"' : '';
                        ${'s_sort_' . $sort_option . '_key'} .= '<option value="' . $key . '"' . $selected . '>' . $text . '</option>';
                    }
                    ${'s_sort_' . $sort_option . '_key'} .= '</select>';
                    ${'s_sort_' . $sort_option . '_dir'} = '<select name="' . $sort_option . '_sd">';
                    foreach ($sort_dir_text as $key => $value) {
                        $selected = $data[$sort_option . '_sd'] == $key ? ' selected="selected"' : '';
                        ${'s_sort_' . $sort_option . '_dir'} .= '<option value="' . $key . '"' . $selected . '>' . $value . '</option>';
                    }
                    ${'s_sort_' . $sort_option . '_dir'} .= '</select>';
                }
                $template->assign_vars(array('S_PREFS' => true, 'S_JABBER_DISABLED' => $config['jab_enable'] && $user_row['user_jabber'] && @extension_loaded('xml') ? false : true, 'VIEW_EMAIL' => $data['viewemail'], 'MASS_EMAIL' => $data['massemail'], 'ALLOW_PM' => $data['allowpm'], 'HIDE_ONLINE' => $data['hideonline'], 'NOTIFY_EMAIL' => $data['notifymethod'] == NOTIFY_EMAIL ? true : false, 'NOTIFY_IM' => $data['notifymethod'] == NOTIFY_IM ? true : false, 'NOTIFY_BOTH' => $data['notifymethod'] == NOTIFY_BOTH ? true : false, 'NOTIFY_PM' => $data['notifypm'], 'POPUP_PM' => $data['popuppm'], 'DST' => $data['dst'], 'BBCODE' => $data['bbcode'], 'SMILIES' => $data['smilies'], 'ATTACH_SIG' => $data['sig'], 'NOTIFY' => $data['notify'], 'VIEW_IMAGES' => $data['view_images'], 'VIEW_FLASH' => $data['view_flash'], 'VIEW_SMILIES' => $data['view_smilies'], 'VIEW_SIGS' => $data['view_sigs'], 'VIEW_AVATARS' => $data['view_avatars'], 'VIEW_WORDCENSOR' => $data['view_wordcensor'], 'S_TOPIC_SORT_DAYS' => $s_limit_topic_days, 'S_TOPIC_SORT_KEY' => $s_sort_topic_key, 'S_TOPIC_SORT_DIR' => $s_sort_topic_dir, 'S_POST_SORT_DAYS' => $s_limit_post_days, 'S_POST_SORT_KEY' => $s_sort_post_key, 'S_POST_SORT_DIR' => $s_sort_post_dir, 'DATE_FORMAT' => $data['dateformat'], 'S_DATEFORMAT_OPTIONS' => $dateformat_options, 'S_CUSTOM_DATEFORMAT' => $s_custom, 'DEFAULT_DATEFORMAT' => $config['default_dateformat'], 'A_DEFAULT_DATEFORMAT' => addslashes($config['default_dateformat']), 'S_LANG_OPTIONS' => language_select($data['lang']), 'S_STYLE_OPTIONS' => style_select($data['style']), 'S_TZ_OPTIONS' => tz_select($data['tz'], true)));
                break;
            case 'avatar':
                include $phpbb_root_path . 'includes/functions_display.' . $phpEx;
                include $phpbb_root_path . 'includes/functions_user.' . $phpEx;
                $can_upload = file_exists($phpbb_root_path . $config['avatar_path']) && phpbb_is_writable($phpbb_root_path . $config['avatar_path']) && $file_uploads ? true : false;
                if ($submit) {
                    if (!check_form_key($form_name)) {
                        trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
                    }
                    if (avatar_process_user($error, $user_row, $can_upload)) {
                        trigger_error($user->lang['USER_AVATAR_UPDATED'] . adm_back_link($this->u_action . '&amp;u=' . $user_row['user_id']));
                    }
                    // Replace "error" strings with their real, localised form
                    $error = preg_replace('#^([A-Z_]+)$#e', "(!empty(\$user->lang['\\1'])) ? \$user->lang['\\1'] : '\\1'", $error);
                }
                if (!$config['allow_avatar'] && $user_row['user_avatar_type']) {
                    $error[] = $user->lang['USER_AVATAR_NOT_ALLOWED'];
                } else {
                    if ($user_row['user_avatar_type'] == AVATAR_UPLOAD && !$config['allow_avatar_upload'] || $user_row['user_avatar_type'] == AVATAR_REMOTE && !$config['allow_avatar_remote'] || $user_row['user_avatar_type'] == AVATAR_GALLERY && !$config['allow_avatar_local']) {
                        $error[] = $user->lang['USER_AVATAR_TYPE_NOT_ALLOWED'];
                    }
                }
                // Generate users avatar
                $avatar_img = $user_row['user_avatar'] ? get_user_avatar($user_row['user_avatar'], $user_row['user_avatar_type'], $user_row['user_avatar_width'], $user_row['user_avatar_height'], 'USER_AVATAR', true) : '<img src="' . $phpbb_admin_path . 'images/no_avatar.gif" alt="" />';
                $display_gallery = isset($_POST['display_gallery']) ? true : false;
                $avatar_select = basename(request_var('avatar_select', ''));
                $category = basename(request_var('category', ''));
                if ($config['allow_avatar_local'] && $display_gallery) {
                    avatar_gallery($category, $avatar_select, 4);
                }
                $template->assign_vars(array('S_AVATAR' => true, 'S_CAN_UPLOAD' => $can_upload, 'S_UPLOAD_FILE' => $config['allow_avatar'] && $can_upload && $config['allow_avatar_upload'] ? true : false, 'S_REMOTE_UPLOAD' => $config['allow_avatar'] && $can_upload && $config['allow_avatar_remote_upload'] ? true : false, 'S_ALLOW_REMOTE' => $config['allow_avatar'] && $config['allow_avatar_remote'] ? true : false, 'S_DISPLAY_GALLERY' => $config['allow_avatar'] && $config['allow_avatar_local'] && !$display_gallery ? true : false, 'S_IN_GALLERY' => $config['allow_avatar'] && $config['allow_avatar_local'] && $display_gallery ? true : false, 'AVATAR_IMAGE' => $avatar_img, 'AVATAR_MAX_FILESIZE' => $config['avatar_filesize'], 'USER_AVATAR_WIDTH' => $user_row['user_avatar_width'], 'USER_AVATAR_HEIGHT' => $user_row['user_avatar_height'], 'L_AVATAR_EXPLAIN' => sprintf($user->lang['AVATAR_EXPLAIN'], $config['avatar_max_width'], $config['avatar_max_height'], round($config['avatar_filesize'] / 1024))));
                break;
            case 'rank':
                if ($submit) {
                    if (!check_form_key($form_name)) {
                        trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
                    }
                    $rank_id = request_var('user_rank', 0);
                    $sql = 'UPDATE ' . USERS_TABLE . "\n\t\t\t\t\t\tSET user_rank = {$rank_id}\n\t\t\t\t\t\tWHERE user_id = {$user_id}";
                    $db->sql_query($sql);
                    trigger_error($user->lang['USER_RANK_UPDATED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
                }
                $sql = 'SELECT *
					FROM ' . RANKS_TABLE . '
					WHERE rank_special = 1
					ORDER BY rank_title';
                $result = $db->sql_query($sql);
                $s_rank_options = '<option value="0"' . (!$user_row['user_rank'] ? ' selected="selected"' : '') . '>' . $user->lang['NO_SPECIAL_RANK'] . '</option>';
                while ($row = $db->sql_fetchrow($result)) {
                    $selected = $user_row['user_rank'] && $row['rank_id'] == $user_row['user_rank'] ? ' selected="selected"' : '';
                    $s_rank_options .= '<option value="' . $row['rank_id'] . '"' . $selected . '>' . $row['rank_title'] . '</option>';
                }
                $db->sql_freeresult($result);
                $template->assign_vars(array('S_RANK' => true, 'S_RANK_OPTIONS' => $s_rank_options));
                break;
            case 'sig':
                include_once $phpbb_root_path . 'includes/functions_posting.' . $phpEx;
                include_once $phpbb_root_path . 'includes/functions_display.' . $phpEx;
                $enable_bbcode = $config['allow_sig_bbcode'] ? (bool) $this->optionget($user_row, 'sig_bbcode') : false;
                $enable_smilies = $config['allow_sig_smilies'] ? (bool) $this->optionget($user_row, 'sig_smilies') : false;
                $enable_urls = $config['allow_sig_links'] ? (bool) $this->optionget($user_row, 'sig_links') : false;
                $signature = utf8_normalize_nfc(request_var('signature', (string) $user_row['user_sig'], true));
                $preview = isset($_POST['preview']) ? true : false;
                if ($submit || $preview) {
                    include_once $phpbb_root_path . 'includes/message_parser.' . $phpEx;
                    $enable_bbcode = $config['allow_sig_bbcode'] ? request_var('disable_bbcode', false) ? false : true : false;
                    $enable_smilies = $config['allow_sig_smilies'] ? request_var('disable_smilies', false) ? false : true : false;
                    $enable_urls = $config['allow_sig_links'] ? request_var('disable_magic_url', false) ? false : true : false;
                    $message_parser = new parse_message($signature);
                    // Allowing Quote BBCode
                    $message_parser->parse($enable_bbcode, $enable_urls, $enable_smilies, $config['allow_sig_img'], $config['allow_sig_flash'], true, $config['allow_sig_links'], true, 'sig');
                    if (sizeof($message_parser->warn_msg)) {
                        $error[] = implode('<br />', $message_parser->warn_msg);
                    }
                    if (!check_form_key($form_name)) {
                        $error = 'FORM_INVALID';
                    }
                    if (!sizeof($error) && $submit) {
                        $this->optionset($user_row, 'sig_bbcode', $enable_bbcode);
                        $this->optionset($user_row, 'sig_smilies', $enable_smilies);
                        $this->optionset($user_row, 'sig_links', $enable_urls);
                        $sql_ary = array('user_sig' => (string) $message_parser->message, 'user_options' => $user_row['user_options'], 'user_sig_bbcode_uid' => (string) $message_parser->bbcode_uid, 'user_sig_bbcode_bitfield' => (string) $message_parser->bbcode_bitfield);
                        $sql = 'UPDATE ' . USERS_TABLE . '
							SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
							WHERE user_id = ' . $user_id;
                        $db->sql_query($sql);
                        trigger_error($user->lang['USER_SIG_UPDATED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
                    }
                    // Replace "error" strings with their real, localised form
                    $error = preg_replace('#^([A-Z_]+)$#e', "(!empty(\$user->lang['\\1'])) ? \$user->lang['\\1'] : '\\1'", $error);
                }
                $signature_preview = '';
                if ($preview) {
                    // Now parse it for displaying
                    $signature_preview = $message_parser->format_display($enable_bbcode, $enable_urls, $enable_smilies, false);
                    unset($message_parser);
                }
                decode_message($signature, $user_row['user_sig_bbcode_uid']);
                $template->assign_vars(array('S_SIGNATURE' => true, 'SIGNATURE' => $signature, 'SIGNATURE_PREVIEW' => $signature_preview, 'S_BBCODE_CHECKED' => !$enable_bbcode ? ' checked="checked"' : '', 'S_SMILIES_CHECKED' => !$enable_smilies ? ' checked="checked"' : '', 'S_MAGIC_URL_CHECKED' => !$enable_urls ? ' checked="checked"' : '', 'BBCODE_STATUS' => $config['allow_sig_bbcode'] ? sprintf($user->lang['BBCODE_IS_ON'], '<a href="' . append_sid("{$phpbb_root_path}faq.{$phpEx}", 'mode=bbcode') . '">', '</a>') : sprintf($user->lang['BBCODE_IS_OFF'], '<a href="' . append_sid("{$phpbb_root_path}faq.{$phpEx}", 'mode=bbcode') . '">', '</a>'), 'SMILIES_STATUS' => $config['allow_sig_smilies'] ? $user->lang['SMILIES_ARE_ON'] : $user->lang['SMILIES_ARE_OFF'], 'IMG_STATUS' => $config['allow_sig_img'] ? $user->lang['IMAGES_ARE_ON'] : $user->lang['IMAGES_ARE_OFF'], 'FLASH_STATUS' => $config['allow_sig_flash'] ? $user->lang['FLASH_IS_ON'] : $user->lang['FLASH_IS_OFF'], 'URL_STATUS' => $config['allow_sig_links'] ? $user->lang['URL_IS_ON'] : $user->lang['URL_IS_OFF'], 'L_SIGNATURE_EXPLAIN' => sprintf($user->lang['SIGNATURE_EXPLAIN'], $config['max_sig_chars']), 'S_BBCODE_ALLOWED' => $config['allow_sig_bbcode'], 'S_SMILIES_ALLOWED' => $config['allow_sig_smilies'], 'S_BBCODE_IMG' => $config['allow_sig_img'] ? true : false, 'S_BBCODE_FLASH' => $config['allow_sig_flash'] ? true : false, 'S_LINKS_ALLOWED' => $config['allow_sig_links'] ? true : false));
                // Assigning custom bbcodes
                display_custom_bbcodes();
                break;
            case 'attach':
                $start = request_var('start', 0);
                $deletemark = isset($_POST['delmarked']) ? true : false;
                $marked = request_var('mark', array(0));
                // Sort keys
                $sort_key = request_var('sk', 'a');
                $sort_dir = request_var('sd', 'd');
                if ($deletemark && sizeof($marked)) {
                    $sql = 'SELECT attach_id
						FROM ' . ATTACHMENTS_TABLE . '
						WHERE poster_id = ' . $user_id . '
							AND is_orphan = 0
							AND ' . $db->sql_in_set('attach_id', $marked);
                    $result = $db->sql_query($sql);
                    $marked = array();
                    while ($row = $db->sql_fetchrow($result)) {
                        $marked[] = $row['attach_id'];
                    }
                    $db->sql_freeresult($result);
                }
                if ($deletemark && sizeof($marked)) {
                    if (confirm_box(true)) {
                        $sql = 'SELECT real_filename
							FROM ' . ATTACHMENTS_TABLE . '
							WHERE ' . $db->sql_in_set('attach_id', $marked);
                        $result = $db->sql_query($sql);
                        $log_attachments = array();
                        while ($row = $db->sql_fetchrow($result)) {
                            $log_attachments[] = $row['real_filename'];
                        }
                        $db->sql_freeresult($result);
                        delete_attachments('attach', $marked);
                        $message = sizeof($log_attachments) == 1 ? $user->lang['ATTACHMENT_DELETED'] : $user->lang['ATTACHMENTS_DELETED'];
                        add_log('admin', 'LOG_ATTACHMENTS_DELETED', implode(', ', $log_attachments));
                        trigger_error($message . adm_back_link($this->u_action . '&amp;u=' . $user_id));
                    } else {
                        confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array('u' => $user_id, 'i' => $id, 'mode' => $mode, 'action' => $action, 'delmarked' => true, 'mark' => $marked)));
                    }
                }
                $sk_text = array('a' => $user->lang['SORT_FILENAME'], 'c' => $user->lang['SORT_EXTENSION'], 'd' => $user->lang['SORT_SIZE'], 'e' => $user->lang['SORT_DOWNLOADS'], 'f' => $user->lang['SORT_POST_TIME'], 'g' => $user->lang['SORT_TOPIC_TITLE']);
                $sk_sql = array('a' => 'a.real_filename', 'c' => 'a.extension', 'd' => 'a.filesize', 'e' => 'a.download_count', 'f' => 'a.filetime', 'g' => 't.topic_title');
                $sd_text = array('a' => $user->lang['ASCENDING'], 'd' => $user->lang['DESCENDING']);
                $s_sort_key = '';
                foreach ($sk_text as $key => $value) {
                    $selected = $sort_key == $key ? ' selected="selected"' : '';
                    $s_sort_key .= '<option value="' . $key . '"' . $selected . '>' . $value . '</option>';
                }
                $s_sort_dir = '';
                foreach ($sd_text as $key => $value) {
                    $selected = $sort_dir == $key ? ' selected="selected"' : '';
                    $s_sort_dir .= '<option value="' . $key . '"' . $selected . '>' . $value . '</option>';
                }
                if (!isset($sk_sql[$sort_key])) {
                    $sort_key = 'a';
                }
                $order_by = $sk_sql[$sort_key] . ' ' . ($sort_dir == 'a' ? 'ASC' : 'DESC');
                $sql = 'SELECT COUNT(attach_id) as num_attachments
					FROM ' . ATTACHMENTS_TABLE . "\n\t\t\t\t\tWHERE poster_id = {$user_id}\n\t\t\t\t\t\tAND is_orphan = 0";
                $result = $db->sql_query_limit($sql, 1);
                $num_attachments = (int) $db->sql_fetchfield('num_attachments');
                $db->sql_freeresult($result);
                $sql = 'SELECT a.*, t.topic_title, p.message_subject as message_title
					FROM ' . ATTACHMENTS_TABLE . ' a
						LEFT JOIN ' . TOPICS_TABLE . ' t ON (a.topic_id = t.topic_id
							AND a.in_message = 0)
						LEFT JOIN ' . PRIVMSGS_TABLE . ' p ON (a.post_msg_id = p.msg_id
							AND a.in_message = 1)
					WHERE a.poster_id = ' . $user_id . "\n\t\t\t\t\t\tAND a.is_orphan = 0\n\t\t\t\t\tORDER BY {$order_by}";
                $result = $db->sql_query_limit($sql, $config['posts_per_page'], $start);
                while ($row = $db->sql_fetchrow($result)) {
                    if ($row['in_message']) {
                        $view_topic = append_sid("{$phpbb_root_path}ucp.{$phpEx}", "i=pm&amp;p={$row['post_msg_id']}");
                    } else {
                        $view_topic = append_sid("{$phpbb_root_path}viewtopic.{$phpEx}", "t={$row['topic_id']}&amp;p={$row['post_msg_id']}") . '#p' . $row['post_msg_id'];
                    }
                    $template->assign_block_vars('attach', array('REAL_FILENAME' => $row['real_filename'], 'COMMENT' => nl2br($row['attach_comment']), 'EXTENSION' => $row['extension'], 'SIZE' => get_formatted_filesize($row['filesize']), 'DOWNLOAD_COUNT' => $row['download_count'], 'POST_TIME' => $user->format_date($row['filetime']), 'TOPIC_TITLE' => $row['in_message'] ? $row['message_title'] : $row['topic_title'], 'ATTACH_ID' => $row['attach_id'], 'POST_ID' => $row['post_msg_id'], 'TOPIC_ID' => $row['topic_id'], 'S_IN_MESSAGE' => $row['in_message'], 'U_DOWNLOAD' => append_sid("{$phpbb_root_path}download/file.{$phpEx}", 'mode=view&amp;id=' . $row['attach_id']), 'U_VIEW_TOPIC' => $view_topic));
                }
                $db->sql_freeresult($result);
                $template->assign_vars(array('S_ATTACHMENTS' => true, 'S_ON_PAGE' => on_page($num_attachments, $config['topics_per_page'], $start), 'S_SORT_KEY' => $s_sort_key, 'S_SORT_DIR' => $s_sort_dir, 'PAGINATION' => generate_pagination($this->u_action . "&amp;u={$user_id}&amp;sk={$sort_key}&amp;sd={$sort_dir}", $num_attachments, $config['topics_per_page'], $start, true)));
                break;
            case 'groups':
                include $phpbb_root_path . 'includes/functions_user.' . $phpEx;
                $user->add_lang(array('groups', 'acp/groups'));
                $group_id = request_var('g', 0);
                if ($group_id) {
                    // Check the founder only entry for this group to make sure everything is well
                    $sql = 'SELECT group_founder_manage
						FROM ' . GROUPS_TABLE . '
						WHERE group_id = ' . $group_id;
                    $result = $db->sql_query($sql);
                    $founder_manage = (int) $db->sql_fetchfield('group_founder_manage');
                    $db->sql_freeresult($result);
                    if ($user->data['user_type'] != USER_FOUNDER && $founder_manage) {
                        trigger_error($user->lang['NOT_ALLOWED_MANAGE_GROUP'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
                    }
                } else {
                    $founder_manage = 0;
                }
                switch ($action) {
                    case 'demote':
                    case 'promote':
                    case 'default':
                        if (!$group_id) {
                            trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
                        }
                        group_user_attributes($action, $group_id, $user_id);
                        if ($action == 'default') {
                            $user_row['group_id'] = $group_id;
                        }
                        break;
                    case 'delete':
                        if (confirm_box(true)) {
                            if (!$group_id) {
                                trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
                            }
                            if ($error = group_user_del($group_id, $user_id)) {
                                trigger_error($user->lang[$error] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
                            }
                            $error = array();
                            // The delete action was successful - therefore update the user row...
                            $sql = 'SELECT u.*, s.*
								FROM ' . USERS_TABLE . ' u
									LEFT JOIN ' . SESSIONS_TABLE . ' s ON (s.session_user_id = u.user_id)
								WHERE u.user_id = ' . $user_id . '
								ORDER BY s.session_time DESC';
                            $result = $db->sql_query_limit($sql, 1);
                            $user_row = $db->sql_fetchrow($result);
                            $db->sql_freeresult($result);
                        } else {
                            confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array('u' => $user_id, 'i' => $id, 'mode' => $mode, 'action' => $action, 'g' => $group_id)));
                        }
                        break;
                    case 'approve':
                        if (confirm_box(true)) {
                            if (!$group_id) {
                                trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
                            }
                            group_user_attributes($action, $group_id, $user_id);
                        } else {
                            confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array('u' => $user_id, 'i' => $id, 'mode' => $mode, 'action' => $action, 'g' => $group_id)));
                        }
                        break;
                }
                // Add user to group?
                if ($submit) {
                    if (!check_form_key($form_name)) {
                        trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
                    }
                    if (!$group_id) {
                        trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
                    }
                    // Add user/s to group
                    if ($error = group_user_add($group_id, $user_id)) {
                        trigger_error($user->lang[$error] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
                    }
                    $error = array();
                }
                $sql = 'SELECT ug.*, g.*
					FROM ' . GROUPS_TABLE . ' g, ' . USER_GROUP_TABLE . " ug\n\t\t\t\t\tWHERE ug.user_id = {$user_id}\n\t\t\t\t\t\tAND g.group_id = ug.group_id\n\t\t\t\t\tORDER BY g.group_type DESC, ug.user_pending ASC, g.group_name";
                $result = $db->sql_query($sql);
                $i = 0;
                $group_data = $id_ary = array();
                while ($row = $db->sql_fetchrow($result)) {
                    $type = $row['group_type'] == GROUP_SPECIAL ? 'special' : ($row['user_pending'] ? 'pending' : 'normal');
                    $group_data[$type][$i]['group_id'] = $row['group_id'];
                    $group_data[$type][$i]['group_name'] = $row['group_name'];
                    $group_data[$type][$i]['group_leader'] = $row['group_leader'] ? 1 : 0;
                    $id_ary[] = $row['group_id'];
                    $i++;
                }
                $db->sql_freeresult($result);
                // Select box for other groups
                $sql = 'SELECT group_id, group_name, group_type, group_founder_manage
					FROM ' . GROUPS_TABLE . '
					' . (sizeof($id_ary) ? 'WHERE ' . $db->sql_in_set('group_id', $id_ary, true) : '') . '
					ORDER BY group_type DESC, group_name ASC';
                $result = $db->sql_query($sql);
                $s_group_options = '';
                while ($row = $db->sql_fetchrow($result)) {
                    if (!$config['coppa_enable'] && $row['group_name'] == 'REGISTERED_COPPA') {
                        continue;
                    }
                    // Do not display those groups not allowed to be managed
                    if ($user->data['user_type'] != USER_FOUNDER && $row['group_founder_manage']) {
                        continue;
                    }
                    $s_group_options .= '<option' . ($row['group_type'] == GROUP_SPECIAL ? ' class="sep"' : '') . ' value="' . $row['group_id'] . '">' . ($row['group_type'] == GROUP_SPECIAL ? $user->lang['G_' . $row['group_name']] : $row['group_name']) . '</option>';
                }
                $db->sql_freeresult($result);
                $current_type = '';
                foreach ($group_data as $group_type => $data_ary) {
                    if ($current_type != $group_type) {
                        $template->assign_block_vars('group', array('S_NEW_GROUP_TYPE' => true, 'GROUP_TYPE' => $user->lang['USER_GROUP_' . strtoupper($group_type)]));
                    }
                    foreach ($data_ary as $data) {
                        $template->assign_block_vars('group', array('U_EDIT_GROUP' => append_sid("{$phpbb_admin_path}index.{$phpEx}", "i=groups&amp;mode=manage&amp;action=edit&amp;u={$user_id}&amp;g={$data['group_id']}&amp;back_link=acp_users_groups"), 'U_DEFAULT' => $this->u_action . "&amp;action=default&amp;u={$user_id}&amp;g=" . $data['group_id'], 'U_DEMOTE_PROMOTE' => $this->u_action . '&amp;action=' . ($data['group_leader'] ? 'demote' : 'promote') . "&amp;u={$user_id}&amp;g=" . $data['group_id'], 'U_DELETE' => $this->u_action . "&amp;action=delete&amp;u={$user_id}&amp;g=" . $data['group_id'], 'U_APPROVE' => $group_type == 'pending' ? $this->u_action . "&amp;action=approve&amp;u={$user_id}&amp;g=" . $data['group_id'] : '', 'GROUP_NAME' => $group_type == 'special' ? $user->lang['G_' . $data['group_name']] : $data['group_name'], 'L_DEMOTE_PROMOTE' => $data['group_leader'] ? $user->lang['GROUP_DEMOTE'] : $user->lang['GROUP_PROMOTE'], 'S_IS_MEMBER' => $group_type != 'pending' ? true : false, 'S_NO_DEFAULT' => $user_row['group_id'] != $data['group_id'] ? true : false, 'S_SPECIAL_GROUP' => $group_type == 'special' ? true : false));
                    }
                }
                $template->assign_vars(array('S_GROUPS' => true, 'S_GROUP_OPTIONS' => $s_group_options));
                break;
            case 'perm':
                include_once $phpbb_root_path . 'includes/acp/auth.' . $phpEx;
                $auth_admin = new auth_admin();
                $user->add_lang('acp/permissions');
                add_permission_language();
                $forum_id = request_var('f', 0);
                // Global Permissions
                if (!$forum_id) {
                    // Select auth options
                    $sql = 'SELECT auth_option, is_local, is_global
						FROM ' . ACL_OPTIONS_TABLE . '
						WHERE auth_option ' . $db->sql_like_expression($db->any_char . '_') . '
							AND is_global = 1
						ORDER BY auth_option';
                    $result = $db->sql_query($sql);
                    $hold_ary = array();
                    while ($row = $db->sql_fetchrow($result)) {
                        $hold_ary = $auth_admin->get_mask('view', $user_id, false, false, $row['auth_option'], 'global', ACL_NEVER);
                        $auth_admin->display_mask('view', $row['auth_option'], $hold_ary, 'user', false, false);
                    }
                    $db->sql_freeresult($result);
                    unset($hold_ary);
                } else {
                    $sql = 'SELECT auth_option, is_local, is_global
						FROM ' . ACL_OPTIONS_TABLE . "\n\t\t\t\t\t\tWHERE auth_option " . $db->sql_like_expression($db->any_char . '_') . "\n\t\t\t\t\t\t\tAND is_local = 1\n\t\t\t\t\t\tORDER BY is_global DESC, auth_option";
                    $result = $db->sql_query($sql);
                    while ($row = $db->sql_fetchrow($result)) {
                        $hold_ary = $auth_admin->get_mask('view', $user_id, false, $forum_id, $row['auth_option'], 'local', ACL_NEVER);
                        $auth_admin->display_mask('view', $row['auth_option'], $hold_ary, 'user', true, false);
                    }
                    $db->sql_freeresult($result);
                }
                $s_forum_options = '<option value="0"' . (!$forum_id ? ' selected="selected"' : '') . '>' . $user->lang['VIEW_GLOBAL_PERMS'] . '</option>';
                $s_forum_options .= make_forum_select($forum_id, false, true, false, false, false);
                $template->assign_vars(array('S_PERMISSIONS' => true, 'S_GLOBAL' => !$forum_id ? true : false, 'S_FORUM_OPTIONS' => $s_forum_options, 'U_ACTION' => $this->u_action . '&amp;u=' . $user_id, 'U_USER_PERMISSIONS' => append_sid("{$phpbb_admin_path}index.{$phpEx}", 'i=permissions&amp;mode=setting_user_global&amp;user_id[]=' . $user_id), 'U_USER_FORUM_PERMISSIONS' => append_sid("{$phpbb_admin_path}index.{$phpEx}", 'i=permissions&amp;mode=setting_user_local&amp;user_id[]=' . $user_id)));
                break;
        }
        // Assign general variables
        $template->assign_vars(array('S_ERROR' => sizeof($error) ? true : false, 'ERROR_MSG' => sizeof($error) ? implode('<br />', $error) : ''));
    }
Example #7
0
 /**
  * Sends user(s) notification via PM
  *
  */
 private function send_pm($to_id)
 {
     global $phpbb_root_path, $phpEx, $user;
     if (!class_exists('parse_message')) {
         include $phpbb_root_path . 'includes/message_parser.' . $phpEx;
     }
     if (!function_exists('submit_pm')) {
         include $phpbb_root_path . 'includes/functions_privmsgs.' . $phpEx;
     }
     // Setup the PM message parser.
     $message_parser = new parse_message();
     $message_parser->message = $this->message_text;
     $message_parser->parse(true, true, true, true, true, true, true);
     // setup the PM data...
     $pm_data = array('from_user_id' => 2, 'from_username' => 'Site Notifications', 'address_list' => array('u' => array($to_id => 'to')), 'icon_id' => 0, 'from_user_ip' => $user->ip, 'enable_bbcode' => true, 'enable_smilies' => true, 'enable_urls' => true, 'enable_sig' => false, 'message' => $message_parser->message, 'bbcode_bitfield' => $message_parser->bbcode_bitfield, 'bbcode_uid' => $message_parser->bbcode_uid);
     // Send the PM to the founders.
     submit_pm('post', $this->message_title, $pm_data, false);
 }
Example #8
0
 public function prepare_text_for_merge(&$data)
 {
     // Create message parser instance
     include_once $this->phpbb_root_path . 'includes/message_parser.' . $this->php_ext;
     $message_parser = new \parse_message();
     $text = isset($data['post_text']) ? $data['post_text'] : $data['message'];
     $message_parser->message = $text;
     // Decode message text properly
     $message_parser->decode_message($data['bbcode_uid']);
     $text = html_entity_decode($message_parser->message, ENT_COMPAT, 'UTF-8');
     return $text;
 }
Example #9
0
/**
* Insert the warning into the database
*/
function add_warning($user_row, $warning, $send_pm = true, $post_id = 0)
{
	global $phpEx, $phpbb_root_path, $config;
	global $template, $db, $user, $auth;

	if ($send_pm)
	{
		include_once($phpbb_root_path . 'includes/functions_privmsgs.' . $phpEx);
		include_once($phpbb_root_path . 'includes/message_parser.' . $phpEx);

		$user_row['user_lang'] = (file_exists($phpbb_root_path . 'language/' . $user_row['user_lang'] . "/mcp.$phpEx")) ? $user_row['user_lang'] : $config['default_lang'];
		include($phpbb_root_path . 'language/' . basename($user_row['user_lang']) . "/mcp.$phpEx");

		$message_parser = new parse_message();

		$message_parser->message = sprintf($lang['WARNING_PM_BODY'], $warning);
		$message_parser->parse(true, true, true, false, false, true, true);

		$pm_data = array(
			'from_user_id'			=> $user->data['user_id'],
			'from_user_ip'			=> $user->ip,
			'from_username'			=> $user->data['username'],
			'enable_sig'			=> false,
			'enable_bbcode'			=> true,
			'enable_smilies'		=> true,
			'enable_urls'			=> false,
			'icon_id'				=> 0,
			'bbcode_bitfield'		=> $message_parser->bbcode_bitfield,
			'bbcode_uid'			=> $message_parser->bbcode_uid,
			'message'				=> $message_parser->message,
			'address_list'			=> array('u' => array($user_row['user_id'] => 'to')),
		);

		submit_pm('post', $lang['WARNING_PM_SUBJECT'], $pm_data, false);
	}

	add_log('admin', 'LOG_USER_WARNING', $user_row['username']);
	$log_id = add_log('user', $user_row['user_id'], 'LOG_USER_WARNING_BODY', $warning);

	$sql_ary = array(
		'user_id'		=> $user_row['user_id'],
		'post_id'		=> $post_id,
		'log_id'		=> $log_id,
		'warning_time'	=> time(),
	);

	$db->sql_query('INSERT INTO ' . WARNINGS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary));

	$sql = 'UPDATE ' . USERS_TABLE . '
		SET user_warnings = user_warnings + 1,
			user_last_warning = ' . time() . '
		WHERE user_id = ' . $user_row['user_id'];
	$db->sql_query($sql);

	// We add this to the mod log too for moderators to see that a specific user got warned.
	$sql = 'SELECT forum_id, topic_id
		FROM ' . POSTS_TABLE . '
		WHERE post_id = ' . $post_id;
	$result = $db->sql_query($sql);
	$row = $db->sql_fetchrow($result);
	$db->sql_freeresult($result);

	add_log('mod', $row['forum_id'], $row['topic_id'], 'LOG_USER_WARNING', $user_row['username']);
}
function create_message_func($xmlrpc_params)
{
    global $db, $user, $auth, $config, $phpbb_root_path, $phpEx;
    $user->setup('ucp');
    include_once $phpbb_root_path . 'includes/functions_privmsgs.' . $phpEx;
    include_once $phpbb_root_path . 'includes/ucp/ucp_pm_compose.' . $phpEx;
    if (!$user->data['is_registered']) {
        trigger_error('LOGIN_EXPLAIN_UCP');
    }
    if (!$config['allow_privmsg']) {
        trigger_error('Module not accessible');
    }
    // Flood check
    $current_time = time();
    $last_post_time = $user->data['user_lastpost_time'];
    if ($last_post_time && $current_time - $last_post_time < intval($config['flood_interval'])) {
        trigger_error('FLOOD_ERROR');
    }
    $params = php_xmlrpc_decode($xmlrpc_params);
    if (!is_array($params[0]) || empty($params[0]) || !isset($params[1]) || utf8_clean_string($params[1]) === '' || !isset($params[2])) {
        trigger_error('Required paramerter missing');
    } else {
        $user_name = $params[0];
        $_REQUEST['subject'] = $params[1];
        $_REQUEST['message'] = $params[2];
        $subject = utf8_normalize_nfc(request_var('subject', '', true));
        $text_body = utf8_normalize_nfc(request_var('message', '', true));
        require_once 'include/emoji.php';
        $text_body = emoji_unified_to_names($text_body);
    }
    $action = 'post';
    // default action
    if (isset($params[3])) {
        if ($params[3] == 1) {
            $action = 'reply';
            $msg_id = intval($params[4]);
        } else {
            if ($params[3] == 2) {
                $action = 'forword';
                $msg_id = intval($params[4]);
            }
        }
        if (!$msg_id) {
            trigger_error('NO_MESSAGE');
        }
    }
    if (($action == 'post' || $action == 'reply') && !$auth->acl_get('u_sendpm')) {
        trigger_error('NO_AUTH_SEND_MESSAGE');
    }
    if ($action == 'forward' && (!$config['forward_pm'] || !$auth->acl_get('u_pm_forward'))) {
        trigger_error('NO_AUTH_FORWARD_MESSAGE');
    }
    // Do NOT use request_var or specialchars here
    $address_list = array('u' => array());
    foreach ($user_name as $msg_to_name) {
        $user_id = get_user_id_by_name(trim($msg_to_name));
        if ($user_id) {
            $address_list['u'][$user_id] = 'to';
        } else {
            trigger_error('PM_NO_USERS');
        }
    }
    $sql = '';
    // What is all this following SQL for? Well, we need to know
    // some basic information in all cases before we do anything.
    if ($action != 'post') {
        $sql = 'SELECT t.folder_id, p.*, u.username as quote_username
                FROM ' . PRIVMSGS_TO_TABLE . ' t, ' . PRIVMSGS_TABLE . ' p, ' . USERS_TABLE . ' u
                WHERE t.user_id = ' . $user->data['user_id'] . "\n                AND p.author_id = u.user_id\n                AND t.msg_id = p.msg_id\n                AND p.msg_id = {$msg_id}";
    }
    if ($sql) {
        $result = $db->sql_query($sql);
        $post = $db->sql_fetchrow($result);
        $db->sql_freeresult($result);
        if (!$post) {
            trigger_error('NO_MESSAGE');
        }
        if (!$post['author_id'] || $post['author_id'] == ANONYMOUS) {
            trigger_error('NO_AUTHOR');
        }
    }
    include $phpbb_root_path . 'includes/message_parser.' . $phpEx;
    $message_parser = new parse_message();
    // Get maximum number of allowed recipients
    if ($config['version'] > '3.0.3') {
        $sql = 'SELECT MAX(g.group_max_recipients) as max_recipients
        FROM ' . GROUPS_TABLE . ' g, ' . USER_GROUP_TABLE . ' ug
        WHERE ug.user_id = ' . $user->data['user_id'] . '
            AND ug.user_pending = 0
            AND ug.group_id = g.group_id';
        $result = $db->sql_query($sql);
        $max_recipients = (int) $db->sql_fetchfield('max_recipients');
        $db->sql_freeresult($result);
        $max_recipients = !$max_recipients ? $config['pm_max_recipients'] : $max_recipients;
    } else {
        $max_recipients = 10;
    }
    // If this is a quote/reply "to all"... we may increase the max_recpients to the number of original recipients
    if (($action == 'reply' || $action == 'quote') && $max_recipients) {
        // We try to include every previously listed member from the TO Header
        $list = rebuild_header(array('to' => $post['to_address']));
        // Can be an empty array too ;)
        $list = !empty($list['u']) ? $list['u'] : array();
        $list[$post['author_id']] = 'to';
        if (isset($list[$user->data['user_id']])) {
            unset($list[$user->data['user_id']]);
        }
        $max_recipients = $max_recipients < sizeof($list) ? sizeof($list) : $max_recipients;
        unset($list);
    }
    // Handle User/Group adding/removing
    handle_message_list_actions($address_list, $error, $remove_u, $remove_g, $add_to, $add_bcc);
    if ($error) {
        $error_msg = trim(strip_tags(implode("\n", $error)));
        trigger_error($error_msg);
    }
    // Check mass pm to group permission
    if ((!$config['allow_mass_pm'] || !$auth->acl_get('u_masspm_group')) && !empty($address_list['g'])) {
        $address_list = array();
        trigger_error('NO_AUTH_GROUP_MESSAGE');
    }
    // Check mass pm to users permission
    if ((!$config['allow_mass_pm'] || !$auth->acl_get('u_masspm')) && num_recipients($address_list) > 1) {
        $address_list = get_recipients($address_list, 1);
        trigger_error('TOO_MANY_RECIPIENTS');
    }
    // Check for too many recipients
    if (!empty($address_list['u']) && $max_recipients && sizeof($address_list['u']) > $max_recipients) {
        $address_list = get_recipients($address_list, $max_recipients);
        trigger_error('TOO_MANY_RECIPIENTS');
    }
    $enable_bbcode = $config['allow_bbcode'] && $config['auth_bbcode_pm'] && $auth->acl_get('u_pm_bbcode') ? true : false;
    $enable_smilies = $config['allow_smilies'] && $config['auth_smilies_pm'] && $auth->acl_get('u_pm_smilies') ? true : false;
    $img_status = $config['auth_img_pm'] && $auth->acl_get('u_pm_img') ? true : false;
    $flash_status = $config['auth_flash_pm'] && $auth->acl_get('u_pm_flash') ? true : false;
    $enable_urls = true;
    $enable_sig = false;
    $message_parser->message = $text_body;
    // Parse message
    $message_parser->parse($enable_bbcode, $config['allow_post_links'] ? $enable_urls : false, $enable_smilies, $img_status, $flash_status, true, $config['allow_post_links']);
    $pm_data = array('msg_id' => (int) $msg_id, 'from_user_id' => $user->data['user_id'], 'from_user_ip' => $user->ip, 'from_username' => $user->data['username'], 'reply_from_root_level' => isset($post['root_level']) ? (int) $post['root_level'] : 0, 'reply_from_msg_id' => (int) $msg_id, 'icon_id' => 0, 'enable_sig' => (bool) $enable_sig, 'enable_bbcode' => (bool) $enable_bbcode, 'enable_smilies' => (bool) $enable_smilies, 'enable_urls' => (bool) $enable_urls, 'bbcode_bitfield' => $message_parser->bbcode_bitfield, 'bbcode_uid' => $message_parser->bbcode_uid, 'message' => $message_parser->message, 'attachment_data' => $message_parser->attachment_data, 'filename_data' => $message_parser->filename_data, 'address_list' => $address_list);
    $msg_id = submit_pm($action, $subject, $pm_data);
    $result = new xmlrpcval(array('result' => new xmlrpcval($msg_id ? true : false, 'boolean'), 'msg_id' => new xmlrpcval($msg_id, 'string')), 'struct');
    return new xmlrpcresp($result);
}
Example #11
0
    /**
     * comment Controller
     *	Route: gallery/comment/{image_id}/edit/{comment_id}
     *
     * @param int	$image_id	Image ID
     * @return Symfony\Component\HttpFoundation\Response A Symfony Response object
     */
    public function edit($image_id, $comment_id)
    {
        $this->user->add_lang_ext('phpbbgallery/core', array('gallery'));
        add_form_key('gallery');
        $submit = $this->request->variable('submit', false);
        $error = $message = '';
        // load Image Data
        $image_data = $this->image->get_image_data($image_id);
        $album_id = (int) $image_data['image_album_id'];
        $album_data = $this->loader->get($album_id);
        $this->display->generate_navigation($album_data);
        $page_title = $image_data['image_name'];
        $image_backlink = $this->helper->route('phpbbgallery_image', array('image_id' => $image_id));
        $album_backlink = $this->helper->route('phpbbgallery_album', array('album_id' => $album_id));
        $image_loginlink = $this->url->append_sid('relative', 'image_page', "album_id={$album_id}&amp;image_id={$image_id}");
        if ($comment_id != 0) {
            $sql = 'SELECT *
				FROM ' . $this->table_comments . '
				WHERE comment_id = ' . $comment_id;
            $result = $this->db->sql_query($sql);
            $comment_data = $this->db->sql_fetchrow($result);
            $this->db->sql_freeresult($result);
            $image_id = (int) $comment_data['comment_image_id'];
        } else {
            $this->misc->not_authorised($image_backlink, $image_loginlink);
        }
        $this->gallery_auth->load_user_premissions($this->user->data['user_id']);
        if (!$this->gallery_auth->acl_check('c_edit', $album_id, $album_data['album_user_id']) && $mode == 'add') {
            if (!$this->gallery_auth->acl_check('m_comments', $album_id, $album_data['album_user_id'])) {
                $this->misc->not_authorised($album_backlink, $album_loginlink, 'LOGIN_EXPLAIN_UPLOAD');
            }
        } else {
            if ($comment_data['comment_user_id'] != $this->user->data['user_id'] && !$this->gallery_auth->acl_check('m_comments', $album_id, $album_data['album_user_id'])) {
                $this->misc->not_authorised($image_backlink, $image_loginlink);
            }
        }
        $this->user->add_lang('posting');
        include_once $this->phpbb_root_path . 'includes/functions_posting.' . $this->php_ext;
        $bbcode_status = $this->config['allow_bbcode'] ? true : false;
        $smilies_status = $this->config['allow_smilies'] ? true : false;
        $img_status = $bbcode_status ? true : false;
        $url_status = $this->config['allow_post_links'] ? true : false;
        $flash_status = false;
        $quote_status = true;
        include_once $this->phpbb_root_path . 'includes/functions_display.' . $this->php_ext;
        // Build custom bbcodes array
        display_custom_bbcodes();
        // Build smilies array
        generate_smilies('inline', 0);
        //$s_hide_comment_input = (time() < ($album_data['contest_start'] + $album_data['contest_end'])) ? true : false;
        $s_hide_comment_input = false;
        $this->template->assign_vars(array('BBCODE_STATUS' => $bbcode_status ? sprintf($this->user->lang['BBCODE_IS_ON'], '<a href="' . $this->url->append_sid('phpbb', 'faq', 'mode=bbcode') . '">', '</a>') : sprintf($this->user->lang['BBCODE_IS_OFF'], '<a href="' . $this->url->append_sid('phpbb', 'faq', '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' => $bbcode_status && $url_status ? $this->user->lang['URL_IS_ON'] : $this->user->lang['URL_IS_OFF'], 'S_BBCODE_ALLOWED' => $bbcode_status, 'S_SMILIES_ALLOWED' => $smilies_status, 'S_LINKS_ALLOWED' => $url_status, 'S_BBCODE_IMG' => $img_status, 'S_BBCODE_URL' => $url_status, 'S_BBCODE_FLASH' => $flash_status, 'S_BBCODE_QUOTE' => $quote_status));
        $comment_username_req = $comment_data['comment_user_id'] == ANONYMOUS ? true : false;
        if ($submit) {
            if (!check_form_key('gallery')) {
                trigger_error('FORM_INVALID');
            }
            $sql_ary = array();
            $comment_plain = $this->request->variable('message', '', true);
            if ($comment_username_req) {
                $comment_username = $this->request->variable('username', '');
                if ($comment_username == '') {
                    $error .= ($error ? '<br />' : '') . $this->this->user->lang['MISSING_USERNAME'];
                }
                if (validate_username($comment_username)) {
                    $error .= ($error ? '<br />' : '') . $this->user->lang['INVALID_USERNAME'];
                    $comment_username = '';
                }
                $sql_ary = array('comment_username' => $comment_username);
            }
            if ($comment_plain == '') {
                $error .= ($error ? '<br />' : '') . $this->user->lang['MISSING_COMMENT'];
            }
            if (utf8_strlen($comment_plain) > $this->gallery_config->get('comment_length')) {
                $error .= ($error ? '<br />' : '') . $this->user->lang['COMMENT_TOO_LONG'];
            }
            if (!class_exists('bbcode')) {
                include $this->phpbb_root_path . 'includes/bbcode.' . $this->php_ext;
            }
            include_once $this->phpbb_root_path . 'includes/message_parser.' . $this->php_ext;
            $message_parser = new \parse_message();
            $message_parser->message = utf8_normalize_nfc($comment_plain);
            if ($message_parser->message) {
                $message_parser->parse(true, true, true, true, false, true, true, true);
            }
            $sql_ary = array_merge($sql_ary, array('comment' => $message_parser->message, 'comment_uid' => $message_parser->bbcode_uid, 'comment_bitfield' => $message_parser->bbcode_bitfield, 'comment_edit_count' => $comment_data['comment_edit_count'] + 1, 'comment_signature' => $this->auth->acl_get('u_sig') && isset($_POST['attach_sig'])));
            if (!$error) {
                $this->comment->edit($comment_id, $sql_ary);
                $message .= $this->user->lang['COMMENT_STORED'] . '<br />';
                if ($this->user->data['user_id'] != $comment_data['comment_user_id']) {
                    $this->gallery_log->add_log('moderator', 'c_edit', $image_data['image_album_id'], $image_data['image_id'], array('LOG_GALLERY_COMMENT_EDITED', $image_data['image_name']));
                }
            }
        } else {
            $sig_checked = (bool) $comment_data['comment_signature'];
            $comment_ary = generate_text_for_edit($comment_data['comment'], $comment_data['comment_uid'], $comment_data['comment_bitfield'], 7);
            $comment_plain = $comment_ary['text'];
            $comment_username = $comment_data['comment_username'];
        }
        $this->template->assign_vars(array('ERROR' => $error, 'MESSAGE' => isset($comment_plain) ? $comment_plain : '', 'USERNAME' => isset($comment_username) ? $comment_username : '', 'REQ_USERNAME' => !empty($comment_username_req) ? true : false, 'L_COMMENT_LENGTH' => sprintf($this->user->lang['COMMENT_LENGTH'], $this->gallery_config->get('comment_length')), 'IMAGE_RSZ_WIDTH' => $this->gallery_config->get('medium_width'), 'IMAGE_RSZ_HEIGHT' => $this->gallery_config->get('medium_height'), 'U_IMAGE' => append_sid($this->url->path('full') . 'image/' . $image_id . '/medium'), 'U_VIEW_IMAGE' => append_sid($this->url->path('full') . 'image/' . $image_id), 'IMAGE_NAME' => $image_data['image_name'], 'S_SIGNATURE_CHECKED' => isset($sig_checked) && $sig_checked ? ' checked="checked"' : '', 'S_ALBUM_ACTION' => $this->helper->route('phpbbgallery_comment_edit', array('image_id' => $image_id, 'comment_id' => $comment_id))));
        if ($submit && !$error) {
            $message .= '<br />' . sprintf($this->user->lang['CLICK_RETURN_IMAGE'], '<a href="' . $image_backlink . '">', '</a>');
            $message .= '<br />' . sprintf($this->user->lang['CLICK_RETURN_ALBUM'], '<a href="' . $album_backlink . '">', '</a>');
            $this->url->meta_refresh(3, $image_backlink);
            trigger_error($message);
        }
        return $this->helper->render('gallery/comment_body.html', $page_title);
    }
Example #12
0
 }
 $db->sql_freeresult($result);
 // Find out whether the user is watching the report
 if ($user->data['user_id'] != ANONYMOUS) {
     $sql = 'SELECT notify_status FROM ' . TOPICS_WATCH_TABLE . " WHERE topic_id = {$report['topic_id']} AND user_id = {$user->data['user_id']}";
     $result = $db->sql_query($sql);
     $is_subscribed = $db->sql_fetchrow($result) != false;
     $db->sql_freeresult($result);
 } else {
     $is_subscribed = false;
 }
 // Get submitted data
 $comment_data = array('comment_subject' => utf8_normalize_nfc(request_var('comment_subject', '', true)), 'comment_message' => utf8_normalize_nfc(request_var('comment_message', '', true)), 'enable_bbcode' => isset($_POST['disable_bbcode']) ? 0 : 1, 'enable_smilies' => isset($_POST['disable_smilies']) ? 0 : 1, 'enable_magic_url' => isset($_POST['disable_magic_url']) ? 0 : 1);
 // Run checks
 if (isset($_POST['preview']) || isset($_POST['submit'])) {
     $message_parser = new parse_message();
     $message_parser->message =& $comment_data['comment_message'];
     $message_md5 = md5($message_parser->message);
     $message_parser->parse($comment_data['enable_bbcode'], $config['allow_post_links'] ? $comment_data['enable_magic_url'] : false, $comment_data['enable_smilies'], $auth->acl_get('f_img', $report['forum_id']), $auth->acl_get('f_flash', $report['forum_id']), true, $config['allow_post_links']);
     if (sizeof($message_parser->warn_msg)) {
         $error = $message_parser->warn_msg;
     }
 }
 // Preview comment
 if (isset($_POST['preview']) && !empty($comment_data['comment_message'])) {
     $template->assign_vars(array('PREVIEW_TEXT' => $message_parser->format_display($comment_data['enable_bbcode'], $comment_data['enable_magic_url'], $comment_data['enable_smilies'], false), 'S_PREVIEW' => true));
 }
 // Post comment
 if (isset($_POST['submit'])) {
     if (!check_form_key('add_comment')) {
         trigger_error('FORM_INVALID');
		{
			$karma_power = 1;
		}

		// Karma comments disable, we'll always karma with max power
		if (!$karmamod->config['comments'])
		{
			$karma_power = $max_karma_power;
		}

		// Include posting functions
		include($phpbb_root_path . 'includes/functions_posting.' . $phpEx);
		include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
		include($phpbb_root_path . 'includes/message_parser.' . $phpEx);

		$message_parser = new parse_message();
		$error = array();

		$s_icons = false;
		// Icons enabled for this forum?
		if ($karmamod->config['icons'])
		{
			$s_icons = posting_gen_topic_icons('', $icon_id);
		}

		// HTML, BBCode, Smilies, Images and Flash status
		$bbcode_status	= ($config['allow_bbcode']) ? true : false;
		$smilies_status	= ($bbcode_status && $config['allow_smilies']) ? true : false;
		$img_status		= ($bbcode_status) ? true : false;
		$url_status		= ($config['allow_post_links']) ? true : false;
		$flash_status	= ($bbcode_status && $config['allow_post_flash']) ? true : false;
Example #14
0
 // Signature
 if ($enable_sig && $config['allow_sig'] && $preview_signature && $_CLASS['auth']->acl_get('f_sigs', $forum_id)) {
     $parse_sig = new parse_message($preview_signature);
     $parse_sig->bbcode_uid = $preview_signature_uid;
     $parse_sig->bbcode_bitfield = $preview_signature_bitfield;
     // Not sure about parameters for bbcode/smilies/urls... in signatures
     $parse_sig->format_display($config['allow_html'], $config['allow_bbcode'], true, $config['allow_smilies']);
     $preview_signature = $parse_sig->message;
     unset($parse_sig);
 } else {
     $preview_signature = '';
 }
 $preview_subject = censor_text($subject);
 // Poll Preview
 if (($mode == 'post' || $mode == 'edit' && $post_id == $topic_first_post_id && (!$poll_last_vote || $_CLASS['auth']->acl_get('m_edit', $forum_id))) && $_CLASS['auth']->acl_get('f_poll', $forum_id)) {
     $parse_poll = new parse_message($poll_title);
     $parse_poll->bbcode_uid = $message_parser->bbcode_uid;
     $parse_poll->bbcode_bitfield = $message_parser->bbcode_bitfield;
     $parse_poll->format_display($enable_html, $enable_bbcode, $enable_urls, $enable_smilies);
     $_CLASS['core_template']->assign_array(array('S_HAS_POLL_OPTIONS' => sizeof($poll_options), 'S_IS_MULTI_CHOICE' => $poll_max_options > 1 ? true : false, 'POLL_QUESTION' => $parse_poll->message, 'L_POLL_LENGTH' => $poll_length ? sprintf($_CLASS['core_user']->lang['POLL_RUN_TILL'], $_CLASS['core_user']->format_date($poll_length + $poll_start)) : '', 'L_MAX_VOTES' => $poll_max_options == 1 ? $_CLASS['core_user']->lang['MAX_OPTION_SELECT'] : sprintf($_CLASS['core_user']->lang['MAX_OPTIONS_SELECT'], $poll_max_options)));
     $parse_poll->message = implode("\n", $poll_options);
     $parse_poll->format_display($enable_html, $enable_bbcode, $enable_urls, $enable_smilies);
     $preview_poll_options = explode('<br />', $parse_poll->message);
     unset($parse_poll);
     foreach ($preview_poll_options as $option) {
         $_CLASS['core_template']->assign_vars_array('poll_option', array('POLL_OPTION_CAPTION' => $option));
     }
     unset($preview_poll_options);
 }
 // Attachment Preview
 if (sizeof($message_parser->attachment_data)) {
        // grab md5 'checksum' of new message
        $message_md5 = md5($message_parser->message);
        $data = array('topic_title' => $title, 'topic_first_post_id' => isset($post_data['topic_first_post_id']) ? (int) $post_data['topic_first_post_id'] : 0, 'topic_last_post_id' => isset($post_data['topic_last_post_id']) ? (int) $post_data['topic_last_post_id'] : 0, 'topic_time_limit' => (int) $post_data['topic_time_limit'], 'topic_attachment' => isset($post_data['topic_attachment']) ? (int) $post_data['topic_attachment'] : 0, 'post_id' => (int) $post_id, 'topic_id' => (int) $topic_id, 'forum_id' => (int) $forum_id, 'icon_id' => (int) $post_data['icon_id'], 'poster_id' => (int) $post_data['poster_id'], 'enable_sig' => (bool) $post_data['enable_sig'], 'enable_bbcode' => (bool) $post_data['enable_bbcode'], 'enable_smilies' => (bool) $post_data['enable_smilies'], 'enable_urls' => (bool) $post_data['enable_urls'], 'enable_indexing' => (bool) $post_data['enable_indexing'], 'message_md5' => (string) $message_md5, 'post_time' => isset($post_data['post_time']) ? (int) $post_data['post_time'] : $current_time, 'post_checksum' => isset($post_data['post_checksum']) ? (string) $post_data['post_checksum'] : '', 'post_edit_reason' => $post_data['post_edit_reason'], 'post_edit_user' => $mode == 'edit' ? $user->data['user_id'] : (isset($post_data['post_edit_user']) ? (int) $post_data['post_edit_user'] : 0), 'forum_parents' => $post_data['forum_parents'], 'forum_name' => $post_data['forum_name'], 'notify' => $notify, 'notify_set' => $post_data['notify_set'], 'poster_ip' => isset($post_data['poster_ip']) ? $post_data['poster_ip'] : $user->ip, 'post_edit_locked' => (int) $post_data['post_edit_locked'], 'bbcode_bitfield' => $message_parser->bbcode_bitfield, 'bbcode_uid' => $message_parser->bbcode_uid, 'message' => $message_parser->message, 'attachment_data' => $message_parser->attachment_data, 'filename_data' => $message_parser->filename_data, 'topic_approved' => isset($post_data['topic_approved']) ? $post_data['topic_approved'] : false, 'post_approved' => isset($post_data['post_approved']) ? $post_data['post_approved'] : false);
        $output = clean(submit_post($mode, $title, $username, POST_NORMAL, $poll, $data, $update_message, 0));
    }
}
// ****************************
// *********** REPLY **********
// ****************************
if ($get == 'reply') {
    // don't allow anonymous posting or spam bots will go crazy
    if ($user->data['is_registered']) {
        include $phpbb_root_path . 'includes/functions_posting.' . $phpEx;
        include $phpbb_root_path . 'includes/functions_display.' . $phpEx;
        include $phpbb_root_path . 'includes/message_parser.' . $phpEx;
        $message_parser = new parse_message();
        $message = utf8_normalize_nfc(request_var('txt', '', true));
        $message_parser->message =& $message;
        $title = utf8_normalize_nfc(request_var('title', '', true));
        $username = $user->data['username'];
        $update_message = true;
        $mode = 'reply';
        $forum_id = request_var('fid', '');
        $topic_id = request_var('tid', '');
        $post_data['poster_id'] = $user->data['user_id'];
        $post_data['enable_bbcode'] = true;
        $post_data['enable_smilies'] = true;
        $post_data['enable_urls'] = true;
        // parse message
        if ($update_message) {
            if (sizeof($message_parser->warn_msg)) {
/**
* handles sending subscription notices for blogs or replies
*
* Sends a PM or Email to each user in the subscription list, depending on what they want
*
* @param string $mode The mode (new_blog, or new_reply)
* @param string $post_subject The subject of the post made
* @param int|bool $uid The user_id of the user who made the new blog (if there is one).  If this is left as 0 it will grab the global value of $user_id.
* @param int|bool $bid The blog_id of the blog.  If this is left as 0 it will grab the global value of $blog_id.
* @param int|bool $rid The reply_id of the new reply (if there is one).  If this is left as 0 it will grab the global value of $reply_id.
*/
function handle_subscription($mode, $post_subject, $uid = 0, $bid = 0, $rid = 0)
{
    global $db, $user, $phpbb_root_path, $phpEx, $config;
    global $user_id, $blog_id, $reply_id;
    global $blog_data, $blog_urls;
    // if $uid, $bid, or $rid are not set, use the globals
    $uid = $uid != 0 ? $uid : $user_id;
    $bid = $bid != 0 ? $bid : $blog_id;
    $rid = $rid != 0 ? $rid : $reply_id;
    // make sure that subscriptions are enabled and that a blog_id is sent
    if (!$config['user_blog_subscription_enabled'] || $bid == 0) {
        return;
    }
    if (!isset($user->lang['BLOG_SUBSCRIPTION_NOTICE'])) {
        $user->add_lang('mods/blog/posting');
    }
    // This will hold all the send info, all ones that will be sent via PM would be $send[1], or Email would be $send[2], next would be $send[4], etc.
    $send = array();
    $subscribe_modes = get_blog_subscription_types();
    $temp = compact('mode', 'post_subject', 'uid', 'bid', 'rid', 'send');
    blog_plugins::plugin_do_ref('function_handle_subscription', $temp);
    extract($temp);
    // Fix the URLs...
    if (isset($config['user_blog_seo']) && $config['user_blog_seo']) {
        $view_url = $rid ? blog_url($uid, $bid, $rid) : blog_url($uid, $bid);
        $unsubscribe_url = $rid ? blog_url($uid, $bid, false, array('page' => 'unsubscribe')) : blog_url($uid, false, false, array('page' => 'unsubscribe'));
    } else {
        $view_url = redirect($rid ? blog_url($uid, $bid, $rid) : blog_url($uid, $bid), true);
        $unsubscribe_url = redirect($rid ? blog_url($uid, $bid, false, array('page' => 'unsubscribe')) : blog_url($uid, false, false, array('page' => 'unsubscribe')), true);
    }
    if ($mode == 'new_reply' && $rid != 0) {
        $sql = 'SELECT * FROM ' . BLOGS_SUBSCRIPTION_TABLE . '
			WHERE blog_id = ' . intval($bid) . '
			AND sub_user_id != ' . $user->data['user_id'];
        $result = $db->sql_query($sql);
        while ($row = $db->sql_fetchrow($result)) {
            if (!array_key_exists($row['sub_type'], $send)) {
                $send[$row['sub_type']] = array($row['sub_user_id']);
            } else {
                $send[$row['sub_type']][] = $row['sub_user_id'];
            }
        }
        $db->sql_freeresult($result);
        $message = sprintf($user->lang['BLOG_SUBSCRIPTION_NOTICE'], $view_url, $user->data['username'], $unsubscribe_url);
    } else {
        if ($mode == 'new_blog' && $uid != 0) {
            $sql = 'SELECT * FROM ' . BLOGS_SUBSCRIPTION_TABLE . '
			WHERE user_id = ' . intval($uid) . '
			AND sub_user_id != ' . $user->data['user_id'];
            $result = $db->sql_query($sql);
            while ($row = $db->sql_fetchrow($result)) {
                if (!array_key_exists($row['sub_type'], $send)) {
                    $send[$row['sub_type']] = array($row['sub_user_id']);
                } else {
                    $send[$row['sub_type']][] = $row['sub_user_id'];
                }
            }
            $db->sql_freeresult($result);
            $message = sprintf($user->lang['USER_SUBSCRIPTION_NOTICE'], $user->data['username'], $view_url, $unsubscribe_url);
        }
    }
    $blog_data->get_user_data($config['user_blog_message_from']);
    // Send the PM
    if (isset($send[1]) && sizeof($send[1])) {
        if (!function_exists('submit_pm')) {
            // include the private messages functions page
            include "{$phpbb_root_path}includes/functions_privmsgs.{$phpEx}";
        }
        if (!class_exists('parse_message')) {
            include "{$phpbb_root_path}includes/message_parser.{$phpEx}";
        }
        $message_parser = new parse_message();
        $message_parser->message = $message;
        $message_parser->parse(true, true, true);
        // setup out to address list
        $address_list = array();
        foreach ($send[1] as $id) {
            $address_list[$id] = 'to';
        }
        $pm_data = array('from_user_id' => $config['user_blog_message_from'], 'from_username' => blog_data::$user[$config['user_blog_message_from']]['username'], 'address_list' => array('u' => $address_list), 'icon_id' => 10, 'from_user_ip' => '0.0.0.0', 'enable_bbcode' => true, 'enable_smilies' => true, 'enable_urls' => true, 'enable_sig' => true, 'message' => $message_parser->message, 'bbcode_bitfield' => $message_parser->bbcode_bitfield, 'bbcode_uid' => $message_parser->bbcode_uid);
        submit_pm('post', $user->lang['SUBSCRIPTION_NOTICE'], $pm_data, false);
        unset($message_parser, $address_list, $pm_data);
    }
    // Send the email
    if (isset($send[2]) && sizeof($send[2]) && $config['email_enable']) {
        if (!class_exists('messenger')) {
            include "{$phpbb_root_path}includes/functions_messenger.{$phpEx}";
        }
        $messenger = new messenger(false);
        $blog_data->get_user_data($send[2]);
        $reply_url_var = $rid ? "r={$rid}#r{$rid}" : '';
        foreach ($send[2] as $uid) {
            $messenger->template('blog_notify', $config['default_lang']);
            $messenger->replyto($config['board_contact']);
            $messenger->to(blog_data::$user[$uid]['user_email'], blog_data::$user[$uid]['username']);
            $messenger->headers('X-AntiAbuse: Board servername - ' . $config['server_name']);
            $messenger->headers('X-AntiAbuse: User_id - ' . blog_data::$user[$config['user_blog_message_from']]['user_id']);
            $messenger->headers('X-AntiAbuse: Username - ' . blog_data::$user[$config['user_blog_message_from']]['username']);
            $messenger->headers('X-AntiAbuse: User IP - ' . blog_data::$user[$config['user_blog_message_from']]['user_ip']);
            $messenger->assign_vars(array('BOARD_CONTACT' => $config['board_contact'], 'SUBJECT' => $user->lang['SUBSCRIPTION_NOTICE'], 'TO_USERNAME' => blog_data::$user[$uid]['username'], 'TYPE' => $rid ? $user->lang['REPLY'] : $user->lang['BLOG'], 'NAME' => $post_subject, 'BY_USERNAME' => $user->data['username'], 'U_VIEW' => $view_url, 'U_UNSUBSCRIBE' => $unsubscribe_url));
            $messenger->send(NOTIFY_EMAIL);
        }
        // save the queue if we must
        $messenger->save_queue();
        unset($messenger);
    }
    blog_plugins::plugin_do('function_handle_subscription_end');
}
Example #17
0
 function main($id, $mode)
 {
     global $auth, $cache, $template, $user, $db, $config, $phpEx, $phpbb_root_path;
     global $blog_plugins, $blog_plugins_path, $user_settings;
     $preview = isset($_POST['preview']) ? true : false;
     $submit = isset($_POST['submit']) ? true : false;
     $error = array();
     $user->add_lang(array('mods/blog/common', 'mods/blog/ucp'));
     include $phpbb_root_path . 'blog/functions.' . $phpEx;
     blog_plugins::plugin_do('ucp_start');
     get_user_settings($user->data['user_id']);
     switch ($mode) {
         case 'ucp_blog_settings':
             $subscription_types = get_blog_subscription_types();
             if ($submit) {
                 $sql_ary = array('instant_redirect' => request_var('instant_redirect', 0), 'blog_subscription_default' => 0, 'blog_style' => $auth->acl_get('u_blog_style') ? request_var('blog_style', '') : '', 'blog_css' => $auth->acl_get('u_blog_css') ? request_var('blog_css', '') : '');
                 if ($config['user_blog_subscription_enabled']) {
                     foreach ($subscription_types as $type => $name) {
                         if (request_var('subscription_' . $type, false)) {
                             $sql_ary['blog_subscription_default'] += $type;
                         }
                     }
                 }
                 update_user_blog_settings($user->data['user_id'], $sql_ary);
             } else {
                 if ($config['user_blog_subscription_enabled']) {
                     $subscribed = array();
                     if (isset($user_settings[$user->data['user_id']])) {
                         foreach ($subscription_types as $type => $name) {
                             // Bitwise check
                             if ($user_settings[$user->data['user_id']]['blog_subscription_default'] & $type) {
                                 $subscribed[$type] = true;
                             }
                         }
                     }
                     foreach ($subscription_types as $type => $name) {
                         $template->assign_block_vars('subscriptions', array('TYPE' => 'subscription_' . $type, 'NAME' => isset($user->lang[$name]) ? $user->lang[$name] : $name, 'S_CHECKED' => isset($subscribed[$type]) ? true : false));
                     }
                 }
                 if ($auth->acl_get('u_blog_style')) {
                     $available_styles = array(array('name' => $user->lang['NONE'], 'value' => 0, 'demo' => $phpbb_root_path . 'images/spacer.gif'));
                     $sql = 'SELECT * FROM ' . STYLES_TABLE . ' s, ' . STYLES_TEMPLATE_TABLE . ' st WHERE style_active = 1 AND s.template_id = st.template_id';
                     $result = $db->sql_query($sql);
                     while ($row = $db->sql_fetchrow($result)) {
                         $demo = $phpbb_root_path . 'images/spacer.gif';
                         if (@file_exists($phpbb_root_path . 'styles/' . $row['template_path'] . '/template/blog/demo.png')) {
                             $demo = $phpbb_root_path . 'styles/' . $row['template_path'] . '/template/blog/demo.png';
                         } else {
                             if (@file_exists($phpbb_root_path . 'styles/' . $row['template_path'] . '/template/blog/demo.gif')) {
                                 $demo = $phpbb_root_path . 'styles/' . $row['template_path'] . '/template/blog/demo.gif';
                             } else {
                                 if (@file_exists($phpbb_root_path . 'styles/' . $row['template_path'] . '/template/blog/demo.jpg')) {
                                     $demo = $phpbb_root_path . 'styles/' . $row['template_path'] . '/template/blog/demo.jpg';
                                 }
                             }
                         }
                         $available_styles[] = array('name' => $row['style_name'], 'value' => $row['style_id'], 'demo' => $demo);
                     }
                     $db->sql_freeresult($result);
                     $dh = @opendir($phpbb_root_path . 'blog/styles/');
                     if ($dh) {
                         while (($file = readdir($dh)) !== false) {
                             if (file_exists($phpbb_root_path . 'blog/styles/' . $file . '/style.' . $phpEx)) {
                                 // Inside of the style.php file, add to the $available_styles array
                                 include $phpbb_root_path . 'blog/styles/' . $file . '/style.' . $phpEx;
                             }
                         }
                         closedir($dh);
                     }
                     foreach ($available_styles as $row) {
                         if (isset($user_settings[$user->data['user_id']]) && $user_settings[$user->data['user_id']]['blog_style'] == $row['value'] && isset($row['demo']) && $row['demo']) {
                             $default_demo = $row['demo'];
                         }
                         $template->assign_block_vars('blog_styles', array('VALUE' => $row['value'], 'SELECTED' => isset($user_settings[$user->data['user_id']]) && $user_settings[$user->data['user_id']]['blog_style'] == $row['value'] ? true : false, 'NAME' => $row['name'], 'BLOG_CSS' => isset($row['blog_css']) && $row['blog_css'] ? true : false, 'DEMO' => isset($row['demo']) && $row['demo'] ? $row['demo'] : ''));
                     }
                 }
                 $template->assign_vars(array('S_BLOG_INSTANT_REDIRECT' => isset($user_settings[$user->data['user_id']]) ? $user_settings[$user->data['user_id']]['instant_redirect'] : 0, 'S_SUBSCRIPTIONS' => $config['user_blog_subscription_enabled'] ? true : false, 'S_BLOG_STYLE' => isset($available_styles) && sizeof($available_styles) > 1 ? true : false, 'S_BLOG_CSS' => $auth->acl_get('u_blog_css') ? true : false, 'DEFAULT_DEMO' => isset($default_demo) ? $default_demo : $phpbb_root_path . 'images/spacer.gif', 'BLOG_CSS' => isset($user_settings[$user->data['user_id']]) ? $user_settings[$user->data['user_id']]['blog_css'] : ''));
             }
             break;
         case 'ucp_blog_permissions':
             if (!$config['user_blog_user_permissions']) {
                 $error[] = $user->lang['USER_PERMISSIONS_DISABLED'];
                 $template->assign_vars(array('PERMISSIONS_DISABLED' => true));
             } else {
                 if ($submit) {
                     $sql_ary = array('perm_guest' => request_var('perm_guest', 1), 'perm_registered' => request_var('perm_registered', 2), 'perm_foe' => request_var('perm_foe', 0), 'perm_friend' => request_var('perm_friend', 2));
                     update_user_blog_settings($user->data['user_id'], $sql_ary, isset($_POST['resync']) ? true : false);
                 } else {
                     permission_settings_builder();
                 }
             }
             break;
         case 'ucp_blog_title_description':
             include $phpbb_root_path . 'includes/functions_posting.' . $phpEx;
             include $phpbb_root_path . 'includes/message_parser.' . $phpEx;
             include $phpbb_root_path . 'blog/includes/functions_posting.' . $phpEx;
             if (!function_exists('display_custom_bbcodes')) {
                 include $phpbb_root_path . 'includes/functions_display.' . $phpEx;
             }
             $user->add_lang('posting');
             $post_options = new post_options();
             $post_options->set_status(true, true, true);
             $post_options->set_in_template();
             if ($submit || $preview) {
                 // see if they tried submitting a message or suject(if they hit preview or submit) put it in an array for consistency with the edit mode
                 $blog_title = utf8_normalize_nfc(request_var('title', '', true));
                 $blog_description = utf8_normalize_nfc(request_var('message', '', true));
                 // set up the message parser to parse BBCode, Smilies, etc
                 $message_parser = new parse_message();
                 $message_parser->message = $blog_description;
                 $message_parser->parse($post_options->enable_bbcode, $post_options->enable_magic_url, $post_options->enable_smilies, $post_options->img_status, $post_options->flash_status, $post_options->bbcode_status, $post_options->url_status);
             } else {
                 if (isset($user_settings[$user->data['user_id']])) {
                     $blog_title = $user_settings[$user->data['user_id']]['title'];
                     $blog_description = $user_settings[$user->data['user_id']]['description'];
                     decode_message($blog_description, $user_settings[$user->data['user_id']]['description_bbcode_uid']);
                 } else {
                     $blog_title = $blog_description = '';
                 }
             }
             if (!$submit || sizeof($error)) {
                 if ($preview && !sizeof($error)) {
                     $preview_message = $message_parser->format_display($post_options->enable_bbcode, $post_options->enable_magic_url, $post_options->enable_smilies, false);
                     // output some data to the template parser
                     $template->assign_vars(array('S_DISPLAY_PREVIEW' => true, 'PREVIEW_SUBJECT' => censor_text($blog_title), 'PREVIEW_MESSAGE' => $preview_message, 'POST_DATE' => $user->format_date(time())));
                 }
                 // Generate smiley listing
                 generate_smilies('inline', false);
                 // Build custom bbcodes array
                 display_custom_bbcodes();
                 $template->assign_vars(array('S_PREVIEW_BUTTON' => true, 'TITLE' => $blog_title, 'MESSAGE' => $blog_description));
             } else {
                 if ($submit) {
                     $sql_ary = array('user_id' => $user->data['user_id'], 'title' => $blog_title, 'description' => $message_parser->message, 'description_bbcode_bitfield' => $message_parser->bbcode_bitfield, 'description_bbcode_uid' => $message_parser->bbcode_uid);
                     unset($message_parser);
                     update_user_blog_settings($user->data['user_id'], $sql_ary);
                 }
             }
             break;
         default:
             $default = true;
             $temp = compact('mode', 'error', 'default');
             blog_plugins::plugin_do_ref('ucp_default', $temp);
             // make sure you set default to false if you use your own page
             extract($temp);
             if ($default) {
                 trigger_error('NO_MODE');
             }
     }
     blog_plugins::plugin_do('ucp_end');
     if ($submit && !sizeof($error)) {
         //$cache->destroy('_blog_settings_' . $user->data['user_id']);
         meta_refresh(3, $this->u_action);
         $message = $user->lang['PREFERENCES_UPDATED'] . '<br /><br />' . sprintf($user->lang['RETURN_UCP'], '<a href="' . $this->u_action . '">', '</a>');
         trigger_error($message);
     }
     $template->assign_vars(array('L_TITLE' => $user->lang[strtoupper($mode)], 'L_TITLE_EXPLAIN' => $user->lang[strtoupper($mode) . '_EXPLAIN'], 'ERROR' => sizeof($error) ? implode($error, '<br />') : false, 'MODE' => $mode, 'S_UCP_ACTION' => $this->u_action));
     $this->tpl_name = 'blog/ucp_blog';
     $this->page_title = strtoupper($mode);
 }
Example #18
0
function new_topic_func($xmlrpc_params)
{
    global $db, $auth, $user, $config, $phpbb_root_path, $phpEx, $mobiquo_config;
    $user->setup('posting');
    if (!$user->data['is_registered']) {
        trigger_error('LOGIN_EXPLAIN_POST');
    }
    $params = php_xmlrpc_decode($xmlrpc_params);
    // get parameters
    $forum_id = isset($params[0]) ? intval($params[0]) : '';
    $subject = isset($params[1]) ? $params[1] : '';
    $text_body = isset($params[2]) ? $params[2] : '';
    require_once 'include/emoji.php';
    $text_body = emoji_unified_to_names($text_body);
    $_POST['attachment_data'] = isset($params[5]) && $params[5] ? unserialize(base64_decode($params[5])) : array();
    if (!$forum_id) {
        trigger_error('NO_FORUM');
    }
    if (utf8_clean_string($subject) === '') {
        trigger_error('EMPTY_SUBJECT');
    }
    if (utf8_clean_string($text_body) === '') {
        trigger_error('TOO_FEW_CHARS');
    }
    $post_data = array();
    $current_time = time();
    $sql = 'SELECT * FROM ' . FORUMS_TABLE . " WHERE forum_id = {$forum_id}";
    $result = $db->sql_query($sql);
    $post_data = $db->sql_fetchrow($result);
    $db->sql_freeresult($result);
    if (!$post_data) {
        trigger_error('NO_FORUM');
    }
    // Need to login to passworded forum first?
    if ($post_data['forum_password'] && !check_forum_password($forum_id)) {
        trigger_error('LOGIN_FORUM');
    }
    // Check permissions
    if ($user->data['is_bot']) {
        trigger_error('NOT_AUTHORISED');
    }
    // Is the user able to read and post within this forum?
    if (!$auth->acl_get('f_read', $forum_id)) {
        if ($user->data['user_id'] != ANONYMOUS) {
            trigger_error('USER_CANNOT_READ');
        }
        trigger_error('LOGIN_EXPLAIN_POST');
    }
    if (!$auth->acl_get('f_post', $forum_id)) {
        if ($user->data['user_id'] != ANONYMOUS) {
            trigger_error('USER_CANNOT_POST');
        }
        trigger_error('LOGIN_EXPLAIN_POST');
    }
    // Is the user able to post within this forum?
    if ($post_data['forum_type'] != FORUM_POST) {
        trigger_error('USER_CANNOT_FORUM_POST');
    }
    // Forum/Topic locked?
    if ($post_data['forum_status'] == ITEM_LOCKED && !$auth->acl_get('m_edit', $forum_id)) {
        trigger_error('FORUM_LOCKED');
    }
    $post_data['quote_username'] = '';
    $post_data['post_edit_locked'] = 0;
    $post_data['post_subject'] = '';
    $post_data['topic_time_limit'] = 0;
    $post_data['poll_length'] = 0;
    $post_data['poll_start'] = 0;
    $post_data['icon_id'] = 0;
    $post_data['poll_options'] = array();
    include $phpbb_root_path . 'includes/message_parser.' . $phpEx;
    $message_parser = new parse_message();
    // Set some default variables
    $uninit = array('post_attachment' => 0, 'poster_id' => $user->data['user_id'], 'enable_magic_url' => 0, 'topic_status' => 0, 'topic_type' => POST_NORMAL, 'post_subject' => '', 'topic_title' => '', 'post_time' => 0, 'post_edit_reason' => '', 'notify_set' => 0);
    foreach ($uninit as $var_name => $default_value) {
        if (!isset($post_data[$var_name])) {
            $post_data[$var_name] = $default_value;
        }
    }
    unset($uninit);
    if ($config['allow_topic_notify'] && $user->data['is_registered']) {
        $notify = $user->data['user_notify'] ? true : false;
    } else {
        $notify = false;
    }
    // Always check if the submitted attachment data is valid and belongs to the user.
    // Further down (especially in submit_post()) we do not check this again.
    $message_parser->get_submitted_attachment_data($post_data['poster_id']);
    $post_data['username'] = '';
    $post_data['enable_urls'] = $post_data['enable_magic_url'];
    $post_data['enable_sig'] = $config['allow_sig'] && $user->optionget('attachsig') ? true : false;
    $post_data['enable_smilies'] = $config['allow_smilies'] && $user->optionget('smilies') ? true : false;
    $post_data['enable_bbcode'] = $config['allow_bbcode'] && $user->optionget('bbcode') ? true : false;
    $post_data['enable_urls'] = true;
    $post_data['enable_magic_url'] = $post_data['drafts'] = false;
    $check_value = ($post_data['enable_bbcode'] + 1 << 8) + ($post_data['enable_smilies'] + 1 << 4) + ($post_data['enable_urls'] + 1 << 2) + ($post_data['enable_sig'] + 1 << 1);
    // HTML, BBCode, Smilies, Images and Flash status
    $bbcode_status = $config['allow_bbcode'] && $auth->acl_get('f_bbcode', $forum_id) ? true : false;
    $smilies_status = $bbcode_status && $config['allow_smilies'] && $auth->acl_get('f_smilies', $forum_id) ? true : false;
    $img_status = $bbcode_status && $auth->acl_get('f_img', $forum_id) ? true : false;
    $url_status = $config['allow_post_links'] ? true : false;
    $flash_status = $bbcode_status && $auth->acl_get('f_flash', $forum_id) && $config['allow_post_flash'] ? true : false;
    $quote_status = $auth->acl_get('f_reply', $forum_id) ? true : false;
    $post_data['topic_cur_post_id'] = request_var('topic_cur_post_id', 0);
    $post_data['post_subject'] = utf8_normalize_nfc($subject);
    $message_parser->message = utf8_normalize_nfc(htmlspecialchars($text_body));
    $post_data['username'] = utf8_normalize_nfc(request_var('username', $post_data['username'], true));
    $post_data['post_edit_reason'] = '';
    $post_data['orig_topic_type'] = $post_data['topic_type'];
    $post_data['topic_type'] = request_var('topic_type', POST_NORMAL);
    $post_data['topic_time_limit'] = request_var('topic_time_limit', 0);
    $post_data['icon_id'] = request_var('icon', 0);
    $post_data['enable_bbcode'] = !$bbcode_status || isset($_POST['disable_bbcode']) ? false : true;
    $post_data['enable_smilies'] = !$smilies_status || isset($_POST['disable_smilies']) ? false : true;
    $post_data['enable_urls'] = isset($_POST['disable_magic_url']) ? 0 : 1;
    $post_data['enable_sig'] = !$config['allow_sig'] || !$auth->acl_get('f_sigs', $forum_id) || !$auth->acl_get('u_sig') ? false : ($user->data['is_registered'] ? true : false);
    $topic_lock = isset($_POST['lock_topic']) ? true : false;
    $post_lock = isset($_POST['lock_post']) ? true : false;
    $poll_delete = isset($_POST['poll_delete']) ? true : false;
    $status_switch = ($post_data['enable_bbcode'] + 1 << 8) + ($post_data['enable_smilies'] + 1 << 4) + ($post_data['enable_urls'] + 1 << 2) + ($post_data['enable_sig'] + 1 << 1);
    $status_switch = $status_switch != $check_value;
    $post_data['poll_title'] = utf8_normalize_nfc(request_var('poll_title', '', true));
    $post_data['poll_length'] = request_var('poll_length', 0);
    $post_data['poll_option_text'] = utf8_normalize_nfc(request_var('poll_option_text', '', true));
    $post_data['poll_max_options'] = request_var('poll_max_options', 1);
    $post_data['poll_vote_change'] = $auth->acl_get('f_votechg', $forum_id) && isset($_POST['poll_vote_change']) ? 1 : 0;
    // Parse Attachments - before checksum is calculated
    $message_parser->parse_attachments('fileupload', 'post', $forum_id, true, false, false);
    // Grab md5 'checksum' of new message
    $message_md5 = md5($message_parser->message);
    if (sizeof($message_parser->warn_msg)) {
        trigger_error(join("\n", $message_parser->warn_msg));
    }
    $message_parser->parse($post_data['enable_bbcode'], $config['allow_post_links'] ? $post_data['enable_urls'] : false, $post_data['enable_smilies'], $img_status, $flash_status, $quote_status, $config['allow_post_links']);
    if ($config['flood_interval'] && !$auth->acl_get('f_ignoreflood', $forum_id)) {
        // Flood check
        $last_post_time = 0;
        if ($user->data['is_registered']) {
            $last_post_time = $user->data['user_lastpost_time'];
        } else {
            $sql = 'SELECT post_time AS last_post_time
                FROM ' . POSTS_TABLE . "\r\r\n                WHERE poster_ip = '" . $user->ip . "'\r\r\n                    AND post_time > " . ($current_time - $config['flood_interval']);
            $result = $db->sql_query_limit($sql, 1);
            if ($row = $db->sql_fetchrow($result)) {
                $last_post_time = $row['last_post_time'];
            }
            $db->sql_freeresult($result);
        }
        if ($last_post_time && $current_time - $last_post_time < intval($config['flood_interval'])) {
            trigger_error('FLOOD_ERROR');
        }
    }
    // Validate username
    if ($post_data['username'] && !$user->data['is_registered']) {
        include $phpbb_root_path . 'includes/functions_user.' . $phpEx;
        if (($result = validate_username($post_data['username'], !empty($post_data['post_username']) ? $post_data['post_username'] : '')) !== false) {
            $user->add_lang('ucp');
            trigger_error($result . '_USERNAME');
        }
    }
    if (sizeof($message_parser->warn_msg)) {
        trigger_error(join("\n", $message_parser->warn_msg));
    }
    // DNSBL check
    if ($config['check_dnsbl'] && $mobiquo_config['check_dnsbl']) {
        if (($dnsbl = $user->check_dnsbl('post')) !== false) {
            trigger_error(sprintf($user->lang['IP_BLACKLISTED'], $user->ip, $dnsbl[1]));
        }
    }
    // Store message, sync counters
    $data = array('topic_title' => empty($post_data['topic_title']) ? $post_data['post_subject'] : $post_data['topic_title'], 'topic_first_post_id' => isset($post_data['topic_first_post_id']) ? (int) $post_data['topic_first_post_id'] : 0, 'topic_last_post_id' => isset($post_data['topic_last_post_id']) ? (int) $post_data['topic_last_post_id'] : 0, 'topic_time_limit' => (int) $post_data['topic_time_limit'], 'topic_attachment' => isset($post_data['topic_attachment']) ? (int) $post_data['topic_attachment'] : 0, 'post_id' => 0, 'topic_id' => 0, 'forum_id' => (int) $forum_id, 'icon_id' => (int) $post_data['icon_id'], 'poster_id' => (int) $post_data['poster_id'], 'enable_sig' => (bool) $post_data['enable_sig'], 'enable_bbcode' => (bool) $post_data['enable_bbcode'], 'enable_smilies' => (bool) $post_data['enable_smilies'], 'enable_urls' => (bool) $post_data['enable_urls'], 'enable_indexing' => (bool) $post_data['enable_indexing'], 'message_md5' => (string) $message_md5, 'post_time' => isset($post_data['post_time']) ? (int) $post_data['post_time'] : $current_time, 'post_checksum' => isset($post_data['post_checksum']) ? (string) $post_data['post_checksum'] : '', 'post_edit_reason' => $post_data['post_edit_reason'], 'post_edit_user' => isset($post_data['post_edit_user']) ? (int) $post_data['post_edit_user'] : 0, 'forum_parents' => $post_data['forum_parents'], 'forum_name' => $post_data['forum_name'], 'notify' => $notify, 'notify_set' => $post_data['notify_set'], 'poster_ip' => isset($post_data['poster_ip']) ? $post_data['poster_ip'] : $user->ip, 'post_edit_locked' => (int) $post_data['post_edit_locked'], 'bbcode_bitfield' => $message_parser->bbcode_bitfield, 'bbcode_uid' => $message_parser->bbcode_uid, 'message' => $message_parser->message, 'attachment_data' => $message_parser->attachment_data, 'filename_data' => $message_parser->filename_data, 'topic_approved' => isset($post_data['topic_approved']) ? $post_data['topic_approved'] : false, 'post_approved' => isset($post_data['post_approved']) ? $post_data['post_approved'] : false, 'post_expire_time' => -1, 'topic_status' => 0);
    $poll = array();
    include $phpbb_root_path . 'includes/functions_posting.' . $phpEx;
    $update_message = true;
    $cwd = getcwd();
    chdir('../');
    $phpbb_root_path_tmp = $phpbb_root_path;
    $phpbb_root_path = './';
    $redirect_url = submit_post('post', $post_data['post_subject'], $post_data['username'], $post_data['topic_type'], $poll, $data, $update_message);
    chdir($cwd);
    $phpbb_root_path = $phpbb_root_path_tmp;
    // Check the permissions for post approval, as well as the queue trigger where users are put on approval with a post count lower than specified. Moderators are not affected.
    $approved = true;
    if (($config['enable_queue_trigger'] && $user->data['user_posts'] < $config['queue_trigger_posts'] || !$auth->acl_get('f_noapprove', $data['forum_id'])) && !$auth->acl_get('m_approve', $data['forum_id'])) {
        $approved = false;
    }
    $posted_success = false;
    $topic_id = '';
    if ($redirect_url) {
        preg_match('/&amp;t=(\\d+)/', $redirect_url, $matches);
        $topic_id = $matches[1];
        $posted_success = true;
    }
    $xmlrpc_create_topic = new xmlrpcval(array('result' => new xmlrpcval($posted_success, 'boolean'), 'topic_id' => new xmlrpcval($topic_id), 'state' => new xmlrpcval($approved ? 0 : 1, 'int')), 'struct');
    return new xmlrpcresp($xmlrpc_create_topic);
}
Example #19
0
    /**
     * View an article
     *
     * @param	string	$article	URL of the article
     * @param	int		$id		ID of the article
     * @return	object
     */
    public function view_article($article, $id = 0)
    {
        // Setup message parser
        $this->message_parser = $this->setup_parser();
        $where = $id === 0 ? "article_url = '" . $this->db->sql_escape($article) . "' AND article_approved = 1" : 'article_id = ' . (int) $id;
        $sql_array = array('SELECT' => 'a.*, 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' => $where, 'ORDER_BY' => 'a.article_last_edit DESC');
        $sql = $this->db->sql_build_query('SELECT', $sql_array);
        $result = $this->db->sql_query_limit($sql, 1);
        $this->data = $this->db->sql_fetchrow($result);
        $this->db->sql_freeresult($result);
        // Do we have a newer version?
        if ($id === 0 && $this->auth->acl_get('u_wiki_set_active')) {
            $sql = 'SELECT article_id
				FROM ' . $this->article_table . "\n\t\t\t\tWHERE article_url = '" . $this->db->sql_escape($this->data['article_url']) . "'\n\t\t\t\t\tAND article_id <> " . (int) $this->data['article_id'] . '
					AND article_last_edit > ' . (int) $this->data['article_last_edit'] . '
				ORDER BY article_last_edit DESC';
            $result = $this->db->sql_query_limit($sql, 1);
            $row = $this->db->sql_fetchrow($result);
            $this->db->sql_freeresult($result);
            if (!empty($row['article_id'])) {
                $this->template->assign_vars(array('S_NEW_VERSION' => true, 'U_NEW_VERSION' => $this->helper->route('tas2580_wiki_article', array('article' => $article, 'id' => $row['article_id']))));
            }
        }
        if ($id != 0 && $this->data['article_approved'] != 1 && $this->auth->acl_get('u_wiki_set_active')) {
            $this->template->assign_vars(array('U_SET_ACTIVE' => $this->helper->route('tas2580_wiki_article', array('article' => $article, 'action' => 'active', 'id' => $id))));
        }
        if (!empty($this->data['article_title']) && !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))));
        }
        // If the article do not exist generate it
        if (!$this->data) {
            // Do we have a inactive article?
            if ($this->auth->acl_get('m_wiki_view_inactive')) {
                $sql = 'SELECT article_id
					FROM ' . $this->article_table . "\n\t\t\t\t\tWHERE article_url = '" . $this->db->sql_escape($article) . "'";
                $result = $this->db->sql_query_limit($sql, 1);
                $row = $this->db->sql_fetchrow($result);
                if (!empty($row['article_id'])) {
                    return $this->compare->view_versions($article);
                }
            }
            return $this->edit->edit_article($article);
        } else {
            $sources = explode("\n", $this->data['article_sources']);
            foreach ($sources as $source) {
                if (!empty($source)) {
                    $this->template->assign_block_vars('article_sources', array('SOURCE' => $source));
                }
            }
            $this->message_parser->message = $this->data['article_text'];
            $this->message_parser->bbcode_bitfield = $this->data['bbcode_bitfield'];
            $this->message_parser->bbcode_uid = $this->data['bbcode_uid'];
            $allow_bbcode = $allow_magic_url = $allow_smilies = true;
            $this->message_parser->format_display($allow_bbcode, $allow_magic_url, $allow_smilies);
            if (!empty($this->data['article_redirect'])) {
                $redirect_note = $this->user->lang('NO_ARTICLE_REDIRECT', $this->helper->route('tas2580_wiki_article', array('article' => $this->data['article_redirect'])), $this->data['article_redirect']);
                if ($this->auth->acl_get('u_wiki_set_redirect')) {
                    $redirect_note = $redirect_note . $this->message_parser->message;
                }
            }
            // article views
            if (isset($this->user->data['session_page']) && !$this->user->data['is_bot'] && (strpos($this->user->data['session_page'], 'wiki/' . $this->data['article_url']) === false || isset($this->user->data['session_created']))) {
                $article_id = $this->data['article_id'];
                $sql = 'UPDATE ' . $this->article_table . "\n\t\t\t\t\t\tSET article_views = article_views + 1\n\t\t\t\t\t\tWHERE article_id = {$article_id}";
                $this->db->sql_query($sql);
            }
            $s_edit_redirect = !empty($this->data['article_redirect']) && $this->auth->acl_get('u_wiki_set_redirect') || empty($this->data['article_redirect']) ? true : false;
            $this->template->assign_vars(array('ARTICLE_TITLE' => $this->data['article_title'], 'ARTICLE_TEXT' => $this->data['article_redirect'] ? $redirect_note : $this->message_parser->message, 'LAST_EDIT' => $this->user->format_date($this->data['article_last_edit']), 'LAST_EDIT_ISO' => date('Y-m-d', $this->data['article_last_edit']), 'ARTICLE_USER' => get_username_string('full', $this->data['user_id'], $this->data['username'], $this->data['user_colour']), 'S_EDIT' => $this->auth->acl_get('u_wiki_edit') && $s_edit_redirect, 'U_EDIT' => $this->helper->route('tas2580_wiki_article', array('article' => $article, 'action' => 'edit')), 'S_VERSIONS' => $this->auth->acl_get('u_wiki_versions'), 'U_VERSIONS' => $this->helper->route('tas2580_wiki_article', array('article' => $article, 'action' => 'versions')), 'S_DELETE' => $this->auth->acl_get('m_wiki_delete') && !$this->data['article_approved'], 'U_DELETE' => $this->helper->route('tas2580_wiki_index', array('article' => $article, 'action' => 'delete', 'id' => $this->data['article_id'])), 'ARTICLE_VERSION' => $id, 'ARTICLE_VIEWS_TEXT' => $this->user->lang('ARTICLE_VIEWS_TEXT', $this->data['article_views']), 'EDIT_REASON' => $id != 0 ? $this->data['article_edit_reason'] : '', 'U_TOPIC' => $this->data['article_topic_id'] != 0 ? append_sid($this->phpbb_root_path . 'viewtopic.' . $this->php_ext, 't=' . $this->data['article_topic_id']) : ''));
        }
        return $this->helper->render('article_body.html', $this->data['article_title']);
    }
			// Generate array to be inserted to the database
			$sql_insert_ary = array();
			foreach ($mod_tags as $tag_id)
			{
				$sql_insert_ary[] = array(
					'topic_id'	=> $row['topic_id'],
					'tag_id'	=> $tag_id,
				);
			}
			
			$db->sql_multi_insert(TAGMATCH_TABLE, $sql_insert_ary);
			
			/**
			* Generate post content
			*/
			$message_parser = new parse_message();		
			$vars = array(
				'MOD_HU_TITLE'		=> $row['mod_hu_title'],
				'MOD_EN_TITLE'		=> $row['mod_title'],
				'MOD_VERSION'		=> $row['mod_version'],
				'MOD_DESC'			=> $row['mod_desc'],
				'MOD_AUTHOR'		=> $row['mod_author_name'],
				'U_MOD_AUTHOR'		=> 'http://www.phpbb.com/community/memberlist.php?mode=viewprofile&amp;u=' . $row['mod_author_id'],
				'U_MOD_COM_DB'		=> 'http://www.phpbb.com/mods/db/index.php?i=misc&mode=display&contrib_id=' . $row['mod_db_id'],
				'MOD_TAGS'			=> generate_tags_bbcode_list($mod_tags, $tagcats, array("{$phpbb_root_path}mods.{$phpEx}", "mode=listtag&cat=%1\$s&tag=%2\$s")),
				'U_MOD'				=> generate_board_url() . '/' . $url_rewriter->rewrite("{$phpbb_root_path}mods.{$phpEx}", "mode=mod&id={$row['mod_id']}"),
			);
			$message = generate_content_post('mod_pack', $vars);
			$message_md5 = md5($message);	
			$message_parser->message = &$message;
			$message_parser->parse(true, true, false, false, false, true, true);
Example #21
0
/**
* Compose private message
* Called from ucp_pm with mode == 'compose'
*/
function compose_pm($id, $mode, $action, $user_folders = array())
{
    global $template, $db, $auth, $user, $cache;
    global $phpbb_root_path, $phpEx, $config;
    global $request, $phpbb_dispatcher, $phpbb_container;
    // Damn php and globals - i know, this is horrible
    // Needed for handle_message_list_actions()
    global $refresh, $submit, $preview;
    include $phpbb_root_path . 'includes/functions_posting.' . $phpEx;
    include $phpbb_root_path . 'includes/functions_display.' . $phpEx;
    include $phpbb_root_path . 'includes/message_parser.' . $phpEx;
    if (!$action) {
        $action = 'post';
    }
    add_form_key('ucp_pm_compose');
    // Grab only parameters needed here
    $to_user_id = request_var('u', 0);
    $to_group_id = request_var('g', 0);
    $msg_id = request_var('p', 0);
    $draft_id = request_var('d', 0);
    $lastclick = request_var('lastclick', 0);
    // Reply to all triggered (quote/reply)
    $reply_to_all = request_var('reply_to_all', 0);
    $address_list = $request->variable('address_list', array('' => array(0 => '')));
    $submit = isset($_POST['post']) ? true : false;
    $preview = isset($_POST['preview']) ? true : false;
    $save = isset($_POST['save']) ? true : false;
    $load = isset($_POST['load']) ? true : false;
    $cancel = isset($_POST['cancel']) && !isset($_POST['save']) ? true : false;
    $delete = isset($_POST['delete']) ? true : false;
    $remove_u = isset($_REQUEST['remove_u']) ? true : false;
    $remove_g = isset($_REQUEST['remove_g']) ? true : false;
    $add_to = isset($_REQUEST['add_to']) ? true : false;
    $add_bcc = isset($_REQUEST['add_bcc']) ? true : false;
    $refresh = isset($_POST['add_file']) || isset($_POST['delete_file']) || $save || $load || $remove_u || $remove_g || $add_to || $add_bcc;
    $action = $delete && !$preview && !$refresh && $submit ? 'delete' : $action;
    $select_single = $config['allow_mass_pm'] && $auth->acl_get('u_masspm') ? false : true;
    $error = array();
    $current_time = time();
    // Was cancel pressed? If so then redirect to the appropriate page
    if ($cancel || $current_time - $lastclick < 2 && $submit) {
        if ($msg_id) {
            redirect(append_sid("{$phpbb_root_path}ucp.{$phpEx}", 'i=pm&amp;mode=view&amp;action=view_message&amp;p=' . $msg_id));
        }
        redirect(append_sid("{$phpbb_root_path}ucp.{$phpEx}", 'i=pm'));
    }
    // Since viewtopic.php language entries are used in several modes,
    // we include the language file here
    $user->add_lang('viewtopic');
    /**
     * Modify the default vars before composing a PM
     *
     * @event core.ucp_pm_compose_modify_data
     * @var	int		msg_id					post_id in the page request
     * @var	int		to_user_id				The id of whom the message is to
     * @var	int		to_group_id				The id of the group the message is to
     * @var	bool	submit					Whether the form has been submitted
     * @var	bool	preview					Whether the user is previewing the PM or not
     * @var	string	action					One of: post, reply, quote, forward, quotepost, edit, delete, smilies
     * @var	bool	delete					Whether the user is deleting the PM
     * @var	int		reply_to_all			Value of reply_to_all request variable.
     * @since 3.1.4-RC1
     */
    $vars = array('msg_id', 'to_user_id', 'to_group_id', 'submit', 'preview', 'action', 'delete', 'reply_to_all');
    extract($phpbb_dispatcher->trigger_event('core.ucp_pm_compose_modify_data', compact($vars)));
    // Output PM_TO box if message composing
    if ($action != 'edit') {
        // Add groups to PM box
        if ($config['allow_mass_pm'] && $auth->acl_get('u_masspm_group')) {
            $sql = 'SELECT g.group_id, g.group_name, g.group_type
				FROM ' . GROUPS_TABLE . ' g';
            if (!$auth->acl_gets('a_group', 'a_groupadd', 'a_groupdel')) {
                $sql .= ' LEFT JOIN ' . USER_GROUP_TABLE . ' ug
					ON (
						g.group_id = ug.group_id
						AND ug.user_id = ' . $user->data['user_id'] . '
						AND ug.user_pending = 0
					)
					WHERE (g.group_type <> ' . GROUP_HIDDEN . ' OR ug.user_id = ' . $user->data['user_id'] . ')';
            }
            $sql .= $auth->acl_gets('a_group', 'a_groupadd', 'a_groupdel') ? ' WHERE ' : ' AND ';
            $sql .= 'g.group_receive_pm = 1
				ORDER BY g.group_type DESC, g.group_name ASC';
            $result = $db->sql_query($sql);
            $group_options = '';
            while ($row = $db->sql_fetchrow($result)) {
                $group_options .= '<option' . ($row['group_type'] == GROUP_SPECIAL ? ' class="sep"' : '') . ' value="' . $row['group_id'] . '">' . ($row['group_type'] == GROUP_SPECIAL ? $user->lang['G_' . $row['group_name']] : $row['group_name']) . '</option>';
            }
            $db->sql_freeresult($result);
        }
        $template->assign_vars(array('S_SHOW_PM_BOX' => true, 'S_ALLOW_MASS_PM' => $config['allow_mass_pm'] && $auth->acl_get('u_masspm') ? true : false, 'S_GROUP_OPTIONS' => $config['allow_mass_pm'] && $auth->acl_get('u_masspm_group') ? $group_options : '', 'U_FIND_USERNAME' => append_sid("{$phpbb_root_path}memberlist.{$phpEx}", "mode=searchuser&amp;form=postform&amp;field=username_list&amp;select_single={$select_single}")));
    }
    $sql = '';
    $folder_id = 0;
    // What is all this following SQL for? Well, we need to know
    // some basic information in all cases before we do anything.
    switch ($action) {
        case 'post':
            if (!$auth->acl_get('u_sendpm')) {
                trigger_error('NO_AUTH_SEND_MESSAGE');
            }
            break;
        case 'reply':
        case 'quote':
        case 'forward':
        case 'quotepost':
            if (!$msg_id) {
                trigger_error('NO_MESSAGE');
            }
            if (!$auth->acl_get('u_sendpm')) {
                trigger_error('NO_AUTH_SEND_MESSAGE');
            }
            if ($action == 'quotepost') {
                $sql = 'SELECT p.post_id as msg_id, p.forum_id, p.post_text as message_text, p.poster_id as author_id, p.post_time as message_time, p.bbcode_bitfield, p.bbcode_uid, p.enable_sig, p.enable_smilies, p.enable_magic_url, t.topic_title as message_subject, u.username as quote_username
					FROM ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . ' t, ' . USERS_TABLE . " u\n\t\t\t\t\tWHERE p.post_id = {$msg_id}\n\t\t\t\t\t\tAND t.topic_id = p.topic_id\n\t\t\t\t\t\tAND u.user_id = p.poster_id";
            } else {
                $sql = 'SELECT t.folder_id, p.*, u.username as quote_username
					FROM ' . PRIVMSGS_TO_TABLE . ' t, ' . PRIVMSGS_TABLE . ' p, ' . USERS_TABLE . ' u
					WHERE t.user_id = ' . $user->data['user_id'] . "\n\t\t\t\t\t\tAND p.author_id = u.user_id\n\t\t\t\t\t\tAND t.msg_id = p.msg_id\n\t\t\t\t\t\tAND p.msg_id = {$msg_id}";
            }
            break;
        case 'edit':
            if (!$msg_id) {
                trigger_error('NO_MESSAGE');
            }
            // check for outbox (not read) status, we do not allow editing if one user already having the message
            $sql = 'SELECT p.*, t.folder_id
				FROM ' . PRIVMSGS_TO_TABLE . ' t, ' . PRIVMSGS_TABLE . ' p
				WHERE t.user_id = ' . $user->data['user_id'] . '
					AND t.folder_id = ' . PRIVMSGS_OUTBOX . "\n\t\t\t\t\tAND t.msg_id = {$msg_id}\n\t\t\t\t\tAND t.msg_id = p.msg_id";
            break;
        case 'delete':
            if (!$auth->acl_get('u_pm_delete')) {
                trigger_error('NO_AUTH_DELETE_MESSAGE');
            }
            if (!$msg_id) {
                trigger_error('NO_MESSAGE');
            }
            $sql = 'SELECT msg_id, pm_unread, pm_new, author_id, folder_id
				FROM ' . PRIVMSGS_TO_TABLE . '
				WHERE user_id = ' . $user->data['user_id'] . "\n\t\t\t\t\tAND msg_id = {$msg_id}";
            break;
        case 'smilies':
            generate_smilies('window', 0);
            break;
        default:
            trigger_error('NO_ACTION_MODE', E_USER_ERROR);
            break;
    }
    if ($action == 'forward' && (!$config['forward_pm'] || !$auth->acl_get('u_pm_forward'))) {
        trigger_error('NO_AUTH_FORWARD_MESSAGE');
    }
    if ($action == 'edit' && !$auth->acl_get('u_pm_edit')) {
        trigger_error('NO_AUTH_EDIT_MESSAGE');
    }
    if ($sql) {
        /**
         * Alter sql query to get message for user to write the PM
         *
         * @event core.ucp_pm_compose_compose_pm_basic_info_query_before
         * @var	string	sql						String with the query to be executed
         * @var	array	forum_list				List of forums that contain the posts
         * @var	int		visibility_const		Integer with one of the possible ITEM_* constant values
         * @var	int		msg_id					topic_id in the page request
         * @var	int		to_user_id				The id of whom the message is to
         * @var	int		to_group_id				The id of the group whom the message is to
         * @var	bool	submit					Whether the user is sending the PM or not
         * @var	bool	preview					Whether the user is previewing the PM or not
         * @var	string	action					One of: post, reply, quote, forward, quotepost, edit, delete, smilies
         * @var	bool	delete					Whether the user is deleting the PM
         * @var	int		reply_to_all			Value of reply_to_all request variable.
         * @var	string	limit_time_sql			String with the SQL code to limit the time interval of the post (Note: May be empty string)
         * @var	string	sort_order_sql			String with the ORDER BY SQL code used in this query
         * @since 3.1.0-RC5
         */
        $vars = array('sql', 'forum_list', 'visibility_const', 'msg_id', 'to_user_id', 'to_group_id', 'submit', 'preview', 'action', 'delete', 'reply_to_all', 'limit_time_sql', 'sort_order_sql');
        extract($phpbb_dispatcher->trigger_event('core.ucp_pm_compose_compose_pm_basic_info_query_before', compact($vars)));
        $result = $db->sql_query($sql);
        $post = $db->sql_fetchrow($result);
        $db->sql_freeresult($result);
        if (!$post) {
            // If editing it could be the recipient already read the message...
            if ($action == 'edit') {
                $sql = 'SELECT p.*, t.folder_id
					FROM ' . PRIVMSGS_TO_TABLE . ' t, ' . PRIVMSGS_TABLE . ' p
					WHERE t.user_id = ' . $user->data['user_id'] . "\n\t\t\t\t\t\tAND t.msg_id = {$msg_id}\n\t\t\t\t\t\tAND t.msg_id = p.msg_id";
                $result = $db->sql_query($sql);
                $post = $db->sql_fetchrow($result);
                $db->sql_freeresult($result);
                if ($post) {
                    trigger_error('NO_EDIT_READ_MESSAGE');
                }
            }
            trigger_error('NO_MESSAGE');
        }
        if ($action == 'quotepost') {
            if ($post['forum_id'] && !$auth->acl_get('f_read', $post['forum_id']) || !$post['forum_id'] && !$auth->acl_getf_global('f_read')) {
                trigger_error('NOT_AUTHORISED');
            }
            /**
             * Get the result of querying for the post to be quoted in the pm message
             *
             * @event core.ucp_pm_compose_quotepost_query_after
             * @var	string	sql					The original SQL used in the query
             * @var	array	post				Associative array with the data of the quoted post
             * @var	array	msg_id				The post_id that was searched to get the message for quoting
             * @var	int		visibility_const	Visibility of the quoted post (one of the possible ITEM_* constant values)
             * @var	int		topic_id			Topic ID of the quoted post
             * @var	int		to_user_id			Users the message is sent to
             * @var	int		to_group_id			Groups the message is sent to
             * @var	bool	submit				Whether the user is sending the PM or not
             * @var	bool	preview				Whether the user is previewing the PM or not
             * @var	string	action				One of: post, reply, quote, forward, quotepost, edit, delete, smilies
             * @var	bool	delete				If deleting message
             * @var	int		reply_to_all		Value of reply_to_all request variable.
             * @since 3.1.0-RC5
             */
            $vars = array('sql', 'post', 'msg_id', 'visibility_const', 'topic_id', 'to_user_id', 'to_group_id', 'submit', 'preview', 'action', 'delete', 'reply_to_all');
            extract($phpbb_dispatcher->trigger_event('core.ucp_pm_compose_quotepost_query_after', compact($vars)));
            // Passworded forum?
            if ($post['forum_id']) {
                $sql = 'SELECT forum_id, forum_name, forum_password
					FROM ' . FORUMS_TABLE . '
					WHERE forum_id = ' . (int) $post['forum_id'];
                $result = $db->sql_query($sql);
                $forum_data = $db->sql_fetchrow($result);
                $db->sql_freeresult($result);
                if (!empty($forum_data['forum_password'])) {
                    login_forum_box($forum_data);
                }
            }
        }
        $msg_id = (int) $post['msg_id'];
        $folder_id = isset($post['folder_id']) ? $post['folder_id'] : 0;
        $message_text = isset($post['message_text']) ? $post['message_text'] : '';
        if ((!$post['author_id'] || $post['author_id'] == ANONYMOUS && $action != 'delete') && $msg_id) {
            trigger_error('NO_AUTHOR');
        }
        if ($action == 'quotepost') {
            // Decode text for message display
            decode_message($message_text, $post['bbcode_uid']);
        }
        if ($action != 'delete') {
            $enable_urls = $post['enable_magic_url'];
            $enable_sig = isset($post['enable_sig']) ? $post['enable_sig'] : 0;
            $message_attachment = isset($post['message_attachment']) ? $post['message_attachment'] : 0;
            $message_subject = $post['message_subject'];
            $message_time = $post['message_time'];
            $bbcode_uid = $post['bbcode_uid'];
            $quote_username = isset($post['quote_username']) ? $post['quote_username'] : '';
            $icon_id = isset($post['icon_id']) ? $post['icon_id'] : 0;
            if (($action == 'reply' || $action == 'quote' || $action == 'quotepost') && !sizeof($address_list) && !$refresh && !$submit && !$preview) {
                // Add the original author as the recipient if quoting a post or only replying and not having checked "reply to all"
                if ($action == 'quotepost' || !$reply_to_all) {
                    $address_list = array('u' => array($post['author_id'] => 'to'));
                } else {
                    // We try to include every previously listed member from the TO Header - Reply to all
                    $address_list = rebuild_header(array('to' => $post['to_address']));
                    // Add the author (if he is already listed then this is no shame (it will be overwritten))
                    $address_list['u'][$post['author_id']] = 'to';
                    // Now, make sure the user itself is not listed. ;)
                    if (isset($address_list['u'][$user->data['user_id']])) {
                        unset($address_list['u'][$user->data['user_id']]);
                    }
                }
            } else {
                if ($action == 'edit' && !sizeof($address_list) && !$refresh && !$submit && !$preview) {
                    // Rebuild TO and BCC Header
                    $address_list = rebuild_header(array('to' => $post['to_address'], 'bcc' => $post['bcc_address']));
                }
            }
            if ($action == 'quotepost') {
                $check_value = 0;
            } else {
                $check_value = ($post['enable_bbcode'] + 1 << 8) + ($post['enable_smilies'] + 1 << 4) + ($enable_urls + 1 << 2) + ($post['enable_sig'] + 1 << 1);
            }
        }
    } else {
        $message_attachment = 0;
        $message_text = $message_subject = '';
        if ($to_user_id && $to_user_id != ANONYMOUS && $action == 'post') {
            $address_list['u'][$to_user_id] = 'to';
        } else {
            if ($to_group_id && $action == 'post') {
                $address_list['g'][$to_group_id] = 'to';
            }
        }
        $check_value = 0;
    }
    if (($to_group_id || isset($address_list['g'])) && (!$config['allow_mass_pm'] || !$auth->acl_get('u_masspm_group'))) {
        trigger_error('NO_AUTH_GROUP_MESSAGE');
    }
    if ($action == 'edit' && !$refresh && !$preview && !$submit) {
        if (!($message_time > time() - $config['pm_edit_time'] * 60 || !$config['pm_edit_time'])) {
            trigger_error('CANNOT_EDIT_MESSAGE_TIME');
        }
    }
    if ($action == 'post') {
        $template->assign_var('S_NEW_MESSAGE', true);
    }
    if (!isset($icon_id)) {
        $icon_id = 0;
    }
    $message_parser = new parse_message();
    $plupload = $phpbb_container->get('plupload');
    $message_parser->set_plupload($plupload);
    $message_parser->message = $action == 'reply' ? '' : $message_text;
    unset($message_text);
    $s_action = append_sid("{$phpbb_root_path}ucp.{$phpEx}", "i={$id}&amp;mode={$mode}&amp;action={$action}", true, $user->session_id);
    $s_action .= ($folder_id ? "&amp;f={$folder_id}" : '') . ($msg_id ? "&amp;p={$msg_id}" : '');
    // Delete triggered ?
    if ($action == 'delete') {
        // Folder id has been determined by the SQL Statement
        // $folder_id = request_var('f', PRIVMSGS_NO_BOX);
        // Do we need to confirm ?
        if (confirm_box(true)) {
            delete_pm($user->data['user_id'], $msg_id, $folder_id);
            // jump to next message in "history"? nope, not for the moment. But able to be included later.
            $meta_info = append_sid("{$phpbb_root_path}ucp.{$phpEx}", "i=pm&amp;folder={$folder_id}");
            $message = $user->lang['MESSAGE_DELETED'];
            meta_refresh(3, $meta_info);
            $message .= '<br /><br />' . sprintf($user->lang['RETURN_FOLDER'], '<a href="' . $meta_info . '">', '</a>');
            trigger_error($message);
        } else {
            $s_hidden_fields = array('p' => $msg_id, 'f' => $folder_id, 'action' => 'delete');
            // "{$phpbb_root_path}ucp.$phpEx?i=pm&amp;mode=compose"
            confirm_box(false, 'DELETE_MESSAGE', build_hidden_fields($s_hidden_fields));
        }
        redirect(append_sid("{$phpbb_root_path}ucp.{$phpEx}", 'i=pm&amp;mode=view&amp;action=view_message&amp;p=' . $msg_id));
    }
    // Get maximum number of allowed recipients
    $sql = 'SELECT MAX(g.group_max_recipients) as max_recipients
		FROM ' . GROUPS_TABLE . ' g, ' . USER_GROUP_TABLE . ' ug
		WHERE ug.user_id = ' . $user->data['user_id'] . '
			AND ug.user_pending = 0
			AND ug.group_id = g.group_id';
    $result = $db->sql_query($sql);
    $max_recipients = (int) $db->sql_fetchfield('max_recipients');
    $db->sql_freeresult($result);
    $max_recipients = !$max_recipients ? $config['pm_max_recipients'] : $max_recipients;
    // If this is a quote/reply "to all"... we may increase the max_recpients to the number of original recipients
    if (($action == 'reply' || $action == 'quote') && $max_recipients && $reply_to_all) {
        // We try to include every previously listed member from the TO Header
        $list = rebuild_header(array('to' => $post['to_address']));
        // Can be an empty array too ;)
        $list = !empty($list['u']) ? $list['u'] : array();
        $list[$post['author_id']] = 'to';
        if (isset($list[$user->data['user_id']])) {
            unset($list[$user->data['user_id']]);
        }
        $max_recipients = $max_recipients < sizeof($list) ? sizeof($list) : $max_recipients;
        unset($list);
    }
    // Handle User/Group adding/removing
    handle_message_list_actions($address_list, $error, $remove_u, $remove_g, $add_to, $add_bcc);
    // Check mass pm to group permission
    if ((!$config['allow_mass_pm'] || !$auth->acl_get('u_masspm_group')) && !empty($address_list['g'])) {
        $address_list = array();
        $error[] = $user->lang['NO_AUTH_GROUP_MESSAGE'];
    }
    // Check mass pm to users permission
    if ((!$config['allow_mass_pm'] || !$auth->acl_get('u_masspm')) && num_recipients($address_list) > 1) {
        $address_list = get_recipients($address_list, 1);
        $error[] = $user->lang('TOO_MANY_RECIPIENTS', 1);
    }
    // Check for too many recipients
    if (!empty($address_list['u']) && $max_recipients && sizeof($address_list['u']) > $max_recipients) {
        $address_list = get_recipients($address_list, $max_recipients);
        $error[] = $user->lang('TOO_MANY_RECIPIENTS', $max_recipients);
    }
    // Always check if the submitted attachment data is valid and belongs to the user.
    // Further down (especially in submit_post()) we do not check this again.
    $message_parser->get_submitted_attachment_data();
    if ($message_attachment && !$submit && !$refresh && !$preview && $action == 'edit') {
        // Do not change to SELECT *
        $sql = 'SELECT attach_id, is_orphan, attach_comment, real_filename, filesize
			FROM ' . ATTACHMENTS_TABLE . "\n\t\t\tWHERE post_msg_id = {$msg_id}\n\t\t\t\tAND in_message = 1\n\t\t\t\tAND is_orphan = 0\n\t\t\tORDER BY filetime DESC";
        $result = $db->sql_query($sql);
        $message_parser->attachment_data = array_merge($message_parser->attachment_data, $db->sql_fetchrowset($result));
        $db->sql_freeresult($result);
    }
    if (!in_array($action, array('quote', 'edit', 'delete', 'forward'))) {
        $enable_sig = $config['allow_sig'] && $config['allow_sig_pm'] && $auth->acl_get('u_sig') && $user->optionget('attachsig');
        $enable_smilies = $config['allow_smilies'] && $auth->acl_get('u_pm_smilies') && $user->optionget('smilies');
        $enable_bbcode = $config['allow_bbcode'] && $auth->acl_get('u_pm_bbcode') && $user->optionget('bbcode');
        $enable_urls = true;
    }
    $enable_magic_url = $drafts = false;
    // User own some drafts?
    if ($auth->acl_get('u_savedrafts') && $action != 'delete') {
        $sql = 'SELECT draft_id
			FROM ' . DRAFTS_TABLE . '
			WHERE forum_id = 0
				AND topic_id = 0
				AND user_id = ' . $user->data['user_id'] . ($draft_id ? " AND draft_id <> {$draft_id}" : '');
        $result = $db->sql_query_limit($sql, 1);
        $row = $db->sql_fetchrow($result);
        $db->sql_freeresult($result);
        if ($row) {
            $drafts = true;
        }
    }
    if ($action == 'edit') {
        $message_parser->bbcode_uid = $bbcode_uid;
    }
    $bbcode_status = $config['allow_bbcode'] && $config['auth_bbcode_pm'] && $auth->acl_get('u_pm_bbcode') ? true : false;
    $smilies_status = $config['allow_smilies'] && $config['auth_smilies_pm'] && $auth->acl_get('u_pm_smilies') ? true : false;
    $img_status = $config['auth_img_pm'] && $auth->acl_get('u_pm_img') ? true : false;
    $flash_status = $config['auth_flash_pm'] && $auth->acl_get('u_pm_flash') ? true : false;
    $url_status = $config['allow_post_links'] ? true : false;
    // Save Draft
    if ($save && $auth->acl_get('u_savedrafts')) {
        $subject = utf8_normalize_nfc(request_var('subject', '', true));
        $subject = !$subject && $action != 'post' ? $user->lang['NEW_MESSAGE'] : $subject;
        $message = utf8_normalize_nfc(request_var('message', '', true));
        if ($subject && $message) {
            if (confirm_box(true)) {
                $sql = 'INSERT INTO ' . DRAFTS_TABLE . ' ' . $db->sql_build_array('INSERT', array('user_id' => $user->data['user_id'], 'topic_id' => 0, 'forum_id' => 0, 'save_time' => $current_time, 'draft_subject' => $subject, 'draft_message' => $message));
                $db->sql_query($sql);
                $redirect_url = append_sid("{$phpbb_root_path}ucp.{$phpEx}", "i=pm&amp;mode={$mode}");
                meta_refresh(3, $redirect_url);
                $message = $user->lang['DRAFT_SAVED'] . '<br /><br />' . sprintf($user->lang['RETURN_UCP'], '<a href="' . $redirect_url . '">', '</a>');
                trigger_error($message);
            } else {
                $s_hidden_fields = build_hidden_fields(array('mode' => $mode, 'action' => $action, 'save' => true, 'subject' => $subject, 'message' => $message, 'u' => $to_user_id, 'g' => $to_group_id, 'p' => $msg_id));
                $s_hidden_fields .= build_address_field($address_list);
                confirm_box(false, 'SAVE_DRAFT', $s_hidden_fields);
            }
        } else {
            if (utf8_clean_string($subject) === '') {
                $error[] = $user->lang['EMPTY_MESSAGE_SUBJECT'];
            }
            if (utf8_clean_string($message) === '') {
                $error[] = $user->lang['TOO_FEW_CHARS'];
            }
        }
        unset($subject, $message);
    }
    // Load Draft
    if ($draft_id && $auth->acl_get('u_savedrafts')) {
        $sql = 'SELECT draft_subject, draft_message
			FROM ' . DRAFTS_TABLE . "\n\t\t\tWHERE draft_id = {$draft_id}\n\t\t\t\tAND topic_id = 0\n\t\t\t\tAND forum_id = 0\n\t\t\t\tAND user_id = " . $user->data['user_id'];
        $result = $db->sql_query_limit($sql, 1);
        if ($row = $db->sql_fetchrow($result)) {
            $message_parser->message = $row['draft_message'];
            $message_subject = $row['draft_subject'];
            $template->assign_var('S_DRAFT_LOADED', true);
        } else {
            $draft_id = 0;
        }
        $db->sql_freeresult($result);
    }
    // Load Drafts
    if ($load && $drafts) {
        load_drafts(0, 0, $id, $action, $msg_id);
    }
    if ($submit || $preview || $refresh) {
        if (($submit || $preview) && !check_form_key('ucp_pm_compose')) {
            $error[] = $user->lang['FORM_INVALID'];
        }
        $subject = utf8_normalize_nfc(request_var('subject', '', true));
        $message_parser->message = utf8_normalize_nfc(request_var('message', '', true));
        $icon_id = request_var('icon', 0);
        $enable_bbcode = !$bbcode_status || isset($_POST['disable_bbcode']) ? false : true;
        $enable_smilies = !$smilies_status || isset($_POST['disable_smilies']) ? false : true;
        $enable_urls = isset($_POST['disable_magic_url']) ? 0 : 1;
        $enable_sig = !$config['allow_sig'] || !$config['allow_sig_pm'] ? false : (isset($_POST['attach_sig']) ? true : false);
        if ($submit) {
            $status_switch = ($enable_bbcode + 1 << 8) + ($enable_smilies + 1 << 4) + ($enable_urls + 1 << 2) + ($enable_sig + 1 << 1);
            $status_switch = $status_switch != $check_value;
        } else {
            $status_switch = 1;
        }
        // Parse Attachments - before checksum is calculated
        $message_parser->parse_attachments('fileupload', $action, 0, $submit, $preview, $refresh, true);
        if (sizeof($message_parser->warn_msg) && !($remove_u || $remove_g || $add_to || $add_bcc)) {
            $error[] = implode('<br />', $message_parser->warn_msg);
            $message_parser->warn_msg = array();
        }
        // Parse message
        $message_parser->parse($enable_bbcode, $config['allow_post_links'] ? $enable_urls : false, $enable_smilies, $img_status, $flash_status, true, $config['allow_post_links']);
        // On a refresh we do not care about message parsing errors
        if (sizeof($message_parser->warn_msg) && !$refresh) {
            $error[] = implode('<br />', $message_parser->warn_msg);
        }
        if ($action != 'edit' && !$preview && !$refresh && $config['flood_interval'] && !$auth->acl_get('u_ignoreflood')) {
            // Flood check
            $last_post_time = $user->data['user_lastpost_time'];
            if ($last_post_time) {
                if ($last_post_time && $current_time - $last_post_time < intval($config['flood_interval'])) {
                    $error[] = $user->lang['FLOOD_ERROR'];
                }
            }
        }
        // Subject defined
        if ($submit) {
            if (utf8_clean_string($subject) === '') {
                $error[] = $user->lang['EMPTY_MESSAGE_SUBJECT'];
            }
            if (!sizeof($address_list)) {
                $error[] = $user->lang['NO_RECIPIENT'];
            }
        }
        // Store message, sync counters
        if (!sizeof($error) && $submit) {
            $pm_data = array('msg_id' => (int) $msg_id, 'from_user_id' => $user->data['user_id'], 'from_user_ip' => $user->ip, 'from_username' => $user->data['username'], 'reply_from_root_level' => isset($post['root_level']) ? (int) $post['root_level'] : 0, 'reply_from_msg_id' => (int) $msg_id, 'icon_id' => (int) $icon_id, 'enable_sig' => (bool) $enable_sig, 'enable_bbcode' => (bool) $enable_bbcode, 'enable_smilies' => (bool) $enable_smilies, 'enable_urls' => (bool) $enable_urls, 'bbcode_bitfield' => $message_parser->bbcode_bitfield, 'bbcode_uid' => $message_parser->bbcode_uid, 'message' => $message_parser->message, 'attachment_data' => $message_parser->attachment_data, 'filename_data' => $message_parser->filename_data, 'address_list' => $address_list);
            // ((!$message_subject) ? $subject : $message_subject)
            $msg_id = submit_pm($action, $subject, $pm_data);
            $return_message_url = append_sid("{$phpbb_root_path}ucp.{$phpEx}", 'i=pm&amp;mode=view&amp;p=' . $msg_id);
            $inbox_folder_url = append_sid("{$phpbb_root_path}ucp.{$phpEx}", 'i=pm&amp;folder=inbox');
            $outbox_folder_url = append_sid("{$phpbb_root_path}ucp.{$phpEx}", 'i=pm&amp;folder=outbox');
            $folder_url = '';
            if ($folder_id > 0 && isset($user_folders[$folder_id])) {
                $folder_url = append_sid("{$phpbb_root_path}ucp.{$phpEx}", 'i=pm&amp;folder=' . $folder_id);
            }
            $return_box_url = $action === 'post' || $action === 'edit' ? $outbox_folder_url : $inbox_folder_url;
            $return_box_lang = $action === 'post' || $action === 'edit' ? 'PM_OUTBOX' : 'PM_INBOX';
            $save_message = $action === 'edit' ? $user->lang['MESSAGE_EDITED'] : $user->lang['MESSAGE_STORED'];
            $message = $save_message . '<br /><br />' . $user->lang('VIEW_PRIVATE_MESSAGE', '<a href="' . $return_message_url . '">', '</a>');
            $last_click_type = 'CLICK_RETURN_FOLDER';
            if ($folder_url) {
                $message .= '<br /><br />' . sprintf($user->lang['CLICK_RETURN_FOLDER'], '<a href="' . $folder_url . '">', '</a>', $user_folders[$folder_id]['folder_name']);
                $last_click_type = 'CLICK_GOTO_FOLDER';
            }
            $message .= '<br /><br />' . sprintf($user->lang[$last_click_type], '<a href="' . $return_box_url . '">', '</a>', $user->lang[$return_box_lang]);
            meta_refresh(3, $return_message_url);
            trigger_error($message);
        }
        $message_subject = $subject;
    }
    // Preview
    if (!sizeof($error) && $preview) {
        $preview_message = $message_parser->format_display($enable_bbcode, $enable_urls, $enable_smilies, false);
        $preview_signature = $user->data['user_sig'];
        $preview_signature_uid = $user->data['user_sig_bbcode_uid'];
        $preview_signature_bitfield = $user->data['user_sig_bbcode_bitfield'];
        // Signature
        if ($enable_sig && $config['allow_sig'] && $preview_signature) {
            $parse_sig = new parse_message($preview_signature);
            $parse_sig->bbcode_uid = $preview_signature_uid;
            $parse_sig->bbcode_bitfield = $preview_signature_bitfield;
            $parse_sig->format_display($config['allow_sig_bbcode'], $config['allow_sig_links'], $config['allow_sig_smilies']);
            $preview_signature = $parse_sig->message;
            unset($parse_sig);
        } else {
            $preview_signature = '';
        }
        // Attachment Preview
        if (sizeof($message_parser->attachment_data)) {
            $template->assign_var('S_HAS_ATTACHMENTS', true);
            $update_count = array();
            $attachment_data = $message_parser->attachment_data;
            parse_attachments(false, $preview_message, $attachment_data, $update_count, true);
            foreach ($attachment_data as $i => $attachment) {
                $template->assign_block_vars('attachment', array('DISPLAY_ATTACHMENT' => $attachment));
            }
            unset($attachment_data);
        }
        $preview_subject = censor_text($subject);
        if (!sizeof($error)) {
            $template->assign_vars(array('PREVIEW_SUBJECT' => $preview_subject, 'PREVIEW_MESSAGE' => $preview_message, 'PREVIEW_SIGNATURE' => $preview_signature, 'S_DISPLAY_PREVIEW' => true));
        }
        unset($message_text);
    }
    // Decode text for message display
    $bbcode_uid = ($action == 'quote' || $action == 'forward') && !$preview && !$refresh && (!sizeof($error) || sizeof($error) && !$submit) ? $bbcode_uid : $message_parser->bbcode_uid;
    $message_parser->decode_message($bbcode_uid);
    if (($action == 'quote' || $action == 'quotepost') && !$preview && !$refresh && !$submit) {
        if ($action == 'quotepost') {
            $post_id = request_var('p', 0);
            if ($config['allow_post_links']) {
                $message_link = "[url=" . generate_board_url() . "/viewtopic.{$phpEx}?p={$post_id}#p{$post_id}]{$user->lang['SUBJECT']}{$user->lang['COLON']} {$message_subject}[/url]\n\n";
            } else {
                $message_link = $user->lang['SUBJECT'] . $user->lang['COLON'] . ' ' . $message_subject . " (" . generate_board_url() . "/viewtopic.{$phpEx}?p={$post_id}#p{$post_id})\n\n";
            }
        } else {
            $message_link = '';
        }
        $message_parser->message = $message_link . '[quote=&quot;' . $quote_username . '&quot;]' . censor_text(trim($message_parser->message)) . "[/quote]\n";
    }
    if (($action == 'reply' || $action == 'quote' || $action == 'quotepost') && !$preview && !$refresh) {
        $message_subject = (!preg_match('/^Re:/', $message_subject) ? 'Re: ' : '') . censor_text($message_subject);
    }
    if ($action == 'forward' && !$preview && !$refresh && !$submit) {
        $fwd_to_field = write_pm_addresses(array('to' => $post['to_address']), 0, true);
        if ($config['allow_post_links']) {
            $quote_username_text = '[url=' . generate_board_url() . "/memberlist.{$phpEx}?mode=viewprofile&amp;u={$post['author_id']}]{$quote_username}[/url]";
        } else {
            $quote_username_text = $quote_username . ' (' . generate_board_url() . "/memberlist.{$phpEx}?mode=viewprofile&amp;u={$post['author_id']})";
        }
        $forward_text = array();
        $forward_text[] = $user->lang['FWD_ORIGINAL_MESSAGE'];
        $forward_text[] = sprintf($user->lang['FWD_SUBJECT'], censor_text($message_subject));
        $forward_text[] = sprintf($user->lang['FWD_DATE'], $user->format_date($message_time, false, true));
        $forward_text[] = sprintf($user->lang['FWD_FROM'], $quote_username_text);
        $forward_text[] = sprintf($user->lang['FWD_TO'], implode($user->lang['COMMA_SEPARATOR'], $fwd_to_field['to']));
        $message_parser->message = implode("\n", $forward_text) . "\n\n[quote=&quot;{$quote_username}&quot;]\n" . censor_text(trim($message_parser->message)) . "\n[/quote]";
        $message_subject = (!preg_match('/^Fwd:/', $message_subject) ? 'Fwd: ' : '') . censor_text($message_subject);
    }
    $attachment_data = $message_parser->attachment_data;
    $filename_data = $message_parser->filename_data;
    $message_text = $message_parser->message;
    // MAIN PM PAGE BEGINS HERE
    // Generate smiley listing
    generate_smilies('inline', 0);
    // Generate PM Icons
    $s_pm_icons = false;
    if ($config['enable_pm_icons']) {
        $s_pm_icons = posting_gen_topic_icons($action, $icon_id);
    }
    // Generate inline attachment select box
    posting_gen_inline_attachments($attachment_data);
    // Build address list for display
    // array('u' => array($author_id => 'to'));
    if (sizeof($address_list)) {
        // Get Usernames and Group Names
        $result = array();
        if (!empty($address_list['u'])) {
            $sql = 'SELECT user_id as id, username as name, user_colour as colour
				FROM ' . USERS_TABLE . '
				WHERE ' . $db->sql_in_set('user_id', array_map('intval', array_keys($address_list['u']))) . '
				ORDER BY username_clean ASC';
            $result['u'] = $db->sql_query($sql);
        }
        if (!empty($address_list['g'])) {
            $sql = 'SELECT g.group_id AS id, g.group_name AS name, g.group_colour AS colour, g.group_type
				FROM ' . GROUPS_TABLE . ' g';
            if (!$auth->acl_gets('a_group', 'a_groupadd', 'a_groupdel')) {
                $sql .= ' LEFT JOIN ' . USER_GROUP_TABLE . ' ug
					ON (
						g.group_id = ug.group_id
						AND ug.user_id = ' . $user->data['user_id'] . '
						AND ug.user_pending = 0
					)
					WHERE (g.group_type <> ' . GROUP_HIDDEN . ' OR ug.user_id = ' . $user->data['user_id'] . ')';
            }
            $sql .= $auth->acl_gets('a_group', 'a_groupadd', 'a_groupdel') ? ' WHERE ' : ' AND ';
            $sql .= 'g.group_receive_pm = 1
				AND ' . $db->sql_in_set('g.group_id', array_map('intval', array_keys($address_list['g']))) . '
				ORDER BY g.group_name ASC';
            $result['g'] = $db->sql_query($sql);
        }
        $u = $g = array();
        $_types = array('u', 'g');
        foreach ($_types as $type) {
            if (isset($result[$type]) && $result[$type]) {
                while ($row = $db->sql_fetchrow($result[$type])) {
                    if ($type == 'g') {
                        $row['name'] = $row['group_type'] == GROUP_SPECIAL ? $user->lang['G_' . $row['name']] : $row['name'];
                    }
                    ${$type}[$row['id']] = array('name' => $row['name'], 'colour' => $row['colour']);
                }
                $db->sql_freeresult($result[$type]);
            }
        }
        // Now Build the address list
        $plain_address_field = '';
        foreach ($address_list as $type => $adr_ary) {
            foreach ($adr_ary as $id => $field) {
                if (!isset(${$type}[$id])) {
                    unset($address_list[$type][$id]);
                    continue;
                }
                $field = $field == 'to' ? 'to' : 'bcc';
                $type = $type == 'u' ? 'u' : 'g';
                $id = (int) $id;
                $tpl_ary = array('IS_GROUP' => $type == 'g' ? true : false, 'IS_USER' => $type == 'u' ? true : false, 'UG_ID' => $id, 'NAME' => ${$type}[$id]['name'], 'COLOUR' => ${$type}[$id]['colour'] ? '#' . ${$type}[$id]['colour'] : '', 'TYPE' => $type);
                if ($type == 'u') {
                    $tpl_ary = array_merge($tpl_ary, array('U_VIEW' => get_username_string('profile', $id, ${$type}[$id]['name'], ${$type}[$id]['colour']), 'NAME_FULL' => get_username_string('full', $id, ${$type}[$id]['name'], ${$type}[$id]['colour'])));
                } else {
                    $tpl_ary = array_merge($tpl_ary, array('U_VIEW' => append_sid("{$phpbb_root_path}memberlist.{$phpEx}", 'mode=group&amp;g=' . $id)));
                }
                $template->assign_block_vars($field . '_recipient', $tpl_ary);
            }
        }
    }
    // Build hidden address list
    $s_hidden_address_field = build_address_field($address_list);
    $bbcode_checked = isset($enable_bbcode) ? !$enable_bbcode : ($config['allow_bbcode'] && $auth->acl_get('u_pm_bbcode') ? !$user->optionget('bbcode') : 1);
    $smilies_checked = isset($enable_smilies) ? !$enable_smilies : ($config['allow_smilies'] && $auth->acl_get('u_pm_smilies') ? !$user->optionget('smilies') : 1);
    $urls_checked = isset($enable_urls) ? !$enable_urls : 0;
    $sig_checked = $enable_sig;
    switch ($action) {
        case 'post':
            $page_title = $user->lang['POST_NEW_PM'];
            break;
        case 'quote':
            $page_title = $user->lang['POST_QUOTE_PM'];
            break;
        case 'quotepost':
            $page_title = $user->lang['POST_PM_POST'];
            break;
        case 'reply':
            $page_title = $user->lang['POST_REPLY_PM'];
            break;
        case 'edit':
            $page_title = $user->lang['POST_EDIT_PM'];
            break;
        case 'forward':
            $page_title = $user->lang['POST_FORWARD_PM'];
            break;
        default:
            trigger_error('NO_ACTION_MODE', E_USER_ERROR);
            break;
    }
    $s_hidden_fields = '<input type="hidden" name="lastclick" value="' . $current_time . '" />';
    $s_hidden_fields .= isset($check_value) ? '<input type="hidden" name="status_switch" value="' . $check_value . '" />' : '';
    $s_hidden_fields .= $draft_id || isset($_REQUEST['draft_loaded']) ? '<input type="hidden" name="draft_loaded" value="' . (isset($_REQUEST['draft_loaded']) ? $request->variable('draft_loaded', 0) : $draft_id) . '" />' : '';
    $form_enctype = @ini_get('file_uploads') == '0' || strtolower(@ini_get('file_uploads')) == 'off' || !$config['allow_pm_attach'] || !$auth->acl_get('u_pm_attach') ? '' : ' enctype="multipart/form-data"';
    // Start assigning vars for main posting page ...
    $template->assign_vars(array('L_POST_A' => $page_title, 'L_ICON' => $user->lang['PM_ICON'], 'L_MESSAGE_BODY_EXPLAIN' => $user->lang('MESSAGE_BODY_EXPLAIN', (int) $config['max_post_chars']), 'SUBJECT' => isset($message_subject) ? $message_subject : '', 'MESSAGE' => $message_text, 'BBCODE_STATUS' => $bbcode_status ? sprintf($user->lang['BBCODE_IS_ON'], '<a href="' . append_sid("{$phpbb_root_path}faq.{$phpEx}", 'mode=bbcode') . '">', '</a>') : sprintf($user->lang['BBCODE_IS_OFF'], '<a href="' . append_sid("{$phpbb_root_path}faq.{$phpEx}", 'mode=bbcode') . '">', '</a>'), 'IMG_STATUS' => $img_status ? $user->lang['IMAGES_ARE_ON'] : $user->lang['IMAGES_ARE_OFF'], 'FLASH_STATUS' => $flash_status ? $user->lang['FLASH_IS_ON'] : $user->lang['FLASH_IS_OFF'], 'SMILIES_STATUS' => $smilies_status ? $user->lang['SMILIES_ARE_ON'] : $user->lang['SMILIES_ARE_OFF'], 'URL_STATUS' => $url_status ? $user->lang['URL_IS_ON'] : $user->lang['URL_IS_OFF'], 'MAX_FONT_SIZE' => (int) $config['max_post_font_size'], 'MINI_POST_IMG' => $user->img('icon_post_target', $user->lang['PM']), 'ERROR' => sizeof($error) ? implode('<br />', $error) : '', 'MAX_RECIPIENTS' => $config['allow_mass_pm'] && ($auth->acl_get('u_masspm') || $auth->acl_get('u_masspm_group')) ? $max_recipients : 0, 'S_COMPOSE_PM' => true, 'S_EDIT_POST' => $action == 'edit', 'S_SHOW_PM_ICONS' => $s_pm_icons, 'S_BBCODE_ALLOWED' => $bbcode_status ? 1 : 0, 'S_BBCODE_CHECKED' => $bbcode_checked ? ' checked="checked"' : '', 'S_SMILIES_ALLOWED' => $smilies_status, 'S_SMILIES_CHECKED' => $smilies_checked ? ' checked="checked"' : '', 'S_SIG_ALLOWED' => $config['allow_sig'] && $config['allow_sig_pm'] && $auth->acl_get('u_sig'), 'S_SIGNATURE_CHECKED' => $sig_checked ? ' checked="checked"' : '', 'S_LINKS_ALLOWED' => $url_status, 'S_MAGIC_URL_CHECKED' => $urls_checked ? ' checked="checked"' : '', 'S_SAVE_ALLOWED' => $auth->acl_get('u_savedrafts') && $action != 'edit' ? true : false, 'S_HAS_DRAFTS' => $auth->acl_get('u_savedrafts') && $drafts, 'S_FORM_ENCTYPE' => $form_enctype, 'S_ATTACH_DATA' => json_encode($message_parser->attachment_data), 'S_BBCODE_IMG' => $img_status, 'S_BBCODE_FLASH' => $flash_status, 'S_BBCODE_QUOTE' => true, 'S_BBCODE_URL' => $url_status, 'S_POST_ACTION' => $s_action, 'S_HIDDEN_ADDRESS_FIELD' => $s_hidden_address_field, 'S_HIDDEN_FIELDS' => $s_hidden_fields, 'S_CLOSE_PROGRESS_WINDOW' => isset($_POST['add_file']), 'U_PROGRESS_BAR' => append_sid("{$phpbb_root_path}posting.{$phpEx}", 'f=0&amp;mode=popup'), 'UA_PROGRESS_BAR' => addslashes(append_sid("{$phpbb_root_path}posting.{$phpEx}", 'f=0&amp;mode=popup'))));
    // Build custom bbcodes array
    display_custom_bbcodes();
    // Show attachment box for adding attachments if true
    $allowed = $auth->acl_get('u_pm_attach') && $config['allow_pm_attach'] && $form_enctype;
    if ($allowed) {
        $max_files = $auth->acl_gets('a_', 'm_') ? 0 : (int) $config['max_attachments_pm'];
        $plupload->configure($cache, $template, $s_action, false, $max_files);
    }
    // Attachment entry
    posting_gen_attachment_entry($attachment_data, $filename_data, $allowed);
    // Message History
    if ($action == 'reply' || $action == 'quote' || $action == 'forward') {
        if (message_history($msg_id, $user->data['user_id'], $post, array(), true)) {
            $template->assign_var('S_DISPLAY_HISTORY', true);
        }
    }
}
Example #22
0
    function main($id, $mode)
    {
        global $config, $db, $user, $auth, $template, $phpbb_root_path, $phpEx;
        $user->add_lang('posting');
        $preview = !empty($_POST['preview']) ? true : false;
        $submit = !empty($_POST['submit']) ? true : false;
        $delete = !empty($_POST['delete']) ? true : false;
        $error = $data = array();
        $s_hidden_fields = '';
        switch ($mode) {
            case 'reg_details':
                $data = array('username' => utf8_normalize_nfc(request_var('username', $user->data['username'], true)), 'email' => strtolower(request_var('email', $user->data['user_email'])), 'email_confirm' => strtolower(request_var('email_confirm', '')), 'new_password' => request_var('new_password', '', true), 'cur_password' => request_var('cur_password', '', true), 'password_confirm' => request_var('password_confirm', '', true));
                add_form_key('ucp_reg_details');
                if ($submit) {
                    // Do not check cur_password, it is the old one.
                    $check_ary = array('new_password' => array(array('string', true, $config['min_pass_chars'], $config['max_pass_chars']), array('password')), 'password_confirm' => array('string', true, $config['min_pass_chars'], $config['max_pass_chars']), 'email' => array(array('string', false, 6, 60), array('email')), 'email_confirm' => array('string', true, 6, 60));
                    if ($auth->acl_get('u_chgname') && $config['allow_namechange']) {
                        $check_ary['username'] = array(array('string', false, $config['min_name_chars'], $config['max_name_chars']), array('username'));
                    }
                    $error = validate_data($data, $check_ary);
                    if ($auth->acl_get('u_chgemail') && $data['email'] != $user->data['user_email'] && $data['email_confirm'] != $data['email']) {
                        $error[] = $data['email_confirm'] ? 'NEW_EMAIL_ERROR' : 'NEW_EMAIL_CONFIRM_EMPTY';
                    }
                    if ($auth->acl_get('u_chgpasswd') && $data['new_password'] && $data['password_confirm'] != $data['new_password']) {
                        $error[] = $data['password_confirm'] ? 'NEW_PASSWORD_ERROR' : 'NEW_PASSWORD_CONFIRM_EMPTY';
                    }
                    // Only check the new password against the previous password if there have been no errors
                    if (!sizeof($error) && $auth->acl_get('u_chgpasswd') && $data['new_password'] && phpbb_check_hash($data['new_password'], $user->data['user_password'])) {
                        $error[] = 'SAME_PASSWORD_ERROR';
                    }
                    if (!phpbb_check_hash($data['cur_password'], $user->data['user_password'])) {
                        $error[] = $data['cur_password'] ? 'CUR_PASSWORD_ERROR' : 'CUR_PASSWORD_EMPTY';
                    }
                    if (!check_form_key('ucp_reg_details')) {
                        $error[] = 'FORM_INVALID';
                    }
                    if (!sizeof($error)) {
                        $sql_ary = array('username' => $auth->acl_get('u_chgname') && $config['allow_namechange'] ? $data['username'] : $user->data['username'], 'username_clean' => $auth->acl_get('u_chgname') && $config['allow_namechange'] ? utf8_clean_string($data['username']) : $user->data['username_clean'], 'user_email' => $auth->acl_get('u_chgemail') ? $data['email'] : $user->data['user_email'], 'user_email_hash' => $auth->acl_get('u_chgemail') ? phpbb_email_hash($data['email']) : $user->data['user_email_hash'], 'user_password' => $auth->acl_get('u_chgpasswd') && $data['new_password'] ? phpbb_hash($data['new_password']) : $user->data['user_password'], 'user_passchg' => $auth->acl_get('u_chgpasswd') && $data['new_password'] ? time() : 0);
                        if ($auth->acl_get('u_chgname') && $config['allow_namechange'] && $data['username'] != $user->data['username']) {
                            add_log('user', $user->data['user_id'], 'LOG_USER_UPDATE_NAME', $user->data['username'], $data['username']);
                        }
                        if ($auth->acl_get('u_chgpasswd') && $data['new_password'] && !phpbb_check_hash($data['new_password'], $user->data['user_password'])) {
                            $user->reset_login_keys();
                            add_log('user', $user->data['user_id'], 'LOG_USER_NEW_PASSWORD', $data['username']);
                        }
                        if ($auth->acl_get('u_chgemail') && $data['email'] != $user->data['user_email']) {
                            add_log('user', $user->data['user_id'], 'LOG_USER_UPDATE_EMAIL', $data['username'], $user->data['user_email'], $data['email']);
                        }
                        $message = 'PROFILE_UPDATED';
                        if ($auth->acl_get('u_chgemail') && $config['email_enable'] && $data['email'] != $user->data['user_email'] && $user->data['user_type'] != USER_FOUNDER && ($config['require_activation'] == USER_ACTIVATION_SELF || $config['require_activation'] == USER_ACTIVATION_ADMIN)) {
                            $message = $config['require_activation'] == USER_ACTIVATION_SELF ? 'ACCOUNT_EMAIL_CHANGED' : 'ACCOUNT_EMAIL_CHANGED_ADMIN';
                            include_once $phpbb_root_path . 'includes/functions_messenger.' . $phpEx;
                            $server_url = generate_board_url();
                            $user_actkey = gen_rand_string(mt_rand(6, 10));
                            $messenger = new messenger(false);
                            $template_file = $config['require_activation'] == USER_ACTIVATION_ADMIN ? 'user_activate_inactive' : 'user_activate';
                            $messenger->template($template_file, $user->data['user_lang']);
                            $messenger->to($data['email'], $data['username']);
                            $messenger->anti_abuse_headers($config, $user);
                            $messenger->assign_vars(array('USERNAME' => htmlspecialchars_decode($data['username']), 'U_ACTIVATE' => "{$server_url}/ucp.{$phpEx}?mode=activate&u={$user->data['user_id']}&k={$user_actkey}"));
                            $messenger->send(NOTIFY_EMAIL);
                            if ($config['require_activation'] == USER_ACTIVATION_ADMIN) {
                                // Grab an array of user_id's with a_user permissions ... these users can activate a user
                                $admin_ary = $auth->acl_get_list(false, 'a_user', false);
                                $admin_ary = !empty($admin_ary[0]['a_user']) ? $admin_ary[0]['a_user'] : array();
                                // Also include founders
                                $where_sql = ' WHERE user_type = ' . USER_FOUNDER;
                                if (sizeof($admin_ary)) {
                                    $where_sql .= ' OR ' . $db->sql_in_set('user_id', $admin_ary);
                                }
                                $sql = 'SELECT user_id, username, user_email, user_lang, user_jabber, user_notify_type
									FROM ' . USERS_TABLE . ' ' . $where_sql;
                                $result = $db->sql_query($sql);
                                while ($row = $db->sql_fetchrow($result)) {
                                    $messenger->template('admin_activate', $row['user_lang']);
                                    $messenger->to($row['user_email'], $row['username']);
                                    $messenger->im($row['user_jabber'], $row['username']);
                                    $messenger->assign_vars(array('USERNAME' => htmlspecialchars_decode($data['username']), 'U_USER_DETAILS' => "{$server_url}/memberlist.{$phpEx}?mode=viewprofile&u={$user->data['user_id']}", 'U_ACTIVATE' => "{$server_url}/ucp.{$phpEx}?mode=activate&u={$user->data['user_id']}&k={$user_actkey}"));
                                    $messenger->send($row['user_notify_type']);
                                }
                                $db->sql_freeresult($result);
                            }
                            user_active_flip('deactivate', $user->data['user_id'], INACTIVE_PROFILE);
                            // Because we want the profile to be reactivated we set user_newpasswd to empty (else the reactivation will fail)
                            $sql_ary['user_actkey'] = $user_actkey;
                            $sql_ary['user_newpasswd'] = '';
                        }
                        if (sizeof($sql_ary)) {
                            $sql = 'UPDATE ' . USERS_TABLE . '
								SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
								WHERE user_id = ' . $user->data['user_id'];
                            $db->sql_query($sql);
                        }
                        // Need to update config, forum, topic, posting, messages, etc.
                        if ($data['username'] != $user->data['username'] && $auth->acl_get('u_chgname') && $config['allow_namechange']) {
                            user_update_name($user->data['username'], $data['username']);
                        }
                        // Now, we can remove the user completely (kill the session) - NOT BEFORE!!!
                        if (!empty($sql_ary['user_actkey'])) {
                            meta_refresh(5, append_sid($phpbb_root_path . 'index.' . $phpEx));
                            $message = $user->lang[$message] . '<br /><br />' . sprintf($user->lang['RETURN_INDEX'], '<a href="' . append_sid($phpbb_root_path . 'index.' . $phpEx) . '">', '</a>');
                            // Because the user gets deactivated we log him out too, killing his session
                            $user->session_kill();
                        } else {
                            meta_refresh(3, $this->u_action);
                            $message = $user->lang[$message] . '<br /><br />' . sprintf($user->lang['RETURN_UCP'], '<a href="' . $this->u_action . '">', '</a>');
                        }
                        trigger_error($message);
                    }
                    // Replace "error" strings with their real, localised form
                    $error = preg_replace('#^([A-Z_]+)$#e', "(!empty(\$user->lang['\\1'])) ? \$user->lang['\\1'] : '\\1'", $error);
                }
                $template->assign_vars(array('ERROR' => sizeof($error) ? implode('<br />', $error) : '', 'USERNAME' => $data['username'], 'EMAIL' => $data['email'], 'PASSWORD_CONFIRM' => $data['password_confirm'], 'NEW_PASSWORD' => $data['new_password'], 'CUR_PASSWORD' => '', 'L_USERNAME_EXPLAIN' => sprintf($user->lang[$config['allow_name_chars'] . '_EXPLAIN'], $config['min_name_chars'], $config['max_name_chars']), 'L_CHANGE_PASSWORD_EXPLAIN' => sprintf($user->lang[$config['pass_complex'] . '_EXPLAIN'], $config['min_pass_chars'], $config['max_pass_chars']), 'S_FORCE_PASSWORD' => $auth->acl_get('u_chgpasswd') && $config['chg_passforce'] && $user->data['user_passchg'] < time() - $config['chg_passforce'] * 86400 ? true : false, 'S_CHANGE_USERNAME' => $config['allow_namechange'] && $auth->acl_get('u_chgname') ? true : false, 'S_CHANGE_EMAIL' => $auth->acl_get('u_chgemail') ? true : false, 'S_CHANGE_PASSWORD' => $auth->acl_get('u_chgpasswd') ? true : false));
                break;
            case 'profile_info':
                include $phpbb_root_path . 'includes/functions_profile_fields.' . $phpEx;
                $cp = new custom_profile();
                $cp_data = $cp_error = array();
                $data = array('icq' => request_var('icq', $user->data['user_icq']), 'aim' => request_var('aim', $user->data['user_aim']), 'msn' => request_var('msn', $user->data['user_msnm']), 'yim' => request_var('yim', $user->data['user_yim']), 'jabber' => utf8_normalize_nfc(request_var('jabber', $user->data['user_jabber'], true)), 'website' => request_var('website', $user->data['user_website']), 'location' => utf8_normalize_nfc(request_var('location', $user->data['user_from'], true)), 'occupation' => utf8_normalize_nfc(request_var('occupation', $user->data['user_occ'], true)), 'interests' => utf8_normalize_nfc(request_var('interests', $user->data['user_interests'], true)));
                if ($config['allow_birthdays']) {
                    $data['bday_day'] = $data['bday_month'] = $data['bday_year'] = 0;
                    if ($user->data['user_birthday']) {
                        list($data['bday_day'], $data['bday_month'], $data['bday_year']) = explode('-', $user->data['user_birthday']);
                    }
                    $data['bday_day'] = request_var('bday_day', $data['bday_day']);
                    $data['bday_month'] = request_var('bday_month', $data['bday_month']);
                    $data['bday_year'] = request_var('bday_year', $data['bday_year']);
                    $data['user_birthday'] = sprintf('%2d-%2d-%4d', $data['bday_day'], $data['bday_month'], $data['bday_year']);
                }
                add_form_key('ucp_profile_info');
                if ($submit) {
                    $validate_array = array('icq' => array(array('string', true, 3, 15), array('match', true, '#^[0-9]+$#i')), 'aim' => array('string', true, 3, 255), 'msn' => array('string', true, 5, 255), 'jabber' => array(array('string', true, 5, 255), array('jabber')), 'yim' => array('string', true, 5, 255), 'website' => array(array('string', true, 12, 255), array('match', true, '#^http[s]?://(.*?\\.)*?[a-z0-9\\-]+\\.[a-z]{2,4}#i')), 'location' => array('string', true, 2, 100), 'occupation' => array('string', true, 2, 500), 'interests' => array('string', true, 2, 500));
                    if ($config['allow_birthdays']) {
                        $validate_array = array_merge($validate_array, array('bday_day' => array('num', true, 1, 31), 'bday_month' => array('num', true, 1, 12), 'bday_year' => array('num', true, 1901, gmdate('Y', time()) + 50), 'user_birthday' => array('date', true)));
                    }
                    $error = validate_data($data, $validate_array);
                    // validate custom profile fields
                    $cp->submit_cp_field('profile', $user->get_iso_lang_id(), $cp_data, $cp_error);
                    if (sizeof($cp_error)) {
                        $error = array_merge($error, $cp_error);
                    }
                    if (!check_form_key('ucp_profile_info')) {
                        $error[] = 'FORM_INVALID';
                    }
                    if (!sizeof($error)) {
                        $data['notify'] = $user->data['user_notify_type'];
                        if ($data['notify'] == NOTIFY_IM && (!$config['jab_enable'] || !$data['jabber'] || !@extension_loaded('xml'))) {
                            // User has not filled in a jabber address (Or one of the modules is disabled or jabber is disabled)
                            // Disable notify by Jabber now for this user.
                            $data['notify'] = NOTIFY_EMAIL;
                        }
                        $sql_ary = array('user_icq' => $data['icq'], 'user_aim' => $data['aim'], 'user_msnm' => $data['msn'], 'user_yim' => $data['yim'], 'user_jabber' => $data['jabber'], 'user_website' => $data['website'], 'user_from' => $data['location'], 'user_occ' => $data['occupation'], 'user_interests' => $data['interests'], 'user_notify_type' => $data['notify']);
                        if ($config['allow_birthdays']) {
                            $sql_ary['user_birthday'] = $data['user_birthday'];
                        }
                        $sql = 'UPDATE ' . USERS_TABLE . '
							SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
							WHERE user_id = ' . $user->data['user_id'];
                        $db->sql_query($sql);
                        // Update Custom Fields
                        $cp->update_profile_field_data($user->data['user_id'], $cp_data);
                        meta_refresh(3, $this->u_action);
                        $message = $user->lang['PROFILE_UPDATED'] . '<br /><br />' . sprintf($user->lang['RETURN_UCP'], '<a href="' . $this->u_action . '">', '</a>');
                        trigger_error($message);
                    }
                    // Replace "error" strings with their real, localised form
                    $error = preg_replace('#^([A-Z_]+)$#e', "(!empty(\$user->lang['\\1'])) ? \$user->lang['\\1'] : '\\1'", $error);
                }
                if ($config['allow_birthdays']) {
                    $s_birthday_day_options = '<option value="0"' . (!$data['bday_day'] ? ' selected="selected"' : '') . '>--</option>';
                    for ($i = 1; $i < 32; $i++) {
                        $selected = $i == $data['bday_day'] ? ' selected="selected"' : '';
                        $s_birthday_day_options .= "<option value=\"{$i}\"{$selected}>{$i}</option>";
                    }
                    $s_birthday_month_options = '<option value="0"' . (!$data['bday_month'] ? ' selected="selected"' : '') . '>--</option>';
                    for ($i = 1; $i < 13; $i++) {
                        $selected = $i == $data['bday_month'] ? ' selected="selected"' : '';
                        $s_birthday_month_options .= "<option value=\"{$i}\"{$selected}>{$i}</option>";
                    }
                    $s_birthday_year_options = '';
                    $now = getdate();
                    $s_birthday_year_options = '<option value="0"' . (!$data['bday_year'] ? ' selected="selected"' : '') . '>--</option>';
                    for ($i = $now['year'] - 100; $i <= $now['year']; $i++) {
                        $selected = $i == $data['bday_year'] ? ' selected="selected"' : '';
                        $s_birthday_year_options .= "<option value=\"{$i}\"{$selected}>{$i}</option>";
                    }
                    unset($now);
                    $template->assign_vars(array('S_BIRTHDAY_DAY_OPTIONS' => $s_birthday_day_options, 'S_BIRTHDAY_MONTH_OPTIONS' => $s_birthday_month_options, 'S_BIRTHDAY_YEAR_OPTIONS' => $s_birthday_year_options, 'S_BIRTHDAYS_ENABLED' => true));
                }
                $template->assign_vars(array('ERROR' => sizeof($error) ? implode('<br />', $error) : '', 'ICQ' => $data['icq'], 'YIM' => $data['yim'], 'AIM' => $data['aim'], 'MSN' => $data['msn'], 'JABBER' => $data['jabber'], 'WEBSITE' => $data['website'], 'LOCATION' => $data['location'], 'OCCUPATION' => $data['occupation'], 'INTERESTS' => $data['interests']));
                // Get additional profile fields and assign them to the template block var 'profile_fields'
                $user->get_profile_fields($user->data['user_id']);
                $cp->generate_profile_fields('profile', $user->get_iso_lang_id());
                break;
            case 'signature':
                if (!$auth->acl_get('u_sig')) {
                    trigger_error('NO_AUTH_SIGNATURE');
                }
                include $phpbb_root_path . 'includes/functions_posting.' . $phpEx;
                include $phpbb_root_path . 'includes/functions_display.' . $phpEx;
                $enable_bbcode = $config['allow_sig_bbcode'] ? (bool) $user->optionget('sig_bbcode') : false;
                $enable_smilies = $config['allow_sig_smilies'] ? (bool) $user->optionget('sig_smilies') : false;
                $enable_urls = $config['allow_sig_links'] ? (bool) $user->optionget('sig_links') : false;
                $signature = utf8_normalize_nfc(request_var('signature', (string) $user->data['user_sig'], true));
                add_form_key('ucp_sig');
                if ($submit || $preview) {
                    include $phpbb_root_path . 'includes/message_parser.' . $phpEx;
                    $enable_bbcode = $config['allow_sig_bbcode'] ? request_var('disable_bbcode', false) ? false : true : false;
                    $enable_smilies = $config['allow_sig_smilies'] ? request_var('disable_smilies', false) ? false : true : false;
                    $enable_urls = $config['allow_sig_links'] ? request_var('disable_magic_url', false) ? false : true : false;
                    if (!sizeof($error)) {
                        $message_parser = new parse_message($signature);
                        // Allowing Quote BBCode
                        $message_parser->parse($enable_bbcode, $enable_urls, $enable_smilies, $config['allow_sig_img'], $config['allow_sig_flash'], true, $config['allow_sig_links'], true, 'sig');
                        if (sizeof($message_parser->warn_msg)) {
                            $error[] = implode('<br />', $message_parser->warn_msg);
                        }
                        if (!check_form_key('ucp_sig')) {
                            $error[] = 'FORM_INVALID';
                        }
                        if (!sizeof($error) && $submit) {
                            $user->optionset('sig_bbcode', $enable_bbcode);
                            $user->optionset('sig_smilies', $enable_smilies);
                            $user->optionset('sig_links', $enable_urls);
                            $sql_ary = array('user_sig' => (string) $message_parser->message, 'user_options' => $user->data['user_options'], 'user_sig_bbcode_uid' => (string) $message_parser->bbcode_uid, 'user_sig_bbcode_bitfield' => $message_parser->bbcode_bitfield);
                            $sql = 'UPDATE ' . USERS_TABLE . '
								SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
								WHERE user_id = ' . $user->data['user_id'];
                            $db->sql_query($sql);
                            $message = $user->lang['PROFILE_UPDATED'] . '<br /><br />' . sprintf($user->lang['RETURN_UCP'], '<a href="' . $this->u_action . '">', '</a>');
                            trigger_error($message);
                        }
                    }
                    // Replace "error" strings with their real, localised form
                    $error = preg_replace('#^([A-Z_]+)$#e', "(!empty(\$user->lang['\\1'])) ? \$user->lang['\\1'] : '\\1'", $error);
                }
                $signature_preview = '';
                if ($preview) {
                    // Now parse it for displaying
                    $signature_preview = $message_parser->format_display($enable_bbcode, $enable_urls, $enable_smilies, false);
                    unset($message_parser);
                }
                decode_message($signature, $user->data['user_sig_bbcode_uid']);
                $template->assign_vars(array('ERROR' => sizeof($error) ? implode('<br />', $error) : '', 'SIGNATURE' => $signature, 'SIGNATURE_PREVIEW' => $signature_preview, 'S_BBCODE_CHECKED' => !$enable_bbcode ? ' checked="checked"' : '', 'S_SMILIES_CHECKED' => !$enable_smilies ? ' checked="checked"' : '', 'S_MAGIC_URL_CHECKED' => !$enable_urls ? ' checked="checked"' : '', 'BBCODE_STATUS' => $config['allow_sig_bbcode'] ? sprintf($user->lang['BBCODE_IS_ON'], '<a href="' . append_sid("{$phpbb_root_path}faq.{$phpEx}", 'mode=bbcode') . '">', '</a>') : sprintf($user->lang['BBCODE_IS_OFF'], '<a href="' . append_sid("{$phpbb_root_path}faq.{$phpEx}", 'mode=bbcode') . '">', '</a>'), 'SMILIES_STATUS' => $config['allow_sig_smilies'] ? $user->lang['SMILIES_ARE_ON'] : $user->lang['SMILIES_ARE_OFF'], 'IMG_STATUS' => $config['allow_sig_img'] ? $user->lang['IMAGES_ARE_ON'] : $user->lang['IMAGES_ARE_OFF'], 'FLASH_STATUS' => $config['allow_sig_flash'] ? $user->lang['FLASH_IS_ON'] : $user->lang['FLASH_IS_OFF'], 'URL_STATUS' => $config['allow_sig_links'] ? $user->lang['URL_IS_ON'] : $user->lang['URL_IS_OFF'], 'MAX_FONT_SIZE' => (int) $config['max_sig_font_size'], 'L_SIGNATURE_EXPLAIN' => sprintf($user->lang['SIGNATURE_EXPLAIN'], $config['max_sig_chars']), 'S_BBCODE_ALLOWED' => $config['allow_sig_bbcode'], 'S_SMILIES_ALLOWED' => $config['allow_sig_smilies'], 'S_BBCODE_IMG' => $config['allow_sig_img'] ? true : false, 'S_BBCODE_FLASH' => $config['allow_sig_flash'] ? true : false, 'S_LINKS_ALLOWED' => $config['allow_sig_links'] ? true : false));
                // Build custom bbcodes array
                display_custom_bbcodes();
                break;
            case 'avatar':
                include $phpbb_root_path . 'includes/functions_display.' . $phpEx;
                $display_gallery = request_var('display_gallery', '0');
                $avatar_select = basename(request_var('avatar_select', ''));
                $category = basename(request_var('category', ''));
                $can_upload = file_exists($phpbb_root_path . $config['avatar_path']) && phpbb_is_writable($phpbb_root_path . $config['avatar_path']) && $auth->acl_get('u_chgavatar') && (@ini_get('file_uploads') || strtolower(@ini_get('file_uploads')) == 'on') ? true : false;
                add_form_key('ucp_avatar');
                if ($submit) {
                    if (check_form_key('ucp_avatar')) {
                        if (avatar_process_user($error, false, $can_upload)) {
                            meta_refresh(3, $this->u_action);
                            $message = $user->lang['PROFILE_UPDATED'] . '<br /><br />' . sprintf($user->lang['RETURN_UCP'], '<a href="' . $this->u_action . '">', '</a>');
                            trigger_error($message);
                        }
                    } else {
                        $error[] = 'FORM_INVALID';
                    }
                    // Replace "error" strings with their real, localised form
                    $error = preg_replace('#^([A-Z_]+)$#e', "(!empty(\$user->lang['\\1'])) ? \$user->lang['\\1'] : '\\1'", $error);
                }
                if (!$config['allow_avatar'] && $user->data['user_avatar_type']) {
                    $error[] = $user->lang['AVATAR_NOT_ALLOWED'];
                } else {
                    if ($user->data['user_avatar_type'] == AVATAR_UPLOAD && !$config['allow_avatar_upload'] || $user->data['user_avatar_type'] == AVATAR_REMOTE && !$config['allow_avatar_remote'] || $user->data['user_avatar_type'] == AVATAR_GALLERY && !$config['allow_avatar_local']) {
                        $error[] = $user->lang['AVATAR_TYPE_NOT_ALLOWED'];
                    }
                }
                $template->assign_vars(array('ERROR' => sizeof($error) ? implode('<br />', $error) : '', 'AVATAR' => get_user_avatar($user->data['user_avatar'], $user->data['user_avatar_type'], $user->data['user_avatar_width'], $user->data['user_avatar_height'], 'USER_AVATAR', true), 'AVATAR_SIZE' => $config['avatar_filesize'], 'U_GALLERY' => append_sid("{$phpbb_root_path}ucp.{$phpEx}", 'i=profile&amp;mode=avatar&amp;display_gallery=1'), 'S_FORM_ENCTYPE' => $can_upload && ($config['allow_avatar_upload'] || $config['allow_avatar_remote_upload']) ? ' enctype="multipart/form-data"' : '', 'L_AVATAR_EXPLAIN' => sprintf($user->lang['AVATAR_EXPLAIN'], $config['avatar_max_width'], $config['avatar_max_height'], $config['avatar_filesize'] / 1024)));
                if ($config['allow_avatar'] && $display_gallery && $auth->acl_get('u_chgavatar') && $config['allow_avatar_local']) {
                    avatar_gallery($category, $avatar_select, 4);
                } else {
                    if ($config['allow_avatar']) {
                        $avatars_enabled = $can_upload && ($config['allow_avatar_upload'] || $config['allow_avatar_remote_upload']) || $auth->acl_get('u_chgavatar') && ($config['allow_avatar_local'] || $config['allow_avatar_remote']) ? true : false;
                        $template->assign_vars(array('AVATAR_WIDTH' => request_var('width', $user->data['user_avatar_width']), 'AVATAR_HEIGHT' => request_var('height', $user->data['user_avatar_height']), 'S_AVATARS_ENABLED' => $avatars_enabled, 'S_UPLOAD_AVATAR_FILE' => $can_upload && $config['allow_avatar_upload'] ? true : false, 'S_UPLOAD_AVATAR_URL' => $can_upload && $config['allow_avatar_remote_upload'] ? true : false, 'S_LINK_AVATAR' => $auth->acl_get('u_chgavatar') && $config['allow_avatar_remote'] ? true : false, 'S_DISPLAY_GALLERY' => $auth->acl_get('u_chgavatar') && $config['allow_avatar_local'] ? true : false));
                    }
                }
                break;
        }
        $template->assign_vars(array('L_TITLE' => $user->lang['UCP_PROFILE_' . strtoupper($mode)], 'S_HIDDEN_FIELDS' => $s_hidden_fields, 'S_UCP_ACTION' => $this->u_action));
        // Set desired template
        $this->tpl_name = 'ucp_profile_' . $mode;
        $this->page_title = 'UCP_PROFILE_' . strtoupper($mode);
    }
/**
* For parsing custom parsed text to be stored within the database.
* This function additionally returns the uid and bitfield that needs to be stored.
* Expects $text to be the value directly from request_var() and in it's non-parsed form
*
* @param string $text The text to be replaced with the parsed one
* @param string $uid The BBCode uid for this parse
* @param string $bitfield The BBCode bitfield for this parse
* @param int $flags The allow_bbcode, allow_urls and allow_smilies compiled into a single integer.
* @param bool $allow_bbcode If BBCode is allowed (i.e. if BBCode is parsed)
* @param bool $allow_urls If urls is allowed
* @param bool $allow_smilies If smilies are allowed
*
* @return array	An array of string with the errors that occurred while parsing
*/
function generate_text_for_storage(&$text, &$uid, &$bitfield, &$flags, $allow_bbcode = false, $allow_urls = false, $allow_smilies = false)
{
    global $phpbb_root_path, $phpEx, $phpbb_dispatcher;
    /**
     * Use this event to modify the text before it is prepared for storage
     *
     * @event core.modify_text_for_storage_before
     * @var string	text			The text to parse
     * @var string	uid				The BBCode UID
     * @var string	bitfield		The BBCode Bitfield
     * @var int		flags			The BBCode Flags
     * @var bool		allow_bbcode	Whether or not to parse BBCode
     * @var bool		allow_urls		Whether or not to parse URLs
     * @var bool		allow_smilies	Whether or not to parse Smilies
     * @since 3.1.0-a1
     */
    $vars = array('text', 'uid', 'bitfield', 'flags', 'allow_bbcode', 'allow_urls', 'allow_smilies');
    extract($phpbb_dispatcher->trigger_event('core.modify_text_for_storage_before', compact($vars)));
    $uid = $bitfield = '';
    $flags = ($allow_bbcode ? OPTION_FLAG_BBCODE : 0) + ($allow_smilies ? OPTION_FLAG_SMILIES : 0) + ($allow_urls ? OPTION_FLAG_LINKS : 0);
    if ($text === '') {
        return;
    }
    if (!class_exists('parse_message')) {
        include $phpbb_root_path . 'includes/message_parser.' . $phpEx;
    }
    $message_parser = new parse_message($text);
    $message_parser->parse($allow_bbcode, $allow_urls, $allow_smilies);
    $text = $message_parser->message;
    $uid = $message_parser->bbcode_uid;
    // If the bbcode_bitfield is empty, there is no need for the uid to be stored.
    if (!$message_parser->bbcode_bitfield) {
        $uid = '';
    }
    $bitfield = $message_parser->bbcode_bitfield;
    /**
     * Use this event to modify the text after it is prepared for storage
     *
     * @event core.modify_text_for_storage_after
     * @var string	text			The text to parse
     * @var string	uid				The BBCode UID
     * @var string	bitfield		The BBCode Bitfield
     * @var int		flags			The BBCode Flags
     * @since 3.1.0-a1
     */
    $vars = array('text', 'uid', 'bitfield', 'flags');
    extract($phpbb_dispatcher->trigger_event('core.modify_text_for_storage_after', compact($vars)));
    return $message_parser->warn_msg;
}
Example #24
0
 $_RESULT['success'] = true;
 //$parser = new parse_message(utf8_normalize_nfc($text));
 //$parser->parse(true, true, true);
 //$o_m    = $parser->format_display(true, true, true, false);
 //$uid = $bitfield = $options = '';
 //$allow_bbcode = $allow_urls = $allow_smilies = true;
 //generate_text_for_storage($text, $uid, $bitfield, $options, $allow_bbcode, $allow_urls, $allow_smilies);
 //if ($bitfield)
 ////{
 //	$bbcode->bbcode_second_pass($text, $uid, $bitfield);
 //}
 //$text = bbcode_nl2br($text);
 //$text = smiley_text($text);
 // Parse and display new post text
 if ($user->data['user_id'] != 1) {
     $parser = new parse_message(utf8_normalize_nfc($text));
     $parser->parse(true, true, true);
     $content = $parser->format_display(true, true, true, false);
 }
 //else
 //{
 //$content = generate_text_for_display($text, $uid, $bitfield, 7);
 //}
 //$o_m = preg_replace(array('#<object(.*?)object>#is',
 //				  '#<embed(.*?)embed>#is',
 //	              '#<object(.*?)embed>#is',
 //	              '#<embed(.*?)object>#is',
 //				  '#<script(.*?)script>#is',
 //				  '#<video(.*?)video>#is',
 //                  '#<audio(.*?)audio>#is',
 //                  '#<source(.*?)source>#is',
Example #25
0
// Polls
$blog_data->get_polls($blog_id);
$poll_option_text = $original_poll_text = '';
$poll_options = array();
foreach (blog_data::$blog[$blog_id]['poll_options'] as $row) {
    $poll_option_text .= $row['poll_option_text'] . "\n";
    $poll_options[] = $row['poll_option_text'];
}
decode_message($poll_option_text, blog_data::$blog[$blog_id]['bbcode_uid']);
$original_poll_text = $poll_option_text;
if ($submit || $preview || $refresh) {
    $blog_subject = utf8_normalize_nfc(request_var('subject', '', true));
    $blog_text = utf8_normalize_nfc(request_var('message', '', true));
    $post_options->set_status(!isset($_POST['disable_bbcode']), !isset($_POST['disable_smilies']), !isset($_POST['disable_magic_url']));
    // set up the message parser to parse BBCode, Smilies, etc
    $message_parser = new parse_message();
    $message_parser->message = $blog_text;
    $message_parser->parse($post_options->enable_bbcode, $post_options->enable_magic_url, $post_options->enable_smilies, $post_options->img_status, $post_options->flash_status, $post_options->bbcode_status, $post_options->url_status);
    // Check the basic posting data
    $error = handle_basic_posting_data(true, 'blog', 'edit');
    // If they did not include a subject, give them the empty subject error
    if ($blog_subject == '' && !$refresh) {
        $error[] = $user->lang['EMPTY_SUBJECT'];
    }
    // Polls
    $poll_title = utf8_normalize_nfc(request_var('poll_title', '', true));
    $poll_length = request_var('poll_length', 0);
    $poll_option_text = utf8_normalize_nfc(request_var('poll_option_text', '', true));
    $poll_max_options = request_var('poll_max_options', 1);
    $poll_vote_change = isset($_POST['poll_vote_change']) ? 1 : 0;
    if ($poll_option_text && $auth->acl_get('u_blog_create_poll') && !isset($_POST['poll_delete'])) {
Example #26
0
$post_data['poll_options'] = array();
// Get Poll Data
if ($post_data['poll_start']) {
    $sql = 'SELECT poll_option_text
		FROM ' . POLL_OPTIONS_TABLE . "\n\t\tWHERE topic_id = {$topic_id}\n\t\tORDER BY poll_option_id";
    $result = $db->sql_query($sql);
    while ($row = $db->sql_fetchrow($result)) {
        $post_data['poll_options'][] = trim($row['poll_option_text']);
    }
    $db->sql_freeresult($result);
}
if ($mode == 'edit') {
    $original_poll_data = array('poll_title' => $post_data['poll_title'], 'poll_length' => $post_data['poll_length'], 'poll_max_options' => $post_data['poll_max_options'], 'poll_option_text' => implode("\n", $post_data['poll_options']), 'poll_start' => $post_data['poll_start'], 'poll_last_vote' => $post_data['poll_last_vote'], 'poll_vote_change' => $post_data['poll_vote_change']);
}
$orig_poll_options_size = sizeof($post_data['poll_options']);
$message_parser = new parse_message();
$plupload = $phpbb_container->get('plupload');
$mimetype_guesser = $phpbb_container->get('mimetype.guesser');
$message_parser->set_plupload($plupload);
$message_parser->set_mimetype_guesser($mimetype_guesser);
if (isset($post_data['post_text'])) {
    $message_parser->message =& $post_data['post_text'];
    unset($post_data['post_text']);
}
// Set some default variables
$uninit = array('post_attachment' => 0, 'poster_id' => $user->data['user_id'], 'enable_magic_url' => 0, 'topic_status' => 0, 'topic_type' => POST_NORMAL, 'post_subject' => '', 'topic_title' => '', 'post_time' => 0, 'post_edit_reason' => '', 'notify_set' => 0);
foreach ($uninit as $var_name => $default_value) {
    if (!isset($post_data[$var_name])) {
        $post_data[$var_name] = $default_value;
    }
}
Example #27
0
    function main($id, $mode)
    {
        global $config, $db, $user, $auth, $template, $cache;
        global $phpbb_root_path, $phpbb_admin_path, $phpEx, $table_prefix, $file_uploads;
        $user->add_lang(array('posting', 'ucp', 'acp/users'));
        $this->tpl_name = 'acp_users';
        $this->page_title = 'ACP_USER_' . strtoupper($mode);
        include $phpbb_root_path . 'includes/functions_user.' . $phpEx;
        include $phpbb_root_path . 'includes/functions_profile_fields.' . $phpEx;
        $error = array();
        $username = request_var('username', '', true);
        $user_id = request_var('u', 0);
        $action = request_var('action', '');
        $submit = isset($_POST['update']) ? true : false;
        // Whois (special case)
        if ($action == 'whois') {
            $this->page_title = 'WHOIS';
            $this->tpl_name = 'simple_body';
            $user_ip = request_var('user_ip', '');
            $domain = gethostbyaddr($user_ip);
            $ipwhois = '';
            if ($ipwhois = user_ipwhois($user_ip)) {
                $ipwhois = preg_replace('#(\\s)([\\w\\-\\._\\+]+@[\\w\\-\\.]+)(\\s)#', '\\1<a href="mailto:\\2">\\2</a>\\3', $ipwhois);
                $ipwhois = preg_replace('#(\\s)(http:/{2}[^\\s]*)(\\s)#', '\\1<a href="\\2" target="_blank">\\2</a>\\3', $ipwhois);
            }
            $template->assign_vars(array('MESSAGE_TITLE' => sprintf($user->lang['IP_WHOIS_FOR'], $domain), 'MESSAGE_TEXT' => nl2br($ipwhois)));
            return;
        }
        // Show user selection mask
        if (!$username && !$user_id) {
            $this->page_title = 'SELECT_USER';
            $template->assign_vars(array('U_ACTION' => $this->u_action, 'ANONYMOUS_USER_ID' => ANONYMOUS, 'S_SELECT_USER' => true, 'U_FIND_USERNAME' => append_sid("{$phpbb_root_path}memberlist.{$phpEx}", 'mode=searchuser&amp;form=select_user&amp;field=username')));
            return;
        }
        if (!$user_id) {
            $sql = 'SELECT user_id
				FROM ' . USERS_TABLE . "\n\t\t\t\tWHERE username = '******'";
            $result = $db->sql_query($sql);
            $user_id = (int) $db->sql_fetchfield('user_id');
            $db->sql_freeresult($result);
            if (!$user_id) {
                trigger_error($user->lang['NO_USER'] . adm_back_link($this->u_action));
            }
        }
        // Generate content for all modes
        $sql = 'SELECT u.*, s.*
			FROM ' . USERS_TABLE . ' u
				LEFT JOIN ' . SESSIONS_TABLE . ' s ON (s.session_user_id = u.user_id)
			WHERE u.user_id = ' . $user_id . '
			ORDER BY s.session_time DESC';
        $result = $db->sql_query($sql);
        $user_row = $db->sql_fetchrow($result);
        $db->sql_freeresult($result);
        if (!$user_row) {
            trigger_error($user->lang['NO_USER'] . adm_back_link($this->u_action));
        }
        // Generate overall "header" for user admin
        $s_form_options = '';
        // Include info file...
        include_once $phpbb_root_path . 'includes/acp/info/acp_users.' . $phpEx;
        $forms_ary = acp_users_info::module();
        foreach ($forms_ary['modes'] as $value => $ary) {
            if (!$this->is_authed($ary['auth'])) {
                continue;
            }
            $selected = $mode == $value ? ' selected="selected"' : '';
            $s_form_options .= '<option value="' . $value . '"' . $selected . '>' . $user->lang['ACP_USER_' . strtoupper($value)] . '</option>';
        }
        $template->assign_vars(array('U_BACK' => $this->u_action, 'U_MODE_SELECT' => append_sid("{$phpbb_admin_path}index.{$phpEx}", "i={$id}&amp;u={$user_id}"), 'U_ACTION' => $this->u_action . '&amp;u=' . $user_id, 'S_FORM_OPTIONS' => $s_form_options));
        // Prevent normal users/admins change/view founders if they are not a founder by themselves
        if ($user->data['user_type'] != USER_FOUNDER && $user_row['user_type'] == USER_FOUNDER) {
            trigger_error($user->lang['NOT_MANAGE_FOUNDER'] . adm_back_link($this->u_action));
        }
        switch ($mode) {
            case 'overview':
                $delete = request_var('delete', 0);
                $delete_type = request_var('delete_type', '');
                $ip = request_var('ip', 'ip');
                if ($submit) {
                    // You can't delete the founder
                    if ($delete && $user_row['user_type'] != USER_FOUNDER) {
                        if (!$auth->acl_get('a_userdel')) {
                            trigger_error($user->lang['NO_ADMIN'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
                        }
                        // Check if the user wants to remove himself or the guest user account
                        if ($user_id == ANONYMOUS) {
                            trigger_error($user->lang['CANNOT_REMOVE_ANONYMOUS'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
                        }
                        if ($user_id == $user->data['user_id']) {
                            trigger_error($user->lang['CANNOT_REMOVE_YOURSELF'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
                        }
                        if (confirm_box(true)) {
                            user_delete($delete_type, $user_id);
                            add_log('admin', 'LOG_USER_DELETED', $user_row['username']);
                            trigger_error($user->lang['USER_DELETED'] . adm_back_link($this->u_action));
                        } else {
                            confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array('u' => $user_id, 'i' => $id, 'mode' => $mode, 'action' => $action, 'update' => true, 'delete' => 1, 'delete_type' => $delete_type)));
                        }
                    }
                    // Handle quicktool actions
                    switch ($action) {
                        case 'banuser':
                        case 'banemail':
                        case 'banip':
                            $ban = array();
                            switch ($action) {
                                case 'banuser':
                                    $ban[] = $user_row['username'];
                                    $reason = 'USER_ADMIN_BAN_NAME_REASON';
                                    $log = 'LOG_USER_BAN_USER';
                                    break;
                                case 'banemail':
                                    $ban[] = $user_row['user_email'];
                                    $reason = 'USER_ADMIN_BAN_EMAIL_REASON';
                                    $log = 'LOG_USER_BAN_EMAIL';
                                    break;
                                case 'banip':
                                    $ban[] = $user_row['user_ip'];
                                    $sql = 'SELECT DISTINCT poster_ip
										FROM ' . POSTS_TABLE . "\n\t\t\t\t\t\t\t\t\t\tWHERE poster_id = {$user_id}";
                                    $result = $db->sql_query($sql);
                                    while ($row = $db->sql_fetchrow($result)) {
                                        $ban[] = $row['poster_ip'];
                                    }
                                    $db->sql_freeresult($result);
                                    $reason = 'USER_ADMIN_BAN_IP_REASON';
                                    $log = 'LOG_USER_BAN_IP';
                                    break;
                            }
                            user_ban(substr($action, 3), $ban, 0, 0, 0, $user->lang[$reason]);
                            add_log('admin', $log, $user->lang[$reason]);
                            add_log('user', $user_id, $log, $user->lang[$reason]);
                            trigger_error($user->lang['BAN_SUCCESSFUL'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
                            break;
                        case 'reactivate':
                            if ($config['email_enable']) {
                                include_once $phpbb_root_path . 'includes/functions_messenger.' . $phpEx;
                                $server_url = generate_board_url();
                                $user_actkey = gen_rand_string(10);
                                $key_len = 54 - strlen($server_url);
                                $key_len = $key_len > 6 ? $key_len : 6;
                                $user_actkey = substr($user_actkey, 0, $key_len);
                                if ($user_row['user_type'] != USER_INACTIVE) {
                                    user_active_flip($user_id, $user_row['user_type'], $user_actkey, $user_row['username']);
                                }
                                $messenger = new messenger(false);
                                $messenger->template('user_resend_inactive', $user_row['user_lang']);
                                $messenger->replyto($config['board_contact']);
                                $messenger->to($user_row['user_email'], $user_row['username']);
                                $messenger->headers('X-AntiAbuse: Board servername - ' . $config['server_name']);
                                $messenger->headers('X-AntiAbuse: User_id - ' . $user->data['user_id']);
                                $messenger->headers('X-AntiAbuse: Username - ' . $user->data['username']);
                                $messenger->headers('X-AntiAbuse: User IP - ' . $user->ip);
                                $messenger->assign_vars(array('SITENAME' => $config['sitename'], 'WELCOME_MSG' => sprintf($user->lang['WELCOME_SUBJECT'], $config['sitename']), 'USERNAME' => html_entity_decode($user_row['username']), 'EMAIL_SIG' => str_replace('<br />', "\n", "-- \n" . $config['board_email_sig']), 'U_ACTIVATE' => "{$server_url}/ucp.{$phpEx}?mode=activate&u={$user_row['user_id']}&k={$user_actkey}"));
                                $messenger->send(NOTIFY_EMAIL);
                                add_log('admin', 'LOG_USER_REACTIVATE', $user_row['username']);
                                add_log('user', $user_id, 'LOG_USER_REACTIVATE_USER');
                                trigger_error($user->lang['FORCE_REACTIVATION_SUCCESS'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
                            }
                            break;
                        case 'active':
                            user_active_flip($user_id, $user_row['user_type'], false, $user_row['username']);
                            $message = $user_row['user_type'] == USER_INACTIVE ? 'USER_ADMIN_ACTIVATED' : 'USER_ADMIN_DEACTIVED';
                            $log = $user_row['user_type'] == USER_INACTIVE ? 'LOG_USER_ACTIVE' : 'LOG_USER_INACTIVE';
                            add_log('user', $user_id, $log . '_USER');
                            if ($user_row['user_type'] == USER_INACTIVE) {
                                set_config('num_users', $config['num_users'] + 1, true);
                            } else {
                                set_config('num_users', $config['num_users'] - 1, true);
                            }
                            // Update latest username
                            update_last_username();
                            trigger_error($user->lang[$message] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
                            break;
                        case 'delsig':
                            $sql_ary = array('user_sig' => '', 'user_sig_bbcode_uid' => '', 'user_sig_bbcode_bitfield' => 0);
                            $sql = 'UPDATE ' . USERS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . "\n\t\t\t\t\t\t\t\tWHERE user_id = {$user_id}";
                            $db->sql_query($sql);
                            add_log('admin', 'LOG_USER_DEL_SIG', $user_row['username']);
                            add_log('user', $user_id, 'LOG_USER_DEL_SIG_USER');
                            trigger_error($user->lang['USER_ADMIN_SIG_REMOVED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
                            break;
                        case 'delavatar':
                            $sql_ary = array('user_avatar' => '', 'user_avatar_type' => 0, 'user_avatar_width' => 0, 'user_avatar_height' => 0);
                            $sql = 'UPDATE ' . USERS_TABLE . '
								SET ' . $db->sql_build_array('UPDATE', $sql_ary) . "\n\t\t\t\t\t\t\t\tWHERE user_id = {$user_id}";
                            $db->sql_query($sql);
                            // Delete old avatar if present
                            if ($user_row['user_avatar'] && $user_row['user_avatar_type'] != AVATAR_GALLERY) {
                                avatar_delete($user_row['user_avatar']);
                            }
                            add_log('admin', 'LOG_USER_DEL_AVATAR', $user_row['username']);
                            add_log('user', $user_id, 'LOG_USER_DEL_AVATAR_USER');
                            trigger_error($user->lang['USER_ADMIN_AVATAR_REMOVED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
                            break;
                        case 'delposts':
                            if (confirm_box(true)) {
                                $sql = 'SELECT topic_id, COUNT(post_id) AS total_posts
									FROM ' . POSTS_TABLE . "\n\t\t\t\t\t\t\t\t\tWHERE poster_id = {$user_id}\n\t\t\t\t\t\t\t\t\tGROUP BY topic_id";
                                $result = $db->sql_query($sql);
                                $topic_id_ary = array();
                                while ($row = $db->sql_fetchrow($result)) {
                                    $topic_id_ary[$row['topic_id']] = $row['total_posts'];
                                }
                                $db->sql_freeresult($result);
                                if (sizeof($topic_id_ary)) {
                                    $sql = 'SELECT topic_id, topic_replies, topic_replies_real
										FROM ' . TOPICS_TABLE . '
										WHERE topic_id IN (' . implode(', ', array_keys($topic_id_ary)) . ')';
                                    $result = $db->sql_query($sql);
                                    $del_topic_ary = array();
                                    while ($row = $db->sql_fetchrow($result)) {
                                        if (max($row['topic_replies'], $row['topic_replies_real']) + 1 == $topic_id_ary[$row['topic_id']]) {
                                            $del_topic_ary[] = $row['topic_id'];
                                        }
                                    }
                                    $db->sql_freeresult($result);
                                    if (sizeof($del_topic_ary)) {
                                        $sql = 'DELETE FROM ' . TOPICS_TABLE . '
											WHERE topic_id IN (' . implode(', ', $del_topic_ary) . ')';
                                        $db->sql_query($sql);
                                    }
                                }
                                // Delete posts, attachments, etc.
                                delete_posts('poster_id', $user_id);
                                add_log('admin', 'LOG_USER_DEL_POSTS', $user_row['username']);
                                trigger_error($user->lang['USER_POSTS_DELETED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
                            } else {
                                confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array('u' => $user_id, 'i' => $id, 'mode' => $mode, 'action' => $action, 'update' => true)));
                            }
                            break;
                        case 'delattach':
                            if (confirm_box(true)) {
                                delete_attachments('user', $user_id);
                                add_log('admin', 'LOG_USER_DEL_ATTACH', $user_row['username']);
                                trigger_error($user->lang['USER_ATTACHMENTS_REMOVED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
                            } else {
                                confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array('u' => $user_id, 'i' => $id, 'mode' => $mode, 'action' => $action, 'update' => true)));
                            }
                            break;
                        case 'moveposts':
                            $new_forum_id = request_var('new_f', 0);
                            if (!$new_forum_id) {
                                $this->page_title = 'USER_ADMIN_MOVE_POSTS';
                                $template->assign_vars(array('S_SELECT_FORUM' => true, 'U_ACTION' => $this->u_action . "&amp;action={$action}&amp;u={$user_id}", 'U_BACK' => $this->u_action . "&amp;u={$user_id}", 'S_FORUM_OPTIONS' => make_forum_select(false, false, false, true)));
                                return;
                            }
                            // Two stage?
                            // Move topics comprising only posts from this user
                            $topic_id_ary = $move_topic_ary = $move_post_ary = $new_topic_id_ary = array();
                            $forum_id_ary = array($new_forum_id);
                            $sql = 'SELECT topic_id, COUNT(post_id) AS total_posts
								FROM ' . POSTS_TABLE . "\n\t\t\t\t\t\t\t\tWHERE poster_id = {$user_id}\n\t\t\t\t\t\t\t\t\tAND forum_id <> {$new_forum_id}\n\t\t\t\t\t\t\t\tGROUP BY topic_id";
                            $result = $db->sql_query($sql);
                            while ($row = $db->sql_fetchrow($result)) {
                                $topic_id_ary[$row['topic_id']] = $row['total_posts'];
                            }
                            $db->sql_freeresult($result);
                            if (sizeof($topic_id_ary)) {
                                $sql = 'SELECT topic_id, forum_id, topic_title, topic_replies, topic_replies_real
									FROM ' . TOPICS_TABLE . '
									WHERE topic_id IN (' . implode(', ', array_keys($topic_id_ary)) . ')';
                                $result = $db->sql_query($sql);
                                while ($row = $db->sql_fetchrow($result)) {
                                    if (max($row['topic_replies'], $row['topic_replies_real']) + 1 == $topic_id_ary[$row['topic_id']]) {
                                        $move_topic_ary[] = $row['topic_id'];
                                    } else {
                                        $move_post_ary[$row['topic_id']]['title'] = $row['topic_title'];
                                        $move_post_ary[$row['topic_id']]['attach'] = $row['attach'] ? 1 : 0;
                                    }
                                    $forum_id_ary[] = $row['forum_id'];
                                }
                                $db->sql_freeresult($result);
                            }
                            // Entire topic comprises posts by this user, move these topics
                            if (sizeof($move_topic_ary)) {
                                move_topics($move_topic_ary, $new_forum_id, false);
                            }
                            if (sizeof($move_post_ary)) {
                                // Create new topic
                                // Update post_ids, report_ids, attachment_ids
                                foreach ($move_post_ary as $topic_id => $post_ary) {
                                    // Create new topic
                                    $sql = 'INSERT INTO ' . TOPICS_TABLE . ' ' . $db->sql_build_array('INSERT', array('topic_poster' => $user_id, 'topic_time' => time(), 'forum_id' => $new_forum_id, 'icon_id' => 0, 'topic_approved' => 1, 'topic_title' => $post_ary['title'], 'topic_first_poster_name' => $user_row['username'], 'topic_type' => POST_NORMAL, 'topic_time_limit' => 0, 'topic_attachment' => $post_ary['attach']));
                                    $db->sql_query($sql);
                                    $new_topic_id = $db->sql_nextid();
                                    // Move posts
                                    $sql = 'UPDATE ' . POSTS_TABLE . "\n\t\t\t\t\t\t\t\t\t\tSET forum_id = {$new_forum_id}, topic_id = {$new_topic_id}\n\t\t\t\t\t\t\t\t\t\tWHERE topic_id = {$topic_id}\n\t\t\t\t\t\t\t\t\t\t\tAND poster_id = {$user_id}";
                                    $db->sql_query($sql);
                                    if ($post_ary['attach']) {
                                        $sql = 'UPDATE ' . ATTACHMENTS_TABLE . "\n\t\t\t\t\t\t\t\t\t\t\tSET topic_id = {$new_topic_id}\n\t\t\t\t\t\t\t\t\t\t\tWHERE topic_id = {$topic_id}\n\t\t\t\t\t\t\t\t\t\t\t\tAND poster_id = {$user_id}";
                                        $db->sql_query($sql);
                                    }
                                    $new_topic_id_ary[] = $new_topic_id;
                                }
                            }
                            $forum_id_ary = array_unique($forum_id_ary);
                            $topic_id_ary = array_unique(array_merge($topic_id_ary, $new_topic_id_ary));
                            if (sizeof($topic_id_ary)) {
                                sync('reported', 'topic_id', $topic_id_ary);
                                sync('topic', 'topic_id', $topic_id_ary);
                            }
                            if (sizeof($forum_id_ary)) {
                                sync('forum', 'forum_id', $forum_id_ary);
                            }
                            $sql = 'SELECT forum_name
								FROM ' . FORUMS_TABLE . "\n\t\t\t\t\t\t\t\tWHERE forum_id = {$new_forum_id}";
                            $result = $db->sql_query($sql, 3600);
                            $forum_info = $db->sql_fetchrow($result);
                            $db->sql_freeresult($result);
                            add_log('admin', 'LOG_USER_MOVE_POSTS', $user_row['username'], $forum_info['forum_name']);
                            add_log('user', $user_id, 'LOG_USER_MOVE_POSTS_USER', $forum_info['forum_name']);
                            trigger_error($user->lang['USER_POSTS_MOVED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
                            break;
                    }
                    $data = array();
                    // Handle registration info updates
                    $var_ary = array('user' => (string) $user_row['username'], 'user_founder' => (int) ($user_row['user_type'] == USER_FOUNDER ? 1 : 0), 'user_email' => (string) $user_row['user_email'], 'email_confirm' => (string) '', 'user_password' => (string) '', 'password_confirm' => (string) '', 'warnings' => (int) $user_row['user_warnings']);
                    // Get the data from the form. Use data from the database if no info is provided
                    foreach ($var_ary as $var => $default) {
                        $data[$var] = request_var($var, $default);
                    }
                    // We use user within the form to circumvent auto filling
                    $data['username'] = $data['user'];
                    unset($data['user']);
                    // Validation data
                    $var_ary = array('password_confirm' => array('string', true, $config['min_pass_chars'], $config['max_pass_chars']), 'user_password' => array('string', true, $config['min_pass_chars'], $config['max_pass_chars']), 'warnings' => array('num'));
                    // Check username if altered
                    if ($data['username'] != $user_row['username']) {
                        $var_ary += array('username' => array(array('string', false, $config['min_name_chars'], $config['max_name_chars']), array('username', $user_row['username'])));
                    }
                    // Check email if altered
                    if ($data['user_email'] != $user_row['user_email']) {
                        $var_ary += array('user_email' => array(array('string', false, 6, 60), array('email', $user_row['user_email'])), 'email_confirm' => array('string', true, 6, 60));
                    }
                    $error = validate_data($data, $var_ary);
                    if ($data['user_password'] && $data['password_confirm'] != $data['user_password']) {
                        $error[] = 'NEW_PASSWORD_ERROR';
                    }
                    if ($data['user_email'] != $user_row['user_email'] && $data['email_confirm'] != $data['user_email']) {
                        $error[] = 'NEW_EMAIL_ERROR';
                    }
                    // Which updates do we need to do?
                    $update_warning = $user_row['user_warnings'] != $data['warnings'] ? true : false;
                    $update_username = $user_row['username'] != $data['username'] ? $data['username'] : false;
                    $update_password = $data['user_password'] && $user_row['user_password'] != md5($data['user_password']) ? true : false;
                    $update_email = $data['user_email'] != $user_row['user_email'] ? $data['user_email'] : false;
                    if (!sizeof($error)) {
                        $sql_ary = array();
                        if ($user_row['user_type'] != USER_FOUNDER || $user->data['user_type'] == USER_FOUNDER) {
                            if ($update_warning) {
                                $sql_ary['user_warnings'] = $data['warnings'];
                            }
                            if ($user_row['user_type'] == USER_FOUNDER && !$data['user_founder'] || $user_row['user_type'] != USER_FOUNDER && $data['user_founder']) {
                                $sql_ary['user_type'] = $data['user_founder'] ? USER_FOUNDER : USER_NORMAL;
                            }
                        }
                        if ($update_username !== false) {
                            $sql_ary['username'] = $update_username;
                            add_log('user', $user_id, 'LOG_USER_UPDATE_NAME', $user_row['username'], $update_username);
                        }
                        if ($update_email !== false) {
                            $sql_ary += array('user_email' => $update_email, 'user_email_hash' => crc32(strtolower($update_email)) . strlen($update_email));
                            add_log('user', $user_id, 'LOG_USER_UPDATE_EMAIL', $user_row['username'], $user_row['user_email'], $update_email);
                        }
                        if ($update_password) {
                            $sql_ary += array('user_password' => md5($data['user_password']), 'user_passchg' => time());
                            $user->reset_login_keys($user_id);
                            add_log('user', $user_id, 'LOG_USER_NEW_PASSWORD', $user_row['username']);
                        }
                        if (sizeof($sql_ary)) {
                            $sql = 'UPDATE ' . USERS_TABLE . '
								SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
								WHERE user_id = ' . $user_id;
                            $db->sql_query($sql);
                        }
                        /**
                         * @todo adjust every data based in the number of user warnings
                         */
                        if ($update_warning) {
                        }
                        if ($update_username) {
                            user_update_name($user_row['username'], $update_username);
                        }
                        add_log('admin', 'LOG_USER_USER_UPDATE', $data['username']);
                        trigger_error($user->lang['USER_OVERVIEW_UPDATED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
                    }
                    // Replace "error" strings with their real, localised form
                    $error = preg_replace('#^([A-Z_]+)$#e', "(!empty(\$user->lang['\\1'])) ? \$user->lang['\\1'] : '\\1'", $error);
                }
                $user_char_ary = array('.*' => 'USERNAME_CHARS_ANY', '[\\w]+' => 'USERNAME_ALPHA_ONLY', '[\\w_\\+\\. \\-\\[\\]]+' => 'USERNAME_ALPHA_SPACERS');
                $quick_tool_ary = array('banuser' => 'BAN_USER', 'banemail' => 'BAN_EMAIL', 'banip' => 'BAN_IP', 'active' => $user_row['user_type'] == USER_INACTIVE ? 'ACTIVATE' : 'DEACTIVATE', 'delsig' => 'DEL_SIG', 'delavatar' => 'DEL_AVATAR', 'moveposts' => 'MOVE_POSTS', 'delposts' => 'DEL_POSTS', 'delattach' => 'DEL_ATTACH');
                if ($config['email_enable']) {
                    $quick_tool_ary['reactivate'] = 'FORCE';
                }
                $s_action_options = '<option class="sep" value="">' . $user->lang['SELECT_OPTION'] . '</option>';
                foreach ($quick_tool_ary as $value => $lang) {
                    $s_action_options .= '<option value="' . $value . '">' . $user->lang['USER_ADMIN_' . $lang] . '</option>';
                }
                $template->assign_vars(array('L_NAME_CHARS_EXPLAIN' => sprintf($user->lang[$user_char_ary[$config['allow_name_chars']] . '_EXPLAIN'], $config['min_name_chars'], $config['max_name_chars']), 'L_CHANGE_PASSWORD_EXPLAIN' => sprintf($user->lang['CHANGE_PASSWORD_EXPLAIN'], $config['min_pass_chars'], $config['max_pass_chars']), 'S_FOUNDER' => $user->data['user_type'] == USER_FOUNDER ? true : false, 'S_OVERVIEW' => true, 'S_USER_IP' => $user_row['user_ip'] ? true : false, 'S_USER_FOUNDER' => $user_row['user_type'] == USER_FOUNDER ? true : false, 'S_ACTION_OPTIONS' => $s_action_options, 'U_SHOW_IP' => $this->u_action . "&amp;u={$user_id}&amp;ip=" . ($ip == 'ip' ? 'hostname' : 'ip'), 'U_WHOIS' => $this->u_action . "&amp;action=whois&amp;user_ip={$user_row['user_ip']}", 'U_SWITCH_PERMISSIONS' => $auth->acl_get('a_switchperm') && $user->data['user_id'] != $user_row['user_id'] ? append_sid("{$phpbb_root_path}ucp.{$phpEx}", "mode=switch_perm&amp;u={$user_row['user_id']}") : '', 'USER' => $user_row['username'], 'USER_REGISTERED' => $user->format_date($user_row['user_regdate']), 'REGISTERED_IP' => $ip == 'hostname' ? gethostbyaddr($user_row['user_ip']) : $user_row['user_ip'], 'USER_LASTACTIVE' => $user_row['user_lastvisit'] ? $user->format_date($user_row['user_lastvisit']) : ' - ', 'USER_EMAIL' => $user_row['user_email'], 'USER_WARNINGS' => $user_row['user_warnings']));
                break;
            case 'feedback':
                $user->add_lang('mcp');
                // Set up general vars
                $start = request_var('start', 0);
                $deletemark = isset($_POST['delmarked']) ? true : false;
                $deleteall = isset($_POST['delall']) ? true : false;
                $marked = request_var('mark', array(0));
                $message = request_var('message', '', true);
                // Sort keys
                $sort_days = request_var('st', 0);
                $sort_key = request_var('sk', 't');
                $sort_dir = request_var('sd', 'd');
                // Delete entries if requested and able
                if (($deletemark || $deleteall) && $auth->acl_get('a_clearlogs')) {
                    $where_sql = '';
                    if ($deletemark && $marked) {
                        $sql_in = array();
                        foreach ($marked as $mark) {
                            $sql_in[] = $mark;
                        }
                        $where_sql = ' AND log_id IN (' . implode(', ', $sql_in) . ')';
                        unset($sql_in);
                    }
                    if ($where_sql || $deleteall) {
                        $sql = 'DELETE FROM ' . LOG_TABLE . '
							WHERE log_type = ' . LOG_USERS . "\n\t\t\t\t\t\t\t{$where_sql}";
                        $db->sql_query($sql);
                        add_log('admin', 'LOG_CLEAR_USER', $user_row['username']);
                    }
                }
                if ($submit && $message) {
                    add_log('admin', 'LOG_USER_FEEDBACK', $user_row['username']);
                    add_log('user', $user_id, 'LOG_USER_GENERAL', $message);
                    trigger_error($user->lang['USER_FEEDBACK_ADDED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
                }
                // Sorting
                $limit_days = array(0 => $user->lang['ALL_ENTRIES'], 1 => $user->lang['1_DAY'], 7 => $user->lang['7_DAYS'], 14 => $user->lang['2_WEEKS'], 30 => $user->lang['1_MONTH'], 90 => $user->lang['3_MONTHS'], 180 => $user->lang['6_MONTHS'], 365 => $user->lang['1_YEAR']);
                $sort_by_text = array('u' => $user->lang['SORT_USERNAME'], 't' => $user->lang['SORT_DATE'], 'i' => $user->lang['SORT_IP'], 'o' => $user->lang['SORT_ACTION']);
                $sort_by_sql = array('u' => 'l.user_id', 't' => 'l.log_time', 'i' => 'l.log_ip', 'o' => 'l.log_operation');
                $s_limit_days = $s_sort_key = $s_sort_dir = $u_sort_param = '';
                gen_sort_selects($limit_days, $sort_by_text, $sort_days, $sort_key, $sort_dir, $s_limit_days, $s_sort_key, $s_sort_dir, $u_sort_param);
                // Define where and sort sql for use in displaying logs
                $sql_where = $sort_days ? time() - $sort_days * 86400 : 0;
                $sql_sort = $sort_by_sql[$sort_key] . ' ' . ($sort_dir == 'd' ? 'DESC' : 'ASC');
                // Grab log data
                $log_data = array();
                $log_count = 0;
                view_log('user', $log_data, $log_count, $config['topics_per_page'], $start, 0, 0, $user_id, $sql_where, $sql_sort);
                $template->assign_vars(array('S_FEEDBACK' => true, 'S_ON_PAGE' => on_page($log_count, $config['topics_per_page'], $start), 'PAGINATION' => generate_pagination($this->u_action . "&amp;u={$user_id}&amp;{$u_sort_param}", $log_count, $config['topics_per_page'], $start, true), 'S_LIMIT_DAYS' => $s_limit_days, 'S_SORT_KEY' => $s_sort_key, 'S_SORT_DIR' => $s_sort_dir, 'S_CLEARLOGS' => $auth->acl_get('a_clearlogs')));
                foreach ($log_data as $row) {
                    $template->assign_block_vars('log', array('USERNAME' => $row['username'], 'IP' => $row['ip'], 'DATE' => $user->format_date($row['time']), 'ACTION' => nl2br($row['action']), 'ID' => $row['id']));
                }
                break;
            case 'profile':
                $cp = new custom_profile();
                $cp_data = $cp_error = array();
                $data = array();
                $sql = 'SELECT lang_id
					FROM ' . LANG_TABLE . "\n\t\t\t\t\tWHERE lang_iso = '" . $db->sql_escape($user_row['user_lang']) . "'";
                $result = $db->sql_query($sql);
                $row = $db->sql_fetchrow($result);
                $db->sql_freeresult($result);
                $user_row['iso_lang_id'] = $row['lang_id'];
                if ($submit) {
                    $var_ary = array('icq' => (string) '', 'aim' => (string) '', 'msn' => (string) '', 'yim' => (string) '', 'jabber' => (string) '', 'website' => (string) '', 'location' => (string) '', 'occupation' => (string) '', 'interests' => (string) '', 'bday_day' => 0, 'bday_month' => 0, 'bday_year' => 0);
                    foreach ($var_ary as $var => $default) {
                        $data[$var] = in_array($var, array('location', 'occupation', 'interests')) ? request_var($var, $default, true) : ($data[$var] = request_var($var, $default));
                    }
                    $var_ary = array('icq' => array(array('string', true, 3, 15), array('match', true, '#^[0-9]+$#i')), 'aim' => array('string', true, 3, 17), 'msn' => array('string', true, 5, 255), 'jabber' => array(array('string', true, 5, 255), array('match', true, '#^[a-z0-9\\.\\-_\\+]+?@(.*?\\.)*?[a-z0-9\\-_]+?\\.[a-z]{2,4}(/.*)?$#i')), 'yim' => array('string', true, 5, 255), 'website' => array(array('string', true, 12, 255), array('match', true, '#^http[s]?://(.*?\\.)*?[a-z0-9\\-]+\\.[a-z]{2,4}#i')), 'location' => array('string', true, 2, 255), 'occupation' => array('string', true, 2, 500), 'interests' => array('string', true, 2, 500), 'bday_day' => array('num', true, 1, 31), 'bday_month' => array('num', true, 1, 12), 'bday_year' => array('num', true, 1901, gmdate('Y', time())));
                    $error = validate_data($data, $var_ary);
                    // validate custom profile fields
                    $cp->submit_cp_field('profile', $user_row['iso_lang_id'], $cp_data, $cp_error);
                    if (sizeof($cp_error)) {
                        $error = array_merge($error, $cp_error);
                    }
                    if (!sizeof($error)) {
                        $sql_ary = array('user_icq' => $data['icq'], 'user_aim' => $data['aim'], 'user_msnm' => $data['msn'], 'user_yim' => $data['yim'], 'user_jabber' => $data['jabber'], 'user_website' => $data['website'], 'user_from' => $data['location'], 'user_occ' => $data['occupation'], 'user_interests' => $data['interests'], 'user_birthday' => sprintf('%2d-%2d-%4d', $data['bday_day'], $data['bday_month'], $data['bday_year']));
                        $sql = 'UPDATE ' . USERS_TABLE . '
							SET ' . $db->sql_build_array('UPDATE', $sql_ary) . "\n\t\t\t\t\t\t\tWHERE user_id = {$user_id}";
                        $db->sql_query($sql);
                        // Update Custom Fields
                        if (sizeof($cp_data)) {
                            $sql = 'UPDATE ' . PROFILE_FIELDS_DATA_TABLE . '
								SET ' . $db->sql_build_array('UPDATE', $cp_data) . "\n\t\t\t\t\t\t\t\tWHERE user_id = {$user_id}";
                            $db->sql_query($sql);
                            if (!$db->sql_affectedrows()) {
                                $cp_data['user_id'] = (int) $user_id;
                                $db->return_on_error = true;
                                $sql = 'INSERT INTO ' . PROFILE_FIELDS_DATA_TABLE . ' ' . $db->sql_build_array('INSERT', $cp_data);
                                $db->sql_query($sql);
                                $db->return_on_error = false;
                            }
                        }
                        trigger_error($user->lang['USER_PROFILE_UPDATED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
                    }
                    // Replace "error" strings with their real, localised form
                    $error = preg_replace('#^([A-Z_]+)$#e', "(!empty(\$user->lang['\\1'])) ? \$user->lang['\\1'] : '\\1'", $error);
                }
                if (!isset($data['bday_day'])) {
                    if ($user_row['user_birthday']) {
                        list($data['bday_day'], $data['bday_month'], $data['bday_year']) = explode('-', $user_row['user_birthday']);
                    } else {
                        $data['bday_day'] = $data['bday_month'] = $data['bday_year'] = 0;
                    }
                }
                $s_birthday_day_options = '<option value="0"' . (!$data['bday_day'] ? ' selected="selected"' : '') . '>--</option>';
                for ($i = 1; $i < 32; $i++) {
                    $selected = $i == $data['bday_day'] ? ' selected="selected"' : '';
                    $s_birthday_day_options .= "<option value=\"{$i}\"{$selected}>{$i}</option>";
                }
                $s_birthday_month_options = '<option value="0"' . (!$data['bday_month'] ? ' selected="selected"' : '') . '>--</option>';
                for ($i = 1; $i < 13; $i++) {
                    $selected = $i == $data['bday_month'] ? ' selected="selected"' : '';
                    $s_birthday_month_options .= "<option value=\"{$i}\"{$selected}>{$i}</option>";
                }
                $s_birthday_year_options = '';
                $now = getdate();
                $s_birthday_year_options = '<option value="0"' . (!$data['bday_year'] ? ' selected="selected"' : '') . '>--</option>';
                for ($i = $now['year'] - 100; $i < $now['year']; $i++) {
                    $selected = $i == $data['bday_year'] ? ' selected="selected"' : '';
                    $s_birthday_year_options .= "<option value=\"{$i}\"{$selected}>{$i}</option>";
                }
                unset($now);
                $template->assign_vars(array('ICQ' => isset($data['icq']) ? $data['icq'] : $user_row['user_icq'], 'YIM' => isset($data['yim']) ? $data['yim'] : $user_row['user_yim'], 'AIM' => isset($data['aim']) ? $data['aim'] : $user_row['user_aim'], 'MSN' => isset($data['msn']) ? $data['msn'] : $user_row['user_msnm'], 'JABBER' => isset($data['jabber']) ? $data['jabber'] : $user_row['user_jabber'], 'WEBSITE' => isset($data['website']) ? $data['website'] : $user_row['user_website'], 'LOCATION' => isset($data['location']) ? $data['location'] : $user_row['user_from'], 'OCCUPATION' => isset($data['occupation']) ? $data['occupation'] : $user_row['user_occ'], 'INTERESTS' => isset($data['interests']) ? $data['interests'] : $user_row['user_interests'], 'S_BIRTHDAY_DAY_OPTIONS' => $s_birthday_day_options, 'S_BIRTHDAY_MONTH_OPTIONS' => $s_birthday_month_options, 'S_BIRTHDAY_YEAR_OPTIONS' => $s_birthday_year_options, 'S_PROFILE' => true));
                // Get additional profile fields and assign them to the template block var 'profile_fields'
                $user->get_profile_fields($user_id);
                $cp->generate_profile_fields('profile', $user_row['iso_lang_id']);
                break;
            case 'prefs':
                $data = array();
                if ($submit) {
                    $var_ary = array('dateformat' => (string) $config['default_dateformat'], 'lang' => (string) $config['default_lang'], 'tz' => (double) $config['board_timezone'], 'style' => (int) $config['default_style'], 'dst' => (bool) $config['board_dst'], 'viewemail' => false, 'massemail' => true, 'hideonline' => false, 'notifymethod' => 0, 'notifypm' => true, 'popuppm' => false, 'allowpm' => true, 'topic_sk' => (string) 't', 'topic_sd' => (string) 'd', 'topic_st' => 0, 'post_sk' => (string) 't', 'post_sd' => (string) 'a', 'post_st' => 0, 'view_images' => true, 'view_flash' => false, 'view_smilies' => true, 'view_sigs' => true, 'view_avatars' => true, 'view_wordcensor' => false, 'bbcode' => true, 'smilies' => true, 'sig' => true, 'notify' => false);
                    foreach ($var_ary as $var => $default) {
                        $data[$var] = request_var($var, $default);
                    }
                    $var_ary = array('dateformat' => array('string', false, 3, 30), 'lang' => array('match', false, '#^[a-z_]{2,}$#i'), 'tz' => array('num', false, -14, 14), 'topic_sk' => array('string', false, 1, 1), 'topic_sd' => array('string', false, 1, 1), 'post_sk' => array('string', false, 1, 1), 'post_sd' => array('string', false, 1, 1));
                    $error = validate_data($data, $var_ary);
                    if (!sizeof($error)) {
                        $this->optionset($user_row, 'popuppm', $data['popuppm']);
                        $this->optionset($user_row, 'viewimg', $data['view_images']);
                        $this->optionset($user_row, 'viewflash', $data['view_flash']);
                        $this->optionset($user_row, 'viewsmilies', $data['view_smilies']);
                        $this->optionset($user_row, 'viewsigs', $data['view_sigs']);
                        $this->optionset($user_row, 'viewavatars', $data['view_avatars']);
                        $this->optionset($user_row, 'viewcensors', $data['view_wordcensor']);
                        $this->optionset($user_row, 'bbcode', $data['bbcode']);
                        $this->optionset($user_row, 'smilies', $data['smilies']);
                        $this->optionset($user_row, 'attachsig', $data['sig']);
                        $sql_ary = array('user_options' => $user_row['user_options'], 'user_allow_pm' => $data['allowpm'], 'user_allow_viewemail' => $data['viewemail'], 'user_allow_massemail' => $data['massemail'], 'user_allow_viewonline' => !$data['hideonline'], 'user_notify_type' => $data['notifymethod'], 'user_notify_pm' => $data['notifypm'], 'user_dst' => $data['dst'], 'user_dateformat' => $data['dateformat'], 'user_lang' => $data['lang'], 'user_timezone' => $data['tz'], 'user_style' => $data['style'], 'user_topic_sortby_type' => $data['topic_sk'], 'user_post_sortby_type' => $data['post_sk'], 'user_topic_sortby_dir' => $data['topic_sd'], 'user_post_sortby_dir' => $data['post_sd'], 'user_topic_show_days' => $data['topic_st'], 'user_post_show_days' => $data['post_st'], 'user_notify' => $data['notify']);
                        $sql = 'UPDATE ' . USERS_TABLE . '
							SET ' . $db->sql_build_array('UPDATE', $sql_ary) . "\n\t\t\t\t\t\t\tWHERE user_id = {$user_id}";
                        $db->sql_query($sql);
                        trigger_error($user->lang['USER_PREFS_UPDATED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
                    }
                    // Replace "error" strings with their real, localised form
                    $error = preg_replace('#^([A-Z_]+)$#e', "(!empty(\$user->lang['\\1'])) ? \$user->lang['\\1'] : '\\1'", $error);
                }
                $notify_method = isset($data['notifymethod']) ? $data['notifymethod'] : $user_row['user_notify_type'];
                $dateformat = isset($data['dateformat']) ? $data['dateformat'] : $user_row['user_dateformat'];
                $lang = isset($data['lang']) ? $data['lang'] : $user_row['user_lang'];
                $style = isset($data['style']) ? $data['style'] : $user_row['user_style'];
                $tz = isset($data['tz']) ? $data['tz'] : $user_row['user_timezone'];
                $dateformat_options = '';
                foreach ($user->lang['dateformats'] as $format => $null) {
                    $dateformat_options .= '<option value="' . $format . '"' . ($format == $dateformat ? ' selected="selected"' : '') . '>';
                    $dateformat_options .= $user->format_date(time(), $format, true) . (strpos($format, '|') !== false ? ' [' . $user->lang['RELATIVE_DAYS'] . ']' : '');
                    $dateformat_options .= '</option>';
                }
                $s_custom = false;
                $dateformat_options .= '<option value="custom"';
                if (!in_array($dateformat, array_keys($user->lang['dateformats']))) {
                    $dateformat_options .= ' selected="selected"';
                    $s_custom = true;
                }
                $dateformat_options .= '>' . $user->lang['CUSTOM_DATEFORMAT'] . '</option>';
                $topic_sk = isset($data['topic_sk']) ? $data['topic_sk'] : ($user_row['user_topic_sortby_type'] ? $user_row['user_topic_sortby_type'] : 't');
                $post_sk = isset($data['post_sk']) ? $data['post_sk'] : ($user_row['user_post_sortby_type'] ? $user_row['user_post_sortby_type'] : 't');
                $topic_sd = isset($data['topic_sd']) ? $data['topic_sd'] : ($user_row['user_topic_sortby_dir'] ? $user_row['user_topic_sortby_dir'] : 'd');
                $post_sd = isset($data['post_sd']) ? $data['post_sd'] : ($user_row['user_post_sortby_dir'] ? $user_row['user_post_sortby_dir'] : 'd');
                $topic_st = isset($data['topic_st']) ? $data['topic_st'] : ($user_row['user_topic_show_days'] ? $user_row['user_topic_show_days'] : 0);
                $post_st = isset($data['post_st']) ? $data['post_st'] : ($user_row['user_post_show_days'] ? $user_row['user_post_show_days'] : 0);
                $sort_dir_text = array('a' => $user->lang['ASCENDING'], 'd' => $user->lang['DESCENDING']);
                // Topic ordering options
                $limit_topic_days = array(0 => $user->lang['ALL_TOPICS'], 1 => $user->lang['1_DAY'], 7 => $user->lang['7_DAYS'], 14 => $user->lang['2_WEEKS'], 30 => $user->lang['1_MONTH'], 90 => $user->lang['3_MONTHS'], 180 => $user->lang['6_MONTHS'], 365 => $user->lang['1_YEAR']);
                $sort_by_topic_text = array('a' => $user->lang['AUTHOR'], 't' => $user->lang['POST_TIME'], 'r' => $user->lang['REPLIES'], 's' => $user->lang['SUBJECT'], 'v' => $user->lang['VIEWS']);
                // Post ordering options
                $limit_post_days = array(0 => $user->lang['ALL_POSTS'], 1 => $user->lang['1_DAY'], 7 => $user->lang['7_DAYS'], 14 => $user->lang['2_WEEKS'], 30 => $user->lang['1_MONTH'], 90 => $user->lang['3_MONTHS'], 180 => $user->lang['6_MONTHS'], 365 => $user->lang['1_YEAR']);
                $sort_by_post_text = array('a' => $user->lang['AUTHOR'], 't' => $user->lang['POST_TIME'], 's' => $user->lang['SUBJECT']);
                $_options = array('topic', 'post');
                foreach ($_options as $sort_option) {
                    ${'s_limit_' . $sort_option . '_days'} = '<select name="' . $sort_option . '_st">';
                    foreach (${'limit_' . $sort_option . '_days'} as $day => $text) {
                        $selected = ${$sort_option . '_st'} == $day ? ' selected="selected"' : '';
                        ${'s_limit_' . $sort_option . '_days'} .= '<option value="' . $day . '"' . $selected . '>' . $text . '</option>';
                    }
                    ${'s_limit_' . $sort_option . '_days'} .= '</select>';
                    ${'s_sort_' . $sort_option . '_key'} = '<select name="' . $sort_option . '_sk">';
                    foreach (${'sort_by_' . $sort_option . '_text'} as $key => $text) {
                        $selected = ${$sort_option . '_sk'} == $key ? ' selected="selected"' : '';
                        ${'s_sort_' . $sort_option . '_key'} .= '<option value="' . $key . '"' . $selected . '>' . $text . '</option>';
                    }
                    ${'s_sort_' . $sort_option . '_key'} .= '</select>';
                    ${'s_sort_' . $sort_option . '_dir'} = '<select name="' . $sort_option . '_sd">';
                    foreach ($sort_dir_text as $key => $value) {
                        $selected = ${$sort_option . '_sd'} == $key ? ' selected="selected"' : '';
                        ${'s_sort_' . $sort_option . '_dir'} .= '<option value="' . $key . '"' . $selected . '>' . $value . '</option>';
                    }
                    ${'s_sort_' . $sort_option . '_dir'} .= '</select>';
                }
                $template->assign_vars(array('S_PREFS' => true, 'S_JABBER_DISABLED' => $config['jab_enable'] && $user->data['user_jabber'] && @extension_loaded('xml') ? false : true, 'VIEW_EMAIL' => isset($data['viewemail']) ? $data['viewemail'] : $user_row['user_allow_viewemail'], 'MASS_EMAIL' => isset($data['massemail']) ? $data['massemail'] : $user_row['user_allow_massemail'], 'ALLOW_PM' => isset($data['allowpm']) ? $data['allowpm'] : $user_row['user_allow_pm'], 'HIDE_ONLINE' => isset($data['hideonline']) ? $data['hideonline'] : !$user_row['user_allow_viewonline'], 'NOTIFY_EMAIL' => $notify_method == NOTIFY_EMAIL ? true : false, 'NOTIFY_IM' => $notify_method == NOTIFY_IM ? true : false, 'NOTIFY_BOTH' => $notify_method == NOTIFY_BOTH ? true : false, 'NOTIFY_PM' => isset($data['notifypm']) ? $data['notifypm'] : $user_row['user_notify_pm'], 'POPUP_PM' => isset($data['popuppm']) ? $data['popuppm'] : $this->optionget($user_row, 'popuppm'), 'DST' => isset($data['dst']) ? $data['dst'] : $user_row['user_dst'], 'BBCODE' => isset($data['bbcode']) ? $data['bbcode'] : $this->optionget($user_row, 'bbcode'), 'SMILIES' => isset($data['smilies']) ? $data['smilies'] : $this->optionget($user_row, 'smilies'), 'ATTACH_SIG' => isset($data['sig']) ? $data['sig'] : $this->optionget($user_row, 'attachsig'), 'NOTIFY' => isset($data['notify']) ? $data['notify'] : $user_row['user_notify'], 'VIEW_IMAGES' => isset($data['view_images']) ? $data['view_images'] : $this->optionget($user_row, 'viewimg'), 'VIEW_FLASH' => isset($data['view_flash']) ? $data['view_flash'] : $this->optionget($user_row, 'viewflash'), 'VIEW_SMILIES' => isset($data['view_smilies']) ? $data['view_smilies'] : $this->optionget($user_row, 'viewsmilies'), 'VIEW_SIGS' => isset($data['view_sigs']) ? $data['view_sigs'] : $this->optionget($user_row, 'viewsigs'), 'VIEW_AVATARS' => isset($data['view_avatars']) ? $data['view_avatars'] : $this->optionget($user_row, 'viewavatars'), 'VIEW_WORDCENSOR' => isset($data['view_wordcensor']) ? $data['view_wordcensor'] : $this->optionget($user_row, 'viewcensors'), 'S_TOPIC_SORT_DAYS' => $s_limit_topic_days, 'S_TOPIC_SORT_KEY' => $s_sort_topic_key, 'S_TOPIC_SORT_DIR' => $s_sort_topic_dir, 'S_POST_SORT_DAYS' => $s_limit_post_days, 'S_POST_SORT_KEY' => $s_sort_post_key, 'S_POST_SORT_DIR' => $s_sort_post_dir, 'DATE_FORMAT' => $dateformat, 'S_DATEFORMAT_OPTIONS' => $dateformat_options, 'S_CUSTOM_DATEFORMAT' => $s_custom, 'DEFAULT_DATEFORMAT' => $config['default_dateformat'], 'A_DEFAULT_DATEFORMAT' => addslashes($config['default_dateformat']), 'S_LANG_OPTIONS' => language_select($lang), 'S_STYLE_OPTIONS' => style_select($style), 'S_TZ_OPTIONS' => tz_select($tz)));
                break;
            case 'avatar':
                $avatar_select = basename(request_var('avatar_select', ''));
                $category = basename(request_var('category', ''));
                $can_upload = file_exists($phpbb_root_path . $config['avatar_path']) && is_writeable($phpbb_root_path . $config['avatar_path']) && $file_uploads ? true : false;
                $data = array();
                if ($submit) {
                    $delete = request_var('delete', '');
                    $var_ary = array('uploadurl' => (string) '', 'remotelink' => (string) '', 'width' => (string) '', 'height' => (string) '');
                    foreach ($var_ary as $var => $default) {
                        $data[$var] = request_var($var, $default);
                    }
                    $var_ary = array('uploadurl' => array('string', true, 5, 255), 'remotelink' => array('string', true, 5, 255), 'width' => array('string', true, 1, 3), 'height' => array('string', true, 1, 3));
                    $error = validate_data($data, $var_ary);
                    if (!sizeof($error)) {
                        $data['user_id'] = $user_id;
                        if ((!empty($_FILES['uploadfile']['name']) || $data['uploadurl']) && $can_upload && $config['allow_avatar_upload']) {
                            list($type, $filename, $width, $height) = avatar_upload($data, $error);
                        } else {
                            if ($data['remotelink'] && $config['allow_avatar_remote']) {
                                list($type, $filename, $width, $height) = avatar_remote($data, $error);
                            } else {
                                if ($avatar_select && $config['allow_avatar_local']) {
                                    $type = AVATAR_GALLERY;
                                    $filename = $avatar_select;
                                    // check avatar gallery
                                    if (!is_dir($phpbb_root_path . $config['avatar_gallery_path'] . '/' . $category)) {
                                        $type = $width = $height = 0;
                                        $filename = '';
                                    } else {
                                        list($width, $height) = getimagesize($phpbb_root_path . $config['avatar_gallery_path'] . '/' . $category . '/' . $filename);
                                        $filename = $category . '/' . $filename;
                                    }
                                } else {
                                    if ($delete) {
                                        $filename = '';
                                        $type = $width = $height = 0;
                                    } else {
                                        $data = array();
                                    }
                                }
                            }
                        }
                    }
                    if (!sizeof($error)) {
                        // Do we actually have any data to update?
                        if (sizeof($data)) {
                            $sql_ary = array('user_avatar' => $filename, 'user_avatar_type' => $type, 'user_avatar_width' => $width, 'user_avatar_height' => $height);
                            $sql = 'UPDATE ' . USERS_TABLE . '
								SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
								WHERE user_id = ' . $user_id;
                            $db->sql_query($sql);
                            // Delete old avatar if present
                            if ($user_row['user_avatar'] && $filename != $user_row['user_avatar'] && $user_row['user_avatar_type'] != AVATAR_GALLERY) {
                                avatar_delete($user_row['user_avatar']);
                            }
                        }
                        trigger_error($user->lang['USER_AVATAR_UPDATED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
                    }
                    // Replace "error" strings with their real, localised form
                    $error = preg_replace('#^([A-Z_]+)$#e', "(!empty(\$user->lang['\\1'])) ? \$user->lang['\\1'] : '\\1'", $error);
                }
                // Generate users avatar
                if ($user_row['user_avatar']) {
                    $avatar_img = '';
                    switch ($user_row['user_avatar_type']) {
                        case AVATAR_UPLOAD:
                            $avatar_img = $phpbb_root_path . $config['avatar_path'] . '/';
                            break;
                        case AVATAR_GALLERY:
                            $avatar_img = $phpbb_root_path . $config['avatar_gallery_path'] . '/';
                            break;
                    }
                    $avatar_img .= $user_row['user_avatar'];
                    $avatar_img = '<img src="' . $avatar_img . '" width="' . $user_row['user_avatar_width'] . '" height="' . $user_row['user_avatar_height'] . '" alt="" />';
                } else {
                    $avatar_img = '<img src="' . $phpbb_admin_path . 'images/no_avatar.gif" alt="" />';
                }
                $display_gallery = isset($_POST['display_gallery']) ? true : false;
                if ($config['allow_avatar_local'] && $display_gallery) {
                    avatar_gallery($category, $avatar_select, 4);
                }
                $template->assign_vars(array('S_AVATAR' => true, 'S_CAN_UPLOAD' => $can_upload && $config['allow_avatar_upload'] ? true : false, 'S_ALLOW_REMOTE' => $config['allow_avatar_remote'] ? true : false, 'S_DISPLAY_GALLERY' => $config['allow_avatar_local'] && !$display_gallery ? true : false, 'S_IN_GALLERY' => $config['allow_avatar_local'] && $display_gallery ? true : false, 'AVATAR_IMAGE' => $avatar_img, 'AVATAR_MAX_FILESIZE' => $config['avatar_filesize'], 'USER_AVATAR_WIDTH' => $user_row['user_avatar_width'], 'USER_AVATAR_HEIGHT' => $user_row['user_avatar_height'], 'L_AVATAR_EXPLAIN' => sprintf($user->lang['AVATAR_EXPLAIN'], $config['avatar_max_width'], $config['avatar_max_height'], round($config['avatar_filesize'] / 1024))));
                break;
            case 'rank':
                if ($submit) {
                    $rank_id = request_var('user_rank', 0);
                    $sql = 'UPDATE ' . USERS_TABLE . "\n\t\t\t\t\t\tSET user_rank = {$rank_id}\n\t\t\t\t\t\tWHERE user_id = {$user_id}";
                    $db->sql_query($sql);
                    trigger_error($user->lang['USER_RANK_UPDATED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
                }
                $sql = 'SELECT * 
					FROM ' . RANKS_TABLE . '
					WHERE rank_special = 1
					ORDER BY rank_title';
                $result = $db->sql_query($sql);
                $s_rank_options = '<option value="0"' . (!$user_row['user_rank'] ? ' selected="selected"' : '') . '>' . $user->lang['NO_SPECIAL_RANK'] . '</option>';
                while ($row = $db->sql_fetchrow($result)) {
                    $selected = $user_row['user_rank'] && $row['rank_id'] == $user_row['user_rank'] ? ' selected="selected"' : '';
                    $s_rank_options .= '<option value="' . $row['rank_id'] . '"' . $selected . '>' . $row['rank_title'] . '</option>';
                }
                $db->sql_freeresult($result);
                $template->assign_vars(array('S_RANK' => true, 'S_RANK_OPTIONS' => $s_rank_options));
                break;
            case 'sig':
                include_once $phpbb_root_path . 'includes/functions_posting.' . $phpEx;
                $enable_bbcode = $config['allow_sig_bbcode'] ? request_var('enable_bbcode', $this->optionget($user_row, 'bbcode')) : false;
                $enable_smilies = $config['allow_sig_smilies'] ? request_var('enable_smilies', $this->optionget($user_row, 'smilies')) : false;
                $enable_urls = request_var('enable_urls', true);
                $signature = request_var('signature', $user_row['user_sig'], true);
                $preview = isset($_POST['preview']) ? true : false;
                if ($submit || $preview) {
                    include_once $phpbb_root_path . 'includes/message_parser.' . $phpEx;
                    $message_parser = new parse_message($signature);
                    // Allowing Quote BBCode
                    $message_parser->parse($enable_bbcode, $enable_urls, $enable_smilies, $config['allow_sig_img'], $config['allow_sig_flash'], true, true, 'sig');
                    if (sizeof($message_parser->warn_msg)) {
                        $error[] = implode('<br />', $message_parser->warn_msg);
                    }
                    if (!sizeof($error) && $submit) {
                        $sql_ary = array('user_sig' => (string) $message_parser->message, 'user_sig_bbcode_uid' => (string) $message_parser->bbcode_uid, 'user_sig_bbcode_bitfield' => (int) $message_parser->bbcode_bitfield);
                        $sql = 'UPDATE ' . USERS_TABLE . ' 
							SET ' . $db->sql_build_array('UPDATE', $sql_ary) . ' 
							WHERE user_id = ' . $user_id;
                        $db->sql_query($sql);
                        trigger_error($user->lang['USER_SIG_UPDATED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
                    }
                    // Replace "error" strings with their real, localised form
                    $error = preg_replace('#^([A-Z_]+)$#e', "(!empty(\$user->lang['\\1'])) ? \$user->lang['\\1'] : '\\1'", $error);
                }
                $signature_preview = '';
                if ($preview) {
                    // Now parse it for displaying
                    $signature_preview = $message_parser->format_display($enable_bbcode, $enable_urls, $enable_smilies, false);
                    unset($message_parser);
                }
                decode_message($signature, $user_row['user_sig_bbcode_uid']);
                $template->assign_vars(array('S_SIGNATURE' => true, 'SIGNATURE' => $signature, 'SIGNATURE_PREVIEW' => $signature_preview, 'S_BBCODE_CHECKED' => !$enable_bbcode ? 'checked="checked"' : '', 'S_SMILIES_CHECKED' => !$enable_smilies ? 'checked="checked"' : '', 'S_MAGIC_URL_CHECKED' => !$enable_urls ? 'checked="checked"' : '', 'BBCODE_STATUS' => $config['allow_sig_bbcode'] ? sprintf($user->lang['BBCODE_IS_ON'], '<a href="' . append_sid("{$phpbb_root_path}faq.{$phpEx}", 'mode=bbcode') . '" onclick="target=\'_phpbbcode\';">', '</a>') : sprintf($user->lang['BBCODE_IS_OFF'], '<a href="' . append_sid("{$phpbb_root_path}faq.{$phpEx}", 'mode=bbcode') . '" onclick="target=\'_phpbbcode\';">', '</a>'), 'SMILIES_STATUS' => $config['allow_sig_smilies'] ? $user->lang['SMILIES_ARE_ON'] : $user->lang['SMILIES_ARE_OFF'], 'IMG_STATUS' => $config['allow_sig_img'] ? $user->lang['IMAGES_ARE_ON'] : $user->lang['IMAGES_ARE_OFF'], 'FLASH_STATUS' => $config['allow_sig_flash'] ? $user->lang['FLASH_IS_ON'] : $user->lang['FLASH_IS_OFF'], 'L_SIGNATURE_EXPLAIN' => sprintf($user->lang['SIGNATURE_EXPLAIN'], $config['max_sig_chars']), 'S_BBCODE_ALLOWED' => $config['allow_sig_bbcode'], 'S_SMILIES_ALLOWED' => $config['allow_sig_smilies']));
                break;
            case 'attach':
                $start = request_var('start', 0);
                $deletemark = isset($_POST['delmarked']) ? true : false;
                $marked = request_var('mark', array(0));
                // Sort keys
                $sort_key = request_var('sk', 'a');
                $sort_dir = request_var('sd', 'd');
                if ($deletemark && sizeof($marked)) {
                    if (confirm_box(true)) {
                        $sql = 'SELECT real_filename
							FROM ' . ATTACHMENTS_TABLE . '
							WHERE attach_id IN (' . implode(', ', $marked) . ')';
                        $result = $db->sql_query($sql);
                        $log_attachments = array();
                        while ($row = $db->sql_fetchrow($result)) {
                            $log_attachments[] = $row['real_filename'];
                        }
                        $db->sql_freeresult($result);
                        delete_attachments('attach', $marked);
                        $log = sizeof($log_attachments) == 1 ? 'ATTACHMENT_DELETED' : 'ATTACHMENTS_DELETED';
                        $message = sizeof($log_attachments) == 1 ? $user->lang['ATTACHMENT_DELETED'] : $user->lang['ATTACHMENTS_DELETED'];
                        add_log('admin', $log, implode(', ', $log_attachments));
                        trigger_error($message . adm_back_link($this->u_action . '&amp;u=' . $user_id));
                    } else {
                        confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array('u' => $user_id, 'i' => $id, 'mode' => $mode, 'action' => $action, 'deletemark' => true, 'mark' => $marked)));
                    }
                }
                $sk_text = array('a' => $user->lang['SORT_FILENAME'], 'c' => $user->lang['SORT_EXTENSION'], 'd' => $user->lang['SORT_SIZE'], 'e' => $user->lang['SORT_DOWNLOADS'], 'f' => $user->lang['SORT_POST_TIME'], 'g' => $user->lang['SORT_TOPIC_TITLE']);
                $sk_sql = array('a' => 'a.real_filename', 'c' => 'a.extension', 'd' => 'a.filesize', 'e' => 'a.download_count', 'f' => 'a.filetime', 'g' => 't.topic_title');
                $sd_text = array('a' => $user->lang['ASCENDING'], 'd' => $user->lang['DESCENDING']);
                $s_sort_key = '';
                foreach ($sk_text as $key => $value) {
                    $selected = $sort_key == $key ? ' selected="selected"' : '';
                    $s_sort_key .= '<option value="' . $key . '"' . $selected . '>' . $value . '</option>';
                }
                $s_sort_dir = '';
                foreach ($sd_text as $key => $value) {
                    $selected = $sort_dir == $key ? ' selected="selected"' : '';
                    $s_sort_dir .= '<option value="' . $key . '"' . $selected . '>' . $value . '</option>';
                }
                $order_by = $sk_sql[$sort_key] . '  ' . ($sort_dir == 'a' ? 'ASC' : 'DESC');
                $sql = 'SELECT COUNT(attach_id) as num_attachments
					FROM ' . ATTACHMENTS_TABLE . "\n\t\t\t\t\tWHERE poster_id = {$user_id}";
                $result = $db->sql_query_limit($sql, 1);
                $num_attachments = (int) $db->sql_fetchfield('num_attachments');
                $db->sql_freeresult($result);
                $sql = 'SELECT a.*, t.topic_title, p.message_subject as message_title
					FROM ' . ATTACHMENTS_TABLE . ' a 
						LEFT JOIN ' . TOPICS_TABLE . ' t ON (a.topic_id = t.topic_id
							AND a.in_message = 0)
						LEFT JOIN ' . PRIVMSGS_TABLE . ' p ON (a.post_msg_id = p.msg_id
							AND a.in_message = 1)
					WHERE a.poster_id = ' . $user_id . "\n\t\t\t\t\tORDER BY {$order_by}";
                $result = $db->sql_query_limit($sql, $config['posts_per_page'], $start);
                while ($row = $db->sql_fetchrow($result)) {
                    if ($row['in_message']) {
                        $view_topic = append_sid("{$phpbb_root_path}ucp.{$phpEx}", "i=pm&amp;p={$row['post_msg_id']}");
                    } else {
                        $view_topic = append_sid("{$phpbb_root_path}viewtopic.{$phpEx}", "t={$row['topic_id']}&amp;p={$row['post_msg_id']}#{$row['post_msg_id']}");
                    }
                    $template->assign_block_vars('attach', array('REAL_FILENAME' => $row['real_filename'], 'COMMENT' => nl2br($row['comment']), 'EXTENSION' => $row['extension'], 'SIZE' => $row['filesize'] >= 1048576 ? ($row['filesize'] >> 20) . ' ' . $user->lang['MB'] : ($row['filesize'] >= 1024 ? ($row['filesize'] >> 10) . ' ' . $user->lang['KB'] : $row['filesize'] . ' ' . $user->lang['BYTES']), 'DOWNLOAD_COUNT' => $row['download_count'], 'POST_TIME' => $user->format_date($row['filetime']), 'TOPIC_TITLE' => $row['in_message'] ? $row['message_title'] : $row['topic_title'], 'ATTACH_ID' => $row['attach_id'], 'POST_ID' => $row['post_msg_id'], 'TOPIC_ID' => $row['topic_id'], 'S_IN_MESSAGE' => $row['in_message'], 'U_DOWNLOAD' => append_sid("{$phpbb_root_path}download.{$phpEx}", 'id=' . $row['attach_id']), 'U_VIEW_TOPIC' => $view_topic));
                }
                $db->sql_freeresult($result);
                $template->assign_vars(array('S_ATTACHMENTS' => true, 'S_ON_PAGE' => on_page($num_attachments, $config['topics_per_page'], $start), 'S_SORT_KEY' => $s_sort_key, 'S_SORT_DIR' => $s_sort_dir, 'PAGINATION' => generate_pagination($this->u_action . "&amp;sk={$sort_key}&amp;sd={$sort_dir}", $num_attachments, $config['topics_per_page'], $start, true)));
                break;
            case 'groups':
                $user->add_lang(array('groups', 'acp/groups'));
                $group_id = request_var('g', 0);
                switch ($action) {
                    case 'demote':
                    case 'promote':
                    case 'default':
                        group_user_attributes($action, $group_id, $user_id);
                        if ($action == 'default') {
                            $user_row['group_id'] = $group_id;
                        }
                        break;
                    case 'delete':
                        if (confirm_box(true)) {
                            if (!$group_id) {
                                trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
                            }
                            if ($error = group_user_del($group_id, $user_id)) {
                                trigger_error($user->lang[$error] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
                            }
                            $error = array();
                        } else {
                            confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array('u' => $user_id, 'i' => $id, 'mode' => $mode, 'action' => $action, 'g' => $group_id)));
                        }
                        break;
                }
                // Add user to group?
                if ($submit) {
                    if (!$group_id) {
                        trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
                    }
                    // Add user/s to group
                    if ($error = group_user_add($group_id, $user_id)) {
                        trigger_error($user->lang[$error] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
                    }
                    $error = array();
                }
                $sql = 'SELECT ug.*, g.*
					FROM ' . GROUPS_TABLE . ' g, ' . USER_GROUP_TABLE . " ug\n\t\t\t\t\tWHERE ug.user_id = {$user_id}\n\t\t\t\t\t\tAND g.group_id = ug.group_id\n\t\t\t\t\tORDER BY g.group_type DESC, ug.user_pending ASC, g.group_name";
                $result = $db->sql_query($sql);
                $i = 0;
                $group_data = $id_ary = array();
                while ($row = $db->sql_fetchrow($result)) {
                    $type = $row['group_type'] == GROUP_SPECIAL ? 'special' : ($row['user_pending'] ? 'pending' : 'normal');
                    $group_data[$type][$i]['group_id'] = $row['group_id'];
                    $group_data[$type][$i]['group_name'] = $row['group_name'];
                    $group_data[$type][$i]['group_leader'] = $row['group_leader'] ? 1 : 0;
                    $id_ary[] = $row['group_id'];
                    $i++;
                }
                $db->sql_freeresult($result);
                // Select box for other groups
                $sql = 'SELECT group_id, group_name, group_type
					FROM ' . GROUPS_TABLE . '
					' . (sizeof($id_ary) ? 'WHERE group_id NOT IN (' . implode(', ', $id_ary) . ')' : '') . '
					ORDER BY group_type DESC, group_name ASC';
                $result = $db->sql_query($sql);
                $s_group_options = '';
                while ($row = $db->sql_fetchrow($result)) {
                    if ($config['coppa_hide_groups'] && in_array($row['group_name'], array('INACTIVE_COPPA', 'REGISTERED_COPPA'))) {
                        continue;
                    }
                    $s_group_options .= '<option' . ($row['group_type'] == GROUP_SPECIAL ? ' class="sep"' : '') . ' value="' . $row['group_id'] . '">' . ($row['group_type'] == GROUP_SPECIAL ? $user->lang['G_' . $row['group_name']] : $row['group_name']) . '</option>';
                }
                $db->sql_freeresult($result);
                $current_type = '';
                foreach ($group_data as $group_type => $data_ary) {
                    if ($current_type != $group_type) {
                        $template->assign_block_vars('group', array('S_NEW_GROUP_TYPE' => true, 'GROUP_TYPE' => $user->lang['USER_GROUP_' . strtoupper($group_type)]));
                    }
                    foreach ($data_ary as $data) {
                        $template->assign_block_vars('group', array('U_EDIT_GROUP' => append_sid("{$phpbb_admin_path}index.{$phpEx}", "i=groups&amp;mode=manage&amp;action=edit&amp;u={$user_id}&amp;g={$data['group_id']}&amp;back_link=acp_users_groups"), 'U_DEFAULT' => $this->u_action . "&amp;action=default&amp;u={$user_id}&amp;g=" . $data['group_id'], 'U_DEMOTE_PROMOTE' => $this->u_action . '&amp;action=' . ($data['group_leader'] ? 'demote' : 'promote') . "&amp;u={$user_id}&amp;g=" . $data['group_id'], 'U_DELETE' => $this->u_action . "&amp;action=delete&amp;u={$user_id}&amp;g=" . $data['group_id'], 'GROUP_NAME' => $group_type == 'special' ? $user->lang['G_' . $data['group_name']] : $data['group_name'], 'L_DEMOTE_PROMOTE' => $data['group_leader'] ? $user->lang['GROUP_DEMOTE'] : $user->lang['GROUP_PROMOTE'], 'S_NO_DEFAULT' => $user_row['group_id'] != $data['group_id'] ? true : false, 'S_SPECIAL_GROUP' => $group_type == 'special' ? true : false));
                    }
                }
                $template->assign_vars(array('S_GROUPS' => true, 'S_GROUP_OPTIONS' => $s_group_options));
                break;
            case 'perm':
                include_once $phpbb_root_path . 'includes/acp/auth.' . $phpEx;
                $auth_admin = new auth_admin();
                $user->add_lang('acp/permissions');
                $user->add_lang('acp/permissions_phpbb');
                // Select auth options
                $sql = 'SELECT auth_option, is_local, is_global
					FROM ' . ACL_OPTIONS_TABLE . "\n\t\t\t\t\tWHERE auth_option LIKE '%\\_'\n\t\t\t\t\t\tAND is_global = 1\n\t\t\t\t\tORDER BY auth_option";
                $result = $db->sql_query($sql);
                while ($row = $db->sql_fetchrow($result)) {
                    $hold_ary = $auth_admin->get_mask('view', $user_id, false, false, $row['auth_option'], 'global', ACL_NO);
                    $auth_admin->display_mask('view', $row['auth_option'], $hold_ary, 'user', false, false);
                }
                $db->sql_freeresult($result);
                $sql = 'SELECT auth_option, is_local, is_global
					FROM ' . ACL_OPTIONS_TABLE . "\n\t\t\t\t\tWHERE auth_option LIKE '%\\_'\n\t\t\t\t\t\tAND is_local = 1\n\t\t\t\t\tORDER BY is_global DESC, auth_option";
                $result = $db->sql_query($sql);
                while ($row = $db->sql_fetchrow($result)) {
                    $hold_ary = $auth_admin->get_mask('view', $user_id, false, false, $row['auth_option'], 'local', ACL_NO);
                    $auth_admin->display_mask('view', $row['auth_option'], $hold_ary, 'user', true, false);
                }
                $db->sql_freeresult($result);
                $template->assign_vars(array('S_PERMISSIONS' => true, 'U_USER_PERMISSIONS' => append_sid("{$phpbb_admin_path}index.{$phpEx}", 'i=permissions&amp;mode=setting_user_global&amp;user_id[]=' . $user_id), 'U_USER_FORUM_PERMISSIONS' => append_sid("{$phpbb_admin_path}index.{$phpEx}", 'i=permissions&amp;mode=setting_user_local&amp;user_id[]=' . $user_id)));
                break;
        }
        // Assign general variables
        $template->assign_vars(array('S_ERROR' => sizeof($error) ? true : false, 'ERROR_MSG' => sizeof($error) ? implode('<br />', $error) : ''));
    }
/**
* For parsing custom parsed text to be stored within the database.
* This function additionally returns the uid and bitfield that needs to be stored.
* Expects $text to be the value directly from request_var() and in it's non-parsed form
*/
function generate_text_for_storage(&$text, &$uid, &$bitfield, &$flags, $allow_bbcode = false, $allow_urls = false, $allow_smilies = false)
{
    global $phpbb_root_path, $phpEx;
    $uid = $bitfield = '';
    $flags = ($allow_bbcode ? OPTION_FLAG_BBCODE : 0) + ($allow_smilies ? OPTION_FLAG_SMILIES : 0) + ($allow_urls ? OPTION_FLAG_LINKS : 0);
    if (!$text) {
        return;
    }
    if (!class_exists('parse_message')) {
        include $phpbb_root_path . 'includes/message_parser.' . $phpEx;
    }
    $message_parser = new parse_message($text);
    $message_parser->parse($allow_bbcode, $allow_urls, $allow_smilies);
    $text = $message_parser->message;
    $uid = $message_parser->bbcode_uid;
    // If the bbcode_bitfield is empty, there is no need for the uid to be stored.
    if (!$message_parser->bbcode_bitfield) {
        $uid = '';
    }
    $bitfield = $message_parser->bbcode_bitfield;
    return;
}
Example #29
0
$post_data['poll_options'] = array();
// Get Poll Data
if ($post_data['poll_start']) {
    $sql = 'SELECT poll_option_text
		FROM ' . POLL_OPTIONS_TABLE . "\n\t\tWHERE topic_id = {$topic_id}\n\t\tORDER BY poll_option_id";
    $result = $db->sql_query($sql);
    while ($row = $db->sql_fetchrow($result)) {
        $post_data['poll_options'][] = trim($row['poll_option_text']);
    }
    $db->sql_freeresult($result);
}
if ($mode == 'edit') {
    $original_poll_data = array('poll_title' => $post_data['poll_title'], 'poll_length' => $post_data['poll_length'], 'poll_max_options' => $post_data['poll_max_options'], 'poll_option_text' => implode("\n", $post_data['poll_options']), 'poll_start' => $post_data['poll_start'], 'poll_last_vote' => $post_data['poll_last_vote'], 'poll_vote_change' => $post_data['poll_vote_change']);
}
$orig_poll_options_size = sizeof($post_data['poll_options']);
$message_parser = new parse_message();
if (isset($post_data['post_text'])) {
    $message_parser->message =& $post_data['post_text'];
    unset($post_data['post_text']);
}
// Set some default variables
$uninit = array('post_attachment' => 0, 'poster_id' => $user->data['user_id'], 'enable_magic_url' => 0, 'topic_status' => 0, 'topic_type' => POST_NORMAL, 'post_subject' => '', 'topic_title' => '', 'post_time' => 0, 'post_edit_reason' => '', 'notify_set' => 0);
foreach ($uninit as $var_name => $default_value) {
    if (!isset($post_data[$var_name])) {
        $post_data[$var_name] = $default_value;
    }
}
unset($uninit);
// Always check if the submitted attachment data is valid and belongs to the user.
// Further down (especially in submit_post()) we do not check this again.
$message_parser->get_submitted_attachment_data($post_data['poster_id']);
function reply_post_func($xmlrpc_params)
{
    global $db, $auth, $user, $config, $phpbb_root_path, $phpEx, $mobiquo_config, $phpbb_home;
    require_once 'include/emoji.php';
    $user->setup('posting');
    if (!$user->data['is_registered']) {
        trigger_error('LOGIN_EXPLAIN_POST');
    }
    $params = php_xmlrpc_decode($xmlrpc_params);
    // get parameters
    $forum_id = isset($params[0]) ? intval($params[0]) : '';
    $topic_id = isset($params[1]) ? intval($params[1]) : '';
    $subject = isset($params[2]) ? $params[2] : '';
    $text_body = isset($params[3]) ? $params[3] : '';
    $text_body = emoji_unified_to_names($text_body);
    $attach_list = isset($params[4]) ? $params[4] : array();
    $_POST['attachment_data'] = isset($params[5]) && $params[5] ? unserialize(base64_decode($params[5])) : array();
    $GLOBALS['return_html'] = isset($params[6]) ? $params[6] : false;
    if (!$topic_id) {
        trigger_error('NO_TOPIC');
    }
    if (utf8_clean_string($text_body) === '') {
        trigger_error('TOO_FEW_CHARS');
    }
    $post_data = array();
    $current_time = time();
    // get topic data
    $sql = 'SELECT *
            FROM ' . TOPICS_TABLE . '
            WHERE topic_id = ' . $topic_id;
    $result = $db->sql_query($sql);
    $post_data = $db->sql_fetchrow($result);
    $db->sql_freeresult($result);
    // get forum data
    $sql = 'SELECT *
            FROM ' . FORUMS_TABLE . "\n            WHERE forum_type = " . FORUM_POST . ($post_data['forum_id'] ? "\n            AND forum_id = '{$post_data['forum_id']}' " : '');
    $result = $db->sql_query_limit($sql, 1);
    $forum_data = $db->sql_fetchrow($result);
    $db->sql_freeresult($result);
    $post_data = array_merge($post_data, $forum_data);
    if (!$post_data) {
        trigger_error('NO_TOPIC');
    }
    // Use post_row values in favor of submitted ones...
    $forum_id = !empty($post_data['forum_id']) ? (int) $post_data['forum_id'] : (int) $forum_id;
    $topic_id = !empty($post_data['topic_id']) ? (int) $post_data['topic_id'] : (int) $topic_id;
    // Need to login to passworded forum first?
    if ($post_data['forum_password'] && !check_forum_password($forum_id)) {
        trigger_error('LOGIN_FORUM');
    }
    // Check permissions
    if ($user->data['is_bot']) {
        trigger_error('NOT_AUTHORISED');
    }
    // Is the user able to read within this forum?
    if (!$auth->acl_get('f_read', $forum_id)) {
        if ($user->data['user_id'] != ANONYMOUS) {
            trigger_error('USER_CANNOT_READ');
        }
        trigger_error('LOGIN_EXPLAIN_POST');
    }
    // Permission to do the reply
    if (!$auth->acl_get('f_reply', $forum_id)) {
        if ($user->data['user_id'] != ANONYMOUS) {
            trigger_error('USER_CANNOT_REPLY');
        }
        trigger_error('LOGIN_EXPLAIN_POST');
    }
    // Is the user able to post within this forum?
    if ($post_data['forum_type'] != FORUM_POST) {
        trigger_error('USER_CANNOT_FORUM_POST');
    }
    // Forum/Topic locked?
    if (($post_data['forum_status'] == ITEM_LOCKED || isset($post_data['topic_status']) && $post_data['topic_status'] == ITEM_LOCKED) && !$auth->acl_get('m_edit', $forum_id)) {
        trigger_error($post_data['forum_status'] == ITEM_LOCKED ? 'FORUM_LOCKED' : 'TOPIC_LOCKED');
    }
    $subject = (strpos($subject, 'Re: ') !== 0 ? 'Re: ' : '') . ($subject ? $subject : censor_text($post_data['topic_title']));
    $post_data['post_edit_locked'] = isset($post_data['post_edit_locked']) ? (int) $post_data['post_edit_locked'] : 0;
    $post_data['post_subject'] = isset($post_data['topic_title']) ? $post_data['topic_title'] : '';
    $post_data['topic_time_limit'] = isset($post_data['topic_time_limit']) ? $post_data['topic_time_limit'] ? (int) $post_data['topic_time_limit'] / 86400 : (int) $post_data['topic_time_limit'] : 0;
    $post_data['poll_length'] = !empty($post_data['poll_length']) ? (int) $post_data['poll_length'] / 86400 : 0;
    $post_data['poll_start'] = !empty($post_data['poll_start']) ? (int) $post_data['poll_start'] : 0;
    $post_data['icon_id'] = 0;
    $post_data['poll_options'] = array();
    // Get Poll Data
    if ($post_data['poll_start']) {
        $sql = 'SELECT poll_option_text
            FROM ' . POLL_OPTIONS_TABLE . "\n            WHERE topic_id = {$topic_id}\n            ORDER BY poll_option_id";
        $result = $db->sql_query($sql);
        while ($row = $db->sql_fetchrow($result)) {
            $post_data['poll_options'][] = trim($row['poll_option_text']);
        }
        $db->sql_freeresult($result);
    }
    $orig_poll_options_size = sizeof($post_data['poll_options']);
    include $phpbb_root_path . 'includes/message_parser.' . $phpEx;
    $message_parser = new parse_message();
    // Set some default variables
    $uninit = array('post_attachment' => 0, 'poster_id' => $user->data['user_id'], 'enable_magic_url' => 0, 'topic_status' => 0, 'topic_type' => POST_NORMAL, 'post_subject' => '', 'topic_title' => '', 'post_time' => 0, 'post_edit_reason' => '', 'notify_set' => 0);
    foreach ($uninit as $var_name => $default_value) {
        if (!isset($post_data[$var_name])) {
            $post_data[$var_name] = $default_value;
        }
    }
    unset($uninit);
    // Always check if the submitted attachment data is valid and belongs to the user.
    // Further down (especially in submit_post()) we do not check this again.
    $message_parser->get_submitted_attachment_data($post_data['poster_id']);
    $post_data['username'] = '';
    $post_data['enable_urls'] = $post_data['enable_magic_url'];
    $post_data['enable_sig'] = $config['allow_sig'] && $user->optionget('attachsig') ? true : false;
    $post_data['enable_smilies'] = $config['allow_smilies'] && $user->optionget('smilies') ? true : false;
    $post_data['enable_bbcode'] = $config['allow_bbcode'] && $user->optionget('bbcode') ? true : false;
    $post_data['enable_urls'] = true;
    $post_data['enable_magic_url'] = $post_data['drafts'] = false;
    $check_value = ($post_data['enable_bbcode'] + 1 << 8) + ($post_data['enable_smilies'] + 1 << 4) + ($post_data['enable_urls'] + 1 << 2) + ($post_data['enable_sig'] + 1 << 1);
    // Check if user is watching this topic
    if ($config['allow_topic_notify'] && $user->data['is_registered']) {
        $sql = 'SELECT topic_id
                FROM ' . TOPICS_WATCH_TABLE . '
                WHERE topic_id = ' . $topic_id . '
                AND user_id = ' . $user->data['user_id'];
        $result = $db->sql_query($sql);
        $post_data['notify_set'] = (int) $db->sql_fetchfield('topic_id');
        $db->sql_freeresult($result);
    }
    // HTML, BBCode, Smilies, Images and Flash status
    $bbcode_status = $config['allow_bbcode'] && $auth->acl_get('f_bbcode', $forum_id) ? true : false;
    $smilies_status = $bbcode_status && $config['allow_smilies'] && $auth->acl_get('f_smilies', $forum_id) ? true : false;
    $img_status = $bbcode_status && $auth->acl_get('f_img', $forum_id) ? true : false;
    $url_status = $config['allow_post_links'] ? true : false;
    $flash_status = $bbcode_status && $auth->acl_get('f_flash', $forum_id) && $config['allow_post_flash'] ? true : false;
    $quote_status = $auth->acl_get('f_reply', $forum_id) ? true : false;
    $post_data['topic_cur_post_id'] = request_var('topic_cur_post_id', 0);
    $post_data['post_subject'] = utf8_normalize_nfc($subject);
    $message_parser->message = utf8_normalize_nfc(htmlspecialchars($text_body));
    $post_data['username'] = utf8_normalize_nfc(request_var('username', $post_data['username'], true));
    $post_data['post_edit_reason'] = '';
    $post_data['orig_topic_type'] = $post_data['topic_type'];
    $post_data['topic_type'] = request_var('topic_type', (int) $post_data['topic_type']);
    $post_data['topic_time_limit'] = request_var('topic_time_limit', (int) $post_data['topic_time_limit']);
    $post_data['icon_id'] = request_var('icon', 0);
    $post_data['enable_bbcode'] = !$bbcode_status || isset($_POST['disable_bbcode']) ? false : true;
    $post_data['enable_smilies'] = !$smilies_status || isset($_POST['disable_smilies']) ? false : true;
    $post_data['enable_urls'] = isset($_POST['disable_magic_url']) ? 0 : 1;
    $post_data['enable_sig'] = !$config['allow_sig'] || !$auth->acl_get('f_sigs', $forum_id) || !$auth->acl_get('u_sig') ? false : ($user->data['is_registered'] ? true : false);
    if ($config['allow_topic_notify'] && $user->data['is_registered']) {
        $notify = !$post_data['notify_set'] ? $user->data['user_notify'] : $post_data['notify_set'] ? true : false;
    } else {
        $notify = false;
    }
    $post_data['poll_title'] = utf8_normalize_nfc(request_var('poll_title', '', true));
    $post_data['poll_length'] = request_var('poll_length', 0);
    $post_data['poll_option_text'] = utf8_normalize_nfc(request_var('poll_option_text', '', true));
    $post_data['poll_max_options'] = request_var('poll_max_options', 1);
    $post_data['poll_vote_change'] = $auth->acl_get('f_votechg', $forum_id) && isset($_POST['poll_vote_change']) ? 1 : 0;
    // Parse Attachments - before checksum is calculated
    $message_parser->parse_attachments('fileupload', 'reply', $forum_id, true, false, false);
    // Grab md5 'checksum' of new message
    $message_md5 = md5($message_parser->message);
    // Check checksum ... don't re-parse message if the same
    if (sizeof($message_parser->warn_msg)) {
        trigger_error(join("\n", $message_parser->warn_msg));
    }
    $message_parser->parse($post_data['enable_bbcode'], $config['allow_post_links'] ? $post_data['enable_urls'] : false, $post_data['enable_smilies'], $img_status, $flash_status, $quote_status, $config['allow_post_links']);
    if ($config['flood_interval'] && !$auth->acl_get('f_ignoreflood', $forum_id)) {
        // Flood check
        $last_post_time = 0;
        if ($user->data['is_registered']) {
            $last_post_time = $user->data['user_lastpost_time'];
        } else {
            $sql = 'SELECT post_time AS last_post_time
                FROM ' . POSTS_TABLE . "\n                WHERE poster_ip = '" . $user->ip . "'\n                    AND post_time > " . ($current_time - $config['flood_interval']);
            $result = $db->sql_query_limit($sql, 1);
            if ($row = $db->sql_fetchrow($result)) {
                $last_post_time = $row['last_post_time'];
            }
            $db->sql_freeresult($result);
        }
        if ($last_post_time && $current_time - $last_post_time < intval($config['flood_interval'])) {
            trigger_error('FLOOD_ERROR');
        }
    }
    // Validate username
    if ($post_data['username'] && !$user->data['is_registered']) {
        include $phpbb_root_path . 'includes/functions_user.' . $phpEx;
        if (($result = validate_username($post_data['username'], !empty($post_data['post_username']) ? $post_data['post_username'] : '')) !== false) {
            $user->add_lang('ucp');
            trigger_error($result . '_USERNAME');
        }
    }
    $post_data['poll_last_vote'] = isset($post_data['poll_last_vote']) ? $post_data['poll_last_vote'] : 0;
    $poll = array();
    //    if (sizeof($message_parser->warn_msg))
    //    {
    //        return get_error();
    //    }
    // DNSBL check
    if ($config['check_dnsbl'] && $mobiquo_config['check_dnsbl']) {
        if (($dnsbl = $user->check_dnsbl('post')) !== false) {
            trigger_error(sprintf($user->lang['IP_BLACKLISTED'], $user->ip, $dnsbl[1]));
        }
    }
    // Store message, sync counters
    $data = array('topic_title' => empty($post_data['topic_title']) ? $post_data['post_subject'] : $post_data['topic_title'], 'topic_first_post_id' => isset($post_data['topic_first_post_id']) ? (int) $post_data['topic_first_post_id'] : 0, 'topic_last_post_id' => isset($post_data['topic_last_post_id']) ? (int) $post_data['topic_last_post_id'] : 0, 'topic_time_limit' => (int) $post_data['topic_time_limit'], 'topic_attachment' => isset($post_data['topic_attachment']) ? (int) $post_data['topic_attachment'] : 0, 'post_id' => 0, 'topic_id' => (int) $topic_id, 'forum_id' => (int) $forum_id, 'icon_id' => (int) $post_data['icon_id'], 'poster_id' => (int) $post_data['poster_id'], 'enable_sig' => (bool) $post_data['enable_sig'], 'enable_bbcode' => (bool) $post_data['enable_bbcode'], 'enable_smilies' => (bool) $post_data['enable_smilies'], 'enable_urls' => (bool) $post_data['enable_urls'], 'enable_indexing' => (bool) $post_data['enable_indexing'], 'message_md5' => (string) $message_md5, 'post_time' => isset($post_data['post_time']) ? (int) $post_data['post_time'] : $current_time, 'post_checksum' => isset($post_data['post_checksum']) ? (string) $post_data['post_checksum'] : '', 'post_edit_reason' => $post_data['post_edit_reason'], 'post_edit_user' => isset($post_data['post_edit_user']) ? (int) $post_data['post_edit_user'] : 0, 'forum_parents' => $post_data['forum_parents'], 'forum_name' => $post_data['forum_name'], 'notify' => $notify, 'notify_set' => $post_data['notify_set'], 'poster_ip' => isset($post_data['poster_ip']) ? $post_data['poster_ip'] : $user->ip, 'post_edit_locked' => (int) $post_data['post_edit_locked'], 'bbcode_bitfield' => $message_parser->bbcode_bitfield, 'bbcode_uid' => $message_parser->bbcode_uid, 'message' => $message_parser->message, 'attachment_data' => $message_parser->attachment_data, 'filename_data' => $message_parser->filename_data, 'topic_approved' => isset($post_data['topic_approved']) ? $post_data['topic_approved'] : false, 'post_approved' => isset($post_data['post_approved']) ? $post_data['post_approved'] : false, 'post_expire_time' => -1);
    include $phpbb_root_path . 'includes/functions_posting.' . $phpEx;
    $update_message = true;
    $cwd = getcwd();
    chdir('../');
    $phpbb_root_path_tmp = $phpbb_root_path;
    $phpbb_root_path = './';
    $redirect_url = submit_post('reply', $post_data['post_subject'], $post_data['username'], $post_data['topic_type'], $poll, $data, $update_message);
    chdir($cwd);
    $phpbb_root_path = $phpbb_root_path_tmp;
    // Check the permissions for post approval, as well as the queue trigger where users are put on approval with a post count lower than specified. Moderators are not affected.
    $approved = true;
    if (($config['enable_queue_trigger'] && $user->data['user_posts'] < $config['queue_trigger_posts'] || !$auth->acl_get('f_noapprove', $data['forum_id'])) && !$auth->acl_get('m_approve', $data['forum_id'])) {
        $approved = false;
    }
    $reply_success = false;
    $post_id = '';
    if ($redirect_url) {
        preg_match('/&amp;p=(\\d+)/', $redirect_url, $matches);
        $post_id = $matches[1];
        $reply_success = true;
        // get new post_content
        $message = censor_text($data['message']);
        $quote_wrote_string = $user->lang['WROTE'];
        $message = str_replace('[/quote:' . $data['bbcode_uid'] . ']', '[/quote]', $message);
        $message = preg_replace('/\\[quote(?:=&quot;(.*?)&quot;)?:' . $data['bbcode_uid'] . '\\]/ise', "'[quote]' . ('\$1' ? '\$1' . ' {$quote_wrote_string}:\n' : '\n')", $message);
        $blocks = preg_split('/(\\[\\/?quote\\])/i', $message, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
        $quote_level = 0;
        $message = '';
        foreach ($blocks as $block) {
            if ($block == '[quote]') {
                if ($quote_level == 0) {
                    $message .= $block;
                }
                $quote_level++;
            } else {
                if ($block == '[/quote]') {
                    if ($quote_level <= 1) {
                        $message .= $block;
                    }
                    if ($quote_level >= 1) {
                        $quote_level--;
                    }
                } else {
                    if ($quote_level <= 1) {
                        $message .= $block;
                    }
                }
            }
        }
        $message = preg_replace('/\\[(youtube|video|googlevideo|gvideo):' . $data['bbcode_uid'] . '\\](.*?)\\[\\/\\1:' . $data['bbcode_uid'] . '\\]/sie', "video_bbcode_format('\$1', '\$2')", $message);
        $message = preg_replace('/\\[(BBvideo)[\\d, ]+:' . $row['bbcode_uid'] . '\\](.*?)\\[\\/\\1:' . $row['bbcode_uid'] . '\\]/si', "[url=\$2]YouTube Video[/url]", $message);
        $message = preg_replace('/\\[(spoil|spoiler):' . $row['bbcode_uid'] . '\\](.*?)\\[\\/\\1:' . $row['bbcode_uid'] . '\\]/si', "[spoiler]\$2[/spoiler]", $message);
        $message = preg_replace('/\\[b:' . $data['bbcode_uid'] . '\\](.*?)\\[\\/b:' . $data['bbcode_uid'] . '\\]/si', '[b]$1[/b]', $message);
        $message = preg_replace('/\\[i:' . $data['bbcode_uid'] . '\\](.*?)\\[\\/i:' . $data['bbcode_uid'] . '\\]/si', '[i]$1[/i]', $message);
        $message = preg_replace('/\\[u:' . $data['bbcode_uid'] . '\\](.*?)\\[\\/u:' . $data['bbcode_uid'] . '\\]/si', '[u]$1[/u]', $message);
        $message = preg_replace('/\\[color=#(\\w{6}):' . $data['bbcode_uid'] . '\\](.*?)\\[\\/color:' . $data['bbcode_uid'] . '\\]/si', '[color=#$1]$2[/color]', $message);
        // Second parse bbcode here
        if ($data['bbcode_bitfield']) {
            $bbcode = new bbcode(base64_encode($data['bbcode_bitfield']));
            $bbcode->bbcode_second_pass($message, $data['bbcode_uid'], $data['bbcode_bitfield']);
        }
        $message = bbcode_nl2br($message);
        $message = smiley_text($message);
        if (!empty($data['attachment_data'])) {
            parse_attachments($forum_id, $message, $data['attachment_data'], $update_count);
        }
        $updated_post_title = html_entity_decode(strip_tags(censor_text($data['topic_title'])), ENT_QUOTES, 'UTF-8');
        $edit_allowed = $auth->acl_get('m_edit', $forum_id) || $auth->acl_get('f_edit', $forum_id) && !$data['post_edit_locked'] && ($data['post_time'] > time() - $config['edit_time'] * 60 || !$config['edit_time']);
        $delete_allowed = $auth->acl_get('m_delete', $forum_id) || $auth->acl_get('f_delete', $forum_id) && ($data['post_time'] > time() - $config['delete_time'] * 60 || !$config['delete_time']) && !$data['post_edit_locked'];
        $attachments = array();
        if (sizeof($attach_list) && sizeof($data['attachment_data'])) {
            $sql = 'SELECT *
                FROM ' . ATTACHMENTS_TABLE . '
                WHERE ' . $db->sql_in_set('attach_id', $attach_list) . '
                    AND in_message = 0
                ORDER BY filetime DESC';
            $result = $db->sql_query($sql);
            while ($row = $db->sql_fetchrow($result)) {
                $attachment_by_id[$row['attach_id']] = $row;
            }
            $db->sql_freeresult($result);
            foreach ($data['attachment_data'] as $attachment) {
                if (preg_match('/<img src=\\".*?(\\/download\\/file.php\\?id=(\\d+).*?)\\"/is', $attachment, $matches)) {
                    $file_url = html_entity_decode($phpbb_home . $matches[1]);
                    $attach_id = $matches[2];
                    unset($matches);
                    $xmlrpc_attachment = new xmlrpcval(array('filename' => new xmlrpcval($attachment_by_id[$attach_id]['real_filename'], 'base64'), 'filesize' => new xmlrpcval($attachment_by_id[$attach_id]['filesize'], 'int'), 'content_type' => new xmlrpcval('image'), 'thumbnail_url' => new xmlrpcval(''), 'url' => new xmlrpcval($file_url)), 'struct');
                    $attachments[] = $xmlrpc_attachment;
                }
            }
        }
    }
    $xmlrpc_reply_topic = new xmlrpcval(array('result' => new xmlrpcval($reply_success, 'boolean'), 'post_id' => new xmlrpcval($post_id, 'string'), 'state' => new xmlrpcval($approved ? 0 : 1, 'int'), 'post_title' => new xmlrpcval($updated_post_title, 'base64'), 'post_content' => new xmlrpcval(post_html_clean($message), 'base64'), 'post_author_name' => new xmlrpcval(html_entity_decode($user->data['username']), 'base64'), 'is_online' => new xmlrpcval(true, 'boolean'), 'can_edit' => new xmlrpcval($edit_allowed, 'boolean'), 'icon_url' => new xmlrpcval($user->optionget('viewavatars') ? get_user_avatar_url($user->data['user_avatar'], $user->data['user_avatar_type']) : ''), 'post_time' => new xmlrpcval(mobiquo_iso8601_encode($current_time), 'dateTime.iso8601'), 'can_delete' => new xmlrpcval($delete_allowed, 'boolean'), 'allow_smilies' => new xmlrpcval($data['enable_smilies'] ? true : false, 'boolean'), 'attachments' => new xmlrpcval($attachments, 'array')), 'struct');
    return new xmlrpcresp($xmlrpc_reply_topic);
}