@@ -2,21 +2,11 @@ |
||
2 | 2 | |
3 | 3 | namespace okapi\services\caches\map; |
4 | 4 | |
5 | -use Exception; |
|
6 | -use okapi\Okapi; |
|
7 | -use okapi\Settings; |
|
8 | -use okapi\Cache; |
|
9 | 5 | use okapi\Db; |
10 | -use okapi\OkapiRequest; |
|
11 | -use okapi\OkapiHttpResponse; |
|
12 | -use okapi\ParamMissing; |
|
13 | 6 | use okapi\InvalidParam; |
14 | -use okapi\BadRequest; |
|
15 | -use okapi\DoesNotExist; |
|
16 | -use okapi\OkapiInternalRequest; |
|
17 | 7 | use okapi\OkapiInternalConsumer; |
8 | +use okapi\OkapiInternalRequest; |
|
18 | 9 | use okapi\OkapiServiceRunner; |
19 | - |
|
20 | 10 | use okapi\services\caches\map\TileTree; |
21 | 11 | |
22 | 12 | require_once 'tiletree.inc.php'; |
@@ -145,8 +145,8 @@ discard block |
||
145 | 145 | |
146 | 146 | $z21x = $row[1]; |
147 | 147 | $z21y = $row[2]; |
148 | - $ex = $z21x >> 8; # initially, z21x / <tile width> |
|
149 | - $ey = $z21y >> 8; # initially, z21y / <tile height> |
|
148 | + $ex = $z21x >> 8; # initially, z21x / <tile width> |
|
149 | + $ey = $z21y >> 8; # initially, z21y / <tile height> |
|
150 | 150 | for ($zoom = 21; $zoom >= 0; $zoom--, $ex >>= 1, $ey >>= 1) |
151 | 151 | { |
152 | 152 | # ($ex, $ey) points to the "exact match" tile. We need to determine |
@@ -154,9 +154,9 @@ discard block |
||
154 | 154 | # go with the simple approach and check all 1+8 bordering tiles. |
155 | 155 | |
156 | 156 | $tiles_in_this_region = array(); |
157 | - for ($x=$ex-1; $x<=$ex+1; $x++) |
|
158 | - for ($y=$ey-1; $y<=$ey+1; $y++) |
|
159 | - if (($x >= 0) && ($x < 1<<$zoom) && ($y >= 0) && ($y < 1<<$zoom)) |
|
157 | + for ($x = $ex - 1; $x <= $ex + 1; $x++) |
|
158 | + for ($y = $ey - 1; $y <= $ey + 1; $y++) |
|
159 | + if (($x >= 0) && ($x < 1 << $zoom) && ($y >= 0) && ($y < 1 << $zoom)) |
|
160 | 160 | $tiles_in_this_region[] = array($x, $y); |
161 | 161 | |
162 | 162 | foreach ($tiles_in_this_region as $coords) |
@@ -164,7 +164,7 @@ discard block |
||
164 | 164 | list($x, $y) = $coords; |
165 | 165 | |
166 | 166 | $scale = 8 + 21 - $zoom; |
167 | - $margin = 1 << ($scale - 3); # 32px of current $zoom level, measured in z21 pixels. |
|
167 | + $margin = 1 << ($scale - 3); # 32px of current $zoom level, measured in z21 pixels. |
|
168 | 168 | |
169 | 169 | $left_z21x = ($x << $scale) - $margin; |
170 | 170 | $right_z21x = (($x + 1) << $scale) + $margin; |
@@ -29,14 +29,13 @@ discard block |
||
29 | 29 | # changelog. The format of $changelog is described in the replicate module |
30 | 30 | # (NOT the entire response, just the "changelog" key). |
31 | 31 | |
32 | - foreach ($changelog as $c) |
|
33 | - { |
|
34 | - if ($c['object_type'] == 'geocache') |
|
35 | - { |
|
36 | - if ($c['change_type'] == 'replace') |
|
37 | - self::handle_geocache_replace($c); |
|
38 | - else |
|
39 | - self::handle_geocache_delete($c); |
|
32 | + foreach ($changelog as $c) { |
|
33 | + if ($c['object_type'] == 'geocache') { |
|
34 | + if ($c['change_type'] == 'replace') { |
|
35 | + self::handle_geocache_replace($c); |
|
36 | + } else { |
|
37 | + self::handle_geocache_delete($c); |
|
38 | + } |
|
40 | 39 | } |
41 | 40 | } |
42 | 41 | } |
@@ -90,25 +89,21 @@ discard block |
||
90 | 89 | # Compute the new row for okapi_tile_caches. Compare with the old one. |
91 | 90 | |
92 | 91 | $theirs = TileTree::generate_short_row($cache); |
93 | - if (!$ours) |
|
94 | - { |
|
92 | + if (!$ours) { |
|
95 | 93 | # Aaah, a new geocache! How nice... ;) |
96 | 94 | |
97 | 95 | self::add_geocache_to_cached_tiles($theirs); |
98 | - } |
|
99 | - elseif (($ours[1] != $theirs[1]) || ($ours[2] != $theirs[2])) # z21x & z21y fields |
|
96 | + } elseif (($ours[1] != $theirs[1]) || ($ours[2] != $theirs[2])) { |
|
97 | + # z21x & z21y fields |
|
100 | 98 | { |
101 | 99 | # Location changed. |
102 | 100 | |
103 | 101 | self::remove_geocache_from_cached_tiles($ours[0]); |
104 | - self::add_geocache_to_cached_tiles($theirs); |
|
105 | 102 | } |
106 | - elseif ($ours != $theirs) |
|
107 | - { |
|
103 | + self::add_geocache_to_cached_tiles($theirs); |
|
104 | + } elseif ($ours != $theirs) { |
|
108 | 105 | self::update_geocache_attributes_in_cached_tiles($theirs); |
109 | - } |
|
110 | - else |
|
111 | - { |
|
106 | + } else { |
|
112 | 107 | # No need to update anything. This is very common (i.e. when the |
113 | 108 | # cache was simply found, not actually changed). Replicate module generates |
114 | 109 | # many updates which do not influence our cache. |
@@ -147,20 +142,21 @@ discard block |
||
147 | 142 | $z21y = $row[2]; |
148 | 143 | $ex = $z21x >> 8; # initially, z21x / <tile width> |
149 | 144 | $ey = $z21y >> 8; # initially, z21y / <tile height> |
150 | - for ($zoom = 21; $zoom >= 0; $zoom--, $ex >>= 1, $ey >>= 1) |
|
151 | - { |
|
145 | + for ($zoom = 21; $zoom >= 0; $zoom--, $ex >>= 1, $ey >>= 1) { |
|
152 | 146 | # ($ex, $ey) points to the "exact match" tile. We need to determine |
153 | 147 | # tile-range to check for "just outside the border" tiles. We will |
154 | 148 | # go with the simple approach and check all 1+8 bordering tiles. |
155 | 149 | |
156 | 150 | $tiles_in_this_region = array(); |
157 | - for ($x=$ex-1; $x<=$ex+1; $x++) |
|
158 | - for ($y=$ey-1; $y<=$ey+1; $y++) |
|
159 | - if (($x >= 0) && ($x < 1<<$zoom) && ($y >= 0) && ($y < 1<<$zoom)) |
|
151 | + for ($x=$ex-1; $x<=$ex+1; $x++) { |
|
152 | + for ($y=$ey-1; |
|
153 | + } |
|
154 | + $y<=$ey+1; $y++) { |
|
155 | + if (($x >= 0) && ($x < 1<<$zoom) && ($y >= 0) && ($y < 1<<$zoom)) |
|
160 | 156 | $tiles_in_this_region[] = array($x, $y); |
157 | + } |
|
161 | 158 | |
162 | - foreach ($tiles_in_this_region as $coords) |
|
163 | - { |
|
159 | + foreach ($tiles_in_this_region as $coords) { |
|
164 | 160 | list($x, $y) = $coords; |
165 | 161 | |
166 | 162 | $scale = 8 + 21 - $zoom; |
@@ -171,14 +167,18 @@ discard block |
||
171 | 167 | $top_z21y = ($y << $scale) - $margin; |
172 | 168 | $bottom_z21y = (($y + 1) << $scale) + $margin; |
173 | 169 | |
174 | - if ($z21x < $left_z21x) |
|
175 | - continue; |
|
176 | - if ($z21x > $right_z21x) |
|
177 | - continue; |
|
178 | - if ($z21y < $top_z21y) |
|
179 | - continue; |
|
180 | - if ($z21y > $bottom_z21y) |
|
181 | - continue; |
|
170 | + if ($z21x < $left_z21x) { |
|
171 | + continue; |
|
172 | + } |
|
173 | + if ($z21x > $right_z21x) { |
|
174 | + continue; |
|
175 | + } |
|
176 | + if ($z21y < $top_z21y) { |
|
177 | + continue; |
|
178 | + } |
|
179 | + if ($z21y > $bottom_z21y) { |
|
180 | + continue; |
|
181 | + } |
|
182 | 182 | |
183 | 183 | # We found a match. Store it for later. |
184 | 184 | |
@@ -191,8 +191,7 @@ discard block |
||
191 | 191 | # only the cached ones. |
192 | 192 | |
193 | 193 | $alternatives_escaped = array(); |
194 | - foreach ($tiles_to_update as $coords) |
|
195 | - { |
|
194 | + foreach ($tiles_to_update as $coords) { |
|
196 | 195 | list($z, $x, $y) = $coords; |
197 | 196 | $alternatives_escaped[] = "( |
198 | 197 | z = '".Db::escape_string($z)."' |
@@ -200,8 +199,7 @@ discard block |
||
200 | 199 | and y = '".Db::escape_string($y)."' |
201 | 200 | )"; |
202 | 201 | } |
203 | - if (count($alternatives_escaped) > 0) |
|
204 | - { |
|
202 | + if (count($alternatives_escaped) > 0) { |
|
205 | 203 | Db::execute(" |
206 | 204 | replace into okapi_tile_caches ( |
207 | 205 | z, x, y, cache_id, z21x, z21y, status, type, rating, flags, name_crc |
@@ -2,15 +2,15 @@ |
||
2 | 2 | |
3 | 3 | namespace okapi\services\caches\search; |
4 | 4 | |
5 | -use okapi\Okapi; |
|
5 | +use Exception; |
|
6 | +use okapi\BadRequest; |
|
6 | 7 | use okapi\Db; |
8 | +use okapi\InvalidParam; |
|
9 | +use okapi\Okapi; |
|
7 | 10 | use okapi\OkapiInternalRequest; |
8 | -use okapi\OkapiServiceRunner; |
|
9 | 11 | use okapi\OkapiRequest; |
10 | -use okapi\InvalidParam; |
|
11 | -use okapi\BadRequest; |
|
12 | +use okapi\OkapiServiceRunner; |
|
12 | 13 | use okapi\Settings; |
13 | -use Exception; |
|
14 | 14 | |
15 | 15 | class SearchAssistant |
16 | 16 | { |
@@ -682,7 +682,7 @@ |
||
682 | 682 | # To avoid join errors, put each of the $where_conds in extra paranthesis. |
683 | 683 | |
684 | 684 | $tmp = array(); |
685 | - foreach($where_conds as $cond) |
|
685 | + foreach ($where_conds as $cond) |
|
686 | 686 | $tmp[] = "(".$cond.")"; |
687 | 687 | $where_conds = $tmp; |
688 | 688 | unset($tmp); |
@@ -95,8 +95,7 @@ discard block |
||
95 | 95 | # At the beginning we have to set up some "magic e$Xpressions". |
96 | 96 | # We will use them to make our query run on both OCPL and OCDE databases. |
97 | 97 | |
98 | - if (Settings::get('OC_BRANCH') == 'oc.pl') |
|
99 | - { |
|
98 | + if (Settings::get('OC_BRANCH') == 'oc.pl') { |
|
100 | 99 | # OCPL's 'caches' table contains some fields which OCDE's does not |
101 | 100 | # (topratings, founds, notfounds, last_found, votes, score). If |
102 | 101 | # we're being run on OCPL installation, we will simply use them. |
@@ -107,9 +106,7 @@ discard block |
||
107 | 106 | $X_LAST_FOUND = 'caches.last_found'; |
108 | 107 | $X_VOTES = 'caches.votes'; |
109 | 108 | $X_SCORE = 'caches.score'; |
110 | - } |
|
111 | - else |
|
112 | - { |
|
109 | + } else { |
|
113 | 110 | # OCDE holds this data in a separate table. Additionally, OCDE |
114 | 111 | # does not provide a rating system (votes and score fields). |
115 | 112 | # If we're being run on OCDE database, we will include this |
@@ -131,55 +128,44 @@ discard block |
||
131 | 128 | # type |
132 | 129 | # |
133 | 130 | |
134 | - if ($tmp = $this->request->get_parameter('type')) |
|
135 | - { |
|
131 | + if ($tmp = $this->request->get_parameter('type')) { |
|
136 | 132 | $operator = "in"; |
137 | - if ($tmp[0] == '-') |
|
138 | - { |
|
133 | + if ($tmp[0] == '-') { |
|
139 | 134 | $tmp = substr($tmp, 1); |
140 | 135 | $operator = "not in"; |
141 | 136 | } |
142 | 137 | $types = array(); |
143 | - foreach (explode("|", $tmp) as $name) |
|
144 | - { |
|
145 | - try |
|
146 | - { |
|
138 | + foreach (explode("|", $tmp) as $name) { |
|
139 | + try { |
|
147 | 140 | $id = Okapi::cache_type_name2id($name); |
148 | 141 | $types[] = $id; |
149 | - } |
|
150 | - catch (Exception $e) |
|
151 | - { |
|
142 | + } catch (Exception $e) { |
|
152 | 143 | throw new InvalidParam('type', "'$name' is not a valid cache type."); |
153 | 144 | } |
154 | 145 | } |
155 | - if (count($types) > 0) |
|
156 | - $where_conds[] = "caches.type $operator ('".implode("','", array_map('\okapi\Db::escape_string', $types))."')"; |
|
157 | - else if ($operator == "in") |
|
158 | - $where_conds[] = "false"; |
|
146 | + if (count($types) > 0) { |
|
147 | + $where_conds[] = "caches.type $operator ('".implode("','", array_map('\okapi\Db::escape_string', $types))."')"; |
|
148 | + } else if ($operator == "in") { |
|
149 | + $where_conds[] = "false"; |
|
150 | + } |
|
159 | 151 | } |
160 | 152 | |
161 | 153 | # |
162 | 154 | # size2 |
163 | 155 | # |
164 | 156 | |
165 | - if ($tmp = $this->request->get_parameter('size2')) |
|
166 | - { |
|
157 | + if ($tmp = $this->request->get_parameter('size2')) { |
|
167 | 158 | $operator = "in"; |
168 | - if ($tmp[0] == '-') |
|
169 | - { |
|
159 | + if ($tmp[0] == '-') { |
|
170 | 160 | $tmp = substr($tmp, 1); |
171 | 161 | $operator = "not in"; |
172 | 162 | } |
173 | 163 | $types = array(); |
174 | - foreach (explode("|", $tmp) as $name) |
|
175 | - { |
|
176 | - try |
|
177 | - { |
|
164 | + foreach (explode("|", $tmp) as $name) { |
|
165 | + try { |
|
178 | 166 | $id = Okapi::cache_size2_to_sizeid($name); |
179 | 167 | $types[] = $id; |
180 | - } |
|
181 | - catch (Exception $e) |
|
182 | - { |
|
168 | + } catch (Exception $e) { |
|
183 | 169 | throw new InvalidParam('size2', "'$name' is not a valid cache size."); |
184 | 170 | } |
185 | 171 | } |
@@ -191,16 +177,14 @@ discard block |
||
191 | 177 | # |
192 | 178 | |
193 | 179 | $tmp = $this->request->get_parameter('status'); |
194 | - if ($tmp == null) $tmp = "Available"; |
|
180 | + if ($tmp == null) { |
|
181 | + $tmp = "Available"; |
|
182 | + } |
|
195 | 183 | $codes = array(); |
196 | - foreach (explode("|", $tmp) as $name) |
|
197 | - { |
|
198 | - try |
|
199 | - { |
|
184 | + foreach (explode("|", $tmp) as $name) { |
|
185 | + try { |
|
200 | 186 | $codes[] = Okapi::cache_status_name2id($name); |
201 | - } |
|
202 | - catch (Exception $e) |
|
203 | - { |
|
187 | + } catch (Exception $e) { |
|
204 | 188 | throw new InvalidParam('status', "'$name' is not a valid cache status."); |
205 | 189 | } |
206 | 190 | } |
@@ -210,26 +194,23 @@ discard block |
||
210 | 194 | # owner_uuid |
211 | 195 | # |
212 | 196 | |
213 | - if ($tmp = $this->request->get_parameter('owner_uuid')) |
|
214 | - { |
|
197 | + if ($tmp = $this->request->get_parameter('owner_uuid')) { |
|
215 | 198 | $operator = "in"; |
216 | - if ($tmp[0] == '-') |
|
217 | - { |
|
199 | + if ($tmp[0] == '-') { |
|
218 | 200 | $tmp = substr($tmp, 1); |
219 | 201 | $operator = "not in"; |
220 | 202 | } |
221 | - try |
|
222 | - { |
|
203 | + try { |
|
223 | 204 | $users = OkapiServiceRunner::call("services/users/users", new OkapiInternalRequest( |
224 | 205 | $this->request->consumer, null, array('user_uuids' => $tmp, 'fields' => 'internal_id'))); |
225 | - } |
|
226 | - catch (InvalidParam $e) # invalid uuid |
|
206 | + } catch (InvalidParam $e) # invalid uuid |
|
227 | 207 | { |
228 | 208 | throw new InvalidParam('owner_uuid', $e->whats_wrong_about_it); |
229 | 209 | } |
230 | 210 | $user_ids = array(); |
231 | - foreach ($users as $user) |
|
232 | - $user_ids[] = $user['internal_id']; |
|
211 | + foreach ($users as $user) { |
|
212 | + $user_ids[] = $user['internal_id']; |
|
213 | + } |
|
233 | 214 | $where_conds[] = "caches.user_id $operator ('".implode("','", array_map('\okapi\Db::escape_string', $user_ids))."')"; |
234 | 215 | } |
235 | 216 | |
@@ -237,27 +218,26 @@ discard block |
||
237 | 218 | # terrain, difficulty, size, rating - these are similar, we'll do them in a loop |
238 | 219 | # |
239 | 220 | |
240 | - foreach (array('terrain', 'difficulty', 'size', 'rating') as $param_name) |
|
241 | - { |
|
242 | - if ($tmp = $this->request->get_parameter($param_name)) |
|
243 | - { |
|
244 | - if (!preg_match("/^[1-5]-[1-5](\|X)?$/", $tmp)) |
|
245 | - throw new InvalidParam($param_name, "'$tmp'"); |
|
221 | + foreach (array('terrain', 'difficulty', 'size', 'rating') as $param_name) { |
|
222 | + if ($tmp = $this->request->get_parameter($param_name)) { |
|
223 | + if (!preg_match("/^[1-5]-[1-5](\|X)?$/", $tmp)) { |
|
224 | + throw new InvalidParam($param_name, "'$tmp'"); |
|
225 | + } |
|
246 | 226 | list($min, $max) = explode("-", $tmp); |
247 | - if (strpos($max, "|X") !== false) |
|
248 | - { |
|
227 | + if (strpos($max, "|X") !== false) { |
|
249 | 228 | $max = $max[0]; |
250 | 229 | $allow_null = true; |
251 | 230 | } else { |
252 | 231 | $allow_null = false; |
253 | 232 | } |
254 | - if ($min > $max) |
|
255 | - throw new InvalidParam($param_name, "'$tmp'"); |
|
256 | - switch ($param_name) |
|
257 | - { |
|
233 | + if ($min > $max) { |
|
234 | + throw new InvalidParam($param_name, "'$tmp'"); |
|
235 | + } |
|
236 | + switch ($param_name) { |
|
258 | 237 | case 'terrain': |
259 | - if ($allow_null) |
|
260 | - throw new InvalidParam($param_name, "The '|X' suffix is not allowed here."); |
|
238 | + if ($allow_null) { |
|
239 | + throw new InvalidParam($param_name, "The '|X' suffix is not allowed here."); |
|
240 | + } |
|
261 | 241 | if (($min == 1) && ($max == 5)) { |
262 | 242 | /* no extra condition necessary */ |
263 | 243 | } else { |
@@ -265,8 +245,9 @@ discard block |
||
265 | 245 | } |
266 | 246 | break; |
267 | 247 | case 'difficulty': |
268 | - if ($allow_null) |
|
269 | - throw new InvalidParam($param_name, "The '|X' suffix is not allowed here."); |
|
248 | + if ($allow_null) { |
|
249 | + throw new InvalidParam($param_name, "The '|X' suffix is not allowed here."); |
|
250 | + } |
|
270 | 251 | if (($min == 1) && ($max == 5)) { |
271 | 252 | /* no extra condition necessary */ |
272 | 253 | } else { |
@@ -288,8 +269,7 @@ discard block |
||
288 | 269 | } |
289 | 270 | break; |
290 | 271 | case 'rating': |
291 | - if (Settings::get('OC_BRANCH') == 'oc.pl') |
|
292 | - { |
|
272 | + if (Settings::get('OC_BRANCH') == 'oc.pl') { |
|
293 | 273 | if (($min == 1) && ($max == 5) && $allow_null) { |
294 | 274 | /* no extra condition necessary */ |
295 | 275 | } else { |
@@ -299,9 +279,7 @@ discard block |
||
299 | 279 | $where_conds[] = "($X_SCORE >= $min and $X_SCORE < $max and $X_VOTES >= 3)". |
300 | 280 | ($allow_null ? " or ($X_VOTES < 3)" : ""); |
301 | 281 | } |
302 | - } |
|
303 | - else |
|
304 | - { |
|
282 | + } else { |
|
305 | 283 | # OCDE does not support rating. We will ignore this parameter. |
306 | 284 | } |
307 | 285 | break; |
@@ -313,22 +291,23 @@ discard block |
||
313 | 291 | # min_rcmds |
314 | 292 | # |
315 | 293 | |
316 | - if ($tmp = $this->request->get_parameter('min_rcmds')) |
|
317 | - { |
|
318 | - if ($tmp[strlen($tmp) - 1] == '%') |
|
319 | - { |
|
294 | + if ($tmp = $this->request->get_parameter('min_rcmds')) { |
|
295 | + if ($tmp[strlen($tmp) - 1] == '%') { |
|
320 | 296 | $tmp = substr($tmp, 0, strlen($tmp) - 1); |
321 | - if (!is_numeric($tmp)) |
|
322 | - throw new InvalidParam('min_rcmds', "'$tmp'"); |
|
297 | + if (!is_numeric($tmp)) { |
|
298 | + throw new InvalidParam('min_rcmds', "'$tmp'"); |
|
299 | + } |
|
323 | 300 | $tmp = intval($tmp); |
324 | - if ($tmp > 100 || $tmp < 0) |
|
325 | - throw new InvalidParam('min_rcmds', "'$tmp'"); |
|
301 | + if ($tmp > 100 || $tmp < 0) { |
|
302 | + throw new InvalidParam('min_rcmds', "'$tmp'"); |
|
303 | + } |
|
326 | 304 | $tmp = floatval($tmp) / 100.0; |
327 | 305 | $where_conds[] = "$X_TOPRATINGS >= $X_FOUNDS * '".Db::escape_string($tmp)."'"; |
328 | 306 | $where_conds[] = "$X_FOUNDS > 0"; |
329 | 307 | } |
330 | - if (!is_numeric($tmp)) |
|
331 | - throw new InvalidParam('min_rcmds', "'$tmp'"); |
|
308 | + if (!is_numeric($tmp)) { |
|
309 | + throw new InvalidParam('min_rcmds', "'$tmp'"); |
|
310 | + } |
|
332 | 311 | $where_conds[] = "$X_TOPRATINGS >= '".Db::escape_string($tmp)."'"; |
333 | 312 | } |
334 | 313 | |
@@ -336,10 +315,10 @@ discard block |
||
336 | 315 | # min_founds |
337 | 316 | # |
338 | 317 | |
339 | - if ($tmp = $this->request->get_parameter('min_founds')) |
|
340 | - { |
|
341 | - if (!is_numeric($tmp)) |
|
342 | - throw new InvalidParam('min_founds', "'$tmp'"); |
|
318 | + if ($tmp = $this->request->get_parameter('min_founds')) { |
|
319 | + if (!is_numeric($tmp)) { |
|
320 | + throw new InvalidParam('min_founds', "'$tmp'"); |
|
321 | + } |
|
343 | 322 | $where_conds[] = "$X_FOUNDS >= '".Db::escape_string($tmp)."'"; |
344 | 323 | } |
345 | 324 | |
@@ -348,10 +327,10 @@ discard block |
||
348 | 327 | # may be '0' for FTF hunts |
349 | 328 | # |
350 | 329 | |
351 | - if (!is_null($tmp = $this->request->get_parameter('max_founds'))) |
|
352 | - { |
|
353 | - if (!is_numeric($tmp)) |
|
354 | - throw new InvalidParam('max_founds', "'$tmp'"); |
|
330 | + if (!is_null($tmp = $this->request->get_parameter('max_founds'))) { |
|
331 | + if (!is_numeric($tmp)) { |
|
332 | + throw new InvalidParam('max_founds', "'$tmp'"); |
|
333 | + } |
|
355 | 334 | $where_conds[] = "$X_FOUNDS <= '".Db::escape_string($tmp)."'"; |
356 | 335 | } |
357 | 336 | |
@@ -359,27 +338,27 @@ discard block |
||
359 | 338 | # modified_since |
360 | 339 | # |
361 | 340 | |
362 | - if ($tmp = $this->request->get_parameter('modified_since')) |
|
363 | - { |
|
341 | + if ($tmp = $this->request->get_parameter('modified_since')) { |
|
364 | 342 | $timestamp = strtotime($tmp); |
365 | - if ($timestamp) |
|
366 | - $where_conds[] = "unix_timestamp(caches.last_modified) > '".Db::escape_string($timestamp)."'"; |
|
367 | - else |
|
368 | - throw new InvalidParam('modified_since', "'$tmp' is not in a valid format or is not a valid date."); |
|
343 | + if ($timestamp) { |
|
344 | + $where_conds[] = "unix_timestamp(caches.last_modified) > '".Db::escape_string($timestamp)."'"; |
|
345 | + } else { |
|
346 | + throw new InvalidParam('modified_since', "'$tmp' is not in a valid format or is not a valid date."); |
|
347 | + } |
|
369 | 348 | } |
370 | 349 | |
371 | 350 | # |
372 | 351 | # found_status |
373 | 352 | # |
374 | 353 | |
375 | - if ($tmp = $this->request->get_parameter('found_status')) |
|
376 | - { |
|
377 | - if ($this->request->token == null) |
|
378 | - throw new InvalidParam('found_status', "Might be used only for requests signed with an Access Token."); |
|
379 | - if (!in_array($tmp, array('found_only', 'notfound_only', 'either'))) |
|
380 | - throw new InvalidParam('found_status', "'$tmp'"); |
|
381 | - if ($tmp != 'either') |
|
382 | - { |
|
354 | + if ($tmp = $this->request->get_parameter('found_status')) { |
|
355 | + if ($this->request->token == null) { |
|
356 | + throw new InvalidParam('found_status', "Might be used only for requests signed with an Access Token."); |
|
357 | + } |
|
358 | + if (!in_array($tmp, array('found_only', 'notfound_only', 'either'))) { |
|
359 | + throw new InvalidParam('found_status', "'$tmp'"); |
|
360 | + } |
|
361 | + if ($tmp != 'either') { |
|
383 | 362 | $found_cache_ids = self::get_found_cache_ids(array($this->request->token->user_id)); |
384 | 363 | $operator = ($tmp == 'found_only') ? "in" : "not in"; |
385 | 364 | $where_conds[] = "caches.cache_id $operator ('".implode("','", array_map('\okapi\Db::escape_string', $found_cache_ids))."')"; |
@@ -390,12 +369,12 @@ discard block |
||
390 | 369 | # found_by |
391 | 370 | # |
392 | 371 | |
393 | - if ($tmp = $this->request->get_parameter('found_by')) |
|
394 | - { |
|
372 | + if ($tmp = $this->request->get_parameter('found_by')) { |
|
395 | 373 | try { |
396 | 374 | $users = OkapiServiceRunner::call("services/users/users", new OkapiInternalRequest( |
397 | 375 | $this->request->consumer, null, array('user_uuids' => $tmp, 'fields' => 'internal_id'))); |
398 | - } catch (InvalidParam $e) { # invalid uuid |
|
376 | + } catch (InvalidParam $e) { |
|
377 | +# invalid uuid |
|
399 | 378 | throw new InvalidParam('found_by', $e->whats_wrong_about_it); |
400 | 379 | } |
401 | 380 | $internal_user_ids = array_map(create_function('$user', 'return $user["internal_id"];'), $users); |
@@ -407,12 +386,12 @@ discard block |
||
407 | 386 | # not_found_by |
408 | 387 | # |
409 | 388 | |
410 | - if ($tmp = $this->request->get_parameter('not_found_by')) |
|
411 | - { |
|
389 | + if ($tmp = $this->request->get_parameter('not_found_by')) { |
|
412 | 390 | try { |
413 | 391 | $users = OkapiServiceRunner::call("services/users/users", new OkapiInternalRequest( |
414 | 392 | $this->request->consumer, null, array('user_uuids' => $tmp, 'fields' => 'internal_id'))); |
415 | - } catch (InvalidParam $e) { # invalid uuid |
|
393 | + } catch (InvalidParam $e) { |
|
394 | +# invalid uuid |
|
416 | 395 | throw new InvalidParam('not_found_by', $e->whats_wrong_about_it); |
417 | 396 | } |
418 | 397 | $internal_user_ids = array_map(create_function('$user', 'return $user["internal_id"];'), $users); |
@@ -424,21 +403,20 @@ discard block |
||
424 | 403 | # watched_only |
425 | 404 | # |
426 | 405 | |
427 | - if ($tmp = $this->request->get_parameter('watched_only')) |
|
428 | - { |
|
429 | - if ($this->request->token == null) |
|
430 | - throw new InvalidParam('watched_only', "Might be used only for requests signed with an Access Token."); |
|
431 | - if (!in_array($tmp, array('true', 'false'))) |
|
432 | - throw new InvalidParam('watched_only', "'$tmp'"); |
|
433 | - if ($tmp == 'true') |
|
434 | - { |
|
406 | + if ($tmp = $this->request->get_parameter('watched_only')) { |
|
407 | + if ($this->request->token == null) { |
|
408 | + throw new InvalidParam('watched_only', "Might be used only for requests signed with an Access Token."); |
|
409 | + } |
|
410 | + if (!in_array($tmp, array('true', 'false'))) { |
|
411 | + throw new InvalidParam('watched_only', "'$tmp'"); |
|
412 | + } |
|
413 | + if ($tmp == 'true') { |
|
435 | 414 | $watched_cache_ids = Db::select_column(" |
436 | 415 | select cache_id |
437 | 416 | from cache_watches |
438 | 417 | where user_id = '".Db::escape_string($this->request->token->user_id)."' |
439 | 418 | "); |
440 | - if (Settings::get('OC_BRANCH') == 'oc.de') |
|
441 | - { |
|
419 | + if (Settings::get('OC_BRANCH') == 'oc.de') { |
|
442 | 420 | $watched_cache_ids = array_merge($watched_cache_ids, Db::select_column(" |
443 | 421 | select cache_id |
444 | 422 | from cache_list_items cli, cache_list_watches clw |
@@ -455,33 +433,35 @@ discard block |
||
455 | 433 | # |
456 | 434 | |
457 | 435 | $ignored_status = 'either'; |
458 | - if ($tmp = $this->request->get_parameter('exclude_ignored')) |
|
459 | - { |
|
460 | - if ($this->request->token == null) |
|
461 | - throw new InvalidParam('exclude_ignored', "Might be used only for requests signed with an Access Token."); |
|
462 | - if ($tmp == 'true') |
|
463 | - $ignored_status = 'notignored_only'; |
|
464 | - elseif ($tmp != 'false') |
|
465 | - throw new InvalidParam('exclude_ignored', "'$tmp'"); |
|
466 | - } |
|
467 | - if ($tmp = $this->request->get_parameter('ignored_status')) |
|
468 | - { |
|
469 | - if ($this->request->token == null) |
|
470 | - throw new InvalidParam('ignored_status', "Might be used only for requests signed with an Access Token."); |
|
471 | - if (!in_array($tmp, array('ignored_only', 'notignored_only', 'either'))) |
|
472 | - throw new InvalidParam('ignored_status', "'$tmp'"); |
|
436 | + if ($tmp = $this->request->get_parameter('exclude_ignored')) { |
|
437 | + if ($this->request->token == null) { |
|
438 | + throw new InvalidParam('exclude_ignored', "Might be used only for requests signed with an Access Token."); |
|
439 | + } |
|
440 | + if ($tmp == 'true') { |
|
441 | + $ignored_status = 'notignored_only'; |
|
442 | + } elseif ($tmp != 'false') { |
|
443 | + throw new InvalidParam('exclude_ignored', "'$tmp'"); |
|
444 | + } |
|
445 | + } |
|
446 | + if ($tmp = $this->request->get_parameter('ignored_status')) { |
|
447 | + if ($this->request->token == null) { |
|
448 | + throw new InvalidParam('ignored_status', "Might be used only for requests signed with an Access Token."); |
|
449 | + } |
|
450 | + if (!in_array($tmp, array('ignored_only', 'notignored_only', 'either'))) { |
|
451 | + throw new InvalidParam('ignored_status', "'$tmp'"); |
|
452 | + } |
|
473 | 453 | if ($tmp != 'either') { |
474 | - if ($tmp == 'ignored_only' && $ignored_status == 'notignored_only') |
|
475 | - $ignored_status = 'none'; |
|
476 | - else |
|
477 | - $ignored_status = $tmp; |
|
454 | + if ($tmp == 'ignored_only' && $ignored_status == 'notignored_only') { |
|
455 | + $ignored_status = 'none'; |
|
456 | + } else { |
|
457 | + $ignored_status = $tmp; |
|
458 | + } |
|
478 | 459 | } |
479 | 460 | } |
480 | 461 | |
481 | - if ($ignored_status == 'none') |
|
482 | - $where_conds[] = 'false'; |
|
483 | - elseif ($ignored_status != 'either') |
|
484 | - { |
|
462 | + if ($ignored_status == 'none') { |
|
463 | + $where_conds[] = 'false'; |
|
464 | + } elseif ($ignored_status != 'either') { |
|
485 | 465 | $ignored_cache_ids = Db::select_column(" |
486 | 466 | select cache_id |
487 | 467 | from cache_ignore |
@@ -495,27 +475,29 @@ discard block |
||
495 | 475 | # exclude_my_own |
496 | 476 | # |
497 | 477 | |
498 | - if ($tmp = $this->request->get_parameter('exclude_my_own')) |
|
499 | - { |
|
500 | - if ($this->request->token == null) |
|
501 | - throw new InvalidParam('exclude_my_own', "Might be used only for requests signed with an Access Token."); |
|
502 | - if (!in_array($tmp, array('true', 'false'))) |
|
503 | - throw new InvalidParam('exclude_my_own', "'$tmp'"); |
|
504 | - if ($tmp == 'true') |
|
505 | - $where_conds[] = "caches.user_id != '".Db::escape_string($this->request->token->user_id)."'"; |
|
478 | + if ($tmp = $this->request->get_parameter('exclude_my_own')) { |
|
479 | + if ($this->request->token == null) { |
|
480 | + throw new InvalidParam('exclude_my_own', "Might be used only for requests signed with an Access Token."); |
|
481 | + } |
|
482 | + if (!in_array($tmp, array('true', 'false'))) { |
|
483 | + throw new InvalidParam('exclude_my_own', "'$tmp'"); |
|
484 | + } |
|
485 | + if ($tmp == 'true') { |
|
486 | + $where_conds[] = "caches.user_id != '".Db::escape_string($this->request->token->user_id)."'"; |
|
487 | + } |
|
506 | 488 | } |
507 | 489 | |
508 | 490 | # |
509 | 491 | # name |
510 | 492 | # |
511 | 493 | |
512 | - if ($tmp = $this->request->get_parameter('name')) |
|
513 | - { |
|
494 | + if ($tmp = $this->request->get_parameter('name')) { |
|
514 | 495 | # WRTODO: Make this more user-friendly. See: |
515 | 496 | # https://github.com/opencaching/okapi/issues/121 |
516 | 497 | |
517 | - if (strlen($tmp) > 100) |
|
518 | - throw new InvalidParam('name', "Maximum length of 'name' parameter is 100 characters"); |
|
498 | + if (strlen($tmp) > 100) { |
|
499 | + throw new InvalidParam('name', "Maximum length of 'name' parameter is 100 characters"); |
|
500 | + } |
|
519 | 501 | $tmp = str_replace("*", "%", str_replace("%", "%%", $tmp)); |
520 | 502 | $where_conds[] = "caches.name LIKE '".Db::escape_string($tmp)."'"; |
521 | 503 | } |
@@ -524,12 +506,11 @@ discard block |
||
524 | 506 | # with_trackables_only |
525 | 507 | # |
526 | 508 | |
527 | - if ($tmp = $this->request->get_parameter('with_trackables_only')) |
|
528 | - { |
|
529 | - if (!in_array($tmp, array('true', 'false'), 1)) |
|
530 | - throw new InvalidParam('with_trackables_only', "'$tmp'"); |
|
531 | - if ($tmp == 'true') |
|
532 | - { |
|
509 | + if ($tmp = $this->request->get_parameter('with_trackables_only')) { |
|
510 | + if (!in_array($tmp, array('true', 'false'), 1)) { |
|
511 | + throw new InvalidParam('with_trackables_only', "'$tmp'"); |
|
512 | + } |
|
513 | + if ($tmp == 'true') { |
|
533 | 514 | $where_conds[] = " |
534 | 515 | caches.wp_oc in ( |
535 | 516 | select distinct wp |
@@ -543,12 +524,11 @@ discard block |
||
543 | 524 | # ftf_hunter |
544 | 525 | # |
545 | 526 | |
546 | - if ($tmp = $this->request->get_parameter('ftf_hunter')) |
|
547 | - { |
|
548 | - if (!in_array($tmp, array('true', 'false'), 1)) |
|
549 | - throw new InvalidParam('ftf_hunter', "'$tmp'"); |
|
550 | - if ($tmp == 'true') |
|
551 | - { |
|
527 | + if ($tmp = $this->request->get_parameter('ftf_hunter')) { |
|
528 | + if (!in_array($tmp, array('true', 'false'), 1)) { |
|
529 | + throw new InvalidParam('ftf_hunter', "'$tmp'"); |
|
530 | + } |
|
531 | + if ($tmp == 'true') { |
|
552 | 532 | $where_conds[] = "$X_FOUNDS = 0"; |
553 | 533 | } |
554 | 534 | } |
@@ -558,8 +538,7 @@ discard block |
||
558 | 538 | # |
559 | 539 | |
560 | 540 | $join_powertrails = false; |
561 | - if ($tmp = $this->request->get_parameter('powertrail_only')) |
|
562 | - { |
|
541 | + if ($tmp = $this->request->get_parameter('powertrail_only')) { |
|
563 | 542 | if ($tmp === 'true') { |
564 | 543 | $join_powertrails = true; |
565 | 544 | } elseif ($tmp === 'false') { |
@@ -594,8 +573,7 @@ discard block |
||
594 | 573 | # set_and |
595 | 574 | # |
596 | 575 | |
597 | - if ($tmp = $this->request->get_parameter('set_and')) |
|
598 | - { |
|
576 | + if ($tmp = $this->request->get_parameter('set_and')) { |
|
599 | 577 | # Check if the set exists. |
600 | 578 | |
601 | 579 | $exists = Db::select_value(" |
@@ -603,8 +581,9 @@ discard block |
||
603 | 581 | from okapi_search_sets |
604 | 582 | where id = '".Db::escape_string($tmp)."' |
605 | 583 | "); |
606 | - if (!$exists) |
|
607 | - throw new InvalidParam('set_and', "Couldn't find a set by given ID."); |
|
584 | + if (!$exists) { |
|
585 | + throw new InvalidParam('set_and', "Couldn't find a set by given ID."); |
|
586 | + } |
|
608 | 587 | $extra_tables[] = "okapi_search_results osr_and"; |
609 | 588 | $where_conds[] = "osr_and.cache_id = caches.cache_id"; |
610 | 589 | $where_conds[] = "osr_and.set_id = '".Db::escape_string($tmp)."'"; |
@@ -615,34 +594,43 @@ discard block |
||
615 | 594 | # |
616 | 595 | |
617 | 596 | $limit = $this->request->get_parameter('limit'); |
618 | - if ($limit == null) $limit = "100"; |
|
619 | - if (!is_numeric($limit)) |
|
620 | - throw new InvalidParam('limit', "'$limit'"); |
|
621 | - if ($limit < 1 || (($limit > 500) && (!$this->request->skip_limits))) |
|
622 | - throw new InvalidParam( |
|
597 | + if ($limit == null) { |
|
598 | + $limit = "100"; |
|
599 | + } |
|
600 | + if (!is_numeric($limit)) { |
|
601 | + throw new InvalidParam('limit', "'$limit'"); |
|
602 | + } |
|
603 | + if ($limit < 1 || (($limit > 500) && (!$this->request->skip_limits))) { |
|
604 | + throw new InvalidParam( |
|
623 | 605 | 'limit', |
624 | 606 | $this->request->skip_limits |
625 | 607 | ? "Cannot be lower than 1." |
626 | 608 | : "Has to be between 1 and 500." |
627 | 609 | ); |
610 | + } |
|
628 | 611 | |
629 | 612 | # |
630 | 613 | # offset |
631 | 614 | # |
632 | 615 | |
633 | 616 | $offset = $this->request->get_parameter('offset'); |
634 | - if ($offset == null) $offset = "0"; |
|
635 | - if (!is_numeric($offset)) |
|
636 | - throw new InvalidParam('offset', "'$offset'"); |
|
637 | - if (($offset + $limit > 500) && (!$this->request->skip_limits)) |
|
638 | - throw new BadRequest("The sum of offset and limit may not exceed 500."); |
|
639 | - if ($offset < 0 || (($offset > 499) && (!$this->request->skip_limits))) |
|
640 | - throw new InvalidParam( |
|
617 | + if ($offset == null) { |
|
618 | + $offset = "0"; |
|
619 | + } |
|
620 | + if (!is_numeric($offset)) { |
|
621 | + throw new InvalidParam('offset', "'$offset'"); |
|
622 | + } |
|
623 | + if (($offset + $limit > 500) && (!$this->request->skip_limits)) { |
|
624 | + throw new BadRequest("The sum of offset and limit may not exceed 500."); |
|
625 | + } |
|
626 | + if ($offset < 0 || (($offset > 499) && (!$this->request->skip_limits))) { |
|
627 | + throw new InvalidParam( |
|
641 | 628 | 'offset', |
642 | 629 | $this->request->skip_limits |
643 | 630 | ? "Cannot be lower than 0." |
644 | 631 | : "Has to be between 0 and 499." |
645 | 632 | ); |
633 | + } |
|
646 | 634 | |
647 | 635 | # |
648 | 636 | # order_by |
@@ -650,21 +638,18 @@ discard block |
||
650 | 638 | |
651 | 639 | $order_clauses = array(); |
652 | 640 | $order_by = $this->request->get_parameter('order_by'); |
653 | - if ($order_by != null) |
|
654 | - { |
|
641 | + if ($order_by != null) { |
|
655 | 642 | $order_by = explode('|', $order_by); |
656 | - foreach ($order_by as $field) |
|
657 | - { |
|
643 | + foreach ($order_by as $field) { |
|
658 | 644 | $dir = 'asc'; |
659 | - if ($field[0] == '-') |
|
660 | - { |
|
645 | + if ($field[0] == '-') { |
|
661 | 646 | $dir = 'desc'; |
662 | 647 | $field = substr($field, 1); |
648 | + } elseif ($field[0] == '+') { |
|
649 | + $field = substr($field, 1); |
|
663 | 650 | } |
664 | - elseif ($field[0] == '+') |
|
665 | - $field = substr($field, 1); # ignore leading "+" |
|
666 | - switch ($field) |
|
667 | - { |
|
651 | + # ignore leading "+" |
|
652 | + switch ($field) { |
|
668 | 653 | case 'code': $cl = "caches.wp_oc"; break; |
669 | 654 | case 'name': $cl = "caches.name"; break; |
670 | 655 | case 'founds': $cl = "$X_FOUNDS"; break; |
@@ -682,8 +667,9 @@ discard block |
||
682 | 667 | # To avoid join errors, put each of the $where_conds in extra paranthesis. |
683 | 668 | |
684 | 669 | $tmp = array(); |
685 | - foreach($where_conds as $cond) |
|
686 | - $tmp[] = "(".$cond.")"; |
|
670 | + foreach($where_conds as $cond) { |
|
671 | + $tmp[] = "(".$cond.")"; |
|
672 | + } |
|
687 | 673 | $where_conds = $tmp; |
688 | 674 | unset($tmp); |
689 | 675 | |
@@ -697,8 +683,7 @@ discard block |
||
697 | 683 | 'extra_joins' => $extra_joins, |
698 | 684 | ); |
699 | 685 | |
700 | - if ($this->search_params === NULL) |
|
701 | - { |
|
686 | + if ($this->search_params === NULL) { |
|
702 | 687 | $this->search_params = $ret_array; |
703 | 688 | } else { |
704 | 689 | $this->search_params = array_merge_recursive($this->search_params, $ret_array); |
@@ -738,8 +723,7 @@ discard block |
||
738 | 723 | limit ".($this->search_params['offset']).", ".($this->search_params['limit'] + 1)."; |
739 | 724 | "); |
740 | 725 | |
741 | - if (count($cache_codes) > $this->search_params['limit']) |
|
742 | - { |
|
726 | + if (count($cache_codes) > $this->search_params['limit']) { |
|
743 | 727 | $more = true; |
744 | 728 | array_pop($cache_codes); # get rid of the one above the limit |
745 | 729 | } else { |
@@ -767,18 +751,17 @@ discard block |
||
767 | 751 | public function prepare_location_search_params() |
768 | 752 | { |
769 | 753 | $location_source = $this->request->get_parameter('location_source'); |
770 | - if (!$location_source) |
|
771 | - $location_source = 'default-coords'; |
|
754 | + if (!$location_source) { |
|
755 | + $location_source = 'default-coords'; |
|
756 | + } |
|
772 | 757 | |
773 | 758 | # Make sure location_source has prefix alt_wpt: |
774 | - if ($location_source != 'default-coords' && strncmp($location_source, 'alt_wpt:', 8) != 0) |
|
775 | - { |
|
759 | + if ($location_source != 'default-coords' && strncmp($location_source, 'alt_wpt:', 8) != 0) { |
|
776 | 760 | throw new InvalidParam('location_source', '\''.$location_source.'\''); |
777 | 761 | } |
778 | 762 | |
779 | 763 | # Make sure we have sufficient authorization |
780 | - if ($location_source == 'alt_wpt:user-coords' && $this->request->token == null) |
|
781 | - { |
|
764 | + if ($location_source == 'alt_wpt:user-coords' && $this->request->token == null) { |
|
782 | 765 | throw new BadRequest("Level 3 Authentication is required to access 'alt_wpt:user-coords'."); |
783 | 766 | } |
784 | 767 | |
@@ -787,14 +770,12 @@ discard block |
||
787 | 770 | $location_source = 'default-coords'; |
788 | 771 | } |
789 | 772 | |
790 | - if ($location_source == 'default-coords') |
|
791 | - { |
|
773 | + if ($location_source == 'default-coords') { |
|
792 | 774 | $this->longitude_expr = 'caches.longitude'; |
793 | 775 | $this->latitude_expr = 'caches.latitude'; |
794 | 776 | } else { |
795 | 777 | $extra_joins = null; |
796 | - if (Settings::get('OC_BRANCH') == 'oc.pl') |
|
797 | - { |
|
778 | + if (Settings::get('OC_BRANCH') == 'oc.pl') { |
|
798 | 779 | $this->longitude_expr = 'ifnull(cache_mod_cords.longitude, caches.longitude)'; |
799 | 780 | $this->latitude_expr = 'ifnull(cache_mod_cords.latitude, caches.latitude)'; |
800 | 781 | $extra_joins = array(" |
@@ -818,8 +799,7 @@ discard block |
||
818 | 799 | $location_extra_sql = array( |
819 | 800 | 'extra_joins' => $extra_joins |
820 | 801 | ); |
821 | - if ($this->search_params === NULL) |
|
822 | - { |
|
802 | + if ($this->search_params === NULL) { |
|
823 | 803 | $this->search_params = $location_extra_sql; |
824 | 804 | } else { |
825 | 805 | $this->search_params = array_merge_recursive($this->search_params, $location_extra_sql); |
@@ -26,10 +26,10 @@ discard block |
||
26 | 26 | public function __construct(OkapiRequest $request) |
27 | 27 | { |
28 | 28 | $this->request = $request; |
29 | - $this->longitude_expr = NULL; |
|
30 | - $this->latitude_expr = NULL; |
|
31 | - $this->location_extra_sql = NULL; |
|
32 | - $this->search_params = NULL; |
|
29 | + $this->longitude_expr = null; |
|
30 | + $this->latitude_expr = null; |
|
31 | + $this->location_extra_sql = null; |
|
32 | + $this->search_params = null; |
|
33 | 33 | } |
34 | 34 | |
35 | 35 | /** |
@@ -697,7 +697,7 @@ discard block |
||
697 | 697 | 'extra_joins' => $extra_joins, |
698 | 698 | ); |
699 | 699 | |
700 | - if ($this->search_params === NULL) |
|
700 | + if ($this->search_params === null) |
|
701 | 701 | { |
702 | 702 | $this->search_params = $ret_array; |
703 | 703 | } else { |
@@ -818,7 +818,7 @@ discard block |
||
818 | 818 | $location_extra_sql = array( |
819 | 819 | 'extra_joins' => $extra_joins |
820 | 820 | ); |
821 | - if ($this->search_params === NULL) |
|
821 | + if ($this->search_params === null) |
|
822 | 822 | { |
823 | 823 | $this->search_params = $location_extra_sql; |
824 | 824 | } else { |
@@ -2,9 +2,8 @@ |
||
2 | 2 | |
3 | 3 | namespace okapi\services\logs\images\delete; |
4 | 4 | |
5 | -use Exception; |
|
6 | -use okapi\Okapi; |
|
7 | 5 | use okapi\Db; |
6 | +use okapi\Okapi; |
|
8 | 7 | use okapi\OkapiRequest; |
9 | 8 | use okapi\Settings; |
10 | 9 | use okapi\services\logs\images\LogImagesCommon; |
@@ -41,12 +41,9 @@ |
||
41 | 41 | # OCDE sequence numbers may have gaps. So we do not need to adjust |
42 | 42 | # any numbers after deleting from table 'pictures'. |
43 | 43 | |
44 | - if (Settings::get('OC_BRANCH') == 'oc.de') |
|
45 | - { |
|
44 | + if (Settings::get('OC_BRANCH') == 'oc.de') { |
|
46 | 45 | # OCDE does all the housekeeping by triggers |
47 | - } |
|
48 | - else |
|
49 | - { |
|
46 | + } else { |
|
50 | 47 | Db::execute(" |
51 | 48 | INSERT INTO removed_objects ( |
52 | 49 | localID, uuid, type, removed_date, node |
@@ -3,13 +3,12 @@ |
||
3 | 3 | namespace okapi\services\users\users; |
4 | 4 | |
5 | 5 | use Exception; |
6 | -use okapi\Okapi; |
|
7 | -use okapi\Settings; |
|
8 | 6 | use okapi\Db; |
7 | +use okapi\InvalidParam; |
|
8 | +use okapi\Okapi; |
|
9 | 9 | use okapi\OkapiRequest; |
10 | 10 | use okapi\ParamMissing; |
11 | -use okapi\InvalidParam; |
|
12 | -use okapi\services\caches\search\SearchAssistant; |
|
11 | +use okapi\Settings; |
|
13 | 12 | |
14 | 13 | class WebService |
15 | 14 | { |
@@ -136,7 +136,7 @@ |
||
136 | 136 | |
137 | 137 | while ($row = Db::fetch_assoc($rs)) |
138 | 138 | { |
139 | - $extras[$row['user_id']] = array();; |
|
139 | + $extras[$row['user_id']] = array(); ; |
|
140 | 140 | $extra_ref = &$extras[$row['user_id']]; |
141 | 141 | $extra_ref['caches_found'] = 0 + $row['founds_count']; |
142 | 142 | $extra_ref['caches_notfound'] = 0 + $row['notfounds_count']; |
@@ -28,18 +28,23 @@ discard block |
||
28 | 28 | public static function call(OkapiRequest $request) |
29 | 29 | { |
30 | 30 | $user_uuids = $request->get_parameter('user_uuids'); |
31 | - if (!$user_uuids) throw new ParamMissing('user_uuids'); |
|
31 | + if (!$user_uuids) { |
|
32 | + throw new ParamMissing('user_uuids'); |
|
33 | + } |
|
32 | 34 | $user_uuids = explode("|", $user_uuids); |
33 | - if (count($user_uuids) > 500) |
|
34 | - throw new InvalidParam('user_uuids', "Maximum allowed number of referenced users ". |
|
35 | + if (count($user_uuids) > 500) { |
|
36 | + throw new InvalidParam('user_uuids', "Maximum allowed number of referenced users ". |
|
35 | 37 | "is 500. You provided ".count($user_uuids)." user IDs."); |
38 | + } |
|
36 | 39 | $fields = $request->get_parameter('fields'); |
37 | - if (!$fields) |
|
38 | - throw new ParamMissing('fields'); |
|
40 | + if (!$fields) { |
|
41 | + throw new ParamMissing('fields'); |
|
42 | + } |
|
39 | 43 | $fields = explode("|", $fields); |
40 | - foreach ($fields as $field) |
|
41 | - if (!in_array($field, self::$valid_field_names)) |
|
44 | + foreach ($fields as $field) { |
|
45 | + if (!in_array($field, self::$valid_field_names)) |
|
42 | 46 | throw new InvalidParam('fields', "'$field' is not a valid field code."); |
47 | + } |
|
43 | 48 | $rs = Db::query(" |
44 | 49 | select user_id, uuid, username, admin, latitude, longitude, date_created |
45 | 50 | from user |
@@ -48,15 +53,12 @@ discard block |
||
48 | 53 | $results = array(); |
49 | 54 | $id2uuid = array(); |
50 | 55 | $uuid2id = array(); |
51 | - while ($row = Db::fetch_assoc($rs)) |
|
52 | - { |
|
56 | + while ($row = Db::fetch_assoc($rs)) { |
|
53 | 57 | $id2uuid[$row['user_id']] = $row['uuid']; |
54 | 58 | $uuid2id[$row['uuid']] = $row['user_id']; |
55 | 59 | $entry = array(); |
56 | - foreach ($fields as $field) |
|
57 | - { |
|
58 | - switch ($field) |
|
59 | - { |
|
60 | + foreach ($fields as $field) { |
|
61 | + switch ($field) { |
|
60 | 62 | case 'uuid': $entry['uuid'] = $row['uuid']; break; |
61 | 63 | case 'username': $entry['username'] = $row['username']; break; |
62 | 64 | case 'profile_url': $entry['profile_url'] = Settings::get('SITE_URL')."viewprofile.php?userid=".$row['user_id']; break; |
@@ -99,15 +101,13 @@ discard block |
||
99 | 101 | # caches_found, caches_notfound, caches_hidden |
100 | 102 | |
101 | 103 | if (in_array('caches_found', $fields) || in_array('caches_notfound', $fields) || in_array('caches_hidden', $fields) |
102 | - || in_array('rcmds_given', $fields)) |
|
103 | - { |
|
104 | + || in_array('rcmds_given', $fields)) { |
|
104 | 105 | # We will load all these stats together. Then we may remove these which |
105 | 106 | # the user doesn't need. |
106 | 107 | |
107 | 108 | $extras = array(); |
108 | 109 | |
109 | - if (Settings::get('OC_BRANCH') == 'oc.pl') |
|
110 | - { |
|
110 | + if (Settings::get('OC_BRANCH') == 'oc.pl') { |
|
111 | 111 | # OCPL stores user stats in 'user' table. |
112 | 112 | |
113 | 113 | $rs = Db::query(" |
@@ -115,9 +115,7 @@ discard block |
||
115 | 115 | from user |
116 | 116 | where user_id in ('".implode("','", array_map('\okapi\Db::escape_string', array_keys($id2uuid)))."') |
117 | 117 | "); |
118 | - } |
|
119 | - else |
|
120 | - { |
|
118 | + } else { |
|
121 | 119 | # OCDE stores user stats in 'stat_user' table. |
122 | 120 | |
123 | 121 | $rs = Db::query(" |
@@ -134,8 +132,7 @@ discard block |
||
134 | 132 | "); |
135 | 133 | } |
136 | 134 | |
137 | - while ($row = Db::fetch_assoc($rs)) |
|
138 | - { |
|
135 | + while ($row = Db::fetch_assoc($rs)) { |
|
139 | 136 | $extras[$row['user_id']] = array();; |
140 | 137 | $extra_ref = &$extras[$row['user_id']]; |
141 | 138 | $extra_ref['caches_found'] = 0 + $row['founds_count']; |
@@ -144,8 +141,7 @@ discard block |
||
144 | 141 | } |
145 | 142 | Db::free_result($rs); |
146 | 143 | |
147 | - if (in_array('rcmds_given', $fields)) |
|
148 | - { |
|
144 | + if (in_array('rcmds_given', $fields)) { |
|
149 | 145 | $rs = Db::query(" |
150 | 146 | select user_id, count(*) as rcmds_given |
151 | 147 | from cache_rating |
@@ -153,30 +149,32 @@ discard block |
||
153 | 149 | group by user_id |
154 | 150 | "); |
155 | 151 | $rcmds_counts = array(); |
156 | - while ($row = Db::fetch_assoc($rs)) |
|
157 | - $rcmds_counts[$row['user_id']] = $row['rcmds_given']; |
|
158 | - foreach ($extras as $user_id => &$extra_ref) |
|
159 | - { |
|
152 | + while ($row = Db::fetch_assoc($rs)) { |
|
153 | + $rcmds_counts[$row['user_id']] = $row['rcmds_given']; |
|
154 | + } |
|
155 | + foreach ($extras as $user_id => &$extra_ref) { |
|
160 | 156 | $extra_ref['rcmds_given'] = isset($rcmds_counts[$user_id]) ? 0 + $rcmds_counts[$user_id] : 0; |
161 | 157 | } |
162 | 158 | } |
163 | 159 | |
164 | 160 | # "Apply" only those fields which the consumer wanted. |
165 | 161 | |
166 | - foreach (array('caches_found', 'caches_notfound', 'caches_hidden', 'rcmds_given') as $field) |
|
167 | - { |
|
168 | - if (!in_array($field, $fields)) |
|
169 | - continue; |
|
170 | - foreach ($results as $uuid => &$result_ref) |
|
171 | - $result_ref[$field] = $extras[$uuid2id[$uuid]][$field]; |
|
162 | + foreach (array('caches_found', 'caches_notfound', 'caches_hidden', 'rcmds_given') as $field) { |
|
163 | + if (!in_array($field, $fields)) { |
|
164 | + continue; |
|
165 | + } |
|
166 | + foreach ($results as $uuid => &$result_ref) { |
|
167 | + $result_ref[$field] = $extras[$uuid2id[$uuid]][$field]; |
|
168 | + } |
|
172 | 169 | } |
173 | 170 | } |
174 | 171 | |
175 | 172 | # Check which user IDs were not found and mark them with null. |
176 | 173 | |
177 | - foreach ($user_uuids as $user_uuid) |
|
178 | - if (!isset($results[$user_uuid])) |
|
174 | + foreach ($user_uuids as $user_uuid) { |
|
175 | + if (!isset($results[$user_uuid])) |
|
179 | 176 | $results[$user_uuid] = null; |
177 | + } |
|
180 | 178 | |
181 | 179 | return Okapi::formatted_response($request, $results); |
182 | 180 | } |
@@ -2,15 +2,13 @@ |
||
2 | 2 | |
3 | 3 | namespace okapi\views\apps\authorize; |
4 | 4 | |
5 | -use Exception; |
|
6 | -use okapi\Okapi; |
|
7 | 5 | use okapi\Db; |
6 | +use okapi\Locales; |
|
7 | +use okapi\OCSession; |
|
8 | +use okapi\Okapi; |
|
8 | 9 | use okapi\OkapiHttpResponse; |
9 | -use okapi\OkapiHttpRequest; |
|
10 | 10 | use okapi\OkapiRedirectResponse; |
11 | 11 | use okapi\Settings; |
12 | -use okapi\Locales; |
|
13 | -use okapi\OCSession; |
|
14 | 12 | |
15 | 13 | class View |
16 | 14 | { |
@@ -111,10 +111,10 @@ discard block |
||
111 | 111 | foreach ($cookies as $cookie) { |
112 | 112 | $parts = explode('=', $cookie); |
113 | 113 | $name = trim($parts[0]); |
114 | - setcookie($name, '', time()-1000); |
|
115 | - setcookie($name, '', time()-1000, '/'); |
|
114 | + setcookie($name, '', time() - 1000); |
|
115 | + setcookie($name, '', time() - 1000, '/'); |
|
116 | 116 | foreach (self::getPossibleCookieDomains() as $domain) { |
117 | - setcookie($name, '', time()-1000, '/', $domain); |
|
117 | + setcookie($name, '', time() - 1000, '/', $domain); |
|
118 | 118 | } |
119 | 119 | } |
120 | 120 | } |
@@ -123,7 +123,7 @@ discard block |
||
123 | 123 | } |
124 | 124 | } |
125 | 125 | |
126 | - $after_login = "okapi/apps/authorize?oauth_token=$token_key".(($langpref != Settings::get('SITELANG'))?"&langpref=".$langpref:""); |
|
126 | + $after_login = "okapi/apps/authorize?oauth_token=$token_key".(($langpref != Settings::get('SITELANG')) ? "&langpref=".$langpref : ""); |
|
127 | 127 | $login_url = Settings::get('SITE_URL').$login_page."target=".urlencode($after_login) |
128 | 128 | ."&langpref=".$langpref; |
129 | 129 | return new OkapiRedirectResponse($login_url); |
@@ -20,8 +20,9 @@ discard block |
||
20 | 20 | $langpref = isset($_GET['langpref']) ? $_GET['langpref'] : Settings::get('SITELANG'); |
21 | 21 | $langprefs = explode("|", $langpref); |
22 | 22 | $locales = array(); |
23 | - foreach (Locales::$languages as $lang => $attrs) |
|
24 | - $locales[$attrs['locale']] = $attrs; |
|
23 | + foreach (Locales::$languages as $lang => $attrs) { |
|
24 | + $locales[$attrs['locale']] = $attrs; |
|
25 | + } |
|
25 | 26 | |
26 | 27 | # Current implementation of the "interactivity" parameter is: If developer |
27 | 28 | # wants to "confirm_user", then just log out the current user before we |
@@ -48,8 +49,7 @@ discard block |
||
48 | 49 | |
49 | 50 | $callback_concat_char = (strpos($token['callback'], '?') === false) ? "?" : "&"; |
50 | 51 | |
51 | - if (!$token) |
|
52 | - { |
|
52 | + if (!$token) { |
|
53 | 53 | # Probably Request Token has expired. This will be usually viewed |
54 | 54 | # by the user, who knows nothing on tokens and OAuth. Let's be nice then! |
55 | 55 | |
@@ -79,26 +79,21 @@ discard block |
||
79 | 79 | |
80 | 80 | # Ensure a user is logged in (or force re-login). |
81 | 81 | |
82 | - if ($force_relogin || ($OC_user_id == null)) |
|
83 | - { |
|
82 | + if ($force_relogin || ($OC_user_id == null)) { |
|
84 | 83 | # TODO: confirm_user should first ask the user if he's "the proper one", |
85 | 84 | # and then offer to sign in as a different user. |
86 | 85 | |
87 | 86 | $login_page = 'login.php?'; |
88 | 87 | |
89 | - if ($OC_user_id !== null) |
|
90 | - { |
|
91 | - if (Settings::get('OC_BRANCH') == 'oc.de') |
|
92 | - { |
|
88 | + if ($OC_user_id !== null) { |
|
89 | + if (Settings::get('OC_BRANCH') == 'oc.de') { |
|
93 | 90 | # OCDE login.php?action=logout&target=... will NOT logout and |
94 | 91 | # then redirect to the target, but it will log out, prompt for |
95 | 92 | # login and then redirect to the target after logging in - |
96 | 93 | # that's exactly the relogin that we want. |
97 | 94 | |
98 | 95 | $login_page .= 'action=logout&'; |
99 | - } |
|
100 | - else |
|
101 | - { |
|
96 | + } else { |
|
102 | 97 | # OCPL uses REAL MAGIC for session handling. I don't get ANY of it. |
103 | 98 | # The logout.php DOES NOT support the "target" parameter, so we |
104 | 99 | # can't just call it. The only thing that comes to mind is... |
@@ -141,15 +136,12 @@ discard block |
||
141 | 136 | and consumer_key = '".Db::escape_string($token['consumer_key'])."' |
142 | 137 | ", 0); |
143 | 138 | |
144 | - if (!$authorized) |
|
145 | - { |
|
146 | - if (isset($_POST['authorization_result'])) |
|
147 | - { |
|
139 | + if (!$authorized) { |
|
140 | + if (isset($_POST['authorization_result'])) { |
|
148 | 141 | # Not yet authorized, but user have just submitted the authorization form. |
149 | 142 | # WRTODO: CSRF protection |
150 | 143 | |
151 | - if ($_POST['authorization_result'] == 'granted') |
|
152 | - { |
|
144 | + if ($_POST['authorization_result'] == 'granted') { |
|
153 | 145 | Db::execute(" |
154 | 146 | insert ignore into okapi_authorizations (consumer_key, user_id) |
155 | 147 | values ( |
@@ -158,9 +150,7 @@ discard block |
||
158 | 150 | ); |
159 | 151 | "); |
160 | 152 | $authorized = true; |
161 | - } |
|
162 | - else |
|
163 | - { |
|
153 | + } else { |
|
164 | 154 | # User denied access. Nothing sensible to do now. Will try to report |
165 | 155 | # back to the Consumer application with an error. |
166 | 156 | |
@@ -175,9 +165,7 @@ discard block |
||
175 | 165 | return new OkapiRedirectResponse(Settings::get('SITE_URL')."index.php"); |
176 | 166 | } |
177 | 167 | } |
178 | - } |
|
179 | - else |
|
180 | - { |
|
168 | + } else { |
|
181 | 169 | # Not yet authorized. Display an authorization request. |
182 | 170 | $vars = array( |
183 | 171 | 'okapi_base_url' => Settings::get('SITE_URL')."okapi/", |
@@ -3,19 +3,12 @@ |
||
3 | 3 | namespace okapi\views\devel\dbstruct; |
4 | 4 | |
5 | 5 | use Exception; |
6 | -use okapi\Okapi; |
|
7 | -use okapi\Settings; |
|
8 | -use okapi\Cache; |
|
9 | -use okapi\Db; |
|
10 | -use okapi\OkapiRequest; |
|
11 | -use okapi\OkapiRedirectResponse; |
|
6 | +use okapi\BadRequest; |
|
12 | 7 | use okapi\OkapiHttpResponse; |
13 | -use okapi\ParamMissing; |
|
14 | -use okapi\InvalidParam; |
|
15 | -use okapi\OkapiServiceRunner; |
|
16 | -use okapi\OkapiInternalRequest; |
|
17 | 8 | use okapi\OkapiInternalConsumer; |
18 | -use okapi\BadRequest; |
|
9 | +use okapi\OkapiInternalRequest; |
|
10 | +use okapi\OkapiServiceRunner; |
|
11 | +use okapi\Settings; |
|
19 | 12 | |
20 | 13 | class View |
21 | 14 | { |
@@ -39,12 +39,12 @@ |
||
39 | 39 | |
40 | 40 | ini_set('memory_limit', '16M'); |
41 | 41 | $shell_arguments = "mysqldump --no-data -h$dbserver -u$user -p$password $dbname"; |
42 | - if (!strpos($shell_arguments,"--no-data")) |
|
42 | + if (!strpos($shell_arguments, "--no-data")) |
|
43 | 43 | throw new Exception("wrong database dump arguments"); |
44 | 44 | $struct = shell_exec($shell_arguments); |
45 | 45 | if (strlen($struct) > 1000000) |
46 | 46 | throw new Exception("something went terribly wrong while dumping table structures"); |
47 | - if (stripos($struct,"dumping data") !== FALSE) |
|
47 | + if (stripos($struct, "dumping data") !== FALSE) |
|
48 | 48 | throw new Exception("something went terribly wrong while dumping table structures"); |
49 | 49 | |
50 | 50 | # Remove the "AUTO_INCREMENT=..." values. They break the diffs. |
@@ -39,13 +39,16 @@ discard block |
||
39 | 39 | |
40 | 40 | ini_set('memory_limit', '16M'); |
41 | 41 | $shell_arguments = "mysqldump --no-data -h$dbserver -u$user -p$password $dbname"; |
42 | - if (!strpos($shell_arguments,"--no-data")) |
|
43 | - throw new Exception("wrong database dump arguments"); |
|
42 | + if (!strpos($shell_arguments,"--no-data")) { |
|
43 | + throw new Exception("wrong database dump arguments"); |
|
44 | + } |
|
44 | 45 | $struct = shell_exec($shell_arguments); |
45 | - if (strlen($struct) > 1000000) |
|
46 | - throw new Exception("something went terribly wrong while dumping table structures"); |
|
47 | - if (stripos($struct,"dumping data") !== FALSE) |
|
48 | - throw new Exception("something went terribly wrong while dumping table structures"); |
|
46 | + if (strlen($struct) > 1000000) { |
|
47 | + throw new Exception("something went terribly wrong while dumping table structures"); |
|
48 | + } |
|
49 | + if (stripos($struct,"dumping data") !== FALSE) { |
|
50 | + throw new Exception("something went terribly wrong while dumping table structures"); |
|
51 | + } |
|
49 | 52 | |
50 | 53 | # Remove the "AUTO_INCREMENT=..." values. They break the diffs. |
51 | 54 | |
@@ -65,12 +68,10 @@ discard block |
||
65 | 68 | |
66 | 69 | $response = new OkapiHttpResponse(); |
67 | 70 | $response->content_type = "text/plain; charset=utf-8"; |
68 | - if (isset($_GET['compare_to'])) |
|
69 | - { |
|
71 | + if (isset($_GET['compare_to'])) { |
|
70 | 72 | self::requireSafe($_GET['compare_to']); |
71 | 73 | $scheme = parse_url($_GET['compare_to'], PHP_URL_SCHEME); |
72 | - if (in_array($scheme, array('http', 'https'))) |
|
73 | - { |
|
74 | + if (in_array($scheme, array('http', 'https'))) { |
|
74 | 75 | try { |
75 | 76 | $alternate_struct = @file_get_contents($_GET['compare_to']); |
76 | 77 | } catch (Exception $e) { |
@@ -84,16 +85,13 @@ discard block |
||
84 | 85 | "-- better to use manual diff instead.\n\n"; |
85 | 86 | require_once("comparator.inc.php"); |
86 | 87 | $updater = new \dbStructUpdater(); |
87 | - if (isset($_GET['reverse']) && ($_GET['reverse'] == 'true')) |
|
88 | - { |
|
88 | + if (isset($_GET['reverse']) && ($_GET['reverse'] == 'true')) { |
|
89 | 89 | $response->body .= |
90 | 90 | "-- REVERSE MODE. The following will alter [2], so that it has the structure of [1].\n". |
91 | 91 | "-- 1. ".Settings::get('SITE_URL')."okapi/devel/dbstruct (".md5($struct).")\n". |
92 | 92 | "-- 2. ".$_GET['compare_to']." (".md5($alternate_struct).")\n\n"; |
93 | 93 | $alters = $updater->getUpdates($alternate_struct, $struct); |
94 | - } |
|
95 | - else |
|
96 | - { |
|
94 | + } else { |
|
97 | 95 | $response->body .= |
98 | 96 | "-- The following will alter [1], so that it has the structure of [2].\n". |
99 | 97 | "-- 1. ".Settings::get('SITE_URL')."okapi/devel/dbstruct (".md5($struct).")\n". |
@@ -101,31 +99,27 @@ discard block |
||
101 | 99 | $alters = $updater->getUpdates($struct, $alternate_struct); |
102 | 100 | } |
103 | 101 | # Add semicolons |
104 | - foreach ($alters as &$alter_ref) |
|
105 | - $alter_ref .= ";"; |
|
102 | + foreach ($alters as &$alter_ref) { |
|
103 | + $alter_ref .= ";"; |
|
104 | + } |
|
106 | 105 | # Comment out all differences containing "okapi_". These should be executed |
107 | 106 | # by OKAPI update scripts. |
108 | - foreach ($alters as &$alter_ref) |
|
109 | - { |
|
110 | - if (strpos($alter_ref, "okapi_") !== false) |
|
111 | - { |
|
107 | + foreach ($alters as &$alter_ref) { |
|
108 | + if (strpos($alter_ref, "okapi_") !== false) { |
|
112 | 109 | $lines = explode("\n", $alter_ref); |
113 | 110 | $alter_ref = "-- Probably you should NOT execute this one. Use okapi/update instead.\n-- {{{\n-- ". |
114 | 111 | implode("\n-- ", $lines)."\n-- }}}"; |
115 | 112 | } |
116 | 113 | } |
117 | - if (count($alters) > 0) |
|
118 | - $response->body .= implode("\n", $alters)."\n"; |
|
119 | - else |
|
120 | - $response->body .= "-- No differences found\n"; |
|
121 | - } |
|
122 | - else |
|
123 | - { |
|
114 | + if (count($alters) > 0) { |
|
115 | + $response->body .= implode("\n", $alters)."\n"; |
|
116 | + } else { |
|
117 | + $response->body .= "-- No differences found\n"; |
|
118 | + } |
|
119 | + } else { |
|
124 | 120 | $response->body = "HTTP(S) only!"; |
125 | 121 | } |
126 | - } |
|
127 | - else |
|
128 | - { |
|
122 | + } else { |
|
129 | 123 | $response->body = $struct; |
130 | 124 | } |
131 | 125 | return $response; |
@@ -44,7 +44,7 @@ |
||
44 | 44 | $struct = shell_exec($shell_arguments); |
45 | 45 | if (strlen($struct) > 1000000) |
46 | 46 | throw new Exception("something went terribly wrong while dumping table structures"); |
47 | - if (stripos($struct,"dumping data") !== FALSE) |
|
47 | + if (stripos($struct,"dumping data") !== false) |
|
48 | 48 | throw new Exception("something went terribly wrong while dumping table structures"); |
49 | 49 | |
50 | 50 | # Remove the "AUTO_INCREMENT=..." values. They break the diffs. |
@@ -3,22 +3,12 @@ |
||
3 | 3 | namespace okapi\views\tilestress; |
4 | 4 | |
5 | 5 | use Exception; |
6 | - |
|
7 | -use okapi\Okapi; |
|
8 | -use okapi\Cache; |
|
9 | 6 | use okapi\Db; |
10 | -use okapi\OkapiRequest; |
|
11 | -use okapi\OkapiRedirectResponse; |
|
12 | -use okapi\OkapiHttpResponse; |
|
13 | -use okapi\ParamMissing; |
|
14 | -use okapi\InvalidParam; |
|
15 | -use okapi\OkapiServiceRunner; |
|
16 | -use okapi\OkapiInternalRequest; |
|
17 | -use okapi\OkapiInternalConsumer; |
|
18 | -use okapi\OkapiInternalAccessToken; |
|
19 | -use okapi\Settings; |
|
20 | -use okapi\OkapiLock; |
|
21 | 7 | use okapi\OkapiExceptionHandler; |
8 | +use okapi\OkapiInternalAccessToken; |
|
9 | +use okapi\OkapiInternalConsumer; |
|
10 | +use okapi\OkapiInternalRequest; |
|
11 | +use okapi\OkapiServiceRunner; |
|
22 | 12 | |
23 | 13 | require_once($GLOBALS['rootpath']."okapi/service_runner.php"); |
24 | 14 |
@@ -66,8 +66,8 @@ |
||
66 | 66 | } |
67 | 67 | |
68 | 68 | $tiles = array(); |
69 | - for ($xx=$x; $xx<$x+4; $xx++) |
|
70 | - for ($yy=$y; $yy<$y+4; $yy++) |
|
69 | + for ($xx = $x; $xx < $x + 4; $xx++) |
|
70 | + for ($yy = $y; $yy < $y + 4; $yy++) |
|
71 | 71 | $tiles[] = array($xx, $yy); |
72 | 72 | srand(); |
73 | 73 | shuffle($tiles); |
@@ -42,8 +42,7 @@ discard block |
||
42 | 42 | $user_id = $_GET['u']; |
43 | 43 | self::out("Yo. I'm $user_id.\n\n"); |
44 | 44 | |
45 | - while (true) |
|
46 | - { |
|
45 | + while (true) { |
|
47 | 46 | srand(floor(time() / 10)); |
48 | 47 | $mode2 = rand(0, 9) <= 7; |
49 | 48 | if ($mode2) { |
@@ -66,14 +65,16 @@ discard block |
||
66 | 65 | } |
67 | 66 | |
68 | 67 | $tiles = array(); |
69 | - for ($xx=$x; $xx<$x+4; $xx++) |
|
70 | - for ($yy=$y; $yy<$y+4; $yy++) |
|
71 | - $tiles[] = array($xx, $yy); |
|
68 | + for ($xx=$x; $xx<$x+4; $xx++) { |
|
69 | + for ($yy=$y; |
|
70 | + } |
|
71 | + $yy<$y+4; $yy++) { |
|
72 | + $tiles[] = array($xx, $yy); |
|
73 | + } |
|
72 | 74 | srand(); |
73 | 75 | shuffle($tiles); |
74 | 76 | |
75 | - foreach ($tiles as $tile) |
|
76 | - { |
|
77 | + foreach ($tiles as $tile) { |
|
77 | 78 | list($x, $y) = $tile; |
78 | 79 | self::out("Loading ".str_pad("($z, $x, $y)... ", 30)); |
79 | 80 | $time_started = microtime(true); |
@@ -35,6 +35,9 @@ discard block |
||
35 | 35 | $this->init(0, 0); |
36 | 36 | } |
37 | 37 | |
38 | + /** |
|
39 | + * @param boolean $request |
|
40 | + */ |
|
38 | 41 | private function initRequest($request) |
39 | 42 | { |
40 | 43 | if ($request) { |
@@ -44,6 +47,9 @@ discard block |
||
44 | 47 | return new RequestHttp(); |
45 | 48 | } |
46 | 49 | |
50 | + /** |
|
51 | + * @param boolean $translator |
|
52 | + */ |
|
47 | 53 | private function initTranslator($translator) |
48 | 54 | { |
49 | 55 | if ($translator) { |
@@ -11,7 +11,7 @@ |
||
11 | 11 | use Oc\Libse\Validator\AlwaysValidValidator; |
12 | 12 | use Oc\Libse\Validator\ArrayValidator; |
13 | 13 | |
14 | -require_once __DIR__ . '/../../../../lib2/error.inc.php'; |
|
14 | +require_once __DIR__.'/../../../../lib2/error.inc.php'; |
|
15 | 15 | |
16 | 16 | abstract class PresenterChildWp |
17 | 17 | { |
@@ -5,7 +5,7 @@ discard block |
||
5 | 5 | * Unicode Reminder メモ |
6 | 6 | ***************************************************************************/ |
7 | 7 | |
8 | -require __DIR__ . '/lib2/web.inc.php'; |
|
8 | +require __DIR__.'/lib2/web.inc.php'; |
|
9 | 9 | |
10 | 10 | $tpl->name = 'adminuser'; |
11 | 11 | $tpl->menuitem = MNU_ADMIN_USER; |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | // send a new confirmation |
52 | 52 | $user->sendRegistrationCode(); |
53 | 53 | |
54 | - $tpl->redirect('adminuser.php?action=searchuser&msg=sendcodecommit&username=' . urlencode($user->getUsername())); |
|
54 | + $tpl->redirect('adminuser.php?action=searchuser&msg=sendcodecommit&username='.urlencode($user->getUsername())); |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | function formAction() |
@@ -97,8 +97,8 @@ discard block |
||
97 | 97 | $user->addEmailProblem($datalicense); |
98 | 98 | } |
99 | 99 | |
100 | - $tpl->redirect('adminuser.php?action=searchuser&username=' . urlencode($username) . |
|
101 | - '&success=' . ($disduelicense + $disable)); |
|
100 | + $tpl->redirect('adminuser.php?action=searchuser&username='.urlencode($username). |
|
101 | + '&success='.($disduelicense + $disable)); |
|
102 | 102 | } |
103 | 103 | |
104 | 104 | function searchUser() |