]> git.mxchange.org Git - friendica.git/commitdiff
update oembed plugin. embed preview in editor
authorfabrixxm <fabrix.xm@gmail.com>
Sun, 22 May 2011 19:56:47 +0000 (21:56 +0200)
committerFabio Comuni <fabrix.xm@gmail.com>
Mon, 23 May 2011 07:13:35 +0000 (09:13 +0200)
addon/oembed/oembed.js
addon/oembed/oembed.php
include/oembed.php
tinymce/jscripts/tiny_mce/plugins/bbcode/editor_plugin_src.js

index 54547a86eca74c445f9c82dfd29a09eb420282d8..f8e957413cb1954f09cc095a9a44d5ff6c34d066 100644 (file)
@@ -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]" );
+       }
 }
index d9b205a3a5cd118fac8736c1782ac688d492ed2d..45f533cc5becc9d722052db57a134a22f4d22b6a 100644 (file)
@@ -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 .= '<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>
-  ';
+  $a->page['htmlhead'] .= sprintf('<script src="%s/oembed/oembed.js"></script>', $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 "<span class='oembed'>".oembed_replacecb($url)."</span>";
+       }
+       
+       if ($a->argv[1]=='h2b'){
+               $text = trim(hex2bin($_GET['text']));
+               echo oembed_html2bbcode($text);
+       }
+       
+       killme();
+       
+}
 
 ?>
\ No newline at end of file
index 4d2b7185e9a43d2f516a46e62461b605f0150d97..10d458ff38c016f54563dd86e46eaefa6f00bae7 100644 (file)
@@ -16,13 +16,14 @@ function oembed_replacecb($matches){
                dbesc(datetime_convert()));
   }
   $j = json_decode($txt);
-  $ret="<span class='oembed'>";
+  $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;
-         $ret = "<a href='".$embedurl."' onclick='this.innerHTML=unescape(\"".urlencode($j->html)."\").replace(/\+/g,\" \"); return false;' >";
+         /*$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 {
@@ -47,7 +48,7 @@ function oembed_replacecb($matches){
   $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>";
+  $ret.="<br style='clear:left'></span>";
   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 {
index aad83280d43926372711d08da839973fa8438dfa..997bc54fa0a76ae53096e417afc60ae1b7d6967a 100644 (file)
                        function rep(re, str) {\r
                                s = s.replace(re, str);\r
                        };\r
+
+
+
+
+                       /* 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 */
+
 \r
                        // example: <strong> to [b]\r
                        rep(/<a.*?href=\"(.*?)\".*?>(.*?)<\/a>/gi,"[url=$1]$2[/url]");\r
@@ -55,8 +76,8 @@
                        rep(/<font>(.*?)<\/font>/gi,"$1");\r
                        rep(/<img.*?width=\"(.*?)\".*?height=\"(.*?)\".*?src=\"(.*?)\".*?\/>/gi,"[img=$1x$2]$3[/img]");\r
                        rep(/<img.*?height=\"(.*?)\".*?width=\"(.*?)\".*?src=\"(.*?)\".*?\/>/gi,"[img=$2x$1]$3[/img]");\r
-      rep(/<img.*?src=\"(.*?)\".*?height=\"(.*?)\".*?width=\"(.*?)\".*?\/>/gi,"[img=$3x$2]$1[/img]");\r
-      rep(/<img.*?src=\"(.*?)\".*?width=\"(.*?)\".*?height=\"(.*?)\".*?\/>/gi,"[img=$2x$3]$1[/img]");\r
+                       rep(/<img.*?src=\"(.*?)\".*?height=\"(.*?)\".*?width=\"(.*?)\".*?\/>/gi,"[img=$3x$2]$1[/img]");\r
+                       rep(/<img.*?src=\"(.*?)\".*?width=\"(.*?)\".*?height=\"(.*?)\".*?\/>/gi,"[img=$2x$3]$1[/img]");\r
                        rep(/<img.*?src=\"(.*?)\".*?\/>/gi,"[img]$1[/img]");\r
                        rep(/<code>(.*?)<\/code>/gi,"[code]$1[/code]");\r
                        rep(/<\/(strong|b)>/gi,"[/b]");\r
                        rep(/\[size=(.*?)\](.*?)\[\/size\]/gi,"<span style=\"font-size: $1;\">$2</span>");\r
                        rep(/\[code\](.*?)\[\/code\]/gi,"<code>$1</code>");\r
                        rep(/\[quote.*?\](.*?)\[\/quote\]/gi,"<blockquote>$1</blockquote>");\r
+
+                       /* 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 */
 \r
                        return s; \r
                }\r