Elgg  Version 1.9
comments.php
Go to the documentation of this file.
1 <?php
10 elgg_register_event_handler('init', 'system', '_elgg_comments_init');
11 
18 function _elgg_comments_init() {
19  elgg_register_entity_type('object', 'comment');
20  elgg_register_plugin_hook_handler('register', 'menu:entity', '_elgg_comment_setup_entity_menu', 900);
21  elgg_register_plugin_hook_handler('entity:url', 'object', '_elgg_comment_url_handler');
22  elgg_register_plugin_hook_handler('container_permissions_check', 'object', '_elgg_comments_container_permissions_override');
23  elgg_register_plugin_hook_handler('permissions_check', 'object', '_elgg_comments_permissions_override');
24  elgg_register_plugin_hook_handler('email', 'system', '_elgg_comments_notification_email_subject');
25 
26  elgg_register_page_handler('comment', '_elgg_comments_page_handler');
27 
28  elgg_register_ajax_view('core/ajax/edit_comment');
29 }
30 
38 function _elgg_comments_page_handler($page) {
39 
40  switch ($page[0]) {
41 
42  case 'edit':
44 
45  if (empty($page[1])) {
46  register_error(elgg_echo('generic_comment:notfound'));
48  }
49  $comment = get_entity($page[1]);
50  if (!($comment instanceof ElggComment) || !$comment->canEdit()) {
51  register_error(elgg_echo('generic_comment:notfound'));
53  }
54 
55  $target = $comment->getContainerEntity();
56  if (!($target instanceof ElggEntity)) {
57  register_error(elgg_echo('generic_comment:notfound'));
59  }
60 
61  $title = elgg_echo('generic_comments:edit');
62  elgg_push_breadcrumb($target->getDisplayName(), $target->getURL());
64 
65  $params = array(
66  'entity' => $target,
67  'comment' => $comment,
68  'is_edit_page' => true,
69  );
70  $content = elgg_view_form('comment/save', null, $params);
71 
72  $params = array(
73  'content' => $content,
74  'title' => $title,
75  'filter' => '',
76  );
77  $body = elgg_view_layout('content', $params);
79 
80  return true;
81  break;
82 
83  default:
84  return false;
85  break;
86  }
87 }
88 
101  if (elgg_in_context('widgets')) {
102  return $return;
103  }
104 
105  $entity = $params['entity'];
106  if (!elgg_instanceof($entity, 'object', 'comment')) {
107  return $return;
108  }
109 
110  // Remove edit link and access level from the menu
111  foreach ($return as $key => $item) {
112  if ($item->getName() === 'access') {
113  unset($return[$key]);
114  }
115  }
116 
117  return $return;
118 }
119 
134  $entity = $params['entity'];
135  /* @var ElggObject $entity */
136 
137  if (!elgg_instanceof($entity, 'object', 'comment') || !$entity->getOwnerEntity()) {
138  // not a comment or has no owner
139 
140  // @todo handle anonymous comments
141  return $return;
142  }
143 
144  $container = $entity->getContainerEntity();
145  if (!$container) {
146  return $return;
147  }
148 
149  return $container->getURL();
150 }
151 
168 
169  // is someone trying to comment, if so override permissions check
170  if ($params['subtype'] === 'comment') {
171  return true;
172  }
173 
174  return $return;
175 }
176 
188  $entity = $params['entity'];
189  $user = $params['user'];
190 
191  if (elgg_instanceof($entity, 'object', 'comment') && $user) {
192  return $entity->getOwnerGUID() == $user->getGUID();
193  }
194 
195  return $return;
196 }
197 
213 function _elgg_comments_notification_email_subject($hook, $type, $returnvalue, $params) {
214 
216  $notification = elgg_extract('notification', $returnvalue['params']);
217 
218  if ($notification instanceof Elgg_Notifications_Notification) {
219  $object = elgg_extract('object', $notification->params);
220 
221  if ($object instanceof ElggComment) {
222  $container = $object->getContainerEntity();
223 
224  $returnvalue['subject'] = 'Re: ' . $container->getDisplayName();
225  }
226  }
227 
228  return $returnvalue;
229 }
elgg_push_breadcrumb($title, $link=null)
Adds a breadcrumb to the breadcrumbs stack.
Definition: navigation.php:221
_elgg_comments_container_permissions_override($hook, $type, $return, $params)
Allow users to comment on entities not owned by them.
Definition: comments.php:167
_elgg_comment_url_handler($hook, $type, $return, $params)
Format and return the URL for a comment.
Definition: comments.php:133
$object
Definition: upgrade.php:12
$return
Definition: opendd.php:15
_elgg_comments_page_handler($page)
Page handler for generic comments manipulation.
Definition: comments.php:38
_elgg_comments_permissions_override($hook, $type, $return, $params)
By default, only authors can edit their comments.
Definition: comments.php:187
elgg_extract($key, array $array, $default=null, $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
Definition: elgglib.php:1464
elgg forward
Meant to mimic the php forward() function by simply redirecting the user to another page...
Definition: elgglib.js:419
elgg_register_plugin_hook_handler($hook, $type, $callback, $priority=500)
Register a callback as a plugin hook handler.
Definition: elgglib.php:853
$comment
Definition: delete.php:10
$title
Definition: save.php:24
$params
Definition: login.php:72
elgg_gatekeeper()
Used at the top of a page to mark it as logged in users only.
Definition: pagehandler.php:58
elgg_instanceof($entity, $type=null, $subtype=null, $class=null)
Checks if $entity is an ElggEntity and optionally for type and subtype.
Definition: entities.php:1886
elgg_echo($message_key, $args=array(), $language="")
Given a message key, returns an appropriately translated full-text string.
Definition: languages.php:21
$key
Definition: summary.php:34
const REFERER
Definition: elgglib.php:2162
$item
Definition: item.php:12
$user
Definition: ban.php:13
_elgg_comments_init()
Comments initialization function.
Definition: comments.php:18
elgg_in_context($context)
Check if this context exists anywhere in the stack.
Definition: pageowner.php:273
elgg echo
Translates a string.
Definition: languages.js:43
elgg_register_page_handler($identifier, $function)
Registers a page handler for a particular identifier.
Definition: pagehandler.php:34
_elgg_comment_setup_entity_menu($hook, $type, $return, $params)
Setup the menu shown with a comment.
Definition: comments.php:100
$type
Definition: add.php:8
elgg_view_layout($layout_name, $vars=array())
Displays a layout with optional parameters.
Definition: views.php:617
elgg_register_event_handler($event, $object_type, $callback, $priority=500)
Register a callback as an Elgg event handler.
Definition: elgglib.php:669
elgg register_error
Wrapper function for system_messages.
Definition: elgglib.js:383
elgg_register_ajax_view($view)
Register a view to be available for ajax calls.
Definition: views.php:208
$content
Set robots.txt action.
Definition: set_robots.php:6
elgg_view_page($title, $body, $page_shell= 'default', $vars=array())
Assembles and outputs a full page.
Definition: views.php:437
$target
Definition: responses.php:18
elgg_register_entity_type($type, $subtype=null)
Registers an entity type and subtype as a public-facing entity that should be shown in search and by ...
Definition: entities.php:1675
$entity
Definition: delete.php:10
$container
Definition: access.php:30
elgg_view_form($action, $form_vars=array(), $body_vars=array())
Definition: views.php:1280
get_entity($guid)
Loads and returns an entity object from a guid.
Definition: entities.php:604