]>
git.immae.eu Git - github/wallabag/wallabag.git/blob - inc/poche/pocheTools.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 $pattern = '|^http(s)?://[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?(/.*)?$|i';
43 return preg_match($pattern, $url);
46 public static function getUrl()
48 $https = (!empty($_SERVER['HTTPS
'])
49 && (strtolower($_SERVER['HTTPS
']) == 'on
'))
50 || (isset($_SERVER["SERVER_PORT"])
51 && $_SERVER["SERVER_PORT"] == '443'); // HTTPS detection.
52 $serverport = (!isset($_SERVER["SERVER_PORT"])
53 || $_SERVER["SERVER_PORT"] == '80'
54 || ($https && $_SERVER["SERVER_PORT"] == '443')
55 ? '' : ':' . $_SERVER["SERVER_PORT"]);
57 $scriptname = str_replace('/index
.php
', '/', $_SERVER["SCRIPT_NAME"]);
59 if (!isset($_SERVER["SERVER_NAME"])) {
63 return 'http
' . ($https ? 's
' : '') . '://'
64 . $_SERVER["SERVER_NAME"] . $serverport . $scriptname;
67 public static function redirect($url = '')
70 $url = (empty($_SERVER['HTTP_REFERER'])?'?':$_SERVER['HTTP_REFERER']);
71 if (isset($_POST['returnurl'])) {
72 $url = $_POST['returnurl'];
77 if (empty($url) || parse_url($url, PHP_URL_QUERY
) === $_SERVER['QUERY_STRING']) {
78 $url = pocheTools
::getUrl();
81 if (substr($url, 0, 1) !== '?') {
82 $ref = pocheTools
::getUrl();
83 if (substr($url, 0, strlen($ref)) !== $ref) {
87 header('Location: '.$url);
91 public static function cleanURL($url)
94 $url = html_entity_decode(trim($url));
96 $stuff = strpos($url,'&utm_source=');
98 $url = substr($url, 0, $stuff);
99 $stuff = strpos($url,'?utm_source=');
100 if ($stuff !== FALSE)
101 $url = substr($url, 0, $stuff);
102 $stuff = strpos($url,'#xtor=RSS-');
103 if ($stuff !== FALSE)
104 $url = substr($url, 0, $stuff);
109 public static function renderJson($data)
111 header('Cache-Control: no-cache, must-revalidate');
112 header('Expires: Sat, 26 Jul 1997 05:00:00 GMT');
113 header('Content-type: application/json; charset=UTF-8');
115 echo json_encode($data);
119 public static function logm($message)
122 $t = strval(date('Y/m/d_H:i:s')) . ' - ' . $_SERVER["REMOTE_ADDR"] . ' - ' . strval($message) . "\n";
123 file_put_contents('./log.txt', $t, FILE_APPEND
);