|
@@ -1,35 +1,42 @@
|
|
|
<?php
|
|
|
|
|
|
/**
|
|
|
+ * @file
|
|
|
* Provides a simple field for easily embedding videos from youtube or vimeo
|
|
|
*
|
|
|
- * This module is not intended to replace media or video - it does not allow for any local storage of videos, custom players or anything else
|
|
|
- * It simply allows users to embed videos from youtube and vimeo - and provides a hook to allow other modules to provide more providers.
|
|
|
+ * This module is not intended to replace media or video - it does not allow for
|
|
|
+ * any local storage of videos, custom players or anything else.
|
|
|
+ * It simply allows users to embed videos from youtube and vimeo - and provides
|
|
|
+ * hooks to allow other modules to provide more providers.
|
|
|
*
|
|
|
- * Uses CTools Export UI to manage settings. @see ./plugins/export_ui/video_embed_field_export_ui.inc
|
|
|
+ * Uses CTools Export UI to manage settings.
|
|
|
+ *
|
|
|
+ * @see ./plugins/export_ui/video_embed_field_export_ui.inc
|
|
|
*
|
|
|
* @author jec006, jdelaune
|
|
|
*/
|
|
|
|
|
|
// Load all Field module hooks.
|
|
|
module_load_include('inc', 'video_embed_field', 'video_embed_field.field');
|
|
|
-// Load the admin forms
|
|
|
+// Load the admin forms.
|
|
|
module_load_include('inc', 'video_embed_field', 'video_embed_field.admin');
|
|
|
-// Load our default handlers
|
|
|
+// Load our default handlers.
|
|
|
module_load_include('inc', 'video_embed_field', 'video_embed_field.handlers');
|
|
|
+// Load feeds mapping hooks.
|
|
|
+module_load_include('inc', 'video_embed_field', 'video_embed_field.feeds');
|
|
|
|
|
|
/**
|
|
|
- * Implementation of hook_ctools_plugin_directory().
|
|
|
+ * Implements hook_ctools_plugin_directory().
|
|
|
*/
|
|
|
function video_embed_field_ctools_plugin_directory($module, $type) {
|
|
|
// Load the export_ui plugin.
|
|
|
- if ($type =='export_ui') {
|
|
|
+ if ($type == 'export_ui') {
|
|
|
return 'plugins/export_ui';
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Implementation of hook_ctools_plugin_api().
|
|
|
+ * Implements hook_ctools_plugin_api().
|
|
|
*
|
|
|
* Tell CTools that we support the default_mymodule_presets API.
|
|
|
*/
|
|
@@ -46,20 +53,22 @@ function video_embed_field_default_video_embed_styles() {
|
|
|
$styles = array();
|
|
|
|
|
|
$handlers = video_embed_get_handlers();
|
|
|
- //create the normal handler
|
|
|
- $normal = new stdClass;
|
|
|
+ // Create the normal handler.
|
|
|
+ $normal = new stdClass();
|
|
|
$normal->disabled = FALSE; /* Edit this to true to make a default video_embed_style disabled initially */
|
|
|
$normal->api_version = 1;
|
|
|
$normal->name = 'normal';
|
|
|
+ $normal->title = 'Normal';
|
|
|
$normal->data = array();
|
|
|
|
|
|
- $teaser = new stdClass;
|
|
|
+ $teaser = new stdClass();
|
|
|
$teaser->disabled = FALSE; /* Edit this to true to make a default video_embed_style disabled initially */
|
|
|
$teaser->api_version = 1;
|
|
|
$teaser->name = 'teaser';
|
|
|
+ $teaser->title = 'Teaser';
|
|
|
$teaser->data = array();
|
|
|
|
|
|
- //add in our settings for each of the handlers
|
|
|
+ // Add in our settings for each of the handlers.
|
|
|
foreach ($handlers as $name => $handler) {
|
|
|
$normal->data[$name] = $handler['defaults'];
|
|
|
$teaser->data[$name] = $handler['defaults'];
|
|
@@ -87,68 +96,6 @@ function video_embed_field_menu() {
|
|
|
return $items;
|
|
|
}
|
|
|
|
|
|
-/**
|
|
|
- * Get an array of all styles and their settings.
|
|
|
- *
|
|
|
- * @return
|
|
|
- * An array of styles keyed by the video style ID (vsid).
|
|
|
- * @see video_embed_field_video_style_load()
|
|
|
- */
|
|
|
-function video_embed_field_video_styles() {
|
|
|
- $styles = &drupal_static(__FUNCTION__);
|
|
|
-
|
|
|
- // Grab from cache or build the array.
|
|
|
- if (!isset($styles)) {
|
|
|
- // load the style via ctools - which will handle all the caching for us -
|
|
|
- // however, because it does a bit more logic, lets still statically cache this function
|
|
|
- ctools_include('export');
|
|
|
- $styles = ctools_export_load_object('vef_video_styles');
|
|
|
- }
|
|
|
-
|
|
|
- return $styles;
|
|
|
-}
|
|
|
-
|
|
|
-/**
|
|
|
- * Load a style by style name or ID. May be used as a loader for menu items.
|
|
|
- *
|
|
|
- * Note that you may also use ctools_export_load_object with the key being vef_video_styles
|
|
|
- *
|
|
|
- * @param $name
|
|
|
- * The name of the style.
|
|
|
- * @param $isid
|
|
|
- * Optional. The numeric id of a style if the name is not known.
|
|
|
- * @return
|
|
|
- * An video style array containing the following keys:
|
|
|
- * - "vsid": The unique image style ID.
|
|
|
- * - "name": The unique image style name.
|
|
|
- * - "data": An array of video settings within this video style.
|
|
|
- * If the video style name or ID is not valid, an empty array is returned.
|
|
|
- */
|
|
|
-function video_embed_field_video_style_load($name = NULL, $vsid = NULL) {
|
|
|
- $styles = video_embed_field_video_styles();
|
|
|
-
|
|
|
- // If retrieving by name.
|
|
|
- if (isset($name) && isset($styles[$name])) {
|
|
|
- $style = $styles[$name];
|
|
|
- } // If retrieving by image style id.
|
|
|
- else if (!isset($name) && isset($vsid)) {
|
|
|
- foreach ($styles as $name => $database_style) {
|
|
|
- if (isset($database_style['vsid']) && $database_style['vsid'] == $vsid) {
|
|
|
- $style = $database_style;
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- //if we found a style return it
|
|
|
- if (isset($style)) {
|
|
|
- return $style;
|
|
|
- }
|
|
|
-
|
|
|
- // Otherwise the style was not found.
|
|
|
- return FALSE;
|
|
|
-}
|
|
|
-
|
|
|
/**
|
|
|
* Implements hook_permission().
|
|
|
*/
|
|
@@ -172,36 +119,115 @@ function video_embed_field_theme() {
|
|
|
),
|
|
|
'video_embed_field_embed_code' => array(
|
|
|
'template' => 'video-embed-field-embed-code',
|
|
|
- 'variables' => array('url' => NULL, 'style' => 'normal', 'video_data' => array()),
|
|
|
+ 'variables' => array(
|
|
|
+ 'url' => NULL,
|
|
|
+ 'style' => 'normal',
|
|
|
+ 'video_data' => array(),
|
|
|
+ ),
|
|
|
),
|
|
|
'video_embed_field_colorbox_code' => array(
|
|
|
- 'variables' => array('image_url' => NULL, 'image_style' => 'normal', 'video_url' => NULL, 'video_style' => NULL, 'video_data' => array()),
|
|
|
+ 'variables' => array(
|
|
|
+ 'image_url' => NULL,
|
|
|
+ 'image_style' => 'normal',
|
|
|
+ 'image_alt' => NULL,
|
|
|
+ 'video_url' => NULL,
|
|
|
+ 'video_style' => NULL,
|
|
|
+ 'video_data' => array(),
|
|
|
+ ),
|
|
|
),
|
|
|
);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Creates a hook that other modules can implement to get handlers - hook_video_embed_handler_info
|
|
|
- * Can be used to add more handlers if needed - from other modules and such
|
|
|
- * @see video_embed_field.api.php for more information
|
|
|
+ * Implements hook_views_api().
|
|
|
*/
|
|
|
-function video_embed_get_handlers() {
|
|
|
- $handlers = cache_get('video_embed_field_handlers');
|
|
|
+function video_embed_field_views_api() {
|
|
|
+ return array(
|
|
|
+ 'api' => 3,
|
|
|
+ 'path' => drupal_get_path('module', 'video_embed_field') . '/views',
|
|
|
+ );
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * Get an array of all styles and their settings.
|
|
|
+ *
|
|
|
+ * @return array
|
|
|
+ * An array of styles keyed by the video style name (name).
|
|
|
+ *
|
|
|
+ * @see video_embed_field_video_style_load()
|
|
|
+ */
|
|
|
+function video_embed_field_video_styles() {
|
|
|
+ $styles = &drupal_static(__FUNCTION__);
|
|
|
|
|
|
- if ($handlers === FALSE) {
|
|
|
- $handlers = module_invoke_all('video_embed_handler_info');
|
|
|
- drupal_alter('video_embed_field_handlers', $handlers);
|
|
|
- cache_set('video_embed_field_handlers', $handlers);
|
|
|
+ // Grab from cache or build the array.
|
|
|
+ if (!isset($styles)) {
|
|
|
+ // Load the style via ctools - which will handle all the caching for us -
|
|
|
+ // Because it does a bit more logic, lets still statically cache this.
|
|
|
+ ctools_include('export');
|
|
|
+ $styles = ctools_export_load_object('vef_video_styles');
|
|
|
}
|
|
|
- else {
|
|
|
- $handlers = $handlers->data;
|
|
|
+
|
|
|
+ return $styles;
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * Load a style by style name. May be used as a loader for menu items.
|
|
|
+ *
|
|
|
+ * Note that you may also use ctools_export_load_object with the key being
|
|
|
+ * vef_video_styles
|
|
|
+ *
|
|
|
+ * @param string $name
|
|
|
+ * The name of the style.
|
|
|
+ *
|
|
|
+ * @return array
|
|
|
+ * An video style array containing the following keys:
|
|
|
+ * - "name": The unique video style ID.
|
|
|
+ * - "title": The human readable video style name.
|
|
|
+ * - "data": An array of video settings within this video style.
|
|
|
+ * If the video style name or ID is not valid, an empty array is returned.
|
|
|
+ */
|
|
|
+function video_embed_field_video_style_load($name) {
|
|
|
+ $styles = video_embed_field_video_styles();
|
|
|
+
|
|
|
+ return isset($styles[$name]) ? $styles[$name] : FALSE;
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * Creates a hook that other modules can implement to get handlers.
|
|
|
+ *
|
|
|
+ * Can be used to add more handlers if needed - from other modules and such.
|
|
|
+ *
|
|
|
+ * @see hook_video_embed_handler_info
|
|
|
+ * @see video_embed_field.api.php
|
|
|
+ */
|
|
|
+function video_embed_get_handlers() {
|
|
|
+ $handlers = &drupal_static(__FUNCTION__);
|
|
|
+
|
|
|
+ if (!isset($handlers)) {
|
|
|
+ if ($handlers = cache_get('video_embed_field_handlers')) {
|
|
|
+ $handlers = $handlers->data;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ $handlers = module_invoke_all('video_embed_handler_info');
|
|
|
+ drupal_alter('video_embed_handler_info', $handlers);
|
|
|
+ cache_set('video_embed_field_handlers', $handlers);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
return $handlers;
|
|
|
}
|
|
|
|
|
|
-function video_embed_get_handler($url){
|
|
|
- // Process video URL
|
|
|
+/**
|
|
|
+ * Retrieves the video handler for a video URL.
|
|
|
+ *
|
|
|
+ * @param string $url
|
|
|
+ * The video URL.
|
|
|
+ *
|
|
|
+ * @return string|bool
|
|
|
+ * The handler name for the URL, FALSE in case there is no handler.
|
|
|
+ */
|
|
|
+function video_embed_get_handler($url) {
|
|
|
+ // Process video URL.
|
|
|
if (!stristr($url, 'http://') && !stristr($url, 'https://')) {
|
|
|
$url = 'http://' . $url;
|
|
|
}
|
|
@@ -222,14 +248,20 @@ function video_embed_get_handler($url){
|
|
|
$handler = $handlers[$handler_name];
|
|
|
$handler['name'] = $handler_name;
|
|
|
return $handler;
|
|
|
- } else {
|
|
|
+ }
|
|
|
+ else {
|
|
|
return FALSE;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Create a form from the player configuration options
|
|
|
- * $defaults will be passed in with the default settings for the various fields
|
|
|
+ * Creates a form from the player configuration options.
|
|
|
+ *
|
|
|
+ * @param array $defaults
|
|
|
+ * The default settings for the various fields.
|
|
|
+ *
|
|
|
+ * @return array
|
|
|
+ * The configuration form array.
|
|
|
*/
|
|
|
function video_embed_field_get_form($defaults) {
|
|
|
$form = array();
|
|
@@ -245,8 +277,9 @@ function video_embed_field_get_form($defaults) {
|
|
|
|
|
|
$form[$name] += array(
|
|
|
'#type' => 'fieldset',
|
|
|
- '#title' => t($handler['title']),
|
|
|
+ '#title' => t('@provider settings', array('@provider' => $handler['title'])),
|
|
|
'#tree' => TRUE,
|
|
|
+ '#element_validate' => isset($handler['form_validate']) ? array($handler['form_validate']) : array(),
|
|
|
);
|
|
|
}
|
|
|
}
|
|
@@ -254,12 +287,28 @@ function video_embed_field_get_form($defaults) {
|
|
|
return $form;
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ * Validates the iframe CSS dimensions.
|
|
|
+ *
|
|
|
+ * @param array $element
|
|
|
+ * The element to validate.
|
|
|
+ */
|
|
|
+function video_embed_field_validate_dimensions($element) {
|
|
|
+ if (!preg_match('/^(\d*)(px|%)?$/', $element['width']['#value'], $results)) {
|
|
|
+ form_error($element['width'], t('You should use a valid CSS value for width in @plugin plugin', array('@plugin' => $element['#title'])));
|
|
|
+ }
|
|
|
+ if (!preg_match('/^(\d*)(px|%)?$/', $element['height']['#value'], $results)) {
|
|
|
+ form_error($element['height'], t('You should use a valid CSS value for height in @plugin plugin', array('@plugin' => $element['#title'])));
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
/**
|
|
|
* Get an array of image styles suitable for using as select list options.
|
|
|
*
|
|
|
- * @param $include_empty
|
|
|
+ * @param bool $include_empty
|
|
|
* If TRUE a <none> option will be inserted in the options array.
|
|
|
- * @return
|
|
|
+ *
|
|
|
+ * @return array
|
|
|
* Array of image styles both key and value are set to style name.
|
|
|
*/
|
|
|
function video_embed_field_video_style_options($include_empty = TRUE) {
|
|
@@ -268,7 +317,9 @@ function video_embed_field_video_style_options($include_empty = TRUE) {
|
|
|
if ($include_empty && !empty($styles)) {
|
|
|
$options[''] = t('<none>');
|
|
|
}
|
|
|
- $options = array_merge($options, drupal_map_assoc(array_keys($styles)));
|
|
|
+ foreach ($styles as $style) {
|
|
|
+ $options[$style->name] = $style->title;
|
|
|
+ }
|
|
|
if (empty($options)) {
|
|
|
$options[''] = t('No defined styles');
|
|
|
}
|
|
@@ -282,12 +333,24 @@ function video_embed_field_filter_info() {
|
|
|
$filters['video_embed_field'] = array(
|
|
|
'title' => t('Video Embedding'),
|
|
|
'description' => t('Replaces [VIDEO::http://www.youtube.com/watch?v=someVideoID::aVideoStyle] tags with embedded videos.'),
|
|
|
- 'process callback' => 'video_embed_field_filter_process',
|
|
|
+ 'process callback' => 'video_embed_field_filter_process',
|
|
|
+ 'tips callback' => '_filter_video_embed_tips',
|
|
|
);
|
|
|
|
|
|
return $filters;
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ * Implements callback_filter_tips().
|
|
|
+ *
|
|
|
+ * Provides help for the URL filter.
|
|
|
+ *
|
|
|
+ * @see filter_filter_info()
|
|
|
+ */
|
|
|
+function _filter_video_embed_tips($filter, $format, $long = FALSE) {
|
|
|
+ return t('Replaces [VIDEO::http://www.youtube.com/watch?v=someVideoID::aVideoStyle] tags with embedded videos.');
|
|
|
+}
|
|
|
+
|
|
|
/**
|
|
|
* Video Embed Field filter process callback.
|
|
|
*/
|
|
@@ -295,12 +358,11 @@ function video_embed_field_filter_process($text, $filter, $format) {
|
|
|
preg_match_all('/ \[VIDEO:: ( [^\[\]]+ )* \] /x', $text, $matches);
|
|
|
|
|
|
$tag_match = (array) array_unique($matches[1]);
|
|
|
- $handlers = video_embed_get_handlers();
|
|
|
|
|
|
foreach ($tag_match as $tag) {
|
|
|
$parts = explode('::', $tag);
|
|
|
|
|
|
- // Get video style
|
|
|
+ // Get video style.
|
|
|
if (isset($parts[1])) {
|
|
|
$style = $parts[1];
|
|
|
}
|
|
@@ -317,130 +379,119 @@ function video_embed_field_filter_process($text, $filter, $format) {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Process variables to format a video player.
|
|
|
+ * Processes variables to format a video player.
|
|
|
*
|
|
|
- * $variables contains the following information:
|
|
|
- * - $url
|
|
|
- * - $style
|
|
|
- * - $video_data
|
|
|
+ * @param array $variables
|
|
|
+ * Contains the following information:
|
|
|
+ * - $url
|
|
|
+ * - $style
|
|
|
+ * - $video_data
|
|
|
*
|
|
|
* @see video-embed.tpl.php
|
|
|
*/
|
|
|
function template_preprocess_video_embed_field_embed_code(&$variables) {
|
|
|
- // Get the handler
|
|
|
+ // Get the handler.
|
|
|
$handler = video_embed_get_handler($variables['url']);
|
|
|
$variables['handler'] = $handler['name'];
|
|
|
|
|
|
- // Load the style
|
|
|
+ // Load the style.
|
|
|
$style = video_embed_field_video_style_load($variables['style']);
|
|
|
- // If there was an issue load in the default style
|
|
|
+ // If there was an issue load in the default style.
|
|
|
if ($style == FALSE) {
|
|
|
$style = video_embed_field_video_style_load('normal');
|
|
|
}
|
|
|
if (isset($style->data[$variables['handler']])) {
|
|
|
$variables['style_settings'] = $style->data[$variables['handler']];
|
|
|
- } //safety valve for when we add new handlers and there are styles in the database.
|
|
|
+ }
|
|
|
+ // Safety value for when we add new handlers and there are styles stored.
|
|
|
else {
|
|
|
$variables['style_settings'] = $handler['defaults'];
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- // Prepare the URL
|
|
|
+ // Prepare the URL.
|
|
|
if (!stristr($variables['url'], 'http://') && !stristr($variables['url'], 'https://')) {
|
|
|
$variables['url'] = 'http://' . $variables['url'];
|
|
|
}
|
|
|
|
|
|
- // Prepare embed code
|
|
|
+ // Prepare embed code.
|
|
|
if ($handler && isset($handler['function']) && function_exists($handler['function'])) {
|
|
|
- $variables['embed_code'] = drupal_render(call_user_func($handler['function'], $variables['url'], $variables['style_settings']));
|
|
|
+ $embed_code = call_user_func($handler['function'], $variables['url'], $variables['style_settings']);
|
|
|
+ $variables['embed_code'] = drupal_render($embed_code);
|
|
|
}
|
|
|
else {
|
|
|
$variables['embed_code'] = l($variables['url'], $variables['url']);
|
|
|
}
|
|
|
|
|
|
- // Prepare video data
|
|
|
+ // Prepare video data.
|
|
|
$variables['data'] = $variables['video_data'];
|
|
|
unset($variables['video_data']);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Returns image style image with a link to
|
|
|
- * an embedded video in colorbox.
|
|
|
+ * Returns image style image with a link to an embedded video in colorbox.
|
|
|
*
|
|
|
- * @param $variables
|
|
|
+ * @param array $variables
|
|
|
* An associative array containing:
|
|
|
* - image_url: The image URL.
|
|
|
* - image_style: The image style to use.
|
|
|
+ * - image_alt: The image ALT attribute.
|
|
|
* - video_url: The video URL.
|
|
|
* - video_style: The video style to use.
|
|
|
* - video_data: An array of data about the video.
|
|
|
*
|
|
|
+ * @return string
|
|
|
+ * The themed output.
|
|
|
+ *
|
|
|
* @ingroup themeable
|
|
|
*/
|
|
|
function theme_video_embed_field_colorbox_code($variables) {
|
|
|
- $style = video_embed_field_video_style_load($variables['video_style']);
|
|
|
-
|
|
|
- // If there was an issue load in the default style
|
|
|
- if ($style == FALSE) {
|
|
|
- $style = video_embed_field_video_style_load('normal');
|
|
|
- }
|
|
|
-
|
|
|
- $handler = video_embed_get_handler($variables['video_url']);
|
|
|
-
|
|
|
- $data = $style->data[$handler['name']];
|
|
|
-
|
|
|
- //Create a unique ID for colorbox inline
|
|
|
- $id = uniqid('video_embed_field-' . rand());
|
|
|
-
|
|
|
- if($variables['image_style'] == 'none'){
|
|
|
- $image = array(
|
|
|
- array(
|
|
|
- '#theme' => 'image',
|
|
|
- '#path' => $variables['image_url'],
|
|
|
- ),
|
|
|
- );
|
|
|
- }
|
|
|
- else {
|
|
|
- $image = array(
|
|
|
- '#theme' => 'image_style',
|
|
|
- '#path' => $variables['image_url'],
|
|
|
- '#style_name' => $variables['image_style'],
|
|
|
- );
|
|
|
- }
|
|
|
+ $path = video_embed_field_get_ajax_url($variables['video_url'], $variables['video_style']);
|
|
|
|
|
|
- $image = drupal_render($image);
|
|
|
-
|
|
|
- // Write values for later AJAX load
|
|
|
- $hash = _video_embed_field_store_video($variables['video_url'], $variables['video_style']);
|
|
|
-
|
|
|
- $output = l($image, base_path() . '?q=vef/load/' . $hash . '&width=' . ($data['width']) . '&height=' . ($data['height']+3), array('html' => true, 'external' => true, 'attributes' => array('class' => array('colorbox-load'))));
|
|
|
+ $image = array(
|
|
|
+ '#theme' => 'image_formatter',
|
|
|
+ '#item' => array('uri' => $variables['image_url'], 'alt' => $variables['image_alt']),
|
|
|
+ '#image_style' => $variables['image_style'],
|
|
|
+ '#path' => $path,
|
|
|
+ );
|
|
|
|
|
|
- return $output;
|
|
|
+ return drupal_render($image);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Get the thumbnail url for a given video url
|
|
|
- * @param $url - the url of the video
|
|
|
- * @return a string representing the url of the thumbnail, or FALSE on error
|
|
|
+ * Gets the thumbnail url for a given video url.
|
|
|
+ *
|
|
|
+ * @param string $url
|
|
|
+ * The url of the video.
|
|
|
+ *
|
|
|
+ * @return string
|
|
|
+ * String representing the url of the thumbnail, or FALSE on error.
|
|
|
*/
|
|
|
-function video_embed_field_thumbnail_url($url){
|
|
|
- $handler = video_embed_get_handler($url);
|
|
|
- if ($handler && isset($handler['thumbnail_function']) && function_exists($handler['thumbnail_function'])) {
|
|
|
- $info = call_user_func($handler['thumbnail_function'], $url);
|
|
|
- $info['handler'] = $handler['name'];
|
|
|
- return $info;
|
|
|
+function video_embed_field_thumbnail_url($url) {
|
|
|
+ $info = FALSE;
|
|
|
+ if ($handler = video_embed_get_handler($url)) {
|
|
|
+ if (isset($handler['thumbnail_function']) && function_exists($handler['thumbnail_function'])) {
|
|
|
+ $info = call_user_func($handler['thumbnail_function'], $url);
|
|
|
+ $info['handler'] = $handler['name'];
|
|
|
+ }
|
|
|
+ if (empty($info['url']) && isset($handler['thumbnail_default']) && file_exists($handler['thumbnail_default'])) {
|
|
|
+ $info = array(
|
|
|
+ 'handler' => $handler['name'],
|
|
|
+ 'id' => 'default_thumbnail',
|
|
|
+ 'url' => $handler['thumbnail_default'],
|
|
|
+ );
|
|
|
+ }
|
|
|
}
|
|
|
- return FALSE;
|
|
|
+ return $info;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Get a video data array for a given video url
|
|
|
+ * Gets a video data array for a given video url.
|
|
|
*
|
|
|
* @param string $url
|
|
|
- * A video URL of the data array you want returned
|
|
|
+ * A video URL of the data array you want returned.
|
|
|
*
|
|
|
- * @return array|false $data
|
|
|
- * An array of video data, or FALSE on error
|
|
|
+ * @return array|false
|
|
|
+ * An array of video data, or FALSE on error.
|
|
|
*/
|
|
|
function video_embed_field_get_video_data($url) {
|
|
|
$handler = video_embed_get_handler($url);
|
|
@@ -453,7 +504,53 @@ function video_embed_field_get_video_data($url) {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Fetch all available provider domains.
|
|
|
+ * Generates the AJAX path array from the video URL and the video_style.
|
|
|
+ *
|
|
|
+ * @param string $video_url
|
|
|
+ * The URL to the video.
|
|
|
+ * @param string $video_style
|
|
|
+ * The video style to render the video.
|
|
|
+ *
|
|
|
+ * @return array
|
|
|
+ * The AJAX path array.
|
|
|
+ */
|
|
|
+function video_embed_field_get_ajax_url($video_url, $video_style) {
|
|
|
+ $style = video_embed_field_video_style_load($video_style);
|
|
|
+
|
|
|
+ // If there was an issue load in the default style.
|
|
|
+ if ($style == FALSE) {
|
|
|
+ $style = video_embed_field_video_style_load('normal');
|
|
|
+ }
|
|
|
+
|
|
|
+ $handler = video_embed_get_handler($video_url);
|
|
|
+
|
|
|
+ $data = $style->data[$handler['name']];
|
|
|
+
|
|
|
+ // Write values for later AJAX load.
|
|
|
+ $hash = _video_embed_field_store_video($video_url, $video_style);
|
|
|
+
|
|
|
+ return array(
|
|
|
+ 'path' => 'vef/load/' . $hash,
|
|
|
+ 'options' => array(
|
|
|
+ 'attributes' => array(
|
|
|
+ 'class' => array(
|
|
|
+ 'colorbox-load',
|
|
|
+ 'colorbox'
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ 'query' => array(
|
|
|
+ 'width' => $data['width'],
|
|
|
+ 'height' => $data['height'] + 5,
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ );
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * Fetches all available provider domains.
|
|
|
+ *
|
|
|
+ * @return array
|
|
|
+ * An array containing the allowed video domains.
|
|
|
*/
|
|
|
function _video_embed_field_get_provider_domains() {
|
|
|
$domains = array();
|
|
@@ -471,41 +568,76 @@ function _video_embed_field_get_provider_domains() {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Fetch settings string
|
|
|
+ * Fetches all available provider domains for certain field instance.
|
|
|
+ *
|
|
|
+ * @param array $instance
|
|
|
+ * The instance definition.
|
|
|
+ *
|
|
|
+ * @return array
|
|
|
+ * An array containing the allowed video domains.
|
|
|
+ */
|
|
|
+function _video_embed_field_get_instance_provider_domains($instance) {
|
|
|
+ $domains = _video_embed_field_get_provider_domains();
|
|
|
+
|
|
|
+ foreach ($domains as $domain => $provider) {
|
|
|
+ if (empty($instance['settings']['allowed_providers'][$provider])) {
|
|
|
+ unset($domains[$domain]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return $domains;
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * Fetches settings string.
|
|
|
+ *
|
|
|
+ * @param array $settings
|
|
|
+ * The settings array.
|
|
|
+ *
|
|
|
+ * @return string
|
|
|
+ * The settings string generated from the settings array.
|
|
|
*/
|
|
|
function _video_embed_code_get_settings_str($settings = array()) {
|
|
|
$values = array();
|
|
|
|
|
|
foreach ($settings as $name => $value) {
|
|
|
- $values[] = $name . '=' . $value;
|
|
|
+ if (!isset($value)) {
|
|
|
+ $values[] = $name;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ $values[] = $name . '=' . $value;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
return implode('&', $values);
|
|
|
}
|
|
|
|
|
|
-//used to array filter in video_embed_field_requirements
|
|
|
-function _video_embed_field_array_filter($item) {
|
|
|
- return (isset($item['type']) && $item['type'] == 'video_embed_field');
|
|
|
-}
|
|
|
-
|
|
|
/**
|
|
|
- * Store a video to be loaded later from an _video_embed_field_load_video
|
|
|
+ * Stores a video to be loaded later from an _video_embed_field_load_video.
|
|
|
+ *
|
|
|
+ * @param string $video_url
|
|
|
+ * The video URL.
|
|
|
+ * @param string $video_style
|
|
|
+ * The video style.
|
|
|
+ *
|
|
|
+ * @return string
|
|
|
+ * The hash generated for the video URL and the given style.
|
|
|
*/
|
|
|
function _video_embed_field_store_video($video_url, $video_style) {
|
|
|
- //create a hash key
|
|
|
+ // Create a hash key.
|
|
|
$hash = _video_embed_field_hash($video_url, $video_style);
|
|
|
|
|
|
- //check that is record doesn't already exist before saving it
|
|
|
- if(!_video_embed_field_load_video($hash)){
|
|
|
+ // Check that this record doesn't already exist before saving it.
|
|
|
+ if (!_video_embed_field_load_video($hash)) {
|
|
|
$record = array(
|
|
|
'vhash' => $hash,
|
|
|
'video_url' => $video_url,
|
|
|
'video_style' => $video_style,
|
|
|
);
|
|
|
|
|
|
- cache_set('vef-store-'.$hash, $record);
|
|
|
+ cache_set('vef-store-' . $hash, $record);
|
|
|
|
|
|
- //add it to our static cache so we won't have to go to the database
|
|
|
+ // Add it to our static cache so we won't have to go to the database.
|
|
|
$static_cache = &drupal_static('vef_video_store', array());
|
|
|
$static_cache[$hash] = $record;
|
|
|
}
|
|
@@ -513,9 +645,15 @@ function _video_embed_field_store_video($video_url, $video_style) {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Callback to render a video for an Ajax call
|
|
|
+ * Renders a video for an AJAX call.
|
|
|
+ *
|
|
|
+ * @param string $hash
|
|
|
+ * The video hash.
|
|
|
+ *
|
|
|
+ * @return Null
|
|
|
+ * Null because prints an AJAX output.
|
|
|
*/
|
|
|
-function _video_embed_field_show_video($hash){
|
|
|
+function _video_embed_field_show_video($hash) {
|
|
|
$data = _video_embed_field_load_video($hash);
|
|
|
$video = array(
|
|
|
'#theme' => 'video_embed_field_embed_code',
|
|
@@ -528,31 +666,45 @@ function _video_embed_field_show_video($hash){
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Loads a video from the video store given its hash
|
|
|
- * Returns either the data - an array with hash, video_url and video_style keys
|
|
|
+ * Loads a video from the video store given its hash.
|
|
|
+ *
|
|
|
+ * @param string $hash
|
|
|
+ * The video hash.
|
|
|
+ *
|
|
|
+ * @return array|bool
|
|
|
+ * An array with video definition, FALSE if the hash does not exist.
|
|
|
*/
|
|
|
function _video_embed_field_load_video($hash) {
|
|
|
$static_cache = &drupal_static('vef_video_store', array());
|
|
|
- //check if we've already loaded it
|
|
|
+ // Check if we've already loaded it.
|
|
|
if (isset($static_cache[$hash])) {
|
|
|
return $static_cache[$hash];
|
|
|
- } else {
|
|
|
-
|
|
|
- $result = cache_get('vef-store-'.$hash);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ $result = cache_get('vef-store-' . $hash);
|
|
|
if ($result) {
|
|
|
- //cache it before returning
|
|
|
+ // Cache it before returning.
|
|
|
$data = $result->data;
|
|
|
$static_cache[$hash] = $data;
|
|
|
return $data;
|
|
|
- } else {
|
|
|
+ }
|
|
|
+ else {
|
|
|
return FALSE;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Creates a hash for storing or looking up a video in the store table
|
|
|
+ * Creates a hash for storing or looking up a video in the store table.
|
|
|
+ *
|
|
|
+ * @param string $video_url
|
|
|
+ * The video URL.
|
|
|
+ * @param string $video_style
|
|
|
+ * The video style.
|
|
|
+ *
|
|
|
+ * @return string
|
|
|
+ * The hash generated for the video URL and the given style.
|
|
|
*/
|
|
|
-function _video_embed_field_hash($video_url, $video_style){
|
|
|
+function _video_embed_field_hash($video_url, $video_style) {
|
|
|
return md5('vef' . $video_url . $video_style);
|
|
|
-}
|
|
|
+}
|