diff options
Diffstat (limited to 'inc/poche/Tools.class.php')
-rw-r--r-- | inc/poche/Tools.class.php | 73 |
1 files changed, 38 insertions, 35 deletions
diff --git a/inc/poche/Tools.class.php b/inc/poche/Tools.class.php index 1d092823..63916582 100644 --- a/inc/poche/Tools.class.php +++ b/inc/poche/Tools.class.php | |||
@@ -53,12 +53,12 @@ class Tools | |||
53 | 53 | ||
54 | $scriptname = str_replace('/index.php', '/', $_SERVER["SCRIPT_NAME"]); | 54 | $scriptname = str_replace('/index.php', '/', $_SERVER["SCRIPT_NAME"]); |
55 | 55 | ||
56 | if (!isset($_SERVER["SERVER_NAME"])) { | 56 | if (!isset($_SERVER["HTTP_HOST"])) { |
57 | return $scriptname; | 57 | return $scriptname; |
58 | } | 58 | } |
59 | 59 | ||
60 | return 'http' . ($https ? 's' : '') . '://' | 60 | return 'http' . ($https ? 's' : '') . '://' |
61 | . $_SERVER["SERVER_NAME"] . $serverport . $scriptname; | 61 | . $_SERVER["HTTP_HOST"] . $serverport . $scriptname; |
62 | } | 62 | } |
63 | 63 | ||
64 | public static function redirect($url = '') | 64 | public static function redirect($url = '') |
@@ -88,39 +88,16 @@ class Tools | |||
88 | 88 | ||
89 | public static function getTplFile($view) | 89 | public static function getTplFile($view) |
90 | { | 90 | { |
91 | $default_tpl = 'home.twig'; | 91 | $views = array( |
92 | 92 | 'install', 'import', 'export', 'config', 'tags', | |
93 | switch ($view) { | 93 | 'edit-tags', 'view', 'login', 'error', 'tag' |
94 | case 'install': | 94 | ); |
95 | $tpl_file = 'install.twig'; | 95 | |
96 | break; | 96 | if (in_array($view, $views)) { |
97 | case 'import'; | 97 | return $view . '.twig'; |
98 | $tpl_file = 'import.twig'; | ||
99 | break; | ||
100 | case 'export': | ||
101 | $tpl_file = 'export.twig'; | ||
102 | break; | ||
103 | case 'config': | ||
104 | $tpl_file = 'config.twig'; | ||
105 | break; | ||
106 | case 'view': | ||
107 | $tpl_file = 'view.twig'; | ||
108 | break; | ||
109 | |||
110 | case 'login': | ||
111 | $tpl_file = 'login.twig'; | ||
112 | break; | ||
113 | |||
114 | case 'error': | ||
115 | $tpl_file = 'error.twig'; | ||
116 | break; | ||
117 | |||
118 | default: | ||
119 | $tpl_file = $default_tpl; | ||
120 | break; | ||
121 | } | 98 | } |
122 | 99 | ||
123 | return $tpl_file; | 100 | return 'home.twig'; |
124 | } | 101 | } |
125 | 102 | ||
126 | public static function getFile($url) | 103 | public static function getFile($url) |
@@ -133,7 +110,9 @@ class Tools | |||
133 | $curl = curl_init(); | 110 | $curl = curl_init(); |
134 | curl_setopt($curl, CURLOPT_URL, $url); | 111 | curl_setopt($curl, CURLOPT_URL, $url); |
135 | curl_setopt($curl, CURLOPT_TIMEOUT, $timeout); | 112 | curl_setopt($curl, CURLOPT_TIMEOUT, $timeout); |
136 | curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); | 113 | if (!ini_get('open_basedir') && !ini_get('safe_mode')) { |
114 | curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); | ||
115 | } | ||
137 | curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); | 116 | curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); |
138 | curl_setopt($curl, CURLOPT_HEADER, false); | 117 | curl_setopt($curl, CURLOPT_HEADER, false); |
139 | 118 | ||
@@ -247,4 +226,28 @@ class Tools | |||
247 | $lang = explode('.', $userlanguage); | 226 | $lang = explode('.', $userlanguage); |
248 | return str_replace('_', '-', $lang[0]); | 227 | return str_replace('_', '-', $lang[0]); |
249 | } | 228 | } |
229 | |||
230 | public static function status($status_code) | ||
231 | { | ||
232 | if (strpos(php_sapi_name(), 'apache') !== false) { | ||
233 | |||
234 | header('HTTP/1.0 '.$status_code); | ||
235 | } | ||
236 | else { | ||
237 | |||
238 | header('Status: '.$status_code); | ||
239 | } | ||
240 | } | ||
241 | |||
242 | |||
243 | public static function download_db() { | ||
244 | header('Content-Disposition: attachment; filename="poche.sqlite.gz"'); | ||
245 | self::status(200); | ||
246 | |||
247 | header('Content-Transfer-Encoding: binary'); | ||
248 | header('Content-Type: application/octet-stream'); | ||
249 | echo gzencode(file_get_contents(STORAGE_SQLITE)); | ||
250 | |||
251 | exit; | ||
252 | } | ||
250 | } | 253 | } |