aboutsummaryrefslogtreecommitdiff
path: root/actions/photos/delete.php
blob: f8d194e553bde35bb18f35a003e4e1a8f9827dd0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
/**
 * Delete album or image
 *
 * @author Cash Costello
 * @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License v2
 */

$guid = (int) get_input('guid');
$entity = get_entity($guid);
if (!$entity) {
	// unable to get Elgg entity
	register_error(elgg_echo("tidypics:deletefailed"));
	forward(REFERER);
}

if (!$entity->canEdit()) {
	// user doesn't have permissions
	register_error(elgg_echo("tidypics:deletefailed"));
	forward(REFERER);
}

$container = $entity->getContainerEntity();

$subtype = $entity->getSubtype();
switch ($subtype) {
	case 'album':
		if (elgg_instanceof($container, 'user')) {
			$forward_url = "photos/owner/$container->username";
		} else {
			$forward_url = "photos/group/$container->guid/all";
		}
		break;
	case 'image':
		$forward_url = $container->getURL();
		break;
	default:
		forward(REFERER);
		break;
}

if ($entity->delete()) {
	system_message(elgg_echo("tidypics:deleted"));
} else {
	register_error(elgg_echo("tidypics:deletefailed"));
}

forward($forward_url);