Completed
Branch master (7d3f82)
by Thomas
09:15
created
htdocs/okapi/services/apiref/issue.php 1 patch
Braces   +7 added lines, -6 removed lines patch added patch discarded remove patch
@@ -26,10 +26,12 @@  discard block
 block discarded – undo
26 26
     public static function call(OkapiRequest $request)
27 27
     {
28 28
         $issue_id = $request->get_parameter('issue_id');
29
-        if (!$issue_id)
30
-            throw new ParamMissing('issue_id');
31
-        if ((!preg_match("/^[0-9]+$/", $issue_id)) || (strlen($issue_id) > 6))
32
-            throw new InvalidParam('issue_id');
29
+        if (!$issue_id) {
30
+                    throw new ParamMissing('issue_id');
31
+        }
32
+        if ((!preg_match("/^[0-9]+$/", $issue_id)) || (strlen($issue_id) > 6)) {
33
+                    throw new InvalidParam('issue_id');
34
+        }
33 35
 
34 36
         $cache_key = "apiref/issue#".$issue_id;
35 37
         $result = Cache::get($cache_key);
@@ -55,8 +57,7 @@  discard block
 block discarded – undo
55 57
                 $context = stream_context_create($opts);
56 58
                 $json = file_get_contents("https://api.github.com/repos/opencaching/okapi/issues/$issue_id",
57 59
                     false, $context);
58
-            }
59
-            catch (ErrorException $e)
60
+            } catch (ErrorException $e)
60 61
             {
61 62
                 throw new BadRequest("Sorry, we could not retrieve issue stats from the GitHub site. ".
62 63
                     "This is probably due to a temporary connection problem. Try again later or contact ".
Please login to merge, or discard this patch.
htdocs/okapi/services/apiref/method.php 1 patch
Braces   +45 added lines, -32 removed lines patch added patch discarded remove patch
@@ -128,15 +128,19 @@  discard block
 block discarded – undo
128 128
     public static function call(OkapiRequest $request)
129 129
     {
130 130
         $methodname = $request->get_parameter('name');
131
-        if (!$methodname)
132
-            throw new ParamMissing('name');
133
-        if (!preg_match("#^services/[0-9a-z_/]*$#", $methodname))
134
-            throw new InvalidParam('name');
135
-        if (!OkapiServiceRunner::exists($methodname))
136
-            throw new InvalidParam('name', "Method does not exist: '$methodname'.");
131
+        if (!$methodname) {
132
+                    throw new ParamMissing('name');
133
+        }
134
+        if (!preg_match("#^services/[0-9a-z_/]*$#", $methodname)) {
135
+                    throw new InvalidParam('name');
136
+        }
137
+        if (!OkapiServiceRunner::exists($methodname)) {
138
+                    throw new InvalidParam('name', "Method does not exist: '$methodname'.");
139
+        }
137 140
         $options = OkapiServiceRunner::options($methodname);
138
-        if (!isset($options['min_auth_level']))
139
-            throw new Exception("Method $methodname is missing a required 'min_auth_level' option!");
141
+        if (!isset($options['min_auth_level'])) {
142
+                    throw new Exception("Method $methodname is missing a required 'min_auth_level' option!");
143
+        }
140 144
         $docs = simplexml_load_string(OkapiServiceRunner::docs($methodname));
141 145
         $exploded = explode("/", $methodname);
142 146
         $result = array(
@@ -149,23 +153,30 @@  discard block
 block discarded – undo
149 153
                 'oauth_token' => $options['min_auth_level'] >= 3,
150 154
             )
151 155
         );
152
-        if (!$docs->brief)
153
-            throw new Exception("Missing <brief> element in the $methodname.xml file.");
154
-        if ($docs->brief != self::get_inner_xml($docs->brief))
155
-            throw new Exception("The <brief> element may not contain HTML markup ($methodname.xml).");
156
-        if (strlen($docs->brief) > 80)
157
-            throw new Exception("The <brief> description may not be longer than 80 characters ($methodname.xml).");
158
-        if (strpos($docs->brief, "\n") !== false)
159
-            throw new Exception("The <brief> element may not contain new-lines ($methodname.xml).");
160
-        if (substr(trim($docs->brief), -1) == '.')
161
-            throw new Exception("The <brief> element should not end with a dot ($methodname.xml).");
156
+        if (!$docs->brief) {
157
+                    throw new Exception("Missing <brief> element in the $methodname.xml file.");
158
+        }
159
+        if ($docs->brief != self::get_inner_xml($docs->brief)) {
160
+                    throw new Exception("The <brief> element may not contain HTML markup ($methodname.xml).");
161
+        }
162
+        if (strlen($docs->brief) > 80) {
163
+                    throw new Exception("The <brief> description may not be longer than 80 characters ($methodname.xml).");
164
+        }
165
+        if (strpos($docs->brief, "\n") !== false) {
166
+                    throw new Exception("The <brief> element may not contain new-lines ($methodname.xml).");
167
+        }
168
+        if (substr(trim($docs->brief), -1) == '.') {
169
+                    throw new Exception("The <brief> element should not end with a dot ($methodname.xml).");
170
+        }
162 171
         $result['brief_description'] = self::get_inner_xml($docs->brief);
163
-        if ($docs->{'issue-id'})
164
-            $result['issue_id'] = (string)$docs->{'issue-id'};
165
-        else
166
-            $result['issue_id'] = null;
167
-        if (!$docs->desc)
168
-            throw new Exception("Missing <desc> element in the $methodname.xml file.");
172
+        if ($docs->{'issue-id'}) {
173
+                    $result['issue_id'] = (string)$docs->{'issue-id'};
174
+        } else {
175
+                    $result['issue_id'] = null;
176
+        }
177
+        if (!$docs->desc) {
178
+                    throw new Exception("Missing <desc> element in the $methodname.xml file.");
179
+        }
169 180
         $result['description'] = self::get_inner_xml($docs->desc);
170 181
         $result['arguments'] = array();
171 182
         foreach ($docs->req as $arg) { $result['arguments'][] = self::arg_desc($arg); }
@@ -180,14 +191,14 @@  discard block
 block discarded – undo
180 191
             $exclude_list = isset($attrs['except']) ? explode("|", $attrs['except']) : array();
181 192
             foreach ($referenced_method_info['arguments'] as $arg)
182 193
             {
183
-                if ($arg['class'] == 'common-formatting')
184
-                    continue;
194
+                if ($arg['class'] == 'common-formatting') {
195
+                                    continue;
196
+                }
185 197
                 if (($include_list === null) && (count($exclude_list) == 0))
186 198
                 {
187 199
                     $arg['description'] = "<i>Inherited from <a href='".$referenced_method_info['ref_url'].
188 200
                         "#arg_". $arg['name'] . "'>".$referenced_method_info['name']."</a> method.</i>";
189
-                }
190
-                elseif (
201
+                } elseif (
191 202
                     (($include_list === null) || in_array($arg['name'], $include_list))
192 203
                     && (!in_array($arg['name'], $exclude_list))
193 204
                 ) {
@@ -217,12 +228,14 @@  discard block
 block discarded – undo
217 228
                 'description' => "<i>Standard <a href='".Settings::get('SITE_URL')."okapi/introduction.html#common-formatting'>common formatting</a> argument.</i>"
218 229
             );
219 230
         }
220
-        foreach ($result['arguments'] as &$arg_ref)
221
-            if ($arg_ref['is_deprecated'])
231
+        foreach ($result['arguments'] as &$arg_ref) {
232
+                    if ($arg_ref['is_deprecated'])
222 233
                 $arg_ref['class'] .= " deprecated";
223
-        if (!$docs->returns)
224
-            throw new Exception("Missing <returns> element in the $methodname.xml file. ".
234
+        }
235
+        if (!$docs->returns) {
236
+                    throw new Exception("Missing <returns> element in the $methodname.xml file. ".
225 237
                 "If your method does not return anything, you should document in nonetheless.");
238
+        }
226 239
         $result['returns'] = self::get_inner_xml($docs->returns);
227 240
         return Okapi::formatted_response($request, $result);
228 241
     }
Please login to merge, or discard this patch.
htdocs/okapi/services/logs/submit.php 1 patch
Braces   +46 added lines, -55 removed lines patch added patch discarded remove patch
@@ -43,10 +43,14 @@  discard block
 block discarded – undo
43 43
         # "call").
44 44
 
45 45
         $cache_code = $request->get_parameter('cache_code');
46
-        if (!$cache_code) throw new ParamMissing('cache_code');
46
+        if (!$cache_code) {
47
+            throw new ParamMissing('cache_code');
48
+        }
47 49
 
48 50
         $logtype = $request->get_parameter('logtype');
49
-        if (!$logtype) throw new ParamMissing('logtype');
51
+        if (!$logtype) {
52
+            throw new ParamMissing('logtype');
53
+        }
50 54
         if (!in_array($logtype, array(
51 55
             'Found it', "Didn't find it", 'Comment', 'Will attend', 'Attended'
52 56
         ))) {
@@ -54,12 +58,17 @@  discard block
 block discarded – undo
54 58
         }
55 59
 
56 60
         $comment = $request->get_parameter('comment');
57
-        if (!$comment) $comment = "";
61
+        if (!$comment) {
62
+            $comment = "";
63
+        }
58 64
 
59 65
         $comment_format = $request->get_parameter('comment_format');
60
-        if (!$comment_format) $comment_format = "auto";
61
-        if (!in_array($comment_format, array('auto', 'html', 'plaintext')))
62
-            throw new InvalidParam('comment_format', $comment_format);
66
+        if (!$comment_format) {
67
+            $comment_format = "auto";
68
+        }
69
+        if (!in_array($comment_format, array('auto', 'html', 'plaintext'))) {
70
+                    throw new InvalidParam('comment_format', $comment_format);
71
+        }
63 72
 
64 73
         $tmp = $request->get_parameter('when');
65 74
         if ($tmp)
@@ -77,8 +86,7 @@  discard block
 block discarded – undo
77 86
                     "the past, but NOT in the future."
78 87
                 ));
79 88
             }
80
-        }
81
-        else {
89
+        } else {
82 90
             $when = time();
83 91
         }
84 92
 
@@ -115,9 +123,12 @@  discard block
 block discarded – undo
115 123
         }
116 124
 
117 125
         $recommend = $request->get_parameter('recommend');
118
-        if (!$recommend) $recommend = 'false';
119
-        if (!in_array($recommend, array('true', 'false')))
120
-            throw new InvalidParam('recommend', "Unknown option: '$recommend'.");
126
+        if (!$recommend) {
127
+            $recommend = 'false';
128
+        }
129
+        if (!in_array($recommend, array('true', 'false'))) {
130
+                    throw new InvalidParam('recommend', "Unknown option: '$recommend'.");
131
+        }
121 132
         $recommend = ($recommend == 'true');
122 133
         if ($recommend && $logtype != 'Found it')
123 134
         {
@@ -125,8 +136,7 @@  discard block
 block discarded – undo
125 136
                 throw new BadRequest(
126 137
                     "Recommending is allowed only for 'Found it' and 'Attended' logs."
127 138
                 );
128
-            }
129
-            else if (Settings::get('OC_BRANCH') == 'oc.pl') {
139
+            } else if (Settings::get('OC_BRANCH') == 'oc.pl') {
130 140
 
131 141
                 # We will remove the recommendation request and change the success message
132 142
                 # (which will be returned IF the rest of the query will meet all the
@@ -156,9 +166,7 @@  discard block
 block discarded – undo
156 166
         # Parse $needs_maintenance and get rid of it.
157 167
 
158 168
         if ($needs_maintenance) {
159
-            if ($needs_maintenance == 'true') { $needs_maintenance2 = 'true'; }
160
-            else if ($needs_maintenance == 'false') { $needs_maintenance2 = 'null'; }
161
-            else {
169
+            if ($needs_maintenance == 'true') { $needs_maintenance2 = 'true'; } else if ($needs_maintenance == 'false') { $needs_maintenance2 = 'null'; } else {
162 170
                 throw new InvalidParam(
163 171
                     'needs_maintenance', "Unknown option: '$needs_maintenance'."
164 172
                 );
@@ -216,16 +224,14 @@  discard block
 block discarded – undo
216 224
                     'you can attend it, or comment on it)!'
217 225
                 ));
218 226
             }
219
-        }
220
-        else  # type != event
227
+        } else  # type != event
221 228
         {
222 229
             if (in_array($logtype, array('Will attend', 'Attended'))) {
223 230
                 throw new CannotPublishException(_(
224 231
                     'This cache is NOT an Event cache. You cannot "Attend" it '.
225 232
                     '(but you can find it, or comment on it)!'
226 233
                 ));
227
-            }
228
-            else if (!in_array($logtype, array('Found it', "Didn't find it", 'Comment'))) {
234
+            } else if (!in_array($logtype, array('Found it', "Didn't find it", 'Comment'))) {
229 235
                 throw new Exception("Unknown log entry - should be documented here.");
230 236
             }
231 237
         }
@@ -276,8 +282,7 @@  discard block
 block discarded – undo
276 282
             if (Settings::get('OC_BRANCH') == 'oc.de')
277 283
             {
278 284
                 $value_for_text_html_field = 0;
279
-            }
280
-            else
285
+            } else
281 286
             {
282 287
                 # 'text_html' = 0 (false) is broken in OCPL code and has been
283 288
                 # deprecated; OCPL code was changed to always set it to 1 (true).
@@ -289,8 +294,7 @@  discard block
 block discarded – undo
289 294
 
290 295
                 $value_for_text_html_field = 1;
291 296
             }
292
-        }
293
-        elseif ($comment_format == 'auto')
297
+        } elseif ($comment_format == 'auto')
294 298
         {
295 299
             # 'Auto' is for backward compatibility. Before the "comment_format"
296 300
             # was introduced, OKAPI used a weird format in between (it allowed
@@ -298,8 +302,7 @@  discard block
 block discarded – undo
298 302
 
299 303
             $formatted_comment = nl2br($comment);
300 304
             $value_for_text_html_field = 1;
301
-        }
302
-        else
305
+        } else
303 306
         {
304 307
             $formatted_comment = $comment;
305 308
 
@@ -318,8 +321,7 @@  discard block
 block discarded – undo
318 321
 
319 322
                 $purifier = new \OcHTMLPurifier($opt);
320 323
                 $formatted_comment = $purifier->purify($formatted_comment);
321
-            }
322
-            else
324
+            } else
323 325
             {
324 326
                 # TODO: Add OCPL HTML filtering.
325 327
                 # See https://github.com/opencaching/okapi/issues/412.
@@ -392,8 +394,7 @@  discard block
 block discarded – undo
392 394
                 {
393 395
                     # Act as if the log has been submitted successfully.
394 396
                     return $duplicate_uuid;
395
-                }
396
-                elseif ($on_duplicate == 'user_error')
397
+                } elseif ($on_duplicate == 'user_error')
397 398
                 {
398 399
                     throw new CannotPublishException(_(
399 400
                         "You have already submitted a log entry with exactly ".
@@ -511,8 +512,7 @@  discard block
 block discarded – undo
511 512
                 $logtype = 'Needs maintenance';
512 513
                 $second_logtype = null;
513 514
                 $second_formatted_comment = null;
514
-            }
515
-            elseif ($logtype == 'Found it')
515
+            } elseif ($logtype == 'Found it')
516 516
             {
517 517
                 # If "Found it", then we'll issue two log entries: one "Found
518 518
                 # it" with the original comment, and second one "Needs
@@ -520,8 +520,7 @@  discard block
 block discarded – undo
520 520
 
521 521
                 $second_logtype = 'Needs maintenance';
522 522
                 $second_formatted_comment = "";
523
-            }
524
-            elseif ($logtype == "Didn't find it")
523
+            } elseif ($logtype == "Didn't find it")
525 524
             {
526 525
                 # If "Didn't find it", then we'll issue two log entries, but this time
527 526
                 # we'll do this the other way around. The first "Didn't find it" entry
@@ -532,8 +531,7 @@  discard block
 block discarded – undo
532 531
                 $second_logtype = 'Needs maintenance';
533 532
                 $second_formatted_comment = $formatted_comment;
534 533
                 $formatted_comment = "";
535
-            }
536
-            else if ($logtype == 'Will attend' || $logtype == 'Attended')
534
+            } else if ($logtype == 'Will attend' || $logtype == 'Attended')
537 535
             {
538 536
                 # OC branches which allow maintenance logs, still don't allow them on
539 537
                 # event caches.
@@ -541,12 +539,10 @@  discard block
 block discarded – undo
541 539
                 throw new CannotPublishException(_(
542 540
                     "Event caches cannot \"need maintenance\"."
543 541
                 ));
544
-            }
545
-            else {
542
+            } else {
546 543
                 throw new Exception();
547 544
             }
548
-        }
549
-        else
545
+        } else
550 546
         {
551 547
             # User didn't check the "Needs maintenance" flag OR "Needs maintenance"
552 548
             # log type isn't supported by this server.
@@ -644,8 +640,7 @@  discard block
 block discarded – undo
644 640
                         from_unixtime('".Db::escape_string($when)."')
645 641
                     );
646 642
                 ");
647
-            }
648
-            else
643
+            } else
649 644
             {
650 645
                 Db::execute("
651 646
                     insert into cache_rating (user_id, cache_id)
@@ -680,7 +675,9 @@  discard block
 block discarded – undo
680 675
         # This is the "real" entry point. A wrapper for the _call method.
681 676
 
682 677
         $langpref = $request->get_parameter('langpref');
683
-        if (!$langpref) $langpref = "en";
678
+        if (!$langpref) {
679
+            $langpref = "en";
680
+        }
684 681
 
685 682
         # Error messages thrown via CannotPublishException exceptions should be localized.
686 683
         # They will be delivered for end user to display in his language.
@@ -698,8 +695,7 @@  discard block
 block discarded – undo
698 695
                 'log_uuids' => $log_uuids
699 696
             );
700 697
             Okapi::gettext_domain_restore();
701
-        }
702
-        catch (CannotPublishException $e)
698
+        } catch (CannotPublishException $e)
703 699
         {
704 700
             Okapi::gettext_domain_restore();
705 701
             $result = array(
@@ -719,8 +715,7 @@  discard block
 block discarded – undo
719 715
         {
720 716
             # OCDE handles cache stats updates using triggers. So, they are already
721 717
             # incremented properly.
722
-        }
723
-        else
718
+        } else
724 719
         {
725 720
             # OCPL doesn't use triggers for this. We need to update manually.
726 721
 
@@ -736,24 +731,21 @@  discard block
 block discarded – undo
736 731
                         )
737 732
                     where cache_id = '".Db::escape_string($cache_internal_id)."'
738 733
                 ");
739
-            }
740
-            elseif ($logtype == "Didn't find it")
734
+            } elseif ($logtype == "Didn't find it")
741 735
             {
742 736
                 Db::execute("
743 737
                     update caches
744 738
                     set notfounds = notfounds + 1
745 739
                     where cache_id = '".Db::escape_string($cache_internal_id)."'
746 740
                 ");
747
-            }
748
-            elseif ($logtype == 'Comment')
741
+            } elseif ($logtype == 'Comment')
749 742
             {
750 743
                 Db::execute("
751 744
                     update caches
752 745
                     set notes = notes + 1
753 746
                     where cache_id = '".Db::escape_string($cache_internal_id)."'
754 747
                 ");
755
-            }
756
-            else
748
+            } else
757 749
             {
758 750
                 # This log type is not represented in cache stats.
759 751
             }
@@ -766,8 +758,7 @@  discard block
 block discarded – undo
766 758
         {
767 759
             # OCDE handles cache stats updates using triggers. So, they are already
768 760
             # incremented properly.
769
-        }
770
-        else
761
+        } else
771 762
         {
772 763
             # OCPL doesn't have triggers for this. We need to update manually.
773 764
 
Please login to merge, or discard this patch.
htdocs/okapi/services/logs/userlogs.php 1 patch
Braces   +21 added lines, -11 removed lines patch added patch discarded remove patch
@@ -24,21 +24,31 @@
 block discarded – undo
24 24
     public static function call(OkapiRequest $request)
25 25
     {
26 26
         $user_uuid = $request->get_parameter('user_uuid');
27
-        if (!$user_uuid) throw new ParamMissing('user_uuid');
27
+        if (!$user_uuid) {
28
+            throw new ParamMissing('user_uuid');
29
+        }
28 30
         $limit = $request->get_parameter('limit');
29
-        if (!$limit) $limit = "20";
30
-        if (!is_numeric($limit))
31
-            throw new InvalidParam('limit', "'$limit'");
31
+        if (!$limit) {
32
+            $limit = "20";
33
+        }
34
+        if (!is_numeric($limit)) {
35
+                    throw new InvalidParam('limit', "'$limit'");
36
+        }
32 37
         $limit = intval($limit);
33
-        if (($limit < 1) || ($limit > 1000))
34
-            throw new InvalidParam('limit', "Has to be in range 1..1000.");
38
+        if (($limit < 1) || ($limit > 1000)) {
39
+                    throw new InvalidParam('limit', "Has to be in range 1..1000.");
40
+        }
35 41
         $offset = $request->get_parameter('offset');
36
-        if (!$offset) $offset = "0";
37
-        if (!is_numeric($offset))
38
-            throw new InvalidParam('offset', "'$offset'");
42
+        if (!$offset) {
43
+            $offset = "0";
44
+        }
45
+        if (!is_numeric($offset)) {
46
+                    throw new InvalidParam('offset', "'$offset'");
47
+        }
39 48
         $offset = intval($offset);
40
-        if ($offset < 0)
41
-            throw new InvalidParam('offset', "'$offset'");
49
+        if ($offset < 0) {
50
+                    throw new InvalidParam('offset', "'$offset'");
51
+        }
42 52
 
43 53
         # Check if user exists and retrieve user's ID (this will throw
44 54
         # a proper exception on invalid UUID).
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/logs/images/add.php 1 patch
Braces   +41 added lines, -31 removed lines patch added patch discarded remove patch
@@ -48,8 +48,9 @@  discard block
 block discarded – undo
48 48
         # validate the 'log_uuid' parameter
49 49
 
50 50
         $log_uuid = $request->get_parameter('log_uuid');
51
-        if (!$log_uuid)
52
-            throw new ParamMissing('log_uuid');
51
+        if (!$log_uuid) {
52
+                    throw new ParamMissing('log_uuid');
53
+        }
53 54
         $rs = Db::query("
54 55
             select id, node, user_id
55 56
             from cache_logs
@@ -57,8 +58,9 @@  discard block
 block discarded – undo
57 58
         );
58 59
         $row = Db::fetch_assoc($rs);
59 60
         Db::free_result($rs);
60
-        if (!$row)
61
-            throw new InvalidParam('log_uuid', "There is no log entry with uuid '".$log_uuid."'.");
61
+        if (!$row) {
62
+                    throw new InvalidParam('log_uuid', "There is no log entry with uuid '".$log_uuid."'.");
63
+        }
62 64
         if ($row['node'] != Settings::get('OC_NODE_ID')) {
63 65
             throw new Exception(
64 66
                 "This site's database contains the log entry '$log_uuid' which has been"
@@ -85,17 +87,21 @@  discard block
 block discarded – undo
85 87
         }
86 88
 
87 89
         $is_spoiler = $request->get_parameter('is_spoiler');
88
-        if ($is_spoiler === null) $is_spoiler = 'false';
89
-        if (!in_array($is_spoiler, array('true', 'false')))
90
-            throw new InvalidParam('is_spoiler');
90
+        if ($is_spoiler === null) {
91
+            $is_spoiler = 'false';
92
+        }
93
+        if (!in_array($is_spoiler, array('true', 'false'))) {
94
+                    throw new InvalidParam('is_spoiler');
95
+        }
91 96
 
92 97
         $position = LogImagesCommon::validate_position($request);
93 98
 
94 99
         # validate the 'image' parameter
95 100
 
96 101
         $base64_image = $request->get_parameter('image');
97
-        if (!$base64_image)
98
-            throw new ParamMissing('image');
102
+        if (!$base64_image) {
103
+                    throw new ParamMissing('image');
104
+        }
99 105
 
100 106
         $estimated_decoded_size = strlen($base64_image) / 4 * 3 - 2;
101 107
         if ($estimated_decoded_size > Settings::get('IMAGE_MAX_UPLOAD_SIZE'))
@@ -112,20 +118,21 @@  discard block
 block discarded – undo
112 118
         }
113 119
 
114 120
         $image = base64_decode($base64_image);
115
-        if (!$image)
116
-            throw new InvalidParam('image', "bad base64 encoding");
121
+        if (!$image) {
122
+                    throw new InvalidParam('image', "bad base64 encoding");
123
+        }
117 124
 
118 125
         try {
119 126
             $image_properties = getimagesizefromstring($image);  # can throw
120
-            if (!$image_properties)
121
-                throw new Exception();
127
+            if (!$image_properties) {
128
+                            throw new Exception();
129
+            }
122 130
             list($width, $height, $image_type) = $image_properties;
123 131
             if (!in_array($image_type, array(IMAGETYPE_JPEG, IMAGETYPE_PNG, IMAGETYPE_GIF))) {
124 132
                 # This will happen e.g. for BMP and XBM images, which are supported by GD.
125 133
                 throw new Exception();
126 134
             }
127
-        }
128
-        catch (Exception $e) {
135
+        } catch (Exception $e) {
129 136
             # Note: There may be *subtypes* which are not accepted by the GD library.
130 137
             # About 1 of 2000 JPEGs at OC.de is not readable by the PHP functions,
131 138
             # though they can be displayed by web browsers.
@@ -149,9 +156,10 @@  discard block
 block discarded – undo
149 156
         }
150 157
         try {
151 158
             $image = imagecreatefromstring($image);  # can throw
152
-            if (!$image) throw new Exception();
153
-        }
154
-        catch (Exception $e) {
159
+            if (!$image) {
160
+                throw new Exception();
161
+            }
162
+        } catch (Exception $e) {
155 163
             throw new CannotPublishException(_("The uploaded image file is broken."));
156 164
         }
157 165
 
@@ -190,8 +198,9 @@  discard block
 block discarded – undo
190 198
                 $file_ext = '.???';
191 199
                 $result = false;
192 200
         }
193
-        if (!$result)
194
-            throw new Exception("could not save image file '".$imagepath.$file_ext."'");
201
+        if (!$result) {
202
+                    throw new Exception("could not save image file '".$imagepath.$file_ext."'");
203
+        }
195 204
 
196 205
         # insert image into database
197 206
 
@@ -201,15 +210,13 @@  discard block
 block discarded – undo
201 210
                 $request->consumer->key, $request->token->user_id,
202 211
                 $log_internal_id, $image_uuid, $position, $caption, $is_spoiler, $file_ext
203 212
             );
204
-        }
205
-        catch (Exception $e)
213
+        } catch (Exception $e)
206 214
         {
207 215
             # TODO: Proper handling of nested exception if the unlink() fails
208 216
             # (which is very unlikely, and will just add a bit more of garbage
209 217
             # to that which is already present in the images directory).
210 218
 
211
-            try { unlink($imagepath.$file_ext); }
212
-            catch (Exception $e2) {}
219
+            try { unlink($imagepath.$file_ext); } catch (Exception $e2) {}
213 220
             throw $e;
214 221
         }
215 222
 
@@ -239,8 +246,9 @@  discard block
 block discarded – undo
239 246
         # and more powerful alternative (e.g. allowing more file types),
240 247
         # but that needs additional and sometimes non-trivial installation.
241 248
 
242
-        if (!extension_loaded('gd'))
243
-            throw new Exception('PHP GD image processing module is disabled');
249
+        if (!extension_loaded('gd')) {
250
+                    throw new Exception('PHP GD image processing module is disabled');
251
+        }
244 252
 
245 253
         # rescale image if necessary
246 254
 
@@ -261,8 +269,9 @@  discard block
 block discarded – undo
261 269
         #   - GD cannot save EXIF data anyway, and
262 270
         #   - the orientation flag may not be recognized by all image processors.
263 271
 
264
-        if (!extension_loaded('exif'))
265
-            throw new Exception('PHP Exif module is disabled');
272
+        if (!extension_loaded('exif')) {
273
+                    throw new Exception('PHP Exif module is disabled');
274
+        }
266 275
 
267 276
         if ($image_type == IMAGETYPE_JPEG)
268 277
         {
@@ -393,7 +402,9 @@  discard block
 block discarded – undo
393 402
         # This is the "real" entry point. A wrapper for the _call method.
394 403
 
395 404
         $langpref = $request->get_parameter('langpref');
396
-        if (!$langpref) $langpref = "en";
405
+        if (!$langpref) {
406
+            $langpref = "en";
407
+        }
397 408
         Okapi::gettext_domain_init(explode("|", $langpref));
398 409
 
399 410
         try
@@ -406,8 +417,7 @@  discard block
 block discarded – undo
406 417
                 'position' => $position
407 418
             );
408 419
             Okapi::gettext_domain_restore();
409
-        }
410
-        catch (CannotPublishException $e)
420
+        } catch (CannotPublishException $e)
411 421
         {
412 422
             Okapi::gettext_domain_restore();
413 423
             $result = array(
Please login to merge, or discard this patch.
htdocs/okapi/services/logs/images/delete.php 1 patch
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -44,8 +44,7 @@
 block discarded – undo
44 44
         if (Settings::get('OC_BRANCH') == 'oc.de')
45 45
         {
46 46
             # OCDE does all the housekeeping by triggers
47
-        }
48
-        else
47
+        } else
49 48
         {
50 49
             Db::execute("
51 50
                 INSERT INTO removed_objects (
Please login to merge, or discard this patch.
htdocs/okapi/services/logs/images/edit.php 1 patch
Braces   +8 added lines, -7 removed lines patch added patch discarded remove patch
@@ -60,8 +60,9 @@  discard block
 block discarded – undo
60 60
 
61 61
         $is_spoiler = $request->get_parameter('is_spoiler');
62 62
         if ($is_spoiler !== null) {
63
-            if (!in_array($is_spoiler, array('true', 'false')))
64
-                throw new InvalidParam('is_spoiler');
63
+            if (!in_array($is_spoiler, array('true', 'false'))) {
64
+                            throw new InvalidParam('is_spoiler');
65
+            }
65 66
         }
66 67
 
67 68
         $position = LogImagesCommon::validate_position($request);
@@ -111,8 +112,7 @@  discard block
 block discarded – undo
111 112
                     order by date_created
112 113
                 ");
113 114
                 $position = array_search($image_uuid, $image_uuids);
114
-            }
115
-            else
115
+            } else
116 116
             {
117 117
                 list($position, $seq) = LogImagesCommon::prepare_position(
118 118
                     $log_internal_id,
@@ -204,7 +204,9 @@  discard block
 block discarded – undo
204 204
         # This is the "real" entry point. A wrapper for the _call method.
205 205
 
206 206
         $langpref = $request->get_parameter('langpref');
207
-        if (!$langpref) $langpref = "en";
207
+        if (!$langpref) {
208
+            $langpref = "en";
209
+        }
208 210
         Okapi::gettext_domain_init(explode("|", $langpref));
209 211
 
210 212
         try
@@ -216,8 +218,7 @@  discard block
 block discarded – undo
216 218
                 'position' => $position
217 219
             );
218 220
             Okapi::gettext_domain_restore();
219
-        }
220
-        catch (CannotPublishException $e)
221
+        } catch (CannotPublishException $e)
221 222
         {
222 223
             Okapi::gettext_domain_restore();
223 224
             $result = array(
Please login to merge, or discard this patch.