static function resolve_url($url, $proto, $host, $base_path)
 {
     $parsed_url = explode_url($url);
     $message = null;
     $remote = $proto && $proto !== "file://" || $parsed_url['protocol'] != "";
     $datauri = strpos($parsed_url['protocol'], "data:") === 0;
     try {
         if (!DOMPDF_ENABLE_REMOTE && $remote && !$datauri) {
             throw new DOMPDF_Image_Exception("DOMPDF_ENABLE_REMOTE is set to FALSE");
         } else {
             if (DOMPDF_ENABLE_REMOTE && $remote || $datauri) {
                 $full_url = dompdf_build_url($proto, $host, $base_path, $url);
                 if (isset(self::$_cache[$full_url])) {
                     $resolved_url = self::$_cache[$full_url];
                 } else {
                     $resolved_url = tempnam(DOMPDF_TEMP_DIR, "ca_dompdf_img_");
                     if ($datauri) {
                         if ($parsed_data_uri = parse_data_uri($url)) {
                             $image = $parsed_data_uri['data'];
                         }
                     } else {
                         $old_err = set_error_handler("record_warnings");
                         $image = wp_remote_get($full_url);
                         $image = isset($image['body']) ? $image['body'] : '';
                         restore_error_handler();
                     }
                     if (strlen($image) == 0) {
                         $msg = $datauri ? "Data-URI could not be parsed" : "Image not found";
                         throw new DOMPDF_Image_Exception($msg);
                     } else {
                         file_put_contents($resolved_url, $image);
                     }
                 }
             } else {
                 $resolved_url = dompdf_build_url($proto, $host, $base_path, $url);
             }
         }
         if (!is_readable($resolved_url) || !filesize($resolved_url)) {
             throw new DOMPDF_Image_Exception("Image not readable or empty");
         } else {
             list($width, $height, $type) = dompdf_getimagesize($resolved_url);
             if ($width && $height && in_array($type, array(IMAGETYPE_GIF, IMAGETYPE_PNG, IMAGETYPE_JPEG, IMAGETYPE_BMP))) {
                 if (DOMPDF_ENABLE_REMOTE && $remote) {
                     self::$_cache[$full_url] = $resolved_url;
                 }
             } else {
                 throw new DOMPDF_Image_Exception("Image type unknown");
                 unlink($resolved_url);
             }
         }
     } catch (DOMPDF_Image_Exception $e) {
         $resolved_url = self::$broken_image;
         $type = IMAGETYPE_PNG;
         $message = $e->getMessage() . " \n {$url}";
     }
     return array($resolved_url, $type, $message);
 }
 function add_link($url, $x, $y, $width, $height)
 {
     $y = $this->y($y) - $height;
     if (strpos($url, '#') === 0) {
         $name = substr($url, 1);
         if ($name) {
             $this->_pdf->create_annotation($x, $y, $x + $width, $y + $height, 'Link', "contents={$url} destname=" . substr($url, 1) . " linewidth=0");
         }
     } else {
         list($proto, $host, $path, $file) = explode_url($url);
         if ($proto == "" || $proto === "file://") {
             return;
         }
         $url = dompdf_build_url($proto, $host, $path, $file);
         $url = '{' . rawurldecode($url) . '}';
         $action = $this->_pdf->create_action("URI", "url=" . $url);
         $this->_pdf->create_annotation($x, $y, $x + $width, $y + $height, 'Link', "contents={$url} action={activate={$action}} linewidth=0");
     }
 }
 protected function _process_html()
 {
     $this->save_locale();
     $this->_tree->build_tree();
     $this->_css->load_css_file(Stylesheet::DEFAULT_STYLESHEET, Stylesheet::ORIG_UA);
     $acceptedmedia = Stylesheet::$ACCEPTED_GENERIC_MEDIA_TYPES;
     if (defined("DOMPDF_DEFAULT_MEDIA_TYPE")) {
         $acceptedmedia[] = DOMPDF_DEFAULT_MEDIA_TYPE;
     } else {
         $acceptedmedia[] = Stylesheet::$ACCEPTED_DEFAULT_MEDIA_TYPE;
     }
     $links = $this->_xml->getElementsByTagName("link");
     foreach ($links as $link) {
         if (mb_strtolower($link->getAttribute("rel")) === "stylesheet" || mb_strtolower($link->getAttribute("type")) === "text/css") {
             $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) {
                     continue;
                 }
             }
             $url = $link->getAttribute("href");
             $url = dompdf_build_url($this->_protocol, $this->_base_host, $this->_base_path, $url);
             $this->_css->load_css_file($url, Stylesheet::ORIG_AUTHOR);
         }
     }
     $this->_css->set_protocol($this->_protocol);
     $this->_css->set_host($this->_base_host);
     $this->_css->set_base_path($this->_base_path);
     $styles = $this->_xml->getElementsByTagName("style");
     foreach ($styles as $style) {
         if ($style->hasAttributes() && ($media = $style->getAttribute("media")) && !in_array($media, $acceptedmedia)) {
             continue;
         }
         $css = "";
         if ($style->hasChildNodes()) {
             $child = $style->firstChild;
             while ($child) {
                 $css .= $child->nodeValue;
                 $child = $child->nextSibling;
             }
         } else {
             $css = $style->nodeValue;
         }
         $this->_css->load_css($css);
     }
     $this->restore_locale();
 }
 protected function _image($val)
 {
     $DEBUGCSS = DEBUGCSS;
     if (mb_strpos($val, "url") === false) {
         $path = "none";
     } else {
         $val = preg_replace("/url\\(['\"]?([^'\")]+)['\"]?\\)/", "\\1", trim($val));
         $parsed_url = explode_url($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 (!$path) {
                 $path = 'none';
             }
         } else {
             $path = dompdf_build_url($this->_stylesheet->get_protocol(), $this->_stylesheet->get_host(), $this->_stylesheet->get_base_path(), $val);
         }
     }
     if ($DEBUGCSS) {
         print "<pre>[_image\n";
         print_r($parsed_url);
         print $this->_stylesheet->get_protocol() . "\n" . $this->_stylesheet->get_base_path() . "\n" . $path . "\n";
         print "_image]</pre>";
     }
     return $path;
 }
 private function _parse_font_face($str)
 {
     $descriptors = $this->_parse_properties($str);
     preg_match_all("/(url|local)\\s*\\([\"\\']?([^\"\\'\\)]+)[\"\\']?\\)\\s*(format\\s*\\([\"\\']?([^\"\\'\\)]+)[\"\\']?\\))?/i", $descriptors->src, $src);
     $sources = array();
     $valid_sources = array();
     foreach ($src[0] as $i => $value) {
         $source = array("local" => strtolower($src[1][$i]) === "local", "uri" => $src[2][$i], "format" => $src[4][$i], "path" => dompdf_build_url($this->_protocol, $this->_base_host, $this->_base_path, $src[2][$i]));
         if (!$source["local"] && in_array($source["format"], array("", "woff", "opentype", "truetype"))) {
             $valid_sources[] = $source;
         }
         $sources[] = $source;
     }
     if (empty($valid_sources)) {
         return;
     }
     $style = array("family" => $descriptors->get_font_family_raw(), "weight" => $descriptors->font_weight, "style" => $descriptors->font_style);
     Font_Metrics::register_font($style, $valid_sources[0]["path"]);
 }