Completed
Pull Request — master (#313)
by Thomas
15:47 queued 06:00
created
htdocs/okapi/views/tilestress.php 1 patch
Braces   +8 added lines, -7 removed lines patch added patch discarded remove patch
@@ -42,8 +42,7 @@  discard block
 block discarded – undo
42 42
         $user_id = $_GET['u'];
43 43
         self::out("Yo. I'm $user_id.\n\n");
44 44
 
45
-        while (true)
46
-        {
45
+        while (true) {
47 46
             srand(floor(time() / 10));
48 47
             $mode2 = rand(0, 9) <= 7;
49 48
             if ($mode2) {
@@ -66,14 +65,16 @@  discard block
 block discarded – undo
66 65
             }
67 66
 
68 67
             $tiles = array();
69
-            for ($xx=$x; $xx<$x+4; $xx++)
70
-                for ($yy=$y; $yy<$y+4; $yy++)
71
-                    $tiles[] = array($xx, $yy);
68
+            for ($xx=$x; $xx<$x+4; $xx++) {
69
+                            for ($yy=$y;
70
+            }
71
+            $yy<$y+4; $yy++) {
72
+                                    $tiles[] = array($xx, $yy);
73
+                }
72 74
             srand();
73 75
             shuffle($tiles);
74 76
 
75
-            foreach ($tiles as $tile)
76
-            {
77
+            foreach ($tiles as $tile) {
77 78
                 list($x, $y) = $tile;
78 79
                 self::out("Loading ".str_pad("($z, $x, $y)... ", 30));
79 80
                 $time_started = microtime(true);
Please login to merge, or discard this patch.
htdocs/okapi/cronjobs.php 1 patch
Braces   +153 added lines, -115 removed lines patch added patch discarded remove patch
@@ -35,8 +35,7 @@  discard block
 block discarded – undo
35 35
     public static function get_enabled_cronjobs()
36 36
     {
37 37
         static $cache = null;
38
-        if ($cache == null)
39
-        {
38
+        if ($cache == null) {
40 39
             $cache = array(
41 40
                 new OAuthCleanupCronJob(),
42 41
                 new CacheCleanupCronJob(),
@@ -54,9 +53,10 @@  discard block
 block discarded – undo
54 53
                 new SearchSetsCleanerJob(),
55 54
                 new TableOptimizerJob(),
56 55
             );
57
-            foreach ($cache as $cronjob)
58
-                if (!in_array($cronjob->get_type(), array('pre-request', 'cron-5')))
56
+            foreach ($cache as $cronjob) {
57
+                            if (!in_array($cronjob->get_type(), array('pre-request', 'cron-5')))
59 58
                     throw new Exception("Cronjob '".$cronjob->get_name()."' has an invalid (unsupported) type.");
59
+            }
60 60
         }
61 61
         return $cache;
62 62
     }
@@ -74,25 +74,18 @@  discard block
 block discarded – undo
74 74
         $lock->acquire();
75 75
 
76 76
         $schedule = Cache::get("cron_schedule");
77
-        if ($schedule == null)
78
-            $schedule = array();
79
-        foreach (self::get_enabled_cronjobs() as $cronjob)
80
-        {
77
+        if ($schedule == null) {
78
+                    $schedule = array();
79
+        }
80
+        foreach (self::get_enabled_cronjobs() as $cronjob) {
81 81
             $name = $cronjob->get_name();
82
-            if ((!isset($schedule[$name])) || ($schedule[$name] <= time()))
83
-            {
84
-                if ($cronjob->get_type() != $type)
85
-                {
82
+            if ((!isset($schedule[$name])) || ($schedule[$name] <= time())) {
83
+                if ($cronjob->get_type() != $type) {
86 84
                     $next_run = isset($schedule[$name]) ? $schedule[$name] : (time() - 1);
87
-                }
88
-                else
89
-                {
90
-                    try
91
-                    {
85
+                } else {
86
+                    try {
92 87
                         $cronjob->execute();
93
-                    }
94
-                    catch (Exception $e)
95
-                    {
88
+                    } catch (Exception $e) {
96 89
                         Okapi::mail_admins("Cronjob error: ".$cronjob->get_name(),
97 90
                             OkapiExceptionHandler::get_exception_info($e));
98 91
                     }
@@ -106,8 +99,7 @@  discard block
 block discarded – undo
106 99
         # Remove "stale" schedule keys (those which are no longer declared).
107 100
 
108 101
         $fixed_schedule = array();
109
-        foreach (self::get_enabled_cronjobs() as $cronjob)
110
-        {
102
+        foreach (self::get_enabled_cronjobs() as $cronjob) {
111 103
             $name = $cronjob->get_name();
112 104
             $fixed_schedule[$name] = $schedule[$name];
113 105
         }
@@ -116,9 +108,10 @@  discard block
 block discarded – undo
116 108
         # Return the nearest scheduled event time.
117 109
 
118 110
         $nearest = time() + 3600;
119
-        foreach ($fixed_schedule as $name => $time)
120
-            if ($time < $nearest)
111
+        foreach ($fixed_schedule as $name => $time) {
112
+                    if ($time < $nearest)
121 113
                 $nearest = $time;
114
+        }
122 115
         Cache::set("cron_schedule", $fixed_schedule, 30*86400);
123 116
         $lock->release();
124 117
         return $nearest;
@@ -132,10 +125,8 @@  discard block
 block discarded – undo
132 125
     {
133 126
         require_once($GLOBALS['rootpath'].'okapi/service_runner.php');
134 127
 
135
-        foreach (self::get_enabled_cronjobs() as $cronjob)
136
-        {
137
-            if (($cronjob->get_name() == $job_name) || ($cronjob->get_name() == "okapi\\cronjobs\\".$job_name))
138
-            {
128
+        foreach (self::get_enabled_cronjobs() as $cronjob) {
129
+            if (($cronjob->get_name() == $job_name) || ($cronjob->get_name() == "okapi\\cronjobs\\".$job_name)) {
139 130
                 $cronjob->execute();
140 131
                 return;
141 132
             }
@@ -150,11 +141,13 @@  discard block
 block discarded – undo
150 141
     public static function reset_job_schedule($job_name)
151 142
     {
152 143
         $thejob = null;
153
-        foreach (self::get_enabled_cronjobs() as $tmp)
154
-            if (($tmp->get_name() == $job_name) || ($tmp->get_name() == "okapi\\cronjobs\\".$job_name))
144
+        foreach (self::get_enabled_cronjobs() as $tmp) {
145
+                    if (($tmp->get_name() == $job_name) || ($tmp->get_name() == "okapi\\cronjobs\\".$job_name))
155 146
                 $thejob = $tmp;
156
-        if ($thejob == null)
157
-            throw new Exception("Could not reset schedule for job $job_name. $jon_name not found.");
147
+        }
148
+        if ($thejob == null) {
149
+                    throw new Exception("Could not reset schedule for job $job_name. $jon_name not found.");
150
+        }
158 151
 
159 152
         # We have to acquire lock on the schedule. This might take some time if cron-5 jobs are
160 153
         # currently being run.
@@ -164,10 +157,10 @@  discard block
 block discarded – undo
164 157
         $lock->acquire();
165 158
 
166 159
         $schedule = Cache::get("cron_schedule");
167
-        if ($schedule != null)
168
-        {
169
-            if (isset($schedule[$thejob->get_name()]))
170
-                unset($schedule[$thejob->get_name()]);
160
+        if ($schedule != null) {
161
+            if (isset($schedule[$thejob->get_name()])) {
162
+                            unset($schedule[$thejob->get_name()]);
163
+            }
171 164
             Cache::set("cron_schedule", $schedule, 30*86400);
172 165
         }
173 166
 
@@ -181,7 +174,9 @@  discard block
 block discarded – undo
181 174
     public abstract function execute();
182 175
 
183 176
     /** Get unique name for this cronjob. */
184
-    public function get_name() { return get_class($this); }
177
+    public function get_name()
178
+    {
179
+return get_class($this); }
185 180
 
186 181
     /**
187 182
      * Get the type of this cronjob. Currently there are two: 'pre-request'
@@ -212,7 +207,9 @@  discard block
 block discarded – undo
212 207
     /**
213 208
      * Always returns 'pre-request'.
214 209
      */
215
-    public final function get_type() { return 'pre-request'; }
210
+    public final function get_type()
211
+    {
212
+return 'pre-request'; }
216 213
 
217 214
     /**
218 215
      * Return number of seconds - a *minimum* time period that should pass between
@@ -235,7 +232,9 @@  discard block
 block discarded – undo
235 232
     /**
236 233
      * Always returns 'cron-5'.
237 234
      */
238
-    public final function get_type() { return 'cron-5'; }
235
+    public final function get_type()
236
+    {
237
+return 'cron-5'; }
239 238
 
240 239
     /**
241 240
      * Return number of seconds - period of time after which cronjob execution
@@ -257,18 +256,23 @@  discard block
 block discarded – undo
257 256
  */
258 257
 class OAuthCleanupCronJob extends PrerequestCronJob
259 258
 {
260
-    public function get_period() { return 300; } # 5 minutes
259
+    public function get_period()
260
+    {
261
+return 300; } # 5 minutes
261 262
     public function execute()
262 263
     {
263
-        if (Okapi::$data_store)
264
-            Okapi::$data_store->cleanup();
264
+        if (Okapi::$data_store) {
265
+                    Okapi::$data_store->cleanup();
266
+        }
265 267
     }
266 268
 }
267 269
 
268 270
 /** Clean up the saved search tables, every 10 minutes. */
269 271
 class SearchSetsCleanerJob extends Cron5Job
270 272
 {
271
-    public function get_period() { return 600; }
273
+    public function get_period()
274
+    {
275
+return 600; }
272 276
     public function execute()
273 277
     {
274 278
         Db::execute("
@@ -286,7 +290,9 @@  discard block
 block discarded – undo
286 290
 /** Clean up the cache, once per hour. */
287 291
 class CacheCleanupCronJob extends Cron5Job
288 292
 {
289
-    public function get_period() { return 3600; }
293
+    public function get_period()
294
+    {
295
+return 3600; }
290 296
     public function execute()
291 297
     {
292 298
         # Delete all expired elements.
@@ -358,11 +364,14 @@  discard block
 block discarded – undo
358 364
 /** Reads temporary (fast) stats-tables and reformats them into more permanent structures. */
359 365
 class StatsWriterCronJob extends PrerequestCronJob
360 366
 {
361
-    public function get_period() { return 60; } # 1 minute
367
+    public function get_period()
368
+    {
369
+return 60; } # 1 minute
362 370
     public function execute()
363 371
     {
364
-        if (Okapi::get_var('db_version', 0) + 0 < 32)
365
-            return;
372
+        if (Okapi::get_var('db_version', 0) + 0 < 32) {
373
+                    return;
374
+        }
366 375
         Db::execute("lock tables okapi_stats_hourly write, okapi_stats_temp write;");
367 376
         try {
368 377
             $rs = Db::query("
@@ -377,8 +386,7 @@  discard block
 block discarded – undo
377 386
                 from okapi_stats_temp
378 387
                 group by substr(`datetime`, 1, 13), consumer_key, user_id, service_name, calltype
379 388
             ");
380
-            while ($row = Db::fetch_assoc($rs))
381
-            {
389
+            while ($row = Db::fetch_assoc($rs)) {
382 390
                 Db::execute("
383 391
                     insert into okapi_stats_hourly (consumer_key, user_id, period_start, service_name,
384 392
                         total_calls, http_calls, total_runtime, http_runtime)
@@ -416,11 +424,14 @@  discard block
 block discarded – undo
416 424
  */
417 425
 class StatsCompressorCronJob extends Cron5Job
418 426
 {
419
-    public function get_period() { return 3600; }  # 1 hour
427
+    public function get_period()
428
+    {
429
+return 3600; }  # 1 hour
420 430
     public function execute()
421 431
     {
422
-        if (Okapi::get_var('db_version', 0) + 0 < 94)
423
-            return;
432
+        if (Okapi::get_var('db_version', 0) + 0 < 94) {
433
+                    return;
434
+        }
424 435
 
425 436
         # We will process a single month, every time we are being run.
426 437
 
@@ -489,7 +500,9 @@  discard block
 block discarded – undo
489 500
  */
490 501
 class CheckCronTab1 extends Cron5Job
491 502
 {
492
-    public function get_period() { return 3600; }
503
+    public function get_period()
504
+    {
505
+return 3600; }
493 506
     public function execute()
494 507
     {
495 508
         Cache::set('crontab_last_ping', time(), 86400);
@@ -502,14 +515,17 @@  discard block
 block discarded – undo
502 515
  */
503 516
 class CheckCronTab2 extends PrerequestCronJob
504 517
 {
505
-    public function get_period() { return 30 * 60; }
518
+    public function get_period()
519
+    {
520
+return 30 * 60; }
506 521
     public function execute()
507 522
     {
508 523
         $last_ping = Cache::get('crontab_last_ping');
509
-        if ($last_ping === null)
510
-            $last_ping = time() - 86400; # if not set, assume 1 day ago.
511
-        if ($last_ping > time() - 3600)
512
-        {
524
+        if ($last_ping === null) {
525
+                    $last_ping = time() - 86400;
526
+        }
527
+        # if not set, assume 1 day ago.
528
+        if ($last_ping > time() - 3600) {
513 529
             # There was a ping during the last hour. Everything is okay.
514 530
             # Reset the counter and return.
515 531
 
@@ -520,15 +536,13 @@  discard block
 block discarded – undo
520 536
         # There was no ping. Decrement the counter. When reached zero, alert.
521 537
 
522 538
         $counter = Cache::get('crontab_check_counter');
523
-        if ($counter === null)
524
-            $counter = 5;
539
+        if ($counter === null) {
540
+                    $counter = 5;
541
+        }
525 542
         $counter--;
526
-        if ($counter > 0)
527
-        {
543
+        if ($counter > 0) {
528 544
             Cache::set('crontab_check_counter', $counter, 86400);
529
-        }
530
-        elseif ($counter == 0)
531
-        {
545
+        } elseif ($counter == 0) {
532 546
             Okapi::mail_admins(
533 547
                 "Crontab not working.",
534 548
                 "Hello. OKAPI detected, that it's crontab is not working properly.\n".
@@ -554,7 +568,9 @@  discard block
 block discarded – undo
554 568
  */
555 569
 class ChangeLogWriterJob extends Cron5Job
556 570
 {
557
-    public function get_period() { return 300; }
571
+    public function get_period()
572
+    {
573
+return 300; }
558 574
     public function execute()
559 575
     {
560 576
         require_once($GLOBALS['rootpath']."okapi/services/replicate/replicate_common.inc.php");
@@ -570,7 +586,9 @@  discard block
 block discarded – undo
570 586
  */
571 587
 class ChangeLogCheckerJob extends Cron5Job
572 588
 {
573
-    public function get_period() { return 86400; }
589
+    public function get_period()
590
+    {
591
+return 86400; }
574 592
     public function execute()
575 593
     {
576 594
         require_once($GLOBALS['rootpath']."okapi/services/replicate/replicate_common.inc.php");
@@ -583,7 +601,9 @@  discard block
 block discarded – undo
583 601
  */
584 602
 class FulldumpGeneratorJob extends Cron5Job
585 603
 {
586
-    public function get_period() { return 7*86400; }
604
+    public function get_period()
605
+    {
606
+return 7*86400; }
587 607
     public function execute()
588 608
     {
589 609
         require_once($GLOBALS['rootpath']."okapi/services/replicate/replicate_common.inc.php");
@@ -596,7 +616,9 @@  discard block
 block discarded – undo
596 616
  */
597 617
 class TileTreeUpdater extends Cron5Job
598 618
 {
599
-    public function get_period() { return 5*60; }
619
+    public function get_period()
620
+    {
621
+return 5*60; }
600 622
     public function execute()
601 623
     {
602 624
         $current_clog_revision = Okapi::get_var('clog_revision', 0);
@@ -605,18 +627,24 @@  discard block
 block discarded – undo
605 627
             # No update necessary.
606 628
         } elseif ($tiletree_revision < $current_clog_revision) {
607 629
             require_once($GLOBALS['rootpath']."okapi/services/caches/map/replicate_listener.inc.php");
608
-            if ($current_clog_revision - $tiletree_revision < 30000)  # In the middle of 2012, OCPL generated 30000 entries per week
630
+            if ($current_clog_revision - $tiletree_revision < 30000) {
631
+                # In the middle of 2012, OCPL generated 30000 entries per week
609 632
             {
610
-                for ($timeout = time() + 240; time() < $timeout; )  # Try to stop after 4 minutes.
633
+                for ($timeout = time() + 240;
634
+            }
635
+            time() < $timeout; ) {
636
+                    # Try to stop after 4 minutes.
611 637
                 {
612 638
                     try {
613 639
                         $response = OkapiServiceRunner::call('services/replicate/changelog', new OkapiInternalRequest(
614 640
                             new OkapiInternalConsumer(), null, array('since' => $tiletree_revision)));
641
+                }
615 642
                         \okapi\services\caches\map\ReplicateListener::receive($response['changelog']);
616 643
                         $tiletree_revision = $response['revision'];
617 644
                         Okapi::set_var('clog_followup_revision', $tiletree_revision);
618
-                        if (!$response['more'])
619
-                            break;
645
+                        if (!$response['more']) {
646
+                                                    break;
647
+                        }
620 648
                     } catch (BadRequest $e) {
621 649
                         # Invalid 'since' parameter? May happen when crontab was
622 650
                         # not working for more than 10 days. Or, just after OKAPI
@@ -640,24 +668,27 @@  discard block
 block discarded – undo
640 668
 /** Once per day, removes all revisions older than 10 days from okapi_clog table. */
641 669
 class ChangeLogCleanerJob extends Cron5Job
642 670
 {
643
-    public function get_period() { return 86400; }
671
+    public function get_period()
672
+    {
673
+return 86400; }
644 674
     public function execute()
645 675
     {
646 676
         require_once($GLOBALS['rootpath']."okapi/services/replicate/replicate_common.inc.php");
647 677
         $max_revision = ReplicateCommon::get_revision();
648 678
         $cache_key = 'clog_revisions_daily';
649 679
         $data = Cache::get($cache_key);
650
-        if ($data == null)
651
-            $data = array();
680
+        if ($data == null) {
681
+                    $data = array();
682
+        }
652 683
         $data[time()] = $max_revision;
653 684
         $new_min_revision = 1;
654 685
         $new_data = array();
655
-        foreach ($data as $time => $r)
656
-        {
657
-            if ($time < time() - 10*86400)
658
-                $new_min_revision = max($new_min_revision, $r);
659
-            else
660
-                $new_data[$time] = $r;
686
+        foreach ($data as $time => $r) {
687
+            if ($time < time() - 10*86400) {
688
+                            $new_min_revision = max($new_min_revision, $r);
689
+            } else {
690
+                            $new_data[$time] = $r;
691
+            }
661 692
         }
662 693
         Db::execute("
663 694
             delete from okapi_clog
@@ -673,7 +704,9 @@  discard block
 block discarded – undo
673 704
  */
674 705
 class AdminStatsSender extends Cron5Job
675 706
 {
676
-    public function get_period() { return 7*86400; }
707
+    public function get_period()
708
+    {
709
+return 7*86400; }
677 710
     public function execute()
678 711
     {
679 712
         ob_start();
@@ -718,15 +751,16 @@  discard block
 block discarded – undo
718 751
         print "== Consumers ==\n\n";
719 752
         print "Consumer name                         Calls     Runtime\n";
720 753
         print "----------------------------------- ------- -----------\n";
721
-        foreach ($consumers as $row)
722
-        {
754
+        foreach ($consumers as $row) {
723 755
             $name = $row['name'];
724
-            if ($row['consumer_key'] == 'anonymous')
725
-                $name = "Anonymous (Level 0 Authentication)";
726
-            elseif ($row['consumer_key'] == 'facade')
727
-                $name = "Internal usage via Facade";
728
-            if (mb_strlen($name) > 35)
729
-                $name = mb_substr($name, 0, 32)."...";
756
+            if ($row['consumer_key'] == 'anonymous') {
757
+                            $name = "Anonymous (Level 0 Authentication)";
758
+            } elseif ($row['consumer_key'] == 'facade') {
759
+                            $name = "Internal usage via Facade";
760
+            }
761
+            if (mb_strlen($name) > 35) {
762
+                            $name = mb_substr($name, 0, 32)."...";
763
+            }
730 764
             print self::mb_str_pad($name, 35, " ", STR_PAD_RIGHT);
731 765
             print str_pad($row['http_calls'], 8, " ", STR_PAD_LEFT);
732 766
             print str_pad(sprintf("%01.2f", $row['http_runtime']), 11, " ", STR_PAD_LEFT)."s\n";
@@ -746,11 +780,11 @@  discard block
 block discarded – undo
746 780
         print "== Methods ==\n\n";
747 781
         print "Service name                          Calls     Runtime      Avg\n";
748 782
         print "----------------------------------- ------- ----------- --------\n";
749
-        foreach ($methods as $row)
750
-        {
783
+        foreach ($methods as $row) {
751 784
             $name = $row['service_name'];
752
-            if (mb_strlen($name) > 35)
753
-                $name = mb_substr($name, 0, 32)."...";
785
+            if (mb_strlen($name) > 35) {
786
+                            $name = mb_substr($name, 0, 32)."...";
787
+            }
754 788
             print self::mb_str_pad($name, 35, " ", STR_PAD_RIGHT);
755 789
             print str_pad($row['http_calls'], 8, " ", STR_PAD_LEFT);
756 790
             print str_pad(sprintf("%01.2f", $row['http_runtime']), 11, " ", STR_PAD_LEFT)."s";
@@ -774,11 +808,11 @@  discard block
 block discarded – undo
774 808
         print "== Current OAuth usage by Consumers with at least 5 users ==\n\n";
775 809
         print "Consumer name                         Users\n";
776 810
         print "----------------------------------- -------\n";
777
-        foreach ($oauth_users as $row)
778
-        {
811
+        foreach ($oauth_users as $row) {
779 812
             $name = $row['name'];
780
-            if (mb_strlen($name) > 35)
781
-                $name = mb_substr($name, 0, 32)."...";
813
+            if (mb_strlen($name) > 35) {
814
+                            $name = mb_substr($name, 0, 32)."...";
815
+            }
782 816
             print self::mb_str_pad($name, 35, " ", STR_PAD_RIGHT);
783 817
             print str_pad($row['users'], 8, " ", STR_PAD_LEFT)."\n";
784 818
         }
@@ -806,18 +840,23 @@  discard block
 block discarded – undo
806 840
  */
807 841
 class LocaleChecker extends Cron5Job
808 842
 {
809
-    public function get_period() { return 7*86400; }
843
+    public function get_period()
844
+    {
845
+return 7*86400; }
810 846
     public function execute()
811 847
     {
812 848
         require_once($GLOBALS['rootpath']."okapi/locale/locales.php");
813 849
         $required = Locales::get_required_locales();
814 850
         $installed = Locales::get_installed_locales();
815 851
         $missing = array();
816
-        foreach ($required as $locale)
817
-            if (!in_array($locale, $installed))
852
+        foreach ($required as $locale) {
853
+                    if (!in_array($locale, $installed))
818 854
                 $missing[] = $locale;
819
-        if (count($missing) == 0)
820
-            return; # okay!
855
+        }
856
+        if (count($missing) == 0) {
857
+                    return;
858
+        }
859
+        # okay!
821 860
         ob_start();
822 861
         print "Hi!\n\n";
823 862
         print "Your system is missing some locales required by OKAPI for proper\n";
@@ -825,24 +864,21 @@  discard block
 block discarded – undo
825 864
         print "languages. This number (hopefully) will be growing.\n\n";
826 865
         print "Please take a moment to install the following missing locales:\n\n";
827 866
         $prefixes = array();
828
-        foreach ($missing as $locale)
829
-        {
867
+        foreach ($missing as $locale) {
830 868
             print " - ".$locale."\n";
831 869
             $prefixes[substr($locale, 0, 2)] = true;
832 870
         }
833 871
         $prefixes = array_keys($prefixes);
834 872
         print "\n";
835
-        if ((count($missing) == 1) && ($missing[0] == 'POSIX'))
836
-        {
873
+        if ((count($missing) == 1) && ($missing[0] == 'POSIX')) {
837 874
             # I don't remember how to install POSIX, probably everyone has it anyway.
838
-        }
839
-        else
840
-        {
875
+        } else {
841 876
             print "On Debian, try the following:\n\n";
842
-            foreach ($prefixes as $lang)
843
-            {
844
-                if ($lang != 'PO') # Two first letters cut from POSIX.
877
+            foreach ($prefixes as $lang) {
878
+                if ($lang != 'PO') {
879
+                    # Two first letters cut from POSIX.
845 880
                     print "sudo apt-get install language-pack-".$lang."-base\n";
881
+                }
846 882
             }
847 883
             print "sudo service apache2 restart\n";
848 884
             print "\n";
@@ -857,7 +893,9 @@  discard block
 block discarded – undo
857 893
 /** Once per day, optimize certain MySQL tables. */
858 894
 class TableOptimizerJob extends Cron5Job
859 895
 {
860
-    public function get_period() { return 86400; }
896
+    public function get_period()
897
+    {
898
+return 86400; }
861 899
     public function execute()
862 900
     {
863 901
         Db::query("optimize table okapi_tile_caches");
Please login to merge, or discard this patch.
htdocs/okapi/lib/tbszip.php 1 patch
Braces   +195 added lines, -76 removed lines patch added patch discarded remove patch
@@ -11,22 +11,28 @@  discard block
 block discarded – undo
11 11
 */
12 12
 
13 13
 
14
-class clsTbsZip {
14
+class clsTbsZip
15
+{
15 16
     const TBSZIP_DOWNLOAD = 1;   // download (default)
16 17
     const TBSZIP_NOHEADER = 4;   // option to use with DOWNLOAD: no header is sent
17 18
     const TBSZIP_FILE     = 8;   // output to file  , or add from file
18 19
     const TBSZIP_STRING   = 32;  // output to string, or add from string
19 20
 
20
-    function __construct() {
21
+    function __construct()
22
+    {
21 23
         $this->Meth8Ok = extension_loaded('zlib'); // check if Zlib extension is available. This is need for compress and uncompress with method 8.
22 24
         $this->DisplayError = true;
23 25
         $this->ArchFile = '';
24 26
         $this->Error = false;
25 27
     }
26 28
 
27
-    function CreateNew($ArchName='new.zip') {
29
+    function CreateNew($ArchName='new.zip')
30
+    {
28 31
     // Create a new virtual empty archive, the name will be the default name when the archive is flushed.
29
-        if (!isset($this->Meth8Ok)) $this->__construct();  // for PHP 4 compatibility
32
+        if (!isset($this->Meth8Ok)) {
33
+            $this->__construct();
34
+        }
35
+        // for PHP 4 compatibility
30 36
         $this->Close(); // note that $this->ArchHnd is set to false here
31 37
         $this->Error = false;
32 38
         $this->ArchFile = $ArchName;
@@ -37,9 +43,13 @@  discard block
 block discarded – undo
37 43
         $this->CdPos = $this->CdInfo['p_cd'];
38 44
     }
39 45
 
40
-    function Open($ArchFile, $UseIncludePath=false) {
46
+    function Open($ArchFile, $UseIncludePath=false)
47
+    {
41 48
     // Open the zip archive
42
-        if (!isset($this->Meth8Ok)) $this->__construct();  // for PHP 4 compatibility
49
+        if (!isset($this->Meth8Ok)) {
50
+            $this->__construct();
51
+        }
52
+        // for PHP 4 compatibility
43 53
         $this->Close(); // close handle and init info
44 54
         $this->Error = false;
45 55
         $this->ArchIsNew = false;
@@ -53,12 +63,17 @@  discard block
 block discarded – undo
53 63
             $this->ArchHnd = fopen($ArchFile, 'rb', $UseIncludePath);
54 64
         }
55 65
         $ok = !($this->ArchHnd===false);
56
-        if ($ok) $ok = $this->CentralDirRead();
66
+        if ($ok) {
67
+            $ok = $this->CentralDirRead();
68
+        }
57 69
         return $ok;
58 70
     }
59 71
 
60
-    function Close() {
61
-        if (isset($this->ArchHnd) and ($this->ArchHnd!==false)) fclose($this->ArchHnd);
72
+    function Close()
73
+    {
74
+        if (isset($this->ArchHnd) and ($this->ArchHnd!==false)) {
75
+            fclose($this->ArchHnd);
76
+        }
62 77
         $this->ArchFile = '';
63 78
         $this->ArchHnd = false;
64 79
         $this->CdInfo = array();
@@ -69,7 +84,8 @@  discard block
 block discarded – undo
69 84
         $this->ArchCancelModif();
70 85
     }
71 86
 
72
-    function ArchCancelModif() {
87
+    function ArchCancelModif()
88
+    {
73 89
         $this->LastReadComp = false; // compression of the last read file (1=compressed, 0=stored not compressed, -1= stored compressed but read uncompressed)
74 90
         $this->LastReadIdx = false;  // index of the last file read
75 91
         $this->ReplInfo = array();
@@ -77,21 +93,28 @@  discard block
 block discarded – undo
77 93
         $this->AddInfo = array();
78 94
     }
79 95
 
80
-    function FileAdd($Name, $Data, $DataType=self::TBSZIP_STRING, $Compress=true) {
96
+    function FileAdd($Name, $Data, $DataType=self::TBSZIP_STRING, $Compress=true)
97
+    {
81 98
 
82
-        if ($Data===false) return $this->FileCancelModif($Name, false); // Cancel a previously added file
99
+        if ($Data===false) {
100
+            return $this->FileCancelModif($Name, false);
101
+        }
102
+        // Cancel a previously added file
83 103
 
84 104
         // Save information for adding a new file into the archive
85 105
         $Diff = 30 + 46 + 2*strlen($Name); // size of the header + cd info
86 106
         $Ref = $this->_DataCreateNewRef($Data, $DataType, $Compress, $Diff, $Name);
87
-        if ($Ref===false) return false;
107
+        if ($Ref===false) {
108
+            return false;
109
+        }
88 110
         $Ref['name'] = $Name;
89 111
         $this->AddInfo[] = $Ref;
90 112
         return $Ref['res'];
91 113
 
92 114
     }
93 115
 
94
-    function CentralDirRead() {
116
+    function CentralDirRead()
117
+    {
95 118
         $cd_info = 'PK'.chr(05).chr(06); // signature of the Central Directory
96 119
         $cd_pos = -22;
97 120
         $this->_MoveTo($cd_pos, SEEK_END);
@@ -113,8 +136,12 @@  discard block
 block discarded – undo
113 136
         $this->CdFileNbr = $this->CdInfo['file_nbr_curr'];
114 137
         $this->CdPos = $this->CdInfo['p_cd'];
115 138
 
116
-        if ($this->CdFileNbr<=0) return $this->RaiseError('No header found in the Central Directory.');
117
-        if ($this->CdPos<=0) return $this->RaiseError('No position found for the Central Directory.');
139
+        if ($this->CdFileNbr<=0) {
140
+            return $this->RaiseError('No header found in the Central Directory.');
141
+        }
142
+        if ($this->CdPos<=0) {
143
+            return $this->RaiseError('No position found for the Central Directory.');
144
+        }
118 145
 
119 146
         $this->_MoveTo($this->CdPos);
120 147
         for ($i=0;$i<$this->CdFileNbr;$i++) {
@@ -127,7 +154,8 @@  discard block
 block discarded – undo
127 154
         return true;
128 155
     }
129 156
 
130
-    function CentralDirRead_End($cd_info) {
157
+    function CentralDirRead_End($cd_info)
158
+    {
131 159
         $b = $cd_info.$this->_ReadData(18);
132 160
         $x = array();
133 161
         $x['disk_num_curr'] = $this->_GetDec($b,4,2);  // number of this disk
@@ -142,12 +170,15 @@  discard block
 block discarded – undo
142 170
         return $x;
143 171
     }
144 172
 
145
-    function CentralDirRead_File($idx) {
173
+    function CentralDirRead_File($idx)
174
+    {
146 175
 
147 176
         $b = $this->_ReadData(46);
148 177
 
149 178
         $x = $this->_GetHex($b,0,4);
150
-        if ($x!=='h:02014b50') return $this->RaiseError("Signature of Central Directory Header #".$idx." (file information) expected but not found at position ".$this->_TxtPos(ftell($this->ArchHnd) - 46).".");
179
+        if ($x!=='h:02014b50') {
180
+            return $this->RaiseError("Signature of Central Directory Header #".$idx." (file information) expected but not found at position ".$this->_TxtPos(ftell($this->ArchHnd) - 46).".");
181
+        }
151 182
 
152 183
         $x = array();
153 184
         $x['vers_used'] = $this->_GetDec($b,4,2);
@@ -175,7 +206,8 @@  discard block
 block discarded – undo
175 206
         return $x;
176 207
     }
177 208
 
178
-    function RaiseError($Msg) {
209
+    function RaiseError($Msg)
210
+    {
179 211
         if ($this->DisplayError) {
180 212
             if (PHP_SAPI==='cli') {
181 213
                 echo get_class($this).' ERROR with the zip archive: '.$Msg."\r\n";
@@ -187,7 +219,8 @@  discard block
 block discarded – undo
187 219
         return false;
188 220
     }
189 221
 
190
-    function Debug($FileHeaders=false) {
222
+    function Debug($FileHeaders=false)
223
+    {
191 224
 
192 225
         $this->DisplayError = true;
193 226
 
@@ -230,7 +263,8 @@  discard block
 block discarded – undo
230 263
 
231 264
     }
232 265
 
233
-    function DebugArray($arr) {
266
+    function DebugArray($arr)
267
+    {
234 268
         foreach ($arr as $k=>$v) {
235 269
             if (is_array($v)) {
236 270
                 $arr[$k] = $this->DebugArray($v);
@@ -241,11 +275,13 @@  discard block
 block discarded – undo
241 275
         return $arr;
242 276
     }
243 277
 
244
-    function FileExists($NameOrIdx) {
278
+    function FileExists($NameOrIdx)
279
+    {
245 280
         return ($this->FileGetIdx($NameOrIdx)!==false);
246 281
     }
247 282
 
248
-    function FileGetIdx($NameOrIdx) {
283
+    function FileGetIdx($NameOrIdx)
284
+    {
249 285
     // Check if a file name, or a file index exists in the Central Directory, and return its index
250 286
         if (is_string($NameOrIdx)) {
251 287
             if (isset($this->CdFileByName[$NameOrIdx])) {
@@ -262,23 +298,31 @@  discard block
 block discarded – undo
262 298
         }
263 299
     }
264 300
 
265
-    function FileGetIdxAdd($Name) {
301
+    function FileGetIdxAdd($Name)
302
+    {
266 303
     // Check if a file name exists in the list of file to add, and return its index
267
-        if (!is_string($Name)) return false;
304
+        if (!is_string($Name)) {
305
+            return false;
306
+        }
268 307
         $idx_lst = array_keys($this->AddInfo);
269 308
         foreach ($idx_lst as $idx) {
270
-            if ($this->AddInfo[$idx]['name']===$Name) return $idx;
309
+            if ($this->AddInfo[$idx]['name']===$Name) {
310
+                return $idx;
311
+            }
271 312
         }
272 313
         return false;
273 314
     }
274 315
 
275
-    function FileRead($NameOrIdx, $Uncompress=true) {
316
+    function FileRead($NameOrIdx, $Uncompress=true)
317
+    {
276 318
 
277 319
         $this->LastReadComp = false; // means the file is not found
278 320
         $this->LastReadIdx = false;
279 321
 
280 322
         $idx = $this->FileGetIdx($NameOrIdx);
281
-        if ($idx===false) return $this->RaiseError('File "'.$NameOrIdx.'" is not found in the Central Directory.');
323
+        if ($idx===false) {
324
+            return $this->RaiseError('File "'.$NameOrIdx.'" is not found in the Central Directory.');
325
+        }
282 326
 
283 327
         $pos = $this->CdFileLst[$idx]['p_loc'];
284 328
         $this->_MoveTo($pos);
@@ -302,7 +346,9 @@  discard block
 block discarded – undo
302 346
         } elseif($meth==0) {
303 347
             $Comp = 0; // means stored without compression
304 348
         } else {
305
-            if ($Uncompress) $this->RaiseError('Unable to uncompress file "'.$NameOrIdx.'" because it is compressed with method '.$meth.'.');
349
+            if ($Uncompress) {
350
+                $this->RaiseError('Unable to uncompress file "'.$NameOrIdx.'" because it is compressed with method '.$meth.'.');
351
+            }
306 352
         }
307 353
         $this->LastReadComp = $Comp;
308 354
 
@@ -310,13 +356,16 @@  discard block
 block discarded – undo
310 356
 
311 357
     }
312 358
 
313
-    function _ReadFile($idx, $ReadData) {
359
+    function _ReadFile($idx, $ReadData)
360
+    {
314 361
     // read the file header (and maybe the data ) in the archive, assuming the cursor in at a new file position
315 362
 
316 363
         $b = $this->_ReadData(30);
317 364
 
318 365
         $x = $this->_GetHex($b,0,4);
319
-        if ($x!=='h:04034b50') return $this->RaiseError("Signature of Local File Header #".$idx." (data section) expected but not found at position ".$this->_TxtPos(ftell($this->ArchHnd)-30).".");
366
+        if ($x!=='h:04034b50') {
367
+            return $this->RaiseError("Signature of Local File Header #".$idx." (data section) expected but not found at position ".$this->_TxtPos(ftell($this->ArchHnd)-30).".");
368
+        }
320 369
 
321 370
         $x = array();
322 371
         $x['vers'] = $this->_GetDec($b,4,2);
@@ -348,7 +397,9 @@  discard block
 block discarded – undo
348 397
             }
349 398
         } else {
350 399
             $len = $x['l_data_c'];
351
-            if ($len==0) $this->RaiseError("File Data #".$idx." cannt be read because no length is specified in the Local File Header and its Central Directory information has not been found.");
400
+            if ($len==0) {
401
+                $this->RaiseError("File Data #".$idx." cannt be read because no length is specified in the Local File Header and its Central Directory information has not been found.");
402
+            }
352 403
         }
353 404
 
354 405
         if ($ReadData) {
@@ -389,11 +440,14 @@  discard block
 block discarded – undo
389 440
 
390 441
     }
391 442
 
392
-    function FileReplace($NameOrIdx, $Data, $DataType=self::TBSZIP_STRING, $Compress=true) {
443
+    function FileReplace($NameOrIdx, $Data, $DataType=self::TBSZIP_STRING, $Compress=true)
444
+    {
393 445
     // Store replacement information.
394 446
 
395 447
         $idx = $this->FileGetIdx($NameOrIdx);
396
-        if ($idx===false) return $this->RaiseError('File "'.$NameOrIdx.'" is not found in the Central Directory.');
448
+        if ($idx===false) {
449
+            return $this->RaiseError('File "'.$NameOrIdx.'" is not found in the Central Directory.');
450
+        }
397 451
 
398 452
         $pos = $this->CdFileLst[$idx]['p_loc'];
399 453
 
@@ -405,7 +459,9 @@  discard block
 block discarded – undo
405 459
             // file to replace
406 460
             $Diff = - $this->CdFileLst[$idx]['l_data_c'];
407 461
             $Ref = $this->_DataCreateNewRef($Data, $DataType, $Compress, $Diff, $NameOrIdx);
408
-            if ($Ref===false) return false;
462
+            if ($Ref===false) {
463
+                return false;
464
+            }
409 465
             $this->ReplInfo[$idx] = $Ref;
410 466
             $Result = $Ref['res'];
411 467
         }
@@ -420,7 +476,8 @@  discard block
 block discarded – undo
420 476
      * Return the state of the file.
421 477
      * @return {string} 'u'=unchanged, 'm'=modified, 'd'=deleted, 'a'=added, false=unknown
422 478
      */
423
-    function FileGetState($NameOrIdx) {
479
+    function FileGetState($NameOrIdx)
480
+    {
424 481
 
425 482
         $idx = $this->FileGetIdx($NameOrIdx);
426 483
         if ($idx===false) {
@@ -442,7 +499,8 @@  discard block
 block discarded – undo
442 499
 
443 500
     }
444 501
 
445
-    function FileCancelModif($NameOrIdx, $ReplacedAndDeleted=true) {
502
+    function FileCancelModif($NameOrIdx, $ReplacedAndDeleted=true)
503
+    {
446 504
     // cancel added, modified or deleted modifications on a file in the archive
447 505
     // return the number of cancels
448 506
 
@@ -472,7 +530,8 @@  discard block
 block discarded – undo
472 530
 
473 531
     }
474 532
 
475
-    function Flush($Render=self::TBSZIP_DOWNLOAD, $File='', $ContentType='') {
533
+    function Flush($Render=self::TBSZIP_DOWNLOAD, $File='', $ContentType='')
534
+    {
476 535
 
477 536
         if ( ($File!=='') && ($this->ArchFile===$File) && ($Render==self::TBSZIP_FILE) ) {
478 537
             $this->RaiseError('Method Flush() cannot overwrite the current opened archive: \''.$File.'\''); // this makes corrupted zip archives without PHP error.
@@ -489,7 +548,9 @@  discard block
 block discarded – undo
489 548
         $date  = $this->_MsDos_Date($now);
490 549
         $time  = $this->_MsDos_Time($now);
491 550
 
492
-        if (!$this->OutputOpen($Render, $File, $ContentType)) return false;
551
+        if (!$this->OutputOpen($Render, $File, $ContentType)) {
552
+            return false;
553
+        }
493 554
 
494 555
         // output modified zipped files and unmodified zipped files that are beetween them
495 556
         ksort($this->ReplByPos);
@@ -497,7 +558,9 @@  discard block
 block discarded – undo
497 558
             // output data from the zip archive which is before the data to replace
498 559
             $this->OutputFromArch($ArchPos, $ReplPos);
499 560
             // get current file information
500
-            if (!isset($this->VisFileLst[$ReplIdx])) $this->_ReadFile($ReplIdx, false);
561
+            if (!isset($this->VisFileLst[$ReplIdx])) {
562
+                $this->_ReadFile($ReplIdx, false);
563
+            }
501 564
             $FileInfo =& $this->VisFileLst[$ReplIdx];
502 565
             $b1 = $FileInfo['bin'];
503 566
             if (isset($FileInfo['desc_bin'])) {
@@ -520,7 +583,10 @@  discard block
 block discarded – undo
520 583
                 $this->_PutDec($b1, $ReplInfo['crc32'], 14, 4); // crc32
521 584
                 $this->_PutDec($b1, $ReplInfo['len_c'], 18, 4); // l_data_c
522 585
                 $this->_PutDec($b1, $ReplInfo['len_u'], 22, 4); // l_data_u
523
-                if ($ReplInfo['meth']!==false) $this->_PutDec($b1, $ReplInfo['meth'], 8, 2); // meth
586
+                if ($ReplInfo['meth']!==false) {
587
+                    $this->_PutDec($b1, $ReplInfo['meth'], 8, 2);
588
+                }
589
+                // meth
524 590
                 // prepare the bottom description if the zipped file, if any
525 591
                 if ($b2!=='') {
526 592
                     $d = (strlen($b2)==16) ? 4 : 0; // offset because of the signature if any
@@ -544,7 +610,10 @@  discard block
 block discarded – undo
544 610
         }
545 611
 
546 612
         // Ouput all the zipped files that remain before the Central Directory listing
547
-        if ($this->ArchHnd!==false) $this->OutputFromArch($ArchPos, $this->CdPos); // ArchHnd is false if CreateNew() has been called
613
+        if ($this->ArchHnd!==false) {
614
+            $this->OutputFromArch($ArchPos, $this->CdPos);
615
+        }
616
+        // ArchHnd is false if CreateNew() has been called
548 617
         $ArchPos = $this->CdPos;
549 618
 
550 619
         // Output file to add
@@ -567,7 +636,10 @@  discard block
 block discarded – undo
567 636
             $b1 = $this->CdFileLst[$i]['bin'];
568 637
             $old_cd_len += strlen($b1);
569 638
             if (!isset($DelLst[$i])) {
570
-                if (isset($FicNewPos[$i])) $this->_PutDec($b1, $FicNewPos[$i], 42, 4);   // p_loc
639
+                if (isset($FicNewPos[$i])) {
640
+                    $this->_PutDec($b1, $FicNewPos[$i], 42, 4);
641
+                }
642
+                // p_loc
571 643
                 if (isset($this->ReplInfo[$i])) {
572 644
                     $ReplInfo =& $this->ReplInfo[$i];
573 645
                     $this->_PutDec($b1, $time, 12, 2); // time
@@ -575,7 +647,10 @@  discard block
 block discarded – undo
575 647
                     $this->_PutDec($b1, $ReplInfo['crc32'], 16, 4); // crc32
576 648
                     $this->_PutDec($b1, $ReplInfo['len_c'], 20, 4); // l_data_c
577 649
                     $this->_PutDec($b1, $ReplInfo['len_u'], 24, 4); // l_data_u
578
-                    if ($ReplInfo['meth']!==false) $this->_PutDec($b1, $ReplInfo['meth'], 10, 2); // meth
650
+                    if ($ReplInfo['meth']!==false) {
651
+                        $this->_PutDec($b1, $ReplInfo['meth'], 10, 2);
652
+                    }
653
+                    // meth
579 654
                 }
580 655
                 $b2 .= $b1;
581 656
             }
@@ -585,7 +660,10 @@  discard block
 block discarded – undo
585 660
         $DeltaCdLen =  $DeltaCdLen + strlen($b2) - $old_cd_len;
586 661
 
587 662
         // Output until "end of central directory record"
588
-        if ($this->ArchHnd!==false) $this->OutputFromArch($ArchPos, $this->CdEndPos); // ArchHnd is false if CreateNew() has been called
663
+        if ($this->ArchHnd!==false) {
664
+            $this->OutputFromArch($ArchPos, $this->CdEndPos);
665
+        }
666
+        // ArchHnd is false if CreateNew() has been called
589 667
 
590 668
         // Output file information of the Central Directory for added files
591 669
         if ($AddNbr>0) {
@@ -625,11 +703,14 @@  discard block
 block discarded – undo
625 703
     // output functions
626 704
     // ----------------
627 705
 
628
-    function OutputOpen($Render, $File, $ContentType) {
706
+    function OutputOpen($Render, $File, $ContentType)
707
+    {
629 708
 
630 709
         if (($Render & self::TBSZIP_FILE)==self::TBSZIP_FILE) {
631 710
             $this->OutputMode = self::TBSZIP_FILE;
632
-            if (''.$File=='') $File = basename($this->ArchFile).'.zip';
711
+            if (''.$File=='') {
712
+                $File = basename($this->ArchFile).'.zip';
713
+            }
633 714
             $this->OutputHandle = @fopen($File, 'w');
634 715
             if ($this->OutputHandle===false) {
635 716
                 return $this->RaiseError('Method Flush() cannot overwrite the target file \''.$File.'\'. This may not be a valid file path or the file may be locked by another process or because of a denied permission.');
@@ -640,11 +721,15 @@  discard block
 block discarded – undo
640 721
         } elseif (($Render & self::TBSZIP_DOWNLOAD)==self::TBSZIP_DOWNLOAD) {
641 722
             $this->OutputMode = self::TBSZIP_DOWNLOAD;
642 723
             // Output the file
643
-            if (''.$File=='') $File = basename($this->ArchFile);
724
+            if (''.$File=='') {
725
+                $File = basename($this->ArchFile);
726
+            }
644 727
             if (($Render & self::TBSZIP_NOHEADER)==self::TBSZIP_NOHEADER) {
645 728
             } else {
646 729
                 header ('Pragma: no-cache');
647
-                if ($ContentType!='') header ('Content-Type: '.$ContentType);
730
+                if ($ContentType!='') {
731
+                    header ('Content-Type: '.$ContentType);
732
+                }
648 733
                 header('Content-Disposition: attachment; filename="'.$File.'"');
649 734
                 header('Expires: 0');
650 735
                 header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
@@ -652,7 +737,9 @@  discard block
 block discarded – undo
652 737
                 header('Content-Description: File Transfer');
653 738
                 header('Content-Transfer-Encoding: binary');
654 739
                 $Len = $this->_EstimateNewArchSize();
655
-                if ($Len!==false) header('Content-Length: '.$Len);
740
+                if ($Len!==false) {
741
+                    header('Content-Length: '.$Len);
742
+                }
656 743
             }
657 744
         } else {
658 745
             return $this->RaiseError('Method Flush is called with a unsupported render option.');
@@ -662,9 +749,12 @@  discard block
 block discarded – undo
662 749
 
663 750
     }
664 751
 
665
-    function OutputFromArch($pos, $pos_stop) {
752
+    function OutputFromArch($pos, $pos_stop)
753
+    {
666 754
         $len = $pos_stop - $pos;
667
-        if ($len<0) return;
755
+        if ($len<0) {
756
+            return;
757
+        }
668 758
         $this->_MoveTo($pos);
669 759
         $block = 1024;
670 760
         while ($len>0) {
@@ -676,7 +766,8 @@  discard block
 block discarded – undo
676 766
         unset($x);
677 767
     }
678 768
 
679
-    function OutputFromString($data) {
769
+    function OutputFromString($data)
770
+    {
680 771
         if ($this->OutputMode===self::TBSZIP_DOWNLOAD) {
681 772
             echo $data; // donwload
682 773
         } elseif ($this->OutputMode===self::TBSZIP_STRING) {
@@ -686,7 +777,8 @@  discard block
 block discarded – undo
686 777
         }
687 778
     }
688 779
 
689
-    function OutputClose() {
780
+    function OutputClose()
781
+    {
690 782
         if ( ($this->OutputMode===self::TBSZIP_FILE) && ($this->OutputHandle!==false) ) {
691 783
             fclose($this->OutputHandle);
692 784
             $this->OutputHandle = false;
@@ -697,11 +789,13 @@  discard block
 block discarded – undo
697 789
     // Reading functions
698 790
     // ----------------
699 791
 
700
-    function _MoveTo($pos, $relative = SEEK_SET) {
792
+    function _MoveTo($pos, $relative = SEEK_SET)
793
+    {
701 794
         fseek($this->ArchHnd, $pos, $relative);
702 795
     }
703 796
 
704
-    function _ReadData($len) {
797
+    function _ReadData($len)
798
+    {
705 799
         if ($len>0) {
706 800
             $x = fread($this->ArchHnd, $len);
707 801
             return $x;
@@ -714,22 +808,27 @@  discard block
 block discarded – undo
714 808
     // Take info from binary data
715 809
     // ----------------
716 810
 
717
-    function _GetDec($txt, $pos, $len) {
811
+    function _GetDec($txt, $pos, $len)
812
+    {
718 813
         $x = substr($txt, $pos, $len);
719 814
         $z = 0;
720 815
         for ($i=0;$i<$len;$i++) {
721 816
             $asc = ord($x[$i]);
722
-            if ($asc>0) $z = $z + $asc*pow(256,$i);
817
+            if ($asc>0) {
818
+                $z = $z + $asc*pow(256,$i);
819
+            }
723 820
         }
724 821
         return $z;
725 822
     }
726 823
 
727
-    function _GetHex($txt, $pos, $len) {
824
+    function _GetHex($txt, $pos, $len)
825
+    {
728 826
         $x = substr($txt, $pos, $len);
729 827
         return 'h:'.bin2hex(strrev($x));
730 828
     }
731 829
 
732
-    function _GetBin($txt, $pos, $len) {
830
+    function _GetBin($txt, $pos, $len)
831
+    {
733 832
         $x = substr($txt, $pos, $len);
734 833
         $z = '';
735 834
         for ($i=0;$i<$len;$i++) {
@@ -749,14 +848,16 @@  discard block
 block discarded – undo
749 848
     // Put info into binary data
750 849
     // ----------------
751 850
 
752
-    function _PutDec(&$txt, $val, $pos, $len) {
851
+    function _PutDec(&$txt, $val, $pos, $len)
852
+    {
753 853
         $x = '';
754 854
         for ($i=0;$i<$len;$i++) {
755 855
             if ($val==0) {
756 856
                 $z = 0;
757 857
             } else {
758 858
                 $z = intval($val % 256);
759
-                if (($val<0) && ($z!=0)) { // ($z!=0) is very important, example: val=-420085702
859
+                if (($val<0) && ($z!=0)) {
860
+// ($z!=0) is very important, example: val=-420085702
760 861
                     // special opration for negative value. If the number id too big, PHP stores it into a signed integer. For example: crc32('coucou') => -256185401 instead of  4038781895. NegVal = BigVal - (MaxVal+1) = BigVal - 256^4
761 862
                     $val = ($val - $z)/256 -1;
762 863
                     $z = 256 + $z;
@@ -769,18 +870,21 @@  discard block
 block discarded – undo
769 870
         $txt = substr_replace($txt, $x, $pos, $len);
770 871
     }
771 872
 
772
-    function _MsDos_Date($Timestamp = false) {
873
+    function _MsDos_Date($Timestamp = false)
874
+    {
773 875
         // convert a date-time timstamp into the MS-Dos format
774 876
         $d = ($Timestamp===false) ? getdate() : getdate($Timestamp);
775 877
         return (($d['year']-1980)*512) + ($d['mon']*32) + $d['mday'];
776 878
     }
777
-    function _MsDos_Time($Timestamp = false) {
879
+    function _MsDos_Time($Timestamp = false)
880
+    {
778 881
         // convert a date-time timstamp into the MS-Dos format
779 882
         $d = ($Timestamp===false) ? getdate() : getdate($Timestamp);
780 883
         return ($d['hours']*2048) + ($d['minutes']*32) + intval($d['seconds']/2); // seconds are rounded to an even number in order to save 1 bit
781 884
     }
782 885
 
783
-    function _MsDos_Debug($date, $time) {
886
+    function _MsDos_Debug($date, $time)
887
+    {
784 888
         // Display the formated date and time. Just for debug purpose.
785 889
         // date end time are encoded on 16 bits (2 bytes) : date = yyyyyyymmmmddddd , time = hhhhhnnnnnssssss
786 890
         $y = ($date & 65024)/512 + 1980;
@@ -792,7 +896,8 @@  discard block
 block discarded – undo
792 896
         return $y.'-'.str_pad($m,2,'0',STR_PAD_LEFT).'-'.str_pad($d,2,'0',STR_PAD_LEFT).' '.str_pad($h,2,'0',STR_PAD_LEFT).':'.str_pad($i,2,'0',STR_PAD_LEFT).':'.str_pad($s,2,'0',STR_PAD_LEFT);
793 897
     }
794 898
 
795
-    function _TxtPos($pos) {
899
+    function _TxtPos($pos)
900
+    {
796 901
         // Return the human readable position in both decimal and hexa
797 902
         return $pos." (h:".dechex($pos).")";
798 903
     }
@@ -803,7 +908,8 @@  discard block
 block discarded – undo
803 908
      * Return false if the record is not found. The comment cannot exceed 65335 bytes (=FFFF).
804 909
      * The method is read backwards a block of 256 bytes and search the key in this block.
805 910
      */
806
-    function _FindCDEnd($cd_info) {
911
+    function _FindCDEnd($cd_info)
912
+    {
807 913
         $nbr = 1;
808 914
         $p = false;
809 915
         $pos = ftell($this->ArchHnd) - 4 - 256;
@@ -825,7 +931,8 @@  discard block
 block discarded – undo
825 931
         return false;
826 932
     }
827 933
 
828
-    function _DataOuputAddedFile($Idx, $PosLoc) {
934
+    function _DataOuputAddedFile($Idx, $PosLoc)
935
+    {
829 936
 
830 937
         $Ref =& $this->AddInfo[$Idx];
831 938
         $this->_DataPrepare($Ref); // get data from external file if necessary
@@ -885,7 +992,8 @@  discard block
 block discarded – undo
885 992
 
886 993
     }
887 994
 
888
-    function _DataCreateNewRef($Data, $DataType, $Compress, $Diff, $NameOrIdx) {
995
+    function _DataCreateNewRef($Data, $DataType, $Compress, $Diff, $NameOrIdx)
996
+    {
889 997
 
890 998
         $file_time = false;
891 999
         if (is_array($Compress)) {
@@ -929,7 +1037,9 @@  discard block
 block discarded – undo
929 1037
             $fi = stat($path);
930 1038
             if ($fi !== false) {
931 1039
                 $fz = $fi['size'];
932
-                if ($len_u===false) $len_u = $fz;
1040
+                if ($len_u===false) {
1041
+                    $len_u = $fz;
1042
+                }
933 1043
                 $len_c = ($Compress) ? false : $fz;
934 1044
                 $file_time = $fi['mtime'];
935 1045
             } else {
@@ -943,12 +1053,15 @@  discard block
 block discarded – undo
943 1053
 
944 1054
     }
945 1055
 
946
-    function _DataPrepare(&$Ref) {
1056
+    function _DataPrepare(&$Ref)
1057
+    {
947 1058
         // returns the real size of data
948 1059
         // TODO: support for data returned from okapi cache
949 1060
         if ($Ref['path']!==false) {
950 1061
             $Ref['data'] = file_get_contents($Ref['path']);
951
-            if ($Ref['crc32']===false) $Ref['crc32'] = crc32($Ref['data']);
1062
+            if ($Ref['crc32']===false) {
1063
+                $Ref['crc32'] = crc32($Ref['data']);
1064
+            }
952 1065
             if ($Ref['len_c']===false) {
953 1066
                 // means the data must be compressed
954 1067
                 $Ref['data'] = gzdeflate($Ref['data']);
@@ -959,7 +1072,8 @@  discard block
 block discarded – undo
959 1072
     /**
960 1073
      * Return the size of the new archive, or false if it cannot be calculated (because of external file that must be compressed before to be insered)
961 1074
      */
962
-    function _EstimateNewArchSize($Optim=true) {
1075
+    function _EstimateNewArchSize($Optim=true)
1076
+    {
963 1077
 
964 1078
         if ($this->ArchIsNew) {
965 1079
             $Len = strlen($this->CdInfo['bin']);
@@ -977,13 +1091,18 @@  discard block
 block discarded – undo
977 1091
                 // file to delete
978 1092
                 $Info =& $this->CdFileLst[$i];
979 1093
                 if (!isset($this->VisFileLst[$i])) {
980
-                    if ($Optim) return false; // if $Optimization is set to true, then we d'ont rewind to read information
1094
+                    if ($Optim) {
1095
+                        return false;
1096
+                    }
1097
+                    // if $Optimization is set to true, then we d'ont rewind to read information
981 1098
                     $this->_MoveTo($Info['p_loc']);
982 1099
                     $this->_ReadFile($i, false);
983 1100
                 }
984 1101
                 $Vis =& $this->VisFileLst[$i];
985 1102
                 $Len += -strlen($Vis['bin']) -strlen($Info['bin']) - $Info['l_data_c'];
986
-                if (isset($Vis['desc_bin'])) $Len += -strlen($Vis['desc_bin']);
1103
+                if (isset($Vis['desc_bin'])) {
1104
+                    $Len += -strlen($Vis['desc_bin']);
1105
+                }
987 1106
             } elseif ($Ref['len_c']===false) {
988 1107
                 return false; // information not yet known
989 1108
             } else {
Please login to merge, or discard this patch.
htdocs/okapi/lib/ocpl_access_logs.php 1 patch
Braces   +36 added lines, -33 removed lines patch added patch discarded remove patch
@@ -22,20 +22,18 @@  discard block
 block discarded – undo
22 22
         // traverse PHP call stack to find out who originally called us
23 23
         // first, find first service_runner.php invocation
24 24
         // then, find previous class invocation
25
-        for($i = count($trace)-1; $i >= 0; $i--)
26
-        {
25
+        for($i = count($trace)-1; $i >= 0; $i--) {
27 26
             $frame = $trace[$i];
28
-            if ($break_next && isset($frame['class']))
29
-            {
27
+            if ($break_next && isset($frame['class'])) {
30 28
                 $class_elems = explode('\\', $frame['class']);
31
-                if (count($class_elems) >= 2)
32
-                    $org_caller = $class_elems[count($class_elems)-2];
29
+                if (count($class_elems) >= 2) {
30
+                                    $org_caller = $class_elems[count($class_elems)-2];
31
+                }
33 32
                 break;
34 33
             }
35 34
             if (isset($frame['file']) &&
36 35
                     // test if file ends with service_runner.php
37
-                    substr($frame['file'], -strlen('service_runner.php')) === 'service_runner.php')
38
-            {
36
+                    substr($frame['file'], -strlen('service_runner.php')) === 'service_runner.php') {
39 37
                 $break_next = true;
40 38
             }
41 39
         }
@@ -50,11 +48,11 @@  discard block
 block discarded – undo
50 48
      */
51 49
     public static function log_geocache_access(OkapiRequest $request, $cache_ids)
52 50
     {
53
-        if (Settings::get('OCPL_ENABLE_GEOCACHE_ACCESS_LOGS') !== true)
54
-            return ;
51
+        if (Settings::get('OCPL_ENABLE_GEOCACHE_ACCESS_LOGS') !== true) {
52
+                    return ;
53
+        }
55 54
 
56
-        if (Settings::get('OC_BRANCH') == 'oc.pl')
57
-        {
55
+        if (Settings::get('OC_BRANCH') == 'oc.pl') {
58 56
             // TODO: can we use the _SERVER global here? or should we make them abstract, and
59 57
             // pass along with request object?
60 58
             $remote_addr_escaped = "'" . Db::escape_string($_SERVER['REMOTE_ADDR']) . "'";
@@ -67,14 +65,16 @@  discard block
 block discarded – undo
67 65
             $original_caller_escaped = "'" . Db::escape_string(self::get_original_caller()) . "'";
68 66
 
69 67
             $user_id = null;
70
-            if ($request->token != null)
71
-                $user_id = $request->token->user_id;
68
+            if ($request->token != null) {
69
+                            $user_id = $request->token->user_id;
70
+            }
72 71
             $user_id_escaped = $user_id === null ? "null" : "'" . Db::escape_string($user_id) . "'";
73
-            if (is_array($cache_ids)){
74
-                if (count($cache_ids) == 1)
75
-                    $cache_ids_where = "= '" . Db::escape_string($cache_ids[0]) . "'";
76
-                else
77
-                    $cache_ids_where = "in ('" . implode("','", array_map('\okapi\Db::escape_string', $cache_ids)) . "')";
72
+            if (is_array($cache_ids)) {
73
+                if (count($cache_ids) == 1) {
74
+                                    $cache_ids_where = "= '" . Db::escape_string($cache_ids[0]) . "'";
75
+                } else {
76
+                                    $cache_ids_where = "in ('" . implode("','", array_map('\okapi\Db::escape_string', $cache_ids)) . "')";
77
+                }
78 78
             } else {
79 79
                 $cache_ids_where = "= '" . Db::escape_string($cache_ids) . "'";
80 80
             }
@@ -99,30 +99,33 @@  discard block
 block discarded – undo
99 99
 
100 100
             // check, if all the geocaches has already been logged
101 101
             if (is_array($cache_ids) && count($already_logged_cache_ids) == count($cache_ids)
102
-                || !is_array($cache_ids) && count($already_logged_cache_ids) == 1)
103
-            {
102
+                || !is_array($cache_ids) && count($already_logged_cache_ids) == 1) {
104 103
                 return ;
105 104
             }
106 105
 
107
-            if (is_array($cache_ids)){
106
+            if (is_array($cache_ids)) {
108 107
                 $tmp = array();
109
-                foreach ($cache_ids as $cache_id)
110
-                    $tmp[$cache_id] = true;
111
-                foreach ($already_logged_cache_ids as $cache_id)
112
-                    unset($tmp[$cache_id]);
113
-                if (count($tmp) <= 0)
114
-                    return ;
108
+                foreach ($cache_ids as $cache_id) {
109
+                                    $tmp[$cache_id] = true;
110
+                }
111
+                foreach ($already_logged_cache_ids as $cache_id) {
112
+                                    unset($tmp[$cache_id]);
113
+                }
114
+                if (count($tmp) <= 0) {
115
+                                    return ;
116
+                }
115 117
                 $cache_ids_filterd = array_keys($tmp);
116 118
                 unset($tmp);
117 119
             } else {
118 120
                 $cache_ids_filterd = $cache_ids;
119 121
             }
120 122
 
121
-            if (is_array($cache_ids_filterd)){
122
-                if (count($cache_ids_filterd) == 1)
123
-                    $cache_ids_where = "= '" . Db::escape_string($cache_ids_filterd[0]) . "'";
124
-                else
125
-                    $cache_ids_where = "in ('" . implode("','", array_map('\okapi\Db::escape_string', $cache_ids_filterd)) . "')";
123
+            if (is_array($cache_ids_filterd)) {
124
+                if (count($cache_ids_filterd) == 1) {
125
+                                    $cache_ids_where = "= '" . Db::escape_string($cache_ids_filterd[0]) . "'";
126
+                } else {
127
+                                    $cache_ids_where = "in ('" . implode("','", array_map('\okapi\Db::escape_string', $cache_ids_filterd)) . "')";
128
+                }
126 129
             } else {
127 130
                 $cache_ids_where = "= '" . Db::escape_string($cache_ids_filterd) . "'";
128 131
             }
Please login to merge, or discard this patch.
htdocs/restorecaches.php 1 patch
Braces   +10 added lines, -5 removed lines patch added patch discarded remove patch
@@ -757,7 +757,8 @@  discard block
 block discarded – undo
757 757
                 $cacheid,
758 758
                 $rdate
759 759
             );
760
-            if ($r = sql_fetch_assoc($rs)) { // should always be true ...
760
+            if ($r = sql_fetch_assoc($rs)) {
761
+// should always be true ...
761 762
                 if (!$simulate) {
762 763
                     sql(
763 764
                         "UPDATE `caches` SET `latitude`='&1', `longitude`='&2' WHERE `cache_id`='&3'",
@@ -790,7 +791,8 @@  discard block
 block discarded – undo
790 791
                 $cacheid,
791 792
                 $rdate
792 793
             );
793
-            if ($r = sql_fetch_assoc($rs)) { // should always be true ...
794
+            if ($r = sql_fetch_assoc($rs)) {
795
+// should always be true ...
794 796
                 if (!$simulate) {
795 797
                     sql(
796 798
                         "UPDATE `caches` SET `country`='&1'  WHERE `cache_id`='&2'",
@@ -827,7 +829,8 @@  discard block
 block discarded – undo
827 829
             'wp_nc' => 'waypoints'
828 830
         ];
829 831
 
830
-        if ($r = sql_fetch_assoc($rs)) {// can be false
832
+        if ($r = sql_fetch_assoc($rs)) {
833
+// can be false
831 834
             $setfields = "";
832 835
             foreach ($fields as $field => $ropt) {
833 836
                 if (in_array($ropt, $roptions) && $r[$field] != $cache[$field]) {
@@ -896,13 +899,15 @@  discard block
 block discarded – undo
896 899
 
897 900
             while ($r = sql_fetch_assoc($rs)) {
898 901
                 if (!$simulate) {
899
-                    if ($r['desc'] === null) { // was newly created -> delete
902
+                    if ($r['desc'] === null) {
903
+// was newly created -> delete
900 904
                         sql(
901 905
                             "DELETE FROM `cache_desc` WHERE `cache_id`='&1' AND `language`='&2'",
902 906
                             $cacheid,
903 907
                             $r['language']
904 908
                         );
905
-                    } else {// id, uuid, date_created and last_modified are set automatically
909
+                    } else {
910
+// id, uuid, date_created and last_modified are set automatically
906 911
                         sql(
907 912
                             "INSERT INTO `cache_desc`
908 913
                             (`node`, `cache_id`, `language`, `desc`, `desc_html`, `desc_htmledit`, `hint`, `short_desc`)
Please login to merge, or discard this patch.
htdocs/util2/gns/gns_import.php 1 patch
Braces   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -44,7 +44,8 @@
 block discarded – undo
44 44
     $file = fopen($filename, "r");
45 45
     $cnt = 0;
46 46
     while ($line = fgets($file, 4096)) {
47
-        if ($cnt ++ == 0) {// skip first line
47
+        if ($cnt ++ == 0) {
48
+// skip first line
48 49
             continue;
49 50
         }
50 51
 
Please login to merge, or discard this patch.
htdocs/util2/cron/modules/picture_cleanup.class.php 1 patch
Braces   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -42,7 +42,8 @@
 block discarded – undo
42 42
             }
43 43
 
44 44
             for ($n = 1; $n < count($instances); ++ $n) {
45
-                if ($instances[$n]['filesize'] !== false) {// ensure that pic is stored locally
45
+                if ($instances[$n]['filesize'] !== false) {
46
+// ensure that pic is stored locally
46 47
                     for ($nn = $n - 1; $nn >= 0; -- $nn) {
47 48
                         if ($instances[$nn]['filesize'] === $instances[$n]['filesize']) {
48 49
                             if (file_get_contents($instances[$nn]['pic']->getFilename())
Please login to merge, or discard this patch.
htdocs/lib2/imagebmp.inc.php 1 patch
Braces   +129 added lines, -130 removed lines patch added patch discarded remove patch
@@ -36,7 +36,9 @@  discard block
 block discarded – undo
36 36
 $IsTransparent=$Transparent!=-1;
37 37
 
38 38
 
39
-if($IsTransparent) $ColorCount--;
39
+if($IsTransparent) {
40
+    $ColorCount--;
41
+}
40 42
 
41 43
 if($ColorCount==0) {$ColorCount=0; $BitCount=24;};
42 44
 if(($ColorCount>0)and($ColorCount<=2)) {$ColorCount=2; $BitCount=1;};
@@ -49,7 +51,9 @@  discard block
 block discarded – undo
49 51
 
50 52
                 $Zbytek=(4-($Width/(8/$BitCount))%4)%4;
51 53
 
52
-                if($BitCount<24) $palsize=pow(2,$BitCount)*4;
54
+                if($BitCount<24) {
55
+                    $palsize=pow(2,$BitCount)*4;
56
+                }
53 57
 
54 58
                 $size=(floor($Width/(8/$BitCount))+$Zbytek)*$Height+54;
55 59
                 $size+=$palsize;
@@ -76,14 +80,16 @@  discard block
 block discarded – undo
76 80
 
77 81
                 $CC=$ColorCount;
78 82
                 $sl1=strlen($ret);
79
-                if($CC==0) $CC=256;
80
-                if($BitCount<24)
81
-                   {
83
+                if($CC==0) {
84
+                    $CC=256;
85
+                }
86
+                if($BitCount<24) {
82 87
                     $ColorTotal=imagecolorstotal($img);
83
-                     if($IsTransparent) $ColorTotal--;
88
+                     if($IsTransparent) {
89
+                         $ColorTotal--;
90
+                     }
84 91
 
85
-                     for($p=0;$p<$ColorTotal;$p++)
86
-                     {
92
+                     for($p=0;$p<$ColorTotal;$p++) {
87 93
                       $color=imagecolorsforindex($img,$p);
88 94
                        $ret.=inttobyte($color["blue"]);
89 95
                        $ret.=inttobyte($color["green"]);
@@ -92,8 +98,7 @@  discard block
 block discarded – undo
92 98
                      };
93 99
 
94 100
                     $CT=$ColorTotal;
95
-                  for($p=$ColorTotal;$p<$CC;$p++)
96
-                       {
101
+                  for($p=$ColorTotal;$p<$CC;$p++) {
97 102
                       $ret.=inttobyte(0);
98 103
                       $ret.=inttobyte(0);
99 104
                       $ret.=inttobyte(0);
@@ -102,75 +107,63 @@  discard block
 block discarded – undo
102 107
                    };
103 108
 
104 109
 
105
-if($BitCount<=8)
106
-{
110
+if($BitCount<=8) {
107 111
 
108
- for($y=$Height-1;$y>=0;$y--)
109
- {
112
+ for($y=$Height-1;$y>=0;$y--) {
110 113
   $bWrite="";
111
-  for($x=0;$x<$Width;$x++)
112
-   {
114
+  for($x=0;$x<$Width;$x++) {
113 115
    $color=imagecolorat($img,$x,$y);
114 116
    $bWrite.=decbinx($color,$BitCount);
115
-   if(strlen($bWrite)==8)
116
-    {
117
+   if(strlen($bWrite)==8) {
117 118
      $retd.=inttobyte(bindec($bWrite));
118 119
      $bWrite="";
119 120
     };
120 121
    };
121 122
 
122
-  if((strlen($bWrite)<8)and(strlen($bWrite)!=0))
123
-    {
123
+  if((strlen($bWrite)<8)and(strlen($bWrite)!=0)) {
124 124
      $sl=strlen($bWrite);
125
-     for($t=0;$t<8-$sl;$t++)
126
-      $sl.="0";
125
+     for($t=0;$t<8-$sl;$t++) {
126
+           $sl.="0";
127
+     }
127 128
      $retd.=inttobyte(bindec($bWrite));
128 129
     };
129
- for($z=0;$z<$Zbytek;$z++)
130
-   $retd.=inttobyte(0);
130
+ for($z=0;$z<$Zbytek;$z++) {
131
+    $retd.=inttobyte(0);
132
+ }
131 133
  };
132 134
 };
133 135
 
134
-if(($RLE==1)and($BitCount==8))
135
-{
136
- for($t=0;$t<strlen($retd);$t+=4)
137
-  {
138
-   if($t!=0)
139
-   if(($t)%$Width==0)
136
+if(($RLE==1)and($BitCount==8)) {
137
+ for($t=0;$t<strlen($retd);$t+=4) {
138
+   if($t!=0) {
139
+      if(($t)%$Width==0)
140 140
     $ret.=chr(0).chr(0);
141
+   }
141 142
 
142
-   if(($t+5)%$Width==0)
143
-   {
143
+   if(($t+5)%$Width==0) {
144 144
      $ret.=chr(0).chr(5).substr($retd,$t,5).chr(0);
145 145
      $t+=1;
146 146
    }
147
-   if(($t+6)%$Width==0)
148
-    {
147
+   if(($t+6)%$Width==0) {
149 148
      $ret.=chr(0).chr(6).substr($retd,$t,6);
150 149
      $t+=2;
151
-    }
152
-    else
153
-    {
150
+    } else {
154 151
      $ret.=chr(0).chr(4).substr($retd,$t,4);
155 152
     };
156 153
   };
157 154
   $ret.=chr(0).chr(1);
158
-}
159
-else
160
-{
155
+} else {
161 156
 $ret.=$retd;
162 157
 };
163 158
 
164 159
 
165
-                if($BitCount==24)
166
-                {
167
-                for($z=0;$z<$Zbytek;$z++)
168
-                 $Dopl.=chr(0);
160
+                if($BitCount==24) {
161
+                for($z=0;$z<$Zbytek;$z++) {
162
+                                 $Dopl.=chr(0);
163
+                }
169 164
 
170
-                for($y=$Height-1;$y>=0;$y--)
171
-                 {
172
-                 for($x=0;$x<$Width;$x++)
173
-                        {
165
+                for($y=$Height-1;$y>=0;$y--) {
166
+                 for($x=0;$x<$Width;$x++) {
174 167
                            $color=imagecolorsforindex($img,ImageColorAt($img,$x,$y));
175 168
                            $ret.=chr($color["blue"]).chr($color["green"]).chr($color["red"]);
176 169
                         }
@@ -179,15 +172,12 @@  discard block
 block discarded – undo
179 172
 
180 173
                  };
181 174
 
182
-  if($file!="")
183
-   {
175
+  if($file!="") {
184 176
     $r=($f=fopen($file,"w"));
185 177
     $r=$r and fwrite($f,$ret);
186 178
     $r=$r and fclose($f);
187 179
     return $r;
188
-   }
189
-  else
190
-  {
180
+   } else {
191 181
    echo $ret;
192 182
   };
193 183
 };
@@ -211,8 +201,7 @@  discard block
 block discarded – undo
211 201
 $f=fopen($file,"r");
212 202
 $Header=fread($f,2);
213 203
 
214
-if($Header=="BM")
215
-{
204
+if($Header=="BM") {
216 205
  $Size=freaddword($f);
217 206
  $Reserved1=freadword($f);
218 207
  $Reserved2=freadword($f);
@@ -230,12 +219,10 @@  discard block
 block discarded – undo
230 219
  $NumberOfPalettesUsed=freaddword($f);
231 220
  $NumberOfImportantColors=freaddword($f);
232 221
 
233
-if($biBitCount<24)
234
- {
222
+if($biBitCount<24) {
235 223
   $img=imagecreate($Width,$Height);
236 224
   $Colors=pow(2,$biBitCount);
237
-  for($p=0;$p<$Colors;$p++)
238
-   {
225
+  for($p=0;$p<$Colors;$p++) {
239 226
     $B=freadbyte($f);
240 227
     $G=freadbyte($f);
241 228
     $R=freadbyte($f);
@@ -246,35 +233,34 @@  discard block
 block discarded – undo
246 233
 
247 234
 
248 235
 
249
-if($RLECompression==0)
250
-{
236
+if($RLECompression==0) {
251 237
    $Zbytek=(4-ceil(($Width/(8/$biBitCount)))%4)%4;
252 238
 
253
-for($y=$Height-1;$y>=0;$y--)
254
-    {
239
+for($y=$Height-1;$y>=0;$y--) {
255 240
      $CurrentBit=0;
256
-     for($x=0;$x<$Width;$x++)
257
-      {
241
+     for($x=0;$x<$Width;$x++) {
258 242
          $C=freadbits($f,$biBitCount);
259 243
        imagesetpixel($img,$x,$y,$Palette[$C]);
260 244
       };
261 245
     if($CurrentBit!=0) {freadbyte($f);};
262
-    for($g=0;$g<$Zbytek;$g++)
263
-     freadbyte($f);
246
+    for($g=0;$g<$Zbytek;$g++) {
247
+         freadbyte($f);
248
+    }
264 249
      };
265 250
 
266 251
  };
267 252
 };
268 253
 
269 254
 
270
-if($RLECompression==1) //$BI_RLE8
255
+if($RLECompression==1) {
256
+    //$BI_RLE8
271 257
 {
272 258
 $y=$Height;
259
+}
273 260
 
274 261
 $pocetb=0;
275 262
 
276
-while(true)
277
-{
263
+while(true) {
278 264
 $y--;
279 265
 $prefix=freadbyte($f);
280 266
 $suffix=freadbyte($f);
@@ -282,33 +268,38 @@  discard block
 block discarded – undo
282 268
 
283 269
 $echoit=false;
284 270
 
285
-if($echoit)echo "Prefix: $prefix Suffix: $suffix<BR>";
286
-if(($prefix==0)and($suffix==1)) break;
287
-if(feof($f)) break;
271
+if($echoit) {
272
+    echo "Prefix: $prefix Suffix: $suffix<BR>";
273
+}
274
+if(($prefix==0)and($suffix==1)) {
275
+    break;
276
+}
277
+if(feof($f)) {
278
+    break;
279
+}
288 280
 
289
-while(!(($prefix==0)and($suffix==0)))
290
-{
291
- if($prefix==0)
292
-  {
281
+while(!(($prefix==0)and($suffix==0))) {
282
+ if($prefix==0) {
293 283
    $pocet=$suffix;
294 284
    $Data.=fread($f,$pocet);
295 285
    $pocetb+=$pocet;
296 286
    if($pocetb%2==1) {freadbyte($f); $pocetb++;};
297 287
   };
298
- if($prefix>0)
299
-  {
288
+ if($prefix>0) {
300 289
    $pocet=$prefix;
301
-   for($r=0;$r<$pocet;$r++)
302
-    $Data.=chr($suffix);
290
+   for($r=0;$r<$pocet;$r++) {
291
+       $Data.=chr($suffix);
292
+   }
303 293
   };
304 294
  $prefix=freadbyte($f);
305 295
  $suffix=freadbyte($f);
306 296
  $pocetb+=2;
307
- if($echoit) echo "Prefix: $prefix Suffix: $suffix<BR>";
308
-};
297
+ if($echoit) {
298
+     echo "Prefix: $prefix Suffix: $suffix<BR>";
299
+ }
300
+ };
309 301
 
310
-for($x=0;$x<strlen($Data);$x++)
311
- {
302
+for($x=0;$x<strlen($Data);$x++) {
312 303
   imagesetpixel($img,$x,$y,$Palette[ord($Data[$x])]);
313 304
  };
314 305
 $Data="";
@@ -318,15 +309,16 @@  discard block
 block discarded – undo
318 309
 };
319 310
 
320 311
 
321
-if($RLECompression==2) //$BI_RLE4
312
+if($RLECompression==2) {
313
+    //$BI_RLE4
322 314
 {
323 315
 $y=$Height;
316
+}
324 317
 $pocetb=0;
325 318
 
326 319
 /*while(!feof($f))
327 320
  echo freadbyte($f)."_".freadbyte($f)."<BR>";*/
328
-while(true)
329
-{
321
+while(true) {
330 322
 //break;
331 323
 $y--;
332 324
 $prefix=freadbyte($f);
@@ -335,35 +327,37 @@  discard block
 block discarded – undo
335 327
 
336 328
 $echoit=false;
337 329
 
338
-if($echoit)echo "Prefix: $prefix Suffix: $suffix<BR>";
339
-if(($prefix==0)and($suffix==1)) break;
340
-if(feof($f)) break;
330
+if($echoit) {
331
+    echo "Prefix: $prefix Suffix: $suffix<BR>";
332
+}
333
+if(($prefix==0)and($suffix==1)) {
334
+    break;
335
+}
336
+if(feof($f)) {
337
+    break;
338
+}
341 339
 
342
-while(!(($prefix==0)and($suffix==0)))
343
-{
344
- if($prefix==0)
345
-  {
340
+while(!(($prefix==0)and($suffix==0))) {
341
+ if($prefix==0) {
346 342
    $pocet=$suffix;
347 343
 
348 344
    $CurrentBit=0;
349
-   for($h=0;$h<$pocet;$h++)
350
-    $Data.=chr(freadbits($f,4));
351
-   if($CurrentBit!=0) freadbits($f,4);
345
+   for($h=0;$h<$pocet;$h++) {
346
+       $Data.=chr(freadbits($f,4));
347
+   }
348
+   if($CurrentBit!=0) {
349
+       freadbits($f,4);
350
+   }
352 351
    $pocetb+=ceil(($pocet/2));
353 352
    if($pocetb%2==1) {freadbyte($f); $pocetb++;};
354 353
   };
355
- if($prefix>0)
356
-  {
354
+ if($prefix>0) {
357 355
    $pocet=$prefix;
358 356
    $i=0;
359
-   for($r=0;$r<$pocet;$r++)
360
-    {
361
-    if($i%2==0)
362
-     {
357
+   for($r=0;$r<$pocet;$r++) {
358
+    if($i%2==0) {
363 359
       $Data.=chr($suffix%16);
364
-     }
365
-     else
366
-     {
360
+     } else {
367 361
       $Data.=chr(floor($suffix/16));
368 362
      };
369 363
     $i++;
@@ -372,11 +366,12 @@  discard block
 block discarded – undo
372 366
  $prefix=freadbyte($f);
373 367
  $suffix=freadbyte($f);
374 368
  $pocetb+=2;
375
- if($echoit) echo "Prefix: $prefix Suffix: $suffix<BR>";
376
-};
369
+ if($echoit) {
370
+     echo "Prefix: $prefix Suffix: $suffix<BR>";
371
+ }
372
+ };
377 373
 
378
-for($x=0;$x<strlen($Data);$x++)
379
- {
374
+for($x=0;$x<strlen($Data);$x++) {
380 375
   imagesetpixel($img,$x,$y,$Palette[ord($Data[$x])]);
381 376
  };
382 377
 $Data="";
@@ -386,24 +381,24 @@  discard block
 block discarded – undo
386 381
 };
387 382
 
388 383
 
389
- if($biBitCount==24)
390
-{
384
+ if($biBitCount==24) {
391 385
  $img=imagecreatetruecolor($Width,$Height);
392 386
  $Zbytek=$Width%4;
393 387
 
394
-   for($y=$Height-1;$y>=0;$y--)
395
-    {
396
-     for($x=0;$x<$Width;$x++)
397
-      {
388
+   for($y=$Height-1;$y>=0;$y--) {
389
+     for($x=0;$x<$Width;$x++) {
398 390
        $B=freadbyte($f);
399 391
        $G=freadbyte($f);
400 392
        $R=freadbyte($f);
401 393
        $color=imagecolorexact($img,$R,$G,$B);
402
-       if($color==-1) $color=imagecolorallocate($img,$R,$G,$B);
394
+       if($color==-1) {
395
+           $color=imagecolorallocate($img,$R,$G,$B);
396
+       }
403 397
        imagesetpixel($img,$x,$y,$color);
404 398
       }
405
-    for($z=0;$z<$Zbytek;$z++)
406
-     freadbyte($f);
399
+    for($z=0;$z<$Zbytek;$z++) {
400
+         freadbyte($f);
401
+    }
407 402
    };
408 403
 };
409 404
 return $img;
@@ -480,12 +475,9 @@  discard block
 block discarded – undo
480 475
  $Byte=freadbyte($f);
481 476
  $LastCBit=$CurrentBit;
482 477
  $CurrentBit+=$count;
483
- if($CurrentBit==8)
484
-  {
478
+ if($CurrentBit==8) {
485 479
    $CurrentBit=0;
486
-  }
487
- else
488
-  {
480
+  } else {
489 481
    fseek($f,ftell($f)-1);
490 482
   };
491 483
  return RetBits($Byte,$LastCBit,$count);
@@ -494,10 +486,16 @@  discard block
 block discarded – undo
494 486
 
495 487
 
496 488
 function RGBToHex($Red,$Green,$Blue)
497
-  {
498
-   $hRed=dechex($Red);if(strlen($hRed)==1) $hRed="0$hRed";
499
-   $hGreen=dechex($Green);if(strlen($hGreen)==1) $hGreen="0$hGreen";
500
-   $hBlue=dechex($Blue);if(strlen($hBlue)==1) $hBlue="0$hBlue";
489
+{
490
+   $hRed=dechex($Red);if(strlen($hRed)==1) {
491
+       $hRed="0$hRed";
492
+   }
493
+   $hGreen=dechex($Green);if(strlen($hGreen)==1) {
494
+       $hGreen="0$hGreen";
495
+   }
496
+   $hBlue=dechex($Blue);if(strlen($hBlue)==1) {
497
+       $hBlue="0$hBlue";
498
+   }
501 499
    return($hRed.$hGreen.$hBlue);
502 500
   };
503 501
 
@@ -520,8 +518,9 @@  discard block
 block discarded – undo
520 518
 {
521 519
 $bin=decbin($d);
522 520
 $sbin=strlen($bin);
523
-for($j=0;$j<$n-$sbin;$j++)
521
+for($j=0;$j<$n-$sbin;$j++) {
524 522
  $bin="0$bin";
523
+}
525 524
 return $bin;
526 525
 };
527 526
 
Please login to merge, or discard this patch.
htdocs/lib2/RSSParser.class.php 1 patch
Braces   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -71,7 +71,8 @@
 block discarded – undo
71 71
                                 // e.g. in SMF Forum Threads
72 72
                             } elseif (!in_array(htmlspecialchars_decode($item->title), $headlines) &&
73 73
                                 strpos($item->title, 'VERSCHOBEN') === false
74
-                            ) { // hack to exclude forum thread-move messages
74
+                            ) {
75
+// hack to exclude forum thread-move messages
75 76
                                 // fill array
76 77
                                 $rss[] = array(
77 78
                                     'pubDate' => date('Y-m-d', strtotime($item->pubDate)),
Please login to merge, or discard this patch.