@@ -3,19 +3,14 @@ |
||
3 | 3 | namespace okapi\services\caches\formatters\garmin; |
4 | 4 | |
5 | 5 | |
6 | -use okapi\Okapi; |
|
7 | 6 | use okapi\Cache; |
8 | 7 | use okapi\Settings; |
9 | 8 | use okapi\OkapiRequest; |
10 | -use okapi\OkapiHttpResponse; |
|
11 | 9 | use okapi\OkapiInternalRequest; |
12 | 10 | use okapi\OkapiServiceRunner; |
13 | 11 | use okapi\OkapiZIPHttpResponse; |
14 | -use okapi\BadRequest; |
|
15 | 12 | use okapi\ParamMissing; |
16 | 13 | use okapi\InvalidParam; |
17 | -use okapi\OkapiAccessToken; |
|
18 | -use okapi\services\caches\search\SearchAssistant; |
|
19 | 14 | |
20 | 15 | use \Exception; |
21 | 16 | use \clsTbsZip; |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | |
40 | 40 | $langpref = $request->get_parameter('langpref'); |
41 | 41 | if (!$langpref) $langpref = "en"; |
42 | - $langpref .= "|".Settings::get('SITELANG'); |
|
42 | + $langpref .= "|" . Settings::get('SITELANG'); |
|
43 | 43 | $images = $request->get_parameter('images'); |
44 | 44 | if (!$images) $images = "all"; |
45 | 45 | if (!in_array($images, array("none", "all", "spoilers", "nonspoilers"))) |
@@ -60,14 +60,14 @@ discard block |
||
60 | 60 | # also include image references (actual images will be added as separate files later) |
61 | 61 | # and personal data (if the method was invoked using Level 3 Authentication). |
62 | 62 | |
63 | - switch($format) { |
|
63 | + switch ($format) { |
|
64 | 64 | case 'gpx' : |
65 | - $data_filename = "Garmin/GPX/opencaching".time().rand(100000,999999).".gpx"; |
|
65 | + $data_filename = "Garmin/GPX/opencaching" . time() . rand(100000, 999999) . ".gpx"; |
|
66 | 66 | $data_method = 'services/caches/formatters/gpx'; |
67 | 67 | $data_use_compression = true; |
68 | 68 | break; |
69 | 69 | case 'ggz' : |
70 | - $data_filename = "Garmin/GGZ/opencaching".time().rand(100000,999999).".ggz"; |
|
70 | + $data_filename = "Garmin/GGZ/opencaching" . time() . rand(100000, 999999) . ".ggz"; |
|
71 | 71 | $data_method = 'services/caches/formatters/ggz'; |
72 | 72 | $data_use_compression = false; |
73 | 73 | break; |
@@ -107,9 +107,9 @@ discard block |
||
107 | 107 | $imgs = $dict['images']; |
108 | 108 | if (count($imgs) == 0) |
109 | 109 | continue; |
110 | - $dir = "Garmin/GeocachePhotos/".$cache_code[strlen($cache_code) - 1]; |
|
111 | - $dir .= "/".$cache_code[strlen($cache_code) - 2]; |
|
112 | - $dir .= "/".$cache_code; |
|
110 | + $dir = "Garmin/GeocachePhotos/" . $cache_code[strlen($cache_code) - 1]; |
|
111 | + $dir .= "/" . $cache_code[strlen($cache_code) - 2]; |
|
112 | + $dir .= "/" . $cache_code; |
|
113 | 113 | foreach ($imgs as $no => $img) |
114 | 114 | { |
115 | 115 | if ($images == 'spoilers' && (!$img['is_spoiler'])) |
@@ -119,19 +119,19 @@ discard block |
||
119 | 119 | $tmp = false; |
120 | 120 | foreach ($supported_extensions as $ext) |
121 | 121 | { |
122 | - if (strtolower(substr($img['url'], strlen($img['url']) - strlen($ext) - 1)) != ".".$ext) |
|
122 | + if (strtolower(substr($img['url'], strlen($img['url']) - strlen($ext) - 1)) != "." . $ext) |
|
123 | 123 | { |
124 | 124 | $tmp = true; |
125 | 125 | continue; |
126 | 126 | } |
127 | 127 | } |
128 | 128 | if (!$tmp) |
129 | - continue; # unsupported file extension |
|
129 | + continue; # unsupported file extension |
|
130 | 130 | |
131 | 131 | if ($img['is_spoiler']) { |
132 | - $zippath = $dir."/Spoilers/".$img['unique_caption'].".jpg"; |
|
132 | + $zippath = $dir . "/Spoilers/" . $img['unique_caption'] . ".jpg"; |
|
133 | 133 | } else { |
134 | - $zippath = $dir."/".$img['unique_caption'].".jpg"; |
|
134 | + $zippath = $dir . "/" . $img['unique_caption'] . ".jpg"; |
|
135 | 135 | } |
136 | 136 | |
137 | 137 | # The safest way would be to use the URL, but that would be painfully slow! |
@@ -141,7 +141,7 @@ discard block |
||
141 | 141 | # Note: Oliver Dietz (oc.de) replied that images with 'local' set to 0 could not |
142 | 142 | # be accessed locally. But all the files have 'local' set to 1 anyway. |
143 | 143 | |
144 | - $syspath = Settings::get('IMAGES_DIR')."/".$img['uuid'].".jpg"; |
|
144 | + $syspath = Settings::get('IMAGES_DIR') . "/" . $img['uuid'] . ".jpg"; |
|
145 | 145 | if (file_exists($syspath)) |
146 | 146 | { |
147 | 147 | $response->zip->FileAdd($zippath, $syspath, clsTbsZip::TBSZIP_FILE, false); |
@@ -151,13 +151,13 @@ discard block |
||
151 | 151 | # If file exists, but does not end with ".jpg", we will create |
152 | 152 | # JPEG version of it and store it in the cache. |
153 | 153 | |
154 | - $cache_key = "jpg#".$img['uuid']; |
|
154 | + $cache_key = "jpg#" . $img['uuid']; |
|
155 | 155 | $jpeg_contents = Cache::get($cache_key); |
156 | 156 | if ($jpeg_contents === null) |
157 | 157 | { |
158 | 158 | foreach ($supported_extensions as $ext) |
159 | 159 | { |
160 | - $syspath_other = Settings::get('IMAGES_DIR')."/".$img['uuid'].".".$ext; |
|
160 | + $syspath_other = Settings::get('IMAGES_DIR') . "/" . $img['uuid'] . "." . $ext; |
|
161 | 161 | if (file_exists($syspath_other)) |
162 | 162 | { |
163 | 163 | try |
@@ -32,22 +32,32 @@ discard block |
||
32 | 32 | public static function call(OkapiRequest $request) |
33 | 33 | { |
34 | 34 | $cache_codes = $request->get_parameter('cache_codes'); |
35 | - if ($cache_codes === null) throw new ParamMissing('cache_codes'); |
|
35 | + if ($cache_codes === null) { |
|
36 | + throw new ParamMissing('cache_codes'); |
|
37 | + } |
|
36 | 38 | |
37 | 39 | # Issue 106 requires us to allow empty list of cache codes to be passed into this method. |
38 | 40 | # All of the queries below have to be ready for $cache_codes to be empty! |
39 | 41 | |
40 | 42 | $langpref = $request->get_parameter('langpref'); |
41 | - if (!$langpref) $langpref = "en"; |
|
43 | + if (!$langpref) { |
|
44 | + $langpref = "en"; |
|
45 | + } |
|
42 | 46 | $langpref .= "|".Settings::get('SITELANG'); |
43 | 47 | $images = $request->get_parameter('images'); |
44 | - if (!$images) $images = "all"; |
|
45 | - if (!in_array($images, array("none", "all", "spoilers", "nonspoilers"))) |
|
46 | - throw new InvalidParam('images'); |
|
48 | + if (!$images) { |
|
49 | + $images = "all"; |
|
50 | + } |
|
51 | + if (!in_array($images, array("none", "all", "spoilers", "nonspoilers"))) { |
|
52 | + throw new InvalidParam('images'); |
|
53 | + } |
|
47 | 54 | $format = $request->get_parameter('caches_format'); |
48 | - if (!$format) $format = "gpx"; |
|
49 | - if (!in_array($format, array("gpx", "ggz"))) |
|
50 | - throw new InvalidParam('caches_format'); |
|
55 | + if (!$format) { |
|
56 | + $format = "gpx"; |
|
57 | + } |
|
58 | + if (!in_array($format, array("gpx", "ggz"))) { |
|
59 | + throw new InvalidParam('caches_format'); |
|
60 | + } |
|
51 | 61 | |
52 | 62 | $location_source = $request->get_parameter('location_source'); |
53 | 63 | $location_change_prefix = $request->get_parameter('location_change_prefix'); |
@@ -97,25 +107,29 @@ discard block |
||
97 | 107 | $caches = OkapiServiceRunner::call('services/caches/geocaches', new OkapiInternalRequest( |
98 | 108 | $request->consumer, $request->token, array('cache_codes' => $cache_codes, |
99 | 109 | 'langpref' => $langpref, 'fields' => "images"))); |
100 | - if (count($caches) > 50) |
|
101 | - throw new InvalidParam('cache_codes', "The maximum number of caches allowed to be downloaded with this method is 50."); |
|
110 | + if (count($caches) > 50) { |
|
111 | + throw new InvalidParam('cache_codes', "The maximum number of caches allowed to be downloaded with this method is 50."); |
|
112 | + } |
|
102 | 113 | if ($images != 'none') |
103 | 114 | { |
104 | 115 | $supported_extensions = array('jpg', 'jpeg', 'gif', 'png', 'bmp'); |
105 | 116 | foreach ($caches as $cache_code => $dict) |
106 | 117 | { |
107 | 118 | $imgs = $dict['images']; |
108 | - if (count($imgs) == 0) |
|
109 | - continue; |
|
119 | + if (count($imgs) == 0) { |
|
120 | + continue; |
|
121 | + } |
|
110 | 122 | $dir = "Garmin/GeocachePhotos/".$cache_code[strlen($cache_code) - 1]; |
111 | 123 | $dir .= "/".$cache_code[strlen($cache_code) - 2]; |
112 | 124 | $dir .= "/".$cache_code; |
113 | 125 | foreach ($imgs as $no => $img) |
114 | 126 | { |
115 | - if ($images == 'spoilers' && (!$img['is_spoiler'])) |
|
116 | - continue; |
|
117 | - if ($images == 'nonspoilers' && $img['is_spoiler']) |
|
118 | - continue; |
|
127 | + if ($images == 'spoilers' && (!$img['is_spoiler'])) { |
|
128 | + continue; |
|
129 | + } |
|
130 | + if ($images == 'nonspoilers' && $img['is_spoiler']) { |
|
131 | + continue; |
|
132 | + } |
|
119 | 133 | $tmp = false; |
120 | 134 | foreach ($supported_extensions as $ext) |
121 | 135 | { |
@@ -125,8 +139,10 @@ discard block |
||
125 | 139 | continue; |
126 | 140 | } |
127 | 141 | } |
128 | - if (!$tmp) |
|
129 | - continue; # unsupported file extension |
|
142 | + if (!$tmp) { |
|
143 | + continue; |
|
144 | + } |
|
145 | + # unsupported file extension |
|
130 | 146 | |
131 | 147 | if ($img['is_spoiler']) { |
132 | 148 | $zippath = $dir."/Spoilers/".$img['unique_caption'].".jpg"; |
@@ -145,8 +161,7 @@ discard block |
||
145 | 161 | if (file_exists($syspath)) |
146 | 162 | { |
147 | 163 | $response->zip->FileAdd($zippath, $syspath, clsTbsZip::TBSZIP_FILE, false); |
148 | - } |
|
149 | - else |
|
164 | + } else |
|
150 | 165 | { |
151 | 166 | # If file exists, but does not end with ".jpg", we will create |
152 | 167 | # JPEG version of it and store it in the cache. |
@@ -167,8 +182,7 @@ discard block |
||
167 | 182 | imagejpeg($image); |
168 | 183 | $jpeg_contents = ob_get_clean(); |
169 | 184 | imagedestroy($image); |
170 | - } |
|
171 | - catch (Exception $e) |
|
185 | + } catch (Exception $e) |
|
172 | 186 | { |
173 | 187 | # GD couldn't parse the file. We will skip it, and cache |
174 | 188 | # the "false" value as the contents. This way, we won't |
@@ -181,8 +195,10 @@ discard block |
||
181 | 195 | } |
182 | 196 | } |
183 | 197 | } |
184 | - if ($jpeg_contents) # This can be "null" *or* "false"! |
|
198 | + if ($jpeg_contents) { |
|
199 | + # This can be "null" *or* "false"! |
|
185 | 200 | $response->zip->FileAdd($zippath, $jpeg_contents, clsTbsZip::TBSZIP_STRING, false); |
201 | + } |
|
186 | 202 | } |
187 | 203 | } |
188 | 204 | } |
@@ -9,9 +9,7 @@ |
||
9 | 9 | use okapi\OkapiServiceRunner; |
10 | 10 | use okapi\BadRequest; |
11 | 11 | use okapi\ParamMissing; |
12 | -use okapi\OkapiAccessToken; |
|
13 | 12 | use okapi\InvalidParam; |
14 | -use okapi\services\caches\search\SearchAssistant; |
|
15 | 13 | use okapi\OkapiInternalConsumer; |
16 | 14 | use okapi\Db; |
17 | 15 | use okapi\Settings; |
@@ -465,7 +465,7 @@ |
||
465 | 465 | $ggz_entry['ratings'] = array(); |
466 | 466 | $ratings_ref = &$ggz_entry['ratings']; |
467 | 467 | if (isset($cache_ref['rating'])){ |
468 | - $ratings_ref['awesomeness'] = $cache_ref['rating']; |
|
468 | + $ratings_ref['awesomeness'] = $cache_ref['rating']; |
|
469 | 469 | } |
470 | 470 | $ratings_ref['difficulty'] = $cache_ref['difficulty']; |
471 | 471 | if (!isset($cache_ref['size'])) { |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | |
97 | 97 | $langpref = $request->get_parameter('langpref'); |
98 | 98 | if (!$langpref) $langpref = "en"; |
99 | - $langpref .= "|".Settings::get('SITELANG'); |
|
99 | + $langpref .= "|" . Settings::get('SITELANG'); |
|
100 | 100 | foreach (array('ns_ground', 'ns_gsak', 'ns_ox', 'latest_logs', 'alt_wpts', 'mark_found') as $param) |
101 | 101 | { |
102 | 102 | $val = $request->get_parameter($param); |
@@ -164,7 +164,7 @@ discard block |
||
164 | 164 | else $protection_areas = 'none'; |
165 | 165 | } |
166 | 166 | if (!in_array($protection_areas, array('none', 'desc:text'))) |
167 | - throw new InvalidParam('protection_areas',"'$protection_areas'"); |
|
167 | + throw new InvalidParam('protection_areas', "'$protection_areas'"); |
|
168 | 168 | $vars['protection_areas'] = $protection_areas; |
169 | 169 | |
170 | 170 | $tmp = $request->get_parameter('trackables'); |
@@ -194,7 +194,7 @@ discard block |
||
194 | 194 | # Make sure location_source has prefix alt_wpt: |
195 | 195 | if ($location_source != 'default-coords' && strncmp($location_source, 'alt_wpt:', 8) != 0) |
196 | 196 | { |
197 | - throw new InvalidParam('location_source', '\''.$location_source.'\''); |
|
197 | + throw new InvalidParam('location_source', '\'' . $location_source . '\''); |
|
198 | 198 | } |
199 | 199 | |
200 | 200 | # Make sure we have sufficient authorization |
@@ -205,8 +205,8 @@ discard block |
||
205 | 205 | |
206 | 206 | # Which fields of the services/caches/geocaches method do we need? |
207 | 207 | |
208 | - $fields = 'code|name|location|date_created|url|type|status|size|size2|oxsize'. |
|
209 | - '|difficulty|terrain|description|hint2|rating|owner|url|internal_id'. |
|
208 | + $fields = 'code|name|location|date_created|url|type|status|size|size2|oxsize' . |
|
209 | + '|difficulty|terrain|description|hint2|rating|owner|url|internal_id' . |
|
210 | 210 | '|protection_areas|short_description'; |
211 | 211 | if ($vars['images'] != 'none') |
212 | 212 | $fields .= "|images"; |
@@ -290,7 +290,7 @@ discard block |
||
290 | 290 | # database; OCPL stores attribute names in a different way and may use |
291 | 291 | # different names for equivalent attributes. |
292 | 292 | |
293 | - $ocde_attrnames = Db::select_group_by('id'," |
|
293 | + $ocde_attrnames = Db::select_group_by('id', " |
|
294 | 294 | select id, name |
295 | 295 | from cache_attrib |
296 | 296 | "); |
@@ -373,7 +373,7 @@ discard block |
||
373 | 373 | $rs = Db::query(" |
374 | 374 | select uuid, user_id |
375 | 375 | from user |
376 | - where uuid in ('".implode("','", array_map('\okapi\Db::escape_string', array_keys($dict)))."') |
|
376 | + where uuid in ('".implode("','", array_map('\okapi\Db::escape_string', array_keys($dict))) . "') |
|
377 | 377 | "); |
378 | 378 | while ($row = Db::fetch_assoc($rs)) |
379 | 379 | $dict[$row['uuid']] = $row['user_id']; |
@@ -393,7 +393,7 @@ discard block |
||
393 | 393 | { |
394 | 394 | foreach ($cache_ref['alt_wpts'] as $alt_wpt_key => $alt_wpt) |
395 | 395 | { |
396 | - if ('alt_wpt:'.$alt_wpt['type'] == $location_source) |
|
396 | + if ('alt_wpt:' . $alt_wpt['type'] == $location_source) |
|
397 | 397 | { |
398 | 398 | # Switch locations between primary wpt and alternate wpt. |
399 | 399 | # Also alter the cache name and make sure to append a proper |
@@ -401,17 +401,17 @@ discard block |
||
401 | 401 | |
402 | 402 | $original_location = $cache_ref['location']; |
403 | 403 | $cache_ref['location'] = $alt_wpt['location']; |
404 | - $cache_ref['name_2'] = $location_change_prefix.$cache_ref['name']; |
|
404 | + $cache_ref['name_2'] = $location_change_prefix . $cache_ref['name']; |
|
405 | 405 | if ($location_source == "alt_wpt:user-coords") { |
406 | 406 | # In case of "user-coords", replace the default warning with a custom-tailored one. |
407 | 407 | $cache_ref['warning_prefix'] = _( |
408 | - "<b>Geocache coordinates have been changed.</b> They have been replaced with ". |
|
408 | + "<b>Geocache coordinates have been changed.</b> They have been replaced with " . |
|
409 | 409 | "your own custom coordinates which you have provided for this geocache." |
410 | 410 | ); |
411 | 411 | } else { |
412 | 412 | # Default warning |
413 | 413 | $cache_ref['warning_prefix'] = _( |
414 | - "<b>Geocache coordinates have been changed.</b> Currently they ". |
|
414 | + "<b>Geocache coordinates have been changed.</b> Currently they " . |
|
415 | 415 | "point to one of the alternate waypoints originally described as:" |
416 | 416 | ) . " " . $alt_wpt['description']; |
417 | 417 | } |
@@ -421,7 +421,7 @@ discard block |
||
421 | 421 | if ($vars['alt_wpts']) |
422 | 422 | { |
423 | 423 | $cache_ref['alt_wpts'][] = array( |
424 | - 'name' => $cache_ref['code'].'-DEFAULT-COORDS', |
|
424 | + 'name' => $cache_ref['code'] . '-DEFAULT-COORDS', |
|
425 | 425 | 'location' => $original_location, |
426 | 426 | 'type' => 'default-coords', |
427 | 427 | 'type_name' => _("Original geocache location"), |
@@ -464,7 +464,7 @@ discard block |
||
464 | 464 | |
465 | 465 | $ggz_entry['ratings'] = array(); |
466 | 466 | $ratings_ref = &$ggz_entry['ratings']; |
467 | - if (isset($cache_ref['rating'])){ |
|
467 | + if (isset($cache_ref['rating'])) { |
|
468 | 468 | $ratings_ref['awesomeness'] = $cache_ref['rating']; |
469 | 469 | } |
470 | 470 | $ratings_ref['difficulty'] = $cache_ref['difficulty']; |
@@ -89,24 +89,31 @@ discard block |
||
89 | 89 | # $vars variable which we will use later in the GPS template. |
90 | 90 | |
91 | 91 | $cache_codes = $request->get_parameter('cache_codes'); |
92 | - if ($cache_codes === null) throw new ParamMissing('cache_codes'); |
|
92 | + if ($cache_codes === null) { |
|
93 | + throw new ParamMissing('cache_codes'); |
|
94 | + } |
|
93 | 95 | |
94 | 96 | # Issue 106 requires us to allow empty list of cache codes to be passed into this method. |
95 | 97 | # All of the queries below have to be ready for $cache_codes to be empty! |
96 | 98 | |
97 | 99 | $langpref = $request->get_parameter('langpref'); |
98 | - if (!$langpref) $langpref = "en"; |
|
100 | + if (!$langpref) { |
|
101 | + $langpref = "en"; |
|
102 | + } |
|
99 | 103 | $langpref .= "|".Settings::get('SITELANG'); |
100 | 104 | foreach (array('ns_ground', 'ns_gsak', 'ns_ox', 'latest_logs', 'alt_wpts', 'mark_found') as $param) |
101 | 105 | { |
102 | 106 | $val = $request->get_parameter($param); |
103 | - if (!$val) $val = "false"; |
|
104 | - elseif (!in_array($val, array("true", "false"))) |
|
105 | - throw new InvalidParam($param); |
|
107 | + if (!$val) { |
|
108 | + $val = "false"; |
|
109 | + } elseif (!in_array($val, array("true", "false"))) { |
|
110 | + throw new InvalidParam($param); |
|
111 | + } |
|
106 | 112 | $vars[$param] = ($val == "true"); |
107 | 113 | } |
108 | - if ($vars['latest_logs'] && (!$vars['ns_ground'])) |
|
109 | - throw new BadRequest("In order for 'latest_logs' to work you have to also include 'ns_ground' extensions."); |
|
114 | + if ($vars['latest_logs'] && (!$vars['ns_ground'])) { |
|
115 | + throw new BadRequest("In order for 'latest_logs' to work you have to also include 'ns_ground' extensions."); |
|
116 | + } |
|
110 | 117 | |
111 | 118 | $tmp = $request->get_parameter('my_notes'); |
112 | 119 | $vars['my_notes'] = array(); |
@@ -134,13 +141,18 @@ discard block |
||
134 | 141 | } |
135 | 142 | |
136 | 143 | $images = $request->get_parameter('images'); |
137 | - if (!$images) $images = 'descrefs:nonspoilers'; |
|
138 | - if (!in_array($images, array('none', 'descrefs:thumblinks', 'descrefs:nonspoilers', 'descrefs:all', 'ox:all'))) |
|
139 | - throw new InvalidParam('images', "'$images'"); |
|
144 | + if (!$images) { |
|
145 | + $images = 'descrefs:nonspoilers'; |
|
146 | + } |
|
147 | + if (!in_array($images, array('none', 'descrefs:thumblinks', 'descrefs:nonspoilers', 'descrefs:all', 'ox:all'))) { |
|
148 | + throw new InvalidParam('images', "'$images'"); |
|
149 | + } |
|
140 | 150 | $vars['images'] = $images; |
141 | 151 | |
142 | 152 | $tmp = $request->get_parameter('attrs'); |
143 | - if (!$tmp) $tmp = 'desc:text'; |
|
153 | + if (!$tmp) { |
|
154 | + $tmp = 'desc:text'; |
|
155 | + } |
|
144 | 156 | $tmp = explode("|", $tmp); |
145 | 157 | $vars['attrs'] = array(); |
146 | 158 | foreach ($tmp as $elem) |
@@ -148,10 +160,11 @@ discard block |
||
148 | 160 | if ($elem == 'none') { |
149 | 161 | /* pass */ |
150 | 162 | } elseif (in_array($elem, array('desc:text', 'ox:tags', 'gc:attrs', 'gc_ocde:attrs'))) { |
151 | - if ($elem == 'gc_ocde:attrs' && Settings::get('OC_BRANCH') != 'oc.de') |
|
152 | - $vars['attrs'][] = 'gc:attrs'; |
|
153 | - else |
|
154 | - $vars['attrs'][] = $elem; |
|
163 | + if ($elem == 'gc_ocde:attrs' && Settings::get('OC_BRANCH') != 'oc.de') { |
|
164 | + $vars['attrs'][] = 'gc:attrs'; |
|
165 | + } else { |
|
166 | + $vars['attrs'][] = $elem; |
|
167 | + } |
|
155 | 168 | } else { |
156 | 169 | throw new InvalidParam('attrs', "Invalid list entry: '$elem'"); |
157 | 170 | } |
@@ -160,27 +173,40 @@ discard block |
||
160 | 173 | $protection_areas = $request->get_parameter('protection_areas'); |
161 | 174 | if (!$protection_areas || $protection_areas == 'desc:auto') |
162 | 175 | { |
163 | - if (Settings::get('OC_BRANCH') == 'oc.de') $protection_areas = 'desc:text'; |
|
164 | - else $protection_areas = 'none'; |
|
176 | + if (Settings::get('OC_BRANCH') == 'oc.de') { |
|
177 | + $protection_areas = 'desc:text'; |
|
178 | + } else { |
|
179 | + $protection_areas = 'none'; |
|
180 | + } |
|
181 | + } |
|
182 | + if (!in_array($protection_areas, array('none', 'desc:text'))) { |
|
183 | + throw new InvalidParam('protection_areas',"'$protection_areas'"); |
|
165 | 184 | } |
166 | - if (!in_array($protection_areas, array('none', 'desc:text'))) |
|
167 | - throw new InvalidParam('protection_areas',"'$protection_areas'"); |
|
168 | 185 | $vars['protection_areas'] = $protection_areas; |
169 | 186 | |
170 | 187 | $tmp = $request->get_parameter('trackables'); |
171 | - if (!$tmp) $tmp = 'none'; |
|
172 | - if (!in_array($tmp, array('none', 'desc:list', 'desc:count'))) |
|
173 | - throw new InvalidParam('trackables', "'$tmp'"); |
|
188 | + if (!$tmp) { |
|
189 | + $tmp = 'none'; |
|
190 | + } |
|
191 | + if (!in_array($tmp, array('none', 'desc:list', 'desc:count'))) { |
|
192 | + throw new InvalidParam('trackables', "'$tmp'"); |
|
193 | + } |
|
174 | 194 | $vars['trackables'] = $tmp; |
175 | 195 | |
176 | 196 | $tmp = $request->get_parameter('recommendations'); |
177 | - if (!$tmp) $tmp = 'none'; |
|
178 | - if (!in_array($tmp, array('none', 'desc:count'))) |
|
179 | - throw new InvalidParam('recommendations', "'$tmp'"); |
|
197 | + if (!$tmp) { |
|
198 | + $tmp = 'none'; |
|
199 | + } |
|
200 | + if (!in_array($tmp, array('none', 'desc:count'))) { |
|
201 | + throw new InvalidParam('recommendations', "'$tmp'"); |
|
202 | + } |
|
180 | 203 | $vars['recommendations'] = $tmp; |
181 | 204 | |
182 | 205 | $lpc = $request->get_parameter('lpc'); |
183 | - if ($lpc === null) $lpc = 10; # will be checked in services/caches/geocaches call |
|
206 | + if ($lpc === null) { |
|
207 | + $lpc = 10; |
|
208 | + } |
|
209 | + # will be checked in services/caches/geocaches call |
|
184 | 210 | |
185 | 211 | $user_uuid = $request->get_parameter('user_uuid'); |
186 | 212 | |
@@ -208,24 +234,32 @@ discard block |
||
208 | 234 | $fields = 'code|name|location|date_created|url|type|status|size|size2|oxsize'. |
209 | 235 | '|difficulty|terrain|description|hint2|rating|owner|url|internal_id'. |
210 | 236 | '|protection_areas|short_description'; |
211 | - if ($vars['images'] != 'none') |
|
212 | - $fields .= "|images"; |
|
213 | - if (count($vars['attrs']) > 0) |
|
214 | - $fields .= "|attrnames|attr_acodes|needs_maintenance"; |
|
215 | - if ($vars['trackables'] == 'desc:list') |
|
216 | - $fields .= "|trackables"; |
|
217 | - elseif ($vars['trackables'] == 'desc:count') |
|
218 | - $fields .= "|trackables_count"; |
|
219 | - if ($vars['alt_wpts'] == 'true' || $location_source != 'default-coords') |
|
220 | - $fields .= "|alt_wpts"; |
|
221 | - if ($vars['recommendations'] != 'none') |
|
222 | - $fields .= "|recommendations|founds"; |
|
223 | - if (count($vars['my_notes']) > 0) |
|
224 | - $fields .= "|my_notes"; |
|
225 | - if ($vars['latest_logs']) |
|
226 | - $fields .= "|latest_logs"; |
|
227 | - if ($vars['mark_found']) |
|
228 | - $fields .= "|is_found"; |
|
237 | + if ($vars['images'] != 'none') { |
|
238 | + $fields .= "|images"; |
|
239 | + } |
|
240 | + if (count($vars['attrs']) > 0) { |
|
241 | + $fields .= "|attrnames|attr_acodes|needs_maintenance"; |
|
242 | + } |
|
243 | + if ($vars['trackables'] == 'desc:list') { |
|
244 | + $fields .= "|trackables"; |
|
245 | + } elseif ($vars['trackables'] == 'desc:count') { |
|
246 | + $fields .= "|trackables_count"; |
|
247 | + } |
|
248 | + if ($vars['alt_wpts'] == 'true' || $location_source != 'default-coords') { |
|
249 | + $fields .= "|alt_wpts"; |
|
250 | + } |
|
251 | + if ($vars['recommendations'] != 'none') { |
|
252 | + $fields .= "|recommendations|founds"; |
|
253 | + } |
|
254 | + if (count($vars['my_notes']) > 0) { |
|
255 | + $fields .= "|my_notes"; |
|
256 | + } |
|
257 | + if ($vars['latest_logs']) { |
|
258 | + $fields .= "|latest_logs"; |
|
259 | + } |
|
260 | + if ($vars['mark_found']) { |
|
261 | + $fields .= "|is_found"; |
|
262 | + } |
|
229 | 263 | |
230 | 264 | $vars['caches'] = OkapiServiceRunner::call( |
231 | 265 | 'services/caches/geocaches', new OkapiInternalRequest( |
@@ -346,8 +380,9 @@ discard block |
||
346 | 380 | { |
347 | 381 | foreach ($vars['caches'] as &$cache_ref) |
348 | 382 | { |
349 | - if ($cache_ref['needs_maintenance']) |
|
350 | - $cache_ref['attrnames'][] = 'Needs maintenance'; |
|
383 | + if ($cache_ref['needs_maintenance']) { |
|
384 | + $cache_ref['attrnames'][] = 'Needs maintenance'; |
|
385 | + } |
|
351 | 386 | } |
352 | 387 | } |
353 | 388 | } |
@@ -366,17 +401,19 @@ discard block |
||
366 | 401 | foreach ($vars['caches'] as &$cache_ref) |
367 | 402 | { |
368 | 403 | $dict[$cache_ref['owner']['uuid']] = true; |
369 | - if (isset($cache_ref['latest_logs'])) |
|
370 | - foreach ($cache_ref['latest_logs'] as &$log_ref) |
|
404 | + if (isset($cache_ref['latest_logs'])) { |
|
405 | + foreach ($cache_ref['latest_logs'] as &$log_ref) |
|
371 | 406 | $dict[$log_ref['user']['uuid']] = true; |
407 | + } |
|
372 | 408 | } |
373 | 409 | $rs = Db::query(" |
374 | 410 | select uuid, user_id |
375 | 411 | from user |
376 | 412 | where uuid in ('".implode("','", array_map('\okapi\Db::escape_string', array_keys($dict)))."') |
377 | 413 | "); |
378 | - while ($row = Db::fetch_assoc($rs)) |
|
379 | - $dict[$row['uuid']] = $row['user_id']; |
|
414 | + while ($row = Db::fetch_assoc($rs)) { |
|
415 | + $dict[$row['uuid']] = $row['user_id']; |
|
416 | + } |
|
380 | 417 | $vars['user_uuid_to_internal_id'] = &$dict; |
381 | 418 | unset($dict); |
382 | 419 |
@@ -13,8 +13,6 @@ |
||
13 | 13 | use okapi\BadRequest; |
14 | 14 | use okapi\OkapiInternalRequest; |
15 | 15 | use okapi\OkapiServiceRunner; |
16 | -use okapi\OkapiAccessToken; |
|
17 | -use okapi\services\caches\search\SearchAssistant; |
|
18 | 16 | use okapi\services\attrs\AttrHelper; |
19 | 17 | |
20 | 18 | class WebService |
@@ -453,7 +453,7 @@ discard block |
||
453 | 453 | # OCDE caches can also be indirectly watched by watching cache lists: |
454 | 454 | if (Settings::get('OC_BRANCH') == 'oc.de') |
455 | 455 | { |
456 | - $tmp = Db::select_column(" |
|
456 | + $tmp = Db::select_column(" |
|
457 | 457 | select c.wp_oc |
458 | 458 | from |
459 | 459 | caches c, |
@@ -464,8 +464,8 @@ discard block |
||
464 | 464 | and clw.cache_list_id = cli.cache_list_id |
465 | 465 | and clw.user_id = '".Db::escape_string($request->token->user_id)."' |
466 | 466 | "); |
467 | - foreach ($tmp as $cache_code) |
|
468 | - $tmp2[$cache_code] = true; |
|
467 | + foreach ($tmp as $cache_code) |
|
468 | + $tmp2[$cache_code] = true; |
|
469 | 469 | } |
470 | 470 | |
471 | 471 | foreach ($results as $cache_code => &$result_ref) |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | 'my_notes', 'trackables_count', 'trackables', 'alt_wpts', 'last_found', |
35 | 35 | 'last_modified', 'date_created', 'date_hidden', 'internal_id', 'is_watched', |
36 | 36 | 'is_ignored', 'willattends', 'country', 'state', 'preview_image', |
37 | - 'trip_time', 'trip_distance', 'attribution_note','gc_code', 'hint2', 'hints2', |
|
37 | + 'trip_time', 'trip_distance', 'attribution_note', 'gc_code', 'hint2', 'hints2', |
|
38 | 38 | 'protection_areas', 'short_description', 'short_descriptions', 'needs_maintenance'); |
39 | 39 | |
40 | 40 | public static function call(OkapiRequest $request) |
@@ -51,14 +51,14 @@ discard block |
||
51 | 51 | $cache_codes = explode("|", $cache_codes); |
52 | 52 | |
53 | 53 | if ((count($cache_codes) > 500) && (!$request->skip_limits)) |
54 | - throw new InvalidParam('cache_codes', "Maximum allowed number of referenced ". |
|
55 | - "caches is 500. You provided ".count($cache_codes)." cache codes."); |
|
54 | + throw new InvalidParam('cache_codes', "Maximum allowed number of referenced " . |
|
55 | + "caches is 500. You provided " . count($cache_codes) . " cache codes."); |
|
56 | 56 | if (count($cache_codes) != count(array_unique($cache_codes))) |
57 | 57 | throw new InvalidParam('cache_codes', "Duplicate codes detected (make sure each cache is referenced only once)."); |
58 | 58 | |
59 | 59 | $langpref = $request->get_parameter('langpref'); |
60 | 60 | if (!$langpref) $langpref = "en"; |
61 | - $langpref .= "|".Settings::get('SITELANG'); |
|
61 | + $langpref .= "|" . Settings::get('SITELANG'); |
|
62 | 62 | $langpref = explode("|", $langpref); |
63 | 63 | |
64 | 64 | $fields = $request->get_parameter('fields'); |
@@ -99,12 +99,12 @@ discard block |
||
99 | 99 | throw new InvalidParam('attribution_append'); |
100 | 100 | |
101 | 101 | $log_fields = $request->get_parameter('log_fields'); |
102 | - if (!$log_fields) $log_fields = "uuid|date|user|type|comment"; // validation is done on call |
|
102 | + if (!$log_fields) $log_fields = "uuid|date|user|type|comment"; // validation is done on call |
|
103 | 103 | |
104 | 104 | $user_uuid = $request->get_parameter('user_uuid'); |
105 | 105 | if ($user_uuid != null) |
106 | 106 | { |
107 | - $user_id = Db::select_value("select user_id from user where uuid='".Db::escape_string($user_uuid)."'"); |
|
107 | + $user_id = Db::select_value("select user_id from user where uuid='" . Db::escape_string($user_uuid) . "'"); |
|
108 | 108 | if ($user_id == null) |
109 | 109 | throw new InvalidParam('user_uuid', "User not found."); |
110 | 110 | if (($request->token != null) && ($request->token->user_id != $user_id)) |
@@ -136,7 +136,7 @@ discard block |
||
136 | 136 | throw new BadRequest("When using 'distance' or 'bearing' fields, you have to supply 'my_location' parameter."); |
137 | 137 | $parts = explode('|', $tmp); |
138 | 138 | if (count($parts) != 2) |
139 | - throw new InvalidParam('my_location', "Expecting 2 pipe-separated parts, got ".count($parts)."."); |
|
139 | + throw new InvalidParam('my_location', "Expecting 2 pipe-separated parts, got " . count($parts) . "."); |
|
140 | 140 | foreach ($parts as &$part_ref) |
141 | 141 | { |
142 | 142 | if (!preg_match("/^-?[0-9]+(\.?[0-9]*)$/", $part_ref)) |
@@ -178,7 +178,7 @@ discard block |
||
178 | 178 | caches c |
179 | 179 | left join stat_caches as sc on c.cache_id = sc.cache_id |
180 | 180 | where |
181 | - wp_oc in ('".implode("','", array_map('\okapi\Db::escape_string', $cache_codes))."') |
|
181 | + wp_oc in ('".implode("','", array_map('\okapi\Db::escape_string', $cache_codes)) . "') |
|
182 | 182 | and status in (1,2,3) |
183 | 183 | "); |
184 | 184 | } |
@@ -209,7 +209,7 @@ discard block |
||
209 | 209 | from |
210 | 210 | caches c |
211 | 211 | where |
212 | - wp_oc in ('".implode("','", array_map('\okapi\Db::escape_string', $cache_codes))."') |
|
212 | + wp_oc in ('".implode("','", array_map('\okapi\Db::escape_string', $cache_codes)) . "') |
|
213 | 213 | and c.status in (1,2,3) |
214 | 214 | "); |
215 | 215 | } |
@@ -239,11 +239,11 @@ discard block |
||
239 | 239 | break; |
240 | 240 | case 'name': $entry['name'] = $row['name']; break; |
241 | 241 | case 'names': $entry['names'] = array(Settings::get('SITELANG') => $row['name']); break; // for the future |
242 | - case 'location': $entry['location'] = round($row['latitude'], 6)."|".round($row['longitude'], 6); break; |
|
242 | + case 'location': $entry['location'] = round($row['latitude'], 6) . "|" . round($row['longitude'], 6); break; |
|
243 | 243 | case 'type': $entry['type'] = Okapi::cache_type_id2name($row['type']); break; |
244 | 244 | case 'status': $entry['status'] = Okapi::cache_status_id2name($row['status']); break; |
245 | 245 | case 'needs_maintenance': $entry['needs_maintenance'] = $row['needs_maintenance'] > 0; break; |
246 | - case 'url': $entry['url'] = Settings::get('SITE_URL')."viewcache.php?wp=".$row['wp_oc']; break; |
|
246 | + case 'url': $entry['url'] = Settings::get('SITE_URL') . "viewcache.php?wp=" . $row['wp_oc']; break; |
|
247 | 247 | case 'owner': |
248 | 248 | $owner_ids[$row['wp_oc']] = $row['user_id']; |
249 | 249 | /* continued later */ |
@@ -253,7 +253,7 @@ discard block |
||
253 | 253 | break; |
254 | 254 | case 'bearing': |
255 | 255 | $tmp = Okapi::get_bearing($center_lat, $center_lon, $row['latitude'], $row['longitude']); |
256 | - $entry['bearing'] = ($tmp !== null) ? ((int)(10*$tmp)) / 10.0 : null; |
|
256 | + $entry['bearing'] = ($tmp !== null) ? ((int)(10 * $tmp)) / 10.0 : null; |
|
257 | 257 | break; |
258 | 258 | case 'bearing2': |
259 | 259 | $tmp = Okapi::get_bearing($center_lat, $center_lon, $row['latitude'], $row['longitude']); |
@@ -287,13 +287,13 @@ discard block |
||
287 | 287 | switch (Okapi::cache_sizeid_to_size2($row['size'])) |
288 | 288 | { |
289 | 289 | case 'none': $entry['size'] = null; break; |
290 | - case 'nano': $entry['size'] = 1.0; break; # same as micro |
|
290 | + case 'nano': $entry['size'] = 1.0; break; # same as micro |
|
291 | 291 | case 'micro': $entry['size'] = 1.0; break; |
292 | 292 | case 'small': $entry['size'] = 2.0; break; |
293 | 293 | case 'regular': $entry['size'] = 3.0; break; |
294 | 294 | case 'large': $entry['size'] = 4.0; break; |
295 | 295 | case 'xlarge': $entry['size'] = 5.0; break; |
296 | - case 'other': $entry['size'] = null; break; # same as none |
|
296 | + case 'other': $entry['size'] = null; break; # same as none |
|
297 | 297 | default: throw new Exception(); |
298 | 298 | } |
299 | 299 | break; |
@@ -304,12 +304,12 @@ discard block |
||
304 | 304 | case 'trip_time': |
305 | 305 | # search time is entered in hours:minutes and converted to decimal hours, |
306 | 306 | # which can produce lots of unneeded decimal places; 2 of them are sufficient here |
307 | - $entry['trip_time'] = $row['trip_time'] === null ? null : round($row['trip_time'],2); break; |
|
307 | + $entry['trip_time'] = $row['trip_time'] === null ? null : round($row['trip_time'], 2); break; |
|
308 | 308 | break; |
309 | 309 | case 'trip_distance': |
310 | 310 | # way length is entered in km as decimal fraction, but number conversions can |
311 | 311 | # create fake digits which should be stripped; meter precision is sufficient here |
312 | - $entry['trip_distance'] = $row['trip_distance'] === null ? null : round($row['trip_distance'],3); break; |
|
312 | + $entry['trip_distance'] = $row['trip_distance'] === null ? null : round($row['trip_distance'], 3); break; |
|
313 | 313 | break; |
314 | 314 | case 'rating': |
315 | 315 | if ($row['votes'] < 3) $entry['rating'] = null; |
@@ -348,7 +348,7 @@ discard block |
||
348 | 348 | case 'internal_id': $entry['internal_id'] = $row['cache_id']; break; |
349 | 349 | case 'attribution_note': /* handled separately */ break; |
350 | 350 | case 'protection_areas': /* handled separately */ break; |
351 | - default: throw new Exception("Missing field case: ".$field); |
|
351 | + default: throw new Exception("Missing field case: " . $field); |
|
352 | 352 | } |
353 | 353 | } |
354 | 354 | $results[$row['wp_oc']] = $entry; |
@@ -364,7 +364,7 @@ discard block |
||
364 | 364 | $rs = Db::query(" |
365 | 365 | select user_id, uuid, username |
366 | 366 | from user |
367 | - where user_id in ('".implode("','", array_map('\okapi\Db::escape_string', array_values($owner_ids)))."') |
|
367 | + where user_id in ('".implode("','", array_map('\okapi\Db::escape_string', array_values($owner_ids))) . "') |
|
368 | 368 | "); |
369 | 369 | $tmp = array(); |
370 | 370 | while ($row = Db::fetch_assoc($rs)) |
@@ -375,7 +375,7 @@ discard block |
||
375 | 375 | $result_ref['owner'] = array( |
376 | 376 | 'uuid' => $row['uuid'], |
377 | 377 | 'username' => $row['username'], |
378 | - 'profile_url' => Settings::get('SITE_URL')."viewprofile.php?userid=".$row['user_id'] |
|
378 | + 'profile_url' => Settings::get('SITE_URL') . "viewprofile.php?userid=" . $row['user_id'] |
|
379 | 379 | ); |
380 | 380 | } |
381 | 381 | } |
@@ -394,11 +394,11 @@ discard block |
||
394 | 394 | where |
395 | 395 | c.cache_id = cl.cache_id |
396 | 396 | and cl.type in ( |
397 | - '".Db::escape_string(Okapi::logtypename2id("Found it"))."', |
|
398 | - '".Db::escape_string(Okapi::logtypename2id("Attended"))."' |
|
397 | + '".Db::escape_string(Okapi::logtypename2id("Found it")) . "', |
|
398 | + '".Db::escape_string(Okapi::logtypename2id("Attended")) . "' |
|
399 | 399 | ) |
400 | - and cl.user_id = '".Db::escape_string($user_id)."' |
|
401 | - ".((Settings::get('OC_BRANCH') == 'oc.pl') ? "and cl.deleted = 0" : "")." |
|
400 | + and cl.user_id = '".Db::escape_string($user_id) . "' |
|
401 | + ".((Settings::get('OC_BRANCH') == 'oc.pl') ? "and cl.deleted = 0" : "") . " |
|
402 | 402 | "); |
403 | 403 | $tmp2 = array(); |
404 | 404 | foreach ($tmp as $cache_code) |
@@ -420,9 +420,9 @@ discard block |
||
420 | 420 | cache_logs cl |
421 | 421 | where |
422 | 422 | c.cache_id = cl.cache_id |
423 | - and cl.type = '".Db::escape_string(Okapi::logtypename2id("Didn't find it"))."' |
|
424 | - and cl.user_id = '".Db::escape_string($user_id)."' |
|
425 | - ".((Settings::get('OC_BRANCH') == 'oc.pl') ? "and cl.deleted = 0" : "")." |
|
423 | + and cl.type = '".Db::escape_string(Okapi::logtypename2id("Didn't find it")) . "' |
|
424 | + and cl.user_id = '".Db::escape_string($user_id) . "' |
|
425 | + ".((Settings::get('OC_BRANCH') == 'oc.pl') ? "and cl.deleted = 0" : "") . " |
|
426 | 426 | "); |
427 | 427 | $tmp2 = array(); |
428 | 428 | foreach ($tmp as $cache_code) |
@@ -444,7 +444,7 @@ discard block |
||
444 | 444 | cache_watches cw |
445 | 445 | where |
446 | 446 | c.cache_id = cw.cache_id |
447 | - and cw.user_id = '".Db::escape_string($request->token->user_id)."' |
|
447 | + and cw.user_id = '".Db::escape_string($request->token->user_id) . "' |
|
448 | 448 | "); |
449 | 449 | $tmp2 = array(); |
450 | 450 | foreach ($tmp as $cache_code) |
@@ -462,7 +462,7 @@ discard block |
||
462 | 462 | where |
463 | 463 | cli.cache_id = c.cache_id |
464 | 464 | and clw.cache_list_id = cli.cache_list_id |
465 | - and clw.user_id = '".Db::escape_string($request->token->user_id)."' |
|
465 | + and clw.user_id = '".Db::escape_string($request->token->user_id) . "' |
|
466 | 466 | "); |
467 | 467 | foreach ($tmp as $cache_code) |
468 | 468 | $tmp2[$cache_code] = true; |
@@ -485,7 +485,7 @@ discard block |
||
485 | 485 | cache_ignore ci |
486 | 486 | where |
487 | 487 | c.cache_id = ci.cache_id |
488 | - and ci.user_id = '".Db::escape_string($request->token->user_id)."' |
|
488 | + and ci.user_id = '".Db::escape_string($request->token->user_id) . "' |
|
489 | 489 | "); |
490 | 490 | $tmp2 = array(); |
491 | 491 | foreach ($tmp as $cache_code) |
@@ -517,7 +517,7 @@ discard block |
||
517 | 517 | $rs = Db::query(" |
518 | 518 | select cache_id, language, `desc`, short_desc, hint |
519 | 519 | from cache_desc |
520 | - where cache_id in ('".implode("','", array_map('\okapi\Db::escape_string', array_keys($cacheid2wptcode)))."') |
|
520 | + where cache_id in ('".implode("','", array_map('\okapi\Db::escape_string', array_keys($cacheid2wptcode))) . "') |
|
521 | 521 | "); |
522 | 522 | while ($row = Db::fetch_assoc($rs)) |
523 | 523 | { |
@@ -534,11 +534,11 @@ discard block |
||
534 | 534 | { |
535 | 535 | Okapi::gettext_domain_init(array_merge(array($row['language']), $langpref)); |
536 | 536 | $tmp = ( |
537 | - "<p style='color:#c00000'><strong>". |
|
538 | - _('Parts of this geocache listing may be outdated.'). |
|
539 | - "</strong> ". |
|
540 | - _('See the log entries for more information.'). |
|
541 | - "</p>\n". |
|
537 | + "<p style='color:#c00000'><strong>" . |
|
538 | + _('Parts of this geocache listing may be outdated.') . |
|
539 | + "</strong> " . |
|
540 | + _('See the log entries for more information.') . |
|
541 | + "</p>\n" . |
|
542 | 542 | $tmp |
543 | 543 | ); |
544 | 544 | Okapi::gettext_domain_restore(); |
@@ -546,11 +546,11 @@ discard block |
||
546 | 546 | |
547 | 547 | if ($attribution_append != 'none') |
548 | 548 | { |
549 | - $tmp .= "\n<p><em>". |
|
549 | + $tmp .= "\n<p><em>" . |
|
550 | 550 | self::get_cache_attribution_note( |
551 | 551 | $row['cache_id'], strtolower($row['language']), $langpref, |
552 | 552 | $results[$cache_code]['owner'], $attribution_append |
553 | - ). |
|
553 | + ) . |
|
554 | 554 | "</em></p>"; |
555 | 555 | } |
556 | 556 | $results[$cache_code]['descriptions'][strtolower($row['language'])] = $tmp; |
@@ -563,7 +563,7 @@ discard block |
||
563 | 563 | { |
564 | 564 | $results[$cache_code]['hints'][strtolower($row['language'])] = $row['hint']; |
565 | 565 | $results[$cache_code]['hints2'][strtolower($row['language'])] |
566 | - = htmlspecialchars_decode(mb_ereg_replace("<br />", "" , $row['hint']), ENT_COMPAT); |
|
566 | + = htmlspecialchars_decode(mb_ereg_replace("<br />", "", $row['hint']), ENT_COMPAT); |
|
567 | 567 | } |
568 | 568 | } |
569 | 569 | foreach ($results as &$result_ref) |
@@ -601,10 +601,10 @@ discard block |
||
601 | 601 | else |
602 | 602 | $preview_field = "0"; |
603 | 603 | $rs = Db::query(" |
604 | - select object_id, uuid, url, title, spoiler, ".$preview_field." as preview |
|
604 | + select object_id, uuid, url, title, spoiler, ".$preview_field . " as preview |
|
605 | 605 | from pictures |
606 | 606 | where |
607 | - object_id in ('".implode("','", array_map('\okapi\Db::escape_string', array_keys($cacheid2wptcode)))."') |
|
607 | + object_id in ('".implode("','", array_map('\okapi\Db::escape_string', array_keys($cacheid2wptcode))) . "') |
|
608 | 608 | and display = 1 |
609 | 609 | and object_type = 2 |
610 | 610 | and unknown_format = 0 |
@@ -630,7 +630,7 @@ discard block |
||
630 | 630 | $image = array( |
631 | 631 | 'uuid' => $row['uuid'], |
632 | 632 | 'url' => $row['url'], |
633 | - 'thumb_url' => Settings::get('SITE_URL') . 'thumbs.php?'.$object_type_param.'uuid=' . $row['uuid'], |
|
633 | + 'thumb_url' => Settings::get('SITE_URL') . 'thumbs.php?' . $object_type_param . 'uuid=' . $row['uuid'], |
|
634 | 634 | 'caption' => $row['title'], |
635 | 635 | 'unique_caption' => self::get_unique_caption($row['title']), |
636 | 636 | 'is_spoiler' => ($row['spoiler'] ? true : false), |
@@ -658,13 +658,13 @@ discard block |
||
658 | 658 | |
659 | 659 | # Load internal_attr_id => acode mapping. |
660 | 660 | |
661 | - require_once($GLOBALS['rootpath'].'okapi/services/attrs/attr_helper.inc.php'); |
|
661 | + require_once($GLOBALS['rootpath'] . 'okapi/services/attrs/attr_helper.inc.php'); |
|
662 | 662 | $internal2acode = AttrHelper::get_internal_id_to_acode_mapping(); |
663 | 663 | |
664 | 664 | $rs = Db::query(" |
665 | 665 | select cache_id, attrib_id |
666 | 666 | from caches_attributes |
667 | - where cache_id in ('".implode("','", array_map('\okapi\Db::escape_string', array_keys($cacheid2wptcode)))."') |
|
667 | + where cache_id in ('".implode("','", array_map('\okapi\Db::escape_string', array_keys($cacheid2wptcode))) . "') |
|
668 | 668 | "); |
669 | 669 | while ($row = Db::fetch_assoc($rs)) |
670 | 670 | { |
@@ -721,9 +721,9 @@ discard block |
||
721 | 721 | select cache_id, uuid |
722 | 722 | from cache_logs |
723 | 723 | where |
724 | - cache_id in ('".implode("','", array_map('\okapi\Db::escape_string', array_keys($cacheid2wptcode)))."') |
|
725 | - and ".((Settings::get('OC_BRANCH') == 'oc.pl') ? "deleted = 0" : "true")." |
|
726 | - order by cache_id, ".$logs_order_field_SQL." desc, date_created desc, id desc |
|
724 | + cache_id in ('".implode("','", array_map('\okapi\Db::escape_string', array_keys($cacheid2wptcode))) . "') |
|
725 | + and ".((Settings::get('OC_BRANCH') == 'oc.pl') ? "deleted = 0" : "true") . " |
|
726 | + order by cache_id, ".$logs_order_field_SQL . " desc, date_created desc, id desc |
|
727 | 727 | "); |
728 | 728 | |
729 | 729 | $loguuids = array(); |
@@ -808,8 +808,8 @@ discard block |
||
808 | 808 | select cache_id, max(date) as date, group_concat(`desc`) as `desc` |
809 | 809 | from cache_notes |
810 | 810 | where |
811 | - cache_id in ('".implode("','", array_map('\okapi\Db::escape_string', array_keys($cacheid2wptcode)))."') |
|
812 | - and user_id = '".Db::escape_string($request->token->user_id)."' |
|
811 | + cache_id in ('".implode("','", array_map('\okapi\Db::escape_string', array_keys($cacheid2wptcode))) . "') |
|
812 | + and user_id = '".Db::escape_string($request->token->user_id) . "' |
|
813 | 813 | group by cache_id |
814 | 814 | "); |
815 | 815 | } |
@@ -822,8 +822,8 @@ discard block |
||
822 | 822 | from coordinates |
823 | 823 | where |
824 | 824 | type = 2 -- personal note |
825 | - and cache_id in ('".implode("','", array_map('\okapi\Db::escape_string', array_keys($cacheid2wptcode)))."') |
|
826 | - and user_id = '".Db::escape_string($request->token->user_id)."' |
|
825 | + and cache_id in ('".implode("','", array_map('\okapi\Db::escape_string', array_keys($cacheid2wptcode))) . "') |
|
826 | + and user_id = '".Db::escape_string($request->token->user_id) . "' |
|
827 | 827 | group by cache_id |
828 | 828 | "); |
829 | 829 | } |
@@ -849,7 +849,7 @@ discard block |
||
849 | 849 | gk_item gki |
850 | 850 | where |
851 | 851 | gkiw.id = gki.id |
852 | - and gkiw.wp in ('".implode("','", array_map('\okapi\Db::escape_string', $cache_codes))."') |
|
852 | + and gkiw.wp in ('".implode("','", array_map('\okapi\Db::escape_string', $cache_codes)) . "') |
|
853 | 853 | "); |
854 | 854 | $trs = array(); |
855 | 855 | while ($row = Db::fetch_assoc($rs)) |
@@ -862,9 +862,9 @@ discard block |
||
862 | 862 | foreach ($trs[$cache_code] as $t) |
863 | 863 | { |
864 | 864 | $result_ref['trackables'][] = array( |
865 | - 'code' => 'GK'.str_pad(strtoupper(dechex($t['gk_id'])), 4, "0", STR_PAD_LEFT), |
|
865 | + 'code' => 'GK' . str_pad(strtoupper(dechex($t['gk_id'])), 4, "0", STR_PAD_LEFT), |
|
866 | 866 | 'name' => $t['name'], |
867 | - 'url' => 'http://geokrety.org/konkret.php?id='.$t['gk_id'] |
|
867 | + 'url' => 'http://geokrety.org/konkret.php?id=' . $t['gk_id'] |
|
868 | 868 | ); |
869 | 869 | } |
870 | 870 | } |
@@ -883,7 +883,7 @@ discard block |
||
883 | 883 | $rs = Db::query(" |
884 | 884 | select wp as cache_code, count(*) as count |
885 | 885 | from gk_item_waypoint |
886 | - where wp in ('".implode("','", array_map('\okapi\Db::escape_string', $cache_codes))."') |
|
886 | + where wp in ('".implode("','", array_map('\okapi\Db::escape_string', $cache_codes)) . "') |
|
887 | 887 | group by wp |
888 | 888 | "); |
889 | 889 | $tr_counts = new ArrayObject(); |
@@ -936,7 +936,7 @@ discard block |
||
936 | 936 | |
937 | 937 | foreach ($results as &$result_ref) |
938 | 938 | $result_ref['alt_wpts'] = array(); |
939 | - $cache_codes_escaped_and_imploded = "'".implode("','", array_map('\okapi\Db::escape_string', array_keys($cacheid2wptcode)))."'"; |
|
939 | + $cache_codes_escaped_and_imploded = "'" . implode("','", array_map('\okapi\Db::escape_string', array_keys($cacheid2wptcode))) . "'"; |
|
940 | 940 | |
941 | 941 | if (Settings::get('OC_BRANCH') == 'oc.pl') |
942 | 942 | { |
@@ -966,7 +966,7 @@ discard block |
||
966 | 966 | end as okapi_type |
967 | 967 | from waypoints |
968 | 968 | where |
969 | - cache_id in (".$cache_codes_escaped_and_imploded.") |
|
969 | + cache_id in (".$cache_codes_escaped_and_imploded . ") |
|
970 | 970 | and status = 1 |
971 | 971 | order by cache_id, stage, `desc` |
972 | 972 | "); |
@@ -1002,7 +1002,7 @@ discard block |
||
1002 | 1002 | from coordinates |
1003 | 1003 | where |
1004 | 1004 | type = 1 |
1005 | - and cache_id in (".$cache_codes_escaped_and_imploded.") |
|
1005 | + and cache_id in (".$cache_codes_escaped_and_imploded . ") |
|
1006 | 1006 | order by cache_id, id |
1007 | 1007 | "); |
1008 | 1008 | } |
@@ -1010,7 +1010,7 @@ discard block |
||
1010 | 1010 | foreach ($cacheid2waypoints as $cache_id => $waypoints) |
1011 | 1011 | { |
1012 | 1012 | $cache_code = $cacheid2wptcode[$cache_id]; |
1013 | - $wpt_format = $cache_code."-%0".strlen(count($waypoints))."d"; |
|
1013 | + $wpt_format = $cache_code . "-%0" . strlen(count($waypoints)) . "d"; |
|
1014 | 1014 | $index = 0; |
1015 | 1015 | foreach ($waypoints as $row) |
1016 | 1016 | { |
@@ -1023,11 +1023,11 @@ discard block |
||
1023 | 1023 | $index++; |
1024 | 1024 | $results[$cache_code]['alt_wpts'][] = array( |
1025 | 1025 | 'name' => sprintf($wpt_format, $index), |
1026 | - 'location' => round($row['latitude'], 6)."|".round($row['longitude'], 6), |
|
1026 | + 'location' => round($row['latitude'], 6) . "|" . round($row['longitude'], 6), |
|
1027 | 1027 | 'type' => $row['okapi_type'], |
1028 | 1028 | 'type_name' => Okapi::pick_best_language($internal_wpt_type_id2names[$row['internal_type_id']], $langpref), |
1029 | 1029 | 'sym' => $row['sym'], |
1030 | - 'description' => ($row['stage'] ? _("Stage")." ".$row['stage'].": " : "").$row['desc'], |
|
1030 | + 'description' => ($row['stage'] ? _("Stage") . " " . $row['stage'] . ": " : "") . $row['desc'], |
|
1031 | 1031 | ); |
1032 | 1032 | } |
1033 | 1033 | } |
@@ -1045,7 +1045,7 @@ discard block |
||
1045 | 1045 | from cache_mod_cords |
1046 | 1046 | where |
1047 | 1047 | cache_id in ($cache_codes_escaped_and_imploded) |
1048 | - and user_id = '".Db::escape_string($request->token->user_id)."' |
|
1048 | + and user_id = '" . Db::escape_string($request->token->user_id) . "' |
|
1049 | 1049 | "); |
1050 | 1050 | } else { |
1051 | 1051 | # oc.de |
@@ -1055,7 +1055,7 @@ discard block |
||
1055 | 1055 | from coordinates |
1056 | 1056 | where |
1057 | 1057 | cache_id in ($cache_codes_escaped_and_imploded) |
1058 | - and user_id = '".Db::escape_string($request->token->user_id)."' |
|
1058 | + and user_id = '" . Db::escape_string($request->token->user_id) . "' |
|
1059 | 1059 | and type = 2 |
1060 | 1060 | and longitude != 0 |
1061 | 1061 | and latitude != 0 |
@@ -1068,8 +1068,8 @@ discard block |
||
1068 | 1068 | { |
1069 | 1069 | # there should be only one user waypoint per cache... |
1070 | 1070 | $results[$cache_code]['alt_wpts'][] = array( |
1071 | - 'name' => $cache_code.'-USER-COORDS', |
|
1072 | - 'location' => round($row['latitude'], 6)."|".round($row['longitude'], 6), |
|
1071 | + 'name' => $cache_code . '-USER-COORDS', |
|
1072 | + 'location' => round($row['latitude'], 6) . "|" . round($row['longitude'], 6), |
|
1073 | 1073 | 'type' => 'user-coords', |
1074 | 1074 | 'type_name' => _("User location"), |
1075 | 1075 | 'sym' => 'Block, Green', |
@@ -1114,7 +1114,7 @@ discard block |
||
1114 | 1114 | inner join countries on countries.short=c.country |
1115 | 1115 | inner join sys_trans_text stt on stt.trans_id = countries.trans_id |
1116 | 1116 | where |
1117 | - c.wp_oc in ('".implode("','", array_map('\okapi\Db::escape_string', $cache_codes))."') |
|
1117 | + c.wp_oc in ('".implode("','", array_map('\okapi\Db::escape_string', $cache_codes)) . "') |
|
1118 | 1118 | "); |
1119 | 1119 | $country_codes2names = array(); |
1120 | 1120 | while ($row = Db::fetch_assoc($rs)) |
@@ -1131,7 +1131,7 @@ discard block |
||
1131 | 1131 | caches c |
1132 | 1132 | left join cache_location cl on c.cache_id = cl.cache_id |
1133 | 1133 | where |
1134 | - c.wp_oc in ('".implode("','", array_map('\okapi\Db::escape_string', $cache_codes))."') |
|
1134 | + c.wp_oc in ('".implode("','", array_map('\okapi\Db::escape_string', $cache_codes)) . "') |
|
1135 | 1135 | "); |
1136 | 1136 | while ($row = Db::fetch_assoc($rs)) |
1137 | 1137 | { |
@@ -1159,7 +1159,7 @@ discard block |
||
1159 | 1159 | caches c, |
1160 | 1160 | cache_location cl |
1161 | 1161 | where |
1162 | - c.wp_oc in ('".implode("','", array_map('\okapi\Db::escape_string', $cache_codes))."') |
|
1162 | + c.wp_oc in ('".implode("','", array_map('\okapi\Db::escape_string', $cache_codes)) . "') |
|
1163 | 1163 | and c.cache_id = cl.cache_id |
1164 | 1164 | "); |
1165 | 1165 | while ($row = Db::fetch_assoc($rs)) |
@@ -1203,7 +1203,7 @@ discard block |
||
1203 | 1203 | |
1204 | 1204 | if (in_array('protection_areas', $fields)) |
1205 | 1205 | { |
1206 | - $cache_ids_escaped_and_imploded = "'".implode("','", array_map('\okapi\Db::escape_string', array_keys($cacheid2wptcode)))."'"; |
|
1206 | + $cache_ids_escaped_and_imploded = "'" . implode("','", array_map('\okapi\Db::escape_string', array_keys($cacheid2wptcode))) . "'"; |
|
1207 | 1207 | |
1208 | 1208 | if (Settings::get('OC_BRANCH') == 'oc.de') |
1209 | 1209 | { |
@@ -1218,7 +1218,7 @@ discard block |
||
1218 | 1218 | inner join npa_areas on cache_npa_areas.npa_id = npa_areas.id |
1219 | 1219 | inner join npa_types on npa_areas.type_id = npa_types.id |
1220 | 1220 | where |
1221 | - c.cache_id in (".$cache_ids_escaped_and_imploded.") |
|
1221 | + c.cache_id in (".$cache_ids_escaped_and_imploded . ") |
|
1222 | 1222 | group by npa_areas.type_id, npa_areas.name |
1223 | 1223 | order by npa_types.ordinal |
1224 | 1224 | "); |
@@ -1233,14 +1233,14 @@ discard block |
||
1233 | 1233 | $rs = Db::query(" |
1234 | 1234 | select |
1235 | 1235 | c.wp_oc as cache_code, |
1236 | - '"._('National Park / Landscape')."' as type, |
|
1236 | + '"._('National Park / Landscape') . "' as type, |
|
1237 | 1237 | CONVERT(parkipl.name USING utf8) as name |
1238 | 1238 | from |
1239 | 1239 | caches c |
1240 | 1240 | inner join cache_npa_areas on cache_npa_areas.cache_id=c.cache_id |
1241 | 1241 | inner join parkipl on cache_npa_areas.parki_id=parkipl.id |
1242 | 1242 | where |
1243 | - c.cache_id in (".$cache_ids_escaped_and_imploded.") |
|
1243 | + c.cache_id in (".$cache_ids_escaped_and_imploded . ") |
|
1244 | 1244 | and cache_npa_areas.parki_id != 0 |
1245 | 1245 | union |
1246 | 1246 | select |
@@ -1252,7 +1252,7 @@ discard block |
||
1252 | 1252 | inner join cache_npa_areas on cache_npa_areas.cache_id=c.cache_id |
1253 | 1253 | inner join npa_areas on cache_npa_areas.npa_id=npa_areas.id |
1254 | 1254 | where |
1255 | - c.cache_id in (".$cache_ids_escaped_and_imploded.") |
|
1255 | + c.cache_id in (".$cache_ids_escaped_and_imploded . ") |
|
1256 | 1256 | and cache_npa_areas.npa_id != 0 |
1257 | 1257 | "); |
1258 | 1258 | } |
@@ -1321,7 +1321,7 @@ discard block |
||
1321 | 1321 | 'description', 'descriptions' |
1322 | 1322 | ), $fields)) > 0) |
1323 | 1323 | ) { |
1324 | - require_once($GLOBALS['rootpath'].'okapi/lib/ocpl_access_logs.php'); |
|
1324 | + require_once($GLOBALS['rootpath'] . 'okapi/lib/ocpl_access_logs.php'); |
|
1325 | 1325 | \okapi\OCPLAccessLogs::log_geocache_access($request, $cache_ids); |
1326 | 1326 | } |
1327 | 1327 | } |
@@ -1340,7 +1340,7 @@ discard block |
||
1340 | 1340 | # Garmin and cannot determine WHY. That's why we won't use captions until we |
1341 | 1341 | # know more. |
1342 | 1342 | |
1343 | - $caption = self::$caption_no.""; |
|
1343 | + $caption = self::$caption_no . ""; |
|
1344 | 1344 | self::$caption_no++; |
1345 | 1345 | return $caption; |
1346 | 1346 | |
@@ -1404,7 +1404,7 @@ discard block |
||
1404 | 1404 | # which replicates geocaches! |
1405 | 1405 | |
1406 | 1406 | $site_name = Okapi::get_normalized_site_name(); |
1407 | - $cache_url = $site_url."viewcache.php?cacheid=$cache_id"; |
|
1407 | + $cache_url = $site_url . "viewcache.php?cacheid=$cache_id"; |
|
1408 | 1408 | |
1409 | 1409 | Okapi::gettext_domain_init(array_merge(array($lang), $langpref)); |
1410 | 1410 | if (Settings::get('OC_BRANCH') == 'oc.pl') |
@@ -1424,8 +1424,8 @@ discard block |
||
1424 | 1424 | { |
1425 | 1425 | $note = sprintf( |
1426 | 1426 | _( |
1427 | - "© <a href='%s'>%s</a>, <a href='%s'>%s</a>, ". |
|
1428 | - "<a href='http://creativecommons.org/licenses/by-nc-nd/3.0/de/deed.en'>CC-BY-NC-ND</a>, ". |
|
1427 | + "© <a href='%s'>%s</a>, <a href='%s'>%s</a>, " . |
|
1428 | + "<a href='http://creativecommons.org/licenses/by-nc-nd/3.0/de/deed.en'>CC-BY-NC-ND</a>, " . |
|
1429 | 1429 | "as of %s; all log entries © their authors" |
1430 | 1430 | ), |
1431 | 1431 | $owner['profile_url'], $owner['username'], $cache_url, $site_name, strftime('%x') |
@@ -1435,8 +1435,8 @@ discard block |
||
1435 | 1435 | { |
1436 | 1436 | $note = sprintf( |
1437 | 1437 | _( |
1438 | - "© <a href='%s'>%s</a>, <a href='%s'>%s</a>, ". |
|
1439 | - "<a href='http://creativecommons.org/licenses/by-nc-nd/3.0/de/deed.en'>CC-BY-NC-ND</a>; ". |
|
1438 | + "© <a href='%s'>%s</a>, <a href='%s'>%s</a>, " . |
|
1439 | + "<a href='http://creativecommons.org/licenses/by-nc-nd/3.0/de/deed.en'>CC-BY-NC-ND</a>; " . |
|
1440 | 1440 | "all log entries © their authors" |
1441 | 1441 | ), |
1442 | 1442 | $owner['profile_url'], $owner['username'], $cache_url, $site_name |
@@ -40,33 +40,42 @@ discard block |
||
40 | 40 | public static function call(OkapiRequest $request) |
41 | 41 | { |
42 | 42 | $cache_codes = $request->get_parameter('cache_codes'); |
43 | - if ($cache_codes === null) throw new ParamMissing('cache_codes'); |
|
43 | + if ($cache_codes === null) { |
|
44 | + throw new ParamMissing('cache_codes'); |
|
45 | + } |
|
44 | 46 | if ($cache_codes === "") |
45 | 47 | { |
46 | 48 | # Issue 106 requires us to allow empty list of cache codes to be passed into this method. |
47 | 49 | # All of the queries below have to be ready for $cache_codes to be empty! |
48 | 50 | $cache_codes = array(); |
51 | + } else { |
|
52 | + $cache_codes = explode("|", $cache_codes); |
|
49 | 53 | } |
50 | - else |
|
51 | - $cache_codes = explode("|", $cache_codes); |
|
52 | 54 | |
53 | - if ((count($cache_codes) > 500) && (!$request->skip_limits)) |
|
54 | - throw new InvalidParam('cache_codes', "Maximum allowed number of referenced ". |
|
55 | + if ((count($cache_codes) > 500) && (!$request->skip_limits)) { |
|
56 | + throw new InvalidParam('cache_codes', "Maximum allowed number of referenced ". |
|
55 | 57 | "caches is 500. You provided ".count($cache_codes)." cache codes."); |
56 | - if (count($cache_codes) != count(array_unique($cache_codes))) |
|
57 | - throw new InvalidParam('cache_codes', "Duplicate codes detected (make sure each cache is referenced only once)."); |
|
58 | + } |
|
59 | + if (count($cache_codes) != count(array_unique($cache_codes))) { |
|
60 | + throw new InvalidParam('cache_codes', "Duplicate codes detected (make sure each cache is referenced only once)."); |
|
61 | + } |
|
58 | 62 | |
59 | 63 | $langpref = $request->get_parameter('langpref'); |
60 | - if (!$langpref) $langpref = "en"; |
|
64 | + if (!$langpref) { |
|
65 | + $langpref = "en"; |
|
66 | + } |
|
61 | 67 | $langpref .= "|".Settings::get('SITELANG'); |
62 | 68 | $langpref = explode("|", $langpref); |
63 | 69 | |
64 | 70 | $fields = $request->get_parameter('fields'); |
65 | - if (!$fields) $fields = "code|name|location|type|status"; |
|
71 | + if (!$fields) { |
|
72 | + $fields = "code|name|location|type|status"; |
|
73 | + } |
|
66 | 74 | $fields = explode("|", $fields); |
67 | - foreach ($fields as $field) |
|
68 | - if (!in_array($field, self::$valid_field_names)) |
|
75 | + foreach ($fields as $field) { |
|
76 | + if (!in_array($field, self::$valid_field_names)) |
|
69 | 77 | throw new InvalidParam('fields', "'$field' is not a valid field code."); |
78 | + } |
|
70 | 79 | |
71 | 80 | # Some fields need to be temporarily included whenever the "description" |
72 | 81 | # or "attribution_note" field are included. That's a little ugly, but |
@@ -94,60 +103,77 @@ discard block |
||
94 | 103 | } |
95 | 104 | |
96 | 105 | $attribution_append = $request->get_parameter('attribution_append'); |
97 | - if (!$attribution_append) $attribution_append = 'full'; |
|
98 | - if (!in_array($attribution_append, array('none', 'static', 'full'))) |
|
99 | - throw new InvalidParam('attribution_append'); |
|
106 | + if (!$attribution_append) { |
|
107 | + $attribution_append = 'full'; |
|
108 | + } |
|
109 | + if (!in_array($attribution_append, array('none', 'static', 'full'))) { |
|
110 | + throw new InvalidParam('attribution_append'); |
|
111 | + } |
|
100 | 112 | |
101 | 113 | $log_fields = $request->get_parameter('log_fields'); |
102 | - if (!$log_fields) $log_fields = "uuid|date|user|type|comment"; // validation is done on call |
|
114 | + if (!$log_fields) { |
|
115 | + $log_fields = "uuid|date|user|type|comment"; |
|
116 | + } |
|
117 | + // validation is done on call |
|
103 | 118 | |
104 | 119 | $user_uuid = $request->get_parameter('user_uuid'); |
105 | 120 | if ($user_uuid != null) |
106 | 121 | { |
107 | 122 | $user_id = Db::select_value("select user_id from user where uuid='".Db::escape_string($user_uuid)."'"); |
108 | - if ($user_id == null) |
|
109 | - throw new InvalidParam('user_uuid', "User not found."); |
|
110 | - if (($request->token != null) && ($request->token->user_id != $user_id)) |
|
111 | - throw new InvalidParam('user_uuid', "User does not match the Access Token used."); |
|
123 | + if ($user_id == null) { |
|
124 | + throw new InvalidParam('user_uuid', "User not found."); |
|
125 | + } |
|
126 | + if (($request->token != null) && ($request->token->user_id != $user_id)) { |
|
127 | + throw new InvalidParam('user_uuid', "User does not match the Access Token used."); |
|
128 | + } |
|
129 | + } elseif (($user_uuid == null) && ($request->token != null)) { |
|
130 | + $user_id = $request->token->user_id; |
|
131 | + } else { |
|
132 | + $user_id = null; |
|
112 | 133 | } |
113 | - elseif (($user_uuid == null) && ($request->token != null)) |
|
114 | - $user_id = $request->token->user_id; |
|
115 | - else |
|
116 | - $user_id = null; |
|
117 | 134 | |
118 | 135 | $lpc = $request->get_parameter('lpc'); |
119 | - if ($lpc === null) $lpc = 10; |
|
120 | - if ($lpc == 'all') |
|
121 | - $lpc = null; |
|
122 | - else |
|
136 | + if ($lpc === null) { |
|
137 | + $lpc = 10; |
|
138 | + } |
|
139 | + if ($lpc == 'all') { |
|
140 | + $lpc = null; |
|
141 | + } else |
|
123 | 142 | { |
124 | - if (!is_numeric($lpc)) |
|
125 | - throw new InvalidParam('lpc', "Invalid number: '$lpc'"); |
|
143 | + if (!is_numeric($lpc)) { |
|
144 | + throw new InvalidParam('lpc', "Invalid number: '$lpc'"); |
|
145 | + } |
|
126 | 146 | $lpc = intval($lpc); |
127 | - if ($lpc < 0) |
|
128 | - throw new InvalidParam('lpc', "Must be a positive value."); |
|
147 | + if ($lpc < 0) { |
|
148 | + throw new InvalidParam('lpc', "Must be a positive value."); |
|
149 | + } |
|
129 | 150 | } |
130 | 151 | |
131 | 152 | if (in_array('distance', $fields) || in_array('bearing', $fields) || in_array('bearing2', $fields) |
132 | 153 | || in_array('bearing3', $fields)) |
133 | 154 | { |
134 | 155 | $tmp = $request->get_parameter('my_location'); |
135 | - if (!$tmp) |
|
136 | - throw new BadRequest("When using 'distance' or 'bearing' fields, you have to supply 'my_location' parameter."); |
|
156 | + if (!$tmp) { |
|
157 | + throw new BadRequest("When using 'distance' or 'bearing' fields, you have to supply 'my_location' parameter."); |
|
158 | + } |
|
137 | 159 | $parts = explode('|', $tmp); |
138 | - if (count($parts) != 2) |
|
139 | - throw new InvalidParam('my_location', "Expecting 2 pipe-separated parts, got ".count($parts)."."); |
|
160 | + if (count($parts) != 2) { |
|
161 | + throw new InvalidParam('my_location', "Expecting 2 pipe-separated parts, got ".count($parts)."."); |
|
162 | + } |
|
140 | 163 | foreach ($parts as &$part_ref) |
141 | 164 | { |
142 | - if (!preg_match("/^-?[0-9]+(\.?[0-9]*)$/", $part_ref)) |
|
143 | - throw new InvalidParam('my_location', "'$part_ref' is not a valid float number."); |
|
165 | + if (!preg_match("/^-?[0-9]+(\.?[0-9]*)$/", $part_ref)) { |
|
166 | + throw new InvalidParam('my_location', "'$part_ref' is not a valid float number."); |
|
167 | + } |
|
144 | 168 | $part_ref = floatval($part_ref); |
145 | 169 | } |
146 | 170 | list($center_lat, $center_lon) = $parts; |
147 | - if ($center_lat > 90 || $center_lat < -90) |
|
148 | - throw new InvalidParam('current_position', "Latitudes have to be within -90..90 range."); |
|
149 | - if ($center_lon > 180 || $center_lon < -180) |
|
150 | - throw new InvalidParam('current_position', "Longitudes have to be within -180..180 range."); |
|
171 | + if ($center_lat > 90 || $center_lat < -90) { |
|
172 | + throw new InvalidParam('current_position', "Latitudes have to be within -90..90 range."); |
|
173 | + } |
|
174 | + if ($center_lon > 180 || $center_lon < -180) { |
|
175 | + throw new InvalidParam('current_position', "Longitudes have to be within -180..180 range."); |
|
176 | + } |
|
151 | 177 | } |
152 | 178 | |
153 | 179 | if (Settings::get('OC_BRANCH') == 'oc.de') |
@@ -181,8 +207,7 @@ discard block |
||
181 | 207 | wp_oc in ('".implode("','", array_map('\okapi\Db::escape_string', $cache_codes))."') |
182 | 208 | and status in (1,2,3) |
183 | 209 | "); |
184 | - } |
|
185 | - elseif (Settings::get('OC_BRANCH') == 'oc.pl') |
|
210 | + } elseif (Settings::get('OC_BRANCH') == 'oc.pl') |
|
186 | 211 | { |
187 | 212 | # PL branch: |
188 | 213 | # - Caches have ratings. |
@@ -231,10 +256,11 @@ discard block |
||
231 | 256 | $wp_gc = $row['wp_gc_maintained'] ? $row['wp_gc_maintained'] : $row['wp_gc']; |
232 | 257 | // OC software allows entering anything here, and that's what users do. |
233 | 258 | // We do a formal verification so that only a valid GC code is returned: |
234 | - if (preg_match('/^\s*[Gg][Cc][A-Za-z0-9]+\s*$/', $wp_gc)) |
|
235 | - $entry['gc_code'] = strtoupper(trim($wp_gc)); |
|
236 | - else |
|
237 | - $entry['gc_code'] = null; |
|
259 | + if (preg_match('/^\s*[Gg][Cc][A-Za-z0-9]+\s*$/', $wp_gc)) { |
|
260 | + $entry['gc_code'] = strtoupper(trim($wp_gc)); |
|
261 | + } else { |
|
262 | + $entry['gc_code'] = null; |
|
263 | + } |
|
238 | 264 | unset($wp_gc); |
239 | 265 | break; |
240 | 266 | case 'name': $entry['name'] = $row['name']; break; |
@@ -312,12 +338,19 @@ discard block |
||
312 | 338 | $entry['trip_distance'] = $row['trip_distance'] === null ? null : round($row['trip_distance'],3); break; |
313 | 339 | break; |
314 | 340 | case 'rating': |
315 | - if ($row['votes'] < 3) $entry['rating'] = null; |
|
316 | - elseif ($row['score'] >= 2.2) $entry['rating'] = 5.0; |
|
317 | - elseif ($row['score'] >= 1.4) $entry['rating'] = 4.0; |
|
318 | - elseif ($row['score'] >= 0.1) $entry['rating'] = 3.0; |
|
319 | - elseif ($row['score'] >= -1.0) $entry['rating'] = 2.0; |
|
320 | - else $entry['rating'] = 1.0; |
|
341 | + if ($row['votes'] < 3) { |
|
342 | + $entry['rating'] = null; |
|
343 | + } elseif ($row['score'] >= 2.2) { |
|
344 | + $entry['rating'] = 5.0; |
|
345 | + } elseif ($row['score'] >= 1.4) { |
|
346 | + $entry['rating'] = 4.0; |
|
347 | + } elseif ($row['score'] >= 0.1) { |
|
348 | + $entry['rating'] = 3.0; |
|
349 | + } elseif ($row['score'] >= -1.0) { |
|
350 | + $entry['rating'] = 2.0; |
|
351 | + } else { |
|
352 | + $entry['rating'] = 1.0; |
|
353 | + } |
|
321 | 354 | break; |
322 | 355 | case 'rating_votes': $entry['rating_votes'] = $row['votes'] + 0; break; |
323 | 356 | case 'recommendations': $entry['recommendations'] = $row['topratings'] + 0; break; |
@@ -352,8 +385,9 @@ discard block |
||
352 | 385 | } |
353 | 386 | } |
354 | 387 | $results[$row['wp_oc']] = $entry; |
355 | - if ($row['listing_outdated'] > 0) |
|
356 | - $outdated_listings[] = $row['wp_oc']; |
|
388 | + if ($row['listing_outdated'] > 0) { |
|
389 | + $outdated_listings[] = $row['wp_oc']; |
|
390 | + } |
|
357 | 391 | } |
358 | 392 | Db::free_result($rs); |
359 | 393 | |
@@ -367,8 +401,9 @@ discard block |
||
367 | 401 | where user_id in ('".implode("','", array_map('\okapi\Db::escape_string', array_values($owner_ids)))."') |
368 | 402 | "); |
369 | 403 | $tmp = array(); |
370 | - while ($row = Db::fetch_assoc($rs)) |
|
371 | - $tmp[$row['user_id']] = $row; |
|
404 | + while ($row = Db::fetch_assoc($rs)) { |
|
405 | + $tmp[$row['user_id']] = $row; |
|
406 | + } |
|
372 | 407 | foreach ($results as $cache_code => &$result_ref) |
373 | 408 | { |
374 | 409 | $row = $tmp[$owner_ids[$cache_code]]; |
@@ -384,8 +419,9 @@ discard block |
||
384 | 419 | |
385 | 420 | if (in_array('is_found', $fields)) |
386 | 421 | { |
387 | - if ($user_id == null) |
|
388 | - throw new BadRequest("Either 'user_uuid' parameter OR Level 3 Authentication is required to access 'is_found' field."); |
|
422 | + if ($user_id == null) { |
|
423 | + throw new BadRequest("Either 'user_uuid' parameter OR Level 3 Authentication is required to access 'is_found' field."); |
|
424 | + } |
|
389 | 425 | $tmp = Db::select_column(" |
390 | 426 | select c.wp_oc |
391 | 427 | from |
@@ -401,18 +437,21 @@ discard block |
||
401 | 437 | ".((Settings::get('OC_BRANCH') == 'oc.pl') ? "and cl.deleted = 0" : "")." |
402 | 438 | "); |
403 | 439 | $tmp2 = array(); |
404 | - foreach ($tmp as $cache_code) |
|
405 | - $tmp2[$cache_code] = true; |
|
406 | - foreach ($results as $cache_code => &$result_ref) |
|
407 | - $result_ref['is_found'] = isset($tmp2[$cache_code]); |
|
440 | + foreach ($tmp as $cache_code) { |
|
441 | + $tmp2[$cache_code] = true; |
|
442 | + } |
|
443 | + foreach ($results as $cache_code => &$result_ref) { |
|
444 | + $result_ref['is_found'] = isset($tmp2[$cache_code]); |
|
445 | + } |
|
408 | 446 | } |
409 | 447 | |
410 | 448 | # is_not_found |
411 | 449 | |
412 | 450 | if (in_array('is_not_found', $fields)) |
413 | 451 | { |
414 | - if ($user_id == null) |
|
415 | - throw new BadRequest("Either 'user_uuid' parameter OR Level 3 Authentication is required to access 'is_not_found' field."); |
|
452 | + if ($user_id == null) { |
|
453 | + throw new BadRequest("Either 'user_uuid' parameter OR Level 3 Authentication is required to access 'is_not_found' field."); |
|
454 | + } |
|
416 | 455 | $tmp = Db::select_column(" |
417 | 456 | select c.wp_oc |
418 | 457 | from |
@@ -425,18 +464,21 @@ discard block |
||
425 | 464 | ".((Settings::get('OC_BRANCH') == 'oc.pl') ? "and cl.deleted = 0" : "")." |
426 | 465 | "); |
427 | 466 | $tmp2 = array(); |
428 | - foreach ($tmp as $cache_code) |
|
429 | - $tmp2[$cache_code] = true; |
|
430 | - foreach ($results as $cache_code => &$result_ref) |
|
431 | - $result_ref['is_not_found'] = isset($tmp2[$cache_code]); |
|
467 | + foreach ($tmp as $cache_code) { |
|
468 | + $tmp2[$cache_code] = true; |
|
469 | + } |
|
470 | + foreach ($results as $cache_code => &$result_ref) { |
|
471 | + $result_ref['is_not_found'] = isset($tmp2[$cache_code]); |
|
472 | + } |
|
432 | 473 | } |
433 | 474 | |
434 | 475 | # is_watched |
435 | 476 | |
436 | 477 | if (in_array('is_watched', $fields)) |
437 | 478 | { |
438 | - if ($request->token == null) |
|
439 | - throw new BadRequest("Level 3 Authentication is required to access 'is_watched' field."); |
|
479 | + if ($request->token == null) { |
|
480 | + throw new BadRequest("Level 3 Authentication is required to access 'is_watched' field."); |
|
481 | + } |
|
440 | 482 | $tmp = Db::select_column(" |
441 | 483 | select c.wp_oc |
442 | 484 | from |
@@ -447,8 +489,9 @@ discard block |
||
447 | 489 | and cw.user_id = '".Db::escape_string($request->token->user_id)."' |
448 | 490 | "); |
449 | 491 | $tmp2 = array(); |
450 | - foreach ($tmp as $cache_code) |
|
451 | - $tmp2[$cache_code] = true; |
|
492 | + foreach ($tmp as $cache_code) { |
|
493 | + $tmp2[$cache_code] = true; |
|
494 | + } |
|
452 | 495 | |
453 | 496 | # OCDE caches can also be indirectly watched by watching cache lists: |
454 | 497 | if (Settings::get('OC_BRANCH') == 'oc.de') |
@@ -464,20 +507,23 @@ discard block |
||
464 | 507 | and clw.cache_list_id = cli.cache_list_id |
465 | 508 | and clw.user_id = '".Db::escape_string($request->token->user_id)."' |
466 | 509 | "); |
467 | - foreach ($tmp as $cache_code) |
|
468 | - $tmp2[$cache_code] = true; |
|
510 | + foreach ($tmp as $cache_code) { |
|
511 | + $tmp2[$cache_code] = true; |
|
512 | + } |
|
469 | 513 | } |
470 | 514 | |
471 | - foreach ($results as $cache_code => &$result_ref) |
|
472 | - $result_ref['is_watched'] = isset($tmp2[$cache_code]); |
|
515 | + foreach ($results as $cache_code => &$result_ref) { |
|
516 | + $result_ref['is_watched'] = isset($tmp2[$cache_code]); |
|
517 | + } |
|
473 | 518 | } |
474 | 519 | |
475 | 520 | # is_ignored |
476 | 521 | |
477 | 522 | if (in_array('is_ignored', $fields)) |
478 | 523 | { |
479 | - if ($request->token == null) |
|
480 | - throw new BadRequest("Level 3 Authentication is required to access 'is_ignored' field."); |
|
524 | + if ($request->token == null) { |
|
525 | + throw new BadRequest("Level 3 Authentication is required to access 'is_ignored' field."); |
|
526 | + } |
|
481 | 527 | $tmp = Db::select_column(" |
482 | 528 | select c.wp_oc |
483 | 529 | from |
@@ -488,10 +534,12 @@ discard block |
||
488 | 534 | and ci.user_id = '".Db::escape_string($request->token->user_id)."' |
489 | 535 | "); |
490 | 536 | $tmp2 = array(); |
491 | - foreach ($tmp as $cache_code) |
|
492 | - $tmp2[$cache_code] = true; |
|
493 | - foreach ($results as $cache_code => &$result_ref) |
|
494 | - $result_ref['is_ignored'] = isset($tmp2[$cache_code]); |
|
537 | + foreach ($tmp as $cache_code) { |
|
538 | + $tmp2[$cache_code] = true; |
|
539 | + } |
|
540 | + foreach ($results as $cache_code => &$result_ref) { |
|
541 | + $result_ref['is_ignored'] = isset($tmp2[$cache_code]); |
|
542 | + } |
|
495 | 543 | } |
496 | 544 | |
497 | 545 | # Descriptions and hints. |
@@ -579,27 +627,31 @@ discard block |
||
579 | 627 | foreach (array( |
580 | 628 | 'short_description', 'short_descriptions', 'description', 'descriptions', |
581 | 629 | 'hint', 'hints', 'hint2', 'hints2' |
582 | - ) as $field) |
|
583 | - if (!in_array($field, $fields)) |
|
630 | + ) as $field) { |
|
631 | + if (!in_array($field, $fields)) |
|
584 | 632 | foreach ($results as &$result_ref) |
585 | 633 | unset($result_ref[$field]); |
634 | + } |
|
586 | 635 | } |
587 | 636 | |
588 | 637 | # Images. |
589 | 638 | |
590 | 639 | if (in_array('images', $fields) || in_array('preview_image', $fields)) |
591 | 640 | { |
592 | - if (in_array('images', $fields)) |
|
593 | - foreach ($results as &$result_ref) |
|
641 | + if (in_array('images', $fields)) { |
|
642 | + foreach ($results as &$result_ref) |
|
594 | 643 | $result_ref['images'] = array(); |
595 | - if (in_array('preview_image', $fields)) |
|
596 | - foreach ($results as &$result_ref) |
|
644 | + } |
|
645 | + if (in_array('preview_image', $fields)) { |
|
646 | + foreach ($results as &$result_ref) |
|
597 | 647 | $result_ref['preview_image'] = null; |
648 | + } |
|
598 | 649 | |
599 | - if (Db::field_exists('pictures', 'mappreview')) |
|
600 | - $preview_field = "mappreview"; |
|
601 | - else |
|
602 | - $preview_field = "0"; |
|
650 | + if (Db::field_exists('pictures', 'mappreview')) { |
|
651 | + $preview_field = "mappreview"; |
|
652 | + } else { |
|
653 | + $preview_field = "0"; |
|
654 | + } |
|
603 | 655 | $rs = Db::query(" |
604 | 656 | select object_id, uuid, url, title, spoiler, ".$preview_field." as preview |
605 | 657 | from pictures |
@@ -635,10 +687,12 @@ discard block |
||
635 | 687 | 'unique_caption' => self::get_unique_caption($row['title']), |
636 | 688 | 'is_spoiler' => ($row['spoiler'] ? true : false), |
637 | 689 | ); |
638 | - if (in_array('images', $fields)) |
|
639 | - $results[$cache_code]['images'][] = $image; |
|
640 | - if ($row['preview'] != 0 && in_array('preview_image', $fields)) |
|
641 | - $results[$cache_code]['preview_image'] = $image; |
|
690 | + if (in_array('images', $fields)) { |
|
691 | + $results[$cache_code]['images'][] = $image; |
|
692 | + } |
|
693 | + if ($row['preview'] != 0 && in_array('preview_image', $fields)) { |
|
694 | + $results[$cache_code]['preview_image'] = $image; |
|
695 | + } |
|
642 | 696 | } |
643 | 697 | } |
644 | 698 | |
@@ -653,8 +707,9 @@ discard block |
||
653 | 707 | { |
654 | 708 | $fields_to_remove_later[] = 'attr_acodes'; |
655 | 709 | } |
656 | - foreach ($results as &$result_ref) |
|
657 | - $result_ref['attr_acodes'] = array(); |
|
710 | + foreach ($results as &$result_ref) { |
|
711 | + $result_ref['attr_acodes'] = array(); |
|
712 | + } |
|
658 | 713 | |
659 | 714 | # Load internal_attr_id => acode mapping. |
660 | 715 | |
@@ -687,8 +742,9 @@ discard block |
||
687 | 742 | foreach ($results as &$result_ref) |
688 | 743 | { |
689 | 744 | $result_ref['attrnames'] = array(); |
690 | - foreach ($result_ref['attr_acodes'] as $acode) |
|
691 | - $result_ref['attrnames'][] = $acode2bestname[$acode]; |
|
745 | + foreach ($result_ref['attr_acodes'] as $acode) { |
|
746 | + $result_ref['attrnames'][] = $acode2bestname[$acode]; |
|
747 | + } |
|
692 | 748 | } |
693 | 749 | } |
694 | 750 | } |
@@ -697,8 +753,9 @@ discard block |
||
697 | 753 | |
698 | 754 | if (in_array('latest_logs', $fields)) |
699 | 755 | { |
700 | - foreach ($results as &$result_ref) |
|
701 | - $result_ref['latest_logs'] = array(); |
|
756 | + foreach ($results as &$result_ref) { |
|
757 | + $result_ref['latest_logs'] = array(); |
|
758 | + } |
|
702 | 759 | |
703 | 760 | # Get all log IDs in proper order, then filter out the latest |
704 | 761 | # ones. This should be the fastest technique ... |
@@ -732,8 +789,9 @@ discard block |
||
732 | 789 | { |
733 | 790 | # User wants some of the latest logs. |
734 | 791 | $tmp = array(); |
735 | - while ($row = Db::fetch_assoc($rs)) |
|
736 | - $tmp[$row['cache_id']][] = $row; |
|
792 | + while ($row = Db::fetch_assoc($rs)) { |
|
793 | + $tmp[$row['cache_id']][] = $row; |
|
794 | + } |
|
737 | 795 | foreach ($tmp as $cache_key => &$rowslist_ref) |
738 | 796 | { |
739 | 797 | for ($i = 0; $i < min(count($rowslist_ref), $lpc); $i++) |
@@ -742,8 +800,7 @@ discard block |
||
742 | 800 | $log2cache_map[$rowslist_ref[$i]['uuid']] = $cacheid2wptcode[$rowslist_ref[$i]['cache_id']]; |
743 | 801 | } |
744 | 802 | } |
745 | - } |
|
746 | - else |
|
803 | + } else |
|
747 | 804 | { |
748 | 805 | # User wants ALL logs. |
749 | 806 | while ($row = Db::fetch_assoc($rs)) |
@@ -773,18 +830,17 @@ discard block |
||
773 | 830 | ); |
774 | 831 | foreach ($subset as $log_uuid) |
775 | 832 | { |
776 | - if ($entries[$log_uuid]) |
|
777 | - $results[$log2cache_map[$log_uuid]]['latest_logs'][] = $entries[$log_uuid]; |
|
833 | + if ($entries[$log_uuid]) { |
|
834 | + $results[$log2cache_map[$log_uuid]]['latest_logs'][] = $entries[$log_uuid]; |
|
835 | + } |
|
778 | 836 | } |
779 | 837 | } |
780 | - } |
|
781 | - catch (Exception $e) |
|
838 | + } catch (Exception $e) |
|
782 | 839 | { |
783 | 840 | if (($e instanceof InvalidParam) && ($e->paramName == 'fields')) |
784 | 841 | { |
785 | 842 | throw new InvalidParam('log_fields', $e->whats_wrong_about_it); |
786 | - } |
|
787 | - else |
|
843 | + } else |
|
788 | 844 | { |
789 | 845 | /* Something is wrong with OUR code. */ |
790 | 846 | throw new Exception($e); |
@@ -796,10 +852,12 @@ discard block |
||
796 | 852 | |
797 | 853 | if (in_array('my_notes', $fields)) |
798 | 854 | { |
799 | - if ($request->token == null) |
|
800 | - throw new BadRequest("Level 3 Authentication is required to access 'my_notes' field."); |
|
801 | - foreach ($results as &$result_ref) |
|
802 | - $result_ref['my_notes'] = null; |
|
855 | + if ($request->token == null) { |
|
856 | + throw new BadRequest("Level 3 Authentication is required to access 'my_notes' field."); |
|
857 | + } |
|
858 | + foreach ($results as &$result_ref) { |
|
859 | + $result_ref['my_notes'] = null; |
|
860 | + } |
|
803 | 861 | if (Settings::get('OC_BRANCH') == 'oc.pl') |
804 | 862 | { |
805 | 863 | # OCPL uses cache_notes table to store notes. |
@@ -812,8 +870,7 @@ discard block |
||
812 | 870 | and user_id = '".Db::escape_string($request->token->user_id)."' |
813 | 871 | group by cache_id |
814 | 872 | "); |
815 | - } |
|
816 | - else |
|
873 | + } else |
|
817 | 874 | { |
818 | 875 | # OCDE uses coordinates table (with type == 2) to store notes (this is somewhat weird). |
819 | 876 | |
@@ -852,13 +909,15 @@ discard block |
||
852 | 909 | and gkiw.wp in ('".implode("','", array_map('\okapi\Db::escape_string', $cache_codes))."') |
853 | 910 | "); |
854 | 911 | $trs = array(); |
855 | - while ($row = Db::fetch_assoc($rs)) |
|
856 | - $trs[$row['cache_code']][] = $row; |
|
912 | + while ($row = Db::fetch_assoc($rs)) { |
|
913 | + $trs[$row['cache_code']][] = $row; |
|
914 | + } |
|
857 | 915 | foreach ($results as $cache_code => &$result_ref) |
858 | 916 | { |
859 | 917 | $result_ref['trackables'] = array(); |
860 | - if (!isset($trs[$cache_code])) |
|
861 | - continue; |
|
918 | + if (!isset($trs[$cache_code])) { |
|
919 | + continue; |
|
920 | + } |
|
862 | 921 | foreach ($trs[$cache_code] as $t) |
863 | 922 | { |
864 | 923 | $result_ref['trackables'][] = array( |
@@ -875,10 +934,10 @@ discard block |
||
875 | 934 | if (in_array('trackables', $fields)) |
876 | 935 | { |
877 | 936 | # We already got all trackables data, no need to query database again. |
878 | - foreach ($results as $cache_code => &$result_ref) |
|
879 | - $result_ref['trackables_count'] = count($result_ref['trackables']); |
|
880 | - } |
|
881 | - else |
|
937 | + foreach ($results as $cache_code => &$result_ref) { |
|
938 | + $result_ref['trackables_count'] = count($result_ref['trackables']); |
|
939 | + } |
|
940 | + } else |
|
882 | 941 | { |
883 | 942 | $rs = Db::query(" |
884 | 943 | select wp as cache_code, count(*) as count |
@@ -887,14 +946,16 @@ discard block |
||
887 | 946 | group by wp |
888 | 947 | "); |
889 | 948 | $tr_counts = new ArrayObject(); |
890 | - while ($row = Db::fetch_assoc($rs)) |
|
891 | - $tr_counts[$row['cache_code']] = $row['count']; |
|
949 | + while ($row = Db::fetch_assoc($rs)) { |
|
950 | + $tr_counts[$row['cache_code']] = $row['count']; |
|
951 | + } |
|
892 | 952 | foreach ($results as $cache_code => &$result_ref) |
893 | 953 | { |
894 | - if (isset($tr_counts[$cache_code])) |
|
895 | - $result_ref['trackables_count'] = $tr_counts[$cache_code] + 0; |
|
896 | - else |
|
897 | - $result_ref['trackables_count'] = 0; |
|
954 | + if (isset($tr_counts[$cache_code])) { |
|
955 | + $result_ref['trackables_count'] = $tr_counts[$cache_code] + 0; |
|
956 | + } else { |
|
957 | + $result_ref['trackables_count'] = 0; |
|
958 | + } |
|
898 | 959 | } |
899 | 960 | unset($tr_counts); |
900 | 961 | } |
@@ -916,11 +977,11 @@ discard block |
||
916 | 977 | coordinates_type ct |
917 | 978 | left join sys_trans_text stt on stt.trans_id = ct.trans_id |
918 | 979 | "); |
919 | - while ($row = Db::fetch_assoc($rs)) |
|
920 | - $internal_wpt_type_id2names[$row['id']][$row['language']] = $row['text']; |
|
980 | + while ($row = Db::fetch_assoc($rs)) { |
|
981 | + $internal_wpt_type_id2names[$row['id']][$row['language']] = $row['text']; |
|
982 | + } |
|
921 | 983 | Db::free_result($rs); |
922 | - } |
|
923 | - else |
|
984 | + } else |
|
924 | 985 | { |
925 | 986 | $rs = Db::query(" |
926 | 987 | select id, pl, en |
@@ -934,8 +995,9 @@ discard block |
||
934 | 995 | } |
935 | 996 | } |
936 | 997 | |
937 | - foreach ($results as &$result_ref) |
|
938 | - $result_ref['alt_wpts'] = array(); |
|
998 | + foreach ($results as &$result_ref) { |
|
999 | + $result_ref['alt_wpts'] = array(); |
|
1000 | + } |
|
939 | 1001 | $cache_codes_escaped_and_imploded = "'".implode("','", array_map('\okapi\Db::escape_string', array_keys($cacheid2wptcode)))."'"; |
940 | 1002 | |
941 | 1003 | if (Settings::get('OC_BRANCH') == 'oc.pl') |
@@ -970,8 +1032,7 @@ discard block |
||
970 | 1032 | and status = 1 |
971 | 1033 | order by cache_id, stage, `desc` |
972 | 1034 | "); |
973 | - } |
|
974 | - else |
|
1035 | + } else |
|
975 | 1036 | { |
976 | 1037 | # OCDE uses 'coordinates' table (with type=1) to store additional waypoints |
977 | 1038 | # and defines waypoint types in 'coordinates_type' table. |
@@ -1117,8 +1178,9 @@ discard block |
||
1117 | 1178 | c.wp_oc in ('".implode("','", array_map('\okapi\Db::escape_string', $cache_codes))."') |
1118 | 1179 | "); |
1119 | 1180 | $country_codes2names = array(); |
1120 | - while ($row = Db::fetch_assoc($rs)) |
|
1121 | - $country_codes2names[$row['country']][$row['language']] = $row['text']; |
|
1181 | + while ($row = Db::fetch_assoc($rs)) { |
|
1182 | + $country_codes2names[$row['country']][$row['language']] = $row['text']; |
|
1183 | + } |
|
1122 | 1184 | Db::free_result($rs); |
1123 | 1185 | |
1124 | 1186 | # get geocache countries and states |
@@ -1135,15 +1197,15 @@ discard block |
||
1135 | 1197 | "); |
1136 | 1198 | while ($row = Db::fetch_assoc($rs)) |
1137 | 1199 | { |
1138 | - if (!isset($country_codes2names[$row['country_code']])) |
|
1139 | - $countries[$row['cache_code']] = ''; |
|
1140 | - else |
|
1141 | - $countries[$row['cache_code']] = Okapi::pick_best_language($country_codes2names[$row['country_code']], $langpref); |
|
1200 | + if (!isset($country_codes2names[$row['country_code']])) { |
|
1201 | + $countries[$row['cache_code']] = ''; |
|
1202 | + } else { |
|
1203 | + $countries[$row['cache_code']] = Okapi::pick_best_language($country_codes2names[$row['country_code']], $langpref); |
|
1204 | + } |
|
1142 | 1205 | $states[$row['cache_code']] = $row['state']; |
1143 | 1206 | } |
1144 | 1207 | Db::free_result($rs); |
1145 | - } |
|
1146 | - else |
|
1208 | + } else |
|
1147 | 1209 | { |
1148 | 1210 | # OCPL: |
1149 | 1211 | # - cache_location data is entered by the user. |
@@ -1172,13 +1234,15 @@ discard block |
||
1172 | 1234 | |
1173 | 1235 | if (in_array('country', $fields)) |
1174 | 1236 | { |
1175 | - foreach ($results as $cache_code => &$row_ref) |
|
1176 | - $row_ref['country'] = isset($countries[$cache_code]) ? $countries[$cache_code] : null; |
|
1237 | + foreach ($results as $cache_code => &$row_ref) { |
|
1238 | + $row_ref['country'] = isset($countries[$cache_code]) ? $countries[$cache_code] : null; |
|
1239 | + } |
|
1177 | 1240 | } |
1178 | 1241 | if (in_array('state', $fields)) |
1179 | 1242 | { |
1180 | - foreach ($results as $cache_code => &$row_ref) |
|
1181 | - $row_ref['state'] = isset($states[$cache_code]) ? $states[$cache_code] : null; |
|
1243 | + foreach ($results as $cache_code => &$row_ref) { |
|
1244 | + $row_ref['state'] = isset($states[$cache_code]) ? $states[$cache_code] : null; |
|
1245 | + } |
|
1182 | 1246 | } |
1183 | 1247 | unset($countries); |
1184 | 1248 | unset($states); |
@@ -1191,12 +1255,13 @@ discard block |
||
1191 | 1255 | /* Note, that the "owner" and "internal_id" fields are automatically included, |
1192 | 1256 | * whenever the attribution_note is included. */ |
1193 | 1257 | |
1194 | - foreach ($results as $cache_code => &$result_ref) |
|
1195 | - $result_ref['attribution_note'] = |
|
1258 | + foreach ($results as $cache_code => &$result_ref) { |
|
1259 | + $result_ref['attribution_note'] = |
|
1196 | 1260 | self::get_cache_attribution_note( |
1197 | 1261 | $result_ref['internal_id'], $langpref[0], $langpref, |
1198 | 1262 | $results[$cache_code]['owner'], 'full' |
1199 | 1263 | ); |
1264 | + } |
|
1200 | 1265 | } |
1201 | 1266 | |
1202 | 1267 | # Protection areas |
@@ -1222,8 +1287,7 @@ discard block |
||
1222 | 1287 | group by npa_areas.type_id, npa_areas.name |
1223 | 1288 | order by npa_types.ordinal |
1224 | 1289 | "); |
1225 | - } |
|
1226 | - else if (in_array(Okapi::get_oc_schema_code(), array("OCPL", "OCNL"))) |
|
1290 | + } else if (in_array(Okapi::get_oc_schema_code(), array("OCPL", "OCNL"))) |
|
1227 | 1291 | { |
1228 | 1292 | # Current OCPL table definitions use collation 'latin1' for parkipl |
1229 | 1293 | # and 'utf8' for np_areas. Union needs identical collations. |
@@ -1255,8 +1319,7 @@ discard block |
||
1255 | 1319 | c.cache_id in (".$cache_ids_escaped_and_imploded.") |
1256 | 1320 | and cache_npa_areas.npa_id != 0 |
1257 | 1321 | "); |
1258 | - } |
|
1259 | - else |
|
1322 | + } else |
|
1260 | 1323 | { |
1261 | 1324 | # OC.US and .UK do not have a 'parkipl' table. |
1262 | 1325 | # OC.US has a 'us_parks' table instead. |
@@ -1264,8 +1327,9 @@ discard block |
||
1264 | 1327 | $rs = null; |
1265 | 1328 | } |
1266 | 1329 | |
1267 | - foreach ($results as &$result_ref) |
|
1268 | - $result_ref['protection_areas'] = array(); |
|
1330 | + foreach ($results as &$result_ref) { |
|
1331 | + $result_ref['protection_areas'] = array(); |
|
1332 | + } |
|
1269 | 1333 | if ($rs) |
1270 | 1334 | { |
1271 | 1335 | while ($row = Db::fetch_assoc($rs)) |
@@ -1280,18 +1344,20 @@ discard block |
||
1280 | 1344 | } |
1281 | 1345 | |
1282 | 1346 | # Check which cache codes were not found and mark them with null. |
1283 | - foreach ($cache_codes as $cache_code) |
|
1284 | - if (!isset($results[$cache_code])) |
|
1347 | + foreach ($cache_codes as $cache_code) { |
|
1348 | + if (!isset($results[$cache_code])) |
|
1285 | 1349 | $results[$cache_code] = null; |
1350 | + } |
|
1286 | 1351 | |
1287 | 1352 | if (count($fields_to_remove_later) > 0) |
1288 | 1353 | { |
1289 | 1354 | # Some of the fields in $results were added only temporarily |
1290 | 1355 | # (the Consumer did not ask for them). We will remove these fields now. |
1291 | 1356 | |
1292 | - foreach ($results as &$result_ref) |
|
1293 | - foreach ($fields_to_remove_later as $field) |
|
1357 | + foreach ($results as &$result_ref) { |
|
1358 | + foreach ($fields_to_remove_later as $field) |
|
1294 | 1359 | unset($result_ref[$field]); |
1360 | + } |
|
1295 | 1361 | } |
1296 | 1362 | |
1297 | 1363 | # Order the results in the same order as the input codes were given. |
@@ -1301,8 +1367,9 @@ discard block |
||
1301 | 1367 | # so we just have to rewrite it (sequentially). |
1302 | 1368 | |
1303 | 1369 | $ordered_results = new ArrayObject(); |
1304 | - foreach ($cache_codes as $cache_code) |
|
1305 | - $ordered_results[$cache_code] = $results[$cache_code]; |
|
1370 | + foreach ($cache_codes as $cache_code) { |
|
1371 | + $ordered_results[$cache_code] = $results[$cache_code]; |
|
1372 | + } |
|
1306 | 1373 | |
1307 | 1374 | /* Handle OCPL's "access logs" feature. */ |
1308 | 1375 | |
@@ -1415,8 +1482,7 @@ discard block |
||
1415 | 1482 | _("This <a href='%s'>geocache</a> description comes from the <a href='%s'>%s</a> site."), |
1416 | 1483 | $cache_url, $site_url, $site_name |
1417 | 1484 | ); |
1418 | - } |
|
1419 | - else |
|
1485 | + } else |
|
1420 | 1486 | { |
1421 | 1487 | # OC.de wants the tld in lowercase here |
1422 | 1488 | $site_name = ucfirst(strtolower($site_name)); |
@@ -1430,8 +1496,7 @@ discard block |
||
1430 | 1496 | ), |
1431 | 1497 | $owner['profile_url'], $owner['username'], $cache_url, $site_name, strftime('%x') |
1432 | 1498 | ); |
1433 | - } |
|
1434 | - elseif ($type == 'static') |
|
1499 | + } elseif ($type == 'static') |
|
1435 | 1500 | { |
1436 | 1501 | $note = sprintf( |
1437 | 1502 | _( |
@@ -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 | 7 | use okapi\OkapiInternalRequest; |
17 | 8 | use okapi\OkapiInternalConsumer; |
18 | 9 | use okapi\OkapiServiceRunner; |
19 | - |
|
20 | 10 | use okapi\services\caches\map\TileTree; |
21 | 11 | |
22 | 12 | require_once 'tiletree.inc.php'; |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | from okapi_tile_caches |
74 | 74 | where |
75 | 75 | z=0 |
76 | - and cache_id = '".Db::escape_string($cache['internal_id'])."' |
|
76 | + and cache_id = '".Db::escape_string($cache['internal_id']) . "' |
|
77 | 77 | ")); |
78 | 78 | |
79 | 79 | # Caches near the poles caused our computations to break here. We will |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | |
123 | 123 | Db::execute(" |
124 | 124 | delete from okapi_tile_caches |
125 | - where cache_id = '".Db::escape_string($cache_id)."' |
|
125 | + where cache_id = '".Db::escape_string($cache_id) . "' |
|
126 | 126 | "); |
127 | 127 | |
128 | 128 | # Note, that after this operation, okapi_tile_status may be out-of-date. |
@@ -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; |
@@ -195,9 +195,9 @@ discard block |
||
195 | 195 | { |
196 | 196 | list($z, $x, $y) = $coords; |
197 | 197 | $alternatives_escaped[] = "( |
198 | - z = '".Db::escape_string($z)."' |
|
199 | - and x = '".Db::escape_string($x)."' |
|
200 | - and y = '".Db::escape_string($y)."' |
|
198 | + z = '".Db::escape_string($z) . "' |
|
199 | + and x = '".Db::escape_string($x) . "' |
|
200 | + and y = '".Db::escape_string($y) . "' |
|
201 | 201 | )"; |
202 | 202 | } |
203 | 203 | if (count($alternatives_escaped) > 0) |
@@ -208,17 +208,17 @@ discard block |
||
208 | 208 | ) |
209 | 209 | select |
210 | 210 | z, x, y, |
211 | - '".Db::escape_string($row[0])."', |
|
212 | - '".Db::escape_string($row[1])."', |
|
213 | - '".Db::escape_string($row[2])."', |
|
214 | - '".Db::escape_string($row[3])."', |
|
215 | - '".Db::escape_string($row[4])."', |
|
216 | - ".(($row[5] === null) ? "null" : "'".Db::escape_string($row[5])."'").", |
|
217 | - '".Db::escape_string($row[6])."', |
|
218 | - '".Db::escape_string($row[7])."' |
|
211 | + '".Db::escape_string($row[0]) . "', |
|
212 | + '".Db::escape_string($row[1]) . "', |
|
213 | + '".Db::escape_string($row[2]) . "', |
|
214 | + '".Db::escape_string($row[3]) . "', |
|
215 | + '".Db::escape_string($row[4]) . "', |
|
216 | + ".(($row[5] === null) ? "null" : "'" . Db::escape_string($row[5]) . "'") . ", |
|
217 | + '".Db::escape_string($row[6]) . "', |
|
218 | + '".Db::escape_string($row[7]) . "' |
|
219 | 219 | from okapi_tile_status |
220 | 220 | where |
221 | - (".implode(" or ", $alternatives_escaped).") |
|
221 | + (".implode(" or ", $alternatives_escaped) . ") |
|
222 | 222 | and status in (1,2) |
223 | 223 | "); |
224 | 224 | |
@@ -229,7 +229,7 @@ discard block |
||
229 | 229 | update okapi_tile_status |
230 | 230 | set status=2 |
231 | 231 | where |
232 | - (".implode(" or ", $alternatives_escaped).") |
|
232 | + (".implode(" or ", $alternatives_escaped) . ") |
|
233 | 233 | and status=1 |
234 | 234 | "); |
235 | 235 | } |
@@ -246,13 +246,13 @@ discard block |
||
246 | 246 | Db::execute(" |
247 | 247 | update okapi_tile_caches |
248 | 248 | set |
249 | - status = '".Db::escape_string($row[3])."', |
|
250 | - type = '".Db::escape_string($row[4])."', |
|
251 | - rating = ".(($row[5] === null) ? "null" : "'".Db::escape_string($row[5])."'").", |
|
252 | - flags = '".Db::escape_string($row[6])."', |
|
253 | - name_crc = '".Db::escape_string($row[7])."' |
|
249 | + status = '".Db::escape_string($row[3]) . "', |
|
250 | + type = '".Db::escape_string($row[4]) . "', |
|
251 | + rating = ".(($row[5] === null) ? "null" : "'" . Db::escape_string($row[5]) . "'") . ", |
|
252 | + flags = '".Db::escape_string($row[6]) . "', |
|
253 | + name_crc = '".Db::escape_string($row[7]) . "' |
|
254 | 254 | where |
255 | - cache_id = '".Db::escape_string($row[0])."' |
|
255 | + cache_id = '".Db::escape_string($row[0]) . "' |
|
256 | 256 | "); |
257 | 257 | } |
258 | 258 | |
@@ -263,7 +263,7 @@ discard block |
||
263 | 263 | $cache_id = Db::select_value(" |
264 | 264 | select cache_id |
265 | 265 | from caches |
266 | - where wp_oc='".Db::escape_string($c['object_key']['code'])."' |
|
266 | + where wp_oc='".Db::escape_string($c['object_key']['code']) . "' |
|
267 | 267 | "); |
268 | 268 | self::remove_geocache_from_cached_tiles($cache_id); |
269 | 269 | } |
@@ -33,10 +33,11 @@ discard block |
||
33 | 33 | { |
34 | 34 | if ($c['object_type'] == 'geocache') |
35 | 35 | { |
36 | - if ($c['change_type'] == 'replace') |
|
37 | - self::handle_geocache_replace($c); |
|
38 | - else |
|
39 | - self::handle_geocache_delete($c); |
|
36 | + if ($c['change_type'] == 'replace') { |
|
37 | + self::handle_geocache_replace($c); |
|
38 | + } else { |
|
39 | + self::handle_geocache_delete($c); |
|
40 | + } |
|
40 | 41 | } |
41 | 42 | } |
42 | 43 | } |
@@ -95,19 +96,18 @@ discard block |
||
95 | 96 | # Aaah, a new geocache! How nice... ;) |
96 | 97 | |
97 | 98 | self::add_geocache_to_cached_tiles($theirs); |
98 | - } |
|
99 | - elseif (($ours[1] != $theirs[1]) || ($ours[2] != $theirs[2])) # z21x & z21y fields |
|
99 | + } elseif (($ours[1] != $theirs[1]) || ($ours[2] != $theirs[2])) { |
|
100 | + # z21x & z21y fields |
|
100 | 101 | { |
101 | 102 | # Location changed. |
102 | 103 | |
103 | 104 | self::remove_geocache_from_cached_tiles($ours[0]); |
104 | - self::add_geocache_to_cached_tiles($theirs); |
|
105 | 105 | } |
106 | - elseif ($ours != $theirs) |
|
106 | + self::add_geocache_to_cached_tiles($theirs); |
|
107 | + } elseif ($ours != $theirs) |
|
107 | 108 | { |
108 | 109 | self::update_geocache_attributes_in_cached_tiles($theirs); |
109 | - } |
|
110 | - else |
|
110 | + } else |
|
111 | 111 | { |
112 | 112 | # No need to update anything. This is very common (i.e. when the |
113 | 113 | # cache was simply found, not actually changed). Replicate module generates |
@@ -154,10 +154,13 @@ 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; |
|
159 | + } |
|
160 | + $y<=$ey+1; $y++) { |
|
161 | + if (($x >= 0) && ($x < 1<<$zoom) && ($y >= 0) && ($y < 1<<$zoom)) |
|
160 | 162 | $tiles_in_this_region[] = array($x, $y); |
163 | + } |
|
161 | 164 | |
162 | 165 | foreach ($tiles_in_this_region as $coords) |
163 | 166 | { |
@@ -171,14 +174,18 @@ discard block |
||
171 | 174 | $top_z21y = ($y << $scale) - $margin; |
172 | 175 | $bottom_z21y = (($y + 1) << $scale) + $margin; |
173 | 176 | |
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; |
|
177 | + if ($z21x < $left_z21x) { |
|
178 | + continue; |
|
179 | + } |
|
180 | + if ($z21x > $right_z21x) { |
|
181 | + continue; |
|
182 | + } |
|
183 | + if ($z21y < $top_z21y) { |
|
184 | + continue; |
|
185 | + } |
|
186 | + if ($z21y > $bottom_z21y) { |
|
187 | + continue; |
|
188 | + } |
|
182 | 189 | |
183 | 190 | # We found a match. Store it for later. |
184 | 191 |
@@ -55,6 +55,10 @@ |
||
55 | 55 | ); |
56 | 56 | } |
57 | 57 | |
58 | + /** |
|
59 | + * @param OkapiRequest $request |
|
60 | + * @param string $name |
|
61 | + */ |
|
58 | 62 | private static function require_uint($request, $name, $min_value = 0) |
59 | 63 | { |
60 | 64 | $val = $request->get_parameter($name); |
@@ -2,26 +2,18 @@ |
||
2 | 2 | |
3 | 3 | namespace okapi\services\caches\map\tile; |
4 | 4 | |
5 | -use Exception; |
|
6 | -use okapi\Okapi; |
|
7 | 5 | use okapi\Settings; |
8 | 6 | use okapi\Cache; |
9 | -use okapi\FileCache; |
|
10 | 7 | use okapi\Db; |
11 | 8 | use okapi\OkapiRequest; |
12 | 9 | use okapi\OkapiHttpResponse; |
13 | 10 | use okapi\ParamMissing; |
14 | 11 | use okapi\InvalidParam; |
15 | 12 | use okapi\BadRequest; |
16 | -use okapi\DoesNotExist; |
|
17 | 13 | use okapi\OkapiInternalRequest; |
18 | -use okapi\OkapiInternalConsumer; |
|
19 | 14 | use okapi\OkapiServiceRunner; |
20 | -use okapi\OkapiLock; |
|
21 | - |
|
22 | 15 | use okapi\services\caches\map\TileTree; |
23 | 16 | use okapi\services\caches\map\TileRenderer; |
24 | -use okapi\services\caches\search\SearchAssistant; |
|
25 | 17 | use okapi\OkapiConsumer; |
26 | 18 | |
27 | 19 | require_once('tiletree.inc.php'); |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | |
27 | 27 | require_once('tiletree.inc.php'); |
28 | 28 | require_once('tilerenderer.inc.php'); |
29 | -require_once($GLOBALS['rootpath']."okapi/services/caches/search/searching.inc.php"); |
|
29 | +require_once($GLOBALS['rootpath'] . "okapi/services/caches/search/searching.inc.php"); |
|
30 | 30 | |
31 | 31 | class WebService |
32 | 32 | { |
@@ -88,10 +88,10 @@ discard block |
||
88 | 88 | throw new InvalidParam('z', "Maximum value for this parameter is 21."); |
89 | 89 | $x = self::require_uint($request, 'x'); |
90 | 90 | $y = self::require_uint($request, 'y'); |
91 | - if ($x >= 1<<$zoom) |
|
92 | - throw new InvalidParam('x', "Should be in 0..".((1<<$zoom) - 1)."."); |
|
93 | - if ($y >= 1<<$zoom) |
|
94 | - throw new InvalidParam('y', "Should be in 0..".((1<<$zoom) - 1)."."); |
|
91 | + if ($x >= 1 << $zoom) |
|
92 | + throw new InvalidParam('x', "Should be in 0.." . ((1 << $zoom) - 1) . "."); |
|
93 | + if ($y >= 1 << $zoom) |
|
94 | + throw new InvalidParam('y', "Should be in 0.." . ((1 << $zoom) - 1) . "."); |
|
95 | 95 | |
96 | 96 | # Now, we will create a search set (or use one previously created). |
97 | 97 | # Instead of creating a new OkapiInternalRequest object, we will pass |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | { |
129 | 129 | # Load user-related cache ids. |
130 | 130 | |
131 | - $cache_key = "tileuser/".$request->token->user_id; |
|
131 | + $cache_key = "tileuser/" . $request->token->user_id; |
|
132 | 132 | $user = self::$USE_OTHER_CACHE ? Cache::get($cache_key) : null; |
133 | 133 | if ($user === null) |
134 | 134 | { |
@@ -139,7 +139,7 @@ discard block |
||
139 | 139 | $rs = Db::query(" |
140 | 140 | select cache_id |
141 | 141 | from cache_ignore |
142 | - where user_id = '".Db::escape_string($request->token->user_id)."' |
|
142 | + where user_id = '".Db::escape_string($request->token->user_id) . "' |
|
143 | 143 | "); |
144 | 144 | $user['ignored'] = array(); |
145 | 145 | while (list($cache_id) = Db::fetch_row($rs)) |
@@ -151,9 +151,9 @@ discard block |
||
151 | 151 | select distinct cache_id |
152 | 152 | from cache_logs |
153 | 153 | where |
154 | - user_id = '".Db::escape_string($request->token->user_id)."' |
|
154 | + user_id = '".Db::escape_string($request->token->user_id) . "' |
|
155 | 155 | and type = 1 |
156 | - and ".((Settings::get('OC_BRANCH') == 'oc.pl') ? "deleted = 0" : "true")." |
|
156 | + and ".((Settings::get('OC_BRANCH') == 'oc.pl') ? "deleted = 0" : "true") . " |
|
157 | 157 | "); |
158 | 158 | $user['found'] = array(); |
159 | 159 | while (list($cache_id) = Db::fetch_row($rs)) |
@@ -164,7 +164,7 @@ discard block |
||
164 | 164 | $rs = Db::query(" |
165 | 165 | select distinct cache_id |
166 | 166 | from caches |
167 | - where user_id = '".Db::escape_string($request->token->user_id)."' |
|
167 | + where user_id = '".Db::escape_string($request->token->user_id) . "' |
|
168 | 168 | "); |
169 | 169 | $user['own'] = array(); |
170 | 170 | while (list($cache_id) = Db::fetch_row($rs)) |
@@ -182,9 +182,9 @@ discard block |
||
182 | 182 | # the current user is the owner). |
183 | 183 | |
184 | 184 | if (isset($user['found'][$row_ref[0]])) |
185 | - $row_ref[6] |= TileTree::$FLAG_FOUND; # $row[6] is "flags" |
|
185 | + $row_ref[6] |= TileTree::$FLAG_FOUND; # $row[6] is "flags" |
|
186 | 186 | if (isset($user['own'][$row_ref[0]])) |
187 | - $row_ref[6] |= TileTree::$FLAG_OWN; # $row[6] is "flags" |
|
187 | + $row_ref[6] |= TileTree::$FLAG_OWN; # $row[6] is "flags" |
|
188 | 188 | } |
189 | 189 | } |
190 | 190 | |
@@ -199,7 +199,7 @@ discard block |
||
199 | 199 | $response = new OkapiHttpResponse(); |
200 | 200 | $response->content_type = $tile->get_content_type(); |
201 | 201 | $response->cache_control = "Cache-Control: private, max-age=600"; |
202 | - $response->etag = 'W/"'.$image_fingerprint.'"'; |
|
202 | + $response->etag = 'W/"' . $image_fingerprint . '"'; |
|
203 | 203 | $response->allow_gzip = false; // images are usually compressed, prevent compression at Apache level |
204 | 204 | |
205 | 205 | # Check if the request didn't include the same ETag. |
@@ -218,7 +218,7 @@ discard block |
||
218 | 218 | |
219 | 219 | # Check if the image was recently rendered and is kept in image cache. |
220 | 220 | |
221 | - $cache_key = "tile/".$image_fingerprint; |
|
221 | + $cache_key = "tile/" . $image_fingerprint; |
|
222 | 222 | $response->body = self::$USE_IMAGE_CACHE ? Cache::get($cache_key) : null; |
223 | 223 | OkapiServiceRunner::save_stats_extra("caches/map/tile/checkpointC", null, |
224 | 224 | microtime(true) - $checkpointC_started); |
@@ -58,11 +58,13 @@ discard block |
||
58 | 58 | private static function require_uint($request, $name, $min_value = 0) |
59 | 59 | { |
60 | 60 | $val = $request->get_parameter($name); |
61 | - if ($val === null) |
|
62 | - throw new ParamMissing($name); |
|
61 | + if ($val === null) { |
|
62 | + throw new ParamMissing($name); |
|
63 | + } |
|
63 | 64 | $ret = intval($val); |
64 | - if ($ret < 0 || ("$ret" !== $val)) |
|
65 | - throw new InvalidParam($name, "Expecting non-negative integer."); |
|
65 | + if ($ret < 0 || ("$ret" !== $val)) { |
|
66 | + throw new InvalidParam($name, "Expecting non-negative integer."); |
|
67 | + } |
|
66 | 68 | return $ret; |
67 | 69 | } |
68 | 70 | |
@@ -84,14 +86,17 @@ discard block |
||
84 | 86 | # zoom, x, y - required tile-specific parameters. |
85 | 87 | |
86 | 88 | $zoom = self::require_uint($request, 'z'); |
87 | - if ($zoom > 21) |
|
88 | - throw new InvalidParam('z', "Maximum value for this parameter is 21."); |
|
89 | + if ($zoom > 21) { |
|
90 | + throw new InvalidParam('z', "Maximum value for this parameter is 21."); |
|
91 | + } |
|
89 | 92 | $x = self::require_uint($request, 'x'); |
90 | 93 | $y = self::require_uint($request, 'y'); |
91 | - if ($x >= 1<<$zoom) |
|
92 | - throw new InvalidParam('x', "Should be in 0..".((1<<$zoom) - 1)."."); |
|
93 | - if ($y >= 1<<$zoom) |
|
94 | - throw new InvalidParam('y', "Should be in 0..".((1<<$zoom) - 1)."."); |
|
94 | + if ($x >= 1<<$zoom) { |
|
95 | + throw new InvalidParam('x', "Should be in 0..".((1<<$zoom) - 1)."."); |
|
96 | + } |
|
97 | + if ($y >= 1<<$zoom) { |
|
98 | + throw new InvalidParam('y', "Should be in 0..".((1<<$zoom) - 1)."."); |
|
99 | + } |
|
95 | 100 | |
96 | 101 | # Now, we will create a search set (or use one previously created). |
97 | 102 | # Instead of creating a new OkapiInternalRequest object, we will pass |
@@ -114,8 +119,9 @@ discard block |
||
114 | 119 | $rows = array(); |
115 | 120 | if ($rs !== null) |
116 | 121 | { |
117 | - while ($row = Db::fetch_row($rs)) |
|
118 | - $rows[] = $row; |
|
122 | + while ($row = Db::fetch_row($rs)) { |
|
123 | + $rows[] = $row; |
|
124 | + } |
|
119 | 125 | unset($row); |
120 | 126 | } |
121 | 127 | OkapiServiceRunner::save_stats_extra("caches/map/tile/checkpointA", null, |
@@ -142,8 +148,9 @@ discard block |
||
142 | 148 | where user_id = '".Db::escape_string($request->token->user_id)."' |
143 | 149 | "); |
144 | 150 | $user['ignored'] = array(); |
145 | - while (list($cache_id) = Db::fetch_row($rs)) |
|
146 | - $user['ignored'][$cache_id] = true; |
|
151 | + while (list($cache_id) = Db::fetch_row($rs)) { |
|
152 | + $user['ignored'][$cache_id] = true; |
|
153 | + } |
|
147 | 154 | |
148 | 155 | # Found caches. |
149 | 156 | |
@@ -156,8 +163,9 @@ discard block |
||
156 | 163 | and ".((Settings::get('OC_BRANCH') == 'oc.pl') ? "deleted = 0" : "true")." |
157 | 164 | "); |
158 | 165 | $user['found'] = array(); |
159 | - while (list($cache_id) = Db::fetch_row($rs)) |
|
160 | - $user['found'][$cache_id] = true; |
|
166 | + while (list($cache_id) = Db::fetch_row($rs)) { |
|
167 | + $user['found'][$cache_id] = true; |
|
168 | + } |
|
161 | 169 | |
162 | 170 | # Own caches. |
163 | 171 | |
@@ -167,8 +175,9 @@ discard block |
||
167 | 175 | where user_id = '".Db::escape_string($request->token->user_id)."' |
168 | 176 | "); |
169 | 177 | $user['own'] = array(); |
170 | - while (list($cache_id) = Db::fetch_row($rs)) |
|
171 | - $user['own'][$cache_id] = true; |
|
178 | + while (list($cache_id) = Db::fetch_row($rs)) { |
|
179 | + $user['own'][$cache_id] = true; |
|
180 | + } |
|
172 | 181 | |
173 | 182 | Cache::set($cache_key, $user, 30); |
174 | 183 | } |
@@ -181,10 +190,14 @@ discard block |
||
181 | 190 | # to be drawn as found) and the "own" flag (to indicate that |
182 | 191 | # the current user is the owner). |
183 | 192 | |
184 | - if (isset($user['found'][$row_ref[0]])) |
|
185 | - $row_ref[6] |= TileTree::$FLAG_FOUND; # $row[6] is "flags" |
|
186 | - if (isset($user['own'][$row_ref[0]])) |
|
187 | - $row_ref[6] |= TileTree::$FLAG_OWN; # $row[6] is "flags" |
|
193 | + if (isset($user['found'][$row_ref[0]])) { |
|
194 | + $row_ref[6] |= TileTree::$FLAG_FOUND; |
|
195 | + } |
|
196 | + # $row[6] is "flags" |
|
197 | + if (isset($user['own'][$row_ref[0]])) { |
|
198 | + $row_ref[6] |= TileTree::$FLAG_OWN; |
|
199 | + } |
|
200 | + # $row[6] is "flags" |
|
188 | 201 | } |
189 | 202 | } |
190 | 203 |
@@ -38,6 +38,7 @@ discard block |
||
38 | 38 | * Takes the zoom level and the list of geocache descriptions. Note, that |
39 | 39 | * $rows_ref can be altered after calling render. If you don't want it to, |
40 | 40 | * you should pass a deep copy. |
41 | + * @param integer $zoom |
|
41 | 42 | */ |
42 | 43 | public function __construct($zoom, &$rows_ref) |
43 | 44 | { |
@@ -101,6 +102,9 @@ discard block |
||
101 | 102 | return ob_get_clean(); |
102 | 103 | } |
103 | 104 | |
105 | + /** |
|
106 | + * @param string $name |
|
107 | + */ |
|
104 | 108 | private static function get_image($name, $opacity=1, $brightness=0, |
105 | 109 | $contrast=0, $r=0, $g=0, $b=0) |
106 | 110 | { |
@@ -157,6 +161,8 @@ discard block |
||
157 | 161 | |
158 | 162 | /** |
159 | 163 | * Extremely slow! Remember to cache the result! |
164 | + * @param resource $im |
|
165 | + * @param integer $ratio |
|
160 | 166 | */ |
161 | 167 | private static function change_opacity($im, $ratio) |
162 | 168 | { |
@@ -295,6 +301,9 @@ discard block |
||
295 | 301 | |
296 | 302 | /** |
297 | 303 | * Split lines so that they fit inside the specified width. |
304 | + * @param string $font |
|
305 | + * @param integer $size |
|
306 | + * @param integer $maxWidth |
|
298 | 307 | */ |
299 | 308 | private static function wordwrap($font, $size, $maxWidth, $text) |
300 | 309 | { |
@@ -503,6 +512,9 @@ discard block |
||
503 | 512 | } |
504 | 513 | } |
505 | 514 | |
515 | + /** |
|
516 | + * @param boolean $extended_set |
|
517 | + */ |
|
506 | 518 | private static function get_type_suffix($type, $extended_set) |
507 | 519 | { |
508 | 520 | switch ($type) { |
@@ -4,7 +4,6 @@ |
||
4 | 4 | |
5 | 5 | use Exception; |
6 | 6 | use okapi\Okapi; |
7 | -use okapi\Settings; |
|
8 | 7 | use okapi\Cache; |
9 | 8 | use okapi\Db; |
10 | 9 | use okapi\FileCache; // WRTODO |
@@ -101,8 +101,8 @@ discard block |
||
101 | 101 | return ob_get_clean(); |
102 | 102 | } |
103 | 103 | |
104 | - private static function get_image($name, $opacity=1, $brightness=0, |
|
105 | - $contrast=0, $r=0, $g=0, $b=0) |
|
104 | + private static function get_image($name, $opacity = 1, $brightness = 0, |
|
105 | + $contrast = 0, $r = 0, $g = 0, $b = 0) |
|
106 | 106 | { |
107 | 107 | static $locmem_cache = array(); |
108 | 108 | |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | |
116 | 116 | try |
117 | 117 | { |
118 | - $cache_key = "tilesrc/".Okapi::$git_revision."/".self::$VERSION."/".$key; |
|
118 | + $cache_key = "tilesrc/" . Okapi::$git_revision . "/" . self::$VERSION . "/" . $key; |
|
119 | 119 | $gd2_path = self::$USE_STATIC_IMAGE_CACHE |
120 | 120 | ? FileCache::get_file_path($cache_key) : null; |
121 | 121 | if ($gd2_path === null) |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | { |
129 | 129 | # Miss again (or error decoding). Read the image from PNG. |
130 | 130 | |
131 | - $locmem_cache[$key] = imagecreatefrompng($GLOBALS['rootpath']."okapi/static/tilemap/$name.png"); |
|
131 | + $locmem_cache[$key] = imagecreatefrompng($GLOBALS['rootpath'] . "okapi/static/tilemap/$name.png"); |
|
132 | 132 | |
133 | 133 | # Apply all wanted effects. |
134 | 134 | |
@@ -165,9 +165,9 @@ discard block |
||
165 | 165 | $w = imagesx($im); |
166 | 166 | $h = imagesy($im); |
167 | 167 | |
168 | - for($x = 0; $x < $w; $x++) |
|
168 | + for ($x = 0; $x < $w; $x++) |
|
169 | 169 | { |
170 | - for($y = 0; $y < $h; $y++) |
|
170 | + for ($y = 0; $y < $h; $y++) |
|
171 | 171 | { |
172 | 172 | $color = imagecolorat($im, $x, $y); |
173 | 173 | $new_color = ((max(0, floor(127 - ((127 - (($color >> 24) & 0x7f)) * $ratio))) & 0x7f) << 24) | ($color & 0x80ffffff); |
@@ -247,7 +247,7 @@ discard block |
||
247 | 247 | |
248 | 248 | # Put the inner marker (indicates the type). |
249 | 249 | |
250 | - $inner_marker = self::get_image("large_inner_".self::get_type_suffix( |
|
250 | + $inner_marker = self::get_image("large_inner_" . self::get_type_suffix( |
|
251 | 251 | $type, true), $a, $br, $c, $r, $g, $b); |
252 | 252 | imagecopy($this->im, $inner_marker, $px - 7, $py - 22, 0, 0, 16, 16); |
253 | 253 | |
@@ -287,7 +287,7 @@ discard block |
||
287 | 287 | |
288 | 288 | if ($found) |
289 | 289 | { |
290 | - $icon = self::get_image("found", 0.7*$a, $br, $c, $r, $g, $b); |
|
290 | + $icon = self::get_image("found", 0.7 * $a, $br, $c, $r, $g, $b); |
|
291 | 291 | imagecopy($this->im, $icon, $px - 2, $py - $center_y - 3, 0, 0, 16, 16); |
292 | 292 | } |
293 | 293 | |
@@ -302,16 +302,16 @@ discard block |
||
302 | 302 | $lines = array(); |
303 | 303 | $line = ""; |
304 | 304 | $nextBonus = ""; |
305 | - for ($i=0; ($i<count($words)) || (mb_strlen($nextBonus)>0); $i++) { |
|
306 | - $word = isset($words[$i])?$words[$i]:""; |
|
305 | + for ($i = 0; ($i < count($words)) || (mb_strlen($nextBonus) > 0); $i++) { |
|
306 | + $word = isset($words[$i]) ? $words[$i] : ""; |
|
307 | 307 | if (mb_strlen($nextBonus) > 0) |
308 | - $word = $nextBonus." ".$word; |
|
308 | + $word = $nextBonus . " " . $word; |
|
309 | 309 | $nextBonus = ""; |
310 | 310 | while (true) { |
311 | - $bbox = imagettfbbox($size, 0, $font, $line.$word); |
|
312 | - $width = $bbox[2]-$bbox[0]; |
|
311 | + $bbox = imagettfbbox($size, 0, $font, $line . $word); |
|
312 | + $width = $bbox[2] - $bbox[0]; |
|
313 | 313 | if ($width <= $maxWidth) { |
314 | - $line .= $word." "; |
|
314 | + $line .= $word . " "; |
|
315 | 315 | continue 2; |
316 | 316 | } |
317 | 317 | if (mb_strlen($line) > 0) { |
@@ -319,8 +319,8 @@ discard block |
||
319 | 319 | $line = ""; |
320 | 320 | continue; |
321 | 321 | } |
322 | - $nextBonus = $word[mb_strlen($word)-1].$nextBonus; |
|
323 | - $word = mb_substr($word, 0, mb_strlen($word)-1); |
|
322 | + $nextBonus = $word[mb_strlen($word) - 1] . $nextBonus; |
|
323 | + $word = mb_substr($word, 0, mb_strlen($word) - 1); |
|
324 | 324 | continue; |
325 | 325 | } |
326 | 326 | } |
@@ -336,16 +336,16 @@ discard block |
||
336 | 336 | { |
337 | 337 | # Check cache. |
338 | 338 | |
339 | - $cache_key = "tilecaption/".self::$VERSION."/".$cache_id."/".$name_crc; |
|
339 | + $cache_key = "tilecaption/" . self::$VERSION . "/" . $cache_id . "/" . $name_crc; |
|
340 | 340 | $gd2 = self::$USE_CAPTIONS_CACHE ? Cache::get($cache_key) : null; |
341 | 341 | if ($gd2 === null) |
342 | 342 | { |
343 | 343 | # We'll work with 16x bigger image to get smoother interpolation. |
344 | 344 | |
345 | - $im = imagecreatetruecolor(64*4, 26*4); |
|
345 | + $im = imagecreatetruecolor(64 * 4, 26 * 4); |
|
346 | 346 | imagealphablending($im, false); |
347 | 347 | $transparent = imagecolorallocatealpha($im, 255, 255, 255, 127); |
348 | - imagefilledrectangle($im, 0, 0, 64*4, 26*4, $transparent); |
|
348 | + imagefilledrectangle($im, 0, 0, 64 * 4, 26 * 4, $transparent); |
|
349 | 349 | imagealphablending($im, true); |
350 | 350 | |
351 | 351 | # Get the name of the cache. |
@@ -353,15 +353,15 @@ discard block |
||
353 | 353 | $name = Db::select_value(" |
354 | 354 | select name |
355 | 355 | from caches |
356 | - where cache_id = '".Db::escape_string($cache_id)."' |
|
356 | + where cache_id = '".Db::escape_string($cache_id) . "' |
|
357 | 357 | "); |
358 | 358 | |
359 | 359 | # Split the name into a couple of lines. |
360 | 360 | |
361 | 361 | //$font = $GLOBALS['rootpath'].'util.sec/bt.ttf'; |
362 | - $font = $GLOBALS['rootpath'].'okapi/static/tilemap/tahoma.ttf'; |
|
362 | + $font = $GLOBALS['rootpath'] . 'okapi/static/tilemap/tahoma.ttf'; |
|
363 | 363 | $size = 25; |
364 | - $lines = explode("\n", self::wordwrap($font, $size, 64*4 - 6*2, $name)); |
|
364 | + $lines = explode("\n", self::wordwrap($font, $size, 64 * 4 - 6 * 2, $name)); |
|
365 | 365 | |
366 | 366 | # For each line, compute its (x, y) so that the text is centered. |
367 | 367 | |
@@ -370,7 +370,7 @@ discard block |
||
370 | 370 | foreach ($lines as $line) |
371 | 371 | { |
372 | 372 | $bbox = imagettfbbox($size, 0, $font, $line); |
373 | - $width = $bbox[2]-$bbox[0]; |
|
373 | + $width = $bbox[2] - $bbox[0]; |
|
374 | 374 | $x = 128 - ($width >> 1); |
375 | 375 | $positions[] = array($x, $y); |
376 | 376 | $y += 36; |
@@ -378,7 +378,7 @@ discard block |
||
378 | 378 | $drawer = function($x, $y, $color) use (&$lines, &$positions, &$im, &$size, &$font) |
379 | 379 | { |
380 | 380 | $len = count($lines); |
381 | - for ($i=0; $i<$len; $i++) |
|
381 | + for ($i = 0; $i < $len; $i++) |
|
382 | 382 | { |
383 | 383 | $line = $lines[$i]; |
384 | 384 | list($offset_x, $offset_y) = $positions[$i]; |
@@ -389,8 +389,8 @@ discard block |
||
389 | 389 | # Draw an outline. |
390 | 390 | |
391 | 391 | $outline_color = imagecolorallocatealpha($im, 255, 255, 255, 80); |
392 | - for ($x=0; $x<=12; $x+=3) |
|
393 | - for ($y=$size-3; $y<=$size+9; $y+=3) |
|
392 | + for ($x = 0; $x <= 12; $x += 3) |
|
393 | + for ($y = $size - 3; $y <= $size + 9; $y += 3) |
|
394 | 394 | $drawer($x, $y, $outline_color); |
395 | 395 | |
396 | 396 | # Add a slight shadow effect (on top of the outline). |
@@ -406,7 +406,7 @@ discard block |
||
406 | 406 | imagealphablending($im, false); |
407 | 407 | $small = imagecreatetruecolor(64, 26); |
408 | 408 | imagealphablending($small, false); |
409 | - imagecopyresampled($small, $im, 0, 0, 0, 0, 64, 26, 64*4, 26*4); |
|
409 | + imagecopyresampled($small, $im, 0, 0, 0, 0, 64, 26, 64 * 4, 26 * 4); |
|
410 | 410 | |
411 | 411 | # Cache it! |
412 | 412 | |
@@ -433,7 +433,7 @@ discard block |
||
433 | 433 | |
434 | 434 | # Put the marker (indicates the type). |
435 | 435 | |
436 | - $marker = self::get_image("medium_".self::get_type_suffix($type, false), $a); |
|
436 | + $marker = self::get_image("medium_" . self::get_type_suffix($type, false), $a); |
|
437 | 437 | $width = 14; |
438 | 438 | $height = 14; |
439 | 439 | $center_x = 7; |
@@ -490,7 +490,7 @@ discard block |
||
490 | 490 | { |
491 | 491 | # Mark found caches with V. |
492 | 492 | |
493 | - $icon = self::get_image("found", 0.7*$a); |
|
493 | + $icon = self::get_image("found", 0.7 * $a); |
|
494 | 494 | imagecopy($this->im, $icon, $px - ($center_x - $markercenter_x) - 7, |
495 | 495 | $py - ($center_y - $markercenter_y) - 9, 0, 0, 16, 16); |
496 | 496 | } |
@@ -532,7 +532,7 @@ discard block |
||
532 | 532 | $own = $flags & TileTree::$FLAG_OWN; |
533 | 533 | $new = $flags & TileTree::$FLAG_NEW; |
534 | 534 | |
535 | - $marker = self::get_image("tiny_".self::get_type_suffix($type, false)); |
|
535 | + $marker = self::get_image("tiny_" . self::get_type_suffix($type, false)); |
|
536 | 536 | $width = 10; |
537 | 537 | $height = 10; |
538 | 538 | $center_x = 5; |
@@ -577,7 +577,7 @@ discard block |
||
577 | 577 | # This is efficient and yields acceptable results. |
578 | 578 | |
579 | 579 | $matrix = array(); |
580 | - for ($i=0; $i<12; $i++) |
|
580 | + for ($i = 0; $i < 12; $i++) |
|
581 | 581 | $matrix[] = array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); |
582 | 582 | |
583 | 583 | foreach ($this->rows_ref as &$row_ref) |
@@ -586,27 +586,27 @@ discard block |
||
586 | 586 | $my = ($row_ref[2] + 64) >> 5; |
587 | 587 | if (($mx >= 12) || ($my >= 12)) continue; |
588 | 588 | if (($matrix[$mx][$my] === 0) && ($row_ref[8] == 1)) # 8 is count |
589 | - $matrix[$mx][$my] = $row_ref[0]; # 0 is cache_id |
|
589 | + $matrix[$mx][$my] = $row_ref[0]; # 0 is cache_id |
|
590 | 590 | else |
591 | 591 | $matrix[$mx][$my] = -1; |
592 | 592 | } |
593 | 593 | $selected_cache_ids = array(); |
594 | - for ($mx=1; $mx<11; $mx++) |
|
594 | + for ($mx = 1; $mx < 11; $mx++) |
|
595 | 595 | { |
596 | - for ($my=1; $my<11; $my++) |
|
596 | + for ($my = 1; $my < 11; $my++) |
|
597 | 597 | { |
598 | 598 | if ($matrix[$mx][$my] > 0) # cache_id |
599 | 599 | { |
600 | 600 | # Check all adjacent squares. |
601 | 601 | |
602 | - if ( ($matrix[$mx-1][$my-1] === 0) |
|
603 | - && ($matrix[$mx-1][$my ] === 0) |
|
604 | - && ($matrix[$mx-1][$my+1] === 0) |
|
605 | - && ($matrix[$mx ][$my-1] === 0) |
|
606 | - && ($matrix[$mx ][$my+1] === 0) |
|
607 | - && ($matrix[$mx+1][$my-1] === 0) |
|
608 | - && ($matrix[$mx+1][$my ] === 0) |
|
609 | - && ($matrix[$mx+1][$my+1] === 0) |
|
602 | + if (($matrix[$mx - 1][$my - 1] === 0) |
|
603 | + && ($matrix[$mx - 1][$my] === 0) |
|
604 | + && ($matrix[$mx - 1][$my + 1] === 0) |
|
605 | + && ($matrix[$mx][$my - 1] === 0) |
|
606 | + && ($matrix[$mx][$my + 1] === 0) |
|
607 | + && ($matrix[$mx + 1][$my - 1] === 0) |
|
608 | + && ($matrix[$mx + 1][$my] === 0) |
|
609 | + && ($matrix[$mx + 1][$my + 1] === 0) |
|
610 | 610 | ) |
611 | 611 | $selected_cache_ids[] = $matrix[$mx][$my]; |
612 | 612 | } |
@@ -74,23 +74,28 @@ discard block |
||
74 | 74 | { |
75 | 75 | # Preprocess the rows. |
76 | 76 | |
77 | - if ($this->zoom >= 5) |
|
78 | - $this->decide_which_get_captions(); |
|
77 | + if ($this->zoom >= 5) { |
|
78 | + $this->decide_which_get_captions(); |
|
79 | + } |
|
79 | 80 | |
80 | 81 | # Make a background. |
81 | 82 | |
82 | 83 | $this->im = imagecreatetruecolor(256, 256); |
83 | 84 | imagealphablending($this->im, false); |
84 | - if ($this->zoom >= 13) $opacity = 15; |
|
85 | - elseif ($this->zoom <= 12) $opacity = max(0, $this->zoom * 2 - 14); |
|
85 | + if ($this->zoom >= 13) { |
|
86 | + $opacity = 15; |
|
87 | + } elseif ($this->zoom <= 12) { |
|
88 | + $opacity = max(0, $this->zoom * 2 - 14); |
|
89 | + } |
|
86 | 90 | $transparent = imagecolorallocatealpha($this->im, 0, 0, 0, 127 - $opacity); |
87 | 91 | imagefilledrectangle($this->im, 0, 0, 256, 256, $transparent); |
88 | 92 | imagealphablending($this->im, true); |
89 | 93 | |
90 | 94 | # Draw the caches. |
91 | 95 | |
92 | - foreach ($this->rows_ref as &$row_ref) |
|
93 | - $this->draw_cache($row_ref); |
|
96 | + foreach ($this->rows_ref as &$row_ref) { |
|
97 | + $this->draw_cache($row_ref); |
|
98 | + } |
|
94 | 99 | |
95 | 100 | # Return the result. |
96 | 101 | |
@@ -118,13 +123,13 @@ discard block |
||
118 | 123 | $cache_key = "tilesrc/".Okapi::$git_revision."/".self::$VERSION."/".$key; |
119 | 124 | $gd2_path = self::$USE_STATIC_IMAGE_CACHE |
120 | 125 | ? FileCache::get_file_path($cache_key) : null; |
121 | - if ($gd2_path === null) |
|
122 | - throw new Exception("Not in cache"); |
|
126 | + if ($gd2_path === null) { |
|
127 | + throw new Exception("Not in cache"); |
|
128 | + } |
|
123 | 129 | # File cache hit. GD2 files are much faster to read than PNGs. |
124 | 130 | # This can throw an Exception (see bug#160). |
125 | 131 | $locmem_cache[$key] = imagecreatefromgd2($gd2_path); |
126 | - } |
|
127 | - catch (Exception $e) |
|
132 | + } catch (Exception $e) |
|
128 | 133 | { |
129 | 134 | # Miss again (or error decoding). Read the image from PNG. |
130 | 135 | |
@@ -132,12 +137,15 @@ discard block |
||
132 | 137 | |
133 | 138 | # Apply all wanted effects. |
134 | 139 | |
135 | - if ($opacity != 1) |
|
136 | - self::change_opacity($locmem_cache[$key], $opacity); |
|
137 | - if ($contrast != 0) |
|
138 | - imagefilter($locmem_cache[$key], IMG_FILTER_CONTRAST, $contrast); |
|
139 | - if ($brightness != 0) |
|
140 | - imagefilter($locmem_cache[$key], IMG_FILTER_BRIGHTNESS, $brightness); |
|
140 | + if ($opacity != 1) { |
|
141 | + self::change_opacity($locmem_cache[$key], $opacity); |
|
142 | + } |
|
143 | + if ($contrast != 0) { |
|
144 | + imagefilter($locmem_cache[$key], IMG_FILTER_CONTRAST, $contrast); |
|
145 | + } |
|
146 | + if ($brightness != 0) { |
|
147 | + imagefilter($locmem_cache[$key], IMG_FILTER_BRIGHTNESS, $brightness); |
|
148 | + } |
|
141 | 149 | if (($r != 0) || ($g != 0) || ($b != 0)) |
142 | 150 | { |
143 | 151 | imagefilter($locmem_cache[$key], IMG_FILTER_GRAYSCALE); |
@@ -182,12 +190,13 @@ discard block |
||
182 | 190 | { |
183 | 191 | $capt = ($cache_struct[6] & TileTree::$FLAG_DRAW_CAPTION); |
184 | 192 | |
185 | - if (($this->zoom <= 8) && (!$capt)) |
|
186 | - $this->draw_cache_tiny($cache_struct); |
|
187 | - elseif (($this->zoom <= 13) && (!$capt)) |
|
188 | - $this->draw_cache_medium($cache_struct); |
|
189 | - else |
|
190 | - $this->draw_cache_large($cache_struct); |
|
193 | + if (($this->zoom <= 8) && (!$capt)) { |
|
194 | + $this->draw_cache_tiny($cache_struct); |
|
195 | + } elseif (($this->zoom <= 13) && (!$capt)) { |
|
196 | + $this->draw_cache_medium($cache_struct); |
|
197 | + } else { |
|
198 | + $this->draw_cache_large($cache_struct); |
|
199 | + } |
|
191 | 200 | |
192 | 201 | # Put caption (this flag is set only when there is plenty of space around). |
193 | 202 | |
@@ -241,8 +250,9 @@ discard block |
||
241 | 250 | $markercenter_x = 12; |
242 | 251 | $markercenter_y = 12; |
243 | 252 | |
244 | - if ($count > 1) |
|
245 | - imagecopy($this->im, $outer_marker, $px - $center_x + 3, $py - $center_y - 2, 0, 0, $width, $height); |
|
253 | + if ($count > 1) { |
|
254 | + imagecopy($this->im, $outer_marker, $px - $center_x + 3, $py - $center_y - 2, 0, 0, $width, $height); |
|
255 | + } |
|
246 | 256 | imagecopy($this->im, $outer_marker, $px - $center_x, $py - $center_y, 0, 0, $width, $height); |
247 | 257 | |
248 | 258 | # Put the inner marker (indicates the type). |
@@ -304,8 +314,9 @@ discard block |
||
304 | 314 | $nextBonus = ""; |
305 | 315 | for ($i=0; ($i<count($words)) || (mb_strlen($nextBonus)>0); $i++) { |
306 | 316 | $word = isset($words[$i])?$words[$i]:""; |
307 | - if (mb_strlen($nextBonus) > 0) |
|
308 | - $word = $nextBonus." ".$word; |
|
317 | + if (mb_strlen($nextBonus) > 0) { |
|
318 | + $word = $nextBonus." ".$word; |
|
319 | + } |
|
309 | 320 | $nextBonus = ""; |
310 | 321 | while (true) { |
311 | 322 | $bbox = imagettfbbox($size, 0, $font, $line.$word); |
@@ -324,8 +335,9 @@ discard block |
||
324 | 335 | continue; |
325 | 336 | } |
326 | 337 | } |
327 | - if (mb_strlen($line) > 0) |
|
328 | - $lines[] = trim($line); |
|
338 | + if (mb_strlen($line) > 0) { |
|
339 | + $lines[] = trim($line); |
|
340 | + } |
|
329 | 341 | return implode("\n", $lines); |
330 | 342 | } |
331 | 343 | |
@@ -389,9 +401,12 @@ discard block |
||
389 | 401 | # Draw an outline. |
390 | 402 | |
391 | 403 | $outline_color = imagecolorallocatealpha($im, 255, 255, 255, 80); |
392 | - for ($x=0; $x<=12; $x+=3) |
|
393 | - for ($y=$size-3; $y<=$size+9; $y+=3) |
|
394 | - $drawer($x, $y, $outline_color); |
|
404 | + for ($x=0; $x<=12; $x+=3) { |
|
405 | + for ($y=$size-3; |
|
406 | + } |
|
407 | + $y<=$size+9; $y+=3) { |
|
408 | + $drawer($x, $y, $outline_color); |
|
409 | + } |
|
395 | 410 | |
396 | 411 | # Add a slight shadow effect (on top of the outline). |
397 | 412 | |
@@ -426,10 +441,11 @@ discard block |
||
426 | 441 | $found = $flags & TileTree::$FLAG_FOUND; |
427 | 442 | $own = $flags & TileTree::$FLAG_OWN; |
428 | 443 | $new = $flags & TileTree::$FLAG_NEW; |
429 | - if ($found && (!($flags & TileTree::$FLAG_DRAW_CAPTION))) |
|
430 | - $a = .35; |
|
431 | - else |
|
432 | - $a = 1; |
|
444 | + if ($found && (!($flags & TileTree::$FLAG_DRAW_CAPTION))) { |
|
445 | + $a = .35; |
|
446 | + } else { |
|
447 | + $a = 1; |
|
448 | + } |
|
433 | 449 | |
434 | 450 | # Put the marker (indicates the type). |
435 | 451 | |
@@ -445,11 +461,12 @@ discard block |
||
445 | 461 | { |
446 | 462 | imagecopy($this->im, $marker, $px - $center_x + 3, $py - $center_y - 2, 0, 0, $width, $height); |
447 | 463 | imagecopy($this->im, $marker, $px - $center_x, $py - $center_y, 0, 0, $width, $height); |
448 | - } |
|
449 | - elseif ($status == 1) # don't put the marker for unavailable caches (X only) |
|
464 | + } elseif ($status == 1) { |
|
465 | + # don't put the marker for unavailable caches (X only) |
|
450 | 466 | { |
451 | 467 | imagecopy($this->im, $marker, $px - $center_x, $py - $center_y, 0, 0, $width, $height); |
452 | 468 | } |
469 | + } |
|
453 | 470 | |
454 | 471 | # If the cache is unavailable, mark it with X. |
455 | 472 | |
@@ -485,16 +502,14 @@ discard block |
||
485 | 502 | |
486 | 503 | $overlay = self::get_image("medium_overlay_own"); |
487 | 504 | imagecopy($this->im, $overlay, $px - $center_x, $py - $center_y, 0, 0, $width, $height); |
488 | - } |
|
489 | - elseif ($found) |
|
505 | + } elseif ($found) |
|
490 | 506 | { |
491 | 507 | # Mark found caches with V. |
492 | 508 | |
493 | 509 | $icon = self::get_image("found", 0.7*$a); |
494 | 510 | imagecopy($this->im, $icon, $px - ($center_x - $markercenter_x) - 7, |
495 | 511 | $py - ($center_y - $markercenter_y) - 9, 0, 0, 16, 16); |
496 | - } |
|
497 | - elseif ($new) |
|
512 | + } elseif ($new) |
|
498 | 513 | { |
499 | 514 | # Mark new caches with additional overlay. |
500 | 515 | |
@@ -546,8 +561,7 @@ discard block |
||
546 | 561 | { |
547 | 562 | imagecopy($this->im, $marker, $px - $center_x + 3, $py - $center_y - 2, 0, 0, $width, $height); |
548 | 563 | imagecopy($this->im, $marker, $px - $center_x, $py - $center_y, 0, 0, $width, $height); |
549 | - } |
|
550 | - elseif ($status == 1) |
|
564 | + } elseif ($status == 1) |
|
551 | 565 | { |
552 | 566 | imagecopy($this->im, $marker, $px - $center_x, $py - $center_y, 0, 0, $width, $height); |
553 | 567 | } |
@@ -577,25 +591,33 @@ discard block |
||
577 | 591 | # This is efficient and yields acceptable results. |
578 | 592 | |
579 | 593 | $matrix = array(); |
580 | - for ($i=0; $i<12; $i++) |
|
581 | - $matrix[] = array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); |
|
594 | + for ($i=0; $i<12; $i++) { |
|
595 | + $matrix[] = array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); |
|
596 | + } |
|
582 | 597 | |
583 | 598 | foreach ($this->rows_ref as &$row_ref) |
584 | 599 | { |
585 | 600 | $mx = ($row_ref[1] + 64) >> 5; |
586 | 601 | $my = ($row_ref[2] + 64) >> 5; |
587 | - if (($mx >= 12) || ($my >= 12)) continue; |
|
588 | - if (($matrix[$mx][$my] === 0) && ($row_ref[8] == 1)) # 8 is count |
|
589 | - $matrix[$mx][$my] = $row_ref[0]; # 0 is cache_id |
|
590 | - else |
|
591 | - $matrix[$mx][$my] = -1; |
|
602 | + if (($mx >= 12) || ($my >= 12)) { |
|
603 | + continue; |
|
604 | + } |
|
605 | + if (($matrix[$mx][$my] === 0) && ($row_ref[8] == 1)) { |
|
606 | + # 8 is count |
|
607 | + $matrix[$mx][$my] = $row_ref[0]; |
|
608 | + } |
|
609 | + # 0 is cache_id |
|
610 | + else { |
|
611 | + $matrix[$mx][$my] = -1; |
|
612 | + } |
|
592 | 613 | } |
593 | 614 | $selected_cache_ids = array(); |
594 | 615 | for ($mx=1; $mx<11; $mx++) |
595 | 616 | { |
596 | 617 | for ($my=1; $my<11; $my++) |
597 | 618 | { |
598 | - if ($matrix[$mx][$my] > 0) # cache_id |
|
619 | + if ($matrix[$mx][$my] > 0) { |
|
620 | + # cache_id |
|
599 | 621 | { |
600 | 622 | # Check all adjacent squares. |
601 | 623 | |
@@ -610,12 +632,14 @@ discard block |
||
610 | 632 | ) |
611 | 633 | $selected_cache_ids[] = $matrix[$mx][$my]; |
612 | 634 | } |
635 | + } |
|
613 | 636 | } |
614 | 637 | } |
615 | 638 | |
616 | - foreach ($this->rows_ref as &$row_ref) |
|
617 | - if (in_array($row_ref[0], $selected_cache_ids)) |
|
639 | + foreach ($this->rows_ref as &$row_ref) { |
|
640 | + if (in_array($row_ref[0], $selected_cache_ids)) |
|
618 | 641 | $row_ref[6] |= TileTree::$FLAG_DRAW_CAPTION; |
642 | + } |
|
619 | 643 | } |
620 | 644 | |
621 | 645 | } |
622 | 646 | \ No newline at end of file |
@@ -57,6 +57,9 @@ |
||
57 | 57 | * Note that $pixels can also be negative or >=256 (up to a margin of 32px). |
58 | 58 | * Count is the number of other caches "eclipsed" by this geocache (such |
59 | 59 | * eclipsed geocaches are not included in the result). |
60 | + * @param integer $zoom |
|
61 | + * @param integer $x |
|
62 | + * @param integer $y |
|
60 | 63 | */ |
61 | 64 | public static function query_fast($zoom, $x, $y, $set_id) |
62 | 65 | { |
@@ -4,19 +4,11 @@ |
||
4 | 4 | |
5 | 5 | use Exception; |
6 | 6 | use okapi\Okapi; |
7 | -use okapi\Settings; |
|
8 | 7 | use okapi\Cache; |
9 | 8 | use okapi\Db; |
10 | -use okapi\OkapiRequest; |
|
11 | -use okapi\OkapiHttpResponse; |
|
12 | -use okapi\ParamMissing; |
|
13 | -use okapi\InvalidParam; |
|
14 | -use okapi\BadRequest; |
|
15 | -use okapi\DoesNotExist; |
|
16 | 9 | use okapi\OkapiInternalRequest; |
17 | 10 | use okapi\OkapiInternalConsumer; |
18 | 11 | use okapi\OkapiServiceRunner; |
19 | -use okapi\OkapiLock; |
|
20 | 12 | |
21 | 13 | |
22 | 14 | class TileTree |
@@ -312,7 +312,7 @@ |
||
312 | 312 | * avoid MySQL casting negative values to 0, we'll do an additional |
313 | 313 | * abs on it. */ |
314 | 314 | |
315 | - return abs(crc32($name)); |
|
315 | + return abs(crc32($name)); |
|
316 | 316 | } |
317 | 317 | |
318 | 318 | private static function latlon_to_z21xy($lat, $lon) |
@@ -41,9 +41,9 @@ discard block |
||
41 | 41 | select status |
42 | 42 | from okapi_tile_status |
43 | 43 | where |
44 | - z = '".Db::escape_string($zoom)."' |
|
45 | - and x = '".Db::escape_string($x)."' |
|
46 | - and y = '".Db::escape_string($y)."' |
|
44 | + z = '".Db::escape_string($zoom) . "' |
|
45 | + and x = '".Db::escape_string($x) . "' |
|
46 | + and y = '".Db::escape_string($y) . "' |
|
47 | 47 | "); |
48 | 48 | } |
49 | 49 | |
@@ -83,9 +83,9 @@ discard block |
||
83 | 83 | $tile_upper_x = $x << 8; |
84 | 84 | $tile_leftmost_y = $y << 8; |
85 | 85 | |
86 | - $zoom_escaped = "'".Db::escape_string($zoom)."'"; |
|
87 | - $tile_upper_x_escaped = "'".Db::escape_string($tile_upper_x)."'"; |
|
88 | - $tile_leftmost_y_escaped = "'".Db::escape_string($tile_leftmost_y)."'"; |
|
86 | + $zoom_escaped = "'" . Db::escape_string($zoom) . "'"; |
|
87 | + $tile_upper_x_escaped = "'" . Db::escape_string($tile_upper_x) . "'"; |
|
88 | + $tile_leftmost_y_escaped = "'" . Db::escape_string($tile_leftmost_y) . "'"; |
|
89 | 89 | return Db::query(" |
90 | 90 | select |
91 | 91 | otc.cache_id, |
@@ -97,10 +97,10 @@ discard block |
||
97 | 97 | okapi_search_results osr |
98 | 98 | where |
99 | 99 | z = $zoom_escaped |
100 | - and x = '".Db::escape_string($x)."' |
|
101 | - and y = '".Db::escape_string($y)."' |
|
100 | + and x = '" . Db::escape_string($x) . "' |
|
101 | + and y = '".Db::escape_string($y) . "' |
|
102 | 102 | and otc.cache_id = osr.cache_id |
103 | - and osr.set_id = '".Db::escape_string($set_id)."' |
|
103 | + and osr.set_id = '".Db::escape_string($set_id) . "' |
|
104 | 104 | group by |
105 | 105 | z21x >> (3 + (21 - $zoom_escaped)), |
106 | 106 | z21y >> (3 + (21 - $zoom_escaped)) |
@@ -135,8 +135,8 @@ discard block |
||
135 | 135 | # but there is *no need* to - this query is run seldom and is cached. |
136 | 136 | |
137 | 137 | $params = array(); |
138 | - $params['status'] = "Available|Temporarily unavailable|Archived"; # we want them all |
|
139 | - $params['limit'] = "10000000"; # no limit |
|
138 | + $params['status'] = "Available|Temporarily unavailable|Archived"; # we want them all |
|
139 | + $params['limit'] = "10000000"; # no limit |
|
140 | 140 | |
141 | 141 | $internal_request = new OkapiInternalRequest(new OkapiInternalConsumer(), null, $params); |
142 | 142 | $internal_request->skip_limits = true; |
@@ -162,14 +162,14 @@ discard block |
||
162 | 162 | z, x, y, cache_id, z21x, z21y, status, type, rating, flags, name_crc |
163 | 163 | ) values ( |
164 | 164 | 0, 0, 0, |
165 | - '".Db::escape_string($row[0])."', |
|
166 | - '".Db::escape_string($row[1])."', |
|
167 | - '".Db::escape_string($row[2])."', |
|
168 | - '".Db::escape_string($row[3])."', |
|
169 | - '".Db::escape_string($row[4])."', |
|
170 | - ".(($row[5] === null) ? "null" : "'".Db::escape_string($row[5])."'").", |
|
171 | - '".Db::escape_string($row[6])."', |
|
172 | - '".Db::escape_string($row[7])."' |
|
165 | + '".Db::escape_string($row[0]) . "', |
|
166 | + '".Db::escape_string($row[1]) . "', |
|
167 | + '".Db::escape_string($row[2]) . "', |
|
168 | + '".Db::escape_string($row[3]) . "', |
|
169 | + '".Db::escape_string($row[4]) . "', |
|
170 | + ".(($row[5] === null) ? "null" : "'" . Db::escape_string($row[5]) . "'") . ", |
|
171 | + '".Db::escape_string($row[6]) . "', |
|
172 | + '".Db::escape_string($row[7]) . "' |
|
173 | 173 | ); |
174 | 174 | "); |
175 | 175 | } |
@@ -229,31 +229,31 @@ discard block |
||
229 | 229 | flags, name_crc |
230 | 230 | ) |
231 | 231 | select |
232 | - '".Db::escape_string($zoom)."', |
|
233 | - '".Db::escape_string($x)."', |
|
234 | - '".Db::escape_string($y)."', |
|
232 | + '".Db::escape_string($zoom) . "', |
|
233 | + '".Db::escape_string($x) . "', |
|
234 | + '".Db::escape_string($y) . "', |
|
235 | 235 | cache_id, z21x, z21y, status, type, rating, |
236 | 236 | flags, name_crc |
237 | 237 | from okapi_tile_caches tc2 |
238 | 238 | where |
239 | - z = '".Db::escape_string($parent_zoom)."' |
|
240 | - and x = '".Db::escape_string($parent_x)."' |
|
241 | - and y = '".Db::escape_string($parent_y)."' |
|
239 | + z = '".Db::escape_string($parent_zoom) . "' |
|
240 | + and x = '".Db::escape_string($parent_x) . "' |
|
241 | + and y = '".Db::escape_string($parent_y) . "' |
|
242 | 242 | and z21x between $left_z21x and $right_z21x |
243 | 243 | and z21y between $top_z21y and $bottom_z21y |
244 | 244 | "); |
245 | 245 | Db::execute("unlock tables;"); |
246 | 246 | } catch (Exception $e) { |
247 | - Db::execute("unlock tables"); // No "finally" in PHP 5.3 |
|
247 | + Db::execute("unlock tables"); // No "finally" in PHP 5.3 |
|
248 | 248 | throw $e; |
249 | 249 | } |
250 | 250 | $test = Db::select_value(" |
251 | 251 | select 1 |
252 | 252 | from okapi_tile_caches |
253 | 253 | where |
254 | - z = '".Db::escape_string($zoom)."' |
|
255 | - and x = '".Db::escape_string($x)."' |
|
256 | - and y = '".Db::escape_string($y)."' |
|
254 | + z = '".Db::escape_string($zoom) . "' |
|
255 | + and x = '".Db::escape_string($x) . "' |
|
256 | + and y = '".Db::escape_string($y) . "' |
|
257 | 257 | limit 1; |
258 | 258 | "); |
259 | 259 | if ($test) |
@@ -268,10 +268,10 @@ discard block |
||
268 | 268 | Db::execute(" |
269 | 269 | replace into okapi_tile_status (z, x, y, status) |
270 | 270 | values ( |
271 | - '".Db::escape_string($zoom)."', |
|
272 | - '".Db::escape_string($x)."', |
|
273 | - '".Db::escape_string($y)."', |
|
274 | - '".Db::escape_string($status)."' |
|
271 | + '".Db::escape_string($zoom) . "', |
|
272 | + '".Db::escape_string($x) . "', |
|
273 | + '".Db::escape_string($y) . "', |
|
274 | + '".Db::escape_string($status) . "' |
|
275 | 275 | ); |
276 | 276 | "); |
277 | 277 | |
@@ -319,7 +319,7 @@ discard block |
||
319 | 319 | { |
320 | 320 | $offset = 128 << 21; |
321 | 321 | $x = round($offset + ($offset * $lon / 180)); |
322 | - $y = round($offset - $offset/pi() * log((1 + sin($lat * pi() / 180)) / (1 - sin($lat * pi() / 180))) / 2); |
|
322 | + $y = round($offset - $offset / pi() * log((1 + sin($lat * pi() / 180)) / (1 - sin($lat * pi() / 180))) / 2); |
|
323 | 323 | return array($x, $y); |
324 | 324 | } |
325 | 325 | } |
326 | 326 | \ No newline at end of file |
@@ -64,19 +64,23 @@ discard block |
||
64 | 64 | # (and if it was, was it empty). |
65 | 65 | |
66 | 66 | $status = self::get_tile_status($zoom, $x, $y); |
67 | - if ($status === null) # Not yet computed. |
|
67 | + if ($status === null) { |
|
68 | + # Not yet computed. |
|
68 | 69 | { |
69 | 70 | # Note, that computing the tile does not involve taking any |
70 | 71 | # search parameters. |
71 | 72 | |
72 | 73 | $status = self::compute_tile($zoom, $x, $y); |
73 | 74 | } |
75 | + } |
|
74 | 76 | |
75 | - if ($status === 1) # Computed and empty. |
|
77 | + if ($status === 1) { |
|
78 | + # Computed and empty. |
|
76 | 79 | { |
77 | 80 | # This tile was already computed and it is empty. |
78 | 81 | return null; |
79 | 82 | } |
83 | + } |
|
80 | 84 | |
81 | 85 | # If we got here, then the tile is computed and not empty (status 2). |
82 | 86 | |
@@ -121,8 +125,9 @@ discard block |
||
121 | 125 | # For low-level tiles, this can be expensive. |
122 | 126 | |
123 | 127 | $status = self::get_tile_status($zoom, $x, $y); |
124 | - if ($status !== null) |
|
125 | - return $status; |
|
128 | + if ($status !== null) { |
|
129 | + return $status; |
|
130 | + } |
|
126 | 131 | |
127 | 132 | if ($zoom === 0) |
128 | 133 | { |
@@ -174,8 +179,7 @@ discard block |
||
174 | 179 | "); |
175 | 180 | } |
176 | 181 | $status = 2; |
177 | - } |
|
178 | - else |
|
182 | + } else |
|
179 | 183 | { |
180 | 184 | # We will use the parent tile to compute the contents of this tile. |
181 | 185 | |
@@ -184,19 +188,23 @@ discard block |
||
184 | 188 | $parent_y = $y >> 1; |
185 | 189 | |
186 | 190 | $status = self::get_tile_status($parent_zoom, $parent_x, $parent_y); |
187 | - if ($status === null) # Not computed. |
|
191 | + if ($status === null) { |
|
192 | + # Not computed. |
|
188 | 193 | { |
189 | 194 | $time_started = microtime(true); |
195 | + } |
|
190 | 196 | $status = self::compute_tile($parent_zoom, $parent_x, $parent_y); |
191 | 197 | } |
192 | 198 | |
193 | - if ($status === 1) # Computed and empty. |
|
199 | + if ($status === 1) { |
|
200 | + # Computed and empty. |
|
194 | 201 | { |
195 | 202 | # No need to check. |
196 | 203 | } |
197 | 204 | else # Computed, not empty. |
198 | 205 | { |
199 | 206 | $scale = 8 + 21 - $zoom; |
207 | + } |
|
200 | 208 | $parentcenter_z21x = (($parent_x << 1) | 1) << $scale; |
201 | 209 | $parentcenter_z21y = (($parent_y << 1) | 1) << $scale; |
202 | 210 | $margin = 1 << ($scale - 2); |
@@ -209,14 +217,20 @@ discard block |
||
209 | 217 | # |1 2| |
210 | 218 | # |3 4| |
211 | 219 | |
212 | - if ($x & 1) # 2 or 4 |
|
220 | + if ($x & 1) { |
|
221 | + # 2 or 4 |
|
213 | 222 | $left_z21x = $parentcenter_z21x - $margin; |
214 | - else # 1 or 3 |
|
223 | + } else { |
|
224 | + # 1 or 3 |
|
215 | 225 | $right_z21x = $parentcenter_z21x + $margin; |
216 | - if ($y & 1) # 3 or 4 |
|
226 | + } |
|
227 | + if ($y & 1) { |
|
228 | + # 3 or 4 |
|
217 | 229 | $top_z21y = $parentcenter_z21y - $margin; |
218 | - else # 1 or 2 |
|
230 | + } else { |
|
231 | + # 1 or 2 |
|
219 | 232 | $bottom_z21y = $parentcenter_z21y + $margin; |
233 | + } |
|
220 | 234 | |
221 | 235 | # Cache the result. |
222 | 236 | |
@@ -256,10 +270,11 @@ discard block |
||
256 | 270 | and y = '".Db::escape_string($y)."' |
257 | 271 | limit 1; |
258 | 272 | "); |
259 | - if ($test) |
|
260 | - $status = 2; |
|
261 | - else |
|
262 | - $status = 1; |
|
273 | + if ($test) { |
|
274 | + $status = 2; |
|
275 | + } else { |
|
276 | + $status = 1; |
|
277 | + } |
|
263 | 278 | } |
264 | 279 | } |
265 | 280 | |
@@ -294,12 +309,15 @@ discard block |
||
294 | 309 | return false; |
295 | 310 | } |
296 | 311 | $flags = 0; |
297 | - if (($cache['founds'] > 6) && (($cache['recommendations'] / $cache['founds']) > 0.3)) |
|
298 | - $flags |= self::$FLAG_STAR; |
|
299 | - if ($cache['trackables_count'] > 0) |
|
300 | - $flags |= self::$FLAG_HAS_TRACKABLES; |
|
301 | - if ($cache['founds'] == 0) |
|
302 | - $flags |= self::$FLAG_NOT_YET_FOUND; |
|
312 | + if (($cache['founds'] > 6) && (($cache['recommendations'] / $cache['founds']) > 0.3)) { |
|
313 | + $flags |= self::$FLAG_STAR; |
|
314 | + } |
|
315 | + if ($cache['trackables_count'] > 0) { |
|
316 | + $flags |= self::$FLAG_HAS_TRACKABLES; |
|
317 | + } |
|
318 | + if ($cache['founds'] == 0) { |
|
319 | + $flags |= self::$FLAG_NOT_YET_FOUND; |
|
320 | + } |
|
303 | 321 | return array($cache['internal_id'], $z21x, $z21y, Okapi::cache_status_name2id($cache['status']), |
304 | 322 | Okapi::cache_type_name2id($cache['type']), $cache['rating'], $flags, |
305 | 323 | self::compute_name_crc($cache['name'])); |
@@ -108,6 +108,9 @@ |
||
108 | 108 | return $str1 == $str2; |
109 | 109 | } |
110 | 110 | |
111 | + /** |
|
112 | + * @param string $new_notes |
|
113 | + */ |
|
111 | 114 | private static function update_notes($cache_id, $user_id, $new_notes) |
112 | 115 | { |
113 | 116 | if (Settings::get('OC_BRANCH') == 'oc.de') |
@@ -2,16 +2,12 @@ |
||
2 | 2 | |
3 | 3 | namespace okapi\services\caches\save_personal_notes; |
4 | 4 | |
5 | -use Exception; |
|
6 | 5 | use okapi\Okapi; |
7 | 6 | use okapi\Db; |
8 | 7 | use okapi\OkapiRequest; |
9 | 8 | use okapi\ParamMissing; |
10 | -use okapi\InvalidParam; |
|
11 | -use okapi\BadRequest; |
|
12 | 9 | use okapi\OkapiInternalRequest; |
13 | 10 | use okapi\OkapiServiceRunner; |
14 | -use okapi\OkapiAccessToken; |
|
15 | 11 | use okapi\Settings; |
16 | 12 | |
17 | 13 |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | |
86 | 86 | /* APPEND mode */ |
87 | 87 | |
88 | - $ret_saved_value = trim($current_value)."\n\n".trim($new_value); |
|
88 | + $ret_saved_value = trim($current_value) . "\n\n" . trim($new_value); |
|
89 | 89 | self::update_notes($cache_id, $request->token->user_id, $ret_saved_value); |
90 | 90 | } |
91 | 91 | |
@@ -123,11 +123,11 @@ discard block |
||
123 | 123 | from coordinates |
124 | 124 | where |
125 | 125 | type = 2 -- personal note |
126 | - and cache_id = '".Db::escape_string($cache_id)."' |
|
127 | - and user_id = '".Db::escape_string($user_id)."' |
|
126 | + and cache_id = '".Db::escape_string($cache_id) . "' |
|
127 | + and user_id = '".Db::escape_string($user_id) . "' |
|
128 | 128 | "); |
129 | 129 | $id = null; |
130 | - if($row = Db::fetch_assoc($rs)) { |
|
130 | + if ($row = Db::fetch_assoc($rs)) { |
|
131 | 131 | $id = $row['id']; |
132 | 132 | } |
133 | 133 | if ($id == null) { |
@@ -137,17 +137,17 @@ discard block |
||
137 | 137 | description |
138 | 138 | ) values ( |
139 | 139 | 2, 0, 0, |
140 | - '".Db::escape_string($cache_id)."', |
|
141 | - '".Db::escape_string($user_id)."', |
|
142 | - '".Db::escape_string($new_notes)."' |
|
140 | + '".Db::escape_string($cache_id) . "', |
|
141 | + '".Db::escape_string($user_id) . "', |
|
142 | + '".Db::escape_string($new_notes) . "' |
|
143 | 143 | ) |
144 | 144 | "); |
145 | 145 | } else { |
146 | 146 | Db::query(" |
147 | 147 | update coordinates |
148 | - set description = '".Db::escape_string($new_notes)."' |
|
148 | + set description = '".Db::escape_string($new_notes) . "' |
|
149 | 149 | where |
150 | - id = '".Db::escape_string($id)."' |
|
150 | + id = '".Db::escape_string($id) . "' |
|
151 | 151 | and type = 2 |
152 | 152 | "); |
153 | 153 | } |
@@ -158,11 +158,11 @@ discard block |
||
158 | 158 | select max(note_id) as id |
159 | 159 | from cache_notes |
160 | 160 | where |
161 | - cache_id = '".Db::escape_string($cache_id)."' |
|
162 | - and user_id = '".Db::escape_string($user_id)."' |
|
161 | + cache_id = '".Db::escape_string($cache_id) . "' |
|
162 | + and user_id = '".Db::escape_string($user_id) . "' |
|
163 | 163 | "); |
164 | 164 | $id = null; |
165 | - if($row = Db::fetch_assoc($rs)) { |
|
165 | + if ($row = Db::fetch_assoc($rs)) { |
|
166 | 166 | $id = $row['id']; |
167 | 167 | } |
168 | 168 | if ($id == null) { |
@@ -170,20 +170,20 @@ discard block |
||
170 | 170 | insert into cache_notes ( |
171 | 171 | cache_id, user_id, date, desc_html, `desc` |
172 | 172 | ) values ( |
173 | - '".Db::escape_string($cache_id)."', |
|
174 | - '".Db::escape_string($user_id)."', |
|
173 | + '".Db::escape_string($cache_id) . "', |
|
174 | + '".Db::escape_string($user_id) . "', |
|
175 | 175 | NOW(), 0, |
176 | - '".Db::escape_string($new_notes)."' |
|
176 | + '".Db::escape_string($new_notes) . "' |
|
177 | 177 | ) |
178 | 178 | "); |
179 | 179 | } else { |
180 | 180 | Db::query(" |
181 | 181 | update cache_notes |
182 | 182 | set |
183 | - `desc` = '".Db::escape_string($new_notes)."', |
|
183 | + `desc` = '".Db::escape_string($new_notes) . "', |
|
184 | 184 | desc_html = 0, |
185 | 185 | date = NOW() |
186 | - where note_id = '".Db::escape_string($id)."' |
|
186 | + where note_id = '".Db::escape_string($id) . "' |
|
187 | 187 | "); |
188 | 188 | } |
189 | 189 | } |
@@ -197,12 +197,12 @@ discard block |
||
197 | 197 | delete from coordinates |
198 | 198 | where |
199 | 199 | type = 2 -- personal note |
200 | - and cache_id = '".Db::escape_string($cache_id)."' |
|
201 | - and user_id = '".Db::escape_string($user_id)."' |
|
200 | + and cache_id = '".Db::escape_string($cache_id) . "' |
|
201 | + and user_id = '".Db::escape_string($user_id) . "' |
|
202 | 202 | and longitude = 0 |
203 | 203 | and latitude = 0 |
204 | 204 | "); |
205 | - if (Db::get_affected_row_count() <= 0){ |
|
205 | + if (Db::get_affected_row_count() <= 0) { |
|
206 | 206 | # no rows deleted - record either doesn't exist, or has coords |
207 | 207 | # remove only description |
208 | 208 | Db::execute(" |
@@ -210,16 +210,16 @@ discard block |
||
210 | 210 | set description = null |
211 | 211 | where |
212 | 212 | type = 2 |
213 | - and cache_id = '".Db::escape_string($cache_id)."' |
|
214 | - and user_id = '".Db::escape_string($user_id)."' |
|
213 | + and cache_id = '".Db::escape_string($cache_id) . "' |
|
214 | + and user_id = '".Db::escape_string($user_id) . "' |
|
215 | 215 | "); |
216 | 216 | } |
217 | 217 | } else { # oc.pl branch |
218 | 218 | Db::execute(" |
219 | 219 | delete from cache_notes |
220 | 220 | where |
221 | - cache_id = '".Db::escape_string($cache_id)."' |
|
222 | - and user_id = '".Db::escape_string($user_id)."' |
|
221 | + cache_id = '".Db::escape_string($cache_id) . "' |
|
222 | + and user_id = '".Db::escape_string($user_id) . "' |
|
223 | 223 | "); |
224 | 224 | } |
225 | 225 | } |
@@ -29,8 +29,9 @@ discard block |
||
29 | 29 | # Get current notes, and verify cache_code |
30 | 30 | |
31 | 31 | $cache_code = $request->get_parameter('cache_code'); |
32 | - if ($cache_code == null) |
|
33 | - throw new ParamMissing('cache_code'); |
|
32 | + if ($cache_code == null) { |
|
33 | + throw new ParamMissing('cache_code'); |
|
34 | + } |
|
34 | 35 | $geocache = OkapiServiceRunner::call( |
35 | 36 | 'services/caches/geocache', |
36 | 37 | new OkapiInternalRequest($request->consumer, $request->token, array( |
@@ -47,14 +48,16 @@ discard block |
||
47 | 48 | # old_value |
48 | 49 | |
49 | 50 | $old_value = $request->get_parameter('old_value'); |
50 | - if ($old_value === null) |
|
51 | - $old_value = ''; |
|
51 | + if ($old_value === null) { |
|
52 | + $old_value = ''; |
|
53 | + } |
|
52 | 54 | |
53 | 55 | # new_value (force "no HTML" policy). |
54 | 56 | |
55 | 57 | $new_value = $request->get_parameter('new_value'); |
56 | - if ($new_value === null) |
|
57 | - throw new ParamMissing('new_value'); |
|
58 | + if ($new_value === null) { |
|
59 | + throw new ParamMissing('new_value'); |
|
60 | + } |
|
58 | 61 | |
59 | 62 | # Force "no HTML" policy. |
60 | 63 | |
@@ -98,10 +101,12 @@ discard block |
||
98 | 101 | |
99 | 102 | private static function str_equals($str1, $str2) |
100 | 103 | { |
101 | - if ($str1 == null) |
|
102 | - $str1 = ''; |
|
103 | - if ($str2 == null) |
|
104 | - $str2 = ''; |
|
104 | + if ($str1 == null) { |
|
105 | + $str1 = ''; |
|
106 | + } |
|
107 | + if ($str2 == null) { |
|
108 | + $str2 = ''; |
|
109 | + } |
|
105 | 110 | $str1 = mb_ereg_replace("[ \t\n\r\x0B]+", '', $str1); |
106 | 111 | $str2 = mb_ereg_replace("[ \t\n\r\x0B]+", '', $str2); |
107 | 112 | |
@@ -151,8 +156,7 @@ discard block |
||
151 | 156 | and type = 2 |
152 | 157 | "); |
153 | 158 | } |
154 | - } |
|
155 | - else # oc.pl branch |
|
159 | + } else # oc.pl branch |
|
156 | 160 | { |
157 | 161 | $rs = Db::query(" |
158 | 162 | select max(note_id) as id |
@@ -24,6 +24,7 @@ discard block |
||
24 | 24 | /** |
25 | 25 | * Get [set_id, date_created, expires] for the given params_hash |
26 | 26 | * (or [null, null, null] if not found). |
27 | + * @param string $params_hash |
|
27 | 28 | */ |
28 | 29 | private static function find_param_set($params_hash, $ref_max_age) |
29 | 30 | { |
@@ -92,6 +93,7 @@ discard block |
||
92 | 93 | /** |
93 | 94 | * Important: YOU HAVE TO make sure $tables and $where_conds don't contain |
94 | 95 | * unescaped user-supplied data! |
96 | + * @param string[] $tables |
|
95 | 97 | */ |
96 | 98 | public static function get_set($tables, $joins, $where_conds, $min_store, $ref_max_age) |
97 | 99 | { |
@@ -6,7 +6,6 @@ |
||
6 | 6 | |
7 | 7 | use okapi\Okapi; |
8 | 8 | use okapi\OkapiRequest; |
9 | -use okapi\ParamMissing; |
|
10 | 9 | use okapi\InvalidParam; |
11 | 10 | use okapi\Db; |
12 | 11 | use okapi\OkapiLock; |
@@ -34,8 +34,8 @@ discard block |
||
34 | 34 | unix_timestamp(expires) as expires |
35 | 35 | from okapi_search_sets |
36 | 36 | where |
37 | - params_hash = '".Db::escape_string($params_hash)."' |
|
38 | - and date_add(date_created, interval '".Db::escape_string($ref_max_age)."' second) > now() |
|
37 | + params_hash = '".Db::escape_string($params_hash) . "' |
|
38 | + and date_add(date_created, interval '".Db::escape_string($ref_max_age) . "' second) > now() |
|
39 | 39 | order by id desc |
40 | 40 | limit 1 |
41 | 41 | "); |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | $tmp = $request->get_parameter('min_store'); |
52 | 52 | if ($tmp === null) $tmp = "300"; |
53 | 53 | $min_store = intval($tmp); |
54 | - if (("$min_store" !== $tmp) ||($min_store < 0) || ($min_store > 64800)) |
|
54 | + if (("$min_store" !== $tmp) || ($min_store < 0) || ($min_store > 64800)) |
|
55 | 55 | throw new InvalidParam('min_store', "Has to be in the 0..64800 range."); |
56 | 56 | |
57 | 57 | $tmp = $request->get_parameter('ref_max_age'); |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | values ( |
129 | 129 | 'processing in progress', |
130 | 130 | now(), |
131 | - date_add(now(), interval '".Db::escape_string($min_store + 60)."' second) |
|
131 | + date_add(now(), interval '".Db::escape_string($min_store + 60) . "' second) |
|
132 | 132 | ) |
133 | 133 | "); |
134 | 134 | $set_id = Db::last_insert_id(); |
@@ -137,12 +137,12 @@ discard block |
||
137 | 137 | Db::execute(" |
138 | 138 | insert into okapi_search_results (set_id, cache_id) |
139 | 139 | select distinct |
140 | - '".Db::escape_string($set_id)."', |
|
140 | + '".Db::escape_string($set_id) . "', |
|
141 | 141 | caches.cache_id |
142 | 142 | from |
143 | - ".implode(", ", $tables)." |
|
144 | - ".implode(" ", $joins)." |
|
145 | - where (".implode(") and (", $where_conds).") |
|
143 | + ".implode(", ", $tables) . " |
|
144 | + ".implode(" ", $joins) . " |
|
145 | + where (".implode(") and (", $where_conds) . ") |
|
146 | 146 | "); |
147 | 147 | |
148 | 148 | # Lock barrier, to make sure the data is visible by other |
@@ -153,8 +153,8 @@ discard block |
||
153 | 153 | |
154 | 154 | Db::execute(" |
155 | 155 | update okapi_search_sets |
156 | - set params_hash = '".Db::escape_string($params_hash)."' |
|
157 | - where id = '".Db::escape_string($set_id)."' |
|
156 | + set params_hash = '".Db::escape_string($params_hash) . "' |
|
157 | + where id = '".Db::escape_string($set_id) . "' |
|
158 | 158 | "); |
159 | 159 | } else { |
160 | 160 | # Some other thread acquired the lock before us and it has |
@@ -178,8 +178,8 @@ discard block |
||
178 | 178 | { |
179 | 179 | Db::execute(" |
180 | 180 | update okapi_search_sets |
181 | - set expires = date_add(now(), interval '".Db::escape_string($min_store + 60)."' second) |
|
182 | - where id = '".Db::escape_string($set_id)."' |
|
181 | + set expires = date_add(now(), interval '".Db::escape_string($min_store + 60) . "' second) |
|
182 | + where id = '".Db::escape_string($set_id) . "' |
|
183 | 183 | "); |
184 | 184 | } |
185 | 185 |
@@ -39,8 +39,9 @@ discard block |
||
39 | 39 | order by id desc |
40 | 40 | limit 1 |
41 | 41 | "); |
42 | - if ($tmp === null) |
|
43 | - return array(null, null, null); |
|
42 | + if ($tmp === null) { |
|
43 | + return array(null, null, null); |
|
44 | + } |
|
44 | 45 | return array($tmp['id'], $tmp['date_created'], $tmp['expires']); |
45 | 46 | } |
46 | 47 | |
@@ -49,17 +50,25 @@ discard block |
||
49 | 50 | # "Cache control" parameters. |
50 | 51 | |
51 | 52 | $tmp = $request->get_parameter('min_store'); |
52 | - if ($tmp === null) $tmp = "300"; |
|
53 | + if ($tmp === null) { |
|
54 | + $tmp = "300"; |
|
55 | + } |
|
53 | 56 | $min_store = intval($tmp); |
54 | - if (("$min_store" !== $tmp) ||($min_store < 0) || ($min_store > 64800)) |
|
55 | - throw new InvalidParam('min_store', "Has to be in the 0..64800 range."); |
|
57 | + if (("$min_store" !== $tmp) ||($min_store < 0) || ($min_store > 64800)) { |
|
58 | + throw new InvalidParam('min_store', "Has to be in the 0..64800 range."); |
|
59 | + } |
|
56 | 60 | |
57 | 61 | $tmp = $request->get_parameter('ref_max_age'); |
58 | - if ($tmp === null) $tmp = "300"; |
|
59 | - if ($tmp == "nolimit") $tmp = "9999999"; |
|
62 | + if ($tmp === null) { |
|
63 | + $tmp = "300"; |
|
64 | + } |
|
65 | + if ($tmp == "nolimit") { |
|
66 | + $tmp = "9999999"; |
|
67 | + } |
|
60 | 68 | $ref_max_age = intval($tmp); |
61 | - if (("$ref_max_age" !== $tmp) || ($ref_max_age < 300)) |
|
62 | - throw new InvalidParam('ref_max_age', "Has to be >=300."); |
|
69 | + if (("$ref_max_age" !== $tmp) || ($ref_max_age < 300)) { |
|
70 | + throw new InvalidParam('ref_max_age', "Has to be >=300."); |
|
71 | + } |
|
63 | 72 | |
64 | 73 | # Search params. |
65 | 74 | |
@@ -75,10 +84,11 @@ discard block |
||
75 | 84 | $search_params['where_conds'] |
76 | 85 | ); |
77 | 86 | |
78 | - if (isset($search_params['extra_joins']) && is_array($search_params['extra_joins'])) |
|
79 | - $joins = $search_params['extra_joins']; |
|
80 | - else |
|
81 | - $joins = array(); |
|
87 | + if (isset($search_params['extra_joins']) && is_array($search_params['extra_joins'])) { |
|
88 | + $joins = $search_params['extra_joins']; |
|
89 | + } else { |
|
90 | + $joins = array(); |
|
91 | + } |
|
82 | 92 | |
83 | 93 | unset($search_params); |
84 | 94 | |
@@ -161,8 +171,7 @@ discard block |
||
161 | 171 | # generated the result set. We don't need to do anything. |
162 | 172 | } |
163 | 173 | $lock->release(); |
164 | - } |
|
165 | - catch (Exception $e) |
|
174 | + } catch (Exception $e) |
|
166 | 175 | { |
167 | 176 | # SQL error? Make sure the lock is released and rethrow. |
168 | 177 |