Passed
Push — master ( 8e685f...ce48d5 )
by Kevin
13:20
created
html/inc/util.inc 1 patch
Spacing   +78 added lines, -78 removed lines patch added patch discarded remove patch
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
 //
39 39
 $config = get_config();
40 40
 global $master_url;
41
-$master_url = parse_config($config , "<master_url>");
41
+$master_url = parse_config($config, "<master_url>");
42 42
 $recaptcha_public_key = parse_config($config, "<recaptcha_public_key>");
43 43
 $recaptcha_private_key = parse_config($config, "<recaptcha_private_key>");
44 44
 
@@ -127,10 +127,10 @@  discard block
 block discarded – undo
127 127
 }
128 128
 
129 129
 function url_base() {
130
-    return is_https()?secure_url_base():URL_BASE;
130
+    return is_https() ?secure_url_base() : URL_BASE;
131 131
 }
132 132
 
133
-function send_cookie($name, $value, $permanent, $ops=false) {
133
+function send_cookie($name, $value, $permanent, $ops = false) {
134 134
     global $master_url;
135 135
 
136 136
     // the following allows independent login for projects on the same server
@@ -141,11 +141,11 @@  discard block
 block discarded – undo
141 141
         $path = substr($path, 0, -1);
142 142
         $path .= "_ops/";
143 143
     }
144
-    $expire = $permanent?time()+3600*24*365:0;
144
+    $expire = $permanent ?time() + 3600*24*365 : 0;
145 145
     setcookie($name, $value, $expire, $path);
146 146
 }
147 147
 
148
-function clear_cookie($name, $ops=false) {
148
+function clear_cookie($name, $ops = false) {
149 149
     global $master_url;
150 150
     $url = parse_url($master_url);
151 151
     $path = $url['path'];
@@ -153,13 +153,13 @@  discard block
 block discarded – undo
153 153
         $path = substr($path, 0, -1);
154 154
         $path .= "_ops/";
155 155
     }
156
-    setcookie($name, '', time()-3600, $path);
156
+    setcookie($name, '', time() - 3600, $path);
157 157
 }
158 158
 
159 159
 $g_logged_in_user = null;
160 160
 $got_logged_in_user = false;
161 161
 
162
-function get_logged_in_user($must_be_logged_in=true) {
162
+function get_logged_in_user($must_be_logged_in = true) {
163 163
     global $g_logged_in_user, $got_logged_in_user;
164 164
     if ($got_logged_in_user) return $g_logged_in_user;
165 165
 
@@ -178,7 +178,7 @@  discard block
 block discarded – undo
178 178
             $next_url = $_SERVER['REQUEST_URI'];
179 179
             $n = strrpos($next_url, "/");
180 180
             if ($n) {
181
-                $next_url = substr($next_url, $n+1);
181
+                $next_url = substr($next_url, $n + 1);
182 182
             }
183 183
         }
184 184
         $next_url = urlencode($next_url);
@@ -189,7 +189,7 @@  discard block
 block discarded – undo
189 189
     return $g_logged_in_user;
190 190
 }
191 191
 
192
-function show_login_info($prefix="") {
192
+function show_login_info($prefix = "") {
193 193
     $user = get_logged_in_user(false);
194 194
     if ($user) {
195 195
         $url_tokens = url_tokens($user->authenticator);
@@ -199,7 +199,7 @@  discard block
 block discarded – undo
199 199
     }
200 200
 }
201 201
 
202
-$cache_control_extra="";
202
+$cache_control_extra = "";
203 203
 $is_login_page = false;
204 204
 
205 205
 // Call this to start pages.
@@ -211,11 +211,11 @@  discard block
 block discarded – undo
211 211
 // with an existing web framework can more easily do so.
212 212
 // To do so, define page_head() in the project include file.
213 213
 //
214
-if (!function_exists("page_head")){
214
+if (!function_exists("page_head")) {
215 215
 function page_head(
216 216
     $title,
217 217
         // page title. Put in <title>, used as title for browser tab.
218
-    $body_attrs=null,
218
+    $body_attrs = null,
219 219
         // <body XXXX>
220 220
         // e.g. Javascript to put focus in an input field
221 221
         // (onload="document.form.foo.focus()")
@@ -224,10 +224,10 @@  discard block
 block discarded – undo
224 224
         // if set, include schedulers.txt.
225 225
         // also pass to project_banner() in case you want a different
226 226
         // header for your main page.
227
-    $url_prefix="",
227
+    $url_prefix = "",
228 228
         // prepend this to links.
229 229
         // Use for web pages not in the top directory
230
-    $head_extra=null
230
+    $head_extra = null
231 231
         // extra stuff to put in <head>. E.g.:
232 232
         // reCAPTCHA code (create_profile.php)
233 233
         // bbcode javascript (forums)
@@ -243,10 +243,10 @@  discard block
 block discarded – undo
243 243
 
244 244
     if (!$caching) {
245 245
         header("Content-type: text/html; charset=utf-8");
246
-        header ("Expires: Mon, 26 Jul 1997 05:00:00 UTC");    // Date in the past
247
-        header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " UTC"); // always modified
248
-        header ("Cache-Control: $cache_control_extra no-cache, must-revalidate, post-check=0, pre-check=0");  // HTTP/1.1
249
-        header ("Pragma: no-cache");                          // HTTP/1.0
246
+        header("Expires: Mon, 26 Jul 1997 05:00:00 UTC"); // Date in the past
247
+        header("Last-Modified: ".gmdate("D, d M Y H:i:s")." UTC"); // always modified
248
+        header("Cache-Control: $cache_control_extra no-cache, must-revalidate, post-check=0, pre-check=0"); // HTTP/1.1
249
+        header("Pragma: no-cache"); // HTTP/1.0
250 250
     }
251 251
 
252 252
     echo '<!DOCTYPE html>
@@ -257,11 +257,11 @@  discard block
 block discarded – undo
257 257
     if ($head_extra) {
258 258
         echo "\n$head_extra\n";
259 259
     }
260
-    if ($is_main && (!defined('NO_COMPUTING')||!NO_COMPUTING)) {
260
+    if ($is_main && (!defined('NO_COMPUTING') || !NO_COMPUTING)) {
261 261
         readfile("schedulers.txt");
262 262
     }
263 263
 
264
-    $t = $title?$title:PROJECT;
264
+    $t = $title ? $title : PROJECT;
265 265
     echo "<title>$t</title>\n";
266 266
     echo '
267 267
         <meta charset="utf-8">
@@ -297,7 +297,7 @@  discard block
 block discarded – undo
297 297
     echo '<div class="container-fluid">
298 298
     ';
299 299
 
300
-    switch($title) {    //kludge
300
+    switch ($title) {    //kludge
301 301
     case tra("Log in"):
302 302
     case tra("Create an account"):
303 303
     case tra("Server status page"):
@@ -312,13 +312,13 @@  discard block
 block discarded – undo
312 312
 
313 313
 // See the comments for page_head()
314 314
 //
315
-if (!function_exists("page_tail")){
315
+if (!function_exists("page_tail")) {
316 316
 function page_tail(
317
-    $show_date=false,
317
+    $show_date = false,
318 318
         // true for pages that are generated periodically rather than on the fly
319
-    $url_prefix="",
319
+    $url_prefix = "",
320 320
         // use for pages not at top level
321
-    $is_main=false
321
+    $is_main = false
322 322
         // passed to project_footer;
323 323
 ) {
324 324
     echo "<br>\n";
@@ -333,10 +333,10 @@  discard block
 block discarded – undo
333 333
 }
334 334
 }
335 335
 
336
-function display_cvs_versions(){
336
+function display_cvs_versions() {
337 337
     global $cvs_version_tracker;
338 338
     echo "\n<!-- SVN VERSIONS -->\n";
339
-    for ($i=0;$i<sizeof($cvs_version_tracker);$i++) {
339
+    for ($i = 0; $i < sizeof($cvs_version_tracker); $i++) {
340 340
         echo "<!-- ".$cvs_version_tracker[$i]." -->\n";
341 341
     }
342 342
 }
@@ -361,23 +361,23 @@  discard block
 block discarded – undo
361 361
 // takes argument in second and returns a human formatted time string
362 362
 // in the form D days + h Hours + m Min + s sec.
363 363
 
364
-function time_diff($x, $res=3) {
364
+function time_diff($x, $res = 3) {
365 365
     $days    = (int)($x/86400);
366
-    $hours   = (int)(($x-$days*86400)/3600);
367
-    $minutes = (int)(($x-$days*86400-$hours*3600)/60);
368
-    $seconds = (int)($x % 60);
366
+    $hours   = (int)(($x - $days*86400)/3600);
367
+    $minutes = (int)(($x - $days*86400 - $hours*3600)/60);
368
+    $seconds = (int)($x%60);
369 369
 
370 370
     $datestring = "";
371 371
     if ($days) {
372 372
         $datestring .= "$days ".tra("days")." ";
373 373
     }
374
-    if ($res>0 && ($hours || strlen($datestring))) {
374
+    if ($res > 0 && ($hours || strlen($datestring))) {
375 375
         $datestring .= "$hours ".tra("hours")." ";
376 376
     }
377
-    if ($res>1 && ($minutes || strlen($datestring))) {
377
+    if ($res > 1 && ($minutes || strlen($datestring))) {
378 378
         $datestring .= "$minutes ".tra("min")." ";
379 379
     }
380
-    if ($res>2 && ($seconds)) {
380
+    if ($res > 2 && ($seconds)) {
381 381
         $datestring .= "$seconds ".tra("sec")." ";
382 382
     }
383 383
 
@@ -392,7 +392,7 @@  discard block
 block discarded – undo
392 392
 
393 393
 function time_str($x) {
394 394
     if ($x == 0) return "---";
395
-    return gmdate('j M Y, G:i:s', $x) . " UTC";
395
+    return gmdate('j M Y, G:i:s', $x)." UTC";
396 396
 }
397 397
 
398 398
 function local_time_str($x) {
@@ -404,14 +404,14 @@  discard block
 block discarded – undo
404 404
     return time_str($x);
405 405
 }
406 406
 
407
-function start_table_str($class="", $style="") {
408
-    $s = $style?'style="'.$style.'"':'';
407
+function start_table_str($class = "", $style = "") {
408
+    $s = $style ? 'style="'.$style.'"' : '';
409 409
     return '<div class="table">
410 410
       <table '.$s.' width="100%" class="table table-condensed '.$class.'" >
411 411
     ';
412 412
 }
413 413
 
414
-function start_table($class="", $style="") {
414
+function start_table($class = "", $style = "") {
415 415
     echo start_table_str($class, $style);
416 416
 }
417 417
 
@@ -456,7 +456,7 @@  discard block
 block discarded – undo
456 456
     echo "</tr>\n";
457 457
 }
458 458
 
459
-function row1($x, $ncols=2, $class="heading") {
459
+function row1($x, $ncols = 2, $class = "heading") {
460 460
     if ($class == "heading") {
461 461
         echo "<tr><th class=\"bg-primary\" colspan=\"$ncols\">$x</th></tr>\n";
462 462
     } else {
@@ -468,10 +468,10 @@  discard block
 block discarded – undo
468 468
 define('VALUE_ATTRS', 'style="padding-left:12px"');
469 469
 define('VALUE_ATTRS_ERR', 'class="danger" style="padding-left:12px"');
470 470
 
471
-function row2($x, $y, $show_error=false, $lwidth='40%') {
472
-    if ($x==="") $x="<br>";
473
-    if ($y==="") $y="<br>";
474
-    $attrs = $show_error?VALUE_ATTRS_ERR:VALUE_ATTRS;
471
+function row2($x, $y, $show_error = false, $lwidth = '40%') {
472
+    if ($x === "") $x = "<br>";
473
+    if ($y === "") $y = "<br>";
474
+    $attrs = $show_error ?VALUE_ATTRS_ERR:VALUE_ATTRS;
475 475
     echo "<tr>
476 476
         <td width=\"$lwidth\" ".NAME_ATTRS.">$x</td>
477 477
         <td $attrs >$y</td>
@@ -479,7 +479,7 @@  discard block
 block discarded – undo
479 479
     ";
480 480
 }
481 481
 
482
-function row2_init($x, $y, $lwidth='40%') {
482
+function row2_init($x, $y, $lwidth = '40%') {
483 483
     echo '<tr>
484 484
         <td class="text-right " width="'.$lwidth.'"  style="padding-right: 20px;">'.$x.'</td>
485 485
         <td '.VALUE_ATTRS.'>'.$y.'
@@ -502,20 +502,20 @@  discard block
 block discarded – undo
502 502
     echo "</tr>\n";
503 503
 }
504 504
 
505
-define ('ALIGN_RIGHT', 'style="text-align:right;"');
505
+define('ALIGN_RIGHT', 'style="text-align:right;"');
506 506
 
507
-function row_heading_array($x, $attrs=null, $class='bg-primary') {
507
+function row_heading_array($x, $attrs = null, $class = 'bg-primary') {
508 508
     echo "<tr>";
509 509
     $i = 0;
510 510
     foreach ($x as $h) {
511
-        $a = $attrs?$attrs[$i]:"";
511
+        $a = $attrs ? $attrs[$i] : "";
512 512
         echo "<th $a class=\"$class\">$h</th>";
513 513
         $i++;
514 514
     }
515 515
     echo "</tr>\n";
516 516
 }
517 517
 
518
-function row_heading($x, $class='bg-primary') {
518
+function row_heading($x, $class = 'bg-primary') {
519 519
     echo sprintf('<tr><th class="%s" colspan=99>%s</th></tr>
520 520
         ', $class, $x
521 521
     );
@@ -571,7 +571,7 @@  discard block
 block discarded – undo
571 571
 // If $ellipsis is true, then an ellipsis is added to any sentence which
572 572
 // is cut short.
573 573
 
574
-function sub_sentence($sentence, $delimiter, $max_chars, $ellipsis=false) {
574
+function sub_sentence($sentence, $delimiter, $max_chars, $ellipsis = false) {
575 575
     $words = explode($delimiter, $sentence);
576 576
     $total_chars = 0;
577 577
     $trunc = false;
@@ -654,8 +654,8 @@  discard block
 block discarded – undo
654 654
 
655 655
 // returns null if the arg is optional and missing
656 656
 //
657
-function get_int($name, $optional=false) {
658
-    $x=null;
657
+function get_int($name, $optional = false) {
658
+    $x = null;
659 659
     if (isset($_GET[$name])) $x = $_GET[$name];
660 660
     if (!is_numeric($x)) {
661 661
         if ($optional) {
@@ -674,7 +674,7 @@  discard block
 block discarded – undo
674 674
 
675 675
 // returns null if the arg is optional and missing
676 676
 //
677
-function post_num($name, $optional=false) {
677
+function post_num($name, $optional = false) {
678 678
     $x = null;
679 679
     if (isset($_POST[$name])) $x = $_POST[$name];
680 680
     if (!is_numeric($x)) {
@@ -689,7 +689,7 @@  discard block
 block discarded – undo
689 689
 
690 690
 // returns null if the arg is optional and missing
691 691
 //
692
-function post_int($name, $optional=false) {
692
+function post_int($name, $optional = false) {
693 693
     $x = post_num($name, $optional);
694 694
     if (is_null($x)) return null;
695 695
     $y = (int)$x;
@@ -707,7 +707,7 @@  discard block
 block discarded – undo
707 707
     }
708 708
 }
709 709
 
710
-function get_str($name, $optional=false) {
710
+function get_str($name, $optional = false) {
711 711
     if (isset($_GET[$name])) {
712 712
         $x = $_GET[$name];
713 713
     } else {
@@ -719,7 +719,7 @@  discard block
 block discarded – undo
719 719
     return undo_magic_quotes($x);
720 720
 }
721 721
 
722
-function post_str($name, $optional=false) {
722
+function post_str($name, $optional = false) {
723 723
     if (isset($_POST[$name])) {
724 724
         $x = $_POST[$name];
725 725
     } else {
@@ -731,7 +731,7 @@  discard block
 block discarded – undo
731 731
     return undo_magic_quotes($x);
732 732
 }
733 733
 
734
-function post_arr($name, $optional=false) {
734
+function post_arr($name, $optional = false) {
735 735
     if (isset($_POST[$name]) && is_array($_POST[$name])) {
736 736
         $x = $_POST[$name];
737 737
     } else {
@@ -747,7 +747,7 @@  discard block
 block discarded – undo
747 747
     // the mb_* functions are not included by default
748 748
     // return (mb_detect_encoding($passwd) -= 'ASCII');
749 749
 
750
-    for ($i=0; $i<strlen($str); $i++) {
750
+    for ($i = 0; $i < strlen($str); $i++) {
751 751
         $c = ord(substr($str, $i));
752 752
         if ($c < 32 || $c > 127) return false;
753 753
     }
@@ -771,7 +771,7 @@  discard block
 block discarded – undo
771 771
     $number = str_replace(',', '.', $number); // replace the german decimal separator
772 772
     // if no value was entered and this is ok
773 773
     //
774
-    if ($number=='' && !$low) return true;
774
+    if ($number == '' && !$low) return true;
775 775
 
776 776
     // the supplied value contains alphabetic characters
777 777
     //
@@ -788,7 +788,7 @@  discard block
 block discarded – undo
788 788
 
789 789
 // Generate a "select" element from an array of values
790 790
 //
791
-function select_from_array($name, $array, $selection=null, $width=240) {
791
+function select_from_array($name, $array, $selection = null, $width = 240) {
792 792
     $out = '<select style="color:#000;"class="form-control input-sm" style="width:'.$width.'px" name="'.$name.'">"';
793 793
 
794 794
     foreach ($array as $key => $value) {
@@ -813,8 +813,8 @@  discard block
 block discarded – undo
813 813
     return $str;
814 814
 }
815 815
 
816
-function strip_bbcode($string){
817
-    return preg_replace("/((\[.+\])+?)(.+?)((\[\/.+\])+?)/","",$string);
816
+function strip_bbcode($string) {
817
+    return preg_replace("/((\[.+\])+?)(.+?)((\[\/.+\])+?)/", "", $string);
818 818
 }
819 819
 
820 820
 function current_url() {
@@ -842,7 +842,7 @@  discard block
 block discarded – undo
842 842
 // @param class The optional CSS class of the button. Defaults to a standard button
843 843
 //
844 844
 
845
-function button_text($url, $text, $desc=null, $class="btn-success btn-sm") {
845
+function button_text($url, $text, $desc = null, $class = "btn-success btn-sm") {
846 846
     if (!$desc) {
847 847
         $desc = $text;
848 848
     }
@@ -851,19 +851,19 @@  discard block
 block discarded – undo
851 851
     );
852 852
 }
853 853
 
854
-function show_button($url, $text, $desc=null, $class="btn-success btn-sm") {
855
-    echo button_text($url, $text, $desc=null, $class);
854
+function show_button($url, $text, $desc = null, $class = "btn-success btn-sm") {
855
+    echo button_text($url, $text, $desc = null, $class);
856 856
 }
857 857
 
858 858
 // for places with a bunch of buttons, like forum posts
859 859
 //
860
-function show_button_small($url, $text, $desc=null) {
860
+function show_button_small($url, $text, $desc = null) {
861 861
     echo button_text($url, $text, $desc, "btn-primary btn-xs");
862 862
 }
863 863
 
864 864
 // used for showing icons
865 865
 //
866
-function show_image($src, $title, $alt, $height=null) {
866
+function show_image($src, $title, $alt, $height = null) {
867 867
     $h = "";
868 868
     if ($height) {
869 869
         $h = "height=\"$height\"";
@@ -900,7 +900,7 @@  discard block
 block discarded – undo
900 900
 // tries instead to connect to <replica_db_host> if tag exists.
901 901
 // DEPRECATED - use boinc_db.inc
902 902
 //
903
-function db_init($try_replica=false) {
903
+function db_init($try_replica = false) {
904 904
     check_web_stopped();
905 905
     $retval = db_init_aux($try_replica);
906 906
     if ($retval == 1) {
@@ -971,7 +971,7 @@  discard block
 block discarded – undo
971 971
 function sanitize_numeric($x) {
972 972
     if (is_numeric($x)) {
973 973
         return $x;
974
-    } else if (trim($x) == '' ) {
974
+    } else if (trim($x) == '') {
975 975
         return '';
976 976
     } else {
977 977
         return "not numeric";
@@ -994,9 +994,9 @@  discard block
 block discarded – undo
994 994
     return $c/(200/24);
995 995
 }
996 996
 
997
-function do_download($path,$name="") {
998
-    if (strcmp($name,"") == 0) {
999
-        $name=basename($path);
997
+function do_download($path, $name = "") {
998
+    if (strcmp($name, "") == 0) {
999
+        $name = basename($path);
1000 1000
     }
1001 1001
     header('Content-Description: File Transfer');
1002 1002
     header('Content-Type: application/octet-stream');
@@ -1005,7 +1005,7 @@  discard block
 block discarded – undo
1005 1005
     header('Expires: 0');
1006 1006
     header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
1007 1007
     header('Pragma: public');
1008
-    header('Content-Length: ' . filesize($path));
1008
+    header('Content-Length: '.filesize($path));
1009 1009
     flush();
1010 1010
     readfile($path);
1011 1011
 }
@@ -1048,10 +1048,10 @@  discard block
 block discarded – undo
1048 1048
 // Otherwise return 0.
1049 1049
 // Format of user agent string is "BOINC client (windows_x86_64 7.3.17)"
1050 1050
 //
1051
-function boinc_client_version(){
1051
+function boinc_client_version() {
1052 1052
     if (!array_key_exists('HTTP_USER_AGENT', $_SERVER)) return 0;
1053 1053
     $x = $_SERVER['HTTP_USER_AGENT'];
1054
-    $e =  "/BOINC client [^ ]* (\d+).(\d+).(\d+)\)/";
1054
+    $e = "/BOINC client [^ ]* (\d+).(\d+).(\d+)\)/";
1055 1055
     if (preg_match($e, $x, $matches)) {
1056 1056
         return $matches[1]*10000 + $matches[2]*100 + $matches[3];
1057 1057
     }
@@ -1080,7 +1080,7 @@  discard block
 block discarded – undo
1080 1080
     $rem_name = $name."_remaining";
1081 1081
     return "<textarea name=\"$name\" class=\"form-control\" rows=3 id=\"$name\" onkeydown=\"text_counter(this.form.$name, this.form.$rem_name, $maxlen);\"
1082 1082
         onkeyup=\"text_counter(this.form.$name, this.form.$rem_name, $maxlen);\">".$text."</textarea>
1083
-        <br><input name=\"$rem_name\" type=\"text\" id=\"$rem_name\" value=\"".($maxlen-strlen($text))."\" size=\"3\" maxlength=\"3\" readonly> ".tra("characters remaining")
1083
+        <br><input name=\"$rem_name\" type=\"text\" id=\"$rem_name\" value=\"".($maxlen - strlen($text))."\" size=\"3\" maxlength=\"3\" readonly> ".tra("characters remaining")
1084 1084
     ;
1085 1085
 }
1086 1086
 
@@ -1110,7 +1110,7 @@  discard block
 block discarded – undo
1110 1110
 // use the following around text with long lines,
1111 1111
 // to limit the width and make it more readable.
1112 1112
 //
1113
-function text_start($width=640) {
1113
+function text_start($width = 640) {
1114 1114
     echo sprintf("<div style=\"max-width: %dpx;\">\n", $width);
1115 1115
 }
1116 1116
 function text_end() {
@@ -1118,9 +1118,9 @@  discard block
 block discarded – undo
1118 1118
 }
1119 1119
 
1120 1120
 function cert_filename() {
1121
-    return defined("CERT_FILENAME")?CERT_FILENAME:"cert1.php";
1121
+    return defined("CERT_FILENAME") ?CERT_FILENAME:"cert1.php";
1122 1122
 }
1123 1123
 
1124
-$cvs_version_tracker[]="\$Id$";  //Generated automatically - do not edit
1124
+$cvs_version_tracker[] = "\$Id$"; //Generated automatically - do not edit
1125 1125
 
1126 1126
 ?>
Please login to merge, or discard this patch.