]>
git.immae.eu Git - github/wallabag/wallabag.git/blob - inc/pocheTool.class.php
3 * poche, a read it later open source system
6 * @author Nicolas LÅ“uillet <support@inthepoche.com>
8 * @license http://www.wtfpl.net/ see COPYING file
13 public static function initPhp()
15 define('START_TIME', microtime(true));
17 if (phpversion() < 5) {
18 die(_('Oops, it seems you don\'t have PHP 5.'));
21 error_reporting(E_ALL
);
23 function stripslashesDeep($value) {
24 return is_array($value)
25 ? array_map('stripslashesDeep', $value)
26 : stripslashes($value);
29 if (get_magic_quotes_gpc()) {
30 $_POST = array_map('stripslashesDeep', $_POST);
31 $_GET = array_map('stripslashesDeep', $_GET);
32 $_COOKIE = array_map('stripslashesDeep', $_COOKIE);
36 register_shutdown_function('ob_end_flush');
39 public static function isUrl($url)
41 // http://neo22s.com/check-if-url-exists-and-is-online-php/
42 $pattern='|^http(s)?://[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?(/.*)?$|i';
44 return preg_match($pattern, $url);
47 public static function getUrl()
49 $https = (!empty($_SERVER['HTTPS
'])
50 && (strtolower($_SERVER['HTTPS
']) == 'on
'))
51 || (isset($_SERVER["SERVER_PORT"])
52 && $_SERVER["SERVER_PORT"] == '443'); // HTTPS detection.
53 $serverport = (!isset($_SERVER["SERVER_PORT"])
54 || $_SERVER["SERVER_PORT"] == '80'
55 || ($https && $_SERVER["SERVER_PORT"] == '443')
56 ? '' : ':' . $_SERVER["SERVER_PORT"]);
58 $scriptname = str_replace('/index
.php
', '/', $_SERVER["SCRIPT_NAME"]);
60 if (!isset($_SERVER["SERVER_NAME"])) {
64 return 'http
' . ($https ? 's
' : '') . '://'
65 . $_SERVER["SERVER_NAME"] . $serverport . $scriptname;
68 public static function renderJson($data)
70 header('Cache-Control: no-cache, must-revalidate');
71 header('Expires: Sat, 26 Jul 1997 05:00:00 GMT');
72 header('Content-type: application/json; charset=UTF-8');
74 echo json_encode($data);
78 public static function redirect($rurl = '')
81 $rurl = (empty($_SERVER['HTTP_REFERER'])?'?':$_SERVER['HTTP_REFERER']);
82 if (isset($_POST['returnurl'])) {
83 $rurl = $_POST['returnurl'];
88 if (empty($rurl) || parse_url($rurl, PHP_URL_QUERY
) === $_SERVER['QUERY_STRING']) {
89 $rurl = pocheTool
::getUrl();
92 if (substr($rurl, 0, 1) !== '?') {
93 $ref = pocheTool
::getUrl();
94 if (substr($rurl, 0, strlen($ref)) !== $ref) {
98 header('Location: '.$rurl);