protected function _image($val) { if (mb_strpos($val, "url") === false) { $path = "none"; //Don't resolve no image -> otherwise would prefix path and no longer recognize as none } else { $val = preg_replace("/url\\(['\"]?([^'\")]+)['\"]?\\)/", "\\1", trim($val)); // Resolve the url now in the context of the current stylesheet $parsed_url = explode_url_parser($val); if ($parsed_url["protocol"] == "" && $this->_stylesheet->get_protocol() == "") { if ($parsed_url["path"][0] === '/' || $parsed_url["path"][0] === '\\') { $path = $_SERVER["DOCUMENT_ROOT"] . '/'; } else { $path = $this->_stylesheet->get_base_path(); } $path .= $parsed_url["path"] . $parsed_url["file"]; $path = realpath($path); // If realpath returns FALSE then specifically state that there is no background image if (!$path) { $path = 'none'; } } else { $path = build_url_parser($this->_stylesheet->get_protocol(), $this->_stylesheet->get_host(), $this->_stylesheet->get_base_path(), $val); } } return $path; }
/** * Builds the {@link FrameParser_Tree}, loads any CSS and applies the styles to * the {@link FrameParser_Tree} */ protected function _process_html($filter = '*') { $this->save_locale(); $this->_tree->build_tree($filter); $this->_css->load_css_file(StyleParsersheet::DEFAULT_STYLESHEET); $acceptedmedia = StyleParsersheet::$ACCEPTED_GENERIC_MEDIA_TYPES; if (defined("PARSERHTML_DEFAULT_MEDIA_TYPE")) { $acceptedmedia[] = PARSERHTML_DEFAULT_MEDIA_TYPE; } else { $acceptedmedia[] = StyleParsersheet::$ACCEPTED_DEFAULT_MEDIA_TYPE; } // load <link rel="STYLESHEET" ... /> tags $links = $this->_xml->getElementsByTagName("link"); foreach ($links as $link) { if (mb_strtolower($link->getAttribute("rel")) === "stylesheet" || mb_strtolower($link->getAttribute("type")) === "text/css") { //Check if the css file is for an accepted media type //media not given then always valid $formedialist = preg_split("/[\\s\n,]/", $link->getAttribute("media"), -1, PREG_SPLIT_NO_EMPTY); if (count($formedialist) > 0) { $accept = false; foreach ($formedialist as $type) { if (in_array(mb_strtolower(trim($type)), $acceptedmedia)) { $accept = true; break; } } if (!$accept) { //found at least one mediatype, but none of the accepted ones //Skip this css file. continue; } } $url = $link->getAttribute("href"); $url = build_url_parser($this->_protocol, $this->_base_host, $this->_base_path, $url); $this->_css->load_css_file($url); } } // load <style> tags $styles = $this->_xml->getElementsByTagName("style"); foreach ($styles as $style) { // Accept all <style> tags by default (note this is contrary to W3C // HTML 4.0 spec: // http://www.w3.org/TR/REC-html40/present/styles.html#adef-media // which states that the default media type is 'screen' if ($style->hasAttributes() && ($media = $style->getAttribute("media")) && !in_array($media, $acceptedmedia)) { continue; } $css = ""; if ($style->hasChildNodes()) { $child = $style->firstChild; while ($child) { $css .= $child->nodeValue; // Handle <style><!-- blah --></style> $child = $child->nextSibling; } } else { $css = $style->nodeValue; } // Set the base path of the StyleParsersheet to that of the file being processed $this->_css->set_protocol($this->_protocol); $this->_css->set_host($this->_base_host); $this->_css->set_base_path($this->_base_path); $this->_css->load_css($css); } $this->restore_locale(); }