BBCode::DoTag( $action,  $tag_name,  $default_value,  $params,  $contents )

Description

Source

File: bp-forums/admin/parser.php

function DoTag($action, $tag_name, $default_value, $params, $contents) {
$tag_rule = @$this->tag_rules[$tag_name];
switch ($action) {
case BBCODE_CHECK:
if (isset($tag_rule['allow'])) {
foreach ($tag_rule['allow'] as $param => $pattern) {
if ($param == '_content') $value = $contents;
else if ($param == '_defaultcontent') {
if (strlen($default_value))
$value = $default_value;
else $value = $contents;
}
else {
if (isset($params[$param]))
$value = $params[$param];
else $value = @$tag_rule['default'][$param];
}
if (!preg_match($pattern, $value)) {
return false;
}
}
return true;
}
switch (@$tag_rule['mode']) {
default:
case BBCODE_MODE_SIMPLE:
$result = true;
break;
case BBCODE_MODE_ENHANCED:
$result = true;
break;
case BBCODE_MODE_INTERNAL:
$result = @call_user_func(Array($this, @$tag_rule['method']), BBCODE_CHECK,
$tag_name, $default_value, $params, $contents);
break;
case BBCODE_MODE_LIBRARY:
$result = @call_user_func(Array($this->defaults, @$tag_rule['method']), $this, BBCODE_CHECK,
$tag_name, $default_value, $params, $contents);
break;
case BBCODE_MODE_CALLBACK:
$result = @call_user_func(@$tag_rule['method'], $this, BBCODE_CHECK,
$tag_name, $default_value, $params, $contents);
break;
}
return $result;
case BBCODE_OUTPUT:
if ($this->plain_mode) {
if (!isset($tag_rule['plain_content']))
$plain_content = Array('_content');
else $plain_content = $tag_rule['plain_content'];
$result = $possible_content = "";
foreach ($plain_content as $possible_content) {
if ($possible_content == '_content'
&& strlen($contents) > 0) {
$result = $contents;
break;
}
if (isset($params[$possible_content])
&& strlen($params[$possible_content]) > 0) {
$result = htmlspecialchars($params[$possible_content]);
break;
}
}
$start = @$tag_rule['plain_start'];
$end = @$tag_rule['plain_end'];
if (isset($tag_rule['plain_link'])) {
$link = $possible_content = "";
foreach ($tag_rule['plain_link'] as $possible_content) {
if ($possible_content == '_content'
&& strlen($contents) > 0) {
$link = $this->UnHTMLEncode(strip_tags($contents));
break;
}
if (isset($params[$possible_content])
&& strlen($params[$possible_content]) > 0) {
$link = $params[$possible_content];
break;
}
}
$params = @parse_url($link);
if (!is_array($params)) $params = Array();
$params['link'] = $link;
$params['url'] = $link;
$start = $this->FillTemplate($start, $params);
$end = $this->FillTemplate($end, $params);
}
return $start . $result . $end;
}
switch (@$tag_rule['mode']) {
default:
case BBCODE_MODE_SIMPLE:
$result = @$tag_rule['simple_start'] . $contents . @$tag_rule['simple_end'];
break;
case BBCODE_MODE_ENHANCED:
$result = $this->Internal_DoEnhancedTag($tag_rule, $params, $contents);
break;
case BBCODE_MODE_INTERNAL:
$result = @call_user_func(Array($this, @$tag_rule['method']), BBCODE_OUTPUT,
$tag_name, $default_value, $params, $contents);
break;
case BBCODE_MODE_LIBRARY:
$result = @call_user_func(Array($this->defaults, @$tag_rule['method']), $this, BBCODE_OUTPUT,
$tag_name, $default_value, $params, $contents);
break;
case BBCODE_MODE_CALLBACK:
$result = @call_user_func(@$tag_rule['method'], $this, BBCODE_OUTPUT,
$tag_name, $default_value, $params, $contents);
break;
}
return $result;
default:
return false;
}
}

Questions?

We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.