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; }
/** * Loads an HTML file * * Parse errors are stored in the global array _dompdf_warnings. * * @param string $file a filename or url to load */ function load_html_file($file) { $this->save_locale(); // Store parsing warnings as messages (this is to prevent output to the // browser if the html is ugly and the dom extension complains, // preventing the pdf from being streamed.) if (!$this->_protocol && !$this->_base_host && !$this->_base_path) { list($this->_protocol, $this->_base_host, $this->_base_path) = explode_url_parser($file); } if (!PARSERHTML_ENABLE_REMOTE && ($this->_protocol != "" && $this->_protocol !== "file://")) { throw new Exception("Remote file requested, but PARSERHTML_ENABLE_REMOTE is false."); } if ($this->_protocol == "" || $this->_protocol === "file://") { $realfile = realpath($file); if (!$file) { throw new Exception("File '{$file}' not found."); } if (strpos($realfile, PARSERHTML_CHROOT) !== 0) { throw new Exception("Permission denied on {$file}."); } // Exclude dot files (e.g. .htaccess) if (substr(basename($realfile), 0, 1) === ".") { throw new Exception("Permission denied on {$file}."); } $file = $realfile; } $context = stream_context_create(array('http' => array('method' => 'GET', 'header' => "Cache-Control: no-cache" . "Connection: close\r\n" . "Referer: http://" . $_SERVER['HTTP_HOST'] . "\r\n", 'timeout' => '10'))); $contents = @file_get_contents(urldecode($file), false, $context); if ($contents === false) { /*var_dump($http_response_header);*/ throw new Exception('Issue reading: ' . $file); } if (strpos($file, 'http') === 0) { $this->htmlFile = $file; } //saves url for relative url when parsing $encoding = null; // See http://the-stickman.com/web-development/php/getting-http-response-headers-when-using-file_get_contents/ if (isset($http_response_header)) { foreach ($http_response_header as $_header) { if (preg_match("@Content-Type:\\s*[\\w/]+;\\s*?charset=([^\\s]+)@i", $_header, $matches)) { $encoding = strtoupper($matches[1]); break; } } } $this->restore_locale(); $this->load_html($contents, $encoding); }