Elgg  Version 3.0
comments.php
Go to the documentation of this file.
1 <?php
14 
15 $entity = elgg_extract('entity', $vars);
16 if (!$entity instanceof \ElggEntity) {
17  return;
18 }
19 
20 $show_add_form = elgg_extract('show_add_form', $vars, true);
21 
23 
24 $limit = elgg_extract('limit', $vars, get_input('limit', 0));
25 if (!$limit) {
27 }
28 
30  'id' => elgg_extract('id', $vars, 'comments'),
31  'class' => elgg_extract_class($vars, 'elgg-comments'),
32 ];
33 
35  'type' => 'object',
36  'subtype' => 'comment',
37  'container_guid' => $entity->guid,
38  'full_view' => true,
39  'limit' => $limit,
40  'distinct' => false,
41  'url_fragment' => $module_vars['id'],
42  'order_by' => [new OrderByClause('e.guid', $latest_first ? 'DESC' : 'ASC')],
43  'list_class' => 'comments-list',
44 ];
45 
46 $show_guid = (int) elgg_extract('show_guid', $vars);
47 if ($show_guid && $limit) {
48  // show the offset that includes the comment
49  // this won't work with threaded comments, but core doesn't support that yet
50  $operator = $latest_first ? '>' : '<';
51  $condition = function(QueryBuilder $qb) use ($show_guid, $operator) {
52  return $qb->compare('e.guid', $operator, $show_guid, ELGG_VALUE_INTEGER);
53  };
55  'type' => 'object',
56  'subtype' => 'comment',
57  'container_guid' => $entity->guid,
58  'count' => true,
59  'wheres' => [$condition],
60  ]);
61  $options['offset'] = (int) floor($count / $limit) * $limit;
62 }
63 
65 
66 $content = '';
67 if ($show_add_form && $entity->canComment()) {
68  $form_vars = [];
69  if ($comments_list) {
70  $form_vars['class'] = 'hidden';
71 
72  $module_vars['menu'] = elgg_view_menu('comments', [
73  'items' => [
74  [
75  'name' => 'add',
76  'text' => elgg_echo('generic_comments:add'),
77  'href' => false,
78  'icon' => 'plus',
79  'class' => ['elgg-button', 'elgg-button-action'],
80  'rel' => 'toggle',
81  'data-toggle-selector' => '.elgg-form-comment-save',
82  ],
83  ],
84  ]);
85  }
86 
87  $content .= elgg_view_form('comment/save', $form_vars, $vars);
88 }
89 
91 
92 if (empty($content)) {
93  return;
94 }
95 
96 echo elgg_view_module('comments', elgg_echo('comments'), $content, $module_vars);
elgg_comments_per_page(ElggEntity $container=null)
How many comments appear per page.
Definition: comments.php:62
if(!$limit) $show_guid
Definition: comments.php:46
const ELGG_VALUE_INTEGER
Value types.
Definition: constants.php:138
elgg_comments_are_latest_first(ElggEntity $container=null)
Are comments displayed with latest first?
Definition: comments.php:48
Database abstraction query builder.
if(!$entity instanceof\ElggEntity) $show_add_form
Definition: comments.php:20
elgg_echo($message_key, array $args=[], $language="")
Given a message key, returns an appropriately translated full-text string.
Definition: languages.php:21
elgg_extract_class(array $array, $existing=[], $extract_key= 'class')
Extract class names from an array, optionally merging into a preexisting set.
Definition: elgglib.php:1153
elgg_list_entities(array $options=[], $getter= 'elgg_get_entities', $viewer= 'elgg_view_entity_list')
Returns a string of rendered entities.
Definition: entities.php:577
if(!elgg_view_exists("plugins/{$plugin_id}/settings")) $form_vars
$limit
Definition: comments.php:24
elgg_view_menu($menu, array $vars=[])
Render a menu.
Definition: views.php:755
elgg_get_entities(array $options=[])
Fetches/counts entities or performs a calculation on their properties.
Definition: entities.php:545
elgg_view_form($action, $form_vars=[], $body_vars=[])
Definition: views.php:1318
get_input($variable, $default=null, $filter_result=true)
Get some input from variables passed submitted through GET or POST.
Definition: input.php:27
if(!$limit) $module_vars
Definition: comments.php:29
elgg_view_module($type, $title, $body, array $vars=[])
Wrapper function for the module display pattern.
Definition: views.php:1198
elgg echo
Translates a string.
Definition: languages.js:43
if(!$limit) $options
Definition: comments.php:34
if($show_guid &&$limit) $comments_list
Definition: comments.php:64
elgg_extract($key, $array, $default=null, $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
Definition: elgglib.php:1131
Extends QueryBuilder with ORDER BY clauses.
$vars['type']
Definition: save.php:11
if(elgg_in_context('widget')) $count
Definition: pagination.php:21
$entity
Definition: comments.php:15
$latest_first
Definition: comments.php:22
$content
Definition: comments.php:66