diff options
Diffstat (limited to 'inc/poche/pocheTool.class.php')
-rw-r--r-- | inc/poche/pocheTool.class.php | 124 |
1 files changed, 0 insertions, 124 deletions
diff --git a/inc/poche/pocheTool.class.php b/inc/poche/pocheTool.class.php deleted file mode 100644 index cade115e..00000000 --- a/inc/poche/pocheTool.class.php +++ /dev/null | |||
@@ -1,124 +0,0 @@ | |||
1 | <?php | ||
2 | /** | ||
3 | * poche, a read it later open source system | ||
4 | * | ||
5 | * @category poche | ||
6 | * @author Nicolas LÅ“uillet <support@inthepoche.com> | ||
7 | * @copyright 2013 | ||
8 | * @license http://www.wtfpl.net/ see COPYING file | ||
9 | */ | ||
10 | |||
11 | class pocheTools | ||
12 | { | ||
13 | public static function initPhp() | ||
14 | { | ||
15 | define('START_TIME', microtime(true)); | ||
16 | |||
17 | if (phpversion() < 5) { | ||
18 | die(_('Oops, it seems you don\'t have PHP 5.')); | ||
19 | } | ||
20 | |||
21 | error_reporting(E_ALL); | ||
22 | |||
23 | function stripslashesDeep($value) { | ||
24 | return is_array($value) | ||
25 | ? array_map('stripslashesDeep', $value) | ||
26 | : stripslashes($value); | ||
27 | } | ||
28 | |||
29 | if (get_magic_quotes_gpc()) { | ||
30 | $_POST = array_map('stripslashesDeep', $_POST); | ||
31 | $_GET = array_map('stripslashesDeep', $_GET); | ||
32 | $_COOKIE = array_map('stripslashesDeep', $_COOKIE); | ||
33 | } | ||
34 | |||
35 | ob_start(); | ||
36 | register_shutdown_function('ob_end_flush'); | ||
37 | } | ||
38 | |||
39 | public static function isUrl($url) | ||
40 | { | ||
41 | $pattern = '|^http(s)?://[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?(/.*)?$|i'; | ||
42 | |||
43 | return preg_match($pattern, $url); | ||
44 | } | ||
45 | |||
46 | public static function getUrl() | ||
47 | { | ||
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"]); | ||
56 | |||
57 | $scriptname = str_replace('/index.php', '/', $_SERVER["SCRIPT_NAME"]); | ||
58 | |||
59 | if (!isset($_SERVER["SERVER_NAME"])) { | ||
60 | return $scriptname; | ||
61 | } | ||
62 | |||
63 | return 'http' . ($https ? 's' : '') . '://' | ||
64 | . $_SERVER["SERVER_NAME"] . $serverport . $scriptname; | ||
65 | } | ||
66 | |||
67 | public static function redirect($url = '') | ||
68 | { | ||
69 | if ($url === '') { | ||
70 | $url = (empty($_SERVER['HTTP_REFERER'])?'?':$_SERVER['HTTP_REFERER']); | ||
71 | if (isset($_POST['returnurl'])) { | ||
72 | $url = $_POST['returnurl']; | ||
73 | } | ||
74 | } | ||
75 | |||
76 | # prevent loop | ||
77 | if (empty($url) || parse_url($url, PHP_URL_QUERY) === $_SERVER['QUERY_STRING']) { | ||
78 | $url = pocheTool::getUrl(); | ||
79 | } | ||
80 | |||
81 | if (substr($url, 0, 1) !== '?') { | ||
82 | $ref = pocheTool::getUrl(); | ||
83 | if (substr($url, 0, strlen($ref)) !== $ref) { | ||
84 | $url = $ref; | ||
85 | } | ||
86 | } | ||
87 | header('Location: '.$url); | ||
88 | exit(); | ||
89 | } | ||
90 | |||
91 | public static function cleanURL($url) | ||
92 | { | ||
93 | |||
94 | $url = html_entity_decode(trim($url)); | ||
95 | |||
96 | $stuff = strpos($url,'&utm_source='); | ||
97 | if ($stuff !== FALSE) | ||
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); | ||
105 | |||
106 | return $url; | ||
107 | } | ||
108 | |||
109 | public static function renderJson($data) | ||
110 | { | ||
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'); | ||
114 | |||
115 | echo json_encode($data); | ||
116 | exit(); | ||
117 | } | ||
118 | |||
119 | public static function logm($message) | ||
120 | { | ||
121 | $t = strval(date('Y/m/d_H:i:s')).' - '.$_SERVER["REMOTE_ADDR"].' - '.strval($message)."\n"; | ||
122 | file_put_contents('./log.txt',$t,FILE_APPEND); | ||
123 | } | ||
124 | } \ No newline at end of file | ||