comments.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. /**
  3. * List comments with optional add form
  4. *
  5. * @uses $vars['entity'] ElggEntity
  6. * @uses $vars['show_add_form'] Display add form or not
  7. * @uses $vars['id'] Optional id for the div
  8. * @uses $vars['class'] Optional additional class for the div
  9. * @uses $vars['limit'] Optional limit value (default is 25)
  10. *
  11. * @todo look into restructuring this so we are not calling elgg_list_entities()
  12. * in this view
  13. */
  14. $show_add_form = elgg_extract('show_add_form', $vars, true);
  15. $full_view = elgg_extract('full_view', $vars, true);
  16. $limit = elgg_extract('limit', $vars, get_input('limit', 0));
  17. if (!$limit) {
  18. $limit = elgg_trigger_plugin_hook('config', 'comments_per_page', [], 25);
  19. }
  20. $attr = [
  21. 'id' => elgg_extract('id', $vars, 'comments'),
  22. 'class' => (array) elgg_extract('class', $vars, []),
  23. ];
  24. $attr['class'][] = 'elgg-comments';
  25. // work around for deprecation code in elgg_view()
  26. unset($vars['internalid']);
  27. $content = elgg_list_entities(array(
  28. 'type' => 'object',
  29. 'subtype' => 'comment',
  30. 'container_guid' => $vars['entity']->guid,
  31. 'reverse_order_by' => true,
  32. 'full_view' => true,
  33. 'limit' => $limit,
  34. 'preload_owners' => true,
  35. 'distinct' => false,
  36. 'url_fragment' => $attr['id'],
  37. ));
  38. if ($show_add_form) {
  39. $content .= elgg_view_form('comment/save', array(), $vars);
  40. }
  41. echo elgg_format_element('div', $attr, $content);