From 570a22de7425e2a486b02e3b43a4b4b1ece552af Mon Sep 17 00:00:00 2001 From: fabrixxm Date: Sun, 22 May 2011 21:56:47 +0200 Subject: [PATCH 1/7] update oembed plugin. embed preview in editor --- addon/oembed/oembed.js | 12 ++-- addon/oembed/oembed.php | 55 ++++++++++--------- include/oembed.php | 13 +++-- .../plugins/bbcode/editor_plugin_src.js | 44 ++++++++++++++- 4 files changed, 81 insertions(+), 43 deletions(-) diff --git a/addon/oembed/oembed.js b/addon/oembed/oembed.js index 54547a86e..f8e957413 100644 --- a/addon/oembed/oembed.js +++ b/addon/oembed/oembed.js @@ -1,10 +1,6 @@ function oembed(){ - $("#oembed").toggleClass('hide'); -} - -function oembed_do(){ - embed = "[embed]"+$('#oembed_url').attr('value')+"[/embed]"; - - tinyMCE.execCommand('mceInsertRawHTML',false,embed); - oembed(); + var reply = prompt("$oembed_message:"); + if(reply && reply.length) { + tinyMCE.execCommand('mceInsertRawHTML',false, "[embed]"+reply+"[/embed]" ); + } } diff --git a/addon/oembed/oembed.php b/addon/oembed/oembed.php index d9b205a3a..45f533cc5 100644 --- a/addon/oembed/oembed.php +++ b/addon/oembed/oembed.php @@ -6,7 +6,9 @@ * http://www.oembed.com/ * */ - + +require_once('include/oembed.php'); + 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'); @@ -18,32 +20,7 @@ function oembed_uninstall() { } function oembed_hook_page_header($a, &$b){ - - if(($a->module !== 'network') && ($a->module !== 'profile')) - return; - - $b .= ' - '; - - $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
-
- '; + $a->page['htmlhead'] .= sprintf('', $a->get_baseurl()); } @@ -56,6 +33,30 @@ function oembed_hook_jot_tool($a, &$b) { } +function oembed_module() { + return; +} +function oembed_init(&$a) { + if ($a->argv[1]=='oembed.js'){ + $tpl = file_get_contents('addon/oembed/oembed.js'); + echo replace_macros($tpl, array( + '$oembed_message' => t('URL to embed:'), + )); + } + + if ($a->argv[1]=='b2h'){ + $url = array( "", trim(hex2bin($_GET['url']))); + echo "".oembed_replacecb($url).""; + } + + if ($a->argv[1]=='h2b'){ + $text = trim(hex2bin($_GET['text'])); + echo oembed_html2bbcode($text); + } + + killme(); + +} ?> \ No newline at end of file diff --git a/include/oembed.php b/include/oembed.php index 4d2b7185e..10d458ff3 100644 --- a/include/oembed.php +++ b/include/oembed.php @@ -16,13 +16,14 @@ function oembed_replacecb($matches){ dbesc(datetime_convert())); } $j = json_decode($txt); - $ret=""; + $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 = ""; + /*$tw = (isset($j->thumbnail_width)) ? $j->thumbnail_width:200; + $th = (isset($j->thumbnail_height)) ? $j->thumbnail_height:180;*/ + $tw=150; $th=120; + $ret = ""; $ret.= ""; $ret.= ""; } else { @@ -47,7 +48,7 @@ function oembed_replacecb($matches){ $ret .= "$embedlink"; if (isset($j->author_name)) $ret.=" by ".$j->author_name; if (isset($j->provider_name)) $ret.=" on ".$j->provider_name; - $ret.=""; + $ret.="
"; return $ret; } @@ -98,7 +99,7 @@ function oembed_html2bbcode($text) { $xattr = oe_build_xpath("rel","oembed"); foreach($entries as $e) { $href = $xpath->evaluate("a[$xattr]/@href", $e)->item(0)->nodeValue; - if(!is_null($href)) $e->parentNode->replaceChild(new DOMText("[embed]".$href."[embed]"), $e); + if(!is_null($href)) $e->parentNode->replaceChild(new DOMText("[embed]".$href."[/embed]"), $e); } return oe_get_inner_html( $dom->getElementsByTagName("body")->item(0) ); } else { diff --git a/tinymce/jscripts/tiny_mce/plugins/bbcode/editor_plugin_src.js b/tinymce/jscripts/tiny_mce/plugins/bbcode/editor_plugin_src.js index aad83280d..997bc54fa 100644 --- a/tinymce/jscripts/tiny_mce/plugins/bbcode/editor_plugin_src.js +++ b/tinymce/jscripts/tiny_mce/plugins/bbcode/editor_plugin_src.js @@ -47,6 +47,27 @@ function rep(re, str) { s = s.replace(re, str); }; + + + + + /* oembed */ + function _h2b_cb(match) { + text = bin2hex(match); + function s_h2b(data) { + match = data; + } + $.ajax({ + url: 'oembed/h2b?text=' + text, + async: false, + success: s_h2b, + dataType: 'html' + }); + return match; + } + s = s.replace(/(.*?)<\/span>/gi, _h2b_cb); + /* /oembed */ + // example: to [b] rep(/(.*?)<\/a>/gi,"[url=$1]$2[/url]"); @@ -55,8 +76,8 @@ rep(/(.*?)<\/font>/gi,"$1"); rep(//gi,"[img=$1x$2]$3[/img]"); rep(//gi,"[img=$2x$1]$3[/img]"); - rep(//gi,"[img=$3x$2]$1[/img]"); - rep(//gi,"[img=$2x$3]$1[/img]"); + rep(//gi,"[img=$3x$2]$1[/img]"); + rep(//gi,"[img=$2x$3]$1[/img]"); rep(//gi,"[img]$1[/img]"); rep(/(.*?)<\/code>/gi,"[code]$1[/code]"); rep(/<\/(strong|b)>/gi,"[/b]"); @@ -106,6 +127,25 @@ rep(/\[size=(.*?)\](.*?)\[\/size\]/gi,"$2"); rep(/\[code\](.*?)\[\/code\]/gi,"$1"); rep(/\[quote.*?\](.*?)\[\/quote\]/gi,"
$1
"); + + /* oembed */ + function _b2h_cb(match) { + url = match.replace(/\[\/*embed\]/gi, "") + url = bin2hex(url); + function s_b2h(data) { + match = data; + } + $.ajax({ + url: 'oembed/b2h?url=' + url, + async: false, + success: s_b2h, + dataType: 'html' + }); + return match; + } + s = s.replace(/\[embed\](.*?)\[\/embed\]/gi, _b2h_cb); + + /* /oembed */ return s; } From 866940ab5d4f460c0083aeffdd7e354e8aa0fafe Mon Sep 17 00:00:00 2001 From: fabrixxm Date: Sun, 22 May 2011 21:58:37 +0200 Subject: [PATCH 2/7] fix IT string.php --- view/it/strings.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/view/it/strings.php b/view/it/strings.php index de67aad4d..aa6184e21 100644 --- a/view/it/strings.php +++ b/view/it/strings.php @@ -119,7 +119,7 @@ $a->strings["Administrator"] = "Amministratore"; $a->strings["Friend/Connection Request"] = "Richieste di Amicizia/Connessione"; $a->strings["Examples: jojo@demo.friendika.com, http://demo.friendika.com/profile/jojo, testuser@identi.ca"] = "Esempi: jojo@demo.friendika.com, http://demo.friendika.com/profile/jojo, testuser@identi.ca"; $a->strings["Please answer the following:"] = "Rispondi al seguente:"; -$a->strings["Does \$name know you?"] = "$name ti conosce?"; +$a->strings["Does \$name know you?"] = "\$name ti conosce?"; $a->strings["Yes"] = "Si"; $a->strings["No"] = "No"; $a->strings["Add a personal note:"] = "Aggiungi una nota personale:"; From 072e4146369ae8ec10af961b7e1b25dc491e8f07 Mon Sep 17 00:00:00 2001 From: fabrixxm Date: Sun, 22 May 2011 23:03:34 +0200 Subject: [PATCH 3/7] Fix missing wrapping span on bbcode to html, split embed data fetch and rappresentation in two functions. Prettier video embed. --- addon/oembed/oembed.php | 2 +- include/oembed.php | 137 +++++++++++++++++++++++++--------------- 2 files changed, 88 insertions(+), 51 deletions(-) diff --git a/addon/oembed/oembed.php b/addon/oembed/oembed.php index 45f533cc5..caf4f5837 100644 --- a/addon/oembed/oembed.php +++ b/addon/oembed/oembed.php @@ -47,7 +47,7 @@ function oembed_init(&$a) { if ($a->argv[1]=='b2h'){ $url = array( "", trim(hex2bin($_GET['url']))); - echo "".oembed_replacecb($url).""; + echo oembed_replacecb($url); } if ($a->argv[1]=='h2b'){ diff --git a/include/oembed.php b/include/oembed.php index 10d458ff3..06a37d8e4 100644 --- a/include/oembed.php +++ b/include/oembed.php @@ -1,55 +1,92 @@ type."'>"; - 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;*/ - $tw=150; $th=120; - $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; + $embedurl=$matches[1]; + $j = oembed_fetch_url($embedurl); + return oembed_format_object($j); +} + + +function oembed_fetch_url($embedurl){ + $r = q("SELECT v FROM `cache` WHERE k='%s'", + dbesc($embedurl)); + + if(count($r)){ + $txt = $r[0]['v']; + } else { + $txt = ""; + + // try oembed autodiscovery + $html_text = fetch_url($embedurl); + $dom = @DOMDocument::loadHTML($html_text); + if ($dom){ + $xpath = new DOMXPath($dom); + $attr = "oembed"; + + $xattr = oe_build_xpath("class","oembed"); + $entries = $xpath->query("//link[@type='application/json+oembed']"); + foreach($entries as $e){ + $href = $e->getAttributeNode("href")->nodeValue; + $txt = fetch_url($href); + } + } + + if ($txt==false || $txt==""){ + // try oohembed service + $ourl = "http://oohembed.com/oohembed/?url=".urlencode($embedurl); + $txt = fetch_url($ourl); + } + + $txt=trim($txt); + if ($txt[0]!="{") $txt='{"type":"error"}'; + + //save in cache + /*q("INSERT INTO `cache` VALUES ('%s','%s','%s')", + dbesc($embedurl), + dbesc($txt), + dbesc(datetime_convert()));*/ + } + + $j = json_decode($txt); + $j->embedurl = $embedurl; + return $j; +} + +function oembed_format_object($j){ + $embedurl = $j->embedurl; + $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;*/ + $tw=150; $th=120; + $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_bbcode2html($text){ From ef64c5187df80da2065655726b8d05a9ce6b0e0a Mon Sep 17 00:00:00 2001 From: fabrixxm Date: Sun, 22 May 2011 23:06:47 +0200 Subject: [PATCH 4/7] add config [system][embed_all] to use oembed with links and youtube. Url parse fallback to default if url has not an oembed rappresentation. --- include/bbcode.php | 17 +++++++++++------ mod/parse_url.php | 15 ++++++++++++--- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/include/bbcode.php b/include/bbcode.php index c2d932674..b2e9cee6d 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -92,17 +92,22 @@ function bbcode($Text,$preserve_nl = false) { // [img=widthxheight]image source[/img] $Text = preg_replace("/\[img\=([0-9]*)x([0-9]*)\](.+?)\[\/img\]/", '', $Text); - // Youtube extensions + $a = get_app(); + if ($a->config['system']['embed_all']){ + // use oembed for youtube links + $Text = preg_replace("/\[youtube\]/",'[embed]',$Text); + $Text = preg_replace("/\[\/youtube\]/",'[/embed]',$Text); + } else { + // Youtube extensions $Text = preg_replace("/\[youtube\]https?:\/\/www.youtube.com\/watch\?v\=(.+?)\[\/youtube\]/",'[youtube]$1[/youtube]',$Text); $Text = preg_replace("/\[youtube\]https?:\/\/youtu.be\/(.+?)\[\/youtube\]/",'[youtube]$1[/youtube]',$Text); - - $Text = preg_replace("/\[youtube\](.+?)\[\/youtube\]/", '
', $Text); - -// $Text = preg_replace("/\[youtube\](.+?)\[\/youtube\]/", '
', $Text); + $Text = preg_replace("/\[youtube\](.+?)\[\/youtube\]/", '', $Text); + } +// $Text = preg_replace("/\[youtube\](.+?)\[\/youtube\]/", '', $Text); // oembed tag $Text = oembed_bbcode2html($Text); - + call_hooks('bbcode',$Text); return $Text; diff --git a/mod/parse_url.php b/mod/parse_url.php index 30371e9f6..8e1684732 100644 --- a/mod/parse_url.php +++ b/mod/parse_url.php @@ -1,7 +1,7 @@ config['system']['embed_all']){ + $j = oembed_fetch_url($url); + if ($j->type!="error"){ + echo oembed_format_object($j); + killme(); + } + } + $s = fetch_url($url); - else { + } else { echo ''; killme(); } From 453a0cff3875ca1cb3587b1fa83ad5b0439faae3 Mon Sep 17 00:00:00 2001 From: fabrixxm Date: Sun, 22 May 2011 23:07:27 +0200 Subject: [PATCH 5/7] fix tiny_mce bbcode embed preview --- .../jscripts/tiny_mce/plugins/bbcode/editor_plugin_src.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tinymce/jscripts/tiny_mce/plugins/bbcode/editor_plugin_src.js b/tinymce/jscripts/tiny_mce/plugins/bbcode/editor_plugin_src.js index 997bc54fa..db676cd90 100644 --- a/tinymce/jscripts/tiny_mce/plugins/bbcode/editor_plugin_src.js +++ b/tinymce/jscripts/tiny_mce/plugins/bbcode/editor_plugin_src.js @@ -65,7 +65,7 @@ }); return match; } - s = s.replace(/(.*?)<\/span>/gi, _h2b_cb); + s = s.replace(//gi, _h2b_cb); /* /oembed */ @@ -129,8 +129,7 @@ rep(/\[quote.*?\](.*?)\[\/quote\]/gi,"
$1
"); /* oembed */ - function _b2h_cb(match) { - url = match.replace(/\[\/*embed\]/gi, "") + function _b2h_cb(match, url) { url = bin2hex(url); function s_b2h(data) { match = data; From 7c5a7a94d4d224d23f7c922b86a60a6ffe53fc9f Mon Sep 17 00:00:00 2001 From: Fabio Comuni Date: Mon, 23 May 2011 10:37:09 +0200 Subject: [PATCH 6/7] Add oembed user option for use oembed instead of standard yotube embedding. Remove global option and parse_url use of oembed. --- addon/oembed/oembed.php | 54 ++++++++++++++++++++++++++++++++--------- include/bbcode.php | 3 +-- mod/parse_url.php | 12 +-------- 3 files changed, 45 insertions(+), 24 deletions(-) diff --git a/addon/oembed/oembed.php b/addon/oembed/oembed.php index caf4f5837..f1fb27986 100644 --- a/addon/oembed/oembed.php +++ b/addon/oembed/oembed.php @@ -10,26 +10,58 @@ require_once('include/oembed.php'); 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('jot_tool', 'addon/oembed/oembed.php', 'oembed_hook_jot_tool'); + register_hook('page_header', 'addon/oembed/oembed.php', 'oembed_hook_page_header'); + register_hook('plugin_settings', 'addon/oembed/oembed.php', 'oembed_settings'); + register_hook('plugin_settings_post', 'addon/oembed/oembed.php', 'oembed_settings_post'); } 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('jot_tool', 'addon/oembed/oembed.php', 'oembed_hook_jot_tool'); + unregister_hook('page_header', 'addon/oembed/oembed.php', 'oembed_hook_page_header'); } +function oembed_settings_post(){ + if(! local_user()) + return; + if (isset($_POST['oembed-submit'])){ + set_pconfig(local_user(), 'oembed', 'use_for_youtube', (isset($_POST['oembed_use_for_youtube'])?1:0)); + notice( t('OEmbed settings updated') . EOL); + } +} + +function oembed_settings(&$a,&$o) { + if(! local_user()) + return; + $uofy = get_pconfig(local_user(), 'oembed', 'use_for_youtube' ); + + $o .='

OEmbed

'; + $o.=' +
+ +
+
+
+ +
'; +} + + function oembed_hook_page_header($a, &$b){ - $a->page['htmlhead'] .= sprintf('', $a->get_baseurl()); + $a->page['htmlhead'] .= sprintf('', $a->get_baseurl()); } function oembed_hook_jot_tool($a, &$b) { - $b .= ' -
- Embed -
- '; + $b .= ' +
+ Embed +
+ '; } @@ -59,4 +91,4 @@ function oembed_init(&$a) { } -?> \ No newline at end of file +?> diff --git a/include/bbcode.php b/include/bbcode.php index b2e9cee6d..3caf2a6b1 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -92,8 +92,7 @@ function bbcode($Text,$preserve_nl = false) { // [img=widthxheight]image source[/img] $Text = preg_replace("/\[img\=([0-9]*)x([0-9]*)\](.+?)\[\/img\]/", '', $Text); - $a = get_app(); - if ($a->config['system']['embed_all']){ + if (get_pconfig(local_user(), 'oembed', 'use_for_youtube' )==1){ // use oembed for youtube links $Text = preg_replace("/\[youtube\]/",'[embed]',$Text); $Text = preg_replace("/\[\/youtube\]/",'[/embed]',$Text); diff --git a/mod/parse_url.php b/mod/parse_url.php index 8e1684732..15a6aced0 100644 --- a/mod/parse_url.php +++ b/mod/parse_url.php @@ -1,7 +1,6 @@ config['system']['embed_all']){ - $j = oembed_fetch_url($url); - if ($j->type!="error"){ - echo oembed_format_object($j); - killme(); - } - } - $s = fetch_url($url); } else { echo ''; @@ -106,4 +96,4 @@ function parse_url_content(&$a) { echo sprintf($template,$url,$title,$text); killme(); -} \ No newline at end of file +} From f93106de3ae5ee525a9fdce6dcc4a1897f07a105 Mon Sep 17 00:00:00 2001 From: Fabio Comuni Date: Mon, 23 May 2011 10:50:22 +0200 Subject: [PATCH 7/7] Add missing widgets_uninstall function to widgets plugin --- addon/widgets/widgets.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/addon/widgets/widgets.php b/addon/widgets/widgets.php index 6bd7a73d1..af17d9e9a 100644 --- a/addon/widgets/widgets.php +++ b/addon/widgets/widgets.php @@ -7,12 +7,15 @@ function widgets_install() { - // we need some hooks, for the configuration and for sending tweets register_hook('plugin_settings', 'addon/widgets/widgets.php', 'widgets_settings'); register_hook('plugin_settings_post', 'addon/widgets/widgets.php', 'widgets_settings_post'); - logger("installed widgets"); } +function widgets_uninstall() { + unregister_hook('plugin_settings', 'addon/widgets/widgets.php', 'widgets_settings'); + unregister_hook('plugin_settings_post', 'addon/widgets/widgets.php', 'widgets_settings_post'); +} + function widgets_settings_post(){