Passed
Pull Request — master (#5470)
by David
09:30
created
html/inc/util.inc 1 patch
Spacing   +76 added lines, -76 removed lines patch added patch discarded remove patch
@@ -37,17 +37,17 @@  discard block
 block discarded – undo
37 37
 //
38 38
 $config = get_config();
39 39
 global $master_url;
40
-$master_url = parse_config($config , "<master_url>");
40
+$master_url = parse_config($config, "<master_url>");
41 41
 $recaptcha_public_key = parse_config($config, "<recaptcha_public_key>");
42 42
 $recaptcha_private_key = parse_config($config, "<recaptcha_private_key>");
43 43
 
44 44
 // the following default to on
45 45
 //
46 46
 $x = parse_config($config, "<user_country>");
47
-define('USER_COUNTRY', ($x===null)?1:(int)$x);
47
+define('USER_COUNTRY', ($x === null) ? 1 : (int)$x);
48 48
 
49 49
 $x = parse_config($config, "<user_url>");
50
-define('USER_URL', ($x===null)?1:(int)$x);
50
+define('USER_URL', ($x === null) ? 1 : (int)$x);
51 51
 
52 52
 // don't allow /... at the end of URL
53 53
 //
@@ -142,10 +142,10 @@  discard block
 block discarded – undo
142 142
 }
143 143
 
144 144
 function url_base() {
145
-    return is_https()?secure_url_base():URL_BASE;
145
+    return is_https() ?secure_url_base() : URL_BASE;
146 146
 }
147 147
 
148
-function send_cookie($name, $value, $permanent, $ops=false) {
148
+function send_cookie($name, $value, $permanent, $ops = false) {
149 149
     global $master_url;
150 150
 
151 151
     // the following allows independent login for projects on the same server
@@ -156,11 +156,11 @@  discard block
 block discarded – undo
156 156
         $path = substr($path, 0, -1);
157 157
         $path .= "_ops/";
158 158
     }
159
-    $expire = $permanent?time()+3600*24*365:0;
159
+    $expire = $permanent ?time() + 3600*24*365 : 0;
160 160
     setcookie($name, $value, $expire, $path);
161 161
 }
162 162
 
163
-function clear_cookie($name, $ops=false) {
163
+function clear_cookie($name, $ops = false) {
164 164
     global $master_url;
165 165
     $url = parse_url($master_url);
166 166
     $path = $url['path'];
@@ -168,13 +168,13 @@  discard block
 block discarded – undo
168 168
         $path = substr($path, 0, -1);
169 169
         $path .= "_ops/";
170 170
     }
171
-    setcookie($name, '', time()-3600, $path);
171
+    setcookie($name, '', time() - 3600, $path);
172 172
 }
173 173
 
174 174
 $g_logged_in_user = null;
175 175
 $got_logged_in_user = false;
176 176
 
177
-function get_logged_in_user($must_be_logged_in=true) {
177
+function get_logged_in_user($must_be_logged_in = true) {
178 178
     global $g_logged_in_user, $got_logged_in_user;
179 179
     if ($got_logged_in_user) {
180 180
         // this could have been called earlier with $must_be_logged_in false
@@ -200,7 +200,7 @@  discard block
 block discarded – undo
200 200
             $next_url = $_SERVER['REQUEST_URI'];
201 201
             $n = strrpos($next_url, "/");
202 202
             if ($n) {
203
-                $next_url = substr($next_url, $n+1);
203
+                $next_url = substr($next_url, $n + 1);
204 204
             }
205 205
         }
206 206
         $next_url = urlencode($next_url);
@@ -211,7 +211,7 @@  discard block
 block discarded – undo
211 211
     return $g_logged_in_user;
212 212
 }
213 213
 
214
-function show_login_info($prefix="") {
214
+function show_login_info($prefix = "") {
215 215
     $user = get_logged_in_user(false);
216 216
     if ($user) {
217 217
         $url_tokens = url_tokens($user->authenticator);
@@ -221,7 +221,7 @@  discard block
 block discarded – undo
221 221
     }
222 222
 }
223 223
 
224
-$cache_control_extra="";
224
+$cache_control_extra = "";
225 225
 $is_login_page = false;
226 226
 
227 227
 // Call this to start pages.
@@ -233,11 +233,11 @@  discard block
 block discarded – undo
233 233
 // with an existing web framework can more easily do so.
234 234
 // To do so, define page_head() in the project include file.
235 235
 //
236
-if (!function_exists("page_head")){
236
+if (!function_exists("page_head")) {
237 237
 function page_head(
238 238
     $title,
239 239
         // page title. Put in <title>, used as title for browser tab.
240
-    $body_attrs=null,
240
+    $body_attrs = null,
241 241
         // <body XXXX>
242 242
         // e.g. Javascript to put focus in an input field
243 243
         // (onload="document.form.foo.focus()")
@@ -246,10 +246,10 @@  discard block
 block discarded – undo
246 246
         // if set, include schedulers.txt.
247 247
         // also pass to project_banner() in case you want a different
248 248
         // header for your main page.
249
-    $url_prefix="",
249
+    $url_prefix = "",
250 250
         // prepend this to links.
251 251
         // Use for web pages not in the top directory
252
-    $head_extra=null
252
+    $head_extra = null
253 253
         // extra stuff to put in <head>. E.g.:
254 254
         // reCAPTCHA code (create_profile.php)
255 255
         // bbcode javascript (forums)
@@ -271,7 +271,7 @@  discard block
 block discarded – undo
271 271
         header("Content-type: text/html; charset=utf-8");
272 272
         header("Expires: Mon, 26 Jul 1997 05:00:00 UTC");
273 273
             // Date in the past
274
-        header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " UTC");
274
+        header("Last-Modified: ".gmdate("D, d M Y H:i:s")." UTC");
275 275
             // always modified
276 276
         header("Cache-Control: $cache_control_extra no-cache, must-revalidate, post-check=0, pre-check=0");
277 277
             // for HTTP/1.1
@@ -292,11 +292,11 @@  discard block
 block discarded – undo
292 292
     if ($head_extra) {
293 293
         echo "\n$head_extra\n";
294 294
     }
295
-    if ($is_main && (!defined('NO_COMPUTING')||!NO_COMPUTING)) {
295
+    if ($is_main && (!defined('NO_COMPUTING') || !NO_COMPUTING)) {
296 296
         readfile("schedulers.txt");
297 297
     }
298 298
 
299
-    $t = $title?$title:PROJECT;
299
+    $t = $title ? $title : PROJECT;
300 300
     echo "<title>$t</title>\n";
301 301
     echo '
302 302
         <meta charset="utf-8">
@@ -353,7 +353,7 @@  discard block
 block discarded – undo
353 353
     echo '<div class="container-fluid">
354 354
     ';
355 355
 
356
-    switch($title) {    //kludge
356
+    switch ($title) {    //kludge
357 357
     case tra("Log in"):
358 358
     case tra("Create an account"):
359 359
     case tra("Server status page"):
@@ -368,13 +368,13 @@  discard block
 block discarded – undo
368 368
 
369 369
 // See the comments for page_head()
370 370
 //
371
-if (!function_exists("page_tail")){
371
+if (!function_exists("page_tail")) {
372 372
 function page_tail(
373
-    $show_date=false,
373
+    $show_date = false,
374 374
         // true for pages that are generated periodically rather than on the fly
375
-    $url_prefix="",
375
+    $url_prefix = "",
376 376
         // use for pages not at top level
377
-    $is_main=false
377
+    $is_main = false
378 378
         // passed to project_footer;
379 379
 ) {
380 380
     echo "<br>\n";
@@ -389,10 +389,10 @@  discard block
 block discarded – undo
389 389
 }
390 390
 }
391 391
 
392
-function display_cvs_versions(){
392
+function display_cvs_versions() {
393 393
     global $cvs_version_tracker;
394 394
     echo "\n<!-- SVN VERSIONS -->\n";
395
-    for ($i=0;$i<sizeof($cvs_version_tracker);$i++) {
395
+    for ($i = 0; $i < sizeof($cvs_version_tracker); $i++) {
396 396
         echo "<!-- ".$cvs_version_tracker[$i]." -->\n";
397 397
     }
398 398
 }
@@ -417,23 +417,23 @@  discard block
 block discarded – undo
417 417
 // takes argument in second and returns a human formatted time string
418 418
 // in the form D days + h Hours + m Min + s sec.
419 419
 
420
-function time_diff($x, $res=3) {
420
+function time_diff($x, $res = 3) {
421 421
     $days    = (int)($x/86400);
422
-    $hours   = (int)(($x-$days*86400)/3600);
423
-    $minutes = (int)(($x-$days*86400-$hours*3600)/60);
424
-    $seconds = (int)($x % 60);
422
+    $hours   = (int)(($x - $days*86400)/3600);
423
+    $minutes = (int)(($x - $days*86400 - $hours*3600)/60);
424
+    $seconds = (int)($x%60);
425 425
 
426 426
     $datestring = "";
427 427
     if ($days) {
428 428
         $datestring .= "$days ".tra("days")." ";
429 429
     }
430
-    if ($res>0 && ($hours || strlen($datestring))) {
430
+    if ($res > 0 && ($hours || strlen($datestring))) {
431 431
         $datestring .= "$hours ".tra("hours")." ";
432 432
     }
433
-    if ($res>1 && ($minutes || strlen($datestring))) {
433
+    if ($res > 1 && ($minutes || strlen($datestring))) {
434 434
         $datestring .= "$minutes ".tra("min")." ";
435 435
     }
436
-    if ($res>2 && ($seconds)) {
436
+    if ($res > 2 && ($seconds)) {
437 437
         $datestring .= "$seconds ".tra("sec")." ";
438 438
     }
439 439
 
@@ -448,7 +448,7 @@  discard block
 block discarded – undo
448 448
 
449 449
 function time_str($x) {
450 450
     if ($x == 0) return "---";
451
-    return gmdate('j M Y, G:i:s', (int)$x) . " UTC";
451
+    return gmdate('j M Y, G:i:s', (int)$x)." UTC";
452 452
 }
453 453
 
454 454
 function local_time_str($x) {
@@ -460,14 +460,14 @@  discard block
 block discarded – undo
460 460
     return time_str($x);
461 461
 }
462 462
 
463
-function start_table_str($class="", $style="") {
464
-    $s = $style?'style="'.$style.'"':'';
463
+function start_table_str($class = "", $style = "") {
464
+    $s = $style ? 'style="'.$style.'"' : '';
465 465
     return '<div class="table">
466 466
       <table '.$s.' width="100%" class="table table-condensed '.$class.'" >
467 467
     ';
468 468
 }
469 469
 
470
-function start_table($class="", $style="") {
470
+function start_table($class = "", $style = "") {
471 471
     echo start_table_str($class, $style);
472 472
 }
473 473
 
@@ -512,7 +512,7 @@  discard block
 block discarded – undo
512 512
     echo "</tr>\n";
513 513
 }
514 514
 
515
-function row1($x, $ncols=2, $class="heading") {
515
+function row1($x, $ncols = 2, $class = "heading") {
516 516
     if ($class == "heading") {
517 517
         echo "<tr><th class=\"bg-primary\" colspan=\"$ncols\">$x</th></tr>\n";
518 518
     } else {
@@ -524,10 +524,10 @@  discard block
 block discarded – undo
524 524
 define('VALUE_ATTRS', 'style="padding-left:12px"');
525 525
 define('VALUE_ATTRS_ERR', 'class="danger" style="padding-left:12px"');
526 526
 
527
-function row2($x, $y, $show_error=false, $lwidth='40%') {
528
-    if ($x==="") $x="<br>";
529
-    if ($y==="") $y="<br>";
530
-    $attrs = $show_error?VALUE_ATTRS_ERR:VALUE_ATTRS;
527
+function row2($x, $y, $show_error = false, $lwidth = '40%') {
528
+    if ($x === "") $x = "<br>";
529
+    if ($y === "") $y = "<br>";
530
+    $attrs = $show_error ?VALUE_ATTRS_ERR:VALUE_ATTRS;
531 531
     echo "<tr>
532 532
         <td width=\"$lwidth\" ".NAME_ATTRS.">$x</td>
533 533
         <td $attrs >$y</td>
@@ -535,7 +535,7 @@  discard block
 block discarded – undo
535 535
     ";
536 536
 }
537 537
 
538
-function row2_init($x, $y, $lwidth='40%') {
538
+function row2_init($x, $y, $lwidth = '40%') {
539 539
     echo '<tr>
540 540
         <td class="text-right " width="'.$lwidth.'"  style="padding-right: 20px;">'.$x.'</td>
541 541
         <td '.VALUE_ATTRS.'>'.$y.'
@@ -558,20 +558,20 @@  discard block
 block discarded – undo
558 558
     echo "</tr>\n";
559 559
 }
560 560
 
561
-define ('ALIGN_RIGHT', 'style="text-align:right;"');
561
+define('ALIGN_RIGHT', 'style="text-align:right;"');
562 562
 
563
-function row_heading_array($x, $attrs=null, $class='bg-primary') {
563
+function row_heading_array($x, $attrs = null, $class = 'bg-primary') {
564 564
     echo "<tr>";
565 565
     $i = 0;
566 566
     foreach ($x as $h) {
567
-        $a = $attrs?$attrs[$i]:"";
567
+        $a = $attrs ? $attrs[$i] : "";
568 568
         echo "<th $a class=\"$class\">$h</th>";
569 569
         $i++;
570 570
     }
571 571
     echo "</tr>\n";
572 572
 }
573 573
 
574
-function row_heading($x, $class='bg-primary') {
574
+function row_heading($x, $class = 'bg-primary') {
575 575
     echo sprintf('<tr><th class="%s" colspan=99>%s</th></tr>
576 576
         ', $class, $x
577 577
     );
@@ -631,7 +631,7 @@  discard block
 block discarded – undo
631 631
 // If $ellipsis is true, then an ellipsis is added to any sentence which
632 632
 // is cut short.
633 633
 
634
-function sub_sentence($sentence, $delimiter, $max_chars, $ellipsis=false) {
634
+function sub_sentence($sentence, $delimiter, $max_chars, $ellipsis = false) {
635 635
     $words = explode($delimiter, $sentence);
636 636
     $total_chars = 0;
637 637
     $trunc = false;
@@ -714,8 +714,8 @@  discard block
 block discarded – undo
714 714
 
715 715
 // returns null if the arg is optional and missing
716 716
 //
717
-function get_int($name, $optional=false) {
718
-    $x=null;
717
+function get_int($name, $optional = false) {
718
+    $x = null;
719 719
     if (isset($_GET[$name])) $x = $_GET[$name];
720 720
     if (!is_numeric($x)) {
721 721
         if ($optional) {
@@ -734,7 +734,7 @@  discard block
 block discarded – undo
734 734
 
735 735
 // returns null if the arg is optional and missing
736 736
 //
737
-function post_num($name, $optional=false) {
737
+function post_num($name, $optional = false) {
738 738
     $x = null;
739 739
     if (isset($_POST[$name])) $x = $_POST[$name];
740 740
     if (!is_numeric($x)) {
@@ -749,7 +749,7 @@  discard block
 block discarded – undo
749 749
 
750 750
 // returns null if the arg is optional and missing
751 751
 //
752
-function post_int($name, $optional=false) {
752
+function post_int($name, $optional = false) {
753 753
     $x = post_num($name, $optional);
754 754
     if (is_null($x)) return null;
755 755
     $y = (int)$x;
@@ -767,7 +767,7 @@  discard block
 block discarded – undo
767 767
     }
768 768
 }
769 769
 
770
-function get_str($name, $optional=false) {
770
+function get_str($name, $optional = false) {
771 771
     if (isset($_GET[$name])) {
772 772
         $x = $_GET[$name];
773 773
     } else {
@@ -779,7 +779,7 @@  discard block
 block discarded – undo
779 779
     return undo_magic_quotes($x);
780 780
 }
781 781
 
782
-function post_str($name, $optional=false) {
782
+function post_str($name, $optional = false) {
783 783
     if (isset($_POST[$name])) {
784 784
         $x = $_POST[$name];
785 785
     } else {
@@ -791,7 +791,7 @@  discard block
 block discarded – undo
791 791
     return undo_magic_quotes($x);
792 792
 }
793 793
 
794
-function post_arr($name, $optional=false) {
794
+function post_arr($name, $optional = false) {
795 795
     if (isset($_POST[$name]) && is_array($_POST[$name])) {
796 796
         $x = $_POST[$name];
797 797
     } else {
@@ -807,7 +807,7 @@  discard block
 block discarded – undo
807 807
     // the mb_* functions are not included by default
808 808
     // return (mb_detect_encoding($passwd) -= 'ASCII');
809 809
 
810
-    for ($i=0; $i<strlen($str); $i++) {
810
+    for ($i = 0; $i < strlen($str); $i++) {
811 811
         $c = ord(substr($str, $i));
812 812
         if ($c < 32 || $c > 127) return false;
813 813
     }
@@ -831,7 +831,7 @@  discard block
 block discarded – undo
831 831
     $number = str_replace(',', '.', $number); // replace the german decimal separator
832 832
     // if no value was entered and this is ok
833 833
     //
834
-    if ($number=='' && !$low) return true;
834
+    if ($number == '' && !$low) return true;
835 835
 
836 836
     // the supplied value contains alphabetic characters
837 837
     //
@@ -848,7 +848,7 @@  discard block
 block discarded – undo
848 848
 
849 849
 // Generate a "select" element from an array of values
850 850
 //
851
-function select_from_array($name, $array, $selection=null, $width=240) {
851
+function select_from_array($name, $array, $selection = null, $width = 240) {
852 852
     $out = '<select style="color:#000;"class="form-control input-sm" style="width:'.$width.'px" name="'.$name.'">"';
853 853
 
854 854
     foreach ($array as $key => $value) {
@@ -873,8 +873,8 @@  discard block
 block discarded – undo
873 873
     return $str;
874 874
 }
875 875
 
876
-function strip_bbcode($string){
877
-    return preg_replace("/((\[.+\])+?)(.+?)((\[\/.+\])+?)/","",$string);
876
+function strip_bbcode($string) {
877
+    return preg_replace("/((\[.+\])+?)(.+?)((\[\/.+\])+?)/", "", $string);
878 878
 }
879 879
 
880 880
 function current_url() {
@@ -903,7 +903,7 @@  discard block
 block discarded – undo
903 903
 // @params extra Additional text in href tag
904 904
 //
905 905
 
906
-function button_text($url, $text, $desc=null, $class=null, $extra='') {
906
+function button_text($url, $text, $desc = null, $class = null, $extra = '') {
907 907
     if (!$desc) {
908 908
         $desc = $text;
909 909
     }
@@ -915,19 +915,19 @@  discard block
 block discarded – undo
915 915
     );
916 916
 }
917 917
 
918
-function show_button($url, $text, $desc=null, $class=null, $extra=null) {
918
+function show_button($url, $text, $desc = null, $class = null, $extra = null) {
919 919
     echo button_text($url, $text, $desc, $class, $extra);
920 920
 }
921 921
 
922 922
 // for places with a bunch of buttons, like forum posts
923 923
 //
924
-function show_button_small($url, $text, $desc=null) {
924
+function show_button_small($url, $text, $desc = null) {
925 925
     echo button_text($url, $text, $desc, "btn-primary btn-xs");
926 926
 }
927 927
 
928 928
 // used for showing icons
929 929
 //
930
-function show_image($src, $title, $alt, $height=null) {
930
+function show_image($src, $title, $alt, $height = null) {
931 931
     $h = "";
932 932
     if ($height) {
933 933
         $h = "height=\"$height\"";
@@ -964,7 +964,7 @@  discard block
 block discarded – undo
964 964
 // tries instead to connect to <replica_db_host> if tag exists.
965 965
 // DEPRECATED - use boinc_db.inc
966 966
 //
967
-function db_init($try_replica=false) {
967
+function db_init($try_replica = false) {
968 968
     check_web_stopped();
969 969
     $retval = db_init_aux($try_replica);
970 970
     if ($retval == 1) {
@@ -1054,7 +1054,7 @@  discard block
 block discarded – undo
1054 1054
 // Check this to avoid XSS vulnerability
1055 1055
 //
1056 1056
 function sanitize_sort_by($x) {
1057
-    switch($x) {
1057
+    switch ($x) {
1058 1058
     case 'expavg_credit':
1059 1059
     case 'total_credit':
1060 1060
         return;
@@ -1071,9 +1071,9 @@  discard block
 block discarded – undo
1071 1071
     return $c/(200/24);
1072 1072
 }
1073 1073
 
1074
-function do_download($path,$name="") {
1075
-    if (strcmp($name,"") == 0) {
1076
-        $name=basename($path);
1074
+function do_download($path, $name = "") {
1075
+    if (strcmp($name, "") == 0) {
1076
+        $name = basename($path);
1077 1077
     }
1078 1078
     header('Content-Description: File Transfer');
1079 1079
     header('Content-Type: application/octet-stream');
@@ -1082,7 +1082,7 @@  discard block
 block discarded – undo
1082 1082
     header('Expires: 0');
1083 1083
     header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
1084 1084
     header('Pragma: public');
1085
-    header('Content-Length: ' . filesize($path));
1085
+    header('Content-Length: '.filesize($path));
1086 1086
     flush();
1087 1087
     readfile($path);
1088 1088
 }
@@ -1131,10 +1131,10 @@  discard block
 block discarded – undo
1131 1131
 // Otherwise return 0.
1132 1132
 // Format of user agent string is "BOINC client (windows_x86_64 7.3.17)"
1133 1133
 //
1134
-function boinc_client_version(){
1134
+function boinc_client_version() {
1135 1135
     if (!array_key_exists('HTTP_USER_AGENT', $_SERVER)) return 0;
1136 1136
     $x = $_SERVER['HTTP_USER_AGENT'];
1137
-    $e =  "/BOINC client [^ ]* (\d+).(\d+).(\d+)\)/";
1137
+    $e = "/BOINC client [^ ]* (\d+).(\d+).(\d+)\)/";
1138 1138
     if (preg_match($e, $x, $matches)) {
1139 1139
         return $matches[1]*10000 + $matches[2]*100 + $matches[3];
1140 1140
     }
@@ -1163,7 +1163,7 @@  discard block
 block discarded – undo
1163 1163
     $rem_name = $name."_remaining";
1164 1164
     return "<textarea name=\"$name\" class=\"form-control\" rows=3 id=\"$name\" onkeydown=\"text_counter(this.form.$name, this.form.$rem_name, $maxlen);\"
1165 1165
         onkeyup=\"text_counter(this.form.$name, this.form.$rem_name, $maxlen);\">".$text."</textarea>
1166
-        <br><input name=\"$rem_name\" type=\"text\" id=\"$rem_name\" value=\"".($maxlen-strlen($text))."\" size=\"3\" maxlength=\"3\" readonly> ".tra("characters remaining")
1166
+        <br><input name=\"$rem_name\" type=\"text\" id=\"$rem_name\" value=\"".($maxlen - strlen($text))."\" size=\"3\" maxlength=\"3\" readonly> ".tra("characters remaining")
1167 1167
     ;
1168 1168
 }
1169 1169
 
@@ -1193,7 +1193,7 @@  discard block
 block discarded – undo
1193 1193
 // use the following around text with long lines,
1194 1194
 // to limit the width and make it more readable.
1195 1195
 //
1196
-function text_start($width=640) {
1196
+function text_start($width = 640) {
1197 1197
     echo sprintf("<div style=\"max-width: %dpx;\">\n", $width);
1198 1198
 }
1199 1199
 function text_end() {
@@ -1219,7 +1219,7 @@  discard block
 block discarded – undo
1219 1219
 }
1220 1220
 
1221 1221
 function cert_filename() {
1222
-    return defined("CERT_FILENAME")?CERT_FILENAME:"cert1.php";
1222
+    return defined("CERT_FILENAME") ?CERT_FILENAME:"cert1.php";
1223 1223
 }
1224 1224
 
1225 1225
 // if user hasn't validated their email addr, tell them to
@@ -1236,6 +1236,6 @@  discard block
 block discarded – undo
1236 1236
     }
1237 1237
 }
1238 1238
 
1239
-$cvs_version_tracker[]="\$Id$";  //Generated automatically - do not edit
1239
+$cvs_version_tracker[] = "\$Id$"; //Generated automatically - do not edit
1240 1240
 
1241 1241
 ?>
Please login to merge, or discard this patch.