first import

This commit is contained in:
Bachir Soussi Chiadmi
2015-04-08 11:40:19 +02:00
commit 1bc61b12ad
8435 changed files with 1582817 additions and 0 deletions

View File

@@ -0,0 +1,98 @@
<?php
/**
* Implementation of MediaInternetBaseHandler.
*
* @see hook_media_internet_providers().
*/
class MediaInternetVimeoHandler extends MediaInternetBaseHandler {
public function parse($embedCode) {
// Vimeo has a few URL formats:
// http://vimeo.com/*
// http://vimeo.com/video/*
// http://vimeo.com/groups/*/videos/*
// http://vimeo.com/channels/*#$ID
$patterns = array(
'@vimeo\.com/(\d+)@i',
'@vimeo\.com/video/(\d+)@i',
'@vimeo\.com/groups/.+/videos/(\d+)@i',
'@vimeo\.com/channels/.+#(\d+)@i',
);
foreach ($patterns as $pattern) {
preg_match($pattern, $embedCode, $matches);
if (isset($matches[1])) {
return file_stream_wrapper_uri_normalize('vimeo://v/' . $matches[1]);
}
}
}
public function claim($embedCode) {
if ($this->parse($embedCode)) {
return TRUE;
}
}
public function save() {
$file = $this->getFileObject();
file_save($file);
return $file;
}
public function getFileObject() {
$uri = $this->parse($this->embedCode);
//@todo: this is terribly broken in some ways because the function is really
// made for local files which are 'real'
$file = file_uri_to_object($uri, TRUE);
// Try to default the file name to the video's title.
if (empty($file->fid) && $info = $this->getOEmbed()) {
$file->filename = truncate_utf8($info['title'], 255);
}
return $file;
}
/**
* Returns information about the media.
*
* See http://video.search.yahoo.com/mrss
*
* @return
* If ATOM+MRSS information is available, a SimpleXML element containing
* ATOM and MRSS elements, as per those respective specifications.
*
* @todo Would be better for the return value to be an array rather than a
* SimpleXML element, but media_retrieve_xml() needs to be upgraded to
* handle namespaces first.
*/
public function getMRSS() {
$uri = $this->parse($this->embedCode);
$video_id = arg(1, file_uri_target($uri));
$rss_url = url('http://gdata.vimeo.com/feeds/api/videos/' . $video_id, array('query' => array('v' => '2')));
// @todo Use media_retrieve_xml() once it's upgraded to include elements
// from all namespaces, not just the document default namespace.
$entry = simplexml_load_file($rss_url);
return $entry;
}
/**
* Returns information about the media.
*
* See http://www.oembed.com/ and https://vimeo.com/api/docs/oembed
*
* @return
* If oEmbed information is available, an array containing 'title', 'type',
* 'url', and other information as specified by the oEmbed standard.
* Otherwise, NULL.
*/
public function getOEmbed() {
$uri = $this->parse($this->embedCode);
$external_url = drupal_realpath($uri);
$oembed_url = url('http://vimeo.com/api/oembed.json', array(
'query' => array('url' => $external_url))
);
$response = drupal_http_request($oembed_url);
if (!isset($response->error)) {
return drupal_json_decode($response->data);
}
}
}

View File

@@ -0,0 +1,53 @@
<?php
/**
* @file
* Create a Vimeo Stream Wrapper class for the Media/Resource module.
*/
/**
* Create an instance like this:
* $vimeo = new ResourceVimeoStreamWrapper('vimeo://v/[video-code]');
*/
class MediaVimeoStreamWrapper extends MediaReadOnlyStreamWrapper {
static function getMimeType($uri, $mapping = NULL) {
return 'video/vimeo';
}
/**
* Call the Vimeo Simple API and fetch the video information.
*
* See http://vimeo.com/api/docs/simple-api
*
* @return
* Array of properties.
*/
static function getVideoProperties($video_id) {
// The .php format returns a serialized array.
$response = drupal_http_request('http://vimeo.com/api/v2/video/'. $video_id .'.php');
return unserialize($response->data);
}
function getTarget($f) {
return FALSE;
}
function interpolateUrl() {
return 'http://vimeo.com/' . intval($this->parameters['v']);
}
function getOriginalThumbnailPath() {
$video_properties = self::getVideoProperties($this->parameters['v']);
return $video_properties[0]['thumbnail_large'];
}
function getLocalThumbnailPath() {
$local_path = 'public://media-vimeo/' . intval($this->parameters['v']) . '.jpg';
if (!file_exists($local_path)) {
$dirname = drupal_dirname($local_path);
file_prepare_directory($dirname, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);
@copy($this->getOriginalThumbnailPath(), $local_path);
}
return $local_path;
}
}

View File

@@ -0,0 +1,45 @@
<?php
/**
* @file
* Styles class implementation for Media: Vimeo.
*/
class MediaVimeoStyles extends FileStyles {
public $autoplay;
public $fullscreen;
function getAutoplay() {
return $this->get('autoplay');
}
function setAutoplay($value) {
return $this->set('autoplay', $value);
}
function getFullscreen() {
return $this->get('fullscreen');
}
function setFullscreen($value) {
return $this->set('fullscreen', $value);
}
function getImageUri() {
if ($image_uri = $this->get('imageUri')) {
return $image_uri;
}
$object = $this->getObject();
if ($object->uri) {
$wrapper = file_stream_wrapper_get_instance_by_uri($object->uri);
return $wrapper->getLocalThumbnailPath();
}
}
function video($effect) {
$variables = array(
'uri' => $this->getUri(),
'width' => $this->getWidth(),
'height' => $this->getHeight(),
'autoplay' => $this->getAutoplay(),
'fullscreen' => $this->getFullscreen(),
);
$this->setOutput(theme('media_vimeo_video', $variables));
}
}

View File

@@ -0,0 +1,167 @@
<?php
/**
* @file
*/
/**
* Implements hook_file_formatter_info().
*/
function media_vimeo_file_formatter_info() {
$formatters['media_vimeo_video'] = array(
'label' => t('Vimeo Video'),
'file types' => array('video'),
'default settings' => array(
'width' => media_vimeo_variable_get('width'),
'height' => media_vimeo_variable_get('height'),
'autoplay' => media_vimeo_variable_get('autoplay'),
),
'view callback' => 'media_vimeo_file_formatter_video_view',
'settings callback' => 'media_vimeo_file_formatter_video_settings',
);
$formatters['media_vimeo_image'] = array(
'label' => t('Vimeo Preview Image'),
'file types' => array('video'),
'default settings' => array(
'image_style' => '',
),
'view callback' => 'media_vimeo_file_formatter_image_view',
'settings callback' => 'media_vimeo_file_formatter_image_settings',
);
return $formatters;
}
/**
* Implements hook_file_formatter_FORMATTER_view().
*/
function media_vimeo_file_formatter_video_view($file, $display, $langcode) {
$scheme = file_uri_scheme($file->uri);
// WYSIWYG does not yet support video inside a running editor instance.
if ($scheme == 'vimeo' && empty($file->override['wysiwyg'])) {
$element = array(
'#theme' => 'media_vimeo_video',
'#uri' => $file->uri,
);
foreach (array('width', 'height', 'autoplay') as $setting) {
$element['#' . $setting] = isset($file->override[$setting]) ? $file->override[$setting] : $display['settings'][$setting];
}
return $element;
}
}
/**
* Implements hook_file_formatter_FORMATTER_settings().
*/
function media_vimeo_file_formatter_video_settings($form, &$form_state, $settings) {
$element = array();
$element['width'] = array(
'#title' => t('Width'),
'#type' => 'textfield',
'#default_value' => $settings['width'],
);
$element['height'] = array(
'#title' => t('Height'),
'#type' => 'textfield',
'#default_value' => $settings['height'],
);
$element['autoplay'] = array(
'#title' => t('Autoplay'),
'#type' => 'checkbox',
'#default_value' => $settings['autoplay'],
);
return $element;
}
/**
* Implements hook_file_formatter_FORMATTER_view().
*/
function media_vimeo_file_formatter_image_view($file, $display, $langcode) {
$scheme = file_uri_scheme($file->uri);
if ($scheme == 'vimeo') {
$wrapper = file_stream_wrapper_get_instance_by_uri($file->uri);
$image_style = $display['settings']['image_style'];
$valid_image_styles = image_style_options(FALSE);
if (empty($image_style) || !isset($valid_image_styles[$image_style])) {
$element = array(
'#theme' => 'image',
'#path' => $wrapper->getOriginalThumbnailPath(),
);
}
else {
$element = array(
'#theme' => 'image_style',
'#style_name' => $image_style,
'#path' => $wrapper->getLocalThumbnailPath(),
);
}
return $element;
}
}
/**
* Implements hook_file_formatter_FORMATTER_settings().
*/
function media_vimeo_file_formatter_image_settings($form, &$form_state, $settings) {
$element = array();
$element['image_style'] = array(
'#title' => t('Image style'),
'#type' => 'select',
'#options' => image_style_options(FALSE),
'#default_value' => $settings['image_style'],
'#empty_option' => t('None (original image)'),
);
return $element;
}
/**
* Implements hook_file_default_displays().
*/
function media_vimeo_file_default_displays() {
$default_displays = array();
// Default settings for displaying as a video.
$default_video_settings = array(
'media_large' => array(
'width' => 480,
'height' => 360,
'autoplay' => FALSE,
),
'media_original' => array(
'width' => 640,
'height' => 480,
'autoplay' => media_vimeo_variable_get('autoplay'),
),
);
foreach ($default_video_settings as $view_mode => $settings) {
$display_name = 'video__' . $view_mode . '__media_vimeo_video';
$default_displays[$display_name] = (object) array(
'api_version' => 1,
'name' => $display_name,
'status' => 1,
'weight' => 1,
'settings' => $settings,
);
}
// Default settings for displaying a video preview image. We enable preview
// images even for view modes that also play video, for use inside a running
// WYSIWYG editor. The higher weight ensures that the video display is used
// where possible.
$default_image_styles = array(
'media_preview' => 'square_thumbnail',
'media_large' => 'large',
'media_original' => ''
);
foreach ($default_image_styles as $view_mode => $image_style) {
$display_name = 'video__' . $view_mode . '__media_vimeo_image';
$default_displays[$display_name] = (object) array(
'api_version' => 1,
'name' => $display_name,
'status' => 1,
'weight' => 2,
'settings' => array('image_style' => $image_style),
);
}
return $default_displays;
}

View File

@@ -0,0 +1,265 @@
<?php
/**
* @file media_vimeo/includes/media_vimeo.styles.inc
* Styles definitions for Media: Vimeo.
*/
/**
* Implementation of Styles module hook_styles_register().
*/
function media_vimeo_styles_register() {
return array(
'MediaVimeoStyles' => array(
'field_types' => 'file',
'name' => t('MediaVimeo'),
'description' => t('Media Vimeo styles.'),
'path' => drupal_get_path('module', 'media_vimeo') .'/includes',
'file' => 'media_vimeo.styles.inc',
),
);
}
/**
* Implements hook_styles_containers(). (Deprecated in version 2)
*/
function media_vimeo_styles_containers() {
return array(
'file' => array(
'containers' => array(
'media_vimeo' => array(
'label' => t('Vimeo Styles'),
'data' => array(
'streams' => array(
'vimeo',
),
'mimetypes' => array(
'video/vimeo',
),
),
'weight' => 0,
'filter callback' => 'media_vimeo_formatter_filter',
'themes' => array(
'field_formatter_styles' => 'media_vimeo_field_formatter_styles',
'styles' => 'media_vimeo_styles',
'preview' => 'media_vimeo_preview_style',
),
'description' => t('Vimeo Styles will display embedded Vimeo videos and thumbnails to your choosing, such as by resizing, setting colors, and autoplay. You can !manage.', array('!manage' => l(t('manage your Vimeo styles here'), 'admin/config/media/media-vimeo-styles'))),
),
),
),
);
}
function media_vimeo_formatter_filter($variables) {
if (isset($variables['object'])) {
$object = isset($variables['object']->file) ? $variables['object']->file : $variables['object'];
return (file_uri_scheme($object->uri) == 'vimeo') && ($object->filemime == 'video/vimeo');
}
}
/**
* Implementation of the File Styles module's hook_file_styles_filter().
*/
function media_vimeo_file_styles_filter($object) {
$file = isset($object->file) ? $object->file : $object;
if ((file_uri_scheme($file->uri) == 'vimeo') && ($file->filemime == 'video/vimeo')) {
return 'media_vimeo';
}
}
/**
* Implements hook_styles_styles().
*/
function media_vimeo_styles_styles() {
$styles = array(
'file' => array(
'containers' => array(
'media_vimeo' => array(
'styles' => array(
'vimeo_thumbnail' => array(
'name' => 'vimeo_thumbnail',
'effects' => array(
array('label' => t('Thumbnail'), 'name' => 'thumbnail', 'data' => array('thumbnail' => 1)),
array('label' => t('Resize'), 'name' => 'resize', 'data' => array('width' => 100, 'height' => 75)),
),
),
'vimeo_preview' => array(
'name' => 'vimeo_preview',
'effects' => array(
array('label' => t('Autoplay'), 'name' => 'autoplay', 'data' => array('autoplay' => 0)),
array('label' => t('Resize'), 'name' => 'resize', 'data' => array('width' => 220, 'height' => 165)),
),
),
'vimeo_full' => array(
'name' => 'vimeo_full',
'effects' => array(
array('label' => t('Autoplay'), 'name' => 'autoplay', 'data' => array('autoplay' => 0)),
array('label' => t('Resize'), 'name' => 'resize', 'data' => array('width' => 640, 'height' => 480)),
array('label' => t('Full screen'), 'name' => 'fullscreen', 'data' => array('fullscreen' => 1)),
),
),
),
),
),
),
);
// Allow any image style to be applied to the thumbnail.
foreach (image_styles() as $style_name => $image_style) {
$styles['file']['containers']['media_vimeo']['styles']['vimeo_thumbnail_' . $style_name] = array(
'name' => 'vimeo_thumbnail_' . $style_name,
'image_style' => $style_name,
'effects' => array(
array('label' => t('Thumbnail'), 'name' => 'thumbnail', 'data' => array('thumbnail' => 1)),
),
);
}
return $styles;
}
/**
* Implements hook_styles_presets().
*/
function media_vimeo_styles_presets() {
$presets = array(
'file' => array(
'square_thumbnail' => array(
'media_vimeo' => array(
'vimeo_thumbnail_square_thumbnail',
),
),
'thumbnail' => array(
'media_vimeo' => array(
'vimeo_thumbnail',
),
),
'small' => array(
'media_vimeo' => array(
'vimeo_preview',
),
),
'large' => array(
'media_vimeo' => array(
'vimeo_full',
),
),
'original' => array(
'media_vimeo' => array(
'vimeo_full',
),
),
),
);
return $presets;
}
/**
* Implementation of Styles module hook_styles_default_containers().
*/
function media_vimeo_styles_default_containers() {
// We append Vimeo to the file containers.
return array(
'file' => array(
'containers' => array(
'media_vimeo' => array(
'class' => 'MediaVimeoStyles',
'name' => 'media_vimeo',
'label' => t('Vimeo'),
'preview' => 'media_vimeo_preview_style',
),
),
),
);
}
/**
* Implementation of Styles module hook_styles_default_presets().
*/
function media_vimeo_styles_default_presets() {
$presets = array(
'file' => array(
'containers' => array(
'media_vimeo' => array(
'default preset' => 'unlinked_thumbnail',
'styles' => array(
'original' => array(
'default preset' => 'video',
),
'thumbnail' => array(
'default preset' => 'linked_thumbnail',
),
'square_thumbnail' => array(
'default preset' => 'linked_square_thumbnail',
),
'medium' => array(
'default preset' => 'linked_medium',
),
'large' => array(
'default preset' => 'large_video',
),
),
'presets' => array(
'video' => array(
array(
'name' => 'video',
'settings' => array(),
),
),
'large_video' => array(
array(
'name' => 'resize',
'settings' => array(
'width' => 640,
'height' => 390,
),
),
array(
'name' => 'video',
'settings' => array(),
),
),
),
),
),
),
);
// Allow any image style to be applied to the thumbnail.
foreach (image_styles() as $style_name => $image_style) {
$presets['file']['containers']['media_vimeo']['presets']['linked_' . $style_name] = array(
array(
'name' => 'linkToMedia',
'settings' => array(),
),
array(
'name' => 'imageStyle',
'settings' => array(
'image_style' => $style_name,
),
),
array(
'name' => 'thumbnail',
'settings' => array(),
),
);
$presets['file']['containers']['media_vimeo']['presets']['unlinked_' . $style_name] = $presets['file']['containers']['media_vimeo']['presets']['linked_' . $style_name];
array_shift($presets['file']['containers']['media_vimeo']['presets']['unlinked_' . $style_name]);
foreach ($image_style['effects'] as $effect) {
if (in_array($effect['name'], array('image_scale', 'image_scale_and_crop', 'image_resize', 'image_crop'))) {
$presets['file']['containers']['media_vimeo']['presets']['video_' . $style_name] = array(
array(
'name' => 'resize',
'settings' => $effect['data'],
),
array(
'name' => 'video',
'settings' => array(),
),
);
}
}
}
return $presets;
}

View File

@@ -0,0 +1,132 @@
<?php
/**
* @file media_vimeo/includes/media_vimeo.variables.inc
* Variable defaults for Media: Vimeo.
*/
/**
* Define our constants.
*/
/**
* This is the variable namespace, automatically prepended to module variables.
*/
define('MEDIA_VIMEO_NAMESPACE', 'media_vimeo__');
/**
* Wrapper for variable_get() using the Media: Vimeo variable registry.
*
* @param string $name
* The variable name to retrieve. Note that it will be namespaced by
* pre-pending MEDIA_VIMEO_NAMESPACE, as to avoid variable collisions
* with other modules.
* @param unknown $default
* An optional default variable to return if the variable hasn't been set
* yet. Note that within this module, all variables should already be set
* in the media_vimeo_variable_default() function.
* @return unknown
* Returns the stored variable or its default.
*
* @see media_vimeo_variable_set()
* @see media_vimeo_variable_del()
* @see media_vimeo_variable_default()
*/
function media_vimeo_variable_get($name, $default = NULL) {
// Allow for an override of the default.
// Useful when a variable is required (like $path), but namespacing is still
// desired.
if (!isset($default)) {
$default = media_vimeo_variable_default($name);
}
// Namespace all variables.
$variable_name = MEDIA_VIMEO_NAMESPACE . $name;
return variable_get($variable_name, $default);
}
/**
* Wrapper for variable_set() using the Media: Vimeo variable registry.
*
* @param string $name
* The variable name to set. Note that it will be namespaced by
* pre-pending MEDIA_VIMEO_NAMESPACE, as to avoid variable collisions with
* other modules.
* @param unknown $value
* The value for which to set the variable.
* @return unknown
* Returns the stored variable after setting.
*
* @see media_vimeo_variable_get()
* @see media_vimeo_variable_del()
* @see media_vimeo_variable_default()
*/
function media_vimeo_variable_set($name, $value) {
$variable_name = MEDIA_VIMEO_NAMESPACE . $name;
return variable_set($variable_name, $value);
}
/**
* Wrapper for variable_del() using the Media: Vimeo variable registry.
*
* @param string $name
* The variable name to delete. Note that it will be namespaced by
* pre-pending MEDIA_VIMEO_NAMESPACE, as to avoid variable collisions with
* other modules.
*
* @see media_vimeo_variable_get()
* @see media_vimeo_variable_set()
* @see media_vimeo_variable_default()
*/
function media_vimeo_variable_del($name) {
$variable_name = MEDIA_VIMEO_NAMESPACE . $name;
variable_del($variable_name);
}
/**
* The default variables within the Media: Vimeo namespace.
*
* @param string $name
* Optional variable name to retrieve the default. Note that it has not yet
* been pre-pended with the MEDIA_VIMEO_NAMESPACE namespace at this time.
* @return unknown
* The default value of this variable, if it's been set, or NULL, unless
* $name is NULL, in which case we return an array of all default values.
*
* @see media_vimeo_variable_get()
* @see media_vimeo_variable_set()
* @see media_vimeo_variable_del()
*/
function media_vimeo_variable_default($name = NULL) {
static $defaults;
if (!isset($defaults)) {
$defaults = array(
'width' => 560,
'height' =>340,
'autoplay' => FALSE,
'fullscreen' => TRUE,
'preview_uri' => 'vimeo://v/21869117',
);
}
if (!isset($name)) {
return $defaults;
}
if (isset($defaults[$name])) {
return $defaults[$name];
}
}
/**
* Return the fully namespace variable name.
*
* @param string $name
* The variable name to retrieve the namespaced name.
* @return string
* The fully namespace variable name, prepended with
* MEDIA_VIMEO_NAMESPACE.
*/
function media_vimeo_variable_name($name) {
return MEDIA_VIMEO_NAMESPACE . $name;
}

View File

@@ -0,0 +1,24 @@
<?php
/**
* @file media_vimeo/includes/themes/media-vimeo-video.tpl.php
*
* Template file for theme('media_vimeo_video').
*
* Variables available:
* $uri - The uri to the Vimeo video, such as vimeo://v/xsy7x8c9.
* $video_id - The unique identifier of the Vimeo video.
* $width - The width to render.
* $height - The height to render.
* $autoplay - If TRUE, then start the player automatically when displaying.
* $fullscreen - Whether to allow fullscreen playback.
*
* Note that we set the width & height of the outer wrapper manually so that
* the JS will respect that when resizing later.
*/
?>
<div class="media-vimeo-outer-wrapper" id="media-vimeo-<?php print $id; ?>" style="width: <?php print $width; ?>px; height: <?php print $height; ?>px;">
<div class="media-vimeo-preview-wrapper" id="<?php print $wrapper_id; ?>">
<?php print $output; ?>
</div>
</div>

View File

@@ -0,0 +1,179 @@
<?php
/**
* @file media_vimeo/includes/themes/media_vimeo.theme.inc
*
* Theme and preprocess functions for Media: Vimeo.
*/
/**
* Preprocess function for theme('media_vimeo_video').
*/
function media_vimeo_preprocess_media_vimeo_video(&$variables) {
// Build the URL for display.
$uri = $variables['uri'];
$wrapper = file_stream_wrapper_get_instance_by_uri($uri);
$parts = $wrapper->get_parameters();
$variables['video_id'] = check_plain($parts['v']);
$variables['width'] = isset($variables['width']) ? $variables['width'] : media_vimeo_variable_get('width');
$variables['height'] = isset($variables['height']) ? $variables['height'] : media_vimeo_variable_get('height');
$variables['autoplay'] = isset($variables['autoplay']) ? $variables['autoplay'] : media_vimeo_variable_get('autoplay');
$variables['fullscreen'] = isset($variables['fullscreen']) ? $variables['fullscreen'] : media_vimeo_variable_get('fullscreen');
$variables['autoplay'] = $variables['autoplay'] ? 1 : 0;
$variables['fullscreen'] = $variables['fullscreen'] ? 'true' : 'false';
$variables['wrapper_id'] = 'media_vimeo_' . $variables['video_id'] . '_' . $variables['id'];
// For users with JavaScript, these object and embed tags will be replaced
// by an iframe, so that we can support users without Flash.
$variables['output'] = <<<OUTPUT
<object width="{$variables['width']}" height="{$variables['height']}">
<param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id={$variables['video_id']}">
<param name="allowFullScreen" value="{$variables['fullscreen']}"></param>
<param name="wmode" value="transparent" />
<embed src="http://vimeo.com/moogaloop.swf?clip_id={$variables['video_id']}" type="application/x-shockwave-flash" width="{$variables['width']}" height="{$variables['height']}" allowfullscreen="{$variables['fullscreen']}"></embed>
</object>
OUTPUT;
// Pass the settings to replace the object tag with an iframe.
$settings = array(
'media_vimeo' => array(
$variables['wrapper_id'] => array(
'width' => $variables['width'],
'height' => $variables['height'],
'video_id' => $variables['video_id'],
'fullscreen' => $variables['fullscreen'],
'id' => $variables['wrapper_id'] .'_iframe',
),
),
);
if ($variables['autoplay']) {
$settings['media_vimeo'][$variables['wrapper_id']]['options'] = array(
'autoplay' => $variables['autoplay'],
);
}
drupal_add_js($settings, 'setting');
drupal_add_js(drupal_get_path('module', 'media_vimeo') . '/js/media_vimeo.js');
drupal_add_css(drupal_get_path('module', 'media_vimeo') . '/css/media_vimeo.css');
drupal_add_js(drupal_get_path('module', 'media_vimeo') . '/js/flash_detect_min.js');
}
function theme_media_vimeo_field_formatter_styles($variables) {
$element = $variables['element'];
$style = $variables['style'];
$variables['file'] = $element['#item'];
$variables['uri'] = $variables['file']['uri'];
$variables['style_name'] = $style['name'];
return theme('media_vimeo_embed', $variables);
}
/**
* Preview for Styles UI.
*/
function theme_media_vimeo_preview_style($variables) {
$variables['uri'] = media_vimeo_variable_get('preview_uri');
$variables['field_type'] = 'file';
$variables['object'] = file_uri_to_object($variables['uri']);
return theme('styles', $variables);
}
/**
* NOTE: Deprecated with Styles version 2.
*/
function theme_media_vimeo_styles($variables) {
$style = $variables['style'];
$variables['file'] = $variables['object'];
$variables['uri'] = $variables['object']->uri;
$variables['style_name'] = $style['name'];
return theme('media_vimeo_embed', $variables);
}
/**
* @todo: get this working
*
* This code is for embedding videos in WYSIYWG areas, not currently working.
* NOTE: Deprecated with Styles version 2.
*/
function theme_media_vimeo_embed($variables) {
$preset_name = $variables['preset_name'];
$preset = styles_containers_available_styles('file', 'media_vimeo', $preset_name);
$output = '';
if (!empty($preset)) {
// Build the URL for display.
$uri = $variables['uri'];
$wrapper = file_stream_wrapper_get_instance_by_uri($uri);
$parts = $wrapper->get_parameters();
$fullscreen_value = $autoplay = 'false';
$in_browser = $thumbnail = FALSE;
foreach ($preset['effects'] as $effect) {
switch ($effect['name']) {
case 'autoplay':
$autoplay = $effect['data']['autoplay'] ? 'true' : 'false';
break;
case 'resize':
$width = $effect['data']['width'];
$height = $effect['data']['height'];
break;
case 'fullscreen':
$fullscreen_value = $effect['data']['fullscreen'] ? 'true' : 'false';
break;
case 'thumbnail':
$thumbnail = $effect['data']['thumbnail'];
}
}
if (isset($variables['object']->override)) {
$override = $variables['object']->override;
if (isset($override['width'])) {
$width = $override['width'];
}
if (isset($override['height'])) {
$height = $override['height'];
}
if (isset($override['wysiwyg'])) {
$thumbnail = TRUE;
}
if (isset($override['browser']) && $override['browser']) {
$in_browser = TRUE;
$thumbnail = TRUE;
}
}
$width = isset($width) ? $width : media_vimeo_variable_get('width');
$height = isset($height) ? $height : media_vimeo_variable_get('height');
$video_id = check_plain($parts['v']);
if ($thumbnail) {
// @todo Clean this up.
$image_variables = array(
'path' => $wrapper->getOriginalThumbnailPath(),
'alt' => $variables['alt'],
'title' => $variables['title'],
'getsize' => FALSE,
);
if (isset($preset['image_style'])) {
$image_variables['path'] = $wrapper->getLocalThumbnailPath();
$image_variables['style_name'] = $preset['image_style'];
$output = theme('image_style', $image_variables);
}
else {
// We need to add this style attribute here so that it doesn't get lost
// If you resize a video in a node, save it, edit it, but don't adjust
// the sizing of the video while editing, the size will revert to the
// default. Adding the specific size here retains the original resizing
$WYSIWYG = isset($variables['object']->override['style']) ? $variables['object']->override['style'] : '';
$image_variables['attributes'] = array('width' => $width, 'height' => $height, 'style' => $WYSIWYG);
$output = theme('image', $image_variables);
}
if ($in_browser) {
// Add an overlay that says 'Vimeo' to media library browser thumbnails.
$output .= '<span />';
}
}
else {
$output = theme('media_vimeo_video', array('uri' => $uri, 'width' => $width, 'height' => $height, 'autoplay' => ($autoplay == 'true' ? TRUE : NULL), 'fullscreen' => ($fullscreen_value == 'true' ? TRUE : NULL)));
}
}
return $output;
}