@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | array( |
69 | 69 | 'site_url' => Settings::get('SITE_URL'), |
70 | 70 | 'site_name' => "Unable to retrieve!", |
71 | - 'okapi_base_url' => Settings::get('SITE_URL')."okapi/", |
|
71 | + 'okapi_base_url' => Settings::get('SITE_URL') . "okapi/", |
|
72 | 72 | ) |
73 | 73 | ); |
74 | 74 | Cache::set($cachekey, $results, 12 * 3600); # so to retry no earlier than after 12 hours |
@@ -83,7 +83,7 @@ discard block |
||
83 | 83 | if ($inst[0]['okapi_base_url']) |
84 | 84 | $okapi_base_url = (string)$inst[0]['okapi_base_url']; |
85 | 85 | else |
86 | - $okapi_base_url = $site_url."okapi/"; |
|
86 | + $okapi_base_url = $site_url . "okapi/"; |
|
87 | 87 | if ($inst[0]['site_name']) |
88 | 88 | $site_name = (string)$inst[0]['site_name']; |
89 | 89 | else |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | $results[] = array( |
106 | 106 | 'site_url' => Settings::get('SITE_URL'), |
107 | 107 | 'site_name' => "DEVELSITE", |
108 | - 'okapi_base_url' => Settings::get('SITE_URL')."okapi/", |
|
108 | + 'okapi_base_url' => Settings::get('SITE_URL') . "okapi/", |
|
109 | 109 | ); |
110 | 110 | # Contact OKAPI developers in order to get added to the official sites list! |
111 | 111 | } |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | # Cache it for one day. Also, save a backup (valid for 30 days). |
114 | 114 | |
115 | 115 | Cache::set($cachekey, $results, 86400); |
116 | - Cache::set($backupkey, $results, 86400*30); |
|
116 | + Cache::set($backupkey, $results, 86400 * 30); |
|
117 | 117 | } |
118 | 118 | |
119 | 119 | return Okapi::formatted_response($request, $results); |
@@ -49,8 +49,7 @@ discard block |
||
49 | 49 | if (!$doc) { |
50 | 50 | throw new ErrorException(); # just to get to the catch block |
51 | 51 | } |
52 | - } |
|
53 | - catch (ErrorException $e) |
|
52 | + } catch (ErrorException $e) |
|
54 | 53 | { |
55 | 54 | # GitHub failed on us. Try to respond with a backup list. |
56 | 55 | |
@@ -80,21 +79,24 @@ discard block |
||
80 | 79 | foreach ($doc->installation as $inst) |
81 | 80 | { |
82 | 81 | $site_url = (string)$inst[0]['site_url']; |
83 | - if ($inst[0]['okapi_base_url']) |
|
84 | - $okapi_base_url = (string)$inst[0]['okapi_base_url']; |
|
85 | - else |
|
86 | - $okapi_base_url = $site_url."okapi/"; |
|
87 | - if ($inst[0]['site_name']) |
|
88 | - $site_name = (string)$inst[0]['site_name']; |
|
89 | - else |
|
90 | - $site_name = Okapi::get_normalized_site_name($site_url); |
|
82 | + if ($inst[0]['okapi_base_url']) { |
|
83 | + $okapi_base_url = (string)$inst[0]['okapi_base_url']; |
|
84 | + } else { |
|
85 | + $okapi_base_url = $site_url."okapi/"; |
|
86 | + } |
|
87 | + if ($inst[0]['site_name']) { |
|
88 | + $site_name = (string)$inst[0]['site_name']; |
|
89 | + } else { |
|
90 | + $site_name = Okapi::get_normalized_site_name($site_url); |
|
91 | + } |
|
91 | 92 | $results[] = array( |
92 | 93 | 'site_url' => $site_url, |
93 | 94 | 'site_name' => $site_name, |
94 | 95 | 'okapi_base_url' => $okapi_base_url, |
95 | 96 | ); |
96 | - if ($site_url == Settings::get('SITE_URL')) |
|
97 | - $i_was_included = true; |
|
97 | + if ($site_url == Settings::get('SITE_URL')) { |
|
98 | + $i_was_included = true; |
|
99 | + } |
|
98 | 100 | } |
99 | 101 | |
100 | 102 | # If running on a local development installation, then include the local |
@@ -195,12 +195,12 @@ discard block |
||
195 | 195 | /** |
196 | 196 | * Maximum size of uploaded images in bytes |
197 | 197 | */ |
198 | - 'IMAGE_MAX_UPLOAD_SIZE' => 4194304, # 4 MB |
|
198 | + 'IMAGE_MAX_UPLOAD_SIZE' => 4194304, # 4 MB |
|
199 | 199 | |
200 | 200 | /** |
201 | 201 | * Maximum 'resolution' of saved images in pixels |
202 | 202 | */ |
203 | - 'IMAGE_MAX_PIXEL_COUNT' => 524288, # 0.5 MP |
|
203 | + 'IMAGE_MAX_PIXEL_COUNT' => 524288, # 0.5 MP |
|
204 | 204 | |
205 | 205 | /** |
206 | 206 | * Quality of saved JPEG images on a scale from 50 to 100. The higher the |
@@ -229,12 +229,12 @@ discard block |
||
229 | 229 | # We have to temporarilly disable our default error handler. |
230 | 230 | |
231 | 231 | OkapiErrorHandler::disable(); |
232 | - require_once($GLOBALS['rootpath']."okapi_settings.php"); |
|
232 | + require_once($GLOBALS['rootpath'] . "okapi_settings.php"); |
|
233 | 233 | $ref = get_okapi_settings(); |
234 | 234 | OkapiErrorHandler::reenable(); |
235 | 235 | |
236 | 236 | } catch (Exception $e) { |
237 | - throw new Exception("Could not import <rootpath>/okapi_settings.php:\n".$e->getMessage()); |
|
237 | + throw new Exception("Could not import <rootpath>/okapi_settings.php:\n" . $e->getMessage()); |
|
238 | 238 | } |
239 | 239 | self::$SETTINGS = self::$DEFAULT_SETTINGS; |
240 | 240 | foreach (self::$SETTINGS as $key => $_) |
@@ -318,12 +318,12 @@ discard block |
||
318 | 318 | */ |
319 | 319 | public static function default_gettext_init($langprefs) |
320 | 320 | { |
321 | - require_once($GLOBALS['rootpath']."okapi/locale/locales.php"); |
|
321 | + require_once($GLOBALS['rootpath'] . "okapi/locale/locales.php"); |
|
322 | 322 | $locale = Locales::get_best_locale($langprefs); |
323 | 323 | putenv("LC_ALL=$locale"); |
324 | 324 | setlocale(LC_ALL, $locale); |
325 | 325 | setlocale(LC_NUMERIC, "POSIX"); # We don't want *this one* to get out of control. |
326 | - bindtextdomain("okapi_messages", $GLOBALS['rootpath'].'okapi/locale'); |
|
326 | + bindtextdomain("okapi_messages", $GLOBALS['rootpath'] . 'okapi/locale'); |
|
327 | 327 | return $locale; |
328 | 328 | } |
329 | 329 |
@@ -249,41 +249,53 @@ discard block |
||
249 | 249 | |
250 | 250 | private static function verify(&$dict) |
251 | 251 | { |
252 | - if (!in_array($dict['OC_BRANCH'], array('oc.pl', 'oc.de'))) |
|
253 | - throw new Exception("Currently, OC_BRANCH has to be either 'oc.pl' or 'oc.de'. Hint: Whom did you get your code from?"); |
|
252 | + if (!in_array($dict['OC_BRANCH'], array('oc.pl', 'oc.de'))) { |
|
253 | + throw new Exception("Currently, OC_BRANCH has to be either 'oc.pl' or 'oc.de'. Hint: Whom did you get your code from?"); |
|
254 | + } |
|
254 | 255 | $boolean_keys = array('DEBUG', 'DEBUG_PREVENT_EMAILS', 'DEBUG_PREVENT_SEMAPHORES'); |
255 | - foreach ($boolean_keys as $key) |
|
256 | - if (!in_array($dict[$key], array(true, false))) |
|
256 | + foreach ($boolean_keys as $key) { |
|
257 | + if (!in_array($dict[$key], array(true, false))) |
|
257 | 258 | throw new Exception("Invalid value for $key."); |
258 | - if (count($dict['ADMINS']) == 0) |
|
259 | - throw new Exception("ADMINS array has to filled (e.g. array('root@localhost'))."); |
|
260 | - if ($dict['DEBUG'] == false) |
|
261 | - foreach ($dict as $k => $v) |
|
259 | + } |
|
260 | + if (count($dict['ADMINS']) == 0) { |
|
261 | + throw new Exception("ADMINS array has to filled (e.g. array('root@localhost'))."); |
|
262 | + } |
|
263 | + if ($dict['DEBUG'] == false) { |
|
264 | + foreach ($dict as $k => $v) |
|
262 | 265 | if ((strpos($k, 'DEBUG_') === 0) && $v == true) |
263 | 266 | throw new Exception("When DEBUG is false, $k has to be false too."); |
264 | - if ($dict['VAR_DIR'] == null) |
|
265 | - throw new Exception("VAR_DIR cannot be null. Please provide a valid directory."); |
|
266 | - if ($dict['IMAGES_DIR'] == null) |
|
267 | - throw new Exception("IMAGES_DIR cannot be null. Please provide a valid directory."); |
|
268 | - foreach ($dict as $k => $v) |
|
269 | - if ((strpos($k, '_DIR') !== false) && ($k[strlen($k) - 1] == '/')) |
|
267 | + } |
|
268 | + if ($dict['VAR_DIR'] == null) { |
|
269 | + throw new Exception("VAR_DIR cannot be null. Please provide a valid directory."); |
|
270 | + } |
|
271 | + if ($dict['IMAGES_DIR'] == null) { |
|
272 | + throw new Exception("IMAGES_DIR cannot be null. Please provide a valid directory."); |
|
273 | + } |
|
274 | + foreach ($dict as $k => $v) { |
|
275 | + if ((strpos($k, '_DIR') !== false) && ($k[strlen($k) - 1] == '/')) |
|
270 | 276 | throw new Exception("None of the *_DIR settings may end with a slash. Check $k."); |
277 | + } |
|
271 | 278 | $notnull = array( |
272 | 279 | 'OC_COOKIE_NAME', 'DB_SERVER', 'DB_NAME', 'DB_USERNAME', 'SITE_URL', |
273 | 280 | 'IMAGES_URL', 'OC_NODE_ID'); |
274 | - foreach ($notnull as $k) |
|
275 | - if ($dict[$k] === null) |
|
281 | + foreach ($notnull as $k) { |
|
282 | + if ($dict[$k] === null) |
|
276 | 283 | throw new Exception("$k cannot be null."); |
284 | + } |
|
277 | 285 | $slash_keys = array('SITE_URL', 'IMAGES_URL'); |
278 | - foreach ($slash_keys as $key) |
|
279 | - if ($dict[$key][strlen($dict[$key]) - 1] != '/') |
|
286 | + foreach ($slash_keys as $key) { |
|
287 | + if ($dict[$key][strlen($dict[$key]) - 1] != '/') |
|
280 | 288 | throw new Exception("$key must end with a slash."); |
281 | - if ($dict['REGISTRATION_URL'] === null) |
|
282 | - $dict['REGISTRATION_URL'] = $dict['SITE_URL'] . 'register.php'; |
|
283 | - if ($dict['SITE_LOGO'] === null) |
|
284 | - $dict['SITE_LOGO'] = $dict['SITE_URL'] . 'okapi/static/oc_logo.png'; |
|
285 | - if ($dict['JPEG_QUALITY'] < 50 || $dict['JPEG_QUALITY'] > 100) |
|
286 | - throw new Exception('JPEG_QUALITY must be between 50 and 100.'); |
|
289 | + } |
|
290 | + if ($dict['REGISTRATION_URL'] === null) { |
|
291 | + $dict['REGISTRATION_URL'] = $dict['SITE_URL'] . 'register.php'; |
|
292 | + } |
|
293 | + if ($dict['SITE_LOGO'] === null) { |
|
294 | + $dict['SITE_LOGO'] = $dict['SITE_URL'] . 'okapi/static/oc_logo.png'; |
|
295 | + } |
|
296 | + if ($dict['JPEG_QUALITY'] < 50 || $dict['JPEG_QUALITY'] > 100) { |
|
297 | + throw new Exception('JPEG_QUALITY must be between 50 and 100.'); |
|
298 | + } |
|
287 | 299 | |
288 | 300 | # The OKAPI code is only compatible with utf8 and utf8mb4 charsets. |
289 | 301 | if (!in_array($dict['DB_CHARSET'], array('utf8', 'utf8mb4'))) { |
@@ -296,11 +308,13 @@ discard block |
||
296 | 308 | */ |
297 | 309 | public static function get($key) |
298 | 310 | { |
299 | - if (self::$SETTINGS == null) |
|
300 | - self::load_settings(); |
|
311 | + if (self::$SETTINGS == null) { |
|
312 | + self::load_settings(); |
|
313 | + } |
|
301 | 314 | |
302 | - if (!array_key_exists($key, self::$SETTINGS)) |
|
303 | - throw new Exception("Tried to access an invalid settings key: '$key'"); |
|
315 | + if (!array_key_exists($key, self::$SETTINGS)) { |
|
316 | + throw new Exception("Tried to access an invalid settings key: '$key'"); |
|
317 | + } |
|
304 | 318 | |
305 | 319 | return self::$SETTINGS[$key]; |
306 | 320 | } |
@@ -11,7 +11,7 @@ discard block |
||
11 | 11 | $row = Db::select_row(" |
12 | 12 | select `key`, secret, name, url, email, bflags |
13 | 13 | from okapi_consumers |
14 | - where `key` = '".Db::escape_string($consumer_key)."' |
|
14 | + where `key` = '".Db::escape_string($consumer_key) . "' |
|
15 | 15 | "); |
16 | 16 | if (!$row) |
17 | 17 | return null; |
@@ -25,9 +25,9 @@ discard block |
||
25 | 25 | select `key`, consumer_key, secret, token_type, user_id, verifier, callback |
26 | 26 | from okapi_tokens |
27 | 27 | where |
28 | - consumer_key = '".Db::escape_string($consumer->key)."' |
|
29 | - and token_type = '".Db::escape_string($token_type)."' |
|
30 | - and `key` = '".Db::escape_string($token)."' |
|
28 | + consumer_key = '".Db::escape_string($consumer->key) . "' |
|
29 | + and token_type = '".Db::escape_string($token_type) . "' |
|
30 | + and `key` = '".Db::escape_string($token) . "' |
|
31 | 31 | "); |
32 | 32 | if (!$row) |
33 | 33 | return null; |
@@ -65,9 +65,9 @@ discard block |
||
65 | 65 | Db::execute(" |
66 | 66 | insert into okapi_nonces (consumer_key, nonce_hash, timestamp) |
67 | 67 | values ( |
68 | - '".Db::escape_string($consumer->key)."', |
|
69 | - '".Db::escape_string($nonce_hash)."', |
|
70 | - '".Db::escape_string($timestamp)."' |
|
68 | + '".Db::escape_string($consumer->key) . "', |
|
69 | + '".Db::escape_string($nonce_hash) . "', |
|
70 | + '".Db::escape_string($timestamp) . "' |
|
71 | 71 | ); |
72 | 72 | "); |
73 | 73 | return null; |
@@ -93,17 +93,17 @@ discard block |
||
93 | 93 | (`key`, secret, token_type, timestamp, |
94 | 94 | user_id, consumer_key, verifier, callback) |
95 | 95 | values ( |
96 | - '".Db::escape_string($token->key)."', |
|
97 | - '".Db::escape_string($token->secret)."', |
|
96 | + '".Db::escape_string($token->key) . "', |
|
97 | + '".Db::escape_string($token->secret) . "', |
|
98 | 98 | 'request', |
99 | 99 | unix_timestamp(), |
100 | 100 | null, |
101 | - '".Db::escape_string($consumer->key)."', |
|
102 | - '".Db::escape_string($token->verifier)."', |
|
101 | + '".Db::escape_string($consumer->key) . "', |
|
102 | + '".Db::escape_string($token->verifier) . "', |
|
103 | 103 | ".(($token->callback_url == 'oob') |
104 | 104 | ? "null" |
105 | - : "'".Db::escape_string($token->callback_url)."'" |
|
106 | - )." |
|
105 | + : "'" . Db::escape_string($token->callback_url) . "'" |
|
106 | + ) . " |
|
107 | 107 | ); |
108 | 108 | "); |
109 | 109 | return $token; |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | |
123 | 123 | Db::execute(" |
124 | 124 | delete from okapi_tokens |
125 | - where `key` = '".Db::escape_string($token->key)."' |
|
125 | + where `key` = '".Db::escape_string($token->key) . "' |
|
126 | 126 | "); |
127 | 127 | |
128 | 128 | # In OKAPI, all Access Tokens are long lived. Therefore, we don't want |
@@ -135,8 +135,8 @@ discard block |
||
135 | 135 | from okapi_tokens |
136 | 136 | where |
137 | 137 | token_type = 'access' |
138 | - and user_id = '".Db::escape_string($token->authorized_by_user_id)."' |
|
139 | - and consumer_key = '".Db::escape_string($consumer->key)."' |
|
138 | + and user_id = '".Db::escape_string($token->authorized_by_user_id) . "' |
|
139 | + and consumer_key = '".Db::escape_string($consumer->key) . "' |
|
140 | 140 | "); |
141 | 141 | if ($row) |
142 | 142 | { |
@@ -155,12 +155,12 @@ discard block |
||
155 | 155 | insert into okapi_tokens |
156 | 156 | (`key`, secret, token_type, timestamp, user_id, consumer_key) |
157 | 157 | values ( |
158 | - '".Db::escape_string($access_token->key)."', |
|
159 | - '".Db::escape_string($access_token->secret)."', |
|
158 | + '".Db::escape_string($access_token->key) . "', |
|
159 | + '".Db::escape_string($access_token->secret) . "', |
|
160 | 160 | 'access', |
161 | 161 | unix_timestamp(), |
162 | - '".Db::escape_string($access_token->user_id)."', |
|
163 | - '".Db::escape_string($consumer->key)."' |
|
162 | + '".Db::escape_string($access_token->user_id) . "', |
|
163 | + '".Db::escape_string($consumer->key) . "' |
|
164 | 164 | ); |
165 | 165 | "); |
166 | 166 | } |
@@ -13,8 +13,9 @@ discard block |
||
13 | 13 | from okapi_consumers |
14 | 14 | where `key` = '".Db::escape_string($consumer_key)."' |
15 | 15 | "); |
16 | - if (!$row) |
|
17 | - return null; |
|
16 | + if (!$row) { |
|
17 | + return null; |
|
18 | + } |
|
18 | 19 | return new OkapiConsumer($row['key'], $row['secret'], $row['name'], |
19 | 20 | $row['url'], $row['email'], $row['bflags']); |
20 | 21 | } |
@@ -29,8 +30,9 @@ discard block |
||
29 | 30 | and token_type = '".Db::escape_string($token_type)."' |
30 | 31 | and `key` = '".Db::escape_string($token)."' |
31 | 32 | "); |
32 | - if (!$row) |
|
33 | - return null; |
|
33 | + if (!$row) { |
|
34 | + return null; |
|
35 | + } |
|
34 | 36 | switch ($row['token_type']) |
35 | 37 | { |
36 | 38 | case 'request': |
@@ -71,8 +73,7 @@ discard block |
||
71 | 73 | ); |
72 | 74 | "); |
73 | 75 | return null; |
74 | - } |
|
75 | - catch (\Exception $e) |
|
76 | + } catch (\Exception $e) |
|
76 | 77 | { |
77 | 78 | # INSERT failed. This nonce was already used. |
78 | 79 | |
@@ -84,8 +85,7 @@ discard block |
||
84 | 85 | { |
85 | 86 | if ((preg_match("#^[a-z][a-z0-9_.-]*://#", $callback) > 0) || |
86 | 87 | $callback == "oob") |
87 | - { /* ok */ } |
|
88 | - else { throw new BadRequest("oauth_callback should begin with lower case <scheme>://, or should equal 'oob'."); } |
|
88 | + { /* ok */ } else { throw new BadRequest("oauth_callback should begin with lower case <scheme>://, or should equal 'oob'."); } |
|
89 | 89 | $token = new OkapiRequestToken(Okapi::generate_key(20), Okapi::generate_key(40), |
90 | 90 | $consumer->key, $callback, null, Okapi::generate_key(8, true)); |
91 | 91 | Db::execute(" |
@@ -111,12 +111,15 @@ discard block |
||
111 | 111 | |
112 | 112 | public function new_access_token($token, $consumer, $verifier = null) |
113 | 113 | { |
114 | - if ($token->consumer_key != $consumer->key) |
|
115 | - throw new BadRequest("Request Token given is not associated with the Consumer who signed the request."); |
|
116 | - if (!$token->authorized_by_user_id) |
|
117 | - throw new BadRequest("Request Token given has not been authorized."); |
|
118 | - if ($token->verifier != $verifier) |
|
119 | - throw new BadRequest("Invalid verifier."); |
|
114 | + if ($token->consumer_key != $consumer->key) { |
|
115 | + throw new BadRequest("Request Token given is not associated with the Consumer who signed the request."); |
|
116 | + } |
|
117 | + if (!$token->authorized_by_user_id) { |
|
118 | + throw new BadRequest("Request Token given has not been authorized."); |
|
119 | + } |
|
120 | + if ($token->verifier != $verifier) { |
|
121 | + throw new BadRequest("Invalid verifier."); |
|
122 | + } |
|
120 | 123 | |
121 | 124 | # Invalidate the Request Token. |
122 | 125 | |
@@ -144,8 +147,7 @@ discard block |
||
144 | 147 | |
145 | 148 | $access_token = new OkapiAccessToken($row['key'], $row['secret'], |
146 | 149 | $consumer->key, $token->authorized_by_user_id); |
147 | - } |
|
148 | - else |
|
150 | + } else |
|
149 | 151 | { |
150 | 152 | # Generate a new Access Token. |
151 | 153 |
@@ -36,9 +36,9 @@ discard block |
||
36 | 36 | use okapi\OkapiFacadeAccessToken; |
37 | 37 | use okapi\Cache; |
38 | 38 | |
39 | -require_once($GLOBALS['rootpath']."okapi/core.php"); |
|
39 | +require_once($GLOBALS['rootpath'] . "okapi/core.php"); |
|
40 | 40 | OkapiErrorHandler::$treat_notices_as_errors = true; |
41 | -require_once($GLOBALS['rootpath']."okapi/service_runner.php"); |
|
41 | +require_once($GLOBALS['rootpath'] . "okapi/service_runner.php"); |
|
42 | 42 | Okapi::init_internals(); |
43 | 43 | |
44 | 44 | /** |
@@ -97,10 +97,10 @@ discard block |
||
97 | 97 | */ |
98 | 98 | public static function import_search_set($temp_table, $min_store, $max_ref_age) |
99 | 99 | { |
100 | - require_once($GLOBALS['rootpath'].'okapi/services/caches/search/save.php'); |
|
100 | + require_once($GLOBALS['rootpath'] . 'okapi/services/caches/search/save.php'); |
|
101 | 101 | $tables = array('caches', $temp_table); |
102 | 102 | $where_conds = array( |
103 | - $temp_table.".cache_id = caches.cache_id", |
|
103 | + $temp_table . ".cache_id = caches.cache_id", |
|
104 | 104 | 'caches.status in (1,2,3)', |
105 | 105 | ); |
106 | 106 | return \okapi\services\caches\search\save\WebService::get_set( |
@@ -123,7 +123,7 @@ discard block |
||
123 | 123 | Db::execute(" |
124 | 124 | update caches |
125 | 125 | set okapi_syncbase = now() |
126 | - where wp_oc in ('".implode("','", array_map('\okapi\Db::escape_string', $cache_codes))."') |
|
126 | + where wp_oc in ('".implode("','", array_map('\okapi\Db::escape_string', $cache_codes)) . "') |
|
127 | 127 | "); |
128 | 128 | } |
129 | 129 | |
@@ -140,8 +140,8 @@ discard block |
||
140 | 140 | update cache_logs |
141 | 141 | set okapi_syncbase = now() |
142 | 142 | where |
143 | - cache_id = '".Db::escape_string($cache_id)."' |
|
144 | - and user_id = '".Db::escape_string($user_id)."' |
|
143 | + cache_id = '".Db::escape_string($cache_id) . "' |
|
144 | + and user_id = '".Db::escape_string($user_id) . "' |
|
145 | 145 | "); |
146 | 146 | } |
147 | 147 | |
@@ -151,7 +151,7 @@ discard block |
||
151 | 151 | */ |
152 | 152 | public static function database_update() |
153 | 153 | { |
154 | - require_once($GLOBALS['rootpath']."okapi/views/update.php"); |
|
154 | + require_once($GLOBALS['rootpath'] . "okapi/views/update.php"); |
|
155 | 155 | $update = new views\update\View; |
156 | 156 | $update->call(); |
157 | 157 | } |
@@ -201,7 +201,7 @@ discard block |
||
201 | 201 | */ |
202 | 202 | public static function cache_set($key, $value, $timeout) |
203 | 203 | { |
204 | - Cache::set("facade#".$key, $value, $timeout); |
|
204 | + Cache::set("facade#" . $key, $value, $timeout); |
|
205 | 205 | } |
206 | 206 | |
207 | 207 | /** Same as `cache_set`, but works on many key->value pair at once. */ |
@@ -209,7 +209,7 @@ discard block |
||
209 | 209 | { |
210 | 210 | $prefixed_dict = array(); |
211 | 211 | foreach ($dict as $key => &$value_ref) { |
212 | - $prefixed_dict["facade#".$key] = &$value_ref; |
|
212 | + $prefixed_dict["facade#" . $key] = &$value_ref; |
|
213 | 213 | } |
214 | 214 | Cache::set_many($prefixed_dict, $timeout); |
215 | 215 | } |
@@ -220,7 +220,7 @@ discard block |
||
220 | 220 | */ |
221 | 221 | public static function cache_get($key) |
222 | 222 | { |
223 | - return Cache::get("facade#".$key); |
|
223 | + return Cache::get("facade#" . $key); |
|
224 | 224 | } |
225 | 225 | |
226 | 226 | /** Same as `cache_get`, but it works on multiple keys at once. */ |
@@ -228,7 +228,7 @@ discard block |
||
228 | 228 | { |
229 | 229 | $prefixed_keys = array(); |
230 | 230 | foreach ($keys as $key) { |
231 | - $prefixed_keys[] = "facade#".$key; |
|
231 | + $prefixed_keys[] = "facade#" . $key; |
|
232 | 232 | } |
233 | 233 | $prefixed_result = Cache::get_many($prefixed_keys); |
234 | 234 | $result = array(); |
@@ -243,7 +243,7 @@ discard block |
||
243 | 243 | */ |
244 | 244 | public static function cache_delete($key) |
245 | 245 | { |
246 | - Cache::delete("facade#".$key); |
|
246 | + Cache::delete("facade#" . $key); |
|
247 | 247 | } |
248 | 248 | |
249 | 249 | /** Same as `cache_delete`, but works on many keys at once. */ |
@@ -251,7 +251,7 @@ discard block |
||
251 | 251 | { |
252 | 252 | $prefixed_keys = array(); |
253 | 253 | foreach ($keys as $key) { |
254 | - $prefixed_keys[] = "facade#".$key; |
|
254 | + $prefixed_keys[] = "facade#" . $key; |
|
255 | 255 | } |
256 | 256 | Cache::delete_many($prefixed_keys); |
257 | 257 | } |
@@ -78,8 +78,9 @@ discard block |
||
78 | 78 | ); |
79 | 79 | $request->i_want_OkapiResponse = true; |
80 | 80 | $request->perceive_as_http_request = true; |
81 | - if (isset($_SERVER['HTTP_IF_NONE_MATCH'])) |
|
82 | - $request->etag = $_SERVER['HTTP_IF_NONE_MATCH']; |
|
81 | + if (isset($_SERVER['HTTP_IF_NONE_MATCH'])) { |
|
82 | + $request->etag = $_SERVER['HTTP_IF_NONE_MATCH']; |
|
83 | + } |
|
83 | 84 | $response = OkapiServiceRunner::call($service_name, $request); |
84 | 85 | $response->display(); |
85 | 86 | } |
@@ -118,8 +119,9 @@ discard block |
||
118 | 119 | */ |
119 | 120 | public static function schedule_geocache_check($cache_codes) |
120 | 121 | { |
121 | - if (!is_array($cache_codes)) |
|
122 | - $cache_codes = array($cache_codes); |
|
122 | + if (!is_array($cache_codes)) { |
|
123 | + $cache_codes = array($cache_codes); |
|
124 | + } |
|
123 | 125 | Db::execute(" |
124 | 126 | update caches |
125 | 127 | set okapi_syncbase = now() |
@@ -20,8 +20,9 @@ discard block |
||
20 | 20 | public static function get_required_locales() |
21 | 21 | { |
22 | 22 | $arr = array('POSIX'); |
23 | - foreach (self::$languages as $key => $value) |
|
24 | - $arr[] = $value['locale']; |
|
23 | + foreach (self::$languages as $key => $value) { |
|
24 | + $arr[] = $value['locale']; |
|
25 | + } |
|
25 | 26 | return $arr; |
26 | 27 | } |
27 | 28 | |
@@ -31,16 +32,18 @@ discard block |
||
31 | 32 | public static function get_installed_locales() |
32 | 33 | { |
33 | 34 | $arr = array(); |
34 | - foreach (explode("\n", shell_exec("locale -a")) as $item) |
|
35 | - if ($item) |
|
35 | + foreach (explode("\n", shell_exec("locale -a")) as $item) { |
|
36 | + if ($item) |
|
36 | 37 | $arr[] = $item; |
38 | + } |
|
37 | 39 | return $arr; |
38 | 40 | } |
39 | 41 | |
40 | 42 | private static function get_locale_for_language($lang) |
41 | 43 | { |
42 | - if (isset(self::$languages[$lang])) |
|
43 | - return self::$languages[$lang]['locale']; |
|
44 | + if (isset(self::$languages[$lang])) { |
|
45 | + return self::$languages[$lang]['locale']; |
|
46 | + } |
|
44 | 47 | return null; |
45 | 48 | } |
46 | 49 | |
@@ -49,8 +52,9 @@ discard block |
||
49 | 52 | foreach ($langprefs as $lang) |
50 | 53 | { |
51 | 54 | $locale = self::get_locale_for_language($lang); |
52 | - if ($locale != null) |
|
53 | - return $locale; |
|
55 | + if ($locale != null) { |
|
56 | + return $locale; |
|
57 | + } |
|
54 | 58 | } |
55 | 59 | return self::$languages['en']['locale']; |
56 | 60 | } |
@@ -25,6 +25,6 @@ |
||
25 | 25 | if (!$OC_sessionid) |
26 | 26 | return null; |
27 | 27 | |
28 | - return Db::select_value("select user_id from sys_sessions where uuid='".Db::escape_string($OC_sessionid)."'"); |
|
28 | + return Db::select_value("select user_id from sys_sessions where uuid='" . Db::escape_string($OC_sessionid) . "'"); |
|
29 | 29 | } |
30 | 30 | } |
31 | 31 | \ No newline at end of file |
@@ -12,18 +12,22 @@ |
||
12 | 12 | public static function get_user_id() |
13 | 13 | { |
14 | 14 | static $cached_result = false; |
15 | - if ($cached_result !== false) |
|
16 | - return $cached_result; |
|
15 | + if ($cached_result !== false) { |
|
16 | + return $cached_result; |
|
17 | + } |
|
17 | 18 | |
18 | 19 | $cookie_name = Settings::get('OC_COOKIE_NAME'); |
19 | - if (!isset($_COOKIE[$cookie_name])) |
|
20 | - return null; |
|
20 | + if (!isset($_COOKIE[$cookie_name])) { |
|
21 | + return null; |
|
22 | + } |
|
21 | 23 | $OC_data = unserialize(base64_decode($_COOKIE[$cookie_name])); |
22 | - if (!isset($OC_data['sessionid'])) |
|
23 | - return null; |
|
24 | + if (!isset($OC_data['sessionid'])) { |
|
25 | + return null; |
|
26 | + } |
|
24 | 27 | $OC_sessionid = $OC_data['sessionid']; |
25 | - if (!$OC_sessionid) |
|
26 | - return null; |
|
28 | + if (!$OC_sessionid) { |
|
29 | + return null; |
|
30 | + } |
|
27 | 31 | |
28 | 32 | return Db::select_value("select user_id from sys_sessions where uuid='".Db::escape_string($OC_sessionid)."'"); |
29 | 33 | } |
@@ -22,14 +22,14 @@ discard block |
||
22 | 22 | // traverse PHP call stack to find out who originally called us |
23 | 23 | // first, find first service_runner.php invocation |
24 | 24 | // then, find previous class invocation |
25 | - for($i = count($trace)-1; $i >= 0; $i--) |
|
25 | + for ($i = count($trace) - 1; $i >= 0; $i--) |
|
26 | 26 | { |
27 | 27 | $frame = $trace[$i]; |
28 | 28 | if ($break_next && isset($frame['class'])) |
29 | 29 | { |
30 | 30 | $class_elems = explode('\\', $frame['class']); |
31 | 31 | if (count($class_elems) >= 2) |
32 | - $org_caller = $class_elems[count($class_elems)-2]; |
|
32 | + $org_caller = $class_elems[count($class_elems) - 2]; |
|
33 | 33 | break; |
34 | 34 | } |
35 | 35 | if (isset($frame['file']) && |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | public static function log_geocache_access(OkapiRequest $request, $cache_ids) |
52 | 52 | { |
53 | 53 | if (Settings::get('OCPL_ENABLE_GEOCACHE_ACCESS_LOGS') !== true) |
54 | - return ; |
|
54 | + return; |
|
55 | 55 | |
56 | 56 | if (Settings::get('OC_BRANCH') == 'oc.pl') |
57 | 57 | { |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | if ($request->token != null) |
71 | 71 | $user_id = $request->token->user_id; |
72 | 72 | $user_id_escaped = $user_id === null ? "null" : "'" . Db::escape_string($user_id) . "'"; |
73 | - if (is_array($cache_ids)){ |
|
73 | + if (is_array($cache_ids)) { |
|
74 | 74 | if (count($cache_ids) == 1) |
75 | 75 | $cache_ids_where = "= '" . Db::escape_string($cache_ids[0]) . "'"; |
76 | 76 | else |
@@ -101,24 +101,24 @@ discard block |
||
101 | 101 | if (is_array($cache_ids) && count($already_logged_cache_ids) == count($cache_ids) |
102 | 102 | || !is_array($cache_ids) && count($already_logged_cache_ids) == 1) |
103 | 103 | { |
104 | - return ; |
|
104 | + return; |
|
105 | 105 | } |
106 | 106 | |
107 | - if (is_array($cache_ids)){ |
|
107 | + if (is_array($cache_ids)) { |
|
108 | 108 | $tmp = array(); |
109 | 109 | foreach ($cache_ids as $cache_id) |
110 | 110 | $tmp[$cache_id] = true; |
111 | 111 | foreach ($already_logged_cache_ids as $cache_id) |
112 | 112 | unset($tmp[$cache_id]); |
113 | 113 | if (count($tmp) <= 0) |
114 | - return ; |
|
114 | + return; |
|
115 | 115 | $cache_ids_filterd = array_keys($tmp); |
116 | 116 | unset($tmp); |
117 | 117 | } else { |
118 | 118 | $cache_ids_filterd = $cache_ids; |
119 | 119 | } |
120 | 120 | |
121 | - if (is_array($cache_ids_filterd)){ |
|
121 | + if (is_array($cache_ids_filterd)) { |
|
122 | 122 | if (count($cache_ids_filterd) == 1) |
123 | 123 | $cache_ids_where = "= '" . Db::escape_string($cache_ids_filterd[0]) . "'"; |
124 | 124 | else |
@@ -28,8 +28,9 @@ discard block |
||
28 | 28 | if ($break_next && isset($frame['class'])) |
29 | 29 | { |
30 | 30 | $class_elems = explode('\\', $frame['class']); |
31 | - if (count($class_elems) >= 2) |
|
32 | - $org_caller = $class_elems[count($class_elems)-2]; |
|
31 | + if (count($class_elems) >= 2) { |
|
32 | + $org_caller = $class_elems[count($class_elems)-2]; |
|
33 | + } |
|
33 | 34 | break; |
34 | 35 | } |
35 | 36 | if (isset($frame['file']) && |
@@ -50,8 +51,9 @@ discard block |
||
50 | 51 | */ |
51 | 52 | public static function log_geocache_access(OkapiRequest $request, $cache_ids) |
52 | 53 | { |
53 | - if (Settings::get('OCPL_ENABLE_GEOCACHE_ACCESS_LOGS') !== true) |
|
54 | - return ; |
|
54 | + if (Settings::get('OCPL_ENABLE_GEOCACHE_ACCESS_LOGS') !== true) { |
|
55 | + return ; |
|
56 | + } |
|
55 | 57 | |
56 | 58 | if (Settings::get('OC_BRANCH') == 'oc.pl') |
57 | 59 | { |
@@ -67,14 +69,16 @@ discard block |
||
67 | 69 | $original_caller_escaped = "'" . Db::escape_string(self::get_original_caller()) . "'"; |
68 | 70 | |
69 | 71 | $user_id = null; |
70 | - if ($request->token != null) |
|
71 | - $user_id = $request->token->user_id; |
|
72 | + if ($request->token != null) { |
|
73 | + $user_id = $request->token->user_id; |
|
74 | + } |
|
72 | 75 | $user_id_escaped = $user_id === null ? "null" : "'" . Db::escape_string($user_id) . "'"; |
73 | 76 | if (is_array($cache_ids)){ |
74 | - if (count($cache_ids) == 1) |
|
75 | - $cache_ids_where = "= '" . Db::escape_string($cache_ids[0]) . "'"; |
|
76 | - else |
|
77 | - $cache_ids_where = "in ('" . implode("','", array_map('\okapi\Db::escape_string', $cache_ids)) . "')"; |
|
77 | + if (count($cache_ids) == 1) { |
|
78 | + $cache_ids_where = "= '" . Db::escape_string($cache_ids[0]) . "'"; |
|
79 | + } else { |
|
80 | + $cache_ids_where = "in ('" . implode("','", array_map('\okapi\Db::escape_string', $cache_ids)) . "')"; |
|
81 | + } |
|
78 | 82 | } else { |
79 | 83 | $cache_ids_where = "= '" . Db::escape_string($cache_ids) . "'"; |
80 | 84 | } |
@@ -106,12 +110,15 @@ discard block |
||
106 | 110 | |
107 | 111 | if (is_array($cache_ids)){ |
108 | 112 | $tmp = array(); |
109 | - foreach ($cache_ids as $cache_id) |
|
110 | - $tmp[$cache_id] = true; |
|
111 | - foreach ($already_logged_cache_ids as $cache_id) |
|
112 | - unset($tmp[$cache_id]); |
|
113 | - if (count($tmp) <= 0) |
|
114 | - return ; |
|
113 | + foreach ($cache_ids as $cache_id) { |
|
114 | + $tmp[$cache_id] = true; |
|
115 | + } |
|
116 | + foreach ($already_logged_cache_ids as $cache_id) { |
|
117 | + unset($tmp[$cache_id]); |
|
118 | + } |
|
119 | + if (count($tmp) <= 0) { |
|
120 | + return ; |
|
121 | + } |
|
115 | 122 | $cache_ids_filterd = array_keys($tmp); |
116 | 123 | unset($tmp); |
117 | 124 | } else { |
@@ -119,10 +126,11 @@ discard block |
||
119 | 126 | } |
120 | 127 | |
121 | 128 | if (is_array($cache_ids_filterd)){ |
122 | - if (count($cache_ids_filterd) == 1) |
|
123 | - $cache_ids_where = "= '" . Db::escape_string($cache_ids_filterd[0]) . "'"; |
|
124 | - else |
|
125 | - $cache_ids_where = "in ('" . implode("','", array_map('\okapi\Db::escape_string', $cache_ids_filterd)) . "')"; |
|
129 | + if (count($cache_ids_filterd) == 1) { |
|
130 | + $cache_ids_where = "= '" . Db::escape_string($cache_ids_filterd[0]) . "'"; |
|
131 | + } else { |
|
132 | + $cache_ids_where = "in ('" . implode("','", array_map('\okapi\Db::escape_string', $cache_ids_filterd)) . "')"; |
|
133 | + } |
|
126 | 134 | } else { |
127 | 135 | $cache_ids_where = "= '" . Db::escape_string($cache_ids_filterd) . "'"; |
128 | 136 | } |
@@ -73,15 +73,15 @@ discard block |
||
73 | 73 | { |
74 | 74 | if (!self::exists($service_name)) |
75 | 75 | throw new Exception(); |
76 | - require_once($GLOBALS['rootpath']."okapi/$service_name.php"); |
|
76 | + require_once($GLOBALS['rootpath'] . "okapi/$service_name.php"); |
|
77 | 77 | try |
78 | 78 | { |
79 | - return call_user_func(array('\\okapi\\'. |
|
80 | - str_replace('/', '\\', $service_name).'\\WebService', 'options')); |
|
79 | + return call_user_func(array('\\okapi\\' . |
|
80 | + str_replace('/', '\\', $service_name) . '\\WebService', 'options')); |
|
81 | 81 | } catch (Exception $e) |
82 | 82 | { |
83 | - throw new Exception("Make sure you've declared your WebService class ". |
|
84 | - "in an valid namespace (".'okapi\\'.str_replace('/', '\\', $service_name)."); ". |
|
83 | + throw new Exception("Make sure you've declared your WebService class " . |
|
84 | + "in an valid namespace (" . 'okapi\\' . str_replace('/', '\\', $service_name) . "); " . |
|
85 | 85 | $e->getMessage()); |
86 | 86 | } |
87 | 87 | } |
@@ -120,13 +120,13 @@ discard block |
||
120 | 120 | $options = self::options($service_name); |
121 | 121 | if ($options['min_auth_level'] >= 2 && $request->consumer == null) |
122 | 122 | { |
123 | - throw new Exception("Method '$service_name' called with mismatched OkapiRequest: ". |
|
124 | - "\$request->consumer MAY NOT be empty for Level 2 and Level 3 methods. Provide ". |
|
123 | + throw new Exception("Method '$service_name' called with mismatched OkapiRequest: " . |
|
124 | + "\$request->consumer MAY NOT be empty for Level 2 and Level 3 methods. Provide " . |
|
125 | 125 | "a dummy Consumer if you have to."); |
126 | 126 | } |
127 | 127 | if ($options['min_auth_level'] >= 3 && $request->token == null) |
128 | 128 | { |
129 | - throw new Exception("Method '$service_name' called with mismatched OkapiRequest: ". |
|
129 | + throw new Exception("Method '$service_name' called with mismatched OkapiRequest: " . |
|
130 | 130 | "\$request->token MAY NOT be empty for Level 3 methods."); |
131 | 131 | } |
132 | 132 | |
@@ -134,14 +134,14 @@ discard block |
||
134 | 134 | Okapi::gettext_domain_init(); |
135 | 135 | try |
136 | 136 | { |
137 | - require_once($GLOBALS['rootpath']."okapi/$service_name.php"); |
|
138 | - $response = call_user_func(array('\\okapi\\'. |
|
139 | - str_replace('/', '\\', $service_name).'\\WebService', 'call'), $request); |
|
137 | + require_once($GLOBALS['rootpath'] . "okapi/$service_name.php"); |
|
138 | + $response = call_user_func(array('\\okapi\\' . |
|
139 | + str_replace('/', '\\', $service_name) . '\\WebService', 'call'), $request); |
|
140 | 140 | if ($options['min_auth_level'] >= 3 && $request->token->token_type == "access") |
141 | 141 | { |
142 | 142 | Db::execute(" |
143 | 143 | update user set last_login=now() |
144 | - where user_id='".Db::escape_string($request->token->user_id)."' |
|
144 | + where user_id='".Db::escape_string($request->token->user_id) . "' |
|
145 | 145 | "); |
146 | 146 | } |
147 | 147 | Okapi::gettext_domain_restore(); |
@@ -166,7 +166,7 @@ discard block |
||
166 | 166 | */ |
167 | 167 | public static function save_stats_extra($extra_name, $request, $runtime) |
168 | 168 | { |
169 | - self::save_stats("extra/".$extra_name, $request, $runtime); |
|
169 | + self::save_stats("extra/" . $extra_name, $request, $runtime); |
|
170 | 170 | } |
171 | 171 | |
172 | 172 | private static function save_stats($service_name, $request, $runtime) |
@@ -195,11 +195,11 @@ discard block |
||
195 | 195 | insert into okapi_stats_temp (`datetime`, consumer_key, user_id, service_name, calltype, runtime) |
196 | 196 | values ( |
197 | 197 | now(), |
198 | - '".Db::escape_string($consumer_key)."', |
|
199 | - '".Db::escape_string($user_id)."', |
|
200 | - '".Db::escape_string($service_name)."', |
|
201 | - '".Db::escape_string($calltype)."', |
|
202 | - '".Db::escape_string($runtime)."' |
|
198 | + '".Db::escape_string($consumer_key) . "', |
|
199 | + '".Db::escape_string($user_id) . "', |
|
200 | + '".Db::escape_string($service_name) . "', |
|
201 | + '".Db::escape_string($calltype) . "', |
|
202 | + '".Db::escape_string($runtime) . "' |
|
203 | 203 | ); |
204 | 204 | "); |
205 | 205 | } |
@@ -71,8 +71,9 @@ discard block |
||
71 | 71 | /** Get method options (is consumer required etc.). */ |
72 | 72 | public static function options($service_name) |
73 | 73 | { |
74 | - if (!self::exists($service_name)) |
|
75 | - throw new Exception(); |
|
74 | + if (!self::exists($service_name)) { |
|
75 | + throw new Exception(); |
|
76 | + } |
|
76 | 77 | require_once($GLOBALS['rootpath']."okapi/$service_name.php"); |
77 | 78 | try |
78 | 79 | { |
@@ -92,8 +93,9 @@ discard block |
||
92 | 93 | */ |
93 | 94 | public static function docs($service_name) |
94 | 95 | { |
95 | - if (!self::exists($service_name)) |
|
96 | - throw new Exception(); |
|
96 | + if (!self::exists($service_name)) { |
|
97 | + throw new Exception(); |
|
98 | + } |
|
97 | 99 | try { |
98 | 100 | return file_get_contents("$service_name.xml", true); |
99 | 101 | } catch (Exception $e) { |
@@ -114,8 +116,9 @@ discard block |
||
114 | 116 | { |
115 | 117 | Okapi::init_internals(); |
116 | 118 | |
117 | - if (!self::exists($service_name)) |
|
118 | - throw new Exception("Method does not exist: '$service_name'"); |
|
119 | + if (!self::exists($service_name)) { |
|
120 | + throw new Exception("Method does not exist: '$service_name'"); |
|
121 | + } |
|
119 | 122 | |
120 | 123 | $options = self::options($service_name); |
121 | 124 | if ($options['min_auth_level'] >= 2 && $request->consumer == null) |
@@ -178,18 +181,21 @@ discard block |
||
178 | 181 | if ($request !== null) { |
179 | 182 | $consumer_key = ($request->consumer != null) ? $request->consumer->key : 'anonymous'; |
180 | 183 | $user_id = (($request->token != null) && ($request->token instanceof OkapiAccessToken)) ? $request->token->user_id : -1; |
181 | - if ($request->is_http_request() && ($service_name[0] == 's')) # 's' for "services/", we don't want "extra/" included |
|
184 | + if ($request->is_http_request() && ($service_name[0] == 's')) { |
|
185 | + # 's' for "services/", we don't want "extra/" included |
|
182 | 186 | $calltype = 'http'; |
183 | - else |
|
184 | - $calltype = 'internal'; |
|
187 | + } else { |
|
188 | + $calltype = 'internal'; |
|
189 | + } |
|
185 | 190 | } else { |
186 | 191 | $consumer_key = 'internal'; |
187 | 192 | $user_id = -1; |
188 | 193 | $calltype = 'internal'; |
189 | 194 | } |
190 | 195 | |
191 | - if (Settings::get('OC_BRANCH') == 'oc.de' && $user_id != -1) |
|
192 | - $user_id = 0; |
|
196 | + if (Settings::get('OC_BRANCH') == 'oc.de' && $user_id != -1) { |
|
197 | + $user_id = 0; |
|
198 | + } |
|
193 | 199 | |
194 | 200 | Db::execute(" |
195 | 201 | insert into okapi_stats_temp (`datetime`, consumer_key, user_id, service_name, calltype, runtime) |
@@ -17,9 +17,9 @@ discard block |
||
17 | 17 | |
18 | 18 | $GLOBALS['rootpath'] = '../'; # this is for OC-code compatibility |
19 | 19 | |
20 | -require_once($GLOBALS['rootpath'].'okapi/core.php'); |
|
20 | +require_once($GLOBALS['rootpath'] . 'okapi/core.php'); |
|
21 | 21 | OkapiErrorHandler::$treat_notices_as_errors = true; |
22 | -require_once($GLOBALS['rootpath'].'okapi/urls.php'); |
|
22 | +require_once($GLOBALS['rootpath'] . 'okapi/urls.php'); |
|
23 | 23 | |
24 | 24 | if (ob_list_handlers() == array('default output handler')) |
25 | 25 | { |
@@ -72,9 +72,9 @@ discard block |
||
72 | 72 | # Pattern matched! Moving on to the proper View... |
73 | 73 | |
74 | 74 | array_shift($matches); |
75 | - require_once($GLOBALS['rootpath']."okapi/views/$namespace.php"); |
|
76 | - $response = call_user_func_array(array('\\okapi\\views\\'. |
|
77 | - str_replace('/', '\\', $namespace).'\\View', 'call'), $matches); |
|
75 | + require_once($GLOBALS['rootpath'] . "okapi/views/$namespace.php"); |
|
76 | + $response = call_user_func_array(array('\\okapi\\views\\' . |
|
77 | + str_replace('/', '\\', $namespace) . '\\View', 'call'), $matches); |
|
78 | 78 | if ($response) |
79 | 79 | $response->display(); |
80 | 80 | return; |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | |
89 | 89 | # None of the patterns matched OR method threw the Http404 exception. |
90 | 90 | |
91 | - require_once($GLOBALS['rootpath']."okapi/views/http404.php"); |
|
91 | + require_once($GLOBALS['rootpath'] . "okapi/views/http404.php"); |
|
92 | 92 | $response = \okapi\views\http404\View::call(); |
93 | 93 | $response->display(); |
94 | 94 | } |
@@ -37,20 +37,23 @@ discard block |
||
37 | 37 | { |
38 | 38 | # Chop off the ?args=... part. |
39 | 39 | |
40 | - if (strpos($uri, '?') !== false) |
|
41 | - $uri = substr($uri, 0, strpos($uri, '?')); |
|
40 | + if (strpos($uri, '?') !== false) { |
|
41 | + $uri = substr($uri, 0, strpos($uri, '?')); |
|
42 | + } |
|
42 | 43 | |
43 | 44 | # Chop off everything before "/okapi/". This should work for okay for most "weird" |
44 | 45 | # server configurations. It will also address a more subtle issue described here: |
45 | 46 | # http://stackoverflow.com/questions/8040461/request-uri-unexpectedly-contains-fqdn |
46 | 47 | |
47 | - if (strpos($uri, "/okapi/") !== false) |
|
48 | - $uri = substr($uri, strpos($uri, "/okapi/")); |
|
48 | + if (strpos($uri, "/okapi/") !== false) { |
|
49 | + $uri = substr($uri, strpos($uri, "/okapi/")); |
|
50 | + } |
|
49 | 51 | |
50 | 52 | # Make sure we're in the right directory (.htaccess should make sure of that). |
51 | 53 | |
52 | - if (strpos($uri, "/okapi/") !== 0) |
|
53 | - throw new Exception("'$uri' is outside of the /okapi/ path."); |
|
54 | + if (strpos($uri, "/okapi/") !== 0) { |
|
55 | + throw new Exception("'$uri' is outside of the /okapi/ path."); |
|
56 | + } |
|
54 | 57 | $uri = substr($uri, 7); |
55 | 58 | |
56 | 59 | # Initializing internals and running pre-request cronjobs (we don't want |
@@ -75,13 +78,13 @@ discard block |
||
75 | 78 | require_once($GLOBALS['rootpath']."okapi/views/$namespace.php"); |
76 | 79 | $response = call_user_func_array(array('\\okapi\\views\\'. |
77 | 80 | str_replace('/', '\\', $namespace).'\\View', 'call'), $matches); |
78 | - if ($response) |
|
79 | - $response->display(); |
|
81 | + if ($response) { |
|
82 | + $response->display(); |
|
83 | + } |
|
80 | 84 | return; |
81 | 85 | } |
82 | 86 | } |
83 | - } |
|
84 | - catch (Http404 $e) |
|
87 | + } catch (Http404 $e) |
|
85 | 88 | { |
86 | 89 | /* pass */ |
87 | 90 | } |