diff --git a/serendipity_event_oembed/OEmbedDatabase.php b/serendipity_event_oembed/OEmbedDatabase.php index 858dc444..d5eda746 100644 --- a/serendipity_event_oembed/OEmbedDatabase.php +++ b/serendipity_event_oembed/OEmbedDatabase.php @@ -42,6 +42,11 @@ class OEmbedDatabase { } return null; } + function clear_cache() { + global $serendipity; + $q = "delete from {$serendipity['dbPrefix']}" . PLUGIN_OEMBED_DATABASEVNAME; + serendipity_db_schema_import($q); + } function install(&$obj) { global $serendipity; @@ -80,6 +85,7 @@ class OEmbedDatabase { } function cleanup_html( $str ) { + $str = trim($str); // Clear unicode stuff $str=str_ireplace("\u003C","<",$str); $str=str_ireplace("\u003E",">",$str); diff --git a/serendipity_event_oembed/lang_en.inc.php b/serendipity_event_oembed/lang_en.inc.php index 1f787309..04f0f325 100755 --- a/serendipity_event_oembed/lang_en.inc.php +++ b/serendipity_event_oembed/lang_en.inc.php @@ -8,6 +8,10 @@ @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_EXPAND_TWEETBACKS', 'Expand tweetbacks'); +@define('PLUGIN_EVENT_OEMBED_EXPAND_TWEETBACKS_DESC', 'If enabled the plugin will detect tweetbacks and set their content to the oEmbed content delivered from twitter.'); +*/ @define('PLUGIN_EVENT_OEMBED_INFO', '

oEmbed Plugin

' . '

'. '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.
' . diff --git a/serendipity_event_oembed/oembed.tpl b/serendipity_event_oembed/oembed.tpl index 41a1b167..b40818bd 100644 --- a/serendipity_event_oembed/oembed.tpl +++ b/serendipity_event_oembed/oembed.tpl @@ -5,12 +5,12 @@ {elseif $oembed.type=='video'} {$oembed.html} {elseif $oembed.type=='image'} - +{$oembed.title} {elseif $oembed.type=='photo'} - +{$oembed.title} {elseif $oembed.type=='link'} {$oembed.author_name} {else} -{$oembedurl} +{$oembedurl} {/if} \ No newline at end of file diff --git a/serendipity_event_oembed/oembed/EmbedProvider.class.php b/serendipity_event_oembed/oembed/EmbedProvider.class.php index ad94760c..5187d849 100644 --- a/serendipity_event_oembed/oembed/EmbedProvider.class.php +++ b/serendipity_event_oembed/oembed/EmbedProvider.class.php @@ -2,11 +2,15 @@ abstract class EmbedProvider { public $url; public $endpoint; + public $maxwidth; + public $maxheight; public abstract function match($url); public abstract function provide($url,$format="json"); // public abstract function register(); - public function __construct($url,$endpoint){ + public function __construct($url,$endpoint, $maxwidth=null, $maxheight=null){ $this->url = $url; $this->endpoint = $endpoint; + $this->maxwidth = $maxwidth; + $this->maxheight = $maxheight; } } diff --git a/serendipity_event_oembed/oembed/OEmbedProvider.class.php b/serendipity_event_oembed/oembed/OEmbedProvider.class.php index af7ce783..b78125b7 100644 --- a/serendipity_event_oembed/oembed/OEmbedProvider.class.php +++ b/serendipity_event_oembed/oembed/OEmbedProvider.class.php @@ -3,12 +3,14 @@ class OEmbedProvider extends EmbedProvider{ private $urlRegExp; private $jsonEndpoint; private $xmlEndpoint; + private $dimensionsSupported = true; private $onlyJson = false; - public function __construct($url,$endpoint, $onlyJson=false){ - parent::__construct($url,$endpoint); + public function __construct($url,$endpoint, $onlyJson=false, $maxwidth=null, $maxheight=null, $dimensionsSupported=true){ + parent::__construct($url,$endpoint,$maxwidth,$maxheight); $this->onlyJson = $onlyJson; + $this->dimensionsSupported = $dimensionsSupported; $this->urlRegExp=preg_replace(array("/\*/","/\//","/\.\*\./"),array(".*","\/",".*"),$url); $this->urlRegExp="/".$this->urlRegExp."/"; if (preg_match("/\{format\}/",$endpoint)){ @@ -20,6 +22,16 @@ class OEmbedProvider extends EmbedProvider{ $this->jsonEndpoint=$endpoint."?url={url}&format=json"; $this->xmlEndpoint=$endpoint."?url={url}&format=xml"; } + if ($this->dimensionsSupported) { + if (!empty($this->maxwidth)) { + $this->jsonEndpoint.= '&maxwidth=' . $this->maxwidth; + $this->xmlEndpoint.= '&maxwidth=' . $this->maxwidth; + } + if (!empty($this->maxheight)) { + $this->jsonEndpoint.= '&maxwidth=' . $this->maxheight; + $this->xmlEndpoint.= '&maxwidth=' . $this->maxheight; + } + } } public function getUrlRegExp(){ return $this->urlRegExp; } diff --git a/serendipity_event_oembed/oembed/ProviderManager.class.php b/serendipity_event_oembed/oembed/ProviderManager.class.php index a2df7618..92691a08 100644 --- a/serendipity_event_oembed/oembed/ProviderManager.class.php +++ b/serendipity_event_oembed/oembed/ProviderManager.class.php @@ -2,13 +2,14 @@ class ProviderManager{ private $providers; private static $_instance; - private function __construct(){ + private function __construct($maxwidth=null, $maxheight=null){ $this->providers=array(); $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)){ $onlyJson = isset($provider->jsononly); - $this->register(new OEmbedProvider($provider->url,$provider->endpoint, $onlyJson)); + $dimensionsSupported = !isset($provider->nodimensionsupport); + $this->register(new OEmbedProvider($provider->url,$provider->endpoint, $onlyJson, $maxwidth, $maxheight, $dimensionsSupported)); } else { $classname="".$provider->class; // force to be string :) $reflection = new ReflectionClass($classname); @@ -16,9 +17,9 @@ class ProviderManager{ } } } - static function getInstance(){ + static function getInstance($maxwidth=null, $maxheight=null){ if(!isset($_instance) || $_instance==null){ - $_instance = new ProviderManager(); + $_instance = new ProviderManager($maxwidth, $maxheight); } return $_instance; } diff --git a/serendipity_event_oembed/oembed/YouTubeProvider.class.php b/serendipity_event_oembed/oembed/YouTubeProvider.class.php index 2bf03ec4..d7797a0b 100644 --- a/serendipity_event_oembed/oembed/YouTubeProvider.class.php +++ b/serendipity_event_oembed/oembed/YouTubeProvider.class.php @@ -74,7 +74,7 @@ class YouTubeProvider extends EmbedProvider { } - public function __construct($config){ - parent::__construct("http://youtube.com",""); + public function __construct($config,$maxwidth=null, $maxheight=null){ + parent::__construct("http://youtube.com","", $maxwidth, $maxheight); } } diff --git a/serendipity_event_oembed/oembed/providers.xml b/serendipity_event_oembed/oembed/providers.xml index 629a871a..04e8eb4e 100644 --- a/serendipity_event_oembed/oembed/providers.xml +++ b/serendipity_event_oembed/oembed/providers.xml @@ -13,7 +13,7 @@ --> Twitter Status - https://*.twitter.com/*/status/* + https?://*.twitter.com/*/status(es)?/* https://api.twitter.com/1/statuses/oembed.{format} @@ -52,6 +52,7 @@ My Opera + http://my.opera.com/* http://my.opera.com/service/oembed @@ -79,6 +80,13 @@ http://www.yfrog.com/api/oembed + + Instragr.am + + http://*.instagr.am/* + http://api.instagram.com/api/v1/oembed/ + + DailyMotion http://*.dailymotion.com/* diff --git a/serendipity_event_oembed/serendipity_event_oembed.php b/serendipity_event_oembed/serendipity_event_oembed.php index b98e42fa..0d115374 100644 --- a/serendipity_event_oembed/serendipity_event_oembed.php +++ b/serendipity_event_oembed/serendipity_event_oembed.php @@ -37,12 +37,10 @@ class serendipity_event_oembed extends serendipity_event )); $propbag->add('groups', array('FRONTEND_EXTERNAL_SERVICES')); $propbag->add('event_hooks', array( -// 'backend_publish' => true, // An entry was puplished (was draft before or saved from the scratch). -// 'backend_save' => true, // An entry was saved. 'frontend_display' => true, )); - - $propbag->add('configuration', array('info')); + $configuration = $configuration = array('info','maxwidth','maxheight'); + $propbag->add('configuration', $configuration); } function introspect_config_item($name, &$propbag) @@ -52,7 +50,20 @@ class serendipity_event_oembed extends serendipity_event $propbag->add('type', 'content'); $propbag->add('default', sprintf(PLUGIN_EVENT_OEMBED_INFO, ProviderList::ul_providernames(true))); break; + case 'maxwidth': + $propbag->add('type', 'string'); + $propbag->add('name', PLUGIN_EVENT_OEMBED_MAXWIDTH); + $propbag->add('description', PLUGIN_EVENT_OEMBED_MAXWIDTH_DESC); + $propbag->add('default', ''); + break; + case 'maxheight': + $propbag->add('type', 'string'); + $propbag->add('name', PLUGIN_EVENT_OEMBED_MAXHEIGHT); + $propbag->add('description', PLUGIN_EVENT_OEMBED_MAXHEIGHT_DESC); + $propbag->add('default', ''); + break; } + return true; } function event_hook($event, &$bag, &$eventData) { @@ -72,14 +83,10 @@ class serendipity_event_oembed extends serendipity_event if (isset($hooks[$event])) { switch($event) { case 'frontend_display': - case 'backend_publish': - case 'backend_save': - if (!isset($eventData['body']) && !isset($eventData['extended'])) { - // Do not use for user comments, html nuggets, static pages etc. - return false; - break; + if (isset($eventData['body']) && isset($eventData['extended'])) { + $this->update_entry($eventData, $simplePatterns, 'body'); + $this->update_entry($eventData, $simplePatterns, 'extended'); } - $this->update_entry($eventData, $simplePatterns); return true; } } @@ -88,27 +95,34 @@ class serendipity_event_oembed extends serendipity_event } - function update_entry(&$eventData, &$patterns) { - if (!empty($eventData['body'])) { - $eventData['body'] = preg_replace_callback( + function update_entry(&$eventData, &$patterns, $dateType) { + if (!empty($eventData[$dateType])) { + $eventData[$dateType] = preg_replace_callback( $patterns['simpleTweet'], array( $this, "oembedRewriteCallback"), - $eventData['body']); - } - if (!empty($eventData['extended'])) { - $eventData['extended'] = preg_replace_callback( - $patterns['simpleTweet'], - array( $this, "oembedRewriteCallback"), - $eventData['extended']); + $eventData[$dateType]); } } function oembedRewriteCallback($match) { $url = $match[1]; + $maxwidth = $this->get_config('maxwidth',''); + $maxheight = $this->get_config('maxheight',''); + $obj = $this->expand($url, $maxwidth, $maxheight); + return OEmbedTemplater::fetchTemplate('oembed.tpl',$obj, $url); + } + + /** + * This method can be used by other plugins. It will expand an URL to an oembed object (or null if not supported). + * @param string $url The url to be expanded + * @param string $maxwidth Maximum width of returned object (if service supports this). May be left empty + * @param string $maxheight Maximum height of returned object (if service supports this). May be left empty + * @return OEmbed or null + */ + function expand($url, $maxwidth=null, $maxheight=null) { $obj = OEmbedDatabase::load_oembed($url); - $html = ''; if (empty($obj)) { - $manager = ProviderManager::getInstance(); + $manager = ProviderManager::getInstance($maxwidth,$maxheight); try { $obj=$manager->provide($url,"object"); if (isset($obj)) { @@ -120,8 +134,9 @@ class serendipity_event_oembed extends serendipity_event //return $e; } } - return OEmbedTemplater::fetchTemplate('oembed.tpl',$obj, $url); + return $obj; } + function cleanup_html( $str ) { // Clear unicode stuff $str=str_ireplace("\u003C","<",$str); @@ -134,6 +149,8 @@ class serendipity_event_oembed extends serendipity_event } function cleanup() { OEmbedDatabase::install($this); + OEmbedDatabase::clear_cache(); + echo '

Cleared oembed cache.
'; } function install() { OEmbedDatabase::install($this); diff --git a/serendipity_plugin_twitter/serendipity_event_twitter.php b/serendipity_plugin_twitter/serendipity_event_twitter.php index 667a875a..7fb6dbf1 100644 --- a/serendipity_plugin_twitter/serendipity_event_twitter.php +++ b/serendipity_plugin_twitter/serendipity_event_twitter.php @@ -625,7 +625,7 @@ class serendipity_event_twitter extends serendipity_plugin { $propbag->add('name', PLUGIN_EVENT_TWITTER_CONSUMER_KEY); $propbag->add('description', PLUGIN_EVENT_TWITTER_CONSUMER_KEY_DESC); $propbag->add('default', ''); - break; + break; case 'general_oa_consumersecret': $propbag->add('type', 'string'); $propbag->add('name', PLUGIN_EVENT_TWITTER_CONSUMER_SECRET); @@ -1245,7 +1245,7 @@ a.twitter_update_time { } if (empty($highest_ids[$article_id]['last_info']) || empty($highest_ids[$article_id]['last_info']['lasttweetid']) || "{$entry[TWITTER_SEARCHRESULT_ID]}">$highest_ids[$article_id]['last_info']['lasttweetid']) { if ($complete) { // This is called from admin interface - echo "Found new tweetback for article $article_id: tweetid: {$entry[TWITTER_SEARCHRESULT_ID]}
"; + echo "
Found new tweetback for article $article_id: tweetid: {$entry[TWITTER_SEARCHRESULT_ID]}

"; } $this->check_tweetbacks_save_comment($article_id, $entry, $comment_type, true); $comment_saved = true;