Skip to content

Commit

Permalink
Update to 2.7.9
Browse files Browse the repository at this point in the history
  • Loading branch information
denysdesign committed Jun 7, 2018
1 parent 5261efe commit 5c46faf
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 35 deletions.
2 changes: 1 addition & 1 deletion build.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<project name="julib" default="dist" basedir=".">

<property name="VERSION" value="2.7.8"/>
<property name="VERSION" value="2.7.9"/>

<tstamp>
<format property="DATE" pattern="%d.%m.%Y" />
Expand Down
2 changes: 1 addition & 1 deletion julib/phpthumb/phpthumb.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ class JUThumbs {
public $issafemode = null;
public $php_memory_limit = null;

public $phpthumb_version = '1.7.15-201802181529';
public $phpthumb_version = '1.7.15-201806071234';

//////////////////////////////////////////////////////////////////////

Expand Down
69 changes: 36 additions & 33 deletions julib/phpthumb/phpthumb.functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -536,9 +536,9 @@ public static function gd_version($fullstring=false) {

public static function filesize_remote($remotefile, $timeout=10) {
$size = false;
$url = self::ParseURLbetter($remotefile);
if ($fp = @fsockopen($url['host'], ($url['port'] ? $url['port'] : 80), $errno, $errstr, $timeout)) {
fwrite($fp, 'HEAD '.@$url['path'].@$url['query'].' HTTP/1.0'."\r\n".'Host: '.@$url['host']."\r\n\r\n");
$parsed_url = self::ParseURLbetter($remotefile);
if ($fp = @fsockopen($parsed_url['host'], $parsed_url['port'], $errno, $errstr, $timeout)) {
fwrite($fp, 'HEAD '.$parsed_url['path'].$parsed_url['query'].' HTTP/1.0'."\r\n".'Host: '.$parsed_url['host']."\r\n\r\n");
if (self::version_compare_replacement(PHP_VERSION, '4.3.0', '>=')) {
stream_set_timeout($fp, $timeout);
}
Expand All @@ -557,9 +557,9 @@ public static function filesize_remote($remotefile, $timeout=10) {

public static function filedate_remote($remotefile, $timeout=10) {
$date = false;
$url = self::ParseURLbetter($remotefile);
if ($fp = @fsockopen($url['host'], ($url['port'] ? $url['port'] : 80), $errno, $errstr, $timeout)) {
fwrite($fp, 'HEAD '.@$url['path'].@$url['query'].' HTTP/1.0'."\r\n".'Host: '.@$url['host']."\r\n\r\n");
$parsed_url = self::ParseURLbetter($remotefile);
if ($fp = @fsockopen($parsed_url['host'], $parsed_url['port'], $errno, $errstr, $timeout)) {
fwrite($fp, 'HEAD '.$parsed_url['path'].$parsed_url['query'].' HTTP/1.0'."\r\n".'Host: '.$parsed_url['host']."\r\n\r\n");
if (self::version_compare_replacement(PHP_VERSION, '4.3.0', '>=')) {
stream_set_timeout($fp, $timeout);
}
Expand Down Expand Up @@ -638,11 +638,12 @@ public static function CaseInsensitiveInArray($needle, $haystack) {
return false;
}

public static function URLreadFsock($host, $file, &$errstr, $successonly=true, $port=80, $timeout=10) {
public static function URLreadFsock($host, $file, &$errstr, $successonly=true, $port=-1, $timeout=10) {
if (!function_exists('fsockopen') || self::FunctionIsDisabled('fsockopen')) {
$errstr = 'fsockopen() unavailable';
$errstr = 'URLreadFsock says: function fsockopen() unavailable';
return false;
}
$port = (int) ($port ? $port : -1); // passing anything as the $port parameter (even empty values like null, false, 0, "") will override the default -1. fsockopen uses -1 as the default port value.
//if ($fp = @fsockopen($host, $port, $errno, $errstr, $timeout)) {
if ($fp = @fsockopen((($port == 443) ? 'ssl://' : '').$host, $port, $errno, $errstr, $timeout)) { // https://github.com/JamesHeinrich/phpThumb/issues/39
$out = 'GET '.$file.' HTTP/1.0'."\r\n";
Expand All @@ -651,15 +652,15 @@ public static function URLreadFsock($host, $file, &$errstr, $successonly=true, $
fwrite($fp, $out);

$isHeader = true;
$Data_header = '';
$Data_body = '';
$data_header = '';
$data_body = '';
$header_newlocation = '';
while (!feof($fp)) {
$line = fgets($fp, 1024);
if ($isHeader) {
$Data_header .= $line;
$data_header .= $line;
} else {
$Data_body .= $line;
$data_body .= $line;
}
if (preg_match('#^HTTP/[\\.0-9]+ ([0-9]+) (.+)$#i', rtrim($line), $matches)) {
list( , $errno, $errstr) = $matches;
Expand All @@ -685,7 +686,7 @@ public static function URLreadFsock($host, $file, &$errstr, $successonly=true, $
}
}
fclose($fp);
return $Data_body;
return $data_body;
}
return null;
}
Expand All @@ -694,8 +695,8 @@ public static function CleanUpURLencoding($url, $queryseperator='&') {
if (!preg_match('#^http#i', $url)) {
return $url;
}
$parse_url = self::ParseURLbetter($url);
$pathelements = explode('/', $parse_url['path']);
$parsed_url = self::ParseURLbetter($url);
$pathelements = explode('/', $parsed_url['path']);
$CleanPathElements = array();
$TranslationMatrix = array(' '=>'%20');
foreach ($pathelements as $key => $pathelement) {
Expand All @@ -707,7 +708,7 @@ public static function CleanUpURLencoding($url, $queryseperator='&') {
}
}

$queries = explode($queryseperator, (isset($parse_url['query']) ? $parse_url['query'] : ''));
$queries = explode($queryseperator, $parsed_url['query']);
$CleanQueries = array();
foreach ($queries as $key => $query) {
@list($param, $value) = explode('=', $query);
Expand All @@ -719,30 +720,32 @@ public static function CleanUpURLencoding($url, $queryseperator='&') {
}
}

$cleaned_url = $parse_url['scheme'].'://';
$cleaned_url .= (@$parse_url['username'] ? $parse_url['host'].(@$parse_url['password'] ? ':'.$parse_url['password'] : '').'@' : '');
$cleaned_url .= $parse_url['host'];
$cleaned_url .= ((!empty($parse_url['port']) && ($parse_url['port'] != 80)) ? ':'.$parse_url['port'] : '');
$cleaned_url = $parsed_url['scheme'].'://';
$cleaned_url .= ($parsed_url['username'] ? $parsed_url['username'].($parsed_url['password'] ? ':'.$parsed_url['password'] : '').'@' : '');
$cleaned_url .= $parsed_url['host'];
$cleaned_url .= (($parsed_url['port'] && ($parsed_url['port'] != URLschemeDefaultPort($parsed_url['scheme']))) ? ':'.$parsed_url['port'] : '');
$cleaned_url .= '/'.implode('/', $CleanPathElements);
$cleaned_url .= (@$CleanQueries ? '?'.implode($queryseperator, $CleanQueries) : '');
$cleaned_url .= (!empty($CleanQueries) ? '?'.implode($queryseperator, $CleanQueries) : '');
return $cleaned_url;
}

public static function URLschemeDefaultPort($scheme) {
static $schemePort = array(
'ftp' => 21,
'http' => 80,
'https' => 443,
);
return (isset($schemePort[strtolower($scheme)]) ? $schemePort[strtolower($scheme)] : null);
}

public static function ParseURLbetter($url) {
$parsedURL = @parse_url($url);
if (!@$parsedURL['port']) {
switch (strtolower(@$parsedURL['scheme'])) {
case 'ftp':
$parsedURL['port'] = 21;
break;
case 'https':
$parsedURL['port'] = 443;
break;
case 'http':
$parsedURL['port'] = 80;
break;
foreach (array('scheme', 'host', 'port', 'user', 'pass', 'path', 'query', 'fragment') as $key) { // ensure all possible array keys are always returned
if (!array_key_exists($key, $parsedURL)) {
$parsedURL[$key] = null;
}
}
$parsedURL['port'] = ($parsedURL['port'] ? $parsedURL['port'] : URLschemeDefaultPort($scheme));
return $parsedURL;
}

Expand All @@ -756,7 +759,7 @@ public static function SafeURLread($url, &$error, $timeout=10, $followredirects=

while (true) {
$tryagain = false;
$rawData = self::URLreadFsock(@$parsed_url[ 'host'], @$parsed_url[ 'path'].'?'.@$parsed_url[ 'query'], $errstr, true, (@$parsed_url[ 'port'] ? @$parsed_url[ 'port'] : 80), $timeout);
$rawData = self::URLreadFsock($parsed_url['host'], $parsed_url['path'].'?'.$parsed_url['query'], $errstr, true, $parsed_url['port'], $timeout);
if ($followredirects && preg_match('#302 [a-z ]+; Location\\: (http.*)#i', $errstr, $matches)) {
$matches[1] = trim(@$matches[1]);
if (!@$alreadyLookedAtURLs[$matches[1]]) {
Expand Down

0 comments on commit 5c46faf

Please sign in to comment.