| Conditions | 17 |
| Paths | 2016 |
| Total Lines | 122 |
| Code Lines | 75 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 26 | function forum_page($forum, $user, $msg=null) { |
||
| 27 | global $forum_sort_styles; |
||
| 28 | $sort_style = get_int("sort", true); |
||
| 29 | $start = get_int("start", true); |
||
| 30 | if (!$start) $start = 0; |
||
| 31 | $subs = null; |
||
| 32 | if ($user) { |
||
| 33 | if (DISABLE_FORUMS && !is_admin($user)) { |
||
| 34 | error_page("Forums are disabled"); |
||
| 35 | } |
||
| 36 | BoincForumPrefs::lookup($user); |
||
| 37 | $subs = BoincSubscription::enum("userid=$user->id"); |
||
| 38 | } |
||
| 39 | |||
| 40 | if (!is_forum_visible_to_user($forum, $user)) { |
||
| 41 | if ($user) { |
||
| 42 | remove_subscriptions_forum($user->id, $forum->id); |
||
| 43 | } |
||
| 44 | error_page(tra("Not visible to you")); |
||
| 45 | } |
||
| 46 | |||
| 47 | if (!$sort_style) { |
||
| 48 | // get the sort style either from the logged in user or a cookie |
||
| 49 | if ($user){ |
||
| 50 | $sort_style = $user->prefs->forum_sorting; |
||
| 51 | } else { |
||
| 52 | list($sort_style, $thread_style) = parse_forum_cookie(); |
||
| 53 | } |
||
| 54 | } else { |
||
| 55 | // set the sort style |
||
| 56 | if ($user){ |
||
| 57 | $user->prefs->forum_sorting = $sort_style; |
||
| 58 | $user->prefs->update("forum_sorting=$sort_style"); |
||
| 59 | } else { |
||
| 60 | list($old_style, $thread_style) = parse_forum_cookie(); |
||
| 61 | send_cookie( |
||
| 62 | 'sorting', implode("|", array($sort_style, $thread_style)), true |
||
| 63 | ); |
||
| 64 | } |
||
| 65 | } |
||
| 66 | |||
| 67 | switch ($forum->parent_type) { |
||
| 68 | case 0: |
||
| 69 | $category = BoincCategory::lookup_id($forum->category); |
||
| 70 | if ($category->is_helpdesk) { |
||
| 71 | page_head(tra("Questions and Answers").' : '.$forum->title); |
||
| 72 | } else { |
||
| 73 | page_head(tra("Message boards").' : '.$forum->title); |
||
| 74 | } |
||
| 75 | if ($msg) echo "<p>$msg</p>\n"; |
||
| 76 | show_forum_header($user); |
||
| 77 | show_forum_title($category, $forum, NULL); |
||
| 78 | break; |
||
| 79 | case 1: |
||
| 80 | $team = BoincTeam::lookup_id($forum->category); |
||
| 81 | page_head(tra("Team message board for %1", $team->name)); |
||
| 82 | if ($msg) echo "<p>$msg</p>\n"; |
||
| 83 | show_forum_header($user); |
||
| 84 | show_team_forum_title($forum); |
||
| 85 | break; |
||
| 86 | } |
||
| 87 | |||
| 88 | echo ' |
||
| 89 | <p> |
||
| 90 | <form action="forum_forum.php" method="get" class="form-inline"> |
||
| 91 | <input type="hidden" name="id" value="'.$forum->id.'"> |
||
| 92 | <table width="100%" cellspacing="0" cellpadding="0"> |
||
| 93 | <tr valign="top"> |
||
| 94 | <td colspan=2> |
||
| 95 | '; |
||
| 96 | |||
| 97 | if (user_can_create_thread($user, $forum)) { |
||
| 98 | show_button( |
||
| 99 | "forum_post.php?id=$forum->id", |
||
| 100 | tra("New thread"), |
||
| 101 | tra("Add a new thread to this forum") |
||
| 102 | ); |
||
| 103 | } |
||
| 104 | |||
| 105 | if (is_subscribed(-$forum->id, $subs)) { |
||
| 106 | BoincNotify::delete_aux(sprintf( |
||
| 107 | 'userid=%d and type=%d and opaque=%d', |
||
| 108 | $logged_in_user->id, |
||
|
|
|||
| 109 | NOTIFY_SUBSCRIBED_FORUM, |
||
| 110 | $forum->id |
||
| 111 | )); |
||
| 112 | show_button_small( |
||
| 113 | "forum_forum.php?id=$forum->id&action=unsubscribe", |
||
| 114 | 'Unsubscribe', |
||
| 115 | 'Unsubscribe from this forum' |
||
| 116 | ); |
||
| 117 | } else { |
||
| 118 | show_button_small( |
||
| 119 | "forum_forum.php?id=$forum->id&action=subscribe", |
||
| 120 | 'Subscribe', |
||
| 121 | 'Click to get notified when there are new threads in this forum' |
||
| 122 | ); |
||
| 123 | } |
||
| 124 | |||
| 125 | echo '</td> |
||
| 126 | <td valign=top align="right"> |
||
| 127 | <div class="form-group"> |
||
| 128 | '; |
||
| 129 | echo select_from_array("sort", $forum_sort_styles, $sort_style); |
||
| 130 | echo sprintf(' |
||
| 131 | <input class="btn btn-sm" %s type="submit" value="Sort"> |
||
| 132 | </div> |
||
| 133 | </td> |
||
| 134 | </tr> |
||
| 135 | </table> |
||
| 136 | </form> |
||
| 137 | <p></p> ', |
||
| 138 | button_style() |
||
| 139 | ); |
||
| 140 | |||
| 141 | show_forum_threads($forum, $start, $sort_style, $user, $subs); |
||
| 142 | |||
| 143 | echo " |
||
| 144 | <p>". |
||
| 145 | tra("This message board is available as an %1 RSS feed %2", "<a href=forum_rss.php?forumid=$forum->id&setup=1>", "<img src=img/feed_logo.png></a>"); |
||
| 146 | |||
| 147 | page_tail(); |
||
| 148 | } |
||
| 274 |