From 17a2e2b64d58d73e622e2d6273deee2089ff3c74 Mon Sep 17 00:00:00 2001 From: Jamie Furness Date: Fri, 22 Apr 2011 19:53:37 +0100 Subject: [PATCH] Adding topic/post/forum/user bbcode. #401 --- help.php | 8 ++++++++ include/functions.php | 2 +- include/parser.php | 36 ++++++++++++++++++++++++++++-------- lang/English/help.php | 5 +++++ 4 files changed, 42 insertions(+), 9 deletions(-) diff --git a/help.php b/help.php index 4c2e36a14..85cceb5e4 100644 --- a/help.php +++ b/help.php @@ -58,6 +58,14 @@

[url=/help.php][/url]

[email]myname@mydomain.com[/email] myname@mydomain.com

[email=myname@mydomain.com][/email]

+

[topic=1][/topic]

+

[topic]1[/topic]

+

[post=1][/post]

+

[post]1[/post]

+

[forum=1][/forum]

+

[forum]1[/forum]

+

[user=2][/user]

+

[user]2[/user]

diff --git a/include/functions.php b/include/functions.php index 8ba8ca543..295de667f 100644 --- a/include/functions.php +++ b/include/functions.php @@ -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 diff --git a/include/parser.php b/include/parser.php index 88c51cf83..1d205055a 100644 --- a/include/parser.php +++ b/include/parser.php @@ -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; @@ -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) @@ -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 = ''; @@ -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[] = '$1'; $replace[] = '$2'; + $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); diff --git a/lang/English/help.php b/lang/English/help.php index 6821653ec..7b4e533a6 100644 --- a/lang/English/help.php +++ b/lang/English/help.php @@ -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.',