decode_message() 공개 메소드

Decode message to be placed back into form box
public decode_message ( $custom_bbcode_uid = '', $update_this_message = true )
예제 #1
0
        $template->assign_var('S_HAS_ATTACHMENTS', true);
        $update_count = array();
        $attachment_data = $message_parser->attachment_data;
        parse_attachments($forum_id, $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);
    }
    if (!sizeof($error)) {
        $template->assign_vars(array('PREVIEW_SUBJECT' => $preview_subject, 'PREVIEW_MESSAGE' => $preview_message, 'PREVIEW_SIGNATURE' => $preview_signature, 'S_DISPLAY_PREVIEW' => true));
    }
}
// Decode text for message display
$post_data['bbcode_uid'] = $mode == 'quote' && !$preview && !$refresh && !sizeof($error) ? $post_data['bbcode_uid'] : $message_parser->bbcode_uid;
$message_parser->decode_message($post_data['bbcode_uid']);
if ($mode == 'quote' && !$submit && !$preview && !$refresh) {
    if ($config['allow_bbcode']) {
        $message_parser->message = '[quote="' . $post_data['quote_username'] . '"]' . censor_text(trim($message_parser->message)) . "[/quote]\n";
    } else {
        $offset = 0;
        $quote_string = "> ";
        $message = censor_text(trim($message_parser->message));
        // see if we are nesting. It's easily tricked but should work for one level of nesting
        if (strpos($message, ">") !== false) {
            $offset = 10;
        }
        $message = utf8_wordwrap($message, 75 + $offset, "\n");
        $message = $quote_string . $message;
        $message = str_replace("\n", "\n" . $quote_string, $message);
        $message_parser->message = $post_data['quote_username'] . " " . $user->lang['WROTE'] . ":\n" . $message . "\n";
예제 #2
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);
        }
    }
}
예제 #3
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;
 }
예제 #4
0
    public function edit($image_id)
    {
        //we cheat a little but we will make good later
        global $phpbb_root_path, $phpEx;
        $image_data = $this->image->get_image_data($image_id);
        $album_id = $image_data['image_album_id'];
        $album_data = $this->album->get_info($album_id);
        $this->user->add_lang_ext('phpbbgallery/core', array('gallery'));
        $this->display->generate_navigation($album_data);
        add_form_key('gallery');
        $submit = $this->request->variable('submit', false);
        $image_backlink = append_sid('./gallery/image/' . $image_id);
        $album_backlink = append_sid('./gallery/album/' . $image_data['image_album_id']);
        $disp_image_data = $image_data;
        $owner_id = $image_data['image_user_id'];
        $album_loginlink = './ucp.php?mode=login';
        $this->gallery_auth->load_user_premissions($this->user->data['user_id']);
        if (!$this->gallery_auth->acl_check('i_edit', $album_id, $owner_id) || $image_data['image_status'] == \phpbbgallery\core\image\image::STATUS_ORPHAN) {
            if (!$this->gallery_auth->acl_check('m_edit', $album_id, $owner_id)) {
                $this->misc->not_authorised($album_backlink, $album_loginlink, 'LOGIN_EXPLAIN_UPLOAD');
            }
        }
        if ($submit) {
            if (!check_form_key('gallery')) {
                trigger_error('FORM_INVALID');
            }
            $image_desc = $this->request->variable('message', array(''), true);
            $image_desc = $image_desc[0];
            $image_name = $this->request->variable('image_name', array(''), true);
            $image_name = $image_name[0];
            if (strlen($image_desc) > $this->gallery_config->get('description_length')) {
                trigger_error($this->user->lang('DESC_TOO_LONG'));
            }
            // Create message parser instance
            include_once $phpbb_root_path . 'includes/message_parser.' . $phpEx;
            $message_parser = new \parse_message();
            $message_parser->message = utf8_normalize_nfc($image_desc);
            if ($message_parser->message) {
                $message_parser->parse(true, true, true, true, false, true, true, true);
            }
            $sql_ary = array('image_name' => $image_name, 'image_name_clean' => utf8_clean_string($image_name), 'image_desc' => $message_parser->message, 'image_desc_uid' => $message_parser->bbcode_uid, 'image_desc_bitfield' => $message_parser->bbcode_bitfield, 'image_allow_comments' => $this->request->variable('allow_comments', 0));
            $errors = array();
            if (empty($sql_ary['image_name_clean'])) {
                $errors[] = $user->lang['MISSING_IMAGE_NAME'];
            }
            if (!$this->gallery_config->get('allow_comments') || !$this->gallery_config->get('comment_user_control')) {
                unset($sql_ary['image_allow_comments']);
            }
            $change_image_count = false;
            if ($this->gallery_auth->acl_check('m_edit', $album_id, $album_data['album_user_id'])) {
                $user_data = $this->image->get_new_author_info($this->request->variable('change_author', '', true));
                if ($user_data) {
                    $sql_ary = array_merge($sql_ary, array('image_user_id' => $user_data['user_id'], 'image_username' => $user_data['username'], 'image_username_clean' => utf8_clean_string($user_data['username']), 'image_user_colour' => $user_data['user_colour']));
                    if ($image_data['image_status'] != $this->image->get_status_unaproved()) {
                        $change_image_count = true;
                    }
                } else {
                    if ($this->request->variable('change_author', '', true)) {
                        $errors[] = $user->lang['INVALID_USERNAME'];
                    }
                }
            }
            $move_to_personal = $this->request->variable('move_to_personal', 0);
            if ($move_to_personal) {
                $personal_album_id = 0;
                if ($user->data['user_id'] != $image_data['image_user_id']) {
                    $image_user = new \phpbbgallery\core\user($db, $image_data['image_user_id']);
                    $personal_album_id = $image_user->get_data('personal_album_id');
                    // The User has no personal album, moderators can created that without the need of permissions
                    if (!$personal_album_id) {
                        $personal_album_id = $this->album->generate_personal_album($image_data['image_username'], $image_data['image_user_id'], $image_data['image_user_colour'], $image_user);
                    }
                } else {
                    $personal_album_id = $this->user->get_data('personal_album_id');
                    if (!$personal_album_id && $this->gallery_auth->acl_check('i_upload', $this->gallery_auth->get_own_album())) {
                        $personal_album_id = $this->album->generate_personal_album($image_data['image_username'], $image_data['image_user_id'], $image_data['image_user_colour'], phpbb_gallery::$user);
                    }
                }
                if ($personal_album_id) {
                    $sql_ary['image_album_id'] = $personal_album_id;
                }
            }
            $rotate = $this->request->variable('rotate', array(0));
            $rotate = isset($rotate[0]) ? $rotate[0] : 0;
            if ($this->gallery_config->get('allow_rotate') && $rotate > 0 && $rotate % 90 == 0) {
                $image_tools = new \phpbbgallery\core\file\file();
                $image_tools->set_image_options($this->gallery_config->get('max_filesize'), $this->gallery_config->get('max_height'), $this->gallery_config->get('max_width'));
                $image_tools->set_image_data($this->url->path('upload') . $image_data['image_filename']);
                // Rotate the image
                $image_tools->rotate_image($rotate, $this->gallery_config->get('allow_rotate'));
                if ($image_tools->rotated) {
                    $image_tools->write_image($image_tools->image_source, $this->gallery_config->get('jpg_quality'), true);
                }
                @unlink($this->url->path('thumbnail') . $image_data['image_filename']);
                @unlink($this->url->path('medium') . $image_data['image_filename']);
            }
            $error = implode('<br />', $errors);
            if (!$error) {
                $sql = 'UPDATE ' . $this->table_images . '
					SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . '
					WHERE image_id = ' . $image_id;
                $this->db->sql_query($sql);
                $this->album->update_info($album_data['album_id']);
                if ($move_to_personal && $personal_album_id) {
                    $this->album->update_info($personal_album_id);
                }
                if ($change_image_count) {
                    $new_user = new phpbb_gallery_user($db, $user_data['user_id'], false);
                    $new_user->update_images(1);
                    $old_user = new phpbb_gallery_user($db, $image_data['image_user_id'], false);
                    $old_user->update_images(-1);
                }
                if ($this->user->data['user_id'] != $image_data['image_user_id']) {
                    $this->gallery_log->add_log('moderator', 'edit', $image_data['image_album_id'], $image_id, array('LOG_GALLERY_EDITED', $image_name));
                }
                $message = $this->user->lang['IMAGES_UPDATED_SUCCESSFULLY'];
                $message .= '<br /><br />' . sprintf($this->user->lang['CLICK_RETURN_IMAGE'], '<a href="' . $image_backlink . '">', '</a>');
                $message .= '<br /><br />' . sprintf($this->user->lang['CLICK_RETURN_ALBUM'], '<a href="' . $album_backlink . '">', '</a>');
                $this->url->meta_refresh(3, $image_backlink);
                trigger_error($message);
            }
            $disp_image_data = array_merge($disp_image_data, $sql_ary);
        }
        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 = $disp_image_data['image_desc'];
        $message_parser->decode_message($disp_image_data['image_desc_uid']);
        $page_title = $disp_image_data['image_name'];
        $this->template->assign_block_vars('image', array('U_IMAGE' => $this->image->generate_link('thumbnail', 'plugin', $image_id, $image_data['image_name'], $album_id), 'IMAGE_NAME' => $disp_image_data['image_name'], 'IMAGE_DESC' => $message_parser->message));
        $this->template->assign_vars(array('L_DESCRIPTION_LENGTH' => $this->user->lang('DESCRIPTION_LENGTH', $this->gallery_config->get('description_length')), 'S_EDIT' => true, 'S_ALBUM_ACTION' => $this->helper->route('phpbbgallery_image_edit', array('image_id' => $image_id)), 'ERROR' => isset($error) ? $error : '', 'U_VIEW_IMAGE' => $this->helper->route('phpbbgallery_image', array('image_id' => $image_id)), 'IMAGE_NAME' => $image_data['image_name'], 'S_CHANGE_AUTHOR' => $this->gallery_auth->acl_check('m_edit', $album_id, $album_data['album_user_id']), 'U_FIND_USERNAME' => $this->url->append_sid('phpbb', 'memberlist', 'mode=searchuser&amp;form=postform&amp;field=change_author&amp;select_single=true'), 'S_COMMENTS_ENABLED' => $this->gallery_config->get('allow_comments') && $this->gallery_config->get('comment_user_control'), 'S_ALLOW_COMMENTS' => $image_data['image_allow_comments'], 'NUM_IMAGES' => 1, 'S_ALLOW_ROTATE' => $this->gallery_config->get('allow_rotate') && function_exists('imagerotate'), 'S_MOVE_MODERATOR' => $this->user->data['user_id'] != $image_data['image_user_id'] ? true : false));
        return $this->helper->render('gallery/posting_body.html', $page_title);
    }
예제 #5
0
        }
        $poll = false;
        $data = array('forum_id' => $report['forum_id'], 'topic_id' => $report['topic_id'], 'topic_title' => $report['report_title'], 'icon_id' => 0, 'post_time' => time(), 'message' => $message_parser->message, 'message_md5' => $message_md5, 'bbcode_uid' => $message_parser->bbcode_uid, 'bbcode_bitfield' => $message_parser->bbcode_bitfield, 'enable_bbcode' => $comment_data['enable_bbcode'], 'enable_smilies' => $comment_data['enable_smilies'], 'enable_urls' => $comment_data['enable_magic_url'], 'enable_sig' => 0, 'post_edit_locked' => 0, 'enable_indexing' => $report['enable_indexing'], 'forum_name' => $report['project_title'], 'notify' => false, 'notify_set' => false);
        submit_post('reply', $comment_data['comment_subject'], '', $report['topic_type'], $poll, $data);
        // Send out notifications
        $notif_users = get_subscribed_users($report['forum_id'], $report['topic_id']);
        send_notification($notif_users, 'bug_comment_added', array('REPORT_ID' => $report['report_id'], 'REPORT_TITLE' => $report['report_title'], 'PROJECT_TITLE' => $report['project_title'], 'U_REPORT' => generate_board_url() . '/' . $url_rewriter->rewrite("bugs.{$phpEx}", "mode=report&project={$report['project_name']}&report_id={$report_id}"), 'U_COMMENT' => generate_board_url() . '/' . $url_rewriter->rewrite("bugs.{$phpEx}", "mode=report&project={$report['project_name']}&report_id={$report_id}") . '#comment-' . $data['post_id'], 'PERFORMER' => $user->data['username']));
        $redirect_url = append_sid("{$phpbb_root_path}bugs.{$phpEx}", "mode=report&amp;project={$project_name}&amp;report_id={$report_id}#comment-{$data['post_id']}");
        meta_refresh(3, $redirect_url);
        $message = sprintf($user->lang['COMMENT_ADDED'], '<a href="' . $redirect_url . '">', '</a>');
        trigger_error($message);
    }
    // Display forms
    add_form_key('add_comment');
    if (isset($message_parser)) {
        $comment_data['comment_message'] = $message_parser->decode_message($message_parser->bbcode_uid, false);
    }
    $report['bbcode_options'] = ($report['enable_bbcode'] ? OPTION_FLAG_BBCODE : 0) + ($report['enable_smilies'] ? OPTION_FLAG_SMILIES : 0) + ($report['enable_magic_url'] ? OPTION_FLAG_LINKS : 0);
    $template->assign_vars(array('COMMENT_SUBJECT' => $comment_data['comment_subject'], 'COMMENT_MESSAGE' => $comment_data['comment_message'], 'S_BBCODE_CHECKED' => $comment_data['enable_bbcode'] ? '' : ' checked="checked"', 'S_SMILIES_CHECKED' => $comment_data['enable_smilies'] ? '' : ' checked="checked"', 'S_MAGIC_URL_CHECKED' => $comment_data['enable_magic_url'] ? '' : ' checked="checked"', 'S_BBCODE_ALLOWED' => $auth->acl_get('f_bbcode', $report['forum_id']), 'S_SMILIES_ALLOWED' => $auth->acl_get('f_smilies', $report['forum_id']), 'S_LINKS_ALLOWED' => $config['allow_post_links'] ? true : false, 'ERROR' => isset($error) && sizeof($error) ? implode('<br />', $error) : false, 'S_PREVIEW_BOLD' => !empty($error) || !isset($_POST['preview']) ? true : false, 'REPORT_TITLE' => $report['report_title'], 'REPORT_TEXT' => generate_text_for_display($report['report_desc'], $report['bbcode_uid'], $report['bbcode_bitfield'], $report['bbcode_options']), 'REPORT_ID' => $report['report_id'], 'PROJECT_TITLE' => $report['project_title'], 'REPORT_COMPONENT' => $report['component_title'], 'REPORT_STATUS' => $report['status_title'], 'REPORT_VERSION' => $report['version_title'], 'ASSIGNED' => $report['assigned_id'] == 0 ? $user->lang['UNASSIGNED'] : get_username_string('username', $report['assigned_id'], $report['assigned_name'], $report['assigned_colour']), 'ASSIGNED_COLOUR' => $report['assigned_id'] == 0 ? $user->lang['UNASSIGNED'] : get_username_string('colour', $report['assigned_id'], $report['assigned_name'], $report['assigned_colour']), 'ASSIGNED_FULL' => $report['assigned_id'] == 0 ? $user->lang['UNASSIGNED'] : get_username_string('full', $report['assigned_id'], $report['assigned_name'], $report['assigned_colour']), 'REPORTED' => get_username_string('username', $report['topic_poster'], $report['topic_first_poster_name'], $report['topic_first_poster_colour']), 'REPORTED_COLOUR' => get_username_string('colour', $report['topic_poster'], $report['topic_first_poster_name'], $report['topic_first_poster_colour']), 'REPORTED_FULL' => get_username_string('full', $report['topic_poster'], $report['topic_first_poster_name'], $report['topic_first_poster_colour']), 'REPORT_TIME' => $user->format_date($report['topic_time']), 'S_IS_CLOSED' => $report['report_closed'] == 1, 'U_BUG_TRACKER' => append_sid("{$phpbb_root_path}bugs.{$phpEx}"), 'U_RETURN' => append_sid("{$phpbb_root_path}bugs.{$phpEx}", "mode=report&amp;project={$report['project_name']}&amp;report_id={$report_id}"), 'U_SUBSCRIBE' => append_sid("{$phpbb_root_path}bugs.{$phpEx}", "mode=report&amp;project={$report['project_name']}&amp;report_id={$report_id}&amp;action=subscribe"), 'U_UNSUBSCRIBE' => append_sid("{$phpbb_root_path}bugs.{$phpEx}", "mode=report&amp;project={$report['project_name']}&amp;report_id={$report_id}&amp;action=unsubscribe"), 'S_IS_SUBSCRIBED' => $is_subscribed, 'S_IS_LOCKED' => $report['topic_status'] == ITEM_LOCKED, 'S_DISPLAY_SUBSCRIBE_INFO' => $is_subscribed || $auth->acl_get('f_subscribe', $report['forum_id'])));
    // Display the page
    site_header($user->lang['BUG_TRACKER'] . ' - ' . $report['report_title'], 'bugs', array(array('bugs.' . $phpEx, 'BUG_TRACKER'), array("bugs.{$phpEx}?mode=project&amp;project={$report['project_name']}", $report['project_title']), array("{$phpbb_root_path}bugs.{$phpEx}?mode=report&amp;project={$report['project_name']}&amp;report_id={$report_id}", sprintf($user->lang['BUG_NO'], $report_id)), array("bugs.{$phpEx}?mode=reply&amp;project={$report['project_name']}&amp;report_id={$report_id}", 'ADD_COMMENT')));
    $template->set_filenames(array('body' => 'bugs_comment_add.html'));
    site_footer();
} else {
    /**
     * Query projects
     */
    $sql = $db->sql_build_query('SELECT', array('SELECT' => 'p.*, f.forum_desc AS project_description, f.forum_desc_uid, f.forum_desc_bitfield, f.forum_desc_options', 'FROM' => array(BUGS_PROJECTS_TABLE => 'p'), 'LEFT_JOIN' => array(array('FROM' => array(FORUMS_TABLE => 'f'), 'ON' => 'p.forum_id = f.forum_id')), 'ORDER_BY' => 'f.left_id ASC'));
    $result = $db->sql_query($sql);
    while ($row = $db->sql_fetchrow($result)) {
        if ($auth->acl_get('f_c_see', $row['forum_id'])) {
	</tr>
<?php 
            }
            ?>
	<tr>
		<td class="row1"><b><?php 
            echo $_CLASS['core_user']->lang['FORUM_RULES'];
            ?>
: </b><br /><span class="gensmall"><?php 
            echo $_CLASS['core_user']->lang['FORUM_RULES_EXPLAIN'];
            ?>
</span></td>
		<td class="row2"><table cellspacing="2" cellpadding="0" border="0"><tr><td colspan="6"><textarea class="post" rows="4" cols="70" name="forum_rules">
<?php 
            if ($forum_rules) {
                $message_parser->decode_message();
                echo $message_parser->message;
            }
            ?>
</textarea></td></tr><tr>
			<td width="10"><input type="checkbox" name="parse_bbcode"<?php 
            echo $bbcode_checked;
            ?>
 /></td><td><?php 
            echo $_CLASS['core_user']->lang['PARSE_BBCODE'];
            ?>
</td><td width="10"><input type="checkbox" name="parse_smilies"<?php 
            echo $smilies_checked;
            ?>
 /></td><td><?php 
            echo $_CLASS['core_user']->lang['PARSE_SMILIES'];
예제 #7
0
function get_raw_post_func($xmlrpc_params)
{
    global $db, $auth, $user, $config, $template, $cache, $phpEx, $phpbb_root_path, $phpbb_home;
    $user->setup('posting');
    include $phpbb_root_path . 'includes/message_parser.' . $phpEx;
    $params = php_xmlrpc_decode($xmlrpc_params);
    // get post id from parameters
    $post_id = intval($params[0]);
    $post_data = array();
    $sql = 'SELECT p.*, t.*, f.*
            FROM ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . ' t, ' . FORUMS_TABLE . " f\n            WHERE p.post_id = {$post_id}\n            AND t.topic_id = p.topic_id\n            AND (f.forum_id = t.forum_id OR (t.topic_type = " . POST_GLOBAL . ' AND f.forum_type = ' . FORUM_POST . '))';
    $result = $db->sql_query_limit($sql, 1);
    $post_data = $db->sql_fetchrow($result);
    $db->sql_freeresult($result);
    if (!$post_data) {
        trigger_error('NO_POST');
    }
    // Use post_row values in favor of submitted ones...
    $forum_id = (int) $post_data['forum_id'];
    $topic_id = (int) $post_data['topic_id'];
    $post_id = (int) $post_id;
    // Need to login to passworded forum first?
    if ($post_data['forum_password'] && !check_forum_password($forum_id)) {
        trigger_error('LOGIN_FORUM');
    }
    // Is the user able to read within this forum?
    if (!$auth->acl_get('f_read', $forum_id)) {
        trigger_error('USER_CANNOT_READ');
    }
    // Permission to do the action asked?
    if (!($user->data['is_registered'] && $auth->acl_gets('f_edit', 'm_edit', $forum_id))) {
        trigger_error('USER_CANNOT_EDIT');
    }
    // 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');
    }
    // Can we edit this post ... if we're a moderator with rights then always yes
    // else it depends on editing times, lock status and if we're the correct user
    if (!$auth->acl_get('m_edit', $forum_id)) {
        if ($user->data['user_id'] != $post_data['poster_id']) {
            trigger_error('USER_CANNOT_EDIT');
        }
        if (!($post_data['post_time'] > time() - $config['edit_time'] * 60 || !$config['edit_time'])) {
            trigger_error('CANNOT_EDIT_TIME');
        }
        if ($post_data['post_edit_locked']) {
            trigger_error('CANNOT_EDIT_POST_LOCKED');
        }
    }
    $message_parser = new parse_message();
    if (isset($post_data['post_text'])) {
        $message_parser->message =& $post_data['post_text'];
        unset($post_data['post_text']);
    }
    // Do we want to edit our post ?
    if ($post_data['bbcode_uid']) {
        $message_parser->bbcode_uid = $post_data['bbcode_uid'];
    }
    // Decode text for message display
    $message_parser->decode_message($post_data['bbcode_uid']);
    $post_data['post_text'] = $message_parser->message;
    return new xmlrpcresp(new xmlrpcval(array('post_id' => new xmlrpcval($post_id), 'post_title' => new xmlrpcval(html_entity_decode(strip_tags($post_data['post_subject'])), 'base64'), 'post_content' => new xmlrpcval(html_entity_decode($post_data['post_text']), 'base64')), 'struct'));
}
예제 #8
0
파일: edit.php 프로젝트: tas2580/wiki
    /**
     * Edit an article
     *
     * @param	string	$article	URL of the article
     * @return	object
     */
    public function edit_article($article)
    {
        // @TODO
        $this->option['bbcode'] = $this->option['url'] = $this->option['img'] = $this->option['flash'] = $this->option['quote'] = $this->option['smilies'] = true;
        // If no auth to edit, display error message
        if (!$this->auth->acl_get('u_wiki_edit')) {
            trigger_error('NO_ARTICLE');
        }
        // Setup message parser
        $this->message_parser = $this->setup_parser();
        // Get data for article
        $this->data = $this->get_article_data($article);
        // Article is a redirect and no auth to edit redirect
        if (!empty($this->data['article_redirect']) && !$this->auth->acl_get('u_wiki_set_redirect')) {
            trigger_error('NOT_AUTHORISED');
        }
        $this->user->add_lang('posting');
        $preview = $this->request->is_set_post('preview');
        $submit = $this->request->is_set_post('submit');
        $error = array();
        if ($preview || $submit) {
            $this->data['article_title'] = $this->request->variable('title', '', true);
            $this->data['article_text'] = $this->request->variable('message', '', true);
            $this->data['article_description'] = $this->request->variable('article_description', '', true);
            $this->data['article_edit_reason'] = $this->request->variable('edit_reason', '', true);
            $this->data['article_sources'] = $this->request->variable('sources', '', true);
            $this->data['article_topic_id'] = $this->auth->acl_get('u_wiki_edit_topic') ? $this->request->variable('topic_id', '', true) : $this->data['article_topic_id'];
            $this->data['article_approved'] = $this->auth->acl_get('u_wiki_set_active') ? $this->request->variable('set_active', 0) : 0;
            $this->data['article_sticky'] = $this->auth->acl_get('u_wiki_set_sticky') ? $this->request->variable('set_sticky', 0) : $this->data['article_sticky'];
            $this->data['article_redirect'] = $this->auth->acl_get('u_wiki_set_redirect') ? $this->request->variable('article_redirect', '', true) : $this->data['article_redirect'];
            $this->data['article_time_created'] = empty($this->data['article_time_created']) ? time() : $this->data['article_time_created'];
            // Validate user input
            $validate_array = array('article_title' => array('string', false, 1, 255), 'article_text' => array('string', false, $this->config['min_post_chars'], $this->config['max_post_chars']), 'article_edit_reason' => array('string', true, 0, 255), 'article_redirect' => array('string', true, 0, 255), 'article_description' => array('string', true, 0, 255), 'article_sources' => array('string', true, 0, 255));
            if (!function_exists('validate_data')) {
                include $this->phpbb_root_path . 'includes/functions_user.' . $this->php_ext;
            }
            $error = validate_data($this->data, $validate_array);
            // Validate sources URL
            $sources_array = explode("\n", $this->data['article_sources']);
            foreach ($sources_array as $source) {
                if (!empty($source) && !filter_var($source, FILTER_VALIDATE_URL)) {
                    $error[] = $this->user->lang['INVALID_SOURCE_URL'];
                }
            }
            $this->message_parser->message = $this->data['article_text'];
        }
        if (sizeof($error)) {
            $this->template->assign_vars(array('ERROR' => implode('<br />', $error)));
            $this->display_edit_form(false);
        } else {
            if ($preview) {
                $this->message_parser->parse($this->option['bbcode'], $this->option['url'], $this->option['smilies'], $this->option['img'], $this->option['flash'], $this->option['quote']);
                $this->message_parser->format_display($this->option['bbcode'], $this->option['url'], $this->option['smilies']);
                foreach ($sources_array as $source) {
                    if (!empty($source)) {
                        $this->template->assign_block_vars('article_sources', array('SOURCE' => $source));
                    }
                }
                $this->display_edit_form(true);
            } else {
                if ($submit) {
                    $this->message_parser->parse($this->option['bbcode'], $this->option['url'], $this->option['smilies'], $this->option['img'], $this->option['flash'], $this->option['quote']);
                    $sql_data = array('article_title' => $this->data['article_title'], 'article_url' => $article, 'article_text' => $this->message_parser->message, 'bbcode_uid' => $this->message_parser->bbcode_uid, 'bbcode_bitfield' => $this->message_parser->bbcode_bitfield, 'article_approved' => (int) $this->data['article_approved'], 'article_user_id' => (int) $this->user->data['user_id'], 'article_last_edit' => time(), 'article_time_created' => $this->data['article_time_created'], 'article_edit_reason' => $this->data['article_edit_reason'], 'article_topic_id' => (int) $this->data['article_topic_id'], 'article_sources' => $this->data['article_sources'], 'article_sticky' => (int) $this->data['article_sticky'], 'article_views' => (int) $this->data['article_views'], 'article_redirect' => $this->data['article_redirect'], 'article_description' => $this->data['article_description'], 'article_toc' => '');
                    $sql = 'INSERT INTO ' . $this->article_table . '
				' . $this->db->sql_build_array('INSERT', $sql_data);
                    $this->db->sql_query($sql);
                    $article_id = $this->db->sql_nextid();
                    if ($this->auth->acl_get('u_wiki_set_active') && $this->data['article_approved'] != 0) {
                        $this->set_active_version($article_id);
                    } else {
                        $notify_data = array('article_id' => $article_id, 'article_title' => $this->data['article_title'], 'article_url' => $article, 'user_id' => $this->user->data['user_id']);
                        $this->notification_manager->add_notifications('tas2580.wiki.notification.type.articke_edit', $notify_data);
                    }
                    $msg = $this->data['article_approved'] != 0 ? $this->user->lang['EDIT_ARTICLE_SUCCESS'] : $this->user->lang['EDIT_ARTICLE_SUCCESS_INACTIVE'];
                    $back_url = empty($article) ? $this->helper->route('tas2580_wiki_index', array()) : $this->helper->route('tas2580_wiki_article', array('article' => $article));
                    trigger_error($msg . '<br /><br /><a href="' . $back_url . '">' . $this->user->lang['BACK_TO_ARTICLE'] . '</a>');
                } else {
                    $this->message_parser->message = $this->data['article_text'];
                    $this->message_parser->decode_message($this->data['bbcode_uid']);
                    $this->display_edit_form(false);
                }
            }
        }
        return $this->helper->render('article_edit.html', $this->user->lang['EDIT_WIKI']);
    }
 function generate_text($profile_row, $preview = false)
 {
     global $_CLASS, $site_file_root;
     $value = $this->get_var('', $profile_row, $profile_row['lang_default_value'], $preview);
     if ($preview == false) {
         include_once $site_file_root . 'includes/forums/message_parser.php';
         include_once $site_file_root . 'includes/forums/functions_posting.php';
         $message_parser = new parse_message();
         $message_parser->message = $value;
         $message_parser->decode_message($_CLASS['core_user']->profile_fields[str_replace('pf_', '', $profile_row['field_ident']) . '_bbcode_uid']);
         $value = $message_parser->message;
     }
     $field_length = explode('|', $profile_row['field_length']);
     $profile_row['field_rows'] = $field_length[0];
     $profile_row['field_cols'] = $field_length[1];
     $this->set_tpl_vars($profile_row, $value);
     return $this->get_cp_html();
 }
예제 #10
0
function get_quote_post_func($xmlrpc_params)
{
    global $db, $auth, $user, $phpEx, $phpbb_root_path;
    $user->setup('posting');
    include $phpbb_root_path . 'includes/message_parser.' . $phpEx;
    $params = php_xmlrpc_decode($xmlrpc_params);
    $post_ids = explode('-', $params[0]);
    $quote_messages = array();
    foreach ($post_ids as $post_id) {
        // get post id from parameters
        $post_id = intval($post_id);
        $post_data = array();
        // We need to know some basic information in all cases before we do anything.
        if (!$post_id) {
            trigger_error('NO_POST');
        }
        $sql = 'SELECT t.*, p.*, f.*, u.username
                FROM ' . POSTS_TABLE . ' p
                    LEFT JOIN ' . TOPICS_TABLE . ' t ON (p.topic_id = t.topic_id) 
                    LEFT JOIN ' . FORUMS_TABLE . ' f ON (f.forum_id = t.forum_id OR (t.topic_type = ' . POST_GLOBAL . ' AND f.forum_type = ' . FORUM_POST . '))
                    LEFT JOIN ' . USERS_TABLE . ' u ON (p.poster_id = u.user_id)' . "\r\r\n                WHERE p.post_id = {$post_id}";
        $result = $db->sql_query_limit($sql, 1);
        $post_data = $db->sql_fetchrow($result);
        $db->sql_freeresult($result);
        if (!$post_data) {
            trigger_error('NO_POST');
        }
        // Use post_row values in favor of submitted ones...
        $forum_id = (int) $post_data['forum_id'];
        $topic_id = (int) $post_data['topic_id'];
        $post_id = (int) $post_data['post_id'];
        // Need to login to passworded forum first?
        if ($post_data['forum_password'] && !check_forum_password($forum_id)) {
            trigger_error('LOGIN_FORUM');
        }
        // Is the user able to read within this forum?
        if (!$auth->acl_get('f_read', $forum_id)) {
            trigger_error('USER_CANNOT_READ');
        }
        if (!$auth->acl_get('f_reply', $forum_id)) {
            trigger_error('USER_CANNOT_REPLY');
        }
        // 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');
        }
        // Determine some vars
        if (isset($post_data['poster_id']) && $post_data['poster_id'] == ANONYMOUS) {
            $post_data['quote_username'] = !empty($post_data['post_username']) ? $post_data['post_username'] : $user->lang['GUEST'];
        } else {
            $post_data['quote_username'] = isset($post_data['username']) ? $post_data['username'] : '';
        }
        $message_parser = new parse_message();
        if (isset($post_data['post_text'])) {
            $message_parser->message = $post_data['post_text'];
            $message_parser->decode_message($post_data['bbcode_uid']);
            $message_parser->message = '[quote=&quot;' . $post_data['quote_username'] . '&quot;]' . censor_text(trim($message_parser->message)) . "[/quote]";
            //$post_data['post_subject'] = ((strpos($post_data['post_subject'], 'Re: ') !== 0) ? 'Re: ' : '') . censor_text($post_data['post_subject']);
            $quote_messages[] = $message_parser->message;
        }
    }
    return new xmlrpcresp(new xmlrpcval(array('post_id' => new xmlrpcval($params[0]), 'post_title' => new xmlrpcval('', 'base64'), 'post_content' => new xmlrpcval(html_entity_decode(implode("\n", $quote_messages)), 'base64')), 'struct'));
}
예제 #11
0
                            }
                            $sql = 'UPDATE ' . GALLERY_IMAGES_TABLE . ' 
						SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
						WHERE image_id = ' . $image_id;
                            $db->sql_query($sql);
                            if ($move_to_personal && $personal_album_id) {
                                phpbb_gallery_album::update_info($album_data['album_id']);
                                phpbb_gallery_album::update_info($personal_album_id);
                            }
                            if ($user->data['user_id'] != $image_data['image_user_id']) {
                                add_log('gallery', $image_data['image_album_id'], $image_id, 'LOG_GALLERY_EDITED', $image_name);
                            }
                        }
                        $message_parser = new parse_message();
                        $message_parser->message = $image_data['image_desc'];
                        $message_parser->decode_message($image_data['image_desc_uid']);
                        $template->assign_vars(array('IMAGE_NAME' => $image_data['image_name'], 'MESSAGE' => $message_parser->message, 'L_DESCRIPTION_LENGTH' => sprintf($user->lang['DESCRIPTION_LENGTH'], phpbb_gallery_config::get('description_length')), 'U_IMAGE' => $image_id ? phpbb_gallery_url::append_sid('image', "album_id={$album_id}&amp;image_id={$image_id}") : '', 'U_VIEW_IMAGE' => $image_id ? phpbb_gallery_url::append_sid('image_page', "album_id={$album_id}&amp;image_id={$image_id}") : '', 'IMAGE_RSZ_WIDTH' => phpbb_gallery_config::get('medium_width'), 'IMAGE_RSZ_HEIGHT' => phpbb_gallery_config::get('medium_height'), 'S_IMAGE' => true, 'S_EDIT' => true, 'S_ALLOW_ROTATE' => phpbb_gallery_config::get('allow_rotate') && function_exists('imagerotate'), 'S_MOVE_PERSONAL' => phpbb_gallery::$auth->acl_check('i_upload', phpbb_gallery_auth::OWN_ALBUM) || phpbb_gallery::$user->get_data('personal_album_id') || $user->data['user_id'] != $image_data['image_user_id'] ? true : false, 'S_MOVE_MODERATOR' => $user->data['user_id'] != $image_data['image_user_id'] ? true : false, 'S_ALBUM_ACTION' => phpbb_gallery_url::append_sid('posting', "mode=image&amp;submode=edit&amp;album_id={$album_id}&amp;image_id={$image_id}")));
                        $message = $user->lang['IMAGES_UPDATED_SUCCESSFULLY'] . '<br />';
                        $page_title = $user->lang['EDIT_IMAGE'];
                    }
                    break;
                case 'report':
                    if ($submode == 'report') {
                        if ($submit) {
                            if (!check_form_key('gallery')) {
                                trigger_error('FORM_INVALID');
                            }
                            $report_message = request_var('message', '', true);
                            $error = '';
                            if ($report_message == '') {
                                $error = $user->lang['MISSING_REPORT_REASON'];
예제 #12
0
    private function post()
    {
        global $phpbb_root_path, $phpEx, $template, $db, $auth;
        global $config, $user;
        if (!function_exists('generate_smilies')) {
            include $phpbb_root_path . 'includes/functions_posting.' . $phpEx;
        }
        if (!function_exists('submit_gb_post')) {
            include $phpbb_root_path . 'includes/functions_guestbook.' . $phpEx;
        }
        if (!class_exists('parse_message')) {
            include $phpbb_root_path . 'includes/message_parser.' . $phpEx;
        }
        $user->add_lang('posting');
        // Grab only parameters needed here
        $post_id = request_var('p', 0);
        $lastclick = request_var('lastclick', 0);
        $submit = isset($_POST['post']) ? true : false;
        $preview = isset($_POST['preview']) ? true : false;
        $delete = isset($_POST['delete']) ? true : false;
        $refresh = isset($_POST['add_file']) || isset($_POST['delete_file']) || isset($_POST['full_editor']) ? true : false;
        $mode = $delete && !$preview && !$refresh && $submit ? 'delete' : request_var('gbmode', '');
        $error = $post_data = array();
        $current_time = time();
        // Was cancel pressed? If so then redirect to the appropriate page
        if ($current_time - $lastclick < 2 && $submit) {
            $redirect = append_sid("{$phpbb_root_path}memberlist.{$phpEx}", "mode=viewprofile&amp;u={$this->user_id}&amp;gbmode=display&amp;{$post_id}#p{$post_id}");
            redirect($redirect);
        }
        // We need to know some basic information in all cases before we do anything.
        switch ($mode) {
            case 'quote':
            case 'edit':
            case 'delete':
                if (!$post_id) {
                    $user->setup('posting');
                    trigger_error('NO_POST');
                }
                $sql = 'SELECT g.*, u.*
					FROM  ' . GUESTBOOK_TABLE . ' g, ' . USERS_TABLE . ' u
						WHERE u.user_id = g.poster_id
							AND post_id = ' . (int) $post_id;
                break;
            case 'smilies':
                $sql = '';
                generate_smilies('window');
                break;
            case 'popup':
                upload_popup();
                break;
            default:
                $sql = '';
                break;
        }
        if ($sql) {
            $result = $db->sql_query($sql);
            $post_data = $db->sql_fetchrow($result);
            $db->sql_freeresult($result);
            if (!$post_data) {
                $user->setup('posting');
                trigger_error('NO_POST');
            }
        }
        if ($mode == 'popup') {
            upload_popup($post_data['forum_style']);
            return;
        }
        if ($config['enable_post_confirm'] && !$user->data['is_registered']) {
            include $phpbb_root_path . 'includes/captcha/captcha_factory.' . $phpEx;
            $captcha =& phpbb_captcha_factory::get_instance($config['captcha_plugin']);
            $captcha->init(CONFIRM_POST);
        }
        // Use post_row values in favor of submitted ones...
        $post_id = !empty($post_data['post_id']) ? (int) $post_data['post_id'] : (int) $post_id;
        // Check permissions
        if ($user->data['is_bot']) {
            redirect(append_sid("{$phpbb_root_path}index.{$phpEx}"));
        }
        // Is the user able to read within this forum?
        if (!$auth->acl_get('u_gb_view')) {
            if ($user->data['user_id'] != ANONYMOUS) {
                trigger_error('USER_CANNOT_READ');
            }
            login_box('', $user->lang['LOGIN_EXPLAIN_POST']);
        }
        // Permission to do the action asked?
        $is_authed = false;
        switch ($mode) {
            case 'post':
                if ($auth->acl_get('u_gb_post')) {
                    $is_authed = true;
                }
                break;
            case 'quote':
                $post_data['post_edit_locked'] = 0;
                // @TODO: Decide if we want to add a config option/ucp option/checkbox for this feature.
                if ($post_data['poster_id'] != ANONYMOUS) {
                    $post_data['orginal_author'] = $post_data['poster_id'];
                }
                // no break;
            // no break;
            case 'reply':
                if ($auth->acl_get('u_gb_post')) {
                    $is_authed = true;
                }
                break;
            case 'edit':
                if ($user->data['is_registered'] && $auth->acl_gets('u_gb_edit', 'm_gb_edit')) {
                    $is_authed = true;
                }
                break;
            case 'delete':
                if ($user->data['is_registered'] && $auth->acl_gets('u_gb_delete', 'm_gb_delete')) {
                    $is_authed = true;
                }
                break;
        }
        if (!$is_authed) {
            $check_auth = $mode == 'quote' ? 'reply' : $mode;
            if ($user->data['is_registered']) {
                trigger_error('USER_CANNOT_' . strtoupper($check_auth));
            }
            login_box('', $user->lang['LOGIN_EXPLAIN_' . strtoupper($mode)]);
        }
        // Can we edit this post ... if we're a moderator with rights then always yes
        // else it depends on editing times, lock status and if we're the correct user
        if ($mode == 'edit' && !$auth->acl_get('m_gb_edit')) {
            if ($user->data['user_id'] != $post_data['poster_id']) {
                trigger_error('USER_CANNOT_EDIT');
            }
            if (!($post_data['post_time'] > time() - $config['edit_time'] * 60 || !$config['edit_time'])) {
                trigger_error('CANNOT_EDIT_TIME');
            }
            if ($post_data['post_edit_locked']) {
                trigger_error('CANNOT_EDIT_POST_LOCKED');
            }
        }
        // Handle delete mode...
        if ($mode == 'delete') {
            handle_gb_post_delete($post_id, $post_data, $this);
            return;
        }
        // Determine some vars
        if (isset($post_data['poster_id']) && $post_data['poster_id'] == ANONYMOUS) {
            $post_data['quote_username'] = !empty($post_data['post_username']) ? $post_data['post_username'] : $user->lang['GUEST'];
        } else {
            $post_data['quote_username'] = isset($post_data['username']) ? $post_data['username'] : '';
        }
        $post_data['post_edit_locked'] = isset($post_data['post_edit_locked']) ? (int) $post_data['post_edit_locked'] : 0;
        $post_data['post_subject_md5'] = isset($post_data['post_subject']) && $mode == 'edit' ? md5($post_data['post_subject']) : '';
        $post_data['post_subject'] = in_array($mode, array('quote', 'edit')) ? $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['icon_id'] = !isset($post_data['icon_id']) || in_array($mode, array('quote', 'reply')) ? 0 : (int) $post_data['icon_id'];
        $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('poster_id' => $user->data['user_id'], 'enable_magic_url' => 0, '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 ($post_data['poster_id'] == ANONYMOUS) {
            $post_data['username'] = $mode == 'quote' || $mode == 'edit' ? trim($post_data['post_username']) : '';
        } else {
            $post_data['username'] = $mode == 'quote' || $mode == 'edit' ? trim($post_data['username']) : '';
        }
        $post_data['enable_urls'] = $post_data['enable_magic_url'];
        if ($mode != 'edit') {
            $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_icons'] = 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);
        // Do we want to edit our post ?
        if ($mode == 'edit' && $post_data['bbcode_uid']) {
            $message_parser->bbcode_uid = $post_data['bbcode_uid'];
        }
        // HTML, BBCode, Smilies, Images and Flash status
        $bbcode_status = $config['allow_bbcode'] && $auth->acl_get('u_gb_bbcode') ? true : false;
        $smilies_status = $config['allow_smilies'] && $auth->acl_get('u_gb_smilies') ? true : false;
        $img_status = $bbcode_status && $auth->acl_get('u_gb_img') ? true : false;
        $url_status = $config['allow_post_links'] ? true : false;
        $flash_status = $bbcode_status && $auth->acl_get('u_gb_flash') && $config['allow_post_flash'] ? true : false;
        $quote_status = true;
        if ($submit || $preview || $refresh) {
            $post_data['post_subject'] = utf8_normalize_nfc(request_var('subject', '', true));
            $message_parser->message = utf8_normalize_nfc(request_var('message', '', true));
            $post_data['username'] = utf8_normalize_nfc(request_var('username', $post_data['username'], true));
            $post_data['topic_time_limit'] = request_var('topic_time_limit', $mode != 'post' ? (int) $post_data['topic_time_limit'] : 0);
            if ($post_data['enable_icons'] && $auth->acl_get('u_gb_icons')) {
                $post_data['icon_id'] = request_var('icon', (int) $post_data['icon_id']);
            }
            $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('u_gb_sig') ? false : (isset($_POST['attach_sig']) && $user->data['is_registered'] ? true : false);
            if ($config['allow_topic_notify'] && $user->data['is_registered']) {
                $notify = isset($_POST['notify']) ? true : false;
            } else {
                $notify = false;
            }
            if ($submit) {
                $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;
            } else {
                $status_switch = 1;
            }
            // Grab md5 'checksum' of new message
            $message_md5 = md5($message_parser->message);
            // Check checksum ... don't re-parse message if the same
            $update_message = $mode != 'edit' || $message_md5 != $post_data['post_checksum'] || $status_switch || strlen($post_data['bbcode_uid']) < BBCODE_UID_LEN ? true : false;
            // Also check if subject got updated...
            $update_subject = $mode != 'edit' || $post_data['post_subject_md5'] && $post_data['post_subject_md5'] != md5($post_data['post_subject']);
            // Parse message
            if ($update_message) {
                if (sizeof($message_parser->warn_msg)) {
                    $error[] = implode('<br />', $message_parser->warn_msg);
                    $message_parser->warn_msg = array();
                }
                $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']);
                // On a refresh we do not care about message parsing errors
                if (sizeof($message_parser->warn_msg) && $refresh) {
                    $message_parser->warn_msg = array();
                }
            } else {
                $message_parser->bbcode_bitfield = $post_data['bbcode_bitfield'];
            }
            if ($mode != 'edit' && !$preview && !$refresh && $config['flood_interval'] && !$auth->acl_get('u_gb_ignoreflood')) {
                // 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\t\t\t\t\t\tWHERE poster_ip = '" . $user->ip . "'\n\t\t\t\t\t\t\tAND 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'])) {
                    $error[] = $user->lang['FLOOD_ERROR'];
                }
            }
            // Validate username
            if ($post_data['username'] && !$user->data['is_registered'] || $mode == 'edit' && $post_data['poster_id'] == ANONYMOUS && $post_data['username'] && $post_data['post_username'] && $post_data['post_username'] != $post_data['username']) {
                if (!function_exists('validate_user')) {
                    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');
                    $error[] = $user->lang[$result . '_USERNAME'];
                }
            }
            if ($config['enable_post_confirm'] && !$user->data['is_registered'] && in_array($mode, array('quote', 'post', 'reply'))) {
                $captcha_data = array('message' => utf8_normalize_nfc(request_var('message', '', true)), 'subject' => utf8_normalize_nfc(request_var('subject', '', true)), 'username' => utf8_normalize_nfc(request_var('username', '', true)));
                $vc_response = $captcha->validate($captcha_data);
                if ($vc_response) {
                    $error[] = $vc_response;
                }
            }
            // check form
            if (($submit || $preview) && !check_form_key('posting')) {
                $error[] = $user->lang['FORM_INVALID'];
            }
            // Parse subject
            if (sizeof($message_parser->warn_msg)) {
                $error[] = implode('<br />', $message_parser->warn_msg);
            }
            // DNSBL check
            if ($config['check_dnsbl'] && !$refresh) {
                if (($dnsbl = $user->check_dnsbl('post')) !== false) {
                    $error[] = sprintf($user->lang['IP_BLACKLISTED'], $user->ip, $dnsbl[1]);
                }
            }
            // Store message, sync counters
            if (!sizeof($error) && $submit) {
                if ($submit) {
                    $data = array('user_id' => (int) ($mode == 'quote' && isset($post_data['orginal_author']) ? $post_data['orginal_author'] : $this->user_id), 'topic_title' => empty($post_data['topic_title']) ? $post_data['post_subject'] : $post_data['topic_title'], 'post_id' => (int) $post_id, 'icon_id' => (int) $post_data['icon_id'], 'poster_id' => (int) $user->data['user_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'], '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), 'poster_ip' => isset($post_data['poster_ip']) ? $post_data['poster_ip'] : $user->ip, 'bbcode_bitfield' => $message_parser->bbcode_bitfield, 'bbcode_uid' => $message_parser->bbcode_uid, 'message' => $message_parser->message, 'guestbook' => $this);
                    // The last parameter tells submit_post if search indexer has to be run
                    submit_gb_post($mode, $post_data['post_subject'], $post_data['username'], $data, $update_message, $update_message || $update_subject ? true : false);
                    $post_id = $data['post_id'];
                    $uid = $mode == 'quote' && isset($post_data['orginal_author']) ? $post_data['orginal_author'] : $this->user_id;
                    $redirect_url = append_sid("{$phpbb_root_path}memberlist.{$phpEx}", "mode=viewprofile&amp;gbmode=display&amp;u={$uid}&amp;p={$post_id}#p{$post_id}");
                    if ($config['enable_post_confirm'] && !$user->data['is_registered'] && (isset($captcha) && $captcha->is_solved() === true) && ($mode == 'post' || $mode == 'reply' || $mode == 'quote')) {
                        $captcha->reset();
                    }
                    meta_refresh(3, $redirect_url);
                    $message = $mode == 'edit' ? 'POST_EDITED' : 'POST_STORED';
                    $message = $user->lang[$message] . '<br /><br />' . sprintf($user->lang['VIEW_MESSAGE'], '<a href="' . $redirect_url . '">', '</a>');
                    trigger_error($message);
                }
            }
        }
        // Preview
        if (!sizeof($error) && $preview) {
            $post_data['post_time'] = $mode == 'edit' ? $post_data['post_time'] : $current_time;
            $preview_message = $message_parser->format_display($post_data['enable_bbcode'], $post_data['enable_urls'], $post_data['enable_smilies'], false);
            $preview_signature = $mode == 'edit' ? $post_data['user_sig'] : $user->data['user_sig'];
            $preview_signature_uid = $mode == 'edit' ? $post_data['user_sig_bbcode_uid'] : $user->data['user_sig_bbcode_uid'];
            $preview_signature_bitfield = $mode == 'edit' ? $post_data['user_sig_bbcode_bitfield'] : $user->data['user_sig_bbcode_bitfield'];
            // Signature
            if ($post_data['enable_sig'] && $config['allow_sig'] && $preview_signature && $auth->acl_get('u_gb_sig')) {
                $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_sig_bbcode'], true, $config['allow_sig_smilies']);
                $preview_signature = $parse_sig->message;
                unset($parse_sig);
            } else {
                $preview_signature = '';
            }
            $preview_subject = censor_text($post_data['post_subject']);
            if (!sizeof($error)) {
                $template->assign_vars(array('PREVIEW_SUBJECT' => $preview_subject, 'PREVIEW_MESSAGE' => $preview_message, 'PREVIEW_SIGNATURE' => $preview_signature, 'S_DISPLAY_PREVIEW' => true));
            }
        }
        // Decode text for message display
        $post_data['bbcode_uid'] = $mode == 'quote' && !$preview && !$refresh && !sizeof($error) ? $post_data['bbcode_uid'] : $message_parser->bbcode_uid;
        $message_parser->decode_message($post_data['bbcode_uid']);
        if ($mode == 'quote' && !$submit && !$preview && !$refresh) {
            if ($config['allow_bbcode']) {
                $message_parser->message = '[quote=&quot;' . $post_data['quote_username'] . '&quot;]' . censor_text(trim($message_parser->message)) . "[/quote]\n";
            } else {
                $offset = 0;
                $quote_string = "&gt; ";
                $message = censor_text(trim($message_parser->message));
                // see if we are nesting. It's easily tricked but should work for one level of nesting
                if (strpos($message, "&gt;") !== false) {
                    $offset = 10;
                }
                $message = utf8_wordwrap($message, 75 + $offset, "\n");
                $message = $quote_string . $message;
                $message = str_replace("\n", "\n" . $quote_string, $message);
                $message_parser->message = $post_data['quote_username'] . " " . $user->lang['WROTE'] . " :\n" . $message . "\n";
            }
        }
        if (($mode == 'reply' || $mode == 'quote') && !$submit && !$preview && !$refresh) {
            $post_data['post_subject'] = (strpos($post_data['post_subject'], 'Re: ') !== 0 ? 'Re: ' : '') . censor_text($post_data['post_subject']);
        }
        $post_data['post_text'] = $message_parser->message;
        // MAIN POSTING PAGE BEGINS HERE
        // Generate smiley listing
        generate_smilies('inline', 0);
        // Do show topic type selection only in first post.
        $topic_type_toggle = false;
        $s_topic_icons = false;
        if ($post_data['enable_icons'] && $auth->acl_get('u_gb_icons')) {
            $s_topic_icons = posting_gen_topic_icons($mode, $post_data['icon_id']);
        }
        $bbcode_checked = isset($post_data['enable_bbcode']) ? !$post_data['enable_bbcode'] : ($config['allow_bbcode'] ? !$user->optionget('bbcode') : 1);
        $smilies_checked = isset($post_data['enable_smilies']) ? !$post_data['enable_smilies'] : ($config['allow_smilies'] ? !$user->optionget('smilies') : 1);
        $urls_checked = isset($post_data['enable_urls']) ? !$post_data['enable_urls'] : 0;
        $sig_checked = $post_data['enable_sig'];
        // If the user is replying or posting and not already watching this topic but set to always being notified we need to overwrite this setting
        $notify_set = $mode != 'edit' && $config['allow_topic_notify'] && $user->data['is_registered'] && !$post_data['notify_set'] ? $user->data['user_notify'] : $post_data['notify_set'];
        $notify_checked = isset($notify) ? $notify : ($mode == 'post' ? $user->data['user_notify'] : $notify_set);
        // Page title & action URL, include session_id for security purpose
        $s_action = append_sid("{$phpbb_root_path}memberlist.{$phpEx}", "mode=viewprofile&amp;u={$this->user_id}&amp;gbmode={$mode}", true, $user->session_id);
        $s_action .= $post_id ? "&amp;p={$post_id}" : '';
        switch ($mode) {
            case 'post':
                $page_title = $user->lang['POST_GUESTBOOK'];
                break;
            case 'quote':
            case 'reply':
                $page_title = $user->lang['POST_GUESTBOOK'];
                break;
            case 'delete':
            case 'edit':
                $page_title = $user->lang['EDIT_POST'];
                break;
        }
        // Posting uses is_solved for legacy reasons. Plugins have to use is_solved to force themselves to be displayed.
        if ($config['enable_post_confirm'] && !$user->data['is_registered'] && (isset($captcha) && $captcha->is_solved() === false) && ($mode == 'post' || $mode == 'reply' || $mode == 'quote')) {
            $template->assign_vars(array('S_CONFIRM_CODE' => true, 'CAPTCHA_TEMPLATE' => $captcha->get_template()));
        }
        $s_hidden_fields = '<input type="hidden" name="lastclick" value="' . $current_time . '" />';
        if ($mode == 'edit') {
            $s_hidden_fields .= build_hidden_fields(array('edit_post_message_checksum' => $post_data['post_checksum'], 'edit_post_subject_checksum' => $post_data['post_subject_md5']));
        }
        // 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) {
            $s_hidden_fields .= build_hidden_fields($captcha->get_hidden_fields());
        }
        add_form_key('posting');
        // Start assigning vars for main posting page ...
        $template->assign_vars(array('L_POST_A' => $page_title, 'L_ICON' => $user->lang['POST_ICON'], 'L_MESSAGE_BODY_EXPLAIN' => intval($config['max_post_chars']) ? sprintf($user->lang['MESSAGE_BODY_EXPLAIN'], intval($config['max_post_chars'])) : '', 'TOPIC_TITLE' => censor_text($post_data['topic_title']), 'USERNAME' => !$preview && $mode != 'quote' || $preview ? $post_data['username'] : '', 'SUBJECT' => $post_data['post_subject'], 'MESSAGE' => $post_data['post_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' => $bbcode_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['POST']), 'POST_DATE' => $post_data['post_time'] ? $user->format_date($post_data['post_time']) : '', 'ERROR' => sizeof($error) ? implode('<br />', $error) : '', 'TOPIC_TIME_LIMIT' => (int) $post_data['topic_time_limit'], 'EDIT_REASON' => $post_data['post_edit_reason'], 'S_PRIVMSGS' => false, 'S_CLOSE_PROGRESS_WINDOW' => isset($_POST['add_file']) ? true : false, 'S_EDIT_POST' => $mode == 'edit' ? true : false, 'S_EDIT_REASON' => false, 'S_DISPLAY_USERNAME' => !$user->data['is_registered'] || $mode == 'edit' && $post_data['poster_id'] == ANONYMOUS ? true : false, 'S_SHOW_TOPIC_ICONS' => $s_topic_icons, 'S_BBCODE_ALLOWED' => $bbcode_status, 'S_BBCODE_CHECKED' => $bbcode_checked ? ' checked="checked"' : '', 'S_SMILIES_ALLOWED' => $smilies_status, 'S_SMILIES_CHECKED' => $smilies_checked ? ' checked="checked"' : '', 'S_SIG_ALLOWED' => $auth->acl_get('u_gb_sig') && $config['allow_sig'] && $user->data['is_registered'] ? true : false, 'S_SIGNATURE_CHECKED' => $sig_checked ? ' checked="checked"' : '', 'S_NOTIFY_ALLOWED' => !$user->data['is_registered'] || $mode == 'edit' && $user->data['user_id'] != $post_data['poster_id'] || !$config['allow_topic_notify'] || !$config['email_enable'] ? false : true, 'S_NOTIFY_CHECKED' => $notify_checked ? ' checked="checked"' : '', 'S_LINKS_ALLOWED' => $url_status, 'S_MAGIC_URL_CHECKED' => $urls_checked ? ' checked="checked"' : '', 'S_TYPE_TOGGLE' => '', 'S_SAVE_ALLOWED' => false, 'S_HAS_DRAFTS' => false, 'S_BBCODE_IMG' => $img_status, 'S_BBCODE_URL' => $url_status, 'S_BBCODE_FLASH' => $flash_status, 'S_BBCODE_QUOTE' => $quote_status, 'SIGNATURE' => '', 'S_POST_ACTION' => $s_action, 'S_HIDDEN_FIELDS' => $s_hidden_fields));
        // Build custom bbcodes array
        display_custom_bbcodes();
        $template->set_filenames(array('body' => 'posting_body.html'));
        make_jumpbox(append_sid("{$phpbb_root_path}viewforum.{$phpEx}"));
    }