aboutsummaryrefslogtreecommitdiff
path: root/mod/lightbox/actions/lightbox/edit.php
blob: 6ee49e671b5edaacf8d91b7fd3d1f475dc5ec7f8 (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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
/**
 * Elgg album create/edit action
 *
 * @package ElggLightbox
 */

elgg_load_library('elgg:lightbox');

// Get variables
$title = get_input("title");
$desc = get_input("description");
$access_id = (int) get_input("access_id");
$container_guid = (int) get_input('container_guid', 0);
$guid = (int) get_input('guid');
$tags = get_input("tags");
$images = lightbox_get_image_inputs();

if ($container_guid == 0) {
	$container_guid = elgg_get_logged_in_user_guid();
}

elgg_make_sticky_form('lightbox:album');

// check whether this is a new album or an edit
$new_album = true;
if ($guid > 0) {
	$new_album = false;
}

if ($new_album) {

	$album = new LightboxPluginAlbum();

} else {
	// load original album object
	$album = new LightboxPluginAlbum($guid);

	// user must be able to edit album
	if (!$album->guid || !$album->canEdit()) {
		register_error(elgg_echo('lightbox:noaccess'));
		forward(REFERER);
	}

	if (!$title) {
		// user blanked title, but we need one
		$title = $album->title;
	}
}

$album->title = $title;
$album->description = $desc;
$album->access_id = $access_id;
$album->container_guid = $container_guid;
$album->tags = string_to_tag_array($tags);

$guid = $album->save();

// lightbox saved so clear sticky form
elgg_clear_sticky_form('lightbox:album');


// handle results differently for new albums and album updates
if ($new_album) {
	if ($guid && $album->attachImages($images)) {
		system_message(elgg_echo("lightbox:saved"));
		add_to_river('river/object/album/create', 'create', elgg_get_logged_in_user_guid(), $album->guid);
		forward("photos/edit/images/$guid");
	} else {
		// failed to save album object - nothing we can do about this
		lightbox_delete_image_inputs($images);
		register_error(elgg_echo("lightbox:save:failed"));
		if (get_entity($container_guid)->getType() == 'group') {
			forward("photos/group/$container->guid/all");
		} else {
			forward("photos/owner/$container->username");
		}
	}

	

} else {
	if ($guid) {
		system_message(elgg_echo("lightbox:saved"));
	} else {
		lightbox_delete_image_inputs($images);
		register_error(elgg_echo("lightbox:save:failed"));
	}

	forward($album->getURL());
}