@@ -113,6 +113,9 @@ |
||
113 | 113 | return ($a->expavg_credit < $b->expavg_credit)? 1 : -1; |
114 | 114 | } |
115 | 115 | |
116 | +/** |
|
117 | + * @param boolean $personal |
|
118 | + */ |
|
116 | 119 | function show_other_projects($user, $personal) { |
117 | 120 | if (!isset($user->projects)) return; |
118 | 121 | if (count($user->projects) < 2) return; |
@@ -33,13 +33,13 @@ discard block |
||
33 | 33 | // they've participated in |
34 | 34 | // |
35 | 35 | function get_other_projects($user) { |
36 | - $cpid = md5($user->cross_project_id . $user->email_addr); |
|
36 | + $cpid = md5($user->cross_project_id.$user->email_addr); |
|
37 | 37 | $url = "http://boinc.netsoft-online.com/get_user.php?cpid=".$cpid; |
38 | 38 | |
39 | 39 | // Check the cache for that URL |
40 | 40 | // |
41 | 41 | $cacheddata = get_cached_data(REMOTE_PROJECTS_TTL, $url); |
42 | - if ($cacheddata){ |
|
42 | + if ($cacheddata) { |
|
43 | 43 | $remote = unserialize($cacheddata); |
44 | 44 | } else { |
45 | 45 | // Fetch the XML, use curl if fopen() is disallowed |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | |
111 | 111 | function cmp($a, $b) { |
112 | 112 | if ($a->expavg_credit == $b->expavg_credit) return 0; |
113 | - return ($a->expavg_credit < $b->expavg_credit)? 1 : -1; |
|
113 | + return ($a->expavg_credit < $b->expavg_credit) ? 1 : -1; |
|
114 | 114 | } |
115 | 115 | |
116 | 116 | function show_other_projects($user, $personal) { |
@@ -133,7 +133,7 @@ discard block |
||
133 | 133 | ), |
134 | 134 | array("", ALIGN_RIGHT, ALIGN_RIGHT, ALIGN_RIGHT) |
135 | 135 | ); |
136 | - foreach($user->projects as $project) { |
|
136 | + foreach ($user->projects as $project) { |
|
137 | 137 | show_project($project); |
138 | 138 | } |
139 | 139 | end_table(); |
@@ -161,7 +161,7 @@ discard block |
||
161 | 161 | $config = get_config(); |
162 | 162 | row2(tra("Computers on this account"), "<a href=\"hosts_user.php\">".tra("View")."</a>"); |
163 | 163 | row2(tra("Tasks"), "<a href=\"results.php?userid=$user->id\">".tra("View")."</a>"); |
164 | - $cpid = md5($user->cross_project_id . $user->email_addr); |
|
164 | + $cpid = md5($user->cross_project_id.$user->email_addr); |
|
165 | 165 | $x = ""; |
166 | 166 | shuffle($cpid_stats_sites); |
167 | 167 | foreach ($cpid_stats_sites as $site) { |
@@ -308,7 +308,7 @@ discard block |
||
308 | 308 | // show user name, with links to profile if present. |
309 | 309 | // if $badge_height is > 0, show badges |
310 | 310 | // |
311 | -function user_links($user, $badge_height=0) { |
|
311 | +function user_links($user, $badge_height = 0) { |
|
312 | 312 | BoincForumPrefs::lookup($user); |
313 | 313 | if (is_banished($user)) { |
314 | 314 | return "(banished: ID $user->id)"; |
@@ -330,7 +330,7 @@ discard block |
||
330 | 330 | if ($badge_height) { |
331 | 331 | $x .= badges_string(true, $user, $badge_height); |
332 | 332 | } |
333 | - if (function_exists("project_user_links")){ |
|
333 | + if (function_exists("project_user_links")) { |
|
334 | 334 | $x .= project_user_links($user); |
335 | 335 | } |
336 | 336 | return $x; |
@@ -383,7 +383,7 @@ discard block |
||
383 | 383 | |
384 | 384 | // if there's a foundership request, notify the founder |
385 | 385 | // |
386 | - if ($user->id==$team->userid && $team->ping_user >0) { |
|
386 | + if ($user->id == $team->userid && $team->ping_user > 0) { |
|
387 | 387 | $x .= "<p class=\"text-danger\">".tra("(foundership change request pending)")."</p>"; |
388 | 388 | } |
389 | 389 | row2(tra("Member of team"), $x); |
@@ -408,7 +408,7 @@ discard block |
||
408 | 408 | $x = "<a href=\"user_search.php\">".tra("Find friends")."</a><br/>\n"; |
409 | 409 | $n = count($friends); |
410 | 410 | if ($n) { |
411 | - foreach($friends as $friend) { |
|
411 | + foreach ($friends as $friend) { |
|
412 | 412 | $fuser = BoincUser::lookup_id($friend->user_dest); |
413 | 413 | if (!$fuser) continue; |
414 | 414 | $x .= friend_links($fuser); |
@@ -461,7 +461,7 @@ discard block |
||
461 | 461 | // Returns a cacheable community links data object |
462 | 462 | // @param user The user to produce a community links object for |
463 | 463 | |
464 | -function get_community_links_object($user){ |
|
464 | +function get_community_links_object($user) { |
|
465 | 465 | $cache_object = new StdClass; |
466 | 466 | $cache_object->post_count = total_posts($user); |
467 | 467 | $cache_object->user = $user; |
@@ -469,7 +469,7 @@ discard block |
||
469 | 469 | $cache_object->friends = array(); |
470 | 470 | |
471 | 471 | $friends = BoincFriend::enum("user_src=$user->id and reciprocated=1"); |
472 | - foreach($friends as $friend) { |
|
472 | + foreach ($friends as $friend) { |
|
473 | 473 | $fuser = BoincUser::lookup_id($friend->user_dest); |
474 | 474 | if (!$fuser) continue; |
475 | 475 | $cache_object->friends[] = $fuser; |
@@ -477,7 +477,7 @@ discard block |
||
477 | 477 | return $cache_object; |
478 | 478 | } |
479 | 479 | |
480 | -function community_links($clo, $logged_in_user){ |
|
480 | +function community_links($clo, $logged_in_user) { |
|
481 | 481 | $user = $clo->user; |
482 | 482 | $team = $clo->team; |
483 | 483 | $friends = $clo->friends; |
@@ -503,15 +503,15 @@ discard block |
||
503 | 503 | "<a href=\"friend.php?action=cancel_confirm&userid=$user->id\">".tra("Cancel friendship")."</a>" |
504 | 504 | ); |
505 | 505 | } else if ($friend) { |
506 | - row2(tra("Friends"), "<a href=\"friend.php?action=add&userid=$user->id\">".tra("Request pending")."</a>"); |
|
506 | + row2(tra("Friends"), "<a href=\"friend.php?action=add&userid=$user->id\">".tra("Request pending")."</a>"); |
|
507 | 507 | } else { |
508 | - row2(tra("Friends"), "<a href=\"friend.php?action=add&userid=$user->id\">".tra("Add as friend")."</a>"); |
|
508 | + row2(tra("Friends"), "<a href=\"friend.php?action=add&userid=$user->id\">".tra("Add as friend")."</a>"); |
|
509 | 509 | } |
510 | 510 | } |
511 | 511 | |
512 | 512 | if ($friends) { |
513 | 513 | $x = ""; |
514 | - foreach($friends as $friend) { |
|
514 | + foreach ($friends as $friend) { |
|
515 | 515 | $x .= friend_links($friend); |
516 | 516 | } |
517 | 517 | row2(tra("Friends")." (".sizeof($friends).")", $x); |
@@ -554,7 +554,7 @@ discard block |
||
554 | 554 | function is_banned_email_addr($email_addr) { |
555 | 555 | global $banned_email_domains; |
556 | 556 | if (isset($banned_email_domains)) { |
557 | - foreach($banned_email_domains as $d) { |
|
557 | + foreach ($banned_email_domains as $d) { |
|
558 | 558 | $x = strstr($email_addr, $d); |
559 | 559 | if ($x == $d) return true; |
560 | 560 | } |
@@ -582,7 +582,7 @@ discard block |
||
582 | 582 | // |
583 | 583 | function make_user( |
584 | 584 | $email_addr, $name, $passwd_hash, |
585 | - $country=null, $postal_code=null, $project_prefs=null, $teamid=0 |
|
585 | + $country = null, $postal_code = null, $project_prefs = null, $teamid = 0 |
|
586 | 586 | ) { |
587 | 587 | if (!is_valid_email_addr($email_addr)) return null; |
588 | 588 | if (is_banned_email_addr($email_addr)) return null; |
@@ -654,6 +654,6 @@ discard block |
||
654 | 654 | $user->delete(); |
655 | 655 | } |
656 | 656 | |
657 | -$cvs_version_tracker[]="\$Id$"; //Generated automatically - do not edit |
|
657 | +$cvs_version_tracker[] = "\$Id$"; //Generated automatically - do not edit |
|
658 | 658 | |
659 | 659 | ?> |
@@ -109,13 +109,19 @@ discard block |
||
109 | 109 | } |
110 | 110 | |
111 | 111 | function cmp($a, $b) { |
112 | - if ($a->expavg_credit == $b->expavg_credit) return 0; |
|
112 | + if ($a->expavg_credit == $b->expavg_credit) { |
|
113 | + return 0; |
|
114 | + } |
|
113 | 115 | return ($a->expavg_credit < $b->expavg_credit)? 1 : -1; |
114 | 116 | } |
115 | 117 | |
116 | 118 | function show_other_projects($user, $personal) { |
117 | - if (!isset($user->projects)) return; |
|
118 | - if (count($user->projects) < 2) return; |
|
119 | + if (!isset($user->projects)) { |
|
120 | + return; |
|
121 | + } |
|
122 | + if (count($user->projects) < 2) { |
|
123 | + return; |
|
124 | + } |
|
119 | 125 | |
120 | 126 | usort($user->projects, "cmp"); |
121 | 127 | if ($personal) { |
@@ -410,7 +416,9 @@ discard block |
||
410 | 416 | if ($n) { |
411 | 417 | foreach($friends as $friend) { |
412 | 418 | $fuser = BoincUser::lookup_id($friend->user_dest); |
413 | - if (!$fuser) continue; |
|
419 | + if (!$fuser) { |
|
420 | + continue; |
|
421 | + } |
|
414 | 422 | $x .= friend_links($fuser); |
415 | 423 | } |
416 | 424 | row2(tra("Friends")." ($n)", $x); |
@@ -471,7 +479,9 @@ discard block |
||
471 | 479 | $friends = BoincFriend::enum("user_src=$user->id and reciprocated=1"); |
472 | 480 | foreach($friends as $friend) { |
473 | 481 | $fuser = BoincUser::lookup_id($friend->user_dest); |
474 | - if (!$fuser) continue; |
|
482 | + if (!$fuser) { |
|
483 | + continue; |
|
484 | + } |
|
475 | 485 | $cache_object->friends[] = $fuser; |
476 | 486 | } |
477 | 487 | return $cache_object; |
@@ -556,7 +566,9 @@ discard block |
||
556 | 566 | if (isset($banned_email_domains)) { |
557 | 567 | foreach($banned_email_domains as $d) { |
558 | 568 | $x = strstr($email_addr, $d); |
559 | - if ($x == $d) return true; |
|
569 | + if ($x == $d) { |
|
570 | + return true; |
|
571 | + } |
|
560 | 572 | } |
561 | 573 | } |
562 | 574 | return false; |
@@ -584,13 +596,19 @@ discard block |
||
584 | 596 | $email_addr, $name, $passwd_hash, |
585 | 597 | $country=null, $postal_code=null, $project_prefs=null, $teamid=0 |
586 | 598 | ) { |
587 | - if (!is_valid_email_addr($email_addr)) return null; |
|
588 | - if (is_banned_email_addr($email_addr)) return null; |
|
599 | + if (!is_valid_email_addr($email_addr)) { |
|
600 | + return null; |
|
601 | + } |
|
602 | + if (is_banned_email_addr($email_addr)) { |
|
603 | + return null; |
|
604 | + } |
|
589 | 605 | |
590 | 606 | $authenticator = random_string(); |
591 | 607 | $cross_project_id = random_string(); |
592 | 608 | $now = time(); |
593 | - if (!is_valid_country($country)) return null; |
|
609 | + if (!is_valid_country($country)) { |
|
610 | + return null; |
|
611 | + } |
|
594 | 612 | |
595 | 613 | $email_addr = BoincDb::escape_string($email_addr); |
596 | 614 | $name = sanitize_tags($name); |
@@ -106,6 +106,9 @@ discard block |
||
106 | 106 | return secure_url_base(); |
107 | 107 | } |
108 | 108 | |
109 | +/** |
|
110 | + * @param string $name |
|
111 | + */ |
|
109 | 112 | function send_cookie($name, $value, $permanent, $ops=false) { |
110 | 113 | global $master_url; |
111 | 114 | |
@@ -455,6 +458,9 @@ discard block |
||
455 | 458 | "; |
456 | 459 | } |
457 | 460 | |
461 | +/** |
|
462 | + * @param string $x |
|
463 | + */ |
|
458 | 464 | function row2_init($x, $y, $lwidth='40%') { |
459 | 465 | echo '<tr> |
460 | 466 | <td class="text-right " width="'.$lwidth.'" style="padding-right: 20px;">'.$x.'</td> |
@@ -466,6 +472,9 @@ discard block |
||
466 | 472 | echo "<tr><td>$x</td><td>$y</td></tr>\n"; |
467 | 473 | } |
468 | 474 | |
475 | +/** |
|
476 | + * @param string $string |
|
477 | + */ |
|
469 | 478 | function rowify($string) { |
470 | 479 | echo "<tr><td>$string</td></tr>"; |
471 | 480 | } |
@@ -491,6 +500,9 @@ discard block |
||
491 | 500 | echo "</tr>\n"; |
492 | 501 | } |
493 | 502 | |
503 | +/** |
|
504 | + * @param string $x |
|
505 | + */ |
|
494 | 506 | function row_heading($x) { |
495 | 507 | echo '<tr><th class="bg-primary" colspan=99>'.$x.'</th></tr> |
496 | 508 | '; |
@@ -555,6 +567,11 @@ discard block |
||
555 | 567 | // If $ellipsis is true, then an ellipsis is added to any sentence which |
556 | 568 | // is cut short. |
557 | 569 | |
570 | +/** |
|
571 | + * @param string $sentence |
|
572 | + * @param string $delimiter |
|
573 | + * @param integer $max_chars |
|
574 | + */ |
|
558 | 575 | function sub_sentence($sentence, $delimiter, $max_chars, $ellipsis=false) { |
559 | 576 | $words = explode($delimiter, $sentence); |
560 | 577 | $total_chars = 0; |
@@ -605,6 +622,9 @@ discard block |
||
605 | 622 | ob_implicit_flush(0); |
606 | 623 | } |
607 | 624 | |
625 | +/** |
|
626 | + * @param string $filename |
|
627 | + */ |
|
608 | 628 | function close_output_buffer($filename) { |
609 | 629 | $fh = fopen($filename, "w"); |
610 | 630 | $page = ob_get_contents(); |
@@ -673,6 +693,9 @@ discard block |
||
673 | 693 | |
674 | 694 | // returns null if the arg is optional and missing |
675 | 695 | // |
696 | +/** |
|
697 | + * @param string $name |
|
698 | + */ |
|
676 | 699 | function post_int($name, $optional=false) { |
677 | 700 | $x = post_num($name, $optional); |
678 | 701 | if (is_null($x)) return null; |
@@ -772,6 +795,9 @@ discard block |
||
772 | 795 | |
773 | 796 | // Generate a "select" element from an array of values |
774 | 797 | // |
798 | +/** |
|
799 | + * @param string $name |
|
800 | + */ |
|
775 | 801 | function select_from_array($name, $array, $selection=null, $width=240) { |
776 | 802 | $out = '<select style="color:#000;"class="form-control input-sm" style="width:'.$width.'px" name="'.$name.'">"'; |
777 | 803 | |
@@ -833,6 +859,9 @@ discard block |
||
833 | 859 | "; |
834 | 860 | } |
835 | 861 | |
862 | +/** |
|
863 | + * @param string $text |
|
864 | + */ |
|
836 | 865 | function button_text($url, $text, $desc=null, $class="btn btn-default") { |
837 | 866 | if (!$desc) $desc = $text; |
838 | 867 | return "<a href=\"".$url."\" title=\"$desc\" class=\"".$class."\">".$text."</a> |
@@ -854,6 +883,12 @@ discard block |
||
854 | 883 | |
855 | 884 | // used for showing icons |
856 | 885 | // |
886 | +/** |
|
887 | + * @param string $src |
|
888 | + * @param string $title |
|
889 | + * @param string $alt |
|
890 | + * @param string $height |
|
891 | + */ |
|
857 | 892 | function show_image($src, $title, $alt, $height=null) { |
858 | 893 | $h = ""; |
859 | 894 | if ($height) { |
@@ -969,6 +1004,9 @@ discard block |
||
969 | 1004 | } |
970 | 1005 | } |
971 | 1006 | |
1007 | +/** |
|
1008 | + * @param integer $f |
|
1009 | + */ |
|
972 | 1010 | function flops_to_credit($f) { |
973 | 1011 | return $f*(200/86400e9); |
974 | 1012 | } |
@@ -1004,6 +1042,9 @@ discard block |
||
1004 | 1042 | } |
1005 | 1043 | } |
1006 | 1044 | |
1045 | +/** |
|
1046 | + * @param integer $height |
|
1047 | + */ |
|
1007 | 1048 | function badges_string($is_user, $item, $height) { |
1008 | 1049 | if (DISABLE_BADGES) return null; |
1009 | 1050 | if ($is_user) { |
@@ -1020,6 +1061,9 @@ discard block |
||
1020 | 1061 | return $x; |
1021 | 1062 | } |
1022 | 1063 | |
1064 | +/** |
|
1065 | + * @param boolean $is_user |
|
1066 | + */ |
|
1023 | 1067 | function show_badges_row($is_user, $item) { |
1024 | 1068 | if (BADGE_HEIGHT_LARGE == 0) return; |
1025 | 1069 | $x = badges_string($is_user, $item, BADGE_HEIGHT_LARGE); |
@@ -1064,6 +1108,11 @@ discard block |
||
1064 | 1108 | // return HTML for a textarea with chars-remaining counter. |
1065 | 1109 | // Call text_counter_script() before using this. |
1066 | 1110 | // |
1111 | +/** |
|
1112 | + * @param string $name |
|
1113 | + * @param integer $maxlen |
|
1114 | + * @param string $text |
|
1115 | + */ |
|
1067 | 1116 | function textarea_with_counter($name, $maxlen, $text) { |
1068 | 1117 | $rem_name = $name."_remaining"; |
1069 | 1118 | return "<textarea name=\"$name\" class=\"form-control\" rows=3 id=\"$name\" onkeydown=\"text_counter(this.form.$name, this.form.$rem_name, $maxlen);\" |
@@ -1082,6 +1131,9 @@ discard block |
||
1082 | 1131 | return sprintf("%d.%d.%d", $maj, $min, $v); |
1083 | 1132 | } |
1084 | 1133 | |
1134 | +/** |
|
1135 | + * @param string $url |
|
1136 | + */ |
|
1085 | 1137 | function google_search_form($url) { |
1086 | 1138 | echo " |
1087 | 1139 | <nobr> |
@@ -868,13 +868,13 @@ |
||
868 | 868 | if ($generating_xml) { |
869 | 869 | xml_error(-183); |
870 | 870 | } else { |
871 | - if (!$did_page_head) { |
|
872 | - page_head(tra("Project down for maintenance")); |
|
873 | - } |
|
871 | + if (!$did_page_head) { |
|
872 | + page_head(tra("Project down for maintenance")); |
|
873 | + } |
|
874 | 874 | echo tra( |
875 | - "%1 is temporarily shut down for maintenance. Please try again later.", |
|
876 | - PROJECT |
|
877 | - ); |
|
875 | + "%1 is temporarily shut down for maintenance. Please try again later.", |
|
876 | + PROJECT |
|
877 | + ); |
|
878 | 878 | page_tail(); |
879 | 879 | exit(); |
880 | 880 | } |
@@ -34,8 +34,8 @@ discard block |
||
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>"); |
|
38 | -$no_computing = parse_bool($config, "no_computing"); |
|
37 | +$master_url = parse_config($config, "<master_url>"); |
|
38 | +$no_computing = parse_bool($config, "no_computing"); |
|
39 | 39 | $recaptcha_public_key = parse_config($config, "<recaptcha_public_key>"); |
40 | 40 | $recaptcha_private_key = parse_config($config, "<recaptcha_private_key>"); |
41 | 41 | |
@@ -106,7 +106,7 @@ discard block |
||
106 | 106 | return secure_url_base(); |
107 | 107 | } |
108 | 108 | |
109 | -function send_cookie($name, $value, $permanent, $ops=false) { |
|
109 | +function send_cookie($name, $value, $permanent, $ops = false) { |
|
110 | 110 | global $master_url; |
111 | 111 | |
112 | 112 | // the following allows independent login for projects on the same server |
@@ -117,11 +117,11 @@ discard block |
||
117 | 117 | $path = substr($path, 0, -1); |
118 | 118 | $path .= "_ops/"; |
119 | 119 | } |
120 | - $expire = $permanent?time()+3600*24*365:0; |
|
120 | + $expire = $permanent ? time() + 3600*24*365 : 0; |
|
121 | 121 | setcookie($name, $value, $expire, $path); |
122 | 122 | } |
123 | 123 | |
124 | -function clear_cookie($name, $ops=false) { |
|
124 | +function clear_cookie($name, $ops = false) { |
|
125 | 125 | global $master_url; |
126 | 126 | $url = parse_url($master_url); |
127 | 127 | $path = $url['path']; |
@@ -129,13 +129,13 @@ discard block |
||
129 | 129 | $path = substr($path, 0, -1); |
130 | 130 | $path .= "_ops/"; |
131 | 131 | } |
132 | - setcookie($name, '', time()-3600, $path); |
|
132 | + setcookie($name, '', time() - 3600, $path); |
|
133 | 133 | } |
134 | 134 | |
135 | 135 | $g_logged_in_user = null; |
136 | 136 | $got_logged_in_user = false; |
137 | 137 | |
138 | -function get_logged_in_user($must_be_logged_in=true) { |
|
138 | +function get_logged_in_user($must_be_logged_in = true) { |
|
139 | 139 | global $g_logged_in_user, $got_logged_in_user; |
140 | 140 | if ($got_logged_in_user) return $g_logged_in_user; |
141 | 141 | |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | $next_url = $_SERVER['REQUEST_URI']; |
155 | 155 | $n = strrpos($next_url, "/"); |
156 | 156 | if ($n) { |
157 | - $next_url = substr($next_url, $n+1); |
|
157 | + $next_url = substr($next_url, $n + 1); |
|
158 | 158 | } |
159 | 159 | } |
160 | 160 | $next_url = urlencode($next_url); |
@@ -165,7 +165,7 @@ discard block |
||
165 | 165 | return $g_logged_in_user; |
166 | 166 | } |
167 | 167 | |
168 | -function show_login_info($prefix="") { |
|
168 | +function show_login_info($prefix = "") { |
|
169 | 169 | $user = get_logged_in_user(false); |
170 | 170 | if ($user) { |
171 | 171 | $url_tokens = url_tokens($user->authenticator); |
@@ -175,7 +175,7 @@ discard block |
||
175 | 175 | } |
176 | 176 | } |
177 | 177 | |
178 | -$cache_control_extra=""; |
|
178 | +$cache_control_extra = ""; |
|
179 | 179 | $is_login_page = false; |
180 | 180 | |
181 | 181 | // Call this to start pages. |
@@ -187,11 +187,11 @@ discard block |
||
187 | 187 | // with an existing web framework can more easily do so. |
188 | 188 | // To do so, define page_head() in the project include file. |
189 | 189 | // |
190 | -if (!function_exists("page_head")){ |
|
190 | +if (!function_exists("page_head")) { |
|
191 | 191 | function page_head( |
192 | 192 | $title, |
193 | 193 | // page title. Put in <title>, used as title for browser tab. |
194 | - $body_attrs=null, |
|
194 | + $body_attrs = null, |
|
195 | 195 | // <body XXXX> |
196 | 196 | // e.g. Javascript to put focus in an input field |
197 | 197 | // (onload="document.form.foo.focus()") |
@@ -200,10 +200,10 @@ discard block |
||
200 | 200 | // if set, include schedulers.txt. |
201 | 201 | // also pass to project_banner() in case you want a different |
202 | 202 | // header for your main page. |
203 | - $url_prefix="", |
|
203 | + $url_prefix = "", |
|
204 | 204 | // prepend this to links. |
205 | 205 | // Use for web pages not in the top directory |
206 | - $head_extra=null |
|
206 | + $head_extra = null |
|
207 | 207 | // extra stuff to put in <head>. E.g.: |
208 | 208 | // reCAPTCHA code (create_profile.php) |
209 | 209 | // bbcode javascript (forums) |
@@ -214,15 +214,15 @@ discard block |
||
214 | 214 | $did_page_head = true; |
215 | 215 | $url_base = url_base(); |
216 | 216 | |
217 | - $rssname = PROJECT . " RSS 2.0"; |
|
217 | + $rssname = PROJECT." RSS 2.0"; |
|
218 | 218 | $rsslink = $url_base."rss_main.php"; |
219 | 219 | |
220 | 220 | if (!$caching) { |
221 | 221 | header("Content-type: text/html; charset=utf-8"); |
222 | - header ("Expires: Mon, 26 Jul 1997 05:00:00 UTC"); // Date in the past |
|
223 | - header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " UTC"); // always modified |
|
224 | - header ("Cache-Control: $cache_control_extra no-cache, must-revalidate, post-check=0, pre-check=0"); // HTTP/1.1 |
|
225 | - header ("Pragma: no-cache"); // HTTP/1.0 |
|
222 | + header("Expires: Mon, 26 Jul 1997 05:00:00 UTC"); // Date in the past |
|
223 | + header("Last-Modified: ".gmdate("D, d M Y H:i:s")." UTC"); // always modified |
|
224 | + header("Cache-Control: $cache_control_extra no-cache, must-revalidate, post-check=0, pre-check=0"); // HTTP/1.1 |
|
225 | + header("Pragma: no-cache"); // HTTP/1.0 |
|
226 | 226 | } |
227 | 227 | |
228 | 228 | echo '<!DOCTYPE html> |
@@ -233,11 +233,11 @@ discard block |
||
233 | 233 | if ($head_extra) { |
234 | 234 | echo "\n$head_extra\n"; |
235 | 235 | } |
236 | - if ($is_main && (!defined('NO_COMPUTING')||!NO_COMPUTING)) { |
|
236 | + if ($is_main && (!defined('NO_COMPUTING') || !NO_COMPUTING)) { |
|
237 | 237 | readfile("schedulers.txt"); |
238 | 238 | } |
239 | 239 | |
240 | - $t = $title?$title:PROJECT; |
|
240 | + $t = $title ? $title : PROJECT; |
|
241 | 241 | echo "<title>$t</title>\n"; |
242 | 242 | echo ' |
243 | 243 | <meta charset="utf-8"> |
@@ -273,7 +273,7 @@ discard block |
||
273 | 273 | echo '<div class="container-fluid"> |
274 | 274 | '; |
275 | 275 | |
276 | - switch($title) { //kludge |
|
276 | + switch ($title) { //kludge |
|
277 | 277 | case tra("Log in"): |
278 | 278 | case tra("Create an account"): |
279 | 279 | case tra("Server status page"): |
@@ -289,13 +289,13 @@ discard block |
||
289 | 289 | |
290 | 290 | // See the comments for page_head() |
291 | 291 | // |
292 | -if (!function_exists("page_tail")){ |
|
292 | +if (!function_exists("page_tail")) { |
|
293 | 293 | function page_tail( |
294 | - $show_date=false, |
|
294 | + $show_date = false, |
|
295 | 295 | // true for pages that are generated periodically rather than on the fly |
296 | - $url_prefix="", |
|
296 | + $url_prefix = "", |
|
297 | 297 | // use for pages not at top level |
298 | - $is_main=false |
|
298 | + $is_main = false |
|
299 | 299 | // passed to project_footer; |
300 | 300 | ) { |
301 | 301 | project_footer($is_main, $show_date, $url_prefix); |
@@ -309,10 +309,10 @@ discard block |
||
309 | 309 | } |
310 | 310 | } |
311 | 311 | |
312 | -function display_cvs_versions(){ |
|
312 | +function display_cvs_versions() { |
|
313 | 313 | global $cvs_version_tracker; |
314 | 314 | echo "\n<!-- SVN VERSIONS -->\n"; |
315 | - for ($i=0;$i<sizeof($cvs_version_tracker);$i++) { |
|
315 | + for ($i = 0; $i < sizeof($cvs_version_tracker); $i++) { |
|
316 | 316 | echo "<!-- ".$cvs_version_tracker[$i]." -->\n"; |
317 | 317 | } |
318 | 318 | } |
@@ -339,9 +339,9 @@ discard block |
||
339 | 339 | |
340 | 340 | function time_diff($x) { |
341 | 341 | $days = (int)($x/86400); |
342 | - $hours = (int)(($x-$days*86400)/3600); |
|
343 | - $minutes = (int)(($x-$days*86400-$hours*3600)/60); |
|
344 | - $seconds = (int)($x % 60); |
|
342 | + $hours = (int)(($x - $days*86400)/3600); |
|
343 | + $minutes = (int)(($x - $days*86400 - $hours*3600)/60); |
|
344 | + $seconds = (int)($x%60); |
|
345 | 345 | |
346 | 346 | $datestring = ""; |
347 | 347 | if ($days) { |
@@ -368,7 +368,7 @@ discard block |
||
368 | 368 | |
369 | 369 | function time_str($x) { |
370 | 370 | if ($x == 0) return "---"; |
371 | - return gmdate('j M Y, G:i:s', $x) . " UTC"; |
|
371 | + return gmdate('j M Y, G:i:s', $x)." UTC"; |
|
372 | 372 | } |
373 | 373 | |
374 | 374 | function local_time_str($x) { |
@@ -380,14 +380,14 @@ discard block |
||
380 | 380 | return time_str($x); |
381 | 381 | } |
382 | 382 | |
383 | -function start_table_str($class="", $style="") { |
|
384 | - $s = $style?'style="'.$style.'"':''; |
|
383 | +function start_table_str($class = "", $style = "") { |
|
384 | + $s = $style ? 'style="'.$style.'"' : ''; |
|
385 | 385 | return '<div class="table"> |
386 | 386 | <table '.$s.' width="100%" class="table table-condensed '.$class.'" > |
387 | 387 | '; |
388 | 388 | } |
389 | 389 | |
390 | -function start_table($class="", $style="") { |
|
390 | +function start_table($class = "", $style = "") { |
|
391 | 391 | echo start_table_str($class, $style); |
392 | 392 | } |
393 | 393 | |
@@ -432,7 +432,7 @@ discard block |
||
432 | 432 | echo "</tr>\n"; |
433 | 433 | } |
434 | 434 | |
435 | -function row1($x, $ncols=2, $class="heading") { |
|
435 | +function row1($x, $ncols = 2, $class = "heading") { |
|
436 | 436 | if ($class == "heading") { |
437 | 437 | echo "<tr><th class=\"bg-primary\" colspan=\"$ncols\">$x</th></tr>\n"; |
438 | 438 | } else { |
@@ -444,10 +444,10 @@ discard block |
||
444 | 444 | define('VALUE_ATTRS', 'style="padding-left:12px"'); |
445 | 445 | define('VALUE_ATTRS_ERR', 'class="danger" style="padding-left:12px"'); |
446 | 446 | |
447 | -function row2($x, $y, $show_error=false, $lwidth='40%') { |
|
448 | - if ($x==="") $x="<br>"; |
|
449 | - if ($y==="") $y="<br>"; |
|
450 | - $attrs = $show_error?VALUE_ATTRS_ERR:VALUE_ATTRS; |
|
447 | +function row2($x, $y, $show_error = false, $lwidth = '40%') { |
|
448 | + if ($x === "") $x = "<br>"; |
|
449 | + if ($y === "") $y = "<br>"; |
|
450 | + $attrs = $show_error ? VALUE_ATTRS_ERR : VALUE_ATTRS; |
|
451 | 451 | echo "<tr> |
452 | 452 | <td width=\"$lwidth\" ".NAME_ATTRS.">$x</td> |
453 | 453 | <td $attrs >$y</td> |
@@ -455,7 +455,7 @@ discard block |
||
455 | 455 | "; |
456 | 456 | } |
457 | 457 | |
458 | -function row2_init($x, $y, $lwidth='40%') { |
|
458 | +function row2_init($x, $y, $lwidth = '40%') { |
|
459 | 459 | echo '<tr> |
460 | 460 | <td class="text-right " width="'.$lwidth.'" style="padding-right: 20px;">'.$x.'</td> |
461 | 461 | <td '.VALUE_ATTRS.'>'.$y.' |
@@ -478,13 +478,13 @@ discard block |
||
478 | 478 | echo "</tr>\n"; |
479 | 479 | } |
480 | 480 | |
481 | -define ('ALIGN_RIGHT', 'style="text-align:right;"'); |
|
481 | +define('ALIGN_RIGHT', 'style="text-align:right;"'); |
|
482 | 482 | |
483 | -function row_heading_array($x, $attrs=null, $class='bg-primary') { |
|
483 | +function row_heading_array($x, $attrs = null, $class = 'bg-primary') { |
|
484 | 484 | echo "<tr>"; |
485 | 485 | $i = 0; |
486 | 486 | foreach ($x as $h) { |
487 | - $a = $attrs?$attrs[$i]:""; |
|
487 | + $a = $attrs ? $attrs[$i] : ""; |
|
488 | 488 | echo "<th $a class=\"$class\">$h</th>"; |
489 | 489 | $i++; |
490 | 490 | } |
@@ -555,7 +555,7 @@ discard block |
||
555 | 555 | // If $ellipsis is true, then an ellipsis is added to any sentence which |
556 | 556 | // is cut short. |
557 | 557 | |
558 | -function sub_sentence($sentence, $delimiter, $max_chars, $ellipsis=false) { |
|
558 | +function sub_sentence($sentence, $delimiter, $max_chars, $ellipsis = false) { |
|
559 | 559 | $words = explode($delimiter, $sentence); |
560 | 560 | $total_chars = 0; |
561 | 561 | $trunc = false; |
@@ -638,8 +638,8 @@ discard block |
||
638 | 638 | |
639 | 639 | // returns null if the arg is optional and missing |
640 | 640 | // |
641 | -function get_int($name, $optional=false) { |
|
642 | - $x=null; |
|
641 | +function get_int($name, $optional = false) { |
|
642 | + $x = null; |
|
643 | 643 | if (isset($_GET[$name])) $x = $_GET[$name]; |
644 | 644 | if (!is_numeric($x)) { |
645 | 645 | if ($optional) { |
@@ -658,7 +658,7 @@ discard block |
||
658 | 658 | |
659 | 659 | // returns null if the arg is optional and missing |
660 | 660 | // |
661 | -function post_num($name, $optional=false) { |
|
661 | +function post_num($name, $optional = false) { |
|
662 | 662 | $x = null; |
663 | 663 | if (isset($_POST[$name])) $x = $_POST[$name]; |
664 | 664 | if (!is_numeric($x)) { |
@@ -673,7 +673,7 @@ discard block |
||
673 | 673 | |
674 | 674 | // returns null if the arg is optional and missing |
675 | 675 | // |
676 | -function post_int($name, $optional=false) { |
|
676 | +function post_int($name, $optional = false) { |
|
677 | 677 | $x = post_num($name, $optional); |
678 | 678 | if (is_null($x)) return null; |
679 | 679 | $y = (int)$x; |
@@ -691,7 +691,7 @@ discard block |
||
691 | 691 | } |
692 | 692 | } |
693 | 693 | |
694 | -function get_str($name, $optional=false) { |
|
694 | +function get_str($name, $optional = false) { |
|
695 | 695 | if (isset($_GET[$name])) { |
696 | 696 | $x = $_GET[$name]; |
697 | 697 | } else { |
@@ -703,7 +703,7 @@ discard block |
||
703 | 703 | return undo_magic_quotes($x); |
704 | 704 | } |
705 | 705 | |
706 | -function post_str($name, $optional=false) { |
|
706 | +function post_str($name, $optional = false) { |
|
707 | 707 | if (isset($_POST[$name])) { |
708 | 708 | $x = $_POST[$name]; |
709 | 709 | } else { |
@@ -715,7 +715,7 @@ discard block |
||
715 | 715 | return undo_magic_quotes($x); |
716 | 716 | } |
717 | 717 | |
718 | -function post_arr($name, $optional=false) { |
|
718 | +function post_arr($name, $optional = false) { |
|
719 | 719 | if (isset($_POST[$name]) && is_array($_POST[$name])) { |
720 | 720 | $x = $_POST[$name]; |
721 | 721 | } else { |
@@ -731,7 +731,7 @@ discard block |
||
731 | 731 | // the mb_* functions are not included by default |
732 | 732 | // return (mb_detect_encoding($passwd) -= 'ASCII'); |
733 | 733 | |
734 | - for ($i=0; $i<strlen($str); $i++) { |
|
734 | + for ($i = 0; $i < strlen($str); $i++) { |
|
735 | 735 | $c = ord(substr($str, $i)); |
736 | 736 | if ($c < 32 || $c > 127) return false; |
737 | 737 | } |
@@ -755,7 +755,7 @@ discard block |
||
755 | 755 | $number = str_replace(',', '.', $number); // replace the german decimal separator |
756 | 756 | // if no value was entered and this is ok |
757 | 757 | // |
758 | - if ($number=='' && !$low) return true; |
|
758 | + if ($number == '' && !$low) return true; |
|
759 | 759 | |
760 | 760 | // the supplied value contains alphabetic characters |
761 | 761 | // |
@@ -772,7 +772,7 @@ discard block |
||
772 | 772 | |
773 | 773 | // Generate a "select" element from an array of values |
774 | 774 | // |
775 | -function select_from_array($name, $array, $selection=null, $width=240) { |
|
775 | +function select_from_array($name, $array, $selection = null, $width = 240) { |
|
776 | 776 | $out = '<select style="color:#000;"class="form-control input-sm" style="width:'.$width.'px" name="'.$name.'">"'; |
777 | 777 | |
778 | 778 | foreach ($array as $key => $value) { |
@@ -797,8 +797,8 @@ discard block |
||
797 | 797 | return $str; |
798 | 798 | } |
799 | 799 | |
800 | -function strip_bbcode($string){ |
|
801 | - return preg_replace("/((\[.+\])+?)(.+?)((\[\/.+\])+?)/","",$string); |
|
800 | +function strip_bbcode($string) { |
|
801 | + return preg_replace("/((\[.+\])+?)(.+?)((\[\/.+\])+?)/", "", $string); |
|
802 | 802 | } |
803 | 803 | |
804 | 804 | function current_url() { |
@@ -825,7 +825,7 @@ discard block |
||
825 | 825 | // @param desc The title of the destination - typically used as a popup |
826 | 826 | // @param class The optional CSS class of the button. Defaults to a standard button |
827 | 827 | // |
828 | -function show_button($url, $text, $desc=null, $class="btn btn-default btn-xs") { |
|
828 | +function show_button($url, $text, $desc = null, $class = "btn btn-default btn-xs") { |
|
829 | 829 | if (!$desc) { |
830 | 830 | $desc = $text; |
831 | 831 | } |
@@ -833,7 +833,7 @@ discard block |
||
833 | 833 | "; |
834 | 834 | } |
835 | 835 | |
836 | -function button_text($url, $text, $desc=null, $class="btn btn-default") { |
|
836 | +function button_text($url, $text, $desc = null, $class = "btn btn-default") { |
|
837 | 837 | if (!$desc) $desc = $text; |
838 | 838 | return "<a href=\"".$url."\" title=\"$desc\" class=\"".$class."\">".$text."</a> |
839 | 839 | "; |
@@ -846,7 +846,7 @@ discard block |
||
846 | 846 | // @param desc The title of the destination - typically used as a popup |
847 | 847 | // @param class The optional CSS class of the button. Defaults to a standard button |
848 | 848 | // |
849 | -function show_actionlist_button($url, $text, $desc, $class="btn btn-default"){ |
|
849 | +function show_actionlist_button($url, $text, $desc, $class = "btn btn-default") { |
|
850 | 850 | echo "<li>"; |
851 | 851 | echo show_button($url, $text, $desc, $class); |
852 | 852 | echo "</li>"; |
@@ -854,7 +854,7 @@ discard block |
||
854 | 854 | |
855 | 855 | // used for showing icons |
856 | 856 | // |
857 | -function show_image($src, $title, $alt, $height=null) { |
|
857 | +function show_image($src, $title, $alt, $height = null) { |
|
858 | 858 | $h = ""; |
859 | 859 | if ($height) { |
860 | 860 | $h = "height=\"$height\""; |
@@ -886,7 +886,7 @@ discard block |
||
886 | 886 | // tries instead to connect to <replica_db_host> if tag exists. |
887 | 887 | // DEPRECATED - use boinc_db.inc |
888 | 888 | // |
889 | -function db_init($try_replica=false) { |
|
889 | +function db_init($try_replica = false) { |
|
890 | 890 | check_web_stopped(); |
891 | 891 | $retval = db_init_aux($try_replica); |
892 | 892 | if ($retval == 1) { |
@@ -954,7 +954,7 @@ discard block |
||
954 | 954 | function sanitize_numeric($x) { |
955 | 955 | if (is_numeric($x)) { |
956 | 956 | return $x; |
957 | - } else if (trim($x) == '' ) { |
|
957 | + } else if (trim($x) == '') { |
|
958 | 958 | return ''; |
959 | 959 | } else { |
960 | 960 | return "not numeric"; |
@@ -977,9 +977,9 @@ discard block |
||
977 | 977 | return $c/(200/24); |
978 | 978 | } |
979 | 979 | |
980 | -function do_download($path,$name="") { |
|
981 | - if (strcmp($name,"") == 0) { |
|
982 | - $name=basename($path); |
|
980 | +function do_download($path, $name = "") { |
|
981 | + if (strcmp($name, "") == 0) { |
|
982 | + $name = basename($path); |
|
983 | 983 | } |
984 | 984 | header('Content-Description: File Transfer'); |
985 | 985 | header('Content-Type: application/octet-stream'); |
@@ -988,7 +988,7 @@ discard block |
||
988 | 988 | header('Expires: 0'); |
989 | 989 | header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); |
990 | 990 | header('Pragma: public'); |
991 | - header('Content-Length: ' . filesize($path)); |
|
991 | + header('Content-Length: '.filesize($path)); |
|
992 | 992 | flush(); |
993 | 993 | readfile($path); |
994 | 994 | } |
@@ -1036,10 +1036,10 @@ discard block |
||
1036 | 1036 | // Otherwise return 0. |
1037 | 1037 | // Format of user agent string is "BOINC client (windows_x86_64 7.3.17)" |
1038 | 1038 | // |
1039 | -function boinc_client_version(){ |
|
1039 | +function boinc_client_version() { |
|
1040 | 1040 | if (!array_key_exists('HTTP_USER_AGENT', $_SERVER)) return 0; |
1041 | 1041 | $x = $_SERVER['HTTP_USER_AGENT']; |
1042 | - $e = "/BOINC client [^ ]* (\d+).(\d+).(\d+)\)/"; |
|
1042 | + $e = "/BOINC client [^ ]* (\d+).(\d+).(\d+)\)/"; |
|
1043 | 1043 | if (preg_match($e, $x, $matches)) { |
1044 | 1044 | return $matches[1]*10000 + $matches[2]*100 + $matches[3]; |
1045 | 1045 | } |
@@ -1068,7 +1068,7 @@ discard block |
||
1068 | 1068 | $rem_name = $name."_remaining"; |
1069 | 1069 | return "<textarea name=\"$name\" class=\"form-control\" rows=3 id=\"$name\" onkeydown=\"text_counter(this.form.$name, this.form.$rem_name, $maxlen);\" |
1070 | 1070 | onkeyup=\"text_counter(this.form.$name, this.form.$rem_name, $maxlen);\">".$text."</textarea> |
1071 | - <br><input name=\"$rem_name\" type=\"text\" id=\"$rem_name\" value=\"".($maxlen-strlen($text))."\" size=\"3\" maxlength=\"3\" readonly> ".tra("characters remaining") |
|
1071 | + <br><input name=\"$rem_name\" type=\"text\" id=\"$rem_name\" value=\"".($maxlen - strlen($text))."\" size=\"3\" maxlength=\"3\" readonly> ".tra("characters remaining") |
|
1072 | 1072 | ; |
1073 | 1073 | } |
1074 | 1074 | |
@@ -1095,6 +1095,6 @@ discard block |
||
1095 | 1095 | "; |
1096 | 1096 | } |
1097 | 1097 | |
1098 | -$cvs_version_tracker[]="\$Id$"; //Generated automatically - do not edit |
|
1098 | +$cvs_version_tracker[] = "\$Id$"; //Generated automatically - do not edit |
|
1099 | 1099 | |
1100 | 1100 | ?> |
@@ -98,7 +98,9 @@ discard block |
||
98 | 98 | } |
99 | 99 | |
100 | 100 | function secure_url_base() { |
101 | - if (defined('SECURE_URL_BASE')) return SECURE_URL_BASE; |
|
101 | + if (defined('SECURE_URL_BASE')) { |
|
102 | + return SECURE_URL_BASE; |
|
103 | + } |
|
102 | 104 | return URL_BASE; |
103 | 105 | } |
104 | 106 | |
@@ -137,12 +139,18 @@ discard block |
||
137 | 139 | |
138 | 140 | function get_logged_in_user($must_be_logged_in=true) { |
139 | 141 | global $g_logged_in_user, $got_logged_in_user; |
140 | - if ($got_logged_in_user) return $g_logged_in_user; |
|
142 | + if ($got_logged_in_user) { |
|
143 | + return $g_logged_in_user; |
|
144 | + } |
|
141 | 145 | |
142 | - if (web_stopped()) return null; |
|
146 | + if (web_stopped()) { |
|
147 | + return null; |
|
148 | + } |
|
143 | 149 | |
144 | 150 | $authenticator = null; |
145 | - if (isset($_COOKIE['auth'])) $authenticator = $_COOKIE['auth']; |
|
151 | + if (isset($_COOKIE['auth'])) { |
|
152 | + $authenticator = $_COOKIE['auth']; |
|
153 | + } |
|
146 | 154 | |
147 | 155 | $authenticator = BoincDb::escape_string($authenticator); |
148 | 156 | if ($authenticator) { |
@@ -362,17 +370,23 @@ discard block |
||
362 | 370 | |
363 | 371 | |
364 | 372 | function date_str($x) { |
365 | - if ($x == 0) return "---"; |
|
373 | + if ($x == 0) { |
|
374 | + return "---"; |
|
375 | + } |
|
366 | 376 | return gmdate('j M Y', $x); |
367 | 377 | } |
368 | 378 | |
369 | 379 | function time_str($x) { |
370 | - if ($x == 0) return "---"; |
|
380 | + if ($x == 0) { |
|
381 | + return "---"; |
|
382 | + } |
|
371 | 383 | return gmdate('j M Y, G:i:s', $x) . " UTC"; |
372 | 384 | } |
373 | 385 | |
374 | 386 | function local_time_str($x) { |
375 | - if ($x == 0) return "---"; |
|
387 | + if ($x == 0) { |
|
388 | + return "---"; |
|
389 | + } |
|
376 | 390 | return date('j M Y, H:i T', $x); |
377 | 391 | } |
378 | 392 | |
@@ -445,8 +459,12 @@ discard block |
||
445 | 459 | define('VALUE_ATTRS_ERR', 'class="danger" style="padding-left:12px"'); |
446 | 460 | |
447 | 461 | function row2($x, $y, $show_error=false, $lwidth='40%') { |
448 | - if ($x==="") $x="<br>"; |
|
449 | - if ($y==="") $y="<br>"; |
|
462 | + if ($x==="") { |
|
463 | + $x="<br>"; |
|
464 | + } |
|
465 | + if ($y==="") { |
|
466 | + $y="<br>"; |
|
467 | + } |
|
450 | 468 | $attrs = $show_error?VALUE_ATTRS_ERR:VALUE_ATTRS; |
451 | 469 | echo "<tr> |
452 | 470 | <td width=\"$lwidth\" ".NAME_ATTRS.">$x</td> |
@@ -523,16 +541,26 @@ discard block |
||
523 | 541 | if (!$ttok) { |
524 | 542 | $ttok = $_POST['ttok']; |
525 | 543 | } |
526 | - if (!$tnow) return false; |
|
527 | - if (!$ttok) return false; |
|
544 | + if (!$tnow) { |
|
545 | + return false; |
|
546 | + } |
|
547 | + if (!$ttok) { |
|
548 | + return false; |
|
549 | + } |
|
528 | 550 | $t = md5((string)$tnow.$auth); |
529 | - if ($t != $ttok) return false; |
|
530 | - if (time() > $tnow + 86400) return false; |
|
551 | + if ($t != $ttok) { |
|
552 | + return false; |
|
553 | + } |
|
554 | + if (time() > $tnow + 86400) { |
|
555 | + return false; |
|
556 | + } |
|
531 | 557 | return true; |
532 | 558 | } |
533 | 559 | |
534 | 560 | function check_tokens($auth) { |
535 | - if (valid_tokens($auth)) return; |
|
561 | + if (valid_tokens($auth)) { |
|
562 | + return; |
|
563 | + } |
|
536 | 564 | error_page( |
537 | 565 | tra("Link has timed out. Please click Back, refresh the page, and try again.") |
538 | 566 | ); |
@@ -640,7 +668,9 @@ discard block |
||
640 | 668 | // |
641 | 669 | function get_int($name, $optional=false) { |
642 | 670 | $x=null; |
643 | - if (isset($_GET[$name])) $x = $_GET[$name]; |
|
671 | + if (isset($_GET[$name])) { |
|
672 | + $x = $_GET[$name]; |
|
673 | + } |
|
644 | 674 | if (!is_numeric($x)) { |
645 | 675 | if ($optional) { |
646 | 676 | if ($x) { |
@@ -660,7 +690,9 @@ discard block |
||
660 | 690 | // |
661 | 691 | function post_num($name, $optional=false) { |
662 | 692 | $x = null; |
663 | - if (isset($_POST[$name])) $x = $_POST[$name]; |
|
693 | + if (isset($_POST[$name])) { |
|
694 | + $x = $_POST[$name]; |
|
695 | + } |
|
664 | 696 | if (!is_numeric($x)) { |
665 | 697 | if ($optional) { |
666 | 698 | return null; |
@@ -675,7 +707,9 @@ discard block |
||
675 | 707 | // |
676 | 708 | function post_int($name, $optional=false) { |
677 | 709 | $x = post_num($name, $optional); |
678 | - if (is_null($x)) return null; |
|
710 | + if (is_null($x)) { |
|
711 | + return null; |
|
712 | + } |
|
679 | 713 | $y = (int)$x; |
680 | 714 | if ($x != $y) { |
681 | 715 | error_page("param $name must be an integer"); |
@@ -733,7 +767,9 @@ discard block |
||
733 | 767 | |
734 | 768 | for ($i=0; $i<strlen($str); $i++) { |
735 | 769 | $c = ord(substr($str, $i)); |
736 | - if ($c < 32 || $c > 127) return false; |
|
770 | + if ($c < 32 || $c > 127) { |
|
771 | + return false; |
|
772 | + } |
|
737 | 773 | } |
738 | 774 | return true; |
739 | 775 | } |
@@ -755,16 +791,24 @@ discard block |
||
755 | 791 | $number = str_replace(',', '.', $number); // replace the german decimal separator |
756 | 792 | // if no value was entered and this is ok |
757 | 793 | // |
758 | - if ($number=='' && !$low) return true; |
|
794 | + if ($number=='' && !$low) { |
|
795 | + return true; |
|
796 | + } |
|
759 | 797 | |
760 | 798 | // the supplied value contains alphabetic characters |
761 | 799 | // |
762 | - if (!is_numeric($number)) return false; |
|
800 | + if (!is_numeric($number)) { |
|
801 | + return false; |
|
802 | + } |
|
763 | 803 | |
764 | - if ($number < $low) return false; |
|
804 | + if ($number < $low) { |
|
805 | + return false; |
|
806 | + } |
|
765 | 807 | |
766 | 808 | if ($high) { |
767 | - if ($number > $high) return false; |
|
809 | + if ($number > $high) { |
|
810 | + return false; |
|
811 | + } |
|
768 | 812 | } |
769 | 813 | $value = (double)$number; |
770 | 814 | return true; |
@@ -834,7 +878,9 @@ discard block |
||
834 | 878 | } |
835 | 879 | |
836 | 880 | function button_text($url, $text, $desc=null, $class="btn btn-default") { |
837 | - if (!$desc) $desc = $text; |
|
881 | + if (!$desc) { |
|
882 | + $desc = $text; |
|
883 | + } |
|
838 | 884 | return "<a href=\"".$url."\" title=\"$desc\" class=\"".$class."\">".$text."</a> |
839 | 885 | "; |
840 | 886 | } |
@@ -939,9 +985,15 @@ discard block |
||
939 | 985 | // |
940 | 986 | function sanitize_local_url($x) { |
941 | 987 | $x = trim($x, "/"); |
942 | - if (strstr($x, "/")) return ""; |
|
943 | - if (strstr($x, "<")) return ""; |
|
944 | - if (strstr($x, "\"")) return ""; |
|
988 | + if (strstr($x, "/")) { |
|
989 | + return ""; |
|
990 | + } |
|
991 | + if (strstr($x, "<")) { |
|
992 | + return ""; |
|
993 | + } |
|
994 | + if (strstr($x, "\"")) { |
|
995 | + return ""; |
|
996 | + } |
|
945 | 997 | return $x; |
946 | 998 | } |
947 | 999 | |
@@ -1005,13 +1057,17 @@ discard block |
||
1005 | 1057 | } |
1006 | 1058 | |
1007 | 1059 | function badges_string($is_user, $item, $height) { |
1008 | - if (DISABLE_BADGES) return null; |
|
1060 | + if (DISABLE_BADGES) { |
|
1061 | + return null; |
|
1062 | + } |
|
1009 | 1063 | if ($is_user) { |
1010 | 1064 | $bus = BoincBadgeUser::enum("user_id=$item->id"); |
1011 | 1065 | } else { |
1012 | 1066 | $bus = BoincBadgeTeam::enum("team_id=$item->id"); |
1013 | 1067 | } |
1014 | - if (!$bus) return null; |
|
1068 | + if (!$bus) { |
|
1069 | + return null; |
|
1070 | + } |
|
1015 | 1071 | $x = ""; |
1016 | 1072 | foreach ($bus as $bu) { |
1017 | 1073 | $badge = BoincBadge::lookup_id($bu->badge_id); |
@@ -1021,7 +1077,9 @@ discard block |
||
1021 | 1077 | } |
1022 | 1078 | |
1023 | 1079 | function show_badges_row($is_user, $item) { |
1024 | - if (BADGE_HEIGHT_LARGE == 0) return; |
|
1080 | + if (BADGE_HEIGHT_LARGE == 0) { |
|
1081 | + return; |
|
1082 | + } |
|
1025 | 1083 | $x = badges_string($is_user, $item, BADGE_HEIGHT_LARGE); |
1026 | 1084 | if ($x) { |
1027 | 1085 | row2("Badges", $x); |
@@ -1037,7 +1095,9 @@ discard block |
||
1037 | 1095 | // Format of user agent string is "BOINC client (windows_x86_64 7.3.17)" |
1038 | 1096 | // |
1039 | 1097 | function boinc_client_version(){ |
1040 | - if (!array_key_exists('HTTP_USER_AGENT', $_SERVER)) return 0; |
|
1098 | + if (!array_key_exists('HTTP_USER_AGENT', $_SERVER)) { |
|
1099 | + return 0; |
|
1100 | + } |
|
1041 | 1101 | $x = $_SERVER['HTTP_USER_AGENT']; |
1042 | 1102 | $e = "/BOINC client [^ ]* (\d+).(\d+).(\d+)\)/"; |
1043 | 1103 | if (preg_match($e, $x, $matches)) { |
@@ -36,6 +36,10 @@ discard block |
||
36 | 36 | return file_exists("$d/stop_sched"); |
37 | 37 | } |
38 | 38 | |
39 | +/** |
|
40 | + * @param string $x |
|
41 | + * @param string $y |
|
42 | + */ |
|
39 | 43 | function show_page($x, $y) { |
40 | 44 | echo " |
41 | 45 | <title>$x</title> |
@@ -44,6 +48,9 @@ discard block |
||
44 | 48 | "; |
45 | 49 | } |
46 | 50 | |
51 | +/** |
|
52 | + * @param integer $num |
|
53 | + */ |
|
47 | 54 | function xml_error($num, $msg=null, $file=null, $line=null) { |
48 | 55 | global $xml_outer_tag; |
49 | 56 | if (!$msg) { |
@@ -107,6 +114,9 @@ discard block |
||
107 | 114 | return trim($element); |
108 | 115 | } |
109 | 116 | |
117 | +/** |
|
118 | + * @param string $tag |
|
119 | + */ |
|
110 | 120 | function parse_next_element($xml, $tag, &$cursor) { |
111 | 121 | $element = null; |
112 | 122 | $closetag = "</" . substr($tag,1); |
@@ -137,6 +147,9 @@ discard block |
||
137 | 147 | |
138 | 148 | // look for a particular element in the config file |
139 | 149 | // |
150 | +/** |
|
151 | + * @param string $tag |
|
152 | + */ |
|
140 | 153 | function parse_config($config, $tag) { |
141 | 154 | $element = parse_element($config, $tag); |
142 | 155 | return $element; |
@@ -44,10 +44,10 @@ discard block |
||
44 | 44 | "; |
45 | 45 | } |
46 | 46 | |
47 | -function xml_error($num, $msg=null, $file=null, $line=null) { |
|
47 | +function xml_error($num, $msg = null, $file = null, $line = null) { |
|
48 | 48 | global $xml_outer_tag; |
49 | 49 | if (!$msg) { |
50 | - switch($num) { |
|
50 | + switch ($num) { |
|
51 | 51 | case -112: $msg = "Invalid XML"; break; |
52 | 52 | case -136: $msg = "Not found"; break; |
53 | 53 | case -137: $msg = "Name or email address is not unique"; break; |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | // |
95 | 95 | function parse_element($xml, $tag) { |
96 | 96 | $element = null; |
97 | - $closetag = "</" . substr($tag,1); |
|
97 | + $closetag = "</".substr($tag, 1); |
|
98 | 98 | $x = strstr($xml, $tag); |
99 | 99 | if ($x) { |
100 | 100 | if (strstr($tag, "/>")) return $tag; |
@@ -109,8 +109,8 @@ discard block |
||
109 | 109 | |
110 | 110 | function parse_next_element($xml, $tag, &$cursor) { |
111 | 111 | $element = null; |
112 | - $closetag = "</" . substr($tag,1); |
|
113 | - $pos = substr($xml,$cursor); |
|
112 | + $closetag = "</".substr($tag, 1); |
|
113 | + $pos = substr($xml, $cursor); |
|
114 | 114 | $x = strstr($pos, $tag); |
115 | 115 | if ($x) { |
116 | 116 | if (strstr($tag, "/>")) return $tag; |
@@ -97,7 +97,9 @@ discard block |
||
97 | 97 | $closetag = "</" . substr($tag,1); |
98 | 98 | $x = strstr($xml, $tag); |
99 | 99 | if ($x) { |
100 | - if (strstr($tag, "/>")) return $tag; |
|
100 | + if (strstr($tag, "/>")) { |
|
101 | + return $tag; |
|
102 | + } |
|
101 | 103 | $y = substr($x, strlen($tag)); |
102 | 104 | $n = strpos($y, $closetag); |
103 | 105 | if ($n) { |
@@ -113,7 +115,9 @@ discard block |
||
113 | 115 | $pos = substr($xml,$cursor); |
114 | 116 | $x = strstr($pos, $tag); |
115 | 117 | if ($x) { |
116 | - if (strstr($tag, "/>")) return $tag; |
|
118 | + if (strstr($tag, "/>")) { |
|
119 | + return $tag; |
|
120 | + } |
|
117 | 121 | $y = substr($x, strlen($tag)); |
118 | 122 | $n = strpos($y, $closetag); |
119 | 123 | if ($n) { |
@@ -128,10 +132,14 @@ discard block |
||
128 | 132 | // |
129 | 133 | function parse_bool($xml, $tag) { |
130 | 134 | $x = "<$tag/>"; |
131 | - if (strstr($xml, $x)) return true; |
|
135 | + if (strstr($xml, $x)) { |
|
136 | + return true; |
|
137 | + } |
|
132 | 138 | $x = "<$tag>"; |
133 | 139 | $y = (int)parse_element($xml, $x); |
134 | - if ($y != 0) return true; |
|
140 | + if ($y != 0) { |
|
141 | + return true; |
|
142 | + } |
|
135 | 143 | return false; |
136 | 144 | } |
137 | 145 | |
@@ -149,10 +157,18 @@ discard block |
||
149 | 157 | // kludge |
150 | 158 | // |
151 | 159 | function is_gpu($plan_class) { |
152 | - if (strstr($plan_class, "ati")) return true; |
|
153 | - if (strstr($plan_class, "cuda")) return true; |
|
154 | - if (strstr($plan_class, "nvidia")) return true; |
|
155 | - if (strstr($plan_class, "intel_gpu")) return true; |
|
160 | + if (strstr($plan_class, "ati")) { |
|
161 | + return true; |
|
162 | + } |
|
163 | + if (strstr($plan_class, "cuda")) { |
|
164 | + return true; |
|
165 | + } |
|
166 | + if (strstr($plan_class, "nvidia")) { |
|
167 | + return true; |
|
168 | + } |
|
169 | + if (strstr($plan_class, "intel_gpu")) { |
|
170 | + return true; |
|
171 | + } |
|
156 | 172 | return false; |
157 | 173 | } |
158 | 174 |
@@ -65,10 +65,17 @@ discard block |
||
65 | 65 | . "<p>\n"; |
66 | 66 | } |
67 | 67 | |
68 | +/** |
|
69 | + * @param string $x |
|
70 | + */ |
|
68 | 71 | function row($x, $y) { |
69 | 72 | echo "<tr><td valign=\"top\" align=\"right\">$x</td>\n<td>$y</td>\n</tr>\n"; |
70 | 73 | } |
71 | 74 | |
75 | +/** |
|
76 | + * @param string $color |
|
77 | + * @param string $x |
|
78 | + */ |
|
72 | 79 | function c_row2($color, $x, $y) { |
73 | 80 | echo "<tr bgcolor=\"$color\"><td align=\"right\">$x</td><td>$y</td></tr>\n"; |
74 | 81 | } |
@@ -134,6 +141,9 @@ discard block |
||
134 | 141 | |
135 | 142 | // allow access only if logged in as user in a given set |
136 | 143 | // |
144 | +/** |
|
145 | + * @param integer[] $admin_user_ids |
|
146 | + */ |
|
137 | 147 | function auth_ops_userid($admin_user_ids) { |
138 | 148 | $user = get_logged_in_user_ops(); |
139 | 149 | if (!$user) { |
@@ -288,6 +298,10 @@ discard block |
||
288 | 298 | |
289 | 299 | ////// badge-related stuff |
290 | 300 | |
301 | +/** |
|
302 | + * @param string $name |
|
303 | + * @param string $title |
|
304 | + */ |
|
291 | 305 | function get_badge($name, $title, $image_url) { |
292 | 306 | $b = BoincBadge::lookup("name='$name'"); |
293 | 307 | if ($b) return $b; |
@@ -319,6 +333,9 @@ discard block |
||
319 | 333 | |
320 | 334 | // unassign all badges except the given one |
321 | 335 | // |
336 | +/** |
|
337 | + * @param integer $k |
|
338 | + */ |
|
322 | 339 | function unassign_badges($is_user, $item, $badges, $k) { |
323 | 340 | $list = null; |
324 | 341 | for ($i=0; $i<count($badges); $i++) { |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | |
63 | 63 | function print_text_field($text,$name,$value) { |
64 | 64 | echo "$text <input type=\"text\" size=\"10\" name=\"$name\" value=\"$value\">\n" |
65 | - . "<p>\n"; |
|
65 | + . "<p>\n"; |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | function row($x, $y) { |
@@ -378,7 +378,7 @@ discard block |
||
378 | 378 | $db->do_query($q4); |
379 | 379 | return 2; |
380 | 380 | } else if (!$db->do_query($q3)) { |
381 | - echo "MySQL command '$q3' failed:<br/>unable to cancel workunits and trigger transitioner.<br>\n"; |
|
381 | + echo "MySQL command '$q3' failed:<br/>unable to cancel workunits and trigger transitioner.<br>\n"; |
|
382 | 382 | $db->do_query($q4); |
383 | 383 | return 3; |
384 | 384 | } |
@@ -46,21 +46,21 @@ discard block |
||
46 | 46 | |
47 | 47 | // TODO: get rid of all the following |
48 | 48 | |
49 | -function print_checkbox($text,$name,$checked) { |
|
49 | +function print_checkbox($text, $name, $checked) { |
|
50 | 50 | echo "<input type=\"checkbox\" name=\"$name\"" |
51 | - . (strlen($checked) ? " checked=\"checked\"" : "") . ">" |
|
51 | + . (strlen($checked) ? " checked=\"checked\"" : "").">" |
|
52 | 52 | . "$text\n" |
53 | 53 | . "<p>\n"; |
54 | 54 | } |
55 | 55 | |
56 | -function print_radio_button($text,$name,$value,$checked) { |
|
56 | +function print_radio_button($text, $name, $value, $checked) { |
|
57 | 57 | echo "<input type=\"radio\" name=\"$name\" value=\"$value\"" |
58 | - . (strlen($checked) ? " checked=\"checked\"" : "") . ">" |
|
58 | + . (strlen($checked) ? " checked=\"checked\"" : "").">" |
|
59 | 59 | . "$text\n" |
60 | 60 | . "<br>\n"; |
61 | 61 | } |
62 | 62 | |
63 | -function print_text_field($text,$name,$value) { |
|
63 | +function print_text_field($text, $name, $value) { |
|
64 | 64 | echo "$text <input type=\"text\" size=\"10\" name=\"$name\" value=\"$value\">\n" |
65 | 65 | . "<p>\n"; |
66 | 66 | } |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | if ($host == null) { |
92 | 92 | $host = "localhost"; |
93 | 93 | } |
94 | - $in = fopen("php://stdin","r"); |
|
94 | + $in = fopen("php://stdin", "r"); |
|
95 | 95 | print "Database username (default: owner of mysqld process): "; |
96 | 96 | $user = rtrim(fgets($in, 80)); |
97 | 97 | print "Database password (if any): "; |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | } |
104 | 104 | } |
105 | 105 | |
106 | -function print_login_form_ops($next_url='') { |
|
106 | +function print_login_form_ops($next_url = '') { |
|
107 | 107 | if ($next_url == '') $next_url = $_SERVER['REQUEST_URI']; |
108 | 108 | start_table(); |
109 | 109 | echo " |
@@ -200,7 +200,7 @@ discard block |
||
200 | 200 | // return a list of the current, non-deprecated ones |
201 | 201 | // |
202 | 202 | function current_versions($avs) { |
203 | - foreach($avs as $av) { |
|
203 | + foreach ($avs as $av) { |
|
204 | 204 | foreach ($avs as $av2) { |
205 | 205 | if ($av->id == $av2->id) continue; |
206 | 206 | if ($av->platformid == $av2->platformid && $av->plan_class == $av2->plan_class && $av->version_num > $av2->version_num) { |
@@ -209,7 +209,7 @@ discard block |
||
209 | 209 | } |
210 | 210 | } |
211 | 211 | $x = array(); |
212 | - foreach($avs as $av) { |
|
212 | + foreach ($avs as $av) { |
|
213 | 213 | if (!$av->deprecated) $x[] = $av; |
214 | 214 | } |
215 | 215 | return $x; |
@@ -321,7 +321,7 @@ discard block |
||
321 | 321 | // |
322 | 322 | function unassign_badges($is_user, $item, $badges, $k) { |
323 | 323 | $list = null; |
324 | - for ($i=0; $i<count($badges); $i++) { |
|
324 | + for ($i = 0; $i < count($badges); $i++) { |
|
325 | 325 | if ($i == $k) continue; |
326 | 326 | $badge = $badges[$i]; |
327 | 327 | if ($list) { |
@@ -104,7 +104,9 @@ discard block |
||
104 | 104 | } |
105 | 105 | |
106 | 106 | function print_login_form_ops($next_url='') { |
107 | - if ($next_url == '') $next_url = $_SERVER['REQUEST_URI']; |
|
107 | + if ($next_url == '') { |
|
108 | + $next_url = $_SERVER['REQUEST_URI']; |
|
109 | + } |
|
108 | 110 | start_table(); |
109 | 111 | echo " |
110 | 112 | <form method=post action=login_action.php> |
@@ -119,9 +121,13 @@ discard block |
||
119 | 121 | |
120 | 122 | function get_logged_in_user_ops() { |
121 | 123 | global $g_logged_in_user; |
122 | - if ($g_logged_in_user) return $g_logged_in_user; |
|
124 | + if ($g_logged_in_user) { |
|
125 | + return $g_logged_in_user; |
|
126 | + } |
|
123 | 127 | $authenticator = null; |
124 | - if (isset($_COOKIE['auth'])) $authenticator = $_COOKIE['auth']; |
|
128 | + if (isset($_COOKIE['auth'])) { |
|
129 | + $authenticator = $_COOKIE['auth']; |
|
130 | + } |
|
125 | 131 | |
126 | 132 | $authenticator = BoincDb::escape_string($authenticator); |
127 | 133 | if ($authenticator) { |
@@ -202,7 +208,9 @@ discard block |
||
202 | 208 | function current_versions($avs) { |
203 | 209 | foreach($avs as $av) { |
204 | 210 | foreach ($avs as $av2) { |
205 | - if ($av->id == $av2->id) continue; |
|
211 | + if ($av->id == $av2->id) { |
|
212 | + continue; |
|
213 | + } |
|
206 | 214 | if ($av->platformid == $av2->platformid && $av->plan_class == $av2->plan_class && $av->version_num > $av2->version_num) { |
207 | 215 | $av2->deprecated = 1; |
208 | 216 | } |
@@ -210,7 +218,9 @@ discard block |
||
210 | 218 | } |
211 | 219 | $x = array(); |
212 | 220 | foreach($avs as $av) { |
213 | - if (!$av->deprecated) $x[] = $av; |
|
221 | + if (!$av->deprecated) { |
|
222 | + $x[] = $av; |
|
223 | + } |
|
214 | 224 | } |
215 | 225 | return $x; |
216 | 226 | } |
@@ -245,7 +255,9 @@ discard block |
||
245 | 255 | $wus = BoincWorkunit::enum("id >= $id1 and id <= $id2"); |
246 | 256 | foreach ($wus as $wu) { |
247 | 257 | $results = BoincResult::enum("workunitid=$wu->id and server_state > 2"); |
248 | - if (count($results)) continue; |
|
258 | + if (count($results)) { |
|
259 | + continue; |
|
260 | + } |
|
249 | 261 | $retval = BoincResult::update_aux("server_state=5, outcome=5 where workunitid=$wu->id"); |
250 | 262 | if (!$retval) { |
251 | 263 | error_page("result update failed"); |
@@ -290,11 +302,15 @@ discard block |
||
290 | 302 | |
291 | 303 | function get_badge($name, $title, $image_url) { |
292 | 304 | $b = BoincBadge::lookup("name='$name'"); |
293 | - if ($b) return $b; |
|
305 | + if ($b) { |
|
306 | + return $b; |
|
307 | + } |
|
294 | 308 | $now = time(); |
295 | 309 | $id = BoincBadge::insert("(create_time, name, title, image_url) values ($now, '$name', '$title', 'img/$image_url')"); |
296 | 310 | $b = BoincBadge::lookup_id($id); |
297 | - if ($b) return $b; |
|
311 | + if ($b) { |
|
312 | + return $b; |
|
313 | + } |
|
298 | 314 | die("can't create badge $name\n"); |
299 | 315 | } |
300 | 316 | |
@@ -322,7 +338,9 @@ discard block |
||
322 | 338 | function unassign_badges($is_user, $item, $badges, $k) { |
323 | 339 | $list = null; |
324 | 340 | for ($i=0; $i<count($badges); $i++) { |
325 | - if ($i == $k) continue; |
|
341 | + if ($i == $k) { |
|
342 | + continue; |
|
343 | + } |
|
326 | 344 | $badge = $badges[$i]; |
327 | 345 | if ($list) { |
328 | 346 | $list .= ",$badge->id"; |
@@ -21,6 +21,9 @@ discard block |
||
21 | 21 | // my PHP currently doesn't support file_get_contents(https://...) |
22 | 22 | // so do it with Curl |
23 | 23 | // |
24 | +/** |
|
25 | + * @param string $url |
|
26 | + */ |
|
24 | 27 | function fetch_url($url) { |
25 | 28 | if (0) { |
26 | 29 | return file_get_contents($url); |
@@ -35,6 +38,11 @@ discard block |
||
35 | 38 | } |
36 | 39 | } |
37 | 40 | |
41 | +/** |
|
42 | + * @param string $project_url |
|
43 | + * @param string $email_addr |
|
44 | + * @param string $passwd_hash |
|
45 | + */ |
|
38 | 46 | function lookup_account( |
39 | 47 | $project_url, |
40 | 48 | $email_addr, |
@@ -57,6 +65,12 @@ discard block |
||
57 | 65 | |
58 | 66 | // return (authenticator, errmsg) |
59 | 67 | // |
68 | +/** |
|
69 | + * @param string $project_url |
|
70 | + * @param string $email_addr |
|
71 | + * @param string $passwd_hash |
|
72 | + * @param string $user_name |
|
73 | + */ |
|
60 | 74 | function create_account( |
61 | 75 | $project_url, |
62 | 76 | $email_addr, |
@@ -42,7 +42,9 @@ discard block |
||
42 | 42 | ) { |
43 | 43 | $url = $project_url."/lookup_account.php?email_addr=".urlencode($email_addr)."&passwd_hash=$passwd_hash"; |
44 | 44 | $reply = fetch_url($url); |
45 | - if (!$reply) return array(null, -1, "HTTP error"); |
|
45 | + if (!$reply) { |
|
46 | + return array(null, -1, "HTTP error"); |
|
47 | + } |
|
46 | 48 | $r = @simplexml_load_string($reply); |
47 | 49 | if (!$r) { |
48 | 50 | return array(null, -1, "Can't parse reply XML:\n$reply"); |
@@ -67,7 +69,9 @@ discard block |
||
67 | 69 | |
68 | 70 | //echo "url: $url\n"; |
69 | 71 | $reply = fetch_url($url); |
70 | - if (!$reply) return array(null, -1, "HTTP error"); |
|
72 | + if (!$reply) { |
|
73 | + return array(null, -1, "HTTP error"); |
|
74 | + } |
|
71 | 75 | //echo "reply: $reply\n"; |
72 | 76 | $r = @simplexml_load_string($reply); |
73 | 77 | if (!$r) { |
@@ -57,6 +57,9 @@ |
||
57 | 57 | |
58 | 58 | $xml_outer_tag = ""; |
59 | 59 | |
60 | +/** |
|
61 | + * @param string $tag |
|
62 | + */ |
|
60 | 63 | function xml_start_tag($tag) { |
61 | 64 | global $xml_outer_tag; |
62 | 65 | echo "<$tag>\n"; |
@@ -26,15 +26,21 @@ |
||
26 | 26 | return ERR_PROJECT_DOWN; |
27 | 27 | } |
28 | 28 | $db = BoincDb::get(); |
29 | - if (!$db) return ERR_DB_CANT_CONNECT; |
|
29 | + if (!$db) { |
|
30 | + return ERR_DB_CANT_CONNECT; |
|
31 | + } |
|
30 | 32 | return 0; |
31 | 33 | } |
32 | 34 | |
33 | 35 | // write PHP warnings as XML, so that the reply can be parsed by client |
34 | 36 | // |
35 | 37 | function error_handler($errno, $errstr, $errfile, $errline) { |
36 | - if ($errno == E_WARNING) $errno = "Warning"; |
|
37 | - if ($errno == E_NOTICE) $errno = "Notice"; |
|
38 | + if ($errno == E_WARNING) { |
|
39 | + $errno = "Warning"; |
|
40 | + } |
|
41 | + if ($errno == E_NOTICE) { |
|
42 | + $errno = "Notice"; |
|
43 | + } |
|
38 | 44 | echo "<error> |
39 | 45 | <error_msg><![CDATA[$errstr]]></error_msg> |
40 | 46 | <type>$errno</type> |
@@ -72,6 +72,9 @@ discard block |
||
72 | 72 | // badge_name_prefix should be user or team |
73 | 73 | // sub_project is an array with name and short_name as in $sub_projects |
74 | 74 | // |
75 | +/** |
|
76 | + * @param string $badge_name_prefix |
|
77 | + */ |
|
75 | 78 | function get_badges( |
76 | 79 | $badge_name_prefix, $badge_level_names, $badge_images, $sub_project |
77 | 80 | ) { |
@@ -105,6 +108,9 @@ discard block |
||
105 | 108 | // decide which subproject badge to assign, if any. |
106 | 109 | // Unassign other badges. |
107 | 110 | // |
111 | +/** |
|
112 | + * @param string $where_clause |
|
113 | + */ |
|
108 | 114 | function assign_sub_badge($is_user, $item, $levels, $badges, $where_clause) { |
109 | 115 | if ($is_user) { |
110 | 116 | $sub_total = BoincCreditUser::sum('total', "where userid=".$item->id." and ($where_clause)"); |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | ) { |
78 | 78 | $badges = array(); |
79 | 79 | $limit = count($badge_level_names); |
80 | - for ($i=0; $i < $limit; $i++) { |
|
80 | + for ($i = 0; $i < $limit; $i++) { |
|
81 | 81 | $badges[$i] = get_badge($badge_name_prefix."_".$sub_project["short_name"]."_".$i, "$badge_level_names[$i] in ".$sub_project["name"]." credit", $sub_project["short_name"].$badge_images[$i]); |
82 | 82 | } |
83 | 83 | return $badges; |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | // count from highest to lowest level, so the user get's assigned the |
91 | 91 | // highest possible level and the lower levels get removed |
92 | 92 | // |
93 | - for ($i=count($levels)-1; $i>=0; $i--) { |
|
93 | + for ($i = count($levels) - 1; $i >= 0; $i--) { |
|
94 | 94 | if ($item->total_credit >= $levels[$i]) { |
95 | 95 | assign_badge($is_user, $item, $badges[$i]); |
96 | 96 | unassign_badges($is_user, $item, $badges, $i); |
@@ -114,7 +114,7 @@ discard block |
||
114 | 114 | // count from highest to lowest level, so the user get's assigned the |
115 | 115 | // highest possible level and the lower levels get removed |
116 | 116 | // |
117 | - for ($i=count($levels)-1; $i>=0; $i--) { |
|
117 | + for ($i = count($levels) - 1; $i >= 0; $i--) { |
|
118 | 118 | if ($sub_total >= $levels[$i]) { |
119 | 119 | assign_badge($is_user, $item, $badges[$i]); |
120 | 120 | unassign_badges($is_user, $item, $badges, $i); |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | $is_user, $badge_levels, $badge_level_names, $badge_images, |
135 | 135 | $subprojects_list |
136 | 136 | ) { |
137 | - $kind = $is_user?"user":"team"; |
|
137 | + $kind = $is_user ? "user" : "team"; |
|
138 | 138 | |
139 | 139 | // get badges for all subprojects including total |
140 | 140 | // |
@@ -143,7 +143,7 @@ discard block |
||
143 | 143 | } |
144 | 144 | |
145 | 145 | $n = 0; |
146 | - $maxid = $is_user?BoincUser::max("id"):BoincTeam::max("id"); |
|
146 | + $maxid = $is_user ? BoincUser::max("id") : BoincTeam::max("id"); |
|
147 | 147 | while ($n <= $maxid) { |
148 | 148 | $m = $n + 1000; |
149 | 149 | if ($is_user) { |
@@ -161,7 +161,7 @@ discard block |
||
161 | 161 | assign_tot_badge($is_user, $item, $badge_levels, $badges["total"]); |
162 | 162 | } else { |
163 | 163 | // appids come from project/project.inc |
164 | - $where_clause = "appid in (". implode(',', $sp["appids"]) .")"; |
|
164 | + $where_clause = "appid in (".implode(',', $sp["appids"]).")"; |
|
165 | 165 | assign_sub_badge( |
166 | 166 | $is_user, $item, $badge_levels, $badges[$sp["short_name"]], |
167 | 167 | $where_clause |
@@ -173,6 +173,9 @@ discard block |
||
173 | 173 | return $x; |
174 | 174 | } |
175 | 175 | |
176 | +/** |
|
177 | + * @param integer $mode |
|
178 | + */ |
|
176 | 179 | function get_nquestions($unit, $mode) { |
177 | 180 | global $snap; |
178 | 181 | |
@@ -187,6 +190,9 @@ discard block |
||
187 | 190 | return 0; |
188 | 191 | } |
189 | 192 | |
193 | +/** |
|
194 | + * @param integer $mode |
|
195 | + */ |
|
190 | 196 | function get_views($unit, $mode) { |
191 | 197 | global $snap; |
192 | 198 | |
@@ -231,6 +237,10 @@ discard block |
||
231 | 237 | |
232 | 238 | $rownum = 0; |
233 | 239 | |
240 | +/** |
|
241 | + * @param string $class |
|
242 | + * @param boolean $is_answer |
|
243 | + */ |
|
234 | 244 | function show_unit_row($unit, $class, $level, $is_answer) { |
235 | 245 | global $breakdown, $breakdown_cat; |
236 | 246 | global $rownum, $course_id; |
@@ -319,6 +329,9 @@ discard block |
||
319 | 329 | echo "</tr>\n"; |
320 | 330 | } |
321 | 331 | |
332 | +/** |
|
333 | + * @param string $class |
|
334 | + */ |
|
322 | 335 | function breakdown_class($class) { |
323 | 336 | switch ($class) { |
324 | 337 | case "BoltLesson": |
@@ -356,6 +369,9 @@ discard block |
||
356 | 369 | } |
357 | 370 | } |
358 | 371 | |
372 | +/** |
|
373 | + * @param integer $level |
|
374 | + */ |
|
359 | 375 | function show_unit_recurse($unit, $level) { |
360 | 376 | show_unit($unit, $level); |
361 | 377 | if ($unit->is_item) return; |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | |
104 | 104 | function spaces($level) { |
105 | 105 | $x = ""; |
106 | - for ($i=0; $i<$level; $i++) { |
|
106 | + for ($i = 0; $i < $level; $i++) { |
|
107 | 107 | $x .= " "; |
108 | 108 | } |
109 | 109 | return $x; |
@@ -136,7 +136,7 @@ discard block |
||
136 | 136 | function avg_score($array) { |
137 | 137 | $sum = 0; |
138 | 138 | $n = count($array); |
139 | - if ($n ==0) return 0; |
|
139 | + if ($n == 0) return 0; |
|
140 | 140 | foreach ($array as $a) { |
141 | 141 | $sum += $a->score; |
142 | 142 | } |
@@ -152,7 +152,7 @@ discard block |
||
152 | 152 | $n++; |
153 | 153 | } |
154 | 154 | } |
155 | - if ($n ==0) return 0; |
|
155 | + if ($n == 0) return 0; |
|
156 | 156 | return $sum/$n; |
157 | 157 | } |
158 | 158 | |
@@ -235,7 +235,7 @@ discard block |
||
235 | 235 | global $breakdown, $breakdown_cat; |
236 | 236 | global $rownum, $course_id; |
237 | 237 | |
238 | - $a = $is_answer?" (answer)":""; |
|
238 | + $a = $is_answer ? " (answer)" : ""; |
|
239 | 239 | $j = ($rownum++)%2; |
240 | 240 | echo "<tr class=row$j>"; |
241 | 241 | if ($breakdown && $breakdown_cat) { |
@@ -243,7 +243,7 @@ discard block |
||
243 | 243 | <td><br></td> |
244 | 244 | <td><br></td> |
245 | 245 | "; |
246 | - } else { |
|
246 | + } else { |
|
247 | 247 | $c = class_name($class); |
248 | 248 | echo " |
249 | 249 | <td><b>".spaces($level)."$unit->name</b></td> |
@@ -277,7 +277,7 @@ discard block |
||
277 | 277 | echo time_graph($t, 200); |
278 | 278 | break; |
279 | 279 | case "BoltExercise": |
280 | - $mode = $is_answer?BOLT_MODE_ANSWER:BOLT_MODE_SHOW; |
|
280 | + $mode = $is_answer ? BOLT_MODE_ANSWER : BOLT_MODE_SHOW; |
|
281 | 281 | $views = get_views($unit, $mode); |
282 | 282 | $n = count($views); |
283 | 283 | $out = outcomes($views); |
@@ -360,7 +360,7 @@ discard block |
||
360 | 360 | show_unit($unit, $level); |
361 | 361 | if ($unit->is_item) return; |
362 | 362 | foreach ($unit->units as $u) { |
363 | - show_unit_recurse($u, $level+1); |
|
363 | + show_unit_recurse($u, $level + 1); |
|
364 | 364 | } |
365 | 365 | } |
366 | 366 | |
@@ -402,9 +402,9 @@ discard block |
||
402 | 402 | <input type=hidden name=course_id value=$course_id> |
403 | 403 | <table width=600><tr><td valign=top> |
404 | 404 | "; |
405 | - filter_form($filter?$filter->name():"", $filter_cat); |
|
405 | + filter_form($filter ? $filter->name() : "", $filter_cat); |
|
406 | 406 | echo "</td><td valign=top>"; |
407 | - breakdown_form($breakdown?$breakdown->name():""); |
|
407 | + breakdown_form($breakdown ? $breakdown->name() : ""); |
|
408 | 408 | echo " |
409 | 409 | </td></tr></table> |
410 | 410 | <p> |
@@ -115,10 +115,14 @@ discard block |
||
115 | 115 | function filter_array($array) { |
116 | 116 | global $snap, $filter, $filter_cat, $breakdown, $breakdown_cat; |
117 | 117 | |
118 | - if (!$filter && !$breakdown) return $array; |
|
118 | + if (!$filter && !$breakdown) { |
|
119 | + return $array; |
|
120 | + } |
|
119 | 121 | $x = array(); |
120 | 122 | foreach ($array as $y) { |
121 | - if (!array_key_exists($y->user_id, $snap->users)) continue; |
|
123 | + if (!array_key_exists($y->user_id, $snap->users)) { |
|
124 | + continue; |
|
125 | + } |
|
122 | 126 | $u = $snap->users[$y->user_id]; |
123 | 127 | if ($filter && $filter->categorize($u) != $filter_cat) { |
124 | 128 | continue; |
@@ -136,7 +140,9 @@ discard block |
||
136 | 140 | function avg_score($array) { |
137 | 141 | $sum = 0; |
138 | 142 | $n = count($array); |
139 | - if ($n ==0) return 0; |
|
143 | + if ($n ==0) { |
|
144 | + return 0; |
|
145 | + } |
|
140 | 146 | foreach ($array as $a) { |
141 | 147 | $sum += $a->score; |
142 | 148 | } |
@@ -152,7 +158,9 @@ discard block |
||
152 | 158 | $n++; |
153 | 159 | } |
154 | 160 | } |
155 | - if ($n ==0) return 0; |
|
161 | + if ($n ==0) { |
|
162 | + return 0; |
|
163 | + } |
|
156 | 164 | return $sum/$n; |
157 | 165 | } |
158 | 166 | |
@@ -180,7 +188,9 @@ discard block |
||
180 | 188 | $a = filter_array($snap->questions[$unit->name]); |
181 | 189 | $n = 0; |
182 | 190 | foreach ($a as $q) { |
183 | - if ($q->mode == $mode) $n++; |
|
191 | + if ($q->mode == $mode) { |
|
192 | + $n++; |
|
193 | + } |
|
184 | 194 | } |
185 | 195 | return $n; |
186 | 196 | } |
@@ -194,7 +204,9 @@ discard block |
||
194 | 204 | if (array_key_exists($unit->name, $snap->views)) { |
195 | 205 | $a = filter_array($snap->views[$unit->name]); |
196 | 206 | foreach ($a as $x) { |
197 | - if ($x->mode == $mode) $y[] = $x; |
|
207 | + if ($x->mode == $mode) { |
|
208 | + $y[] = $x; |
|
209 | + } |
|
198 | 210 | } |
199 | 211 | } |
200 | 212 | return $y; |
@@ -358,7 +370,9 @@ discard block |
||
358 | 370 | |
359 | 371 | function show_unit_recurse($unit, $level) { |
360 | 372 | show_unit($unit, $level); |
361 | - if ($unit->is_item) return; |
|
373 | + if ($unit->is_item) { |
|
374 | + return; |
|
375 | + } |
|
362 | 376 | foreach ($unit->units as $u) { |
363 | 377 | show_unit_recurse($u, $level+1); |
364 | 378 | } |
@@ -431,7 +445,9 @@ discard block |
||
431 | 445 | </tr> |
432 | 446 | "; |
433 | 447 | foreach ($qs as $q) { |
434 | - if ($q->mode != $mode) continue; |
|
448 | + if ($q->mode != $mode) { |
|
449 | + continue; |
|
450 | + } |
|
435 | 451 | $user = $snap->users[$q->user_id]; |
436 | 452 | echo "<tr> |
437 | 453 | <td>".time_str($q->create_time)."</td> |
@@ -446,7 +462,9 @@ discard block |
||
446 | 462 | |
447 | 463 | $course_id = get_int('course_id'); |
448 | 464 | $course = BoltCourse::lookup_id($course_id); |
449 | -if (!$course) error_page("no course"); |
|
465 | +if (!$course) { |
|
466 | + error_page("no course"); |
|
467 | +} |
|
450 | 468 | $top_unit = require_once($course->doc_file()); |
451 | 469 | |
452 | 470 | $action = get_str('action', true); |
@@ -34,6 +34,9 @@ |
||
34 | 34 | require_once($file); |
35 | 35 | } |
36 | 36 | |
37 | +/** |
|
38 | + * @param integer $i |
|
39 | + */ |
|
37 | 40 | function show_bossa_app($app, $i) { |
38 | 41 | $j = $i%2; |
39 | 42 | echo "<tr class=row$j> |
@@ -101,9 +101,9 @@ discard block |
||
101 | 101 | "; |
102 | 102 | start_table(); |
103 | 103 | row1("User settings"); |
104 | - $x = ($flags&BOLT_FLAGS_SHOW_ALL)?"checked":""; |
|
104 | + $x = ($flags&BOLT_FLAGS_SHOW_ALL) ? "checked" : ""; |
|
105 | 105 | row2("Show hidden apps?", "<input type=checkbox name=show_all $x>"); |
106 | - $x = ($flags&BOLT_FLAGS_DEBUG)?"checked":""; |
|
106 | + $x = ($flags&BOLT_FLAGS_DEBUG) ? "checked" : ""; |
|
107 | 107 | row2("Show debugging output?", "<input type=checkbox name=debug $x>"); |
108 | 108 | row2("", "<input class=\"btn btn-default\" type=submit value=\"Update user\">"); |
109 | 109 | end_table(); |
@@ -171,7 +171,7 @@ discard block |
||
171 | 171 | foreach ($jobs as $job) { |
172 | 172 | $t = time_str($job->create_time); |
173 | 173 | $s = job_state_string($job->state); |
174 | - $j = $i++ % 2; |
|
174 | + $j = $i++%2; |
|
175 | 175 | echo "<tr class=row$j> |
176 | 176 | <td> |
177 | 177 | $job->id <a href=bossa_admin.php?action=job_show_insts&job_id=$job->id>(details)</a><br> |
@@ -203,7 +203,7 @@ discard block |
||
203 | 203 | table_row( |
204 | 204 | "$batch->id | <a href=bossa_admin.php?action=show_batch&batch_id=$batch->id>show jobs</a> | <a href=bossa_admin.php?action=clear_batch_confirm&batch_id=$batch->id>delete instances</a>", |
205 | 205 | "$batch->name", |
206 | - $batch->calibration?"yes":"no", |
|
206 | + $batch->calibration ? "yes" : "no", |
|
207 | 207 | time_str($batch->create_time), |
208 | 208 | BossaJob::count("batch_id=$batch->id"), |
209 | 209 | BossaJob::count("batch_id=$batch->id and state=2") |
@@ -333,7 +333,7 @@ discard block |
||
333 | 333 | if (!$time_estimate) $time_estimate = 60; |
334 | 334 | $time_limit = get_str('time_limit'); |
335 | 335 | if (!$time_limit) $time_limit = 3600; |
336 | - $calibration_frac = get_str('calibration_frac' , true); |
|
336 | + $calibration_frac = get_str('calibration_frac', true); |
|
337 | 337 | if (!$calibration_frac) $calibration_frac = 0; |
338 | 338 | $now = time(); |
339 | 339 | $app_id = BossaApp::insert("(create_time, name, short_name, description, bolt_course_id, time_estimate, time_limit, calibration_frac) values ($now, '$name', '$short_name', '$description', $courseid, $time_estimate, $time_limit, $calibration_frac)"); |
@@ -161,7 +161,9 @@ discard block |
||
161 | 161 | |
162 | 162 | function show_batch($batch_id) { |
163 | 163 | $batch = BossaBatch::lookup_id($batch_id); |
164 | - if (!$batch) error_page("No such batch"); |
|
164 | + if (!$batch) { |
|
165 | + error_page("No such batch"); |
|
166 | + } |
|
165 | 167 | include_app_file($batch->app_id); |
166 | 168 | admin_page_head("Jobs for batch $batch->name"); |
167 | 169 | $jobs = BossaJob::enum("batch_id=$batch_id"); |
@@ -293,7 +295,9 @@ discard block |
||
293 | 295 | $user = get_logged_in_user(); |
294 | 296 | |
295 | 297 | $db = BossaDb::get(); |
296 | -if (!$db) error_page("Can't connect to database server"); |
|
298 | +if (!$db) { |
|
299 | + error_page("Can't connect to database server"); |
|
300 | +} |
|
297 | 301 | |
298 | 302 | if (!$db->table_exists('bossa_app')) { |
299 | 303 | admin_page_head("Create Bossa database"); |
@@ -330,11 +334,17 @@ discard block |
||
330 | 334 | $courseid = 0; |
331 | 335 | } |
332 | 336 | $time_estimate = get_str('time_estimate'); |
333 | - if (!$time_estimate) $time_estimate = 60; |
|
337 | + if (!$time_estimate) { |
|
338 | + $time_estimate = 60; |
|
339 | + } |
|
334 | 340 | $time_limit = get_str('time_limit'); |
335 | - if (!$time_limit) $time_limit = 3600; |
|
341 | + if (!$time_limit) { |
|
342 | + $time_limit = 3600; |
|
343 | + } |
|
336 | 344 | $calibration_frac = get_str('calibration_frac' , true); |
337 | - if (!$calibration_frac) $calibration_frac = 0; |
|
345 | + if (!$calibration_frac) { |
|
346 | + $calibration_frac = 0; |
|
347 | + } |
|
338 | 348 | $now = time(); |
339 | 349 | $app_id = BossaApp::insert("(create_time, name, short_name, description, bolt_course_id, time_estimate, time_limit, calibration_frac) values ($now, '$name', '$short_name', '$description', $courseid, $time_estimate, $time_limit, $calibration_frac)"); |
340 | 350 | if ($courseid) { |
@@ -344,8 +354,12 @@ discard block |
||
344 | 354 | exit; |
345 | 355 | case 'update_user': |
346 | 356 | $flags = 0; |
347 | - if (get_str('show_all', true)) $flags |= BOLT_FLAGS_SHOW_ALL; |
|
348 | - if (get_str('debug', true)) $flags |= BOLT_FLAGS_DEBUG; |
|
357 | + if (get_str('show_all', true)) { |
|
358 | + $flags |= BOLT_FLAGS_SHOW_ALL; |
|
359 | + } |
|
360 | + if (get_str('debug', true)) { |
|
361 | + $flags |= BOLT_FLAGS_DEBUG; |
|
362 | + } |
|
349 | 363 | $user->bossa->update("flags=$flags"); |
350 | 364 | $user->bossa->flags = $flags; |
351 | 365 | Header('Location: bossa_admin.php'); |
@@ -368,13 +382,17 @@ discard block |
||
368 | 382 | case 'hide': |
369 | 383 | $app_id = get_int('app_id'); |
370 | 384 | $app = BossaApp::lookup_id($app_id); |
371 | - if (!$app) error_page("no such app"); |
|
385 | + if (!$app) { |
|
386 | + error_page("no such app"); |
|
387 | + } |
|
372 | 388 | $app->update("hidden=1"); |
373 | 389 | break; |
374 | 390 | case 'unhide': |
375 | 391 | $app_id = get_int('app_id'); |
376 | 392 | $app = BossaApp::lookup_id($app_id); |
377 | - if (!$app) error_page("no such app"); |
|
393 | + if (!$app) { |
|
394 | + error_page("no such app"); |
|
395 | + } |
|
378 | 396 | $app->update("hidden=0"); |
379 | 397 | break; |
380 | 398 | case 'clear_batch_confirm': |