Skip to content

Commit

Permalink
Adding topic/post/forum/user bbcode. #401
Browse files Browse the repository at this point in the history
  • Loading branch information
reines committed Apr 22, 2011
1 parent 10c42c8 commit 17a2e2b
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 9 deletions.
8 changes: 8 additions & 0 deletions help.php
Expand Up @@ -58,6 +58,14 @@
<p><code>[url=/help.php]<?php echo $lang_help['This help page'] ?>[/url]</code> <?php echo $lang_help['produces'] ?> <samp><a href="<?php echo get_base_url(true).'/help.php' ?>"><?php echo $lang_help['This help page'] ?></a></samp></p>
<p><code>[email]myname@mydomain.com[/email]</code> <?php echo $lang_help['produces'] ?> <samp><a href="mailto:myname@mydomain.com">myname@mydomain.com</a></samp></p>
<p><code>[email=myname@mydomain.com]<?php echo $lang_help['My email address'] ?>[/email]</code> <?php echo $lang_help['produces'] ?> <samp><a href="mailto:myname@mydomain.com"><?php echo $lang_help['My email address'] ?></a></samp></p>
<p><code>[topic=1]<?php echo $lang_help['Test topic'] ?>[/topic]</code> <?php echo $lang_help['produces'] ?> <samp><a href="<?php echo pun_htmlspecialchars(get_base_url(true).'/viewtopic.php?id=1') ?>"><?php echo $lang_help['Test topic'] ?></a></samp></p>
<p><code>[topic]1[/topic]</code> <?php echo $lang_help['produces'] ?> <samp><a href="<?php echo pun_htmlspecialchars(get_base_url(true).'/viewtopic.php?id=1') ?>"><?php echo pun_htmlspecialchars(get_base_url(true).'/viewtopic.php?id=1') ?></a></samp></p>
<p><code>[post=1]<?php echo $lang_help['Test post'] ?>[/post]</code> <?php echo $lang_help['produces'] ?> <samp><a href="<?php echo pun_htmlspecialchars(get_base_url(true).'/viewtopic.php?pid=1#p1') ?>"><?php echo $lang_help['Test post'] ?></a></samp></p>
<p><code>[post]1[/post]</code> <?php echo $lang_help['produces'] ?> <samp><a href="<?php echo pun_htmlspecialchars(get_base_url(true).'/viewtopic.php?pid=1#p1') ?>"><?php echo pun_htmlspecialchars(get_base_url(true).'/viewtopic.php?pid=1#p1') ?></a></samp></p>
<p><code>[forum=1]<?php echo $lang_help['Test forum'] ?>[/forum]</code> <?php echo $lang_help['produces'] ?> <samp><a href="<?php echo pun_htmlspecialchars(get_base_url(true).'/viewforum.php?id=1') ?>"><?php echo $lang_help['Test forum'] ?></a></samp></p>
<p><code>[forum]1[/forum]</code> <?php echo $lang_help['produces'] ?> <samp><a href="<?php echo pun_htmlspecialchars(get_base_url(true).'/viewforum.php?id=1') ?>"><?php echo pun_htmlspecialchars(get_base_url(true).'/viewforum.php?id=1') ?></a></samp></p>
<p><code>[user=2]<?php echo $lang_help['Test user'] ?>[/user]</code> <?php echo $lang_help['produces'] ?> <samp><a href="<?php echo pun_htmlspecialchars(get_base_url(true).'/profile.php?id=2') ?>"><?php echo $lang_help['Test user'] ?></a></samp></p>
<p><code>[user]2[/user]</code> <?php echo $lang_help['produces'] ?> <samp><a href="<?php echo pun_htmlspecialchars(get_base_url(true).'/profile.php?id=2') ?>"><?php echo pun_htmlspecialchars(get_base_url(true).'/profile.php?id=2') ?></a></samp></p>
</div>
<div class="inbox">
<p><a name="img"></a><?php echo $lang_help['Images info'] ?></p>
Expand Down
2 changes: 1 addition & 1 deletion include/functions.php
Expand Up @@ -441,7 +441,7 @@ function check_username($username, $exclude_id = null)
$errors[] = $lang_prof_reg['Username IP'];
else if ((strpos($username, '[') !== false || strpos($username, ']') !== false) && strpos($username, '\'') !== false && strpos($username, '"') !== false)
$errors[] = $lang_prof_reg['Username reserved chars'];
else if (preg_match('/(?:\[\/?(?:b|u|s|ins|del|em|i|h|colou?r|quote|code|img|url|email|list|\*)\]|\[(?:img|url|quote|list)=)/i', $username))
else if (preg_match('/(?:\[\/?(?:b|u|s|ins|del|em|i|h|colou?r|quote|code|img|url|email|list|\*|topic|post|forum|user)\]|\[(?:img|url|quote|list)=)/i', $username))
$errors[] = $lang_prof_reg['Username BBCode'];

// Check username for any censored words
Expand Down
36 changes: 28 additions & 8 deletions include/parser.php
Expand Up @@ -150,7 +150,7 @@ function strip_empty_bbcode($text, &$errors)
}

// Remove empty tags
while (($new_text = preg_replace('/\[(b|u|s|ins|del|em|i|h|colou?r|quote|img|url|email|list)(?:\=[^\]]*)?\]\s*\[\/\1\]/', '', $text)) !== NULL)
while (($new_text = preg_replace('/\[(b|u|s|ins|del|em|i|h|colou?r|quote|img|url|email|list|topic|post|forum|user)(?:\=[^\]]*)?\]\s*\[\/\1\]/', '', $text)) !== NULL)
{
if ($new_text != $text)
$text = $new_text;
Expand Down Expand Up @@ -196,7 +196,7 @@ function preparse_tags($text, &$errors, $is_signature = false)
// Start off by making some arrays of bbcode tags and what we need to do with each one

// List of all the tags
$tags = array('quote', 'code', 'b', 'i', 'u', 's', 'ins', 'del', 'em', 'color', 'colour', 'url', 'email', 'img', 'list', '*', 'h');
$tags = array('quote', 'code', 'b', 'i', 'u', 's', 'ins', 'del', 'em', 'color', 'colour', 'url', 'email', 'img', 'list', '*', 'h', 'topic', 'post', 'forum', 'user');
// List of tags that we need to check are open (You could not put b,i,u in here then illegal nesting like [b][i][/b][/i] would be allowed)
$tags_opened = $tags;
// and tags we need to check are closed (the same as above, added it just in case)
Expand All @@ -208,26 +208,30 @@ function preparse_tags($text, &$errors, $is_signature = false)
// Block tags, block tags can only go within another block tag, they cannot be in a normal tag
$tags_block = array('quote', 'code', 'list', 'h', '*');
// Inline tags, we do not allow new lines in these
$tags_inline = array('b', 'i', 'u', 's', 'ins', 'del', 'em', 'color', 'colour', 'h');
$tags_inline = array('b', 'i', 'u', 's', 'ins', 'del', 'em', 'color', 'colour', 'h', 'topic', 'post', 'forum', 'user');
// Tags we trim interior space
$tags_trim = array('img');
// Tags we remove quotes from the argument
$tags_quotes = array('url', 'email', 'img');
$tags_quotes = array('url', 'email', 'img', 'topic', 'post', 'forum', 'user');
// Tags we limit bbcode in
$tags_limit_bbcode = array(
'*' => array('b', 'i', 'u', 's', 'ins', 'del', 'em', 'color', 'colour', 'url', 'email', 'list', 'img', 'code'),
'*' => array('b', 'i', 'u', 's', 'ins', 'del', 'em', 'color', 'colour', 'url', 'email', 'list', 'img', 'code', 'topic', 'post', 'forum', 'user'),
'list' => array('*'),
'url' => array('b', 'i', 'u', 's', 'ins', 'del', 'em', 'color', 'colour', 'img'),
'email' => array('b', 'i', 'u', 's', 'ins', 'del', 'em', 'color', 'colour', 'img'),
'topic' => array('b', 'i', 'u', 's', 'ins', 'del', 'em', 'color', 'colour', 'img'),
'post' => array('b', 'i', 'u', 's', 'ins', 'del', 'em', 'color', 'colour', 'img'),
'forum' => array('b', 'i', 'u', 's', 'ins', 'del', 'em', 'color', 'colour', 'img'),
'user' => array('b', 'i', 'u', 's', 'ins', 'del', 'em', 'color', 'colour', 'img'),
'img' => array(),
'h' => array('b', 'i', 'u', 's', 'ins', 'del', 'em', 'color', 'colour', 'url', 'email'),
'h' => array('b', 'i', 'u', 's', 'ins', 'del', 'em', 'color', 'colour', 'url', 'email', 'topic', 'post', 'forum', 'user'),
);
// Tags we can automatically fix bad nesting
$tags_fix = array('quote', 'b', 'i', 'u', 's', 'ins', 'del', 'em', 'color', 'colour', 'url', 'email', 'h');
$tags_fix = array('quote', 'b', 'i', 'u', 's', 'ins', 'del', 'em', 'color', 'colour', 'url', 'email', 'h', 'topic', 'post', 'forum', 'user');

$split_text = preg_split("/(\[[\*a-zA-Z0-9-\/]*?(?:=.*?)?\])/", $text, -1, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY);

$open_tags = array('post');
$open_tags = array('fluxbb-bbcode');
$open_args = array('');
$opened_tag = 0;
$new_text = '';
Expand Down Expand Up @@ -766,11 +770,27 @@ function do_bbcode($text, $is_signature = false)
$pattern[] = '#\[url=([^\[]+?)\](.*?)\[/url\]#e';
$pattern[] = '#\[email\]([^\[]*?)\[/email\]#';
$pattern[] = '#\[email=([^\[]+?)\](.*?)\[/email\]#';
$pattern[] = '#\[topic\]([^\[]*?)\[/topic\]#e';
$pattern[] = '#\[topic=([^\[]+?)\](.*?)\[/topic\]#e';
$pattern[] = '#\[post\]([^\[]*?)\[/post\]#e';
$pattern[] = '#\[post=([^\[]+?)\](.*?)\[/post\]#e';
$pattern[] = '#\[forum\]([^\[]*?)\[/forum\]#e';
$pattern[] = '#\[forum=([^\[]+?)\](.*?)\[/forum\]#e';
$pattern[] = '#\[user\]([^\[]*?)\[/user\]#e';
$pattern[] = '#\[user=([^\[]+?)\](.*?)\[/user\]#e';

$replace[] = 'handle_url_tag(\'$1\')';
$replace[] = 'handle_url_tag(\'$1\', \'$2\')';
$replace[] = '<a href="mailto:$1">$1</a>';
$replace[] = '<a href="mailto:$1">$2</a>';
$replace[] = 'handle_url_tag(\''.get_base_url(true).'/viewtopic.php?id=$1\')';
$replace[] = 'handle_url_tag(\''.get_base_url(true).'/viewtopic.php?id=$1\', \'$2\')';
$replace[] = 'handle_url_tag(\''.get_base_url(true).'/viewtopic.php?pid=$1#p$1\')';
$replace[] = 'handle_url_tag(\''.get_base_url(true).'/viewtopic.php?pid=$1#p$1\', \'$2\')';
$replace[] = 'handle_url_tag(\''.get_base_url(true).'/viewforum.php?id=$1\')';
$replace[] = 'handle_url_tag(\''.get_base_url(true).'/viewforum.php?id=$1\', \'$2\')';
$replace[] = 'handle_url_tag(\''.get_base_url(true).'/profile.php?id=$1\')';
$replace[] = 'handle_url_tag(\''.get_base_url(true).'/profile.php?id=$1\', \'$2\')';

// This thing takes a while! :)
$text = preg_replace($pattern, $replace, $text);
Expand Down
5 changes: 5 additions & 0 deletions lang/English/help.php
Expand Up @@ -30,6 +30,11 @@
'Images info' => 'If you want to display an image you can use the img tag. The text appearing after the "=" sign in the opening tag is used for the alt attribute and should be included whenever possible.',
'FluxBB bbcode test' => 'FluxBB bbcode test',

'Test topic' => 'Test topic',
'Test post' => 'Test post',
'Test forum' => 'Test forum',
'Test user' => 'Test user',

'Quotes' => 'Quotes',
'Quotes info' => 'If you want to quote someone, you should use the quote tag.',
'Quotes info 2' => 'If you don\'t want to quote anyone in particular, you can use the quote tag without specifying a name.',
Expand Down

0 comments on commit 17a2e2b

Please sign in to comment.