Completed
Push — master ( f02629...903674 )
by Kevin
15:50
created
html/inc/util.inc 1 patch
Spacing   +77 added lines, -77 removed lines patch added patch discarded remove patch
@@ -34,7 +34,7 @@  discard block
 block discarded – undo
34 34
 // parse some stuff from config (do it here for efficiency)
35 35
 //
36 36
 $config = get_config();
37
-$master_url = parse_config($config , "<master_url>");
37
+$master_url = parse_config($config, "<master_url>");
38 38
 $recaptcha_public_key = parse_config($config, "<recaptcha_public_key>");
39 39
 $recaptcha_private_key = parse_config($config, "<recaptcha_private_key>");
40 40
 
@@ -123,10 +123,10 @@  discard block
 block discarded – undo
123 123
 }
124 124
 
125 125
 function url_base() {
126
-    return is_https()?secure_url_base():URL_BASE;
126
+    return is_https() ?secure_url_base() : URL_BASE;
127 127
 }
128 128
 
129
-function send_cookie($name, $value, $permanent, $ops=false) {
129
+function send_cookie($name, $value, $permanent, $ops = false) {
130 130
     global $master_url;
131 131
 
132 132
     // the following allows independent login for projects on the same server
@@ -137,11 +137,11 @@  discard block
 block discarded – undo
137 137
         $path = substr($path, 0, -1);
138 138
         $path .= "_ops/";
139 139
     }
140
-    $expire = $permanent?time()+3600*24*365:0;
140
+    $expire = $permanent ?time() + 3600*24*365 : 0;
141 141
     setcookie($name, $value, $expire, $path);
142 142
 }
143 143
 
144
-function clear_cookie($name, $ops=false) {
144
+function clear_cookie($name, $ops = false) {
145 145
     global $master_url;
146 146
     $url = parse_url($master_url);
147 147
     $path = $url['path'];
@@ -149,13 +149,13 @@  discard block
 block discarded – undo
149 149
         $path = substr($path, 0, -1);
150 150
         $path .= "_ops/";
151 151
     }
152
-    setcookie($name, '', time()-3600, $path);
152
+    setcookie($name, '', time() - 3600, $path);
153 153
 }
154 154
 
155 155
 $g_logged_in_user = null;
156 156
 $got_logged_in_user = false;
157 157
 
158
-function get_logged_in_user($must_be_logged_in=true) {
158
+function get_logged_in_user($must_be_logged_in = true) {
159 159
     global $g_logged_in_user, $got_logged_in_user;
160 160
     if ($got_logged_in_user) return $g_logged_in_user;
161 161
 
@@ -174,7 +174,7 @@  discard block
 block discarded – undo
174 174
             $next_url = $_SERVER['REQUEST_URI'];
175 175
             $n = strrpos($next_url, "/");
176 176
             if ($n) {
177
-                $next_url = substr($next_url, $n+1);
177
+                $next_url = substr($next_url, $n + 1);
178 178
             }
179 179
         }
180 180
         $next_url = urlencode($next_url);
@@ -185,7 +185,7 @@  discard block
 block discarded – undo
185 185
     return $g_logged_in_user;
186 186
 }
187 187
 
188
-function show_login_info($prefix="") {
188
+function show_login_info($prefix = "") {
189 189
     $user = get_logged_in_user(false);
190 190
     if ($user) {
191 191
         $url_tokens = url_tokens($user->authenticator);
@@ -195,7 +195,7 @@  discard block
 block discarded – undo
195 195
     }
196 196
 }
197 197
 
198
-$cache_control_extra="";
198
+$cache_control_extra = "";
199 199
 $is_login_page = false;
200 200
 
201 201
 // Call this to start pages.
@@ -207,11 +207,11 @@  discard block
 block discarded – undo
207 207
 // with an existing web framework can more easily do so.
208 208
 // To do so, define page_head() in the project include file.
209 209
 //
210
-if (!function_exists("page_head")){
210
+if (!function_exists("page_head")) {
211 211
 function page_head(
212 212
     $title,
213 213
         // page title. Put in <title>, used as title for browser tab.
214
-    $body_attrs=null,
214
+    $body_attrs = null,
215 215
         // <body XXXX>
216 216
         // e.g. Javascript to put focus in an input field
217 217
         // (onload="document.form.foo.focus()")
@@ -220,10 +220,10 @@  discard block
 block discarded – undo
220 220
         // if set, include schedulers.txt.
221 221
         // also pass to project_banner() in case you want a different
222 222
         // header for your main page.
223
-    $url_prefix="",
223
+    $url_prefix = "",
224 224
         // prepend this to links.
225 225
         // Use for web pages not in the top directory
226
-    $head_extra=null
226
+    $head_extra = null
227 227
         // extra stuff to put in <head>. E.g.:
228 228
         // reCAPTCHA code (create_profile.php)
229 229
         // bbcode javascript (forums)
@@ -239,10 +239,10 @@  discard block
 block discarded – undo
239 239
 
240 240
     if (!$caching) {
241 241
         header("Content-type: text/html; charset=utf-8");
242
-        header ("Expires: Mon, 26 Jul 1997 05:00:00 UTC");    // Date in the past
243
-        header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " UTC"); // always modified
244
-        header ("Cache-Control: $cache_control_extra no-cache, must-revalidate, post-check=0, pre-check=0");  // HTTP/1.1
245
-        header ("Pragma: no-cache");                          // HTTP/1.0
242
+        header("Expires: Mon, 26 Jul 1997 05:00:00 UTC"); // Date in the past
243
+        header("Last-Modified: ".gmdate("D, d M Y H:i:s")." UTC"); // always modified
244
+        header("Cache-Control: $cache_control_extra no-cache, must-revalidate, post-check=0, pre-check=0"); // HTTP/1.1
245
+        header("Pragma: no-cache"); // HTTP/1.0
246 246
     }
247 247
 
248 248
     echo '<!DOCTYPE html>
@@ -253,11 +253,11 @@  discard block
 block discarded – undo
253 253
     if ($head_extra) {
254 254
         echo "\n$head_extra\n";
255 255
     }
256
-    if ($is_main && (!defined('NO_COMPUTING')||!NO_COMPUTING)) {
256
+    if ($is_main && (!defined('NO_COMPUTING') || !NO_COMPUTING)) {
257 257
         readfile("schedulers.txt");
258 258
     }
259 259
 
260
-    $t = $title?$title:PROJECT;
260
+    $t = $title ? $title : PROJECT;
261 261
     echo "<title>$t</title>\n";
262 262
     echo '
263 263
         <meta charset="utf-8">
@@ -293,7 +293,7 @@  discard block
 block discarded – undo
293 293
     echo '<div class="container-fluid">
294 294
     ';
295 295
 
296
-    switch($title) {    //kludge
296
+    switch ($title) {    //kludge
297 297
     case tra("Log in"):
298 298
     case tra("Create an account"):
299 299
     case tra("Server status page"):
@@ -308,13 +308,13 @@  discard block
 block discarded – undo
308 308
 
309 309
 // See the comments for page_head()
310 310
 //
311
-if (!function_exists("page_tail")){
311
+if (!function_exists("page_tail")) {
312 312
 function page_tail(
313
-    $show_date=false,
313
+    $show_date = false,
314 314
         // true for pages that are generated periodically rather than on the fly
315
-    $url_prefix="",
315
+    $url_prefix = "",
316 316
         // use for pages not at top level
317
-    $is_main=false
317
+    $is_main = false
318 318
         // passed to project_footer;
319 319
 ) {
320 320
     echo "<br>\n";
@@ -329,10 +329,10 @@  discard block
 block discarded – undo
329 329
 }
330 330
 }
331 331
 
332
-function display_cvs_versions(){
332
+function display_cvs_versions() {
333 333
     global $cvs_version_tracker;
334 334
     echo "\n<!-- SVN VERSIONS -->\n";
335
-    for ($i=0;$i<sizeof($cvs_version_tracker);$i++) {
335
+    for ($i = 0; $i < sizeof($cvs_version_tracker); $i++) {
336 336
         echo "<!-- ".$cvs_version_tracker[$i]." -->\n";
337 337
     }
338 338
 }
@@ -357,23 +357,23 @@  discard block
 block discarded – undo
357 357
 // takes argument in second and returns a human formatted time string
358 358
 // in the form D days + h Hours + m Min + s sec.
359 359
 
360
-function time_diff($x, $res=3) {
360
+function time_diff($x, $res = 3) {
361 361
     $days    = (int)($x/86400);
362
-    $hours   = (int)(($x-$days*86400)/3600);
363
-    $minutes = (int)(($x-$days*86400-$hours*3600)/60);
364
-    $seconds = (int)($x % 60);
362
+    $hours   = (int)(($x - $days*86400)/3600);
363
+    $minutes = (int)(($x - $days*86400 - $hours*3600)/60);
364
+    $seconds = (int)($x%60);
365 365
 
366 366
     $datestring = "";
367 367
     if ($days) {
368 368
         $datestring .= "$days ".tra("days")." ";
369 369
     }
370
-    if ($res>0 && ($hours || strlen($datestring))) {
370
+    if ($res > 0 && ($hours || strlen($datestring))) {
371 371
         $datestring .= "$hours ".tra("hours")." ";
372 372
     }
373
-    if ($res>1 && ($minutes || strlen($datestring))) {
373
+    if ($res > 1 && ($minutes || strlen($datestring))) {
374 374
         $datestring .= "$minutes ".tra("min")." ";
375 375
     }
376
-    if ($res>2 && ($seconds)) {
376
+    if ($res > 2 && ($seconds)) {
377 377
         $datestring .= "$seconds ".tra("sec")." ";
378 378
     }
379 379
 
@@ -388,7 +388,7 @@  discard block
 block discarded – undo
388 388
 
389 389
 function time_str($x) {
390 390
     if ($x == 0) return "---";
391
-    return gmdate('j M Y, G:i:s', $x) . " UTC";
391
+    return gmdate('j M Y, G:i:s', $x)." UTC";
392 392
 }
393 393
 
394 394
 function local_time_str($x) {
@@ -400,14 +400,14 @@  discard block
 block discarded – undo
400 400
     return time_str($x);
401 401
 }
402 402
 
403
-function start_table_str($class="", $style="") {
404
-    $s = $style?'style="'.$style.'"':'';
403
+function start_table_str($class = "", $style = "") {
404
+    $s = $style ? 'style="'.$style.'"' : '';
405 405
     return '<div class="table">
406 406
       <table '.$s.' width="100%" class="table table-condensed '.$class.'" >
407 407
     ';
408 408
 }
409 409
 
410
-function start_table($class="", $style="") {
410
+function start_table($class = "", $style = "") {
411 411
     echo start_table_str($class, $style);
412 412
 }
413 413
 
@@ -452,7 +452,7 @@  discard block
 block discarded – undo
452 452
     echo "</tr>\n";
453 453
 }
454 454
 
455
-function row1($x, $ncols=2, $class="heading") {
455
+function row1($x, $ncols = 2, $class = "heading") {
456 456
     if ($class == "heading") {
457 457
         echo "<tr><th class=\"bg-primary\" colspan=\"$ncols\">$x</th></tr>\n";
458 458
     } else {
@@ -464,10 +464,10 @@  discard block
 block discarded – undo
464 464
 define('VALUE_ATTRS', 'style="padding-left:12px"');
465 465
 define('VALUE_ATTRS_ERR', 'class="danger" style="padding-left:12px"');
466 466
 
467
-function row2($x, $y, $show_error=false, $lwidth='40%') {
468
-    if ($x==="") $x="<br>";
469
-    if ($y==="") $y="<br>";
470
-    $attrs = $show_error?VALUE_ATTRS_ERR:VALUE_ATTRS;
467
+function row2($x, $y, $show_error = false, $lwidth = '40%') {
468
+    if ($x === "") $x = "<br>";
469
+    if ($y === "") $y = "<br>";
470
+    $attrs = $show_error ?VALUE_ATTRS_ERR:VALUE_ATTRS;
471 471
     echo "<tr>
472 472
         <td width=\"$lwidth\" ".NAME_ATTRS.">$x</td>
473 473
         <td $attrs >$y</td>
@@ -475,7 +475,7 @@  discard block
 block discarded – undo
475 475
     ";
476 476
 }
477 477
 
478
-function row2_init($x, $y, $lwidth='40%') {
478
+function row2_init($x, $y, $lwidth = '40%') {
479 479
     echo '<tr>
480 480
         <td class="text-right " width="'.$lwidth.'"  style="padding-right: 20px;">'.$x.'</td>
481 481
         <td '.VALUE_ATTRS.'>'.$y.'
@@ -498,20 +498,20 @@  discard block
 block discarded – undo
498 498
     echo "</tr>\n";
499 499
 }
500 500
 
501
-define ('ALIGN_RIGHT', 'style="text-align:right;"');
501
+define('ALIGN_RIGHT', 'style="text-align:right;"');
502 502
 
503
-function row_heading_array($x, $attrs=null, $class='bg-primary') {
503
+function row_heading_array($x, $attrs = null, $class = 'bg-primary') {
504 504
     echo "<tr>";
505 505
     $i = 0;
506 506
     foreach ($x as $h) {
507
-        $a = $attrs?$attrs[$i]:"";
507
+        $a = $attrs ? $attrs[$i] : "";
508 508
         echo "<th $a class=\"$class\">$h</th>";
509 509
         $i++;
510 510
     }
511 511
     echo "</tr>\n";
512 512
 }
513 513
 
514
-function row_heading($x, $class='bg-primary') {
514
+function row_heading($x, $class = 'bg-primary') {
515 515
     echo sprintf('<tr><th class="%s" colspan=99>%s</th></tr>
516 516
         ', $class, $x
517 517
     );
@@ -573,7 +573,7 @@  discard block
 block discarded – undo
573 573
 // If $ellipsis is true, then an ellipsis is added to any sentence which
574 574
 // is cut short.
575 575
 
576
-function sub_sentence($sentence, $delimiter, $max_chars, $ellipsis=false) {
576
+function sub_sentence($sentence, $delimiter, $max_chars, $ellipsis = false) {
577 577
     $words = explode($delimiter, $sentence);
578 578
     $total_chars = 0;
579 579
     $trunc = false;
@@ -656,8 +656,8 @@  discard block
 block discarded – undo
656 656
 
657 657
 // returns null if the arg is optional and missing
658 658
 //
659
-function get_int($name, $optional=false) {
660
-    $x=null;
659
+function get_int($name, $optional = false) {
660
+    $x = null;
661 661
     if (isset($_GET[$name])) $x = $_GET[$name];
662 662
     if (!is_numeric($x)) {
663 663
         if ($optional) {
@@ -676,7 +676,7 @@  discard block
 block discarded – undo
676 676
 
677 677
 // returns null if the arg is optional and missing
678 678
 //
679
-function post_num($name, $optional=false) {
679
+function post_num($name, $optional = false) {
680 680
     $x = null;
681 681
     if (isset($_POST[$name])) $x = $_POST[$name];
682 682
     if (!is_numeric($x)) {
@@ -691,7 +691,7 @@  discard block
 block discarded – undo
691 691
 
692 692
 // returns null if the arg is optional and missing
693 693
 //
694
-function post_int($name, $optional=false) {
694
+function post_int($name, $optional = false) {
695 695
     $x = post_num($name, $optional);
696 696
     if (is_null($x)) return null;
697 697
     $y = (int)$x;
@@ -709,7 +709,7 @@  discard block
 block discarded – undo
709 709
     }
710 710
 }
711 711
 
712
-function get_str($name, $optional=false) {
712
+function get_str($name, $optional = false) {
713 713
     if (isset($_GET[$name])) {
714 714
         $x = $_GET[$name];
715 715
     } else {
@@ -721,7 +721,7 @@  discard block
 block discarded – undo
721 721
     return undo_magic_quotes($x);
722 722
 }
723 723
 
724
-function post_str($name, $optional=false) {
724
+function post_str($name, $optional = false) {
725 725
     if (isset($_POST[$name])) {
726 726
         $x = $_POST[$name];
727 727
     } else {
@@ -733,7 +733,7 @@  discard block
 block discarded – undo
733 733
     return undo_magic_quotes($x);
734 734
 }
735 735
 
736
-function post_arr($name, $optional=false) {
736
+function post_arr($name, $optional = false) {
737 737
     if (isset($_POST[$name]) && is_array($_POST[$name])) {
738 738
         $x = $_POST[$name];
739 739
     } else {
@@ -749,7 +749,7 @@  discard block
 block discarded – undo
749 749
     // the mb_* functions are not included by default
750 750
     // return (mb_detect_encoding($passwd) -= 'ASCII');
751 751
 
752
-    for ($i=0; $i<strlen($str); $i++) {
752
+    for ($i = 0; $i < strlen($str); $i++) {
753 753
         $c = ord(substr($str, $i));
754 754
         if ($c < 32 || $c > 127) return false;
755 755
     }
@@ -773,7 +773,7 @@  discard block
 block discarded – undo
773 773
     $number = str_replace(',', '.', $number); // replace the german decimal separator
774 774
     // if no value was entered and this is ok
775 775
     //
776
-    if ($number=='' && !$low) return true;
776
+    if ($number == '' && !$low) return true;
777 777
 
778 778
     // the supplied value contains alphabetic characters
779 779
     //
@@ -790,7 +790,7 @@  discard block
 block discarded – undo
790 790
 
791 791
 // Generate a "select" element from an array of values
792 792
 //
793
-function select_from_array($name, $array, $selection=null, $width=240) {
793
+function select_from_array($name, $array, $selection = null, $width = 240) {
794 794
     $out = '<select style="color:#000;"class="form-control input-sm" style="width:'.$width.'px" name="'.$name.'">"';
795 795
 
796 796
     foreach ($array as $key => $value) {
@@ -815,8 +815,8 @@  discard block
 block discarded – undo
815 815
     return $str;
816 816
 }
817 817
 
818
-function strip_bbcode($string){
819
-    return preg_replace("/((\[.+\])+?)(.+?)((\[\/.+\])+?)/","",$string);
818
+function strip_bbcode($string) {
819
+    return preg_replace("/((\[.+\])+?)(.+?)((\[\/.+\])+?)/", "", $string);
820 820
 }
821 821
 
822 822
 function current_url() {
@@ -844,7 +844,7 @@  discard block
 block discarded – undo
844 844
 // @param class The optional CSS class of the button. Defaults to a standard button
845 845
 //
846 846
 
847
-function button_text($url, $text, $desc=null, $class="btn-success btn-sm") {
847
+function button_text($url, $text, $desc = null, $class = "btn-success btn-sm") {
848 848
     if (!$desc) {
849 849
         $desc = $text;
850 850
     }
@@ -853,19 +853,19 @@  discard block
 block discarded – undo
853 853
     );
854 854
 }
855 855
 
856
-function show_button($url, $text, $desc=null, $class="btn-success btn-sm") {
857
-    echo button_text($url, $text, $desc=null, $class);
856
+function show_button($url, $text, $desc = null, $class = "btn-success btn-sm") {
857
+    echo button_text($url, $text, $desc = null, $class);
858 858
 }
859 859
 
860 860
 // for places with a bunch of buttons, like forum posts
861 861
 //
862
-function show_button_small($url, $text, $desc=null) {
862
+function show_button_small($url, $text, $desc = null) {
863 863
     echo button_text($url, $text, $desc, "btn-primary btn-xs");
864 864
 }
865 865
 
866 866
 // used for showing icons
867 867
 //
868
-function show_image($src, $title, $alt, $height=null) {
868
+function show_image($src, $title, $alt, $height = null) {
869 869
     $h = "";
870 870
     if ($height) {
871 871
         $h = "height=\"$height\"";
@@ -902,7 +902,7 @@  discard block
 block discarded – undo
902 902
 // tries instead to connect to <replica_db_host> if tag exists.
903 903
 // DEPRECATED - use boinc_db.inc
904 904
 //
905
-function db_init($try_replica=false) {
905
+function db_init($try_replica = false) {
906 906
     check_web_stopped();
907 907
     $retval = db_init_aux($try_replica);
908 908
     if ($retval == 1) {
@@ -970,7 +970,7 @@  discard block
 block discarded – undo
970 970
 function sanitize_numeric($x) {
971 971
     if (is_numeric($x)) {
972 972
         return $x;
973
-    } else if (trim($x) == '' ) {
973
+    } else if (trim($x) == '') {
974 974
         return '';
975 975
     } else {
976 976
         return "not numeric";
@@ -993,9 +993,9 @@  discard block
 block discarded – undo
993 993
     return $c/(200/24);
994 994
 }
995 995
 
996
-function do_download($path,$name="") {
997
-    if (strcmp($name,"") == 0) {
998
-        $name=basename($path);
996
+function do_download($path, $name = "") {
997
+    if (strcmp($name, "") == 0) {
998
+        $name = basename($path);
999 999
     }
1000 1000
     header('Content-Description: File Transfer');
1001 1001
     header('Content-Type: application/octet-stream');
@@ -1004,7 +1004,7 @@  discard block
 block discarded – undo
1004 1004
     header('Expires: 0');
1005 1005
     header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
1006 1006
     header('Pragma: public');
1007
-    header('Content-Length: ' . filesize($path));
1007
+    header('Content-Length: '.filesize($path));
1008 1008
     flush();
1009 1009
     readfile($path);
1010 1010
 }
@@ -1051,10 +1051,10 @@  discard block
 block discarded – undo
1051 1051
 // Otherwise return 0.
1052 1052
 // Format of user agent string is "BOINC client (windows_x86_64 7.3.17)"
1053 1053
 //
1054
-function boinc_client_version(){
1054
+function boinc_client_version() {
1055 1055
     if (!array_key_exists('HTTP_USER_AGENT', $_SERVER)) return 0;
1056 1056
     $x = $_SERVER['HTTP_USER_AGENT'];
1057
-    $e =  "/BOINC client [^ ]* (\d+).(\d+).(\d+)\)/";
1057
+    $e = "/BOINC client [^ ]* (\d+).(\d+).(\d+)\)/";
1058 1058
     if (preg_match($e, $x, $matches)) {
1059 1059
         return $matches[1]*10000 + $matches[2]*100 + $matches[3];
1060 1060
     }
@@ -1083,7 +1083,7 @@  discard block
 block discarded – undo
1083 1083
     $rem_name = $name."_remaining";
1084 1084
     return "<textarea name=\"$name\" class=\"form-control\" rows=3 id=\"$name\" onkeydown=\"text_counter(this.form.$name, this.form.$rem_name, $maxlen);\"
1085 1085
         onkeyup=\"text_counter(this.form.$name, this.form.$rem_name, $maxlen);\">".$text."</textarea>
1086
-        <br><input name=\"$rem_name\" type=\"text\" id=\"$rem_name\" value=\"".($maxlen-strlen($text))."\" size=\"3\" maxlength=\"3\" readonly> ".tra("characters remaining")
1086
+        <br><input name=\"$rem_name\" type=\"text\" id=\"$rem_name\" value=\"".($maxlen - strlen($text))."\" size=\"3\" maxlength=\"3\" readonly> ".tra("characters remaining")
1087 1087
     ;
1088 1088
 }
1089 1089
 
@@ -1113,13 +1113,13 @@  discard block
 block discarded – undo
1113 1113
 // use the following around text with long lines,
1114 1114
 // to limit the width and make it more readable.
1115 1115
 //
1116
-function text_start($width=640) {
1116
+function text_start($width = 640) {
1117 1117
     echo sprintf("<div style=\"max-width: %dpx;\">\n", $width);
1118 1118
 }
1119 1119
 function text_end() {
1120 1120
     echo "</div>\n";
1121 1121
 }
1122 1122
 
1123
-$cvs_version_tracker[]="\$Id$";  //Generated automatically - do not edit
1123
+$cvs_version_tracker[] = "\$Id$"; //Generated automatically - do not edit
1124 1124
 
1125 1125
 ?>
Please login to merge, or discard this patch.