Ejemplo n.º 1
0
 /**
  * Normalize URLs
  *
  * @link http://dev.w3.org/html5/spec/links.html#attr-hyperlink-href
  *
  * @param  DOMElement $template <xsl:template/> node
  * @return void
  */
 public function normalize(DOMElement $template)
 {
     foreach (TemplateHelper::getURLNodes($template->ownerDocument) as $node) {
         if ($node instanceof DOMAttr) {
             $this->normalizeAttribute($node);
         } elseif ($node instanceof DOMElement) {
             $this->normalizeElement($node);
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * Parse given template and store the references it contains
  *
  * @param  string $template
  * @return void
  */
 protected function parseTemplate($template)
 {
     $this->references = ['anywhere' => [], 'asUrl' => [], 'inText' => []];
     preg_match_all($this->referencesRegexp, $template, $matches);
     foreach ($matches[0] as $match) {
         $key = trim($match, '\\${}');
         $this->references['anywhere'][$key] = $key;
     }
     $dom = TemplateHelper::loadTemplate($template);
     $xpath = new DOMXPath($dom);
     foreach ($xpath->query('//text()') as $node) {
         preg_match_all($this->referencesRegexp, $node->textContent, $matches);
         foreach ($matches[0] as $match) {
             $key = trim($match, '\\${}');
             $this->references['inText'][$key] = $key;
         }
     }
     foreach (TemplateHelper::getURLNodes($dom) as $node) {
         // We only bother with literal attributes that start with a capture
         if ($node instanceof DOMAttr && preg_match('(^(?:[$\\\\]\\d+|\\$\\{\\d+\\}))', trim($node->value), $m)) {
             $key = trim($m[0], '\\${}');
             $this->references['asUrl'][$key] = $key;
         }
     }
     $this->removeUnknownReferences();
 }
Ejemplo n.º 3
0
 protected function parseTemplate($template)
 {
     $this->references = array('anywhere' => array(), 'asUrl' => array(), 'inText' => array());
     \preg_match_all($this->referencesRegexp, $template, $matches);
     foreach ($matches[0] as $match) {
         $key = \trim($match, '\\${}');
         $this->references['anywhere'][$key] = $key;
     }
     $dom = TemplateHelper::loadTemplate($template);
     $xpath = new DOMXPath($dom);
     foreach ($xpath->query('//text()') as $node) {
         \preg_match_all($this->referencesRegexp, $node->textContent, $matches);
         foreach ($matches[0] as $match) {
             $key = \trim($match, '\\${}');
             $this->references['inText'][$key] = $key;
         }
     }
     foreach (TemplateHelper::getURLNodes($dom) as $node) {
         if ($node instanceof DOMAttr && \preg_match('(^(?:[$\\\\]\\d+|\\$\\{\\d+\\}))', \trim($node->value), $m)) {
             $key = \trim($m[0], '\\${}');
             $this->references['asUrl'][$key] = $key;
         }
     }
     $this->removeUnknownReferences();
 }
 /**
  * {@inheritdoc}
  */
 protected function getNodes(DOMElement $template)
 {
     return TemplateHelper::getURLNodes($template->ownerDocument);
 }
Ejemplo n.º 5
0
 /**
  * Return all the nodes in this template whose value is an URL
  *
  * @return array
  */
 public function getURLNodes()
 {
     return TemplateHelper::getURLNodes($this->asDOM());
 }