updated vieo_embed_field
This commit is contained in:
parent
9afc105c7e
commit
785dee0639
@ -1,29 +1,34 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Define this Export UI plugin.
|
||||
* @file
|
||||
* Defines the CTools Export UI plugin.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Defines this Export UI plugin.
|
||||
*/
|
||||
$plugin = array(
|
||||
'schema' => 'vef_video_styles', // As defined in hook_schema().
|
||||
'access' => 'administer video styles', // Define a permission users must have to access these pages.
|
||||
|
||||
'schema' => 'vef_video_styles',
|
||||
'access' => 'administer video styles',
|
||||
// Define the menu item.
|
||||
'menu' => array(
|
||||
'menu prefix' => 'admin/config/media',
|
||||
'menu item' => 'vef_video_styles',
|
||||
'menu title' => 'Configure Video Embed Styles',
|
||||
'menu title' => 'Video Embed Styles',
|
||||
'menu description' => 'Administer Video Embed Field\'s video styles.',
|
||||
),
|
||||
|
||||
// Define user interface texts.
|
||||
'title singular' => t('video style'),
|
||||
'title plural' => t('video styles'),
|
||||
'title singular proper' => t('Video Styles'),
|
||||
'title plural proper' => t('Video Styles'),
|
||||
|
||||
// Define the names of the functions that provide the add/edit forms.
|
||||
'form' => array(
|
||||
'settings' => 'video_embed_field_video_style_form',
|
||||
// 'submit' and 'validate' are also valid callbacks.
|
||||
),
|
||||
);
|
||||
'export' => array(
|
||||
'admin_title' => 'title',
|
||||
),
|
||||
);
|
||||
|
@ -19,4 +19,4 @@
|
||||
<div class="player">
|
||||
<?php print $embed_code; ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -1,13 +1,13 @@
|
||||
name = "Video Embed Facebook"
|
||||
description = "Provides Facebook handler for Video Embed Fields. This module also serves as an example of how to add handlers to video embed field."
|
||||
core = "7.x"
|
||||
core = 7.x
|
||||
package = Media
|
||||
configure = admin/config/media/vef_video_styles
|
||||
|
||||
dependencies[] = "video_embed_field"
|
||||
; Information added by drupal.org packaging script on 2012-06-21
|
||||
version = "7.x-2.0-beta5"
|
||||
; Information added by Drupal.org packaging script on 2015-04-17
|
||||
version = "7.x-2.0-beta8+7-dev"
|
||||
core = "7.x"
|
||||
project = "video_embed_field"
|
||||
datestamp = "1340317020"
|
||||
datestamp = "1429278491"
|
||||
|
||||
|
@ -1,40 +1,30 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file Add a handler for facebook videos to Video Embed Field.
|
||||
* @see video_embed_field.api.php for more documentation
|
||||
* @file
|
||||
* Adds a handler for Facebook videos to Video Embed Field.
|
||||
*
|
||||
* @see video_embed_field.api.php for more documentation
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_video_embed_handler_info().
|
||||
* This function is used to tell video_embed_field which functions will be used to handle
|
||||
* different operations, along with a bit of metadata.
|
||||
* @return an associative array with the data
|
||||
* @see video_embed_field.api.php for specific details on the data to return.
|
||||
* Implements hook_video_embed_handler_info().
|
||||
*/
|
||||
function video_embed_facebook_video_embed_handler_info () {
|
||||
function video_embed_facebook_video_embed_handler_info() {
|
||||
$handlers = array();
|
||||
//the key here should be unique to our handler, normally the name of the service will suffice
|
||||
$handlers['facebook'] = array(
|
||||
'title' => 'Facebook Video', //The title is the name to show to users
|
||||
//function is a function to take the url and return the embed code
|
||||
'function' => 'video_embed_facebook_handle_video',
|
||||
//thumbnail_function is optional and takes the url and returns the thumbnail url
|
||||
'title' => 'Facebook Video',
|
||||
'function' => 'video_embed_facebook_handle_video',
|
||||
'thumbnail_function' => 'video_embed_facebook_handle_thumbnail',
|
||||
//data_function is optional and returns an array of extra data for the given video url
|
||||
//because facebook requires oath to get this data, we'll leave it out for now
|
||||
//'data_function' => 'video_embed_facebook_handle_data',
|
||||
//form is the configure form to embed into video_embed styles - this is where all settings should go
|
||||
'thumbnail_default' => drupal_get_path('module', 'video_embed_facebook') . '/img/facebook.jpg',
|
||||
'form' => 'video_embed_facebook_form',
|
||||
//domains is how video embed determines which handler to use, its an array of domains to match
|
||||
//urls against. Don't include the scheme (like http://) or www.
|
||||
'form_validate' => 'video_embed_field_handler_youtube_form_validate',
|
||||
'domains' => array(
|
||||
'facebook.com',
|
||||
),
|
||||
//defaults are the defaults to provide to your form (as defined in your form callback)
|
||||
'defaults' => array(
|
||||
'width' => 640,
|
||||
'height' => 360,
|
||||
'allowfullscreen' => TRUE,
|
||||
),
|
||||
);
|
||||
|
||||
@ -42,107 +32,116 @@ function video_embed_facebook_video_embed_handler_info () {
|
||||
}
|
||||
|
||||
/**
|
||||
* Our configuration form (the callback for the form key in info)
|
||||
* Provide a form to configure out video settings
|
||||
* @param $defaults - default/current values for your provider, the currently saved settings
|
||||
* with empty values filled with the defaults provided in info hook
|
||||
* @return a form as defined by forms api
|
||||
* Defines the form elements for the Facebook videos configuration form.
|
||||
*
|
||||
* @param array $defaults
|
||||
* The form default values.
|
||||
*
|
||||
* @return array
|
||||
* The provider settings form array.
|
||||
*/
|
||||
function video_embed_facebook_form ($defaults) {
|
||||
function video_embed_facebook_form($defaults) {
|
||||
$form = array();
|
||||
//form element for the width of the player - note we're using the default from defaults
|
||||
$form['height'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Player Width'),
|
||||
'#description' => t('The width of the player.'),
|
||||
'#default_value' => $defaults['height'],
|
||||
);
|
||||
//element for width
|
||||
|
||||
$form['width'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Player Width'),
|
||||
'#description' => t('The width of the player.'),
|
||||
'#default_value' => $defaults['width'],
|
||||
);
|
||||
//allow configuration of fullscreen
|
||||
$form['allowfullscreen'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Allow Fullscreen'),
|
||||
'#desecription' => t('This will allow the video to be fullscreened.'),
|
||||
'#default_value' => $defaults['allowfullscreen'],
|
||||
|
||||
$form['height'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Player Height'),
|
||||
'#description' => t('The height of the player.'),
|
||||
'#default_value' => $defaults['height'],
|
||||
);
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates the form elements for the Facebook video configuration form.
|
||||
*
|
||||
* @param array $element
|
||||
* The form element to validate.
|
||||
* @param array $form_state
|
||||
* The form to validate state.
|
||||
* @param array $form
|
||||
* The form to validate structure.
|
||||
*/
|
||||
function video_embed_field_handler_facebook_form_validate($element, &$form_state, $form) {
|
||||
video_embed_field_validate_dimensions($element);
|
||||
}
|
||||
|
||||
/**
|
||||
* This is the video handler (the 'function' key from handler_info)
|
||||
* @param $url - the full video url
|
||||
* @param $settings - an associative array of this handlers settings, from the settings form
|
||||
* @return - the embed code for the video
|
||||
* Handler for Facebook videos.
|
||||
*
|
||||
* @param string $url
|
||||
* The video URL.
|
||||
* @param array $settings
|
||||
* The settings array.
|
||||
*
|
||||
* @return string|bool
|
||||
* The video iframe, or FALSE in case the ID can't be retrieved from the URL.
|
||||
*/
|
||||
function video_embed_facebook_handle_video ($url, $settings) {
|
||||
function video_embed_facebook_handle_video($url, $settings) {
|
||||
$id = _video_embed_facebook_get_video_id($url);
|
||||
|
||||
if($id) {
|
||||
//our embed code
|
||||
$embed = '<object>
|
||||
<param name="allowfullscreen" value="!fullscreen" />
|
||||
<param name="allowscriptaccess" value="always" />
|
||||
<param name="movie" value="http://www.facebook.com/v/!id" />
|
||||
<param name="wmode" value="opaque" />
|
||||
<embed src="http://www.facebook.com/v/!id" type="application/x-shockwave-flash" wmode="opaque"
|
||||
allowscriptaccess="always" allowfullscreen="!fullscreen" width="!width" height="!height">
|
||||
</embed>
|
||||
</object>';
|
||||
//use format_string to replace our placeholders with the values from the settings
|
||||
if ($id) {
|
||||
// Our embed code.
|
||||
$embed='<iframe src="//www.facebook.com/video/embed?video_id=!id" width="!width" height="!height"></iframe> ';
|
||||
// Use format_string to replace our placeholders with the settings values.
|
||||
$embed = format_string($embed, array(
|
||||
'!id' => $id,
|
||||
'!fullscreen' => $settings['allowfullscreen'] ? 'true' : 'false',
|
||||
'!width' => $settings['width'],
|
||||
'!height' => $settings['height'],
|
||||
));
|
||||
//we want to return a render array
|
||||
|
||||
$video = array(
|
||||
'#markup' => $embed,
|
||||
);
|
||||
return $video;
|
||||
}
|
||||
// just return an empty string if there is no id, so we don't have broken embeds showing up
|
||||
return '';
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retreive the thumbnail for the facebook video - note that based on a users permissions, this may be
|
||||
* the facebook unknown thumbnail: https://s-static.ak.facebook.com/rsrc.php/v1/y0/r/XsEg9L6Ie5_.jpg
|
||||
* @param $url - the url of the video as entered by the user
|
||||
* @return an array with the keys:
|
||||
* 'id' => an id for the video which is unique to your provider, used for naming the cached thumbnail file
|
||||
* 'url' => the url to retrieve the thumbnail from
|
||||
* Gets the thumbnail url for Facebook videos.
|
||||
*
|
||||
* @param string $url
|
||||
* The video URL.
|
||||
*
|
||||
* @return array
|
||||
* The video thumbnail information.
|
||||
*/
|
||||
function video_embed_facebook_handle_thumbnail ($url) {
|
||||
function video_embed_facebook_handle_thumbnail($url) {
|
||||
$id = _video_embed_facebook_get_video_id($url);
|
||||
// We're using a part of the graphs api to return the thumbnail. This only works for some videos
|
||||
|
||||
return array(
|
||||
'id' => $id, //generally the id that the provider uses for the video
|
||||
'url' => 'https://graph.facebook.com/'.$id.'/picture', //the url of the thumbnail
|
||||
'id' => $id,
|
||||
'url' => 'https://graph.facebook.com/' . $id . '/picture',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to take a facebook video url and return its id
|
||||
* @param $url - the full facebook video url
|
||||
* @return the id for the video
|
||||
* Helper function to get the Facebook video's id.
|
||||
*
|
||||
* @param string $url
|
||||
* The video URL.
|
||||
*
|
||||
* @return string|bool
|
||||
* The video ID, or FALSE in case the ID can't be retrieved from the URL.
|
||||
*/
|
||||
function _video_embed_facebook_get_video_id ($url) {
|
||||
//parse_url is an easy way to break a url into its components
|
||||
function _video_embed_facebook_get_video_id($url) {
|
||||
// Parse_url is an easy way to break a url into its components.
|
||||
$matches = array();
|
||||
preg_match('/(.*)?v=([^&#]*)/', $url, $matches);
|
||||
//if the v get parameter is set, return it
|
||||
preg_match('/(.*)?[v|video_id]=([^&#]*)/', $url, $matches);
|
||||
// If the v or video_id get parameters are set, return it.
|
||||
if ($matches && !empty($matches[2])) {
|
||||
return $matches[2];
|
||||
}
|
||||
//otherwise return false.
|
||||
// Otherwise return false.
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
@ -1,30 +1,34 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Form builder; Form for editing a video style.
|
||||
* Used by CTools export ui
|
||||
*
|
||||
* @ingroup forms
|
||||
* @see video_embed_field_video_style_form_submit()
|
||||
* Used by CTools export ui.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Video embed style form handler.
|
||||
*/
|
||||
function video_embed_field_video_style_form(&$form, &$form_state) {
|
||||
if(isset($form_state['item'])){
|
||||
if (isset($form_state['item'])) {
|
||||
$style = (array) $form_state['item'];
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
$style = array();
|
||||
}
|
||||
$form_state['video_style'] = $style;
|
||||
|
||||
//Grab the settings off the parser form
|
||||
// Grab the settings off the parser form.
|
||||
$values = isset($style['data']) ? $style['data'] : array();
|
||||
$parser_form = video_embed_field_get_form($values);
|
||||
|
||||
//General settings for playback - formerly in the configuration section
|
||||
// General settings for playback - formerly in the configuration section.
|
||||
$form['data'] = array(
|
||||
'#type' => 'vertical_tabs',
|
||||
'#title' => t('Playback settings'),
|
||||
'#tree' => TRUE,
|
||||
) + $parser_form; //add in our extra settings
|
||||
) + $parser_form;
|
||||
|
||||
return $form;
|
||||
}
|
||||
}
|
||||
|
@ -1,22 +1,33 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* API Info for video_embed_field module
|
||||
* API Info for video_embed_field module
|
||||
*/
|
||||
|
||||
/**
|
||||
* @function hook_video_embed_handler_info
|
||||
* Can be used to add more handlers for video_embed_field
|
||||
* @return an array of handlers, each handler is an array with the following keys
|
||||
* 'title' : required, the untranslated title of the provider, to show to the admin user
|
||||
* 'function' : required, the function used to generate the embed code
|
||||
* 'thumbnail_function' : optional, the function used to provide the thumbnail for a video
|
||||
* 'data_function' : optional, the function to return an array of video data.
|
||||
* 'form' : required, the function that returns the settings form for your provider
|
||||
* 'domains' : required, an array of domains to match against, this is used to know which provider to use
|
||||
* 'defaults' : default values for each setting made configurable in your form function
|
||||
* @function hook_video_embed_handler_info
|
||||
* Can be used to add more handlers for video_embed_field
|
||||
* @return an array of handlers, each handler is an array with the following
|
||||
* keys:
|
||||
* 'title' : required, the untranslated title of the provider, to show to the
|
||||
* admin user.
|
||||
* 'function' : required, the function used to generate the embed code.
|
||||
* 'thumbnail_function' : optional, the function used to provide the thumbnail
|
||||
* for a video.
|
||||
* 'thumbnail_default : optional, the default thumbnail image to display in case
|
||||
* thumbnail_function does not exist or has no results.
|
||||
* 'data_function' : optional, the function to return an array of video data.
|
||||
* 'form' : required, the function that returns the settings form for your
|
||||
* provider.
|
||||
* 'form_validate: optional the function that validates the settings form for
|
||||
* your provider.
|
||||
* 'domains' : required, an array of domains to match against, this is used to
|
||||
* know which provider to use.
|
||||
* 'defaults' : default values for each setting made configurable in your form
|
||||
* function.
|
||||
*
|
||||
* @see below for function definitions
|
||||
* @see hook_video_embed_handler_info_alter()
|
||||
* @see below for function definitions
|
||||
*/
|
||||
function hook_video_embed_handler_info() {
|
||||
$handlers = array();
|
||||
@ -25,8 +36,10 @@ function hook_video_embed_handler_info() {
|
||||
'title' => 'UStream',
|
||||
'function' => 'your_module_handle_ustream',
|
||||
'thumbnail_function' => 'your_module_handle_ustream_thumbnail',
|
||||
'thumbnail_default' => drupal_get_path('module', 'your_module') . '/img/ustream.jpg',
|
||||
'data_function' => 'your_module_handler_ustream_data',
|
||||
'form' => 'your_module_handler_ustream_form',
|
||||
'form_validate' => 'your_module_handler_ustream_form_validate',
|
||||
'domains' => array(
|
||||
'ustream.com',
|
||||
),
|
||||
@ -39,31 +52,47 @@ function hook_video_embed_handler_info() {
|
||||
return $handlers;
|
||||
}
|
||||
|
||||
// Example callbacks for a provider (in this case for ustream) - obviously, these functions are only for example
|
||||
// purposes
|
||||
/**
|
||||
* Performs alterations on video_embed_field handlers.
|
||||
*
|
||||
* @param $info
|
||||
* Array of information on video handlers exposed by
|
||||
* hook_video_embed_handler_info() implementations.
|
||||
*/
|
||||
function hook_video_embed_handler_info_alter(&$info) {
|
||||
// Change the thumbnail function for 'ustream' provider.
|
||||
if (isset($info['ustream'])) {
|
||||
$info['ustream']['thumbnail_function'] = 'your_module_handle_ustream_thumbnail_alter';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the embed code for a video
|
||||
* @param $url - the video url as entered by the user
|
||||
* @param $settings - the settings for this provider as defined in the form function,
|
||||
* defaulting to your provider's defaults
|
||||
* @return the embed code as a renderable array
|
||||
* Example callbacks for a provider (in this case for ustream).
|
||||
* Obviously, these functions are only for example purposes.
|
||||
*/
|
||||
function your_module_handle_ustream($url, $settings) {
|
||||
return array(
|
||||
//this should be the full embed code for your provider, including each of the settings
|
||||
'#markup' => '<iframe src="ustream"></iframe>',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve information about the thumbnail for a given url
|
||||
* @param $url - the url of the video as entered by the user
|
||||
* @return an array with the keys:
|
||||
* 'id' => an id for the video which is unique to your provider, used for naming the cached thumbnail file
|
||||
* 'url' => the url to retrieve the thumbnail from
|
||||
*/
|
||||
function your_module_handle_ustream_thumbnail ($url) {
|
||||
/**
|
||||
* Generate the embed code for a video
|
||||
* @param $url - the video url as entered by the user
|
||||
* @param $settings - the settings for this provider as defined in the form function,
|
||||
* defaulting to your provider's defaults
|
||||
* @return the embed code as a renderable array
|
||||
*/
|
||||
function your_module_handle_ustream($url, $settings) {
|
||||
return array(
|
||||
//this should be the full embed code for your provider, including each of the settings
|
||||
'#markup' => '<iframe src="ustream"></iframe>',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve information about the thumbnail for a given url
|
||||
* @param $url - the url of the video as entered by the user
|
||||
* @return an array with the keys:
|
||||
* 'id' => an id for the video which is unique to your provider, used for naming the cached thumbnail file
|
||||
* 'url' => the url to retrieve the thumbnail from
|
||||
*/
|
||||
function your_module_handle_ustream_thumbnail($url) {
|
||||
return array(
|
||||
'id' => '12332243242', //generally the id that the provider uses for the video
|
||||
'url' => 'http://something/thumbnail/somthing.jpg', //the url of the thumbnail
|
||||
@ -71,12 +100,12 @@ function your_module_handle_ustream_thumbnail ($url) {
|
||||
}
|
||||
|
||||
/**
|
||||
* A forms api callback, returns the settings form for the provider
|
||||
* @param $defaults - default/current values for your provider, the currently saved settings
|
||||
* A forms api callback, returns the settings form for the provider
|
||||
* @param $defaults - default/current values for your provider, the currently saved settings
|
||||
* with empty values filled with the defaults provided in info hook
|
||||
* @return a form as defined by forms api
|
||||
* @return a form as defined by forms api
|
||||
*
|
||||
* @see http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7
|
||||
* @see http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7
|
||||
*/
|
||||
function your_module_handler_ustream_form($defaults) {
|
||||
$form = array();
|
||||
@ -92,9 +121,9 @@ function your_module_handler_ustream_form($defaults) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of extra data to be stored with the video, this data will be available for theming
|
||||
* @return an array
|
||||
* Return an array of extra data to be stored with the video, this data will be available for theming
|
||||
* @return an array
|
||||
*/
|
||||
function your_module_handler_ustream_data($url) {
|
||||
return array();
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,7 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements of hook_field_info().
|
||||
* Implements hook_field_info().
|
||||
*/
|
||||
function video_embed_field_field_info() {
|
||||
return array(
|
||||
@ -16,28 +16,116 @@ function video_embed_field_field_info() {
|
||||
'settings' => array(),
|
||||
'instance_settings' => array(
|
||||
'description_field' => 0,
|
||||
'description_length' => 128,
|
||||
'allowed_providers' => array_keys(video_embed_get_handlers()),
|
||||
),
|
||||
'default_widget' => 'video_embed_field_video',
|
||||
'default_formatter' => 'video_embed_field',
|
||||
)
|
||||
'property_type' => 'video_embed_field',
|
||||
'property_callbacks' => array('video_embed_field_property_info_callback'),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Property callback for the Entity Metadata framework.
|
||||
*/
|
||||
function video_embed_field_property_info_callback(&$info, $entity_type, $field, $instance, $field_type) {
|
||||
// Apply the default.
|
||||
entity_metadata_field_default_property_callback($info, $entity_type, $field, $instance, $field_type);
|
||||
|
||||
// Finally add in instance specific property info.
|
||||
$name = $field['field_name'];
|
||||
$property = &$info[$entity_type]['bundles'][$instance['bundle']]['properties'][$name];
|
||||
$property['type'] = ($field['cardinality'] != 1) ? 'list<video_embed_field>' : 'video_embed_field';
|
||||
$property['property info'] = video_embed_field_data_property_info('Video embed');
|
||||
$property['getter callback'] = 'entity_metadata_field_verbatim_get';
|
||||
$property['setter callback'] = 'entity_metadata_field_verbatim_set';
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines info for the properties of the video_embed_field data structure.
|
||||
*/
|
||||
function video_embed_field_data_property_info($name = NULL) {
|
||||
// Build an array of basic property information for video_embed_field.
|
||||
$properties = array(
|
||||
'video_url' => array(
|
||||
'label' => 'Video URL',
|
||||
'type' => 'uri',
|
||||
'setter callback' => 'entity_property_verbatim_set',
|
||||
),
|
||||
'thumbnail_path' => array(
|
||||
'label' => 'Thumbnail path',
|
||||
'type' => 'uri',
|
||||
'getter callback' => 'entity_property_verbatim_get_url',
|
||||
),
|
||||
'description' => array(
|
||||
'label' => 'Description',
|
||||
'type' => 'text',
|
||||
'setter callback' => 'entity_property_verbatim_set',
|
||||
),
|
||||
);
|
||||
|
||||
// Add the default values for each of the video_embed_field properties.
|
||||
foreach ($properties as $key => &$value) {
|
||||
$value += array(
|
||||
'description' => !empty($name) ? t('!label of field %name', array('!label' => $value['label'], '%name' => $name)) : '',
|
||||
);
|
||||
}
|
||||
|
||||
return $properties;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the property just as it is set in the data and converts to absolute url.
|
||||
*/
|
||||
function entity_property_verbatim_get_url($data, array $options, $name, $type, $info) {
|
||||
$property = entity_property_verbatim_get($data, $options, $name, $type, $info);
|
||||
return file_create_url($property);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_field_instance_settings_form().
|
||||
*/
|
||||
function video_embed_field_field_instance_settings_form($field, $instance) {
|
||||
$settings = $instance['settings'];
|
||||
|
||||
|
||||
$providers = video_embed_get_handlers();
|
||||
$allowed_providers = array();
|
||||
foreach ($providers as $provider_id => $definition) {
|
||||
$allowed_providers[$provider_id] = $definition['title'];
|
||||
}
|
||||
|
||||
$form['allowed_providers'] = array(
|
||||
'#type' => 'checkboxes',
|
||||
'#title' => t('Select the allowed video providers'),
|
||||
'#options' => $allowed_providers,
|
||||
'#default_value' => isset($settings['allowed_providers']) ? $settings['allowed_providers'] : array(),
|
||||
'#weight' => 10,
|
||||
);
|
||||
|
||||
$form['description_field'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Enable <em>Description</em> field'),
|
||||
'#default_value' => isset($settings['description_field']) ? $settings['description_field'] : '',
|
||||
'#description' => t('The description field allows users to enter a description about the video.'),
|
||||
'#parents' => array('instance', 'settings', 'description_field'),
|
||||
'#weight' => 11,
|
||||
);
|
||||
|
||||
|
||||
$form['description_length'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Max description length'),
|
||||
'#default_value' => isset($settings['description_length']) ? $settings['description_length'] : 128,
|
||||
'#weight' => 12,
|
||||
'#size' => 5,
|
||||
'#maxlength' => 5,
|
||||
'#states' => array(
|
||||
'visible' => array(
|
||||
':input[id="edit-instance-settings-description-field"]' => array('checked' => TRUE),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
@ -53,7 +141,7 @@ function video_embed_field_field_widget_info() {
|
||||
'settings' => array(),
|
||||
'behaviors' => array(
|
||||
'multiple values' => FIELD_BEHAVIOR_DEFAULT,
|
||||
'default value' => FIELD_BEHAVIOR_DEFAULT
|
||||
'default value' => FIELD_BEHAVIOR_DEFAULT,
|
||||
),
|
||||
),
|
||||
);
|
||||
@ -63,24 +151,25 @@ function video_embed_field_field_widget_info() {
|
||||
* Implements hook_field_widget_form().
|
||||
*/
|
||||
function video_embed_field_field_widget_form(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $element) {
|
||||
// Don't need to check the type right now because we're only defining one
|
||||
// Don't need to check the type right now because we're only defining one.
|
||||
$element += array(
|
||||
'#type' => 'fieldset'
|
||||
'#type' => 'fieldset',
|
||||
);
|
||||
|
||||
|
||||
$element['video_url'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Video URL'),
|
||||
'#attributes' => array('class' => array('video_embed_url')),
|
||||
'#attached' => array(
|
||||
'css' => array(
|
||||
drupal_get_path('module', 'video_embed_field') .'/video_embed_field.form.css'
|
||||
)
|
||||
'#attached' => array(
|
||||
'css' => array(
|
||||
drupal_get_path('module', 'video_embed_field') . '/video_embed_field.form.css',
|
||||
),
|
||||
),
|
||||
'#default_value' => isset($items[$delta]['video_url'])?$items[$delta]['video_url']:'',
|
||||
'#required' => $element['#required']
|
||||
'#default_value' => isset($items[$delta]['video_url']) ? $items[$delta]['video_url'] : '',
|
||||
'#required' => $element['#required'],
|
||||
'#maxlength' => 255,
|
||||
);
|
||||
|
||||
|
||||
// Add the description field if enabled.
|
||||
if (!empty($instance['settings']['description_field'])) {
|
||||
$element['description'] = array(
|
||||
@ -88,6 +177,7 @@ function video_embed_field_field_widget_form(&$form, &$form_state, $field, $inst
|
||||
'#title' => t('Description'),
|
||||
'#default_value' => isset($items[$delta]['description']) ? $items[$delta]['description'] : '',
|
||||
'#description' => t('The description which may be used as a label.'),
|
||||
'#maxlength' => $instance['settings']['description_length'],
|
||||
);
|
||||
}
|
||||
|
||||
@ -104,11 +194,11 @@ function video_embed_field_field_validate($entity_type, $entity, $field, $instan
|
||||
if (stristr($item['video_url'], '.') && !stristr($item['video_url'], 'http://') && !stristr($item['video_url'], 'https://')) {
|
||||
$item['video_url'] = 'http://' . $item['video_url'];
|
||||
}
|
||||
|
||||
|
||||
$parts = parse_url($item['video_url']);
|
||||
if (!$parts || !isset($parts['host'])) {
|
||||
$errors[$field['field_name']][$langcode][$delta][] = array(
|
||||
'error' => t('Invalid Url'),
|
||||
'error' => t('Invalid Url'),
|
||||
'message' => t('Video: Invalid Video URL.', array('%name' => $instance['label'])),
|
||||
);
|
||||
}
|
||||
@ -117,10 +207,10 @@ function video_embed_field_field_validate($entity_type, $entity, $field, $instan
|
||||
if (stripos($host, 'www.') > -1) {
|
||||
$host = substr($host, 4);
|
||||
}
|
||||
$domains = _video_embed_field_get_provider_domains();
|
||||
$domains = _video_embed_field_get_instance_provider_domains($instance);
|
||||
if (!array_key_exists($host, $domains)) {
|
||||
$errors[$field['field_name']][$langcode][$delta][] = array(
|
||||
'error' => t('Unsupported Video Provider'),
|
||||
'error' => t('Unsupported Video Provider'),
|
||||
'message' => t('%name: This video provider is not currently supported.', array('%name' => $instance['label'])),
|
||||
);
|
||||
}
|
||||
@ -130,39 +220,44 @@ function video_embed_field_field_validate($entity_type, $entity, $field, $instan
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of hook_field_prepare_view().
|
||||
* Implements hook_field_presave().
|
||||
*
|
||||
* Download and save the thumbnail if it hasn't already been stored.
|
||||
* Get video data.
|
||||
*/
|
||||
function video_embed_field_field_presave($entity_type, $entity, $field, $instance, $langcode, &$items) {
|
||||
foreach($items as $delta => $item){
|
||||
foreach ($items as $delta => $item) {
|
||||
// Trim whitespace from the video URL.
|
||||
$items[$delta]['video_url'] = trim($item['video_url']);
|
||||
|
||||
// Try to load thumbnail URL
|
||||
$info = video_embed_field_thumbnail_url($item['video_url']);
|
||||
// Try to load thumbnail URL.
|
||||
$info = video_embed_field_thumbnail_url($item['video_url']);
|
||||
if (isset($info['url']) && $info['url']) {
|
||||
$thumb_url = $info['url'];
|
||||
$local_path = 'public://video_embed_field_thumbnails/' . $info['handler'] . '/' . $info['id'] . '.jpg';
|
||||
$thumb_extension = pathinfo($thumb_url, PATHINFO_EXTENSION);
|
||||
$local_path = "public://video_embed_field_thumbnails/{$info['handler']}/{$info['id']}.$thumb_extension";
|
||||
|
||||
$dirname = drupal_dirname($local_path);
|
||||
file_prepare_directory($dirname, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);
|
||||
|
||||
$response = drupal_http_request($thumb_url);
|
||||
if (!isset($response->error)) {
|
||||
file_save_data($response->data, $local_path, TRUE);
|
||||
file_save_data($response->data, $local_path, FILE_EXISTS_REPLACE);
|
||||
}
|
||||
else{
|
||||
@copy($thumb_url, $local_path);
|
||||
else {
|
||||
@copy($thumb_url, $local_path);
|
||||
}
|
||||
|
||||
|
||||
$items[$delta]['thumbnail_path'] = $local_path;
|
||||
} //couldn't get the thumbnail for whatever reason
|
||||
// Delete any image derivatives at the original image path.
|
||||
image_path_flush($local_path);
|
||||
}
|
||||
// Couldn't get the thumbnail for whatever reason.
|
||||
else {
|
||||
$items[$delta]['thumbnail_path'] = '';
|
||||
$items[$delta]['thumbnail_path'] = '';
|
||||
}
|
||||
|
||||
// Try to load video data
|
||||
// Try to load video data.
|
||||
$data = video_embed_field_get_video_data($item['video_url']);
|
||||
if (is_array($data) && !empty($data)) {
|
||||
$items[$delta]['video_data'] = serialize($data);
|
||||
@ -175,9 +270,9 @@ function video_embed_field_field_presave($entity_type, $entity, $field, $instanc
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements of hook_field_is_empty().
|
||||
* Implements hook_field_is_empty().
|
||||
*/
|
||||
function video_embed_field_field_is_empty($item, $field){
|
||||
function video_embed_field_field_is_empty($item, $field) {
|
||||
return empty($item) || empty($item['video_url']) || $item['video_url'] === '';
|
||||
}
|
||||
|
||||
@ -189,23 +284,45 @@ function video_embed_field_field_formatter_info() {
|
||||
'video_embed_field' => array(
|
||||
'label' => t('Video Player'),
|
||||
'field types' => array('video_embed_field'),
|
||||
'settings' => array('video_style' => 'normal', 'description' => 1),
|
||||
'settings' => array(
|
||||
'video_style' => 'normal',
|
||||
'description' => 1,
|
||||
'description_position' => 'bottom',
|
||||
),
|
||||
),
|
||||
'video_embed_field_url' => array(
|
||||
'label' => t('URL to Video'),
|
||||
'field types' => array('video_embed_field'),
|
||||
'settings' => array(),
|
||||
),
|
||||
'video_embed_field_thumbnail' => array(
|
||||
'label' => t('Thumbnail Preview'),
|
||||
'field types' => array('video_embed_field'),
|
||||
'settings' => array(
|
||||
'image_style' => 'none',
|
||||
'image_style' => '',
|
||||
'description' => 1,
|
||||
'description_position' => 'bottom',
|
||||
'image_link' => 'none',
|
||||
),
|
||||
),
|
||||
);
|
||||
if( module_exists('colorbox') ) {
|
||||
if (module_exists('colorbox')) {
|
||||
$info['video_embed_field_thumbnail_colorbox'] = array(
|
||||
'label' => t('Thumbnail Preview w/Colorbox'),
|
||||
'field types' => array('video_embed_field'),
|
||||
'settings' => array('video_style' => 'normal', 'image_style' => 'none', 'description' => 1),
|
||||
'settings' => array(
|
||||
'video_style' => 'normal',
|
||||
'image_style' => '',
|
||||
'description' => 1,
|
||||
'description_position' => 'bottom',
|
||||
),
|
||||
);
|
||||
$info['video_embed_field_url_colorbox'] = array(
|
||||
'label' => t('URL to Video w/Colorbox'),
|
||||
'field types' => array('video_embed_field'),
|
||||
'settings' => array(
|
||||
'video_style' => 'normal',
|
||||
),
|
||||
);
|
||||
}
|
||||
return $info;
|
||||
@ -218,8 +335,8 @@ function video_embed_field_field_formatter_settings_form($field, $instance, $vie
|
||||
$display = $instance['display'][$view_mode];
|
||||
$settings = $display['settings'];
|
||||
$element = array();
|
||||
|
||||
if ($display['type'] == 'video_embed_field' || $display['type'] == 'video_embed_field_thumbnail_colorbox') {
|
||||
|
||||
if ($display['type'] == 'video_embed_field' || $display['type'] == 'video_embed_field_thumbnail_colorbox' || $display['type'] == 'video_embed_field_url_colorbox') {
|
||||
$video_styles = video_embed_field_video_style_options(FALSE);
|
||||
$element['video_style'] = array(
|
||||
'#title' => t('Video style'),
|
||||
@ -227,7 +344,7 @@ function video_embed_field_field_formatter_settings_form($field, $instance, $vie
|
||||
'#default_value' => $settings['video_style'],
|
||||
'#options' => $video_styles,
|
||||
);
|
||||
}
|
||||
}
|
||||
if ($display['type'] == 'video_embed_field_thumbnail' || $display['type'] == 'video_embed_field_thumbnail_colorbox') {
|
||||
$element['image_style'] = array(
|
||||
'#title' => t('Image style'),
|
||||
@ -235,12 +352,12 @@ function video_embed_field_field_formatter_settings_form($field, $instance, $vie
|
||||
'#options' => image_style_options(FALSE),
|
||||
'#default_value' => $settings['image_style'],
|
||||
'#empty_option' => t('None (original image)'),
|
||||
);
|
||||
);
|
||||
}
|
||||
|
||||
if($display['type'] == 'video_embed_field_thumbnail'){
|
||||
|
||||
if ($display['type'] == 'video_embed_field_thumbnail') {
|
||||
$link_types = array(
|
||||
'node' => t('Node'),
|
||||
'content' => t('Content'),
|
||||
'source' => t('Video Source'),
|
||||
);
|
||||
$element['image_link'] = array(
|
||||
@ -251,17 +368,31 @@ function video_embed_field_field_formatter_settings_form($field, $instance, $vie
|
||||
'#options' => $link_types,
|
||||
);
|
||||
}
|
||||
|
||||
if ($instance['settings']['description_field']) {
|
||||
|
||||
if ($instance['settings']['description_field'] && $display['type'] != 'video_embed_field_url' && $display['type'] != 'video_embed_field_url_colorbox') {
|
||||
$element['description'] = array(
|
||||
'#title' => t('Show description'),
|
||||
'#type' => 'checkbox',
|
||||
'#default_value' => $settings['description'],
|
||||
);
|
||||
|
||||
$element['description_position'] = array(
|
||||
'#title' => t('Description Position'),
|
||||
'#type' => 'select',
|
||||
'#options' => array(
|
||||
'top' => t('Top'),
|
||||
'bottom' => t('Bottom'),
|
||||
),
|
||||
'#default_value' => $settings['description_position'],
|
||||
'#states' => array(
|
||||
'visible' => array(
|
||||
':input[name="fields[' . $field['field_name'] . '][settings_edit_form][settings][description]"]' => array('checked' => TRUE),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
return $element;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_field_formatter_settings_summary().
|
||||
*/
|
||||
@ -270,138 +401,160 @@ function video_embed_field_field_formatter_settings_summary($field, $instance, $
|
||||
$settings = $display['settings'];
|
||||
|
||||
$summary = array();
|
||||
if($display['type'] == 'video_embed_field' || $display['type'] == 'video_embed_field_thumbnail_colorbox'){
|
||||
if ($display['type'] == 'video_embed_field' || $display['type'] == 'video_embed_field_thumbnail_colorbox' || $display['type'] == 'video_embed_field_url_colorbox') {
|
||||
$video_styles = video_embed_field_video_style_options(FALSE);
|
||||
// Styles could be lost because of enabled/disabled modules that defines
|
||||
// their styles in code.
|
||||
if (isset($video_styles[$settings['video_style']])) {
|
||||
$summary[] = t('Video style: @style', array('@style' => $video_styles[$settings['video_style']]));
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($display['type'] == 'video_embed_field_thumbnail' || $display['type'] == 'video_embed_field_thumbnail_colorbox') {
|
||||
$image_styles = image_style_options(FALSE);
|
||||
if (isset($image_styles[$settings['image_style']])) {
|
||||
$summary[] = t('Image style: @style', array('@style' => $image_styles[$settings['image_style']]));
|
||||
} //No Image style (original image)
|
||||
}
|
||||
// No Image style (original image).
|
||||
else {
|
||||
$summary[] = t('Original Image.');
|
||||
}
|
||||
if(isset($settings['image_link'])){
|
||||
$summary[] = t('Image link: ' . $settings['image_link']);
|
||||
if (isset($settings['image_link'])) {
|
||||
$summary[] = t('Image link: @image_link', array('@image_link' => $settings['image_link']));
|
||||
}
|
||||
else{
|
||||
else {
|
||||
$summary[] = t('Image link: none');
|
||||
}
|
||||
}
|
||||
|
||||
if ($settings['description'] && $instance['settings']['description_field']) {
|
||||
$summary[] = t('Show description');
|
||||
if (isset($settings['description'])) {
|
||||
if ($settings['description'] && $instance['settings']['description_field']) {
|
||||
$summary[] = t('Show description');
|
||||
}
|
||||
elseif ($instance['settings']['description_field']) {
|
||||
$summary[] = t('Hide description');
|
||||
}
|
||||
}
|
||||
else if ($instance['settings']['description_field']) {
|
||||
$summary[] = t('Hide description');
|
||||
}
|
||||
|
||||
|
||||
return implode('<br />', $summary);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_field_formatter_view().
|
||||
*/
|
||||
function video_embed_field_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display){
|
||||
function video_embed_field_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
|
||||
$element = array();
|
||||
|
||||
$settings = $display['settings'];
|
||||
|
||||
if ($display['type'] == 'video_embed_field_thumbnail' && $display['settings']['image_link'] == 'content') {
|
||||
$path = entity_uri($entity_type, $entity);
|
||||
}
|
||||
|
||||
foreach ($items as $delta => $item) {
|
||||
//create the render array for the description
|
||||
if (isset($item['description']) && $item['description'] && $display['settings']['description'] && $instance['settings']['description_field']) {
|
||||
// Create the render array for the description.
|
||||
if (isset($item['description']) && $item['description'] && $settings['description'] && $instance['settings']['description_field']) {
|
||||
$description = array(
|
||||
'#prefix' => '<div class="video-embed-description">',
|
||||
'#markup' => $item['description'],
|
||||
'#suffix' => '</div>',
|
||||
);
|
||||
$alt = $item['description'];
|
||||
}
|
||||
else {
|
||||
$description = array();
|
||||
$alt = '';
|
||||
}
|
||||
|
||||
//Render the field
|
||||
// Render the field.
|
||||
if ($display['type'] == 'video_embed_field') {
|
||||
$element[$delta] = array(
|
||||
array(
|
||||
'#theme' => 'video_embed_field_embed_code',
|
||||
'#url' => $item['video_url'],
|
||||
'#style' => $display['settings']['video_style'],
|
||||
'#style' => $settings['video_style'],
|
||||
'#video_data' => !empty($item['video_data']) ? unserialize($item['video_data']) : array(),
|
||||
),
|
||||
);
|
||||
}
|
||||
else if ($display['type'] == 'video_embed_field_thumbnail') {
|
||||
elseif ($display['type'] == 'video_embed_field_url') {
|
||||
$element[$delta] = array(
|
||||
array(
|
||||
'#markup' => url($item['video_url']),
|
||||
),
|
||||
);
|
||||
}
|
||||
elseif ($display['type'] == 'video_embed_field_thumbnail') {
|
||||
if (isset($item['thumbnail_path'])) {
|
||||
if(empty($display['settings']['image_style']) || $display['settings']['image_style'] == 'none'){
|
||||
$element[$delta] = array(
|
||||
array(
|
||||
'#theme' => 'image',
|
||||
'#path' => $item['thumbnail_path'],
|
||||
),
|
||||
if ($display['settings']['image_link'] == 'source') {
|
||||
if ($ret = parse_url($item['video_url'])) {
|
||||
if (!isset($ret["scheme"])) {
|
||||
$item['video_url'] = "http://{$item['video_url']}";
|
||||
}
|
||||
}
|
||||
$path = array(
|
||||
'path' => $item['video_url'],
|
||||
'options' => array(),
|
||||
);
|
||||
}
|
||||
else {
|
||||
$element[$delta] = array(
|
||||
array(
|
||||
'#theme' => 'image_style',
|
||||
'#path' => $item['thumbnail_path'],
|
||||
'#style_name' => $display['settings']['image_style'],
|
||||
),
|
||||
);
|
||||
}
|
||||
if($display['settings']['image_link'] == 'source'){
|
||||
$link = explode('|||', l('|||', $item['video_url']));
|
||||
$element[$delta]['#prefix'] = $link[0];
|
||||
$element[$delta]['#suffix'] = $link[1];
|
||||
}
|
||||
else if($display['settings']['image_link'] == 'node'){
|
||||
$nid = $entity->nid;
|
||||
$link = explode('|||', l('|||', 'node/'. $nid));
|
||||
$element[$delta]['#prefix'] = $link[0];
|
||||
$element[$delta]['#suffix'] = $link[1];
|
||||
}
|
||||
} //incase no thumbnail was downloaded / provider doesn't support thumbnails
|
||||
else {
|
||||
|
||||
$element[$delta] = array(
|
||||
);
|
||||
'#theme' => 'image_formatter',
|
||||
'#item' => array('uri' => $item['thumbnail_path'], 'alt' => $alt),
|
||||
'#image_style' => $display['settings']['image_style'],
|
||||
'#path' => isset($path) ? $path : '',
|
||||
);
|
||||
}
|
||||
// Incase no thumbnail was downloaded/provider doesn't support thumbnails.
|
||||
else {
|
||||
$element[$delta] = array();
|
||||
}
|
||||
}
|
||||
else if ($display['type'] == 'video_embed_field_thumbnail_colorbox') {
|
||||
elseif ($display['type'] == 'video_embed_field_thumbnail_colorbox') {
|
||||
if (isset($item['thumbnail_path'])) {
|
||||
$element[$delta] = array(
|
||||
if ($ret = parse_url($item['video_url'])) {
|
||||
if (!isset($ret["scheme"])) {
|
||||
$item['video_url'] = "http://{$item['video_url']}";
|
||||
}
|
||||
}
|
||||
$element[$delta] = array(
|
||||
array(
|
||||
'#theme' => 'video_embed_field_colorbox_code',
|
||||
'#image_url' => $item['thumbnail_path'],
|
||||
'#image_style' => $display['settings']['image_style'],
|
||||
'#image_alt' => $alt,
|
||||
'#video_url' => $item['video_url'],
|
||||
'#video_style' => $display['settings']['video_style'],
|
||||
'#video_data' => unserialize($item['video_data']),
|
||||
),
|
||||
);
|
||||
}//incase no thumbnail was downloaded / provider doesn't support thumbnails
|
||||
);
|
||||
}
|
||||
// Incase no thumbnail was downloaded/provider doesn't support thumbnails.
|
||||
else {
|
||||
$element[$delta] = array(
|
||||
);
|
||||
$element[$delta] = array();
|
||||
}
|
||||
}
|
||||
//Get the HTML instead of the array, because we append it to the suffix.
|
||||
//This way, the thumbnail link wrapper doesn't make the description a link as well.
|
||||
elseif ($display['type'] == 'video_embed_field_url_colorbox') {
|
||||
$path = video_embed_field_get_ajax_url($item['video_url'], $display['settings']['video_style']);
|
||||
|
||||
$element[$delta] = array(
|
||||
array(
|
||||
'#markup' => url($path['path'], $path['options']),
|
||||
),
|
||||
);
|
||||
}
|
||||
// Get the HTML instead of the array, because we append it to the suffix.
|
||||
// This way, the thumbnail link doesn't make the description a link as well.
|
||||
$description_html = drupal_render($description);
|
||||
|
||||
//No need to check to add, as we set it to blank above if it's set to not display.
|
||||
//The if/else is so that it doesn't show an error in case there's no suffix.
|
||||
if(isset($element[$delta]['#suffix'])){
|
||||
|
||||
$pos = isset($settings['description_position']) ? $settings['description_position'] : 'bottom';
|
||||
if ($pos == 'top') {
|
||||
$element[$delta]['#prefix'] = isset($element[$delta]['#prefix']) ? $element[$delta]['#prefix'] : '';
|
||||
$element[$delta]['#prefix'] = $description_html . $element[$delta]['#prefix'];
|
||||
}
|
||||
else {
|
||||
$element[$delta]['#suffix'] = isset($element[$delta]['#suffix']) ? $element[$delta]['#suffix'] : '';
|
||||
$element[$delta]['#suffix'] .= $description_html;
|
||||
}
|
||||
else{
|
||||
$element[$delta]['#suffix'] = $description_html;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
return $element;
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,15 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Provide some handlers for video embed field
|
||||
* Other modules can implement the hook_video_embed_handler_info to provide more handlers
|
||||
* @file
|
||||
* Provide some handlers for video embed field
|
||||
* Other modules can implement the hook_video_embed_handler_info to provide more
|
||||
* handlers.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Implementation of hook_video_embed_handler_info
|
||||
* Implements hook_video_embed_handler_info().
|
||||
*/
|
||||
function video_embed_field_video_embed_handler_info() {
|
||||
$handlers = array();
|
||||
@ -15,18 +18,21 @@ function video_embed_field_video_embed_handler_info() {
|
||||
'title' => 'Youtube',
|
||||
'function' => 'video_embed_field_handle_youtube',
|
||||
'thumbnail_function' => 'video_embed_field_handle_youtube_thumbnail',
|
||||
'thumbnail_default' => drupal_get_path('module', 'video_embed_field') . '/img/youtube.jpg',
|
||||
'data_function' => 'video_embed_field_handle_youtube_data',
|
||||
'form' => 'video_embed_field_handler_youtube_form',
|
||||
'form_validate' => 'video_embed_field_handler_youtube_form_validate',
|
||||
'domains' => array(
|
||||
'youtube.com',
|
||||
'youtu.be'
|
||||
'youtu.be',
|
||||
),
|
||||
'defaults' => array(
|
||||
'width' => '640px',
|
||||
'height' => '360px',
|
||||
'width' => 640,
|
||||
'height' => 360,
|
||||
'autoplay' => 0,
|
||||
'hd' => 1,
|
||||
'vq' => 'large',
|
||||
'rel' => 0,
|
||||
'controls' => 1,
|
||||
'autohide' => 2,
|
||||
'showinfo' => 1,
|
||||
'modestbranding' => 0,
|
||||
@ -39,20 +45,22 @@ function video_embed_field_video_embed_handler_info() {
|
||||
'title' => 'Vimeo',
|
||||
'function' => 'video_embed_field_handle_vimeo',
|
||||
'thumbnail_function' => 'video_embed_field_handle_vimeo_thumbnail',
|
||||
'data_function' => 'video_embed_field_handle_vimeo_data',
|
||||
'thumbnail_default' => drupal_get_path('module', 'video_embed_field') . '/img/vimeo.jpg',
|
||||
'form' => 'video_embed_field_handler_vimeo_form',
|
||||
'form_validate' => 'video_embed_field_handler_vimeo_form_validate',
|
||||
'domains' => array(
|
||||
'vimeo.com'
|
||||
'vimeo.com',
|
||||
),
|
||||
'defaults' => array(
|
||||
'width' => '640px',
|
||||
'height' => '360px',
|
||||
'width' => 640,
|
||||
'height' => 360,
|
||||
'color' => '00adef',
|
||||
'portrait' => 1,
|
||||
'title' => 1,
|
||||
'byline' => 1,
|
||||
'autoplay' => 0,
|
||||
'loop' => 0,
|
||||
'froogaloop' => 0,
|
||||
),
|
||||
);
|
||||
|
||||
@ -60,51 +68,56 @@ function video_embed_field_video_embed_handler_info() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to get the youtube video's id
|
||||
* Returns false if it doesn't parse for wahtever reason
|
||||
* Helper function to get the youtube video's id.
|
||||
*
|
||||
* @param string $url
|
||||
* The video URL.
|
||||
*
|
||||
* @return string|bool
|
||||
* The video ID, or FALSE in case the ID can't be retrieved from the URL.
|
||||
*/
|
||||
function _video_embed_field_get_youtube_id($url){
|
||||
// Find the ID of the video they want to play from the url
|
||||
function _video_embed_field_get_youtube_id($url) {
|
||||
// Find the ID of the video they want to play from the url.
|
||||
if (stristr($url, 'http://')) {
|
||||
$url = substr($url, 7);
|
||||
}
|
||||
else if (stristr($url, 'https://')) {
|
||||
elseif (stristr($url, 'https://')) {
|
||||
$url = substr($url, 8);
|
||||
}
|
||||
|
||||
if(stristr($url, 'playlist')){
|
||||
//Playlists need the appended ampersand to take the options properly.
|
||||
if (stristr($url, 'playlist')) {
|
||||
// Playlists need the appended ampersand to take the options properly.
|
||||
$url = $url . '&';
|
||||
$pos = strripos($url, '?list=');
|
||||
if($pos!==FALSE){
|
||||
if ($pos !== FALSE) {
|
||||
$pos2 = stripos($url, '&');
|
||||
$pos2++;
|
||||
}
|
||||
else{
|
||||
else {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
//Alternate playlist link
|
||||
else if(stristr($url, 'view_play_list')){
|
||||
// Alternate playlist link.
|
||||
elseif (stristr($url, 'view_play_list')) {
|
||||
$url = $url . '&';
|
||||
//All playlist ID's are prepended with PL. view_play_list links allow you to not have that, though.
|
||||
if(!stristr($url, '?p=PL')){
|
||||
// All playlist ID's are prepended with PL.
|
||||
if (!stristr($url, '?p=PL')) {
|
||||
$url = substr_replace($url, 'PL', strpos($url, '?p=') + 3, 0);
|
||||
}
|
||||
//Replace the links format with the embed format
|
||||
// Replace the links format with the embed format.
|
||||
$url = str_ireplace('play_list?p=', 'videoseries?list=', $url);
|
||||
$pos = strripos($url, 'videoseries?list=');
|
||||
if($pos !== FALSE){
|
||||
if ($pos !== FALSE) {
|
||||
$pos2 = stripos($url, '&');
|
||||
$pos2++;
|
||||
}
|
||||
else{
|
||||
else {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
else{
|
||||
else {
|
||||
$pos = strripos($url, 'v=');
|
||||
if ($pos!== FALSE) {
|
||||
if ($pos !== FALSE) {
|
||||
$pos += 2;
|
||||
$pos2 = stripos($url, '&', $pos);
|
||||
$pos_hash = stripos($url, '#', $pos);
|
||||
@ -138,90 +151,102 @@ function _video_embed_field_get_youtube_id($url){
|
||||
|
||||
/**
|
||||
* Handler for Youtube videos.
|
||||
*
|
||||
* @param string $url
|
||||
* The video URL.
|
||||
* @param array $settings
|
||||
* The settings array.
|
||||
*
|
||||
* @return array
|
||||
* The video iframe render array.
|
||||
*/
|
||||
function video_embed_field_handle_youtube($url, $settings) {
|
||||
$output = array();
|
||||
|
||||
//Grab the minutes and seconds, and just convert it down to seconds
|
||||
// Grab the minutes and seconds, and just convert it down to seconds.
|
||||
preg_match('/#t=((?P<min>\d+)m)?((?P<sec>\d+)s)?/', $url, $matches);
|
||||
|
||||
//Give it some default data in case there is no #t=...
|
||||
// Give it some default data in case there is no #t=...
|
||||
$matches += array(
|
||||
"min" => 0,
|
||||
"sec" => 0,
|
||||
"min" => 0,
|
||||
"sec" => 0,
|
||||
);
|
||||
$time = ($matches["min"] * 60) + $matches["sec"];
|
||||
$settings['start'] = $time;
|
||||
|
||||
$id = _video_embed_field_get_youtube_id($url);
|
||||
if (!$id) {
|
||||
// We can't decode the URL - just return the URL as a link
|
||||
// We can't decode the URL - just return the URL as a link.
|
||||
$output['#markup'] = l($url, $url);
|
||||
return $output;
|
||||
}
|
||||
// Construct the embed code
|
||||
// Construct the embed code.
|
||||
$settings['wmode'] = 'opaque';
|
||||
$settings_str = _video_embed_code_get_settings_str($settings);
|
||||
|
||||
$output['#markup'] = '<iframe width="' . $settings['width'] . '" height="' . $settings['height'] . '" src="//www.youtube.com/embed/' . $id . '?' . $settings_str . '" frameborder="0" allowfullscreen></iframe>';
|
||||
$output['#markup'] = '<iframe width="' . check_plain($settings['width']) . '" height="' . check_plain($settings['height']) . '" src="//www.youtube.com/embed/' . $id . '?' . $settings_str . '" frameborder="0" allowfullscreen></iframe>';
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the thumbnail url for youtube videos
|
||||
* Gets the thumbnail url for youtube videos.
|
||||
*
|
||||
* @param string $url
|
||||
* The video URL.
|
||||
*
|
||||
* @return array
|
||||
* The video thumbnail information.
|
||||
*/
|
||||
function video_embed_field_handle_youtube_thumbnail($video_url){
|
||||
function video_embed_field_handle_youtube_thumbnail($url) {
|
||||
$info = array();
|
||||
|
||||
$id = _video_embed_field_get_youtube_id($video_url);
|
||||
$id = _video_embed_field_get_youtube_id($url);
|
||||
|
||||
//Playlist
|
||||
if(stristr($id, '?list=')){
|
||||
//Strip out all but the ID, including the PL behind the ID.
|
||||
// Playlist.
|
||||
if (stristr($id, '?list=')) {
|
||||
// Strip out all but the ID, including the PL behind the ID.
|
||||
$start = strpos($id, '?list=PL') + 8;
|
||||
$length = strpos($id, '&') - $start;
|
||||
$id = substr($id, $start, $length);
|
||||
$info['id'] = $id;
|
||||
//Playlist info is stored in XML. The thumbnail is in there.
|
||||
// Playlist info is stored in XML. The thumbnail is in there.
|
||||
$xml = drupal_http_request('http://gdata.youtube.com/feeds/api/playlists/' . $id);
|
||||
if(!isset($xml->error)){
|
||||
if (!isset($xml->error)) {
|
||||
$xml = new SimpleXMLElement($xml->data);
|
||||
$media = $xml->children('http://search.yahoo.com/mrss/');
|
||||
if($media->group->thumbnail && $media->group->thumbnail[0]->attributes()){
|
||||
if ($media->group->thumbnail && $media->group->thumbnail[0]->attributes()) {
|
||||
$attrs = $media->group->thumbnail[0]->attributes();
|
||||
$info['url'] = (string)$attrs['url'];
|
||||
$info['url'] = (string) $attrs['url'];
|
||||
}
|
||||
}
|
||||
}
|
||||
//Regular video
|
||||
else if($id) {
|
||||
// Regular video.
|
||||
elseif ($id) {
|
||||
$info['id'] = $id;
|
||||
$info['url'] = 'http://img.youtube.com/vi/'.$id.'/0.jpg';
|
||||
$info['url'] = 'http://img.youtube.com/vi/' . $id . '/0.jpg';
|
||||
}
|
||||
return $info;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get video data for a YouTube video URL
|
||||
/**
|
||||
* Gets video data for a YouTube video URL.
|
||||
*
|
||||
* @param string $url
|
||||
* A YouTube video URL to get data for
|
||||
*
|
||||
* @return array|false $data
|
||||
* @return array|bool
|
||||
* An array of video data, or FALSE if unable to fetch data
|
||||
*/
|
||||
function video_embed_field_handle_youtube_data($url) {
|
||||
$data = array();
|
||||
|
||||
// Get YouTube video ID from URL
|
||||
// Get YouTube video ID from URL.
|
||||
$id = _video_embed_field_get_youtube_id($url);
|
||||
|
||||
if ($id) {
|
||||
$response = drupal_http_request('http://gdata.youtube.com/feeds/api/videos/' . $id . '?v=2&alt=json');
|
||||
if (!isset($response->error)) {
|
||||
$data = json_decode($response->data);
|
||||
$data = (array) $data->entry;
|
||||
$data = isset($data->entry) ? (array) $data->entry : (array) $data->feed;
|
||||
return _video_embed_field_clean_up_youtube_data($data);
|
||||
}
|
||||
}
|
||||
@ -230,30 +255,38 @@ function video_embed_field_handle_youtube_data($url) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Flatten out some unnecessary nesting in the youtube data
|
||||
* Flattens out some unnecessary nesting in the youtube data.
|
||||
*
|
||||
* @param array $data
|
||||
* The unflattened data.
|
||||
*
|
||||
* @return array
|
||||
* The flattened data.
|
||||
*/
|
||||
function _video_embed_field_clean_up_youtube_data($data) {
|
||||
//make things a bit nicer for people trying to use the data
|
||||
// Make things a bit nicer for people trying to use the data.
|
||||
foreach ($data as $key => $value) {
|
||||
if (is_object($value)) {
|
||||
$temp = (array)$value;
|
||||
$temp = (array) $value;
|
||||
if (isset($temp['$t'])) {
|
||||
$data[$key] = $temp['$t'];
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
$data[$key] = _video_embed_field_clean_up_youtube_data($temp);
|
||||
}
|
||||
} else if (is_array($value)) {
|
||||
}
|
||||
elseif (is_array($value)) {
|
||||
$data[$key] = _video_embed_field_clean_up_youtube_data($value);
|
||||
}
|
||||
|
||||
if($key === 'category') {
|
||||
if ($key === 'category') {
|
||||
$terms = array();
|
||||
foreach ($data[$key] as $value) {
|
||||
if(isset($value['scheme']) && $value['scheme'] == 'http://schemas.google.com/g/2005#kind') {
|
||||
if (isset($value['scheme']) && $value['scheme'] == 'http://schemas.google.com/g/2005#kind') {
|
||||
continue;
|
||||
}
|
||||
|
||||
if(isset($value['term'])) {
|
||||
if (isset($value['term'])) {
|
||||
$terms[] = $value['term'];
|
||||
}
|
||||
}
|
||||
@ -265,6 +298,12 @@ function _video_embed_field_clean_up_youtube_data($data) {
|
||||
|
||||
/**
|
||||
* Defines the form elements for the Youtube configuration form.
|
||||
*
|
||||
* @param array $defaults
|
||||
* The form default values.
|
||||
*
|
||||
* @return array
|
||||
* The provider settings form array.
|
||||
*/
|
||||
function video_embed_field_handler_youtube_form($defaults) {
|
||||
$form = array();
|
||||
@ -298,11 +337,18 @@ function video_embed_field_handler_youtube_form($defaults) {
|
||||
'#description' => t('Play the video immediately.'),
|
||||
'#default_value' => $defaults['autoplay'],
|
||||
);
|
||||
$form['hd'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Use HD'),
|
||||
'#description' => t('Attempt to play the video in HD if available.'),
|
||||
'#default_value' => $defaults['hd'],
|
||||
$form['vq'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('Video quality'),
|
||||
'#options' => array(
|
||||
'small' => t('Small (240p)'),
|
||||
'medium' => t('Medium (360p)'),
|
||||
'large' => t('Large (480p)'),
|
||||
'hd720' => t('HD 720p'),
|
||||
'hd1080' => t('HD 10800p'),
|
||||
),
|
||||
'#default_value' => $defaults['vq'],
|
||||
'#description' => t('Attempt to play the video in certain quality if available.'),
|
||||
);
|
||||
$form['rel'] = array(
|
||||
'#type' => 'checkbox',
|
||||
@ -317,10 +363,10 @@ function video_embed_field_handler_youtube_form($defaults) {
|
||||
'#default_value' => $defaults['showinfo'],
|
||||
);
|
||||
$form['modestbranding'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Hide Youtube logo'),
|
||||
'#description' => t('Hide the Youtube logo button on the player'),
|
||||
'#default_value' => $defaults['modestbranding']
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Hide Youtube logo'),
|
||||
'#description' => t('Hide the Youtube logo button on the player'),
|
||||
'#default_value' => $defaults['modestbranding'],
|
||||
);
|
||||
$form['iv_load_policy'] = array(
|
||||
'#type' => 'radios',
|
||||
@ -332,6 +378,17 @@ function video_embed_field_handler_youtube_form($defaults) {
|
||||
'#description' => t('Controls the display of annotations over the video content. Only works when using the flash player.'),
|
||||
'#default_value' => $defaults['iv_load_policy'],
|
||||
);
|
||||
$form['controls'] = array(
|
||||
'#type' => 'radios',
|
||||
'#options' => array(
|
||||
0 => t('Hide video controls.'),
|
||||
1 => t('Show video controls. Youtube default.'),
|
||||
2 => t('Show video controls with performance improvement for iframe embeds.'),
|
||||
),
|
||||
'#title' => t('Display Youtube player controls'),
|
||||
'#description' => t('This parameter indicates whether the video player controls will display.'),
|
||||
'#default_value' => $defaults['controls'],
|
||||
);
|
||||
$form['autohide'] = array(
|
||||
'#type' => 'radios',
|
||||
'#options' => array(
|
||||
@ -348,89 +405,134 @@ function video_embed_field_handler_youtube_form($defaults) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to get the Vimeo video's ID
|
||||
* Validates the form elements for the Youtube configuration form.
|
||||
*
|
||||
* @param array $element
|
||||
* The form element to validate.
|
||||
* @param array $form_state
|
||||
* The form to validate state.
|
||||
* @param array $form
|
||||
* The form to validate structure.
|
||||
*/
|
||||
function video_embed_field_handler_youtube_form_validate($element, &$form_state, $form) {
|
||||
video_embed_field_validate_dimensions($element);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to get the Vimeo video's data attributes.
|
||||
*
|
||||
* @param string $url
|
||||
* A Vimeo video URL to get the ID of
|
||||
* A Vimeo video URL to get the data from.
|
||||
*
|
||||
* @return integer|false $id
|
||||
* The video ID, or FALSE if unable to get the video ID
|
||||
* @return integer|false
|
||||
* The video's data attributes, or FALSE if unable to get the video ID.
|
||||
*/
|
||||
function _video_embed_field_get_vimeo_id($url){
|
||||
$pos = strripos($url, '/');
|
||||
if ($pos != FALSE) {
|
||||
$pos += 1;
|
||||
return (int) substr($url, $pos);
|
||||
function _video_embed_field_get_vimeo_data($url) {
|
||||
// Set oembed endpoint
|
||||
$oembed_endpoint = 'http://vimeo.com/api/oembed';
|
||||
// Fetch vimeo data
|
||||
$response = drupal_http_request($oembed_endpoint . '.json?url=' . rawurlencode($url));
|
||||
|
||||
try {
|
||||
return json_decode($response->data, TRUE);
|
||||
} catch (Exception $e) {
|
||||
return FALSE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to get the Vimeo video's data attributes.
|
||||
*
|
||||
* @param string $url
|
||||
* A Vimeo video URL to get the ID of.
|
||||
*
|
||||
* @return integer|false
|
||||
* The video ID, or FALSE if unable to get the video ID.
|
||||
*/
|
||||
function _video_embed_field_get_vimeo_id($vimeo_data) {
|
||||
try {
|
||||
$video_id = $vimeo_data['video_id'];
|
||||
} catch (Exception $e) {
|
||||
$video_id = FALSE;
|
||||
}
|
||||
|
||||
return $video_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handler for Vimeo videos.
|
||||
*
|
||||
* @param string $url
|
||||
* The video URL.
|
||||
* @param array $settings
|
||||
* The settings array.
|
||||
*
|
||||
* @return string
|
||||
* The video iframe.
|
||||
*/
|
||||
function video_embed_field_handle_vimeo($url, $settings) {
|
||||
// Get ID of video from URL
|
||||
$id = _video_embed_field_get_vimeo_id($url);
|
||||
if (!$id) {
|
||||
$vimeo_data = _video_embed_field_get_vimeo_data($url);
|
||||
|
||||
// Get ID of video from URL.
|
||||
$id = _video_embed_field_get_vimeo_id($vimeo_data);
|
||||
|
||||
if (empty($id)) {
|
||||
return array(
|
||||
'#markup' => l($url, $url),
|
||||
);
|
||||
}
|
||||
|
||||
// Construct the embed code
|
||||
$settings['portrait'] = 0;
|
||||
// Construct the embed code.
|
||||
$settings['player_id'] = drupal_html_id('vimeo-' . $id);
|
||||
if (!empty($settings['froogaloop'])) {
|
||||
$settings['api'] = 1;
|
||||
}
|
||||
unset($settings['froogaloop']);
|
||||
|
||||
$settings_str = _video_embed_code_get_settings_str($settings);
|
||||
|
||||
return array(
|
||||
'#markup' => '<iframe width="' . $settings['width'] . '" height="' . $settings['height'] . '" src="//player.vimeo.com/video/' . $id .
|
||||
'?' . $settings_str . '" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowfullscreen></iframe>',
|
||||
'#markup' => '<iframe id="' . $settings['player_id'] . '" width="' . check_plain($settings['width']) . '" height="' . check_plain($settings['height']) . '" src="//player.vimeo.com/video/' . $id .
|
||||
'?' . $settings_str . '" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowfullscreen></iframe>',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the thumbnail url for youtube videos
|
||||
* Gets the thumbnail url for vimeo videos.
|
||||
*
|
||||
* @param string $url
|
||||
* The video URL.
|
||||
*
|
||||
* @return array
|
||||
* The video thumbnail information.
|
||||
*/
|
||||
function video_embed_field_handle_vimeo_thumbnail($url){
|
||||
// Get ID of video from URL
|
||||
$id = _video_embed_field_get_vimeo_id($url);
|
||||
function video_embed_field_handle_vimeo_thumbnail($url) {
|
||||
$vimeo_data = _video_embed_field_get_vimeo_data($url);
|
||||
|
||||
// Get ID of video from URL.
|
||||
$id = _video_embed_field_get_vimeo_id($vimeo_data);
|
||||
|
||||
$info = array(
|
||||
'id' => $id,
|
||||
);
|
||||
$response = drupal_http_request('http://vimeo.com/api/v2/video/' . $id . '.php');
|
||||
if (!isset($response->error)) {
|
||||
$response = unserialize($response->data);
|
||||
$video = current($response);
|
||||
|
||||
$image_url = $video['thumbnail_large'];
|
||||
$info['url'] = $image_url;
|
||||
try {
|
||||
$info['url'] = $vimeo_data['thumbnail_url'];
|
||||
} catch (Exception $e) {
|
||||
|
||||
}
|
||||
|
||||
return $info;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get video data for a Vimeo video URL
|
||||
*
|
||||
* @param string $url
|
||||
* A Vimeo video URL to get data for
|
||||
*
|
||||
* @return array|false $data
|
||||
* An array of video data, or FALSE if unable to fetch data
|
||||
*/
|
||||
function video_embed_field_handle_vimeo_data($url) {
|
||||
// Get ID of video from URL
|
||||
$id = _video_embed_field_get_vimeo_id($url);
|
||||
if ($id) {
|
||||
$response = drupal_http_request('http://vimeo.com/api/v2/video/' . $id . '.php');
|
||||
if (!isset($response->error)) {
|
||||
$response = unserialize($response->data);
|
||||
return (array) current($response);
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines the form elements for the Vimeo configuration form.
|
||||
*
|
||||
* @param array $defaults
|
||||
* The form default values.
|
||||
*
|
||||
* @return array
|
||||
* The provider settings form array.
|
||||
*/
|
||||
function video_embed_field_handler_vimeo_form($defaults) {
|
||||
$form = array();
|
||||
@ -442,6 +544,7 @@ function video_embed_field_handler_vimeo_form($defaults) {
|
||||
'#description' => t('The width of the vimeo player.'),
|
||||
'#default_value' => $defaults['width'],
|
||||
);
|
||||
|
||||
$form['height'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#size' => '5',
|
||||
@ -449,6 +552,7 @@ function video_embed_field_handler_vimeo_form($defaults) {
|
||||
'#description' => t('The height of the vimeo player.'),
|
||||
'#default_value' => $defaults['height'],
|
||||
);
|
||||
|
||||
$form['color'] = array(
|
||||
'#type' => 'select',
|
||||
'#options' => array(
|
||||
@ -456,60 +560,98 @@ function video_embed_field_handler_vimeo_form($defaults) {
|
||||
'ff9933' => t('Orange'),
|
||||
'c9ff23' => t('Lime'),
|
||||
'ff0179' => t('Fuschia'),
|
||||
'ffffff' => t('White')
|
||||
'ffffff' => t('White'),
|
||||
),
|
||||
'#title' => t('Player Color'),
|
||||
'#description' => t('The color to use on the vimeo player.'),
|
||||
'#default_value' => $defaults['color'],
|
||||
);
|
||||
|
||||
$form['portrait'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Overlay Author Thumbnail'),
|
||||
'#description' => t('Overlay the author\'s thumbnail before the video is played.'),
|
||||
'#description' => t("Overlay the author's thumbnail before the video is played."),
|
||||
'#default_value' => $defaults['portrait'],
|
||||
);
|
||||
|
||||
$form['title'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Overlay Video\'s Title'),
|
||||
'#description' => t('Overlay the video\'s title before the video is played.'),
|
||||
'#title' => t("Overlay Video's Title"),
|
||||
'#description' => t("Overlay the video's title before the video is played."),
|
||||
'#default_value' => $defaults['title'],
|
||||
);
|
||||
|
||||
$form['byline'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Overlay Video\'s Byline'),
|
||||
'#description' => t('Overlay the video\'s description before the video is played.'),
|
||||
'#title' => t("Overlay Video's Byline"),
|
||||
'#description' => t("Overlay the video's description before the video is played."),
|
||||
'#default_value' => $defaults['byline'],
|
||||
);
|
||||
$form['overridable'] = array (
|
||||
'#prefix' => '<p class="note"><strong>'.t('Note').': </strong><em>',
|
||||
|
||||
$form['overridable'] = array(
|
||||
'#prefix' => '<p class="note"><strong>' . t('Note') . ': </strong><em>',
|
||||
'#markup' => t('Color, portrait, title and byline can be restricted by Vimeo Plus videos.
|
||||
Such videos will ignore these settings.'),
|
||||
'#suffix' => '</em></p>',
|
||||
);
|
||||
|
||||
$form['autoplay'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Autoplay'),
|
||||
'#description' => t('Play the video immediately.'),
|
||||
'#default_value' => $defaults['autoplay'],
|
||||
);
|
||||
|
||||
$form['loop'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Loop'),
|
||||
'#description' => t('Loop the video\'s playback'),
|
||||
'#description' => t("Loop the video's playback"),
|
||||
'#default_value' => $defaults['loop'],
|
||||
);
|
||||
|
||||
$form['froogaloop'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Enable froogaloop support'),
|
||||
'#description' => t("Enables Froogallop Vimeo's library support"),
|
||||
'#default_value' => $defaults['loop'],
|
||||
);
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the min index for use in finding the id of a youtube video
|
||||
* Validates the form elements for the Vimeo configuration form.
|
||||
*
|
||||
* @param array $element
|
||||
* The form element to validate.
|
||||
* @param array $form_state
|
||||
* The form to validate state.
|
||||
* @param array $form
|
||||
* The form to validate structure.
|
||||
*/
|
||||
function video_embed_field_handler_vimeo_form_validate($element, &$form_state, $form) {
|
||||
video_embed_field_validate_dimensions($element);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the min index for use in finding the id of a youtube video.
|
||||
*
|
||||
* @param string $pos1
|
||||
* The first index.
|
||||
* @param string $pos2
|
||||
* The second index.
|
||||
*
|
||||
* @return string
|
||||
* The min index.
|
||||
*/
|
||||
function _video_embed_get_min($pos1, $pos2) {
|
||||
if(!$pos1) {
|
||||
if (!$pos1) {
|
||||
return $pos2;
|
||||
} else if(!$pos2) {
|
||||
}
|
||||
elseif (!$pos2) {
|
||||
return $pos1;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
return min($pos1, $pos2);
|
||||
}
|
||||
}
|
||||
|
@ -4,11 +4,15 @@ core = 7.x
|
||||
package = Media
|
||||
configure = admin/config/media/vef_video_styles
|
||||
|
||||
files[] = video_embed_field.migrate.inc
|
||||
files[] = views/handlers/views_embed_field_views_handler_field_thumbnail_path.inc
|
||||
|
||||
dependencies[] = ctools
|
||||
dependencies[] = image
|
||||
; Information added by drupal.org packaging script on 2012-06-21
|
||||
version = "7.x-2.0-beta5"
|
||||
|
||||
; Information added by Drupal.org packaging script on 2015-04-17
|
||||
version = "7.x-2.0-beta8+7-dev"
|
||||
core = "7.x"
|
||||
project = "video_embed_field"
|
||||
datestamp = "1340317020"
|
||||
datestamp = "1429278491"
|
||||
|
||||
|
@ -1,16 +1,21 @@
|
||||
<?php
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Install, update and uninstall functions for the video_embed_field module.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Install file for video_embed_field module
|
||||
* @author jcaldwell
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Implements hook_field_schema().
|
||||
*/
|
||||
function video_embed_field_field_schema($field){
|
||||
switch($field['type']){
|
||||
case 'video_embed_field' :
|
||||
function video_embed_field_field_schema($field) {
|
||||
switch ($field['type']) {
|
||||
case 'video_embed_field':
|
||||
$columns = array(
|
||||
'video_url' => array(
|
||||
'type' => 'varchar',
|
||||
@ -39,45 +44,43 @@ function video_embed_field_field_schema($field){
|
||||
),
|
||||
);
|
||||
$indexes = array();
|
||||
break;
|
||||
break;
|
||||
}
|
||||
|
||||
return array(
|
||||
'columns' => $columns,
|
||||
'indexes' => $indexes
|
||||
'indexes' => $indexes,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_schema().
|
||||
*/
|
||||
function video_embed_field_schema(){
|
||||
function video_embed_field_schema() {
|
||||
$schema['vef_video_styles'] = array(
|
||||
'description' => 'Stores video embed styles.',
|
||||
'export' => array(
|
||||
'key' => 'name',
|
||||
'primary key' => 'vsid',
|
||||
'identifier' => 'video_embed_style', // Exports will be as $video_style
|
||||
'default hook' => 'default_video_embed_styles', // Function hook name.
|
||||
'identifier' => 'video_embed_style',
|
||||
'default hook' => 'default_video_embed_styles',
|
||||
'api' => array(
|
||||
'owner' => 'video_embed_field',
|
||||
'api' => 'default_video_embed_styles', // Base name for api include files.
|
||||
'api' => 'default_video_embed_styles',
|
||||
'minimum_version' => 1,
|
||||
'current_version' => 1,
|
||||
),
|
||||
),
|
||||
'fields' => array(
|
||||
'vsid' => array(
|
||||
'description' => 'The primary identifier for a video style.',
|
||||
'type' => 'serial',
|
||||
'unsigned' => TRUE,
|
||||
'not null' => TRUE,
|
||||
'no export' => TRUE,
|
||||
),
|
||||
'name' => array(
|
||||
'description' => 'The style name.',
|
||||
'description' => 'The machine-readable option set name.',
|
||||
'type' => 'varchar',
|
||||
'length' => '255',
|
||||
'length' => 255,
|
||||
'not null' => TRUE,
|
||||
),
|
||||
'title' => array(
|
||||
'description' => 'The human-readable title for this option set.',
|
||||
'type' => 'varchar',
|
||||
'length' => 255,
|
||||
'not null' => TRUE,
|
||||
),
|
||||
'data' => array(
|
||||
@ -88,24 +91,13 @@ function video_embed_field_schema(){
|
||||
'serialize' => TRUE,
|
||||
),
|
||||
),
|
||||
'primary key' => array('vsid'),
|
||||
'unique keys' => array(
|
||||
'name' => array('name')
|
||||
),
|
||||
'primary key' => array('name'),
|
||||
);
|
||||
return $schema;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_uninstall().
|
||||
*/
|
||||
function video_embed_field_uninstall(){
|
||||
//do nothing right now - should eventually remove all the variables
|
||||
}
|
||||
|
||||
/**
|
||||
* Update 7000
|
||||
* Add an optional description form
|
||||
* Adds an optional description form.
|
||||
*/
|
||||
function video_embed_field_update_7000() {
|
||||
// Get the list of fields of type 'video_embed_field'.
|
||||
@ -115,7 +107,7 @@ function video_embed_field_update_7000() {
|
||||
$video_embed_fields[$field_name] = field_read_field($field_name);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
foreach ($video_embed_fields as $field) {
|
||||
if ($field['deleted']) {
|
||||
$table = "field_deleted_data_{$field['id']}";
|
||||
@ -125,29 +117,27 @@ function video_embed_field_update_7000() {
|
||||
$table = "field_data_{$field['field_name']}";
|
||||
$revision_table = "field_revision_{$field['field_name']}";
|
||||
}
|
||||
$column = $field['field_name'] . '_' . 'description';
|
||||
$column = $field['field_name'] . '_description';
|
||||
db_add_field($table, $column, array('type' => 'text', 'not null' => FALSE));
|
||||
db_add_field($revision_table, $column, array('type' => 'text', 'not null' => FALSE));
|
||||
}
|
||||
|
||||
|
||||
return t('Additional columns added.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Update 7001
|
||||
* Add video style storage table
|
||||
* Adds video style storage table.
|
||||
*/
|
||||
function video_embed_field_update_7001() {
|
||||
if (!db_table_exists('vef_video_styles')) {
|
||||
$schema = video_embed_field_schema();
|
||||
db_create_table('vef_video_styles', $schema['vef_video_styles']);
|
||||
}
|
||||
|
||||
|
||||
return t('Video styles storage table created.');
|
||||
}
|
||||
/**
|
||||
* Update 7002
|
||||
* Add field for storing the path to the video thumbnail
|
||||
/**
|
||||
* Adds field for storing the path to the video thumbnail.
|
||||
*/
|
||||
function video_embed_field_update_7002() {
|
||||
// Get the list of fields of type 'video_embed_field'.
|
||||
@ -157,7 +147,7 @@ function video_embed_field_update_7002() {
|
||||
$video_embed_fields[$field_name] = field_read_field($field_name);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
foreach ($video_embed_fields as $field) {
|
||||
if ($field['deleted']) {
|
||||
$table = "field_deleted_data_{$field['id']}";
|
||||
@ -167,39 +157,39 @@ function video_embed_field_update_7002() {
|
||||
$table = "field_data_{$field['field_name']}";
|
||||
$revision_table = "field_revision_{$field['field_name']}";
|
||||
}
|
||||
$column = $field['field_name'] . '_' . 'thumbnail_path';
|
||||
$column = $field['field_name'] . '_thumbnail_path';
|
||||
db_add_field($table, $column, array(
|
||||
'type' => 'varchar',
|
||||
'length' => 512,
|
||||
'default' => ''
|
||||
'default' => '',
|
||||
));
|
||||
db_add_field($revision_table, $column, array(
|
||||
'type' => 'varchar',
|
||||
'length' => 512,
|
||||
'default' => ''
|
||||
'default' => '',
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
return t('Thumbnail column added.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable inline colorbox support if colorbox is installed [NO LONGER NEEDED - This update hook does nothing]
|
||||
* Enables inline colorbox support if colorbox is installed.
|
||||
*
|
||||
* [NO LONGER NEEDED - This update hook does nothing]
|
||||
*/
|
||||
function video_embed_field_update_7003() {
|
||||
//this is no longer needed
|
||||
//variable_set('colorbox_inline', 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable colorbox load support if colorbox is installed, we no longer need inline support
|
||||
* Enables colorbox load support if colorbox is installed.
|
||||
*/
|
||||
function video_embed_field_update_7004() {
|
||||
variable_set('colorbox_load', 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add data column to field database.
|
||||
* Adds data column to field database.
|
||||
*/
|
||||
function video_embed_field_update_7005() {
|
||||
// Get the list of fields of type 'video_embed_field'.
|
||||
@ -219,20 +209,157 @@ function video_embed_field_update_7005() {
|
||||
$table = "field_data_{$field['field_name']}";
|
||||
$revision_table = "field_revision_{$field['field_name']}";
|
||||
}
|
||||
$column = $field['field_name'] . '_' . 'video_data';
|
||||
$column = $field['field_name'] . '_video_data';
|
||||
db_add_field($table, $column, array(
|
||||
'type' => 'blob',
|
||||
'not null' => FALSE,
|
||||
'size' => 'big',
|
||||
'serialize' => TRUE
|
||||
'serialize' => TRUE,
|
||||
));
|
||||
db_add_field($revision_table, $column, array(
|
||||
'type' => 'blob',
|
||||
'not null' => FALSE,
|
||||
'size' => 'big',
|
||||
'serialize' => TRUE
|
||||
'serialize' => TRUE,
|
||||
));
|
||||
}
|
||||
|
||||
return t('Data column added. Please clear cache.');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates vef_video_styles table structure.
|
||||
*/
|
||||
function video_embed_field_update_7006() {
|
||||
// Convert the table structure.
|
||||
db_drop_field('vef_video_styles', 'vsid');
|
||||
db_add_primary_key('vef_video_styles', array('name'));
|
||||
db_drop_unique_key('vef_video_styles', 'name');
|
||||
|
||||
db_add_field('vef_video_styles', 'title', array(
|
||||
'type' => 'varchar',
|
||||
'length' => 255,
|
||||
'not null' => TRUE,
|
||||
'default' => '',
|
||||
));
|
||||
// Update title and name values.
|
||||
$result = db_select('vef_video_styles', 'vef')
|
||||
->fields('vef', array('name'))
|
||||
->execute();
|
||||
foreach ($result as $record) {
|
||||
// Set current name as title.
|
||||
db_update('vef_video_styles')
|
||||
->fields(array(
|
||||
'title' => $record->name,
|
||||
))
|
||||
->condition('name', $record->name)
|
||||
->execute();
|
||||
|
||||
// Update name to fit with machine_name constraints.
|
||||
$new_name = preg_replace('/[^a-z0-9_]+/', '_', drupal_strtolower($record->name));
|
||||
if ($new_name != $record->name) {
|
||||
// Check if new name already exists in the database.
|
||||
$counter = 1;
|
||||
$base_name = $new_name;
|
||||
while (TRUE) {
|
||||
$result = db_select('vef_video_styles', 'vef')
|
||||
->fields('vef', array('name'))
|
||||
->condition('name', $new_name)
|
||||
->execute();
|
||||
if ($result->rowCount()) {
|
||||
$new_name = $base_name . '_' . $counter;
|
||||
}
|
||||
else {
|
||||
db_update('vef_video_styles')
|
||||
->fields(array(
|
||||
'name' => $new_name,
|
||||
))
|
||||
->condition('name', $record->name)
|
||||
->execute();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return t('Database schema updated successfully');
|
||||
}
|
||||
|
||||
/**
|
||||
* Update youtube "hd" URL deprecated parameter.
|
||||
*/
|
||||
function video_embed_field_update_7007() {
|
||||
drupal_get_schema('vef_video_styles', TRUE);
|
||||
ctools_include('export');
|
||||
$styles = ctools_export_load_object('vef_video_styles');
|
||||
foreach ($styles as $style) {
|
||||
if (isset($style->data['youtube']['hd'])) {
|
||||
if ($style->data['youtube']['hd']) {
|
||||
$style->data['youtube']['vq'] = 'hd720';
|
||||
}
|
||||
else {
|
||||
$style->data['youtube']['vq'] = 'large';
|
||||
}
|
||||
unset($style->data['youtube']['hd']);
|
||||
ctools_export_crud_save('vef_video_styles', $style);
|
||||
}
|
||||
}
|
||||
|
||||
return t('Parameter hd has been converted to vq.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates naming of 'node' formatter setting to 'content'.
|
||||
*/
|
||||
function video_embed_field_update_7008() {
|
||||
$instances = field_info_instances();
|
||||
foreach ($instances as $entity_type) {
|
||||
foreach ($entity_type as $bundle) {
|
||||
foreach ($bundle as $instance) {
|
||||
$field_info = field_info_field($instance['field_name']);
|
||||
if ($field_info['type'] == 'video_embed_field') {
|
||||
$update = FALSE;
|
||||
foreach ($instance['display'] as &$display) {
|
||||
if ($display['type'] == 'video_embed_field_thumbnail') {
|
||||
if ($display['settings']['image_link'] == 'node') {
|
||||
$display['settings']['image_link'] = 'content';
|
||||
$update = TRUE;
|
||||
}
|
||||
if ($display['settings']['image_style'] == 'none') {
|
||||
$display['settings']['image_style'] = '';
|
||||
$update = TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($update) {
|
||||
field_update_instance($instance);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return t("Updated 'node' setting to 'content'");
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds new Allowed Providers setting to existing instances.
|
||||
*/
|
||||
function video_embed_field_update_7009() {
|
||||
$allowed_providers = array_keys(video_embed_get_handlers());
|
||||
|
||||
$instances = field_info_instances();
|
||||
foreach ($instances as $entity_type) {
|
||||
foreach ($entity_type as $bundle) {
|
||||
foreach ($bundle as $instance) {
|
||||
$field_info = field_info_field($instance['field_name']);
|
||||
if ($field_info['type'] == 'video_embed_field') {
|
||||
$instance['settings']['allowed_providers'] = $allowed_providers;
|
||||
field_update_instance($instance);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return t('Updated default instance settings');
|
||||
}
|
||||
|
@ -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_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__);
|
||||
|
||||
// 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');
|
||||
}
|
||||
|
||||
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 = cache_get('video_embed_field_handlers');
|
||||
$handlers = &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);
|
||||
}
|
||||
else {
|
||||
$handlers = $handlers->data;
|
||||
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']);
|
||||
$path = video_embed_field_get_ajax_url($variables['video_url'], $variables['video_style']);
|
||||
|
||||
// If there was an issue load in the default style
|
||||
if ($style == FALSE) {
|
||||
$style = video_embed_field_video_style_load('normal');
|
||||
}
|
||||
$image = array(
|
||||
'#theme' => 'image_formatter',
|
||||
'#item' => array('uri' => $variables['image_url'], 'alt' => $variables['image_alt']),
|
||||
'#image_style' => $variables['image_style'],
|
||||
'#path' => $path,
|
||||
);
|
||||
|
||||
$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'],
|
||||
);
|
||||
}
|
||||
|
||||
$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'))));
|
||||
|
||||
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
|
||||
*/
|
||||
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;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a video data array for a given video url
|
||||
* Gets the thumbnail url for a given video url.
|
||||
*
|
||||
* @param string $url
|
||||
* A video URL of the data array you want returned
|
||||
* The url of the video.
|
||||
*
|
||||
* @return array|false $data
|
||||
* An array of video data, or FALSE on error
|
||||
* @return string
|
||||
* String representing the url of the thumbnail, or FALSE on error.
|
||||
*/
|
||||
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 $info;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a video data array for a given video url.
|
||||
*
|
||||
* @param string $url
|
||||
* A video URL of the data array you want returned.
|
||||
*
|
||||
* @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);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user