/** * Determines if the arguments to the given element are valid based on * any validators attached to this CodeDefinition. * * @param $el the ElementNode to validate * @return true if the ElementNode's {option} and {param} are OK, false if they're not */ public function hasValidInputs(ElementNode $el) { if ($this->usesOption() && $this->optionValidator && !$this->optionValidator->validate($el->getAttribute())) { /* The option argument to $el does not pass the option validator. */ return false; } if (!$this->parseContent() && $this->bodyValidator) { /* We only evaluate the content if we're not parsing the content. */ $content = ""; foreach ($el->getChildren() as $child) { $content .= $child->getAsBBCode(); } if (!$this->bodyValidator->validate($content)) { /* The content of the element is not valid. */ return false; } } return true; }
/** * Accepts an ElementNode that is defined by this CodeDefinition and returns the HTML markup of the element. * This is a commonly overridden class for custom CodeDefinitions so that the content can be directly manipulated. * * @param el the element to return an html representation of * * @return the parsed html of this element (INCLUDING ITS CHILDREN) */ public function asHtml(ElementNode $el) { $html = $this->getReplacementText(); if ($this->usesOption()) { $html = str_ireplace('{option}', $el->getAttribute(), $html); } if ($this->parseContent()) { $content = ""; foreach ($el->getChildren() as $child) { $content .= $child->getAsHTML(); } } else { $content = ""; foreach ($el->getChildren() as $child) { $content .= $child->getAsBBCode(); } } $html = str_ireplace('{param}', $content, $html); return $html; }
/** * Determines if the arguments to the given element are valid based on * any validators attached to this CodeDefinition. * * @param $el the ElementNode to validate * @return true if the ElementNode's {option} and {param} are OK, false if they're not */ public function hasValidInputs(ElementNode $el) { if ($this->usesOption() && $this->optionValidator) { $att = $el->getAttribute(); foreach ($att as $name => $value) { if (isset($this->optionValidator[$name]) && !$this->optionValidator[$name]->validate($value)) { return false; } } } if (!$this->parseContent() && $this->bodyValidator) { /* We only evaluate the content if we're not parsing the content. */ $content = ""; foreach ($el->getChildren() as $child) { $content .= $child->getAsBBCode(); } if (!$this->bodyValidator->validate($content)) { /* The content of the element is not valid. */ return false; } } return true; }