Fix up display of sigs and bbcode for preview

git-svn-id: file:///svn/phpbb/trunk@4170 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
Paul S. Owen 2003-06-24 16:46:30 +00:00
parent 97680b4f54
commit b44bc16bd0
6 changed files with 68 additions and 66 deletions

View file

@ -24,7 +24,7 @@ class bbcode
var $bbcode_uid = '';
var $bbcode_bitfield = 0;
var $bbcode_cache = array();
var $bbcode_tpl = array();
var $bbcode_template = array();
function bbcode($bitfield = 0)
{
@ -257,27 +257,31 @@ class bbcode
function bbcode_tpl($tpl_name, $bbcode_id = -1)
{
static $bbcode_hardtpl = array(
'b_open' => '<span style="font-weight: bold">',
'b_close' => '</span>',
'i_open' => '<span style="font-style: italic">',
'i_close' => '</span>',
'u_open' => '<span style="text-decoration: underline">',
'u_close' => '</span>',
'url' => '<a href="\1" target="_blank">\2</a>',
'img' => '<img src="\1" border="0" />',
'size' => '<span style="font-size: \1px; line-height: normal">\2</span>',
'color' => '<span style="color: \1">\2</span>',
'email' => '<a href="mailto:\1">\2</a>'
);
global $template, $user;
if (empty($bbcode_hardtpl))
{
static $bbcode_hardtpl = array(
'b_open' => '<span style="font-weight: bold">',
'b_close' => '</span>',
'i_open' => '<span style="font-style: italic">',
'i_close' => '</span>',
'u_open' => '<span style="text-decoration: underline">',
'u_close' => '</span>',
'url' => '<a href="\1" target="_blank">\2</a>',
'img' => '<img src="\1" border="0" />',
'size' => '<span style="font-size: \1px; line-height: normal">\2</span>',
'color' => '<span style="color: \1">\2</span>',
'email' => '<a href="mailto:\1">\2</a>'
);
}
if ($bbcode_id != -1 && !($user->theme['bbcode_bitfield'] & pow(2, $bbcode_id)))
{
return $bbcode_hardtpl[$tpl_name];
}
if (empty($this->bbcode_tpl))
if (empty($this->bbcode_template))
{
$tpl_filename = $template->make_filename('bbcode.html');
@ -296,13 +300,13 @@ class bbcode
$tpl = preg_replace("/\n[\n\r\s\t]*/", '', $tpl);
// Turn template blocks into PHP assignment statements for the values of $bbcode_tpl..
$tpl = preg_replace('#<!-- BEGIN (.*?) -->(.*?)<!-- END (.*?) -->#', "\n" . "\$this->bbcode_tpl['\\1'] = \$this->bbcode_tpl_replace('\\1','\\2');", $tpl);
$tpl = preg_replace('#<!-- BEGIN (.*?) -->(.*?)<!-- END (.*?) -->#', "\n" . "\$this->bbcode_template['\\1'] = \$this->bbcode_tpl_replace('\\1','\\2');", $tpl);
$this->bbcode_tpl = array();
$this->bbcode_template = array();
eval($tpl);
}
return $this->bbcode_tpl[$tpl_name];
return $this->bbcode_template[$tpl_name];
}
function bbcode_tpl_replace($tpl_name, $tpl)

View file

@ -84,16 +84,10 @@ function generate_smilies($mode)
}
// Format text to be displayed - from viewtopic.php - centralizing this would be nice ;)
function format_display($message, $html, $bbcode, $uid, $url, $smilies, $sig)
function format_display(&$message, &$signature, $uid, $siguid, $html, $bbcode, $url, $smilies, $sig)
{
global $auth, $forum_id, $config, $censors, $user, $bbcode, $phpbb_root_path;
// If the board has HTML off but the post has HTML on then we process it, else leave it alone
/* if ($html && $auth->acl_get('f_bbcode', $forum_id))
{
$message = preg_replace('#(<)([\/]?.*?)(>)#is', "&lt;\\2&gt;", $message);
}
*/
// Second parse bbcode here
$message = $bbcode->bbcode_second_pass($message, $uid);
@ -110,33 +104,27 @@ function format_display($message, $html, $bbcode, $uid, $url, $smilies, $sig)
$message = str_replace("\n", '<br />', $message);
// Signature
$user_sig = ($sig && $config['allow_sig']) ? trim($user->data['user_sig']) : '';
if ($user_sig != '' && $auth->acl_get('f_sigs', $forum_id))
if ($sig && $config['allow_sig'] && $signature && $auth->acl_get('f_sigs', $forum_id))
{
/* if (!$auth->acl_get('f_html', $forum_id) && $user->data['user_allowhtml'])
{
$user_sig = preg_replace('#(<)([\/]?.*?)(>)#is', "&lt;\\2&gt;", $user_sig);
}
*/
$user_sig = (empty($user->data['user_allowsmile']) || !$config['enable_smilies']) ? preg_replace('#<!\-\- s(.*?) \-\-><img src="\{SMILE_PATH\}\/.*? \/><!\-\- s\1 \-\->#', '\1', $user_sig) : str_replace('<img src="{SMILE_PATH}', '<img src="' . $phpbb_root_path . $config['smilies_path'], $user_sig);
$signature = trim($signature);
$signature = $bbcode->bbcode_second_pass($signature, $siguid);
$signature = (!$config['enable_smilies']) ? preg_replace('#<!\-\- s(.*?) \-\-><img src="\{SMILE_PATH\}\/.*? \/><!\-\- s\1 \-\->#', '\1', $signature) : str_replace('<img src="{SMILE_PATH}', '<img src="' . $phpbb_root_path . $config['smilies_path'], $signature);
if (sizeof($censors))
{
$user_sig = str_replace('\"', '"', substr(preg_replace('#(\>(((?>([^><]+|(?R)))*)\<))#se', "preg_replace(\$censors['match'], \$censors['replace'], '\\0')", '>' . $user_sig . '<'), 1, -1));
$signature = str_replace('\"', '"', substr(preg_replace('#(\>(((?>([^><]+|(?R)))*)\<))#se', "preg_replace(\$censors['match'], \$censors['replace'], '\\0')", '>' . $signature . '<'), 1, -1));
}
$user_sig = str_replace("\n", '<br />', $user_sig);
$signature = str_replace("\n", '<br />', $signature);
}
else
{
$user_sig = '';
$signature = '';
}
// Inappropriate
$message .= $user_sig;
return $message;
return;
}
// Update Last Post Informations

View file

@ -454,7 +454,7 @@ class user extends session
// Set up style
$style = ($style) ? $style : ((!$config['override_user_style'] && $this->data['user_id'] != ANONYMOUS) ? $this->data['user_style'] : $config['default_style']);
$sql = "SELECT DISTINCT t.template_path, t.poll_length, t.pm_box_length, c.css_data, c.css_external, i.*
$sql = "SELECT DISTINCT t.*, c.*, i.*
FROM " . STYLES_TABLE . " s, " . STYLES_TPL_TABLE . " t, " . STYLES_CSS_TABLE . " c, " . STYLES_IMAGE_TABLE . " i
WHERE s.style_id IN ($style, " . $config['default_style'] . ")
AND t.template_id = s.template_id

View file

@ -54,6 +54,9 @@ if ($delete && !$preview && !$refresh && $submit)
$mode = 'delete';
}
$error = array();
// Was cancel pressed? If so then redirect to the appropriate page
if ($cancel || time() - $lastclick < 2)
{
@ -74,11 +77,10 @@ $parameters = array(
'topic_status' => 'i', 'topic_first_post_id' => 'i', 'topic_last_post_id' => 'i', 'topic_type' => 'i', 'topic_title' => 's', 'poll_last_vote' => 'i', 'poll_start' => 'i', 'poll_title' => 's', 'poll_max_options' => 'i', 'poll_length' => 'i'
),
'posts' => array(
'post_time' => 'i', 'poster_id' => 'i', 'post_username' => 's', 'post_text' => 's', 'post_subject' => 's', 'post_checksum' => 's', 'post_attachment' => 'i', 'bbcode_uid' => 's', 'enable_magic_url' => 'i', 'enable_sig' => 'i', 'enable_smilies' => 'i', 'enable_bbcode' => 'i', 'post_edit_locked' => 'i'
'post_time' => 'i', 'poster_id' => 'i', 'post_username' => 's', 'post_text' => 's', 'post_subject' => 's', 'post_checksum' => 's', 'post_attachment' => 'i', 'bbcode_uid' => 's', 'enable_magic_url' => 'i', 'enable_sig' => 'i', 'enable_smilies' => 'i', 'enable_bbcode' => 'i', 'post_edit_locked' => 'i', 'username' => 's', 'user_sig' => 's', 'user_sig_bbcode_uid' => 's', 'user_sig_bbcode_bitfield' => 'i'
)
);
$sql = '';
switch ($mode)
{
case 'post':
@ -116,7 +118,7 @@ switch ($mode)
trigger_error($user->lang['NO_POST']);
}
$sql = 'SELECT p.*, t.*, f.*, u.username
$sql = 'SELECT p.*, t.*, f.*, u.username, u.user_sig, u.user_sig_bbcode_uid, u.user_sig_bbcode_bitfield
FROM ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . ' t, ' . FORUMS_TABLE . ' f, ' . USERS_TABLE . " u
WHERE p.post_id = $post_id
AND t.topic_id = p.topic_id
@ -140,6 +142,7 @@ switch ($mode)
break;
default:
$sql = '';
trigger_error($user->lang['NO_MODE']);
}
@ -478,6 +481,7 @@ $smilies_status = ($config['allow_smilies'] && $auth->acl_get('f_smilies', $foru
$img_status = ($config['allow_img'] && $auth->acl_get('f_img', $forum_id)) ? true : false;
$flash_status = ($config['allow_flash'] && $auth->acl_get('f_flash', $forum_id)) ? true : false;
if ($submit || $preview || $refresh)
{
$topic_cur_post_id = (isset($_POST['topic_cur_post_id'])) ? intval($_POST['topic_cur_post_id']) : false;
@ -490,7 +494,7 @@ if ($submit || $preview || $refresh)
$message_parser->message = (!empty($_POST['message'])) ? trim(stripslashes($_POST['message'])) : '';
$username = (!empty($_POST['username'])) ? trim($_POST['username']) : '';
$username = (!empty($_POST['username'])) ? trim($_POST['username']) : ((!empty($username)) ? $username : '');
$topic_type = (!empty($_POST['topic_type'])) ? (int) $_POST['topic_type'] : (($mode != 'post') ? $topic_type : POST_NORMAL);
$icon_id = (!empty($_POST['icon'])) ? intval($_POST['icon']) : 0;
@ -546,9 +550,10 @@ if ($submit || $preview || $refresh)
$poll_max_options = (!empty($_POST['poll_max_options'])) ? intval($_POST['poll_max_options']) : 1;
}
$error = array();
$current_time = time();
// If replying/quoting and last post id has changed
// give user option to continue submit or return to post
// notify and show user the post made between his request and the final submit
@ -617,6 +622,7 @@ if ($submit || $preview || $refresh)
$refresh = TRUE;
}
// Grab md5 'checksum' of new message
$message_md5 = md5($message_parser->message);
@ -795,22 +801,25 @@ if (!sizeof($error) && $preview)
obtain_word_list($censors);
}
$post_time = $current_time;
$post_time = ($mode == 'edit') ? $post_time : $current_time;
include($phpbb_root_path . 'includes/bbcode.' . $phpEx);
$bbcode = new bbcode($message_parser->bbcode_bitfield);
$preview_message = format_display($message_parser->message, $enable_html, $enable_bbcode, $message_parser->bbcode_uid, $enable_urls, $enable_smilies, $enable_sig);
$preview_subject = (sizeof($censors)) ? preg_replace($censors['match'], $censors['replace'], $subject) : $subject;
$preview_signature = ($mode == 'edit') ? $user_sig : $user->data['user_sig'];
$preview_signature_uid = ($mode == 'edit') ? $user_sig_bbcode_uid : $user->data['user_sig_bbcode_uid'];
$preview_signature_bitfield = ($mode == 'edit') ? $user_sig_bbcode_bitfield : $user->data['user_sig_bbcode_bitfield'];
include($phpbb_root_path . 'includes/bbcode.' . $phpEx);
$bbcode = new bbcode($message_parser->bbcode_bitfield | $preview_signature_bitfield);
$preview_message = $message_parser->message;
format_display($preview_message, $preview_signature, $message_parser->bbcode_uid, $preview_signature_uid, $enable_html, $enable_bbcode, $enable_urls, $enable_smilies, $enable_sig);
// Poll Preview
if (($mode == 'post' || ($mode == 'edit' && $post_id == $topic_first_post_id && empty($poll_last_vote))) && ($auth->acl_get('f_poll', $forum_id) || $auth->acl_get('m_edit', $forum_id)))
{
decode_text($poll_title, $message_parser->bbcode_uid);
$preview_poll_title = format_display(stripslashes($poll_title), $enable_html, $enable_bbcode, $message_parser->bbcode_uid, $enable_urls, $enable_smilies, false, false);
$preview_poll_title = format_display(stripslashes($poll_title), $null, $message_parser->bbcode_uid, false, $enable_html, $enable_bbcode, $enable_urls, $enable_smilies, false, false);
$template->assign_vars(array(
'S_HAS_POLL_OPTIONS' => (sizeof($poll_options)) ? true : false,
@ -825,7 +834,6 @@ if (!sizeof($error) && $preview)
}
}
// Attachment Preview
if (sizeof($message_parser->attachment_data))
{
@ -922,6 +930,7 @@ if ($mode == 'post' || ($mode == 'edit' && $post_id == $topic_first_post_id))
'global' => array('const' => POST_GLOBAL, 'lang' => 'POST_GLOBAL')
);
foreach ($topic_types as $auth_key => $topic_value)
{
if ($auth->acl_get('f_' . $auth_key, $forum_id))
@ -999,9 +1008,10 @@ $template->assign_vars(array(
'MODERATORS' => (sizeof($moderators)) ? implode(', ', $moderators[$forum_id]) : '',
'USERNAME' => (((!$preview) && ($mode != 'quote')) || ($preview)) ? stripslashes($username) : '',
'SUBJECT' => $post_subject,
'PREVIEW_SUBJECT' => ($preview && !sizeof($error)) ? $preview_subject : '',
'MESSAGE' => trim($post_text),
'PREVIEW_MESSAGE' => ($preview && !sizeof($error)) ? $preview_message : '',
'PREVIEW_SUBJECT' => ($preview && !sizeof($error)) ? $preview_subject : '',
'PREVIEW_MESSAGE' => ($preview && !sizeof($error)) ? $preview_message : '',
'PREVIEW_SIGNATURE' => ($preview && !sizeof($error)) ? $preview_signature : '',
'HTML_STATUS' => ($html_status) ? $user->lang['HTML_IS_ON'] : $user->lang['HTML_IS_OFF'],
'BBCODE_STATUS' => ($bbcode_status) ? sprintf($user->lang['BBCODE_IS_ON'], '<a href="' . "faq.$phpEx$SID&amp;mode=bbcode" . '" target="_phpbbcode">', '</a>') : sprintf($user->lang['BBCODE_IS_OFF'], '<a href="' . "faq.$phpEx$SID&amp;mode=bbcode" . '" target="_phpbbcode">', '</a>'),
'IMG_STATUS' => ($img_status) ? $user->lang['IMAGES_ARE_ON'] : $user->lang['IMAGES_ARE_OFF'],
@ -1009,7 +1019,7 @@ $template->assign_vars(array(
'SMILIES_STATUS' => ($smilies_status) ? $user->lang['SMILIES_ARE_ON'] : $user->lang['SMILIES_ARE_OFF'],
'MINI_POST_IMG' => $user->img('icon_post', $user->lang['POST']),
'POST_DATE' => ($post_time) ? $user->format_date($post_time) : '',
'ERROR_MESSAGE' => (sizeof($error)) ? implode('<br />', $error) : '',
'ERROR' => (sizeof($error)) ? implode('<br />', $error) : '',
'U_VIEW_FORUM' => "viewforum.$phpEx$SID&amp;f=" . $forum_id,
'U_VIEWTOPIC' => ($mode != 'post') ? "viewtopic.$phpEx$SID&amp;$forum_id&amp;t=$topic_id" : '',

View file

@ -114,11 +114,13 @@ function checkForm()
<tr>
<th colspan="2" height="25"><b>{L_POST_A}</b></th>
</tr>
<!-- IF ERROR_MESSAGE neq '' -->
<!-- IF ERROR -->
<tr>
<td class="row2" colspan="2" align="center"><span class="genmed" style="color:red;font-weight:bold">{ERROR_MESSAGE}</span></td>
<td class="row2" colspan="2" align="center"><span class="genmed" style="color:red">{ERROR}</span></td>
</tr>
<!-- ENDIF -->
<!-- IF S_DELETE_ALLOWED -->
<tr>
<td class="row1"><b class="genmed">{L_DELETE_POST}</b></td>

View file

@ -30,12 +30,10 @@
<tr>
<td class="row1"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
<span class="postbody">{PREVIEW_MESSAGE}</span>
<td><span class="postbody">{PREVIEW_MESSAGE}</span>
<!-- BEGIN postrow -->
<!-- IF postrow.S_HAS_ATTACHMENTS --><!-- INCLUDE viewtopic_attach_body.html --><!-- ENDIF -->
<!-- END postrow -->
</td>
<!-- IF postrow.S_HAS_ATTACHMENTS --><!-- INCLUDE viewtopic_attach_body.html --><!-- ENDIF -->
<!-- END postrow --><!-- IF PREVIEW_SIGNATURE --><span class="postbody"><br />_________________<br />{PREVIEW_SIGNATURE}</span><!-- ENDIF --></td>
</tr>
</table></td>
</tr>