Completed
Pull Request — master (#313)
by Thomas
09:55
created
htdocs/lib2/logic/cracklib.inc.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -34,7 +34,7 @@
 block discarded – undo
34 34
 
35 35
     // min. 4 different chars
36 36
     $chars = array();
37
-    for ($i = 0; $i < mb_strlen($pw); $i ++) {
37
+    for ($i = 0; $i < mb_strlen($pw); $i++) {
38 38
         $chars[mb_substr($pw, $i, 1)] = true;
39 39
     }
40 40
 
Please login to merge, or discard this patch.
Braces   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -75,7 +75,8 @@
 block discarded – undo
75 75
 
76 76
     // $pw may not contain one of $addwords[]
77 77
     foreach ($wordlist as $v) {
78
-        if (mb_stripos($pw_lc, $v) !== false) {// mb_stripos needs PHP 5.2
78
+        if (mb_stripos($pw_lc, $v) !== false) {
79
+// mb_stripos needs PHP 5.2
79 80
             return false;
80 81
         }
81 82
     }
Please login to merge, or discard this patch.
htdocs/lib2/error.inc.php 1 patch
Indentation   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -7,34 +7,34 @@
 block discarded – undo
7 7
  *  Common error messages
8 8
  ***************************************************************************/
9 9
 
10
- define('ERROR_UNKNOWN', 1000);
11
- define('ERROR_TEMPLATE_NOT_FOUND', 1001);
12
- define('ERROR_COMPILATION_FAILED', 1002);
13
- define('ERROR_NO_ACCESS', 1003);
14
- define('ERROR_INVALID_OPERATION', 1004);
15
- define('ERROR_LOGIN_REQUIRED', 1005);
16
- define('ERROR_MAIL_TEMPLATE_NOT_FOUND', 1006);
17
- define('ERROR_NO_COOKIES', 1007);
18
- define('ERROR_ALREADY_LOGGEDIN', 1008);
19
- define('ERROR_USER_NOT_ACTIVE', 1009);
20
- define('ERROR_USER_NO_EMAIL', 1010);
21
- define('ERROR_CACHE_NOT_PUBLISHED', 1011);
22
- define('ERROR_CACHE_LOCKED', 1012);
10
+    define('ERROR_UNKNOWN', 1000);
11
+    define('ERROR_TEMPLATE_NOT_FOUND', 1001);
12
+    define('ERROR_COMPILATION_FAILED', 1002);
13
+    define('ERROR_NO_ACCESS', 1003);
14
+    define('ERROR_INVALID_OPERATION', 1004);
15
+    define('ERROR_LOGIN_REQUIRED', 1005);
16
+    define('ERROR_MAIL_TEMPLATE_NOT_FOUND', 1006);
17
+    define('ERROR_NO_COOKIES', 1007);
18
+    define('ERROR_ALREADY_LOGGEDIN', 1008);
19
+    define('ERROR_USER_NOT_ACTIVE', 1009);
20
+    define('ERROR_USER_NO_EMAIL', 1010);
21
+    define('ERROR_CACHE_NOT_PUBLISHED', 1011);
22
+    define('ERROR_CACHE_LOCKED', 1012);
23 23
 
24
- define('ERROR_SEARCHPLUGIN_WAYPOINT_FORMAT', 1013);
25
- define('ERROR_SEARCHPLUGIN_WAYPOINT_MANY', 1014);
26
- define('ERROR_SEARCHPLUGIN_WAYPOINT_NOTFOUND', 1015);
24
+    define('ERROR_SEARCHPLUGIN_WAYPOINT_FORMAT', 1013);
25
+    define('ERROR_SEARCHPLUGIN_WAYPOINT_MANY', 1014);
26
+    define('ERROR_SEARCHPLUGIN_WAYPOINT_NOTFOUND', 1015);
27 27
  
28
- define('ERROR_DB_COULD_NOT_RECONNECT', 1016);
29
- define('ERROR_DB_NO_ROOT', 1017);
28
+    define('ERROR_DB_COULD_NOT_RECONNECT', 1016);
29
+    define('ERROR_DB_NO_ROOT', 1017);
30 30
 
31
- define('ERROR_USER_NOT_EXISTS', 1018);
32
- define('ERROR_CACHE_NOT_EXISTS', 1019);
33
- define('ERROR_CACHELOG_NOT_EXISTS', 1020);
34
- define('ERROR_PICTURE_NOT_EXISTS', 1021);
31
+    define('ERROR_USER_NOT_EXISTS', 1018);
32
+    define('ERROR_CACHE_NOT_EXISTS', 1019);
33
+    define('ERROR_CACHELOG_NOT_EXISTS', 1020);
34
+    define('ERROR_PICTURE_NOT_EXISTS', 1021);
35 35
 
36
- define('ERROR_UPLOAD_ERR_NO_FILE', 1022);
37
- define('ERROR_UPLOAD_ERR_SIZE', 1023);
38
- define('ERROR_UPLOAD_ERR_TYPE', 1024);
39
- define('ERROR_UPLOAD_UNKNOWN', 1025);
40
- define('ERROR_UPLOAD_ERR_BAD_FORMAT', 1026);
36
+    define('ERROR_UPLOAD_ERR_NO_FILE', 1022);
37
+    define('ERROR_UPLOAD_ERR_SIZE', 1023);
38
+    define('ERROR_UPLOAD_ERR_TYPE', 1024);
39
+    define('ERROR_UPLOAD_UNKNOWN', 1025);
40
+    define('ERROR_UPLOAD_ERR_BAD_FORMAT', 1026);
Please login to merge, or discard this patch.
htdocs/lib2/login.class.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -20,13 +20,13 @@
 block discarded – undo
20 20
  *
21 21
  ***************************************************************************/
22 22
 
23
-define('LOGIN_UNKNOWN_ERROR', - 1);     // unkown error occured
24
-define('LOGIN_OK', 0);                 // login succeeded
25
-define('LOGIN_BADUSERPW', 1);          // bad username or password
26
-define('LOGIN_TOOMUCHLOGINS', 2);      // too many logins in short time
27
-define('LOGIN_USERNOTACTIVE', 3);      // the useraccount locked
23
+define('LOGIN_UNKNOWN_ERROR', - 1); // unkown error occured
24
+define('LOGIN_OK', 0); // login succeeded
25
+define('LOGIN_BADUSERPW', 1); // bad username or password
26
+define('LOGIN_TOOMUCHLOGINS', 2); // too many logins in short time
27
+define('LOGIN_USERNOTACTIVE', 3); // the useraccount locked
28 28
 define('LOGIN_EMPTY_USERPASSWORD', 4); // given username/password was empty
29
-define('LOGIN_LOGOUT_OK', 5);          // logout was successfull
29
+define('LOGIN_LOGOUT_OK', 5); // logout was successfull
30 30
 
31 31
 // login times in seconds
32 32
 define('LOGIN_TIME', 60 * 60);
Please login to merge, or discard this patch.
htdocs/okapi/services/replicate/changelog.php 1 patch
Braces   +9 added lines, -4 removed lines patch added patch discarded remove patch
@@ -29,13 +29,18 @@
 block discarded – undo
29 29
         require_once('replicate_common.inc.php');
30 30
 
31 31
         $since = $request->get_parameter('since');
32
-        if ($since === null) throw new ParamMissing('since');
33
-        if ((int)$since != $since) throw new InvalidParam('since');
32
+        if ($since === null) {
33
+            throw new ParamMissing('since');
34
+        }
35
+        if ((int)$since != $since) {
36
+            throw new InvalidParam('since');
37
+        }
34 38
 
35 39
         # Let's check the $since parameter.
36 40
 
37
-        if (!ReplicateCommon::check_since_param($since))
38
-            throw new BadRequest("The 'since' parameter is too old. You must update your database more frequently.");
41
+        if (!ReplicateCommon::check_since_param($since)) {
42
+                    throw new BadRequest("The 'since' parameter is too old. You must update your database more frequently.");
43
+        }
39 44
 
40 45
         # Select a best chunk for the given $since, get the chunk from the database (or cache).
41 46
 
Please login to merge, or discard this patch.
htdocs/okapi/services/caches/geocaches.php 4 patches
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -453,7 +453,7 @@  discard block
 block discarded – undo
453 453
             # OCDE caches can also be indirectly watched by watching cache lists:
454 454
             if (Settings::get('OC_BRANCH') == 'oc.de')
455 455
             {
456
-              $tmp = Db::select_column("
456
+                $tmp = Db::select_column("
457 457
                   select c.wp_oc
458 458
                   from
459 459
                       caches c,
@@ -464,8 +464,8 @@  discard block
 block discarded – undo
464 464
                       and clw.cache_list_id = cli.cache_list_id
465 465
                       and clw.user_id = '".Db::escape_string($request->token->user_id)."'
466 466
               ");
467
-              foreach ($tmp as $cache_code)
468
-                  $tmp2[$cache_code] = true;
467
+                foreach ($tmp as $cache_code)
468
+                    $tmp2[$cache_code] = true;
469 469
             }
470 470
 
471 471
             foreach ($results as $cache_code => &$result_ref)
Please login to merge, or discard this patch.
Unused Use Statements   +6 added lines, -8 removed lines patch added patch discarded remove patch
@@ -2,19 +2,17 @@
 block discarded – undo
2 2
 
3 3
 namespace okapi\services\caches\geocaches;
4 4
 
5
-use Exception;
6 5
 use ArrayObject;
7
-use okapi\Okapi;
6
+use Exception;
7
+use okapi\BadRequest;
8 8
 use okapi\Db;
9
-use okapi\Settings;
10
-use okapi\OkapiRequest;
11
-use okapi\ParamMissing;
12 9
 use okapi\InvalidParam;
13
-use okapi\BadRequest;
10
+use okapi\Okapi;
14 11
 use okapi\OkapiInternalRequest;
12
+use okapi\OkapiRequest;
15 13
 use okapi\OkapiServiceRunner;
16
-use okapi\OkapiAccessToken;
17
-use okapi\services\caches\search\SearchAssistant;
14
+use okapi\ParamMissing;
15
+use okapi\Settings;
18 16
 use okapi\services\attrs\AttrHelper;
19 17
 
20 18
 class WebService
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -34,7 +34,7 @@  discard block
 block discarded – undo
34 34
         'my_notes', 'trackables_count', 'trackables', 'alt_wpts', 'last_found',
35 35
         'last_modified', 'date_created', 'date_hidden', 'internal_id', 'is_watched',
36 36
         'is_ignored', 'willattends', 'country', 'state', 'preview_image',
37
-        'trip_time', 'trip_distance', 'attribution_note','gc_code', 'hint2', 'hints2',
37
+        'trip_time', 'trip_distance', 'attribution_note', 'gc_code', 'hint2', 'hints2',
38 38
         'protection_areas', 'short_description', 'short_descriptions', 'needs_maintenance');
39 39
 
40 40
     public static function call(OkapiRequest $request)
@@ -99,7 +99,7 @@  discard block
 block discarded – undo
99 99
             throw new InvalidParam('attribution_append');
100 100
 
101 101
         $log_fields = $request->get_parameter('log_fields');
102
-        if (!$log_fields) $log_fields = "uuid|date|user|type|comment";  // validation is done on call
102
+        if (!$log_fields) $log_fields = "uuid|date|user|type|comment"; // validation is done on call
103 103
 
104 104
         $user_uuid = $request->get_parameter('user_uuid');
105 105
         if ($user_uuid != null)
@@ -253,7 +253,7 @@  discard block
 block discarded – undo
253 253
                         break;
254 254
                     case 'bearing':
255 255
                         $tmp = Okapi::get_bearing($center_lat, $center_lon, $row['latitude'], $row['longitude']);
256
-                        $entry['bearing'] = ($tmp !== null) ? ((int)(10*$tmp)) / 10.0 : null;
256
+                        $entry['bearing'] = ($tmp !== null) ? ((int)(10 * $tmp)) / 10.0 : null;
257 257
                         break;
258 258
                     case 'bearing2':
259 259
                         $tmp = Okapi::get_bearing($center_lat, $center_lon, $row['latitude'], $row['longitude']);
@@ -287,13 +287,13 @@  discard block
 block discarded – undo
287 287
                         switch (Okapi::cache_sizeid_to_size2($row['size']))
288 288
                         {
289 289
                             case 'none': $entry['size'] = null; break;
290
-                            case 'nano': $entry['size'] = 1.0; break;  # same as micro
290
+                            case 'nano': $entry['size'] = 1.0; break; # same as micro
291 291
                             case 'micro': $entry['size'] = 1.0; break;
292 292
                             case 'small': $entry['size'] = 2.0; break;
293 293
                             case 'regular': $entry['size'] = 3.0; break;
294 294
                             case 'large': $entry['size'] = 4.0; break;
295 295
                             case 'xlarge': $entry['size'] = 5.0; break;
296
-                            case 'other': $entry['size'] = null; break;  # same as none
296
+                            case 'other': $entry['size'] = null; break; # same as none
297 297
                             default: throw new Exception();
298 298
                         }
299 299
                         break;
@@ -304,12 +304,12 @@  discard block
 block discarded – undo
304 304
                     case 'trip_time':
305 305
                         # search time is entered in hours:minutes and converted to decimal hours,
306 306
                         # which can produce lots of unneeded decimal places; 2 of them are sufficient here
307
-                        $entry['trip_time'] = $row['trip_time'] === null ? null : round($row['trip_time'],2); break;
307
+                        $entry['trip_time'] = $row['trip_time'] === null ? null : round($row['trip_time'], 2); break;
308 308
                         break;
309 309
                     case 'trip_distance':
310 310
                         # way length is entered in km as decimal fraction, but number conversions can
311 311
                         # create fake digits which should be stripped; meter precision is sufficient here
312
-                        $entry['trip_distance'] = $row['trip_distance'] === null ? null : round($row['trip_distance'],3); break;
312
+                        $entry['trip_distance'] = $row['trip_distance'] === null ? null : round($row['trip_distance'], 3); break;
313 313
                         break;
314 314
                     case 'rating':
315 315
                         if ($row['votes'] < 3) $entry['rating'] = null;
@@ -563,7 +563,7 @@  discard block
 block discarded – undo
563 563
                 {
564 564
                     $results[$cache_code]['hints'][strtolower($row['language'])] = $row['hint'];
565 565
                     $results[$cache_code]['hints2'][strtolower($row['language'])]
566
-                        = htmlspecialchars_decode(mb_ereg_replace("<br />", "" , $row['hint']), ENT_COMPAT);
566
+                        = htmlspecialchars_decode(mb_ereg_replace("<br />", "", $row['hint']), ENT_COMPAT);
567 567
                 }
568 568
             }
569 569
             foreach ($results as &$result_ref)
@@ -630,7 +630,7 @@  discard block
 block discarded – undo
630 630
                 $image = array(
631 631
                     'uuid' => $row['uuid'],
632 632
                     'url' => $row['url'],
633
-                    'thumb_url' => Settings::get('SITE_URL') . 'thumbs.php?'.$object_type_param.'uuid=' . $row['uuid'],
633
+                    'thumb_url' => Settings::get('SITE_URL').'thumbs.php?'.$object_type_param.'uuid='.$row['uuid'],
634 634
                     'caption' => $row['title'],
635 635
                     'unique_caption' => self::get_unique_caption($row['title']),
636 636
                     'is_spoiler' => ($row['spoiler'] ? true : false),
Please login to merge, or discard this patch.
Braces   +324 added lines, -349 removed lines patch added patch discarded remove patch
@@ -40,33 +40,41 @@  discard block
 block discarded – undo
40 40
     public static function call(OkapiRequest $request)
41 41
     {
42 42
         $cache_codes = $request->get_parameter('cache_codes');
43
-        if ($cache_codes === null) throw new ParamMissing('cache_codes');
44
-        if ($cache_codes === "")
45
-        {
43
+        if ($cache_codes === null) {
44
+            throw new ParamMissing('cache_codes');
45
+        }
46
+        if ($cache_codes === "") {
46 47
             # Issue 106 requires us to allow empty list of cache codes to be passed into this method.
47 48
             # All of the queries below have to be ready for $cache_codes to be empty!
48 49
             $cache_codes = array();
50
+        } else {
51
+                    $cache_codes = explode("|", $cache_codes);
49 52
         }
50
-        else
51
-            $cache_codes = explode("|", $cache_codes);
52 53
 
53
-        if ((count($cache_codes) > 500) && (!$request->skip_limits))
54
-            throw new InvalidParam('cache_codes', "Maximum allowed number of referenced ".
54
+        if ((count($cache_codes) > 500) && (!$request->skip_limits)) {
55
+                    throw new InvalidParam('cache_codes', "Maximum allowed number of referenced ".
55 56
                 "caches is 500. You provided ".count($cache_codes)." cache codes.");
56
-        if (count($cache_codes) != count(array_unique($cache_codes)))
57
-            throw new InvalidParam('cache_codes', "Duplicate codes detected (make sure each cache is referenced only once).");
57
+        }
58
+        if (count($cache_codes) != count(array_unique($cache_codes))) {
59
+                    throw new InvalidParam('cache_codes', "Duplicate codes detected (make sure each cache is referenced only once).");
60
+        }
58 61
 
59 62
         $langpref = $request->get_parameter('langpref');
60
-        if (!$langpref) $langpref = "en";
63
+        if (!$langpref) {
64
+            $langpref = "en";
65
+        }
61 66
         $langpref .= "|".Settings::get('SITELANG');
62 67
         $langpref = explode("|", $langpref);
63 68
 
64 69
         $fields = $request->get_parameter('fields');
65
-        if (!$fields) $fields = "code|name|location|type|status";
70
+        if (!$fields) {
71
+            $fields = "code|name|location|type|status";
72
+        }
66 73
         $fields = explode("|", $fields);
67
-        foreach ($fields as $field)
68
-            if (!in_array($field, self::$valid_field_names))
74
+        foreach ($fields as $field) {
75
+                    if (!in_array($field, self::$valid_field_names))
69 76
                 throw new InvalidParam('fields', "'$field' is not a valid field code.");
77
+        }
70 78
 
71 79
         # Some fields need to be temporarily included whenever the "description"
72 80
         # or "attribution_note" field are included. That's a little ugly, but
@@ -79,79 +87,88 @@  discard block
 block discarded – undo
79 87
             || in_array('hint', $fields) || in_array('hints', $fields)
80 88
             || in_array('hint2', $fields) || in_array('hints2', $fields)
81 89
             || in_array('attribution_note', $fields)
82
-        )
83
-        {
84
-            if (!in_array('owner', $fields))
85
-            {
90
+        ) {
91
+            if (!in_array('owner', $fields)) {
86 92
                 $fields[] = "owner";
87 93
                 $fields_to_remove_later[] = "owner";
88 94
             }
89
-            if (!in_array('internal_id', $fields))
90
-            {
95
+            if (!in_array('internal_id', $fields)) {
91 96
                 $fields[] = "internal_id";
92 97
                 $fields_to_remove_later[] = "internal_id";
93 98
             }
94 99
         }
95 100
 
96 101
         $attribution_append = $request->get_parameter('attribution_append');
97
-        if (!$attribution_append) $attribution_append = 'full';
98
-        if (!in_array($attribution_append, array('none', 'static', 'full')))
99
-            throw new InvalidParam('attribution_append');
102
+        if (!$attribution_append) {
103
+            $attribution_append = 'full';
104
+        }
105
+        if (!in_array($attribution_append, array('none', 'static', 'full'))) {
106
+                    throw new InvalidParam('attribution_append');
107
+        }
100 108
 
101 109
         $log_fields = $request->get_parameter('log_fields');
102
-        if (!$log_fields) $log_fields = "uuid|date|user|type|comment";  // validation is done on call
110
+        if (!$log_fields) {
111
+            $log_fields = "uuid|date|user|type|comment";
112
+        }
113
+        // validation is done on call
103 114
 
104 115
         $user_uuid = $request->get_parameter('user_uuid');
105
-        if ($user_uuid != null)
106
-        {
116
+        if ($user_uuid != null) {
107 117
             $user_id = Db::select_value("select user_id from user where uuid='".Db::escape_string($user_uuid)."'");
108
-            if ($user_id == null)
109
-                throw new InvalidParam('user_uuid', "User not found.");
110
-            if (($request->token != null) && ($request->token->user_id != $user_id))
111
-                throw new InvalidParam('user_uuid', "User does not match the Access Token used.");
118
+            if ($user_id == null) {
119
+                            throw new InvalidParam('user_uuid', "User not found.");
120
+            }
121
+            if (($request->token != null) && ($request->token->user_id != $user_id)) {
122
+                            throw new InvalidParam('user_uuid', "User does not match the Access Token used.");
123
+            }
124
+        } elseif (($user_uuid == null) && ($request->token != null)) {
125
+                    $user_id = $request->token->user_id;
126
+        } else {
127
+                    $user_id = null;
112 128
         }
113
-        elseif (($user_uuid == null) && ($request->token != null))
114
-            $user_id = $request->token->user_id;
115
-        else
116
-            $user_id = null;
117 129
 
118 130
         $lpc = $request->get_parameter('lpc');
119
-        if ($lpc === null) $lpc = 10;
120
-        if ($lpc == 'all')
121
-            $lpc = null;
122
-        else
123
-        {
124
-            if (!is_numeric($lpc))
125
-                throw new InvalidParam('lpc', "Invalid number: '$lpc'");
131
+        if ($lpc === null) {
132
+            $lpc = 10;
133
+        }
134
+        if ($lpc == 'all') {
135
+                    $lpc = null;
136
+        } else {
137
+            if (!is_numeric($lpc)) {
138
+                            throw new InvalidParam('lpc', "Invalid number: '$lpc'");
139
+            }
126 140
             $lpc = intval($lpc);
127
-            if ($lpc < 0)
128
-                throw new InvalidParam('lpc', "Must be a positive value.");
141
+            if ($lpc < 0) {
142
+                            throw new InvalidParam('lpc', "Must be a positive value.");
143
+            }
129 144
         }
130 145
 
131 146
         if (in_array('distance', $fields) || in_array('bearing', $fields) || in_array('bearing2', $fields)
132
-            || in_array('bearing3', $fields))
133
-        {
147
+            || in_array('bearing3', $fields)) {
134 148
             $tmp = $request->get_parameter('my_location');
135
-            if (!$tmp)
136
-                throw new BadRequest("When using 'distance' or 'bearing' fields, you have to supply 'my_location' parameter.");
149
+            if (!$tmp) {
150
+                            throw new BadRequest("When using 'distance' or 'bearing' fields, you have to supply 'my_location' parameter.");
151
+            }
137 152
             $parts = explode('|', $tmp);
138
-            if (count($parts) != 2)
139
-                throw new InvalidParam('my_location', "Expecting 2 pipe-separated parts, got ".count($parts).".");
140
-            foreach ($parts as &$part_ref)
141
-            {
142
-                if (!preg_match("/^-?[0-9]+(\.?[0-9]*)$/", $part_ref))
143
-                    throw new InvalidParam('my_location', "'$part_ref' is not a valid float number.");
153
+            if (count($parts) != 2) {
154
+                            throw new InvalidParam('my_location', "Expecting 2 pipe-separated parts, got ".count($parts).".");
155
+            }
156
+            foreach ($parts as &$part_ref) {
157
+                if (!preg_match("/^-?[0-9]+(\.?[0-9]*)$/", $part_ref)) {
158
+                                    throw new InvalidParam('my_location', "'$part_ref' is not a valid float number.");
159
+                }
144 160
                 $part_ref = floatval($part_ref);
145 161
             }
146 162
             list($center_lat, $center_lon) = $parts;
147
-            if ($center_lat > 90 || $center_lat < -90)
148
-                throw new InvalidParam('current_position', "Latitudes have to be within -90..90 range.");
149
-            if ($center_lon > 180 || $center_lon < -180)
150
-                throw new InvalidParam('current_position', "Longitudes have to be within -180..180 range.");
163
+            if ($center_lat > 90 || $center_lat < -90) {
164
+                            throw new InvalidParam('current_position', "Latitudes have to be within -90..90 range.");
165
+            }
166
+            if ($center_lon > 180 || $center_lon < -180) {
167
+                            throw new InvalidParam('current_position', "Longitudes have to be within -180..180 range.");
168
+            }
151 169
         }
152 170
 
153
-        if (Settings::get('OC_BRANCH') == 'oc.de')
154
-        {
171
+        if (Settings::get('OC_BRANCH') == 'oc.de') {
155 172
             # DE branch:
156 173
             # - Caches do not have ratings.
157 174
             # - Total numbers of founds and notfounds are kept in the "stat_caches" table.
@@ -181,9 +198,7 @@  discard block
 block discarded – undo
181 198
                     wp_oc in ('".implode("','", array_map('\okapi\Db::escape_string', $cache_codes))."')
182 199
                     and status in (1,2,3)
183 200
             ");
184
-        }
185
-        elseif (Settings::get('OC_BRANCH') == 'oc.pl')
186
-        {
201
+        } elseif (Settings::get('OC_BRANCH') == 'oc.pl') {
187 202
             # PL branch:
188 203
             # - Caches have ratings.
189 204
             # - Total numbers of found and notfounds are kept in the "caches" table.
@@ -218,23 +233,21 @@  discard block
 block discarded – undo
218 233
         $cacheid2wptcode = array();
219 234
         $owner_ids = array();
220 235
         $outdated_listings = array();
221
-        while ($row = Db::fetch_assoc($rs))
222
-        {
236
+        while ($row = Db::fetch_assoc($rs)) {
223 237
             $entry = array();
224 238
             $cacheid2wptcode[$row['cache_id']] = $row['wp_oc'];
225
-            foreach ($fields as $field)
226
-            {
227
-                switch ($field)
228
-                {
239
+            foreach ($fields as $field) {
240
+                switch ($field) {
229 241
                     case 'code': $entry['code'] = $row['wp_oc']; break;
230 242
                     case 'gc_code':
231 243
                         $wp_gc = $row['wp_gc_maintained'] ? $row['wp_gc_maintained'] : $row['wp_gc'];
232 244
                         // OC software allows entering anything here, and that's what users do.
233 245
                         // We do a formal verification so that only a valid GC code is returned:
234
-                        if (preg_match('/^\s*[Gg][Cc][A-Za-z0-9]+\s*$/', $wp_gc))
235
-                            $entry['gc_code'] = strtoupper(trim($wp_gc));
236
-                        else
237
-                            $entry['gc_code'] = null;
246
+                        if (preg_match('/^\s*[Gg][Cc][A-Za-z0-9]+\s*$/', $wp_gc)) {
247
+                                                    $entry['gc_code'] = strtoupper(trim($wp_gc));
248
+                        } else {
249
+                                                    $entry['gc_code'] = null;
250
+                        }
238 251
                         unset($wp_gc);
239 252
                         break;
240 253
                     case 'name': $entry['name'] = $row['name']; break;
@@ -269,23 +282,26 @@  discard block
 block discarded – undo
269 282
                     case 'is_ignored': /* handled separately */ break;
270 283
                     case 'founds': $entry['founds'] = $row['founds'] + 0; break;
271 284
                     case 'notfounds':
272
-                        if ($row['type'] != 6) {  # non-event
285
+                        if ($row['type'] != 6) {
286
+# non-event
273 287
                             $entry['notfounds'] = $row['notfounds'] + 0;
274
-                        } else {  # event
288
+                        } else {
289
+# event
275 290
                             $entry['notfounds'] = 0;
276 291
                         }
277 292
                         break;
278 293
                     case 'willattends':
279
-                        if ($row['type'] == 6) {  # event
294
+                        if ($row['type'] == 6) {
295
+# event
280 296
                             $entry['willattends'] = $row['willattends'] + 0;
281
-                        } else {  # non-event
297
+                        } else {
298
+# non-event
282 299
                             $entry['willattends'] = 0;
283 300
                         }
284 301
                         break;
285 302
                     case 'size':
286 303
                         # Deprecated. Leave it for backward-compatibility. See issue 155.
287
-                        switch (Okapi::cache_sizeid_to_size2($row['size']))
288
-                        {
304
+                        switch (Okapi::cache_sizeid_to_size2($row['size'])) {
289 305
                             case 'none': $entry['size'] = null; break;
290 306
                             case 'nano': $entry['size'] = 1.0; break;  # same as micro
291 307
                             case 'micro': $entry['size'] = 1.0; break;
@@ -312,12 +328,19 @@  discard block
 block discarded – undo
312 328
                         $entry['trip_distance'] = $row['trip_distance'] === null ? null : round($row['trip_distance'],3); break;
313 329
                         break;
314 330
                     case 'rating':
315
-                        if ($row['votes'] < 3) $entry['rating'] = null;
316
-                        elseif ($row['score'] >= 2.2) $entry['rating'] = 5.0;
317
-                        elseif ($row['score'] >= 1.4) $entry['rating'] = 4.0;
318
-                        elseif ($row['score'] >= 0.1) $entry['rating'] = 3.0;
319
-                        elseif ($row['score'] >= -1.0) $entry['rating'] = 2.0;
320
-                        else $entry['rating'] = 1.0;
331
+                        if ($row['votes'] < 3) {
332
+                            $entry['rating'] = null;
333
+                        } elseif ($row['score'] >= 2.2) {
334
+                            $entry['rating'] = 5.0;
335
+                        } elseif ($row['score'] >= 1.4) {
336
+                            $entry['rating'] = 4.0;
337
+                        } elseif ($row['score'] >= 0.1) {
338
+                            $entry['rating'] = 3.0;
339
+                        } elseif ($row['score'] >= -1.0) {
340
+                            $entry['rating'] = 2.0;
341
+                        } else {
342
+                            $entry['rating'] = 1.0;
343
+                        }
321 344
                         break;
322 345
                     case 'rating_votes': $entry['rating_votes'] = $row['votes'] + 0; break;
323 346
                     case 'recommendations': $entry['recommendations'] = $row['topratings'] + 0; break;
@@ -352,25 +375,25 @@  discard block
 block discarded – undo
352 375
                 }
353 376
             }
354 377
             $results[$row['wp_oc']] = $entry;
355
-            if ($row['listing_outdated'] > 0)
356
-                $outdated_listings[] = $row['wp_oc'];
378
+            if ($row['listing_outdated'] > 0) {
379
+                            $outdated_listings[] = $row['wp_oc'];
380
+            }
357 381
         }
358 382
         Db::free_result($rs);
359 383
 
360 384
         # owner
361 385
 
362
-        if (in_array('owner', $fields) && (count($results) > 0))
363
-        {
386
+        if (in_array('owner', $fields) && (count($results) > 0)) {
364 387
             $rs = Db::query("
365 388
                 select user_id, uuid, username
366 389
                 from user
367 390
                 where user_id in ('".implode("','", array_map('\okapi\Db::escape_string', array_values($owner_ids)))."')
368 391
             ");
369 392
             $tmp = array();
370
-            while ($row = Db::fetch_assoc($rs))
371
-                $tmp[$row['user_id']] = $row;
372
-            foreach ($results as $cache_code => &$result_ref)
373
-            {
393
+            while ($row = Db::fetch_assoc($rs)) {
394
+                            $tmp[$row['user_id']] = $row;
395
+            }
396
+            foreach ($results as $cache_code => &$result_ref) {
374 397
                 $row = $tmp[$owner_ids[$cache_code]];
375 398
                 $result_ref['owner'] = array(
376 399
                     'uuid' => $row['uuid'],
@@ -382,10 +405,10 @@  discard block
 block discarded – undo
382 405
 
383 406
         # is_found
384 407
 
385
-        if (in_array('is_found', $fields))
386
-        {
387
-            if ($user_id == null)
388
-                throw new BadRequest("Either 'user_uuid' parameter OR Level 3 Authentication is required to access 'is_found' field.");
408
+        if (in_array('is_found', $fields)) {
409
+            if ($user_id == null) {
410
+                            throw new BadRequest("Either 'user_uuid' parameter OR Level 3 Authentication is required to access 'is_found' field.");
411
+            }
389 412
             $tmp = Db::select_column("
390 413
                 select c.wp_oc
391 414
                 from
@@ -401,18 +424,20 @@  discard block
 block discarded – undo
401 424
                     ".((Settings::get('OC_BRANCH') == 'oc.pl') ? "and cl.deleted = 0" : "")."
402 425
             ");
403 426
             $tmp2 = array();
404
-            foreach ($tmp as $cache_code)
405
-                $tmp2[$cache_code] = true;
406
-            foreach ($results as $cache_code => &$result_ref)
407
-                $result_ref['is_found'] = isset($tmp2[$cache_code]);
427
+            foreach ($tmp as $cache_code) {
428
+                            $tmp2[$cache_code] = true;
429
+            }
430
+            foreach ($results as $cache_code => &$result_ref) {
431
+                            $result_ref['is_found'] = isset($tmp2[$cache_code]);
432
+            }
408 433
         }
409 434
 
410 435
         # is_not_found
411 436
 
412
-        if (in_array('is_not_found', $fields))
413
-        {
414
-            if ($user_id == null)
415
-                throw new BadRequest("Either 'user_uuid' parameter OR Level 3 Authentication is required to access 'is_not_found' field.");
437
+        if (in_array('is_not_found', $fields)) {
438
+            if ($user_id == null) {
439
+                            throw new BadRequest("Either 'user_uuid' parameter OR Level 3 Authentication is required to access 'is_not_found' field.");
440
+            }
416 441
             $tmp = Db::select_column("
417 442
                 select c.wp_oc
418 443
                 from
@@ -425,18 +450,20 @@  discard block
 block discarded – undo
425 450
                     ".((Settings::get('OC_BRANCH') == 'oc.pl') ? "and cl.deleted = 0" : "")."
426 451
             ");
427 452
             $tmp2 = array();
428
-            foreach ($tmp as $cache_code)
429
-                $tmp2[$cache_code] = true;
430
-            foreach ($results as $cache_code => &$result_ref)
431
-                $result_ref['is_not_found'] = isset($tmp2[$cache_code]);
453
+            foreach ($tmp as $cache_code) {
454
+                            $tmp2[$cache_code] = true;
455
+            }
456
+            foreach ($results as $cache_code => &$result_ref) {
457
+                            $result_ref['is_not_found'] = isset($tmp2[$cache_code]);
458
+            }
432 459
         }
433 460
 
434 461
         # is_watched
435 462
 
436
-        if (in_array('is_watched', $fields))
437
-        {
438
-            if ($request->token == null)
439
-                throw new BadRequest("Level 3 Authentication is required to access 'is_watched' field.");
463
+        if (in_array('is_watched', $fields)) {
464
+            if ($request->token == null) {
465
+                            throw new BadRequest("Level 3 Authentication is required to access 'is_watched' field.");
466
+            }
440 467
             $tmp = Db::select_column("
441 468
                 select c.wp_oc
442 469
                 from
@@ -447,12 +474,12 @@  discard block
 block discarded – undo
447 474
                     and cw.user_id = '".Db::escape_string($request->token->user_id)."'
448 475
             ");
449 476
             $tmp2 = array();
450
-            foreach ($tmp as $cache_code)
451
-                $tmp2[$cache_code] = true;
477
+            foreach ($tmp as $cache_code) {
478
+                            $tmp2[$cache_code] = true;
479
+            }
452 480
 
453 481
             # OCDE caches can also be indirectly watched by watching cache lists:
454
-            if (Settings::get('OC_BRANCH') == 'oc.de')
455
-            {
482
+            if (Settings::get('OC_BRANCH') == 'oc.de') {
456 483
               $tmp = Db::select_column("
457 484
                   select c.wp_oc
458 485
                   from
@@ -464,20 +491,22 @@  discard block
 block discarded – undo
464 491
                       and clw.cache_list_id = cli.cache_list_id
465 492
                       and clw.user_id = '".Db::escape_string($request->token->user_id)."'
466 493
               ");
467
-              foreach ($tmp as $cache_code)
468
-                  $tmp2[$cache_code] = true;
494
+              foreach ($tmp as $cache_code) {
495
+                                $tmp2[$cache_code] = true;
496
+              }
469 497
             }
470 498
 
471
-            foreach ($results as $cache_code => &$result_ref)
472
-                $result_ref['is_watched'] = isset($tmp2[$cache_code]);
499
+            foreach ($results as $cache_code => &$result_ref) {
500
+                            $result_ref['is_watched'] = isset($tmp2[$cache_code]);
501
+            }
473 502
         }
474 503
 
475 504
         # is_ignored
476 505
 
477
-        if (in_array('is_ignored', $fields))
478
-        {
479
-            if ($request->token == null)
480
-                throw new BadRequest("Level 3 Authentication is required to access 'is_ignored' field.");
506
+        if (in_array('is_ignored', $fields)) {
507
+            if ($request->token == null) {
508
+                            throw new BadRequest("Level 3 Authentication is required to access 'is_ignored' field.");
509
+            }
481 510
             $tmp = Db::select_column("
482 511
                 select c.wp_oc
483 512
                 from
@@ -488,10 +517,12 @@  discard block
 block discarded – undo
488 517
                     and ci.user_id = '".Db::escape_string($request->token->user_id)."'
489 518
             ");
490 519
             $tmp2 = array();
491
-            foreach ($tmp as $cache_code)
492
-                $tmp2[$cache_code] = true;
493
-            foreach ($results as $cache_code => &$result_ref)
494
-                $result_ref['is_ignored'] = isset($tmp2[$cache_code]);
520
+            foreach ($tmp as $cache_code) {
521
+                            $tmp2[$cache_code] = true;
522
+            }
523
+            foreach ($results as $cache_code => &$result_ref) {
524
+                            $result_ref['is_ignored'] = isset($tmp2[$cache_code]);
525
+            }
495 526
         }
496 527
 
497 528
         # Descriptions and hints.
@@ -499,13 +530,11 @@  discard block
 block discarded – undo
499 530
         if (in_array('description', $fields) || in_array('descriptions', $fields)
500 531
             || in_array('short_description', $fields) || in_array('short_descriptions', $fields)
501 532
             || in_array('hint', $fields) || in_array('hints', $fields)
502
-            || in_array('hint2', $fields) || in_array('hints2', $fields))
503
-        {
533
+            || in_array('hint2', $fields) || in_array('hints2', $fields)) {
504 534
             # At first, we will fill all those fields, even if user requested just one
505 535
             # of them. We will chop off the unwanted ones at the end.
506 536
 
507
-            foreach ($results as &$result_ref)
508
-            {
537
+            foreach ($results as &$result_ref) {
509 538
                 $result_ref['short_descriptions'] = new ArrayObject();
510 539
                 $result_ref['descriptions'] = new ArrayObject();
511 540
                 $result_ref['hints'] = new ArrayObject();
@@ -519,19 +548,16 @@  discard block
 block discarded – undo
519 548
                 from cache_desc
520 549
                 where cache_id in ('".implode("','", array_map('\okapi\Db::escape_string', array_keys($cacheid2wptcode)))."')
521 550
             ");
522
-            while ($row = Db::fetch_assoc($rs))
523
-            {
551
+            while ($row = Db::fetch_assoc($rs)) {
524 552
                 $cache_code = $cacheid2wptcode[$row['cache_id']];
525 553
                 // strtolower - ISO 639-1 codes are lowercase
526
-                if ($row['desc'])
527
-                {
554
+                if ($row['desc']) {
528 555
                     /* Note, that the "owner" and "internal_id" fields are automatically included,
529 556
                      * whenever the cache description is included. */
530 557
 
531 558
                     $tmp = Okapi::fix_oc_html($row['desc'], Okapi::OBJECT_TYPE_CACHE);
532 559
 
533
-                    if (in_array($cache_code, $outdated_listings))
534
-                    {
560
+                    if (in_array($cache_code, $outdated_listings)) {
535 561
                         Okapi::gettext_domain_init(array_merge(array($row['language']), $langpref));
536 562
                         $tmp = (
537 563
                             "<p style='color:#c00000'><strong>".
@@ -544,8 +570,7 @@  discard block
 block discarded – undo
544 570
                         Okapi::gettext_domain_restore();
545 571
                     }
546 572
 
547
-                    if ($attribution_append != 'none')
548
-                    {
573
+                    if ($attribution_append != 'none') {
549 574
                         $tmp .= "\n<p><em>".
550 575
                             self::get_cache_attribution_note(
551 576
                                 $row['cache_id'], strtolower($row['language']), $langpref,
@@ -555,19 +580,16 @@  discard block
 block discarded – undo
555 580
                     }
556 581
                     $results[$cache_code]['descriptions'][strtolower($row['language'])] = $tmp;
557 582
                 }
558
-                if ($row['short_desc'])
559
-                {
583
+                if ($row['short_desc']) {
560 584
                     $results[$cache_code]['short_descriptions'][strtolower($row['language'])] = $row['short_desc'];
561 585
                 }
562
-                if ($row['hint'])
563
-                {
586
+                if ($row['hint']) {
564 587
                     $results[$cache_code]['hints'][strtolower($row['language'])] = $row['hint'];
565 588
                     $results[$cache_code]['hints2'][strtolower($row['language'])]
566 589
                         = htmlspecialchars_decode(mb_ereg_replace("<br />", "" , $row['hint']), ENT_COMPAT);
567 590
                 }
568 591
             }
569
-            foreach ($results as &$result_ref)
570
-            {
592
+            foreach ($results as &$result_ref) {
571 593
                 $result_ref['short_description'] = Okapi::pick_best_language($result_ref['short_descriptions'], $langpref);
572 594
                 $result_ref['description'] = Okapi::pick_best_language($result_ref['descriptions'], $langpref);
573 595
                 $result_ref['hint'] = Okapi::pick_best_language($result_ref['hints'], $langpref);
@@ -579,27 +601,30 @@  discard block
 block discarded – undo
579 601
             foreach (array(
580 602
                 'short_description', 'short_descriptions', 'description', 'descriptions',
581 603
                 'hint', 'hints', 'hint2', 'hints2'
582
-            ) as $field)
583
-                if (!in_array($field, $fields))
604
+            ) as $field) {
605
+                            if (!in_array($field, $fields))
584 606
                     foreach ($results as &$result_ref)
585 607
                         unset($result_ref[$field]);
608
+            }
586 609
         }
587 610
 
588 611
         # Images.
589 612
 
590
-        if (in_array('images', $fields) || in_array('preview_image', $fields))
591
-        {
592
-            if (in_array('images', $fields))
593
-                foreach ($results as &$result_ref)
613
+        if (in_array('images', $fields) || in_array('preview_image', $fields)) {
614
+            if (in_array('images', $fields)) {
615
+                            foreach ($results as &$result_ref)
594 616
                     $result_ref['images'] = array();
595
-            if (in_array('preview_image', $fields))
596
-                foreach ($results as &$result_ref)
617
+            }
618
+            if (in_array('preview_image', $fields)) {
619
+                            foreach ($results as &$result_ref)
597 620
                     $result_ref['preview_image'] = null;
621
+            }
598 622
 
599
-            if (Db::field_exists('pictures', 'mappreview'))
600
-                $preview_field = "mappreview";
601
-            else
602
-                $preview_field = "0";
623
+            if (Db::field_exists('pictures', 'mappreview')) {
624
+                            $preview_field = "mappreview";
625
+            } else {
626
+                            $preview_field = "0";
627
+            }
603 628
             $rs = Db::query("
604 629
                 select object_id, uuid, url, title, spoiler, ".$preview_field." as preview
605 630
                 from pictures
@@ -613,11 +638,9 @@  discard block
 block discarded – undo
613 638
 
614 639
             unset($sql);
615 640
             $prev_cache_code = null;
616
-            while ($row = Db::fetch_assoc($rs))
617
-            {
641
+            while ($row = Db::fetch_assoc($rs)) {
618 642
                 $cache_code = $cacheid2wptcode[$row['object_id']];
619
-                if ($cache_code != $prev_cache_code)
620
-                {
643
+                if ($cache_code != $prev_cache_code) {
621 644
                     # Group images together. Images must have unique captions within one cache.
622 645
                     self::reset_unique_captions();
623 646
                     $prev_cache_code = $cache_code;
@@ -635,26 +658,27 @@  discard block
 block discarded – undo
635 658
                     'unique_caption' => self::get_unique_caption($row['title']),
636 659
                     'is_spoiler' => ($row['spoiler'] ? true : false),
637 660
                 );
638
-                if (in_array('images', $fields))
639
-                    $results[$cache_code]['images'][] = $image;
640
-                if ($row['preview'] != 0 && in_array('preview_image', $fields))
641
-                    $results[$cache_code]['preview_image'] = $image;
661
+                if (in_array('images', $fields)) {
662
+                                    $results[$cache_code]['images'][] = $image;
663
+                }
664
+                if ($row['preview'] != 0 && in_array('preview_image', $fields)) {
665
+                                    $results[$cache_code]['preview_image'] = $image;
666
+                }
642 667
             }
643 668
         }
644 669
 
645 670
         # A-codes and attrnames
646 671
 
647
-        if (in_array('attr_acodes', $fields) || in_array('attrnames', $fields))
648
-        {
672
+        if (in_array('attr_acodes', $fields) || in_array('attrnames', $fields)) {
649 673
             # Either case, we'll need acodes. If the user didn't want them,
650 674
             # remember to remove them later.
651 675
 
652
-            if (!in_array('attr_acodes', $fields))
653
-            {
676
+            if (!in_array('attr_acodes', $fields)) {
654 677
                 $fields_to_remove_later[] = 'attr_acodes';
655 678
             }
656
-            foreach ($results as &$result_ref)
657
-                $result_ref['attr_acodes'] = array();
679
+            foreach ($results as &$result_ref) {
680
+                            $result_ref['attr_acodes'] = array();
681
+            }
658 682
 
659 683
             # Load internal_attr_id => acode mapping.
660 684
 
@@ -666,12 +690,10 @@  discard block
 block discarded – undo
666 690
                 from caches_attributes
667 691
                 where cache_id in ('".implode("','", array_map('\okapi\Db::escape_string', array_keys($cacheid2wptcode)))."')
668 692
             ");
669
-            while ($row = Db::fetch_assoc($rs))
670
-            {
693
+            while ($row = Db::fetch_assoc($rs)) {
671 694
                 $cache_code = $cacheid2wptcode[$row['cache_id']];
672 695
                 $attr_internal_id = $row['attrib_id'];
673
-                if (!isset($internal2acode[$attr_internal_id]))
674
-                {
696
+                if (!isset($internal2acode[$attr_internal_id])) {
675 697
                     # Unknown attribute. Ignore.
676 698
                     continue;
677 699
                 }
@@ -681,24 +703,23 @@  discard block
 block discarded – undo
681 703
             # Now, each cache object has a list of its acodes. We can get
682 704
             # the attrnames now.
683 705
 
684
-            if (in_array('attrnames', $fields))
685
-            {
706
+            if (in_array('attrnames', $fields)) {
686 707
                 $acode2bestname = AttrHelper::get_acode_to_name_mapping($langpref);
687
-                foreach ($results as &$result_ref)
688
-                {
708
+                foreach ($results as &$result_ref) {
689 709
                     $result_ref['attrnames'] = array();
690
-                    foreach ($result_ref['attr_acodes'] as $acode)
691
-                        $result_ref['attrnames'][] = $acode2bestname[$acode];
710
+                    foreach ($result_ref['attr_acodes'] as $acode) {
711
+                                            $result_ref['attrnames'][] = $acode2bestname[$acode];
712
+                    }
692 713
                 }
693 714
             }
694 715
         }
695 716
 
696 717
         # Latest log entries.
697 718
 
698
-        if (in_array('latest_logs', $fields))
699
-        {
700
-            foreach ($results as &$result_ref)
701
-                $result_ref['latest_logs'] = array();
719
+        if (in_array('latest_logs', $fields)) {
720
+            foreach ($results as &$result_ref) {
721
+                            $result_ref['latest_logs'] = array();
722
+            }
702 723
 
703 724
             # Get all log IDs in proper order, then filter out the latest
704 725
             # ones. This should be the fastest technique ...
@@ -728,26 +749,21 @@  discard block
 block discarded – undo
728 749
 
729 750
             $loguuids = array();
730 751
             $log2cache_map = array();
731
-            if ($lpc !== null)
732
-            {
752
+            if ($lpc !== null) {
733 753
                 # User wants some of the latest logs.
734 754
                 $tmp = array();
735
-                while ($row = Db::fetch_assoc($rs))
736
-                    $tmp[$row['cache_id']][] = $row;
737
-                foreach ($tmp as $cache_key => &$rowslist_ref)
738
-                {
739
-                    for ($i = 0; $i < min(count($rowslist_ref), $lpc); $i++)
740
-                    {
755
+                while ($row = Db::fetch_assoc($rs)) {
756
+                                    $tmp[$row['cache_id']][] = $row;
757
+                }
758
+                foreach ($tmp as $cache_key => &$rowslist_ref) {
759
+                    for ($i = 0; $i < min(count($rowslist_ref), $lpc); $i++) {
741 760
                         $loguuids[] = $rowslist_ref[$i]['uuid'];
742 761
                         $log2cache_map[$rowslist_ref[$i]['uuid']] = $cacheid2wptcode[$rowslist_ref[$i]['cache_id']];
743 762
                     }
744 763
                 }
745
-            }
746
-            else
747
-            {
764
+            } else {
748 765
                 # User wants ALL logs.
749
-                while ($row = Db::fetch_assoc($rs))
750
-                {
766
+                while ($row = Db::fetch_assoc($rs)) {
751 767
                     $loguuids[] = $row['uuid'];
752 768
                     $log2cache_map[$row['uuid']] = $cacheid2wptcode[$row['cache_id']];
753 769
                 }
@@ -758,10 +774,8 @@  discard block
 block discarded – undo
758 774
             # We need to retrieve logs/entry for each of the $logids. We do this in groups
759 775
             # (there is a limit for log uuids passed to logs/entries method).
760 776
 
761
-            try
762
-            {
763
-                foreach (Okapi::make_groups($loguuids, 500) as $subset)
764
-                {
777
+            try {
778
+                foreach (Okapi::make_groups($loguuids, 500) as $subset) {
765 779
                     $entries = OkapiServiceRunner::call(
766 780
                         "services/logs/entries",
767 781
                         new OkapiInternalRequest(
@@ -771,21 +785,16 @@  discard block
 block discarded – undo
771 785
                             )
772 786
                         )
773 787
                     );
774
-                    foreach ($subset as $log_uuid)
775
-                    {
776
-                        if ($entries[$log_uuid])
777
-                            $results[$log2cache_map[$log_uuid]]['latest_logs'][] = $entries[$log_uuid];
788
+                    foreach ($subset as $log_uuid) {
789
+                        if ($entries[$log_uuid]) {
790
+                                                    $results[$log2cache_map[$log_uuid]]['latest_logs'][] = $entries[$log_uuid];
791
+                        }
778 792
                     }
779 793
                 }
780
-            }
781
-            catch (Exception $e)
782
-            {
783
-                if (($e instanceof InvalidParam) && ($e->paramName == 'fields'))
784
-                {
794
+            } catch (Exception $e) {
795
+                if (($e instanceof InvalidParam) && ($e->paramName == 'fields')) {
785 796
                     throw new InvalidParam('log_fields', $e->whats_wrong_about_it);
786
-                }
787
-                else
788
-                {
797
+                } else {
789 798
                     /* Something is wrong with OUR code. */
790 799
                     throw new Exception($e);
791 800
                 }
@@ -794,14 +803,14 @@  discard block
 block discarded – undo
794 803
 
795 804
         # My notes
796 805
 
797
-        if (in_array('my_notes', $fields))
798
-        {
799
-            if ($request->token == null)
800
-                throw new BadRequest("Level 3 Authentication is required to access 'my_notes' field.");
801
-            foreach ($results as &$result_ref)
802
-                $result_ref['my_notes'] = null;
803
-            if (Settings::get('OC_BRANCH') == 'oc.pl')
804
-            {
806
+        if (in_array('my_notes', $fields)) {
807
+            if ($request->token == null) {
808
+                            throw new BadRequest("Level 3 Authentication is required to access 'my_notes' field.");
809
+            }
810
+            foreach ($results as &$result_ref) {
811
+                            $result_ref['my_notes'] = null;
812
+            }
813
+            if (Settings::get('OC_BRANCH') == 'oc.pl') {
805 814
                 # OCPL uses cache_notes table to store notes.
806 815
 
807 816
                 $rs = Db::query("
@@ -812,9 +821,7 @@  discard block
 block discarded – undo
812 821
                         and user_id = '".Db::escape_string($request->token->user_id)."'
813 822
                     group by cache_id
814 823
                 ");
815
-            }
816
-            else
817
-            {
824
+            } else {
818 825
                 # OCDE uses coordinates table (with type == 2) to store notes (this is somewhat weird).
819 826
 
820 827
                 $rs = Db::query("
@@ -827,15 +834,13 @@  discard block
 block discarded – undo
827 834
                     group by cache_id
828 835
                 ");
829 836
             }
830
-            while ($row = Db::fetch_assoc($rs))
831
-            {
837
+            while ($row = Db::fetch_assoc($rs)) {
832 838
                 # This one is plain-text. We may add my_notes_html for those who want it in HTML.
833 839
                 $results[$cacheid2wptcode[$row['cache_id']]]['my_notes'] = strip_tags($row['desc']);
834 840
             }
835 841
         }
836 842
 
837
-        if (in_array('trackables', $fields))
838
-        {
843
+        if (in_array('trackables', $fields)) {
839 844
             # Currently we support Geokrety only. But this interface should remain
840 845
             # compatible. In future, other trackables might be returned the same way.
841 846
 
@@ -852,15 +857,15 @@  discard block
 block discarded – undo
852 857
                     and gkiw.wp in ('".implode("','", array_map('\okapi\Db::escape_string', $cache_codes))."')
853 858
             ");
854 859
             $trs = array();
855
-            while ($row = Db::fetch_assoc($rs))
856
-                $trs[$row['cache_code']][] = $row;
857
-            foreach ($results as $cache_code => &$result_ref)
858
-            {
860
+            while ($row = Db::fetch_assoc($rs)) {
861
+                            $trs[$row['cache_code']][] = $row;
862
+            }
863
+            foreach ($results as $cache_code => &$result_ref) {
859 864
                 $result_ref['trackables'] = array();
860
-                if (!isset($trs[$cache_code]))
861
-                    continue;
862
-                foreach ($trs[$cache_code] as $t)
863
-                {
865
+                if (!isset($trs[$cache_code])) {
866
+                                    continue;
867
+                }
868
+                foreach ($trs[$cache_code] as $t) {
864 869
                     $result_ref['trackables'][] = array(
865 870
                         'code' => 'GK'.str_pad(strtoupper(dechex($t['gk_id'])), 4, "0", STR_PAD_LEFT),
866 871
                         'name' => $t['name'],
@@ -870,16 +875,13 @@  discard block
 block discarded – undo
870 875
             }
871 876
             unset($trs);
872 877
         }
873
-        if (in_array('trackables_count', $fields))
874
-        {
875
-            if (in_array('trackables', $fields))
876
-            {
878
+        if (in_array('trackables_count', $fields)) {
879
+            if (in_array('trackables', $fields)) {
877 880
                 # We already got all trackables data, no need to query database again.
878
-                foreach ($results as $cache_code => &$result_ref)
879
-                    $result_ref['trackables_count'] = count($result_ref['trackables']);
880
-            }
881
-            else
882
-            {
881
+                foreach ($results as $cache_code => &$result_ref) {
882
+                                    $result_ref['trackables_count'] = count($result_ref['trackables']);
883
+                }
884
+            } else {
883 885
                 $rs = Db::query("
884 886
                     select wp as cache_code, count(*) as count
885 887
                     from gk_item_waypoint
@@ -887,14 +889,15 @@  discard block
 block discarded – undo
887 889
                     group by wp
888 890
                 ");
889 891
                 $tr_counts = new ArrayObject();
890
-                while ($row = Db::fetch_assoc($rs))
891
-                    $tr_counts[$row['cache_code']] = $row['count'];
892
-                foreach ($results as $cache_code => &$result_ref)
893
-                {
894
-                    if (isset($tr_counts[$cache_code]))
895
-                        $result_ref['trackables_count'] = $tr_counts[$cache_code] + 0;
896
-                    else
897
-                        $result_ref['trackables_count'] = 0;
892
+                while ($row = Db::fetch_assoc($rs)) {
893
+                                    $tr_counts[$row['cache_code']] = $row['count'];
894
+                }
895
+                foreach ($results as $cache_code => &$result_ref) {
896
+                    if (isset($tr_counts[$cache_code])) {
897
+                                            $result_ref['trackables_count'] = $tr_counts[$cache_code] + 0;
898
+                    } else {
899
+                                            $result_ref['trackables_count'] = 0;
900
+                    }
898 901
                 }
899 902
                 unset($tr_counts);
900 903
             }
@@ -902,11 +905,9 @@  discard block
 block discarded – undo
902 905
 
903 906
         # Alternate/Additional waypoints.
904 907
 
905
-        if (in_array('alt_wpts', $fields))
906
-        {
908
+        if (in_array('alt_wpts', $fields)) {
907 909
             $internal_wpt_type_id2names = array();
908
-            if (Settings::get('OC_BRANCH') == 'oc.de')
909
-            {
910
+            if (Settings::get('OC_BRANCH') == 'oc.de') {
910 911
                 $rs = Db::query("
911 912
                     select
912 913
                         ct.id,
@@ -916,30 +917,28 @@  discard block
 block discarded – undo
916 917
                         coordinates_type ct
917 918
                         left join sys_trans_text stt on stt.trans_id = ct.trans_id
918 919
                 ");
919
-                while ($row = Db::fetch_assoc($rs))
920
-                    $internal_wpt_type_id2names[$row['id']][$row['language']] = $row['text'];
920
+                while ($row = Db::fetch_assoc($rs)) {
921
+                                    $internal_wpt_type_id2names[$row['id']][$row['language']] = $row['text'];
922
+                }
921 923
                 Db::free_result($rs);
922
-            }
923
-            else
924
-            {
924
+            } else {
925 925
                 $rs = Db::query("
926 926
                     select id, pl, en
927 927
                     from waypoint_type
928 928
                     where id > 0
929 929
                 ");
930
-                while ($row = Db::fetch_assoc($rs))
931
-                {
930
+                while ($row = Db::fetch_assoc($rs)) {
932 931
                     $internal_wpt_type_id2names[$row['id']]['pl'] = $row['pl'];
933 932
                     $internal_wpt_type_id2names[$row['id']]['en'] = $row['en'];
934 933
                 }
935 934
             }
936 935
 
937
-            foreach ($results as &$result_ref)
938
-                $result_ref['alt_wpts'] = array();
936
+            foreach ($results as &$result_ref) {
937
+                            $result_ref['alt_wpts'] = array();
938
+            }
939 939
             $cache_codes_escaped_and_imploded = "'".implode("','", array_map('\okapi\Db::escape_string', array_keys($cacheid2wptcode)))."'";
940 940
 
941
-            if (Settings::get('OC_BRANCH') == 'oc.pl')
942
-            {
941
+            if (Settings::get('OC_BRANCH') == 'oc.pl') {
943 942
                 # OCPL uses 'waypoints' table to store additional waypoints and defines
944 943
                 # waypoint types in 'waypoint_type' table.
945 944
                 # OCPL also have a special 'status' field to denote a hidden waypoint
@@ -970,9 +969,7 @@  discard block
 block discarded – undo
970 969
                         and status = 1
971 970
                     order by cache_id, stage, `desc`
972 971
                 ");
973
-            }
974
-            else
975
-            {
972
+            } else {
976 973
                 # OCDE uses 'coordinates' table (with type=1) to store additional waypoints
977 974
                 # and defines waypoint types in 'coordinates_type' table.
978 975
                 # All additional waypoints are public.
@@ -1007,15 +1004,12 @@  discard block
 block discarded – undo
1007 1004
                 ");
1008 1005
             }
1009 1006
 
1010
-            foreach ($cacheid2waypoints as $cache_id => $waypoints)
1011
-            {
1007
+            foreach ($cacheid2waypoints as $cache_id => $waypoints) {
1012 1008
                 $cache_code = $cacheid2wptcode[$cache_id];
1013 1009
                 $wpt_format = $cache_code."-%0".strlen(count($waypoints))."d";
1014 1010
                 $index = 0;
1015
-                foreach ($waypoints as $row)
1016
-                {
1017
-                    if (!isset($internal_wpt_type_id2names[$row['internal_type_id']]))
1018
-                    {
1011
+                foreach ($waypoints as $row) {
1012
+                    if (!isset($internal_wpt_type_id2names[$row['internal_type_id']])) {
1019 1013
                         # Sanity check. Waypoints of undefined type won't be accessible via OKAPI.
1020 1014
                         # See issue 219.
1021 1015
                         continue;
@@ -1034,11 +1028,9 @@  discard block
 block discarded – undo
1034 1028
 
1035 1029
             # Issue #298 - User coordinates implemented in oc.pl
1036 1030
             # Issue #305 - User coordinates implemented in oc.de
1037
-            if ($request->token != null)
1038
-            {
1031
+            if ($request->token != null) {
1039 1032
                 # Query DB for user provided coordinates
1040
-                if (Settings::get('OC_BRANCH') == 'oc.pl')
1041
-                {
1033
+                if (Settings::get('OC_BRANCH') == 'oc.pl') {
1042 1034
                     $cacheid2user_coords = Db::select_group_by('cache_id', "
1043 1035
                         select
1044 1036
                             cache_id, longitude, latitude
@@ -1061,11 +1053,9 @@  discard block
 block discarded – undo
1061 1053
                             and latitude != 0
1062 1054
                     ");
1063 1055
                 }
1064
-                foreach ($cacheid2user_coords as $cache_id => $waypoints)
1065
-                {
1056
+                foreach ($cacheid2user_coords as $cache_id => $waypoints) {
1066 1057
                     $cache_code = $cacheid2wptcode[$cache_id];
1067
-                    foreach ($waypoints as $row)
1068
-                    {
1058
+                    foreach ($waypoints as $row) {
1069 1059
                         # there should be only one user waypoint per cache...
1070 1060
                         $results[$cache_code]['alt_wpts'][] = array(
1071 1061
                             'name' => $cache_code.'-USER-COORDS',
@@ -1085,13 +1075,11 @@  discard block
 block discarded – undo
1085 1075
 
1086 1076
         # Country and/or state.
1087 1077
 
1088
-        if (in_array('country', $fields) || in_array('state', $fields))
1089
-        {
1078
+        if (in_array('country', $fields) || in_array('state', $fields)) {
1090 1079
             $countries = array();
1091 1080
             $states = array();
1092 1081
 
1093
-            if (Settings::get('OC_BRANCH') == 'oc.de')
1094
-            {
1082
+            if (Settings::get('OC_BRANCH') == 'oc.de') {
1095 1083
                 # OCDE:
1096 1084
                 #  - cache_location entries are created by a cronjob *after* listing the
1097 1085
                 #      caches and may not yet exist.
@@ -1117,8 +1105,9 @@  discard block
 block discarded – undo
1117 1105
                         c.wp_oc in ('".implode("','", array_map('\okapi\Db::escape_string', $cache_codes))."')
1118 1106
                 ");
1119 1107
                 $country_codes2names = array();
1120
-                while ($row = Db::fetch_assoc($rs))
1121
-                    $country_codes2names[$row['country']][$row['language']] = $row['text'];
1108
+                while ($row = Db::fetch_assoc($rs)) {
1109
+                                    $country_codes2names[$row['country']][$row['language']] = $row['text'];
1110
+                }
1122 1111
                 Db::free_result($rs);
1123 1112
 
1124 1113
                 # get geocache countries and states
@@ -1133,18 +1122,16 @@  discard block
 block discarded – undo
1133 1122
                     where
1134 1123
                         c.wp_oc in ('".implode("','", array_map('\okapi\Db::escape_string', $cache_codes))."')
1135 1124
                 ");
1136
-                while ($row = Db::fetch_assoc($rs))
1137
-                {
1138
-                    if (!isset($country_codes2names[$row['country_code']]))
1139
-                        $countries[$row['cache_code']] = '';
1140
-                    else
1141
-                        $countries[$row['cache_code']] = Okapi::pick_best_language($country_codes2names[$row['country_code']], $langpref);
1125
+                while ($row = Db::fetch_assoc($rs)) {
1126
+                    if (!isset($country_codes2names[$row['country_code']])) {
1127
+                                            $countries[$row['cache_code']] = '';
1128
+                    } else {
1129
+                                            $countries[$row['cache_code']] = Okapi::pick_best_language($country_codes2names[$row['country_code']], $langpref);
1130
+                    }
1142 1131
                     $states[$row['cache_code']] = $row['state'];
1143 1132
                 }
1144 1133
                 Db::free_result($rs);
1145
-            }
1146
-            else
1147
-            {
1134
+            } else {
1148 1135
                 # OCPL:
1149 1136
                 #  - cache_location data is entered by the user.
1150 1137
                 #  - The state is in adm3 field.
@@ -1162,23 +1149,22 @@  discard block
 block discarded – undo
1162 1149
                         c.wp_oc in ('".implode("','", array_map('\okapi\Db::escape_string', $cache_codes))."')
1163 1150
                         and c.cache_id = cl.cache_id
1164 1151
                 ");
1165
-                while ($row = Db::fetch_assoc($rs))
1166
-                {
1152
+                while ($row = Db::fetch_assoc($rs)) {
1167 1153
                     $countries[$row['cache_code']] = $row['country'];
1168 1154
                     $states[$row['cache_code']] = $row['state'];
1169 1155
                 }
1170 1156
                 Db::free_result($rs);
1171 1157
             }
1172 1158
 
1173
-            if (in_array('country', $fields))
1174
-            {
1175
-                foreach ($results as $cache_code => &$row_ref)
1176
-                    $row_ref['country'] = isset($countries[$cache_code]) ? $countries[$cache_code] : null;
1159
+            if (in_array('country', $fields)) {
1160
+                foreach ($results as $cache_code => &$row_ref) {
1161
+                                    $row_ref['country'] = isset($countries[$cache_code]) ? $countries[$cache_code] : null;
1162
+                }
1177 1163
             }
1178
-            if (in_array('state', $fields))
1179
-            {
1180
-                foreach ($results as $cache_code => &$row_ref)
1181
-                    $row_ref['state'] = isset($states[$cache_code]) ? $states[$cache_code] : null;
1164
+            if (in_array('state', $fields)) {
1165
+                foreach ($results as $cache_code => &$row_ref) {
1166
+                                    $row_ref['state'] = isset($states[$cache_code]) ? $states[$cache_code] : null;
1167
+                }
1182 1168
             }
1183 1169
             unset($countries);
1184 1170
             unset($states);
@@ -1186,27 +1172,25 @@  discard block
 block discarded – undo
1186 1172
 
1187 1173
         # Attribution note
1188 1174
 
1189
-        if (in_array('attribution_note', $fields))
1190
-        {
1175
+        if (in_array('attribution_note', $fields)) {
1191 1176
             /* Note, that the "owner" and "internal_id" fields are automatically included,
1192 1177
              * whenever the attribution_note is included. */
1193 1178
 
1194
-            foreach ($results as $cache_code => &$result_ref)
1195
-                $result_ref['attribution_note'] =
1179
+            foreach ($results as $cache_code => &$result_ref) {
1180
+                            $result_ref['attribution_note'] =
1196 1181
                     self::get_cache_attribution_note(
1197 1182
                         $result_ref['internal_id'], $langpref[0], $langpref,
1198 1183
                         $results[$cache_code]['owner'], 'full'
1199 1184
                     );
1185
+            }
1200 1186
         }
1201 1187
 
1202 1188
         # Protection areas
1203 1189
 
1204
-        if (in_array('protection_areas', $fields))
1205
-        {
1190
+        if (in_array('protection_areas', $fields)) {
1206 1191
             $cache_ids_escaped_and_imploded = "'".implode("','", array_map('\okapi\Db::escape_string', array_keys($cacheid2wptcode)))."'";
1207 1192
 
1208
-            if (Settings::get('OC_BRANCH') == 'oc.de')
1209
-            {
1193
+            if (Settings::get('OC_BRANCH') == 'oc.de') {
1210 1194
                 $rs = Db::query("
1211 1195
                     select
1212 1196
                         c.wp_oc as cache_code,
@@ -1222,9 +1206,7 @@  discard block
 block discarded – undo
1222 1206
                     group by npa_areas.type_id, npa_areas.name
1223 1207
                     order by npa_types.ordinal
1224 1208
                 ");
1225
-            }
1226
-            else if (in_array(Okapi::get_oc_schema_code(), array("OCPL", "OCNL")))
1227
-            {
1209
+            } else if (in_array(Okapi::get_oc_schema_code(), array("OCPL", "OCNL"))) {
1228 1210
                 # Current OCPL table definitions use collation 'latin1' for parkipl
1229 1211
                 # and 'utf8' for np_areas. Union needs identical collations.
1230 1212
                 # To be sure, we convert both to utf8.
@@ -1255,21 +1237,18 @@  discard block
 block discarded – undo
1255 1237
                         c.cache_id in (".$cache_ids_escaped_and_imploded.")
1256 1238
                         and cache_npa_areas.npa_id != 0
1257 1239
                 ");
1258
-            }
1259
-            else
1260
-            {
1240
+            } else {
1261 1241
                 # OC.US and .UK do not have a 'parkipl' table.
1262 1242
                 # OC.US has a 'us_parks' table instead.
1263 1243
                 # Natura 2000 is Europe-only.
1264 1244
                 $rs = null;
1265 1245
             }
1266 1246
 
1267
-            foreach ($results as &$result_ref)
1268
-                $result_ref['protection_areas'] = array();
1269
-            if ($rs)
1270
-            {
1271
-                while ($row = Db::fetch_assoc($rs))
1272
-                {
1247
+            foreach ($results as &$result_ref) {
1248
+                            $result_ref['protection_areas'] = array();
1249
+            }
1250
+            if ($rs) {
1251
+                while ($row = Db::fetch_assoc($rs)) {
1273 1252
                     $results[$row['cache_code']]['protection_areas'][] = array(
1274 1253
                         'type' => $row['type'],
1275 1254
                         'name' => $row['name'],
@@ -1280,18 +1259,19 @@  discard block
 block discarded – undo
1280 1259
         }
1281 1260
 
1282 1261
         # Check which cache codes were not found and mark them with null.
1283
-        foreach ($cache_codes as $cache_code)
1284
-            if (!isset($results[$cache_code]))
1262
+        foreach ($cache_codes as $cache_code) {
1263
+                    if (!isset($results[$cache_code]))
1285 1264
                 $results[$cache_code] = null;
1265
+        }
1286 1266
 
1287
-        if (count($fields_to_remove_later) > 0)
1288
-        {
1267
+        if (count($fields_to_remove_later) > 0) {
1289 1268
             # Some of the fields in $results were added only temporarily
1290 1269
             # (the Consumer did not ask for them). We will remove these fields now.
1291 1270
 
1292
-            foreach ($results as &$result_ref)
1293
-                foreach ($fields_to_remove_later as $field)
1271
+            foreach ($results as &$result_ref) {
1272
+                            foreach ($fields_to_remove_later as $field)
1294 1273
                     unset($result_ref[$field]);
1274
+            }
1295 1275
         }
1296 1276
 
1297 1277
         # Order the results in the same order as the input codes were given.
@@ -1301,8 +1281,9 @@  discard block
 block discarded – undo
1301 1281
         # so we just have to rewrite it (sequentially).
1302 1282
 
1303 1283
         $ordered_results = new ArrayObject();
1304
-        foreach ($cache_codes as $cache_code)
1305
-            $ordered_results[$cache_code] = $results[$cache_code];
1284
+        foreach ($cache_codes as $cache_code) {
1285
+                    $ordered_results[$cache_code] = $results[$cache_code];
1286
+        }
1306 1287
 
1307 1288
         /* Handle OCPL's "access logs" feature. */
1308 1289
 
@@ -1407,21 +1388,17 @@  discard block
 block discarded – undo
1407 1388
         $cache_url = $site_url."viewcache.php?cacheid=$cache_id";
1408 1389
 
1409 1390
         Okapi::gettext_domain_init(array_merge(array($lang), $langpref));
1410
-        if (Settings::get('OC_BRANCH') == 'oc.pl')
1411
-        {
1391
+        if (Settings::get('OC_BRANCH') == 'oc.pl') {
1412 1392
             # This does not vary on $type (yet).
1413 1393
 
1414 1394
             $note = sprintf(
1415 1395
                 _("This <a href='%s'>geocache</a> description comes from the <a href='%s'>%s</a> site."),
1416 1396
                 $cache_url, $site_url, $site_name
1417 1397
             );
1418
-        }
1419
-        else
1420
-        {
1398
+        } else {
1421 1399
             # OC.de wants the tld in lowercase here
1422 1400
             $site_name = ucfirst(strtolower($site_name));
1423
-            if ($type == 'full')
1424
-            {
1401
+            if ($type == 'full') {
1425 1402
                 $note = sprintf(
1426 1403
                     _(
1427 1404
                         "&copy; <a href='%s'>%s</a>, <a href='%s'>%s</a>, ".
@@ -1430,9 +1407,7 @@  discard block
 block discarded – undo
1430 1407
                     ),
1431 1408
                     $owner['profile_url'], $owner['username'], $cache_url, $site_name, strftime('%x')
1432 1409
                 );
1433
-            }
1434
-            elseif ($type == 'static')
1435
-            {
1410
+            } elseif ($type == 'static') {
1436 1411
                 $note = sprintf(
1437 1412
                     _(
1438 1413
                         "&copy; <a href='%s'>%s</a>, <a href='%s'>%s</a>, ".
Please login to merge, or discard this patch.
htdocs/okapi/services/caches/formatters/gpx.php 4 patches
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -465,7 +465,7 @@
 block discarded – undo
465 465
                 $ggz_entry['ratings'] = array();
466 466
                 $ratings_ref = &$ggz_entry['ratings'];
467 467
                 if (isset($cache_ref['rating'])){
468
-                   $ratings_ref['awesomeness'] = $cache_ref['rating'];
468
+                    $ratings_ref['awesomeness'] = $cache_ref['rating'];
469 469
                 }
470 470
                 $ratings_ref['difficulty'] = $cache_ref['difficulty'];
471 471
                 if (!isset($cache_ref['size'])) {
Please login to merge, or discard this patch.
Unused Use Statements   +5 added lines, -7 removed lines patch added patch discarded remove patch
@@ -2,18 +2,16 @@
 block discarded – undo
2 2
 
3 3
 namespace okapi\services\caches\formatters\gpx;
4 4
 
5
+use okapi\BadRequest;
6
+use okapi\Db;
7
+use okapi\InvalidParam;
5 8
 use okapi\Okapi;
6
-use okapi\OkapiRequest;
7 9
 use okapi\OkapiHttpResponse;
10
+use okapi\OkapiInternalConsumer;
8 11
 use okapi\OkapiInternalRequest;
12
+use okapi\OkapiRequest;
9 13
 use okapi\OkapiServiceRunner;
10
-use okapi\BadRequest;
11 14
 use okapi\ParamMissing;
12
-use okapi\OkapiAccessToken;
13
-use okapi\InvalidParam;
14
-use okapi\services\caches\search\SearchAssistant;
15
-use okapi\OkapiInternalConsumer;
16
-use okapi\Db;
17 15
 use okapi\Settings;
18 16
 use okapi\services\attrs\AttrHelper;
19 17
 
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -164,7 +164,7 @@  discard block
 block discarded – undo
164 164
             else $protection_areas = 'none';
165 165
         }
166 166
         if (!in_array($protection_areas, array('none', 'desc:text')))
167
-            throw new InvalidParam('protection_areas',"'$protection_areas'");
167
+            throw new InvalidParam('protection_areas', "'$protection_areas'");
168 168
         $vars['protection_areas'] = $protection_areas;
169 169
 
170 170
         $tmp = $request->get_parameter('trackables');
@@ -290,7 +290,7 @@  discard block
 block discarded – undo
290 290
                     # database; OCPL stores attribute names in a different way and may use
291 291
                     # different names for equivalent attributes.
292 292
 
293
-                    $ocde_attrnames = Db::select_group_by('id',"
293
+                    $ocde_attrnames = Db::select_group_by('id', "
294 294
                         select id, name
295 295
                         from cache_attrib
296 296
                     ");
@@ -413,7 +413,7 @@  discard block
 block discarded – undo
413 413
                             $cache_ref['warning_prefix'] = _(
414 414
                                 "<b>Geocache coordinates have been changed.</b> Currently they ".
415 415
                                 "point to one of the alternate waypoints originally described as:"
416
-                            ) . " " . $alt_wpt['description'];
416
+                            )." ".$alt_wpt['description'];
417 417
                         }
418 418
                         # remove current alt waypoint
419 419
                         unset($cache_ref['alt_wpts'][$alt_wpt_key]);
@@ -464,7 +464,7 @@  discard block
 block discarded – undo
464 464
 
465 465
                 $ggz_entry['ratings'] = array();
466 466
                 $ratings_ref = &$ggz_entry['ratings'];
467
-                if (isset($cache_ref['rating'])){
467
+                if (isset($cache_ref['rating'])) {
468 468
                    $ratings_ref['awesomeness'] = $cache_ref['rating'];
469 469
                 }
470 470
                 $ratings_ref['difficulty'] = $cache_ref['difficulty'];
@@ -491,7 +491,7 @@  discard block
 block discarded – undo
491 491
                         $ggz_entry = &$alt_wpt_ref['ggz_entry'];
492 492
                         $ggz_entries[] = &$ggz_entry;
493 493
 
494
-                        $ggz_entry['code'] = $cache_ref['code'] . '-' . $idx;
494
+                        $ggz_entry['code'] = $cache_ref['code'].'-'.$idx;
495 495
                         $ggz_entry['name'] = $alt_wpt_ref['type_name'];
496 496
                         $ggz_entry['type'] = $alt_wpt_ref['sym'];
497 497
                         list($lat, $lon) = explode("|", $alt_wpt_ref['location']);
Please login to merge, or discard this 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/logs/entry.php 1 patch
Braces   +9 added lines, -4 removed lines patch added patch discarded remove patch
@@ -21,16 +21,21 @@
 block discarded – undo
21 21
     public static function call(OkapiRequest $request)
22 22
     {
23 23
         $log_uuid = $request->get_parameter('log_uuid');
24
-        if (!$log_uuid) throw new ParamMissing('log_uuid');
24
+        if (!$log_uuid) {
25
+            throw new ParamMissing('log_uuid');
26
+        }
25 27
         $fields = $request->get_parameter('fields');
26
-        if (!$fields) $fields = "date|user|type|comment";
28
+        if (!$fields) {
29
+            $fields = "date|user|type|comment";
30
+        }
27 31
 
28 32
         $results = OkapiServiceRunner::call('services/logs/entries', new OkapiInternalRequest(
29 33
             $request->consumer, $request->token, array('log_uuids' => $log_uuid,
30 34
             'fields' => $fields)));
31 35
         $result = $results[$log_uuid];
32
-        if ($result == null)
33
-            throw new InvalidParam('log_uuid', "This log entry does not exist.");
36
+        if ($result == null) {
37
+                    throw new InvalidParam('log_uuid', "This log entry does not exist.");
38
+        }
34 39
         return Okapi::formatted_response($request, $result);
35 40
     }
36 41
 }
Please login to merge, or discard this patch.
htdocs/okapi/services/logs/logs.php 1 patch
Braces   +24 added lines, -11 removed lines patch added patch discarded remove patch
@@ -24,19 +24,31 @@  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');
27
+        if (!$cache_code) {
28
+            throw new ParamMissing('cache_code');
29
+        }
28 30
         $fields = $request->get_parameter('fields');
29
-        if (!$fields) $fields = "uuid|date|user|type|comment";
31
+        if (!$fields) {
32
+            $fields = "uuid|date|user|type|comment";
33
+        }
30 34
 
31 35
         $offset = $request->get_parameter('offset');
32
-        if (!$offset) $offset = "0";
33
-        if ((((int)$offset) != $offset) || ((int)$offset) < 0)
34
-            throw new InvalidParam('offset', "Expecting non-negative integer.");
36
+        if (!$offset) {
37
+            $offset = "0";
38
+        }
39
+        if ((((int)$offset) != $offset) || ((int)$offset) < 0) {
40
+                    throw new InvalidParam('offset', "Expecting non-negative integer.");
41
+        }
35 42
         $limit = $request->get_parameter('limit');
36
-        if (!$limit) $limit = "none";
37
-        if ($limit == "none") $limit = "999999999";
38
-        if ((((int)$limit) != $limit) || ((int)$limit) < 0)
39
-            throw new InvalidParam('limit', "Expecting non-negative integer or 'none'.");
43
+        if (!$limit) {
44
+            $limit = "none";
45
+        }
46
+        if ($limit == "none") {
47
+            $limit = "999999999";
48
+        }
49
+        if ((((int)$limit) != $limit) || ((int)$limit) < 0) {
50
+                    throw new InvalidParam('limit', "Expecting non-negative integer or 'none'.");
51
+        }
40 52
 
41 53
         # Check if code exists and retrieve cache ID (this will throw
42 54
         # a proper exception on invalid code).
@@ -64,8 +76,9 @@  discard block
 block discarded – undo
64 76
         $internal_request->skip_limits = true;
65 77
         $logs = OkapiServiceRunner::call('services/logs/entries', $internal_request);
66 78
         $results = array();
67
-        foreach ($log_uuids as $log_uuid)
68
-            $results[] = $logs[$log_uuid];
79
+        foreach ($log_uuids as $log_uuid) {
80
+                    $results[] = $logs[$log_uuid];
81
+        }
69 82
 
70 83
         /* Handle OCPL's "access logs" feature. */
71 84
 
Please login to merge, or discard this patch.
htdocs/okapi/services/users/by_username.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -32,7 +32,7 @@
 block discarded – undo
32 32
         # Catch pipe chars here, because services/users/by_usernames would split up the name.
33 33
         # OC databases do not contain user names with pipe chars.
34 34
 
35
-        if (strstr($username,'|'))
35
+        if (strstr($username, '|'))
36 36
             throw new InvalidParam('username', "There is no user by this username.");
37 37
         $fields = $request->get_parameter('fields');
38 38
 
Please login to merge, or discard this patch.
Braces   +9 added lines, -5 removed lines patch added patch discarded remove patch
@@ -26,14 +26,17 @@  discard block
 block discarded – undo
26 26
     public static function call(OkapiRequest $request)
27 27
     {
28 28
         $username = $request->get_parameter('username');
29
-        if (!$username) throw new ParamMissing('username');
29
+        if (!$username) {
30
+            throw new ParamMissing('username');
31
+        }
30 32
 
31 33
         # Fix for issue 339:
32 34
         # Catch pipe chars here, because services/users/by_usernames would split up the name.
33 35
         # OC databases do not contain user names with pipe chars.
34 36
 
35
-        if (strstr($username,'|'))
36
-            throw new InvalidParam('username', "There is no user by this username.");
37
+        if (strstr($username,'|')) {
38
+                    throw new InvalidParam('username', "There is no user by this username.");
39
+        }
37 40
         $fields = $request->get_parameter('fields');
38 41
 
39 42
         # There's no need to validate the fields parameter.
@@ -42,8 +45,9 @@  discard block
 block discarded – undo
42 45
             $request->consumer, $request->token, array('usernames' => $username,
43 46
             'fields' => $fields)));
44 47
         $result = $results[$username];
45
-        if ($result == null)
46
-            throw new InvalidParam('username', "There is no user by this username.");
48
+        if ($result == null) {
49
+                    throw new InvalidParam('username', "There is no user by this username.");
50
+        }
47 51
         return Okapi::formatted_response($request, $result);
48 52
     }
49 53
 }
Please login to merge, or discard this patch.