From 01c44e9002d03f58c9a5271c6256096de3273eb5 Mon Sep 17 00:00:00 2001 From: Steve Clay Date: Mon, 9 Apr 2012 15:06:33 -0400 Subject: More PHPDoc comments and @var declarations to help IDE comprehension --- start.php | 52 ++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 36 insertions(+), 16 deletions(-) (limited to 'start.php') diff --git a/start.php b/start.php index 07ec618a0..d764a78c9 100644 --- a/start.php +++ b/start.php @@ -128,6 +128,12 @@ function videolist_page_handler($page) { /** * Add a menu item to the user ownerblock + * + * @param string $hook + * @param string $type + * @param array $return + * @param array $params + * @return array */ function videolist_owner_block_menu($hook, $type, $return, $params) { if (elgg_instanceof($params['entity'], 'user')) { @@ -145,6 +151,10 @@ function videolist_owner_block_menu($hook, $type, $return, $params) { return $return; } +/** + * @param ElggObject $videolist_item + * @return string + */ function videolist_url($videolist_item) { $guid = $videolist_item->guid; $title = elgg_get_friendly_title($videolist_item->title); @@ -154,6 +164,9 @@ function videolist_url($videolist_item) { /** * Event handler for videolist * + * @param string $event + * @param string $object_type + * @param ElggObject $object */ function videolist_object_notifications($event, $object_type, $object) { static $flag; @@ -177,11 +190,11 @@ function videolist_object_notifications($event, $object_type, $object) { * Intercepts the notification on an event of new video being created and prevents a notification from going out * (because one will be sent on the annotation) * - * @param unknown_type $hook - * @param unknown_type $entity_type - * @param unknown_type $returnvalue - * @param unknown_type $params - * @return unknown + * @param string $hook + * @param string $entity_type + * @param array $returnvalue + * @param array $params + * @return bool */ function videolist_object_notifications_intercept($hook, $entity_type, $returnvalue, $params) { if (isset($params)) { @@ -198,10 +211,11 @@ function videolist_object_notifications_intercept($hook, $entity_type, $returnva /** * Register videolist as an embed type. * - * @param unknown_type $hook - * @param unknown_type $type - * @param unknown_type $value - * @param unknown_type $params + * @param string $hook + * @param string $type + * @param array $value + * @param array $params + * @return array */ function videolist_embed_get_sections($hook, $type, $value, $params) { $value['videolist'] = array( @@ -216,10 +230,11 @@ function videolist_embed_get_sections($hook, $type, $value, $params) { /** * Return a list of videos for embedding * - * @param unknown_type $hook - * @param unknown_type $type - * @param unknown_type $value - * @param unknown_type $params + * @param string $hook + * @param string $type + * @param array $value + * @param array $params + * @return array */ function videolist_embed_get_items($hook, $type, $value, $params) { $options = array( @@ -245,13 +260,18 @@ function videolist_embed_get_items($hook, $type, $value, $params) { /** * Override the default entity icon for videoslist items * + * @param string $hook + * @param string $type + * @param string $returnvalue + * @param array $params * @return string Relative URL */ function videolist_icon_url_override($hook, $type, $returnvalue, $params) { $videolist_item = $params['entity']; - $size = $params['size']; - - if($videolist_item->getSubtype() != 'videolist_item'){ + /* @var ElggObject $videolist_item */ + $size = $params['size']; + + if($videolist_item->getSubtype() != 'videolist_item'){ return $returnvalue; } -- cgit v1.2.3 From e80bb29671b7887d5749a9eb147be38e6f0401f4 Mon Sep 17 00:00:00 2001 From: Steve Clay Date: Mon, 9 Apr 2012 15:07:15 -0400 Subject: Removed deprecated call, unused variable --- lib/videolist.php | 3 +-- start.php | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) (limited to 'start.php') diff --git a/lib/videolist.php b/lib/videolist.php index 96a2c6335..ae2441847 100644 --- a/lib/videolist.php +++ b/lib/videolist.php @@ -27,8 +27,7 @@ function videolist_parseurl($url){ */ function videolist_get_data($parsed) { $videotype = $parsed['videotype']; - $video_id = $parsed['video_id']; - + if(is_callable("videolist_get_data_$videotype")){ return array_merge($parsed, call_user_func("videolist_get_data_$videotype", $parsed)); } else { diff --git a/start.php b/start.php index d764a78c9..bfb1796b9 100644 --- a/start.php +++ b/start.php @@ -238,7 +238,7 @@ function videolist_embed_get_sections($hook, $type, $value, $params) { */ function videolist_embed_get_items($hook, $type, $value, $params) { $options = array( - 'owner_guid' => get_loggedin_userid(), + 'owner_guid' => elgg_get_logged_in_user_guid(), 'type_subtype_pair' => array('object' => 'videolist_item'), 'count' => TRUE ); -- 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 'start.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 'start.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 4af120de2bd0fe2046795346a40102f00fbe5479 Mon Sep 17 00:00:00 2001 From: Steve Clay Date: Tue, 10 Apr 2012 12:04:42 -0400 Subject: Allow plugins to alter video dimensions. --- start.php | 28 ++++++++++++++++++++++++++++ views/default/object/videolist_item.php | 7 ++++--- 2 files changed, 32 insertions(+), 3 deletions(-) (limited to 'start.php') diff --git a/start.php b/start.php index 2791b1185..77bf0a7bc 100644 --- a/start.php +++ b/start.php @@ -288,6 +288,34 @@ function videolist_icon_url_override($hook, $type, $returnvalue, $params) { } } +/** + * @param ElggObject $videolist_item + * @return array + */ +function videolist_get_video_dimensions(ElggObject $videolist_item) { + $dimensions = array( + 'width' => 600, + 'height' => 400, + ); + $params['entity'] = $videolist_item; + $params['videotype'] = $videolist_item->videotype; + $dimensions = elgg_trigger_plugin_hook( + 'videolist:setdimensions', + $params['videotype'], + $params, + $dimensions); + if (! is_array($dimensions)) { + $dimensions = array(); + } + if (empty($dimensions['width']) || ! is_numeric($dimensions['width'])) { + $dimensions['width'] = 600; + } + if (empty($dimensions['height']) || ! is_numeric($dimensions['height'])) { + $dimensions['height'] = 400; + } + return $dimensions; +} + /** * Prepend HTTP scheme if missing * @param string $hook diff --git a/views/default/object/videolist_item.php b/views/default/object/videolist_item.php index e30d9d95b..5e0db00ce 100644 --- a/views/default/object/videolist_item.php +++ b/views/default/object/videolist_item.php @@ -60,11 +60,12 @@ if (elgg_in_context('widgets')) { } if ($full && !elgg_in_context('gallery')) { - + + $dimensions = videolist_get_video_dimensions($entity); $content = elgg_view("videolist/watch/{$entity->videotype}", array( 'entity' => $entity, - 'width' => 600, - 'height' => 400, + 'width' => $dimensions['width'], + 'height' => $dimensions['height'], )); $content = "
$content
"; -- cgit v1.2.3