@@ -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 | } |
@@ -30,48 +30,56 @@ discard block |
||
30 | 30 | |
31 | 31 | static $host = null; |
32 | 32 | static $length = null; |
33 | - if ($host == null) |
|
34 | - { |
|
33 | + if ($host == null) { |
|
35 | 34 | $host = parse_url(Settings::get('SITE_URL'), PHP_URL_HOST); |
36 | - if (strpos($host, "www.") === 0) |
|
37 | - $host = substr($host, 4); |
|
35 | + if (strpos($host, "www.") === 0) { |
|
36 | + $host = substr($host, 4); |
|
37 | + } |
|
38 | 38 | $length = strlen($host); |
39 | 39 | } |
40 | 40 | |
41 | 41 | # Parse the URL |
42 | 42 | |
43 | 43 | $uri = parse_url($url); |
44 | - if ($uri == false) |
|
45 | - return null; |
|
46 | - if ((!isset($uri['scheme'])) || (!in_array($uri['scheme'], array('http', 'https')))) |
|
47 | - return null; |
|
48 | - if ((!isset($uri['host'])) || (substr($uri['host'], -$length) != $host)) |
|
49 | - return null; |
|
50 | - if (!isset($uri['path'])) |
|
51 | - return null; |
|
52 | - if (preg_match("#^/(O[A-Z][A-Z0-9]{4,5})$#", $uri['path'], $matches)) |
|
53 | - { |
|
44 | + if ($uri == false) { |
|
45 | + return null; |
|
46 | + } |
|
47 | + if ((!isset($uri['scheme'])) || (!in_array($uri['scheme'], array('http', 'https')))) { |
|
48 | + return null; |
|
49 | + } |
|
50 | + if ((!isset($uri['host'])) || (substr($uri['host'], -$length) != $host)) { |
|
51 | + return null; |
|
52 | + } |
|
53 | + if (!isset($uri['path'])) { |
|
54 | + return null; |
|
55 | + } |
|
56 | + if (preg_match("#^/(O[A-Z][A-Z0-9]{4,5})$#", $uri['path'], $matches)) { |
|
54 | 57 | # Some servers allow "http://oc.xx/<cache_code>" shortcut. |
55 | 58 | return array('cache_code', $matches[1]); |
56 | 59 | } |
57 | 60 | $parts = array(); |
58 | - if (isset($uri['query'])) |
|
59 | - $parts = array_merge($parts, explode('&', $uri['query'])); |
|
60 | - if (isset($uri['fragment'])) |
|
61 | - $parts = array_merge($parts, explode('&', $uri['fragment'])); |
|
62 | - foreach ($parts as $param) |
|
63 | - { |
|
61 | + if (isset($uri['query'])) { |
|
62 | + $parts = array_merge($parts, explode('&', $uri['query'])); |
|
63 | + } |
|
64 | + if (isset($uri['fragment'])) { |
|
65 | + $parts = array_merge($parts, explode('&', $uri['fragment'])); |
|
66 | + } |
|
67 | + foreach ($parts as $param) { |
|
64 | 68 | $item = explode('=', $param, 2); |
65 | - if (count($item) != 2) |
|
66 | - continue; |
|
69 | + if (count($item) != 2) { |
|
70 | + continue; |
|
71 | + } |
|
67 | 72 | $key = $item[0]; |
68 | 73 | $value = $item[1]; |
69 | - if ($key == 'wp') |
|
70 | - return array('cache_code', $value); |
|
71 | - if ($key == 'cacheid') |
|
72 | - return array('internal_id', $value); |
|
73 | - if ($key == 'uuid') |
|
74 | - return array('uuid', $value); |
|
74 | + if ($key == 'wp') { |
|
75 | + return array('cache_code', $value); |
|
76 | + } |
|
77 | + if ($key == 'cacheid') { |
|
78 | + return array('internal_id', $value); |
|
79 | + } |
|
80 | + if ($key == 'uuid') { |
|
81 | + return array('uuid', $value); |
|
82 | + } |
|
75 | 83 | } |
76 | 84 | return null; |
77 | 85 | } |
@@ -81,13 +89,17 @@ discard block |
||
81 | 89 | # Retrieve the list of URLs to check. |
82 | 90 | |
83 | 91 | $tmp = $request->get_parameter('urls'); |
84 | - if (!$tmp) |
|
85 | - throw new ParamMissing('urls'); |
|
92 | + if (!$tmp) { |
|
93 | + throw new ParamMissing('urls'); |
|
94 | + } |
|
86 | 95 | $urls = explode('|', $tmp); |
87 | 96 | $as_dict = $request->get_parameter('as_dict'); |
88 | - if (!$as_dict) $as_dict = 'false'; |
|
89 | - if (!in_array($as_dict, array('true', 'false'))) |
|
90 | - throw new InvalidParam('as_dict'); |
|
97 | + if (!$as_dict) { |
|
98 | + $as_dict = 'false'; |
|
99 | + } |
|
100 | + if (!in_array($as_dict, array('true', 'false'))) { |
|
101 | + throw new InvalidParam('as_dict'); |
|
102 | + } |
|
91 | 103 | $as_dict = ($as_dict == 'true'); |
92 | 104 | |
93 | 105 | # Generate the lists of keys. |
@@ -98,25 +110,25 @@ discard block |
||
98 | 110 | 'internal_id' => array(), |
99 | 111 | 'uuid' => array() |
100 | 112 | ); |
101 | - foreach ($urls as &$url_ref) |
|
102 | - { |
|
113 | + foreach ($urls as &$url_ref) { |
|
103 | 114 | $key = self::get_cache_key($url_ref); |
104 | - if ($key != null) |
|
105 | - $urls_with[$key[0]][$url_ref] = $key[1]; |
|
106 | - else |
|
107 | - $results[$url_ref] = null; |
|
115 | + if ($key != null) { |
|
116 | + $urls_with[$key[0]][$url_ref] = $key[1]; |
|
117 | + } else { |
|
118 | + $results[$url_ref] = null; |
|
119 | + } |
|
108 | 120 | } |
109 | 121 | |
110 | 122 | # Include 'cache_code' references. |
111 | 123 | |
112 | - foreach ($urls_with['cache_code'] as $url => $cache_code) |
|
113 | - $results[$url] = $cache_code; |
|
124 | + foreach ($urls_with['cache_code'] as $url => $cache_code) { |
|
125 | + $results[$url] = $cache_code; |
|
126 | + } |
|
114 | 127 | |
115 | 128 | # Include 'internal_id' references. |
116 | 129 | |
117 | 130 | $internal_ids = array_values($urls_with['internal_id']); |
118 | - if (count($internal_ids) > 0) |
|
119 | - { |
|
131 | + if (count($internal_ids) > 0) { |
|
120 | 132 | $rs = Db::query(" |
121 | 133 | select cache_id, wp_oc |
122 | 134 | from caches |
@@ -125,22 +137,22 @@ discard block |
||
125 | 137 | and status in (1,2,3) |
126 | 138 | "); |
127 | 139 | $dict = array(); |
128 | - while ($row = Db::fetch_assoc($rs)) |
|
129 | - $dict[$row['cache_id']] = $row['wp_oc']; |
|
130 | - foreach ($urls_with['internal_id'] as $url => $internal_id) |
|
131 | - { |
|
132 | - if (isset($dict[$internal_id])) |
|
133 | - $results[$url] = $dict[$internal_id]; |
|
134 | - else |
|
135 | - $results[$url] = null; |
|
140 | + while ($row = Db::fetch_assoc($rs)) { |
|
141 | + $dict[$row['cache_id']] = $row['wp_oc']; |
|
142 | + } |
|
143 | + foreach ($urls_with['internal_id'] as $url => $internal_id) { |
|
144 | + if (isset($dict[$internal_id])) { |
|
145 | + $results[$url] = $dict[$internal_id]; |
|
146 | + } else { |
|
147 | + $results[$url] = null; |
|
148 | + } |
|
136 | 149 | } |
137 | 150 | } |
138 | 151 | |
139 | 152 | # Include 'uuid' references. |
140 | 153 | |
141 | 154 | $uuids = array_values($urls_with['uuid']); |
142 | - if (count($uuids) > 0) |
|
143 | - { |
|
155 | + if (count($uuids) > 0) { |
|
144 | 156 | $rs = Db::query(" |
145 | 157 | select uuid, wp_oc |
146 | 158 | from caches |
@@ -149,27 +161,28 @@ discard block |
||
149 | 161 | and status in (1,2,3) |
150 | 162 | "); |
151 | 163 | $dict = array(); |
152 | - while ($row = Db::fetch_assoc($rs)) |
|
153 | - $dict[$row['uuid']] = $row['wp_oc']; |
|
154 | - foreach ($urls_with['uuid'] as $url => $uuid) |
|
155 | - { |
|
156 | - if (isset($dict[$uuid])) |
|
157 | - $results[$url] = $dict[$uuid]; |
|
158 | - else |
|
159 | - $results[$url] = null; |
|
164 | + while ($row = Db::fetch_assoc($rs)) { |
|
165 | + $dict[$row['uuid']] = $row['wp_oc']; |
|
166 | + } |
|
167 | + foreach ($urls_with['uuid'] as $url => $uuid) { |
|
168 | + if (isset($dict[$uuid])) { |
|
169 | + $results[$url] = $dict[$uuid]; |
|
170 | + } else { |
|
171 | + $results[$url] = null; |
|
172 | + } |
|
160 | 173 | } |
161 | 174 | } |
162 | 175 | |
163 | 176 | # Format the results according to the 'as_dict' parameter. |
164 | 177 | |
165 | - if ($as_dict) |
|
166 | - return Okapi::formatted_response($request, $results); |
|
167 | - else |
|
168 | - { |
|
178 | + if ($as_dict) { |
|
179 | + return Okapi::formatted_response($request, $results); |
|
180 | + } else { |
|
169 | 181 | $cache_codes = array(); |
170 | - foreach ($results as $url => $cache_code) |
|
171 | - if ($cache_code != null) |
|
182 | + foreach ($results as $url => $cache_code) { |
|
183 | + if ($cache_code != null) |
|
172 | 184 | $cache_codes[$cache_code] = true; |
185 | + } |
|
173 | 186 | $flattened = array('results' => array_keys($cache_codes)); |
174 | 187 | return Okapi::formatted_response($request, $flattened); |
175 | 188 | } |
@@ -31,55 +31,58 @@ |
||
31 | 31 | # on it - this will also throw a proper exception if it doesn't exist. |
32 | 32 | |
33 | 33 | $cache_code = $request->get_parameter('cache_code'); |
34 | - if ($cache_code == null) |
|
35 | - throw new ParamMissing('cache_code'); |
|
34 | + if ($cache_code == null) { |
|
35 | + throw new ParamMissing('cache_code'); |
|
36 | + } |
|
36 | 37 | $geocache = OkapiServiceRunner::call('services/caches/geocache', new OkapiInternalRequest( |
37 | 38 | $request->consumer, $request->token, array('cache_code' => $cache_code, 'fields' => 'internal_id'))); |
38 | 39 | |
39 | 40 | # watched |
40 | 41 | |
41 | - if ($tmp = $request->get_parameter('watched')) |
|
42 | - { |
|
43 | - if (!in_array($tmp, array('true', 'false', 'unchanged'))) |
|
44 | - throw new InvalidParam('watched', $tmp); |
|
45 | - if ($tmp == 'true') |
|
46 | - Db::execute(" |
|
42 | + if ($tmp = $request->get_parameter('watched')) { |
|
43 | + if (!in_array($tmp, array('true', 'false', 'unchanged'))) { |
|
44 | + throw new InvalidParam('watched', $tmp); |
|
45 | + } |
|
46 | + if ($tmp == 'true') { |
|
47 | + Db::execute(" |
|
47 | 48 | insert ignore into cache_watches (cache_id, user_id) |
48 | 49 | values ( |
49 | 50 | '".Db::escape_string($geocache['internal_id'])."', |
50 | 51 | '".Db::escape_string($request->token->user_id)."' |
51 | 52 | ); |
52 | 53 | "); |
53 | - elseif ($tmp == 'false') |
|
54 | - Db::execute(" |
|
54 | + } elseif ($tmp == 'false') { |
|
55 | + Db::execute(" |
|
55 | 56 | delete from cache_watches |
56 | 57 | where |
57 | 58 | cache_id = '".Db::escape_string($geocache['internal_id'])."' |
58 | 59 | and user_id = '".Db::escape_string($request->token->user_id)."'; |
59 | 60 | "); |
61 | + } |
|
60 | 62 | } |
61 | 63 | |
62 | 64 | # ignored |
63 | 65 | |
64 | - if ($tmp = $request->get_parameter('ignored')) |
|
65 | - { |
|
66 | - if (!in_array($tmp, array('true', 'false', 'unchanged'))) |
|
67 | - throw new InvalidParam('ignored', $tmp); |
|
68 | - if ($tmp == 'true') |
|
69 | - Db::execute(" |
|
66 | + if ($tmp = $request->get_parameter('ignored')) { |
|
67 | + if (!in_array($tmp, array('true', 'false', 'unchanged'))) { |
|
68 | + throw new InvalidParam('ignored', $tmp); |
|
69 | + } |
|
70 | + if ($tmp == 'true') { |
|
71 | + Db::execute(" |
|
70 | 72 | insert ignore into cache_ignore (cache_id, user_id) |
71 | 73 | values ( |
72 | 74 | '".Db::escape_string($geocache['internal_id'])."', |
73 | 75 | '".Db::escape_string($request->token->user_id)."' |
74 | 76 | ); |
75 | 77 | "); |
76 | - elseif ($tmp == 'false') |
|
77 | - Db::execute(" |
|
78 | + } elseif ($tmp == 'false') { |
|
79 | + Db::execute(" |
|
78 | 80 | delete from cache_ignore |
79 | 81 | where |
80 | 82 | cache_id = '".Db::escape_string($geocache['internal_id'])."' |
81 | 83 | and user_id = '".Db::escape_string($request->token->user_id)."' |
82 | 84 | "); |
85 | + } |
|
83 | 86 | } |
84 | 87 | |
85 | 88 | $result = array( |
@@ -23,14 +23,18 @@ discard block |
||
23 | 23 | public static function call(OkapiRequest $request) |
24 | 24 | { |
25 | 25 | $internal_ids = $request->get_parameter('internal_ids'); |
26 | - if (!$internal_ids) throw new ParamMissing('internal_ids'); |
|
26 | + if (!$internal_ids) { |
|
27 | + throw new ParamMissing('internal_ids'); |
|
28 | + } |
|
27 | 29 | $internal_ids = explode("|", $internal_ids); |
28 | - if (count($internal_ids) > 500) |
|
29 | - throw new InvalidParam('internal_ids', "Maximum allowed number of referenced users ". |
|
30 | + if (count($internal_ids) > 500) { |
|
31 | + throw new InvalidParam('internal_ids', "Maximum allowed number of referenced users ". |
|
30 | 32 | "is 500. You provided ".count($internal_ids)." references."); |
33 | + } |
|
31 | 34 | $fields = $request->get_parameter('fields'); |
32 | - if (!$fields) |
|
33 | - throw new ParamMissing('fields'); |
|
35 | + if (!$fields) { |
|
36 | + throw new ParamMissing('fields'); |
|
37 | + } |
|
34 | 38 | |
35 | 39 | # There's no need to validate the fields parameter as the 'users' |
36 | 40 | # method does this (it will raise a proper exception on invalid values). |
@@ -41,8 +45,7 @@ discard block |
||
41 | 45 | where user_id in ('".implode("','", array_map('\okapi\Db::escape_string', $internal_ids))."') |
42 | 46 | "); |
43 | 47 | $internalid2useruuid = array(); |
44 | - while ($row = Db::fetch_assoc($rs)) |
|
45 | - { |
|
48 | + while ($row = Db::fetch_assoc($rs)) { |
|
46 | 49 | $internalid2useruuid[$row['user_id']] = $row['uuid']; |
47 | 50 | } |
48 | 51 | Db::free_result($rs); |
@@ -55,12 +58,12 @@ discard block |
||
55 | 58 | # Map user_uuids to internal_ids. Also check which internal_ids were not found |
56 | 59 | # and mark them with null. |
57 | 60 | $results = array(); |
58 | - foreach ($internal_ids as $internal_id) |
|
59 | - { |
|
60 | - if (!isset($internalid2useruuid[$internal_id])) |
|
61 | - $results[$internal_id] = null; |
|
62 | - else |
|
63 | - $results[$internal_id] = $id_results[$internalid2useruuid[$internal_id]]; |
|
61 | + foreach ($internal_ids as $internal_id) { |
|
62 | + if (!isset($internalid2useruuid[$internal_id])) { |
|
63 | + $results[$internal_id] = null; |
|
64 | + } else { |
|
65 | + $results[$internal_id] = $id_results[$internalid2useruuid[$internal_id]]; |
|
66 | + } |
|
64 | 67 | } |
65 | 68 | |
66 | 69 | return Okapi::formatted_response($request, $results); |
@@ -26,16 +26,12 @@ discard block |
||
26 | 26 | public static function call(OkapiRequest $request) |
27 | 27 | { |
28 | 28 | $user_uuid = $request->get_parameter('user_uuid'); |
29 | - if (!$user_uuid) |
|
30 | - { |
|
31 | - if ($request->token) |
|
32 | - { |
|
29 | + if (!$user_uuid) { |
|
30 | + if ($request->token) { |
|
33 | 31 | $tmp = OkapiServiceRunner::call('services/users/by_internal_id', new OkapiInternalRequest( |
34 | 32 | $request->consumer, null, array('internal_id' => $request->token->user_id, 'fields' => 'uuid'))); |
35 | 33 | $user_uuid = $tmp['uuid']; |
36 | - } |
|
37 | - else |
|
38 | - { |
|
34 | + } else { |
|
39 | 35 | throw new BadRequest("You must either: 1. supply the user_uuid argument, or " |
40 | 36 | ."2. sign your request with an Access Token."); |
41 | 37 | } |
@@ -49,8 +45,9 @@ discard block |
||
49 | 45 | $request->consumer, $request->token, array('user_uuids' => $user_uuid, |
50 | 46 | 'fields' => $fields))); |
51 | 47 | $result = $results[$user_uuid]; |
52 | - if ($result == null) |
|
53 | - throw new InvalidParam('user_uuid', "There is no user by this ID."); |
|
48 | + if ($result == null) { |
|
49 | + throw new InvalidParam('user_uuid', "There is no user by this ID."); |
|
50 | + } |
|
54 | 51 | return Okapi::formatted_response($request, $result); |
55 | 52 | } |
56 | 53 | } |