plugin_oembed:

New AudioBoo resolver supporting the 3 different players of AudioBoo
(configurable wich).
The old "wordpress player" is default for backwards compatibility reason
This commit is contained in:
Grischa Brockhaus 2012-02-03 01:42:31 +01:00
parent c2581d945a
commit f4885a0d52
7 changed files with 182 additions and 51 deletions

View file

@ -1,3 +1,8 @@
Version 1.06 (brockhaus)
-----------------------
* New AudioBoo resolver supporting the 3 different players of AudioBoo (configurable wich).
The old "wordpress player" is default for backwards compatibility reason.
Version 1.05 (brockhaus)
-----------------------
* Better handling of unparsable oembed results (like youtube links not allowed to embed).

View file

@ -33,4 +33,11 @@
@define('PLUGIN_EVENT_OEMBED_SUPPORTED', '<p>'.
'The plugin supports representations of the following link types without the need of the generic fallback:%s'.
'</p>');
'</p>');
// new entries 2012-02-03
@define('PLUGIN_EVENT_OEMBED_PLAYER_BOO', 'Audioboo player');
@define('PLUGIN_EVENT_OEMBED_PLAYER_BOO_DESC', 'Audioboo supports 3 different players (see http://audioboo.fm/boos/649785-ein-erster-testboo.embed?labs=1). Choose the one you like most.');
@define('PLUGIN_EVENT_OEMBED_PLAYER_BOO_STANDARD', 'standard player');
@define('PLUGIN_EVENT_OEMBED_PLAYER_BOO_FULLFEATURED', 'full-featured (requires JavaScript)');
@define('PLUGIN_EVENT_OEMBED_PLAYER_BOO_WORDPRESS', 'wordpress.com player (requires Flash)');

View file

@ -4,6 +4,7 @@ abstract class EmbedProvider {
public $endpoint;
public $maxwidth;
public $maxheight;
public $config;
public abstract function match($url);
public abstract function provide($url,$format="json");
// public abstract function register();
@ -13,4 +14,7 @@ abstract class EmbedProvider {
$this->maxwidth = $maxwidth;
$this->maxheight = $maxheight;
}
public function set_config($config) {
$this->config = $config;
}
}

View file

@ -2,8 +2,10 @@
class ProviderManager{
private $providers;
private static $_instance;
private function __construct($maxwidth=null, $maxheight=null){
private $config;
private function __construct($maxwidth=null, $maxheight=null, $config = array()){
$this->providers=array();
$this->config = $config;
$xml = simplexml_load_file(PLUGIN_OEMBED_PROVIDER_XML_FILE);// PROVIDER_XML comes from config.php
foreach($xml->provider as $provider){
if(!isset($provider->class) && isset($provider->endpoint)){
@ -17,13 +19,14 @@ class ProviderManager{
}
}
}
static function getInstance($maxwidth=null, $maxheight=null){
static function getInstance($maxwidth=null, $maxheight=null, $config = array()){
if(!isset($_instance) || $_instance==null){
$_instance = new ProviderManager($maxwidth, $maxheight);
$_instance = new ProviderManager($maxwidth, $maxheight, $config);
}
return $_instance;
}
public function register($provider){
if (!empty($this->config)) $provider->set_config($this->config);
$this->providers[]=$provider;
}
public function provide($url,$format){

View file

@ -0,0 +1,133 @@
<?php
/**
* This is a kind of example class how to do a oembed provider for a service, that doesn't support oembed.
* This provider reads the Posterous API to resolve post.ly links. If the result is an image or a video, the XML result
* will be converted as an OEmbed
*
* Converting is done in the getEmbed function. This is the main code.
* Everything else is only type converting that should be nearly the same in any custom provider
*
* All *.class.php files found in the customs directory will be included automatically
*
* After implementing the provider you have to add it to the providers.xml like this:
* <provider>
* <name>Posterous post.ly</name>
* <url>http://post.ly/*</url>
* <class>PostlyProvider</class>
* </provider>
*
* @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 = '<object data="http://abfiles.s3.amazonaws.com/swf/fullsize_player.swf" height="129" id="boo_embed_' . $boo_id .'" type="application/x-shockwave-flash" width="400"><param name="movie" value="http://abfiles.s3.amazonaws.com/swf/fullsize_player.swf" /><param name="scale" value="noscale" /><param name="salign" value="lt" /><param name="bgColor" value="#FFFFFF" /><param name="allowScriptAccess" value="always" /><param name="wmode" value="window" /><param name="FlashVars" value="mp3=' . $detail_enc .'.mp3%3Fkeyed%3Dtrue%26source%3Dembed&amp;mp3Title=' . $title_enc . '&amp;mp3Time=' . $time_enc . '&amp;mp3LinkURL=' .$detail_enc . '&amp;mp3Author=gbrockhaus&amp;rootID=boo_embed_' . $boo_id . ' " /><a href="' . $detail_url . '.mp3?keyed=true&amp;source=embed">' . $title .' (mp3)</a></object>';
$tpl_fullfeatured = '<div class="ab-player" data-boourl="' . $detail_url . '/embed"><a href="' . $detail_url . '">listen to &lsquo;' . $title. '&rsquo; on Audioboo</a></div>
<script type="text/javascript">(function() { var po = document.createElement("script"); po.type = "text/javascript"; po.async = true; po.src = "http://d15mj6e6qmt1na.cloudfront.net/assets/embed.js"; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(po, s); })();</script>';
$tpl_standard = '<iframe style="margin: 0px; padding: 0px; border: none; display: block; max-width:100%; width: 1000px; height: 145px;" allowtransparency="allowtransparency" cellspacing="0" frameborder="0" hspace="0" marginheight="0" marginwidth="0" scrolling="no" vspace="0" src="' . $detail_url . '/embed" title="Audioboo player"></iframe>';
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."</".$key.">\n";
}
$string="<oembed>\n".$string."</oembed>";
}
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","");
}
}

View file

@ -126,6 +126,11 @@
<url>http://post.ly/*</url>
<class>PostlyProvider</class>
</provider>
<provider>
<name>AudioBoo (3 different players)</name>
<url>http://(audio)?boo.fm/boos/*</url>
<class>AudioBooProvider</class>
</provider>
<!-- noembed providers =========================================== -->
@ -141,14 +146,6 @@
<url>http://imgur.com/*</url>
<endpoint>http://noembed.com/embed</endpoint>
</provider>
<!--
<provider>
<name>Imdb.com (via noembed.com)</name>
<jsononly/>
<url>http://(www.)?imdb.com/title/*</url>
<endpoint>http://noembed.com/embed</endpoint>
</provider>
-->
<provider>
<name>CloudApp (via noembed.com)</name>
<jsononly/>
@ -191,35 +188,4 @@
<url>http://(www.)?beeradvocate.com/beer/profile/*</url>
<endpoint>http://noembed.com/embed</endpoint>
</provider>
<!-- Too big for blogs
<provider>
<name>Amazon.com (via noembed.com)</name>
<jsononly/>
<url>https?://www.(amazon|amzn).com/*</url>
<endpoint>http://noembed.com/embed</endpoint>
</provider>
-->
<!-- oohembed.com providers -->
<!--
<provider>
<name>Audioboo (via oohembed.com)</name>
<jsononly/>
<url>http://((www.)?audio)?boo.fm/boos/*</url>
<endpoint>http://oohembed.com/oohembed/</endpoint>
</provider>
<provider>
<name>Wikipedia (via oohembed.com)</name>
<jsononly/>
<url>https?://*.wikipedia.org/wiki/*</url>
<endpoint>http://oohembed.com/oohembed/</endpoint>
</provider>
<provider>
<name>Imdb.com (via oohembed.com)</name>
<jsononly/>
<url>http://(www.)?imdb.com/title/*</url>
<endpoint>http://oohembed.com/oohembed/</endpoint>
</provider>
-->
</providers>

View file

@ -30,7 +30,7 @@ class serendipity_event_oembed extends serendipity_event
$propbag->add('description', PLUGIN_EVENT_OEMBED_DESC);
$propbag->add('stackable', false);
$propbag->add('author', 'Grischa Brockhaus');
$propbag->add('version', '1.05');
$propbag->add('version', '1.06');
$propbag->add('requirements', array(
'serendipity' => '0.8',
'smarty' => '2.6.7',
@ -41,18 +41,13 @@ class serendipity_event_oembed extends serendipity_event
'frontend_display' => true,
'css' => true,
));
$configuration = $configuration = array('info','maxwidth','maxheight','generic_service','embedly_apikey');
$configuration = $configuration = array('info','maxwidth','maxheight','generic_service','embedly_apikey', 'audioboo_player');
$configuration[] = 'supported'; // always last
$propbag->add('configuration', $configuration);
}
function introspect_config_item($name, &$propbag)
{
$generic_services = array (
'none' => PLUGIN_EVENT_OEMBED_SERVICE_NONE,
'oohembed' => PLUGIN_EVENT_OEMBED_SERVICE_OOHEMBED,
'embedly' => PLUGIN_EVENT_OEMBED_SERVICE_EMBEDLY,
);
switch($name) {
case 'info':
$propbag->add('type', 'content');
@ -71,12 +66,29 @@ class serendipity_event_oembed extends serendipity_event
$propbag->add('default', '');
break;
case 'generic_service':
$generic_services = array (
'none' => PLUGIN_EVENT_OEMBED_SERVICE_NONE,
'oohembed' => PLUGIN_EVENT_OEMBED_SERVICE_OOHEMBED,
'embedly' => PLUGIN_EVENT_OEMBED_SERVICE_EMBEDLY,
);
$propbag->add('type', 'select');
$propbag->add('name', PLUGIN_EVENT_OEMBED_GENERIC_SERVICE);
$propbag->add('description', PLUGIN_EVENT_OEMBED_GENERIC_SERVICE_DESC);
$propbag->add('select_values', $generic_services);
$propbag->add('default', 'oohembed');
break;
case 'audioboo_player':
$player_boo = array (
'standard' => PLUGIN_EVENT_OEMBED_PLAYER_BOO_STANDARD,
'fullfeatured' => PLUGIN_EVENT_OEMBED_PLAYER_BOO_FULLFEATURED,
'wordpress' => PLUGIN_EVENT_OEMBED_PLAYER_BOO_WORDPRESS,
);
$propbag->add('type', 'select');
$propbag->add('name', PLUGIN_EVENT_OEMBED_PLAYER_BOO);
$propbag->add('description', PLUGIN_EVENT_OEMBED_PLAYER_BOO_DESC);
$propbag->add('select_values', $player_boo);
$propbag->add('default', 'wordpress');
break;
case 'embedly_apikey':
$propbag->add('type', 'string');
$propbag->add('name', PLUGIN_EVENT_OEMBED_EMBEDLY_APIKEY);
@ -173,7 +185,8 @@ class serendipity_event_oembed extends serendipity_event
function expand($url, $maxwidth=null, $maxheight=null) {
$obj = OEmbedDatabase::load_oembed($url);
if (empty($obj)) {
$manager = ProviderManager::getInstance($maxwidth,$maxheight);
$config = array('audioboo_tpl' => $this->get_config('audioboo_player', 'wordpress'));
$manager = ProviderManager::getInstance($maxwidth,$maxheight,$config);
try {
$obj=$manager->provide($url,"object");
if (!isset($obj)) {