first import
This commit is contained in:
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Implementation of MediaInternetBaseHandler.
|
||||
*
|
||||
* @see hook_media_internet_providers().
|
||||
*/
|
||||
class MediaInternetYouTubeHandler extends MediaInternetBaseHandler {
|
||||
public function parse($embedCode) {
|
||||
$patterns = array(
|
||||
'@youtube\.com/watch[#\?].*?v=([^"\& ]+)@i',
|
||||
'@youtube\.com/embed/([^"\&\? ]+)@i',
|
||||
'@youtube\.com/v/([^"\&\? ]+)@i',
|
||||
'@youtube\.com/\?v=([^"\& ]+)@i',
|
||||
'@youtu.be/([^"\&\? ]+)@i',
|
||||
);
|
||||
foreach ($patterns as $pattern) {
|
||||
preg_match($pattern, $embedCode, $matches);
|
||||
if (isset($matches[1]) && $this->valid_id($matches[1])) {
|
||||
return file_stream_wrapper_uri_normalize('youtube://v/' . $matches[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function valid_id($id) {
|
||||
$url = 'http://gdata.youtube.com/feeds/api/videos/'. $id;
|
||||
$response = drupal_http_request($url, array('method' => 'HEAD'));
|
||||
if ($response->code != 200) {
|
||||
throw new MediaInternetValidationException(t('The YouTube video ID is invalid or the video was deleted.'));
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
public function claim($embedCode) {
|
||||
if ($this->parse($embedCode)) {
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
public function getFileObject() {
|
||||
$uri = $this->parse($this->embedCode);
|
||||
$file = file_uri_to_object($uri, TRUE);
|
||||
|
||||
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.youtube.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/.
|
||||
*
|
||||
* @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://www.youtube.com/oembed', array('query' => array('url' => $external_url, 'format' => 'json')));
|
||||
$response = drupal_http_request($oembed_url);
|
||||
if (!isset($response->error)) {
|
||||
return drupal_json_decode($response->data);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Create a YouTube Stream Wrapper class for the Media/Resource module.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Create an instance like this:
|
||||
* $youtube = new ResourceYouTubeStreamWrapper('youtube://?v=[video-code]');
|
||||
*/
|
||||
class MediaYouTubeStreamWrapper extends MediaReadOnlyStreamWrapper {
|
||||
protected $base_url = 'http://youtube.com/watch';
|
||||
|
||||
function getTarget($f) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static function getMimeType($uri, $mapping = NULL) {
|
||||
return 'video/youtube';
|
||||
}
|
||||
|
||||
function getOriginalThumbnailPath() {
|
||||
$parts = $this->get_parameters();
|
||||
return 'http://img.youtube.com/vi/'. check_plain($parts['v']) .'/0.jpg';
|
||||
}
|
||||
|
||||
function getLocalThumbnailPath() {
|
||||
$parts = $this->get_parameters();
|
||||
$local_path = 'public://media-youtube/' . check_plain($parts['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;
|
||||
}
|
||||
}
|
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Styles class implementation for Media: YouTube.
|
||||
*/
|
||||
|
||||
class MediaYouTubeStyles 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_youtube_video', $variables));
|
||||
}
|
||||
}
|
@@ -0,0 +1,223 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_file_formatter_info().
|
||||
*/
|
||||
function media_youtube_file_formatter_info() {
|
||||
$formatters['media_youtube_video'] = array(
|
||||
'label' => t('YouTube Video'),
|
||||
'file types' => array('video'),
|
||||
'default settings' => array(),
|
||||
'view callback' => 'media_youtube_file_formatter_video_view',
|
||||
'settings callback' => 'media_youtube_file_formatter_video_settings',
|
||||
);
|
||||
foreach (array('width', 'height', 'autoplay', 'related', 'hd', 'showsearch', 'modestbranding', 'showinfo', 'version', 'theme', 'fullscreen', 'wmode', 'chromeless') as $setting) {
|
||||
$formatters['media_youtube_video']['default settings'][$setting] = media_youtube_variable_get($setting);
|
||||
}
|
||||
$formatters['media_youtube_image'] = array(
|
||||
'label' => t('YouTube Preview Image'),
|
||||
'file types' => array('video'),
|
||||
'default settings' => array(
|
||||
'image_style' => '',
|
||||
),
|
||||
'view callback' => 'media_youtube_file_formatter_image_view',
|
||||
'settings callback' => 'media_youtube_file_formatter_image_settings',
|
||||
);
|
||||
return $formatters;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_file_formatter_FORMATTER_view().
|
||||
*/
|
||||
function media_youtube_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 == 'youtube' && empty($file->override['wysiwyg'])) {
|
||||
$element = array(
|
||||
'#theme' => 'media_youtube_video',
|
||||
'#uri' => $file->uri,
|
||||
'#options' => array(),
|
||||
);
|
||||
foreach (array('width', 'height', 'autoplay', 'related', 'hd', 'showsearch', 'modestbranding', 'showinfo', 'version', 'theme', 'fullscreen', 'wmode', 'chromeless') as $setting) {
|
||||
$element['#options'][$setting] = isset($file->override[$setting]) ? $file->override[$setting] : $display['settings'][$setting];
|
||||
}
|
||||
return $element;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_file_formatter_FORMATTER_settings().
|
||||
*/
|
||||
function media_youtube_file_formatter_video_settings($form, &$form_state, $settings) {
|
||||
$element = array();
|
||||
$options = array(
|
||||
0 => t('AS2'),
|
||||
3 => t('AS3'),
|
||||
);
|
||||
$element['version'] = array(
|
||||
'#title' => t('YouTube player version'),
|
||||
'#type' => 'select',
|
||||
'#options' => $options,
|
||||
'#default_value' => $settings['version'],
|
||||
);
|
||||
$options = array(
|
||||
'dark' => t('dark'),
|
||||
'light' => t('light'),
|
||||
);
|
||||
$element['theme'] = array(
|
||||
'#title' => t('YouTube player theme'),
|
||||
'#type' => 'select',
|
||||
'#options' => $options,
|
||||
'#default_value' => $settings['theme'],
|
||||
);
|
||||
|
||||
$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['fullscreen'] = array(
|
||||
'#title' => t('Allow the video to be played in full screen mode'),
|
||||
'#type' => 'checkbox',
|
||||
'#default_value' => $settings['fullscreen'],
|
||||
);
|
||||
$element['autoplay'] = array(
|
||||
'#title' => t('Autoplay'),
|
||||
'#type' => 'checkbox',
|
||||
'#default_value' => $settings['autoplay'],
|
||||
);
|
||||
$element['related'] = array(
|
||||
'#title' => t('Show suggested videos when the video finishes'),
|
||||
'#type' => 'checkbox',
|
||||
'#default_value' => $settings['related'],
|
||||
);
|
||||
$element['hd'] = array(
|
||||
'#title' => t('Display the high quality version of the video when available'),
|
||||
'#type' => 'checkbox',
|
||||
'#default_value' => $settings['hd'],
|
||||
);
|
||||
$element['showsearch'] = array(
|
||||
'#title' => t('Allow users to search from the video'),
|
||||
'#type' => 'checkbox',
|
||||
'#default_value' => $settings['showsearch'],
|
||||
);
|
||||
$element['modestbranding'] = array(
|
||||
'#title' => t('Use modest YouTube branding (requires AS3 version player)'),
|
||||
'#type' => 'checkbox',
|
||||
'#default_value' => $settings['modestbranding'],
|
||||
);
|
||||
$element['showinfo'] = array(
|
||||
'#title' => t('Display video title'),
|
||||
'#type' => 'checkbox',
|
||||
'#default_value' => $settings['showinfo'],
|
||||
);
|
||||
$element['chromeless'] = array(
|
||||
'#title' => t('Use chromeless player'),
|
||||
'#type' => 'checkbox',
|
||||
'#default_value' => $settings['chromeless'],
|
||||
);
|
||||
return $element;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_file_formatter_FORMATTER_view().
|
||||
*/
|
||||
function media_youtube_file_formatter_image_view($file, $display, $langcode) {
|
||||
$scheme = file_uri_scheme($file->uri);
|
||||
if ($scheme == 'youtube') {
|
||||
$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_youtube_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_youtube_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_youtube_variable_get('autoplay'),
|
||||
),
|
||||
);
|
||||
foreach ($default_video_settings as $view_mode => $settings) {
|
||||
$display_name = 'video__' . $view_mode . '__media_youtube_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_youtube_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;
|
||||
}
|
@@ -0,0 +1,265 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file media_youtube/includes/media_youtube.styles.inc
|
||||
* Styles definitions for Media: YouTube.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implementation of Styles module hook_styles_register().
|
||||
*/
|
||||
function media_youtube_styles_register() {
|
||||
return array(
|
||||
'MediaYouTubeStyles' => array(
|
||||
'field_types' => 'file',
|
||||
'name' => t('MediaYouTube'),
|
||||
'description' => t('Media YouTube styles.'),
|
||||
'path' => drupal_get_path('module', 'media_youtube') .'/includes',
|
||||
'file' => 'media_youtube.styles.inc',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_styles_containers(). (Deprecated in version 2)
|
||||
*/
|
||||
function media_youtube_styles_containers() {
|
||||
return array(
|
||||
'file' => array(
|
||||
'containers' => array(
|
||||
'media_youtube' => array(
|
||||
'label' => t('YouTube Styles'),
|
||||
'data' => array(
|
||||
'streams' => array(
|
||||
'youtube',
|
||||
),
|
||||
'mimetypes' => array(
|
||||
'video/youtube',
|
||||
),
|
||||
),
|
||||
'weight' => 0,
|
||||
'filter callback' => 'media_youtube_formatter_filter',
|
||||
'themes' => array(
|
||||
'field_formatter_styles' => 'media_youtube_field_formatter_styles',
|
||||
'styles' => 'media_youtube_styles',
|
||||
'preview' => 'media_youtube_preview_style',
|
||||
),
|
||||
'description' => t('YouTube Styles will display embedded YouTube videos and thumbnails to your choosing, such as by resizing, setting colors, and autoplay. You can !manage.', array('!manage' => l(t('manage your YouTube styles here'), 'admin/config/media/media-youtube-styles'))),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
function media_youtube_formatter_filter($variables) {
|
||||
if (isset($variables['object'])) {
|
||||
$object = isset($variables['object']->file) ? $variables['object']->file : $variables['object'];
|
||||
return (file_uri_scheme($object->uri) == 'youtube') && ($object->filemime == 'video/youtube');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of the File Styles module's hook_file_styles_filter().
|
||||
*/
|
||||
function media_youtube_file_styles_filter($object) {
|
||||
$file = isset($object->file) ? $object->file : $object;
|
||||
if ((file_uri_scheme($file->uri) == 'youtube') && ($file->filemime == 'video/youtube')) {
|
||||
return 'media_youtube';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_styles_styles().
|
||||
*/
|
||||
function media_youtube_styles_styles() {
|
||||
$styles = array(
|
||||
'file' => array(
|
||||
'containers' => array(
|
||||
'media_youtube' => array(
|
||||
'styles' => array(
|
||||
'youtube_thumbnail' => array(
|
||||
'name' => 'youtube_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)),
|
||||
),
|
||||
),
|
||||
'youtube_preview' => array(
|
||||
'name' => 'youtube_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)),
|
||||
),
|
||||
),
|
||||
'youtube_full' => array(
|
||||
'name' => 'youtube_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_youtube']['styles']['youtube_thumbnail_' . $style_name] = array(
|
||||
'name' => 'youtube_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_youtube_styles_presets() {
|
||||
$presets = array(
|
||||
'file' => array(
|
||||
'square_thumbnail' => array(
|
||||
'media_youtube' => array(
|
||||
'youtube_thumbnail_square_thumbnail',
|
||||
),
|
||||
),
|
||||
'thumbnail' => array(
|
||||
'media_youtube' => array(
|
||||
'youtube_thumbnail',
|
||||
),
|
||||
),
|
||||
'small' => array(
|
||||
'media_youtube' => array(
|
||||
'youtube_preview',
|
||||
),
|
||||
),
|
||||
'large' => array(
|
||||
'media_youtube' => array(
|
||||
'youtube_full',
|
||||
),
|
||||
),
|
||||
'original' => array(
|
||||
'media_youtube' => array(
|
||||
'youtube_full',
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
return $presets;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of Styles module hook_styles_default_containers().
|
||||
*/
|
||||
function media_youtube_styles_default_containers() {
|
||||
// We append YouTube to the file containers.
|
||||
return array(
|
||||
'file' => array(
|
||||
'containers' => array(
|
||||
'media_youtube' => array(
|
||||
'class' => 'MediaYouTubeStyles',
|
||||
'name' => 'media_youtube',
|
||||
'label' => t('YouTube'),
|
||||
'preview' => 'media_youtube_preview_style',
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Implementation of Styles module hook_styles_default_presets().
|
||||
*/
|
||||
function media_youtube_styles_default_presets() {
|
||||
$presets = array(
|
||||
'file' => array(
|
||||
'containers' => array(
|
||||
'media_youtube' => 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_youtube']['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_youtube']['presets']['unlinked_' . $style_name] = $presets['file']['containers']['media_youtube']['presets']['linked_' . $style_name];
|
||||
array_shift($presets['file']['containers']['media_youtube']['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_youtube']['presets']['video_' . $style_name] = array(
|
||||
array(
|
||||
'name' => 'resize',
|
||||
'settings' => $effect['data'],
|
||||
),
|
||||
array(
|
||||
'name' => 'video',
|
||||
'settings' => array(),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $presets;
|
||||
}
|
@@ -0,0 +1,141 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file media_youtube/includes/media_youtube.variables.inc
|
||||
* Variable defaults for Media: YouTube.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Define our constants.
|
||||
*/
|
||||
|
||||
/**
|
||||
* This is the variable namespace, automatically prepended to module variables.
|
||||
*/
|
||||
define('MEDIA_YOUTUBE_NAMESPACE', 'media_youtube__');
|
||||
|
||||
/**
|
||||
* Wrapper for variable_get() using the Media: YouTube variable registry.
|
||||
*
|
||||
* @param string $name
|
||||
* The variable name to retrieve. Note that it will be namespaced by
|
||||
* pre-pending MEDIA_YOUTUBE_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_youtube_variable_default() function.
|
||||
* @return unknown
|
||||
* Returns the stored variable or its default.
|
||||
*
|
||||
* @see media_youtube_variable_set()
|
||||
* @see media_youtube_variable_del()
|
||||
* @see media_youtube_variable_default()
|
||||
*/
|
||||
function media_youtube_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_youtube_variable_default($name);
|
||||
}
|
||||
// Namespace all variables.
|
||||
$variable_name = MEDIA_YOUTUBE_NAMESPACE . $name;
|
||||
return variable_get($variable_name, $default);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper for variable_set() using the Media: YouTube variable registry.
|
||||
*
|
||||
* @param string $name
|
||||
* The variable name to set. Note that it will be namespaced by
|
||||
* pre-pending MEDIA_YOUTUBE_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_youtube_variable_get()
|
||||
* @see media_youtube_variable_del()
|
||||
* @see media_youtube_variable_default()
|
||||
*/
|
||||
function media_youtube_variable_set($name, $value) {
|
||||
$variable_name = MEDIA_YOUTUBE_NAMESPACE . $name;
|
||||
return variable_set($variable_name, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper for variable_del() using the Media: YouTube variable registry.
|
||||
*
|
||||
* @param string $name
|
||||
* The variable name to delete. Note that it will be namespaced by
|
||||
* pre-pending MEDIA_YOUTUBE_NAMESPACE, as to avoid variable collisions with
|
||||
* other modules.
|
||||
*
|
||||
* @see media_youtube_variable_get()
|
||||
* @see media_youtube_variable_set()
|
||||
* @see media_youtube_variable_default()
|
||||
*/
|
||||
function media_youtube_variable_del($name) {
|
||||
$variable_name = MEDIA_YOUTUBE_NAMESPACE . $name;
|
||||
variable_del($variable_name);
|
||||
}
|
||||
|
||||
/**
|
||||
* The default variables within the Media: YouTube namespace.
|
||||
*
|
||||
* @param string $name
|
||||
* Optional variable name to retrieve the default. Note that it has not yet
|
||||
* been pre-pended with the MEDIA_YOUTUBE_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_youtube_variable_get()
|
||||
* @see media_youtube_variable_set()
|
||||
* @see media_youtube_variable_del()
|
||||
*/
|
||||
function media_youtube_variable_default($name = NULL) {
|
||||
static $defaults;
|
||||
|
||||
if (!isset($defaults)) {
|
||||
$defaults = array(
|
||||
'width' => 560,
|
||||
'height' =>340,
|
||||
'autoplay' => FALSE,
|
||||
'related' => TRUE,
|
||||
'hd' => FALSE,
|
||||
'showsearch' => TRUE,
|
||||
'modestbranding' => FALSE,
|
||||
'showinfo'=> TRUE,
|
||||
'version' => 3,
|
||||
'theme' => 'dark',
|
||||
'fullscreen' => TRUE,
|
||||
'wmode' => 'transparent',
|
||||
'chromeless' => FALSE,
|
||||
'preview_uri' => 'youtube://v/-jubiv7QUco',
|
||||
);
|
||||
}
|
||||
|
||||
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_YOUTUBE_NAMESPACE.
|
||||
*/
|
||||
function media_youtube_variable_name($name) {
|
||||
return MEDIA_YOUTUBE_NAMESPACE . $name;
|
||||
}
|
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file media_youtube/includes/themes/media-youtube-video.tpl.php
|
||||
*
|
||||
* Template file for theme('media_youtube_video').
|
||||
*
|
||||
* Variables available:
|
||||
* $uri - The uri to the YouTube video, such as youtube://v/xsy7x8c9.
|
||||
* $video_id - The unique identifier of the YouTube 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-youtube-outer-wrapper" id="media-youtube-<?php print $id; ?>" style="width: <?php print $width; ?>px; height: <?php print $height; ?>px;">
|
||||
<div class="media-youtube-preview-wrapper" id="<?php print $wrapper_id; ?>">
|
||||
<?php print $output; ?>
|
||||
</div>
|
||||
</div>
|
@@ -0,0 +1,227 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file media_youtube/includes/themes/media_youtube.theme.inc
|
||||
*
|
||||
* Theme and preprocess functions for Media: YouTube.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Preprocess function for theme('media_youtube_video').
|
||||
*/
|
||||
function media_youtube_preprocess_media_youtube_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['query'] = array();
|
||||
|
||||
// @see http://code.google.com/apis/youtube/player_parameters.html
|
||||
foreach (array('width', 'height', 'autoplay', 'related', 'hd', 'showsearch', 'modestbranding', 'showinfo', 'version', 'theme', 'fullscreen', 'wmode', 'chromeless') as $option) {
|
||||
// Set the option, either from the options array, or from the default value.
|
||||
$variables[$option] = isset($variables[$option]) ? $variables[$option] : (isset($variables['options'][$option]) ? $variables['options'][$option] : media_youtube_variable_get($option));
|
||||
}
|
||||
|
||||
// We have to set fullscreen in the url query and as a parameter to the flash.
|
||||
$variables['fs'] = $variables['fullscreen'];
|
||||
$variables['fullscreen'] = $variables['fullscreen'] ? 'true' : 'false';
|
||||
|
||||
$variables['wrapper_id'] = 'media_youtube_' . $variables['video_id'] . '_' . $variables['id'];
|
||||
|
||||
// Pass the settings to replace the object tag with an iframe.
|
||||
$settings = array(
|
||||
'media_youtube' => array(
|
||||
$variables['wrapper_id'] => array(
|
||||
'width' => $variables['width'],
|
||||
'height' => $variables['height'],
|
||||
'video_id' => $variables['video_id'],
|
||||
'fullscreen' => $variables['fullscreen'],
|
||||
'id' => $variables['wrapper_id'] .'_iframe',
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
// Set the version of the youtube api player.
|
||||
if ($variables['version']) {
|
||||
$variables['query']['version'] = $variables['version'];
|
||||
// Note that the fs variable defaults to 1 with the AS3 player.
|
||||
if (!$variables['fs']) {
|
||||
$variables['query']['fs'] = 0;
|
||||
}
|
||||
}
|
||||
else if ($variables['fs']) {
|
||||
// Note that the fs variable defaults to 0 with the AS2 player.
|
||||
$variables['query']['fs'] = 1;
|
||||
}
|
||||
|
||||
// These options default to 0.
|
||||
foreach (array('modestbranding', 'autoplay', 'hd') as $variable) {
|
||||
if ($variables[$variable]) {
|
||||
$variables['query'][$variable] = 1;
|
||||
}
|
||||
}
|
||||
// These options default to 1.
|
||||
foreach (array('showsearch', 'showinfo') as $variable) {
|
||||
if (!$variables[$variable]) {
|
||||
$variables['query'][$variable] = 0;
|
||||
}
|
||||
}
|
||||
if (!$variables['related']) {
|
||||
$variables['query']['rel'] = 0;
|
||||
}
|
||||
if ($variables['theme'] != 'dark') {
|
||||
$variables['query']['theme'] = $variables['theme'];
|
||||
}
|
||||
|
||||
// Ensure that we pass the required query variables to the Iframe settings.
|
||||
if (!empty($variables['query'])) {
|
||||
$settings['media_youtube'][$variables['wrapper_id']]['options'] = $variables['query'];
|
||||
}
|
||||
|
||||
drupal_add_js($settings, 'setting');
|
||||
drupal_add_js(drupal_get_path('module', 'media_youtube') . '/js/media_youtube.js');
|
||||
drupal_add_css(drupal_get_path('module', 'media_youtube') . '/css/media_youtube.css');
|
||||
drupal_add_js(drupal_get_path('module', 'media_youtube') . '/js/flash_detect_min.js');
|
||||
|
||||
// The chromeless player requires a different url.
|
||||
if ($variables['chromeless']) {
|
||||
$variables['url_api'] = 'apiplayer';
|
||||
$variables['query']['video_id'] = $variables['video_id'];
|
||||
}
|
||||
else {
|
||||
$variables['url_api'] = 'v/' . $variables['video_id'];
|
||||
}
|
||||
|
||||
$variables['url'] = url('http://www.youtube.com/' . $variables['url_api'], array('query' => $variables['query'], 'external' => TRUE, 'https' => TRUE));
|
||||
|
||||
// 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="{$variables['url']}"></param>
|
||||
<param name="allowFullScreen" value="{$variables['fullscreen']}"></param>
|
||||
<param name="wmode" value="{$variables['wmode']}" />
|
||||
<embed src="{$variables['url']}" type="application/x-shockwave-flash" width="{$variables['width']}" height="{$variables['height']}" allowfullscreen="{$variables['fullscreen']}" wmode="{$variables['wmode']}"></embed>
|
||||
</object>
|
||||
OUTPUT;
|
||||
}
|
||||
|
||||
function theme_media_youtube_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_youtube_embed', $variables);
|
||||
}
|
||||
|
||||
/**
|
||||
* Preview for Styles UI.
|
||||
*/
|
||||
function theme_media_youtube_preview_style($variables) {
|
||||
$variables['uri'] = media_youtube_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_youtube_styles($variables) {
|
||||
$style = $variables['style'];
|
||||
$variables['file'] = $variables['object'];
|
||||
$variables['uri'] = $variables['object']->uri;
|
||||
$variables['style_name'] = $style['name'];
|
||||
return theme('media_youtube_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_youtube_embed($variables) {
|
||||
$preset_name = $variables['preset_name'];
|
||||
$preset = styles_containers_available_styles('file', 'media_youtube', $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_youtube_variable_get('width');
|
||||
$height = isset($height) ? $height : media_youtube_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 'YouTube' to media library browser thumbnails.
|
||||
$output .= '<span />';
|
||||
}
|
||||
}
|
||||
else {
|
||||
$output = theme('media_youtube_video', array('uri' => $uri, 'width' => $width, 'height' => $height, 'autoplay' => ($autoplay == 'true' ? TRUE : NULL), 'fullscreen' => ($fullscreen_value == 'true' ? TRUE : NULL)));
|
||||
}
|
||||
}
|
||||
return $output;
|
||||
}
|
Reference in New Issue
Block a user