Elgg  Version 2.2
 All Classes Namespaces Files Functions Variables Pages
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 
13 if (empty($comment_text)) {
14  register_error(elgg_echo("generic_comment:blank"));
16 }
17 
18 if ($comment_guid) {
19  // Edit an existing comment
21 
22  if (!elgg_instanceof($comment, 'object', 'comment')) {
23  register_error(elgg_echo("generic_comment:notfound"));
25  }
26  if (!$comment->canEdit()) {
27  register_error(elgg_echo("actionunauthorized"));
29  }
30 
31  $comment->description = $comment_text;
32  if ($comment->save()) {
33  system_message(elgg_echo('generic_comment:updated'));
34 
35  if (elgg_is_xhr()) {
36  // @todo move to its own view object/comment/content in 1.x
37  echo elgg_view('output/longtext', array(
38  'value' => $comment->description,
39  'class' => 'elgg-inner',
40  'data-role' => 'comment-text',
41  ));
42  }
43  } else {
44  register_error(elgg_echo('generic_comment:failure'));
45  }
46 } else {
47  // Create a new comment on the target entity
49  if (!$entity) {
50  register_error(elgg_echo("generic_comment:notfound"));
52  }
53 
55 
57  $comment->description = $comment_text;
58  $comment->owner_guid = $user->getGUID();
59  $comment->container_guid = $entity->getGUID();
60  $comment->access_id = $entity->access_id;
61  $guid = $comment->save();
62 
63  if (!$guid) {
64  register_error(elgg_echo("generic_comment:failure"));
66  }
67 
68  // Notify if poster wasn't owner
69  if ($entity->owner_guid != $user->guid) {
70  $owner = $entity->getOwnerEntity();
71 
72  notify_user($owner->guid,
73  $user->guid,
74  elgg_echo('generic_comment:email:subject', array(), $owner->language),
75  elgg_echo('generic_comment:email:body', array(
76  $entity->title,
77  $user->name,
79  $comment->getURL(),
80  $user->name,
81  $user->getURL()
82  ), $owner->language),
83  array(
84  'object' => $comment,
85  'action' => 'create',
86  )
87  );
88  }
89 
90  // Add to river
92  'view' => 'river/object/comment/create',
93  'action_type' => 'comment',
94  'subject_guid' => $user->guid,
95  'object_guid' => $guid,
96  'target_guid' => $entity_guid,
97  ));
98 
99  system_message(elgg_echo('generic_comment:posted'));
100 }
101 
102 // return to activity page if posted from there
103 if (!empty($_SERVER['HTTP_REFERER'])) {
104  // don't redirect to URLs from client without verifying within site
105  $site_url = preg_quote(elgg_get_site_url(), '~');
106  if (preg_match("~^{$site_url}activity(/|\\z)~", $_SERVER['HTTP_REFERER'], $m)) {
107  forward("{$m[0]}#elgg-object-{$comment->guid}");
108  }
109 }
110 
111 forward($comment->getURL());
$comment_text
Definition: save.php:11
elgg_is_xhr()
Checks whether the request was requested via ajax.
Definition: actions.php:226
$m
Definition: metadata.php:11
elgg_echo($message_key, $args=array(), $language="")
Given a message key, returns an appropriately translated full-text string.
Definition: languages.php:21
$guid
Definition: save.php:61
$comment
Definition: save.php:56
$comment_guid
Definition: save.php:10
register_error($error)
Display an error on next page load.
Definition: elgglib.php:452
$entity_guid
Definition: save.php:9
if(!$entity) $user
Definition: save.php:54
elgg_instanceof($entity, $type=null, $subtype=null, $class=null)
Checks if $entity is an and optionally for type and subtype.
Definition: entities.php:716
elgg_create_river_item(array $options=array())
Adds an item to the river.
Definition: river.php:37
$owner
Definition: crop.php:8
get_input($variable, $default=null, $filter_result=true)
Get some input from variables passed submitted through GET or POST.
Definition: input.php:27
const REFERER
Definition: elgglib.php:2029
$site_url
Definition: header_logo.php:8
elgg_view($view, $vars=array(), $ignore1=false, $ignore2=false, $viewtype= '')
Return a parsed view.
Definition: views.php:342
elgg_get_site_url($site_guid=0)
Get the URL for the current (or specified) site.
forward($location="", $reason= 'system')
Forward to $location.
Definition: elgglib.php:93
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:16
system_message($message)
Display a system message on next page load.
Definition: elgglib.php:438
get_entity($guid)
Loads and returns an entity object from a guid.
Definition: entities.php:204