Ejemplo n.º 1
0
 /**
  * Constructor
  * 
  * @param \string $url				Resource document URL
  * @param \string $source			Resource document source code
  * @return \Jkphl\Micrometa			Micrometa parser object
  */
 public function __construct($url, $source = null)
 {
     $this->_url = new \Jkphl\Utility\Url($url, true);
     $this->_source = $source === null ? $this->_getUrl($url) : $source;
     // Instanciate the source document as DOM object
     libxml_use_internal_errors(true);
     $this->_source = mb_convert_encoding($this->_source, 'HTML-ENTITIES', mb_detect_encoding($this->_source));
     $this->dom = new \DOMDocument();
     @$this->dom->loadHTML($this->_source);
     $this->xpath = new \DOMXPath($this->dom);
     // Determine and resolve the base URL
     $this->baseUrl = $this->_url;
     /** @var \DOMElement $base */
     foreach ($this->xpath->query('//base[@href]') as $base) {
         $this->baseUrl = new \Jkphl\Utility\Url($base->getAttribute('href'), true);
         $this->baseUrl->absolutize($this->_url);
         break;
     }
     // Set the focus node
     $this->_focus = $this->dom->documentElement;
     libxml_use_internal_errors(false);
 }