groupforumtopic.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <?php
  2. /**
  3. * Forum topic entity view
  4. *
  5. * @package ElggGroups
  6. */
  7. $full = elgg_extract('full_view', $vars, FALSE);
  8. $topic = elgg_extract('entity', $vars, FALSE);
  9. if (!$topic) {
  10. return;
  11. }
  12. $poster = $topic->getOwnerEntity();
  13. if (!$poster) {
  14. elgg_log("User {$topic->owner_guid} could not be loaded, and is needed to display entity {$topic->guid}", 'WARNING');
  15. if ($full) {
  16. forward('', '404');
  17. }
  18. return;
  19. }
  20. $excerpt = elgg_get_excerpt($topic->description);
  21. $poster_icon = elgg_view_entity_icon($poster, 'tiny');
  22. $poster_link = elgg_view('output/url', array(
  23. 'href' => $poster->getURL(),
  24. 'text' => $poster->name,
  25. 'is_trusted' => true,
  26. ));
  27. $poster_text = elgg_echo('groups:started', array($poster->name));
  28. $tags = elgg_view('output/tags', array('tags' => $topic->tags));
  29. $date = elgg_view_friendly_time($topic->time_created);
  30. $replies_link = '';
  31. $reply_text = '';
  32. $num_replies = elgg_get_entities(array(
  33. 'type' => 'object',
  34. 'subtype' => 'discussion_reply',
  35. 'container_guid' => $topic->getGUID(),
  36. 'count' => true,
  37. 'distinct' => false,
  38. ));
  39. if ($num_replies != 0) {
  40. $last_reply = elgg_get_entities(array(
  41. 'type' => 'object',
  42. 'subtype' => 'discussion_reply',
  43. 'container_guid' => $topic->getGUID(),
  44. 'limit' => 1,
  45. 'distinct' => false,
  46. ));
  47. if (isset($last_reply[0])) {
  48. $last_reply = $last_reply[0];
  49. }
  50. $poster = $last_reply->getOwnerEntity();
  51. $reply_time = elgg_view_friendly_time($last_reply->time_created);
  52. $reply_text = elgg_echo('groups:updated', array($poster->name, $reply_time));
  53. $replies_link = elgg_view('output/url', array(
  54. 'href' => $topic->getURL() . '#group-replies',
  55. 'text' => elgg_echo('group:replies') . " ($num_replies)",
  56. 'is_trusted' => true,
  57. ));
  58. }
  59. // do not show the metadata and controls in widget view
  60. if (elgg_in_context('widgets')) {
  61. $metadata = '';
  62. } else {
  63. $metadata = elgg_view_menu('entity', array(
  64. 'entity' => $vars['entity'],
  65. 'handler' => 'discussion',
  66. 'sort_by' => 'priority',
  67. 'class' => 'elgg-menu-hz',
  68. ));
  69. }
  70. if ($full) {
  71. $subtitle = "$poster_text $date $replies_link";
  72. $params = array(
  73. 'entity' => $topic,
  74. 'metadata' => $metadata,
  75. 'subtitle' => $subtitle,
  76. 'tags' => $tags,
  77. );
  78. $params = $params + $vars;
  79. $list_body = elgg_view('object/elements/summary', $params);
  80. $info = elgg_view_image_block($poster_icon, $list_body);
  81. $body = elgg_view('output/longtext', array(
  82. 'value' => $topic->description,
  83. 'class' => 'clearfix',
  84. ));
  85. echo <<<HTML
  86. $info
  87. $body
  88. HTML;
  89. } else {
  90. // brief view
  91. $subtitle = "$poster_text $date $replies_link <span class=\"groups-latest-reply\">$reply_text</span>";
  92. $params = array(
  93. 'entity' => $topic,
  94. 'metadata' => $metadata,
  95. 'subtitle' => $subtitle,
  96. 'tags' => $tags,
  97. 'content' => $excerpt,
  98. );
  99. $params = $params + $vars;
  100. $list_body = elgg_view('object/elements/summary', $params);
  101. echo elgg_view_image_block($poster_icon, $list_body);
  102. }