From 62fda0a120fe4d068f1380924b5493adb70064ea Mon Sep 17 00:00:00 2001 From: Fabio Comuni Date: Wed, 26 Jan 2011 16:20:12 +0100 Subject: oembed consumer plugin --- addon/oembed/oembed.php | 56 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 addon/oembed/oembed.php (limited to 'addon/oembed/oembed.php') diff --git a/addon/oembed/oembed.php b/addon/oembed/oembed.php new file mode 100644 index 000000000..55654a543 --- /dev/null +++ b/addon/oembed/oembed.php @@ -0,0 +1,56 @@ + + '; + + $b .= ' +
  + + +

Paste a link from 5min.com, Amazon Product Image, blip.tv, Clikthrough, CollegeHumor Video, + Daily Show with Jon Stewart, Dailymotion, dotSUB.com, Flickr Photos, Funny or Die Video, + Google Video, Hulu, Kinomap, LiveJournal UserPic, Metacafe, National Film Board of Canada, + Phodroid Photos, Photobucket, Qik Video, Revision3, Scribd, SlideShare, TwitPic, Twitter Status, + Viddler Video, Vimeo, Wikipedia, Wordpress.com, XKCD Comic, YFrog, YouTube

+
+ '; +} + + +function oembed_hook_jot_tool($a, &$b) { + $b .= ' +
+ Embed +
+ '; +} + + + +?> \ No newline at end of file -- cgit v1.2.3 From 43be72297a281b41e7b77ba6078aeb48ee007299 Mon Sep 17 00:00:00 2001 From: Fabio Comuni Date: Wed, 26 Jan 2011 17:17:02 +0100 Subject: Rewrite oembed plugin to use new bbcode tag [embed] and make discovery server-side --- addon/oembed/oembed.php | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'addon/oembed/oembed.php') diff --git a/addon/oembed/oembed.php b/addon/oembed/oembed.php index 55654a543..82183f3cc 100644 --- a/addon/oembed/oembed.php +++ b/addon/oembed/oembed.php @@ -10,11 +10,13 @@ function oembed_install() { register_hook('jot_tool', 'addon/oembed/oembed.php', 'oembed_hook_jot_tool'); register_hook('page_header', 'addon/oembed/oembed.php', 'oembed_hook_page_header'); + register_hook('bbcode', 'addon/oembed/oembed.php', 'oembed_hook_bbcode'); } function oembed_uninstall() { unregister_hook('jot_tool', 'addon/oembed/oembed.php', 'oembed_hook_jot_tool'); unregister_hook('page_header', 'addon/oembed/oembed.php', 'oembed_hook_page_header'); + unregister_hook('bbcode', 'addon/oembed/oembed.php', 'oembed_hook_bbcode'); } function oembed_hook_page_header($a, &$b){ @@ -51,6 +53,49 @@ function oembed_hook_jot_tool($a, &$b) { '; } +function oembed_replacecb($matches){ + $embedurl=$matches[1]; + $ourl = "http://oohembed.com/oohembed/?url=".urlencode($embedurl); + $txt = fetch_url($ourl); + $j = json_decode($txt); + $ret=""; + switch ($j->type) { + case "video": { + if (isset($j->thumbnail_url)) { + $tw = (isset($j->thumbnail_width)) ? $j->thumbnail_width:200; + $th = (isset($j->thumbnail_height)) ? $j->thumbnail_height:180; + $ret = ""; + $ret.= ""; + $ret.= ""; + } else { + $ret=$j->html; + } + $ret.="
"; + }; break; + case "photo": { + $ret = ""; + $ret.="
"; + }; break; + case "link": { + //$ret = "".$j->title.""; + }; break; + case "rich": { + // not so safe.. + $ret = "
".$j->html."
"; + }; break; + } + + $embedlink = (isset($j->title))?$j->title:$embedurl; + $ret .= "$embedlink"; + if (isset($j->author_name)) $ret.=" by ".$j->author_name; + if (isset($j->provider_name)) $ret.=" on ".$j->provider_name; + $ret.=""; + return $ret; +} + +function oembed_hook_bbcode($a, &$text){ + $text = preg_replace_callback("/\[embed\](.+?)\[\/embed\]/is", oembed_replacecb ,$text); +} ?> \ No newline at end of file -- cgit v1.2.3