Skip to content
This repository has been archived by the owner on Apr 11, 2024. It is now read-only.

Commit

Permalink
Moved some more functions to helpers class
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielbull committed Mar 22, 2014
1 parent 172640d commit 1f62f9e
Show file tree
Hide file tree
Showing 20 changed files with 573 additions and 568 deletions.
2 changes: 1 addition & 1 deletion dompdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ function getoptions() {
if ( strtolower(DOMPDF_PDF_BACKEND) === "gd" )
$outfile = str_replace(".pdf", ".png", $outfile);

list($proto, $host, $path, $file) = Helpers::explodeUrl($outfile);
list($proto, $host, $path, $file) = Helpers::explode_url($outfile);
if ( $proto != "" ) // i.e. not file://
$outfile = $file; // just save it locally, FIXME? could save it like wget: ./host/basepath/file

Expand Down
5 changes: 3 additions & 2 deletions src/Dompdf/Adapter/CPDF.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

use Dompdf\Canvas;
use Dompdf\Dompdf;
use Dompdf\Helpers;
use Dompdf\Exception;
use Dompdf\Image\Cache;
use Dompdf\PhpEvaluator;
Expand Down Expand Up @@ -553,7 +554,7 @@ protected function _convert_gif_bmp_to_png($image_url, $type)
throw new Exception("Function $func_name() not found. Cannot convert $image_type image: $image_url. Please install the image PHP extension.");
}

set_error_handler("record_warnings");
set_error_handler(array("\\Dompdf\\Helpers", "record_warnings"));
$im = $func_name($image_url);

if ($im) {
Expand Down Expand Up @@ -666,7 +667,7 @@ function circle($x, $y, $r1, $color, $width = null, $style = null, $fill = false

function image($img, $x, $y, $w, $h, $resolution = "normal")
{
list($width, $height, $type) = dompdf_getimagesize($img);
list($width, $height, $type) = Helpers::dompdf_getimagesize($img);

$debug_png = $this->_dompdf->get_option("debug_png");

Expand Down
3 changes: 2 additions & 1 deletion src/Dompdf/Adapter/GD.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Dompdf\Canvas;
use Dompdf\Dompdf;
use Dompdf\Image\Cache;
use Dompdf\Helpers;

/**
* Image rendering interface
Expand Down Expand Up @@ -232,7 +233,7 @@ private function _allocate_color($color)
{

if (isset($color["c"])) {
$color = cmyk_to_rgb($color);
$color = Helpers::cmyk_to_rgb($color);
}

// Full opacity if no alpha set
Expand Down
4 changes: 2 additions & 2 deletions src/Dompdf/Adapter/PDFLib.php
Original file line number Diff line number Diff line change
Expand Up @@ -907,11 +907,11 @@ function add_link($url, $x, $y, $width, $height)
$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) = Helpers::explodeUrl($url);
list($proto, $host, $path, $file) = Helpers::explode_url($url);

if ($proto == "" || $proto === "file://")
return; // Local links are not allowed
$url = build_url($proto, $host, $path, $file);
$url = Helpers::build_url($proto, $host, $path, $file);
$url = '{' . rawurldecode($url) . '}';

$action = $this->_pdf->create_action("URI", "url=" . $url);
Expand Down
2 changes: 1 addition & 1 deletion src/Dompdf/Cellmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ public function add_frame(Frame $frame)
$width = $style->width;

$val = null;
if (is_percent($width)) {
if (Helpers::is_percent($width)) {
$var = "percent";
$val = (float)rtrim($width, "% ") / $colspan;
} else if ($width !== "auto") {
Expand Down
4 changes: 2 additions & 2 deletions src/Dompdf/Css/Style.php
Original file line number Diff line number Diff line change
Expand Up @@ -1547,7 +1547,7 @@ protected function _image($val)
$val = preg_replace("/url\(['\"]?([^'\")]+)['\"]?\)/", "\\1", trim($val));

// Resolve the url now in the context of the current stylesheet
$parsed_url = Helpers::explodeUrl($val);
$parsed_url = Helpers::explode_url($val);
if ($parsed_url["protocol"] == "" && $this->_stylesheet->get_protocol() == "") {
if ($parsed_url["path"][0] === '/' || $parsed_url["path"][0] === '\\') {
$path = $_SERVER["DOCUMENT_ROOT"] . '/';
Expand All @@ -1562,7 +1562,7 @@ protected function _image($val)
$path = 'none';
}
} else {
$path = build_url($this->_stylesheet->get_protocol(),
$path = Helpers::build_url($this->_stylesheet->get_protocol(),
$this->_stylesheet->get_host(),
$this->_stylesheet->get_base_path(),
$val);
Expand Down
24 changes: 12 additions & 12 deletions src/Dompdf/Css/Stylesheet.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ function __construct(Dompdf $dompdf)
$this->_dompdf = $dompdf;
$this->_styles = array();
$this->_loaded_files = array();
list($this->_protocol, $this->_base_host, $this->_base_path) = Helpers::explodeUrl($_SERVER["SCRIPT_FILENAME"]);
list($this->_protocol, $this->_base_host, $this->_base_path) = Helpers::explode_url($_SERVER["SCRIPT_FILENAME"]);
$this->_page_styles = array("base" => null);
}

Expand Down Expand Up @@ -316,21 +316,21 @@ function load_css_file($file, $origin = self::ORIG_AUTHOR)
$this->_loaded_files[$file] = true;

if (strpos($file, "data:") === 0) {
$parsed = parse_data_uri($file);
$parsed = Helpers::parse_data_uri($file);
$css = $parsed["data"];
} else {
$parsed_url = Helpers::explodeUrl($file);
$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 = build_url($this->_protocol, $this->_base_host, $this->_base_path, $filename);
$file = Helpers::build_url($this->_protocol, $this->_base_host, $this->_base_path, $filename);
}

set_error_handler("record_warnings");
set_error_handler(array("\\Dompdf\\Helpers", "record_warnings"));
$css = file_get_contents($file, null, $this->_dompdf->get_http_context());
restore_error_handler();

Expand All @@ -348,7 +348,7 @@ function load_css_file($file, $origin = self::ORIG_AUTHOR)
}

if (!$good_mime_type || $css == "") {
record_warnings(E_USER_WARNING, "Unable to load css file $file", __FILE__, __LINE__);
Helpers::record_warnings(E_USER_WARNING, "Unable to load css file $file", __FILE__, __LINE__);
return;
}
}
Expand Down Expand Up @@ -843,7 +843,7 @@ function apply_styles(FrameTree $tree)
// Retrieve the nodes, limit to body for generated content
$nodes = @$xp->query('.' . $query["query"]);
if ($nodes == null) {
record_warnings(E_USER_WARNING, "The CSS selector '$selector' is not valid", __FILE__, __LINE__);
Helpers::record_warnings(E_USER_WARNING, "The CSS selector '$selector' is not valid", __FILE__, __LINE__);
continue;
}

Expand Down Expand Up @@ -875,7 +875,7 @@ function apply_styles(FrameTree $tree)
// Retrieve the nodes
$nodes = @$xp->query($query["query"]);
if ($nodes == null) {
record_warnings(E_USER_WARNING, "The CSS selector '$selector' is not valid", __FILE__, __LINE__);
Helpers::record_warnings(E_USER_WARNING, "The CSS selector '$selector' is not valid", __FILE__, __LINE__);
continue;
}

Expand Down Expand Up @@ -1165,7 +1165,7 @@ protected function _image($val)
$val = preg_replace("/url\(['\"]?([^'\")]+)['\"]?\)/", "\\1", trim($val));

// Resolve the url now in the context of the current stylesheet
$parsed_url = Helpers::explodeUrl($val);
$parsed_url = Helpers::explode_url($val);
if ($parsed_url["protocol"] == "" && $this->get_protocol() == "") {
if ($parsed_url["path"][0] === '/' || $parsed_url["path"][0] === '\\') {
$path = $_SERVER["DOCUMENT_ROOT"] . '/';
Expand All @@ -1181,7 +1181,7 @@ protected function _image($val)
$path = 'none';
}
} else {
$path = build_url($this->get_protocol(),
$path = Helpers::build_url($this->get_protocol(),
$this->get_host(),
$this->get_base_path(),
$val);
Expand Down Expand Up @@ -1234,7 +1234,7 @@ private function _parse_import($url)

// $url = str_replace(array('"',"url", "(", ")"), "", $url);
// If the protocol is php, assume that we will import using file://
// $url = build_url($protocol == "php://" ? "file://" : $protocol, $host, $path, $url);
// $url = Helpers::build_url($protocol == "php://" ? "file://" : $protocol, $host, $path, $url);
// Above does not work for subfolders and absolute urls.
// Todo: As above, do we need to replace php or file to an empty protocol for local files?
Expand Down Expand Up @@ -1271,7 +1271,7 @@ private function _parse_font_face($str)
"local" => strtolower($src[1][$i]) === "local",
"uri" => $src[2][$i],
"format" => $src[4][$i],
"path" => build_url($this->_protocol, $this->_base_host, $this->_base_path, $src[2][$i]),
"path" => Helpers::build_url($this->_protocol, $this->_base_host, $this->_base_path, $src[2][$i]),
);

if (!$source["local"] && in_array($source["format"], array("", "woff", "opentype", "truetype"))) {
Expand Down
10 changes: 5 additions & 5 deletions src/Dompdf/Dompdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ public function loadHtmlFile($file)
// 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) = Helpers::explodeUrl($file);
list($this->_protocol, $this->_base_host, $this->_base_path) = Helpers::explode_url($file);
}

if (!$this->get_option("enable_remote") && ($this->_protocol != "" && $this->_protocol !== "file://")) {
Expand Down Expand Up @@ -595,7 +595,7 @@ public function loadHtml($str, $encoding = null)
}

// Store parsing warnings as messages
set_error_handler("record_warnings");
set_error_handler(array("\\Dompdf\\Helpers", "record_warnings"));

// @todo Take the quirksmode into account
// http://hsivonen.iki.fi/doctype/
Expand Down Expand Up @@ -691,7 +691,7 @@ protected function _process_html()
// <base href="" />
$base_nodes = $this->_xml->getElementsByTagName("base");
if ($base_nodes->length && ($href = $base_nodes->item(0)->getAttribute("href"))) {
list($this->_protocol, $this->_base_host, $this->_base_path) = Helpers::explodeUrl($href);
list($this->_protocol, $this->_base_host, $this->_base_path) = Helpers::explode_url($href);
}

// Set the base path of the Stylesheet to that of the file being processed
Expand Down Expand Up @@ -730,7 +730,7 @@ protected function _process_html()
}

$url = $tag->getAttribute("href");
$url = build_url($this->_protocol, $this->_base_host, $this->_base_path, $url);
$url = Helpers::build_url($this->_protocol, $this->_base_host, $this->_base_path, $url);

$this->_css->load_css_file($url, Stylesheet::ORIG_AUTHOR);
}
Expand Down Expand Up @@ -1007,7 +1007,7 @@ private function write_log()
}

$frames = Frame::$ID_COUNTER;
$memory = DOMPDF_memory_usage() / 1024;
$memory = Helpers::DOMPDF_memory_usage() / 1024;
$time = (microtime(true) - $this->_start_time) * 1000;

$out = sprintf(
Expand Down
10 changes: 5 additions & 5 deletions src/Dompdf/FrameDecorator/AbstractFrameDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use DOMElement;
use DOMNode;
use DOMText;

use Dompdf\Helpers;
use Dompdf\Dompdf;
use Dompdf\Frame;
use Dompdf\Frame\FrameTreeList;
Expand Down Expand Up @@ -749,10 +749,10 @@ function counter_value($id = self::DEFAULT_COUNTER, $type = "decimal")
return str_pad($value, 2, "0");

case "lower-roman":
return dec2roman($value);
return Helpers::dec2roman($value);

case "upper-roman":
return mb_strtoupper(dec2roman($value));
return mb_strtoupper(Helpers::dec2roman($value));

case "lower-latin":
case "lower-alpha":
Expand All @@ -763,10 +763,10 @@ function counter_value($id = self::DEFAULT_COUNTER, $type = "decimal")
return chr(($value % 26) + ord('A') - 1);

case "lower-greek":
return unichr($value + 944);
return Helpers::unichr($value + 944);

case "upper-greek":
return unichr($value + 912);
return Helpers::unichr($value + 912);
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/Dompdf/FrameDecorator/ListBulletImage.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

use Dompdf\Dompdf;
use Dompdf\Frame;
use Dompdf\Helpers;

/**
* Decorates frames for list bullets with custom images
Expand Down Expand Up @@ -53,7 +54,7 @@ function __construct(Frame $frame, Dompdf $dompdf)
$frame->get_node()->setAttribute("src", $url);
$this->_img = new Image($frame, $dompdf);
parent::__construct($this->_img, $dompdf);
list($width, $height) = dompdf_getimagesize($this->_img->get_image_url());
list($width, $height) = Helpers::dompdf_getimagesize($this->_img->get_image_url());

// Resample the bullet image to be consistent with 'auto' sized images
// See also Image::get_min_max_width
Expand Down
Loading

0 comments on commit 1f62f9e

Please sign in to comment.