diff --git a/providers/soundcloud.inc b/providers/soundcloud.inc index b3a62cb..155b28f 100644 --- a/providers/soundcloud.inc +++ b/providers/soundcloud.inc @@ -71,9 +71,9 @@ function emaudio_soundcloud_extract($embed = '') { * The embedded flash displaying the SoundCloud audio. */ function theme_emaudio_soundcloud_flash($item, $embed, $width, $height, $autoplay) { - // If the swf element is NULL, then we have an embed code instead of a URL; - // return this directly. - if (is_null($item['data']['swf'])) { + // If embed code is between tags, assume its embed code, not URL + // return the embed code directly. + if (preg_match('/^.*/i', $item['embed'])) { return $item['embed']; } @@ -82,14 +82,15 @@ function theme_emaudio_soundcloud_flash($item, $embed, $width, $height, $autopla if ($item['data']['emaudio_soundcloud_version'] >= 1) { $id = form_clean_id('soundcloud'); $autoplay = $autoplay ? '&auto_play=true' : ''; - $output .= << - - - - - -SOUNDCLOUDEMBED; + $swf = 'http://soundcloud.com/oembed?url=http://soundcloud.com/'. urldecode($item['data']['swf']); + $xml = drupal_http_request($swf); + if (($xml->code) == 200) { // code 200 assumes successful query of the soundcloud servers + $xml = new SimpleXmlElement($xml->data); + $output = (string)$xml->html; + } + else { // any code but 200 we'll assume is an error + $output = 'SoundCloud server returned an ERROR: ' . $xml->code . ' ' . $xml->status_message; + } } } @@ -111,8 +112,9 @@ function emaudio_soundcloud_data($field, $item) { $patterns = array(); $h1tags = preg_match('/()/i', $response->data, $patterns); $data['player'] = isset($patterns[2]) ? explode('&', $patterns[2]) : NULL; - $data['swf'] = isset($data['player'][0]) ? $data['player'][0] : NULL; + $data['swf'] = $item['value']; } + return $data; } @@ -181,7 +183,7 @@ function emaudio_soundcloud_preview($embed, $width, $height, $field, $item, &$no * Implementation of hook_emfield_subtheme. */ function emaudio_soundcloud_emfield_subtheme() { - return array ( + return array( 'emaudio_soundcloud_flash' => array( 'arguments' => array('item' => NULL, 'embed' => NULL, 'width' => NULL, 'height' => NULL, 'autoplay' => NULL), 'file' => 'providers/soundcloud.inc'