aboutsummaryrefslogtreecommitdiff
path: root/mod/lightpics/actions/photos/batch/edit.php
blob: 6d376a9db45932a8e8729562cc1c2c8f199b7818 (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
<?php
/**
 * Edit the images in a batch
 *
 * @author Cash Costello
 * @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License v2
 */

$guids = get_input('guid');
$titles = get_input('title');
$captions = get_input('caption');
$tags = get_input('tags');

$not_updated = array();
foreach ($guids as $key => $guid) {
	$image = get_entity($guid);

	if ($image->canEdit()) {

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

		// set description appropriately
		$image->description = $captions[$key];
		$image->tags = string_to_tag_array($tags[$key]);

		if (!$image->save()) {
			array_push($not_updated, $image->getGUID());
		}
	}
}

if (count($not_updated) > 0) {
	register_error(elgg_echo("images:notedited"));
} else {
	system_message(elgg_echo("images:edited"));
}
forward($image->getContainerEntity()->getURL());