diff options
author | Nicolas Lœuillet <nicolas.loeuillet@gmail.com> | 2013-08-02 22:40:51 +0200 |
---|---|---|
committer | Nicolas Lœuillet <nicolas.loeuillet@gmail.com> | 2013-08-02 22:40:51 +0200 |
commit | a4565e88edbc8e3bd092a475469769c86a4c350c (patch) | |
tree | a6a3c935b03a23ff87575c8c315cf8ba78fe68c2 /inc/poche/pocheTool.class.php | |
parent | f6c9baab3efeec1d0efa151e276fc08d5b58f9e9 (diff) | |
download | wallabag-a4565e88edbc8e3bd092a475469769c86a4c350c.tar.gz wallabag-a4565e88edbc8e3bd092a475469769c86a4c350c.tar.zst wallabag-a4565e88edbc8e3bd092a475469769c86a4c350c.zip |
add Twig & refactor poche
Diffstat (limited to 'inc/poche/pocheTool.class.php')
-rw-r--r-- | inc/poche/pocheTool.class.php | 124 |
1 files changed, 124 insertions, 0 deletions
diff --git a/inc/poche/pocheTool.class.php b/inc/poche/pocheTool.class.php new file mode 100644 index 00000000..cade115e --- /dev/null +++ b/inc/poche/pocheTool.class.php | |||
@@ -0,0 +1,124 @@ | |||
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 | ||