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 --- start.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'start.php') 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