Conditions | 30 |
Paths | 81 |
Total Lines | 290 |
Code Lines | 162 |
Lines | 5 |
Ratio | 1.72 % |
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 |
||
262 | } |
||
263 | } |
||
264 | |||
265 | /** |
||
266 | * Create list of options to modify forums |
||
267 | * |
||
268 | * @param int $forum_guid |
||
269 | * |
||
270 | */ |
||
271 | function render_forums($forum_guid) |
||
272 | { |
||
273 | elgg_load_css('gcforums-css'); |
||
274 | $entity = get_entity($forum_guid); |
||
275 | |||
276 | |||
277 | if ($entity instanceof ElggEntity) { |
||
278 | |||
279 | $dbprefix = elgg_get_config('dbprefix'); |
||
280 | $base_url = elgg_get_site_entity()->getURL(); |
||
281 | $group_entity = get_entity(gcforums_get_forum_in_group($entity->getGUID(), $entity->getGUID())); |
||
282 | $current_user = elgg_get_logged_in_user_entity(); |
||
283 | // set the breadcrumb trail |
||
284 | assemble_forum_breadcrumb($entity); |
||
285 | |||
286 | // forums will always remain as content within a group |
||
287 | elgg_set_page_owner_guid($group_entity->getGUID()); |
||
288 | $return = array(); |
||
289 | |||
290 | if ($forum_guid !== $group_entity->guid) |
||
291 | $content .= "<div class='forums-menu-buttons'>".gcforums_menu_buttons($entity->getGUID(), $group_entity->getGUID())."</div> "; |
||
292 | |||
293 | |||
294 | // administrative only tool to fix up all the topics that were misplaced |
||
295 | if (elgg_is_admin_logged_in()) { |
||
296 | $content .= elgg_view_form('gcforums/move_topic'); |
||
297 | } |
||
298 | |||
299 | $query = "SELECT * FROM elggentities e, elggentity_subtypes es WHERE e.subtype = es.id AND e.container_guid = {$forum_guid} AND es.subtype = 'hjforumtopic'"; |
||
300 | $topics = get_data($query); |
||
301 | |||
302 | // sort |
||
303 | usort($topics, function($a, $b) { |
||
304 | return $b->guid - $a->guid; |
||
305 | }); |
||
306 | |||
307 | if (count($topics) > 0 && !$entity->enable_posting) { |
||
308 | $content .= " |
||
309 | <div class='topic-main-box'> |
||
310 | <div style='background: #e6e6e6; width:100%;' > |
||
311 | <div class='topic-header'>".elgg_echo('gcforums:translate:hjforumtopic')." |
||
312 | <div class='topic-information'>options</div> |
||
313 | <div class='topic-information'>".elgg_echo('gcforums:translate:last_posted')."</div> |
||
314 | <div class='topic-information'>".elgg_echo('gcforums:translate:replies')."</div> |
||
315 | <div class='topic-information'>".elgg_echo('gcforums:translate:topic_starter')."</div> |
||
316 | </div>" |
||
317 | |||
318 | /// topic |
||
319 | foreach ($topics as $topic) { |
||
|
|||
320 | |||
321 | $topic = get_entity($topic->guid); |
||
322 | $hyperlink = "<a href='{$base_url}gcforums/topic/view/{$topic->guid}'><strong>{$topic->title}</strong></a>"; |
||
323 | if (!$topic->guid) continue; |
||
324 | $query = "SELECT e.guid, ue.username, e.time_created |
||
325 | FROM {$dbprefix}entities e, {$dbprefix}users_entity ue |
||
326 | WHERE e.container_guid = {$topic->guid} AND e.owner_guid = ue.guid"; |
||
327 | $replies = get_data($query); |
||
328 | |||
329 | |||
330 | $total_replies = count($replies); |
||
331 | $topic_starter = get_user($topic->owner_guid)->username; |
||
332 | $time_posted = $replies[$total_replies - 1]->time_created; |
||
333 | $time_posted = date('Y-m-d H:i:s', $time_posted); |
||
334 | |||
335 | $options = render_edit_options($topic->guid, $group_entity->guid); |
||
336 | if ($options == '') $options = '-'; |
||
337 | $admin_only = (elgg_is_admin_logged_in()) ? "(guid:{$topic->guid})" : ""; |
||
338 | $last_post = ($total_replies <= 0) ? elgg_echo('gcforums:no_posts') : "<div>{$replies[$total_replies - 1]->username}</div> <div>{$time_posted}</div>"; |
||
339 | |||
340 | $content .= " |
||
341 | <div class='topic-info-header'> |
||
342 | <div class='topic-description'>{$hyperlink} {$admin_only}</div> |
||
343 | <div class='topic-options-edit'>{$options}</div> |
||
344 | <div class='topic-options'>{$last_post}</div> |
||
345 | <div class='topic-options'>{$total_replies}</div> |
||
346 | <div class='topic-options'>{$topic_starter}</div> |
||
347 | </div>"; |
||
348 | } |
||
349 | |||
350 | $content .= "</div> </div> </p> <br/>"; |
||
351 | } |
||
352 | |||
353 | |||
354 | |||
355 | /// display the categories if the forum has this enabled |
||
356 | if ($entity->enable_subcategories || $entity instanceof ElggGroup) { |
||
357 | |||
358 | $categories = elgg_get_entities(array( |
||
359 | 'types' => 'object', |
||
360 | 'subtypes' => 'hjforumcategory', |
||
361 | 'limit' => false, |
||
362 | 'container_guid' => $forum_guid |
||
363 | )); |
||
364 | |||
365 | /// category |
||
366 | foreach ($categories as $category) { |
||
367 | $options = render_edit_options($category->guid, $group_entity->getGUID()); |
||
368 | if ($options == '') $options = '-'; |
||
369 | $admin_only = (elgg_is_admin_logged_in()) ? "(guid:{$category->guid})" : ""; |
||
370 | $content .= " |
||
371 | <p> |
||
372 | <div class='category-main-box'> |
||
373 | <div class='category-options'>{$options} {$admin_only}</div> |
||
374 | <h1>{$category->title}</h1> |
||
375 | <div class='category-description'>{$category->description}</div> |
||
376 | </div>"; |
||
377 | |||
378 | |||
379 | $forums = elgg_get_entities_from_relationship(array( |
||
380 | 'relationship' => 'filed_in', |
||
381 | 'relationship_guid' => $category->getGUID(), |
||
382 | 'container_guid' => $entity->getGUID(), |
||
383 | 'inverse_relationship' => true, |
||
384 | 'limit' => false |
||
385 | )); |
||
386 | |||
387 | if (sizeof($forums) > 0) { |
||
388 | |||
389 | $content .= "<div class='forum-main-box'> |
||
390 | <div style='background: #e6e6e6; width:100%;' > |
||
391 | <div class='forum-header'>Forum |
||
392 | <div class='forum-information'>options</div> |
||
393 | <div class='forum-information'>".elgg_echo('gcforums:translate:total_topics')."</div> |
||
394 | <div class='forum-information'>".elgg_echo('gcforums:translate:total_replies')."</div> |
||
395 | <div class='forum-information'>".elgg_echo('gcforums:translate:last_posted')."</div> |
||
396 | </div>"; |
||
397 | |||
398 | /// forums |
||
399 | foreach ($forums as $forum) { |
||
400 | $total_topics = get_forums_statistics_information($forum->guid, TOTAL_TOPICS); |
||
401 | $total_posts = get_forums_statistics_information($forum->guid, TOTAL_POST); |
||
402 | $recent_post = get_forums_statistics_information($forum->guid, RECENT_POST); |
||
403 | $options = render_edit_options($forum->getGUID(), $group_entity->getGUID()); |
||
404 | |||
405 | $admin_only = (elgg_is_admin_logged_in()) ? "(guid:{$forum->guid})" : ""; |
||
406 | |||
407 | $hyperlink = "<a href='{$base_url}gcforums/view/{$forum->getGUID()}'><strong>{$forum->title}</strong></a>"; |
||
408 | |||
409 | $content .= "<div class='forum-info-header'> |
||
410 | <div class='forum-description'>{$hyperlink} {$admin_only} |
||
411 | <div class='forum-description-text'>{$forum->description}</div> |
||
412 | </div> |
||
413 | <div class='forum-options-edit'>{$options}</div> |
||
414 | <div class='forum-options'>{$total_topics}</div> |
||
415 | <div class='forum-options'>{$total_posts}</div> |
||
416 | <div class='forum-options'>{$recent_post}</div> |
||
417 | </div>"; |
||
418 | } |
||
419 | $content .= "</div> </div> </p> <br/>"; |
||
420 | |||
421 | } else { |
||
422 | $content .= "<div class='forum-empty'>".elgg_echo('gcforums:forums_not_available')."</div>"; |
||
423 | } |
||
424 | } |
||
425 | |||
426 | |||
427 | if (elgg_is_admin_logged_in() /*|| $group_entity->getOwnerGUID() == $current_user->guid || check_entity_relationship($current_user->getGUID(), 'operator', $group_entity->getGUID())*/) { |
||
428 | |||
429 | /// there are the problem where user creates forum in the existing forum with categories enabled, show the forums without categories |
||
430 | $forums = elgg_get_entities_from_relationship(array( |
||
431 | 'relationship' => 'descendant', |
||
432 | 'container_guid' => $forum_guid, |
||
433 | 'subtypes' => array('hjforum'), |
||
434 | 'relationship_guid' => $forum_guid, |
||
435 | 'inverse_relationship' => true, |
||
436 | 'types' => 'object', |
||
437 | 'limit' => 0, |
||
438 | )); |
||
439 | |||
440 | if (sizeof($forums) > 0) { |
||
441 | |||
442 | $content .= " |
||
443 | <div class='forum-category-issue-notice'> |
||
444 | <section class='alert alert-danger'> |
||
445 | <strong>This only shows up for administrators</strong>. |
||
446 | If you don't see a specific forum appearing above, you can correct that by editing the forums below. |
||
447 | </section> |
||
448 | <div class='forum-main-box'> |
||
449 | <div style='background: #e6e6e6; width:100%;' > |
||
450 | <div class='forum-header'>Forum |
||
451 | <div class='forum-information'>options</div> |
||
452 | <div class='forum-information'>".elgg_echo('gcforums:translate:total_topics')."</div> |
||
453 | <div class='forum-information'>".elgg_echo('gcforums:translate:total_replies')."</div> |
||
454 | <div class='forum-information'>".elgg_echo('gcforums:translate:last_posted')."</div> |
||
455 | </div>"; |
||
456 | |||
457 | foreach ($forums as $forum) { |
||
458 | |||
459 | $query = "SELECT COUNT(guid_one) AS total FROM elggentity_relationships WHERE guid_one = '{$forum->guid}' AND relationship = 'filed_in' AND guid_two = 0"; |
||
460 | $is_filed_in_category = get_data($query); |
||
461 | |||
462 | //if ($is_filed_in_category[0]->total == 1) { |
||
463 | |||
464 | $total_topics = get_forums_statistics_information($forum->guid, TOTAL_TOPICS); |
||
465 | $total_posts = get_forums_statistics_information($forum->guid, TOTAL_POST); |
||
466 | $recent_post = get_forums_statistics_information($forum->guid, RECENT_POST); |
||
467 | $options = render_edit_options($forum->getGUID(), $group_entity->getGUID()); |
||
468 | if ($options == '') $options = '-'; |
||
469 | $admin_only = (elgg_is_admin_logged_in()) ? "(guid:{$forum->guid})" : ""; |
||
470 | $hyperlink = "<a href='{$base_url}gcforums/view/{$forum->getGUID()}'><strong>{$forum->title}</strong></a>"; |
||
471 | |||
472 | $content .= " |
||
473 | <div class='forum-info-header'> |
||
474 | <div class='forum-description'>{$hyperlink} {$admin_only} |
||
475 | <div class='forum-description-text'>{$forum->description}</div> |
||
476 | </div> |
||
477 | <div class='forum-options-edit'>{$options}</div> |
||
478 | <div class='forum-options'>{$total_topics}</div> |
||
479 | <div class='forum-options'>{$total_posts}</div> |
||
480 | <div class='forum-options'>{$recent_post}</div> |
||
481 | </div>"; |
||
482 | //} |
||
483 | } |
||
484 | |||
485 | $content .= "</div> </div> </div> </p> <br/>"; |
||
486 | } |
||
487 | } |
||
488 | |||
489 | |||
490 | |||
491 | } else { |
||
492 | |||
493 | /// display forums with no categories |
||
494 | $forums = elgg_get_entities_from_relationship(array( |
||
495 | 'relationship' => 'descendant', |
||
496 | 'subtypes' => array('hjforum'), |
||
497 | 'relationship_guid' => $forum_guid, |
||
498 | 'inverse_relationship' => true, |
||
499 | 'types' => 'object', |
||
500 | 'limit' => 0, |
||
501 | )); |
||
502 | |||
503 | if (sizeof($forums) > 0) { |
||
504 | $content .= " |
||
505 | <div class='forum-main-box'> |
||
506 | <div style='background: #e6e6e6; width:100%;' > |
||
507 | <div class='forum-header'>Forum |
||
508 | <div class='forum-information'>options</div> |
||
509 | <div class='forum-information'>".elgg_echo('gcforums:translate:total_topics')."</div> |
||
510 | <div class='forum-information'>".elgg_echo('gcforums:translate:total_replies')."</div> |
||
511 | <div class='forum-information'>".elgg_echo('gcforums:translate:last_posted')."</div> |
||
512 | </div>"; |
||
513 | |||
514 | foreach ($forums as $forum) { |
||
515 | |||
516 | if ($forum->getContainerGUID() != $entity->getGUID()) continue; |
||
517 | |||
518 | $total_topics = get_forums_statistics_information($forum->guid, TOTAL_TOPICS); |
||
519 | $total_posts = get_forums_statistics_information($forum->guid, TOTAL_POST); |
||
520 | $recent_post = get_forums_statistics_information($forum->guid, RECENT_POST); |
||
521 | $options = render_edit_options($forum->getGUID(), $group_entity->getGUID()); |
||
522 | if ($options == '') $options = '-'; |
||
523 | $hyperlink = "<a href='{$base_url}gcforums/view/{$forum->getGUID()}'><strong>{$forum->title}</strong></a>"; |
||
524 | $admin_only = (elgg_is_admin_logged_in()) ? "(guid:{$forum->guid})" : ""; |
||
525 | |||
526 | $content .= " |
||
527 | <div class='forum-info-header'> |
||
528 | <div class='forum-description'>{$hyperlink} {$admin_only} |
||
529 | <div class='forum-description-text'>{$forum->description}</div> |
||
530 | </div> |
||
531 | <div class='forum-options-edit'>{$options}</div> |
||
532 | <div class='forum-options'>{$total_topics}</div> |
||
533 | <div class='forum-options'>{$total_posts}</div> |
||
534 | <div class='forum-options'>{$recent_post}</div> |
||
535 | </div>"; |
||
536 | } |
||
537 | |||
538 | $content .= "</div> </div> </p> <br/>"; |
||
539 | } |
||
540 | } |
||
541 | |||
542 | $title = $entity->title; |
||
543 | if (!$title) $title = elgg_echo('gcforum:heading:default_title'); |
||
544 | |||
545 | |||
546 | $return['filter'] = ''; |
||
547 | $return['title'] = gc_explode_translation($title, get_current_language()); |
||
548 | $return['content'] = $content; |
||
549 | |||
550 | } else { |
||
551 | $return['filter'] = ''; |
||
552 | $return['title'] = '404 - '.elgg_echo('gcforums:notfound'); |
||
787 |