@@ -20,8 +20,7 @@ |
||
20 | 20 | public static function call(OkapiRequest $request) |
21 | 21 | { |
22 | 22 | $callback = $request->get_parameter('oauth_callback'); |
23 | - if (!$callback) |
|
24 | - { |
|
23 | + if (!$callback) { |
|
25 | 24 | # We require the 1.0a flow (throw an error when there is no oauth_callback). |
26 | 25 | throw new ParamMissing("oauth_callback"); |
27 | 26 | } |
@@ -21,8 +21,7 @@ |
||
21 | 21 | public static function call(OkapiRequest $request) |
22 | 22 | { |
23 | 23 | $verifier = $request->get_parameter('oauth_verifier'); |
24 | - if (!$verifier) |
|
25 | - { |
|
24 | + if (!$verifier) { |
|
26 | 25 | # We require the 1.0a flow (throw an error when there is no oauth_verifier). |
27 | 26 | throw new ParamMissing("oauth_verifier"); |
28 | 27 | } |
@@ -27,7 +27,7 @@ |
||
27 | 27 | <?php if (isset($c['ratings'])) { |
28 | 28 | ?><ratings> |
29 | 29 | <?php |
30 | - foreach ($c['ratings'] as $rating_key => $rating_val){ |
|
30 | + foreach ($c['ratings'] as $rating_key => $rating_val) { |
|
31 | 31 | echo "<$rating_key>$rating_val</$rating_key>\n"; |
32 | 32 | } |
33 | 33 | ?> |
@@ -27,7 +27,7 @@ |
||
27 | 27 | <?php if (isset($c['ratings'])) { |
28 | 28 | ?><ratings> |
29 | 29 | <?php |
30 | - foreach ($c['ratings'] as $rating_key => $rating_val){ |
|
30 | + foreach ($c['ratings'] as $rating_key => $rating_val) { |
|
31 | 31 | echo "<$rating_key>$rating_val</$rating_key>\n"; |
32 | 32 | } |
33 | 33 | ?> |
@@ -43,7 +43,7 @@ |
||
43 | 43 | # Geocaching.com (groundspeak:) and Opencaching.com (ox:) extensions. It will |
44 | 44 | # also include personal data (if the method was invoked using Level 3 Authentication). |
45 | 45 | |
46 | - $file_item_name = "data_".time()."_".rand(100000,999999).".gpx"; |
|
46 | + $file_item_name = "data_".time()."_".rand(100000, 999999).".gpx"; |
|
47 | 47 | $ggz_file = array( |
48 | 48 | 'name' => $file_item_name, |
49 | 49 | 'crc32' => sprintf('%08X', crc32($gpx_result['gpx'])), |
@@ -17,7 +17,7 @@ discard block |
||
17 | 17 | http://www.gsak.net/xmlv1/5 http://www.gsak.net/xmlv1/5/gsak.xsd |
18 | 18 | "> |
19 | 19 | <name><?= $vars['installation']['site_name'] ?> Geocache Search Results</name> |
20 | - <desc><?= $vars['installation']['site_name'] ?> Geocache Search Results, downloaded via OKAPI - <?= $vars['installation']['okapi_base_url'] . ($vars['alt_wpts'] && $vars['ns_gsak'] ? ' (HasChildren)' : '') ?></desc> |
|
20 | + <desc><?= $vars['installation']['site_name'] ?> Geocache Search Results, downloaded via OKAPI - <?= $vars['installation']['okapi_base_url'].($vars['alt_wpts'] && $vars['ns_gsak'] ? ' (HasChildren)' : '') ?></desc> |
|
21 | 21 | <author><?= $vars['installation']['site_name'] ?></author> |
22 | 22 | <url><?= $vars['installation']['site_url'] ?></url> |
23 | 23 | <urlname><?= $vars['installation']['site_name'] ?></urlname> |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | <?php if ($vars['protection_areas'] == 'desc:text' && count($c['protection_areas'])) { ?> |
141 | 141 | <p><?= _("The cache probably is located in the following protection areas:") ?></p> |
142 | 142 | <ul> |
143 | - <?php foreach($c['protection_areas'] as $protection_area) { ?> |
|
143 | + <?php foreach ($c['protection_areas'] as $protection_area) { ?> |
|
144 | 144 | <li><?= Okapi::xmlescape($protection_area['type'])." - ".Okapi::xmlescape($protection_area['name']) ?></li> |
145 | 145 | <?php } ?> |
146 | 146 | </ul;> |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | <groundspeak:date><?= $log['date'] ?></groundspeak:date> |
158 | 158 | <groundspeak:type><?= $log['type'] ?></groundspeak:type> |
159 | 159 | <groundspeak:finder id="<?= $vars['user_uuid_to_internal_id'][$log['user']['uuid']] ?>"><?= Okapi::xmlescape($log['user']['username']) ?></groundspeak:finder> |
160 | - <groundspeak:text encoded="False"><?= $log['was_recommended'] ? "(*) ": "" ?><?= Okapi::xmlescape($log['comment']) ?></groundspeak:text> |
|
160 | + <groundspeak:text encoded="False"><?= $log['was_recommended'] ? "(*) " : "" ?><?= Okapi::xmlescape($log['comment']) ?></groundspeak:text> |
|
161 | 161 | </groundspeak:log> |
162 | 162 | <?php } ?> |
163 | 163 | </groundspeak:logs> |
@@ -220,7 +220,7 @@ discard block |
||
220 | 220 | <?php } ?> |
221 | 221 | </wpt> |
222 | 222 | <?php |
223 | - if (isset($wpt_ref['ggz_entry'])){ |
|
223 | + if (isset($wpt_ref['ggz_entry'])) { |
|
224 | 224 | $wpt_ref['ggz_entry']['file_len'] = ob_get_length() - $wpt_ref['ggz_entry']['file_pos']; |
225 | 225 | } |
226 | 226 | ?> |
@@ -40,14 +40,16 @@ discard block |
||
40 | 40 | <urlname><?= Okapi::xmlescape($c['name']) ?></urlname> |
41 | 41 | <sym><?= ($vars['mark_found'] && $c['is_found']) ? "Geocache Found" : "Geocache" ?></sym> |
42 | 42 | <type>Geocache|<?= $vars['cache_GPX_types'][$c['type']] ?></type> |
43 | - <?php if ($vars['ns_ground']) { /* Does user want us to include Groundspeak's <cache> element? */ ?> |
|
43 | + <?php if ($vars['ns_ground']) { |
|
44 | +/* Does user want us to include Groundspeak's <cache> element? */ ?> |
|
44 | 45 | <groundspeak:cache archived="<?= ($c['status'] == 'Archived') ? "True" : "False" ?>" available="<?= ($c['status'] == 'Available') ? "True" : "False" ?>" id="<?= $c['internal_id'] ?>" xmlns:groundspeak="http://www.groundspeak.com/cache/1/0/1"> |
45 | 46 | <groundspeak:name><?= Okapi::xmlescape(isset($c['name_2']) ? $c['name_2'] : $c['name']) ?></groundspeak:name> |
46 | 47 | <groundspeak:placed_by><?= Okapi::xmlescape($c['owner']['username']) ?></groundspeak:placed_by> |
47 | 48 | <groundspeak:owner id="<?= $vars['user_uuid_to_internal_id'][$c['owner']['uuid']] ?>"><?= Okapi::xmlescape($c['owner']['username']) ?></groundspeak:owner> |
48 | 49 | <groundspeak:type><?= $vars['cache_GPX_types'][$c['type']] ?></groundspeak:type> |
49 | 50 | <groundspeak:container><?= $vars['cache_GPX_sizes'][$c['size2']] ?></groundspeak:container> |
50 | - <?php if ($vars['gc_attrs'] || $vars['gc_ocde_attrs']) { /* Does user want us to include groundspeak:attributes? */ ?> |
|
51 | + <?php if ($vars['gc_attrs'] || $vars['gc_ocde_attrs']) { |
|
52 | +/* Does user want us to include groundspeak:attributes? */ ?> |
|
51 | 53 | <groundspeak:attributes> |
52 | 54 | <?php |
53 | 55 | foreach ($c['gc_attrs'] as $gc_id => $gc_attr) { |
@@ -71,23 +73,28 @@ discard block |
||
71 | 73 | <p> |
72 | 74 | <a href="<?= $c['url'] ?>"><?= Okapi::xmlescape($c['name']) ?></a> |
73 | 75 | <?= _("hidden by") ?> <a href='<?= $c['owner']['profile_url'] ?>'><?= Okapi::xmlescape($c['owner']['username']) ?></a><br/> |
74 | - <?php if ($vars['recommendations'] == 'desc:count') { /* Does user want us to include recommendations count? */ ?> |
|
76 | + <?php if ($vars['recommendations'] == 'desc:count') { |
|
77 | +/* Does user want us to include recommendations count? */ ?> |
|
75 | 78 | <?= sprintf(ngettext("%d recommendation", "%d recommendations", $c['recommendations']), $c['recommendations']) ?> |
76 | 79 | (<?= sprintf(ngettext("found %d time", "found %d times", $c['founds']), $c['founds']) ?>). |
77 | 80 | <?php } ?> |
78 | - <?php if ($vars['trackables'] == 'desc:count') { /* Does user want us to include trackables count? */ ?> |
|
81 | + <?php if ($vars['trackables'] == 'desc:count') { |
|
82 | +/* Does user want us to include trackables count? */ ?> |
|
79 | 83 | <?= sprintf(ngettext("%d trackable", "%d trackables", $c['trackables_count']), $c['trackables_count']) ?>. |
80 | 84 | <?php } ?> |
81 | 85 | </p> |
82 | - <?php if ((in_array('desc:text', $vars['my_notes'])) && ($c['my_notes'] != null)) { /* Does user want us to include personal notes? */ ?> |
|
86 | + <?php if ((in_array('desc:text', $vars['my_notes'])) && ($c['my_notes'] != null)) { |
|
87 | +/* Does user want us to include personal notes? */ ?> |
|
83 | 88 | <p><b><?= _("Personal notes") ?>:</b><br><?= Okapi::xmlescape(nl2br($c['my_notes'])) ?></p> |
84 | 89 | <?php } ?> |
85 | 90 | |
86 | - <?php if (in_array('desc:text', $vars['attrs']) && count($c['attrnames']) > 0) { /* Does user want us to include attributes? */ ?> |
|
91 | + <?php if (in_array('desc:text', $vars['attrs']) && count($c['attrnames']) > 0) { |
|
92 | +/* Does user want us to include attributes? */ ?> |
|
87 | 93 | <p><?= _("Attributes") ?>:</p> |
88 | 94 | <ul><li><?= implode("</li><li>", $c['attrnames']) ?></li></ul> |
89 | 95 | <?php } ?> |
90 | - <?php if ($vars['trackables'] == 'desc:list' && count($c['trackables']) > 0) { /* Does user want us to include trackables list? */ ?> |
|
96 | + <?php if ($vars['trackables'] == 'desc:list' && count($c['trackables']) > 0) { |
|
97 | +/* Does user want us to include trackables list? */ ?> |
|
91 | 98 | <p><?= _("Trackables") ?>:</p> |
92 | 99 | <ul> |
93 | 100 | <?php foreach ($c['trackables'] as $t) { ?> |
@@ -96,7 +103,8 @@ discard block |
||
96 | 103 | </ul> |
97 | 104 | <?php } ?> |
98 | 105 | <?= Okapi::xmlescape($c['description']) ?> |
99 | - <?php if ((strpos($vars['images'], "descrefs:") === 0) && count($c['images']) > 0) { /* Does user want us to include <img> references in cache descriptions? */ |
|
106 | + <?php if ((strpos($vars['images'], "descrefs:") === 0) && count($c['images']) > 0) { |
|
107 | +/* Does user want us to include <img> references in cache descriptions? */ |
|
100 | 108 | if ($vars['images'] == "descrefs:thumblinks") { ?> |
101 | 109 | <h2><?= _("Images") ?> (<?= count($c['images']) ?>)</h2> |
102 | 110 | <div> |
@@ -109,9 +117,12 @@ discard block |
||
109 | 117 | # We will split images into two subcategories: spoilers and nonspoilers. |
110 | 118 | $spoilers = array(); |
111 | 119 | $nonspoilers = array(); |
112 | - foreach ($c['images'] as $img) |
|
113 | - if ($img['is_spoiler']) $spoilers[] = $img; |
|
114 | - else $nonspoilers[] = $img; |
|
120 | + foreach ($c['images'] as $img) { |
|
121 | + if ($img['is_spoiler']) $spoilers[] = $img; |
|
122 | + } |
|
123 | + else { |
|
124 | + $nonspoilers[] = $img; |
|
125 | + } |
|
115 | 126 | ?> |
116 | 127 | <?php if (count($nonspoilers) > 0) { ?> |
117 | 128 | <h2><?= _("Images") ?> (<?= count($nonspoilers) ?>)</h2> |
@@ -129,7 +140,8 @@ discard block |
||
129 | 140 | <?php } ?> |
130 | 141 | <?php } ?> |
131 | 142 | <?php } ?> |
132 | - <?php if ((strpos($vars['images'], "ox:") === 0) && count($c['images']) > 0) { /* Include image descriptions (for ox:image numbers)? */ ?> |
|
143 | + <?php if ((strpos($vars['images'], "ox:") === 0) && count($c['images']) > 0) { |
|
144 | +/* Include image descriptions (for ox:image numbers)? */ ?> |
|
133 | 145 | <p><?= _("Image descriptions") ?>:</p> |
134 | 146 | <ul> |
135 | 147 | <?php foreach ($c['images'] as $no => $img) { ?> |
@@ -147,10 +159,12 @@ discard block |
||
147 | 159 | <?php } ?> |
148 | 160 | </groundspeak:long_description> |
149 | 161 | <groundspeak:encoded_hints><?= Okapi::xmlescape($c['hint2']) ?></groundspeak:encoded_hints> |
150 | - <?php if ((in_array('gc:personal_note', $vars['my_notes'])) && ($c['my_notes'] != null)) { /* Does user want us to include personal notes? -> Issue 294 */ ?> |
|
162 | + <?php if ((in_array('gc:personal_note', $vars['my_notes'])) && ($c['my_notes'] != null)) { |
|
163 | +/* Does user want us to include personal notes? -> Issue 294 */ ?> |
|
151 | 164 | <groundspeak:personal_note><?= Okapi::xmlescape($c['my_notes']) ?></groundspeak:personal_note> |
152 | 165 | <?php } ?> |
153 | - <?php if ($vars['latest_logs']) { /* Does user want us to include latest log entries? */ ?> |
|
166 | + <?php if ($vars['latest_logs']) { |
|
167 | +/* Does user want us to include latest log entries? */ ?> |
|
154 | 168 | <groundspeak:logs> |
155 | 169 | <?php foreach ($c['latest_logs'] as $log) { ?> |
156 | 170 | <groundspeak:log id="<?= $log['internal_id'] ?>"> |
@@ -164,7 +178,8 @@ discard block |
||
164 | 178 | <?php } ?> |
165 | 179 | </groundspeak:cache> |
166 | 180 | <?php } ?> |
167 | - <?php if ($vars['ns_ox']) { /* Does user want us to include Garmin's <opencaching> element? */ ?> |
|
181 | + <?php if ($vars['ns_ox']) { |
|
182 | +/* Does user want us to include Garmin's <opencaching> element? */ ?> |
|
168 | 183 | <ox:opencaching xmlns:ox="http://www.opencaching.com/xmlschemas/opencaching/1/0"> |
169 | 184 | <ox:ratings> |
170 | 185 | <?php if ($c['rating'] !== null) { ?><ox:awesomeness><?= $c['rating'] ?></ox:awesomeness><?php } ?> |
@@ -172,10 +187,12 @@ discard block |
||
172 | 187 | <?php if ($c['oxsize'] !== null) { ?><ox:size><?= $c['oxsize'] ?></ox:size><?php } ?> |
173 | 188 | <ox:terrain><?= $c['terrain'] ?></ox:terrain> |
174 | 189 | </ox:ratings> |
175 | - <?php if (in_array('ox:tags', $vars['attrs']) && count($c['attrnames']) > 0) { /* Does user want us to include ox:tags? */ ?> |
|
190 | + <?php if (in_array('ox:tags', $vars['attrs']) && count($c['attrnames']) > 0) { |
|
191 | +/* Does user want us to include ox:tags? */ ?> |
|
176 | 192 | <ox:tags><ox:tag><?= implode("</ox:tag><ox:tag>", $c['attrnames']) ?></ox:tag></ox:tags> |
177 | 193 | <?php } ?> |
178 | - <?php if ((strpos($vars['images'], "ox:") === 0) && count($c['images']) > 0) { /* Does user want us to include ox:image references? */ ?> |
|
194 | + <?php if ((strpos($vars['images'], "ox:") === 0) && count($c['images']) > 0) { |
|
195 | +/* Does user want us to include ox:image references? */ ?> |
|
179 | 196 | <ox:images> |
180 | 197 | <?php foreach ($c['images'] as $no => $img) { ?> |
181 | 198 | <ox:image> |
@@ -220,7 +237,7 @@ discard block |
||
220 | 237 | <?php } ?> |
221 | 238 | </wpt> |
222 | 239 | <?php |
223 | - if (isset($wpt_ref['ggz_entry'])){ |
|
240 | + if (isset($wpt_ref['ggz_entry'])) { |
|
224 | 241 | $wpt_ref['ggz_entry']['file_len'] = ob_get_length() - $wpt_ref['ggz_entry']['file_pos']; |
225 | 242 | } |
226 | 243 | ?> |
@@ -24,19 +24,33 @@ discard block |
||
24 | 24 | public static function call(OkapiRequest $request) |
25 | 25 | { |
26 | 26 | $cache_code = $request->get_parameter('cache_code'); |
27 | - if (!$cache_code) throw new ParamMissing('cache_code'); |
|
28 | - if (strpos($cache_code, "|") !== false) throw new InvalidParam('cache_code'); |
|
27 | + if (!$cache_code) { |
|
28 | + throw new ParamMissing('cache_code'); |
|
29 | + } |
|
30 | + if (strpos($cache_code, "|") !== false) { |
|
31 | + throw new InvalidParam('cache_code'); |
|
32 | + } |
|
29 | 33 | $langpref = $request->get_parameter('langpref'); |
30 | - if (!$langpref) $langpref = "en"; |
|
34 | + if (!$langpref) { |
|
35 | + $langpref = "en"; |
|
36 | + } |
|
31 | 37 | $langpref .= "|".Settings::get('SITELANG'); |
32 | 38 | $fields = $request->get_parameter('fields'); |
33 | - if (!$fields) $fields = "code|name|location|type|status"; |
|
39 | + if (!$fields) { |
|
40 | + $fields = "code|name|location|type|status"; |
|
41 | + } |
|
34 | 42 | $log_fields = $request->get_parameter('log_fields'); |
35 | - if (!$log_fields) $log_fields = "uuid|date|user|type|comment"; |
|
43 | + if (!$log_fields) { |
|
44 | + $log_fields = "uuid|date|user|type|comment"; |
|
45 | + } |
|
36 | 46 | $lpc = $request->get_parameter('lpc'); |
37 | - if (!$lpc) $lpc = 10; |
|
47 | + if (!$lpc) { |
|
48 | + $lpc = 10; |
|
49 | + } |
|
38 | 50 | $attribution_append = $request->get_parameter('attribution_append'); |
39 | - if (!$attribution_append) $attribution_append = 'full'; |
|
51 | + if (!$attribution_append) { |
|
52 | + $attribution_append = 'full'; |
|
53 | + } |
|
40 | 54 | $params = array( |
41 | 55 | 'cache_codes' => $cache_code, |
42 | 56 | 'langpref' => $langpref, |
@@ -46,11 +60,13 @@ discard block |
||
46 | 60 | 'log_fields' => $log_fields |
47 | 61 | ); |
48 | 62 | $my_location = $request->get_parameter('my_location'); |
49 | - if ($my_location) |
|
50 | - $params['my_location'] = $my_location; |
|
63 | + if ($my_location) { |
|
64 | + $params['my_location'] = $my_location; |
|
65 | + } |
|
51 | 66 | $user_uuid = $request->get_parameter('user_uuid'); |
52 | - if ($user_uuid) |
|
53 | - $params['user_uuid'] = $user_uuid; |
|
67 | + if ($user_uuid) { |
|
68 | + $params['user_uuid'] = $user_uuid; |
|
69 | + } |
|
54 | 70 | |
55 | 71 | # There's no need to validate the fields/lpc parameters as the 'geocaches' |
56 | 72 | # method does this (it will raise a proper exception on invalid values). |
@@ -58,8 +74,7 @@ discard block |
||
58 | 74 | $results = OkapiServiceRunner::call('services/caches/geocaches', new OkapiInternalRequest( |
59 | 75 | $request->consumer, $request->token, $params)); |
60 | 76 | $result = $results[$cache_code]; |
61 | - if ($result === null) |
|
62 | - { |
|
77 | + if ($result === null) { |
|
63 | 78 | # Two errors messages (for OCDE). Makeshift solution for issue #350. |
64 | 79 | |
65 | 80 | $exists = Db::select_value(" |
@@ -24,98 +24,104 @@ |
||
24 | 24 | { |
25 | 25 | # Check search method |
26 | 26 | $search_method = $request->get_parameter('search_method'); |
27 | - if (!$search_method) |
|
28 | - throw new ParamMissing('search_method'); |
|
29 | - if (strpos($search_method, "services/caches/search/") !== 0) |
|
30 | - throw new InvalidParam('search_method', "Should begin with 'services/caches/search/'."); |
|
31 | - if (!OkapiServiceRunner::exists($search_method)) |
|
32 | - throw new InvalidParam('search_method', "Method does not exist: '$search_method'"); |
|
27 | + if (!$search_method) { |
|
28 | + throw new ParamMissing('search_method'); |
|
29 | + } |
|
30 | + if (strpos($search_method, "services/caches/search/") !== 0) { |
|
31 | + throw new InvalidParam('search_method', "Should begin with 'services/caches/search/'."); |
|
32 | + } |
|
33 | + if (!OkapiServiceRunner::exists($search_method)) { |
|
34 | + throw new InvalidParam('search_method', "Method does not exist: '$search_method'"); |
|
35 | + } |
|
33 | 36 | $search_params = $request->get_parameter('search_params'); |
34 | - if (!$search_params) |
|
35 | - throw new ParamMissing('search_params'); |
|
37 | + if (!$search_params) { |
|
38 | + throw new ParamMissing('search_params'); |
|
39 | + } |
|
36 | 40 | $search_params = json_decode($search_params, true); |
37 | - if (!is_array($search_params)) |
|
38 | - throw new InvalidParam('search_params', "Should be a JSON-encoded dictionary"); |
|
41 | + if (!is_array($search_params)) { |
|
42 | + throw new InvalidParam('search_params', "Should be a JSON-encoded dictionary"); |
|
43 | + } |
|
39 | 44 | |
40 | 45 | # Check retrieval method |
41 | 46 | $retr_method = $request->get_parameter('retr_method'); |
42 | - if (!$retr_method) |
|
43 | - throw new ParamMissing('retr_method'); |
|
44 | - if (!OkapiServiceRunner::exists($retr_method)) |
|
45 | - throw new InvalidParam('retr_method', "Method does not exist: '$retr_method'"); |
|
47 | + if (!$retr_method) { |
|
48 | + throw new ParamMissing('retr_method'); |
|
49 | + } |
|
50 | + if (!OkapiServiceRunner::exists($retr_method)) { |
|
51 | + throw new InvalidParam('retr_method', "Method does not exist: '$retr_method'"); |
|
52 | + } |
|
46 | 53 | $retr_params = $request->get_parameter('retr_params'); |
47 | - if (!$retr_params) |
|
48 | - throw new ParamMissing('retr_params'); |
|
54 | + if (!$retr_params) { |
|
55 | + throw new ParamMissing('retr_params'); |
|
56 | + } |
|
49 | 57 | $retr_params = json_decode($retr_params, true); |
50 | - if (!is_array($retr_params)) |
|
51 | - throw new InvalidParam('retr_params', "Should be a JSON-encoded dictionary"); |
|
58 | + if (!is_array($retr_params)) { |
|
59 | + throw new InvalidParam('retr_params', "Should be a JSON-encoded dictionary"); |
|
60 | + } |
|
52 | 61 | |
53 | 62 | self::map_values_to_strings($search_params); |
54 | 63 | self::map_values_to_strings($retr_params); |
55 | 64 | |
56 | 65 | # Wrapped? |
57 | 66 | $wrap = $request->get_parameter('wrap'); |
58 | - if ($wrap == null) throw new ParamMissing('wrap'); |
|
59 | - if (!in_array($wrap, array('true', 'false'))) |
|
60 | - throw new InvalidParam('wrap'); |
|
67 | + if ($wrap == null) { |
|
68 | + throw new ParamMissing('wrap'); |
|
69 | + } |
|
70 | + if (!in_array($wrap, array('true', 'false'))) { |
|
71 | + throw new InvalidParam('wrap'); |
|
72 | + } |
|
61 | 73 | $wrap = ($wrap == 'true'); |
62 | 74 | |
63 | 75 | # Run search method |
64 | - try |
|
65 | - { |
|
76 | + try { |
|
66 | 77 | $search_result = OkapiServiceRunner::call($search_method, new OkapiInternalRequest( |
67 | 78 | $request->consumer, $request->token, $search_params)); |
68 | - } |
|
69 | - catch (BadRequest $e) |
|
70 | - { |
|
79 | + } catch (BadRequest $e) { |
|
71 | 80 | throw new InvalidParam('search_params', "Search method responded with the ". |
72 | 81 | "following error message: ".$e->getMessage()); |
73 | 82 | } |
74 | 83 | |
75 | 84 | # Run retrieval method |
76 | - try |
|
77 | - { |
|
85 | + try { |
|
78 | 86 | $retr_result = OkapiServiceRunner::call($retr_method, new OkapiInternalRequest( |
79 | 87 | $request->consumer, $request->token, array_merge($retr_params, |
80 | 88 | array('cache_codes' => implode("|", $search_result['results']))))); |
81 | - } |
|
82 | - catch (BadRequest $e) |
|
83 | - { |
|
89 | + } catch (BadRequest $e) { |
|
84 | 90 | throw new InvalidParam('retr_params', "Retrieval method responded with the ". |
85 | 91 | "following error message: ".$e->getMessage()); |
86 | 92 | } |
87 | 93 | |
88 | - if ($wrap) |
|
89 | - { |
|
94 | + if ($wrap) { |
|
90 | 95 | # $retr_result might be a PHP object, but also might be a binary response |
91 | 96 | # (e.g. a GPX file). |
92 | - if ($retr_result instanceof OkapiHttpResponse) |
|
93 | - $result = array('results' => $retr_result->get_body()); |
|
94 | - else |
|
95 | - $result = array('results' => $retr_result); |
|
96 | - foreach ($search_result as $key => &$value_ref) |
|
97 | - if ($key != 'results') |
|
97 | + if ($retr_result instanceof OkapiHttpResponse) { |
|
98 | + $result = array('results' => $retr_result->get_body()); |
|
99 | + } else { |
|
100 | + $result = array('results' => $retr_result); |
|
101 | + } |
|
102 | + foreach ($search_result as $key => &$value_ref) { |
|
103 | + if ($key != 'results') |
|
98 | 104 | $result[$key] = $value_ref; |
105 | + } |
|
99 | 106 | return Okapi::formatted_response($request, $result); |
100 | - } |
|
101 | - else |
|
102 | - { |
|
103 | - if ($retr_result instanceof OkapiHttpResponse) |
|
104 | - return $retr_result; |
|
105 | - else |
|
106 | - return Okapi::formatted_response($request, $retr_result); |
|
107 | + } else { |
|
108 | + if ($retr_result instanceof OkapiHttpResponse) { |
|
109 | + return $retr_result; |
|
110 | + } else { |
|
111 | + return Okapi::formatted_response($request, $retr_result); |
|
112 | + } |
|
107 | 113 | } |
108 | 114 | } |
109 | 115 | |
110 | 116 | private static function map_values_to_strings(&$dict) |
111 | 117 | { |
112 | - foreach (array_keys($dict) as $key) |
|
113 | - { |
|
118 | + foreach (array_keys($dict) as $key) { |
|
114 | 119 | $val = $dict[$key]; |
115 | - if (is_numeric($val) || is_string($val)) |
|
116 | - $dict[$key] = (string)$val; |
|
117 | - else |
|
118 | - throw new BadRequest("Invalid value format for key: ".$key); |
|
120 | + if (is_numeric($val) || is_string($val)) { |
|
121 | + $dict[$key] = (string)$val; |
|
122 | + } else { |
|
123 | + throw new BadRequest("Invalid value format for key: ".$key); |
|
124 | + } |
|
119 | 125 | } |
120 | 126 | } |
121 | 127 | } |
@@ -30,26 +30,32 @@ discard block |
||
30 | 30 | # It's much easier to grasp their meaning this way. |
31 | 31 | |
32 | 32 | $tmp = $request->get_parameter('bbox'); |
33 | - if (!$tmp) |
|
34 | - throw new ParamMissing('bbox'); |
|
33 | + if (!$tmp) { |
|
34 | + throw new ParamMissing('bbox'); |
|
35 | + } |
|
35 | 36 | $parts = explode('|', $tmp); |
36 | - if (count($parts) != 4) |
|
37 | - throw new InvalidParam('bbox', "Expecting 4 pipe-separated parts, got ".count($parts)."."); |
|
38 | - foreach ($parts as &$part_ref) |
|
39 | - { |
|
40 | - if (!preg_match("/^-?[0-9]+(\.?[0-9]*)$/", $part_ref)) |
|
41 | - throw new InvalidParam('bbox', "'$part_ref' is not a valid float number."); |
|
37 | + if (count($parts) != 4) { |
|
38 | + throw new InvalidParam('bbox', "Expecting 4 pipe-separated parts, got ".count($parts)."."); |
|
39 | + } |
|
40 | + foreach ($parts as &$part_ref) { |
|
41 | + if (!preg_match("/^-?[0-9]+(\.?[0-9]*)$/", $part_ref)) { |
|
42 | + throw new InvalidParam('bbox', "'$part_ref' is not a valid float number."); |
|
43 | + } |
|
42 | 44 | $part_ref = floatval($part_ref); |
43 | 45 | } |
44 | 46 | list($bbsouth, $bbwest, $bbnorth, $bbeast) = $parts; |
45 | - if ($bbnorth <= $bbsouth) |
|
46 | - throw new InvalidParam('bbox', "Northern edge must be situated to the north of the southern edge."); |
|
47 | - if ($bbeast == $bbwest) |
|
48 | - throw new InvalidParam('bbox', "Eastern edge longitude is the same as the western one."); |
|
49 | - if ($bbnorth > 90 || $bbnorth < -90 || $bbsouth > 90 || $bbsouth < -90) |
|
50 | - throw new InvalidParam('bbox', "Latitudes have to be within -90..90 range."); |
|
51 | - if ($bbeast > 180 || $bbeast < -180 || $bbwest > 180 || $bbwest < -180) |
|
52 | - throw new InvalidParam('bbox', "Longitudes have to be within -180..180 range."); |
|
47 | + if ($bbnorth <= $bbsouth) { |
|
48 | + throw new InvalidParam('bbox', "Northern edge must be situated to the north of the southern edge."); |
|
49 | + } |
|
50 | + if ($bbeast == $bbwest) { |
|
51 | + throw new InvalidParam('bbox', "Eastern edge longitude is the same as the western one."); |
|
52 | + } |
|
53 | + if ($bbnorth > 90 || $bbnorth < -90 || $bbsouth > 90 || $bbsouth < -90) { |
|
54 | + throw new InvalidParam('bbox', "Latitudes have to be within -90..90 range."); |
|
55 | + } |
|
56 | + if ($bbeast > 180 || $bbeast < -180 || $bbwest > 180 || $bbwest < -180) { |
|
57 | + throw new InvalidParam('bbox', "Longitudes have to be within -180..180 range."); |
|
58 | + } |
|
53 | 59 | |
54 | 60 | # Construct SQL conditions for the specified bounding box. |
55 | 61 | |
@@ -64,16 +70,13 @@ discard block |
||
64 | 70 | $lat >= '".Db::escape_string($bbsouth)."' |
65 | 71 | and $lat < '".Db::escape_string($bbnorth)."' |
66 | 72 | )"; |
67 | - if ($bbeast > $bbwest) |
|
68 | - { |
|
73 | + if ($bbeast > $bbwest) { |
|
69 | 74 | # Easy one. |
70 | 75 | $where_conds[] = "( |
71 | 76 | $lon >= '".Db::escape_string($bbwest)."' |
72 | 77 | and $lon < '".Db::escape_string($bbeast)."' |
73 | 78 | )"; |
74 | - } |
|
75 | - else |
|
76 | - { |
|
79 | + } else { |
|
77 | 80 | # We'll have to assume that this bbox goes through the 180-degree meridian. |
78 | 81 | # For example, $bbwest = 179 and $bbeast = -179. |
79 | 82 | $where_conds[] = "( |
@@ -70,14 +70,14 @@ discard block |
||
70 | 70 | { |
71 | 71 | if (!preg_match("/^-?[0-9]+(\.?[0-9]*)$/", $tmp)) |
72 | 72 | throw new InvalidParam('radius', "'$tmp' is not a valid float number."); |
73 | - $radius = floatval($tmp); # is given in kilometers |
|
73 | + $radius = floatval($tmp); # is given in kilometers |
|
74 | 74 | if ($radius <= 0) |
75 | 75 | throw new InvalidParam('radius', "Has to be a positive number."); |
76 | 76 | |
77 | 77 | # Apply a latitude-range prefilter if it looks promising. |
78 | 78 | # See https://github.com/opencaching/okapi/issues/363 for more info. |
79 | 79 | |
80 | - $optimization_radius = 100; # in kilometers, optimized for Opencaching.de |
|
80 | + $optimization_radius = 100; # in kilometers, optimized for Opencaching.de |
|
81 | 81 | $km2degrees_upper_estimate_factor = 0.01; |
82 | 82 | |
83 | 83 | if ($radius <= $optimization_radius) |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | "; |
90 | 90 | } |
91 | 91 | |
92 | - $radius *= 1000; # convert from kilometers to meters |
|
92 | + $radius *= 1000; # convert from kilometers to meters |
|
93 | 93 | $where_conds[] = "$distance_formula <= '".Db::escape_string($radius)."'"; |
94 | 94 | } |
95 | 95 |
@@ -30,22 +30,26 @@ discard block |
||
30 | 30 | # It's much easier to grasp their meaning this way. |
31 | 31 | |
32 | 32 | $tmp = $request->get_parameter('center'); |
33 | - if (!$tmp) |
|
34 | - throw new ParamMissing('center'); |
|
33 | + if (!$tmp) { |
|
34 | + throw new ParamMissing('center'); |
|
35 | + } |
|
35 | 36 | $parts = explode('|', $tmp); |
36 | - if (count($parts) != 2) |
|
37 | - throw new InvalidParam('center', "Expecting 2 pipe-separated parts, got ".count($parts)."."); |
|
38 | - foreach ($parts as &$part_ref) |
|
39 | - { |
|
40 | - if (!preg_match("/^-?[0-9]+(\.?[0-9]*)$/", $part_ref)) |
|
41 | - throw new InvalidParam('center', "'$part_ref' is not a valid float number."); |
|
37 | + if (count($parts) != 2) { |
|
38 | + throw new InvalidParam('center', "Expecting 2 pipe-separated parts, got ".count($parts)."."); |
|
39 | + } |
|
40 | + foreach ($parts as &$part_ref) { |
|
41 | + if (!preg_match("/^-?[0-9]+(\.?[0-9]*)$/", $part_ref)) { |
|
42 | + throw new InvalidParam('center', "'$part_ref' is not a valid float number."); |
|
43 | + } |
|
42 | 44 | $part_ref = floatval($part_ref); |
43 | 45 | } |
44 | 46 | list($center_lat, $center_lon) = $parts; |
45 | - if ($center_lat > 90 || $center_lat < -90) |
|
46 | - throw new InvalidParam('center', "Latitudes have to be within -90..90 range."); |
|
47 | - if ($center_lon > 180 || $center_lon < -180) |
|
48 | - throw new InvalidParam('center', "Longitudes have to be within -180..180 range."); |
|
47 | + if ($center_lat > 90 || $center_lat < -90) { |
|
48 | + throw new InvalidParam('center', "Latitudes have to be within -90..90 range."); |
|
49 | + } |
|
50 | + if ($center_lon > 180 || $center_lon < -180) { |
|
51 | + throw new InvalidParam('center', "Longitudes have to be within -180..180 range."); |
|
52 | + } |
|
49 | 53 | |
50 | 54 | # |
51 | 55 | # In the method description, we promised to return caches ordered by the *rough* |
@@ -66,13 +70,14 @@ discard block |
||
66 | 70 | |
67 | 71 | $where_conds = array(); |
68 | 72 | $radius = null; |
69 | - if ($tmp = $request->get_parameter('radius')) |
|
70 | - { |
|
71 | - if (!preg_match("/^-?[0-9]+(\.?[0-9]*)$/", $tmp)) |
|
72 | - throw new InvalidParam('radius', "'$tmp' is not a valid float number."); |
|
73 | + if ($tmp = $request->get_parameter('radius')) { |
|
74 | + if (!preg_match("/^-?[0-9]+(\.?[0-9]*)$/", $tmp)) { |
|
75 | + throw new InvalidParam('radius', "'$tmp' is not a valid float number."); |
|
76 | + } |
|
73 | 77 | $radius = floatval($tmp); # is given in kilometers |
74 | - if ($radius <= 0) |
|
75 | - throw new InvalidParam('radius', "Has to be a positive number."); |
|
78 | + if ($radius <= 0) { |
|
79 | + throw new InvalidParam('radius', "Has to be a positive number."); |
|
80 | + } |
|
76 | 81 | |
77 | 82 | # Apply a latitude-range prefilter if it looks promising. |
78 | 83 | # See https://github.com/opencaching/okapi/issues/363 for more info. |
@@ -80,8 +85,7 @@ discard block |
||
80 | 85 | $optimization_radius = 100; # in kilometers, optimized for Opencaching.de |
81 | 86 | $km2degrees_upper_estimate_factor = 0.01; |
82 | 87 | |
83 | - if ($radius <= $optimization_radius) |
|
84 | - { |
|
88 | + if ($radius <= $optimization_radius) { |
|
85 | 89 | $radius_degrees = $radius * $km2degrees_upper_estimate_factor; |
86 | 90 | $where_conds[] = " |
87 | 91 | caches.latitude >= '".Db::escape_string($center_lat - $radius_degrees)."' |
@@ -100,8 +104,7 @@ discard block |
||
100 | 104 | $search_assistant->set_search_params($search_params); |
101 | 105 | |
102 | 106 | $result = $search_assistant->get_common_search_result(); |
103 | - if ($radius == null) |
|
104 | - { |
|
107 | + if ($radius == null) { |
|
105 | 108 | # 'more' is meaningless in this case, we'll remove it. |
106 | 109 | unset($result['more']); |
107 | 110 | } |