Conditions | 14 |
Paths | 40 |
Total Lines | 100 |
Code Lines | 65 |
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 |
||
155 | function show_forum_threads($forum, $start, $sort_style, $user, $subs) { |
||
156 | $page_nav = page_links( |
||
157 | "forum_forum.php?id=$forum->id&sort=$sort_style", |
||
158 | $forum->threads, |
||
159 | THREADS_PER_PAGE, |
||
160 | $start |
||
161 | ); |
||
162 | echo $page_nav; |
||
163 | start_table('table-striped'); |
||
164 | row_heading_array( |
||
165 | array( |
||
166 | "", |
||
167 | tra("Threads"), |
||
168 | tra("Posts"), |
||
169 | tra("Author"), |
||
170 | tra("Views"), |
||
171 | "<nobr>".tra("Last post")."</nobr>" |
||
172 | ), |
||
173 | array("", "width=35%", "", "", "", "") |
||
174 | |||
175 | ); |
||
176 | |||
177 | $sticky_first = !$user || !$user->prefs->ignore_sticky_posts; |
||
178 | |||
179 | // Show hidden threads if logged in user is a moderator |
||
180 | // |
||
181 | $show_hidden = is_moderator($user, $forum); |
||
182 | $threads = get_forum_threads( |
||
183 | $forum->id, $start, THREADS_PER_PAGE, |
||
184 | $sort_style, $show_hidden, $sticky_first |
||
185 | ); |
||
186 | |||
187 | // Run through the list of threads, displaying each of them |
||
188 | // |
||
189 | foreach ($threads as $thread) { |
||
190 | $owner = BoincUser::lookup_id($thread->owner); |
||
191 | if (!$owner) continue; |
||
192 | $unread = thread_is_unread($user, $thread); |
||
193 | |||
194 | //if ($thread->status==1){ |
||
195 | // This is an answered helpdesk thread |
||
196 | if ($user && is_subscribed($thread->id, $subs)) { |
||
197 | echo '<tr class="bg-info">'; |
||
198 | } else { |
||
199 | // Just a standard thread. |
||
200 | echo '<tr>'; |
||
201 | } |
||
202 | |||
203 | echo "<td width=\"1%\"><nobr>"; |
||
204 | if ($thread->hidden) { |
||
205 | show_image(IMAGE_HIDDEN, tra("This thread is hidden"), tra("hidden")); |
||
206 | } else if ($unread) { |
||
207 | if ($thread->sticky) { |
||
208 | if ($thread->locked) { |
||
209 | show_image(NEW_IMAGE_STICKY_LOCKED, tra("This thread is sticky and locked, and you haven't read it yet"), tra("sticky/locked/unread")); |
||
210 | } else { |
||
211 | show_image(NEW_IMAGE_STICKY, tra("This thread is sticky and you haven't read it yet"), tra("sticky/unread")); |
||
212 | } |
||
213 | } else { |
||
214 | if ($thread->locked) { |
||
215 | show_image(NEW_IMAGE_LOCKED, tra("You haven't read this thread yet, and it's locked"), tra("unread/locked")); |
||
216 | } else { |
||
217 | show_image(NEW_IMAGE, tra("You haven't read this thread yet"), tra("unread")); |
||
218 | } |
||
219 | } |
||
220 | } else { |
||
221 | if ($thread->sticky) { |
||
222 | if ($thread->locked) { |
||
223 | show_image(IMAGE_STICKY_LOCKED, tra("This thread is sticky and locked"), tra("sticky/locked")); |
||
224 | } else { |
||
225 | show_image(IMAGE_STICKY, tra("This thread is sticky"), tra("sticky")); |
||
226 | } |
||
227 | } else { |
||
228 | if ($thread->locked) { |
||
229 | show_image(IMAGE_LOCKED, tra("This thread is locked"), tra("locked")); |
||
230 | } else { |
||
231 | show_image(IMAGE_POST, tra("You read this thread"), tra("read")); |
||
232 | } |
||
233 | } |
||
234 | } |
||
235 | echo "</nobr></td>"; |
||
236 | |||
237 | $title = cleanup_title($thread->title); |
||
238 | //$titlelength = 9999; |
||
239 | //if (strlen($title) > $titlelength) { |
||
240 | // $title = substr($title, 0, $titlelength)."..."; |
||
241 | //} |
||
242 | echo "<td><a href=\"forum_thread.php?id=$thread->id\">$title</a><br></td>"; |
||
243 | |||
244 | echo ' |
||
245 | <td>'.($thread->replies+1).'</td> |
||
246 | <td>'.user_links($owner, BADGE_HEIGHT_SMALL).'</td> |
||
247 | <td>'.$thread->views.'</td> |
||
248 | <td>'.time_diff_str($thread->timestamp, time()).'</td> |
||
249 | </tr> |
||
250 | '; |
||
251 | flush(); |
||
252 | } |
||
253 | end_table(); |
||
254 | echo "<br>$page_nav"; // show page links |
||
255 | } |
||
274 |