BBCodeLexer::Internal_DecodeTag( $tag )

Description

Source

File: bp-forums/admin/parser.php

function Internal_DecodeTag($tag) {
$result = Array('_tag' => $tag, '_endtag' => '', '_name' => '',
'_hasend' => false, '_end' => false, '_default' => false);
$tag = substr($tag, 1, strlen($tag)-2);
$ch = ord(substr($tag, 0, 1));
if ($ch >= 0 && $ch <= 32) return $result;
$pieces = preg_split("/(\\\"[^\\\"]+\\\"|\\'[^\\']+\\'|=|[\\x00-\\x20]+)/",
$tag, -1, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY);
$ptr = 0;
if (count($pieces) < 1) return $result;
if (@substr($pieces[$ptr], 0, 1) == '/') {
$result['_name'] = strtolower(substr($pieces[$ptr++], 1));
$result['_end'] = true;
}
else {
$result['_name'] = strtolower($pieces[$ptr++]);
$result['_end'] = false;
}
while (($type = $this->Internal_ClassifyPiece($ptr, $pieces)) == ' ')
$ptr++;
$params = Array();
if ($type != '=') {
$result['_default'] = false;
$params[] = Array('key' => '', 'value' => '');
}
else {
$ptr++;
while (($type = $this->Internal_ClassifyPiece($ptr, $pieces)) == ' ')
$ptr++;
if ($type == "\"")
$value = $this->Internal_StripQuotes($pieces[$ptr++]);
else {
$after_space = false;
$start = $ptr;
while (($type = $this->Internal_ClassifyPiece($ptr, $pieces)) != -1) {
if ($type == ' ') $after_space = true;
if ($type == '=' && $after_space) break;
$ptr++;
}
if ($type == -1) $ptr--;
if ($type == '=') {
$ptr--;
while ($ptr > $start && $this->Internal_ClassifyPiece($ptr, $pieces) == ' ')
$ptr--;
while ($ptr > $start && $this->Internal_ClassifyPiece($ptr, $pieces) != ' ')
$ptr--;
}
$value = "";
for (; $start <= $ptr; $start++) {
if ($this->Internal_ClassifyPiece($start, $pieces) == ' ')
$value .= " ";
else $value .= $this->Internal_StripQuotes($pieces[$start]);
}
$value = trim($value);
$ptr++;
}
$result['_default'] = $value;
$params[] = Array('key' => '', 'value' => $value);
}
while (($type = $this->Internal_ClassifyPiece($ptr, $pieces)) != -1) {
while ($type == ' ') {
$ptr++;
$type = $this->Internal_ClassifyPiece($ptr, $pieces);
}
if ($type == 'A' || $type == '"')
$key = strtolower($this->Internal_StripQuotes(@$pieces[$ptr++]));
else if ($type == '=') {
$ptr++;
continue;
}
else if ($type == -1) break;
while (($type = $this->Internal_ClassifyPiece($ptr, $pieces)) == ' ')
$ptr++;
if ($type != '=')
$value = $this->Internal_StripQuotes($key);
else {
$ptr++;
while (($type = $this->Internal_ClassifyPiece($ptr, $pieces)) == ' ')
$ptr++;
if ($type == '"') {
$value = $this->Internal_StripQuotes($pieces[$ptr++]);
}
else if ($type != -1) {
$value = $pieces[$ptr++];
while (($type = $this->Internal_ClassifyPiece($ptr, $pieces)) != -1
&& $type != ' ')
$value .= $pieces[$ptr++];
}
else $value = "";
}
if (substr($key, 0, 1) != '_')
$result[$key] = $value;
$params[] = Array('key' => $key, 'value' => $value);
}
$result['_params'] = $params;
return $result;
}

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.