X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=inc%2Fpoche%2FTools.class.php;h=7f06402079408ebfbc36ead8d6607cef21b99134;hb=ab157bbb75ba226917145c9bf906cbf764a85cd0;hp=eeb101b40c546c037d217c50813c0d2a229f2613;hpb=bf79463070c0dc96eacc52a949c1e3ad356817c0;p=github%2Fwallabag%2Fwallabag.git diff --git a/inc/poche/Tools.class.php b/inc/poche/Tools.class.php old mode 100644 new mode 100755 index eeb101b4..7f064020 --- a/inc/poche/Tools.class.php +++ b/inc/poche/Tools.class.php @@ -7,7 +7,7 @@ * @copyright 2013 * @license http://www.wtfpl.net/ see COPYING file */ - + class Tools { public static function initPhp() @@ -42,7 +42,7 @@ class Tools && (strtolower($_SERVER['HTTPS']) == 'on')) || (isset($_SERVER["SERVER_PORT"]) && $_SERVER["SERVER_PORT"] == '443') // HTTPS detection. - || (isset($_SERVER["SERVER_PORT"]) //Custom HTTPS port detection + || (isset($_SERVER["SERVER_PORT"]) //Custom HTTPS port detection && $_SERVER["SERVER_PORT"] == SSL_PORT) || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https'); @@ -59,8 +59,10 @@ class Tools return $scriptname; } + $host = (isset($_SERVER['HTTP_X_FORWARDED_HOST']) ? $_SERVER['HTTP_X_FORWARDED_HOST'] : (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : $_SERVER['SERVER_NAME'])); + return 'http' . ($https ? 's' : '') . '://' - . $_SERVER["HTTP_HOST"] . $serverport . $scriptname; + . $host . $serverport . $scriptname; } public static function redirect($url = '') @@ -148,7 +150,7 @@ class Tools ); # only download page lesser than 4MB - $data = @file_get_contents($url, false, $context, -1, 4000000); + $data = @file_get_contents($url, false, $context, -1, 4000000); if (isset($http_response_header) and isset($http_response_header[0])) { $httpcodeOK = isset($http_response_header) and isset($http_response_header[0]) and ((strpos($http_response_header[0], '200 OK') !== FALSE) or (strpos($http_response_header[0], '301 Moved Permanently') !== FALSE)); @@ -200,7 +202,7 @@ class Tools } } - public static function encodeString($string) + public static function encodeString($string) { return sha1($string . SALT); } @@ -311,4 +313,14 @@ class Tools return json_decode($json, true); } + + /** + * Returns whether we handle an AJAX (XMLHttpRequest) request. + * @return boolean whether we handle an AJAX (XMLHttpRequest) request. + */ + public static function isAjaxRequest() + { + return isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH']==='XMLHttpRequest'; + } + }