View source
<?php
define('EMVIDEO_FLICKR_SETS_DATA_VERSION', 1);
function emvideo_flickr_sets_info() {
$features = array(
array(
t('Autoplay'),
t('No'),
'',
),
array(
t('RSS Attachment'),
t('No'),
'',
),
array(
t('Thumbnails'),
t('Yes'),
t(''),
),
array(
t('Full screen mode'),
t('Yes'),
t('Full screen mode is enabled for this player, but may not be disabled.'),
),
);
return array(
'provider' => 'flickr_sets',
'name' => t('Flickr Photosets'),
'url' => MEDIA_FLICKR_MAIN_URL,
'settings_description' => t('These settings specifically affect slideshows displayed from !flickr_sets.', array(
'!flickr_sets' => l(t('Flickr.com'), MEDIA_FLICKR_MAIN_URL),
)),
'supported_features' => $features,
);
}
function emvideo_flickr_sets_settings() {
if (!function_exists('emfield_imagerotator_url')) {
drupal_set_message(t('You should upgrade to a newer version of !emfield if you wish support for the !player or !imagerotator.', array(
'!emfield' => l(t('Embedded Media Field'), 'https://drupal.org/project/emfield'),
'!player' => l(t('JW Flash Media Player'), 'http://www.longtailvideo.com/players/jw-flv-player/'),
'!imagerotator' => l(t('JW Image Rotator'), 'http://www.longtailvideo.com/players/jw-image-rotator/'),
)), 'error');
}
$form['flickr_sets']['media_flickr_store_local'] = array(
'#type' => 'checkbox',
'#title' => t('Store images locally'),
'#description' => t('If checked, then images from Flickr will be stored locally.'),
'#default_value' => variable_get('media_flickr_store_local', FALSE),
);
$form['flickr_sets']['media_flickr_max_saves'] = array(
'#type' => 'textfield',
'#title' => t('Maximum local saves per page load'),
'#description' => t('This will limit the number of remote files that will be stored locally from Flickr per page load when storing a photoset locally, causing the rest in that specific view to be displayed from the remote location. If you set this to 0, then all such files will be stored on the initial slideshow view. Note that setting this to 0 or to an arbitrarily large number can cause the initial view to take a very long time, or even cause the browser to time out. Also note that this setting has no effect if the images are not to be stored locally.'),
'#default_value' => variable_get('media_flickr_max_saves', 10),
);
if (function_exists('emimage_flickr_settings')) {
$form['flickr_sets']['api'] = array(
'#type' => 'fieldset',
'#title' => t('Flickr API'),
'#description' => t('You will first need to apply for an API Developer Key from the <a href="@flickr" target="_blank">Flickr Developer Profile page</a>.', array(
'@flickr' => MEDIA_FLICKR_API_APPLICATION_URL,
)),
'#collapsible' => TRUE,
'#collapsed' => variable_get('emimage_flickr_api_key', '') != '',
);
$form['flickr_sets']['api']['notice'] = array(
'#type' => 'item',
'#value' => t('Please enter your Flickr Developer Key in the fieldset for Flickr, in the Embedded Image Field field set above.'),
);
}
else {
$form['flickr_sets']['api'] = array(
'#type' => 'fieldset',
'#title' => t('Flickr API'),
'#description' => t('You will first need to apply for an API Developer Key from the <a href="@flickr" target="_blank">Flickr Developer Profile page</a>.', array(
'@flickr' => MEDIA_FLICKR_API_APPLICATION_URL,
)),
'#collapsible' => TRUE,
'#collapsed' => variable_get('emimage_flickr_api_key', '') != '',
);
$form['flickr_sets']['api']['emimage_flickr_api_key'] = array(
'#type' => 'textfield',
'#title' => t('Flickr API Key'),
'#default_value' => variable_get('emimage_flickr_api_key', ''),
'#description' => t('Please enter your Flickr Developer Key here.'),
);
$form['flickr_sets']['api']['emimage_flickr_api_secret'] = array(
'#type' => 'textfield',
'#title' => t('Flickr API Secret'),
'#default_value' => variable_get('emimage_flickr_api_secret', ''),
'#description' => t('If you have a secret for the Flickr API, enter it here.'),
);
}
return $form;
}
function emvideo_flickr_sets_data_version() {
return EMVIDEO_FLICKR_SETS_DATA_VERSION;
}
function emvideo_flickr_sets_data($field, $item) {
$data = array();
$xml = media_flickr_sets_request('flickr.photosets.getPhotos', array(
'photoset_id' => $item['value'],
'per_page' => 1,
));
$data['owner'] = $xml['photoset']['owner'];
$data['first_photo'] = $xml['photoset']['photo'][0]['id'];
$data['emvideo_data_version'] = EMVIDEO_FLICKR_SETS_DATA_VERSION;
return $data;
}
function emvideo_flickr_sets_rss($item, $teaser = NULL) {
}
function emvideo_flickr_sets_validate($value, $error_field) {
if ($value == 'FLICKR_SETS_ERROR_SEARCH') {
form_set_error($error_field, t("Flickr search-based slide shows are not currently supported; only slide shows of a specific photo set will be accepted."));
}
else {
if ($value == 'FLICKR_SETS_ERROR_USER') {
form_set_error($error_field, t("Flickr user slide shows are not currently supported; only slide shows of a specific photo set will be accepted."));
}
else {
if ($value == 'FLICKR_SETS_ERROR_GROUPS') {
form_set_error($error_field, t("Flickr groups slide shows are not currently supported; only slide shows of a specific photo set will be accepted."));
}
}
}
}
function emvideo_flickr_sets_extract($embed = '') {
if (preg_match('@\\.flickr\\.com/search.+?\\?q=([^\\&]+)@i', $embed, $matches)) {
return 'FLICKR_SETS_ERROR_SEARCH';
}
else {
if (!($set = preg_match('@\\.flickr\\.com/.+?/.+?/sets/([^/\\?]+)@i', $embed, $matches)) && preg_match('@\\.flickr\\.com/photos/([^/\\?\\#]+)@i', $embed, $matches)) {
return 'FLICKR_SETS_ERROR_USER';
}
else {
if (!$set && preg_match('@\\.flickr\\.com/groups/([^/\\?\\#]+)@i', $embed, $matches)) {
return 'FLICKR_SETS_ERROR_GROUPS';
}
}
}
return array(
'@\\.flickr\\.com/.+?/.+?/sets/([^/\\?]+)@i',
'@sets%2F(.+?)%2Fshow.+?flickr\\.com/apps/slideshow/show\\.swf@i',
);
}
function emvideo_flickr_sets_embedded_link($video_code, $data = array()) {
if (empty($data)) {
$data = emvideo_flickr_sets_data(NULL, array(
'value' => $video_code,
));
}
return 'https://www.flickr.com/photos/' . $data['owner'] . '/sets/' . $video_code;
}
function theme_emvideo_flickr_sets_flash($item, $width, $height, $autoplay, $options = array()) {
$output = '';
if ($item['value']) {
$value = check_plain($item['value']);
$embed = drupal_urlencode('photos/' . $item['data']['owner'] . '/sets/' . $value);
$output = <<<EMBED
<object type="application/x-shockwave-flash" data="https://www.flickr.com/apps/slideshow/show.swf?v=71649" width="{<span class="php-variable">$width</span>}" height="{<span class="php-variable">$height</span>}">
<param name="movie" value="https://www.flickr.com/apps/slideshow/show.swf?v=71649" />
<param name="flashvars" value="offsite=true&lang=en-us&page_show_url=/{<span class="php-variable">$embed</span>}/show/&page_show_back_url=/{<span class="php-variable">$embed</span>}&set_id={<span class="php-variable">$value</span>}&jump_to=" />
<param name="allowFullScreen" value="true" />
</object>
EMBED;
}
return $output;
}
function theme_emvideo_flickr_sets_flvmediaplayer($item, $width, $height, $autoplay, $options = array()) {
global $base_path;
$formatter = isset($options['formatter']) ? $options['formatter'] : 'video';
$delay = isset($options['delay']) ? $options['delay'] : (isset($options['field']['widget']['media_flickr_delay_' . $formatter]) ? $options['field']['widget']['media_flickr_delay_' . $formatter] : variable_get('media_flickr_options_delay', 10));
if (module_exists('media_flickr_xspf')) {
$captions = isset($options['captions']) ? $options['captions'] : (isset($options['field']['widget']['media_flickr_captions_' . $formatter]) ? $options['field']['widget']['media_flickr_captions_' . $formatter] : variable_get('media_flickr_xspf_caption_type', MEDIA_FLICKR_XSPF_CAPTION_TYPE_TITLE));
$flashvars['file'] = url('media/flickr/photoset/' . $item['value'] . '/xspf/' . $delay . '/' . $width . '/' . $height . '/' . $captions);
}
else {
$flashvars['file'] = url('media/flickr/remote/' . $item['value']);
}
$params['width'] = $width;
$params['height'] = $height;
$params['allowfullscreen'] = isset($options['allowfullscreen']) ? $options['allowfullscreen'] : (isset($options['field']['widget']['media_flickr_allowfullscreen_' . $formatter]) ? $options['field']['widget']['media_flickr_allowfullscreen_' . $formatter] : variable_get('media_flickr_options_allowfullscreen', TRUE));
$params['allowfullscreen'] = $options['allowfullscreen'] ? 'true' : 'false';
$params['allowscriptaccess'] = isset($options['allowscriptaccess']) ? $options['allowscriptaccess'] : (isset($options['field']['widget']['media_flickr_allowscriptaccess_' . $formatter]) ? $options['field']['widget']['media_flickr_allowscriptaccess_' . $formatter] : variable_get('media_flickr_options_allowscriptaccess', 'always'));
$flashvars['autostart'] = $autoplay ? 'true' : 'false';
$flashvars['playlist'] = isset($options['playlist']) ? $options['playlist'] : (isset($options['field']['widget']['media_flickr_playlist_' . $formatter]) ? $options['field']['widget']['media_flickr_playlist_' . $formatter] : variable_get('media_flickr_options_playlist', 'right'));
$flashvars['playlistsize'] = isset($options['playlistsize']) ? $options['playlistsize'] : (isset($options['field']['widget']['media_flickr_playlistsize_' . $formatter]) ? $options['field']['widget']['media_flickr_playlistsize_' . $formatter] : variable_get('media_flickr_options_playlistsize', 86));
$flashvars['repeat'] = isset($options['repeat']) ? $options['repeat'] : (isset($options['field']['widget']['media_flickr_repeat_' . $formatter]) ? $options['field']['widget']['media_flickr_repeat_' . $formatter] : variable_get('media_flickr_options_repeat', 'list'));
$flashvars['controlbar'] = isset($options['controlbar']) ? $options['controlbar'] : (isset($options['field']['widget']['media_flickr_controlbar_' . $formatter]) ? $options['field']['widget']['media_flickr_controlbar_' . $formatter] : variable_get('media_flickr_options_controlbar', 'none'));
$logo = isset($options['logo']) ? $options['logo'] : (isset($options['field']['widget']['media_flickr_logo_' . $formatter]) ? $options['field']['widget']['media_flickr_logo_' . $formatter] : variable_get('media_flickr_options_logo', ''));
if ($logo) {
$flashvars['logo'] = url($logo);
}
if (function_exists('emfield_flvmediaplayer_url')) {
$path = emfield_flvmediaplayer_url();
}
if (module_exists('flvmediaplayer')) {
if (!$path) {
$path = variable_get('flvmediaplayer_path', drupal_get_path('module', 'flvmediaplayer') . '/mediaplayer.swf');
}
return theme('flvmediaplayer_render_player', $base_path . $path, $params, $flashvars);
}
else {
if ($path && module_exists('swfobject_api')) {
return theme('swfobject_api', $base_path . $path, $params, $flashvars);
}
}
return theme('emvideo_flickr_sets_flash', $item, $width, $height, $autoplay, $options);
}
function theme_emvideo_flickr_sets_imagerotator($item, $width, $height, $autoplay, $options = array()) {
global $base_path;
$formatter = isset($options['formatter']) ? $options['formatter'] : 'video';
$delay = isset($options['rotatetime']) ? $options['rotatetime'] : (isset($options['field']['widget']['media_flickr_rotatetime_' . $formatter]) ? $options['field']['widget']['media_flickr_rotatetime_' . $formatter] : variable_get('media_flickr_options_rotatetime', 5));
if (module_exists('media_flickr')) {
$captions = isset($options['captions']) ? $options['captions'] : (isset($options['field']['widget']['media_flickr_ir_captions_' . $formatter]) ? $options['field']['widget']['media_flickr_ir_captions_' . $formatter] : variable_get('media_flickr_xspf_caption_type', MEDIA_FLICKR_XSPF_CAPTION_TYPE_TITLE));
$flashvars['file'] = url('media/flickr/photoset/' . $item['value'] . '/xspf/' . $delay . '/' . $width . '/' . $height . '/' . $captions, array(
'absolute' => TRUE,
));
}
else {
$flashvars['file'] = url('media/flickr/remote/' . $item['value'], array(
'absolute' => TRUE,
));
}
$params['width'] = $width;
$params['height'] = $height;
$params['allowfullscreen'] = isset($options['allowfullscreen']) ? $options['allowfullscreen'] : (isset($options['field']['widget']['media_flickr_ir_allowfullscreen_' . $formatter]) ? $options['field']['widget']['media_flickr_ir_allowfullscreen_' . $formatter] : variable_get('media_flickr_options_ir_allowfullscreen', TRUE));
$params['allowfullscreen'] = $params['allowfullscreen'] ? 'true' : 'false';
$params['allowscriptaccess'] = isset($options['allowscriptaccess']) ? $options['allowscriptaccess'] : (isset($options['field']['widget']['media_flickr_ir_allowscriptaccess_' . $formatter]) ? $options['field']['widget']['media_flickr_ir_allowscriptaccess_' . $formatter] : variable_get('media_flickr_options_ir_allowscriptaccess', 'always'));
$flashvars['usefullscreen'] = $params['allowfullscreen'];
$flashvars['autostart'] = $autoplay ? 'true' : 'false';
$flashvars['repeat'] = isset($options['repeat']) ? $options['repeat'] : (isset($options['field']['widget']['media_flickr_ir_repeat_' . $formatter]) ? $options['field']['widget']['media_flickr_ir_repeat_' . $formatter] : variable_get('media_flickr_options_ir_repeat', 'list'));
$flashvars['shownavigation'] = isset($options['shownavigation']) ? $options['shownavigation'] : (isset($options['field']['widget']['media_flickr_ir_shownavigation_' . $formatter]) ? $options['field']['widget']['media_flickr_ir_shownavigation_' . $formatter] : variable_get('media_flickr_options_ir_shownavigation', TRUE));
$flashvars['shownavigation'] = $flashvars['shownavigation'] ? 'true' : 'false';
$flashvars['showicons'] = isset($options['showicons']) ? $options['showicons'] : (isset($options['field']['widget']['media_flickr_ir_showicons_' . $formatter]) ? $options['field']['widget']['media_flickr_ir_showicons_' . $formatter] : variable_get('media_flickr_options_ir_showicons', TRUE));
$flashvars['showicons'] = $flashvars['showicons'] ? 'true' : 'false';
$flashvars['shuffle'] = isset($options['shuffle']) ? $options['shuffle'] : (isset($options['field']['widget']['media_flickr_ir_shuffle_' . $formatter]) ? $options['field']['widget']['media_flickr_ir_shuffle_' . $formatter] : variable_get('media_flickr_options_ir_shuffle', FALSE));
$flashvars['shuffle'] = $flashvars['shuffle'] ? 'true' : 'false';
$flashvars['transition'] = isset($options['transition']) ? $options['transition'] : (isset($options['field']['widget']['media_flickr_ir_transition_' . $formatter]) ? $options['field']['widget']['media_flickr_ir_transition_' . $formatter] : variable_get('media_flickr_options_ir_transition', 'random'));
$flashvars['enablejs'] = 'true';
$logo = isset($options['logo']) ? $options['logo'] : (isset($options['field']['widget']['media_flickr_ir_logo_' . $formatter]) ? $options['field']['widget']['media_flickr_ir_logo_' . $formatter] : variable_get('media_flickr_options_ir_logo', ''));
if ($logo) {
$flashvars['logo'] = url($logo);
}
$accessibility_title = isset($options['title']) ? $options['title'] : variable_get('media_flickr_sets_title_default', t('Flickr Photoset'));
if (function_exists('emfield_imagerotator_url')) {
$path = emfield_imagerotator_url();
}
if ($path && variable_get('emfield_swfobject', FALSE) && module_exists('swfobject_api')) {
return theme('swfobject_api', $base_path . $path, $params, $flashvars);
}
else {
if ($path) {
static $count;
$count++;
$id = 'emvideo-flickr-' . $count;
$object_id = $id . '-rotator';
$path = $base_path . $path;
$flashvars['width'] = $width;
$flashvars['height'] = $height;
$flashvars = drupal_query_string_encode($flashvars);
$base_root = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ? 'https' : 'http';
$output = <<<EMBED
<div id="{<span class="php-variable">$id</span>}">
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
codebase="{<span class="php-variable">$base_root</span>}://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0"
width="{<span class="php-variable">$width</span>}" height="{<span class="php-variable">$height</span>}" id="{<span class="php-variable">$object_id</span>}">
<param name="movie" value="{<span class="php-variable">$path</span>}" />
<param name="allowfullscreen" value="true" />
<param name="wmode" value="transparent" />
<param name="flashvars" value="{<span class="php-variable">$flashvars</span>}" />
<!--[if !IE]> -->
<object type="application/x-shockwave-flash" data="{<span class="php-variable">$path</span>}" name="rotator" width="{<span class="php-variable">$width</span>}" height="{<span class="php-variable">$height</span>}" id="{<span class="php-variable">$object_id</span>}">
<param name="movie" value="{<span class="php-variable">$path</span>}" />
<param name="allowfullscreen" value="true" />
<param name="wmode" value="transparent" />
<param name="flashvars" value="{<span class="php-variable">$flashvars</span>}" />
{<span class="php-variable">$accessibility_title</span>}
</object>
<!-- <![endif]-->
</object>
</div>
EMBED;
return $output;
}
}
return theme('emvideo_flickr_sets_flash', $item, $width, $height, $autoplay, $options);
}
function theme_emvideo_flickr_sets_custom($item, $width, $height, $autoplay, $options = array()) {
return theme('emvideo_flickr_sets_flvmediaplayer', $item, $width, $height, $autoplay, $options);
}
function emvideo_flickr_sets_thumbnail($field, $item, $formatter, $node, $width, $height, $options = array()) {
if ($item['value']) {
return media_flickr_photo_url($item['data']['first_photo'], $width, $height);
}
}
function emvideo_flickr_sets_video($embed, $width, $height, $field, $item, $node, $autoplay, $options = array()) {
$options['node'] = $options['node'] ? $options['node'] : $node;
$options['field'] = $options['field'] ? $options['field'] : $field;
$options['player'] = $options['player'] ? $options['player'] : ($field['widget']['media_flickr_player_video'] ? $field['widget']['media_flickr_player_video'] : variable_get('media_flickr_player', 'flash'));
$options['formatter'] = $options['formatter'] ? $options['formatter'] : 'video';
$output = theme('emvideo_flickr_sets_' . $options['player'], $item, $width, $height, $autoplay, $options);
return $output;
}
function emvideo_flickr_sets_preview($embed, $width, $height, $field, $item, $node, $autoplay, $options = array()) {
$options['node'] = $options['node'] ? $options['node'] : $node;
$options['field'] = $options['field'] ? $options['field'] : $field;
$options['player'] = $options['player'] ? $options['player'] : ($field['widget']['media_flickr_player_preview'] ? $field['widget']['media_flickr_player_preview'] : variable_get('media_flickr_player', 'flash'));
$options['formatter'] = $options['formatter'] ? $options['formatter'] : 'preview';
$output = theme('emvideo_flickr_sets_' . $options['player'], $item, $width, $height, $autoplay, $options);
return $output;
}
function emvideo_flickr_sets_emfield_subtheme() {
$themes = array(
'emvideo_flickr_sets_flash' => array(
'arguments' => array(
'item' => NULL,
'width' => NULL,
'height' => NULL,
'autoplay' => NULL,
'options' => array(),
),
'file' => 'providers/emvideo/flickr_sets.inc',
'path' => drupal_get_path('module', 'media_flickr'),
),
'emvideo_flickr_sets_imagerotator' => array(
'arguments' => array(
'item' => NULL,
'width' => NULL,
'height' => NULL,
'autoplay' => NULL,
'options' => array(),
),
'file' => 'providers/emvideo/flickr_sets.inc',
'path' => drupal_get_path('module', 'media_flickr'),
),
'emvideo_flickr_sets_flvmediaplayer' => array(
'arguments' => array(
'item' => NULL,
'width' => NULL,
'height' => NULL,
'autoplay' => NULL,
'options' => array(),
),
'file' => 'providers/emvideo/flickr_sets.inc',
'path' => drupal_get_path('module', 'media_flickr'),
),
'emvideo_flickr_sets_custom' => array(
'arguments' => array(
'item' => NULL,
'width' => NULL,
'height' => NULL,
'autoplay' => NULL,
'options' => array(),
),
'file' => 'providers/emvideo/flickr_sets.inc',
'path' => drupal_get_path('module', 'media_flickr'),
),
);
return $themes;
}