]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
Move URL preprocessing to hook
authorSteve Clay <steve@mrclay.org>
Tue, 10 Apr 2012 13:51:20 +0000 (09:51 -0400)
committerSteve Clay <steve@mrclay.org>
Tue, 10 Apr 2012 13:51:20 +0000 (09:51 -0400)
actions/videolist/edit.php
lib/videolist.php
start.php

index 107cdc917a02ace3f5a95e298fd4c0e91c6743cb..fe614cd5a336706adc38b45a764b4b0bd035db24 100644 (file)
@@ -27,14 +27,14 @@ elgg_load_library('elgg:videolist');
 \r
 // If new video, get data from video providers\r
 if(!$video_guid) {\r
-       if (!$input['video_url']) {\r
+\r
+    $input['video_url'] = elgg_trigger_plugin_hook('videolist:preprocess', 'url', $input, $input['video_url']);\r
+\r
+    if (!$input['video_url']) {\r
                register_error(elgg_echo('videolist:error:no_url'));\r
                forward(REFERER);\r
        }\r
 \r
-    // get_input (htmlawed) "fixes" URLs by breaking them\r
-    $input['video_url'] = str_replace('&amp;', '&', $input['video_url']);\r
-\r
        $parsedPlatform = videolist_parse_url($input['video_url']);\r
 \r
        if (!$parsedPlatform) {\r
index 776ce709325de4fbab6991b402aa44173962a262..b86db99cf56bfa3c999a9c288a05543af0278250 100644 (file)
@@ -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) {
index bfb1796b97aacaa7c1c0c45ee44ec5cdcc052012..f423b75ed1a976bb3e0ed60928deceecdf70f862 100644 (file)
--- 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('&amp;', '&', $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
  */