more module updates
This commit is contained in:
BIN
sites/all/modules/contrib/fields/video_embed_field/img/vimeo.jpg
Normal file
BIN
sites/all/modules/contrib/fields/video_embed_field/img/vimeo.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 14 KiB |
Binary file not shown.
After Width: | Height: | Size: 21 KiB |
@@ -0,0 +1,5 @@
|
||||
Brightcove Video Embed Field
|
||||
----------------------------
|
||||
This module parses a Brightcove URL via the Video Embed Field
|
||||
|
||||
Example URL: http://link.brightcove.com/services/player/bcpid3303744435001?bckey=AQ~~,AAAAAGL7jok~,vslbwQw3pdWM_Ya9IsUVNvJJIhV9YG1S&bctid=3118695475001
|
Binary file not shown.
After Width: | Height: | Size: 76 KiB |
@@ -0,0 +1,14 @@
|
||||
name = "Video Embed Brightcove"
|
||||
description = "Provides Brightcove handler for Video Embed Fields."
|
||||
core = 7.x
|
||||
package = Media
|
||||
configure = admin/config/media/vef_video_styles
|
||||
|
||||
dependencies[] = "video_embed_field"
|
||||
|
||||
; 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 = "1429278491"
|
||||
|
@@ -0,0 +1,159 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Add a handler for brightcove videos to Video Embed Field.
|
||||
* @see video_embed_field.api.php for more documentation.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_video_embed_handler_info().
|
||||
*/
|
||||
function video_embed_brightcove_video_embed_handler_info() {
|
||||
$handlers = array();
|
||||
$handlers['brightcove'] = array(
|
||||
'title' => 'Brightcove Video',
|
||||
'function' => 'video_embed_brightcove_handle_video',
|
||||
'thumbnail_default' => drupal_get_path('module', 'video_embed_brightcove') . '/img/brightcove.jpg',
|
||||
'form' => 'video_embed_brightcove_form',
|
||||
'form_validate' => 'video_embed_field_handler_brightcove_form_validate',
|
||||
'domains' => array(
|
||||
'brightcove.com',
|
||||
'link.brightcove.com',
|
||||
),
|
||||
'defaults' => array(
|
||||
'width' => 640,
|
||||
'height' => 360,
|
||||
),
|
||||
);
|
||||
|
||||
return $handlers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Form to configure out video settings.
|
||||
*
|
||||
* @param array $defaults
|
||||
* Values for your provider.
|
||||
*
|
||||
* @return array
|
||||
* A form as defined by form API.
|
||||
*/
|
||||
function video_embed_brightcove_form($defaults) {
|
||||
$form = array();
|
||||
// Element for the width of the player.
|
||||
$form['width'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Player Width'),
|
||||
'#description' => t('The width of the player.'),
|
||||
'#default_value' => $defaults['width'],
|
||||
);
|
||||
|
||||
// Element for the height of the player.
|
||||
$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 Brightcove configuration form.
|
||||
*/
|
||||
function video_embed_field_handler_brightcove_form_validate($element, &$form_state, $form) {
|
||||
video_embed_field_validate_dimensions($element);
|
||||
}
|
||||
|
||||
/**
|
||||
* The video handler.
|
||||
*
|
||||
* @param string $url
|
||||
* The full video url.
|
||||
* @param array $settings
|
||||
* Handlers settings from the settings form.
|
||||
*
|
||||
* @return array|string
|
||||
* The embed code for the video.
|
||||
*/
|
||||
function video_embed_brightcove_handle_video($url, $settings) {
|
||||
$parameters = _video_embed_brightcove_get_video_properties($url);
|
||||
|
||||
if (isset($parameters['id']) && isset($parameters['key'])) {
|
||||
// Embed code.
|
||||
$embed = '<object id="myExperience" class="BrightcoveExperience">
|
||||
<param name="bgcolor" value="#FFFFFF" />
|
||||
<param name="width" value="@width" />
|
||||
<param name="height" value="@height" />
|
||||
<param name="playerID" value="!id" />
|
||||
<param name="playerKey" value="!key" />
|
||||
<param name="isVid" value="true" />
|
||||
<param name="isUI" value="true" />
|
||||
<param name="dynamicStreaming" value="true" />
|
||||
<param name="@videoPlayer" value="!videoplayer" />
|
||||
</object>';
|
||||
// Replace our placeholders with the values from the settings.
|
||||
$embed = format_string($embed, array(
|
||||
'!id' => $parameters['id'],
|
||||
'!key' => $parameters['key'],
|
||||
'@width' => $settings['width'],
|
||||
'@height' => $settings['height'],
|
||||
'!videoplayer' => $parameters['player'],
|
||||
));
|
||||
|
||||
$video = array(
|
||||
'#markup' => $embed,
|
||||
'#suffix' => '<script type="text/javascript">brightcove.createExperiences();</script>',
|
||||
'#attached' => array(
|
||||
'js' => array(
|
||||
'//admin.brightcove.com/js/BrightcoveExperiences.js' => array(
|
||||
'type' => 'external',
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
return $video;
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to take a brightcove video url and return its id.
|
||||
*
|
||||
* @param string $url
|
||||
* The full brightcove video url.
|
||||
*
|
||||
* @return array
|
||||
* The video properties.
|
||||
*/
|
||||
function _video_embed_brightcove_get_video_properties($url) {
|
||||
// Easy way to break a url into its components.
|
||||
$components = array(
|
||||
'id' => array(
|
||||
'start' => 'bcpid',
|
||||
'finish' => '\?bckey',
|
||||
),
|
||||
'key' => array(
|
||||
'start' => 'bckey=',
|
||||
'finish' => '&bctid',
|
||||
),
|
||||
'player' => array(
|
||||
'start' => 'bctid=',
|
||||
'finish' => '',
|
||||
),
|
||||
);
|
||||
|
||||
$matches = array();
|
||||
$return = array();
|
||||
foreach ($components as $key => $component) {
|
||||
$string = "/(.*){$component['start']}(.*){$component['finish']}/";
|
||||
preg_match($string, $url, $matches);
|
||||
if ($matches && !empty($matches[2])) {
|
||||
$return[$key] = $matches[2];
|
||||
}
|
||||
}
|
||||
return $return;
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 142 KiB |
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Devel generate support for video_embed_field module.
|
||||
*/
|
||||
|
||||
// The Youtube’s API url.
|
||||
define('YT_API_URL', 'http://gdata.youtube.com/feeds/api/videos?q=');
|
||||
|
||||
/**
|
||||
* Devel generate plugin definition.
|
||||
*/
|
||||
function video_embed_field_devel_generate($object, $field, $instance, $bundle) {
|
||||
if (field_behaviors_widget('multiple values', $instance) == FIELD_BEHAVIOR_CUSTOM) {
|
||||
return devel_generate_multiple('_video_embed_field_devel_generate', $object, $field, $instance, $bundle);
|
||||
}
|
||||
else {
|
||||
return _video_embed_field_devel_generate($object, $field, $instance, $bundle);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a random video_embed_field item.
|
||||
*
|
||||
* @param object $object
|
||||
* The devel_generate object.
|
||||
* @param array $field
|
||||
* The field definition.
|
||||
* @param array $instance
|
||||
* The field instance definition.
|
||||
* @param array $bundle
|
||||
* The bundle definition.
|
||||
*
|
||||
* @return array
|
||||
* The video_embed_field item.
|
||||
*/
|
||||
function _video_embed_field_devel_generate($object, $field, $instance, $bundle) {
|
||||
$video = video_embed_field_retrieve_video();
|
||||
$object_field = array();
|
||||
$object_field['video_url'] = $video['video_url'];
|
||||
if ($instance['settings']['description_field']) {
|
||||
$object_field['description'] = $video['description'];
|
||||
}
|
||||
return $object_field;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves a random youtube video info from the bunch.
|
||||
*
|
||||
* @return array
|
||||
* The video definition.
|
||||
*/
|
||||
function video_embed_field_retrieve_video() {
|
||||
$videos = video_embed_field_generate_videos();
|
||||
return $videos[array_rand($videos)];
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a pseudo random bunch of youtube videos.
|
||||
*
|
||||
* @return array
|
||||
* A bunch of youtube videos.
|
||||
*/
|
||||
function video_embed_field_generate_videos() {
|
||||
$videos = &drupal_static(__FUNCTION__);
|
||||
if (!isset($videos)) {
|
||||
$videos = array();
|
||||
|
||||
// Create random video seed.
|
||||
$video_id = user_password(2);
|
||||
|
||||
// Using cURL php extension to make the request to youtube API.
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, YT_API_URL . $video_id);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
// $feed holds a rss feed xml returned by youtube API.
|
||||
$feed = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
|
||||
// Using SimpleXML to parse youtube’s feed.
|
||||
$xml = simplexml_load_string($feed);
|
||||
foreach ($xml->entry as $entry) {
|
||||
$videos[] = array(
|
||||
'video_url' => $entry->children('media', TRUE)->group->player->attributes()->url,
|
||||
'description' => $entry->title,
|
||||
);
|
||||
}
|
||||
if (empty($videos)) {
|
||||
video_embed_field_generate_videos();
|
||||
}
|
||||
}
|
||||
return $videos;
|
||||
}
|
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
* On behalf implementation of Feeds mapping API for video_embed_field.module.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_feeds_processor_targets_alter().
|
||||
*
|
||||
* @see FeedsNodeProcessor::getMappingTargets()
|
||||
*/
|
||||
function video_embed_field_feeds_processor_targets_alter(&$targets, $entity_type, $bundle_name) {
|
||||
foreach (field_info_instances($entity_type, $bundle_name) as $name => $instance) {
|
||||
$info = field_info_field($name);
|
||||
if ($info['type'] == 'video_embed_field') {
|
||||
$targets[$name . ":video_url"] = array(
|
||||
'name' => t('@name: Embed URL', array('@name' => $instance['label'])),
|
||||
'callback' => 'video_embed_field_set_target',
|
||||
'description' => t('The URL for the @label field of the @entity_type.', array('@entity_type' => $entity_type, '@label' => $instance['label'])),
|
||||
'real_target' => $name,
|
||||
);
|
||||
$targets[$name . ':description'] = array(
|
||||
'name' => t('@name: Embed description', array('@name' => $instance['label'])),
|
||||
'callback' => 'video_embed_field_set_target',
|
||||
'description' => t('The description for the @label field of the @entity_type.', array('@entity_type' => $entity_type, '@label' => $instance['label'])),
|
||||
'real_target' => $name,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for mapping. Here is where the actual mapping happens.
|
||||
*
|
||||
* When the callback is invoked, $target contains the name of the field the
|
||||
* user has decided to map to and $value contains the value of the feed item
|
||||
* element the user has picked as a source.
|
||||
*/
|
||||
function video_embed_field_set_target($source, $entity, $target, $value) {
|
||||
if (empty($value)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!is_array($value)) {
|
||||
$value = array($value);
|
||||
}
|
||||
|
||||
list($field_name, $sub_field) = explode(':', $target, 2);
|
||||
|
||||
$info = field_info_field($field_name);
|
||||
|
||||
// Iterate over all values.
|
||||
$field = isset($entity->$field_name) ? $entity->$field_name : array(LANGUAGE_NONE => array());
|
||||
|
||||
// Allow for multiple mappings to the same target.
|
||||
$count = call_user_func_array('array_merge_recursive', $field[LANGUAGE_NONE]);
|
||||
$delta = count($count[$sub_field]);
|
||||
|
||||
foreach ($value as $v) {
|
||||
|
||||
if ($info['cardinality'] != FIELD_CARDINALITY_UNLIMITED && $info['cardinality'] <= $delta) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (is_scalar($v)) {
|
||||
$field[LANGUAGE_NONE][$delta][$sub_field] = $v;
|
||||
|
||||
$delta++;
|
||||
}
|
||||
}
|
||||
|
||||
$entity->{$field_name} = $field;
|
||||
}
|
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Migrate support for Video Embed Field module.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_migrate_api().
|
||||
*/
|
||||
function video_embed_field_migrate_api() {
|
||||
$api = array(
|
||||
'api' => 2,
|
||||
'field handlers' => array('MigrateVideoEmbedFieldFieldHandler'),
|
||||
);
|
||||
return $api;
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom extended MigrateFieldHandler class for Video Embed Field module.
|
||||
*/
|
||||
class MigrateVideoEmbedFieldFieldHandler extends MigrateFieldHandler {
|
||||
|
||||
public function __construct() {
|
||||
$this->registerTypes(array('video_embed_field'));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function fields($type, $parent_field, $migration = NULL) {
|
||||
$fields = array(
|
||||
'video_url' => t('Video: The video URL.'),
|
||||
);
|
||||
return $fields;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function prepare($entity, array $field_info, array $instance, array $values) {
|
||||
$arguments = array();
|
||||
if (isset($values['arguments'])) {
|
||||
$arguments = array_filter($values['arguments']);
|
||||
unset($values['arguments']);
|
||||
}
|
||||
$language = $this->getFieldLanguage($entity, $field_info, $arguments);
|
||||
|
||||
// Setup the standard Field API array for saving.
|
||||
$delta = 0;
|
||||
foreach ($values as $value) {
|
||||
$return[$language][$delta] = array('video_url' => $value);
|
||||
$delta++;
|
||||
}
|
||||
|
||||
return isset($return) ? $return : NULL;
|
||||
}
|
||||
}
|
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Video embed field thumbnail_path column implementation.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Defines a field handler that can display the thumbnail_path url instead of
|
||||
* the drupal internal uri.
|
||||
*/
|
||||
class views_embed_field_views_handler_field_thumbnail_path extends views_handler_field {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
function get_value($values, $field = NULL) {
|
||||
$value = parent::get_value($values, $field);
|
||||
|
||||
return file_create_url($value);
|
||||
}
|
||||
}
|
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Hooks for Views integration.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_field_views_data().
|
||||
*/
|
||||
function video_embed_field_field_views_data($field) {
|
||||
$data = field_views_field_default_views_data($field);
|
||||
|
||||
// Only expose these components as Views field handlers.
|
||||
$implemented = array(
|
||||
'video_url' => 'views_handler_field',
|
||||
'thumbnail_path' => 'views_embed_field_views_handler_field_thumbnail_path',
|
||||
'description' => 'views_handler_field',
|
||||
);
|
||||
|
||||
// Get the translated field information.
|
||||
$properties = video_embed_field_data_property_info();
|
||||
|
||||
// Iterate over video_embed_field defined tables.
|
||||
foreach ($data as &$table) {
|
||||
// Make sure the parent Views field (video_embed_field) is defined.
|
||||
if (isset($table[$field['field_name']]['field'])) {
|
||||
// Use the parent field definition as a template for component columns.
|
||||
$field_def = $table[$field['field_name']]['field'];
|
||||
|
||||
// Remove 'additional fields' from the field definition. We don't
|
||||
// necessarily want all our sibling columns.
|
||||
unset($field_def['additional fields']);
|
||||
|
||||
// Define the valid columns.
|
||||
$valid_columns = array();
|
||||
foreach ($implemented as $implement => $handler) {
|
||||
$column_name = $field['field_name'] . '_' . $implement;
|
||||
$valid_columns[$column_name] = $handler;
|
||||
}
|
||||
|
||||
// Iterate over the video_embed_field components.
|
||||
foreach ($table as $column_name => &$column) {
|
||||
if (empty($column['field']) && isset($valid_columns[$column_name])) {
|
||||
// Assign the default component definition.
|
||||
$column['field'] = $field_def;
|
||||
$column['field']['real field'] = $column_name;
|
||||
$column['field']['handler'] = $valid_columns[$column_name];
|
||||
|
||||
// Assign human-friendly labels for video_embed_field components.
|
||||
$field_labels = field_views_field_label($field['field_name']);
|
||||
$field_label = array_shift($field_labels);
|
||||
$property = str_replace($field_def['field_name'] . '_', '', $column_name);
|
||||
|
||||
if (!empty($properties[$property])) {
|
||||
$property_label = $properties[$property]['label'];
|
||||
|
||||
$title = t('@field-label - @property-label', array(
|
||||
'@field-label' => $field_label,
|
||||
'@property-label' => $property_label,
|
||||
));
|
||||
|
||||
$column['title'] = $title;
|
||||
$column['title short'] = $title;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
Reference in New Issue
Block a user