Completed
Pull Request — master (#312)
by
unknown
26:01 queued 18:06
created
htdocs/okapi/core.php 2 patches
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -12,7 +12,6 @@
 block discarded – undo
12 12
 use ArrayObject;
13 13
 use okapi\oauth\OAuthServerException;
14 14
 use okapi\oauth\OAuthServer400Exception;
15
-use okapi\oauth\OAuthServer401Exception;
16 15
 use okapi\oauth\OAuthMissingParameterException;
17 16
 use okapi\oauth\OAuthConsumer;
18 17
 use okapi\oauth\OAuthToken;
Please login to merge, or discard this patch.
Braces   +351 added lines, -253 removed lines patch added patch discarded remove patch
@@ -29,14 +29,15 @@  discard block
 block discarded – undo
29 29
     {
30 30
         try
31 31
         {
32
-            foreach (Settings::get('ADMINS') as $email)
33
-                if (!in_array($email, $emails))
32
+            foreach (Settings::get('ADMINS') as $email) {
33
+                            if (!in_array($email, $emails))
34 34
                     $emails[] = $email;
35
-        }
36
-        catch (Exception $e) { /* pass */ }
35
+            }
36
+        } catch (Exception $e) { /* pass */ }
37
+    }
38
+    if (count($emails) == 0) {
39
+            $emails[] = 'root@localhost';
37 40
     }
38
-    if (count($emails) == 0)
39
-        $emails[] = 'root@localhost';
40 41
     return $emails;
41 42
 }
42 43
 
@@ -81,16 +82,16 @@  discard block
 block discarded – undo
81 82
             # of this exception. All of them result in HTTP 400 or HTTP 401 error
82 83
             # code. See also: http://oauth.net/core/1.0a/#http_codes
83 84
 
84
-            if ($e instanceof OAuthServer400Exception)
85
-                header("HTTP/1.0 400 Bad Request");
86
-            else
87
-                header("HTTP/1.0 401 Unauthorized");
85
+            if ($e instanceof OAuthServer400Exception) {
86
+                            header("HTTP/1.0 400 Bad Request");
87
+            } else {
88
+                            header("HTTP/1.0 401 Unauthorized");
89
+            }
88 90
             header("Access-Control-Allow-Origin: *");
89 91
             header("Content-Type: application/json; charset=utf-8");
90 92
 
91 93
             print $e->getOkapiJSON();
92
-        }
93
-        elseif ($e instanceof BadRequest)
94
+        } elseif ($e instanceof BadRequest)
94 95
         {
95 96
             # Intentionally thrown from within the OKAPI method code.
96 97
             # Consumer (aka external developer) had something wrong with his
@@ -105,8 +106,7 @@  discard block
 block discarded – undo
105 106
             }
106 107
 
107 108
             print $e->getOkapiJSON();
108
-        }
109
-        else # (ErrorException, MySQL exception etc.)
109
+        } else # (ErrorException, MySQL exception etc.)
110 110
         {
111 111
             # This one is thrown on PHP notices and warnings - usually this
112 112
             # indicates an error in OKAPI method. If thrown, then something
@@ -137,8 +137,7 @@  discard block
 block discarded – undo
137 137
             {
138 138
                 # Sending emails was blocked on admin's demand.
139 139
                 # This is possible only on development environment.
140
-            }
141
-            else
140
+            } else
142 141
             {
143 142
                 $subject = "OKAPI Method Error - ".substr(
144 143
                     $_SERVER['REQUEST_URI'], 0, strpos(
@@ -153,16 +152,16 @@  discard block
 block discarded – undo
153 152
                 try
154 153
                 {
155 154
                     Okapi::mail_admins($subject, $message);
156
-                }
157
-                catch (Exception $e)
155
+                } catch (Exception $e)
158 156
                 {
159 157
                     # Unable to use full-featured mail_admins version. We'll use a backup.
160 158
                     # We need to make sure we're not spamming.
161 159
 
162 160
                     $lock_file = "/tmp/okapi-fatal-error-mode";
163 161
                     $last_email = false;
164
-                    if (file_exists($lock_file))
165
-                        $last_email = filemtime($lock_file);
162
+                    if (file_exists($lock_file)) {
163
+                                            $last_email = filemtime($lock_file);
164
+                    }
166 165
                     if ($last_email === false) {
167 166
                         # Assume this is the first email.
168 167
                         $last_email = 0;
@@ -219,8 +218,7 @@  discard block
 block discarded – undo
219 218
             # the file and line.
220 219
 
221 220
             $exception_info .= "File: ".$e->getFile()."\nLine: ".$e->getLine()."\n\n";
222
-        }
223
-        else
221
+        } else
224 222
         {
225 223
             $exception_info .= "--- Stack trace ---\n".
226 224
                 self::removeSensitiveData($e->getTraceAsString())."\n\n";
@@ -254,7 +252,9 @@  discard block
 block discarded – undo
254 252
     /** Handle error encountered while executing OKAPI request. */
255 253
     public static function handle($severity, $message, $filename, $lineno)
256 254
     {
257
-        if ($severity == E_STRICT || $severity == E_DEPRECATED) return false;
255
+        if ($severity == E_STRICT || $severity == E_DEPRECATED) {
256
+            return false;
257
+        }
258 258
         if (($severity == E_NOTICE) && !self::$treat_notices_as_errors) {
259 259
             return false;
260 260
         }
@@ -340,10 +340,11 @@  discard block
 block discarded – undo
340 340
     {
341 341
         $this->paramName = $paramName;
342 342
         $this->whats_wrong_about_it = $whats_wrong_about_it;
343
-        if ($whats_wrong_about_it)
344
-            parent::__construct("Parameter '$paramName' has invalid value: ".$whats_wrong_about_it, $code);
345
-        else
346
-            parent::__construct("Parameter '$paramName' has invalid value.", $code);
343
+        if ($whats_wrong_about_it) {
344
+                    parent::__construct("Parameter '$paramName' has invalid value: ".$whats_wrong_about_it, $code);
345
+        } else {
346
+                    parent::__construct("Parameter '$paramName' has invalid value.", $code);
347
+        }
347 348
     }
348 349
 }
349 350
 
@@ -369,9 +370,9 @@  discard block
 block discarded – undo
369 370
             mysql_select_db(Settings::get('DB_NAME'));
370 371
             mysql_query("set names '" . Settings::get('DB_CHARSET') . "'");
371 372
             self::$connected = true;
373
+        } else {
374
+                    throw new Exception("Could not connect to MySQL: ".mysql_error());
372 375
         }
373
-        else
374
-            throw new Exception("Could not connect to MySQL: ".mysql_error());
375 376
     }
376 377
 
377 378
     /** Fetch [{row}], return {row}. */
@@ -402,12 +403,14 @@  discard block
 block discarded – undo
402 403
         while (true)
403 404
         {
404 405
             $row = Db::fetch_assoc($rs);
405
-            if ($row === false)
406
-                break;
407
-            if ($keyField == null)
408
-                $arr[] = $row;
409
-            else
410
-                $arr[$row[$keyField]] = $row;
406
+            if ($row === false) {
407
+                            break;
408
+            }
409
+            if ($keyField == null) {
410
+                            $arr[] = $row;
411
+            } else {
412
+                            $arr[$row[$keyField]] = $row;
413
+            }
411 414
         }
412 415
         Db::free_result($rs);
413 416
     }
@@ -420,8 +423,9 @@  discard block
 block discarded – undo
420 423
         while (true)
421 424
         {
422 425
             $row = Db::fetch_assoc($rs);
423
-            if ($row === false)
424
-                break;
426
+            if ($row === false) {
427
+                            break;
428
+            }
425 429
             $groups[$row[$keyField]][] = $row;
426 430
         }
427 431
         Db::free_result($rs);
@@ -432,10 +436,12 @@  discard block
 block discarded – undo
432 436
     public static function select_value($query)
433 437
     {
434 438
         $column = self::select_column($query);
435
-        if ($column == null)
436
-            return null;
437
-        if (count($column) == 1)
438
-            return $column[0];
439
+        if ($column == null) {
440
+                    return null;
441
+        }
442
+        if (count($column) == 1) {
443
+                    return $column[0];
444
+        }
439 445
         throw new DbException("Invalid query. Db::select_value returned more than one row for:\n\n".$query."\n");
440 446
     }
441 447
 
@@ -447,8 +453,9 @@  discard block
 block discarded – undo
447 453
         while (true)
448 454
         {
449 455
             $values = Db::fetch_row($rs);
450
-            if ($values === false)
451
-                break;
456
+            if ($values === false) {
457
+                            break;
458
+            }
452 459
             array_push($column, $values[0]);
453 460
         }
454 461
         Db::free_result($rs);
@@ -488,15 +495,17 @@  discard block
 block discarded – undo
488 495
     public static function execute($query)
489 496
     {
490 497
         $rs = self::query($query);
491
-        if ($rs !== true)
492
-            throw new DbException("Db::execute returned a result set for your query. ".
498
+        if ($rs !== true) {
499
+                    throw new DbException("Db::execute returned a result set for your query. ".
493 500
                 "You should use Db::select_* or Db::query for SELECT queries!");
501
+        }
494 502
     }
495 503
 
496 504
     public static function query($query)
497 505
     {
498
-        if (!self::$connected)
499
-            self::connect();
506
+        if (!self::$connected) {
507
+                    self::connect();
508
+        }
500 509
         $rs = mysql_query($query);
501 510
         if (!$rs)
502 511
         {
@@ -555,8 +564,9 @@  discard block
 block discarded – undo
555 564
 
556 565
     public static function field_exists($table, $field)
557 566
     {
558
-        if (!preg_match("/[a-z0-9_]+/", $table.$field))
559
-            return false;
567
+        if (!preg_match("/[a-z0-9_]+/", $table.$field)) {
568
+                    return false;
569
+        }
560 570
         try {
561 571
             $spec = self::select_all("desc ".$table.";");
562 572
         } catch (Exception $e) {
@@ -564,8 +574,9 @@  discard block
 block discarded – undo
564 574
             return false;
565 575
         }
566 576
         foreach ($spec as &$row_ref) {
567
-            if (strtoupper($row_ref['Field']) == strtoupper($field))
568
-                return true;
577
+            if (strtoupper($row_ref['Field']) == strtoupper($field)) {
578
+                            return true;
579
+            }
569 580
         }
570 581
         return false;
571 582
     }
@@ -765,10 +776,11 @@  discard block
 block discarded – undo
765 776
         } catch (OAuthMissingParameterException $e) {
766 777
             # Note, that exception will be different if token is supplied
767 778
             # and is invalid. We catch only a completely MISSING token parameter.
768
-            if (($e->getParamName() == 'oauth_token') && (!$token_required))
769
-                $token = null;
770
-            else
771
-                throw $e;
779
+            if (($e->getParamName() == 'oauth_token') && (!$token_required)) {
780
+                            $token = null;
781
+            } else {
782
+                            throw $e;
783
+            }
772 784
         }
773 785
         $this->check_signature($request, $consumer, $token);
774 786
         return array($consumer, $token);
@@ -798,8 +810,9 @@  discard block
 block discarded – undo
798 810
 
799 811
     public function get_length()
800 812
     {
801
-        if (is_resource($this->body))
802
-            return $this->stream_length;
813
+        if (is_resource($this->body)) {
814
+                    return $this->stream_length;
815
+        }
803 816
         return strlen($this->body);
804 817
     }
805 818
 
@@ -808,11 +821,12 @@  discard block
 block discarded – undo
808 821
     {
809 822
         if (is_resource($this->body))
810 823
         {
811
-            while (!feof($this->body))
812
-                print fread($this->body, 1024*1024);
824
+            while (!feof($this->body)) {
825
+                            print fread($this->body, 1024*1024);
826
+            }
827
+        } else {
828
+                    print $this->body;
813 829
         }
814
-        else
815
-            print $this->body;
816 830
     }
817 831
 
818 832
     /**
@@ -826,9 +840,9 @@  discard block
 block discarded – undo
826 840
             ob_start();
827 841
             fpassthru($this->body);
828 842
             return ob_get_clean();
843
+        } else {
844
+                    return $this->body;
829 845
         }
830
-        else
831
-            return $this->body;
832 846
     }
833 847
 
834 848
     /**
@@ -840,17 +854,21 @@  discard block
 block discarded – undo
840 854
         header("Access-Control-Allow-Origin: *");
841 855
         header("Content-Type: ".$this->content_type);
842 856
         header("Cache-Control: ".$this->cache_control);
843
-        if ($this->connection_close)
844
-            header("Connection: close");
845
-        if ($this->content_disposition)
846
-            header("Content-Disposition: ".$this->content_disposition);
847
-        if ($this->etag)
848
-            header("ETag: $this->etag");
857
+        if ($this->connection_close) {
858
+                    header("Connection: close");
859
+        }
860
+        if ($this->content_disposition) {
861
+                    header("Content-Disposition: ".$this->content_disposition);
862
+        }
863
+        if ($this->etag) {
864
+                    header("ETag: $this->etag");
865
+        }
849 866
 
850 867
         # Make sure that gzip is supported by the client.
851 868
         $use_gzip = $this->allow_gzip;
852
-        if (empty($_SERVER["HTTP_ACCEPT_ENCODING"]) || (strpos($_SERVER["HTTP_ACCEPT_ENCODING"], "gzip") === false))
853
-            $use_gzip = false;
869
+        if (empty($_SERVER["HTTP_ACCEPT_ENCODING"]) || (strpos($_SERVER["HTTP_ACCEPT_ENCODING"], "gzip") === false)) {
870
+                    $use_gzip = false;
871
+        }
854 872
 
855 873
         # We will gzip the data ourselves, while disabling gziping by Apache. This way, we can
856 874
         # set the Content-Length correctly which is handy in some scenarios.
@@ -863,8 +881,7 @@  discard block
 block discarded – undo
863 881
             $gzipped = gzencode($this->body, 5);
864 882
             header("Content-Length: ".strlen($gzipped));
865 883
             print $gzipped;
866
-        }
867
-        else
884
+        } else
868 885
         {
869 886
             # We don't want Apache to gzip this response. Tell it so.
870 887
 
@@ -873,8 +890,9 @@  discard block
 block discarded – undo
873 890
             }
874 891
 
875 892
             $length = $this->get_length();
876
-            if ($length)
877
-                header("Content-Length: ".$length);
893
+            if ($length) {
894
+                            header("Content-Length: ".$length);
895
+            }
878 896
             $this->print_body();
879 897
         }
880 898
     }
@@ -954,8 +972,7 @@  discard block
 block discarded – undo
954 972
             # Using semaphores is forbidden on this server by its admin.
955 973
             # This is possible only on development environment.
956 974
             $this->lock = null;
957
-        }
958
-        else
975
+        } else
959 976
         {
960 977
             $this->lockfile = Okapi::get_var_dir()."/okapi-lock-".$name;
961 978
             $this->lock = fopen($this->lockfile, "wb");
@@ -964,22 +981,26 @@  discard block
 block discarded – undo
964 981
 
965 982
     public function acquire()
966 983
     {
967
-        if ($this->lock !== null)
968
-            flock($this->lock, LOCK_EX);
984
+        if ($this->lock !== null) {
985
+                    flock($this->lock, LOCK_EX);
986
+        }
969 987
     }
970 988
 
971 989
     public function try_acquire()
972 990
     {
973
-        if ($this->lock !== null)
974
-            return flock($this->lock, LOCK_EX | LOCK_NB);
975
-        else
976
-            return true;  # $lock can be null only when debugging
991
+        if ($this->lock !== null) {
992
+                    return flock($this->lock, LOCK_EX | LOCK_NB);
993
+        } else {
994
+                    return true;
995
+        }
996
+        # $lock can be null only when debugging
977 997
     }
978 998
 
979 999
     public function release()
980 1000
     {
981
-        if ($this->lock !== null)
982
-            flock($this->lock, LOCK_UN);
1001
+        if ($this->lock !== null) {
1002
+                    flock($this->lock, LOCK_UN);
1003
+        }
983 1004
     }
984 1005
 
985 1006
     /**
@@ -1040,11 +1061,13 @@  discard block
 block discarded – undo
1040 1061
                 from okapi_vars
1041 1062
             ");
1042 1063
             self::$okapi_vars = array();
1043
-            while ($row = Db::fetch_assoc($rs))
1044
-                self::$okapi_vars[$row['var']] = $row['value'];
1064
+            while ($row = Db::fetch_assoc($rs)) {
1065
+                            self::$okapi_vars[$row['var']] = $row['value'];
1066
+            }
1067
+        }
1068
+        if (isset(self::$okapi_vars[$varname])) {
1069
+                    return self::$okapi_vars[$varname];
1045 1070
         }
1046
-        if (isset(self::$okapi_vars[$varname]))
1047
-            return self::$okapi_vars[$varname];
1048 1071
         return $default;
1049 1072
     }
1050 1073
 
@@ -1100,8 +1123,9 @@  discard block
 block discarded – undo
1100 1123
 
1101 1124
             return;
1102 1125
         }
1103
-        if ($counter === null)
1104
-            $counter = 0;
1126
+        if ($counter === null) {
1127
+                    $counter = 0;
1128
+        }
1105 1129
         $counter++;
1106 1130
         try {
1107 1131
             Cache::set($cache_key, $counter, 3600);
@@ -1114,8 +1138,7 @@  discard block
 block discarded – undo
1114 1138
             # We're not spamming yet.
1115 1139
 
1116 1140
             self::mail_from_okapi(get_admin_emails(), $subject, $message);
1117
-        }
1118
-        else
1141
+        } else
1119 1142
         {
1120 1143
             # We are spamming. Prevent sending more emails.
1121 1144
 
@@ -1148,8 +1171,9 @@  discard block
 block discarded – undo
1148 1171
             # This is possible only on development environment.
1149 1172
             return;
1150 1173
         }
1151
-        if (!is_array($email_addresses))
1152
-            $email_addresses = array($email_addresses);
1174
+        if (!is_array($email_addresses)) {
1175
+                    $email_addresses = array($email_addresses);
1176
+        }
1153 1177
         $sender_email = class_exists("okapi\\Settings") ? Settings::get('FROM_FIELD') : 'root@localhost';
1154 1178
         mail(implode(", ", $email_addresses), $subject, $message,
1155 1179
             "Content-Type: text/plain; charset=utf-8\n".
@@ -1162,16 +1186,18 @@  discard block
 block discarded – undo
1162 1186
     public static function get_var_dir()
1163 1187
     {
1164 1188
         $dir = Settings::get('VAR_DIR');
1165
-        if ($dir != null)
1166
-            return rtrim($dir, "/");
1189
+        if ($dir != null) {
1190
+                    return rtrim($dir, "/");
1191
+        }
1167 1192
         throw new Exception("You need to set a valid VAR_DIR.");
1168 1193
     }
1169 1194
 
1170 1195
     /** Returns something like "Opencaching.PL" or "Opencaching.DE". */
1171 1196
     public static function get_normalized_site_name($site_url = null)
1172 1197
     {
1173
-        if ($site_url == null)
1174
-            $site_url = Settings::get('SITE_URL');
1198
+        if ($site_url == null) {
1199
+                    $site_url = Settings::get('SITE_URL');
1200
+        }
1175 1201
         $matches = null;
1176 1202
         if (preg_match("#^https?://(www.)?opencaching.([a-z.]+)/$#", $site_url, $matches)) {
1177 1203
             return "Opencaching.".strtoupper($matches[2]);
@@ -1320,11 +1346,13 @@  discard block
 block discarded – undo
1320 1346
      */
1321 1347
     public static function pick_best_language($langdict, $langprefs)
1322 1348
     {
1323
-        foreach ($langprefs as $pref)
1324
-            if (isset($langdict[$pref]))
1349
+        foreach ($langprefs as $pref) {
1350
+                    if (isset($langdict[$pref]))
1325 1351
                 return $langdict[$pref];
1326
-        foreach ($langdict as &$text_ref)
1327
-            return $text_ref;
1352
+        }
1353
+        foreach ($langdict as &$text_ref) {
1354
+                    return $text_ref;
1355
+        }
1328 1356
         return "";
1329 1357
     }
1330 1358
 
@@ -1405,8 +1433,9 @@  discard block
 block discarded – undo
1405 1433
     {
1406 1434
         # Put the langprefs on the stack.
1407 1435
 
1408
-        if ($langprefs == null)
1409
-            $langprefs = array(Settings::get('SITELANG'));
1436
+        if ($langprefs == null) {
1437
+                    $langprefs = array(Settings::get('SITELANG'));
1438
+        }
1410 1439
         self::$gettext_langprefs_stack[] = $langprefs;
1411 1440
 
1412 1441
         if (count(self::$gettext_langprefs_stack) == 1)
@@ -1438,8 +1467,7 @@  discard block
 block discarded – undo
1438 1467
         {
1439 1468
             $langprefs = self::$gettext_langprefs_stack[$size - 1];
1440 1469
             self::gettext_set_lang($langprefs);
1441
-        }
1442
-        else
1470
+        } else
1443 1471
         {
1444 1472
             # The stack is empty. This means we're going out of OKAPI code and
1445 1473
             # we want the original textdomain reestablished.
@@ -1455,20 +1483,25 @@  discard block
 block discarded – undo
1455 1483
     public static function init_internals($allow_cronjobs = true)
1456 1484
     {
1457 1485
         static $init_made = false;
1458
-        if ($init_made)
1459
-            return;
1486
+        if ($init_made) {
1487
+                    return;
1488
+        }
1460 1489
         ini_set('memory_limit', '256M');
1461 1490
         # The memory limit is - among other - crucial for the maximum size
1462 1491
         # of processable images; see services/logs/images/add.php: max_pixels()
1463 1492
         Db::connect();
1464
-        if (Settings::get('TIMEZONE') !== null)
1465
-            date_default_timezone_set(Settings::get('TIMEZONE'));
1466
-        if (!self::$data_store)
1467
-            self::$data_store = new OkapiDataStore();
1468
-        if (!self::$server)
1469
-            self::$server = new OkapiOAuthServer(self::$data_store);
1470
-        if ($allow_cronjobs)
1471
-            self::execute_prerequest_cronjobs();
1493
+        if (Settings::get('TIMEZONE') !== null) {
1494
+                    date_default_timezone_set(Settings::get('TIMEZONE'));
1495
+        }
1496
+        if (!self::$data_store) {
1497
+                    self::$data_store = new OkapiDataStore();
1498
+        }
1499
+        if (!self::$server) {
1500
+                    self::$server = new OkapiOAuthServer(self::$data_store);
1501
+        }
1502
+        if ($allow_cronjobs) {
1503
+                    self::execute_prerequest_cronjobs();
1504
+        }
1472 1505
         $init_made = true;
1473 1506
     }
1474 1507
 
@@ -1479,10 +1512,11 @@  discard block
 block discarded – undo
1479 1512
      */
1480 1513
     public static function generate_key($length, $user_friendly = false)
1481 1514
     {
1482
-        if ($user_friendly)
1483
-            $chars = "0123456789";
1484
-        else
1485
-            $chars = "abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789";
1515
+        if ($user_friendly) {
1516
+                    $chars = "0123456789";
1517
+        } else {
1518
+                    $chars = "abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789";
1519
+        }
1486 1520
         $max = strlen($chars);
1487 1521
         $key = "";
1488 1522
         for ($i=0; $i<$length; $i++)
@@ -1504,10 +1538,11 @@  discard block
 block discarded – undo
1504 1538
             $appname, $appurl, $email);
1505 1539
         $sample_cache = OkapiServiceRunner::call("services/caches/search/all",
1506 1540
             new OkapiInternalRequest($consumer, null, array('limit', 1)));
1507
-        if (count($sample_cache['results']) > 0)
1508
-            $sample_cache_code = $sample_cache['results'][0];
1509
-        else
1510
-            $sample_cache_code = "CACHECODE";
1541
+        if (count($sample_cache['results']) > 0) {
1542
+                    $sample_cache_code = $sample_cache['results'][0];
1543
+        } else {
1544
+                    $sample_cache_code = "CACHECODE";
1545
+        }
1511 1546
 
1512 1547
         # Message for the Consumer.
1513 1548
         ob_start();
@@ -1558,7 +1593,9 @@  discard block
 block discarded – undo
1558 1593
         # to floating point precision limits. See issue #351 for details.
1559 1594
         #
1560 1595
         $d = acos(min(1, cos($x1) * cos($x2) + sin($x1) * sin($x2) * cos(($lon1-$lon2) * 3.14159 / 180))) * 6371000;
1561
-        if ($d < 0) $d = 0;
1596
+        if ($d < 0) {
1597
+            $d = 0;
1598
+        }
1562 1599
         return $d;
1563 1600
     }
1564 1601
 
@@ -1581,10 +1618,15 @@  discard block
 block discarded – undo
1581 1618
     /** Return bearing (float 0..360) from geopoint 1 to 2. */
1582 1619
     public static function get_bearing($lat1, $lon1, $lat2, $lon2)
1583 1620
     {
1584
-        if ($lat1 == $lat2 && $lon1 == $lon2)
1585
-            return null;
1586
-        if ($lat1 == $lat2) $lat1 += 0.0000166;
1587
-        if ($lon1 == $lon2) $lon1 += 0.0000166;
1621
+        if ($lat1 == $lat2 && $lon1 == $lon2) {
1622
+                    return null;
1623
+        }
1624
+        if ($lat1 == $lat2) {
1625
+            $lat1 += 0.0000166;
1626
+        }
1627
+        if ($lon1 == $lon2) {
1628
+            $lon1 += 0.0000166;
1629
+        }
1588 1630
 
1589 1631
         $rad_lat1 = $lat1 / 180.0 * 3.14159;
1590 1632
         $rad_lon1 = $lon1 / 180.0 * 3.14159;
@@ -1595,7 +1637,9 @@  discard block
 block discarded – undo
1595 1637
         $bearing = atan2(sin($delta_lon) * cos($rad_lat2),
1596 1638
             cos($rad_lat1) * sin($rad_lat2) - sin($rad_lat1) * cos($rad_lat2) * cos($delta_lon));
1597 1639
         $bearing = 180.0 * $bearing / 3.14159;
1598
-        if ( $bearing < 0.0 ) $bearing = $bearing + 360.0;
1640
+        if ( $bearing < 0.0 ) {
1641
+            $bearing = $bearing + 360.0;
1642
+        }
1599 1643
 
1600 1644
         return $bearing;
1601 1645
     }
@@ -1604,7 +1648,9 @@  discard block
 block discarded – undo
1604 1648
     public static function bearing_as_two_letters($b)
1605 1649
     {
1606 1650
         static $names = array('N', 'NE', 'E', 'SE', 'S', 'SW', 'W', 'NW');
1607
-        if ($b === null) return 'n/a';
1651
+        if ($b === null) {
1652
+            return 'n/a';
1653
+        }
1608 1654
         return $names[round(($b / 360.0) * 8.0) % 8];
1609 1655
     }
1610 1656
 
@@ -1613,7 +1659,9 @@  discard block
 block discarded – undo
1613 1659
     {
1614 1660
         static $names = array('N', 'NNE', 'NE', 'ENE', 'E', 'ESE', 'SE', 'SSE',
1615 1661
             'S', 'SSW', 'SW', 'WSW', 'W', 'WNW', 'NW', 'NNW');
1616
-        if ($b === null) return 'n/a';
1662
+        if ($b === null) {
1663
+            return 'n/a';
1664
+        }
1617 1665
         return $names[round(($b / 360.0) * 16.0) % 16];
1618 1666
     }
1619 1667
 
@@ -1641,46 +1689,48 @@  discard block
 block discarded – undo
1641 1689
             return $object;
1642 1690
         }
1643 1691
         $format = $request->get_parameter('format');
1644
-        if ($format == null) $format = 'json';
1645
-        if (!in_array($format, array('json', 'jsonp', 'xmlmap', 'xmlmap2')))
1646
-            throw new InvalidParam('format', "'$format'");
1692
+        if ($format == null) {
1693
+            $format = 'json';
1694
+        }
1695
+        if (!in_array($format, array('json', 'jsonp', 'xmlmap', 'xmlmap2'))) {
1696
+                    throw new InvalidParam('format', "'$format'");
1697
+        }
1647 1698
         $callback = $request->get_parameter('callback');
1648
-        if ($callback && $format != 'jsonp')
1649
-            throw new BadRequest("The 'callback' parameter is reserved to be used with the JSONP output format.");
1699
+        if ($callback && $format != 'jsonp') {
1700
+                    throw new BadRequest("The 'callback' parameter is reserved to be used with the JSONP output format.");
1701
+        }
1650 1702
         if ($format == 'json')
1651 1703
         {
1652 1704
             $response = new OkapiHttpResponse();
1653 1705
             $response->content_type = "application/json; charset=utf-8";
1654 1706
             $response->body = json_encode($object);
1655 1707
             return $response;
1656
-        }
1657
-        elseif ($format == 'jsonp')
1708
+        } elseif ($format == 'jsonp')
1658 1709
         {
1659
-            if (!$callback)
1660
-                throw new BadRequest("'callback' parameter is required for JSONP calls");
1661
-            if (!preg_match("/^[a-zA-Z_][a-zA-Z0-9_]*$/", $callback))
1662
-                throw new InvalidParam('callback', "'$callback' doesn't seem to be a valid JavaScript function name (should match /^[a-zA-Z_][a-zA-Z0-9_]*\$/).");
1710
+            if (!$callback) {
1711
+                            throw new BadRequest("'callback' parameter is required for JSONP calls");
1712
+            }
1713
+            if (!preg_match("/^[a-zA-Z_][a-zA-Z0-9_]*$/", $callback)) {
1714
+                            throw new InvalidParam('callback', "'$callback' doesn't seem to be a valid JavaScript function name (should match /^[a-zA-Z_][a-zA-Z0-9_]*\$/).");
1715
+            }
1663 1716
             $response = new OkapiHttpResponse();
1664 1717
             $response->content_type = "application/javascript; charset=utf-8";
1665 1718
             $response->body = $callback."(".json_encode($object).");";
1666 1719
             return $response;
1667
-        }
1668
-        elseif ($format == 'xmlmap')
1720
+        } elseif ($format == 'xmlmap')
1669 1721
         {
1670 1722
             # Deprecated (see issue 128). Keeping this for backward-compatibility.
1671 1723
             $response = new OkapiHttpResponse();
1672 1724
             $response->content_type = "text/xml; charset=utf-8";
1673 1725
             $response->body = self::xmlmap_dumps($object);
1674 1726
             return $response;
1675
-        }
1676
-        elseif ($format == 'xmlmap2')
1727
+        } elseif ($format == 'xmlmap2')
1677 1728
         {
1678 1729
             $response = new OkapiHttpResponse();
1679 1730
             $response->content_type = "text/xml; charset=utf-8";
1680 1731
             $response->body = self::xmlmap2_dumps($object);
1681 1732
             return $response;
1682
-        }
1683
-        else
1733
+        } else
1684 1734
         {
1685 1735
             # Should not happen (as we do a proper check above).
1686 1736
             throw new Exception();
@@ -1694,24 +1744,19 @@  discard block
 block discarded – undo
1694 1744
             $chunks[] = "<string>";
1695 1745
             $chunks[] = self::xmlescape($obj);
1696 1746
             $chunks[] = "</string>";
1697
-        }
1698
-        elseif (is_int($obj))
1747
+        } elseif (is_int($obj))
1699 1748
         {
1700 1749
             $chunks[] = "<int>$obj</int>";
1701
-        }
1702
-        elseif (is_float($obj))
1750
+        } elseif (is_float($obj))
1703 1751
         {
1704 1752
             $chunks[] = "<float>$obj</float>";
1705
-        }
1706
-        elseif (is_bool($obj))
1753
+        } elseif (is_bool($obj))
1707 1754
         {
1708 1755
             $chunks[] = $obj ? "<bool>true</bool>" : "<bool>false</bool>";
1709
-        }
1710
-        elseif (is_null($obj))
1756
+        } elseif (is_null($obj))
1711 1757
         {
1712 1758
             $chunks[] = "<null/>";
1713
-        }
1714
-        elseif (is_array($obj))
1759
+        } elseif (is_array($obj))
1715 1760
         {
1716 1761
             # Have to check if this is associative or not! Shit. I hate PHP.
1717 1762
             if (array_keys($obj) === range(0, count($obj) - 1))
@@ -1725,8 +1770,7 @@  discard block
 block discarded – undo
1725 1770
                     $chunks[] = "</item>";
1726 1771
                 }
1727 1772
                 $chunks[] = "</list>";
1728
-            }
1729
-            else
1773
+            } else
1730 1774
             {
1731 1775
                 # Assoc.
1732 1776
                 $chunks[] = "<dict>";
@@ -1738,8 +1782,7 @@  discard block
 block discarded – undo
1738 1782
                 }
1739 1783
                 $chunks[] = "</dict>";
1740 1784
             }
1741
-        }
1742
-        else
1785
+        } else
1743 1786
         {
1744 1787
             # That's a bug.
1745 1788
             throw new Exception("Cannot encode as xmlmap: " + print_r($obj, true));
@@ -1754,24 +1797,19 @@  discard block
 block discarded – undo
1754 1797
             $chunks[] = "<string$attrs>";
1755 1798
             $chunks[] = self::xmlescape($obj);
1756 1799
             $chunks[] = "</string>";
1757
-        }
1758
-        elseif (is_int($obj))
1800
+        } elseif (is_int($obj))
1759 1801
         {
1760 1802
             $chunks[] = "<number$attrs>$obj</number>";
1761
-        }
1762
-        elseif (is_float($obj))
1803
+        } elseif (is_float($obj))
1763 1804
         {
1764 1805
             $chunks[] = "<number$attrs>$obj</number>";
1765
-        }
1766
-        elseif (is_bool($obj))
1806
+        } elseif (is_bool($obj))
1767 1807
         {
1768 1808
             $chunks[] = $obj ? "<boolean$attrs>true</boolean>" : "<boolean$attrs>false</boolean>";
1769
-        }
1770
-        elseif (is_null($obj))
1809
+        } elseif (is_null($obj))
1771 1810
         {
1772 1811
             $chunks[] = "<null$attrs/>";
1773
-        }
1774
-        elseif (is_array($obj) || ($obj instanceof ArrayObject))
1812
+        } elseif (is_array($obj) || ($obj instanceof ArrayObject))
1775 1813
         {
1776 1814
             # Have to check if this is associative or not! Shit. I hate PHP.
1777 1815
             if (is_array($obj) && (array_keys($obj) === range(0, count($obj) - 1)))
@@ -1783,8 +1821,7 @@  discard block
 block discarded – undo
1783 1821
                     self::_xmlmap2_add($chunks, $item_ref, null);
1784 1822
                 }
1785 1823
                 $chunks[] = "</array>";
1786
-            }
1787
-            else
1824
+            } else
1788 1825
             {
1789 1826
                 # Assoc.
1790 1827
                 $chunks[] = "<object$attrs>";
@@ -1794,8 +1831,7 @@  discard block
 block discarded – undo
1794 1831
                 }
1795 1832
                 $chunks[] = "</object>";
1796 1833
             }
1797
-        }
1798
-        else
1834
+        } else
1799 1835
         {
1800 1836
             # That's a bug.
1801 1837
             throw new Exception("Cannot encode as xmlmap2: " . print_r($obj, true));
@@ -1851,8 +1887,9 @@  discard block
 block discarded – undo
1851 1887
     public static function cache_type_name2id($name)
1852 1888
     {
1853 1889
         $ref = &self::$cache_types[Settings::get('OC_BRANCH')];
1854
-        if (isset($ref[$name]))
1855
-            return $ref[$name];
1890
+        if (isset($ref[$name])) {
1891
+                    return $ref[$name];
1892
+        }
1856 1893
         throw new Exception("Method cache_type_name2id called with unsupported cache ".
1857 1894
             "type name '$name'. You should not allow users to submit caches ".
1858 1895
             "of non-primary type.");
@@ -1865,11 +1902,13 @@  discard block
 block discarded – undo
1865 1902
         if ($reversed == null)
1866 1903
         {
1867 1904
             $reversed = array();
1868
-            foreach (self::$cache_types[Settings::get('OC_BRANCH')] as $key => $value)
1869
-                $reversed[$value] = $key;
1905
+            foreach (self::$cache_types[Settings::get('OC_BRANCH')] as $key => $value) {
1906
+                            $reversed[$value] = $key;
1907
+            }
1908
+        }
1909
+        if (isset($reversed[$id])) {
1910
+                    return $reversed[$id];
1870 1911
         }
1871
-        if (isset($reversed[$id]))
1872
-            return $reversed[$id];
1873 1912
         return "Other";
1874 1913
     }
1875 1914
 
@@ -1880,8 +1919,9 @@  discard block
 block discarded – undo
1880 1919
     /** E.g. 'Available' => 1. For unknown names throws an Exception. */
1881 1920
     public static function cache_status_name2id($name)
1882 1921
     {
1883
-        if (isset(self::$cache_statuses[$name]))
1884
-            return self::$cache_statuses[$name];
1922
+        if (isset(self::$cache_statuses[$name])) {
1923
+                    return self::$cache_statuses[$name];
1924
+        }
1885 1925
         throw new Exception("Method cache_status_name2id called with invalid name '$name'.");
1886 1926
     }
1887 1927
 
@@ -1892,11 +1932,13 @@  discard block
 block discarded – undo
1892 1932
         if ($reversed == null)
1893 1933
         {
1894 1934
             $reversed = array();
1895
-            foreach (self::$cache_statuses as $key => $value)
1896
-                $reversed[$value] = $key;
1935
+            foreach (self::$cache_statuses as $key => $value) {
1936
+                            $reversed[$value] = $key;
1937
+            }
1938
+        }
1939
+        if (isset($reversed[$id])) {
1940
+                    return $reversed[$id];
1897 1941
         }
1898
-        if (isset($reversed[$id]))
1899
-            return $reversed[$id];
1900 1942
         return 'Archived';
1901 1943
     }
1902 1944
 
@@ -1914,8 +1956,9 @@  discard block
 block discarded – undo
1914 1956
     /** E.g. 'micro' => 2. For unknown names throw an Exception. */
1915 1957
     public static function cache_size2_to_sizeid($size2)
1916 1958
     {
1917
-        if (isset(self::$cache_sizes[$size2]))
1918
-            return self::$cache_sizes[$size2];
1959
+        if (isset(self::$cache_sizes[$size2])) {
1960
+                    return self::$cache_sizes[$size2];
1961
+        }
1919 1962
         throw new Exception("Method cache_size2_to_sizeid called with invalid size2 '$size2'.");
1920 1963
     }
1921 1964
 
@@ -1926,11 +1969,13 @@  discard block
 block discarded – undo
1926 1969
         if ($reversed == null)
1927 1970
         {
1928 1971
             $reversed = array();
1929
-            foreach (self::$cache_sizes as $key => $value)
1930
-                $reversed[$value] = $key;
1972
+            foreach (self::$cache_sizes as $key => $value) {
1973
+                            $reversed[$value] = $key;
1974
+            }
1975
+        }
1976
+        if (isset($reversed[$id])) {
1977
+                    return $reversed[$id];
1931 1978
         }
1932
-        if (isset($reversed[$id]))
1933
-            return $reversed[$id];
1934 1979
         return "other";
1935 1980
     }
1936 1981
 
@@ -1953,8 +1998,9 @@  discard block
 block discarded – undo
1953 1998
      */
1954 1999
     public static function cache_size2_to_oxsize($size2)
1955 2000
     {
1956
-        if (array_key_exists($size2, self::$cache_OX_sizes))
1957
-            return self::$cache_OX_sizes[$size2];
2001
+        if (array_key_exists($size2, self::$cache_OX_sizes)) {
2002
+                    return self::$cache_OX_sizes[$size2];
2003
+        }
1958 2004
         throw new Exception("Method cache_size2_to_oxsize called with invalid size2 '$size2'.");
1959 2005
     }
1960 2006
 
@@ -1963,12 +2009,24 @@  discard block
 block discarded – undo
1963 2009
      */
1964 2010
     public static function logtypename2id($name)
1965 2011
     {
1966
-        if ($name == 'Found it') return 1;
1967
-        if ($name == "Didn't find it") return 2;
1968
-        if ($name == 'Comment') return 3;
1969
-        if ($name == 'Attended') return 7;
1970
-        if ($name == 'Will attend') return 8;
1971
-        if (($name == 'Needs maintenance') && (Settings::get('OC_BRANCH') == 'oc.pl')) return 5;
2012
+        if ($name == 'Found it') {
2013
+            return 1;
2014
+        }
2015
+        if ($name == "Didn't find it") {
2016
+            return 2;
2017
+        }
2018
+        if ($name == 'Comment') {
2019
+            return 3;
2020
+        }
2021
+        if ($name == 'Attended') {
2022
+            return 7;
2023
+        }
2024
+        if ($name == 'Will attend') {
2025
+            return 8;
2026
+        }
2027
+        if (($name == 'Needs maintenance') && (Settings::get('OC_BRANCH') == 'oc.pl')) {
2028
+            return 5;
2029
+        }
1972 2030
         throw new Exception("logtype2id called with invalid log type argument: $name");
1973 2031
     }
1974 2032
 
@@ -1981,21 +2039,47 @@  discard block
 block discarded – undo
1981 2039
         # These names are officially documented and may never change!
1982 2040
 
1983 2041
         # Primary.
1984
-        if ($id == 1) return "Found it";
1985
-        if ($id == 2) return "Didn't find it";
1986
-        if ($id == 3) return "Comment";
1987
-        if ($id == 7) return "Attended";
1988
-        if ($id == 8) return "Will attend";
2042
+        if ($id == 1) {
2043
+            return "Found it";
2044
+        }
2045
+        if ($id == 2) {
2046
+            return "Didn't find it";
2047
+        }
2048
+        if ($id == 3) {
2049
+            return "Comment";
2050
+        }
2051
+        if ($id == 7) {
2052
+            return "Attended";
2053
+        }
2054
+        if ($id == 8) {
2055
+            return "Will attend";
2056
+        }
1989 2057
 
1990 2058
         # Other.
1991
-        if ($id == 4) return "Moved";
1992
-        if ($id == 5) return "Needs maintenance";
1993
-        if ($id == 6) return "Maintenance performed";
1994
-        if ($id == 9) return "Archived";
1995
-        if ($id == 10) return "Ready to search";
1996
-        if ($id == 11) return "Temporarily unavailable";
1997
-        if ($id == 12) return "OC Team comment";
1998
-        if ($id == 13 || $id == 14) return "Locked";
2059
+        if ($id == 4) {
2060
+            return "Moved";
2061
+        }
2062
+        if ($id == 5) {
2063
+            return "Needs maintenance";
2064
+        }
2065
+        if ($id == 6) {
2066
+            return "Maintenance performed";
2067
+        }
2068
+        if ($id == 9) {
2069
+            return "Archived";
2070
+        }
2071
+        if ($id == 10) {
2072
+            return "Ready to search";
2073
+        }
2074
+        if ($id == 11) {
2075
+            return "Temporarily unavailable";
2076
+        }
2077
+        if ($id == 12) {
2078
+            return "OC Team comment";
2079
+        }
2080
+        if ($id == 13 || $id == 14) {
2081
+            return "Locked";
2082
+        }
1999 2083
 
2000 2084
         # Important: This set is not closed. Other types may be introduced
2001 2085
         # in the future. This has to be documented in the public method
@@ -2047,8 +2131,9 @@  discard block
 block discarded – undo
2047 2131
     function php_ini_get_bytes($variable)
2048 2132
     {
2049 2133
         $value = trim(ini_get($variable));
2050
-        if (!preg_match("/^[0-9]+[KM]?$/", $value))
2051
-            throw new Exception("Unexpected PHP setting: ".$variable. " = ".$value);
2134
+        if (!preg_match("/^[0-9]+[KM]?$/", $value)) {
2135
+                    throw new Exception("Unexpected PHP setting: ".$variable. " = ".$value);
2136
+        }
2052 2137
         $value = str_replace('K', '*1024', $value);
2053 2138
         $value = str_replace('M', '*1024*1024', $value);
2054 2139
         $value = eval('return '.$value.';');
@@ -2116,8 +2201,9 @@  discard block
 block discarded – undo
2116 2201
     /** Do 'set' on many keys at once. */
2117 2202
     public static function set_many($dict, $timeout)
2118 2203
     {
2119
-        if (count($dict) == 0)
2120
-            return;
2204
+        if (count($dict) == 0) {
2205
+                    return;
2206
+        }
2121 2207
         if ($timeout == null)
2122 2208
         {
2123 2209
             # The current cache implementation is ALWAYS persistent, so we will
@@ -2153,15 +2239,18 @@  discard block
 block discarded – undo
2153 2239
                 and expires > now()
2154 2240
         ");
2155 2241
         list($blob, $score) = Db::fetch_row($rs);
2156
-        if (!$blob)
2157
-            return null;
2158
-        if ($score != null)  # Only non-null entries are scored.
2242
+        if (!$blob) {
2243
+                    return null;
2244
+        }
2245
+        if ($score != null) {
2246
+            # Only non-null entries are scored.
2159 2247
         {
2160 2248
             Db::execute("
2161 2249
                 insert into okapi_cache_reads (`cache_key`)
2162 2250
                 values ('".Db::escape_string($key)."')
2163 2251
             ");
2164 2252
         }
2253
+        }
2165 2254
         return unserialize(gzinflate($blob));
2166 2255
     }
2167 2256
 
@@ -2181,8 +2270,7 @@  discard block
 block discarded – undo
2181 2270
             try
2182 2271
             {
2183 2272
                 $dict[$row['key']] = unserialize(gzinflate($row['value']));
2184
-            }
2185
-            catch (ErrorException $e)
2273
+            } catch (ErrorException $e)
2186 2274
             {
2187 2275
                 unset($dict[$row['key']]);
2188 2276
                 Okapi::mail_admins("Debug: Unserialize error",
@@ -2192,10 +2280,11 @@  discard block
 block discarded – undo
2192 2280
                     "Length of data, compressed: ".strlen($row['value']));
2193 2281
             }
2194 2282
         }
2195
-        if (count($dict) < count($keys))
2196
-            foreach ($keys as $key)
2283
+        if (count($dict) < count($keys)) {
2284
+                    foreach ($keys as $key)
2197 2285
                 if (!isset($dict[$key]))
2198 2286
                     $dict[$key] = null;
2287
+        }
2199 2288
         return $dict;
2200 2289
     }
2201 2290
 
@@ -2210,8 +2299,9 @@  discard block
 block discarded – undo
2210 2299
     /** Do 'delete' on many keys at once. */
2211 2300
     public static function delete_many($keys)
2212 2301
     {
2213
-        if (count($keys) == 0)
2214
-            return;
2302
+        if (count($keys) == 0) {
2303
+                    return;
2304
+        }
2215 2305
         Db::execute("
2216 2306
             delete from okapi_cache
2217 2307
             where `key` in ('".implode("','", array_map('\okapi\Db::escape_string', $keys))."')
@@ -2229,8 +2319,9 @@  discard block
 block discarded – undo
2229 2319
     public static function get_file_path($key)
2230 2320
     {
2231 2321
         $filename = Okapi::get_var_dir()."/okapi_filecache_".md5($key);
2232
-        if (!file_exists($filename))
2233
-            return null;
2322
+        if (!file_exists($filename)) {
2323
+                    return null;
2324
+        }
2234 2325
         return $filename;
2235 2326
     }
2236 2327
 
@@ -2316,17 +2407,19 @@  discard block
 block discarded – undo
2316 2407
         $this->consumer = $consumer;
2317 2408
         $this->token = $token;
2318 2409
         $this->parameters = array();
2319
-        foreach ($parameters as $key => $value)
2320
-            if ($value !== null)
2410
+        foreach ($parameters as $key => $value) {
2411
+                    if ($value !== null)
2321 2412
                 $this->parameters[$key] = $value;
2413
+        }
2322 2414
     }
2323 2415
 
2324 2416
     public function get_parameter($name)
2325 2417
     {
2326
-        if (isset($this->parameters[$name]))
2327
-            return $this->parameters[$name];
2328
-        else
2329
-            return null;
2418
+        if (isset($this->parameters[$name])) {
2419
+                    return $this->parameters[$name];
2420
+        } else {
2421
+                    return null;
2422
+        }
2330 2423
     }
2331 2424
 
2332 2425
     public function get_all_parameters_including_unknown()
@@ -2377,7 +2470,9 @@  discard block
 block discarded – undo
2377 2470
                     break;
2378 2471
             }
2379 2472
         }
2380
-        if ($this->opt_min_auth_level === null) throw new Exception("Required 'min_auth_level' option is missing.");
2473
+        if ($this->opt_min_auth_level === null) {
2474
+            throw new Exception("Required 'min_auth_level' option is missing.");
2475
+        }
2381 2476
 
2382 2477
         if ($DEBUG_AS_USERNAME != null)
2383 2478
         {
@@ -2416,24 +2511,23 @@  discard block
 block discarded – undo
2416 2511
 
2417 2512
             list($this->consumer, $this->token) = Okapi::$server->
2418 2513
                 verify_request2($this->request, $this->opt_token_type, $this->opt_min_auth_level == 3);
2419
-            if ($this->get_parameter('consumer_key') && $this->get_parameter('consumer_key') != $this->get_parameter('oauth_consumer_key'))
2420
-                throw new BadRequest("Inproper mixing of authentication types. You used both 'consumer_key' ".
2514
+            if ($this->get_parameter('consumer_key') && $this->get_parameter('consumer_key') != $this->get_parameter('oauth_consumer_key')) {
2515
+                            throw new BadRequest("Inproper mixing of authentication types. You used both 'consumer_key' ".
2421 2516
                     "and 'oauth_consumer_key' parameters (Level 1 and Level 2), but they do not match with ".
2422 2517
                     "each other. Were you trying to hack me? ;)");
2518
+            }
2423 2519
             if ($this->opt_min_auth_level == 3 && !$this->token)
2424 2520
             {
2425 2521
                 throw new BadRequest("This method requires a valid Token to be included (Level 3 ".
2426 2522
                     "Authentication). You didn't provide one.");
2427 2523
             }
2428
-        }
2429
-        else
2524
+        } else
2430 2525
         {
2431 2526
             if ($this->opt_min_auth_level >= 2)
2432 2527
             {
2433 2528
                 throw new BadRequest("This method requires OAuth signature (Level ".
2434 2529
                     $this->opt_min_auth_level." Authentication). You didn't sign your request.");
2435
-            }
2436
-            else
2530
+            } else
2437 2531
             {
2438 2532
                 $consumer_key = $this->get_parameter('consumer_key');
2439 2533
                 if ($consumer_key)
@@ -2443,9 +2537,10 @@  discard block
 block discarded – undo
2443 2537
                         throw new InvalidParam('consumer_key', "Consumer does not exist.");
2444 2538
                     }
2445 2539
                 }
2446
-                if (($this->opt_min_auth_level == 1) && (!$this->consumer))
2447
-                    throw new BadRequest("This method requires the 'consumer_key' argument (Level 1 ".
2540
+                if (($this->opt_min_auth_level == 1) && (!$this->consumer)) {
2541
+                                    throw new BadRequest("This method requires the 'consumer_key' argument (Level 1 ".
2448 2542
                         "Authentication). You didn't provide one.");
2543
+                }
2449 2544
             }
2450 2545
         }
2451 2546
 
@@ -2479,16 +2574,18 @@  discard block
 block discarded – undo
2479 2574
 
2480 2575
             $debug_user_id = Db::select_value("select user_id from user where username='".
2481 2576
                 Db::escape_string($options['DEBUG_AS_USERNAME'])."'");
2482
-            if ($debug_user_id == null)
2483
-                throw new Exception("Invalid user name in DEBUG_AS_USERNAME: '".$options['DEBUG_AS_USERNAME']."'");
2577
+            if ($debug_user_id == null) {
2578
+                            throw new Exception("Invalid user name in DEBUG_AS_USERNAME: '".$options['DEBUG_AS_USERNAME']."'");
2579
+            }
2484 2580
             $this->consumer = new OkapiDebugConsumer();
2485 2581
             $this->token = new OkapiDebugAccessToken($debug_user_id);
2486 2582
         }
2487 2583
 
2488 2584
         # Read the ETag.
2489 2585
 
2490
-        if (isset($_SERVER['HTTP_IF_NONE_MATCH']))
2491
-            $this->etag = $_SERVER['HTTP_IF_NONE_MATCH'];
2586
+        if (isset($_SERVER['HTTP_IF_NONE_MATCH'])) {
2587
+                    $this->etag = $_SERVER['HTTP_IF_NONE_MATCH'];
2588
+        }
2492 2589
     }
2493 2590
 
2494 2591
     private function init_request()
@@ -2536,8 +2633,9 @@  discard block
 block discarded – undo
2536 2633
         # in OKAPI and should be reported back. See issue 85:
2537 2634
         # https://github.com/opencaching/okapi/issues/85
2538 2635
 
2539
-        if (is_array($value))
2540
-            throw new InvalidParam($name, "Make sure you are using '$name' no more than ONCE in your URL.");
2636
+        if (is_array($value)) {
2637
+                    throw new InvalidParam($name, "Make sure you are using '$name' no more than ONCE in your URL.");
2638
+        }
2541 2639
         return $value;
2542 2640
     }
2543 2641
 
Please login to merge, or discard this patch.
htdocs/okapi/services/caches/formatters/garmin.php 2 patches
Unused Use Statements   -5 removed lines patch added patch discarded remove patch
@@ -3,19 +3,14 @@
 block discarded – undo
3 3
 namespace okapi\services\caches\formatters\garmin;
4 4
 
5 5
 
6
-use okapi\Okapi;
7 6
 use okapi\Cache;
8 7
 use okapi\Settings;
9 8
 use okapi\OkapiRequest;
10
-use okapi\OkapiHttpResponse;
11 9
 use okapi\OkapiInternalRequest;
12 10
 use okapi\OkapiServiceRunner;
13 11
 use okapi\OkapiZIPHttpResponse;
14
-use okapi\BadRequest;
15 12
 use okapi\ParamMissing;
16 13
 use okapi\InvalidParam;
17
-use okapi\OkapiAccessToken;
18
-use okapi\services\caches\search\SearchAssistant;
19 14
 
20 15
 use \Exception;
21 16
 use \clsTbsZip;
Please login to merge, or discard this patch.
Braces   +39 added lines, -23 removed lines patch added patch discarded remove patch
@@ -32,22 +32,32 @@  discard block
 block discarded – undo
32 32
     public static function call(OkapiRequest $request)
33 33
     {
34 34
         $cache_codes = $request->get_parameter('cache_codes');
35
-        if ($cache_codes === null) throw new ParamMissing('cache_codes');
35
+        if ($cache_codes === null) {
36
+            throw new ParamMissing('cache_codes');
37
+        }
36 38
 
37 39
         # Issue 106 requires us to allow empty list of cache codes to be passed into this method.
38 40
         # All of the queries below have to be ready for $cache_codes to be empty!
39 41
 
40 42
         $langpref = $request->get_parameter('langpref');
41
-        if (!$langpref) $langpref = "en";
43
+        if (!$langpref) {
44
+            $langpref = "en";
45
+        }
42 46
         $langpref .= "|".Settings::get('SITELANG');
43 47
         $images = $request->get_parameter('images');
44
-        if (!$images) $images = "all";
45
-        if (!in_array($images, array("none", "all", "spoilers", "nonspoilers")))
46
-            throw new InvalidParam('images');
48
+        if (!$images) {
49
+            $images = "all";
50
+        }
51
+        if (!in_array($images, array("none", "all", "spoilers", "nonspoilers"))) {
52
+                    throw new InvalidParam('images');
53
+        }
47 54
         $format = $request->get_parameter('caches_format');
48
-        if (!$format) $format = "gpx";
49
-        if (!in_array($format, array("gpx", "ggz")))
50
-            throw new InvalidParam('caches_format');
55
+        if (!$format) {
56
+            $format = "gpx";
57
+        }
58
+        if (!in_array($format, array("gpx", "ggz"))) {
59
+                    throw new InvalidParam('caches_format');
60
+        }
51 61
 
52 62
         $location_source = $request->get_parameter('location_source');
53 63
         $location_change_prefix = $request->get_parameter('location_change_prefix');
@@ -97,25 +107,29 @@  discard block
 block discarded – undo
97 107
         $caches = OkapiServiceRunner::call('services/caches/geocaches', new OkapiInternalRequest(
98 108
             $request->consumer, $request->token, array('cache_codes' => $cache_codes,
99 109
             'langpref' => $langpref, 'fields' => "images")));
100
-        if (count($caches) > 50)
101
-            throw new InvalidParam('cache_codes', "The maximum number of caches allowed to be downloaded with this method is 50.");
110
+        if (count($caches) > 50) {
111
+                    throw new InvalidParam('cache_codes', "The maximum number of caches allowed to be downloaded with this method is 50.");
112
+        }
102 113
         if ($images != 'none')
103 114
         {
104 115
             $supported_extensions = array('jpg', 'jpeg', 'gif', 'png', 'bmp');
105 116
             foreach ($caches as $cache_code => $dict)
106 117
             {
107 118
                 $imgs = $dict['images'];
108
-                if (count($imgs) == 0)
109
-                    continue;
119
+                if (count($imgs) == 0) {
120
+                                    continue;
121
+                }
110 122
                 $dir = "Garmin/GeocachePhotos/".$cache_code[strlen($cache_code) - 1];
111 123
                 $dir .= "/".$cache_code[strlen($cache_code) - 2];
112 124
                 $dir .= "/".$cache_code;
113 125
                 foreach ($imgs as $no => $img)
114 126
                 {
115
-                    if ($images == 'spoilers' && (!$img['is_spoiler']))
116
-                        continue;
117
-                    if ($images == 'nonspoilers' && $img['is_spoiler'])
118
-                        continue;
127
+                    if ($images == 'spoilers' && (!$img['is_spoiler'])) {
128
+                                            continue;
129
+                    }
130
+                    if ($images == 'nonspoilers' && $img['is_spoiler']) {
131
+                                            continue;
132
+                    }
119 133
                     $tmp = false;
120 134
                     foreach ($supported_extensions as $ext)
121 135
                     {
@@ -125,8 +139,10 @@  discard block
 block discarded – undo
125 139
                             continue;
126 140
                         }
127 141
                     }
128
-                    if (!$tmp)
129
-                        continue;  # unsupported file extension
142
+                    if (!$tmp) {
143
+                                            continue;
144
+                    }
145
+                    # unsupported file extension
130 146
 
131 147
                     if ($img['is_spoiler']) {
132 148
                         $zippath = $dir."/Spoilers/".$img['unique_caption'].".jpg";
@@ -145,8 +161,7 @@  discard block
 block discarded – undo
145 161
                     if (file_exists($syspath))
146 162
                     {
147 163
                         $response->zip->FileAdd($zippath, $syspath, clsTbsZip::TBSZIP_FILE, false);
148
-                    }
149
-                    else
164
+                    } else
150 165
                     {
151 166
                         # If file exists, but does not end with ".jpg", we will create
152 167
                         # JPEG version of it and store it in the cache.
@@ -167,8 +182,7 @@  discard block
 block discarded – undo
167 182
                                         imagejpeg($image);
168 183
                                         $jpeg_contents = ob_get_clean();
169 184
                                         imagedestroy($image);
170
-                                    }
171
-                                    catch (Exception $e)
185
+                                    } catch (Exception $e)
172 186
                                     {
173 187
                                         # GD couldn't parse the file. We will skip it, and cache
174 188
                                         # the "false" value as the contents. This way, we won't
@@ -181,8 +195,10 @@  discard block
 block discarded – undo
181 195
                                 }
182 196
                             }
183 197
                         }
184
-                        if ($jpeg_contents)  # This can be "null" *or* "false"!
198
+                        if ($jpeg_contents) {
199
+                            # This can be "null" *or* "false"!
185 200
                             $response->zip->FileAdd($zippath, $jpeg_contents, clsTbsZip::TBSZIP_STRING, false);
201
+                        }
186 202
                     }
187 203
                 }
188 204
             }
Please login to merge, or discard this patch.
htdocs/okapi/services/caches/geocaches.php 2 patches
Unused Use Statements   -2 removed lines patch added patch discarded remove patch
@@ -13,8 +13,6 @@
 block discarded – undo
13 13
 use okapi\BadRequest;
14 14
 use okapi\OkapiInternalRequest;
15 15
 use okapi\OkapiServiceRunner;
16
-use okapi\OkapiAccessToken;
17
-use okapi\services\caches\search\SearchAssistant;
18 16
 use okapi\services\attrs\AttrHelper;
19 17
 
20 18
 class WebService
Please login to merge, or discard this patch.
Braces   +236 added lines, -171 removed lines patch added patch discarded remove patch
@@ -40,33 +40,42 @@  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');
43
+        if ($cache_codes === null) {
44
+            throw new ParamMissing('cache_codes');
45
+        }
44 46
         if ($cache_codes === "")
45 47
         {
46 48
             # Issue 106 requires us to allow empty list of cache codes to be passed into this method.
47 49
             # All of the queries below have to be ready for $cache_codes to be empty!
48 50
             $cache_codes = array();
51
+        } else {
52
+                    $cache_codes = explode("|", $cache_codes);
49 53
         }
50
-        else
51
-            $cache_codes = explode("|", $cache_codes);
52 54
 
53
-        if ((count($cache_codes) > 500) && (!$request->skip_limits))
54
-            throw new InvalidParam('cache_codes', "Maximum allowed number of referenced ".
55
+        if ((count($cache_codes) > 500) && (!$request->skip_limits)) {
56
+                    throw new InvalidParam('cache_codes', "Maximum allowed number of referenced ".
55 57
                 "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).");
58
+        }
59
+        if (count($cache_codes) != count(array_unique($cache_codes))) {
60
+                    throw new InvalidParam('cache_codes', "Duplicate codes detected (make sure each cache is referenced only once).");
61
+        }
58 62
 
59 63
         $langpref = $request->get_parameter('langpref');
60
-        if (!$langpref) $langpref = "en";
64
+        if (!$langpref) {
65
+            $langpref = "en";
66
+        }
61 67
         $langpref .= "|".Settings::get('SITELANG');
62 68
         $langpref = explode("|", $langpref);
63 69
 
64 70
         $fields = $request->get_parameter('fields');
65
-        if (!$fields) $fields = "code|name|location|type|status";
71
+        if (!$fields) {
72
+            $fields = "code|name|location|type|status";
73
+        }
66 74
         $fields = explode("|", $fields);
67
-        foreach ($fields as $field)
68
-            if (!in_array($field, self::$valid_field_names))
75
+        foreach ($fields as $field) {
76
+                    if (!in_array($field, self::$valid_field_names))
69 77
                 throw new InvalidParam('fields', "'$field' is not a valid field code.");
78
+        }
70 79
 
71 80
         # Some fields need to be temporarily included whenever the "description"
72 81
         # or "attribution_note" field are included. That's a little ugly, but
@@ -94,60 +103,77 @@  discard block
 block discarded – undo
94 103
         }
95 104
 
96 105
         $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');
106
+        if (!$attribution_append) {
107
+            $attribution_append = 'full';
108
+        }
109
+        if (!in_array($attribution_append, array('none', 'static', 'full'))) {
110
+                    throw new InvalidParam('attribution_append');
111
+        }
100 112
 
101 113
         $log_fields = $request->get_parameter('log_fields');
102
-        if (!$log_fields) $log_fields = "uuid|date|user|type|comment";  // validation is done on call
114
+        if (!$log_fields) {
115
+            $log_fields = "uuid|date|user|type|comment";
116
+        }
117
+        // validation is done on call
103 118
 
104 119
         $user_uuid = $request->get_parameter('user_uuid');
105 120
         if ($user_uuid != null)
106 121
         {
107 122
             $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.");
123
+            if ($user_id == null) {
124
+                            throw new InvalidParam('user_uuid', "User not found.");
125
+            }
126
+            if (($request->token != null) && ($request->token->user_id != $user_id)) {
127
+                            throw new InvalidParam('user_uuid', "User does not match the Access Token used.");
128
+            }
129
+        } elseif (($user_uuid == null) && ($request->token != null)) {
130
+                    $user_id = $request->token->user_id;
131
+        } else {
132
+                    $user_id = null;
112 133
         }
113
-        elseif (($user_uuid == null) && ($request->token != null))
114
-            $user_id = $request->token->user_id;
115
-        else
116
-            $user_id = null;
117 134
 
118 135
         $lpc = $request->get_parameter('lpc');
119
-        if ($lpc === null) $lpc = 10;
120
-        if ($lpc == 'all')
121
-            $lpc = null;
122
-        else
136
+        if ($lpc === null) {
137
+            $lpc = 10;
138
+        }
139
+        if ($lpc == 'all') {
140
+                    $lpc = null;
141
+        } else
123 142
         {
124
-            if (!is_numeric($lpc))
125
-                throw new InvalidParam('lpc', "Invalid number: '$lpc'");
143
+            if (!is_numeric($lpc)) {
144
+                            throw new InvalidParam('lpc', "Invalid number: '$lpc'");
145
+            }
126 146
             $lpc = intval($lpc);
127
-            if ($lpc < 0)
128
-                throw new InvalidParam('lpc', "Must be a positive value.");
147
+            if ($lpc < 0) {
148
+                            throw new InvalidParam('lpc', "Must be a positive value.");
149
+            }
129 150
         }
130 151
 
131 152
         if (in_array('distance', $fields) || in_array('bearing', $fields) || in_array('bearing2', $fields)
132 153
             || in_array('bearing3', $fields))
133 154
         {
134 155
             $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.");
156
+            if (!$tmp) {
157
+                            throw new BadRequest("When using 'distance' or 'bearing' fields, you have to supply 'my_location' parameter.");
158
+            }
137 159
             $parts = explode('|', $tmp);
138
-            if (count($parts) != 2)
139
-                throw new InvalidParam('my_location', "Expecting 2 pipe-separated parts, got ".count($parts).".");
160
+            if (count($parts) != 2) {
161
+                            throw new InvalidParam('my_location', "Expecting 2 pipe-separated parts, got ".count($parts).".");
162
+            }
140 163
             foreach ($parts as &$part_ref)
141 164
             {
142
-                if (!preg_match("/^-?[0-9]+(\.?[0-9]*)$/", $part_ref))
143
-                    throw new InvalidParam('my_location', "'$part_ref' is not a valid float number.");
165
+                if (!preg_match("/^-?[0-9]+(\.?[0-9]*)$/", $part_ref)) {
166
+                                    throw new InvalidParam('my_location', "'$part_ref' is not a valid float number.");
167
+                }
144 168
                 $part_ref = floatval($part_ref);
145 169
             }
146 170
             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.");
171
+            if ($center_lat > 90 || $center_lat < -90) {
172
+                            throw new InvalidParam('current_position', "Latitudes have to be within -90..90 range.");
173
+            }
174
+            if ($center_lon > 180 || $center_lon < -180) {
175
+                            throw new InvalidParam('current_position', "Longitudes have to be within -180..180 range.");
176
+            }
151 177
         }
152 178
 
153 179
         if (Settings::get('OC_BRANCH') == 'oc.de')
@@ -181,8 +207,7 @@  discard block
 block discarded – undo
181 207
                     wp_oc in ('".implode("','", array_map('\okapi\Db::escape_string', $cache_codes))."')
182 208
                     and status in (1,2,3)
183 209
             ");
184
-        }
185
-        elseif (Settings::get('OC_BRANCH') == 'oc.pl')
210
+        } elseif (Settings::get('OC_BRANCH') == 'oc.pl')
186 211
         {
187 212
             # PL branch:
188 213
             # - Caches have ratings.
@@ -231,10 +256,11 @@  discard block
 block discarded – undo
231 256
                         $wp_gc = $row['wp_gc_maintained'] ? $row['wp_gc_maintained'] : $row['wp_gc'];
232 257
                         // OC software allows entering anything here, and that's what users do.
233 258
                         // 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;
259
+                        if (preg_match('/^\s*[Gg][Cc][A-Za-z0-9]+\s*$/', $wp_gc)) {
260
+                                                    $entry['gc_code'] = strtoupper(trim($wp_gc));
261
+                        } else {
262
+                                                    $entry['gc_code'] = null;
263
+                        }
238 264
                         unset($wp_gc);
239 265
                         break;
240 266
                     case 'name': $entry['name'] = $row['name']; break;
@@ -312,12 +338,19 @@  discard block
 block discarded – undo
312 338
                         $entry['trip_distance'] = $row['trip_distance'] === null ? null : round($row['trip_distance'],3); break;
313 339
                         break;
314 340
                     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;
341
+                        if ($row['votes'] < 3) {
342
+                            $entry['rating'] = null;
343
+                        } elseif ($row['score'] >= 2.2) {
344
+                            $entry['rating'] = 5.0;
345
+                        } elseif ($row['score'] >= 1.4) {
346
+                            $entry['rating'] = 4.0;
347
+                        } elseif ($row['score'] >= 0.1) {
348
+                            $entry['rating'] = 3.0;
349
+                        } elseif ($row['score'] >= -1.0) {
350
+                            $entry['rating'] = 2.0;
351
+                        } else {
352
+                            $entry['rating'] = 1.0;
353
+                        }
321 354
                         break;
322 355
                     case 'rating_votes': $entry['rating_votes'] = $row['votes'] + 0; break;
323 356
                     case 'recommendations': $entry['recommendations'] = $row['topratings'] + 0; break;
@@ -352,8 +385,9 @@  discard block
 block discarded – undo
352 385
                 }
353 386
             }
354 387
             $results[$row['wp_oc']] = $entry;
355
-            if ($row['listing_outdated'] > 0)
356
-                $outdated_listings[] = $row['wp_oc'];
388
+            if ($row['listing_outdated'] > 0) {
389
+                            $outdated_listings[] = $row['wp_oc'];
390
+            }
357 391
         }
358 392
         Db::free_result($rs);
359 393
 
@@ -367,8 +401,9 @@  discard block
 block discarded – undo
367 401
                 where user_id in ('".implode("','", array_map('\okapi\Db::escape_string', array_values($owner_ids)))."')
368 402
             ");
369 403
             $tmp = array();
370
-            while ($row = Db::fetch_assoc($rs))
371
-                $tmp[$row['user_id']] = $row;
404
+            while ($row = Db::fetch_assoc($rs)) {
405
+                            $tmp[$row['user_id']] = $row;
406
+            }
372 407
             foreach ($results as $cache_code => &$result_ref)
373 408
             {
374 409
                 $row = $tmp[$owner_ids[$cache_code]];
@@ -384,8 +419,9 @@  discard block
 block discarded – undo
384 419
 
385 420
         if (in_array('is_found', $fields))
386 421
         {
387
-            if ($user_id == null)
388
-                throw new BadRequest("Either 'user_uuid' parameter OR Level 3 Authentication is required to access 'is_found' field.");
422
+            if ($user_id == null) {
423
+                            throw new BadRequest("Either 'user_uuid' parameter OR Level 3 Authentication is required to access 'is_found' field.");
424
+            }
389 425
             $tmp = Db::select_column("
390 426
                 select c.wp_oc
391 427
                 from
@@ -401,18 +437,21 @@  discard block
 block discarded – undo
401 437
                     ".((Settings::get('OC_BRANCH') == 'oc.pl') ? "and cl.deleted = 0" : "")."
402 438
             ");
403 439
             $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]);
440
+            foreach ($tmp as $cache_code) {
441
+                            $tmp2[$cache_code] = true;
442
+            }
443
+            foreach ($results as $cache_code => &$result_ref) {
444
+                            $result_ref['is_found'] = isset($tmp2[$cache_code]);
445
+            }
408 446
         }
409 447
 
410 448
         # is_not_found
411 449
 
412 450
         if (in_array('is_not_found', $fields))
413 451
         {
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.");
452
+            if ($user_id == null) {
453
+                            throw new BadRequest("Either 'user_uuid' parameter OR Level 3 Authentication is required to access 'is_not_found' field.");
454
+            }
416 455
             $tmp = Db::select_column("
417 456
                 select c.wp_oc
418 457
                 from
@@ -425,18 +464,21 @@  discard block
 block discarded – undo
425 464
                     ".((Settings::get('OC_BRANCH') == 'oc.pl') ? "and cl.deleted = 0" : "")."
426 465
             ");
427 466
             $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]);
467
+            foreach ($tmp as $cache_code) {
468
+                            $tmp2[$cache_code] = true;
469
+            }
470
+            foreach ($results as $cache_code => &$result_ref) {
471
+                            $result_ref['is_not_found'] = isset($tmp2[$cache_code]);
472
+            }
432 473
         }
433 474
 
434 475
         # is_watched
435 476
 
436 477
         if (in_array('is_watched', $fields))
437 478
         {
438
-            if ($request->token == null)
439
-                throw new BadRequest("Level 3 Authentication is required to access 'is_watched' field.");
479
+            if ($request->token == null) {
480
+                            throw new BadRequest("Level 3 Authentication is required to access 'is_watched' field.");
481
+            }
440 482
             $tmp = Db::select_column("
441 483
                 select c.wp_oc
442 484
                 from
@@ -447,8 +489,9 @@  discard block
 block discarded – undo
447 489
                     and cw.user_id = '".Db::escape_string($request->token->user_id)."'
448 490
             ");
449 491
             $tmp2 = array();
450
-            foreach ($tmp as $cache_code)
451
-                $tmp2[$cache_code] = true;
492
+            foreach ($tmp as $cache_code) {
493
+                            $tmp2[$cache_code] = true;
494
+            }
452 495
 
453 496
             # OCDE caches can also be indirectly watched by watching cache lists:
454 497
             if (Settings::get('OC_BRANCH') == 'oc.de')
@@ -464,20 +507,23 @@  discard block
 block discarded – undo
464 507
                       and clw.cache_list_id = cli.cache_list_id
465 508
                       and clw.user_id = '".Db::escape_string($request->token->user_id)."'
466 509
               ");
467
-              foreach ($tmp as $cache_code)
468
-                  $tmp2[$cache_code] = true;
510
+              foreach ($tmp as $cache_code) {
511
+                                $tmp2[$cache_code] = true;
512
+              }
469 513
             }
470 514
 
471
-            foreach ($results as $cache_code => &$result_ref)
472
-                $result_ref['is_watched'] = isset($tmp2[$cache_code]);
515
+            foreach ($results as $cache_code => &$result_ref) {
516
+                            $result_ref['is_watched'] = isset($tmp2[$cache_code]);
517
+            }
473 518
         }
474 519
 
475 520
         # is_ignored
476 521
 
477 522
         if (in_array('is_ignored', $fields))
478 523
         {
479
-            if ($request->token == null)
480
-                throw new BadRequest("Level 3 Authentication is required to access 'is_ignored' field.");
524
+            if ($request->token == null) {
525
+                            throw new BadRequest("Level 3 Authentication is required to access 'is_ignored' field.");
526
+            }
481 527
             $tmp = Db::select_column("
482 528
                 select c.wp_oc
483 529
                 from
@@ -488,10 +534,12 @@  discard block
 block discarded – undo
488 534
                     and ci.user_id = '".Db::escape_string($request->token->user_id)."'
489 535
             ");
490 536
             $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]);
537
+            foreach ($tmp as $cache_code) {
538
+                            $tmp2[$cache_code] = true;
539
+            }
540
+            foreach ($results as $cache_code => &$result_ref) {
541
+                            $result_ref['is_ignored'] = isset($tmp2[$cache_code]);
542
+            }
495 543
         }
496 544
 
497 545
         # Descriptions and hints.
@@ -579,27 +627,31 @@  discard block
 block discarded – undo
579 627
             foreach (array(
580 628
                 'short_description', 'short_descriptions', 'description', 'descriptions',
581 629
                 'hint', 'hints', 'hint2', 'hints2'
582
-            ) as $field)
583
-                if (!in_array($field, $fields))
630
+            ) as $field) {
631
+                            if (!in_array($field, $fields))
584 632
                     foreach ($results as &$result_ref)
585 633
                         unset($result_ref[$field]);
634
+            }
586 635
         }
587 636
 
588 637
         # Images.
589 638
 
590 639
         if (in_array('images', $fields) || in_array('preview_image', $fields))
591 640
         {
592
-            if (in_array('images', $fields))
593
-                foreach ($results as &$result_ref)
641
+            if (in_array('images', $fields)) {
642
+                            foreach ($results as &$result_ref)
594 643
                     $result_ref['images'] = array();
595
-            if (in_array('preview_image', $fields))
596
-                foreach ($results as &$result_ref)
644
+            }
645
+            if (in_array('preview_image', $fields)) {
646
+                            foreach ($results as &$result_ref)
597 647
                     $result_ref['preview_image'] = null;
648
+            }
598 649
 
599
-            if (Db::field_exists('pictures', 'mappreview'))
600
-                $preview_field = "mappreview";
601
-            else
602
-                $preview_field = "0";
650
+            if (Db::field_exists('pictures', 'mappreview')) {
651
+                            $preview_field = "mappreview";
652
+            } else {
653
+                            $preview_field = "0";
654
+            }
603 655
             $rs = Db::query("
604 656
                 select object_id, uuid, url, title, spoiler, ".$preview_field." as preview
605 657
                 from pictures
@@ -635,10 +687,12 @@  discard block
 block discarded – undo
635 687
                     'unique_caption' => self::get_unique_caption($row['title']),
636 688
                     'is_spoiler' => ($row['spoiler'] ? true : false),
637 689
                 );
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;
690
+                if (in_array('images', $fields)) {
691
+                                    $results[$cache_code]['images'][] = $image;
692
+                }
693
+                if ($row['preview'] != 0 && in_array('preview_image', $fields)) {
694
+                                    $results[$cache_code]['preview_image'] = $image;
695
+                }
642 696
             }
643 697
         }
644 698
 
@@ -653,8 +707,9 @@  discard block
 block discarded – undo
653 707
             {
654 708
                 $fields_to_remove_later[] = 'attr_acodes';
655 709
             }
656
-            foreach ($results as &$result_ref)
657
-                $result_ref['attr_acodes'] = array();
710
+            foreach ($results as &$result_ref) {
711
+                            $result_ref['attr_acodes'] = array();
712
+            }
658 713
 
659 714
             # Load internal_attr_id => acode mapping.
660 715
 
@@ -687,8 +742,9 @@  discard block
 block discarded – undo
687 742
                 foreach ($results as &$result_ref)
688 743
                 {
689 744
                     $result_ref['attrnames'] = array();
690
-                    foreach ($result_ref['attr_acodes'] as $acode)
691
-                        $result_ref['attrnames'][] = $acode2bestname[$acode];
745
+                    foreach ($result_ref['attr_acodes'] as $acode) {
746
+                                            $result_ref['attrnames'][] = $acode2bestname[$acode];
747
+                    }
692 748
                 }
693 749
             }
694 750
         }
@@ -697,8 +753,9 @@  discard block
 block discarded – undo
697 753
 
698 754
         if (in_array('latest_logs', $fields))
699 755
         {
700
-            foreach ($results as &$result_ref)
701
-                $result_ref['latest_logs'] = array();
756
+            foreach ($results as &$result_ref) {
757
+                            $result_ref['latest_logs'] = array();
758
+            }
702 759
 
703 760
             # Get all log IDs in proper order, then filter out the latest
704 761
             # ones. This should be the fastest technique ...
@@ -732,8 +789,9 @@  discard block
 block discarded – undo
732 789
             {
733 790
                 # User wants some of the latest logs.
734 791
                 $tmp = array();
735
-                while ($row = Db::fetch_assoc($rs))
736
-                    $tmp[$row['cache_id']][] = $row;
792
+                while ($row = Db::fetch_assoc($rs)) {
793
+                                    $tmp[$row['cache_id']][] = $row;
794
+                }
737 795
                 foreach ($tmp as $cache_key => &$rowslist_ref)
738 796
                 {
739 797
                     for ($i = 0; $i < min(count($rowslist_ref), $lpc); $i++)
@@ -742,8 +800,7 @@  discard block
 block discarded – undo
742 800
                         $log2cache_map[$rowslist_ref[$i]['uuid']] = $cacheid2wptcode[$rowslist_ref[$i]['cache_id']];
743 801
                     }
744 802
                 }
745
-            }
746
-            else
803
+            } else
747 804
             {
748 805
                 # User wants ALL logs.
749 806
                 while ($row = Db::fetch_assoc($rs))
@@ -773,18 +830,17 @@  discard block
 block discarded – undo
773 830
                     );
774 831
                     foreach ($subset as $log_uuid)
775 832
                     {
776
-                        if ($entries[$log_uuid])
777
-                            $results[$log2cache_map[$log_uuid]]['latest_logs'][] = $entries[$log_uuid];
833
+                        if ($entries[$log_uuid]) {
834
+                                                    $results[$log2cache_map[$log_uuid]]['latest_logs'][] = $entries[$log_uuid];
835
+                        }
778 836
                     }
779 837
                 }
780
-            }
781
-            catch (Exception $e)
838
+            } catch (Exception $e)
782 839
             {
783 840
                 if (($e instanceof InvalidParam) && ($e->paramName == 'fields'))
784 841
                 {
785 842
                     throw new InvalidParam('log_fields', $e->whats_wrong_about_it);
786
-                }
787
-                else
843
+                } else
788 844
                 {
789 845
                     /* Something is wrong with OUR code. */
790 846
                     throw new Exception($e);
@@ -796,10 +852,12 @@  discard block
 block discarded – undo
796 852
 
797 853
         if (in_array('my_notes', $fields))
798 854
         {
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;
855
+            if ($request->token == null) {
856
+                            throw new BadRequest("Level 3 Authentication is required to access 'my_notes' field.");
857
+            }
858
+            foreach ($results as &$result_ref) {
859
+                            $result_ref['my_notes'] = null;
860
+            }
803 861
             if (Settings::get('OC_BRANCH') == 'oc.pl')
804 862
             {
805 863
                 # OCPL uses cache_notes table to store notes.
@@ -812,8 +870,7 @@  discard block
 block discarded – undo
812 870
                         and user_id = '".Db::escape_string($request->token->user_id)."'
813 871
                     group by cache_id
814 872
                 ");
815
-            }
816
-            else
873
+            } else
817 874
             {
818 875
                 # OCDE uses coordinates table (with type == 2) to store notes (this is somewhat weird).
819 876
 
@@ -852,13 +909,15 @@  discard block
 block discarded – undo
852 909
                     and gkiw.wp in ('".implode("','", array_map('\okapi\Db::escape_string', $cache_codes))."')
853 910
             ");
854 911
             $trs = array();
855
-            while ($row = Db::fetch_assoc($rs))
856
-                $trs[$row['cache_code']][] = $row;
912
+            while ($row = Db::fetch_assoc($rs)) {
913
+                            $trs[$row['cache_code']][] = $row;
914
+            }
857 915
             foreach ($results as $cache_code => &$result_ref)
858 916
             {
859 917
                 $result_ref['trackables'] = array();
860
-                if (!isset($trs[$cache_code]))
861
-                    continue;
918
+                if (!isset($trs[$cache_code])) {
919
+                                    continue;
920
+                }
862 921
                 foreach ($trs[$cache_code] as $t)
863 922
                 {
864 923
                     $result_ref['trackables'][] = array(
@@ -875,10 +934,10 @@  discard block
 block discarded – undo
875 934
             if (in_array('trackables', $fields))
876 935
             {
877 936
                 # 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
937
+                foreach ($results as $cache_code => &$result_ref) {
938
+                                    $result_ref['trackables_count'] = count($result_ref['trackables']);
939
+                }
940
+            } else
882 941
             {
883 942
                 $rs = Db::query("
884 943
                     select wp as cache_code, count(*) as count
@@ -887,14 +946,16 @@  discard block
 block discarded – undo
887 946
                     group by wp
888 947
                 ");
889 948
                 $tr_counts = new ArrayObject();
890
-                while ($row = Db::fetch_assoc($rs))
891
-                    $tr_counts[$row['cache_code']] = $row['count'];
949
+                while ($row = Db::fetch_assoc($rs)) {
950
+                                    $tr_counts[$row['cache_code']] = $row['count'];
951
+                }
892 952
                 foreach ($results as $cache_code => &$result_ref)
893 953
                 {
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;
954
+                    if (isset($tr_counts[$cache_code])) {
955
+                                            $result_ref['trackables_count'] = $tr_counts[$cache_code] + 0;
956
+                    } else {
957
+                                            $result_ref['trackables_count'] = 0;
958
+                    }
898 959
                 }
899 960
                 unset($tr_counts);
900 961
             }
@@ -916,11 +977,11 @@  discard block
 block discarded – undo
916 977
                         coordinates_type ct
917 978
                         left join sys_trans_text stt on stt.trans_id = ct.trans_id
918 979
                 ");
919
-                while ($row = Db::fetch_assoc($rs))
920
-                    $internal_wpt_type_id2names[$row['id']][$row['language']] = $row['text'];
980
+                while ($row = Db::fetch_assoc($rs)) {
981
+                                    $internal_wpt_type_id2names[$row['id']][$row['language']] = $row['text'];
982
+                }
921 983
                 Db::free_result($rs);
922
-            }
923
-            else
984
+            } else
924 985
             {
925 986
                 $rs = Db::query("
926 987
                     select id, pl, en
@@ -934,8 +995,9 @@  discard block
 block discarded – undo
934 995
                 }
935 996
             }
936 997
 
937
-            foreach ($results as &$result_ref)
938
-                $result_ref['alt_wpts'] = array();
998
+            foreach ($results as &$result_ref) {
999
+                            $result_ref['alt_wpts'] = array();
1000
+            }
939 1001
             $cache_codes_escaped_and_imploded = "'".implode("','", array_map('\okapi\Db::escape_string', array_keys($cacheid2wptcode)))."'";
940 1002
 
941 1003
             if (Settings::get('OC_BRANCH') == 'oc.pl')
@@ -970,8 +1032,7 @@  discard block
 block discarded – undo
970 1032
                         and status = 1
971 1033
                     order by cache_id, stage, `desc`
972 1034
                 ");
973
-            }
974
-            else
1035
+            } else
975 1036
             {
976 1037
                 # OCDE uses 'coordinates' table (with type=1) to store additional waypoints
977 1038
                 # and defines waypoint types in 'coordinates_type' table.
@@ -1117,8 +1178,9 @@  discard block
 block discarded – undo
1117 1178
                         c.wp_oc in ('".implode("','", array_map('\okapi\Db::escape_string', $cache_codes))."')
1118 1179
                 ");
1119 1180
                 $country_codes2names = array();
1120
-                while ($row = Db::fetch_assoc($rs))
1121
-                    $country_codes2names[$row['country']][$row['language']] = $row['text'];
1181
+                while ($row = Db::fetch_assoc($rs)) {
1182
+                                    $country_codes2names[$row['country']][$row['language']] = $row['text'];
1183
+                }
1122 1184
                 Db::free_result($rs);
1123 1185
 
1124 1186
                 # get geocache countries and states
@@ -1135,15 +1197,15 @@  discard block
 block discarded – undo
1135 1197
                 ");
1136 1198
                 while ($row = Db::fetch_assoc($rs))
1137 1199
                 {
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);
1200
+                    if (!isset($country_codes2names[$row['country_code']])) {
1201
+                                            $countries[$row['cache_code']] = '';
1202
+                    } else {
1203
+                                            $countries[$row['cache_code']] = Okapi::pick_best_language($country_codes2names[$row['country_code']], $langpref);
1204
+                    }
1142 1205
                     $states[$row['cache_code']] = $row['state'];
1143 1206
                 }
1144 1207
                 Db::free_result($rs);
1145
-            }
1146
-            else
1208
+            } else
1147 1209
             {
1148 1210
                 # OCPL:
1149 1211
                 #  - cache_location data is entered by the user.
@@ -1172,13 +1234,15 @@  discard block
 block discarded – undo
1172 1234
 
1173 1235
             if (in_array('country', $fields))
1174 1236
             {
1175
-                foreach ($results as $cache_code => &$row_ref)
1176
-                    $row_ref['country'] = isset($countries[$cache_code]) ? $countries[$cache_code] : null;
1237
+                foreach ($results as $cache_code => &$row_ref) {
1238
+                                    $row_ref['country'] = isset($countries[$cache_code]) ? $countries[$cache_code] : null;
1239
+                }
1177 1240
             }
1178 1241
             if (in_array('state', $fields))
1179 1242
             {
1180
-                foreach ($results as $cache_code => &$row_ref)
1181
-                    $row_ref['state'] = isset($states[$cache_code]) ? $states[$cache_code] : null;
1243
+                foreach ($results as $cache_code => &$row_ref) {
1244
+                                    $row_ref['state'] = isset($states[$cache_code]) ? $states[$cache_code] : null;
1245
+                }
1182 1246
             }
1183 1247
             unset($countries);
1184 1248
             unset($states);
@@ -1191,12 +1255,13 @@  discard block
 block discarded – undo
1191 1255
             /* Note, that the "owner" and "internal_id" fields are automatically included,
1192 1256
              * whenever the attribution_note is included. */
1193 1257
 
1194
-            foreach ($results as $cache_code => &$result_ref)
1195
-                $result_ref['attribution_note'] =
1258
+            foreach ($results as $cache_code => &$result_ref) {
1259
+                            $result_ref['attribution_note'] =
1196 1260
                     self::get_cache_attribution_note(
1197 1261
                         $result_ref['internal_id'], $langpref[0], $langpref,
1198 1262
                         $results[$cache_code]['owner'], 'full'
1199 1263
                     );
1264
+            }
1200 1265
         }
1201 1266
 
1202 1267
         # Protection areas
@@ -1222,8 +1287,7 @@  discard block
 block discarded – undo
1222 1287
                     group by npa_areas.type_id, npa_areas.name
1223 1288
                     order by npa_types.ordinal
1224 1289
                 ");
1225
-            }
1226
-            else if (in_array(Okapi::get_oc_schema_code(), array("OCPL", "OCNL")))
1290
+            } else if (in_array(Okapi::get_oc_schema_code(), array("OCPL", "OCNL")))
1227 1291
             {
1228 1292
                 # Current OCPL table definitions use collation 'latin1' for parkipl
1229 1293
                 # and 'utf8' for np_areas. Union needs identical collations.
@@ -1255,8 +1319,7 @@  discard block
 block discarded – undo
1255 1319
                         c.cache_id in (".$cache_ids_escaped_and_imploded.")
1256 1320
                         and cache_npa_areas.npa_id != 0
1257 1321
                 ");
1258
-            }
1259
-            else
1322
+            } else
1260 1323
             {
1261 1324
                 # OC.US and .UK do not have a 'parkipl' table.
1262 1325
                 # OC.US has a 'us_parks' table instead.
@@ -1264,8 +1327,9 @@  discard block
 block discarded – undo
1264 1327
                 $rs = null;
1265 1328
             }
1266 1329
 
1267
-            foreach ($results as &$result_ref)
1268
-                $result_ref['protection_areas'] = array();
1330
+            foreach ($results as &$result_ref) {
1331
+                            $result_ref['protection_areas'] = array();
1332
+            }
1269 1333
             if ($rs)
1270 1334
             {
1271 1335
                 while ($row = Db::fetch_assoc($rs))
@@ -1280,18 +1344,20 @@  discard block
 block discarded – undo
1280 1344
         }
1281 1345
 
1282 1346
         # 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]))
1347
+        foreach ($cache_codes as $cache_code) {
1348
+                    if (!isset($results[$cache_code]))
1285 1349
                 $results[$cache_code] = null;
1350
+        }
1286 1351
 
1287 1352
         if (count($fields_to_remove_later) > 0)
1288 1353
         {
1289 1354
             # Some of the fields in $results were added only temporarily
1290 1355
             # (the Consumer did not ask for them). We will remove these fields now.
1291 1356
 
1292
-            foreach ($results as &$result_ref)
1293
-                foreach ($fields_to_remove_later as $field)
1357
+            foreach ($results as &$result_ref) {
1358
+                            foreach ($fields_to_remove_later as $field)
1294 1359
                     unset($result_ref[$field]);
1360
+            }
1295 1361
         }
1296 1362
 
1297 1363
         # Order the results in the same order as the input codes were given.
@@ -1301,8 +1367,9 @@  discard block
 block discarded – undo
1301 1367
         # so we just have to rewrite it (sequentially).
1302 1368
 
1303 1369
         $ordered_results = new ArrayObject();
1304
-        foreach ($cache_codes as $cache_code)
1305
-            $ordered_results[$cache_code] = $results[$cache_code];
1370
+        foreach ($cache_codes as $cache_code) {
1371
+                    $ordered_results[$cache_code] = $results[$cache_code];
1372
+        }
1306 1373
 
1307 1374
         /* Handle OCPL's "access logs" feature. */
1308 1375
 
@@ -1415,8 +1482,7 @@  discard block
 block discarded – undo
1415 1482
                 _("This <a href='%s'>geocache</a> description comes from the <a href='%s'>%s</a> site."),
1416 1483
                 $cache_url, $site_url, $site_name
1417 1484
             );
1418
-        }
1419
-        else
1485
+        } else
1420 1486
         {
1421 1487
             # OC.de wants the tld in lowercase here
1422 1488
             $site_name = ucfirst(strtolower($site_name));
@@ -1430,8 +1496,7 @@  discard block
 block discarded – undo
1430 1496
                     ),
1431 1497
                     $owner['profile_url'], $owner['username'], $cache_url, $site_name, strftime('%x')
1432 1498
                 );
1433
-            }
1434
-            elseif ($type == 'static')
1499
+            } elseif ($type == 'static')
1435 1500
             {
1436 1501
                 $note = sprintf(
1437 1502
                     _(
Please login to merge, or discard this patch.
htdocs/okapi/services/caches/map/replicate_listener.inc.php 2 patches
Unused Use Statements   -10 removed lines patch added patch discarded remove patch
@@ -2,21 +2,11 @@
 block discarded – undo
2 2
 
3 3
 namespace okapi\services\caches\map;
4 4
 
5
-use Exception;
6
-use okapi\Okapi;
7
-use okapi\Settings;
8
-use okapi\Cache;
9 5
 use okapi\Db;
10
-use okapi\OkapiRequest;
11
-use okapi\OkapiHttpResponse;
12
-use okapi\ParamMissing;
13 6
 use okapi\InvalidParam;
14
-use okapi\BadRequest;
15
-use okapi\DoesNotExist;
16 7
 use okapi\OkapiInternalRequest;
17 8
 use okapi\OkapiInternalConsumer;
18 9
 use okapi\OkapiServiceRunner;
19
-
20 10
 use okapi\services\caches\map\TileTree;
21 11
 
22 12
 require_once 'tiletree.inc.php';
Please login to merge, or discard this patch.
Braces   +28 added lines, -21 removed lines patch added patch discarded remove patch
@@ -33,10 +33,11 @@  discard block
 block discarded – undo
33 33
         {
34 34
             if ($c['object_type'] == 'geocache')
35 35
             {
36
-                if ($c['change_type'] == 'replace')
37
-                    self::handle_geocache_replace($c);
38
-                else
39
-                    self::handle_geocache_delete($c);
36
+                if ($c['change_type'] == 'replace') {
37
+                                    self::handle_geocache_replace($c);
38
+                } else {
39
+                                    self::handle_geocache_delete($c);
40
+                }
40 41
             }
41 42
         }
42 43
     }
@@ -95,19 +96,18 @@  discard block
 block discarded – undo
95 96
             # Aaah, a new geocache! How nice... ;)
96 97
 
97 98
             self::add_geocache_to_cached_tiles($theirs);
98
-        }
99
-        elseif (($ours[1] != $theirs[1]) || ($ours[2] != $theirs[2]))  # z21x & z21y fields
99
+        } elseif (($ours[1] != $theirs[1]) || ($ours[2] != $theirs[2])) {
100
+            # z21x & z21y fields
100 101
         {
101 102
             # Location changed.
102 103
 
103 104
             self::remove_geocache_from_cached_tiles($ours[0]);
104
-            self::add_geocache_to_cached_tiles($theirs);
105 105
         }
106
-        elseif ($ours != $theirs)
106
+            self::add_geocache_to_cached_tiles($theirs);
107
+        } elseif ($ours != $theirs)
107 108
         {
108 109
             self::update_geocache_attributes_in_cached_tiles($theirs);
109
-        }
110
-        else
110
+        } else
111 111
         {
112 112
             # No need to update anything. This is very common (i.e. when the
113 113
             # cache was simply found, not actually changed). Replicate module generates
@@ -154,10 +154,13 @@  discard block
 block discarded – undo
154 154
             # go with the simple approach and check all 1+8 bordering tiles.
155 155
 
156 156
             $tiles_in_this_region = array();
157
-            for ($x=$ex-1; $x<=$ex+1; $x++)
158
-                for ($y=$ey-1; $y<=$ey+1; $y++)
159
-                    if (($x >= 0) && ($x < 1<<$zoom) && ($y >= 0) && ($y < 1<<$zoom))
157
+            for ($x=$ex-1; $x<=$ex+1; $x++) {
158
+                            for ($y=$ey-1;
159
+            }
160
+            $y<=$ey+1; $y++) {
161
+                                    if (($x >= 0) && ($x < 1<<$zoom) && ($y >= 0) && ($y < 1<<$zoom))
160 162
                         $tiles_in_this_region[] = array($x, $y);
163
+                }
161 164
 
162 165
             foreach ($tiles_in_this_region as $coords)
163 166
             {
@@ -171,14 +174,18 @@  discard block
 block discarded – undo
171 174
                 $top_z21y = ($y << $scale) - $margin;
172 175
                 $bottom_z21y = (($y + 1) << $scale) + $margin;
173 176
 
174
-                if ($z21x < $left_z21x)
175
-                    continue;
176
-                if ($z21x > $right_z21x)
177
-                    continue;
178
-                if ($z21y < $top_z21y)
179
-                    continue;
180
-                if ($z21y > $bottom_z21y)
181
-                    continue;
177
+                if ($z21x < $left_z21x) {
178
+                                    continue;
179
+                }
180
+                if ($z21x > $right_z21x) {
181
+                                    continue;
182
+                }
183
+                if ($z21y < $top_z21y) {
184
+                                    continue;
185
+                }
186
+                if ($z21y > $bottom_z21y) {
187
+                                    continue;
188
+                }
182 189
 
183 190
                 # We found a match. Store it for later.
184 191
 
Please login to merge, or discard this patch.
htdocs/okapi/services/caches/map/tile.php 2 patches
Unused Use Statements   -8 removed lines patch added patch discarded remove patch
@@ -2,26 +2,18 @@
 block discarded – undo
2 2
 
3 3
 namespace okapi\services\caches\map\tile;
4 4
 
5
-use Exception;
6
-use okapi\Okapi;
7 5
 use okapi\Settings;
8 6
 use okapi\Cache;
9
-use okapi\FileCache;
10 7
 use okapi\Db;
11 8
 use okapi\OkapiRequest;
12 9
 use okapi\OkapiHttpResponse;
13 10
 use okapi\ParamMissing;
14 11
 use okapi\InvalidParam;
15 12
 use okapi\BadRequest;
16
-use okapi\DoesNotExist;
17 13
 use okapi\OkapiInternalRequest;
18
-use okapi\OkapiInternalConsumer;
19 14
 use okapi\OkapiServiceRunner;
20
-use okapi\OkapiLock;
21
-
22 15
 use okapi\services\caches\map\TileTree;
23 16
 use okapi\services\caches\map\TileRenderer;
24
-use okapi\services\caches\search\SearchAssistant;
25 17
 use okapi\OkapiConsumer;
26 18
 
27 19
 require_once('tiletree.inc.php');
Please login to merge, or discard this patch.
Braces   +35 added lines, -22 removed lines patch added patch discarded remove patch
@@ -58,11 +58,13 @@  discard block
 block discarded – undo
58 58
     private static function require_uint($request, $name, $min_value = 0)
59 59
     {
60 60
         $val = $request->get_parameter($name);
61
-        if ($val === null)
62
-            throw new ParamMissing($name);
61
+        if ($val === null) {
62
+                    throw new ParamMissing($name);
63
+        }
63 64
         $ret = intval($val);
64
-        if ($ret < 0 || ("$ret" !== $val))
65
-            throw new InvalidParam($name, "Expecting non-negative integer.");
65
+        if ($ret < 0 || ("$ret" !== $val)) {
66
+                    throw new InvalidParam($name, "Expecting non-negative integer.");
67
+        }
66 68
         return $ret;
67 69
     }
68 70
 
@@ -84,14 +86,17 @@  discard block
 block discarded – undo
84 86
         # zoom, x, y - required tile-specific parameters.
85 87
 
86 88
         $zoom = self::require_uint($request, 'z');
87
-        if ($zoom > 21)
88
-            throw new InvalidParam('z', "Maximum value for this parameter is 21.");
89
+        if ($zoom > 21) {
90
+                    throw new InvalidParam('z', "Maximum value for this parameter is 21.");
91
+        }
89 92
         $x = self::require_uint($request, 'x');
90 93
         $y = self::require_uint($request, 'y');
91
-        if ($x >= 1<<$zoom)
92
-            throw new InvalidParam('x', "Should be in 0..".((1<<$zoom) - 1).".");
93
-        if ($y >= 1<<$zoom)
94
-            throw new InvalidParam('y', "Should be in 0..".((1<<$zoom) - 1).".");
94
+        if ($x >= 1<<$zoom) {
95
+                    throw new InvalidParam('x', "Should be in 0..".((1<<$zoom) - 1).".");
96
+        }
97
+        if ($y >= 1<<$zoom) {
98
+                    throw new InvalidParam('y', "Should be in 0..".((1<<$zoom) - 1).".");
99
+        }
95 100
 
96 101
         # Now, we will create a search set (or use one previously created).
97 102
         # Instead of creating a new OkapiInternalRequest object, we will pass
@@ -114,8 +119,9 @@  discard block
 block discarded – undo
114 119
         $rows = array();
115 120
         if ($rs !== null)
116 121
         {
117
-            while ($row = Db::fetch_row($rs))
118
-                $rows[] = $row;
122
+            while ($row = Db::fetch_row($rs)) {
123
+                            $rows[] = $row;
124
+            }
119 125
             unset($row);
120 126
         }
121 127
         OkapiServiceRunner::save_stats_extra("caches/map/tile/checkpointA", null,
@@ -142,8 +148,9 @@  discard block
 block discarded – undo
142 148
                     where user_id = '".Db::escape_string($request->token->user_id)."'
143 149
                 ");
144 150
                 $user['ignored'] = array();
145
-                while (list($cache_id) = Db::fetch_row($rs))
146
-                    $user['ignored'][$cache_id] = true;
151
+                while (list($cache_id) = Db::fetch_row($rs)) {
152
+                                    $user['ignored'][$cache_id] = true;
153
+                }
147 154
 
148 155
                 # Found caches.
149 156
 
@@ -156,8 +163,9 @@  discard block
 block discarded – undo
156 163
                         and ".((Settings::get('OC_BRANCH') == 'oc.pl') ? "deleted = 0" : "true")."
157 164
                 ");
158 165
                 $user['found'] = array();
159
-                while (list($cache_id) = Db::fetch_row($rs))
160
-                    $user['found'][$cache_id] = true;
166
+                while (list($cache_id) = Db::fetch_row($rs)) {
167
+                                    $user['found'][$cache_id] = true;
168
+                }
161 169
 
162 170
                 # Own caches.
163 171
 
@@ -167,8 +175,9 @@  discard block
 block discarded – undo
167 175
                     where user_id = '".Db::escape_string($request->token->user_id)."'
168 176
                 ");
169 177
                 $user['own'] = array();
170
-                while (list($cache_id) = Db::fetch_row($rs))
171
-                    $user['own'][$cache_id] = true;
178
+                while (list($cache_id) = Db::fetch_row($rs)) {
179
+                                    $user['own'][$cache_id] = true;
180
+                }
172 181
 
173 182
                 Cache::set($cache_key, $user, 30);
174 183
             }
@@ -181,10 +190,14 @@  discard block
 block discarded – undo
181 190
                 # to be drawn as found) and the "own" flag (to indicate that
182 191
                 # the current user is the owner).
183 192
 
184
-                if (isset($user['found'][$row_ref[0]]))
185
-                    $row_ref[6] |= TileTree::$FLAG_FOUND;  # $row[6] is "flags"
186
-                if (isset($user['own'][$row_ref[0]]))
187
-                    $row_ref[6] |= TileTree::$FLAG_OWN;  # $row[6] is "flags"
193
+                if (isset($user['found'][$row_ref[0]])) {
194
+                                    $row_ref[6] |= TileTree::$FLAG_FOUND;
195
+                }
196
+                # $row[6] is "flags"
197
+                if (isset($user['own'][$row_ref[0]])) {
198
+                                    $row_ref[6] |= TileTree::$FLAG_OWN;
199
+                }
200
+                # $row[6] is "flags"
188 201
             }
189 202
         }
190 203
 
Please login to merge, or discard this patch.
htdocs/okapi/services/caches/map/tilerenderer.inc.php 2 patches
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -4,7 +4,6 @@
 block discarded – undo
4 4
 
5 5
 use Exception;
6 6
 use okapi\Okapi;
7
-use okapi\Settings;
8 7
 use okapi\Cache;
9 8
 use okapi\Db;
10 9
 use okapi\FileCache; // WRTODO
Please login to merge, or discard this patch.
Braces   +77 added lines, -53 removed lines patch added patch discarded remove patch
@@ -74,23 +74,28 @@  discard block
 block discarded – undo
74 74
     {
75 75
         # Preprocess the rows.
76 76
 
77
-        if ($this->zoom >= 5)
78
-            $this->decide_which_get_captions();
77
+        if ($this->zoom >= 5) {
78
+                    $this->decide_which_get_captions();
79
+        }
79 80
 
80 81
         # Make a background.
81 82
 
82 83
         $this->im = imagecreatetruecolor(256, 256);
83 84
         imagealphablending($this->im, false);
84
-        if ($this->zoom >= 13) $opacity = 15;
85
-        elseif ($this->zoom <= 12) $opacity = max(0, $this->zoom * 2 - 14);
85
+        if ($this->zoom >= 13) {
86
+            $opacity = 15;
87
+        } elseif ($this->zoom <= 12) {
88
+            $opacity = max(0, $this->zoom * 2 - 14);
89
+        }
86 90
         $transparent = imagecolorallocatealpha($this->im, 0, 0, 0, 127 - $opacity);
87 91
         imagefilledrectangle($this->im, 0, 0, 256, 256, $transparent);
88 92
         imagealphablending($this->im, true);
89 93
 
90 94
         # Draw the caches.
91 95
 
92
-        foreach ($this->rows_ref as &$row_ref)
93
-            $this->draw_cache($row_ref);
96
+        foreach ($this->rows_ref as &$row_ref) {
97
+                    $this->draw_cache($row_ref);
98
+        }
94 99
 
95 100
         # Return the result.
96 101
 
@@ -118,13 +123,13 @@  discard block
 block discarded – undo
118 123
                 $cache_key = "tilesrc/".Okapi::$git_revision."/".self::$VERSION."/".$key;
119 124
                 $gd2_path = self::$USE_STATIC_IMAGE_CACHE
120 125
                     ? FileCache::get_file_path($cache_key) : null;
121
-                if ($gd2_path === null)
122
-                    throw new Exception("Not in cache");
126
+                if ($gd2_path === null) {
127
+                                    throw new Exception("Not in cache");
128
+                }
123 129
                 # File cache hit. GD2 files are much faster to read than PNGs.
124 130
                 # This can throw an Exception (see bug#160).
125 131
                 $locmem_cache[$key] = imagecreatefromgd2($gd2_path);
126
-            }
127
-            catch (Exception $e)
132
+            } catch (Exception $e)
128 133
             {
129 134
                 # Miss again (or error decoding). Read the image from PNG.
130 135
 
@@ -132,12 +137,15 @@  discard block
 block discarded – undo
132 137
 
133 138
                 # Apply all wanted effects.
134 139
 
135
-                if ($opacity != 1)
136
-                    self::change_opacity($locmem_cache[$key], $opacity);
137
-                if ($contrast != 0)
138
-                    imagefilter($locmem_cache[$key], IMG_FILTER_CONTRAST, $contrast);
139
-                if ($brightness != 0)
140
-                    imagefilter($locmem_cache[$key], IMG_FILTER_BRIGHTNESS, $brightness);
140
+                if ($opacity != 1) {
141
+                                    self::change_opacity($locmem_cache[$key], $opacity);
142
+                }
143
+                if ($contrast != 0) {
144
+                                    imagefilter($locmem_cache[$key], IMG_FILTER_CONTRAST, $contrast);
145
+                }
146
+                if ($brightness != 0) {
147
+                                    imagefilter($locmem_cache[$key], IMG_FILTER_BRIGHTNESS, $brightness);
148
+                }
141 149
                 if (($r != 0) || ($g != 0) || ($b != 0))
142 150
                 {
143 151
                     imagefilter($locmem_cache[$key], IMG_FILTER_GRAYSCALE);
@@ -182,12 +190,13 @@  discard block
 block discarded – undo
182 190
     {
183 191
         $capt = ($cache_struct[6] & TileTree::$FLAG_DRAW_CAPTION);
184 192
 
185
-        if (($this->zoom <= 8) && (!$capt))
186
-            $this->draw_cache_tiny($cache_struct);
187
-        elseif (($this->zoom <= 13) && (!$capt))
188
-            $this->draw_cache_medium($cache_struct);
189
-        else
190
-            $this->draw_cache_large($cache_struct);
193
+        if (($this->zoom <= 8) && (!$capt)) {
194
+                    $this->draw_cache_tiny($cache_struct);
195
+        } elseif (($this->zoom <= 13) && (!$capt)) {
196
+                    $this->draw_cache_medium($cache_struct);
197
+        } else {
198
+                    $this->draw_cache_large($cache_struct);
199
+        }
191 200
 
192 201
         # Put caption (this flag is set only when there is plenty of space around).
193 202
 
@@ -241,8 +250,9 @@  discard block
 block discarded – undo
241 250
         $markercenter_x = 12;
242 251
         $markercenter_y = 12;
243 252
 
244
-        if ($count > 1)
245
-            imagecopy($this->im, $outer_marker, $px - $center_x + 3, $py - $center_y - 2, 0, 0, $width, $height);
253
+        if ($count > 1) {
254
+                    imagecopy($this->im, $outer_marker, $px - $center_x + 3, $py - $center_y - 2, 0, 0, $width, $height);
255
+        }
246 256
         imagecopy($this->im, $outer_marker, $px - $center_x, $py - $center_y, 0, 0, $width, $height);
247 257
 
248 258
         # Put the inner marker (indicates the type).
@@ -304,8 +314,9 @@  discard block
 block discarded – undo
304 314
         $nextBonus = "";
305 315
         for ($i=0; ($i<count($words)) || (mb_strlen($nextBonus)>0); $i++) {
306 316
             $word = isset($words[$i])?$words[$i]:"";
307
-            if (mb_strlen($nextBonus) > 0)
308
-                $word = $nextBonus." ".$word;
317
+            if (mb_strlen($nextBonus) > 0) {
318
+                            $word = $nextBonus." ".$word;
319
+            }
309 320
             $nextBonus = "";
310 321
             while (true) {
311 322
                 $bbox = imagettfbbox($size, 0, $font, $line.$word);
@@ -324,8 +335,9 @@  discard block
 block discarded – undo
324 335
                 continue;
325 336
             }
326 337
         }
327
-        if (mb_strlen($line) > 0)
328
-            $lines[] = trim($line);
338
+        if (mb_strlen($line) > 0) {
339
+                    $lines[] = trim($line);
340
+        }
329 341
         return implode("\n", $lines);
330 342
     }
331 343
 
@@ -389,9 +401,12 @@  discard block
 block discarded – undo
389 401
             # Draw an outline.
390 402
 
391 403
             $outline_color = imagecolorallocatealpha($im, 255, 255, 255, 80);
392
-            for ($x=0; $x<=12; $x+=3)
393
-                for ($y=$size-3; $y<=$size+9; $y+=3)
394
-                    $drawer($x, $y, $outline_color);
404
+            for ($x=0; $x<=12; $x+=3) {
405
+                            for ($y=$size-3;
406
+            }
407
+            $y<=$size+9; $y+=3) {
408
+                                    $drawer($x, $y, $outline_color);
409
+                }
395 410
 
396 411
             # Add a slight shadow effect (on top of the outline).
397 412
 
@@ -426,10 +441,11 @@  discard block
 block discarded – undo
426 441
         $found = $flags & TileTree::$FLAG_FOUND;
427 442
         $own = $flags & TileTree::$FLAG_OWN;
428 443
         $new = $flags & TileTree::$FLAG_NEW;
429
-        if ($found && (!($flags & TileTree::$FLAG_DRAW_CAPTION)))
430
-            $a = .35;
431
-        else
432
-            $a = 1;
444
+        if ($found && (!($flags & TileTree::$FLAG_DRAW_CAPTION))) {
445
+                    $a = .35;
446
+        } else {
447
+                    $a = 1;
448
+        }
433 449
 
434 450
         # Put the marker (indicates the type).
435 451
 
@@ -445,11 +461,12 @@  discard block
 block discarded – undo
445 461
         {
446 462
             imagecopy($this->im, $marker, $px - $center_x + 3, $py - $center_y - 2, 0, 0, $width, $height);
447 463
             imagecopy($this->im, $marker, $px - $center_x, $py - $center_y, 0, 0, $width, $height);
448
-        }
449
-        elseif ($status == 1)  # don't put the marker for unavailable caches (X only)
464
+        } elseif ($status == 1) {
465
+            # don't put the marker for unavailable caches (X only)
450 466
         {
451 467
             imagecopy($this->im, $marker, $px - $center_x, $py - $center_y, 0, 0, $width, $height);
452 468
         }
469
+        }
453 470
 
454 471
         # If the cache is unavailable, mark it with X.
455 472
 
@@ -485,16 +502,14 @@  discard block
 block discarded – undo
485 502
 
486 503
             $overlay = self::get_image("medium_overlay_own");
487 504
             imagecopy($this->im, $overlay, $px - $center_x, $py - $center_y, 0, 0, $width, $height);
488
-        }
489
-        elseif ($found)
505
+        } elseif ($found)
490 506
         {
491 507
             # Mark found caches with V.
492 508
 
493 509
             $icon = self::get_image("found", 0.7*$a);
494 510
             imagecopy($this->im, $icon, $px - ($center_x - $markercenter_x) - 7,
495 511
                 $py - ($center_y - $markercenter_y) - 9, 0, 0, 16, 16);
496
-        }
497
-        elseif ($new)
512
+        } elseif ($new)
498 513
         {
499 514
             # Mark new caches with additional overlay.
500 515
 
@@ -546,8 +561,7 @@  discard block
 block discarded – undo
546 561
         {
547 562
             imagecopy($this->im, $marker, $px - $center_x + 3, $py - $center_y - 2, 0, 0, $width, $height);
548 563
             imagecopy($this->im, $marker, $px - $center_x, $py - $center_y, 0, 0, $width, $height);
549
-        }
550
-        elseif ($status == 1)
564
+        } elseif ($status == 1)
551 565
         {
552 566
             imagecopy($this->im, $marker, $px - $center_x, $py - $center_y, 0, 0, $width, $height);
553 567
         }
@@ -577,25 +591,33 @@  discard block
 block discarded – undo
577 591
         # This is efficient and yields acceptable results.
578 592
 
579 593
         $matrix = array();
580
-        for ($i=0; $i<12; $i++)
581
-            $matrix[] = array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
594
+        for ($i=0; $i<12; $i++) {
595
+                    $matrix[] = array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
596
+        }
582 597
 
583 598
         foreach ($this->rows_ref as &$row_ref)
584 599
         {
585 600
             $mx = ($row_ref[1] + 64) >> 5;
586 601
             $my = ($row_ref[2] + 64) >> 5;
587
-            if (($mx >= 12) || ($my >= 12)) continue;
588
-            if (($matrix[$mx][$my] === 0) && ($row_ref[8] == 1))  # 8 is count
589
-                $matrix[$mx][$my] = $row_ref[0];  # 0 is cache_id
590
-            else
591
-                $matrix[$mx][$my] = -1;
602
+            if (($mx >= 12) || ($my >= 12)) {
603
+                continue;
604
+            }
605
+            if (($matrix[$mx][$my] === 0) && ($row_ref[8] == 1)) {
606
+                # 8 is count
607
+                $matrix[$mx][$my] = $row_ref[0];
608
+            }
609
+            # 0 is cache_id
610
+            else {
611
+                            $matrix[$mx][$my] = -1;
612
+            }
592 613
         }
593 614
         $selected_cache_ids = array();
594 615
         for ($mx=1; $mx<11; $mx++)
595 616
         {
596 617
             for ($my=1; $my<11; $my++)
597 618
             {
598
-                if ($matrix[$mx][$my] > 0)  # cache_id
619
+                if ($matrix[$mx][$my] > 0) {
620
+                    # cache_id
599 621
                 {
600 622
                     # Check all adjacent squares.
601 623
 
@@ -610,12 +632,14 @@  discard block
 block discarded – undo
610 632
                     )
611 633
                         $selected_cache_ids[] = $matrix[$mx][$my];
612 634
                 }
635
+                }
613 636
             }
614 637
         }
615 638
 
616
-        foreach ($this->rows_ref as &$row_ref)
617
-            if (in_array($row_ref[0], $selected_cache_ids))
639
+        foreach ($this->rows_ref as &$row_ref) {
640
+                    if (in_array($row_ref[0], $selected_cache_ids))
618 641
                 $row_ref[6] |= TileTree::$FLAG_DRAW_CAPTION;
642
+        }
619 643
     }
620 644
 
621 645
 }
622 646
\ No newline at end of file
Please login to merge, or discard this patch.
htdocs/okapi/services/caches/map/tiletree.inc.php 2 patches
Unused Use Statements   -8 removed lines patch added patch discarded remove patch
@@ -4,19 +4,11 @@
 block discarded – undo
4 4
 
5 5
 use Exception;
6 6
 use okapi\Okapi;
7
-use okapi\Settings;
8 7
 use okapi\Cache;
9 8
 use okapi\Db;
10
-use okapi\OkapiRequest;
11
-use okapi\OkapiHttpResponse;
12
-use okapi\ParamMissing;
13
-use okapi\InvalidParam;
14
-use okapi\BadRequest;
15
-use okapi\DoesNotExist;
16 9
 use okapi\OkapiInternalRequest;
17 10
 use okapi\OkapiInternalConsumer;
18 11
 use okapi\OkapiServiceRunner;
19
-use okapi\OkapiLock;
20 12
 
21 13
 
22 14
 class TileTree
Please login to merge, or discard this patch.
Braces   +40 added lines, -22 removed lines patch added patch discarded remove patch
@@ -64,19 +64,23 @@  discard block
 block discarded – undo
64 64
         # (and if it was, was it empty).
65 65
 
66 66
         $status = self::get_tile_status($zoom, $x, $y);
67
-        if ($status === null)  # Not yet computed.
67
+        if ($status === null) {
68
+            # Not yet computed.
68 69
         {
69 70
             # Note, that computing the tile does not involve taking any
70 71
             # search parameters.
71 72
 
72 73
             $status = self::compute_tile($zoom, $x, $y);
73 74
         }
75
+        }
74 76
 
75
-        if ($status === 1)  # Computed and empty.
77
+        if ($status === 1) {
78
+            # Computed and empty.
76 79
         {
77 80
             # This tile was already computed and it is empty.
78 81
             return null;
79 82
         }
83
+        }
80 84
 
81 85
         # If we got here, then the tile is computed and not empty (status 2).
82 86
 
@@ -121,8 +125,9 @@  discard block
 block discarded – undo
121 125
         # For low-level tiles, this can be expensive.
122 126
 
123 127
         $status = self::get_tile_status($zoom, $x, $y);
124
-        if ($status !== null)
125
-            return $status;
128
+        if ($status !== null) {
129
+                    return $status;
130
+        }
126 131
 
127 132
         if ($zoom === 0)
128 133
         {
@@ -174,8 +179,7 @@  discard block
 block discarded – undo
174 179
                 ");
175 180
             }
176 181
             $status = 2;
177
-        }
178
-        else
182
+        } else
179 183
         {
180 184
             # We will use the parent tile to compute the contents of this tile.
181 185
 
@@ -184,19 +188,23 @@  discard block
 block discarded – undo
184 188
             $parent_y = $y >> 1;
185 189
 
186 190
             $status = self::get_tile_status($parent_zoom, $parent_x, $parent_y);
187
-            if ($status === null)  # Not computed.
191
+            if ($status === null) {
192
+                # Not computed.
188 193
             {
189 194
                 $time_started = microtime(true);
195
+            }
190 196
                 $status = self::compute_tile($parent_zoom, $parent_x, $parent_y);
191 197
             }
192 198
 
193
-            if ($status === 1)  # Computed and empty.
199
+            if ($status === 1) {
200
+                # Computed and empty.
194 201
             {
195 202
                 # No need to check.
196 203
             }
197 204
             else  # Computed, not empty.
198 205
             {
199 206
                 $scale = 8 + 21 - $zoom;
207
+            }
200 208
                 $parentcenter_z21x = (($parent_x << 1) | 1) << $scale;
201 209
                 $parentcenter_z21y = (($parent_y << 1) | 1) << $scale;
202 210
                 $margin = 1 << ($scale - 2);
@@ -209,14 +217,20 @@  discard block
 block discarded – undo
209 217
                 # |1 2|
210 218
                 # |3 4|
211 219
 
212
-                if ($x & 1)  # 2 or 4
220
+                if ($x & 1) {
221
+                    # 2 or 4
213 222
                     $left_z21x = $parentcenter_z21x - $margin;
214
-                else  # 1 or 3
223
+                } else {
224
+                    # 1 or 3
215 225
                     $right_z21x = $parentcenter_z21x + $margin;
216
-                if ($y & 1)  # 3 or 4
226
+                }
227
+                if ($y & 1) {
228
+                    # 3 or 4
217 229
                     $top_z21y = $parentcenter_z21y - $margin;
218
-                else  # 1 or 2
230
+                } else {
231
+                    # 1 or 2
219 232
                     $bottom_z21y = $parentcenter_z21y + $margin;
233
+                }
220 234
 
221 235
                 # Cache the result.
222 236
 
@@ -256,10 +270,11 @@  discard block
 block discarded – undo
256 270
                         and y = '".Db::escape_string($y)."'
257 271
                     limit 1;
258 272
                 ");
259
-                if ($test)
260
-                    $status = 2;
261
-                else
262
-                    $status = 1;
273
+                if ($test) {
274
+                                    $status = 2;
275
+                } else {
276
+                                    $status = 1;
277
+                }
263 278
             }
264 279
         }
265 280
 
@@ -294,12 +309,15 @@  discard block
 block discarded – undo
294 309
             return false;
295 310
         }
296 311
         $flags = 0;
297
-        if (($cache['founds'] > 6) && (($cache['recommendations'] / $cache['founds']) > 0.3))
298
-            $flags |= self::$FLAG_STAR;
299
-        if ($cache['trackables_count'] > 0)
300
-            $flags |= self::$FLAG_HAS_TRACKABLES;
301
-        if ($cache['founds'] == 0)
302
-            $flags |= self::$FLAG_NOT_YET_FOUND;
312
+        if (($cache['founds'] > 6) && (($cache['recommendations'] / $cache['founds']) > 0.3)) {
313
+                    $flags |= self::$FLAG_STAR;
314
+        }
315
+        if ($cache['trackables_count'] > 0) {
316
+                    $flags |= self::$FLAG_HAS_TRACKABLES;
317
+        }
318
+        if ($cache['founds'] == 0) {
319
+                    $flags |= self::$FLAG_NOT_YET_FOUND;
320
+        }
303 321
         return array($cache['internal_id'], $z21x, $z21y, Okapi::cache_status_name2id($cache['status']),
304 322
             Okapi::cache_type_name2id($cache['type']), $cache['rating'], $flags,
305 323
             self::compute_name_crc($cache['name']));
Please login to merge, or discard this patch.
htdocs/okapi/services/caches/save_personal_notes.php 2 patches
Unused Use Statements   -4 removed lines patch added patch discarded remove patch
@@ -2,16 +2,12 @@
 block discarded – undo
2 2
 
3 3
 namespace okapi\services\caches\save_personal_notes;
4 4
 
5
-use Exception;
6 5
 use okapi\Okapi;
7 6
 use okapi\Db;
8 7
 use okapi\OkapiRequest;
9 8
 use okapi\ParamMissing;
10
-use okapi\InvalidParam;
11
-use okapi\BadRequest;
12 9
 use okapi\OkapiInternalRequest;
13 10
 use okapi\OkapiServiceRunner;
14
-use okapi\OkapiAccessToken;
15 11
 use okapi\Settings;
16 12
 
17 13
 
Please login to merge, or discard this patch.
Braces   +16 added lines, -12 removed lines patch added patch discarded remove patch
@@ -29,8 +29,9 @@  discard block
 block discarded – undo
29 29
         # Get current notes, and verify cache_code
30 30
 
31 31
         $cache_code = $request->get_parameter('cache_code');
32
-        if ($cache_code == null)
33
-            throw new ParamMissing('cache_code');
32
+        if ($cache_code == null) {
33
+                    throw new ParamMissing('cache_code');
34
+        }
34 35
         $geocache = OkapiServiceRunner::call(
35 36
             'services/caches/geocache',
36 37
             new OkapiInternalRequest($request->consumer, $request->token, array(
@@ -47,14 +48,16 @@  discard block
 block discarded – undo
47 48
         # old_value
48 49
 
49 50
         $old_value = $request->get_parameter('old_value');
50
-        if ($old_value === null)
51
-            $old_value = '';
51
+        if ($old_value === null) {
52
+                    $old_value = '';
53
+        }
52 54
 
53 55
         # new_value (force "no HTML" policy).
54 56
 
55 57
         $new_value = $request->get_parameter('new_value');
56
-        if ($new_value === null)
57
-            throw new ParamMissing('new_value');
58
+        if ($new_value === null) {
59
+                    throw new ParamMissing('new_value');
60
+        }
58 61
 
59 62
         # Force "no HTML" policy.
60 63
 
@@ -98,10 +101,12 @@  discard block
 block discarded – undo
98 101
 
99 102
     private static function str_equals($str1, $str2)
100 103
     {
101
-        if ($str1 == null)
102
-            $str1 = '';
103
-        if ($str2 == null)
104
-            $str2 = '';
104
+        if ($str1 == null) {
105
+                    $str1 = '';
106
+        }
107
+        if ($str2 == null) {
108
+                    $str2 = '';
109
+        }
105 110
         $str1 = mb_ereg_replace("[ \t\n\r\x0B]+", '', $str1);
106 111
         $str2 = mb_ereg_replace("[ \t\n\r\x0B]+", '', $str2);
107 112
 
@@ -151,8 +156,7 @@  discard block
 block discarded – undo
151 156
                         and type = 2
152 157
                 ");
153 158
             }
154
-        }
155
-        else  # oc.pl branch
159
+        } else  # oc.pl branch
156 160
         {
157 161
             $rs = Db::query("
158 162
                 select max(note_id) as id
Please login to merge, or discard this patch.
htdocs/okapi/services/caches/search/save.php 2 patches
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -6,7 +6,6 @@
 block discarded – undo
6 6
 
7 7
 use okapi\Okapi;
8 8
 use okapi\OkapiRequest;
9
-use okapi\ParamMissing;
10 9
 use okapi\InvalidParam;
11 10
 use okapi\Db;
12 11
 use okapi\OkapiLock;
Please login to merge, or discard this patch.
Braces   +24 added lines, -15 removed lines patch added patch discarded remove patch
@@ -39,8 +39,9 @@  discard block
 block discarded – undo
39 39
             order by id desc
40 40
             limit 1
41 41
         ");
42
-        if ($tmp === null)
43
-            return array(null, null, null);
42
+        if ($tmp === null) {
43
+                    return array(null, null, null);
44
+        }
44 45
         return array($tmp['id'], $tmp['date_created'], $tmp['expires']);
45 46
     }
46 47
 
@@ -49,17 +50,25 @@  discard block
 block discarded – undo
49 50
         # "Cache control" parameters.
50 51
 
51 52
         $tmp = $request->get_parameter('min_store');
52
-        if ($tmp === null) $tmp = "300";
53
+        if ($tmp === null) {
54
+            $tmp = "300";
55
+        }
53 56
         $min_store = intval($tmp);
54
-        if (("$min_store" !== $tmp) ||($min_store < 0) || ($min_store > 64800))
55
-            throw new InvalidParam('min_store', "Has to be in the 0..64800 range.");
57
+        if (("$min_store" !== $tmp) ||($min_store < 0) || ($min_store > 64800)) {
58
+                    throw new InvalidParam('min_store', "Has to be in the 0..64800 range.");
59
+        }
56 60
 
57 61
         $tmp = $request->get_parameter('ref_max_age');
58
-        if ($tmp === null) $tmp = "300";
59
-        if ($tmp == "nolimit") $tmp = "9999999";
62
+        if ($tmp === null) {
63
+            $tmp = "300";
64
+        }
65
+        if ($tmp == "nolimit") {
66
+            $tmp = "9999999";
67
+        }
60 68
         $ref_max_age = intval($tmp);
61
-        if (("$ref_max_age" !== $tmp) || ($ref_max_age < 300))
62
-            throw new InvalidParam('ref_max_age', "Has to be >=300.");
69
+        if (("$ref_max_age" !== $tmp) || ($ref_max_age < 300)) {
70
+                    throw new InvalidParam('ref_max_age', "Has to be >=300.");
71
+        }
63 72
 
64 73
         # Search params.
65 74
 
@@ -75,10 +84,11 @@  discard block
 block discarded – undo
75 84
             $search_params['where_conds']
76 85
         );
77 86
 
78
-        if (isset($search_params['extra_joins']) && is_array($search_params['extra_joins']))
79
-            $joins = $search_params['extra_joins'];
80
-        else
81
-            $joins = array();
87
+        if (isset($search_params['extra_joins']) && is_array($search_params['extra_joins'])) {
88
+                    $joins = $search_params['extra_joins'];
89
+        } else {
90
+                    $joins = array();
91
+        }
82 92
 
83 93
         unset($search_params);
84 94
 
@@ -161,8 +171,7 @@  discard block
 block discarded – undo
161 171
                     # generated the result set. We don't need to do anything.
162 172
                 }
163 173
                 $lock->release();
164
-            }
165
-            catch (Exception $e)
174
+            } catch (Exception $e)
166 175
             {
167 176
                 # SQL error? Make sure the lock is released and rethrow.
168 177
 
Please login to merge, or discard this patch.