diff --git a/app/Tygh/Pdf.php b/app/Tygh/Pdf.php
index 7bd9c9b..271fea6 100644
--- a/app/Tygh/Pdf.php
+++ b/app/Tygh/Pdf.php
@@ -18,8 +18,8 @@ use Tygh\Http;
class Pdf
{
- protected static $transaction_id;
- protected static $url = 'http://converter.cart-services.com';
+ private static $_transaction_id;
+ private static $_url = 'http://converter.cart-services.com';
/**
* Pushes HTML code to batch to render PDF later
@@ -28,10 +28,10 @@ class Pdf
*/
public static function batchAdd($html)
{
- $transaction_id = Http::post(self::action('/pdf/batch/add'),
+ $transaction_id = Http::post(self::_action('/pdf/batch/add'),
json_encode(array(
- 'transaction_id' => !empty(self::$transaction_id) ? self::$transaction_id : '',
- 'content' => self::convertImages($html)
+ 'transaction_id' => !empty(self::$_transaction_id) ? self::$_transaction_id : '',
+ 'content' => self::_convertImages($html)
)), array(
'headers' => array(
'Content-type: application/json',
@@ -40,8 +40,8 @@ class Pdf
'binary_transfer' => true
));
- if (!empty($transaction_id) && empty(self::$transaction_id)) {
- self::$transaction_id = json_decode($transaction_id);
+ if (!empty($transaction_id) && empty(self::$_transaction_id)) {
+ self::$_transaction_id = json_decode($transaction_id);
}
return !empty($transaction_id);
@@ -58,27 +58,24 @@ class Pdf
public static function batchRender($filename = '', $save = false, $params = array())
{
$default_params = array(
- 'transaction_id' => self::$transaction_id,
+ 'transaction_id' => self::$_transaction_id,
'page_size' => 'A4'
);
$params = array_merge($default_params, $params);
- $file = fn_create_temp_file();
-
- $response = Http::post(self::action('/pdf/batch/render'), json_encode($params), array(
+ $content = Http::post(self::_action('/pdf/batch/render'), json_encode($params), array(
'headers' => array(
'Content-type: application/json',
'Accept: application/pdf'
),
- 'binary_transfer' => true,
- 'write_to_file' => $file
+ 'binary_transfer' => true
));
- self::$transaction_id = null;
+ self::$_transaction_id = null;
- if (!empty($response)) {
- return self::output($file, $filename, $save);
+ if (!empty($content)) {
+ return self::_output($content, $filename, $save);
}
return false;
@@ -98,8 +95,8 @@ class Pdf
$html = implode("
", $html);
}
- if (self::isLocalIP(gethostbyname($_SERVER['HTTP_HOST']))) {
- $html = self::convertImages($html);
+ if (self::_isLocalIP(gethostbyname($_SERVER['HTTP_HOST']))) {
+ $html = self::_convertImages($html);
}
$default_params = array(
@@ -107,21 +104,18 @@ class Pdf
'page_size' => 'A4'
);
- $params = array_merge($default_params, $params);
-
- $file = fn_create_temp_file();
+ $params = array_merge($default_params, $params);
- $response = Http::post(self::action('/pdf/render'), json_encode($params), array(
+ $content = Http::post(self::_action('/pdf/render'), json_encode($params), array(
'headers' => array(
'Content-type: application/json',
'Accept: application/pdf'
),
- 'binary_transfer' => true,
- 'write_to_file' => $file
+ 'binary_transfer' => true
));
- if (!empty($response)) {
- return self::output($file, $filename, $save);
+ if (!empty($content)) {
+ return self::_output($content, $filename, $save);
}
return false;
@@ -132,26 +126,26 @@ class Pdf
* @param string $action action
* @return string formed URL
*/
- protected static function action($action)
+ private static function _action($action)
{
- return self::$url . $action;
+ return self::$_url . $action;
}
/**
* Saves PDF document or outputs it
- * @param string $file file with PDF document
+ * @param string $content PDF document
* @param string $filename filename to save PDF or name of attachment to download
* @param boolean $save saves to file if true, outputs if not
* @return mixed true if document saved, false on failure or outputs document
*/
- protected static function output($file, $filename = '', $save = false)
+ private static function _output($content, $filename = '', $save = false)
{
if (!empty($filename) && strpos($filename, '.pdf') === false) {
$filename .= '.pdf';
}
if (!empty($filename) && $save == true) {
- return fn_rename($file, $filename);
+ return fn_put_contents($filename, $content);
} else {
if (!empty($filename)) {
@@ -160,8 +154,7 @@ class Pdf
}
header('Content-type: application/pdf');
- readfile($file);
- fn_rm($file);
+ fn_echo($content);
exit;
}
@@ -173,7 +166,7 @@ class Pdf
* @param string $html html code
* @return string html code with converted links
*/
- protected static function convertImages($html)
+ private static function _convertImages($html)
{
$http_location = Registry::get('config.http_location');
$https_location = Registry::get('config.https_location');
@@ -232,7 +225,7 @@ class Pdf
* @param string $ip IP address
* @return boolean true if IP is local, false - if public
*/
- protected static function isLocalIP($ip)
+ private static function _isLocalIP($ip)
{
$ranges = array(
'10' => array(