@@ -208,6 +208,9 @@ discard block |
||
208 | 208 | // (to accommodate long [pre] lines) |
209 | 209 | // and the left column (author info) has fixed size |
210 | 210 | // |
211 | +/** |
|
212 | + * @param string[] $headings |
|
213 | + */ |
|
211 | 214 | function start_forum_table($headings) { |
212 | 215 | $a = array(); |
213 | 216 | foreach ($headings as $h) { |
@@ -488,6 +491,9 @@ discard block |
||
488 | 491 | // Display an individual post. |
489 | 492 | // Generates a table row with two cells: author and message |
490 | 493 | // |
494 | +/** |
|
495 | + * @param integer $controls |
|
496 | + */ |
|
491 | 497 | function show_post( |
492 | 498 | $post, $thread, $forum, $logged_in_user, $latest_viewed, |
493 | 499 | $controls=FORUM_CONTROLS, $filter=true |
@@ -852,6 +858,9 @@ discard block |
||
852 | 858 | // These take care of counts and timestamps. |
853 | 859 | // Don't do these things directly - use these functions |
854 | 860 | // |
861 | +/** |
|
862 | + * @param integer $parent_id |
|
863 | + */ |
|
855 | 864 | function create_post($content, $parent_id, $user, $forum, $thread, $signature) { |
856 | 865 | $content = substr($content, 0, 64000); |
857 | 866 | $content = BoincDb::escape_string($content); |
@@ -1084,6 +1093,9 @@ discard block |
||
1084 | 1093 | // $sort_style - string (checked by switch statement) |
1085 | 1094 | // $show_hidden - bool (not directly passed to SQL) |
1086 | 1095 | // |
1096 | +/** |
|
1097 | + * @param boolean $show_hidden |
|
1098 | + */ |
|
1087 | 1099 | function get_thread_posts($threadid, $sort_style, $show_hidden) { |
1088 | 1100 | $sql = "thread=$threadid"; |
1089 | 1101 | if (!$show_hidden) { |
@@ -1109,6 +1121,9 @@ discard block |
||
1109 | 1121 | // Show links for post moderation actions; |
1110 | 1122 | // logged in user has moderation rights. |
1111 | 1123 | // |
1124 | +/** |
|
1125 | + * @param string $config |
|
1126 | + */ |
|
1112 | 1127 | function show_post_moderation_links( |
1113 | 1128 | $config, $logged_in_user, $post, $forum, $tokens |
1114 | 1129 | ){ |
@@ -780,9 +780,9 @@ discard block |
||
780 | 780 | |
781 | 781 | function post_rules() { |
782 | 782 | if (function_exists("project_forum_post_rules")) { |
783 | - $project_rules=project_forum_post_rules(); |
|
783 | + $project_rules=project_forum_post_rules(); |
|
784 | 784 | } else { |
785 | - $project_rules=""; |
|
785 | + $project_rules=""; |
|
786 | 786 | } |
787 | 787 | return tra(" |
788 | 788 | <ul> |
@@ -1218,7 +1218,7 @@ discard block |
||
1218 | 1218 | } |
1219 | 1219 | if ($thread->hidden) { |
1220 | 1220 | error_page( |
1221 | - tra("Can't post to a hidden thread.") |
|
1221 | + tra("Can't post to a hidden thread.") |
|
1222 | 1222 | ); |
1223 | 1223 | } |
1224 | 1224 |
@@ -50,12 +50,12 @@ discard block |
||
50 | 50 | define('THREAD_SOLVED', 1); |
51 | 51 | |
52 | 52 | define('AVATAR_WIDTH', 100); |
53 | -define('AVATAR_HEIGHT',100); |
|
53 | +define('AVATAR_HEIGHT', 100); |
|
54 | 54 | |
55 | 55 | define('ST_NEW_TIME', 1209600); //3600*24*14 - 14 days |
56 | 56 | define('ST_NEW', 'New member'); |
57 | 57 | |
58 | -define('MAXIMUM_EDIT_TIME',3600); |
|
58 | +define('MAXIMUM_EDIT_TIME', 3600); |
|
59 | 59 | // allow edits of forums posts up till one hour after posting. |
60 | 60 | |
61 | 61 | define('MAX_FORUM_LOGGING_TIME', 2419200); //3600*24*28 - 28 days |
@@ -73,24 +73,24 @@ discard block |
||
73 | 73 | define('IMAGE_HIDDEN', 'img/hidden.png'); |
74 | 74 | define('IMAGE_STICKY_LOCKED', 'img/sticky_locked_post.png'); |
75 | 75 | define('IMAGE_POST', 'img/post.png'); |
76 | -define('NEW_IMAGE_HEIGHT','15'); |
|
76 | +define('NEW_IMAGE_HEIGHT', '15'); |
|
77 | 77 | define('EMPHASIZE_IMAGE', 'img/emphasized_post.png'); |
78 | -define('EMPHASIZE_IMAGE_HEIGHT','15'); |
|
78 | +define('EMPHASIZE_IMAGE_HEIGHT', '15'); |
|
79 | 79 | define('FILTER_IMAGE', 'img/filtered_post.png'); |
80 | -define('FILTER_IMAGE_HEIGHT','15'); |
|
80 | +define('FILTER_IMAGE_HEIGHT', '15'); |
|
81 | 81 | define('RATE_POSITIVE_IMAGE', 'img/rate_positive.png'); |
82 | -define('RATE_POSITIVE_IMAGE_HEIGHT','9'); |
|
82 | +define('RATE_POSITIVE_IMAGE_HEIGHT', '9'); |
|
83 | 83 | define('RATE_NEGATIVE_IMAGE', 'img/rate_negative.png'); |
84 | -define('RATE_NEGATIVE_IMAGE_HEIGHT','9'); |
|
84 | +define('RATE_NEGATIVE_IMAGE_HEIGHT', '9'); |
|
85 | 85 | define('REPORT_POST_IMAGE', 'img/report_post.png'); |
86 | -define('REPORT_POST_IMAGE_HEIGHT','9'); |
|
86 | +define('REPORT_POST_IMAGE_HEIGHT', '9'); |
|
87 | 87 | |
88 | -define ('SOLUTION', 'This answered my question'); |
|
89 | -define ('SUFFERER', 'I also have this question'); |
|
90 | -define ('OFF_TOPIC', 'Off-topic'); |
|
88 | +define('SOLUTION', 'This answered my question'); |
|
89 | +define('SUFFERER', 'I also have this question'); |
|
90 | +define('OFF_TOPIC', 'Off-topic'); |
|
91 | 91 | |
92 | -define ('DEFAULT_LOW_RATING_THRESHOLD', -25); |
|
93 | -define ('DEFAULT_HIGH_RATING_THRESHOLD', 5); |
|
92 | +define('DEFAULT_LOW_RATING_THRESHOLD', -25); |
|
93 | +define('DEFAULT_HIGH_RATING_THRESHOLD', 5); |
|
94 | 94 | |
95 | 95 | // A list of what kind of special users exist |
96 | 96 | define('S_MODERATOR', 0); |
@@ -148,15 +148,15 @@ discard block |
||
148 | 148 | |
149 | 149 | // Output the forum/thread title. |
150 | 150 | // |
151 | -function show_forum_title($category, $forum, $thread, $link_thread=false) { |
|
151 | +function show_forum_title($category, $forum, $thread, $link_thread = false) { |
|
152 | 152 | if ($category) { |
153 | 153 | $is_helpdesk = $category->is_helpdesk; |
154 | 154 | } else { |
155 | 155 | $is_helpdesk = false; |
156 | 156 | } |
157 | 157 | |
158 | - $where = $is_helpdesk?tra("Questions and Answers"):tra("Message boards"); |
|
159 | - $top_url = $is_helpdesk?"forum_help_desk.php":"forum_index.php"; |
|
158 | + $where = $is_helpdesk ? tra("Questions and Answers") : tra("Message boards"); |
|
159 | + $top_url = $is_helpdesk ? "forum_help_desk.php" : "forum_index.php"; |
|
160 | 160 | |
161 | 161 | if (!$forum && !$thread) { |
162 | 162 | echo "<span class=\"title\">$where</span>\n"; |
@@ -184,7 +184,7 @@ discard block |
||
184 | 184 | } |
185 | 185 | } |
186 | 186 | |
187 | -function show_team_forum_title($forum, $thread=null, $link_thread=false) { |
|
187 | +function show_team_forum_title($forum, $thread = null, $link_thread = false) { |
|
188 | 188 | $team = BoincTeam::lookup_id($forum->category); |
189 | 189 | echo "<span class=title> |
190 | 190 | <a href=\"forum_index.php\">".tra("Message boards")."</a> : |
@@ -219,12 +219,12 @@ discard block |
||
219 | 219 | } |
220 | 220 | |
221 | 221 | function page_link($url, $page_num, $items_per_page, $text) { |
222 | - return " <a href=\"$url&start=" . $page_num*$items_per_page . "\">$text</a> "; |
|
222 | + return " <a href=\"$url&start=".$page_num*$items_per_page."\">$text</a> "; |
|
223 | 223 | } |
224 | 224 | |
225 | 225 | // return a string for navigating pages |
226 | 226 | // |
227 | -function page_links($url, $nitems, $items_per_page, $start){ |
|
227 | +function page_links($url, $nitems, $items_per_page, $start) { |
|
228 | 228 | // How many pages to potentially show before and after this one: |
229 | 229 | $preshow = 3; |
230 | 230 | $postshow = 3; |
@@ -232,14 +232,14 @@ discard block |
||
232 | 232 | $x = ""; |
233 | 233 | |
234 | 234 | if ($nitems <= $items_per_page) return ""; |
235 | - $npages = ceil($nitems / $items_per_page); |
|
236 | - $curpage = ceil($start / $items_per_page); |
|
235 | + $npages = ceil($nitems/$items_per_page); |
|
236 | + $curpage = ceil($start/$items_per_page); |
|
237 | 237 | |
238 | 238 | // If this is not the first page, display "previous" |
239 | 239 | // |
240 | - if ($curpage > 0){ |
|
240 | + if ($curpage > 0) { |
|
241 | 241 | $x .= page_link( |
242 | - $url, $curpage-1, $items_per_page, |
|
242 | + $url, $curpage - 1, $items_per_page, |
|
243 | 243 | tra("Previous")." · " |
244 | 244 | ); |
245 | 245 | } |
@@ -254,8 +254,8 @@ discard block |
||
254 | 254 | } |
255 | 255 | // Display a list of pages surrounding this one |
256 | 256 | // |
257 | - for ($i=$curpage-$preshow; $i<=$curpage+$postshow; $i++){ |
|
258 | - $page_str = (string)($i+1); |
|
257 | + for ($i = $curpage - $preshow; $i <= $curpage + $postshow; $i++) { |
|
258 | + $page_str = (string)($i + 1); |
|
259 | 259 | if ($i < 0) continue; |
260 | 260 | if ($i >= $npages) break; |
261 | 261 | |
@@ -264,20 +264,20 @@ discard block |
||
264 | 264 | } else { |
265 | 265 | $x .= page_link($url, $i, $items_per_page, $page_str); |
266 | 266 | } |
267 | - if ($i == $npages-1) break; |
|
268 | - if ($i == $curpage+$postshow) break; |
|
267 | + if ($i == $npages - 1) break; |
|
268 | + if ($i == $curpage + $postshow) break; |
|
269 | 269 | $x .= " · "; |
270 | 270 | } |
271 | 271 | |
272 | - if ($curpage + $postshow < $npages-1) { |
|
272 | + if ($curpage + $postshow < $npages - 1) { |
|
273 | 273 | $x .= " . . . "; |
274 | - $x .= page_link($url, $npages-1, $items_per_page, $npages); |
|
274 | + $x .= page_link($url, $npages - 1, $items_per_page, $npages); |
|
275 | 275 | } |
276 | 276 | // If there is a next page |
277 | 277 | // |
278 | - if ($curpage < $npages-1){ |
|
278 | + if ($curpage < $npages - 1) { |
|
279 | 279 | $x .= page_link( |
280 | - $url, $curpage+1, $items_per_page, |
|
280 | + $url, $curpage + 1, $items_per_page, |
|
281 | 281 | " · ".tra("Next") |
282 | 282 | ); |
283 | 283 | } |
@@ -298,7 +298,7 @@ discard block |
||
298 | 298 | function cleanup_title($title) { |
299 | 299 | $x = sanitize_tags(bb2html($title)); |
300 | 300 | $x = trim($x); |
301 | - if (strlen($x)==0) return "(no title)"; |
|
301 | + if (strlen($x) == 0) return "(no title)"; |
|
302 | 302 | else return $x; |
303 | 303 | } |
304 | 304 | |
@@ -360,7 +360,7 @@ discard block |
||
360 | 360 | $i = 0; |
361 | 361 | foreach ($posts as $post) { |
362 | 362 | if ($post->id == $postid) { |
363 | - $start = $i - ($i % $num_to_show); |
|
363 | + $start = $i - ($i%$num_to_show); |
|
364 | 364 | $jump_to_post = $post; |
365 | 365 | break; |
366 | 366 | } |
@@ -387,7 +387,7 @@ discard block |
||
387 | 387 | // if jump to post, figure out what page to show |
388 | 388 | // |
389 | 389 | if ($jump_to_post) { |
390 | - $start = $ibest - ($ibest % $num_to_show); |
|
390 | + $start = $ibest - ($ibest%$num_to_show); |
|
391 | 391 | } else { |
392 | 392 | $start = $default_start; |
393 | 393 | } |
@@ -490,7 +490,7 @@ discard block |
||
490 | 490 | // |
491 | 491 | function show_post( |
492 | 492 | $post, $thread, $forum, $logged_in_user, $latest_viewed, |
493 | - $controls=FORUM_CONTROLS, $filter=true |
|
493 | + $controls = FORUM_CONTROLS, $filter = true |
|
494 | 494 | ) { |
495 | 495 | global $country_to_iso3166_2; |
496 | 496 | |
@@ -502,7 +502,7 @@ discard block |
||
502 | 502 | |
503 | 503 | // If the user no longer exists, skip the post |
504 | 504 | // |
505 | - if (!$user){ |
|
505 | + if (!$user) { |
|
506 | 506 | return; |
507 | 507 | } |
508 | 508 | |
@@ -518,9 +518,9 @@ discard block |
||
518 | 518 | // check whether the poster is on the list of people to ignore |
519 | 519 | // |
520 | 520 | $ignore_poster = false; |
521 | - if ($logged_in_user){ |
|
521 | + if ($logged_in_user) { |
|
522 | 522 | $tokens = url_tokens($logged_in_user->authenticator); |
523 | - if (is_ignoring($logged_in_user, $user)){ |
|
523 | + if (is_ignoring($logged_in_user, $user)) { |
|
524 | 524 | $ignore_poster = true; |
525 | 525 | } |
526 | 526 | } |
@@ -534,8 +534,8 @@ discard block |
||
534 | 534 | if (is_moderator($logged_in_user, $forum)) { |
535 | 535 | $can_edit = true; |
536 | 536 | } else if (can_reply($thread, $forum, $logged_in_user)) { |
537 | - $time_limit = $post->timestamp+MAXIMUM_EDIT_TIME; |
|
538 | - $can_edit = time()<$time_limit; |
|
537 | + $time_limit = $post->timestamp + MAXIMUM_EDIT_TIME; |
|
538 | + $can_edit = time() < $time_limit; |
|
539 | 539 | } else { |
540 | 540 | $can_edit = false; |
541 | 541 | } |
@@ -545,24 +545,24 @@ discard block |
||
545 | 545 | // Print the special user lines, if any |
546 | 546 | // |
547 | 547 | global $special_user_bitfield; |
548 | - $fstatus=""; |
|
548 | + $fstatus = ""; |
|
549 | 549 | $keys = array_keys($special_user_bitfield); |
550 | 550 | $is_posted_by_special = false; |
551 | - for ($i=0; $i<sizeof($special_user_bitfield);$i++) { |
|
551 | + for ($i = 0; $i < sizeof($special_user_bitfield); $i++) { |
|
552 | 552 | if ($user->prefs && $user->prefs->privilege($keys[$i])) { |
553 | - $fstatus.=$special_user_bitfield[$keys[$i]]."<br>"; |
|
553 | + $fstatus .= $special_user_bitfield[$keys[$i]]."<br>"; |
|
554 | 554 | $is_posted_by_special = true; |
555 | 555 | } |
556 | 556 | } |
557 | 557 | |
558 | 558 | // Highlight special users if set in prefs; |
559 | 559 | // |
560 | - if ($logged_in_user && $logged_in_user->prefs){ |
|
560 | + if ($logged_in_user && $logged_in_user->prefs) { |
|
561 | 561 | $highlight = $logged_in_user->prefs->highlight_special && $is_posted_by_special; |
562 | 562 | } else { |
563 | 563 | $highlight = $is_posted_by_special; |
564 | 564 | } |
565 | - $class = $highlight?' style="border-left: 5px solid LightGreen" ':''; |
|
565 | + $class = $highlight ? ' style="border-left: 5px solid LightGreen" ' : ''; |
|
566 | 566 | |
567 | 567 | // row and start of author col |
568 | 568 | // |
@@ -574,12 +574,12 @@ discard block |
||
574 | 574 | |
575 | 575 | echo user_links($user, 0); |
576 | 576 | echo "<br>"; |
577 | - if ($user->create_time > time()-ST_NEW_TIME) $fstatus.=ST_NEW."<br>"; |
|
577 | + if ($user->create_time > time() - ST_NEW_TIME) $fstatus .= ST_NEW."<br>"; |
|
578 | 578 | echo "<span class=\"small\">"; |
579 | 579 | if ($fstatus) echo "$fstatus"; |
580 | 580 | |
581 | - if (!$filter || !$ignore_poster){ |
|
582 | - if ($user->prefs && $user->prefs->avatar!="" && (!$logged_in_user || ($logged_in_user->prefs->hide_avatars==false))) { |
|
581 | + if (!$filter || !$ignore_poster) { |
|
582 | + if ($user->prefs && $user->prefs->avatar != "" && (!$logged_in_user || ($logged_in_user->prefs->hide_avatars == false))) { |
|
583 | 583 | echo "<img width=\"".AVATAR_WIDTH."\" height=\"".AVATAR_HEIGHT."\" src=\"".avatar_url($user->prefs->avatar)."\" alt=\"Avatar\"><br>"; |
584 | 584 | } |
585 | 585 | } |
@@ -587,14 +587,14 @@ discard block |
||
587 | 587 | |
588 | 588 | $url = "pm.php?action=new&userid=".$user->id; |
589 | 589 | $name = $user->name; |
590 | - show_button($url, tra("Send message"), tra("Send %1 a private message",$name)); |
|
590 | + show_button($url, tra("Send message"), tra("Send %1 a private message", $name)); |
|
591 | 591 | echo '<br>'.tra("Joined: %1", gmdate('j M y', $user->create_time)), "<br>"; |
592 | 592 | |
593 | 593 | if (!isset($user->nposts)) { |
594 | 594 | $user->nposts = BoincPost::count("user=$user->id"); |
595 | 595 | } |
596 | 596 | |
597 | - if (function_exists('project_forum_user_info')){ |
|
597 | + if (function_exists('project_forum_user_info')) { |
|
598 | 598 | project_forum_user_info($user); |
599 | 599 | } else { |
600 | 600 | echo tra("Posts: %1", $user->nposts)."<br>"; |
@@ -603,8 +603,8 @@ discard block |
||
603 | 603 | // |
604 | 604 | //echo "ID: ".$user->id."<br>"; |
605 | 605 | if (!no_computing()) { |
606 | - echo tra("Credit: %1", number_format($user->total_credit)) ."<br>"; |
|
607 | - echo tra("RAC: %1", number_format($user->expavg_credit))."<br>"; |
|
606 | + echo tra("Credit: %1", number_format($user->total_credit))."<br>"; |
|
607 | + echo tra("RAC: %1", number_format($user->expavg_credit))."<br>"; |
|
608 | 608 | } |
609 | 609 | |
610 | 610 | // to use this feature: |
@@ -633,7 +633,7 @@ discard block |
||
633 | 633 | echo "<form action=\"forum_rate.php?post=", $post->id, "\" method=\"post\">"; |
634 | 634 | } |
635 | 635 | |
636 | - if ($logged_in_user && $post->timestamp>$latest_viewed){ |
|
636 | + if ($logged_in_user && $post->timestamp > $latest_viewed) { |
|
637 | 637 | show_image(NEW_IMAGE, tra("You haven't read this message yet"), tra("Unread"), NEW_IMAGE_HEIGHT); |
638 | 638 | } |
639 | 639 | |
@@ -653,8 +653,8 @@ discard block |
||
653 | 653 | if ($post->modified) { |
654 | 654 | echo "<br>".tra("Last modified: %1", pretty_time_Str($post->modified)); |
655 | 655 | } |
656 | - if ($ignore_poster && $filter){ |
|
657 | - echo "<br>".tra("This post is not shown because the sender is on your 'ignore' list. Click %1here%2 to view this post","<a href=\"?id=".$thread->id."&filter=false#".$post->id."\">","</a>"); |
|
656 | + if ($ignore_poster && $filter) { |
|
657 | + echo "<br>".tra("This post is not shown because the sender is on your 'ignore' list. Click %1here%2 to view this post", "<a href=\"?id=".$thread->id."&filter=false#".$post->id."\">", "</a>"); |
|
658 | 658 | } |
659 | 659 | if ($controls == FORUM_CONTROLS) { |
660 | 660 | echo "</form>\n"; |
@@ -663,7 +663,7 @@ discard block |
||
663 | 663 | <p> |
664 | 664 | "; |
665 | 665 | |
666 | - if (!$filter || !$ignore_poster){ |
|
666 | + if (!$filter || !$ignore_poster) { |
|
667 | 667 | $posttext = $post->content; |
668 | 668 | |
669 | 669 | // If the creator of this post has a signature and |
@@ -671,7 +671,7 @@ discard block |
||
671 | 671 | // user has signatures enabled: show it |
672 | 672 | // |
673 | 673 | $posttext = output_transform($posttext, $options); |
674 | - if ($post->signature && (!$logged_in_user || !$logged_in_user->prefs->hide_signatures)){ |
|
674 | + if ($post->signature && (!$logged_in_user || !$logged_in_user->prefs->hide_signatures)) { |
|
675 | 675 | $sig = output_transform($user->prefs->signature, $options); |
676 | 676 | $posttext .= "<hr>$sig\n"; |
677 | 677 | } |
@@ -705,10 +705,10 @@ discard block |
||
705 | 705 | } |
706 | 706 | if (($controls == FORUM_CONTROLS) && (can_reply($thread, $forum, $logged_in_user))) { |
707 | 707 | echo " "; |
708 | - $url = "forum_reply.php?thread=" . $thread->id . "&post=" . $post->id . "&no_quote=1#input"; |
|
708 | + $url = "forum_reply.php?thread=".$thread->id."&post=".$post->id."&no_quote=1#input"; |
|
709 | 709 | // "Reply" is used as a verb |
710 | 710 | show_button($url, tra("Reply"), tra("Post a reply to this message")); |
711 | - $url = "forum_reply.php?thread=" . $thread->id . "&post=" . $post->id . "#input"; |
|
711 | + $url = "forum_reply.php?thread=".$thread->id."&post=".$post->id."#input"; |
|
712 | 712 | // "Quote" is used as a verb |
713 | 713 | show_button($url, tra("Quote"), tra("Post a reply by quoting this message")); |
714 | 714 | } |
@@ -780,9 +780,9 @@ discard block |
||
780 | 780 | |
781 | 781 | function post_rules() { |
782 | 782 | if (function_exists("project_forum_post_rules")) { |
783 | - $project_rules=project_forum_post_rules(); |
|
783 | + $project_rules = project_forum_post_rules(); |
|
784 | 784 | } else { |
785 | - $project_rules=""; |
|
785 | + $project_rules = ""; |
|
786 | 786 | } |
787 | 787 | return tra(" |
788 | 788 | <ul> |
@@ -803,7 +803,7 @@ discard block |
||
803 | 803 | "; |
804 | 804 | } |
805 | 805 | |
806 | -function post_warning($forum=null) { |
|
806 | +function post_warning($forum = null) { |
|
807 | 807 | $x = "<br><br> |
808 | 808 | <table><tr><td align=left> |
809 | 809 | "; |
@@ -856,7 +856,7 @@ discard block |
||
856 | 856 | $content = substr($content, 0, 64000); |
857 | 857 | $content = BoincDb::escape_string($content); |
858 | 858 | $now = time(); |
859 | - $sig = $signature?1:0; |
|
859 | + $sig = $signature ? 1 : 0; |
|
860 | 860 | $id = BoincPost::insert("(thread, user, timestamp, content, modified, parent_post, score, votes, signature, hidden) values ($thread->id, $user->id, $now, '$content', 0, $parent_id, 0, 0, $sig, 0)"); |
861 | 861 | if (!$id) return null; |
862 | 862 | |
@@ -873,7 +873,7 @@ discard block |
||
873 | 873 | // |
874 | 874 | function update_thread_timestamp($thread) { |
875 | 875 | $posts = BoincPost::enum("thread=$thread->id and hidden=0 order by timestamp desc limit 1"); |
876 | - if (count($posts)>0) { |
|
876 | + if (count($posts) > 0) { |
|
877 | 877 | $post = $posts[0]; |
878 | 878 | $thread->update("timestamp=$post->timestamp"); |
879 | 879 | } |
@@ -881,7 +881,7 @@ discard block |
||
881 | 881 | |
882 | 882 | function update_forum_timestamp($forum) { |
883 | 883 | $threads = BoincThread::enum("forum=$forum->id and hidden=0 order by timestamp desc limit 1"); |
884 | - if (count($threads)>0) { |
|
884 | + if (count($threads) > 0) { |
|
885 | 885 | $thread = $threads[0]; |
886 | 886 | $forum->update("timestamp=$thread->timestamp"); |
887 | 887 | } |
@@ -896,7 +896,7 @@ discard block |
||
896 | 896 | if (is_news_forum($forum) && !$export) { |
897 | 897 | $status = 1; |
898 | 898 | } |
899 | - $id = BoincThread::insert("(forum, owner, status, title, timestamp, views, replies, activity, sufferers, score, votes, create_time, hidden, sticky, locked) values ($forum->id, $user->id, $status, '$title', $now, 0, -1, 0, 0, 0, 0, $now, 0, 0, 0)"); |
|
899 | + $id = BoincThread::insert("(forum, owner, status, title, timestamp, views, replies, activity, sufferers, score, votes, create_time, hidden, sticky, locked) values ($forum->id, $user->id, $status, '$title', $now, 0, -1, 0, 0, 0, 0, $now, 0, 0, 0)"); |
|
900 | 900 | if (!$id) return null; |
901 | 901 | $thread = BoincThread::lookup_id($id); |
902 | 902 | create_post($content, 0, $user, $forum, $thread, $signature); |
@@ -1021,22 +1021,22 @@ discard block |
||
1021 | 1021 | // $sticky - bool (not directly passed to SQL) |
1022 | 1022 | // |
1023 | 1023 | function get_forum_threads( |
1024 | - $forumID, $start=-1, $nRec=-1, $sort_style=MODIFIED_NEW, |
|
1024 | + $forumID, $start = -1, $nRec = -1, $sort_style = MODIFIED_NEW, |
|
1025 | 1025 | $show_hidden = 0, $sticky = 1 |
1026 | 1026 | ) { |
1027 | 1027 | //if (! (is_numeric($forumID) && is_numeric($min) && is_numeric($nRec))) { |
1028 | 1028 | // return NULL; // Something is wrong here. |
1029 | 1029 | //} |
1030 | 1030 | |
1031 | - $sql = 'forum = ' . $forumID ; |
|
1031 | + $sql = 'forum = '.$forumID; |
|
1032 | 1032 | $stickysql = ""; |
1033 | - if ($sticky){ |
|
1033 | + if ($sticky) { |
|
1034 | 1034 | $stickysql = "sticky DESC, "; |
1035 | 1035 | } |
1036 | 1036 | if (!$show_hidden) { |
1037 | 1037 | $sql .= ' AND hidden = 0'; |
1038 | 1038 | } |
1039 | - switch($sort_style) { |
|
1039 | + switch ($sort_style) { |
|
1040 | 1040 | case MODIFIED_NEW: |
1041 | 1041 | $sql .= ' ORDER BY '.$stickysql.'timestamp DESC'; |
1042 | 1042 | break; |
@@ -1089,7 +1089,7 @@ discard block |
||
1089 | 1089 | if (!$show_hidden) { |
1090 | 1090 | $sql .= ' AND hidden = 0'; |
1091 | 1091 | } |
1092 | - switch($sort_style) { |
|
1092 | + switch ($sort_style) { |
|
1093 | 1093 | case CREATE_TIME_NEW: |
1094 | 1094 | $sql .= ' ORDER BY timestamp desc'; |
1095 | 1095 | break; |
@@ -1111,7 +1111,7 @@ discard block |
||
1111 | 1111 | // |
1112 | 1112 | function show_post_moderation_links( |
1113 | 1113 | $config, $logged_in_user, $post, $forum, $tokens |
1114 | -){ |
|
1114 | +) { |
|
1115 | 1115 | $moderators_allowed_to_ban = parse_bool($config, "moderators_allowed_to_ban"); |
1116 | 1116 | $moderators_vote_to_ban = parse_bool($config, "moderators_vote_to_ban"); |
1117 | 1117 | |
@@ -1198,14 +1198,14 @@ discard block |
||
1198 | 1198 | // We do not tell the (ab)user how much this is - |
1199 | 1199 | // no need to make it easy for them to break the system. |
1200 | 1200 | // |
1201 | - if ($user->total_credit<$forum->post_min_total_credit || $user->expavg_credit<$forum->post_min_expavg_credit) { |
|
1201 | + if ($user->total_credit < $forum->post_min_total_credit || $user->expavg_credit < $forum->post_min_expavg_credit) { |
|
1202 | 1202 | error_page(tra("To create a new thread in %1 you must have a certain level of average credit. This is to protect against abuse of the system.", $forum->title)); |
1203 | 1203 | } |
1204 | 1204 | |
1205 | 1205 | // If the user is posting faster than forum regulations allow |
1206 | 1206 | // Tell the user to wait a while before creating any more posts |
1207 | 1207 | // |
1208 | - if (time()-$user->prefs->last_post <$forum->post_min_interval) { |
|
1208 | + if (time() - $user->prefs->last_post < $forum->post_min_interval) { |
|
1209 | 1209 | error_page(tra("You cannot create threads right now. Please wait before trying again. This is to protect against abuse of the system.")); |
1210 | 1210 | } |
1211 | 1211 | } |
@@ -1233,7 +1233,7 @@ discard block |
||
1233 | 1233 | |
1234 | 1234 | function is_moderator($user, $forum) { |
1235 | 1235 | if (!$user) return false; |
1236 | - $type = $forum?$forum->parent_type:0; |
|
1236 | + $type = $forum ? $forum->parent_type : 0; |
|
1237 | 1237 | switch ($type) { |
1238 | 1238 | case 0: |
1239 | 1239 | if ($user->prefs->privilege(S_MODERATOR)) return true; |
@@ -1270,7 +1270,7 @@ discard block |
||
1270 | 1270 | if (!is_forum_visible_to_user($thread_forum, $user)) return; |
1271 | 1271 | $owner = BoincUser::lookup_id($thread->owner); |
1272 | 1272 | echo "<tr><td>\n"; |
1273 | - switch($thread_forum->parent_type) { |
|
1273 | + switch ($thread_forum->parent_type) { |
|
1274 | 1274 | case 0: |
1275 | 1275 | $category = BoincCategory::lookup_id($thread_forum->category); |
1276 | 1276 | show_forum_title($category, $thread_forum, $thread, true); |
@@ -1280,7 +1280,7 @@ discard block |
||
1280 | 1280 | break; |
1281 | 1281 | } |
1282 | 1282 | echo ' |
1283 | - </td><td class="numbers">'.($thread->replies+1).'</td> |
|
1283 | + </td><td class="numbers">'.($thread->replies + 1).'</td> |
|
1284 | 1284 | <td>'.user_links($owner).'</td> |
1285 | 1285 | <td class="numbers">'.$thread->views.'</td> |
1286 | 1286 | <td class="lastpost">'.time_diff_str($thread->timestamp, time()).'</td> |
@@ -1314,13 +1314,13 @@ discard block |
||
1314 | 1314 | |
1315 | 1315 | function subscribed_post_web_line($notify) { |
1316 | 1316 | $thread = BoincThread::lookup_id($notify->opaque); |
1317 | - return tra("New posts in the thread %1","<a href=forum_thread.php?id=$thread->id>$thread->title</a>"); |
|
1317 | + return tra("New posts in the thread %1", "<a href=forum_thread.php?id=$thread->id>$thread->title</a>"); |
|
1318 | 1318 | } |
1319 | 1319 | |
1320 | 1320 | function subscribe_rss($notify, &$title, &$msg, &$url) { |
1321 | 1321 | $thread = BoincThread::lookup_id($notify->opaque); |
1322 | 1322 | $title = tra("New posts in subscribed thread"); |
1323 | - $msg = tra("There are new posts in the thread '%1'",$thread->title); |
|
1323 | + $msg = tra("There are new posts in the thread '%1'", $thread->title); |
|
1324 | 1324 | $url = secure_url_base()."forum_thread.php?id=$thread->id"; |
1325 | 1325 | } |
1326 | 1326 |
@@ -231,7 +231,9 @@ discard block |
||
231 | 231 | |
232 | 232 | $x = ""; |
233 | 233 | |
234 | - if ($nitems <= $items_per_page) return ""; |
|
234 | + if ($nitems <= $items_per_page) { |
|
235 | + return ""; |
|
236 | + } |
|
235 | 237 | $npages = ceil($nitems / $items_per_page); |
236 | 238 | $curpage = ceil($start / $items_per_page); |
237 | 239 | |
@@ -256,16 +258,24 @@ discard block |
||
256 | 258 | // |
257 | 259 | for ($i=$curpage-$preshow; $i<=$curpage+$postshow; $i++){ |
258 | 260 | $page_str = (string)($i+1); |
259 | - if ($i < 0) continue; |
|
260 | - if ($i >= $npages) break; |
|
261 | + if ($i < 0) { |
|
262 | + continue; |
|
263 | + } |
|
264 | + if ($i >= $npages) { |
|
265 | + break; |
|
266 | + } |
|
261 | 267 | |
262 | 268 | if ($i == $curpage) { |
263 | 269 | $x .= "<b>$page_str</b>"; |
264 | 270 | } else { |
265 | 271 | $x .= page_link($url, $i, $items_per_page, $page_str); |
266 | 272 | } |
267 | - if ($i == $npages-1) break; |
|
268 | - if ($i == $curpage+$postshow) break; |
|
273 | + if ($i == $npages-1) { |
|
274 | + break; |
|
275 | + } |
|
276 | + if ($i == $curpage+$postshow) { |
|
277 | + break; |
|
278 | + } |
|
269 | 279 | $x .= " · "; |
270 | 280 | } |
271 | 281 | |
@@ -286,10 +296,16 @@ discard block |
||
286 | 296 | } |
287 | 297 | |
288 | 298 | function thread_is_unread($user, $thread) { |
289 | - if (!$user) return false; |
|
290 | - if ($thread->timestamp <= $user->prefs->mark_as_read_timestamp) return false; |
|
299 | + if (!$user) { |
|
300 | + return false; |
|
301 | + } |
|
302 | + if ($thread->timestamp <= $user->prefs->mark_as_read_timestamp) { |
|
303 | + return false; |
|
304 | + } |
|
291 | 305 | $log = BoincForumLogging::lookup($user->id, $thread->id); |
292 | - if ($log && ($thread->timestamp <= $log->timestamp)) return false; |
|
306 | + if ($log && ($thread->timestamp <= $log->timestamp)) { |
|
307 | + return false; |
|
308 | + } |
|
293 | 309 | return true; |
294 | 310 | } |
295 | 311 | |
@@ -298,13 +314,18 @@ discard block |
||
298 | 314 | function cleanup_title($title) { |
299 | 315 | $x = sanitize_tags(bb2html($title)); |
300 | 316 | $x = trim($x); |
301 | - if (strlen($x)==0) return "(no title)"; |
|
302 | - else return $x; |
|
303 | -} |
|
317 | + if (strlen($x)==0) { |
|
318 | + return "(no title)"; |
|
319 | + } else { |
|
320 | + return $x; |
|
321 | + } |
|
322 | + } |
|
304 | 323 | |
305 | 324 | function can_reply($thread, $forum, $user) { |
306 | 325 | if ($thread->locked) { |
307 | - if (!is_moderator($user, $forum)) return false; |
|
326 | + if (!is_moderator($user, $forum)) { |
|
327 | + return false; |
|
328 | + } |
|
308 | 329 | } |
309 | 330 | return true; |
310 | 331 | } |
@@ -343,7 +364,9 @@ discard block |
||
343 | 364 | // show the last page |
344 | 365 | // |
345 | 366 | $nposts = sizeof($posts); |
346 | - if ($nposts) $nposts -= 1; |
|
367 | + if ($nposts) { |
|
368 | + $nposts -= 1; |
|
369 | + } |
|
347 | 370 | $page = (int)($nposts/$num_to_show); |
348 | 371 | $default_start = $page*$num_to_show; |
349 | 372 | } else { |
@@ -574,9 +597,13 @@ discard block |
||
574 | 597 | |
575 | 598 | echo user_links($user, 0); |
576 | 599 | echo "<br>"; |
577 | - if ($user->create_time > time()-ST_NEW_TIME) $fstatus.=ST_NEW."<br>"; |
|
600 | + if ($user->create_time > time()-ST_NEW_TIME) { |
|
601 | + $fstatus.=ST_NEW."<br>"; |
|
602 | + } |
|
578 | 603 | echo "<span class=\"small\">"; |
579 | - if ($fstatus) echo "$fstatus"; |
|
604 | + if ($fstatus) { |
|
605 | + echo "$fstatus"; |
|
606 | + } |
|
580 | 607 | |
581 | 608 | if (!$filter || !$ignore_poster){ |
582 | 609 | if ($user->prefs && $user->prefs->avatar!="" && (!$logged_in_user || ($logged_in_user->prefs->hide_avatars==false))) { |
@@ -638,7 +665,9 @@ discard block |
||
638 | 665 | } |
639 | 666 | |
640 | 667 | echo " <a href=\"forum_thread.php?id=".$thread->id."&postid=$post->id\">".tra("Message %1", $post->id)."</a> - "; |
641 | - if ($post->hidden) echo "<font color=red>[".tra("hidden")."] </font>"; |
|
668 | + if ($post->hidden) { |
|
669 | + echo "<font color=red>[".tra("hidden")."] </font>"; |
|
670 | + } |
|
642 | 671 | echo tra("Posted: %1", pretty_time_str($post->timestamp)), " "; |
643 | 672 | |
644 | 673 | if ($post->parent_post) { |
@@ -840,7 +869,9 @@ discard block |
||
840 | 869 | function notify_subscribers($thread, $user) { |
841 | 870 | $subs = BoincSubscription::enum("threadid=$thread->id"); |
842 | 871 | foreach ($subs as $sub) { |
843 | - if ($user && ($user->id == $sub->userid)) continue; |
|
872 | + if ($user && ($user->id == $sub->userid)) { |
|
873 | + continue; |
|
874 | + } |
|
844 | 875 | $user2 = BoincUser::lookup_id($sub->userid); |
845 | 876 | if ($user2) { |
846 | 877 | notify_subscriber($thread, $user2); |
@@ -858,7 +889,9 @@ discard block |
||
858 | 889 | $now = time(); |
859 | 890 | $sig = $signature?1:0; |
860 | 891 | $id = BoincPost::insert("(thread, user, timestamp, content, modified, parent_post, score, votes, signature, hidden) values ($thread->id, $user->id, $now, '$content', 0, $parent_id, 0, 0, $sig, 0)"); |
861 | - if (!$id) return null; |
|
892 | + if (!$id) { |
|
893 | + return null; |
|
894 | + } |
|
862 | 895 | |
863 | 896 | notify_subscribers($thread, $user); |
864 | 897 | |
@@ -897,7 +930,9 @@ discard block |
||
897 | 930 | $status = 1; |
898 | 931 | } |
899 | 932 | $id = BoincThread::insert("(forum, owner, status, title, timestamp, views, replies, activity, sufferers, score, votes, create_time, hidden, sticky, locked) values ($forum->id, $user->id, $status, '$title', $now, 0, -1, 0, 0, 0, 0, $now, 0, 0, 0)"); |
900 | - if (!$id) return null; |
|
933 | + if (!$id) { |
|
934 | + return null; |
|
935 | + } |
|
901 | 936 | $thread = BoincThread::lookup_id($id); |
902 | 937 | create_post($content, 0, $user, $forum, $thread, $signature); |
903 | 938 | $forum->update("threads=threads+1"); |
@@ -906,7 +941,9 @@ discard block |
||
906 | 941 | |
907 | 942 | function hide_post($post, $thread, $forum) { |
908 | 943 | $ret = $post->update("hidden=1"); |
909 | - if (!$ret) return $ret; |
|
944 | + if (!$ret) { |
|
945 | + return $ret; |
|
946 | + } |
|
910 | 947 | $thread->update("replies=if(replies>0, replies-1, 0)"); |
911 | 948 | $forum->update("posts=if(posts>0, posts-1, 0)"); |
912 | 949 | update_thread_timestamp($thread); |
@@ -916,7 +953,9 @@ discard block |
||
916 | 953 | |
917 | 954 | function unhide_post($post, $thread, $forum) { |
918 | 955 | $ret = $post->update("hidden=0"); |
919 | - if (!$ret) return $ret; |
|
956 | + if (!$ret) { |
|
957 | + return $ret; |
|
958 | + } |
|
920 | 959 | $thread->update("replies=replies+1"); |
921 | 960 | $forum->update("posts=posts+1"); |
922 | 961 | update_thread_timestamp($thread); |
@@ -968,7 +1007,9 @@ discard block |
||
968 | 1007 | BoincSubscription::delete($s->userid, $s->threadid); |
969 | 1008 | } |
970 | 1009 | $p = BoincForumPrefs::lookup_userid($user->id); |
971 | - if ($p) $p->delete(); |
|
1010 | + if ($p) { |
|
1011 | + $p->delete(); |
|
1012 | + } |
|
972 | 1013 | BoincForumLogging::delete_aux("userid=$user->id"); |
973 | 1014 | } |
974 | 1015 | |
@@ -989,7 +1030,9 @@ discard block |
||
989 | 1030 | |
990 | 1031 | function hide_thread($thread, $forum) { |
991 | 1032 | $ret = $thread->update("hidden=1"); |
992 | - if (!$ret) return $ret; |
|
1033 | + if (!$ret) { |
|
1034 | + return $ret; |
|
1035 | + } |
|
993 | 1036 | $forum->update("threads=if(threads>0, threads-1, 0)"); |
994 | 1037 | $forum->update("posts=posts-$thread->replies-1"); |
995 | 1038 | update_forum_timestamp($forum); |
@@ -998,7 +1041,9 @@ discard block |
||
998 | 1041 | |
999 | 1042 | function unhide_thread($thread, $forum) { |
1000 | 1043 | $ret = $thread->update("hidden=0"); |
1001 | - if (!$ret) return $ret; |
|
1044 | + if (!$ret) { |
|
1045 | + return $ret; |
|
1046 | + } |
|
1002 | 1047 | $forum->update("threads=threads+1, posts=posts+$thread->replies+1"); |
1003 | 1048 | update_forum_timestamp($forum); |
1004 | 1049 | return true; |
@@ -1160,15 +1205,25 @@ discard block |
||
1160 | 1205 | // - delete threads and posts |
1161 | 1206 | // |
1162 | 1207 | function is_admin($user) { |
1163 | - if (!$user) return false; |
|
1164 | - if ($user->prefs->privilege(S_SCIENTIST)) return true; |
|
1165 | - if ($user->prefs->privilege(S_DEV)) return true; |
|
1166 | - if ($user->prefs->privilege(S_ADMIN)) return true; |
|
1208 | + if (!$user) { |
|
1209 | + return false; |
|
1210 | + } |
|
1211 | + if ($user->prefs->privilege(S_SCIENTIST)) { |
|
1212 | + return true; |
|
1213 | + } |
|
1214 | + if ($user->prefs->privilege(S_DEV)) { |
|
1215 | + return true; |
|
1216 | + } |
|
1217 | + if ($user->prefs->privilege(S_ADMIN)) { |
|
1218 | + return true; |
|
1219 | + } |
|
1167 | 1220 | return false; |
1168 | 1221 | } |
1169 | 1222 | |
1170 | 1223 | function user_can_create_thread($user, $forum) { |
1171 | - if (!$user) return false; |
|
1224 | + if (!$user) { |
|
1225 | + return false; |
|
1226 | + } |
|
1172 | 1227 | if ($forum->is_dev_blog && !is_admin($user)) { |
1173 | 1228 | return false; |
1174 | 1229 | } |
@@ -1176,15 +1231,21 @@ discard block |
||
1176 | 1231 | } |
1177 | 1232 | |
1178 | 1233 | function check_post_access($user, $forum) { |
1179 | - if (is_admin($user)) return; |
|
1234 | + if (is_admin($user)) { |
|
1235 | + return; |
|
1236 | + } |
|
1180 | 1237 | |
1181 | 1238 | switch ($forum->parent_type) { |
1182 | 1239 | case 0: |
1183 | - if ($user->prefs->privilege(S_MODERATOR)) return; |
|
1240 | + if ($user->prefs->privilege(S_MODERATOR)) { |
|
1241 | + return; |
|
1242 | + } |
|
1184 | 1243 | break; |
1185 | 1244 | case 1: |
1186 | 1245 | $team = BoincTeam::lookup_id($forum->category); |
1187 | - if (is_team_admin($user, $team)) return; |
|
1246 | + if (is_team_admin($user, $team)) { |
|
1247 | + return; |
|
1248 | + } |
|
1188 | 1249 | |
1189 | 1250 | // non-team-members can't post |
1190 | 1251 | // |
@@ -1232,17 +1293,29 @@ discard block |
||
1232 | 1293 | // - hide/unhide/move threads and posts |
1233 | 1294 | |
1234 | 1295 | function is_moderator($user, $forum) { |
1235 | - if (!$user) return false; |
|
1296 | + if (!$user) { |
|
1297 | + return false; |
|
1298 | + } |
|
1236 | 1299 | $type = $forum?$forum->parent_type:0; |
1237 | 1300 | switch ($type) { |
1238 | 1301 | case 0: |
1239 | - if ($user->prefs->privilege(S_MODERATOR)) return true; |
|
1240 | - if ($user->prefs->privilege(S_ADMIN)) return true; |
|
1241 | - if ($user->prefs->privilege(S_DEV)) return true; |
|
1242 | - if ($user->prefs->privilege(S_SCIENTIST)) return true; |
|
1302 | + if ($user->prefs->privilege(S_MODERATOR)) { |
|
1303 | + return true; |
|
1304 | + } |
|
1305 | + if ($user->prefs->privilege(S_ADMIN)) { |
|
1306 | + return true; |
|
1307 | + } |
|
1308 | + if ($user->prefs->privilege(S_DEV)) { |
|
1309 | + return true; |
|
1310 | + } |
|
1311 | + if ($user->prefs->privilege(S_SCIENTIST)) { |
|
1312 | + return true; |
|
1313 | + } |
|
1243 | 1314 | break; |
1244 | 1315 | case 1: |
1245 | - if ($user->prefs->privilege(S_ADMIN)) return true; |
|
1316 | + if ($user->prefs->privilege(S_ADMIN)) { |
|
1317 | + return true; |
|
1318 | + } |
|
1246 | 1319 | $team = BoincTeam::lookup_id($forum->category); |
1247 | 1320 | return is_team_admin($user, $team); |
1248 | 1321 | break; |
@@ -1266,8 +1339,12 @@ discard block |
||
1266 | 1339 | // |
1267 | 1340 | function show_thread_and_context($thread, $user) { |
1268 | 1341 | $thread_forum = BoincForum::lookup_id($thread->forum); |
1269 | - if (!$thread_forum) return; |
|
1270 | - if (!is_forum_visible_to_user($thread_forum, $user)) return; |
|
1342 | + if (!$thread_forum) { |
|
1343 | + return; |
|
1344 | + } |
|
1345 | + if (!is_forum_visible_to_user($thread_forum, $user)) { |
|
1346 | + return; |
|
1347 | + } |
|
1271 | 1348 | $owner = BoincUser::lookup_id($thread->owner); |
1272 | 1349 | echo "<tr><td>\n"; |
1273 | 1350 | switch($thread_forum->parent_type) { |
@@ -1292,7 +1369,9 @@ discard block |
||
1292 | 1369 | // |
1293 | 1370 | function is_subscribed($thread, $subs) { |
1294 | 1371 | foreach ($subs as $sub) { |
1295 | - if ($sub->threadid == $thread->id) return true; |
|
1372 | + if ($sub->threadid == $thread->id) { |
|
1373 | + return true; |
|
1374 | + } |
|
1296 | 1375 | } |
1297 | 1376 | return false; |
1298 | 1377 | } |
@@ -1300,8 +1379,12 @@ discard block |
||
1300 | 1379 | function is_forum_visible_to_user($forum, $user) { |
1301 | 1380 | if ($forum->parent_type == 1) { |
1302 | 1381 | if (parse_config(get_config(), "<team_forums_members_only>")) { |
1303 | - if (!$user) return false; |
|
1304 | - if ($user->teamid != $forum->category) return false; |
|
1382 | + if (!$user) { |
|
1383 | + return false; |
|
1384 | + } |
|
1385 | + if ($user->teamid != $forum->category) { |
|
1386 | + return false; |
|
1387 | + } |
|
1305 | 1388 | } |
1306 | 1389 | } |
1307 | 1390 | return true; |
@@ -115,6 +115,10 @@ discard block |
||
115 | 115 | $db = BoincDb::get(); |
116 | 116 | return $db->enum('post', 'BoincPost', $clause); |
117 | 117 | } |
118 | + |
|
119 | + /** |
|
120 | + * @param string $query |
|
121 | + */ |
|
118 | 122 | static function enum_general($query) { |
119 | 123 | $db = BoincDb::get(); |
120 | 124 | return $db->enum_general('BoincPost', $query); |
@@ -175,6 +179,10 @@ discard block |
||
175 | 179 | $db = BoincDb::get(); |
176 | 180 | return $db->delete_aux('forum_preferences', "userid=$this->userid"); |
177 | 181 | } |
182 | + |
|
183 | + /** |
|
184 | + * @param string $clause |
|
185 | + */ |
|
178 | 186 | static function enum($clause=null) { |
179 | 187 | $db = BoincDb::get(); |
180 | 188 | return $db->enum('forum_preferences', 'BoincForumPrefs', $clause); |
@@ -290,6 +298,10 @@ discard block |
||
290 | 298 | } |
291 | 299 | |
292 | 300 | class BoincNotify { |
301 | + |
|
302 | + /** |
|
303 | + * @param string $clause |
|
304 | + */ |
|
293 | 305 | static function insert($clause) { |
294 | 306 | $db = BoincDb::get(); |
295 | 307 | $ret = $db->insert('notify', $clause); |
@@ -304,6 +316,10 @@ discard block |
||
304 | 316 | $db = BoincDb::get(); |
305 | 317 | return $db->enum('notify', 'BoincNotify', $clause); |
306 | 318 | } |
319 | + |
|
320 | + /** |
|
321 | + * @param integer $type |
|
322 | + */ |
|
307 | 323 | static function lookup($userid, $type, $opaque) { |
308 | 324 | $db = BoincDb::get(); |
309 | 325 | return $db->lookup('notify', 'BoincNotify', "userid=$userid and type=$type and opaque=$opaque"); |
@@ -316,6 +332,10 @@ discard block |
||
316 | 332 | $db = BoincDb::get(); |
317 | 333 | $db->delete_aux('notify', $clause); |
318 | 334 | } |
335 | + |
|
336 | + /** |
|
337 | + * @param string $query |
|
338 | + */ |
|
319 | 339 | static function enum_general($query) { |
320 | 340 | $db = BoincDb::get(); |
321 | 341 | return $db->enum_general('BoincNotify', $query); |
@@ -164,7 +164,7 @@ |
||
164 | 164 | $user->prefs = $prefs; |
165 | 165 | } |
166 | 166 | function privilege($specialbit) { |
167 | - return (substr($this->special_user, $specialbit,1)==1); |
|
167 | + return (substr($this->special_user, $specialbit,1)==1); |
|
168 | 168 | } |
169 | 169 | function update($clause) { |
170 | 170 | $db = BoincDb::get(); |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | $db = BoincDb::get(); |
28 | 28 | return $db->lookup('category', 'BoincCategory', $clause); |
29 | 29 | } |
30 | - static function enum($clause=null) { |
|
30 | + static function enum($clause = null) { |
|
31 | 31 | $db = BoincDb::get(); |
32 | 32 | return $db->enum('category', 'BoincCategory', $clause); |
33 | 33 | } |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | $db = BoincDb::get(); |
79 | 79 | return $db->update($this, 'thread', $clause); |
80 | 80 | } |
81 | - static function enum($clause="") { |
|
81 | + static function enum($clause = "") { |
|
82 | 82 | $db = BoincDb::get(); |
83 | 83 | return $db->enum('thread', 'BoincThread', $clause); |
84 | 84 | } |
@@ -142,7 +142,7 @@ discard block |
||
142 | 142 | $db = BoincDb::get(); |
143 | 143 | $ret = $db->insert('forum_preferences', $clause); |
144 | 144 | } |
145 | - static function lookup(&$user, $nocache=false) { |
|
145 | + static function lookup(&$user, $nocache = false) { |
|
146 | 146 | if (!$user) return; |
147 | 147 | if (isset($user->prefs)) return; |
148 | 148 | if (!$nocache && isset(self::$cache[$user->id])) { |
@@ -164,7 +164,7 @@ discard block |
||
164 | 164 | $user->prefs = $prefs; |
165 | 165 | } |
166 | 166 | function privilege($specialbit) { |
167 | - return (substr($this->special_user, $specialbit,1)==1); |
|
167 | + return (substr($this->special_user, $specialbit, 1) == 1); |
|
168 | 168 | } |
169 | 169 | function update($clause) { |
170 | 170 | $db = BoincDb::get(); |
@@ -175,7 +175,7 @@ discard block |
||
175 | 175 | $db = BoincDb::get(); |
176 | 176 | return $db->delete_aux('forum_preferences', "userid=$this->userid"); |
177 | 177 | } |
178 | - static function enum($clause=null) { |
|
178 | + static function enum($clause = null) { |
|
179 | 179 | $db = BoincDb::get(); |
180 | 180 | return $db->enum('forum_preferences', 'BoincForumPrefs', $clause); |
181 | 181 | } |
@@ -215,8 +215,8 @@ discard block |
||
215 | 215 | // |
216 | 216 | $fl = BoincForumLogging::lookup(0, 0); |
217 | 217 | if ($fl) { |
218 | - if ($fl->timestamp<time()-MAX_FORUM_LOGGING_TIME){ |
|
219 | - BoincForumLogging::delete_aux("timestamp<'".(time()-MAX_FORUM_LOGGING_TIME)."' and userid != 0"); |
|
218 | + if ($fl->timestamp < time() - MAX_FORUM_LOGGING_TIME) { |
|
219 | + BoincForumLogging::delete_aux("timestamp<'".(time() - MAX_FORUM_LOGGING_TIME)."' and userid != 0"); |
|
220 | 220 | BoincForumLogging::replace(0, 0, time()); |
221 | 221 | } |
222 | 222 | } else { |
@@ -322,9 +322,9 @@ discard block |
||
322 | 322 | } |
323 | 323 | } |
324 | 324 | |
325 | -define ('NOTIFY_FRIEND_REQ', 1); |
|
326 | -define ('NOTIFY_FRIEND_ACCEPT', 2); |
|
327 | -define ('NOTIFY_PM', 3); |
|
328 | -define ('NOTIFY_SUBSCRIBED_POST', 4); |
|
325 | +define('NOTIFY_FRIEND_REQ', 1); |
|
326 | +define('NOTIFY_FRIEND_ACCEPT', 2); |
|
327 | +define('NOTIFY_PM', 3); |
|
328 | +define('NOTIFY_SUBSCRIBED_POST', 4); |
|
329 | 329 | |
330 | 330 | ?> |
@@ -37,7 +37,9 @@ discard block |
||
37 | 37 | static function insert($clause) { |
38 | 38 | $db = BoincDb::get(); |
39 | 39 | $ret = $db->insert('forum', $clause); |
40 | - if (!$ret) return null; |
|
40 | + if (!$ret) { |
|
41 | + return null; |
|
42 | + } |
|
41 | 43 | return $db->insert_id(); |
42 | 44 | } |
43 | 45 | static function lookup_id($id) { |
@@ -66,7 +68,9 @@ discard block |
||
66 | 68 | static function insert($clause) { |
67 | 69 | $db = BoincDb::get(); |
68 | 70 | $ret = $db->insert('thread', $clause); |
69 | - if (!$ret) return null; |
|
71 | + if (!$ret) { |
|
72 | + return null; |
|
73 | + } |
|
70 | 74 | return $db->insert_id(); |
71 | 75 | |
72 | 76 | } |
@@ -96,7 +100,9 @@ discard block |
||
96 | 100 | static function insert($clause) { |
97 | 101 | $db = BoincDb::get(); |
98 | 102 | $ret = $db->insert('post', $clause); |
99 | - if (!$ret) return null; |
|
103 | + if (!$ret) { |
|
104 | + return null; |
|
105 | + } |
|
100 | 106 | return $db->insert_id(); |
101 | 107 | } |
102 | 108 | static function lookup_id($id) { |
@@ -143,8 +149,12 @@ discard block |
||
143 | 149 | $ret = $db->insert('forum_preferences', $clause); |
144 | 150 | } |
145 | 151 | static function lookup(&$user, $nocache=false) { |
146 | - if (!$user) return; |
|
147 | - if (isset($user->prefs)) return; |
|
152 | + if (!$user) { |
|
153 | + return; |
|
154 | + } |
|
155 | + if (isset($user->prefs)) { |
|
156 | + return; |
|
157 | + } |
|
148 | 158 | if (!$nocache && isset(self::$cache[$user->id])) { |
149 | 159 | $prefs = self::$cache[$user->id]; |
150 | 160 | } else { |
@@ -293,7 +303,9 @@ discard block |
||
293 | 303 | static function insert($clause) { |
294 | 304 | $db = BoincDb::get(); |
295 | 305 | $ret = $db->insert('notify', $clause); |
296 | - if (!$ret) return null; |
|
306 | + if (!$ret) { |
|
307 | + return null; |
|
308 | + } |
|
297 | 309 | return $db->insert_id(); |
298 | 310 | } |
299 | 311 | static function replace($clause) { |
@@ -196,6 +196,10 @@ |
||
196 | 196 | |
197 | 197 | //////////////////// a banishment vote has been started /////////// |
198 | 198 | // |
199 | +/** |
|
200 | + * @param integer $duration |
|
201 | + * @param integer $end_time |
|
202 | + */ |
|
199 | 203 | function send_banish_vote_email($user, $duration, $reason, $end_time) { |
200 | 204 | global $master_url; |
201 | 205 | $now=time(); |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | $link = secure_url_base() . "forum_thread.php?id=" . $thread->id; |
129 | 129 | $body = "Another " . PROJECT . " user has posted to the thread |
130 | 130 | \"" . $thread->title . "\".\n" |
131 | - ."To view the updated thread, visit:\n$link |
|
131 | + ."To view the updated thread, visit:\n$link |
|
132 | 132 | |
133 | 133 | -------------------------- |
134 | 134 | To change email preferences, visit: |
@@ -141,7 +141,7 @@ discard block |
||
141 | 141 | //////////////////// a user clicks the red "x" to report a post /////////// |
142 | 142 | // |
143 | 143 | function send_report_post_email($user, $forum, $thread, $post, $message) { |
144 | - global $master_url; |
|
144 | + global $master_url; |
|
145 | 145 | |
146 | 146 | $body = ""; |
147 | 147 | $owner = BoincUser::lookup_id($post->user); |
@@ -197,7 +197,7 @@ discard block |
||
197 | 197 | //////////////////// a banishment vote has been started /////////// |
198 | 198 | // |
199 | 199 | function send_banish_vote_email($user, $duration, $reason, $end_time) { |
200 | - global $master_url; |
|
200 | + global $master_url; |
|
201 | 201 | $now=time(); |
202 | 202 | $subject = PROJECT." banishment vote underway"; |
203 | 203 | $vote_url = $master_url."forum_banishment_vote.php"; |
@@ -219,11 +219,11 @@ discard block |
||
219 | 219 | pm_send_msg($user, $user, $subject, $body, false); |
220 | 220 | |
221 | 221 | $body .= "\n\n<a href=".$vote_url."?action=yes&userid=" |
222 | - .$user->id |
|
223 | - .">[vote to banish author]</a>\n\n" |
|
224 | - ."<a href=".$vote_url."?action=no&userid=" |
|
225 | - .$user->id |
|
226 | - .">[vote not to banish author]</a>"; |
|
222 | + .$user->id |
|
223 | + .">[vote to banish author]</a>\n\n" |
|
224 | + ."<a href=".$vote_url."?action=no&userid=" |
|
225 | + .$user->id |
|
226 | + .">[vote not to banish author]</a>"; |
|
227 | 227 | |
228 | 228 | $forum = new BoincForum; |
229 | 229 | $forum->parent_type = 0; |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | // - project forums: everyone in POST_REPORT_EMAILS |
25 | 25 | // - team message board: team founder and admins |
26 | 26 | // |
27 | -function mail_report_list($forum, $subject, $body, $must_send=false) { |
|
27 | +function mail_report_list($forum, $subject, $body, $must_send = false) { |
|
28 | 28 | $success = true; |
29 | 29 | switch ($forum->parent_type) { |
30 | 30 | case 0: |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | function send_moderation_email($forum, $post, $thread, $explanation, $action) { |
63 | 63 | global $master_url; |
64 | 64 | |
65 | - $moderator=get_logged_in_user(); |
|
65 | + $moderator = get_logged_in_user(); |
|
66 | 66 | $body = ""; |
67 | 67 | $user = BoincUser::lookup_id($post->user); |
68 | 68 | |
@@ -123,11 +123,11 @@ discard block |
||
123 | 123 | // If a user is subscribed to a thread that is replied to, |
124 | 124 | // send them an email notifying them of the reply. |
125 | 125 | // |
126 | -function send_reply_notification_email($thread, $user){ |
|
127 | - $title = PROJECT . ": A user has posted to '". $thread->title ."'"; |
|
128 | - $link = secure_url_base() . "forum_thread.php?id=" . $thread->id; |
|
129 | - $body = "Another " . PROJECT . " user has posted to the thread |
|
130 | -\"" . $thread->title . "\".\n" |
|
126 | +function send_reply_notification_email($thread, $user) { |
|
127 | + $title = PROJECT.": A user has posted to '".$thread->title."'"; |
|
128 | + $link = secure_url_base()."forum_thread.php?id=".$thread->id; |
|
129 | + $body = "Another ".PROJECT." user has posted to the thread |
|
130 | +\"" . $thread->title."\".\n" |
|
131 | 131 | ."To view the updated thread, visit:\n$link |
132 | 132 | |
133 | 133 | -------------------------- |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | |
141 | 141 | //////////////////// a user clicks the red "x" to report a post /////////// |
142 | 142 | // |
143 | -function send_report_post_email($user, $forum, $thread, $post, $message) { |
|
143 | +function send_report_post_email($user, $forum, $thread, $post, $message) { |
|
144 | 144 | global $master_url; |
145 | 145 | |
146 | 146 | $body = ""; |
@@ -198,16 +198,16 @@ discard block |
||
198 | 198 | // |
199 | 199 | function send_banish_vote_email($user, $duration, $reason, $end_time) { |
200 | 200 | global $master_url; |
201 | - $now=time(); |
|
201 | + $now = time(); |
|
202 | 202 | $subject = PROJECT." banishment vote underway"; |
203 | 203 | $vote_url = $master_url."forum_banishment_vote.php"; |
204 | 204 | $body = " |
205 | 205 | A vote has been started to banish you |
206 | 206 | from the ".PROJECT." message boards until ".date('M j, |
207 | -Y G:i', $duration+$now).", |
|
207 | +Y G:i', $duration + $now).", |
|
208 | 208 | because your postings have not followed our guidelines. |
209 | 209 | |
210 | -This vote will last until ".date('M j, Y G:i',$end_time)." or until a majority |
|
210 | +This vote will last until ".date('M j, Y G:i', $end_time)." or until a majority |
|
211 | 211 | decision has been reached. If the vote does not result in banishment, you will be |
212 | 212 | able to resume posting at that time. |
213 | 213 | "; |
@@ -29,6 +29,9 @@ |
||
29 | 29 | return false; |
30 | 30 | } |
31 | 31 | |
32 | +/** |
|
33 | + * @param boolean $no_images |
|
34 | + */ |
|
32 | 35 | function show_forum_rss_item($thread, $userid, $threads_only, $no_images) { |
33 | 36 | $unique_url=secure_url_base()."forum_thread.php?id=".$thread->id; |
34 | 37 |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | } |
31 | 31 | |
32 | 32 | function show_forum_rss_item($thread, $userid, $threads_only, $no_images) { |
33 | - $unique_url=secure_url_base()."forum_thread.php?id=".$thread->id; |
|
33 | + $unique_url = secure_url_base()."forum_thread.php?id=".$thread->id; |
|
34 | 34 | |
35 | 35 | $clause2 = " and hidden=0 "; |
36 | 36 | if ($userid) $clause2 .= "and user=$userid"; |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | } |
42 | 42 | if (!count($posts)) return; |
43 | 43 | $post = $posts[0]; |
44 | - $post_date = gmdate('D, d M Y H:i:s',$post->timestamp).' GMT'; |
|
44 | + $post_date = gmdate('D, d M Y H:i:s', $post->timestamp).' GMT'; |
|
45 | 45 | $post_user = BOincUser::lookup_id($post->user); |
46 | 46 | BoincForumPrefs::lookup($post_user); |
47 | 47 | $options = new output_options(); |
@@ -84,25 +84,25 @@ discard block |
||
84 | 84 | |
85 | 85 | // Now construct header |
86 | 86 | // |
87 | - header ("Expires: " . gmdate('D, d M Y H:i:s', time()+86400) . " GMT"); |
|
87 | + header("Expires: ".gmdate('D, d M Y H:i:s', time() + 86400)." GMT"); |
|
88 | 88 | if (sizeof($threads)) { |
89 | 89 | $t = $threads[0]; |
90 | - $last_mod_time = $threads_only?$t->create_time:$t->timestamp; |
|
91 | - $create_date = gmdate('D, d M Y H:i:s', $last_mod_time) . ' GMT'; |
|
92 | - header ("Last-Modified: " . $create_date); |
|
90 | + $last_mod_time = $threads_only ? $t->create_time : $t->timestamp; |
|
91 | + $create_date = gmdate('D, d M Y H:i:s', $last_mod_time).' GMT'; |
|
92 | + header("Last-Modified: ".$create_date); |
|
93 | 93 | } else { |
94 | - $create_date = gmdate('D, d M Y H:i:s') . ' GMT'; |
|
94 | + $create_date = gmdate('D, d M Y H:i:s').' GMT'; |
|
95 | 95 | } |
96 | - header ("Content-Type: application/xml"); |
|
96 | + header("Content-Type: application/xml"); |
|
97 | 97 | |
98 | - $forum=BoincForum::lookup_id($forumid); |
|
98 | + $forum = BoincForum::lookup_id($forumid); |
|
99 | 99 | // Create channel header and open XML content |
100 | 100 | // |
101 | 101 | $description = PROJECT.": $forum->title"; |
102 | 102 | if ($userid) { |
103 | 103 | $description .= " (posts by $user->name)"; |
104 | 104 | } |
105 | - $channel_image = secure_url_base() . "rss_image.gif"; |
|
105 | + $channel_image = secure_url_base()."rss_image.gif"; |
|
106 | 106 | $language = "en-us"; |
107 | 107 | echo "<?xml version=\"1.0\" encoding=\"UTF-8\" ?> |
108 | 108 | <rss version=\"2.0\"> |
@@ -23,9 +23,15 @@ discard block |
||
23 | 23 | // return true if the given HTML may contain images or video |
24 | 24 | // |
25 | 25 | function contains_image_or_video($x) { |
26 | - if (strstr($x, "<img ")) return true; |
|
27 | - if (strstr($x, "<object ")) return true; |
|
28 | - if (strstr($x, "<iframe ")) return true; |
|
26 | + if (strstr($x, "<img ")) { |
|
27 | + return true; |
|
28 | + } |
|
29 | + if (strstr($x, "<object ")) { |
|
30 | + return true; |
|
31 | + } |
|
32 | + if (strstr($x, "<iframe ")) { |
|
33 | + return true; |
|
34 | + } |
|
29 | 35 | return false; |
30 | 36 | } |
31 | 37 | |
@@ -33,13 +39,17 @@ discard block |
||
33 | 39 | $unique_url=secure_url_base()."forum_thread.php?id=".$thread->id; |
34 | 40 | |
35 | 41 | $clause2 = " and hidden=0 "; |
36 | - if ($userid) $clause2 .= "and user=$userid"; |
|
42 | + if ($userid) { |
|
43 | + $clause2 .= "and user=$userid"; |
|
44 | + } |
|
37 | 45 | if ($threads_only) { |
38 | 46 | $posts = BoincPost::enum("thread=$thread->id $clause2 order by id limit 1"); |
39 | 47 | } else { |
40 | 48 | $posts = BoincPost::enum("thread=$thread->id $clause2 order by timestamp desc limit 1"); |
41 | 49 | } |
42 | - if (!count($posts)) return; |
|
50 | + if (!count($posts)) { |
|
51 | + return; |
|
52 | + } |
|
43 | 53 | $post = $posts[0]; |
44 | 54 | $post_date = gmdate('D, d M Y H:i:s',$post->timestamp).' GMT'; |
45 | 55 | $post_user = BOincUser::lookup_id($post->user); |
@@ -49,7 +59,9 @@ discard block |
||
49 | 59 | $options->htmlitems = false; |
50 | 60 | } |
51 | 61 | $t = output_transform($post->content, $options); |
52 | - if ($no_images && contains_image_or_video($t)) return; |
|
62 | + if ($no_images && contains_image_or_video($t)) { |
|
63 | + return; |
|
64 | + } |
|
53 | 65 | echo "<item> |
54 | 66 | <title><![CDATA[".sanitize_tags(bb2html($thread->title))."]]></title> |
55 | 67 | <link>$unique_url</link> |
@@ -65,7 +77,9 @@ discard block |
||
65 | 77 | |
66 | 78 | if ($userid) { |
67 | 79 | $user = BoincUser::lookup_id($userid); |
68 | - if (!$user) error_page("no such user"); |
|
80 | + if (!$user) { |
|
81 | + error_page("no such user"); |
|
82 | + } |
|
69 | 83 | $clause .= " and owner=$userid"; |
70 | 84 | } |
71 | 85 |
@@ -229,6 +229,9 @@ discard block |
||
229 | 229 | shmop_close ($shmid); |
230 | 230 | } |
231 | 231 | |
232 | +/** |
|
233 | + * @param GeoIP $gi |
|
234 | + */ |
|
232 | 235 | function _setup_segments($gi){ |
233 | 236 | $gi->databaseType = GEOIP_COUNTRY_EDITION; |
234 | 237 | $gi->record_length = STANDARD_RECORD_LENGTH; |
@@ -311,6 +314,10 @@ discard block |
||
311 | 314 | return $gi; |
312 | 315 | } |
313 | 316 | |
317 | +/** |
|
318 | + * @param string $filename |
|
319 | + * @param integer $flags |
|
320 | + */ |
|
314 | 321 | function geoip_open($filename, $flags) { |
315 | 322 | $gi = new GeoIP; |
316 | 323 | $gi->flags = $flags; |
@@ -419,6 +426,9 @@ discard block |
||
419 | 426 | return false; |
420 | 427 | } |
421 | 428 | |
429 | +/** |
|
430 | + * @param integer $ipnum |
|
431 | + */ |
|
422 | 432 | function _get_org($gi,$ipnum){ |
423 | 433 | $seek_org = _geoip_seek_country($gi,$ipnum); |
424 | 434 | if ($seek_org == $gi->databaseSegments) { |
@@ -443,6 +453,9 @@ discard block |
||
443 | 453 | return _get_org($gi, $ipnum); |
444 | 454 | } |
445 | 455 | |
456 | +/** |
|
457 | + * @param integer $ipnum |
|
458 | + */ |
|
446 | 459 | function _get_region($gi,$ipnum){ |
447 | 460 | if ($gi->databaseType == GEOIP_REGION_EDITION_REV0){ |
448 | 461 | $seek_region = _geoip_seek_country($gi,$ipnum) - GEOIP_STATE_BEGIN_REV0; |
@@ -213,26 +213,26 @@ discard block |
||
213 | 213 | } |
214 | 214 | function geoip_load_shared_mem ($file) { |
215 | 215 | |
216 | - $fp = fopen($file, "rb"); |
|
217 | - if (!$fp) { |
|
216 | + $fp = fopen($file, "rb"); |
|
217 | + if (!$fp) { |
|
218 | 218 | print "error opening $file: $php_errormsg\n"; |
219 | 219 | exit; |
220 | - } |
|
221 | - $s_array = fstat($fp); |
|
222 | - $size = $s_array['size']; |
|
223 | - if ($shmid = @shmop_open (GEOIP_SHM_KEY, "w", 0, 0)) { |
|
220 | + } |
|
221 | + $s_array = fstat($fp); |
|
222 | + $size = $s_array['size']; |
|
223 | + if ($shmid = @shmop_open (GEOIP_SHM_KEY, "w", 0, 0)) { |
|
224 | 224 | shmop_delete ($shmid); |
225 | 225 | shmop_close ($shmid); |
226 | - } |
|
227 | - $shmid = shmop_open (GEOIP_SHM_KEY, "c", 0644, $size); |
|
228 | - shmop_write ($shmid, fread($fp, $size), 0); |
|
229 | - shmop_close ($shmid); |
|
226 | + } |
|
227 | + $shmid = shmop_open (GEOIP_SHM_KEY, "c", 0644, $size); |
|
228 | + shmop_write ($shmid, fread($fp, $size), 0); |
|
229 | + shmop_close ($shmid); |
|
230 | 230 | } |
231 | 231 | |
232 | 232 | function _setup_segments($gi){ |
233 | - $gi->databaseType = GEOIP_COUNTRY_EDITION; |
|
234 | - $gi->record_length = STANDARD_RECORD_LENGTH; |
|
235 | - if ($gi->flags & GEOIP_SHARED_MEMORY) { |
|
233 | + $gi->databaseType = GEOIP_COUNTRY_EDITION; |
|
234 | + $gi->record_length = STANDARD_RECORD_LENGTH; |
|
235 | + if ($gi->flags & GEOIP_SHARED_MEMORY) { |
|
236 | 236 | $offset = @shmop_size ($gi->shmid) - 3; |
237 | 237 | for ($i = 0; $i < STRUCTURE_INFO_MAX_SIZE; $i++) { |
238 | 238 | $delim = @shmop_read ($gi->shmid, $offset, 3); |
@@ -245,19 +245,19 @@ discard block |
||
245 | 245 | $gi->databaseSegments = GEOIP_STATE_BEGIN_REV0; |
246 | 246 | } else if ($gi->databaseType == GEOIP_REGION_EDITION_REV1){ |
247 | 247 | $gi->databaseSegments = GEOIP_STATE_BEGIN_REV1; |
248 | - } else if (($gi->databaseType == GEOIP_CITY_EDITION_REV0)|| |
|
248 | + } else if (($gi->databaseType == GEOIP_CITY_EDITION_REV0)|| |
|
249 | 249 | ($gi->databaseType == GEOIP_CITY_EDITION_REV1) |
250 | 250 | || ($gi->databaseType == GEOIP_ORG_EDITION) |
251 | - || ($gi->databaseType == GEOIP_ISP_EDITION) |
|
252 | - || ($gi->databaseType == GEOIP_ASNUM_EDITION)){ |
|
251 | + || ($gi->databaseType == GEOIP_ISP_EDITION) |
|
252 | + || ($gi->databaseType == GEOIP_ASNUM_EDITION)){ |
|
253 | 253 | $gi->databaseSegments = 0; |
254 | 254 | $buf = @shmop_read ($gi->shmid, $offset, SEGMENT_RECORD_LENGTH); |
255 | 255 | for ($j = 0;$j < SEGMENT_RECORD_LENGTH;$j++){ |
256 | 256 | $gi->databaseSegments += (ord($buf[$j]) << ($j * 8)); |
257 | 257 | } |
258 | - if (($gi->databaseType == GEOIP_ORG_EDITION)|| |
|
259 | - ($gi->databaseType == GEOIP_ISP_EDITION)) { |
|
260 | - $gi->record_length = ORG_RECORD_LENGTH; |
|
258 | + if (($gi->databaseType == GEOIP_ORG_EDITION)|| |
|
259 | + ($gi->databaseType == GEOIP_ISP_EDITION)) { |
|
260 | + $gi->record_length = ORG_RECORD_LENGTH; |
|
261 | 261 | } |
262 | 262 | } |
263 | 263 | break; |
@@ -270,7 +270,7 @@ discard block |
||
270 | 270 | ($gi->databaseType == GEOIP_NETSPEED_EDITION)){ |
271 | 271 | $gi->databaseSegments = GEOIP_COUNTRY_BEGIN; |
272 | 272 | } |
273 | - } else { |
|
273 | + } else { |
|
274 | 274 | $filepos = ftell($gi->filehandle); |
275 | 275 | fseek($gi->filehandle, -3, SEEK_END); |
276 | 276 | for ($i = 0; $i < STRUCTURE_INFO_MAX_SIZE; $i++) { |
@@ -281,19 +281,19 @@ discard block |
||
281 | 281 | $gi->databaseSegments = GEOIP_STATE_BEGIN_REV0; |
282 | 282 | } |
283 | 283 | else if ($gi->databaseType == GEOIP_REGION_EDITION_REV1){ |
284 | - $gi->databaseSegments = GEOIP_STATE_BEGIN_REV1; |
|
284 | + $gi->databaseSegments = GEOIP_STATE_BEGIN_REV1; |
|
285 | 285 | } else if (($gi->databaseType == GEOIP_CITY_EDITION_REV0) || |
286 | 286 | ($gi->databaseType == GEOIP_CITY_EDITION_REV1) || |
287 | 287 | ($gi->databaseType == GEOIP_ORG_EDITION) || |
288 | - ($gi->databaseType == GEOIP_ISP_EDITION) || |
|
288 | + ($gi->databaseType == GEOIP_ISP_EDITION) || |
|
289 | 289 | ($gi->databaseType == GEOIP_ASNUM_EDITION)){ |
290 | 290 | $gi->databaseSegments = 0; |
291 | 291 | $buf = fread($gi->filehandle,SEGMENT_RECORD_LENGTH); |
292 | 292 | for ($j = 0;$j < SEGMENT_RECORD_LENGTH;$j++){ |
293 | 293 | $gi->databaseSegments += (ord($buf[$j]) << ($j * 8)); |
294 | 294 | } |
295 | - if ($gi->databaseType == GEOIP_ORG_EDITION) { |
|
296 | - $gi->record_length = ORG_RECORD_LENGTH; |
|
295 | + if ($gi->databaseType == GEOIP_ORG_EDITION) { |
|
296 | + $gi->record_length = ORG_RECORD_LENGTH; |
|
297 | 297 | } |
298 | 298 | } |
299 | 299 | break; |
@@ -304,17 +304,17 @@ discard block |
||
304 | 304 | if (($gi->databaseType == GEOIP_COUNTRY_EDITION)|| |
305 | 305 | ($gi->databaseType == GEOIP_PROXY_EDITION)|| |
306 | 306 | ($gi->databaseType == GEOIP_NETSPEED_EDITION)){ |
307 | - $gi->databaseSegments = GEOIP_COUNTRY_BEGIN; |
|
307 | + $gi->databaseSegments = GEOIP_COUNTRY_BEGIN; |
|
308 | 308 | } |
309 | 309 | fseek($gi->filehandle,$filepos,SEEK_SET); |
310 | - } |
|
311 | - return $gi; |
|
310 | + } |
|
311 | + return $gi; |
|
312 | 312 | } |
313 | 313 | |
314 | 314 | function geoip_open($filename, $flags) { |
315 | - $gi = new GeoIP; |
|
316 | - $gi->flags = $flags; |
|
317 | - if ($gi->flags & GEOIP_SHARED_MEMORY) { |
|
315 | + $gi = new GeoIP; |
|
316 | + $gi->flags = $flags; |
|
317 | + if ($gi->flags & GEOIP_SHARED_MEMORY) { |
|
318 | 318 | $gi->shmid = @shmop_open (GEOIP_SHM_KEY, "a", 0, 0); |
319 | 319 | } else { |
320 | 320 | $gi->filehandle = fopen($filename,"rb"); |
@@ -322,174 +322,174 @@ discard block |
||
322 | 322 | $s_array = fstat($gi->filehandle); |
323 | 323 | $gi->memory_buffer = fread($gi->filehandle, $s_array[size]); |
324 | 324 | } |
325 | - } |
|
325 | + } |
|
326 | 326 | |
327 | - $gi = _setup_segments($gi); |
|
328 | - return $gi; |
|
327 | + $gi = _setup_segments($gi); |
|
328 | + return $gi; |
|
329 | 329 | } |
330 | 330 | |
331 | 331 | function geoip_close($gi) { |
332 | - if ($gi->flags & GEOIP_SHARED_MEMORY) { |
|
332 | + if ($gi->flags & GEOIP_SHARED_MEMORY) { |
|
333 | 333 | return true; |
334 | - } |
|
334 | + } |
|
335 | 335 | |
336 | - return fclose($gi->filehandle); |
|
336 | + return fclose($gi->filehandle); |
|
337 | 337 | } |
338 | 338 | |
339 | 339 | function geoip_country_id_by_name($gi, $name) { |
340 | - $addr = gethostbyname($name); |
|
341 | - if (!$addr || $addr == $name) { |
|
340 | + $addr = gethostbyname($name); |
|
341 | + if (!$addr || $addr == $name) { |
|
342 | 342 | return false; |
343 | - } |
|
344 | - return geoip_country_id_by_addr($gi, $addr); |
|
343 | + } |
|
344 | + return geoip_country_id_by_addr($gi, $addr); |
|
345 | 345 | } |
346 | 346 | |
347 | 347 | function geoip_country_code_by_name($gi, $name) { |
348 | - $country_id = geoip_country_id_by_name($gi,$name); |
|
349 | - if ($country_id !== false) { |
|
348 | + $country_id = geoip_country_id_by_name($gi,$name); |
|
349 | + if ($country_id !== false) { |
|
350 | 350 | return $gi->GEOIP_COUNTRY_CODES[$country_id]; |
351 | - } |
|
352 | - return false; |
|
351 | + } |
|
352 | + return false; |
|
353 | 353 | } |
354 | 354 | |
355 | 355 | function geoip_country_name_by_name($gi, $name) { |
356 | - $country_id = geoip_country_id_by_name($gi,$name); |
|
357 | - if ($country_id !== false) { |
|
356 | + $country_id = geoip_country_id_by_name($gi,$name); |
|
357 | + if ($country_id !== false) { |
|
358 | 358 | return $gi->GEOIP_COUNTRY_NAMES[$country_id]; |
359 | - } |
|
360 | - return false; |
|
359 | + } |
|
360 | + return false; |
|
361 | 361 | } |
362 | 362 | |
363 | 363 | function geoip_country_id_by_addr($gi, $addr) { |
364 | - $ipnum = ip2long($addr); |
|
365 | - return _geoip_seek_country($gi, $ipnum) - GEOIP_COUNTRY_BEGIN; |
|
364 | + $ipnum = ip2long($addr); |
|
365 | + return _geoip_seek_country($gi, $ipnum) - GEOIP_COUNTRY_BEGIN; |
|
366 | 366 | } |
367 | 367 | |
368 | 368 | function geoip_country_code_by_addr($gi, $addr) { |
369 | - $country_id = geoip_country_id_by_addr($gi,$addr); |
|
370 | - if ($country_id !== false) { |
|
369 | + $country_id = geoip_country_id_by_addr($gi,$addr); |
|
370 | + if ($country_id !== false) { |
|
371 | 371 | return $gi->GEOIP_COUNTRY_CODES[$country_id]; |
372 | - } |
|
373 | - return false; |
|
372 | + } |
|
373 | + return false; |
|
374 | 374 | } |
375 | 375 | |
376 | 376 | function geoip_country_name_by_addr($gi, $addr) { |
377 | - $country_id = geoip_country_id_by_addr($gi,$addr); |
|
378 | - if ($country_id !== false) { |
|
377 | + $country_id = geoip_country_id_by_addr($gi,$addr); |
|
378 | + if ($country_id !== false) { |
|
379 | 379 | return $gi->GEOIP_COUNTRY_NAMES[$country_id]; |
380 | - } |
|
381 | - return false; |
|
380 | + } |
|
381 | + return false; |
|
382 | 382 | } |
383 | 383 | |
384 | 384 | function _geoip_seek_country($gi, $ipnum) { |
385 | - $offset = 0; |
|
386 | - for ($depth = 31; $depth >= 0; --$depth) { |
|
385 | + $offset = 0; |
|
386 | + for ($depth = 31; $depth >= 0; --$depth) { |
|
387 | 387 | if ($gi->flags & GEOIP_MEMORY_CACHE) { |
388 | - $buf = substr($gi->memory_buffer, |
|
388 | + $buf = substr($gi->memory_buffer, |
|
389 | 389 | 2 * $gi->record_length * $offset, |
390 | 390 | 2 * $gi->record_length); |
391 | 391 | } elseif ($gi->flags & GEOIP_SHARED_MEMORY) { |
392 | - $buf = @shmop_read ($gi->shmid, |
|
392 | + $buf = @shmop_read ($gi->shmid, |
|
393 | 393 | 2 * $gi->record_length * $offset, |
394 | 394 | 2 * $gi->record_length ); |
395 | 395 | } else { |
396 | - fseek($gi->filehandle, 2 * $gi->record_length * $offset, SEEK_SET) == 0 |
|
396 | + fseek($gi->filehandle, 2 * $gi->record_length * $offset, SEEK_SET) == 0 |
|
397 | 397 | or die("fseek failed"); |
398 | - $buf = fread($gi->filehandle, 2 * $gi->record_length); |
|
398 | + $buf = fread($gi->filehandle, 2 * $gi->record_length); |
|
399 | 399 | } |
400 | 400 | $x = array(0,0); |
401 | 401 | for ($i = 0; $i < 2; ++$i) { |
402 | - for ($j = 0; $j < $gi->record_length; ++$j) { |
|
402 | + for ($j = 0; $j < $gi->record_length; ++$j) { |
|
403 | 403 | $x[$i] += ord($buf[$gi->record_length * $i + $j]) << ($j * 8); |
404 | - } |
|
404 | + } |
|
405 | 405 | } |
406 | 406 | if ($ipnum & (1 << $depth)) { |
407 | - if ($x[1] >= $gi->databaseSegments) { |
|
407 | + if ($x[1] >= $gi->databaseSegments) { |
|
408 | 408 | return $x[1]; |
409 | - } |
|
410 | - $offset = $x[1]; |
|
409 | + } |
|
410 | + $offset = $x[1]; |
|
411 | 411 | } else { |
412 | - if ($x[0] >= $gi->databaseSegments) { |
|
412 | + if ($x[0] >= $gi->databaseSegments) { |
|
413 | 413 | return $x[0]; |
414 | - } |
|
415 | - $offset = $x[0]; |
|
414 | + } |
|
415 | + $offset = $x[0]; |
|
416 | + } |
|
416 | 417 | } |
417 | - } |
|
418 | - trigger_error("error traversing database - perhaps it is corrupt?", E_USER_ERROR); |
|
419 | - return false; |
|
418 | + trigger_error("error traversing database - perhaps it is corrupt?", E_USER_ERROR); |
|
419 | + return false; |
|
420 | 420 | } |
421 | 421 | |
422 | 422 | function _get_org($gi,$ipnum){ |
423 | - $seek_org = _geoip_seek_country($gi,$ipnum); |
|
424 | - if ($seek_org == $gi->databaseSegments) { |
|
423 | + $seek_org = _geoip_seek_country($gi,$ipnum); |
|
424 | + if ($seek_org == $gi->databaseSegments) { |
|
425 | 425 | return NULL; |
426 | - } |
|
427 | - $record_pointer = $seek_org + (2 * $gi->record_length - 1) * $gi->databaseSegments; |
|
428 | - if ($gi->flags & GEOIP_SHARED_MEMORY) { |
|
426 | + } |
|
427 | + $record_pointer = $seek_org + (2 * $gi->record_length - 1) * $gi->databaseSegments; |
|
428 | + if ($gi->flags & GEOIP_SHARED_MEMORY) { |
|
429 | 429 | $org_buf = @shmop_read ($gi->shmid, $record_pointer, MAX_ORG_RECORD_LENGTH); |
430 | 430 | } else { |
431 | 431 | fseek($gi->filehandle, $record_pointer, SEEK_SET); |
432 | 432 | $org_buf = fread($gi->filehandle,MAX_ORG_RECORD_LENGTH); |
433 | - } |
|
434 | - $org_buf = substr($org_buf, 0, strpos($org_buf, 0)); |
|
435 | - return $org_buf; |
|
433 | + } |
|
434 | + $org_buf = substr($org_buf, 0, strpos($org_buf, 0)); |
|
435 | + return $org_buf; |
|
436 | 436 | } |
437 | 437 | |
438 | 438 | function geoip_org_by_addr ($gi,$addr) { |
439 | - if ($addr == NULL) { |
|
439 | + if ($addr == NULL) { |
|
440 | 440 | return 0; |
441 | - } |
|
442 | - $ipnum = ip2long($addr); |
|
443 | - return _get_org($gi, $ipnum); |
|
441 | + } |
|
442 | + $ipnum = ip2long($addr); |
|
443 | + return _get_org($gi, $ipnum); |
|
444 | 444 | } |
445 | 445 | |
446 | 446 | function _get_region($gi,$ipnum){ |
447 | - if ($gi->databaseType == GEOIP_REGION_EDITION_REV0){ |
|
447 | + if ($gi->databaseType == GEOIP_REGION_EDITION_REV0){ |
|
448 | 448 | $seek_region = _geoip_seek_country($gi,$ipnum) - GEOIP_STATE_BEGIN_REV0; |
449 | 449 | if ($seek_region >= 1000){ |
450 | - $country_code = "US"; |
|
451 | - $region = chr(($seek_region - 1000)/26 + 65) . chr(($seek_region - 1000)%26 + 65); |
|
450 | + $country_code = "US"; |
|
451 | + $region = chr(($seek_region - 1000)/26 + 65) . chr(($seek_region - 1000)%26 + 65); |
|
452 | 452 | } else { |
453 | 453 | $country_code = $gi->GEOIP_COUNTRY_CODES[$seek_region]; |
454 | - $region = ""; |
|
454 | + $region = ""; |
|
455 | 455 | } |
456 | - return array ($country_code,$region); |
|
456 | + return array ($country_code,$region); |
|
457 | 457 | } else if ($gi->databaseType == GEOIP_REGION_EDITION_REV1) { |
458 | 458 | $seek_region = _geoip_seek_country($gi,$ipnum) - GEOIP_STATE_BEGIN_REV1; |
459 | 459 | //print $seek_region; |
460 | 460 | if ($seek_region < US_OFFSET){ |
461 | - $country_code = ""; |
|
462 | - $region = ""; |
|
461 | + $country_code = ""; |
|
462 | + $region = ""; |
|
463 | 463 | } else if ($seek_region < CANADA_OFFSET) { |
464 | - $country_code = "US"; |
|
465 | - $region = chr(($seek_region - US_OFFSET)/26 + 65) . chr(($seek_region - US_OFFSET)%26 + 65); |
|
464 | + $country_code = "US"; |
|
465 | + $region = chr(($seek_region - US_OFFSET)/26 + 65) . chr(($seek_region - US_OFFSET)%26 + 65); |
|
466 | 466 | } else if ($seek_region < WORLD_OFFSET) { |
467 | - $country_code = "CA"; |
|
468 | - $region = chr(($seek_region - CANADA_OFFSET)/26 + 65) . chr(($seek_region - CANADA_OFFSET)%26 + 65); |
|
467 | + $country_code = "CA"; |
|
468 | + $region = chr(($seek_region - CANADA_OFFSET)/26 + 65) . chr(($seek_region - CANADA_OFFSET)%26 + 65); |
|
469 | 469 | } else { |
470 | 470 | $country_code = $gi->GEOIP_COUNTRY_CODES[($seek_region - WORLD_OFFSET) / FIPS_RANGE]; |
471 | - $region = ""; |
|
471 | + $region = ""; |
|
472 | + } |
|
473 | + return array ($country_code,$region); |
|
472 | 474 | } |
473 | - return array ($country_code,$region); |
|
474 | - } |
|
475 | 475 | } |
476 | 476 | |
477 | 477 | function geoip_region_by_addr ($gi,$addr) { |
478 | - if ($addr == NULL) { |
|
478 | + if ($addr == NULL) { |
|
479 | 479 | return 0; |
480 | - } |
|
481 | - $ipnum = ip2long($addr); |
|
482 | - return _get_region($gi, $ipnum); |
|
480 | + } |
|
481 | + $ipnum = ip2long($addr); |
|
482 | + return _get_region($gi, $ipnum); |
|
483 | 483 | } |
484 | 484 | |
485 | 485 | function getdnsattributes ($l,$ip){ |
486 | - $r = new Net_DNS_Resolver(); |
|
487 | - $r->nameservers = array("ws1.maxmind.com"); |
|
488 | - $p = $r->search($l."." . $ip .".s.maxmind.com","TXT","IN"); |
|
489 | - $str = is_object($p->answer[0])?$p->answer[0]->string():''; |
|
490 | - ereg("\"(.*)\"",$str,$regs); |
|
491 | - $str = $regs[1]; |
|
492 | - return $str; |
|
486 | + $r = new Net_DNS_Resolver(); |
|
487 | + $r->nameservers = array("ws1.maxmind.com"); |
|
488 | + $p = $r->search($l."." . $ip .".s.maxmind.com","TXT","IN"); |
|
489 | + $str = is_object($p->answer[0])?$p->answer[0]->string():''; |
|
490 | + ereg("\"(.*)\"",$str,$regs); |
|
491 | + $str = $regs[1]; |
|
492 | + return $str; |
|
493 | 493 | } |
494 | 494 | |
495 | 495 | ?> |
@@ -138,25 +138,25 @@ discard block |
||
138 | 138 | "VU", "WF", "WS", "YE", "YT", "CS", "ZA", "ZM", "ZR", "ZW", "A1", "A2", "O1" |
139 | 139 | ); |
140 | 140 | var $GEOIP_COUNTRY_CODES3 = array( |
141 | -"","AP","EU","AND","ARE","AFG","ATG","AIA","ALB","ARM","ANT","AGO","AQ","ARG", |
|
142 | -"ASM","AUT","AUS","ABW","AZE","BIH","BRB","BGD","BEL","BFA","BGR","BHR","BDI", |
|
143 | -"BEN","BMU","BRN","BOL","BRA","BHS","BTN","BV","BWA","BLR","BLZ","CAN","CC", |
|
144 | -"COD","CAF","COG","CHE","CIV","COK","CHL","CMR","CHN","COL","CRI","CUB","CPV", |
|
145 | -"CX","CYP","CZE","DEU","DJI","DNK","DMA","DOM","DZA","ECU","EST","EGY","ESH", |
|
146 | -"ERI","ESP","ETH","FIN","FJI","FLK","FSM","FRO","FRA","FX","GAB","GBR","GRD", |
|
147 | -"GEO","GUF","GHA","GIB","GRL","GMB","GIN","GLP","GNQ","GRC","GS","GTM","GUM", |
|
148 | -"GNB","GUY","HKG","HM","HND","HRV","HTI","HUN","IDN","IRL","ISR","IND","IO", |
|
149 | -"IRQ","IRN","ISL","ITA","JAM","JOR","JPN","KEN","KGZ","KHM","KIR","COM","KNA", |
|
150 | -"PRK","KOR","KWT","CYM","KAZ","LAO","LBN","LCA","LIE","LKA","LBR","LSO","LTU", |
|
151 | -"LUX","LVA","LBY","MAR","MCO","MDA","MDG","MHL","MKD","MLI","MMR","MNG","MAC", |
|
152 | -"MNP","MTQ","MRT","MSR","MLT","MUS","MDV","MWI","MEX","MYS","MOZ","NAM","NCL", |
|
153 | -"NER","NFK","NGA","NIC","NLD","NOR","NPL","NRU","NIU","NZL","OMN","PAN","PER", |
|
154 | -"PYF","PNG","PHL","PAK","POL","SPM","PCN","PRI","PSE","PRT","PLW","PRY","QAT", |
|
155 | -"REU","ROU","RUS","RWA","SAU","SLB","SYC","SDN","SWE","SGP","SHN","SVN","SJM", |
|
156 | -"SVK","SLE","SMR","SEN","SOM","SUR","STP","SLV","SYR","SWZ","TCA","TCD","TF", |
|
157 | -"TGO","THA","TJK","TKL","TLS","TKM","TUN","TON","TUR","TTO","TUV","TWN","TZA", |
|
158 | -"UKR","UGA","UM","USA","URY","UZB","VAT","VCT","VEN","VGB","VIR","VNM","VUT", |
|
159 | - "WLF","WSM","YEM","YT","SCG","ZAF","ZMB","ZR","ZWE","A1","A2","O1" |
|
141 | +"", "AP", "EU", "AND", "ARE", "AFG", "ATG", "AIA", "ALB", "ARM", "ANT", "AGO", "AQ", "ARG", |
|
142 | +"ASM", "AUT", "AUS", "ABW", "AZE", "BIH", "BRB", "BGD", "BEL", "BFA", "BGR", "BHR", "BDI", |
|
143 | +"BEN", "BMU", "BRN", "BOL", "BRA", "BHS", "BTN", "BV", "BWA", "BLR", "BLZ", "CAN", "CC", |
|
144 | +"COD", "CAF", "COG", "CHE", "CIV", "COK", "CHL", "CMR", "CHN", "COL", "CRI", "CUB", "CPV", |
|
145 | +"CX", "CYP", "CZE", "DEU", "DJI", "DNK", "DMA", "DOM", "DZA", "ECU", "EST", "EGY", "ESH", |
|
146 | +"ERI", "ESP", "ETH", "FIN", "FJI", "FLK", "FSM", "FRO", "FRA", "FX", "GAB", "GBR", "GRD", |
|
147 | +"GEO", "GUF", "GHA", "GIB", "GRL", "GMB", "GIN", "GLP", "GNQ", "GRC", "GS", "GTM", "GUM", |
|
148 | +"GNB", "GUY", "HKG", "HM", "HND", "HRV", "HTI", "HUN", "IDN", "IRL", "ISR", "IND", "IO", |
|
149 | +"IRQ", "IRN", "ISL", "ITA", "JAM", "JOR", "JPN", "KEN", "KGZ", "KHM", "KIR", "COM", "KNA", |
|
150 | +"PRK", "KOR", "KWT", "CYM", "KAZ", "LAO", "LBN", "LCA", "LIE", "LKA", "LBR", "LSO", "LTU", |
|
151 | +"LUX", "LVA", "LBY", "MAR", "MCO", "MDA", "MDG", "MHL", "MKD", "MLI", "MMR", "MNG", "MAC", |
|
152 | +"MNP", "MTQ", "MRT", "MSR", "MLT", "MUS", "MDV", "MWI", "MEX", "MYS", "MOZ", "NAM", "NCL", |
|
153 | +"NER", "NFK", "NGA", "NIC", "NLD", "NOR", "NPL", "NRU", "NIU", "NZL", "OMN", "PAN", "PER", |
|
154 | +"PYF", "PNG", "PHL", "PAK", "POL", "SPM", "PCN", "PRI", "PSE", "PRT", "PLW", "PRY", "QAT", |
|
155 | +"REU", "ROU", "RUS", "RWA", "SAU", "SLB", "SYC", "SDN", "SWE", "SGP", "SHN", "SVN", "SJM", |
|
156 | +"SVK", "SLE", "SMR", "SEN", "SOM", "SUR", "STP", "SLV", "SYR", "SWZ", "TCA", "TCD", "TF", |
|
157 | +"TGO", "THA", "TJK", "TKL", "TLS", "TKM", "TUN", "TON", "TUR", "TTO", "TUV", "TWN", "TZA", |
|
158 | +"UKR", "UGA", "UM", "USA", "URY", "UZB", "VAT", "VCT", "VEN", "VGB", "VIR", "VNM", "VUT", |
|
159 | + "WLF", "WSM", "YEM", "YT", "SCG", "ZAF", "ZMB", "ZR", "ZWE", "A1", "A2", "O1" |
|
160 | 160 | ); |
161 | 161 | var $GEOIP_COUNTRY_NAMES = array( |
162 | 162 | "", "Asia/Pacific Region", "Europe", "Andorra", "United Arab Emirates", |
@@ -208,10 +208,10 @@ discard block |
||
208 | 208 | Grenadines", "Venezuela", "Virgin Islands, British", "Virgin Islands, U.S.", |
209 | 209 | "Vietnam", "Vanuatu", "Wallis and Futuna", "Samoa", "Yemen", "Mayotte", |
210 | 210 | "Serbia and Montenegro", "South Africa", "Zambia", "Zaire", "Zimbabwe", |
211 | -"Anonymous Proxy","Satellite Provider","Other" |
|
211 | +"Anonymous Proxy", "Satellite Provider", "Other" |
|
212 | 212 | ); |
213 | 213 | } |
214 | -function geoip_load_shared_mem ($file) { |
|
214 | +function geoip_load_shared_mem($file) { |
|
215 | 215 | |
216 | 216 | $fp = fopen($file, "rb"); |
217 | 217 | if (!$fp) { |
@@ -220,42 +220,42 @@ discard block |
||
220 | 220 | } |
221 | 221 | $s_array = fstat($fp); |
222 | 222 | $size = $s_array['size']; |
223 | - if ($shmid = @shmop_open (GEOIP_SHM_KEY, "w", 0, 0)) { |
|
224 | - shmop_delete ($shmid); |
|
225 | - shmop_close ($shmid); |
|
223 | + if ($shmid = @shmop_open(GEOIP_SHM_KEY, "w", 0, 0)) { |
|
224 | + shmop_delete($shmid); |
|
225 | + shmop_close($shmid); |
|
226 | 226 | } |
227 | - $shmid = shmop_open (GEOIP_SHM_KEY, "c", 0644, $size); |
|
228 | - shmop_write ($shmid, fread($fp, $size), 0); |
|
229 | - shmop_close ($shmid); |
|
227 | + $shmid = shmop_open(GEOIP_SHM_KEY, "c", 0644, $size); |
|
228 | + shmop_write($shmid, fread($fp, $size), 0); |
|
229 | + shmop_close($shmid); |
|
230 | 230 | } |
231 | 231 | |
232 | -function _setup_segments($gi){ |
|
232 | +function _setup_segments($gi) { |
|
233 | 233 | $gi->databaseType = GEOIP_COUNTRY_EDITION; |
234 | 234 | $gi->record_length = STANDARD_RECORD_LENGTH; |
235 | - if ($gi->flags & GEOIP_SHARED_MEMORY) { |
|
236 | - $offset = @shmop_size ($gi->shmid) - 3; |
|
235 | + if ($gi->flags&GEOIP_SHARED_MEMORY) { |
|
236 | + $offset = @shmop_size($gi->shmid) - 3; |
|
237 | 237 | for ($i = 0; $i < STRUCTURE_INFO_MAX_SIZE; $i++) { |
238 | - $delim = @shmop_read ($gi->shmid, $offset, 3); |
|
238 | + $delim = @shmop_read($gi->shmid, $offset, 3); |
|
239 | 239 | $offset += 3; |
240 | 240 | if ($delim == (chr(255).chr(255).chr(255))) { |
241 | - $gi->databaseType = ord(@shmop_read ($gi->shmid, $offset, 1)); |
|
241 | + $gi->databaseType = ord(@shmop_read($gi->shmid, $offset, 1)); |
|
242 | 242 | $offset++; |
243 | 243 | |
244 | - if ($gi->databaseType == GEOIP_REGION_EDITION_REV0){ |
|
244 | + if ($gi->databaseType == GEOIP_REGION_EDITION_REV0) { |
|
245 | 245 | $gi->databaseSegments = GEOIP_STATE_BEGIN_REV0; |
246 | - } else if ($gi->databaseType == GEOIP_REGION_EDITION_REV1){ |
|
246 | + } else if ($gi->databaseType == GEOIP_REGION_EDITION_REV1) { |
|
247 | 247 | $gi->databaseSegments = GEOIP_STATE_BEGIN_REV1; |
248 | - } else if (($gi->databaseType == GEOIP_CITY_EDITION_REV0)|| |
|
248 | + } else if (($gi->databaseType == GEOIP_CITY_EDITION_REV0) || |
|
249 | 249 | ($gi->databaseType == GEOIP_CITY_EDITION_REV1) |
250 | 250 | || ($gi->databaseType == GEOIP_ORG_EDITION) |
251 | 251 | || ($gi->databaseType == GEOIP_ISP_EDITION) |
252 | - || ($gi->databaseType == GEOIP_ASNUM_EDITION)){ |
|
252 | + || ($gi->databaseType == GEOIP_ASNUM_EDITION)) { |
|
253 | 253 | $gi->databaseSegments = 0; |
254 | - $buf = @shmop_read ($gi->shmid, $offset, SEGMENT_RECORD_LENGTH); |
|
255 | - for ($j = 0;$j < SEGMENT_RECORD_LENGTH;$j++){ |
|
256 | - $gi->databaseSegments += (ord($buf[$j]) << ($j * 8)); |
|
254 | + $buf = @shmop_read($gi->shmid, $offset, SEGMENT_RECORD_LENGTH); |
|
255 | + for ($j = 0; $j < SEGMENT_RECORD_LENGTH; $j++) { |
|
256 | + $gi->databaseSegments += (ord($buf[$j]) << ($j*8)); |
|
257 | 257 | } |
258 | - if (($gi->databaseType == GEOIP_ORG_EDITION)|| |
|
258 | + if (($gi->databaseType == GEOIP_ORG_EDITION) || |
|
259 | 259 | ($gi->databaseType == GEOIP_ISP_EDITION)) { |
260 | 260 | $gi->record_length = ORG_RECORD_LENGTH; |
261 | 261 | } |
@@ -265,32 +265,32 @@ discard block |
||
265 | 265 | $offset -= 4; |
266 | 266 | } |
267 | 267 | } |
268 | - if (($gi->databaseType == GEOIP_COUNTRY_EDITION)|| |
|
269 | - ($gi->databaseType == GEOIP_PROXY_EDITION)|| |
|
270 | - ($gi->databaseType == GEOIP_NETSPEED_EDITION)){ |
|
268 | + if (($gi->databaseType == GEOIP_COUNTRY_EDITION) || |
|
269 | + ($gi->databaseType == GEOIP_PROXY_EDITION) || |
|
270 | + ($gi->databaseType == GEOIP_NETSPEED_EDITION)) { |
|
271 | 271 | $gi->databaseSegments = GEOIP_COUNTRY_BEGIN; |
272 | 272 | } |
273 | 273 | } else { |
274 | 274 | $filepos = ftell($gi->filehandle); |
275 | 275 | fseek($gi->filehandle, -3, SEEK_END); |
276 | 276 | for ($i = 0; $i < STRUCTURE_INFO_MAX_SIZE; $i++) { |
277 | - $delim = fread($gi->filehandle,3); |
|
278 | - if ($delim == (chr(255).chr(255).chr(255))){ |
|
279 | - $gi->databaseType = ord(fread($gi->filehandle,1)); |
|
280 | - if ($gi->databaseType == GEOIP_REGION_EDITION_REV0){ |
|
277 | + $delim = fread($gi->filehandle, 3); |
|
278 | + if ($delim == (chr(255).chr(255).chr(255))) { |
|
279 | + $gi->databaseType = ord(fread($gi->filehandle, 1)); |
|
280 | + if ($gi->databaseType == GEOIP_REGION_EDITION_REV0) { |
|
281 | 281 | $gi->databaseSegments = GEOIP_STATE_BEGIN_REV0; |
282 | 282 | } |
283 | - else if ($gi->databaseType == GEOIP_REGION_EDITION_REV1){ |
|
283 | + else if ($gi->databaseType == GEOIP_REGION_EDITION_REV1) { |
|
284 | 284 | $gi->databaseSegments = GEOIP_STATE_BEGIN_REV1; |
285 | - } else if (($gi->databaseType == GEOIP_CITY_EDITION_REV0) || |
|
285 | + } else if (($gi->databaseType == GEOIP_CITY_EDITION_REV0) || |
|
286 | 286 | ($gi->databaseType == GEOIP_CITY_EDITION_REV1) || |
287 | 287 | ($gi->databaseType == GEOIP_ORG_EDITION) || |
288 | 288 | ($gi->databaseType == GEOIP_ISP_EDITION) || |
289 | - ($gi->databaseType == GEOIP_ASNUM_EDITION)){ |
|
289 | + ($gi->databaseType == GEOIP_ASNUM_EDITION)) { |
|
290 | 290 | $gi->databaseSegments = 0; |
291 | - $buf = fread($gi->filehandle,SEGMENT_RECORD_LENGTH); |
|
292 | - for ($j = 0;$j < SEGMENT_RECORD_LENGTH;$j++){ |
|
293 | - $gi->databaseSegments += (ord($buf[$j]) << ($j * 8)); |
|
291 | + $buf = fread($gi->filehandle, SEGMENT_RECORD_LENGTH); |
|
292 | + for ($j = 0; $j < SEGMENT_RECORD_LENGTH; $j++) { |
|
293 | + $gi->databaseSegments += (ord($buf[$j]) << ($j*8)); |
|
294 | 294 | } |
295 | 295 | if ($gi->databaseType == GEOIP_ORG_EDITION) { |
296 | 296 | $gi->record_length = ORG_RECORD_LENGTH; |
@@ -301,12 +301,12 @@ discard block |
||
301 | 301 | fseek($gi->filehandle, -4, SEEK_CUR); |
302 | 302 | } |
303 | 303 | } |
304 | - if (($gi->databaseType == GEOIP_COUNTRY_EDITION)|| |
|
305 | - ($gi->databaseType == GEOIP_PROXY_EDITION)|| |
|
306 | - ($gi->databaseType == GEOIP_NETSPEED_EDITION)){ |
|
304 | + if (($gi->databaseType == GEOIP_COUNTRY_EDITION) || |
|
305 | + ($gi->databaseType == GEOIP_PROXY_EDITION) || |
|
306 | + ($gi->databaseType == GEOIP_NETSPEED_EDITION)) { |
|
307 | 307 | $gi->databaseSegments = GEOIP_COUNTRY_BEGIN; |
308 | 308 | } |
309 | - fseek($gi->filehandle,$filepos,SEEK_SET); |
|
309 | + fseek($gi->filehandle, $filepos, SEEK_SET); |
|
310 | 310 | } |
311 | 311 | return $gi; |
312 | 312 | } |
@@ -314,11 +314,11 @@ discard block |
||
314 | 314 | function geoip_open($filename, $flags) { |
315 | 315 | $gi = new GeoIP; |
316 | 316 | $gi->flags = $flags; |
317 | - if ($gi->flags & GEOIP_SHARED_MEMORY) { |
|
318 | - $gi->shmid = @shmop_open (GEOIP_SHM_KEY, "a", 0, 0); |
|
317 | + if ($gi->flags&GEOIP_SHARED_MEMORY) { |
|
318 | + $gi->shmid = @shmop_open(GEOIP_SHM_KEY, "a", 0, 0); |
|
319 | 319 | } else { |
320 | - $gi->filehandle = fopen($filename,"rb"); |
|
321 | - if ($gi->flags & GEOIP_MEMORY_CACHE) { |
|
320 | + $gi->filehandle = fopen($filename, "rb"); |
|
321 | + if ($gi->flags&GEOIP_MEMORY_CACHE) { |
|
322 | 322 | $s_array = fstat($gi->filehandle); |
323 | 323 | $gi->memory_buffer = fread($gi->filehandle, $s_array[size]); |
324 | 324 | } |
@@ -329,7 +329,7 @@ discard block |
||
329 | 329 | } |
330 | 330 | |
331 | 331 | function geoip_close($gi) { |
332 | - if ($gi->flags & GEOIP_SHARED_MEMORY) { |
|
332 | + if ($gi->flags&GEOIP_SHARED_MEMORY) { |
|
333 | 333 | return true; |
334 | 334 | } |
335 | 335 | |
@@ -345,7 +345,7 @@ discard block |
||
345 | 345 | } |
346 | 346 | |
347 | 347 | function geoip_country_code_by_name($gi, $name) { |
348 | - $country_id = geoip_country_id_by_name($gi,$name); |
|
348 | + $country_id = geoip_country_id_by_name($gi, $name); |
|
349 | 349 | if ($country_id !== false) { |
350 | 350 | return $gi->GEOIP_COUNTRY_CODES[$country_id]; |
351 | 351 | } |
@@ -353,7 +353,7 @@ discard block |
||
353 | 353 | } |
354 | 354 | |
355 | 355 | function geoip_country_name_by_name($gi, $name) { |
356 | - $country_id = geoip_country_id_by_name($gi,$name); |
|
356 | + $country_id = geoip_country_id_by_name($gi, $name); |
|
357 | 357 | if ($country_id !== false) { |
358 | 358 | return $gi->GEOIP_COUNTRY_NAMES[$country_id]; |
359 | 359 | } |
@@ -366,7 +366,7 @@ discard block |
||
366 | 366 | } |
367 | 367 | |
368 | 368 | function geoip_country_code_by_addr($gi, $addr) { |
369 | - $country_id = geoip_country_id_by_addr($gi,$addr); |
|
369 | + $country_id = geoip_country_id_by_addr($gi, $addr); |
|
370 | 370 | if ($country_id !== false) { |
371 | 371 | return $gi->GEOIP_COUNTRY_CODES[$country_id]; |
372 | 372 | } |
@@ -374,7 +374,7 @@ discard block |
||
374 | 374 | } |
375 | 375 | |
376 | 376 | function geoip_country_name_by_addr($gi, $addr) { |
377 | - $country_id = geoip_country_id_by_addr($gi,$addr); |
|
377 | + $country_id = geoip_country_id_by_addr($gi, $addr); |
|
378 | 378 | if ($country_id !== false) { |
379 | 379 | return $gi->GEOIP_COUNTRY_NAMES[$country_id]; |
380 | 380 | } |
@@ -384,26 +384,26 @@ discard block |
||
384 | 384 | function _geoip_seek_country($gi, $ipnum) { |
385 | 385 | $offset = 0; |
386 | 386 | for ($depth = 31; $depth >= 0; --$depth) { |
387 | - if ($gi->flags & GEOIP_MEMORY_CACHE) { |
|
387 | + if ($gi->flags&GEOIP_MEMORY_CACHE) { |
|
388 | 388 | $buf = substr($gi->memory_buffer, |
389 | - 2 * $gi->record_length * $offset, |
|
390 | - 2 * $gi->record_length); |
|
391 | - } elseif ($gi->flags & GEOIP_SHARED_MEMORY) { |
|
392 | - $buf = @shmop_read ($gi->shmid, |
|
393 | - 2 * $gi->record_length * $offset, |
|
394 | - 2 * $gi->record_length ); |
|
389 | + 2*$gi->record_length*$offset, |
|
390 | + 2*$gi->record_length); |
|
391 | + } elseif ($gi->flags&GEOIP_SHARED_MEMORY) { |
|
392 | + $buf = @shmop_read($gi->shmid, |
|
393 | + 2*$gi->record_length*$offset, |
|
394 | + 2*$gi->record_length); |
|
395 | 395 | } else { |
396 | - fseek($gi->filehandle, 2 * $gi->record_length * $offset, SEEK_SET) == 0 |
|
396 | + fseek($gi->filehandle, 2*$gi->record_length*$offset, SEEK_SET) == 0 |
|
397 | 397 | or die("fseek failed"); |
398 | - $buf = fread($gi->filehandle, 2 * $gi->record_length); |
|
398 | + $buf = fread($gi->filehandle, 2*$gi->record_length); |
|
399 | 399 | } |
400 | - $x = array(0,0); |
|
400 | + $x = array(0, 0); |
|
401 | 401 | for ($i = 0; $i < 2; ++$i) { |
402 | 402 | for ($j = 0; $j < $gi->record_length; ++$j) { |
403 | - $x[$i] += ord($buf[$gi->record_length * $i + $j]) << ($j * 8); |
|
403 | + $x[$i] += ord($buf[$gi->record_length*$i + $j]) << ($j*8); |
|
404 | 404 | } |
405 | 405 | } |
406 | - if ($ipnum & (1 << $depth)) { |
|
406 | + if ($ipnum&(1 << $depth)) { |
|
407 | 407 | if ($x[1] >= $gi->databaseSegments) { |
408 | 408 | return $x[1]; |
409 | 409 | } |
@@ -419,23 +419,23 @@ discard block |
||
419 | 419 | return false; |
420 | 420 | } |
421 | 421 | |
422 | -function _get_org($gi,$ipnum){ |
|
423 | - $seek_org = _geoip_seek_country($gi,$ipnum); |
|
422 | +function _get_org($gi, $ipnum) { |
|
423 | + $seek_org = _geoip_seek_country($gi, $ipnum); |
|
424 | 424 | if ($seek_org == $gi->databaseSegments) { |
425 | 425 | return NULL; |
426 | 426 | } |
427 | - $record_pointer = $seek_org + (2 * $gi->record_length - 1) * $gi->databaseSegments; |
|
428 | - if ($gi->flags & GEOIP_SHARED_MEMORY) { |
|
429 | - $org_buf = @shmop_read ($gi->shmid, $record_pointer, MAX_ORG_RECORD_LENGTH); |
|
427 | + $record_pointer = $seek_org + (2*$gi->record_length - 1)*$gi->databaseSegments; |
|
428 | + if ($gi->flags&GEOIP_SHARED_MEMORY) { |
|
429 | + $org_buf = @shmop_read($gi->shmid, $record_pointer, MAX_ORG_RECORD_LENGTH); |
|
430 | 430 | } else { |
431 | 431 | fseek($gi->filehandle, $record_pointer, SEEK_SET); |
432 | - $org_buf = fread($gi->filehandle,MAX_ORG_RECORD_LENGTH); |
|
432 | + $org_buf = fread($gi->filehandle, MAX_ORG_RECORD_LENGTH); |
|
433 | 433 | } |
434 | 434 | $org_buf = substr($org_buf, 0, strpos($org_buf, 0)); |
435 | 435 | return $org_buf; |
436 | 436 | } |
437 | 437 | |
438 | -function geoip_org_by_addr ($gi,$addr) { |
|
438 | +function geoip_org_by_addr($gi, $addr) { |
|
439 | 439 | if ($addr == NULL) { |
440 | 440 | return 0; |
441 | 441 | } |
@@ -443,38 +443,38 @@ discard block |
||
443 | 443 | return _get_org($gi, $ipnum); |
444 | 444 | } |
445 | 445 | |
446 | -function _get_region($gi,$ipnum){ |
|
447 | - if ($gi->databaseType == GEOIP_REGION_EDITION_REV0){ |
|
448 | - $seek_region = _geoip_seek_country($gi,$ipnum) - GEOIP_STATE_BEGIN_REV0; |
|
449 | - if ($seek_region >= 1000){ |
|
446 | +function _get_region($gi, $ipnum) { |
|
447 | + if ($gi->databaseType == GEOIP_REGION_EDITION_REV0) { |
|
448 | + $seek_region = _geoip_seek_country($gi, $ipnum) - GEOIP_STATE_BEGIN_REV0; |
|
449 | + if ($seek_region >= 1000) { |
|
450 | 450 | $country_code = "US"; |
451 | - $region = chr(($seek_region - 1000)/26 + 65) . chr(($seek_region - 1000)%26 + 65); |
|
451 | + $region = chr(($seek_region - 1000)/26 + 65).chr(($seek_region - 1000)%26 + 65); |
|
452 | 452 | } else { |
453 | 453 | $country_code = $gi->GEOIP_COUNTRY_CODES[$seek_region]; |
454 | 454 | $region = ""; |
455 | 455 | } |
456 | - return array ($country_code,$region); |
|
457 | - } else if ($gi->databaseType == GEOIP_REGION_EDITION_REV1) { |
|
458 | - $seek_region = _geoip_seek_country($gi,$ipnum) - GEOIP_STATE_BEGIN_REV1; |
|
456 | + return array($country_code, $region); |
|
457 | + } else if ($gi->databaseType == GEOIP_REGION_EDITION_REV1) { |
|
458 | + $seek_region = _geoip_seek_country($gi, $ipnum) - GEOIP_STATE_BEGIN_REV1; |
|
459 | 459 | //print $seek_region; |
460 | - if ($seek_region < US_OFFSET){ |
|
460 | + if ($seek_region < US_OFFSET) { |
|
461 | 461 | $country_code = ""; |
462 | 462 | $region = ""; |
463 | 463 | } else if ($seek_region < CANADA_OFFSET) { |
464 | 464 | $country_code = "US"; |
465 | - $region = chr(($seek_region - US_OFFSET)/26 + 65) . chr(($seek_region - US_OFFSET)%26 + 65); |
|
465 | + $region = chr(($seek_region - US_OFFSET)/26 + 65).chr(($seek_region - US_OFFSET)%26 + 65); |
|
466 | 466 | } else if ($seek_region < WORLD_OFFSET) { |
467 | 467 | $country_code = "CA"; |
468 | - $region = chr(($seek_region - CANADA_OFFSET)/26 + 65) . chr(($seek_region - CANADA_OFFSET)%26 + 65); |
|
468 | + $region = chr(($seek_region - CANADA_OFFSET)/26 + 65).chr(($seek_region - CANADA_OFFSET)%26 + 65); |
|
469 | 469 | } else { |
470 | - $country_code = $gi->GEOIP_COUNTRY_CODES[($seek_region - WORLD_OFFSET) / FIPS_RANGE]; |
|
470 | + $country_code = $gi->GEOIP_COUNTRY_CODES[($seek_region - WORLD_OFFSET)/FIPS_RANGE]; |
|
471 | 471 | $region = ""; |
472 | 472 | } |
473 | - return array ($country_code,$region); |
|
473 | + return array($country_code, $region); |
|
474 | 474 | } |
475 | 475 | } |
476 | 476 | |
477 | -function geoip_region_by_addr ($gi,$addr) { |
|
477 | +function geoip_region_by_addr($gi, $addr) { |
|
478 | 478 | if ($addr == NULL) { |
479 | 479 | return 0; |
480 | 480 | } |
@@ -482,12 +482,12 @@ discard block |
||
482 | 482 | return _get_region($gi, $ipnum); |
483 | 483 | } |
484 | 484 | |
485 | -function getdnsattributes ($l,$ip){ |
|
485 | +function getdnsattributes($l, $ip) { |
|
486 | 486 | $r = new Net_DNS_Resolver(); |
487 | 487 | $r->nameservers = array("ws1.maxmind.com"); |
488 | - $p = $r->search($l."." . $ip .".s.maxmind.com","TXT","IN"); |
|
489 | - $str = is_object($p->answer[0])?$p->answer[0]->string():''; |
|
490 | - ereg("\"(.*)\"",$str,$regs); |
|
488 | + $p = $r->search($l.".".$ip.".s.maxmind.com", "TXT", "IN"); |
|
489 | + $str = is_object($p->answer[0]) ? $p->answer[0]->string() : ''; |
|
490 | + ereg("\"(.*)\"", $str, $regs); |
|
491 | 491 | $str = $regs[1]; |
492 | 492 | return $str; |
493 | 493 | } |
@@ -279,10 +279,9 @@ discard block |
||
279 | 279 | $gi->databaseType = ord(fread($gi->filehandle,1)); |
280 | 280 | if ($gi->databaseType == GEOIP_REGION_EDITION_REV0){ |
281 | 281 | $gi->databaseSegments = GEOIP_STATE_BEGIN_REV0; |
282 | - } |
|
283 | - else if ($gi->databaseType == GEOIP_REGION_EDITION_REV1){ |
|
282 | + } else if ($gi->databaseType == GEOIP_REGION_EDITION_REV1){ |
|
284 | 283 | $gi->databaseSegments = GEOIP_STATE_BEGIN_REV1; |
285 | - } else if (($gi->databaseType == GEOIP_CITY_EDITION_REV0) || |
|
284 | + } else if (($gi->databaseType == GEOIP_CITY_EDITION_REV0) || |
|
286 | 285 | ($gi->databaseType == GEOIP_CITY_EDITION_REV1) || |
287 | 286 | ($gi->databaseType == GEOIP_ORG_EDITION) || |
288 | 287 | ($gi->databaseType == GEOIP_ISP_EDITION) || |
@@ -454,7 +453,7 @@ discard block |
||
454 | 453 | $region = ""; |
455 | 454 | } |
456 | 455 | return array ($country_code,$region); |
457 | - } else if ($gi->databaseType == GEOIP_REGION_EDITION_REV1) { |
|
456 | + } else if ($gi->databaseType == GEOIP_REGION_EDITION_REV1) { |
|
458 | 457 | $seek_region = _geoip_seek_country($gi,$ipnum) - GEOIP_STATE_BEGIN_REV1; |
459 | 458 | //print $seek_region; |
460 | 459 | if ($seek_region < US_OFFSET){ |
@@ -324,6 +324,11 @@ discard block |
||
324 | 324 | // so it's OK to show the domain name etc. |
325 | 325 | // If private is false, show the owner's name only if they've given permission |
326 | 326 | // |
327 | +/** |
|
328 | + * @param integer $i |
|
329 | + * @param boolean $show_owner |
|
330 | + * @param boolean $any_product_name |
|
331 | + */ |
|
327 | 332 | function show_host_row($host, $i, $private, $show_owner, $any_product_name) { |
328 | 333 | $anonymous = false; |
329 | 334 | if (!$private) { |
@@ -503,6 +508,9 @@ discard block |
||
503 | 508 | // that their time intervals are disjoint. |
504 | 509 | // So the CPU/OS checks don't have to be very strict. |
505 | 510 | // |
511 | +/** |
|
512 | + * @param boolean $show_detail |
|
513 | + */ |
|
506 | 514 | function hosts_compatible($host1, $host2, $show_detail) { |
507 | 515 | // A host is "new" if it has no credit and no results. |
508 | 516 | // Skip disjoint-time check if one host or other is new |
@@ -642,6 +650,9 @@ discard block |
||
642 | 650 | return "hosts_user.php?sort=$sort&rev=$rev&show_all=$show_all$x"; |
643 | 651 | } |
644 | 652 | |
653 | +/** |
|
654 | + * @param string $sort |
|
655 | + */ |
|
645 | 656 | function link_url_rev($actual_sort, $sort, $rev, $show_all) { |
646 | 657 | if ($actual_sort == $sort) { |
647 | 658 | $rev = 1 - $rev; |
@@ -661,6 +672,9 @@ discard block |
||
661 | 672 | echo "<p>"; |
662 | 673 | } |
663 | 674 | |
675 | +/** |
|
676 | + * @param boolean $any_product_name |
|
677 | + */ |
|
664 | 678 | function user_host_table_start( |
665 | 679 | $private, $sort, $rev, $show_all, $any_product_name |
666 | 680 | ) { |
@@ -32,12 +32,12 @@ discard block |
||
32 | 32 | |
33 | 33 | function sched_log_name($x) { |
34 | 34 | if ($x == 0) return "NO_SUCH_LOG"; |
35 | - return gmdate('Y-m-d_H/Y-m-d_H:i', $x) . ".txt"; |
|
35 | + return gmdate('Y-m-d_H/Y-m-d_H:i', $x).".txt"; |
|
36 | 36 | } |
37 | 37 | |
38 | 38 | function sched_log_link($x) { |
39 | 39 | if (file_exists("sched_logs")) { |
40 | - return "<a href=\"../sched_logs/" . sched_log_name($x) . "\">" . time_str($x) . "</a>"; |
|
40 | + return "<a href=\"../sched_logs/".sched_log_name($x)."\">".time_str($x)."</a>"; |
|
41 | 41 | } else { |
42 | 42 | return time_str($x); |
43 | 43 | } |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | |
46 | 46 | function location_form($host) { |
47 | 47 | $none = "selected"; |
48 | - $h=$w=$s=$m=""; |
|
48 | + $h = $w = $s = $m = ""; |
|
49 | 49 | if ($host->venue == "home") $h = "selected"; |
50 | 50 | if ($host->venue == "work") $w = "selected"; |
51 | 51 | if ($host->venue == "school") $s = "selected"; |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | row2(tra("Product name"), $host->product_name); |
99 | 99 | } |
100 | 100 | $x = $host->timezone/3600; |
101 | - if ($x >= 0) $x="+$x"; |
|
101 | + if ($x >= 0) $x = "+$x"; |
|
102 | 102 | row2(tra("Local Standard Time"), tra("UTC %1 hours", $x)); |
103 | 103 | } else { |
104 | 104 | $owner = BoincUser::lookup_id($host->userid); |
@@ -256,7 +256,7 @@ discard block |
||
256 | 256 | if ($d[0] == "BOINC") continue; |
257 | 257 | if ($d[0] == "vbox") continue; |
258 | 258 | if ($str) $str .= "<p>"; |
259 | - if ($d[2]!="" && $d[2]!="1") $str .= "[".$d[2]."] "; |
|
259 | + if ($d[2] != "" && $d[2] != "1") $str .= "[".$d[2]."] "; |
|
260 | 260 | if ($d[0] == "CUDA") { |
261 | 261 | $str .= "NVIDIA"; |
262 | 262 | } else if ($d[0] == "CAL") { |
@@ -449,14 +449,14 @@ discard block |
||
449 | 449 | if ($pos1 === false) return $x; |
450 | 450 | $pos2 = strpos($model, ']'); |
451 | 451 | if ($pos2 === false) return $x; |
452 | - $a = substr($model, $pos1+1, $pos2-$pos1-1); |
|
452 | + $a = substr($model, $pos1 + 1, $pos2 - $pos1 - 1); |
|
453 | 453 | $y = explode(" ", $a); |
454 | 454 | if (count($y) == 0) return $x; |
455 | 455 | if ($y[0] == "Family") { |
456 | 456 | $x->info = $a; |
457 | 457 | } else { |
458 | 458 | $x->arch = $y[0]; |
459 | - $x->info = substr($a, strlen($y[0])+1); |
|
459 | + $x->info = substr($a, strlen($y[0]) + 1); |
|
460 | 460 | } |
461 | 461 | return $x; |
462 | 462 | } |
@@ -545,7 +545,7 @@ discard block |
||
545 | 545 | $avg_time = 0; |
546 | 546 | |
547 | 547 | $results = BoincResult::enum("hostid=$hostid order by received_time"); |
548 | - foreach($results as $result) { |
|
548 | + foreach ($results as $result) { |
|
549 | 549 | if ($result->granted_credit <= 0) continue; |
550 | 550 | $total += $result->granted_credit; |
551 | 551 | |
@@ -638,7 +638,7 @@ discard block |
||
638 | 638 | |
639 | 639 | function link_url($sort, $rev, $show_all) { |
640 | 640 | global $userid; |
641 | - $x = $userid ? "&userid=$userid":""; |
|
641 | + $x = $userid ? "&userid=$userid" : ""; |
|
642 | 642 | return "hosts_user.php?sort=$sort&rev=$rev&show_all=$show_all$x"; |
643 | 643 | } |
644 | 644 | |
@@ -710,7 +710,7 @@ discard block |
||
710 | 710 | } |
711 | 711 | |
712 | 712 | function show_user_hosts($userid, $private, $show_all, $sort, $rev) { |
713 | - $desc = false; // whether the sort order's default is decreasing |
|
713 | + $desc = false; // whether the sort order's default is decreasing |
|
714 | 714 | switch ($sort) { |
715 | 715 | case "total_credit": $sort_clause = "total_credit"; $desc = true; break; |
716 | 716 | case "expavg_credit": $sort_clause = "expavg_credit"; $desc = true; break; |
@@ -733,7 +733,7 @@ discard block |
||
733 | 733 | more_or_less($sort, $rev, $show_all); |
734 | 734 | |
735 | 735 | $now = time(); |
736 | - $old_hosts=0; |
|
736 | + $old_hosts = 0; |
|
737 | 737 | $i = 1; |
738 | 738 | $hosts = BoincHost::enum("userid=$userid order by $sort_clause"); |
739 | 739 | $any_product_name = false; |
@@ -745,9 +745,9 @@ discard block |
||
745 | 745 | } |
746 | 746 | user_host_table_start($private, $sort, $rev, $show_all, $any_product_name); |
747 | 747 | foreach ($hosts as $host) { |
748 | - $is_old=false; |
|
748 | + $is_old = false; |
|
749 | 749 | if (($now - $host->rpc_time) > 30*86400) { |
750 | - $is_old=true; |
|
750 | + $is_old = true; |
|
751 | 751 | $old_hosts++; |
752 | 752 | } |
753 | 753 | if (!$show_all && $is_old) continue; |
@@ -756,7 +756,7 @@ discard block |
||
756 | 756 | } |
757 | 757 | end_table(); |
758 | 758 | |
759 | - if ($old_hosts>0) { |
|
759 | + if ($old_hosts > 0) { |
|
760 | 760 | more_or_less($sort, $rev, $show_all); |
761 | 761 | } |
762 | 762 | |
@@ -776,6 +776,6 @@ discard block |
||
776 | 776 | } |
777 | 777 | } |
778 | 778 | |
779 | -$cvs_version_tracker[]="\$Id$"; //Generated automatically - do not edit |
|
779 | +$cvs_version_tracker[] = "\$Id$"; //Generated automatically - do not edit |
|
780 | 780 | |
781 | 781 | ?> |
@@ -22,16 +22,24 @@ discard block |
||
22 | 22 | require_once("../inc/user.inc"); |
23 | 23 | |
24 | 24 | function link_to_results($host) { |
25 | - if (!$host) return tra("No host"); |
|
25 | + if (!$host) { |
|
26 | + return tra("No host"); |
|
27 | + } |
|
26 | 28 | $config = get_config(); |
27 | - if (!parse_bool($config, "show_results")) return tra("Unavailable"); |
|
29 | + if (!parse_bool($config, "show_results")) { |
|
30 | + return tra("Unavailable"); |
|
31 | + } |
|
28 | 32 | $nresults = host_nresults($host); |
29 | - if (!$nresults) return "0"; |
|
33 | + if (!$nresults) { |
|
34 | + return "0"; |
|
35 | + } |
|
30 | 36 | return "<a href=results.php?hostid=$host->id>$nresults</a>"; |
31 | 37 | } |
32 | 38 | |
33 | 39 | function sched_log_name($x) { |
34 | - if ($x == 0) return "NO_SUCH_LOG"; |
|
40 | + if ($x == 0) { |
|
41 | + return "NO_SUCH_LOG"; |
|
42 | + } |
|
35 | 43 | return gmdate('Y-m-d_H/Y-m-d_H:i', $x) . ".txt"; |
36 | 44 | } |
37 | 45 | |
@@ -46,9 +54,15 @@ discard block |
||
46 | 54 | function location_form($host) { |
47 | 55 | $none = "selected"; |
48 | 56 | $h=$w=$s=$m=""; |
49 | - if ($host->venue == "home") $h = "selected"; |
|
50 | - if ($host->venue == "work") $w = "selected"; |
|
51 | - if ($host->venue == "school") $s = "selected"; |
|
57 | + if ($host->venue == "home") { |
|
58 | + $h = "selected"; |
|
59 | + } |
|
60 | + if ($host->venue == "work") { |
|
61 | + $w = "selected"; |
|
62 | + } |
|
63 | + if ($host->venue == "school") { |
|
64 | + $s = "selected"; |
|
65 | + } |
|
52 | 66 | $x = "<form action=host_venue_action.php> |
53 | 67 | <input type=hidden name=hostid value=$host->id> |
54 | 68 | <select class=\"form-control\" name=venue> |
@@ -98,7 +112,9 @@ discard block |
||
98 | 112 | row2(tra("Product name"), $host->product_name); |
99 | 113 | } |
100 | 114 | $x = $host->timezone/3600; |
101 | - if ($x >= 0) $x="+$x"; |
|
115 | + if ($x >= 0) { |
|
116 | + $x="+$x"; |
|
117 | + } |
|
102 | 118 | row2(tra("Local Standard Time"), tra("UTC %1 hours", $x)); |
103 | 119 | } else { |
104 | 120 | $owner = BoincUser::lookup_id($host->userid); |
@@ -253,10 +269,18 @@ discard block |
||
253 | 269 | $desc = trim($desc, "["); |
254 | 270 | $d = explode("|", $desc); |
255 | 271 | //print_r($d); |
256 | - if ($d[0] == "BOINC") continue; |
|
257 | - if ($d[0] == "vbox") continue; |
|
258 | - if ($str) $str .= "<p>"; |
|
259 | - if ($d[2]!="" && $d[2]!="1") $str .= "[".$d[2]."] "; |
|
272 | + if ($d[0] == "BOINC") { |
|
273 | + continue; |
|
274 | + } |
|
275 | + if ($d[0] == "vbox") { |
|
276 | + continue; |
|
277 | + } |
|
278 | + if ($str) { |
|
279 | + $str .= "<p>"; |
|
280 | + } |
|
281 | + if ($d[2]!="" && $d[2]!="1") { |
|
282 | + $str .= "[".$d[2]."] "; |
|
283 | + } |
|
260 | 284 | if ($d[0] == "CUDA") { |
261 | 285 | $str .= "NVIDIA"; |
262 | 286 | } else if ($d[0] == "CAL") { |
@@ -297,7 +321,9 @@ discard block |
||
297 | 321 | |
298 | 322 | |
299 | 323 | } |
300 | - if (!$str) $str = "---"; |
|
324 | + if (!$str) { |
|
325 | + $str = "---"; |
|
326 | + } |
|
301 | 327 | return $str; |
302 | 328 | } |
303 | 329 | |
@@ -305,7 +331,9 @@ discard block |
||
305 | 331 | // |
306 | 332 | function boinc_version($x) { |
307 | 333 | $y = strstr($x, 'BOINC'); |
308 | - if (!$y) return ''; |
|
334 | + if (!$y) { |
|
335 | + return ''; |
|
336 | + } |
|
309 | 337 | $z = explode("]", $y, 2); |
310 | 338 | $a = explode('|', $z[0]); |
311 | 339 | $v = $a[1]; |
@@ -442,16 +470,26 @@ discard block |
||
442 | 470 | $x->arch = null; |
443 | 471 | $x->info = null; |
444 | 472 | foreach ($y as $z) { |
445 | - if (strstr($z, "GHz")) $x->speed = $z; |
|
446 | - if (strstr($z, "MHz")) $x->speed = $z; |
|
473 | + if (strstr($z, "GHz")) { |
|
474 | + $x->speed = $z; |
|
475 | + } |
|
476 | + if (strstr($z, "MHz")) { |
|
477 | + $x->speed = $z; |
|
478 | + } |
|
447 | 479 | } |
448 | 480 | $pos1 = strpos($model, '['); |
449 | - if ($pos1 === false) return $x; |
|
481 | + if ($pos1 === false) { |
|
482 | + return $x; |
|
483 | + } |
|
450 | 484 | $pos2 = strpos($model, ']'); |
451 | - if ($pos2 === false) return $x; |
|
485 | + if ($pos2 === false) { |
|
486 | + return $x; |
|
487 | + } |
|
452 | 488 | $a = substr($model, $pos1+1, $pos2-$pos1-1); |
453 | 489 | $y = explode(" ", $a); |
454 | - if (count($y) == 0) return $x; |
|
490 | + if (count($y) == 0) { |
|
491 | + return $x; |
|
492 | + } |
|
455 | 493 | if ($y[0] == "Family") { |
456 | 494 | $x->info = $a; |
457 | 495 | } else { |
@@ -462,38 +500,64 @@ discard block |
||
462 | 500 | } |
463 | 501 | |
464 | 502 | function cpus_compatible($host1, $host2) { |
465 | - if ($host1->p_ncpus != $host2->p_ncpus) return false; |
|
466 | - if ($host1->p_vendor != $host2->p_vendor) return false; |
|
503 | + if ($host1->p_ncpus != $host2->p_ncpus) { |
|
504 | + return false; |
|
505 | + } |
|
506 | + if ($host1->p_vendor != $host2->p_vendor) { |
|
507 | + return false; |
|
508 | + } |
|
467 | 509 | $x1 = parse_model($host1->p_model); |
468 | 510 | $x2 = parse_model($host2->p_model); |
469 | 511 | if ($x1->info && $x2->info) { |
470 | - if ($x1->info != $x2->info) return false; |
|
512 | + if ($x1->info != $x2->info) { |
|
513 | + return false; |
|
514 | + } |
|
471 | 515 | if ($x1->speed && $x2->speed) { |
472 | - if ($x1->speed != $x2->speed) return false; |
|
516 | + if ($x1->speed != $x2->speed) { |
|
517 | + return false; |
|
518 | + } |
|
473 | 519 | } |
474 | 520 | if ($x1->arch && $x2->arch) { |
475 | - if ($x1->arch != $x2->arch) return false; |
|
521 | + if ($x1->arch != $x2->arch) { |
|
522 | + return false; |
|
523 | + } |
|
476 | 524 | } |
477 | 525 | return true; |
478 | 526 | } |
479 | - if ($host1->p_model != $host2->p_model) return false; |
|
527 | + if ($host1->p_model != $host2->p_model) { |
|
528 | + return false; |
|
529 | + } |
|
480 | 530 | return true; |
481 | 531 | } |
482 | 532 | |
483 | 533 | // does one host strictly precede the other? |
484 | 534 | // |
485 | 535 | function times_disjoint($host1, $host2) { |
486 | - if ($host1->rpc_time < $host2->create_time) return true; |
|
487 | - if ($host2->rpc_time < $host1->create_time) return true; |
|
536 | + if ($host1->rpc_time < $host2->create_time) { |
|
537 | + return true; |
|
538 | + } |
|
539 | + if ($host2->rpc_time < $host1->create_time) { |
|
540 | + return true; |
|
541 | + } |
|
488 | 542 | return false; |
489 | 543 | } |
490 | 544 | |
491 | 545 | function os_compatible($host1, $host2) { |
492 | - if (strstr($host1->os_name, "Windows") && strstr($host2->os_name, "Windows")) return true; |
|
493 | - if (strstr($host1->os_name, "Linux") && strstr($host2->os_name, "Linux")) return true; |
|
494 | - if (strstr($host1->os_name, "Darwin") && strstr($host2->os_name, "Darwin")) return true; |
|
495 | - if (strstr($host1->os_name, "SunOS") && strstr($host2->os_name, "SunOS")) return true; |
|
496 | - if ($host1->os_name == $host2->os_name) return true; |
|
546 | + if (strstr($host1->os_name, "Windows") && strstr($host2->os_name, "Windows")) { |
|
547 | + return true; |
|
548 | + } |
|
549 | + if (strstr($host1->os_name, "Linux") && strstr($host2->os_name, "Linux")) { |
|
550 | + return true; |
|
551 | + } |
|
552 | + if (strstr($host1->os_name, "Darwin") && strstr($host2->os_name, "Darwin")) { |
|
553 | + return true; |
|
554 | + } |
|
555 | + if (strstr($host1->os_name, "SunOS") && strstr($host2->os_name, "SunOS")) { |
|
556 | + return true; |
|
557 | + } |
|
558 | + if ($host1->os_name == $host2->os_name) { |
|
559 | + return true; |
|
560 | + } |
|
497 | 561 | return false; |
498 | 562 | } |
499 | 563 | |
@@ -546,7 +610,9 @@ discard block |
||
546 | 610 | |
547 | 611 | $results = BoincResult::enum("hostid=$hostid order by received_time"); |
548 | 612 | foreach($results as $result) { |
549 | - if ($result->granted_credit <= 0) continue; |
|
613 | + if ($result->granted_credit <= 0) { |
|
614 | + continue; |
|
615 | + } |
|
550 | 616 | $total += $result->granted_credit; |
551 | 617 | |
552 | 618 | update_average( |
@@ -750,7 +816,9 @@ discard block |
||
750 | 816 | $is_old=true; |
751 | 817 | $old_hosts++; |
752 | 818 | } |
753 | - if (!$show_all && $is_old) continue; |
|
819 | + if (!$show_all && $is_old) { |
|
820 | + continue; |
|
821 | + } |
|
754 | 822 | show_host_row($host, $i, $private, false, $any_product_name); |
755 | 823 | $i++; |
756 | 824 | } |
@@ -65,6 +65,10 @@ |
||
65 | 65 | return $forum->parent_type == 0 && ($forum->title === $forum_name); |
66 | 66 | } |
67 | 67 | |
68 | +/** |
|
69 | + * @param integer $start |
|
70 | + * @param integer $count |
|
71 | + */ |
|
68 | 72 | function show_news($start, $count) { |
69 | 73 | $forum = news_forum(); |
70 | 74 | if (!$forum) { |
@@ -118,5 +118,5 @@ |
||
118 | 118 | "; |
119 | 119 | } |
120 | 120 | |
121 | -$cvs_version_tracker[]="\$Id$"; //Generated automatically - do not edit |
|
121 | +$cvs_version_tracker[] = "\$Id$"; //Generated automatically - do not edit |
|
122 | 122 | ?> |
@@ -27,6 +27,10 @@ discard block |
||
27 | 27 | echo "</div>\n"; |
28 | 28 | } |
29 | 29 | |
30 | +/** |
|
31 | + * @param null|integer $teamid |
|
32 | + * @param string $error |
|
33 | + */ |
|
30 | 34 | function pm_team_form($user, $teamid, $error=null) { |
31 | 35 | global $bbcode_html, $bbcode_js; |
32 | 36 | $team = BoincTeam::lookup_id($teamid); |
@@ -78,6 +82,9 @@ discard block |
||
78 | 82 | page_tail(); |
79 | 83 | } |
80 | 84 | |
85 | +/** |
|
86 | + * @param string $error |
|
87 | + */ |
|
81 | 88 | function pm_form($replyto, $userid, $error = null) { |
82 | 89 | global $bbcode_html, $bbcode_js; |
83 | 90 | global $g_logged_in_user; |
@@ -196,6 +203,9 @@ discard block |
||
196 | 203 | return "<a href=pm.php>".tra("Private message%1 from %2, subject:" , "</a>", $from_user->name )." $pm->subject"; |
197 | 204 | } |
198 | 205 | |
206 | +/** |
|
207 | + * @param boolean $send_email |
|
208 | + */ |
|
199 | 209 | function pm_send_msg($from_user, $to_user, $subject, $content, $send_email) { |
200 | 210 | $sql_subject = BoincDb::escape_string(sanitize_tags($subject)); |
201 | 211 | $sql_content = BoincDb::escape_string($content); |
@@ -224,6 +234,9 @@ discard block |
||
224 | 234 | BoincNotify::insert("(userid, create_time, type, opaque) values ($to_user->id, ".time().", ".NOTIFY_PM.", $mid)"); |
225 | 235 | } |
226 | 236 | |
237 | +/** |
|
238 | + * @param integer $duration |
|
239 | + */ |
|
227 | 240 | function pm_count($userid, $duration) { |
228 | 241 | $time = time() - $duration; |
229 | 242 |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | echo "</div>\n"; |
28 | 28 | } |
29 | 29 | |
30 | -function pm_team_form($user, $teamid, $error=null) { |
|
30 | +function pm_team_form($user, $teamid, $error = null) { |
|
31 | 31 | global $bbcode_html, $bbcode_js; |
32 | 32 | $team = BoincTeam::lookup_id($teamid); |
33 | 33 | if (!$team) { |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | error_page("not admin"); |
38 | 38 | } |
39 | 39 | |
40 | - page_head(tra("Send message to team"),'','','', $bbcode_js); |
|
40 | + page_head(tra("Send message to team"), '', '', '', $bbcode_js); |
|
41 | 41 | |
42 | 42 | $subject = post_str("subject", true); |
43 | 43 | $content = post_str("content", true); |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | function pm_form($replyto, $userid, $error = null) { |
82 | 82 | global $bbcode_html, $bbcode_js; |
83 | 83 | global $g_logged_in_user; |
84 | - page_head(tra("Send private message"),'','','', $bbcode_js); |
|
84 | + page_head(tra("Send private message"), '', '', '', $bbcode_js); |
|
85 | 85 | |
86 | 86 | if (post_str("preview", true) == tra("Preview")) { |
87 | 87 | $content = post_str("content", true); |
@@ -163,7 +163,7 @@ discard block |
||
163 | 163 | function send_pm_notification_email( |
164 | 164 | $logged_in_user, $to_user, $subject, $content |
165 | 165 | ) { |
166 | - $message = " |
|
166 | + $message = " |
|
167 | 167 | You have received a new private message at ".PROJECT.". |
168 | 168 | |
169 | 169 | From: $logged_in_user->name (ID $logged_in_user->id) |
@@ -193,7 +193,7 @@ discard block |
||
193 | 193 | $pm = BoincPrivateMessage::lookup_id($notify->opaque); |
194 | 194 | $from_user = BoincUser::lookup_id($pm->senderid); |
195 | 195 | if (!$pm || !$from_user) return null; |
196 | - return "<a href=pm.php>".tra("Private message%1 from %2, subject:" , "</a>", $from_user->name )." $pm->subject"; |
|
196 | + return "<a href=pm.php>".tra("Private message%1 from %2, subject:", "</a>", $from_user->name)." $pm->subject"; |
|
197 | 197 | } |
198 | 198 | |
199 | 199 | function pm_send_msg($from_user, $to_user, $subject, $content, $send_email) { |
@@ -257,11 +257,11 @@ discard block |
||
257 | 257 | |
258 | 258 | function pm_email_remind($user) { |
259 | 259 | if (!$user->prefs->pm_notification) { |
260 | - return "<br><small>" . |
|
260 | + return "<br><small>". |
|
261 | 261 | tra( |
262 | 262 | "For email notification, %1edit community prefs%2", |
263 | 263 | '<a href="edit_forum_preferences_form.php">', '</a>' |
264 | - ) . |
|
264 | + ). |
|
265 | 265 | "</small>" |
266 | 266 | ; |
267 | 267 | } |
@@ -287,5 +287,5 @@ discard block |
||
287 | 287 | } |
288 | 288 | } |
289 | 289 | |
290 | -$cvs_version_tracker[]="\$Id: pm.inc 14019 2007-11-01 23:04:39Z davea $"; |
|
290 | +$cvs_version_tracker[] = "\$Id: pm.inc 14019 2007-11-01 23:04:39Z davea $"; |
|
291 | 291 | ?> |
@@ -185,14 +185,18 @@ |
||
185 | 185 | function pm_email_line($notify) { |
186 | 186 | $pm = BoincPrivateMessage::lookup_id($notify->opaque); |
187 | 187 | $from_user = BoincUser::lookup_id($pm->senderid); |
188 | - if (!$pm || !$from_user) return null; |
|
188 | + if (!$pm || !$from_user) { |
|
189 | + return null; |
|
190 | + } |
|
189 | 191 | return "$from_user->name ".tra("sent you a private message; subject:")." '$pm->subject'"; |
190 | 192 | } |
191 | 193 | |
192 | 194 | function pm_web_line($notify) { |
193 | 195 | $pm = BoincPrivateMessage::lookup_id($notify->opaque); |
194 | 196 | $from_user = BoincUser::lookup_id($pm->senderid); |
195 | - if (!$pm || !$from_user) return null; |
|
197 | + if (!$pm || !$from_user) { |
|
198 | + return null; |
|
199 | + } |
|
196 | 200 | return "<a href=pm.php>".tra("Private message%1 from %2, subject:" , "</a>", $from_user->name )." $pm->subject"; |
197 | 201 | } |
198 | 202 |
@@ -291,6 +291,9 @@ discard block |
||
291 | 291 | return $dp; |
292 | 292 | } |
293 | 293 | |
294 | +/** |
|
295 | + * @param string $t |
|
296 | + */ |
|
294 | 297 | function group_header($t) { |
295 | 298 | echo "<tr><th class=\"bg-info\">$t</th><td class=\"bg-info\" colspan=4><br></td></tr>\n"; |
296 | 299 | } |
@@ -413,6 +416,9 @@ discard block |
||
413 | 416 | |
414 | 417 | // Display all venues as columns next to descriptions |
415 | 418 | // |
419 | +/** |
|
420 | + * @param stdClass $prefs |
|
421 | + */ |
|
416 | 422 | function prefs_show_columns_global($prefs) { |
417 | 423 | global $cpu_prefs; |
418 | 424 | global $disk_prefs; |
@@ -483,6 +489,11 @@ discard block |
||
483 | 489 | return PROJECT; |
484 | 490 | } |
485 | 491 | |
492 | +/** |
|
493 | + * @param stdClass $prefs |
|
494 | + * @param string $venue |
|
495 | + * @param string $subset |
|
496 | + */ |
|
486 | 497 | function prefs_display_venue($prefs, $venue, $subset) { |
487 | 498 | global $g_logged_in_user; |
488 | 499 | $tokens = url_tokens($g_logged_in_user->authenticator); |
@@ -276,9 +276,9 @@ discard block |
||
276 | 276 | $dp->disk_max_used_pct = parse_config($config, "<default_disk_max_used_pct>"); |
277 | 277 | $dp->disk_min_free_gb = parse_config($config, "<default_disk_min_free_gb>"); |
278 | 278 | // set some defaults if not found |
279 | - if (!$dp->disk_max_used_gb) $dp->disk_max_used_gb = 0; // no limit |
|
279 | + if (!$dp->disk_max_used_gb) $dp->disk_max_used_gb = 0; // no limit |
|
280 | 280 | if (!$dp->disk_max_used_pct) $dp->disk_max_used_pct = 90; // 90 percent |
281 | - if (!$dp->disk_min_free_gb) $dp->disk_min_free_gb = 1; // 1 GB |
|
281 | + if (!$dp->disk_min_free_gb) $dp->disk_min_free_gb = 1; // 1 GB |
|
282 | 282 | // set mininimum free space scheduler allows |
283 | 283 | // - depends on which scheduler is running |
284 | 284 | $dp->new_sched_flag = 1; |
@@ -304,7 +304,7 @@ discard block |
||
304 | 304 | global $text; |
305 | 305 | global $venue_name; |
306 | 306 | |
307 | - switch($name) { |
|
307 | + switch ($name) { |
|
308 | 308 | case "venue": |
309 | 309 | if (array_key_exists("name", $attrs)) { |
310 | 310 | $venue_name = $attrs["name"]; |
@@ -350,7 +350,7 @@ discard block |
||
350 | 350 | return; |
351 | 351 | } |
352 | 352 | } |
353 | - switch($name) { |
|
353 | + switch ($name) { |
|
354 | 354 | case "venue": |
355 | 355 | $top_parse_result->$venue_name = $parse_result; |
356 | 356 | $parse_result = $top_parse_result; |
@@ -509,7 +509,7 @@ discard block |
||
509 | 509 | } |
510 | 510 | } |
511 | 511 | |
512 | -function print_prefs_display_global($user, $columns=false) { |
|
512 | +function print_prefs_display_global($user, $columns = false) { |
|
513 | 513 | $global_prefs = prefs_parse_global($user->global_prefs); |
514 | 514 | |
515 | 515 | echo tra("These settings apply to all computers using this account except") |
@@ -519,7 +519,7 @@ discard block |
||
519 | 519 | .tra("Android devices") |
520 | 520 | ."</ul> |
521 | 521 | "; |
522 | - $switch_link = " <font size=\"-1\"><a href=prefs.php?subset=global&cols=". (int)!$columns .">".tra("(Switch view)")."</a></font>"; |
|
522 | + $switch_link = " <font size=\"-1\"><a href=prefs.php?subset=global&cols=".(int)!$columns.">".tra("(Switch view)")."</a></font>"; |
|
523 | 523 | if ($columns) { |
524 | 524 | echo "<h3>".tra("Combined preferences").$switch_link."</h3>"; |
525 | 525 | start_table(); |
@@ -554,9 +554,9 @@ discard block |
||
554 | 554 | // otherwise false |
555 | 555 | // |
556 | 556 | function print_prefs_form( |
557 | - $action, $subset, $venue, $user, $prefs, $cols, $error=false, |
|
558 | - $project_error=false |
|
559 | -){ |
|
557 | + $action, $subset, $venue, $user, $prefs, $cols, $error = false, |
|
558 | + $project_error = false |
|
559 | +) { |
|
560 | 560 | if ($action == "add") { |
561 | 561 | $script = "add_venue.php"; |
562 | 562 | $submit_value = tra("Add preferences"); |
@@ -595,7 +595,7 @@ discard block |
||
595 | 595 | // |
596 | 596 | // Functions to display preference subsets as forms |
597 | 597 | // |
598 | -function prefs_form_global($user, $prefs, $error=false) { |
|
598 | +function prefs_form_global($user, $prefs, $error = false) { |
|
599 | 599 | global $cpu_prefs; |
600 | 600 | global $disk_prefs; |
601 | 601 | global $mem_prefs; |
@@ -635,9 +635,9 @@ discard block |
||
635 | 635 | // |
636 | 636 | function prefs_form_radio_buttons($name, $yesno) { |
637 | 637 | $rb = tra("yes")." <input type=radio name=$name value=yes " |
638 | - .($yesno?"checked":"") |
|
638 | + .($yesno ? "checked" : "") |
|
639 | 639 | ."> ".tra("no")." <input type=radio name=$name value=no " |
640 | - .($yesno?"":"checked") |
|
640 | + .($yesno ? "" : "checked") |
|
641 | 641 | .">\n"; |
642 | 642 | return $rb; |
643 | 643 | } |
@@ -656,12 +656,12 @@ discard block |
||
656 | 656 | } |
657 | 657 | function venue_show($user) { |
658 | 658 | $venue = $user->venue; |
659 | - if ($venue =='') $venue = '---'; |
|
659 | + if ($venue == '') $venue = '---'; |
|
660 | 660 | tooltip_row2(VENUE_TOOLTIP, VENUE_DESC, $venue); |
661 | 661 | } |
662 | 662 | |
663 | 663 | function venue_form($user) { |
664 | - $n=$h=$w=$s=$m=''; |
|
664 | + $n = $h = $w = $s = $m = ''; |
|
665 | 665 | if ($user->venue == '') $n = 'selected'; |
666 | 666 | if ($user->venue == 'home') $h = 'selected'; |
667 | 667 | if ($user->venue == 'work') $w = 'selected'; |
@@ -717,7 +717,7 @@ discard block |
||
717 | 717 | // |
718 | 718 | // convert prefs from structure to XML |
719 | 719 | // |
720 | -function global_prefs_make_xml($prefs, $primary=true) { |
|
720 | +function global_prefs_make_xml($prefs, $primary = true) { |
|
721 | 721 | global $cpu_prefs; |
722 | 722 | global $disk_prefs; |
723 | 723 | global $mem_prefs; |
@@ -276,9 +276,18 @@ discard block |
||
276 | 276 | $dp->disk_max_used_pct = parse_config($config, "<default_disk_max_used_pct>"); |
277 | 277 | $dp->disk_min_free_gb = parse_config($config, "<default_disk_min_free_gb>"); |
278 | 278 | // set some defaults if not found |
279 | - if (!$dp->disk_max_used_gb) $dp->disk_max_used_gb = 0; // no limit |
|
280 | - if (!$dp->disk_max_used_pct) $dp->disk_max_used_pct = 90; // 90 percent |
|
281 | - if (!$dp->disk_min_free_gb) $dp->disk_min_free_gb = 1; // 1 GB |
|
279 | + if (!$dp->disk_max_used_gb) { |
|
280 | + $dp->disk_max_used_gb = 0; |
|
281 | + } |
|
282 | + // no limit |
|
283 | + if (!$dp->disk_max_used_pct) { |
|
284 | + $dp->disk_max_used_pct = 90; |
|
285 | + } |
|
286 | + // 90 percent |
|
287 | + if (!$dp->disk_min_free_gb) { |
|
288 | + $dp->disk_min_free_gb = 1; |
|
289 | + } |
|
290 | + // 1 GB |
|
282 | 291 | // set mininimum free space scheduler allows |
283 | 292 | // - depends on which scheduler is running |
284 | 293 | $dp->new_sched_flag = 1; |
@@ -329,7 +338,9 @@ discard block |
||
329 | 338 | global $net_prefs; |
330 | 339 | |
331 | 340 | foreach ($cpu_prefs as $p) { |
332 | - if (is_string($p)) continue; |
|
341 | + if (is_string($p)) { |
|
342 | + continue; |
|
343 | + } |
|
333 | 344 | if ($p->xml_parse($parse_result, $name, $text)) { |
334 | 345 | return; |
335 | 346 | } |
@@ -345,7 +356,9 @@ discard block |
||
345 | 356 | } |
346 | 357 | } |
347 | 358 | foreach ($net_prefs as $p) { |
348 | - if (is_string($p)) continue; |
|
359 | + if (is_string($p)) { |
|
360 | + continue; |
|
361 | + } |
|
349 | 362 | if ($p->xml_parse($parse_result, $name, $text)) { |
350 | 363 | return; |
351 | 364 | } |
@@ -381,7 +394,9 @@ discard block |
||
381 | 394 | |
382 | 395 | $p = new StdClass; |
383 | 396 | foreach ($cpu_prefs as $pref) { |
384 | - if (is_string($pref)) continue; |
|
397 | + if (is_string($pref)) { |
|
398 | + continue; |
|
399 | + } |
|
385 | 400 | $pref->set_default($p); |
386 | 401 | } |
387 | 402 | foreach ($disk_prefs as $pref) { |
@@ -391,7 +406,9 @@ discard block |
||
391 | 406 | $pref->set_default($p); |
392 | 407 | } |
393 | 408 | foreach ($net_prefs as $pref) { |
394 | - if (is_string($pref)) continue; |
|
409 | + if (is_string($pref)) { |
|
410 | + continue; |
|
411 | + } |
|
395 | 412 | $pref->set_default($p); |
396 | 413 | } |
397 | 414 | return $p; |
@@ -479,7 +496,9 @@ discard block |
||
479 | 496 | } |
480 | 497 | |
481 | 498 | function subset_name($subset) { |
482 | - if ($subset == "global") return tra("Computing"); |
|
499 | + if ($subset == "global") { |
|
500 | + return tra("Computing"); |
|
501 | + } |
|
483 | 502 | return PROJECT; |
484 | 503 | } |
485 | 504 | |
@@ -487,7 +506,9 @@ discard block |
||
487 | 506 | global $g_logged_in_user; |
488 | 507 | $tokens = url_tokens($g_logged_in_user->authenticator); |
489 | 508 | $x = false; |
490 | - if (isset($prefs->$venue)) $x = $prefs->$venue; |
|
509 | + if (isset($prefs->$venue)) { |
|
510 | + $x = $prefs->$venue; |
|
511 | + } |
|
491 | 512 | |
492 | 513 | if ($x) { |
493 | 514 | start_table(); |
@@ -656,16 +677,26 @@ discard block |
||
656 | 677 | } |
657 | 678 | function venue_show($user) { |
658 | 679 | $venue = $user->venue; |
659 | - if ($venue =='') $venue = '---'; |
|
680 | + if ($venue =='') { |
|
681 | + $venue = '---'; |
|
682 | + } |
|
660 | 683 | tooltip_row2(VENUE_TOOLTIP, VENUE_DESC, $venue); |
661 | 684 | } |
662 | 685 | |
663 | 686 | function venue_form($user) { |
664 | 687 | $n=$h=$w=$s=$m=''; |
665 | - if ($user->venue == '') $n = 'selected'; |
|
666 | - if ($user->venue == 'home') $h = 'selected'; |
|
667 | - if ($user->venue == 'work') $w = 'selected'; |
|
668 | - if ($user->venue == 'school') $s = 'selected'; |
|
688 | + if ($user->venue == '') { |
|
689 | + $n = 'selected'; |
|
690 | + } |
|
691 | + if ($user->venue == 'home') { |
|
692 | + $h = 'selected'; |
|
693 | + } |
|
694 | + if ($user->venue == 'work') { |
|
695 | + $w = 'selected'; |
|
696 | + } |
|
697 | + if ($user->venue == 'school') { |
|
698 | + $s = 'selected'; |
|
699 | + } |
|
669 | 700 | tooltip_row2( |
670 | 701 | VENUE_TOOLTIP, |
671 | 702 | VENUE_DESC, |
@@ -696,7 +727,9 @@ discard block |
||
696 | 727 | |
697 | 728 | $error = false; |
698 | 729 | foreach ($cpu_prefs as $p) { |
699 | - if (is_string($p)) continue; |
|
730 | + if (is_string($p)) { |
|
731 | + continue; |
|
732 | + } |
|
700 | 733 | $p->parse_form($prefs, $error); |
701 | 734 | } |
702 | 735 | foreach ($disk_prefs as $p) { |
@@ -706,7 +739,9 @@ discard block |
||
706 | 739 | $p->parse_form($prefs, $error); |
707 | 740 | } |
708 | 741 | foreach ($net_prefs as $p) { |
709 | - if (is_string($p)) continue; |
|
742 | + if (is_string($p)) { |
|
743 | + continue; |
|
744 | + } |
|
710 | 745 | $p->parse_form($prefs, $error); |
711 | 746 | } |
712 | 747 | return $error; |
@@ -731,7 +766,9 @@ discard block |
||
731 | 766 | } |
732 | 767 | |
733 | 768 | foreach ($cpu_prefs as $p) { |
734 | - if (is_string($p)) continue; |
|
769 | + if (is_string($p)) { |
|
770 | + continue; |
|
771 | + } |
|
735 | 772 | $xml .= $p->xml_string($prefs); |
736 | 773 | } |
737 | 774 | foreach ($disk_prefs as $p) { |
@@ -741,7 +778,9 @@ discard block |
||
741 | 778 | $xml .= $p->xml_string($prefs); |
742 | 779 | } |
743 | 780 | foreach ($net_prefs as $p) { |
744 | - if (is_string($p)) continue; |
|
781 | + if (is_string($p)) { |
|
782 | + continue; |
|
783 | + } |
|
745 | 784 | $xml .= $p->xml_string($prefs); |
746 | 785 | } |
747 | 786 |