* AudioBoo (3 different players) * http://(audio)?boo.fm/boos/* * AudioBooProvider * * * @author Grischa Brockhaus * */ class AudioBooProvider extends EmbedProvider { /** * This is the main function calling the Posterous postly API and converting it into a OEmbed object * @param string $url post.ly url * @return OEmbed the embed object */ public function getEmbed($url){ // http://audioboo.fm/boos/649785-ein-erster-testboo if(preg_match("/audioboo\.fm\/boos\/(\d+)-/",$url,$matches) || preg_match("/boo\.fm\/boos\/(\d+)-/",$url,$matches)){ $boo_id=$matches[1]; } if (empty($boo_id)) return null; $api_fetch = "http://api.audioboo.fm/audio_clips/" . $boo_id . ".xml"; $xml = simplexml_load_file($api_fetch); if (!isset($xml) && !isset($xml->body)) return null; $audioboo = $xml->body; if (isset($audioboo->error)) return null; if (!isset($audioboo->audio_clip)) return null; $audio = $audioboo->audio_clip; $detail_url = (string)$audio->urls->detail; $detail_enc = urlencode($detail_url); $title = (string)$audio->title; $title_enc = urlencode($title); $time = (string)$audio->recorded_at; $time = str_ireplace("T", " ", $time); $time = str_ireplace("Z", "", $time); $time_enc = urlencode($time); $username = (string)$audio->user->username; $tpl_wordpress = '' . $title .' (mp3)'; $tpl_fullfeatured = '
listen to ‘' . $title. '’ on Audioboo
'; $tpl_standard = ''; if (is_array($this->config)) { $tpls = array( 'standard' => $tpl_standard, 'wordpress' => $tpl_wordpress, 'fullfeatured' => $tpl_fullfeatured ); $tpl = $tpls[$this->config['audioboo_tpl']]; } if (empty($tpl)) $tpl = $tpl_wordpress; $oembed = new RichEmbed(); $oembed->type='rich'; $oembed->html = $tpl; $oembed->width='400'; $oembed->height='129'; $oembed->url=$detail_url; $oembed->version='1.0'; $oembed->provider_name="AudioBoo"; $oembed->provider_url="http://audioboo.fm"; $oembed->resource_url=$detail_url .'.mp3'; $oembed->title = $title; //$oembed->html = $post->body; $oembed->author_name = $username; return $oembed; } // === here comes the regular stuff for providers, what is very similar in any custom provider ========= private function provideXML($url){ $string=""; $oembed = $this->getEmbed($url); if (isset($oembed)) { foreach($this->getEmbed($url) as $key=>$value){ if(isset($value)&& $value!="") $string.=" <".$key.">".$value."\n"; } $string="\n".$string.""; } return $string; } private function provideObject($url){ return $this->getEmbed($url); } private function provideJSON($url){ $oembed = $this->getEmbed($url); if (isset($oembed)) return json_encode($this->getEmbed($url)); else return null; } private function provideSerialized($url){ $oembed = $this->getEmbed($url); if (isset($oembed)) return serialize($this->getEmbed($url)); else return null; } public function provide($url,$format="json"){ if($format=="xml"){ return $this->provideXML($url); } else if ($format=="object"){ return $this->provideObject($url); } else if ($format=="serialized"){ return $this->provideSerialized($url); } else { return $this->provideJSON($url);; } } public function match($url) { return preg_match('/audioboo\.fm\/boos\/(\d+)/',$url) || preg_match('/boo\.fm\/boos\/(\d+)/',$url); } /** * Constructor * Enter description here ... * @param simplexml $config holds the entry in the providers.xml for this Provider. You can add more parameters parsed here */ public function __construct($config){ parent::__construct("http://boo.fm/boo",""); } }