Elgg  Version 1.9
save.php
Go to the documentation of this file.
1 <?php
9 $entity_guid = (int) get_input('entity_guid', 0, false);
10 $comment_guid = (int) get_input('comment_guid', 0, false);
11 $comment_text = get_input('generic_comment');
12 $is_edit_page = (bool) get_input('is_edit_page', false, false);
13 
14 if (empty($comment_text)) {
15  register_error(elgg_echo("generic_comment:blank"));
17 }
18 
19 if ($comment_guid) {
20  // Edit an existing comment
22 
23  if (!elgg_instanceof($comment, 'object', 'comment')) {
24  register_error(elgg_echo("generic_comment:notfound"));
26  }
27  if (!$comment->canEdit()) {
28  register_error(elgg_echo("actionunauthorized"));
30  }
31 
32  $comment->description = $comment_text;
33  if ($comment->save()) {
34  system_message(elgg_echo('generic_comment:updated'));
35  } else {
36  register_error(elgg_echo('generic_comment:failure'));
37  }
38 } else {
39  // Create a new comment on the target entity
41  if (!$entity) {
42  register_error(elgg_echo("generic_comment:notfound"));
44  }
45 
47 
49  $comment->description = $comment_text;
50  $comment->owner_guid = $user->getGUID();
51  $comment->container_guid = $entity->getGUID();
52  $comment->access_id = $entity->access_id;
53  $guid = $comment->save();
54 
55  if (!$guid) {
56  register_error(elgg_echo("generic_comment:failure"));
58  }
59 
60  // Notify if poster wasn't owner
61  if ($entity->owner_guid != $user->guid) {
62  $owner = $entity->getOwnerEntity();
63 
64  notify_user($owner->guid,
65  $user->guid,
66  elgg_echo('generic_comment:email:subject', array(), $owner->language),
67  elgg_echo('generic_comment:email:body', array(
68  $entity->title,
69  $user->name,
71  $entity->getURL(),
72  $user->name,
73  $user->getURL()
74  ), $owner->language),
75  array(
76  'object' => $comment,
77  'action' => 'create',
78  )
79  );
80  }
81 
82  // Add to river
84  'view' => 'river/object/comment/create',
85  'action_type' => 'comment',
86  'subject_guid' => $user->guid,
87  'object_guid' => $guid,
88  'target_guid' => $entity_guid,
89  ));
90 
91  system_message(elgg_echo('generic_comment:posted'));
92 }
93 
94 if ($is_edit_page) {
95  forward($comment->getURL());
96 }
97 
$comment_text
Definition: save.php:11
get_input($variable, $default=null, $filter_result=true)
Get some input from variables passed submitted through GET or POST.
Definition: input.php:27
$is_edit_page
Definition: save.php:12
$guid
Definition: save.php:53
elgg forward
Meant to mimic the php forward() function by simply redirecting the user to another page...
Definition: elgglib.js:419
$comment
Definition: save.php:48
$comment_guid
Definition: save.php:10
$entity_guid
Definition: save.php:9
if(!$entity) $user
Definition: save.php:46
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
elgg_create_river_item(array $options=array())
Adds an item to the river.
Definition: river.php:37
$owner
Definition: crop.php:8
const REFERER
Definition: elgglib.php:2162
elgg system_message
Wrapper function for system_messages.
Definition: elgglib.js:374
elgg register_error
Wrapper function for system_messages.
Definition: elgglib.js:383
notify_user($to, $from, $subject, $message, array $params=array(), $methods_override="")
Notify a user via their preferences.
elgg_get_logged_in_user_entity()
Return the current logged in user, or null if no user is logged in.
Definition: sessions.php:32
if(!elgg_is_logged_in()) $entity
Definition: save.php:17
get_entity($guid)
Loads and returns an entity object from a guid.
Definition: entities.php:604