Elgg  Version 5.1
comment.php
Go to the documentation of this file.
1 <?php
10 $full_view = elgg_extract('full_view', $vars, true);
11 
13 if (!$comment instanceof \ElggComment) {
14  return;
15 }
16 
17 $entity = $comment->getContainerEntity();
18 $commenter = $comment->getOwnerEntity();
19 if (!$entity || !$commenter) {
20  return;
21 }
22 
23 if ($comment->canEdit()) {
24  elgg_require_js('elgg/comments');
25 }
26 
27 if ($full_view) {
28  if (elgg_extract('show_excerpt', $vars)) {
29  $body = elgg_view('output/longtext', [
30  'value' => elgg_get_excerpt((string) $comment->description),
31  ]);
32  } else {
33  $body = elgg_view('output/longtext', [
34  'value' => $comment->description,
35  ]);
36 
37  if (elgg_extract('show_add_form', $vars, true) && $comment->canComment()) {
38  elgg_require_js('elgg/comments');
39 
40  $body .= elgg_view('output/url', [
41  'text' => elgg_echo('generic_comments:add'),
42  'href' => "#elgg-form-comment-save-{$comment->guid}",
43  'data-load-comment' => $comment->guid,
44  'class' => ['elgg-subtext', 'elgg-toggle-comment'],
45  ]);
46  }
47  }
48 
49  $params = [
50  'icon_entity' => $commenter,
51  'time_href' => $comment->getURL(),
52  'access' => false,
53  'title' => false,
54  'show_summary' => true,
55  'content' => $body,
56  'imprint' => elgg_extract('imprint', $vars, []),
57  'class' => elgg_extract_class($vars),
58  ];
59  $params = $params + $vars;
60 
61  if (!empty(elgg()->thread_preloader->getChildren($comment->guid))) {
62  $params['class'][] = 'with-children';
63  }
64 
65  if ($comment->isCreatedByContentOwner()) {
66  $params['class'][] = 'elgg-comment-by-owner';
67 
68  $params['imprint'][] = [
69  'icon_name' => 'user-edit',
70  'content' => elgg_echo('generic_comment:by_owner'),
71  ];
72  }
73 
74  echo elgg_view('object/elements/full', $params);
75 } else {
76  // brief view
77  $commenter_icon = elgg_view_entity_icon($commenter, 'small');
78 
80 
82 
83  $entity_link = elgg_view('output/url', [
84  'href' => $entity->getURL(),
85  'text' => $entity->getDisplayName() ?: elgg_echo('untitled'),
86  ]);
87 
88  $excerpt = elgg_get_excerpt((string) $comment->description, 80);
89  $posted = elgg_echo('generic_comment:on', [$commenter_link, $entity_link]);
90 
92  'class' => 'elgg-subtext',
93  ], "$posted ($friendlytime): $excerpt");
94 
95  echo elgg_view_image_block($commenter_icon, $body);
96 }
$commenter_link
Definition: comment.php:81
$params
Saves global plugin settings.
Definition: save.php:13
elgg_view_image_block(string $image, string $body, array $vars=[])
Wrapper function for the image block display pattern.
Definition: views.php:919
elgg_get_excerpt(string $text, int $num_chars=250)
Returns an excerpt.
Definition: output.php:83
$full_view
Elgg comment view.
Definition: comment.php:10
elgg_echo(string $message_key, array $args=[], string $language= '')
Elgg language module Functions to manage language and translations.
Definition: languages.php:17
$commenter
Definition: comment.php:18
$excerpt
Definition: comment.php:88
elgg_extract_class(array $array, $existing=[], $extract_key= 'class')
Extract class names from an array, optionally merging into a preexisting set.
Definition: elgglib.php:276
elgg_extract($key, $array, $default=null, bool $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
Definition: elgglib.php:254
elgg_view(string $view, array $vars=[], string $viewtype= '')
Return a parsed view.
Definition: views.php:177
elgg_view_entity_icon(\ElggEntity $entity, string $size= 'medium', array $vars=[])
View the icon of an entity.
Definition: views.php:563
elgg_view_friendly_time($time, $time_updated=null)
Displays a UNIX timestamp in a friendly way.
Definition: views.php:853
$posted
Definition: comment.php:89
getDisplayName()
{}
Definition: ElggObject.php:38
$vars
Definition: theme.php:5
$entity_link
Definition: comment.php:83
$body
Definition: comment.php:91
if(!$comment instanceof\ElggComment) $entity
Definition: comment.php:17
elgg_format_element(string $tag_name, array $attributes=[], string $text= '', array $options=[])
Format an HTML element.
Definition: output.php:145
$comment
Definition: comment.php:12
$friendlytime
Definition: comment.php:79
elgg_require_js(string $name)
Request that Elgg load an AMD module onto the page.
getURL()
Gets the URL for this entity.
var elgg
Definition: elgglib.js:4
elgg_view_entity_url(\ElggEntity $entity, array $options=[])
Helper function for outputting a link to an entity.
Definition: views.php:1498