* @license PHP License * @package wb * @subpackage Markup */ WBClass::load('WBMarkup_Validator'); /** * Markup Validator: Html * * Validator for simple HTML elements * * @version 0.2.0 * @package wb * @subpackage Markup */ class WBMarkup_Validator_Html extends WBMarkup_Validator { /** * Validator's config * * @var array */ protected $config = array( 'heading' => array( 1, 2, 3, 4, 5, 6 ), 'markup' => array(), 'paragraph' => array('p', 'br', 'hr'), 'list' => array('ul', 'ol') ); /** * Validate tags * * @param string $ns * @param string $tag * @param array $attributes * @param bool $isEmpty * @return bool */ public function validateStartElement($ns, $tag, $attributes, $isEmpty) { $this->flushError(); if (!empty($ns)) { return false; } // internal HTML validator if ($this->validateHeading($tag, $attributes)) { return true; } if ($this->validateParagraph($tag, $attributes)) { return true; } if ($this->validateMarkup($tag, $attributes)) { return true; } if ($this->validateList($tag, $attributes)) { return true; } return false; } /** * Validate Heading Tag * * * * @param string $tag named tag * @param array $attributes * @return true if tag is a relevant tag for this validator */ private function validateHeading($tag, $attributes) { if (2 != strlen($tag) || 'h' != $tag[0]) { return false; } if (!is_numeric($tag[1])) { return false; } if (!is_array($this->config['heading']) || empty($this->config['heading'])) { $this->setError(1, 'Headings are not allowed.'); return true; } $n = $tag[1]; if (in_array($tag[1], $this->config['heading'])) { return true; } $this->setError(intval($tag[1]) + 1, 'Heading level ' . $tag[1] . ' is not allowed.'); return true; } /** * Validate Paragraph * *
,
and