diff options
Diffstat (limited to 'mod/videolist/actions')
-rw-r--r-- | mod/videolist/actions/videolist/delete.php | 39 | ||||
-rw-r--r-- | mod/videolist/actions/videolist/edit.php | 107 |
2 files changed, 146 insertions, 0 deletions
diff --git a/mod/videolist/actions/videolist/delete.php b/mod/videolist/actions/videolist/delete.php new file mode 100644 index 000000000..0b9724c52 --- /dev/null +++ b/mod/videolist/actions/videolist/delete.php @@ -0,0 +1,39 @@ +<?php +/** +* Elgg videolist item delete +* +* @package ElggVideolist +*/ + +$guid = (int) get_input('guid'); + +$videolist_item = get_entity($guid); +if (!$videolist_item->guid) { + register_error(elgg_echo("videolist:deletefailed")); + forward('videolist/all'); +} + +if (!$videolist_item->canEdit()) { + register_error(elgg_echo("videolist:deletefailed")); + forward($videolist_item->getURL()); +} + +$container = $videolist_item->getContainerEntity(); +$url = $videolist_item->getURL(); + +if (!$videolist_item->delete()) { + register_error(elgg_echo("videolist:deletefailed")); +} else { + system_message(elgg_echo("videolist:deleted")); +} + +// we can't come back to video url because it's deleted +if($url != $_SERVER['HTTP_REFERER']) { + forward(REFERER); +} + +if (elgg_instanceof($container, 'group')) { + forward("videolist/group/$container->guid/all"); +} else { + forward("videolist/owner/$container->username"); +} diff --git a/mod/videolist/actions/videolist/edit.php b/mod/videolist/actions/videolist/edit.php new file mode 100644 index 000000000..a5e6ea453 --- /dev/null +++ b/mod/videolist/actions/videolist/edit.php @@ -0,0 +1,107 @@ +<?php
+/**
+ * Create or edit a video
+ *
+ * @package ElggVideolist
+ */
+
+$variables = elgg_get_config('videolist');
+$input = array();
+foreach ($variables as $name => $type) {
+ $filter_input = ($name !== 'video_url');
+ $input[$name] = get_input($name, null, $filter_input);
+ 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) {
+
+ $input['video_url'] = elgg_trigger_plugin_hook('videolist:preprocess', 'url', $input, $input['video_url']);
+
+ if (!$input['video_url']) {
+ register_error(elgg_echo('videolist:error:no_url'));
+ forward(REFERER);
+ }
+
+ $parsedPlatform = videolist_parse_url($input['video_url']);
+
+ if (!$parsedPlatform) {
+ register_error(elgg_echo('videolist:error:invalid_url'));
+ forward(REFERER);
+ }
+ list ($parsed, $platform) = $parsedPlatform;
+ /* @var Videolist_PlatformInterface $platform */
+
+ unset($input['title']);
+ unset($input['description']);
+ $input = array_merge($parsed, $platform->getData($parsed), $input);
+ $input['videotype'] = $platform->getType();
+
+} 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');
+
+ // Let's save the thumbnail in the data folder
+ $thumb_url = $video->thumbnail;
+ if ($thumb_url) {
+ $thumbnail = file_get_contents($thumb_url);
+ if ($thumbnail) {
+ $prefix = "videolist/" . $video->guid;
+ $filehandler = new ElggFile();
+ $filehandler->owner_guid = $video->owner_guid;
+ $filehandler->setFilename($prefix . ".jpg");
+ $filehandler->open("write");
+ $filehandler->write($thumbnail);
+ $filehandler->close();
+ }
+ }
+
+ 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);
+}
|