Elgg  Version 1.9
add.php
Go to the documentation of this file.
1 <?php
9 // Get the GUID of the user to friend
10 $friend_guid = get_input('friend');
12 if (!$friend) {
13  register_error(elgg_echo('error:missing_data'));
15 }
16 
17 $errors = false;
18 
19 // Get the user
20 try {
21  if (!elgg_get_logged_in_user_entity()->addFriend($friend_guid)) {
22  $errors = true;
23  }
24 } catch (Exception $e) {
25  register_error(elgg_echo("friends:add:failure", array($friend->name)));
26  $errors = true;
27 }
28 if (!$errors) {
29  // add to river
31  'view' => 'river/relationship/friend/create',
32  'action_type' => 'friend',
33  'subject_guid' => elgg_get_logged_in_user_guid(),
34  'object_guid' => $friend_guid,
35  ));
36  system_message(elgg_echo("friends:add:successful", array($friend->name)));
37 }
38 
39 // Forward back to the page you friended the user on
get_input($variable, $default=null, $filter_result=true)
Get some input from variables passed submitted through GET or POST.
Definition: input.php:27
$e
Definition: metadata.php:12
$friend
Definition: add.php:11
elgg forward
Meant to mimic the php forward() function by simply redirecting the user to another page...
Definition: elgglib.js:419
if(!$friend) $errors
Definition: add.php:17
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
const REFERER
Definition: elgglib.php:2162
$friend_guid
Definition: add.php:10
elgg system_message
Wrapper function for system_messages.
Definition: elgglib.js:374
elgg register_error
Wrapper function for system_messages.
Definition: elgglib.js:383
elgg_get_logged_in_user_entity()
Return the current logged in user, or null if no user is logged in.
Definition: sessions.php:32
elgg_get_logged_in_user_guid()
Return the current logged in user by guid.
Definition: sessions.php:42
get_entity($guid)
Loads and returns an entity object from a guid.
Definition: entities.php:604