aboutsummaryrefslogtreecommitdiff
path: root/actions/edit_multi.php
blob: 1d0e537b026050d5ad743e9878951986da573417 (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
<?php
/**
 * Elgg album: multi image edit action
 *
 * This is called when uploading images
 */

// Make sure we're logged in 
gatekeeper();

// Get input data
$title_array = get_input('title');
$caption_array = get_input('caption');
$tags_array = get_input('tags');
$image_guid_array = get_input('image_guid');
$container_guid = get_input('container_guid');
$album_entity = get_entity($container_guid);
$cover = get_input('cover');
$not_updated = array();

foreach($image_guid_array as $key => $im) {
	$image = get_entity($im);

	if ($image->canEdit()) {

		// Convert string of tags into a preformatted array
		$tagarray = string_to_tag_array($tags_array[$key]);

		//set title appropriately
		if ($title_array[$key]) {
			$image->title = $title_array[$key];
		} else {
			$image->title = substr($image->originalfilename, 0, strrpos($image->originalfilename, '.'));
		}

		//set description appropriately
		$image->description = $caption_array[$key];

		// Before we can set metadata, we need to save the image
		if (!$image->save()) {
			array_push($not_updated, $image->guid);
		}

		// Now let's add tags. We can pass an array directly to the object property! Easy.
		$image->clearMetadata('tags');
		if (is_array($tagarray)) {
			$image->tags = $tagarray;
		}

		//if cover meta is sent from image save as metadata
		if ($cover == $im) {
			$album_entity->setCoverImageGuid($im);
		}
	}
}

// Success message
if (count($not_updated) > 0) {
	register_error(elgg_echo("images:notedited"));
} else {
	system_message(elgg_echo("images:edited"));
}

// Forward to the main album page
forward($album_entity->getURL());