View source
<?php
define('EMVIDEO_YAHOOMUSIC_MAIN_URL', 'http://new.music.yahoo.com/');
define('EMVIDEO_YAHOOMUSIC_API_INFO', 'http://developer.yahoo.com/music/api_guide/');
define('EMVIDEO_YAHOOMUSIC_API_APPLICATION_URL', 'http://developer.yahoo.com/music/');
define('EMVIDEO_YAHOOMUSIC_BGCOLOR_DEFAULT', '#000000');
function video_cck_yahoomusic_info() {
$features = array(
array(
t('Autoplay'),
t('Yes'),
'',
),
array(
t('Thumbnails'),
t('Yes'),
t(''),
),
array(
t('Full screen mode'),
t('Yes'),
t('You may customize the player to enable or disable full screen playback. Full screen mode is enabled by default.'),
),
);
return array(
'provider' => 'yahoomusic',
'name' => t('Yahoo! Music'),
'url' => EMVIDEO_YAHOOMUSIC_MAIN_URL,
'settings_description' => t('These settings specifically affect videos displayed from <a href="@yahoomusic" target="_blank">Yahoo Music</a>. You can learn more about its <a href="@api" target="_blank">API</a> here.', array(
'@yahoomusic' => EMVIDEO_YAHOOMUSIC_MAIN_URL,
'@api' => EMVIDEO_YAHOOMUSIC_API_INFO,
)),
'supported_features' => $features,
);
}
function video_cck_yahoomusic_settings() {
$form['yahoomusic']['api'] = array(
'#type' => 'fieldset',
'#title' => t('Yahoo! Music API'),
'#description' => t('You will first need to apply for a Yahoo App ID from the <a href="@yahoomusic" target="_blank">Yahoo! Developer Network</a>.', array(
'@yahoomusic' => EMVIDEO_YAHOOMUSIC_API_APPLICATION_URL,
)),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form['yahoomusic']['api']['video_cck_yahoomusic_app_id'] = array(
'#type' => 'textfield',
'#title' => t('Yahoo! App ID'),
'#default_value' => variable_get('video_cck_yahoomusic_app_id', ''),
'#description' => t('Please enter your Yahoo! App ID here.'),
);
$form['yahoomusic']['api']['video_cck_yahoomusic_locale'] = array(
'#type' => 'select',
'#title' => t('Locale'),
'#default_value' => variable_get('video_cck_yahoomusic_locale', 'us'),
'#options' => array(
'us' => t('United States'),
'e1' => t('United States (Espanol)'),
'ca' => t('Canada'),
'mx' => t('Mexico'),
'au' => t('Australia'),
'nz' => t('New Zealand'),
'uk' => t('United Kingdom'),
'de' => t('Germany'),
'es' => t('Spain'),
'it' => t('Italy'),
'fr' => t('France'),
),
'#description' => t('If your application is designed for use by a web site or service in a particular country, Yahoo! Music requires that you use the locale for that country.'),
);
$form['yahoomusic']['player_options'] = array(
'#type' => 'fieldset',
'#title' => t('Embedded video player options'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form['yahoomusic']['player_options']['video_cck_yahoomusic_full_screen'] = array(
'#type' => 'checkbox',
'#title' => t('Allow fullscreen'),
'#default_value' => variable_get('video_cck_yahoomusic_full_screen', 1),
'#description' => t('Allow users to view video using the entire computer screen.'),
);
$form['yahoomusic']['player_options']['video_cck_yahoomusic_close_enable'] = array(
'#type' => 'checkbox',
'#title' => t('Enable Close'),
'#default_value' => variable_get('video_cck_yahoomusic_close_enable', 0),
'#description' => t('Sets visibility of the close button; button action will throw a callback event of type "close".'),
);
$form['yahoomusic']['player_options']['video_cck_yahoomusic_controls_enable'] = array(
'#type' => 'checkbox',
'#title' => t('Enable Controls'),
'#default_value' => variable_get('video_cck_yahoomusic_controls_enable', 1),
'#description' => t('Enables the player controls.'),
);
$form['yahoomusic']['player_options']['video_cck_yahoomusic_info_enable'] = array(
'#type' => 'checkbox',
'#title' => t('Enable Info'),
'#default_value' => variable_get('video_cck_yahoomusic_info_enable', 1),
'#description' => t('Sets visibility of the "more info" button.'),
);
$form['yahoomusic']['player_options']['video_cck_yahoomusic_now_playing_enable'] = array(
'#type' => 'checkbox',
'#title' => t('Enable Intro'),
'#default_value' => variable_get('video_cck_yahoomusic_now_playing_enable', 1),
'#description' => t('Enables the intro "Now Playing: ..." component during the first few seconds of playback.'),
);
$form['yahoomusic']['player_options']['video_cck_yahoomusic_post_panel_enable'] = array(
'#type' => 'checkbox',
'#title' => t('Enable Post Panel'),
'#default_value' => variable_get('video_cck_yahoomusic_post_panel_enable', 1),
'#description' => t('Enables the post panel; displayed after a clip completes playback.'),
);
$form['yahoomusic']['player_options']['video_cck_yahoomusic_pre_panel_enable'] = array(
'#type' => 'checkbox',
'#title' => t('Enable Pre Panel'),
'#default_value' => variable_get('video_cck_yahoomusic_pre_panel_enable', 1),
'#description' => t('Enables the pre meta panel on player initialization when autoStart is disabled and a valid id has been passed into the player.'),
);
$form['yahoomusic']['player_options']['video_cck_yahoomusic_share_enable'] = array(
'#type' => 'checkbox',
'#title' => t('Enable Share'),
'#default_value' => variable_get('video_cck_yahoomusic_share_enable', 1),
'#description' => t('Enables the Share panel.'),
);
$form['yahoomusic']['player_options']['video_cck_yahoomusic_bgcolor'] = array(
'#type' => 'textfield',
'#title' => t('Background Color'),
'#default_value' => variable_get('video_cck_yahoomusic_bgcolor', EMVIDEO_YAHOOMUSIC_BGCOLOR_DEFAULT),
);
$form['yahoomusic']['player_options']['video_cck_yahoomusic_bandwidth'] = array(
'#type' => 'textfield',
'#title' => t('Bandwidth'),
'#default_value' => variable_get('video_cck_yahoomusic_bandwidth', ''),
'#description' => t('Used to force a bandwidth; if bw is not specified the player will attempt to determine the best video bitrate quality for the user.'),
);
$form['yahoomusic']['player_options']['video_cck_yahoomusic_event_handler'] = array(
'#type' => 'textfield',
'#title' => t('Event Handler'),
'#default_value' => variable_get('video_cck_yahoomusic_event_handler', ''),
'#description' => t('Callback event handler that the player should make calls to.'),
);
return $form;
}
function video_cck_yahoomusic_data($field, $item) {
$data = array();
$data['video_cck_yahoomusic_version'] = 1;
return $data;
}
function video_cck_yahoomusic_extract($embed = '') {
if ($embed && preg_match('@(.*)yahoo.com(.*)--([0-9]+)@i', $embed, $matches)) {
return $matches[3];
}
else {
if ($embed && preg_match('@id=v([^"\\&]+)@i', $embed, $matches)) {
return $matches[1];
}
}
return FALSE;
}
function video_cck_yahoomusic_embedded_link($video_code) {
$locale = _video_cck_yahoomusic_locale_lookup();
return 'http://new.' . $locale . '.music.yahoo.com/videos/--' . $video_code;
}
function _video_cck_yahoomusic_locale_lookup($value = 'code') {
static $locales = array();
$code = variable_get('video_cck_yahoomusic_locale', 'us');
switch ($code) {
case 'us':
$locales[$code] = array(
'name' => 'United States',
'eid' => 1301797,
'ympsc' => 4195351,
'lang' => 'en',
);
break;
case 'e1':
$locales[$code] = array(
'name' => 'United States (Espanol)',
'eid' => 1307666,
'ympsc' => 559940629,
'lang' => 'es',
);
break;
case 'ca':
$locales[$code] = array(
'name' => 'Canada',
'eid' => 1307409,
'ympsc' => 642778131,
'lang' => 'en',
);
break;
case 'mx':
$locales[$code] = array(
'name' => 'Mexico',
'eid' => 8257040,
'ympsc' => 640680961,
'lang' => 'es',
);
break;
case 'au':
$locales[$code] = array(
'name' => 'Australia',
'eid' => 1307669,
'ympsc' => 638583826,
'lang' => 'en',
);
break;
case 'nz':
$locales[$code] = array(
'name' => 'New Zealand',
'eid' => 5300947,
'ympsc' => 638583833,
'lang' => 'en',
);
break;
case 'uk':
$locales[$code] = array(
'name' => 'United Kingdom',
'eid' => 1301655,
'ympsc' => 529531933,
'lang' => 'uk',
);
break;
case 'de':
$locales[$code] = array(
'name' => 'Germany',
'eid' => 1307668,
'ympsc' => 535823380,
'lang' => 'de',
);
break;
case 'es':
$locales[$code] = array(
'name' => 'Spain',
'eid' => 1307660,
'ympsc' => 534774806,
'lang' => 'es',
);
break;
case 'it':
$locales[$code] = array(
'name' => 'Italy',
'eid' => 1307667,
'ympsc' => 533726232,
'lang' => 'it',
);
break;
case 'fr':
$locales[$code] = array(
'name' => 'France',
'eid' => 1307665,
'ympsc' => 536871959,
'lang' => 'fr',
);
break;
default:
$code = 'us';
$locales[$code] = array(
'name' => 'United States',
'eid' => 1301797,
'ympsc' => 4195351,
'lang' => 'en',
);
}
$locales[$code]['hostname'] = $code . '.music.yahooapis.com';
switch ($value) {
case 'code':
return $code;
break;
case 'name':
return $locales[$code]['name'];
break;
case 'hostname':
return $locales[$code]['hostname'];
break;
case 'eid':
return $locales[$code]['eid'];
break;
case 'ympsc':
return $locales[$code]['ympsc'];
break;
case 'lang':
return $locales[$code]['lang'];
break;
default:
drupal_set_message(t('Bad locale lookup request.'), 'warning');
return '';
}
}
function theme_video_cck_yahoomusic_flash($embed, $width, $height, $autoplay, $options = array()) {
static $count;
if ($embed) {
$variables = array();
$variables['id'] = 'v' . $embed;
$variables['eID'] = _video_cck_yahoomusic_locale_lookup('eid');
$variables['ympsc'] = _video_cck_yahoomusic_locale_lookup('ympsc');
$variables['lang'] = _video_cck_yahoomusic_locale_lookup('lang');
$fullscreen = variable_get('video_cck_yahoomusic_full_screen', 1);
$fullscreen_value = $fullscreen ? "true" : "false";
$variables['enableFullScreen'] = $fullscreen ? "1" : "0";
$variables['autoStart'] = $autoplay ? '1' : '0';
$variables['bw'] = variable_get('video_cck_yahoomusic_bandwidth', '');
$variables['eh'] = variable_get('video_cck_yahoomusic_event_handler', '');
$variables['closeEnable'] = variable_get('video_cck_yahoomusic_close_enable', 0);
$variables['controlsEnable'] = variable_get('video_cck_yahoomusic_controls_enable', 1);
$variables['infoEnable'] = variable_get('video_cck_yahoomusic_info_enable', 1);
$variables['nowplayingEnable'] = variable_get('video_cck_yahoomusic_now_playing_enable', 1);
$variables['postpanelEnable'] = variable_get('video_cck_yahoomusic_post_panel_enable', 1);
$variables['prepanelEnable'] = variable_get('video_cck_yahoomusic_pre_panel_enable', 1);
$variables['shareEnable'] = variable_get('video_cck_yahoomusic_share_enable', 1);
$bgcolor = variable_get('video_cck_yahoomusic_bgcolor', EMVIDEO_YAHOOMUSIC_BGCOLOR_DEFAULT);
foreach ($variables as $name => $value) {
if ($value !== '') {
if ($name == 'id') {
$flash_vars = $name . '=' . $value;
}
else {
$flash_vars .= '&' . $name . '=' . $value;
}
}
else {
unset($variables[$name]);
}
}
$id = isset($options['id']) ? $options['id'] : 'video-cck-yahoomusic-flash-' . ++$count;
$div_id = isset($options['div_id']) ? $options['div_id'] : 'video-cck-yahoomusic-flash-wrapper-' . $count;
$url = "http://d.yimg.com/cosmos.bcst.yahoo.com/up/fop/embedflv/swf/fop.swf";
if (variable_get('emfield_swfobject', FALSE) && (module_exists('swfobject_api') || variable_get('emfield_swfobject_location', ''))) {
if (module_exists('swfobject_api')) {
$params['width'] = $width;
$params['height'] = $height;
$params['div_id'] = $id;
$params['allowFullScreen'] = $fullscreen_value;
$params['bgcolor'] = $bgcolor;
$output .= theme('swfobject_api', $url, $params, $variables, $id);
}
else {
drupal_add_js(variable_get('emfield_swfobject_location', ''));
$output .= <<<FLASH
<div id="{<span class="php-variable">$div_id</span>}">
Sorry, you need to install flash to see this content.
</div>
<script type="text/javascript">
var so = new SWFObject('{<span class="php-variable">$url</span>}', '{<span class="php-variable">$id</span>}', '{<span class="php-variable">$width</span>}', '{<span class="php-variable">$height</span>}', '9', '#ffffff');
FLASH;
foreach ($variables as $name => $value) {
$output .= "so.addVariable({$name}, '{$value}');\n";
}
$output .= <<<FLASH
so.addParam("allowFullScreen", "{<span class="php-variable">$fullscreen_value</span>}");
so.addParam("bgcolor", "{<span class="php-variable">$bgcolor</span>}");
so.addParam("allowScriptAccess", "always"); // for scripting access
so.write("{<span class="php-variable">$div_id</span>}");
</script>
FLASH;
}
}
else {
$output .= <<<FLASH
<div id="{<span class="php-variable">$div_id</span>}">
<object height="{<span class="php-variable">$height</span>}" width="{<span class="php-variable">$width</span>}" type="application/x-shockwave-flash" data="{<span class="php-variable">$url</span>}" id="{<span class="php-variable">$id</span>}" style="visibility: visible;">
<param name="div_id" value="{<span class="php-variable">$div_id</span>}"/>
<param name="allowFullScreen" value="{<span class="php-variable">$fullscreen_value</span>}"/>
<param name="type" value="movie"/>
<param name="flashvars" value="{<span class="php-variable">$flash_vars</span>}"/>
<param name="bgcolor" value="{<span class="php-variable">$bgcolor</span>}"/>
</object>
</div>
FLASH;
}
}
return $output;
}
function video_cck_yahoomusic_thumbnail($field, $item, $formatter, $node, $width, $height) {
$yahoomusic_id = $item['value'];
$locale = _video_cck_yahoomusic_locale_lookup();
$tn = "http://d.yimg.com/img.music.yahoo.com/image/v1/video/{$yahoomusic_id};encoding=jpg;size=" . $width . 'x' . $height . ";locale={$locale};";
if ($width > 385 || $height > 231) {
$tn = "http://d.yimg.com/img.music.yahoo.com/image/v1/video/{$yahoomusic_id};encoding=jpg;locale={$locale};";
}
return $tn;
}
function video_cck_yahoomusic_video($embed, $width, $height, $field, $item, $autoplay) {
$output = theme('video_cck_yahoomusic_flash', $embed, $width, $height, $autoplay);
return $output;
}
function video_cck_yahoomusic_preview($embed, $width, $height, $field, $item, $autoplay) {
$output = theme('video_cck_yahoomusic_flash', $embed, $width, $height, $autoplay);
return $output;
}