Elgg  Version 2.3
delete.php
Go to the documentation of this file.
1 <?php
2 
6 $guid = get_input('guid');
8 
9 if (!$entity instanceof ElggEntity) {
10  register_error(elgg_echo('entity:delete:item_not_found'));
12 }
13 
14 if (!$entity->canDelete() || $entity instanceof ElggPlugin || $entity instanceof ElggSite) {
15  register_error(elgg_echo('entity:delete:permission_denied'));
17 }
18 
19 set_time_limit(0);
20 
21 // determine what name to show on success
22 $display_name = $entity->getDisplayName();
23 if (!$display_name) {
24  $display_name = elgg_echo('entity:delete:item');
25 }
26 
27 $type = $entity->getType();
28 $subtype = $entity->getSubtype();
29 $container = $entity->getContainerEntity();
30 
31 if (!$entity->delete()) {
32  register_error(elgg_echo('entity:delete:fail', array($display_name)));
34 }
35 
36 // determine forward URL
38 if (!$forward_url) {
40  $referrer_url = !empty($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '';
42  if ($referrer_url && 0 == strpos($referrer_url, $site_url)) {
43  $referrer_path = substr($referrer_url, strlen($site_url));
44  $segments = explode('/', $referrer_path);
45  if (in_array($guid, $segments)) {
46  // referrer URL contains a reference to the entity that will be deleted
47  $forward_url = ($container) ? $container->getURL() : '';
48  }
49  } else if ($container) {
50  $forward_url = $container->getURL() ? : '';
51  }
52 }
53 
54 $success_keys = array(
55  "entity:delete:$type:$subtype:success",
56  "entity:delete:$type:success",
57  "entity:delete:success",
58 );
59 
60 foreach ($success_keys as $success_key) {
61  if (elgg_language_key_exists($success_key)) {
62  system_message(elgg_echo($success_key, array($display_name)));
63  break;
64  }
65 }
elgg_language_key_exists($key, $language= 'en')
Check if a given language key exists.
Definition: languages.php:133
$display_name
Definition: delete.php:22
if(!$entity->delete()) $forward_url
Definition: delete.php:37
elgg_echo($message_key, $args=array(), $language="")
Given a message key, returns an appropriately translated full-text string.
Definition: languages.php:21
elgg_normalize_site_url($unsafe_url)
From untrusted input, get a site URL safe for forwarding.
Definition: output.php:326
$subtype
Definition: delete.php:28
elgg forward
Meant to mimic the php forward() function by simply redirecting the user to another page...
Definition: elgglib.js:425
const REFERRER
Definition: elgglib.php:2113
$guid
Definition: delete.php:13
$container
Definition: delete.php:29
get_input($variable, $default=null, $filter_result=true)
Get some input from variables passed submitted through GET or POST.
Definition: input.php:27
$site_url
Definition: header_logo.php:8
if(!$forward_url) $success_keys
Definition: delete.php:54
elgg_get_site_url($site_guid=0)
Get the URL for the current (or specified) site.
elgg system_message
Wrapper function for system_messages.
Definition: elgglib.js:390
elgg register_error
Wrapper function for system_messages.
Definition: elgglib.js:399
$entity
Definition: delete.php:7
get_entity($guid)
Loads and returns an entity object from a guid.
Definition: entities.php:204
if(!$display_name) $type
Definition: delete.php:27