From f399afdd2e3cc072efaca069b7a874c7801b31f6 Mon Sep 17 00:00:00 2001 From: Steve Clay Date: Mon, 9 Apr 2012 17:05:57 -0400 Subject: switched to platform classes. see https://github.com/Elgg/videolist/issues/4 --- actions/videolist/edit.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'actions/videolist/edit.php') diff --git a/actions/videolist/edit.php b/actions/videolist/edit.php index be566de7e..1572d88ce 100644 --- a/actions/videolist/edit.php +++ b/actions/videolist/edit.php @@ -32,16 +32,19 @@ if(!$video_guid) { forward(REFERER); } - $parsed_url = videolist_parseurl($input['video_url']); - if(!$parsed_url) { + $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(videolist_get_data($parsed_url), $input); + $input = array_merge($parsed, $platform->getData($parsed), $input); } else { unset($input['video_url']); -- cgit v1.2.3 From 0577676d63ad90e1328ffd7ffaf7a93f2e73187c Mon Sep 17 00:00:00 2001 From: Steve Clay Date: Mon, 9 Apr 2012 17:06:47 -0400 Subject: fix for ampersands getting HTML-escaped in URLs --- actions/videolist/edit.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'actions/videolist/edit.php') diff --git a/actions/videolist/edit.php b/actions/videolist/edit.php index 1572d88ce..107cdc917 100644 --- a/actions/videolist/edit.php +++ b/actions/videolist/edit.php @@ -32,6 +32,8 @@ if(!$video_guid) { forward(REFERER); } + // get_input (htmlawed) "fixes" URLs by breaking them + $input['video_url'] = str_replace('&', '&', $input['video_url']); $parsedPlatform = videolist_parse_url($input['video_url']); -- cgit v1.2.3 From 6d4ac854d8f0a4480ffe16f2bd2a7861707074ee Mon Sep 17 00:00:00 2001 From: Steve Clay Date: Tue, 10 Apr 2012 09:51:20 -0400 Subject: Move URL preprocessing to hook --- actions/videolist/edit.php | 8 ++++---- lib/videolist.php | 9 +++------ start.php | 23 +++++++++++++++++++++++ 3 files changed, 30 insertions(+), 10 deletions(-) (limited to 'actions/videolist/edit.php') diff --git a/actions/videolist/edit.php b/actions/videolist/edit.php index 107cdc917..fe614cd5a 100644 --- a/actions/videolist/edit.php +++ b/actions/videolist/edit.php @@ -27,14 +27,14 @@ elgg_load_library('elgg:videolist'); // If new video, get data from video providers if(!$video_guid) { - if (!$input['video_url']) { + + $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); } - // get_input (htmlawed) "fixes" URLs by breaking them - $input['video_url'] = str_replace('&', '&', $input['video_url']); - $parsedPlatform = videolist_parse_url($input['video_url']); if (!$parsedPlatform) { diff --git a/lib/videolist.php b/lib/videolist.php index 776ce7093..b86db99cf 100644 --- a/lib/videolist.php +++ b/lib/videolist.php @@ -28,12 +28,9 @@ function videolist_get_default_platforms() { * @return array [parsed, platform] */ function videolist_parse_url($url) { - $parsed = parse_url($url); - if (empty($parsed['host']) && ! empty($parsed['path']) && $parsed['path'][0] !== '/') { - // user probably forgot scheme - $url = 'http://' . $url; - } - $params['url'] = $url; + $params = array( + 'url' => $url, + ); $platforms = videolist_get_default_platforms(); $platforms = elgg_trigger_plugin_hook('videolist:prepare', 'platforms', $params, $platforms); foreach ($platforms as $list) { diff --git a/start.php b/start.php index bfb1796b9..f423b75ed 100644 --- a/start.php +++ b/start.php @@ -61,6 +61,9 @@ function videolist_init() { // register for embed elgg_register_plugin_hook_handler('embed_get_sections', 'all', 'videolist_embed_get_sections'); elgg_register_plugin_hook_handler('embed_get_items', 'videolist', 'videolist_embed_get_items'); + + // handle URLs without scheme + elgg_register_plugin_hook_handler('videolist:preprocess', 'url', 'videolist_preprocess_url'); // Register actions $actions_path = elgg_get_plugins_path() . "videolist/actions/videolist"; @@ -285,6 +288,26 @@ function videolist_icon_url_override($hook, $type, $returnvalue, $params) { } } +/** + * Prepend HTTP scheme if missing + * @param string $hook + * @param string $type + * @param string $returnvalue + * @param array $params + * @return string + */ +function videolist_preprocess_url($hook, $type, $returnvalue, $params) { + // undo get_input (htmlawed's) HTML-encoding + $returnvalue = str_replace('&', '&', $returnvalue); + + $parsed = parse_url($returnvalue); + if (empty($parsed['host']) && ! empty($parsed['path']) && $parsed['path'][0] !== '/') { + // user probably forgot scheme + $returnvalue = 'http://' . $returnvalue; + } + return $returnvalue; +} + /** * Process upgrades for the videolist plugin */ -- cgit v1.2.3 From c70ec6161e4ef4d0daee6514da0a4d4e6b183207 Mon Sep 17 00:00:00 2001 From: Steve Clay Date: Tue, 10 Apr 2012 10:43:51 -0400 Subject: Remove filtering on URL input --- actions/videolist/edit.php | 3 ++- start.php | 3 --- 2 files changed, 2 insertions(+), 4 deletions(-) (limited to 'actions/videolist/edit.php') diff --git a/actions/videolist/edit.php b/actions/videolist/edit.php index fe614cd5a..480a3943b 100644 --- a/actions/videolist/edit.php +++ b/actions/videolist/edit.php @@ -8,7 +8,8 @@ $variables = elgg_get_config('videolist'); $input = array(); foreach ($variables as $name => $type) { - $input[$name] = get_input($name); + $filter_input = ($name !== 'video_url'); + $input[$name] = get_input($name, null, $filter_input); if ($name == 'title') { $input[$name] = strip_tags($input[$name]); } diff --git a/start.php b/start.php index f423b75ed..2791b1185 100644 --- a/start.php +++ b/start.php @@ -297,9 +297,6 @@ function videolist_icon_url_override($hook, $type, $returnvalue, $params) { * @return string */ function videolist_preprocess_url($hook, $type, $returnvalue, $params) { - // undo get_input (htmlawed's) HTML-encoding - $returnvalue = str_replace('&', '&', $returnvalue); - $parsed = parse_url($returnvalue); if (empty($parsed['host']) && ! empty($parsed['path']) && $parsed['path'][0] !== '/') { // user probably forgot scheme -- cgit v1.2.3 From d2bb8789a80215708517f4ffc88462382ec601a8 Mon Sep 17 00:00:00 2001 From: Steve Clay Date: Tue, 10 Apr 2012 10:44:40 -0400 Subject: Remove redundant videotype from parseUrl return array --- actions/videolist/edit.php | 1 + lib/Videolist/Platform/Bliptv.php | 1 - lib/Videolist/Platform/Gisstv.php | 1 - lib/Videolist/Platform/Metacafe.php | 1 - lib/Videolist/Platform/Vimeo.php | 1 - lib/Videolist/Platform/Youtube.php | 1 - 6 files changed, 1 insertion(+), 5 deletions(-) (limited to 'actions/videolist/edit.php') diff --git a/actions/videolist/edit.php b/actions/videolist/edit.php index 480a3943b..4b96720d8 100644 --- a/actions/videolist/edit.php +++ b/actions/videolist/edit.php @@ -48,6 +48,7 @@ if(!$video_guid) { unset($input['title']); unset($input['description']); $input = array_merge($parsed, $platform->getData($parsed), $input); + $input['videotype'] = $platform->getType(); } else { unset($input['video_url']); diff --git a/lib/Videolist/Platform/Bliptv.php b/lib/Videolist/Platform/Bliptv.php index 6956e060d..aa53032f9 100644 --- a/lib/Videolist/Platform/Bliptv.php +++ b/lib/Videolist/Platform/Bliptv.php @@ -17,7 +17,6 @@ class Videolist_Platform_Bliptv implements Videolist_PlatformInterface } return array( - 'videotype' => 'bliptv', 'video_id' => $parsed['path'], ); } diff --git a/lib/Videolist/Platform/Gisstv.php b/lib/Videolist/Platform/Gisstv.php index f811619a8..b79898449 100644 --- a/lib/Videolist/Platform/Gisstv.php +++ b/lib/Videolist/Platform/Gisstv.php @@ -25,7 +25,6 @@ class Videolist_Platform_Gisstv implements Videolist_PlatformInterface } return array( - 'videotype' => 'gisstv', 'video_id' => $video_id, ); } diff --git a/lib/Videolist/Platform/Metacafe.php b/lib/Videolist/Platform/Metacafe.php index 3cf2fb8ce..7da6d1647 100644 --- a/lib/Videolist/Platform/Metacafe.php +++ b/lib/Videolist/Platform/Metacafe.php @@ -17,7 +17,6 @@ class Videolist_Platform_Metacafe implements Videolist_PlatformInterface } return array( - 'videotype' => 'metacafe', 'video_id' => $path[2], ); } diff --git a/lib/Videolist/Platform/Vimeo.php b/lib/Videolist/Platform/Vimeo.php index 82bd57309..a4a1f275c 100644 --- a/lib/Videolist/Platform/Vimeo.php +++ b/lib/Videolist/Platform/Vimeo.php @@ -17,7 +17,6 @@ class Videolist_Platform_Vimeo implements Videolist_PlatformInterface } return array( - 'videotype' => 'vimeo', 'video_id' => $path[1], ); } diff --git a/lib/Videolist/Platform/Youtube.php b/lib/Videolist/Platform/Youtube.php index 648ac282c..d5a388356 100644 --- a/lib/Videolist/Platform/Youtube.php +++ b/lib/Videolist/Platform/Youtube.php @@ -27,7 +27,6 @@ class Videolist_Platform_Youtube implements Videolist_PlatformInterface } if ($id) { return array( - 'videotype' => 'youtube', 'video_id' => $id, ); } -- cgit v1.2.3 From 4a447a9cfe118373f3b5e7ec35382239455d1541 Mon Sep 17 00:00:00 2001 From: Steve Clay Date: Tue, 10 Apr 2012 12:04:03 -0400 Subject: Don't try to load null when there's no thumbnail URL --- actions/videolist/edit.php | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) (limited to 'actions/videolist/edit.php') diff --git a/actions/videolist/edit.php b/actions/videolist/edit.php index 4b96720d8..a5e6ea453 100644 --- a/actions/videolist/edit.php +++ b/actions/videolist/edit.php @@ -80,16 +80,19 @@ if ($video->save()) { elgg_clear_sticky_form('videolist'); // Let's save the thumbnail in the data folder - $thumbnail = file_get_contents($video->thumbnail); - 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(); - } + $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')); -- cgit v1.2.3