Shorty1968
Erfahrenes Mitglied
Zeilen davor:
Zeilen danach:
PHP:
/**
* Returns true, if $tag is allowed in open tags.
*
* @param array $openTags list of open tags
* @param array $tag
* @return boolean
*/
protected function isAllowed($openTags, $tag, $closing = false) {
foreach ($openTags as $openTag) {
if ($closing && $openTag == $tag) continue;
if ($this->definedTags[$openTag]['allowedChildren'] == 'all') continue;
if ($this->definedTags[$openTag]['allowedChildren'] == 'none') return false;
$arguments = explode('^', $this->definedTags[$openTag]['allowedChildren']);
if (!empty($arguments[1])) $tags = explode(',', $arguments[1]);
else $tags = array();
if ($arguments[0] == 'none' && !in_array($tag, $tags)) return false;
if ($arguments[0] == 'all' && in_array($tag, $tags)) return false;
}
return true;
}
/**
* Builds the parsed string.
*/
public function buildParsedString() {
// reset parsed text
$this->parsedText = '';
// create text buffer
$buffer =& $this->parsedText;
// stack of buffered tags
$bufferedTagStack = array();
// loop through the tags
$i = -1;
foreach ($this->tagArray as $i => $tag) {
PHP:
if ($tag['closing']) {
// get buffered opening tag
$openingTag = end($bufferedTagStack);
// closing tag
if ($openingTag && $openingTag['name'] == $tag['name']) {
$hideBuffer = false;
// insert buffered content as attribute value
foreach ($this->definedTags[$tag['name']]['attributes'] as $attribute) {
if ($attribute['useText'] && !isset($openingTag['attributes'][$attribute['attributeNo']])) {
$openingTag['attributes'][$attribute['attributeNo']] = $buffer;
$hideBuffer = true;
break;
}
}
// validate tag attributes again
if ($this->isValidTag($openingTag)) {
if ($this->definedTags[$tag['name']]['className']) {
// get bbcode object
$bbcodeObj = $this->getBBCodeObject($tag['name']);
// build tag
$parsedTag = $bbcodeObj->getParsedTag($openingTag, $buffer, $tag, $this);
}
else {
// build tag
$parsedTag = $this->buildOpeningTag($openingTag);
$closingTag = $this->buildClosingTag($tag);
if (!empty($closingTag) && $hideBuffer) $parsedTag .= $buffer.$closingTag;
}
}
else {
$parsedTag = $openingTag['source'].$buffer.$tag['source'];
}
// close current buffer
array_pop($bufferedTagStack);
// open previous buffer
if (count($bufferedTagStack) > 0) {
$bufferedTag =& $bufferedTagStack[count($bufferedTagStack) - 1];
$buffer =& $bufferedTag['buffer'];
}
else {
$buffer =& $this->parsedText;
}