/** * load and parse a CSS file * * @param string $file * @param int $origin */ function load_css_file($file, $origin = self::ORIG_AUTHOR) { if ($origin) { $this->_current_origin = $origin; } // Prevent circular references if (isset($this->_loaded_files[$file])) { return; } $this->_loaded_files[$file] = true; if (strpos($file, "data:") === 0) { $parsed = Helpers::parse_data_uri($file); $css = $parsed["data"]; } else { $parsed_url = Helpers::explode_url($file); list($this->_protocol, $this->_base_host, $this->_base_path, $filename) = $parsed_url; // Fix submitted by Nick Oostveen for aliased directory support: if ($this->_protocol == "") { $file = $this->_base_path . $filename; } else { $file = Helpers::build_url($this->_protocol, $this->_base_host, $this->_base_path, $filename); } list($css, $http_response_header) = Helpers::getFileContent($file, $this->_dompdf->get_http_context()); $good_mime_type = true; // See http://the-stickman.com/web-development/php/getting-http-response-headers-when-using-file_get_contents/ if (isset($http_response_header) && !$this->_dompdf->get_quirksmode()) { foreach ($http_response_header as $_header) { if (preg_match("@Content-Type:\\s*([\\w/]+)@i", $_header, $matches) && $matches[1] !== "text/css") { $good_mime_type = false; } } } if (!$good_mime_type || $css == "") { Helpers::record_warnings(E_USER_WARNING, "Unable to load css file {$file}", __FILE__, __LINE__); return; } } if (substr($file, 0, 4) == "http") { $this->_dompdf->setHttpContext(stream_context_create(['http' => ['method' => "GET", 'header' => "Referer: " . $file]])); } $this->_parse_css($css); }