* @copyright 2013
* @license http://www.wtfpl.net/ see COPYING file
*/
-
+
class Tools
{
public static function initPhp()
die(_('Oops, it seems you don\'t have PHP 5.'));
}
- error_reporting(E_ALL);
-
function stripslashesDeep($value) {
return is_array($value)
? array_map('stripslashesDeep', $value)
&& (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');
return $scriptname;
}
+ $host = (isset($_SERVER['HTTP_X_FORWARDED_HOST']) ? $_SERVER['HTTP_X_FORWARDED_HOST'] : (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : $_SERVER['SERVER_NAME']));
+
+ if (strpos($host, ':') !== false) {
+ $serverport = '';
+ }
+
return 'http' . ($https ? 's' : '') . '://'
- . $_SERVER["HTTP_HOST"] . $serverport . $scriptname;
+ . $host . $serverport . $scriptname;
}
public static function redirect($url = '')
);
# 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));
}
}
- public static function encodeString($string)
+ public static function encodeString($string)
{
return sha1($string . SALT);
}
public static function getDomain($url)
{
- return parse_url($url, PHP_URL_HOST);
+ return parse_url($url, PHP_URL_HOST);
}
public static function getReadingTime($text) {
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';
+ }
+
}