Elgg  Version 1.11
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 
36  if (elgg_is_xhr()) {
37  // @todo move to its own view object/comment/content in 1.x
38  echo elgg_view('output/longtext', array(
39  'value' => $comment->description,
40  'class' => 'elgg-inner',
41  'data-role' => 'comment-text',
42  ));
43  }
44  } else {
45  register_error(elgg_echo('generic_comment:failure'));
46  }
47 } else {
48  // Create a new comment on the target entity
50  if (!$entity) {
51  register_error(elgg_echo("generic_comment:notfound"));
53  }
54 
56 
58  $comment->description = $comment_text;
59  $comment->owner_guid = $user->getGUID();
60  $comment->container_guid = $entity->getGUID();
61  $comment->access_id = $entity->access_id;
62  $guid = $comment->save();
63 
64  if (!$guid) {
65  register_error(elgg_echo("generic_comment:failure"));
67  }
68 
69  // Notify if poster wasn't owner
70  if ($entity->owner_guid != $user->guid) {
71  $owner = $entity->getOwnerEntity();
72 
73  notify_user($owner->guid,
74  $user->guid,
75  elgg_echo('generic_comment:email:subject', array(), $owner->language),
76  elgg_echo('generic_comment:email:body', array(
77  $entity->title,
78  $user->name,
80  $comment->getURL(),
81  $user->name,
82  $user->getURL()
83  ), $owner->language),
84  array(
85  'object' => $comment,
86  'action' => 'create',
87  )
88  );
89  }
90 
91  // Add to river
93  'view' => 'river/object/comment/create',
94  'action_type' => 'comment',
95  'subject_guid' => $user->guid,
96  'object_guid' => $guid,
97  'target_guid' => $entity_guid,
98  ));
99 
100  system_message(elgg_echo('generic_comment:posted'));
101 }
102 
103 if ($is_edit_page) {
104  forward($comment->getURL());
105 }
106 
$comment_text
Definition: save.php:11
elgg_is_xhr()
Checks whether the request was requested via ajax.
Definition: actions.php:227
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:62
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:57
$comment_guid
Definition: save.php:10
$entity_guid
Definition: save.php:9
if(!$entity) $user
Definition: save.php:55
elgg_instanceof($entity, $type=null, $subtype=null, $class=null)
Checks if $entity is an and optionally for type and subtype.
Definition: entities.php:922
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:1995
elgg echo
Translates a string.
Definition: languages.js:43
elgg_view($view, $vars=array(), $bypass=false, $ignored=false, $viewtype= '')
Return a parsed view.
Definition: views.php:354
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:382