aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFriendika <info@friendika.com>2011-05-23 18:18:01 -0700
committerFriendika <info@friendika.com>2011-05-23 18:18:01 -0700
commit19ccd658ebcf13a7cc208a3e460e44d152dda32f (patch)
treea6cfc22e4e40fe00ef5aac27023ccbfa8789958a
parent78b2db3a9840f551c951bf0a58a54cce08133bcf (diff)
parentcde888f7f87449d4f5a281b8a23abcf3234ce9b9 (diff)
downloadvolse-hubzilla-19ccd658ebcf13a7cc208a3e460e44d152dda32f.tar.gz
volse-hubzilla-19ccd658ebcf13a7cc208a3e460e44d152dda32f.tar.bz2
volse-hubzilla-19ccd658ebcf13a7cc208a3e460e44d152dda32f.zip
Merge branch 'pull'
-rw-r--r--addon/oembed/oembed.js12
-rw-r--r--addon/oembed/oembed.php107
-rw-r--r--addon/widgets/widgets.php7
-rw-r--r--include/bbcode.php16
-rw-r--r--include/oembed.php138
-rw-r--r--mod/parse_url.php7
-rw-r--r--tinymce/jscripts/tiny_mce/plugins/bbcode/editor_plugin_src.js43
-rw-r--r--view/it/strings.php2
8 files changed, 222 insertions, 110 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..f1fb27986 100644
--- a/addon/oembed/oembed.php
+++ b/addon/oembed/oembed.php
@@ -6,56 +6,89 @@
* 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');
+ 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 .='<h3 class="settings-heading">OEmbed</h3>';
+ $o.='
+ <div id="settings-username-wrapper">
+ <label for="oembed_use_for_youtube">'
+ .t('Use OEmbed for YouTube videos: ')
+ .'</label><input type="checkbox" id="oembed_use_for_youtube" name="oembed_use_for_youtube"'
+ . ($uofy==1?'checked="true"':'')
+ .'>
+ </div>
+ <div id="settings-username-end"></div>
+ <div class="settings-submit-wrapper">
+ <input type="submit" value="'.t('Submit').'" class="settings-submit" name="oembed-submit">
+ </div>';
}
-function oembed_hook_page_header($a, &$b){
- if(($a->module !== 'network') && ($a->module !== 'profile'))
- return;
-
- $b .= '<script src="addon/oembed/oembed.js"></script>
- <style>#oembed.hide { display: none }
- #oembed {
- display:block; position: absolute; width: 300px; height:200px;
- background-color:#fff; color: #000;
- border:2px solid #8888FF; padding: 1em;
- top: 200px; left: 400px; z-index:2000;
- }
- #oembed_url { width: 100%; margin-bottom:3px;}
- </style>';
-
- $b .= '
- <div id="oembed" class="hide"><input id="oembed_url">&nbsp;
- <input type="button" value="Embed" onclick="oembed_do()" style="float:left;">
- <a onclick="oembed(); return false;" style="float:right;"><img onmouseout="imgdull(this);" onmouseover="imgbright(this);" class="wall-item-delete-icon" src="images/b_drophide.gif" style="width: 16px; height: 16px;"></a>
- <div style="clear:both">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</div>
- </div>
- ';
+function oembed_hook_page_header($a, &$b){
+ $a->page['htmlhead'] .= sprintf('<script src="%s/oembed/oembed.js"></script>', $a->get_baseurl());
}
function oembed_hook_jot_tool($a, &$b) {
- $b .= '
- <div class="tool-wrapper" style="display: $visitor;" >
- <img class="tool-link" src="addon/oembed/oembed.png" alt="Embed" title="Embed" onclick="oembed();" />
- </div>
- ';
+ $b .= '
+ <div class="tool-wrapper" style="display: $visitor;" >
+ <img class="tool-link" src="addon/oembed/oembed.png" alt="Embed" title="Embed" onclick="oembed();" />
+ </div>
+ ';
}
+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/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(){
diff --git a/include/bbcode.php b/include/bbcode.php
index c2d932674..3caf2a6b1 100644
--- a/include/bbcode.php
+++ b/include/bbcode.php
@@ -92,17 +92,21 @@ function bbcode($Text,$preserve_nl = false) {
// [img=widthxheight]image source[/img]
$Text = preg_replace("/\[img\=([0-9]*)x([0-9]*)\](.+?)\[\/img\]/", '<img src="$3" style="height:{$2}px; width:{$1}px;" >', $Text);
- // Youtube extensions
+ 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);
+ } 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\]/", '<br /><iframe style="width:425px;height:349px;padding:10px 0 10px 0;float:left;" src="http://www.youtube.com/embed/$1" frameborder="0" allowfullscreen></iframe>', $Text);
-
-// $Text = preg_replace("/\[youtube\](.+?)\[\/youtube\]/", '<br /><object style="width:425px;height:350px;" type="application/x-shockwave-flash" data="http://www.youtube.com/v/$1" ><param name="movie" value="http://www.youtube.com/v/$1"></param><!--[if IE]><embed src="http://www.youtube.com/v/$1" type="application/x-shockwave-flash" style="width:425px;height:350px;" /><![endif]--></object>', $Text);
+ $Text = preg_replace("/\[youtube\](.+?)\[\/youtube\]/", '<iframe width="425" height="349" src="http://www.youtube.com/embed/$1" frameborder="0" allowfullscreen></iframe>', $Text);
+ }
+// $Text = preg_replace("/\[youtube\](.+?)\[\/youtube\]/", '<object width="425" height="350" type="application/x-shockwave-flash" data="http://www.youtube.com/v/$1" ><param name="movie" value="http://www.youtube.com/v/$1"></param><!--[if IE]><embed src="http://www.youtube.com/v/$1" type="application/x-shockwave-flash" width="425" height="350" /><![endif]--></object>', $Text);
// oembed tag
$Text = oembed_bbcode2html($Text);
-
+
call_hooks('bbcode',$Text);
return $Text;
diff --git a/include/oembed.php b/include/oembed.php
index 4d2b7185e..06a37d8e4 100644
--- a/include/oembed.php
+++ b/include/oembed.php
@@ -1,54 +1,92 @@
<?php
function oembed_replacecb($matches){
- $embedurl=$matches[1];
-
- $r = q("SELECT v FROM `cache` WHERE k='%s'",
- dbesc($embedurl));
- if(count($r)){
- $txt = $r[0]['v'];
- } else {
- $ourl = "http://oohembed.com/oohembed/?url=".urlencode($embedurl);
- $txt = fetch_url($ourl);
- //save in cache
- q("INSERT INTO `cache` VALUES ('%s','%s','%s')",
- dbesc($embedurl),
- dbesc($txt),
- dbesc(datetime_convert()));
- }
- $j = json_decode($txt);
- $ret="<span class='oembed'>";
- 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 = "<a href='".$embedurl."' onclick='this.innerHTML=unescape(\"".urlencode($j->html)."\").replace(/\+/g,\" \"); return false;' >";
- $ret.= "<img width='$tw' height='$th' src='".$j->thumbnail_url."'>";
- $ret.= "</a>";
- } else {
- $ret=$j->html;
- }
- $ret.="<br>";
- }; break;
- case "photo": {
- $ret = "<img width='".$j->width."' height='".$j->height."' src='".$j->url."'>";
- $ret.="<br>";
- }; break;
- case "link": {
- //$ret = "<a href='".$embedurl."'>".$j->title."</a>";
- }; break;
- case "rich": {
- // not so safe..
- $ret = "<blockquote>".$j->html."</blockquote>";
- }; break;
- }
-
- $embedlink = (isset($j->title))?$j->title:$embedurl;
- $ret .= "<a href='$embedurl' rel='oembed'>$embedlink</a>";
- if (isset($j->author_name)) $ret.=" by ".$j->author_name;
- if (isset($j->provider_name)) $ret.=" on ".$j->provider_name;
- $ret.="</span>";
- 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="<span class='oembed ".$j->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.= "<a href='".$embedurl."' onclick='this.innerHTML=unescape(\"".urlencode($j->html)."\").replace(/\+/g,\" \"); return false;' style='float:left; margin: 1em; '>";
+ $ret.= "<img width='$tw' height='$th' src='".$j->thumbnail_url."'>";
+ $ret.= "</a>";
+ } else {
+ $ret=$j->html;
+ }
+ $ret.="<br>";
+ }; break;
+ case "photo": {
+ $ret.= "<img width='".$j->width."' height='".$j->height."' src='".$j->url."'>";
+ $ret.="<br>";
+ }; break;
+ case "link": {
+ //$ret = "<a href='".$embedurl."'>".$j->title."</a>";
+ }; break;
+ case "rich": {
+ // not so safe..
+ $ret.= "<blockquote>".$j->html."</blockquote>";
+ }; break;
+ }
+
+ $embedlink = (isset($j->title))?$j->title:$embedurl;
+ $ret .= "<a href='$embedurl' rel='oembed'>$embedlink</a>";
+ if (isset($j->author_name)) $ret.=" by ".$j->author_name;
+ if (isset($j->provider_name)) $ret.=" on ".$j->provider_name;
+ $ret.="<br style='clear:left'></span>";
+ return $ret;
}
function oembed_bbcode2html($text){
@@ -98,7 +136,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/mod/parse_url.php b/mod/parse_url.php
index 30371e9f6..15a6aced0 100644
--- a/mod/parse_url.php
+++ b/mod/parse_url.php
@@ -2,7 +2,6 @@
require_once('library/HTML5/Parser.php');
-
function parse_url_content(&$a) {
logger('parse_url: ' . $_GET['url']);
@@ -25,9 +24,9 @@ function parse_url_content(&$a) {
killme();
}
- if($url)
+ if($url) {
$s = fetch_url($url);
- else {
+ } else {
echo '';
killme();
}
@@ -97,4 +96,4 @@ function parse_url_content(&$a) {
echo sprintf($template,$url,$title,$text);
killme();
-} \ No newline at end of file
+}
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..db676cd90 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 class=\"oembed(.*?)<\/span>/gi, _h2b_cb);
+ /* /oembed */
+
// example: <strong> to [b]
rep(/<a.*?href=\"(.*?)\".*?>(.*?)<\/a>/gi,"[url=$1]$2[/url]");
@@ -55,8 +76,8 @@
rep(/<font>(.*?)<\/font>/gi,"$1");
rep(/<img.*?width=\"(.*?)\".*?height=\"(.*?)\".*?src=\"(.*?)\".*?\/>/gi,"[img=$1x$2]$3[/img]");
rep(/<img.*?height=\"(.*?)\".*?width=\"(.*?)\".*?src=\"(.*?)\".*?\/>/gi,"[img=$2x$1]$3[/img]");
- rep(/<img.*?src=\"(.*?)\".*?height=\"(.*?)\".*?width=\"(.*?)\".*?\/>/gi,"[img=$3x$2]$1[/img]");
- rep(/<img.*?src=\"(.*?)\".*?width=\"(.*?)\".*?height=\"(.*?)\".*?\/>/gi,"[img=$2x$3]$1[/img]");
+ rep(/<img.*?src=\"(.*?)\".*?height=\"(.*?)\".*?width=\"(.*?)\".*?\/>/gi,"[img=$3x$2]$1[/img]");
+ rep(/<img.*?src=\"(.*?)\".*?width=\"(.*?)\".*?height=\"(.*?)\".*?\/>/gi,"[img=$2x$3]$1[/img]");
rep(/<img.*?src=\"(.*?)\".*?\/>/gi,"[img]$1[/img]");
rep(/<code>(.*?)<\/code>/gi,"[code]$1[/code]");
rep(/<\/(strong|b)>/gi,"[/b]");
@@ -106,6 +127,24 @@
rep(/\[size=(.*?)\](.*?)\[\/size\]/gi,"<span style=\"font-size: $1;\">$2</span>");
rep(/\[code\](.*?)\[\/code\]/gi,"<code>$1</code>");
rep(/\[quote.*?\](.*?)\[\/quote\]/gi,"<blockquote>$1</blockquote>");
+
+ /* oembed */
+ function _b2h_cb(match, url) {
+ 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;
}
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:";