aboutsummaryrefslogtreecommitdiff
path: root/actions/edit.php
blob: a5d84bc1801881b424d8d201baab899714322dc5 (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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php

	/**
	 * Tidypics edit album/image action
	 * 
	 */
	 
	// Make sure we're logged in (send us to the front page if not)
	if (!isloggedin()) forward();

	// Get input data
	$guid    = (int) get_input('guid');  // guid of image or album
	$title   = get_input('title');
	$body    = get_input('descript');
	$access  = get_input('access_id');
	$tags    = get_input('tags');
	$subtype = get_input('subtype');
	
	$container_guid = get_input('container_guid');
	error_log('container_guid is ' . $container_guid);

	// Make sure we actually have permission to edit
	$entity = get_entity($guid);
	if (!$entity->canEdit()) {
		forward();
	}

	// Get owning user/group
	error_log("owning user is " . $entity->getOwner());
	$owner = get_entity($entity->getOwner());

	// change access only if access is different from current
	if ($subtype == 'album' && $entity->access_id != $access) {
		$entity->access_id = $access;
	
		//get images from album and update access on image entities
		$images = get_entities("object","image", $guid, '', 999, '', false);
		foreach ($images as $im) {
			$im->access_id = $access;
			$im->save();
		}
	}


	// Set its title and description appropriately
	$entity->title = $title;
	$entity->description = $body;

	// Before we can set metadata, we need to save the entity
	if (!$entity->save()) {
		register_error(elgg_echo("album:error"));
		$entity->delete();
		forward($_SERVER['HTTP_REFERER']); //failed, so forward to previous page
	}

	// Now let's add tags
	$tagarray = string_to_tag_array($tags);
	$entity->clearMetadata('tags');
	if (is_array($tagarray)) {
		$entity->tags = $tagarray;
	}

	//if cover meta is sent from image save as metadata
	if ($subtype == 'image' && get_input('cover') == elgg_echo('album:cover:yes')) {
		$album = get_entity($container_guid); 
		$album->cover = $entity->guid;
	}

	// Success message
	if ($subtype == 'album')
		system_message(elgg_echo("album:edited"));
	else
		system_message(elgg_echo('images:edited'));

	forward($entity->getURL());
?>