OEmbed entities templatable
This commit is contained in:
parent
56854a6a53
commit
46fda7303d
|
@ -6,13 +6,16 @@ class OEmbedDatabase {
|
|||
|
||||
function save_oembed($url, $oembed) {
|
||||
if (empty($url) || !isset($oembed)) return false;
|
||||
if (isset($oembed->html)) {
|
||||
$oembed->html = OEmbedDatabase::cleanup_html($oembed->html);
|
||||
}
|
||||
$save = array();
|
||||
$save['urlmd5'] = md5($url);
|
||||
$save['url'] = $url;
|
||||
$save['oetype'] = $oembed->type;
|
||||
$save['oeobj'] = serialize($oembed);
|
||||
return serendipity_db_insert( PLUGIN_OEMBED_DATABASEVNAME, $save );
|
||||
|
||||
serendipity_db_insert( PLUGIN_OEMBED_DATABASEVNAME, $save );
|
||||
return $oembed;
|
||||
}
|
||||
|
||||
function load_oembed($url) {
|
||||
|
@ -76,4 +79,15 @@ class OEmbedDatabase {
|
|||
}
|
||||
}
|
||||
|
||||
function cleanup_html( $str ) {
|
||||
// Clear unicode stuff
|
||||
$str=str_ireplace("\u003C","<",$str);
|
||||
$str=str_ireplace("\u003E",">",$str);
|
||||
// Clear CDATA Trash.
|
||||
$str = preg_replace("@^<!\[CDATA\[(.*)]]>$@", '$1', $str);
|
||||
$str = preg_replace("@^<!\[CDATA\[(.*)$@", '$1', $str);
|
||||
$str = preg_replace("@(.*)]]>$@", '$1', $str);
|
||||
return $str;
|
||||
}
|
||||
|
||||
}
|
21
serendipity_event_oembed/OEmbedTemplater.php
Normal file
21
serendipity_event_oembed/OEmbedTemplater.php
Normal file
|
@ -0,0 +1,21 @@
|
|||
<?php
|
||||
class OEmbedTemplater {
|
||||
/* get the right template path - as default in template folder or the fallback plugin folder */
|
||||
function fetchTemplate($filename, $oembed, $url) {
|
||||
global $serendipity;
|
||||
|
||||
// Declare the oembed to smarty
|
||||
$serendipity['smarty']->assign('oembedurl',$url);
|
||||
$serendipity['smarty']->assign('oembed',(array)$oembed);
|
||||
$tfile = serendipity_getTemplateFile($filename, 'serendipityPath');
|
||||
if (!$tfile || $filename == $tfile) {
|
||||
$tfile = dirname(__FILE__) . '/' . $filename;
|
||||
}
|
||||
$inclusion = $serendipity['smarty']->security_settings[@INCLUDE_ANY];
|
||||
$serendipity['smarty']->security_settings[@INCLUDE_ANY] = true;
|
||||
// be smarty 3 compat including the serendipity_smarty class wrappers ->fetch and ->display methods and remove changed parameter number 4
|
||||
$content = $serendipity['smarty']->fetch('file:'. $tfile);//, false
|
||||
$serendipity['smarty']->security_settings[@INCLUDE_ANY] = $inclusion;
|
||||
return $content;
|
||||
}
|
||||
}
|
|
@ -8,3 +8,12 @@
|
|||
|
||||
@define('PLUGIN_EVENT_OEMBED_NAME', 'oEmbed Plugin');
|
||||
@define('PLUGIN_EVENT_OEMBED_DESC', 'oEmbed is a format for allowing an embedded representation of a URL on your blog. It allows blog articles to display embedded content (such as tweets, photos or videos) when a user posts a link to that resource, without having to parse the resource directly.');
|
||||
@define('PLUGIN_EVENT_OEMBED_INFO', '<h3>oEmbed Plugin</h3>' .
|
||||
'<p>'.
|
||||
'This plugin expands URLs to pages of known services to a representation of that URL. It shows i.e. the video for a youtube URL or the image instead of a flickr URL.<br/>' .
|
||||
'The syntax for this plugin is <b>[embed <i>link</i>]</b>. If the link is not supported by the plugin at the moment, it will replace the URL by a link pointing to that URL.<br/>'.
|
||||
'</p><p>'.
|
||||
'Please put this plugin at the top of your plugins list, so no other plugin can change this syntax (by adding a href i.e.)'.
|
||||
'</p><p>'.
|
||||
'The plugin supports representations of the following link types:%s'.
|
||||
'</p>');
|
||||
|
|
16
serendipity_event_oembed/oembed.tpl
Normal file
16
serendipity_event_oembed/oembed.tpl
Normal file
|
@ -0,0 +1,16 @@
|
|||
{* oembed.tpl last modified 2011-12-01 *}
|
||||
<span class="serendipity_oembed">
|
||||
{if $oembed.type=='rich'}
|
||||
{$oembed.html}
|
||||
{elseif $oembed.type=='video'}
|
||||
{$oembed.html}
|
||||
{elseif $oembed.type=='image'}
|
||||
<a href="{$oembed.url}"><img src="{$oembed.thumbnail_url}"/></a>
|
||||
{elseif $oembed.type=='photo'}
|
||||
<img src="{$oembed.url}"/>
|
||||
{elseif $oembed.type=='link'}
|
||||
<a href="{$oembedurl}" title="{$oembed.title}">{$oembed.author_name}</a>
|
||||
{else}
|
||||
<a href="{$oembedurl}">{$oembedurl}</a>
|
||||
{/if}
|
||||
</span>
|
|
@ -34,6 +34,7 @@ class OEmbedProvider extends EmbedProvider{
|
|||
}
|
||||
private function getTypeObj($type){
|
||||
switch($type){
|
||||
case "image":
|
||||
case "photo":
|
||||
return new PhotoEmbed();
|
||||
break;
|
||||
|
|
18
serendipity_event_oembed/oembed/ProviderList.php
Normal file
18
serendipity_event_oembed/oembed/ProviderList.php
Normal file
|
@ -0,0 +1,18 @@
|
|||
<?php
|
||||
class ProviderList {
|
||||
function ul_providernames($with_url=false) {
|
||||
$provider_names = array();
|
||||
$xml = simplexml_load_file(PLUGIN_OEMBED_PROVIDER_XML_FILE);// PROVIDER_XML comes from config.php
|
||||
foreach($xml->provider as $provider){
|
||||
if (isset($provider->name)) {
|
||||
$pentry = $provider->name;
|
||||
if ($with_url && isset($provider->url)) {
|
||||
$pentry = "<b>$pentry</b><br/>(" . $provider->url . ")";
|
||||
}
|
||||
$provider_names[] = $pentry;
|
||||
}
|
||||
}
|
||||
natsort($provider_names);
|
||||
return "<ol><li>" . implode("</li><li>", $provider_names) . "</li></ol>";
|
||||
}
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
<?xml version="1.0"?>
|
||||
<providers>
|
||||
<provider>
|
||||
<name>Flickr (image and video)</name>
|
||||
<url>http://*.flickr.com/*</url>
|
||||
<endpoint>http://www.flickr.com/services/oembed/</endpoint>
|
||||
</provider>
|
||||
|
@ -11,7 +12,8 @@
|
|||
</provider>
|
||||
-->
|
||||
<provider>
|
||||
<url>https://*.twitter.com/*</url>
|
||||
<name>Twitter Status</name>
|
||||
<url>https://*.twitter.com/*/status/*</url>
|
||||
<endpoint>https://api.twitter.com/1/statuses/oembed.{format}</endpoint>
|
||||
</provider>
|
||||
<provider>
|
||||
|
@ -25,23 +27,76 @@
|
|||
</provider>
|
||||
-->
|
||||
<provider>
|
||||
<name>Youtube</name>
|
||||
<url>http://*.youtube.com/*</url>
|
||||
<endpoint>http://www.youtube.com/oembed</endpoint>
|
||||
</provider>
|
||||
<provider>
|
||||
<name>Youtube short link</name>
|
||||
<url>http://*.youtu.be/*</url>
|
||||
<endpoint>http://www.youtube.com/oembed</endpoint>
|
||||
</provider>
|
||||
|
||||
<provider>
|
||||
<name>Official.fm (tracks and playlist)</name>
|
||||
<url>http://official.fm/(playlists|tracks)/*</url>
|
||||
<endpoint>http://official.fm/services/oembed.{format}</endpoint>
|
||||
</provider>
|
||||
|
||||
<provider>
|
||||
<name>Blib TV</name>
|
||||
<url>http://blip.tv/*</url>
|
||||
<jsononly/>
|
||||
<endpoint>http://blip.tv/oembed</endpoint>
|
||||
</provider>
|
||||
|
||||
<provider>
|
||||
<name>My Opera</name>
|
||||
<url>http://my.opera.com/*</url>
|
||||
<endpoint>http://my.opera.com/service/oembed</endpoint>
|
||||
</provider>
|
||||
|
||||
<provider>
|
||||
<name>Hulu</name>
|
||||
<url>http://www.hulu.com/*</url>
|
||||
<endpoint>http://www.hulu.com/api/oembed.{format}</endpoint>
|
||||
</provider>
|
||||
<provider>
|
||||
<name>Revision 3</name>
|
||||
<url>http://*.revision3.com/*</url>
|
||||
<endpoint>http://revision3.com/api/oembed/</endpoint>
|
||||
</provider>
|
||||
<provider>
|
||||
<name>Viddler</name>
|
||||
<url>http://*.viddler.com/*</url>
|
||||
<endpoint>http://lab.viddler.com/services/oembed/</endpoint>
|
||||
</provider>
|
||||
|
||||
<provider>
|
||||
<name>YFrog</name>
|
||||
<jsononly/>
|
||||
<url>http://*.yfrog.com/*</url>
|
||||
<endpoint>http://www.yfrog.com/api/oembed</endpoint>
|
||||
</provider>
|
||||
|
||||
<provider>
|
||||
<name>DailyMotion</name>
|
||||
<url>http://*.dailymotion.com/*</url>
|
||||
<endpoint>http://www.dailymotion.com/services/oembed</endpoint>
|
||||
</provider>
|
||||
|
||||
<provider>
|
||||
<name>PicPlz</name>
|
||||
<jsononly/>
|
||||
<url>http://*.picplz.com/*</url>
|
||||
<endpoint>http://picplz.com/oembed</endpoint>
|
||||
</provider>
|
||||
|
||||
<provider>
|
||||
<name>SoundCloud</name>
|
||||
<url>http://*.soundcloud.com/*</url>
|
||||
<endpoint>http://soundcloud.com/oembed</endpoint>
|
||||
</provider>
|
||||
|
||||
</providers>
|
||||
|
||||
|
|
|
@ -11,8 +11,10 @@ if (file_exists($probelang)) {
|
|||
}
|
||||
|
||||
include dirname(__FILE__) . '/lang_en.inc.php';
|
||||
require_once dirname(__FILE__) . '/oembed/config.php'; // autoload oembed classes
|
||||
require_once dirname(__FILE__) . '/oembed/config.php'; // autoload oembed classes and config
|
||||
require_once dirname(__FILE__) . '/OEmbedDatabase.php';
|
||||
require_once dirname(__FILE__) . '/OEmbedTemplater.php';
|
||||
require_once dirname(__FILE__) . '/oembed/ProviderList.php';
|
||||
|
||||
|
||||
class serendipity_event_oembed extends serendipity_event
|
||||
|
@ -48,7 +50,7 @@ class serendipity_event_oembed extends serendipity_event
|
|||
switch($name) {
|
||||
case 'info':
|
||||
$propbag->add('type', 'content');
|
||||
$propbag->add('default', "Info");
|
||||
$propbag->add('default', sprintf(PLUGIN_EVENT_OEMBED_INFO, ProviderList::ul_providernames(true)));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -94,7 +96,7 @@ class serendipity_event_oembed extends serendipity_event
|
|||
$eventData['body']);
|
||||
}
|
||||
if (!empty($eventData['extended'])) {
|
||||
$eventData['body'] = preg_replace_callback(
|
||||
$eventData['extended'] = preg_replace_callback(
|
||||
$patterns['simpleTweet'],
|
||||
array( $this, "oembedRewriteCallback"),
|
||||
$eventData['extended']);
|
||||
|
@ -110,30 +112,26 @@ class serendipity_event_oembed extends serendipity_event
|
|||
try {
|
||||
$obj=$manager->provide($url,"object");
|
||||
if (isset($obj)) {
|
||||
OEmbedDatabase::save_oembed($url,$obj);
|
||||
$obj = OEmbedDatabase::save_oembed($url,$obj);
|
||||
}
|
||||
}
|
||||
catch (ErrorException $e) {
|
||||
print "Loading online url ex $e ..\n";
|
||||
// Timeout in most cases
|
||||
return $e;
|
||||
//return $e;
|
||||
}
|
||||
}
|
||||
if (!empty($obj)) {
|
||||
if ($obj->type == 'rich')
|
||||
$html = $obj->html;
|
||||
elseif ($obj->type == 'video')
|
||||
$html = $obj->html;
|
||||
elseif ($obj->type == 'photo') {
|
||||
$html = '<img src="' . $obj->url . '" title="' .$obj->title . '" alt="' .$obj->title . '"/>';
|
||||
}
|
||||
}
|
||||
else {
|
||||
$html = '<a href="' . $match[1] . '">' . $match[1] . '</a>';
|
||||
}
|
||||
return '<span class="serendipity_oembed">' . $html . '</span>';
|
||||
return OEmbedTemplater::fetchTemplate('oembed.tpl',$obj, $url);
|
||||
}
|
||||
function cleanup_html( $str ) {
|
||||
// Clear unicode stuff
|
||||
$str=str_ireplace("\u003C","<",$str);
|
||||
$str=str_ireplace("\u003E",">",$str);
|
||||
// Clear CDATA Trash.
|
||||
$str = preg_replace("@^<!\[CDATA\[(.*)]]>$@", '$1', $str);
|
||||
$str = preg_replace("@^<!\[CDATA\[(.*)$@", '$1', $str);
|
||||
$str = preg_replace("@(.*)]]>$@", '$1', $str);
|
||||
return $str;
|
||||
}
|
||||
|
||||
function cleanup() {
|
||||
OEmbedDatabase::install($this);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue