Skip to content

Commit 0f815f7

Browse files
authored
Merge pull request #35 from brcontainer/master
Version 1.1.3 👾
2 parents aa05670 + 1b86d27 commit 0f815f7

File tree

1 file changed

+20
-15
lines changed

1 file changed

+20
-15
lines changed

html2canvasproxy.php

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
/*
3-
* html2canvas-php-proxy 1.1.2
3+
* html2canvas-php-proxy 1.1.3
44
*
55
* Copyright (c) 2018 Guilherme Nascimento (brcontainer@yahoo.com.br)
66
*
@@ -35,7 +35,12 @@
3535
define('H2CP_WOL', chr(13));
3636
define('H2CP_GMDATECACHE', gmdate('D, d M Y H:i:s'));
3737
define('H2CP_INIT_EXEC', time());
38-
define('H2CP_JSONP', empty($_GET['callback']) ? false : $_GET['callback']);
38+
39+
if (empty($_GET['callback'])) {
40+
$callback = false;
41+
} else {
42+
$callback = $_GET['callback'];
43+
}
3944

4045
/*
4146
If execution has reached the time limit prevents page goes blank (off errors)
@@ -750,13 +755,13 @@ function downloadSource($url, $toSource, $caller)
750755
$err !== null && empty($err['message']) ? '' : (': ' . $err['message'])
751756
));
752757
$err = null;
758+
} elseif (H2CP_PREFER_CURL && function_exists('curl_init')) {
759+
$response = curlDownloadSource($_GET['url'], $tmp['source']);
753760
} else {
754-
$response = H2CP_PREFER_CURL && function_exists('curl_init') ?
755-
curlDownloadSource($_GET['url'], $tmp['source']) :
756-
downloadSource($_GET['url'], $tmp['source'], 0);
757-
758-
fclose($tmp['source']);
761+
$response = downloadSource($_GET['url'], $tmp['source'], 0);
759762
}
763+
764+
if ($tmp) fclose($tmp['source']);
760765
}
761766

762767
//set mime-type
@@ -794,7 +799,7 @@ function downloadSource($url, $toSource, $caller)
794799
$mime .= ';charset=' . JsonEncodeString($response['encode'], true);
795800
}
796801

797-
if (H2CP_JSONP === false) {
802+
if ($callback === false) {
798803
header('Content-Type: ' . $mime);
799804
echo file_get_contents($locationFile);
800805
} elseif (H2CP_DATAURI) {
@@ -803,13 +808,13 @@ function downloadSource($url, $toSource, $caller)
803808
header('Content-Type: application/javascript');
804809

805810
if (strpos($mime, 'image/svg') !== 0 && strpos($mime, 'image/') === 0) {
806-
echo H2CP_JSONP, '("data:', $mime, ';base64,',
811+
echo $callback, '("data:', $mime, ';base64,',
807812
base64_encode(
808813
file_get_contents($locationFile)
809814
),
810815
'");';
811816
} else {
812-
echo H2CP_JSONP, '("data:', $mime, ',',
817+
echo $callback, '("data:', $mime, ',',
813818
asciiToInline(file_get_contents($locationFile)),
814819
'");';
815820
}
@@ -824,7 +829,7 @@ function downloadSource($url, $toSource, $caller)
824829
$dir_name = '';
825830
}
826831

827-
echo H2CP_JSONP, '(',
832+
echo $callback, '(',
828833
JsonEncodeString(
829834
($http_port === 443 ? 'https://' : 'http://') .
830835
preg_replace('#[:]\\d+$#', '', $_SERVER['HTTP_HOST']) .
@@ -854,10 +859,10 @@ function downloadSource($url, $toSource, $caller)
854859

855860
removeOldFiles();
856861

857-
$callback = H2CP_JSONP !== false ? H2CP_JSONP : H2CP_ALTERNATIVE;
862+
if ($callback === false) {
863+
$callback = H2CP_ALTERNATIVE;
864+
}
858865

859866
echo $callback, '(',
860-
JsonEncodeString(
861-
'error: html2canvas-proxy-php: ' . $response['error']
862-
),
867+
JsonEncodeString('error: html2canvas-proxy-php: ' . $response['error']),
863868
');';

0 commit comments

Comments
 (0)