aboutsummaryrefslogtreecommitdiff
path: root/actions/videolist/edit.php
blob: 6670ceadb33c9d0ad453d541dfb57f422cb70caa (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
<?php
/**
 * Create or edit a video
 *
 * @package ElggVideolist
 */

$variables = elgg_get_config('videolist');
$input = array();
foreach ($variables as $name => $type) {
	$input[$name] = get_input($name);
	if ($name == 'title') {
		$input[$name] = strip_tags($input[$name]);
	}
	if ($type == 'tags') {
		$input[$name] = string_to_tag_array($input[$name]);
	}
}

// Get guids
$video_guid = (int)get_input('video_guid');
$container_guid = (int)get_input('container_guid');

elgg_make_sticky_form('videolist');

elgg_load_library('elgg:videolist');

// If new video, get data from video providers
if(!$video_guid) {
	if (!$input['video_url']) {
		register_error(elgg_echo('videolist:error:no_url'));
		forward(REFERER);
	}

	$parsed_url = videolist_parseurl($input['video_url']);

	if(!$parsed_url) {
		register_error(elgg_echo('videolist:error:invalid_url'));
		forward(REFERER);
	}
	
	unset($input['title']);
	unset($input['description']);
	$input = array_merge(videolist_get_data($parsed_url), $input);
	
} else {
	unset($input['video_url']);
}

if ($video_guid) {
	$video = get_entity($video_guid);
	if (!$video || !$video->canEdit()) {
		register_error(elgg_echo('videolist:error:no_save'));
		forward(REFERER);
	}
	$new_video = false;
} else {
	$video = new ElggObject();
	$video->subtype = 'videolist_item';
	$new_video = true;
}

if (sizeof($input) > 0) {
	foreach ($input as $name => $value) {
		$video->$name = $value;
	}
}

$video->container_guid = $container_guid;

if ($video->save()) {

	elgg_clear_sticky_form('videolist');

	system_message(elgg_echo('videolist:saved'));

	if ($new_video) {
		add_to_river('river/object/videolist_item/create', 'create', elgg_get_logged_in_user_guid(), $video->guid);
	}

	forward($video->getURL());
} else {
	register_error(elgg_echo('videolist:error:no_save'));
	forward(REFERER);
}