Completed
Pull Request — master (#313)
by Thomas
09:55
created
htdocs/okapi/services/logs/images/add.php 1 patch
Braces   +51 added lines, -48 removed lines patch added patch discarded remove patch
@@ -19,7 +19,9 @@  discard block
 block discarded – undo
19 19
  * the Consumer did anything wrong (it's the user who did). This exception shouldn't
20 20
  * be used outside of this file.
21 21
  */
22
-class CannotPublishException extends Exception {}
22
+class CannotPublishException extends Exception
23
+{
24
+}
23 25
 
24 26
 class WebService
25 27
 {
@@ -48,8 +50,9 @@  discard block
 block discarded – undo
48 50
         # validate the 'log_uuid' parameter
49 51
 
50 52
         $log_uuid = $request->get_parameter('log_uuid');
51
-        if (!$log_uuid)
52
-            throw new ParamMissing('log_uuid');
53
+        if (!$log_uuid) {
54
+                    throw new ParamMissing('log_uuid');
55
+        }
53 56
         $rs = Db::query("
54 57
             select id, node, user_id
55 58
             from cache_logs
@@ -57,8 +60,9 @@  discard block
 block discarded – undo
57 60
         );
58 61
         $row = Db::fetch_assoc($rs);
59 62
         Db::free_result($rs);
60
-        if (!$row)
61
-            throw new InvalidParam('log_uuid', "There is no log entry with uuid '".$log_uuid."'.");
63
+        if (!$row) {
64
+                    throw new InvalidParam('log_uuid', "There is no log entry with uuid '".$log_uuid."'.");
65
+        }
62 66
         if ($row['node'] != Settings::get('OC_NODE_ID')) {
63 67
             throw new Exception(
64 68
                 "This site's database contains the log entry '$log_uuid' which has been"
@@ -85,21 +89,24 @@  discard block
 block discarded – undo
85 89
         }
86 90
 
87 91
         $is_spoiler = $request->get_parameter('is_spoiler');
88
-        if ($is_spoiler === null) $is_spoiler = 'false';
89
-        if (!in_array($is_spoiler, array('true', 'false')))
90
-            throw new InvalidParam('is_spoiler');
92
+        if ($is_spoiler === null) {
93
+            $is_spoiler = 'false';
94
+        }
95
+        if (!in_array($is_spoiler, array('true', 'false'))) {
96
+                    throw new InvalidParam('is_spoiler');
97
+        }
91 98
 
92 99
         $position = LogImagesCommon::validate_position($request);
93 100
 
94 101
         # validate the 'image' parameter
95 102
 
96 103
         $base64_image = $request->get_parameter('image');
97
-        if (!$base64_image)
98
-            throw new ParamMissing('image');
104
+        if (!$base64_image) {
105
+                    throw new ParamMissing('image');
106
+        }
99 107
 
100 108
         $estimated_decoded_size = strlen($base64_image) / 4 * 3 - 2;
101
-        if ($estimated_decoded_size > Settings::get('IMAGE_MAX_UPLOAD_SIZE'))
102
-        {
109
+        if ($estimated_decoded_size > Settings::get('IMAGE_MAX_UPLOAD_SIZE')) {
103 110
             $estimated_decoded_size_MB = round($estimated_decoded_size / 1024 / 1024, 1);
104 111
             $max_upload_size_MB = round(Settings::get('IMAGE_MAX_UPLOAD_SIZE') / 1024 / 1024, 1);
105 112
 
@@ -112,20 +119,21 @@  discard block
 block discarded – undo
112 119
         }
113 120
 
114 121
         $image = base64_decode($base64_image);
115
-        if (!$image)
116
-            throw new InvalidParam('image', "bad base64 encoding");
122
+        if (!$image) {
123
+                    throw new InvalidParam('image', "bad base64 encoding");
124
+        }
117 125
 
118 126
         try {
119 127
             $image_properties = getimagesizefromstring($image);  # can throw
120
-            if (!$image_properties)
121
-                throw new Exception();
128
+            if (!$image_properties) {
129
+                            throw new Exception();
130
+            }
122 131
             list($width, $height, $image_type) = $image_properties;
123 132
             if (!in_array($image_type, array(IMAGETYPE_JPEG, IMAGETYPE_PNG, IMAGETYPE_GIF))) {
124 133
                 # This will happen e.g. for BMP and XBM images, which are supported by GD.
125 134
                 throw new Exception();
126 135
             }
127
-        }
128
-        catch (Exception $e) {
136
+        } catch (Exception $e) {
129 137
             # Note: There may be *subtypes* which are not accepted by the GD library.
130 138
             # About 1 of 2000 JPEGs at OC.de is not readable by the PHP functions,
131 139
             # though they can be displayed by web browsers.
@@ -149,9 +157,10 @@  discard block
 block discarded – undo
149 157
         }
150 158
         try {
151 159
             $image = imagecreatefromstring($image);  # can throw
152
-            if (!$image) throw new Exception();
153
-        }
154
-        catch (Exception $e) {
160
+            if (!$image) {
161
+                throw new Exception();
162
+            }
163
+        } catch (Exception $e) {
155 164
             throw new CannotPublishException(_("The uploaded image file is broken."));
156 165
         }
157 166
 
@@ -168,8 +177,7 @@  discard block
 block discarded – undo
168 177
 
169 178
         $image_uuid = Okapi::create_uuid();
170 179
         $imagepath = Settings::get('IMAGES_DIR').'/'.$image_uuid;
171
-        switch ($image_type)
172
-        {
180
+        switch ($image_type) {
173 181
             case IMAGETYPE_JPEG:
174 182
                 $file_ext = '.jpg';
175 183
                 $quality = Settings::get('JPEG_QUALITY');
@@ -190,26 +198,23 @@  discard block
 block discarded – undo
190 198
                 $file_ext = '.???';
191 199
                 $result = false;
192 200
         }
193
-        if (!$result)
194
-            throw new Exception("could not save image file '".$imagepath.$file_ext."'");
201
+        if (!$result) {
202
+                    throw new Exception("could not save image file '".$imagepath.$file_ext."'");
203
+        }
195 204
 
196 205
         # insert image into database
197 206
 
198
-        try
199
-        {
207
+        try {
200 208
             $position = self::db_insert_image(
201 209
                 $request->consumer->key, $request->token->user_id,
202 210
                 $log_internal_id, $image_uuid, $position, $caption, $is_spoiler, $file_ext
203 211
             );
204
-        }
205
-        catch (Exception $e)
206
-        {
212
+        } catch (Exception $e) {
207 213
             # TODO: Proper handling of nested exception if the unlink() fails
208 214
             # (which is very unlikely, and will just add a bit more of garbage
209 215
             # to that which is already present in the images directory).
210 216
 
211
-            try { unlink($imagepath.$file_ext); }
212
-            catch (Exception $e2) {}
217
+            try { unlink($imagepath.$file_ext); } catch (Exception $e2) {}
213 218
             throw $e;
214 219
         }
215 220
 
@@ -239,15 +244,15 @@  discard block
 block discarded – undo
239 244
         # and more powerful alternative (e.g. allowing more file types),
240 245
         # but that needs additional and sometimes non-trivial installation.
241 246
 
242
-        if (!extension_loaded('gd'))
243
-            throw new Exception('PHP GD image processing module is disabled');
247
+        if (!extension_loaded('gd')) {
248
+                    throw new Exception('PHP GD image processing module is disabled');
249
+        }
244 250
 
245 251
         # rescale image if necessary
246 252
 
247 253
         $scale_factor = sqrt(Settings::get('IMAGE_MAX_PIXEL_COUNT') / ($width * $height));
248 254
 
249
-        if ($scale_factor < 1)
250
-        {
255
+        if ($scale_factor < 1) {
251 256
             $new_width = $width * $scale_factor;
252 257
             $new_height = $height * $scale_factor;
253 258
             $scaled_image = imagecreatetruecolor($new_width, $new_height);
@@ -261,18 +266,17 @@  discard block
 block discarded – undo
261 266
         #   - GD cannot save EXIF data anyway, and
262 267
         #   - the orientation flag may not be recognized by all image processors.
263 268
 
264
-        if (!extension_loaded('exif'))
265
-            throw new Exception('PHP Exif module is disabled');
269
+        if (!extension_loaded('exif')) {
270
+                    throw new Exception('PHP Exif module is disabled');
271
+        }
266 272
 
267
-        if ($image_type == IMAGETYPE_JPEG)
268
-        {
273
+        if ($image_type == IMAGETYPE_JPEG) {
269 274
             # The PHP Exif module can read EXIF data only from files. To avoid
270 275
             # disk I/O overhead, we pipe the image string through a pseudo-file:
271 276
 
272 277
             $exif_data = exif_read_data("data://image/jpeg;base64," . $base64_image);
273 278
             if ($exif_data && isset($exif_data['Orientation'])) {
274
-                switch ($exif_data['Orientation'])
275
-                {
279
+                switch ($exif_data['Orientation']) {
276 280
                     case 3: $image = imagerotate($image, 180, 0); break;
277 281
                     case 6: $image = imagerotate($image, -90, 0); break;
278 282
                     case 8: $image = imagerotate($image, 90, 0); break;
@@ -393,11 +397,12 @@  discard block
 block discarded – undo
393 397
         # This is the "real" entry point. A wrapper for the _call method.
394 398
 
395 399
         $langpref = $request->get_parameter('langpref');
396
-        if (!$langpref) $langpref = "en";
400
+        if (!$langpref) {
401
+            $langpref = "en";
402
+        }
397 403
         Okapi::gettext_domain_init(explode("|", $langpref));
398 404
 
399
-        try
400
-        {
405
+        try {
401 406
             list($image_uuid, $position) = self::_call($request);
402 407
             $result = array(
403 408
                 'success' => true,
@@ -406,9 +411,7 @@  discard block
 block discarded – undo
406 411
                 'position' => $position
407 412
             );
408 413
             Okapi::gettext_domain_restore();
409
-        }
410
-        catch (CannotPublishException $e)
411
-        {
414
+        } catch (CannotPublishException $e) {
412 415
             Okapi::gettext_domain_restore();
413 416
             $result = array(
414 417
                 'success' => false,
Please login to merge, or discard this patch.
htdocs/okapi/services/oauth/request_token.php 1 patch
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -20,8 +20,7 @@
 block discarded – undo
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
         }
Please login to merge, or discard this patch.
htdocs/okapi/services/oauth/access_token.php 1 patch
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -21,8 +21,7 @@
 block discarded – undo
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
         }
Please login to merge, or discard this patch.
htdocs/okapi/services/caches/formatters/garmin.php 1 patch
Braces   +49 added lines, -45 removed lines patch added patch discarded remove patch
@@ -32,22 +32,32 @@  discard block
 block discarded – undo
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,36 +107,37 @@  discard block
 block discarded – undo
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.");
102
-        if ($images != 'none')
103
-        {
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
+        }
113
+        if ($images != 'none') {
104 114
             $supported_extensions = array('jpg', 'jpeg', 'gif', 'png', 'bmp');
105
-            foreach ($caches as $cache_code => $dict)
106
-            {
115
+            foreach ($caches as $cache_code => $dict) {
107 116
                 $imgs = $dict['images'];
108
-                if (count($imgs) == 0)
109
-                    continue;
117
+                if (count($imgs) == 0) {
118
+                                    continue;
119
+                }
110 120
                 $dir = "Garmin/GeocachePhotos/".$cache_code[strlen($cache_code) - 1];
111 121
                 $dir .= "/".$cache_code[strlen($cache_code) - 2];
112 122
                 $dir .= "/".$cache_code;
113
-                foreach ($imgs as $no => $img)
114
-                {
115
-                    if ($images == 'spoilers' && (!$img['is_spoiler']))
116
-                        continue;
117
-                    if ($images == 'nonspoilers' && $img['is_spoiler'])
118
-                        continue;
123
+                foreach ($imgs as $no => $img) {
124
+                    if ($images == 'spoilers' && (!$img['is_spoiler'])) {
125
+                                            continue;
126
+                    }
127
+                    if ($images == 'nonspoilers' && $img['is_spoiler']) {
128
+                                            continue;
129
+                    }
119 130
                     $tmp = false;
120
-                    foreach ($supported_extensions as $ext)
121
-                    {
122
-                        if (strtolower(substr($img['url'], strlen($img['url']) - strlen($ext) - 1)) != ".".$ext)
123
-                        {
131
+                    foreach ($supported_extensions as $ext) {
132
+                        if (strtolower(substr($img['url'], strlen($img['url']) - strlen($ext) - 1)) != ".".$ext) {
124 133
                             $tmp = true;
125 134
                             continue;
126 135
                         }
127 136
                     }
128
-                    if (!$tmp)
129
-                        continue;  # unsupported file extension
137
+                    if (!$tmp) {
138
+                                            continue;
139
+                    }
140
+                    # unsupported file extension
130 141
 
131 142
                     if ($img['is_spoiler']) {
132 143
                         $zippath = $dir."/Spoilers/".$img['unique_caption'].".jpg";
@@ -142,34 +153,25 @@  discard block
 block discarded – undo
142 153
                     # be accessed locally. But all the files have 'local' set to 1 anyway.
143 154
 
144 155
                     $syspath = Settings::get('IMAGES_DIR')."/".$img['uuid'].".jpg";
145
-                    if (file_exists($syspath))
146
-                    {
156
+                    if (file_exists($syspath)) {
147 157
                         $response->zip->FileAdd($zippath, $syspath, clsTbsZip::TBSZIP_FILE, false);
148
-                    }
149
-                    else
150
-                    {
158
+                    } else {
151 159
                         # If file exists, but does not end with ".jpg", we will create
152 160
                         # JPEG version of it and store it in the cache.
153 161
 
154 162
                         $cache_key = "jpg#".$img['uuid'];
155 163
                         $jpeg_contents = Cache::get($cache_key);
156
-                        if ($jpeg_contents === null)
157
-                        {
158
-                            foreach ($supported_extensions as $ext)
159
-                            {
164
+                        if ($jpeg_contents === null) {
165
+                            foreach ($supported_extensions as $ext) {
160 166
                                 $syspath_other = Settings::get('IMAGES_DIR')."/".$img['uuid'].".".$ext;
161
-                                if (file_exists($syspath_other))
162
-                                {
163
-                                    try
164
-                                    {
167
+                                if (file_exists($syspath_other)) {
168
+                                    try {
165 169
                                         $image = imagecreatefromstring(file_get_contents($syspath_other));
166 170
                                         ob_start();
167 171
                                         imagejpeg($image);
168 172
                                         $jpeg_contents = ob_get_clean();
169 173
                                         imagedestroy($image);
170
-                                    }
171
-                                    catch (Exception $e)
172
-                                    {
174
+                                    } catch (Exception $e) {
173 175
                                         # GD couldn't parse the file. We will skip it, and cache
174 176
                                         # the "false" value as the contents. This way, we won't
175 177
                                         # attempt to parse it during the next 24 hours.
@@ -181,8 +183,10 @@  discard block
 block discarded – undo
181 183
                                 }
182 184
                             }
183 185
                         }
184
-                        if ($jpeg_contents)  # This can be "null" *or* "false"!
186
+                        if ($jpeg_contents) {
187
+                            # This can be "null" *or* "false"!
185 188
                             $response->zip->FileAdd($zippath, $jpeg_contents, clsTbsZip::TBSZIP_STRING, false);
189
+                        }
186 190
                     }
187 191
                 }
188 192
             }
Please login to merge, or discard this patch.
htdocs/okapi/services/caches/formatters/ggzindex.tpl.php 1 patch
Braces   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -27,7 +27,7 @@
 block discarded – undo
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
                     ?>
Please login to merge, or discard this patch.
htdocs/okapi/services/caches/formatters/gpx.php 1 patch
Braces   +113 added lines, -98 removed lines patch added patch discarded remove patch
@@ -89,24 +89,30 @@  discard block
 block discarded – undo
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
-        foreach (array('ns_ground', 'ns_gsak', 'ns_ox', 'latest_logs', 'alt_wpts', 'mark_found') as $param)
101
-        {
104
+        foreach (array('ns_ground', 'ns_gsak', 'ns_ox', 'latest_logs', 'alt_wpts', 'mark_found') as $param) {
102 105
             $val = $request->get_parameter($param);
103
-            if (!$val) $val = "false";
104
-            elseif (!in_array($val, array("true", "false")))
105
-                throw new InvalidParam($param);
106
+            if (!$val) {
107
+                $val = "false";
108
+            } elseif (!in_array($val, array("true", "false"))) {
109
+                            throw new InvalidParam($param);
110
+            }
106 111
             $vars[$param] = ($val == "true");
107 112
         }
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.");
113
+        if ($vars['latest_logs'] && (!$vars['ns_ground'])) {
114
+                    throw new BadRequest("In order for 'latest_logs' to work you have to also include 'ns_ground' extensions.");
115
+        }
110 116
 
111 117
         $tmp = $request->get_parameter('my_notes');
112 118
         $vars['my_notes'] = array();
@@ -134,72 +140,86 @@  discard block
 block discarded – undo
134 140
         }
135 141
 
136 142
         $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'");
143
+        if (!$images) {
144
+            $images = 'descrefs:nonspoilers';
145
+        }
146
+        if (!in_array($images, array('none', 'descrefs:thumblinks', 'descrefs:nonspoilers', 'descrefs:all', 'ox:all'))) {
147
+                    throw new InvalidParam('images', "'$images'");
148
+        }
140 149
         $vars['images'] = $images;
141 150
 
142 151
         $tmp = $request->get_parameter('attrs');
143
-        if (!$tmp) $tmp = 'desc:text';
152
+        if (!$tmp) {
153
+            $tmp = 'desc:text';
154
+        }
144 155
         $tmp = explode("|", $tmp);
145 156
         $vars['attrs'] = array();
146
-        foreach ($tmp as $elem)
147
-        {
157
+        foreach ($tmp as $elem) {
148 158
             if ($elem == 'none') {
149 159
                 /* pass */
150 160
             } 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;
161
+                if ($elem == 'gc_ocde:attrs' && Settings::get('OC_BRANCH') != 'oc.de') {
162
+                                    $vars['attrs'][] = 'gc:attrs';
163
+                } else {
164
+                                    $vars['attrs'][] = $elem;
165
+                }
155 166
             } else {
156 167
                 throw new InvalidParam('attrs', "Invalid list entry: '$elem'");
157 168
             }
158 169
         }
159 170
 
160 171
         $protection_areas = $request->get_parameter('protection_areas');
161
-        if (!$protection_areas || $protection_areas == 'desc:auto')
162
-        {
163
-            if (Settings::get('OC_BRANCH') == 'oc.de') $protection_areas = 'desc:text';
164
-            else $protection_areas = 'none';
172
+        if (!$protection_areas || $protection_areas == 'desc:auto') {
173
+            if (Settings::get('OC_BRANCH') == 'oc.de') {
174
+                $protection_areas = 'desc:text';
175
+            } else {
176
+                $protection_areas = 'none';
177
+            }
178
+        }
179
+        if (!in_array($protection_areas, array('none', 'desc:text'))) {
180
+                    throw new InvalidParam('protection_areas',"'$protection_areas'");
165 181
         }
166
-        if (!in_array($protection_areas, array('none', 'desc:text')))
167
-            throw new InvalidParam('protection_areas',"'$protection_areas'");
168 182
         $vars['protection_areas'] = $protection_areas;
169 183
 
170 184
         $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'");
185
+        if (!$tmp) {
186
+            $tmp = 'none';
187
+        }
188
+        if (!in_array($tmp, array('none', 'desc:list', 'desc:count'))) {
189
+                    throw new InvalidParam('trackables', "'$tmp'");
190
+        }
174 191
         $vars['trackables'] = $tmp;
175 192
 
176 193
         $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'");
194
+        if (!$tmp) {
195
+            $tmp = 'none';
196
+        }
197
+        if (!in_array($tmp, array('none', 'desc:count'))) {
198
+                    throw new InvalidParam('recommendations', "'$tmp'");
199
+        }
180 200
         $vars['recommendations'] = $tmp;
181 201
 
182 202
         $lpc = $request->get_parameter('lpc');
183
-        if ($lpc === null) $lpc = 10; # will be checked in services/caches/geocaches call
203
+        if ($lpc === null) {
204
+            $lpc = 10;
205
+        }
206
+        # will be checked in services/caches/geocaches call
184 207
 
185 208
         $user_uuid = $request->get_parameter('user_uuid');
186 209
 
187 210
         # location_source (part 1 of 2)
188 211
 
189 212
         $location_source = $request->get_parameter('location_source');
190
-        if (!$location_source)
191
-        {
213
+        if (!$location_source) {
192 214
             $location_source = 'default-coords';
193 215
         }
194 216
         # Make sure location_source has prefix alt_wpt:
195
-        if ($location_source != 'default-coords' && strncmp($location_source, 'alt_wpt:', 8) != 0)
196
-        {
217
+        if ($location_source != 'default-coords' && strncmp($location_source, 'alt_wpt:', 8) != 0) {
197 218
             throw new InvalidParam('location_source', '\''.$location_source.'\'');
198 219
         }
199 220
 
200 221
         # Make sure we have sufficient authorization
201
-        if ($location_source == 'alt_wpt:user-coords' && $request->token == null)
202
-        {
222
+        if ($location_source == 'alt_wpt:user-coords' && $request->token == null) {
203 223
             throw new BadRequest("Level 3 Authentication is required to access 'alt_wpt:user-coords'.");
204 224
         }
205 225
 
@@ -208,24 +228,32 @@  discard block
 block discarded – undo
208 228
         $fields = 'code|name|location|date_created|url|type|status|size|size2|oxsize'.
209 229
             '|difficulty|terrain|description|hint2|rating|owner|url|internal_id'.
210 230
             '|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";
231
+        if ($vars['images'] != 'none') {
232
+                    $fields .= "|images";
233
+        }
234
+        if (count($vars['attrs']) > 0) {
235
+                    $fields .= "|attrnames|attr_acodes|needs_maintenance";
236
+        }
237
+        if ($vars['trackables'] == 'desc:list') {
238
+                    $fields .= "|trackables";
239
+        } elseif ($vars['trackables'] == 'desc:count') {
240
+                    $fields .= "|trackables_count";
241
+        }
242
+        if ($vars['alt_wpts'] == 'true' || $location_source != 'default-coords') {
243
+                    $fields .= "|alt_wpts";
244
+        }
245
+        if ($vars['recommendations'] != 'none') {
246
+                    $fields .= "|recommendations|founds";
247
+        }
248
+        if (count($vars['my_notes']) > 0) {
249
+                    $fields .= "|my_notes";
250
+        }
251
+        if ($vars['latest_logs']) {
252
+                    $fields .= "|latest_logs";
253
+        }
254
+        if ($vars['mark_found']) {
255
+                    $fields .= "|is_found";
256
+        }
229 257
 
230 258
         $vars['caches'] = OkapiServiceRunner::call(
231 259
             'services/caches/geocaches', new OkapiInternalRequest(
@@ -261,8 +289,7 @@  discard block
 block discarded – undo
261 289
         $vars['cache_GPX_types'] = self::$cache_GPX_types;
262 290
         $vars['cache_GPX_sizes'] = self::$cache_GPX_sizes;
263 291
 
264
-        if (count($vars['attrs']) > 0)
265
-        {
292
+        if (count($vars['attrs']) > 0) {
266 293
             /* The user asked for some kind of attribute output. We'll fetch all
267 294
              * the data we MAY need. This is often far too much, but thanks to
268 295
              * caching, it will work fast. */
@@ -281,10 +308,8 @@  discard block
 block discarded – undo
281 308
 
282 309
             $vars['gc_attrs'] = in_array('gc:attrs', $vars['attrs']);
283 310
             $vars['gc_ocde_attrs'] = in_array('gc_ocde:attrs', $vars['attrs']);
284
-            if ($vars['gc_attrs'] || $vars['gc_ocde_attrs'])
285
-            {
286
-                if ($vars['gc_ocde_attrs'])
287
-                {
311
+            if ($vars['gc_attrs'] || $vars['gc_ocde_attrs']) {
312
+                if ($vars['gc_ocde_attrs']) {
288 313
                     # As this is an OCDE compatibility feature, we use the same Pseudo-GS
289 314
                     # attribute names here as OCDE. Note that this code is specific to OCDE
290 315
                     # database; OCPL stores attribute names in a different way and may use
@@ -297,14 +322,11 @@  discard block
 block discarded – undo
297 322
                     $attr_dict = AttrHelper::get_attrdict();
298 323
                 }
299 324
 
300
-                foreach ($vars['caches'] as &$cache_ref)
301
-                {
325
+                foreach ($vars['caches'] as &$cache_ref) {
302 326
                     $cache_ref['gc_attrs'] = array();
303
-                    foreach ($cache_ref['attr_acodes'] as $acode)
304
-                    {
327
+                    foreach ($cache_ref['attr_acodes'] as $acode) {
305 328
                         $has_gc_equivs = false;
306
-                        foreach ($vars['attr_index'][$acode]['gc_equivs'] as $gc)
307
-                        {
329
+                        foreach ($vars['attr_index'][$acode]['gc_equivs'] as $gc) {
308 330
                             # The assignment via GC-ID as array key will prohibit duplicate
309 331
                             # GC attributes, which can result from
310 332
                             # - assigning the same GC ID to multiple A-Codes,
@@ -313,8 +335,7 @@  discard block
 block discarded – undo
313 335
                             $cache_ref['gc_attrs'][$gc['id']] = $gc;
314 336
                             $has_gc_equivs = true;
315 337
                         }
316
-                        if (!$has_gc_equivs && $vars['gc_ocde_attrs'])
317
-                        {
338
+                        if (!$has_gc_equivs && $vars['gc_ocde_attrs']) {
318 339
                             # Generate an OCDE pseudo-GS attribute;
319 340
                             # see https://github.com/opencaching/okapi/issues/190 and
320 341
                             # https://github.com/opencaching/okapi/issues/271.
@@ -329,8 +350,7 @@  discard block
 block discarded – undo
329 350
                             );
330 351
                         }
331 352
                     }
332
-                    if ($cache_ref['needs_maintenance'])
333
-                    {
353
+                    if ($cache_ref['needs_maintenance']) {
334 354
                         # export NM cache flag as GC attribute #42
335 355
                         $cache_ref['gc_attrs']['42'] = array(
336 356
                             'inc' => 1,
@@ -342,12 +362,11 @@  discard block
 block discarded – undo
342 362
 
343 363
             # As the 'needs maintenance' flag is usually transported as attribute in
344 364
             # GPX files, we add it also to desc:text attribs.
345
-            if (in_array('desc:text', $vars['attrs']))
346
-            {
347
-                foreach ($vars['caches'] as &$cache_ref)
348
-                {
349
-                    if ($cache_ref['needs_maintenance'])
350
-                        $cache_ref['attrnames'][] = 'Needs maintenance';
365
+            if (in_array('desc:text', $vars['attrs'])) {
366
+                foreach ($vars['caches'] as &$cache_ref) {
367
+                    if ($cache_ref['needs_maintenance']) {
368
+                                            $cache_ref['attrnames'][] = 'Needs maintenance';
369
+                    }
351 370
                 }
352 371
             }
353 372
         }
@@ -363,38 +382,35 @@  discard block
 block discarded – undo
363 382
          * from the database here. */
364 383
 
365 384
         $dict = array();
366
-        foreach ($vars['caches'] as &$cache_ref)
367
-        {
385
+        foreach ($vars['caches'] as &$cache_ref) {
368 386
             $dict[$cache_ref['owner']['uuid']] = true;
369
-            if (isset($cache_ref['latest_logs']))
370
-                foreach ($cache_ref['latest_logs'] as &$log_ref)
387
+            if (isset($cache_ref['latest_logs'])) {
388
+                            foreach ($cache_ref['latest_logs'] as &$log_ref)
371 389
                     $dict[$log_ref['user']['uuid']] = true;
390
+            }
372 391
         }
373 392
         $rs = Db::query("
374 393
             select uuid, user_id
375 394
             from user
376 395
             where uuid in ('".implode("','", array_map('\okapi\Db::escape_string', array_keys($dict)))."')
377 396
         ");
378
-        while ($row = Db::fetch_assoc($rs))
379
-            $dict[$row['uuid']] = $row['user_id'];
397
+        while ($row = Db::fetch_assoc($rs)) {
398
+                    $dict[$row['uuid']] = $row['user_id'];
399
+        }
380 400
         $vars['user_uuid_to_internal_id'] = &$dict;
381 401
         unset($dict);
382 402
 
383 403
         # location_source (part 2 of 2)
384 404
 
385
-        if ($location_source != 'default-coords')
386
-        {
405
+        if ($location_source != 'default-coords') {
387 406
             $location_change_prefix = $request->get_parameter('location_change_prefix');
388 407
             if (!$location_change_prefix) {
389 408
                 $location_change_prefix = '# ';
390 409
             }
391 410
             # lets find requested coords
392
-            foreach ($vars['caches'] as &$cache_ref)
393
-            {
394
-                foreach ($cache_ref['alt_wpts'] as $alt_wpt_key => $alt_wpt)
395
-                {
396
-                    if ('alt_wpt:'.$alt_wpt['type'] == $location_source)
397
-                    {
411
+            foreach ($vars['caches'] as &$cache_ref) {
412
+                foreach ($cache_ref['alt_wpts'] as $alt_wpt_key => $alt_wpt) {
413
+                    if ('alt_wpt:'.$alt_wpt['type'] == $location_source) {
398 414
                         # Switch locations between primary wpt and alternate wpt.
399 415
                         # Also alter the cache name and make sure to append a proper
400 416
                         # notice.
@@ -418,8 +434,7 @@  discard block
 block discarded – undo
418 434
                         # remove current alt waypoint
419 435
                         unset($cache_ref['alt_wpts'][$alt_wpt_key]);
420 436
                         # add original location as alternate
421
-                        if ($vars['alt_wpts'])
422
-                        {
437
+                        if ($vars['alt_wpts']) {
423 438
                             $cache_ref['alt_wpts'][] = array(
424 439
                                 'name' => $cache_ref['code'].'-DEFAULT-COORDS',
425 440
                                 'location' => $original_location,
@@ -444,8 +459,7 @@  discard block
 block discarded – undo
444 459
 
445 460
             $ggz_entries = array();
446 461
 
447
-            foreach ($vars['caches'] as &$cache_ref)
448
-            {
462
+            foreach ($vars['caches'] as &$cache_ref) {
449 463
                 # Every $cache_ref will also be holding a reference to its entry.
450 464
                 # Note, that more attributes are added while processing gpsfile.tpl.php!
451 465
 
@@ -464,13 +478,14 @@  discard block
 block discarded – undo
464 478
 
465 479
                 $ggz_entry['ratings'] = array();
466 480
                 $ratings_ref = &$ggz_entry['ratings'];
467
-                if (isset($cache_ref['rating'])){
481
+                if (isset($cache_ref['rating'])) {
468 482
                    $ratings_ref['awesomeness'] = $cache_ref['rating'];
469 483
                 }
470 484
                 $ratings_ref['difficulty'] = $cache_ref['difficulty'];
471 485
                 if (!isset($cache_ref['size'])) {
472 486
                     $ratings_ref['size'] = 0; // Virtual, Event
473
-                } else if ($cache_ref['oxsize'] !== null) { // is this ox size one-to-one?
487
+                } else if ($cache_ref['oxsize'] !== null) {
488
+// is this ox size one-to-one?
474 489
                     $ratings_ref['size'] = $cache_ref['oxsize'];
475 490
                 }
476 491
                 $ratings_ref['terrain'] = $cache_ref['terrain'];
Please login to merge, or discard this patch.
htdocs/okapi/services/caches/formatters/gpxfile.tpl.php 1 patch
Braces   +35 added lines, -18 removed lines patch added patch discarded remove patch
@@ -40,14 +40,16 @@  discard block
 block discarded – undo
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
 block discarded – undo
71 73
                         &lt;p&gt;
72 74
                             &lt;a href="<?= $c['url'] ?>"&gt;<?= Okapi::xmlescape($c['name']) ?>&lt;/a&gt;
73 75
                             <?= _("hidden by") ?> &lt;a href='<?= $c['owner']['profile_url'] ?>'&gt;<?= Okapi::xmlescape($c['owner']['username']) ?>&lt;/a&gt;&lt;br/&gt;
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
                         &lt;/p&gt;
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
                             &lt;p&gt;&lt;b&gt;<?= _("Personal notes") ?>:&lt;/b&gt;&lt;br&gt;<?= Okapi::xmlescape(nl2br($c['my_notes'])) ?>&lt;/p&gt;
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
                             &lt;p&gt;<?= _("Attributes") ?>:&lt;/p&gt;
88 94
                             &lt;ul&gt;&lt;li&gt;<?= implode("&lt;/li&gt;&lt;li&gt;", $c['attrnames']) ?>&lt;/li&gt;&lt;/ul&gt;
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
                             &lt;p&gt;<?= _("Trackables") ?>:&lt;/p&gt;
92 99
                             &lt;ul&gt;
93 100
                             <?php foreach ($c['trackables'] as $t) { ?>
@@ -96,7 +103,8 @@  discard block
 block discarded – undo
96 103
                             &lt;/ul&gt;
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
                                 &lt;h2&gt;<?= _("Images") ?> (<?= count($c['images']) ?>)&lt;/h2&gt;
102 110
                                 &lt;div&gt;
@@ -109,9 +117,12 @@  discard block
 block discarded – undo
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
                                     &lt;h2&gt;<?= _("Images") ?> (<?= count($nonspoilers) ?>)&lt;/h2&gt;
@@ -129,7 +140,8 @@  discard block
 block discarded – undo
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
                             &lt;p&gt;<?= _("Image descriptions") ?>:&lt;/p&gt;
134 146
                             &lt;ul&gt;
135 147
                                 <?php foreach ($c['images'] as $no => $img) { ?>
@@ -147,10 +159,12 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
                 ?>
Please login to merge, or discard this patch.
htdocs/okapi/services/caches/geocache.php 1 patch
Braces   +28 added lines, -13 removed lines patch added patch discarded remove patch
@@ -24,19 +24,33 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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("
Please login to merge, or discard this patch.
htdocs/okapi/services/caches/shortcuts/search_and_retrieve.php 1 patch
Braces   +58 added lines, -52 removed lines patch added patch discarded remove patch
@@ -24,98 +24,104 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.