Commit fa0a5528 authored by attila.fekete's avatar attila.fekete
Browse files

Issue #1413024 by SlackerD: added a new formatter (html5 player), so now the...

Issue #1413024 by SlackerD: added a new formatter (html5 player), so now the HTML5 SoundCloud widget is available for use
parent f8e8ddbe
......@@ -192,7 +192,11 @@ function soundcloudfield_field_widget_form(&$form, &$form_state, $field, $instan
function soundcloudfield_field_formatter_info() {
return array(
'soundcloud_default' => array(
'label' => t('Player'),
'label' => t('Flash player'),
'field types' => array('soundcloud'),
),
'soundcloud_html5' => array(
'label' => t('HTML5 player'),
'field types' => array('soundcloud'),
),
'soundcloud_link' => array(
......@@ -209,33 +213,34 @@ function soundcloudfield_field_formatter_view($obj_type, $object, $field, $insta
$element = array();
$settings = $instance['settings']['player'];
$showcomments = ($settings['showcomments']) ? 'true' : 'false';
$autoplay = ($settings['autoplay']) ? 'true' : 'false';
$showplaycount = ($settings['showplaycount']) ? 'true' : 'false';
$showartwork = ($settings['showartwork']) ? 'true' : 'false';
$color = $settings['color'];
switch ($display['type']) {
case 'soundcloud_default':
foreach ($items as $delta => $item) {
$output = '';
$encoded_url = urlencode($item['url']);
$parsed_url = parse_url($item['url']);
$showcomments = ($settings['showcomments']) ? 'true' : 'false';
$autoplay = ($settings['autoplay']) ? 'true' : 'false';
$showplaycount = ($settings['showplaycount']) ? 'true' : 'false';
$showartwork = ($settings['showartwork']) ? 'true' : 'false';
$params_track = 'url=' . $encoded_url .
'&show_comments=' . $showcomments .
'&auto_play=' . $autoplay .
'&color=' . $settings['color'];
// '&color=' . str_replace('#', '', $settings['color']);
'&color=' . $color;
// '&color=' . str_replace('#', '', $color);
$params_set = 'url=' . $encoded_url .
'&show_comments=' . $showcomments .
'&auto_play=' . $autoplay .
'&show_playcount=' . $showplaycount .
'&show_artwork=' . $showartwork .
'&color=' . $settings['color'];
// '&color=' . str_replace('#', '', $settings['color']);
'&color=' . $color;
// '&color=' . str_replace('#', '', $color);
$splitted_url = explode("/", $parsed_url['path']);
......@@ -250,6 +255,47 @@ function soundcloudfield_field_formatter_view($obj_type, $object, $field, $insta
}
break;
case 'soundcloud_html5':
$oembed_endpoint = 'http://soundcloud.com/oembed';
foreach ($items as $delta => $item) {
$output = '';
$encoded_url = urlencode($item['url']);
// Create the URL
$oembed_url = $oembed_endpoint . '?iframe=true&url=' . ($encoded_url);
// Load in the oEmbed XML
$oembed = simplexml_load_string(curl_get($oembed_url));
// Replace player default settings with our settings
$final_iframe = preg_replace('/(width=)"([^"]+)"/', 'width="'.$settings['width'].'%"', $oembed->html);
// $final_iframe = preg_replace('/(height=)"([^"]+)"/', 'height="'.$settings['height'].'"', $final_iframe);
if (preg_match('/auto_play=(true|false)/', $final_iframe)) {
$final_iframe = preg_replace('/auto_play=(true|false)/', 'auto_play='.$autoplay, $final_iframe);
} else {
$final_iframe = preg_replace('/">/', '&auto_play='.$autoplay.'">', $final_iframe);
}
if (preg_match('/show_artwork=(true|false)/', $final_iframe)) {
$final_iframe = preg_replace('/show_artwork=(true|false)/', 'show_artwork='.$showartwork, $final_iframe);
} else {
$final_iframe = preg_replace('/">/', '&show_artwork='.$showartwork.'">', $final_iframe);
}
if (preg_match('/color=([a-zA-Z0-9]{6})/', $final_iframe)) {
$final_iframe = preg_replace('/color=([a-zA-Z0-9]{6})/', 'color='.$color, $final_iframe);
} else {
$final_iframe = preg_replace('/">/', '&color='.$color.'">', $final_iframe);
}
$output = html_entity_decode($final_iframe); // '$oembed->html' for original embed
$element[$delta] = array('#markup' => $output);
}
break;
case 'soundcloud_link':
foreach ($items as $delta => $item) {
$element[$delta] = array('#markup' => l($item['url'], $item['url']));
......@@ -269,4 +315,17 @@ function soundcloudfield_field_widget_error($element, $error) {
form_error($element, $error['message']);
break;
}
}
/*
* Curl helper function
*/
function curl_get($url) {
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_TIMEOUT, 30);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
$return = curl_exec($curl);
curl_close($curl);
return $return;
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment