responses.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 true;
  13. }
  14. $item = $vars['item'];
  15. $object = $item->getObjectEntity();
  16. $target = $item->getTargetEntity();
  17. // annotations and comments do not have responses
  18. if ($item->annotation_id != 0 || !$object || elgg_instanceof($target, 'object', 'comment')) {
  19. return true;
  20. }
  21. $comment_count = $object->countComments();
  22. $comments = elgg_get_entities(array(
  23. 'type' => 'object',
  24. 'subtype' => 'comment',
  25. 'container_guid' => $object->getGUID(),
  26. 'limit' => 3,
  27. 'order_by' => 'e.time_created desc'
  28. ));
  29. if ($comments) {
  30. // why is this reversing it? because we're asking for the 3 latest
  31. // comments by sorting desc and limiting by 3, but we want to display
  32. // these comments with the latest at the bottom.
  33. $comments = array_reverse($comments);
  34. ?>
  35. <span class="elgg-river-comments-tab"><?php echo elgg_echo('comments'); ?></span>
  36. <?php
  37. echo elgg_view_entity_list($comments, array('list_class' => 'elgg-river-comments'));
  38. if ($comment_count > count($comments)) {
  39. $num_more_comments = $comment_count - count($comments);
  40. $url = $object->getURL();
  41. $params = array(
  42. 'href' => $url,
  43. 'text' => elgg_echo('river:comments:more', array($num_more_comments)),
  44. 'is_trusted' => true,
  45. );
  46. $link = elgg_view('output/url', $params);
  47. echo "<div class=\"elgg-river-more\">$link</div>";
  48. }
  49. }
  50. // inline comment form
  51. $form_vars = array('id' => "comments-add-{$object->getGUID()}", 'class' => 'hidden');
  52. $body_vars = array('entity' => $object, 'inline' => true, 'river_id' => $item->id);
  53. echo elgg_view_form('comment/save', $form_vars, $body_vars);