Skip to content

Commit

Permalink
#646: Implement disallowing links (if that feature is enabled) in pos…
Browse files Browse the repository at this point in the history
…t.php.
  • Loading branch information
franzliedke committed Mar 30, 2012
1 parent 3856d0a commit ccf00d1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
15 changes: 14 additions & 1 deletion include/parser.php
Expand Up @@ -183,7 +183,7 @@ function strip_empty_bbcode($text)
//
function preparse_tags($text, &$errors, $is_signature = false)
{
global $lang_common, $pun_config;
global $lang_common, $pun_config, $pun_user;

// Start off by making some arrays of bbcode tags and what we need to do with each one

Expand All @@ -197,6 +197,8 @@ function preparse_tags($text, &$errors, $is_signature = false)
$tags_nested = array('quote' => $pun_config['o_quote_depth'], 'list' => 5, '*' => 5);
// Tags to ignore the contents of completely (just code)
$tags_ignore = array('code');
// Tags not allowed
$tags_forbidden = array();
// 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
Expand All @@ -221,6 +223,10 @@ function preparse_tags($text, &$errors, $is_signature = false)
// Tags we can automatically fix bad nesting
$tags_fix = array('quote', 'b', 'i', 'u', 's', 'ins', 'del', 'em', 'color', 'colour', 'url', 'email', 'h', 'topic', 'post', 'forum', 'user');

// Disallow URL tags
if ($pun_user['g_post_links'] != '1')
$tags_forbidden[] = 'url';

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

$open_tags = array('fluxbb-bbcode');
Expand Down Expand Up @@ -378,6 +384,13 @@ function preparse_tags($text, &$errors, $is_signature = false)
continue;
}

// Is the tag forbidden?
if (in_array($current_tag, $tags_forbidden))
{
$errors[] = sprintf($lang_common['BBCode error tag not allowed'], $current_tag);
return false;
}

if ($current_nest)
{
// We are currently too deeply nested so lets see if we are closing the tag or not
Expand Down
1 change: 1 addition & 0 deletions lang/English/common.php
Expand Up @@ -86,6 +86,7 @@
'BBCode error invalid self-nesting' => '[%s] was opened within itself, this is not allowed',
'BBCode error no closing tag' => '[%1$s] was found without a matching [/%1$s]',
'BBCode error empty attribute' => '[%s] tag had an empty attribute section',
'BBCode error tag not allowed' => 'You are not allowed to use [%s] tags',
'BBCode code problem' => 'There is a problem with your [code] tags',
'BBCode list size error' => 'Your list was too long to parse, please make it smaller!',

Expand Down

0 comments on commit ccf00d1

Please sign in to comment.