Merge branch 'master' of github.com:s9y/additional_plugins

This commit is contained in:
Garvin Hicking 2011-12-18 16:28:45 +01:00
commit 14206d95f1
26 changed files with 1059 additions and 2 deletions

View file

@ -0,0 +1,3 @@
Version 1.00 (brockhaus)
-----------------------
* Initial Release, have fun! :)

View file

@ -0,0 +1,79 @@
<?php
class CurlFetcher {
public function file_get_contents($fileurl, $allow_curl =TRUE) {
$max_redirects = 5;
if (defined('OEMBED_USE_CURL') && OEMBED_USE_CURL && defined('CURLOPT_URL')) {
$ch = curl_init();
$timeout = 5; // 0 wenn kein Timeout
curl_setopt($ch, CURLOPT_URL, $fileurl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
//curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, true );
//curl_setopt($ch, CURLOPT_MAXREDIRS, $max_redirects );
//$file_content = curl_exec($ch);
$file_content = CurlFetcher::curl_exec_follow($ch, $max_redirects);
curl_close($ch);
}
else {
$context = array ( 'http' => array ( 'method' => 'GET', 'max_redirects' => $max_redirects, ),);
$file_content = file_get_contents($fileurl, null, stream_context_create($context));
}
return $file_content;
}
/**
* Handling redirections with curl if safe_mode or open_basedir is enabled. The function working transparent, no problem with header and returntransfer options. You can handle the max redirection with the optional second argument (the function is set the variable to zero if max redirection exceeded).
* Second parameter values:
* - maxredirect is null or not set: redirect maximum five time, after raise PHP warning
* - maxredirect is greather then zero: no raiser error, but parameter variable set to zero
* - maxredirect is less or equal zero: no follow redirections
* (see: http://php.net/manual/en/function.curl-setopt.php)
*/
private function curl_exec_follow(/*resource*/ $ch, /*int*/ &$maxredirect = null) {
$mr = $maxredirect === null ? 5 : intval($maxredirect);
if (ini_get('open_basedir') == '' && ini_get('safe_mode' == 'Off')) {
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, $mr > 0);
curl_setopt($ch, CURLOPT_MAXREDIRS, $mr);
} else {
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
if ($mr > 0) {
$newurl = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
$rch = curl_copy_handle($ch);
curl_setopt($rch, CURLOPT_HEADER, true);
curl_setopt($rch, CURLOPT_NOBODY, true);
curl_setopt($rch, CURLOPT_FORBID_REUSE, false);
curl_setopt($rch, CURLOPT_RETURNTRANSFER, true);
do {
curl_setopt($rch, CURLOPT_URL, $newurl);
$header = curl_exec($rch);
if (curl_errno($rch)) {
$code = 0;
} else {
$code = curl_getinfo($rch, CURLINFO_HTTP_CODE);
if ($code == 301 || $code == 302) {
preg_match('/Location:(.*?)\n/', $header, $matches);
$newurl = trim(array_pop($matches));
} else {
$code = 0;
}
}
} while ($code && --$mr);
curl_close($rch);
if (!$mr) {
if ($maxredirect === null) {
trigger_error('Too many redirects. When following redirects, libcurl hit the maximum amount.', E_USER_WARNING);
} else {
$maxredirect = 0;
}
return false;
}
curl_setopt($ch, CURLOPT_URL, $newurl);
}
}
return curl_exec($ch);
}
}

View file

@ -0,0 +1,99 @@
<?php
@define('PLUGIN_OEMBED_DATABASEVERSION_CONFIG', "oembed_version");
@define('PLUGIN_OEMBED_DATABASEVNAME', "oembeds");
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);
serendipity_db_insert( PLUGIN_OEMBED_DATABASEVNAME, $save );
return $oembed;
}
function load_oembed($url) {
global $serendipity;
if (empty($url)) return null;
$urlmd5 = md5($url);
$query = "select oeobj from {$serendipity['dbPrefix']}" . PLUGIN_OEMBED_DATABASEVNAME . " where urlmd5='$urlmd5'";
$rows = serendipity_db_query($query);
if (!is_array($rows)) { // fresh search
return null;
}
else {
$oeobj = null;
foreach ($rows as $row) {
$oeobj = $row['oeobj'];
if (!empty($oeobj)) break;
}
if (!empty($oeobj)) {
return unserialize($oeobj);
}
}
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;
if (!OEmbedDatabase::table_created(PLUGIN_OEMBED_DATABASEVNAME)) {
$md5test = md5("test");
$md5len = strlen($md5test);
$q = "create table {$serendipity['dbPrefix']}" . PLUGIN_OEMBED_DATABASEVNAME. " (" .
"urlmd5 char($md5len) not null, " .
"url varchar(3000) not null, " .
"oetype varchar(20) not null, " .
"oeobj text not null, " .
"primary key (urlmd5)" .
")";
$result = serendipity_db_schema_import($q);
if ($result !== true) {
return;
}
}
}
function table_created($table = PLUGIN_OEMBED_DATABASEVNAME) {
global $serendipity;
$q = "select count(*) from {$serendipity['dbPrefix']}" . $table;
$row = serendipity_db_query($q, true, 'num');
if (!is_numeric($row[0])) { // if the response we got back was an SQL error.. :P
return false;
} else {
return true;
}
}
function cleanup_html( $str ) {
$str = trim($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;
}
}

View file

@ -0,0 +1,35 @@
<?php
class OEmbedTemplater {
/* get the right template (s9y template path, then plugin path) and expand it */
function fetchTemplate($filename, $oembed, $url) {
global $serendipity;
if (!is_object($serendipity['smarty']))
serendipity_smarty_init();
// 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;
if (version_compare($serendipity['version'], '1.7-alpha1')>=0) {
$serendipity['smarty']->disableSecurity();
}
else {
$serendipity['smarty']->security = false;
}
// 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;
}
}

View file

@ -0,0 +1,9 @@
<?php # $Id: lang_en.inc.php,v 1.1 2006/08/16 04:49:12 elf2000 Exp $
/**
* @version $Revision: 1.1 $
* @author Translator Name <yourmail@example.com>
* EN-Revision: Revision of lang_en.inc.php
*/
@define('PLUGIN_EVENT_OEMBED_NAME', 'oEmbed Plugin');

View file

@ -0,0 +1,26 @@
<?php # $Id: lang_en.inc.php,v 1.1 2006/08/16 04:49:12 elf2000 Exp $
/**
* @version $Revision: 1.1 $
* @author Translator Name <yourmail@example.com>
* EN-Revision: Revision of lang_en.inc.php
*/
@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_MAXWIDTH', 'Max width of replacements');
@define('PLUGIN_EVENT_OEMBED_MAXWIDTH_DESC', 'This is the max width the service should produce when providing a replacement. Not all services supports this but most.');
@define('PLUGIN_EVENT_OEMBED_MAXHEIGHT', 'Max height of replacements');
@define('PLUGIN_EVENT_OEMBED_MAXHEIGHT_DESC','This is the max height the service should produce when providing a replacement. Not all services supports this but most.');
@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 of this plugin is <b>[embed <i>link</i>]</b> (or <b>[e <i>link</i>]</b> if you like it shorter).<br/>'.
'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>');

View file

@ -0,0 +1,41 @@
{* oembed.tpl last modified 2011-12-01 *}
{if $oembed.type=='rich'} {* =================================================== RICH *}
<span class="serendipity_oembed_rich">
{if $oembed.provider_name=="Wikipedia"}
<blockquote>{$oembed.html}</blockquote>
{elseif $oembed.provider_name=="IMDB"} {* beautify IMDB content *}
<blockquote>{$oembed.html|replace:"<h2>":"<strong>"|replace:"</h2>":"</strong>"|replace:"<img":"<img align='right'"}</blockquote>
{elseif $oembed.provider-name=="Soundcloud"} {* beautify SoundCloud *}
{$oembed.html|replace:"</object>":"</object><br/>"}
{else}
{$oembed.html}
{/if}
</span>
{elseif $oembed.type=='video'} {* =================================================== VIDEO *}
<span class="serendipity_oembed_video">
{$oembed.html}
</span>
{elseif $oembed.type=='image'} {* =================================================== IMAGE *}
<span class="serendipity_oembed_photo">
<a href="{$oembed.url}"><img src="{$oembed.thumbnail_url}""{if $oembed.title} title="{$oembed.title}" alt="{$oembed.title}"{/if}/></a>
</span>
{elseif $oembed.type=='photo'} {* =================================================== PHOTO *}
<span class="serendipity_oembed_photo">
<img src="{$oembed.url}"{if $oembed.title} title="{$oembed.title}" alt="{$oembed.title}"{/if}/>
</span>
{elseif $oembed.type=='link'} {* =================================================== LINK *}
<span class="serendipity_oembed_link">
{if $oembed.provider_name=="Wikipedia"}<blockquote>{/if}
{if $oembed.description}
{if $oembed.title}<strong>{$oembed.title}</strong><br/>{/if}
<p>{if $oembed.thumbnail_url}<img src="{$oembed.thumbnail_url}" align="left">{/if}{$oembed.description}{if $oembed.url}<br/>[<a href="{$oembed.url}" target="_blank">link</a>]{/if}</p>
{else}
<a href="{$oembedurl}" title="{$oembed.title}">{$oembed.author_name}</a>
{/if}
{if $oembed.provider_name=="Wikipedia"}</blockquote>{/if}
</span>
{else} {* Link type finishes *}
<span class="serendipity_oembed">
<a href="{$oembedurl}" target="_blank">{if $oembed.error}{$oembed.error}{else}{$oembedurl}{/if}</a>
</span>
{/if}

View file

@ -0,0 +1,16 @@
<?php
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, $maxwidth=null, $maxheight=null){
$this->url = $url;
$this->endpoint = $endpoint;
$this->maxwidth = $maxwidth;
$this->maxheight = $maxheight;
}
}

View file

@ -0,0 +1,3 @@
<?php
class Exception404 extends Exception{
}

View file

@ -0,0 +1,4 @@
<?php
class LinkEmbed extends OEmbed{
}

View file

@ -0,0 +1,23 @@
<?php
class OEmbed{
public $type;
public $version;
public $title;
public $author_name;
public $author_url;
public $provider_name;
public $provider_url;
public $cache_age;
public $description; // added by me, not part of OEmbed
public $resource_url; // added by me, not part of OEmbed
public $thumbnail_url;
public $thumbnail_width;
public $thumbnail_height;
public function cloneObj($object){
foreach($object as $key=>$value){
$this->$key=(string)$value;
}
}
}

View file

@ -0,0 +1,103 @@
<?php
require_once dirname(__FILE__) . '/../CurlFetcher.php';
class OEmbedProvider extends EmbedProvider{
private $urlRegExp;
private $jsonEndpoint;
private $xmlEndpoint;
private $dimensionsSupported = true;
private $onlyJson = false;
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)){
$this->jsonEndpoint=preg_replace("/\{format\}/","json",$endpoint);
$this->jsonEndpoint.="?url={url}";
$this->xmlEndpoint=preg_replace("/\{format\}/","xml",$endpoint);
$this->xmlEndpoint.="?url={url}";
} else {
$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; }
public function getJsonEndpoint(){ return $this->jsonEndpoint; }
public function getXmlEndpoint(){ return $this->xmlEndpoint; }
public function match($url){
return preg_match($this->urlRegExp,$url);
}
private function file_get_contents($fileurl) {
$allow_curl = defined('OEMBED_USE_CURL') && OEMBED_USE_CURL && defined('CURLOPT_URL');
return CurlFetcher::file_get_contents($fileurl, $allow_curl);
}
private function provideXML($url){
return $this->file_get_contents(preg_replace("/\{url\}/",urlencode($url),$this->xmlEndpoint));
}
private function getTypeObj($type){
switch($type){
case "image":
case "photo":
return new PhotoEmbed();
break;
case "video":
return new VideoEmbed();
break;
case "link":
return new LinkEmbed();
break;
case "rich":
return new RichEmbed();
break;
default:
return new OEmbed();
}
}
private function provideObject($url){
if (!$this->onlyJson) {
$xml=simplexml_load_string($this->provideXML($url));
}
else {
$data=$this->provide($url);
if (!empty($data)) $xml = json_decode($data);
}
//TODO $xml->type alapjan assigner
$obj = $this->getTypeObj((string)$xml->type);
$obj->cloneObj($xml);
$obj->resource_url=$url;
return $obj;
}
private function provideSerialized($url){
$serialized=serialize($this->provideObject($url));
return $serialized;
}
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->file_get_contents(preg_replace("/\{url\}/",urlencode($url),$this->jsonEndpoint));
}
}
public function register(){}
}

View file

@ -0,0 +1,6 @@
<?php
class PhotoEmbed extends OEmbed{
public $url;
public $width;
public $height;
}

View 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>";
}
}

View file

@ -0,0 +1,37 @@
<?php
class ProviderManager{
private $providers;
private static $_instance;
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);
$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);
$this->register($reflection->newInstance($provider));//so we could pass config vars
}
}
}
static function getInstance($maxwidth=null, $maxheight=null){
if(!isset($_instance) || $_instance==null){
$_instance = new ProviderManager($maxwidth, $maxheight);
}
return $_instance;
}
public function register($provider){
$this->providers[]=$provider;
}
public function provide($url,$format){
foreach ($this->providers as $provider){
if ($provider->match($url)){
return $provider->provide($url,$format);
}
}
return null;
}
}

View file

@ -0,0 +1,6 @@
<?php
class RichEmbed extends OEmbed {
public $html;
public $width;
public $height;
}

View file

@ -0,0 +1,7 @@
<?php
class VideoEmbed extends OEmbed {
public $html;
public $width;
public $height;
public $duration; // added by me, not part of OEmbed
}

View file

@ -0,0 +1,80 @@
<?php
class YouTubeProvider extends EmbedProvider {
public function match($url){
return preg_match('/youtube.com\/watch\?v=([\w-]+)/',$url) || preg_match('/youtu.be\/([\w-]+)/',$url); // http://youtu.be/8UVNT4wvIGY
}
public function getEmbed($url){
$urlArray=array();
if(preg_match("/(www.)?youtube.com\/watch\?v=([\w-]+)/",$url,$matches)){
$video_id=$matches[2];
}
else if(preg_match("/(www.)?youtu.be\/([\w-]+)/",$url,$matches)){
$video_id=$matches[2];
}
$myEmbed = new VideoEmbed();
$myEmbed->type='video';
$myEmbed->version='1.0';
$myEmbed->provider_name="Youtube";
$myEmbed->provider_url="http://youtube.com";
$myEmbed->resource_url=$url;
$xml = new DOMDocument;
if(@($xml->load('http://gdata.youtube.com/feeds/api/videos/'.$video_id))) {
@$guid = $xml->getElementsByTagName("guid")->item(0)->nodeValue;
$link = str_replace("http://www.youtube.com/watch?v=","http://bergengocia.net/indavideobombyoutubemashup/view.php?id=",$guid);
$myEmbed->title =$xml->getElementsByTagName("title")->item(0)->nodeValue;
$myEmbed->description =$xml->getElementsByTagNameNS("*","description")->item(0)->nodeValue;
$myEmbed->author_name =$xml->getElementsByTagName("author")->item(0)->getElementsByTagName("name")->item(0)->nodeValue;
$myEmbed->author_url =$xml->getElementsByTagName("author")->item(0)->getElementsByTagName("uri")->item(0)->nodeValue;
$myEmbed->thumbnail_url =$xml->getElementsByTagNameNS("*","thumbnail")->item(0)->getAttribute("url");
$myEmbed->thumbnail_width =$xml->getElementsByTagNameNS("*","thumbnail")->item(0)->getAttribute("width");
$myEmbed->thumbnail_height =$xml->getElementsByTagNameNS("*","thumbnail")->item(0)->getAttribute("height");
$med_content_url=$xml->getElementsByTagNameNS("http://search.yahoo.com/mrss/","content")->item(0)->getAttribute("url");
$myEmbed->html=
'<object width="425" height="350">'."\n".
' <param name="movie" value="'.$med_content_url.'"></param>'."\n".
' <embed src="'.$med_content_url.'"'.
' type="application/x-shockwave-flash" width="425" height="350">'."\n".
' </embed>'."\n".
'</object>'; // according to http://code.google.com/apis/youtube/developers_guide_protocol.html#Displaying_information_about_a_video
$myEmbed->width="425";
$myEmbed->height="350"; // same as in the html
//$myEmbed->duration=$xml->getElementsByTagNameNS($xml->lookupNamespaceURI("*"),"content")->item(0)->getAttribute("duration");
//$time = floor($duration / 60) . ":" . $duration % 60;
return $myEmbed;
} else throw new Exception404("xxx");
}
private function provideXML($url){
$string="";
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){
return json_encode($this->getEmbed($url));
}
private function provideSerialized($url){
return serialize($this->getEmbed($url));
}
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 __construct($config,$maxwidth=null, $maxheight=null){
parent::__construct("http://youtube.com","", $maxwidth, $maxheight);
}
}

View file

@ -0,0 +1,29 @@
<?php
if (!defined("PLUGIN_OEMBED_PROVIDER_XML_FILE")) {
@define("PLUGIN_OEMBED_PROVIDER_XML_FILE", dirname(__FILE__) . '/' . "providers.xml");
}
// Include all class files
/*
$oembed_config_class_wildcard = dirname(__FILE__) . "/*class.php";
foreach (glob($oembed_config_class_wildcard) as $filename)
{
//echo "$filename<br/>\n";
@include $filename;
}
*/
require_once dirname(__FILE__) . '/' . 'Exception404.class.php';
require_once dirname(__FILE__) . '/' . 'OEmbed.class.php';
require_once dirname(__FILE__) . '/' . 'LinkEmbed.class.php';
require_once dirname(__FILE__) . '/' . 'PhotoEmbed.class.php';
require_once dirname(__FILE__) . '/' . 'RichEmbed.class.php';
require_once dirname(__FILE__) . '/' . 'VideoEmbed.class.php';
require_once dirname(__FILE__) . '/' . 'EmbedProvider.class.php';
require_once dirname(__FILE__) . '/' . 'OEmbedProvider.class.php';
// Will be loaded via generic oembedprovider!
//require_once dirname(__FILE__) . '/' . 'YouTubeProvider.class.php';
require_once dirname(__FILE__) . '/' . 'ProviderManager.class.php';

View file

@ -0,0 +1,205 @@
<?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>
<!-- down
<provider>
<url>http://*.pownce.com/*</url>
<endpoint>http://api.pownce.com/2.1/oembed.{format}</endpoint>
</provider>
-->
<provider>
<name>Twitter Status</name>
<url>https?://*.twitter.com/*/status(es)?/*</url>
<endpoint>https://api.twitter.com/1/statuses/oembed.{format}</endpoint>
</provider>
<provider>
<url>http://*.vimeo.com/*</url>
<endpoint>http://vimeo.com/api/oembed.{format}</endpoint>
</provider>
<!--
<provider>
<url>http://*.youtube.*/*</url>
<class>YouTubeProvider</class>
</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>SmugMug</name>
<url>http://*.smugmug.com/*</url>
<endpoint>http://api.smugmug.com/services/oembed/</endpoint>
</provider>
<provider>
<name>Photobucket</name>
<url>http://*.photobucket.com/(albums|groups)/*</url>
<endpoint>http://photobucket.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>Qik Mobile Videos</name>
<url>http://qik.com/video/*</url>
<endpoint>http://qik.com/api/oembed.{format}</endpoint>
</provider>
<provider>
<name>My Opera</name>
<nodimensionsupport/>
<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>Instagr.am</name>
<jsononly/>
<url>http://*.instagr.am/*</url>
<endpoint>http://api.instagram.com/api/v1/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>
<provider>
<name>Skitch</name>
<url>http://(www.)?skitch.com/*</url>
<endpoint>http://skitch.com/oembed/</endpoint>
</provider>
<!-- noembed providers -->
<!--
<provider>
<name>Wikipedia (via noembed.com)</name>
<jsononly/>
<url>https?://*.wikipedia.org/wiki/*</url>
<endpoint>http://noembed.com/embed</endpoint>
</provider>
-->
<provider>
<name>Twitpic (via noembed.com)</name>
<jsononly/>
<url>http://(www.)?twitpic.com/*</url>
<endpoint>http://noembed.com/embed</endpoint>
</provider>
<provider>
<name>Imgur.com (via noembed.com)</name>
<jsononly/>
<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/>
<url>http://cl.ly/*</url>
<endpoint>http://noembed.com/embed</endpoint>
</provider>
<provider>
<name>ASCII Art Farts (via noembed.com)</name>
<jsononly/>
<url>http://www.asciiartfarts.com/*.html</url>
<endpoint>http://noembed.com/embed</endpoint>
</provider>
<provider>
<name>GiantBomb (via noembed.com)</name>
<jsononly/>
<url>http://www.giantbomb.com/*</url>
<endpoint>http://noembed.com/embed</endpoint>
</provider>
<provider>
<name>Spotify (via noembed.com)</name>
<jsononly/>
<url>https?://open.spotify.com/(track|album)/*</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>
</providers>

View file

@ -0,0 +1,24 @@
<?
/*
* PHP OEmbed provider/proxy - for details, visit
*
* http://code.google.com/p/php-oembed/
*
* Copyright(C) by Adam Nemeth. Licensed under New BSD license.
*
* I would love to hear every feedback on aadaam at googlesmailservice
*
*/
require_once(dirname(__FILE__) . '/../' . "config.php");
$xml = simplexml_load_file(dirname(__FILE__) . '/../' . "providers.xml");
foreach($xml->provider as $provider){
// $x = new OEmbedProvider("http://*.flickr.com/*","http://www.flickr.com/services/oembed/");
$x = new OEmbedProvider($provider->url,$provider->endpoint);
echo $x->url.":\n";
if ($x->match("http://www.flickr.com/photos/bees/2341623661/")){
print_r($x->provide("http://www.flickr.com/photos/bees/2341623661/","object"));
}
echo " ".$x->getUrlRegExp()."\n";
echo " ".$x->getJsonEndpoint()."\n";
echo " ".$x->getXmlEndpoint()."\n";
}

View file

@ -0,0 +1,24 @@
<?
/** Testfile für die Provider Konfiguration
* @author: Grischa Brockhaus
*/
require_once(dirname(__FILE__) . '/../' . "config.php");
function test($manager, $url) {
$obj=$manager->provide($url,"object");
if (!empty($obj)) print_r($obj);
}
$manager = ProviderManager::getInstance();
// Youtube long link
//test($manager,"http://www.youtube.com/watch?v=8UVNT4wvIGY");
// Youtube Kurze URL
//test($manager,"http://youtu.be/8UVNT4wvIGY");
// Twitter
//test($manager,"https://twitter.com/#!/tagesschau/status/146562892454572032");
// flickr
test($manager,"http://www.flickr.com/photos/gbrockhaus/2052855443/in/set-72157603214268227/");
// vimeo
//test($manager,"http://vimeo.com/33510073");

View file

@ -0,0 +1,8 @@
<?php
$xml = simplexml_load_file(dirname(__FILE__) . '/../' . "providers.xml");
foreach($xml->provider as $provider){
echo $provider->url;
echo $provider->endpoint;
}

View file

@ -0,0 +1,12 @@
<?
require_once(dirname(__FILE__) . '/../' . "config.php");
function testYoutubeProvider() {
$x = new YouTubeProvider('');
$obj = $x->provide("","object");
//print_r($obj);
print_r($obj->html);
}
testYoutubeProvider();

View file

@ -0,0 +1,160 @@
<?php
if (IN_serendipity !== true) {
die ("Don't hack!");
}
// Probe for a language include with constants. Still include defines later on, if some constants were missing
$probelang = dirname(__FILE__) . '/' . $serendipity['charset'] . 'lang_' . $serendipity['lang'] . '.inc.php';
if (file_exists($probelang)) {
include $probelang;
}
include dirname(__FILE__) . '/lang_en.inc.php';
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';
@define('OEMBED_USE_CURL',TRUE);
class serendipity_event_oembed extends serendipity_event
{
var $title = PLUGIN_EVENT_OEMBED_NAME;
function introspect(&$propbag)
{
global $serendipity;
$propbag->add('name', PLUGIN_EVENT_OEMBED_NAME);
$propbag->add('description', PLUGIN_EVENT_OEMBED_DESC);
$propbag->add('stackable', false);
$propbag->add('author', 'Grischa Brockhaus');
$propbag->add('version', '1.00');
$propbag->add('requirements', array(
'serendipity' => '0.8',
'smarty' => '2.6.7',
'php' => '5.1.0'
));
$propbag->add('groups', array('FRONTEND_EXTERNAL_SERVICES'));
$propbag->add('event_hooks', array(
'frontend_display' => true,
));
$configuration = $configuration = array('info','maxwidth','maxheight');
$propbag->add('configuration', $configuration);
}
function introspect_config_item($name, &$propbag)
{
switch($name) {
case 'info':
$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) {
global $serendipity;
static $simplePatterns = null;
if ($simplePatterns==null) {
$simplePatterns = array(
//'simpleTweet' => '@\(tweet\s+(\S*)\)@Usi',
'simpleTweet' => '@\[(?:e|embed)\s+(.*)\]@Usi',
);
}
$hooks = &$bag->get('event_hooks');
if (isset($hooks[$event])) {
switch($event) {
case 'frontend_display':
if (isset($eventData['body']) && isset($eventData['extended'])) {
$this->update_entry($eventData, $simplePatterns, 'body');
$this->update_entry($eventData, $simplePatterns, 'extended');
}
return true;
}
}
return true;
}
function update_entry(&$eventData, &$patterns, $dateType) {
if (!empty($eventData[$dateType])) {
$eventData[$dateType] = preg_replace_callback(
$patterns['simpleTweet'],
array( $this, "oembedRewriteCallback"),
$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);
if (empty($obj)) {
$manager = ProviderManager::getInstance($maxwidth,$maxheight);
try {
$obj=$manager->provide($url,"object");
if (isset($obj)) {
$obj = OEmbedDatabase::save_oembed($url,$obj);
}
}
catch (ErrorException $e) {
// Timeout in most cases
//return $e;
}
}
return $obj;
}
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);
OEmbedDatabase::clear_cache();
echo '<div class="serendipityAdminMsgSuccess">Cleared oembed cache.</div>';
}
function install() {
OEmbedDatabase::install($this);
}
}

View file

@ -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]}<br/>";
echo "<div class='serendipityAdminMsgSuccess'>Found new tweetback for article $article_id: tweetid: {$entry[TWITTER_SEARCHRESULT_ID]}</div><br/>";
}
$this->check_tweetbacks_save_comment($article_id, $entry, $comment_type, true);
$comment_saved = true;