responses.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. /**
  3. * River item footer
  4. *
  5. * @uses $vars['item'] ElggRiverItem
  6. * @uses $vars['responses'] Alternate override for this item
  7. */
  8. // allow river views to override the response content
  9. $responses = elgg_extract('responses', $vars, false);
  10. if ($responses) {
  11. echo $responses;
  12. return;
  13. }
  14. $item = $vars['item'];
  15. /* @var ElggRiverItem $item */
  16. $object = $item->getObjectEntity();
  17. // annotations and comments do not have responses
  18. if ($item->annotation_id != 0 || !$object || $object instanceof ElggComment) {
  19. return;
  20. }
  21. $comment_count = $object->countComments();
  22. if ($comment_count) {
  23. $comments = elgg_get_entities(array(
  24. 'type' => 'object',
  25. 'subtype' => 'comment',
  26. 'container_guid' => $object->getGUID(),
  27. 'limit' => 3,
  28. 'order_by' => 'e.time_created desc',
  29. 'distinct' => false,
  30. ));
  31. // why is this reversing it? because we're asking for the 3 latest
  32. // comments by sorting desc and limiting by 3, but we want to display
  33. // these comments with the latest at the bottom.
  34. $comments = array_reverse($comments);
  35. echo elgg_view_entity_list($comments, array('list_class' => 'elgg-river-comments'));
  36. if ($comment_count > count($comments)) {
  37. $url = $object->getURL();
  38. $params = array(
  39. 'href' => $url,
  40. 'text' => elgg_echo('river:comments:all', array($comment_count)),
  41. 'is_trusted' => true,
  42. );
  43. $link = elgg_view('output/url', $params);
  44. echo "<div class=\"elgg-river-more\">$link</div>";
  45. }
  46. }
  47. // inline comment form
  48. $form_vars = array('id' => "comments-add-{$object->getGUID()}", 'class' => 'hidden');
  49. $body_vars = array('entity' => $object, 'inline' => true);
  50. echo elgg_view_form('comment/save', $form_vars, $body_vars);