From 8eaab0642fcddcce86b618913af56a86d6014665 Mon Sep 17 00:00:00 2001 From: friendica Date: Tue, 12 Nov 2013 15:44:49 -0800 Subject: [PATCH] very crude zid support for e2ee content and move bbcode converter to main.js so it's available when not logged in (though we might ultimately want to force people to get a matrix account to use our encryption). --- js/main.js | 135 ++++++++++++++++++++++++++++++++++++++++ view/tpl/jot-header.tpl | 123 ------------------------------------ 2 files changed, 135 insertions(+), 123 deletions(-) diff --git a/js/main.js b/js/main.js index a9e670da5..a7421b312 100644 --- a/js/main.js +++ b/js/main.js @@ -1038,3 +1038,138 @@ function chanviewFull() { resize_iframe(); } } + + function addhtmltext(data) { + data = h2b(data); + addeditortext(data); + } + + + function addeditortext(data) { + if(typeof tinyMCE !== "undefined") { + tinyMCE.execCommand('mceInsertRawHTML',false,data); + } + else { + var currentText = $("#profile-jot-text").val(); + $("#profile-jot-text").val(currentText + data); + } + } + + function h2b(s) { + var y = s; + function rep(re, str) { + y = y.replace(re,str); + }; + + rep(/(.*?)<\/a>/gi,"[url=$1]$2[/url]"); + rep(/(.*?)<\/span>/gi,"[size=$1]$2[/size]"); + rep(/(.*?)<\/span>/gi,"[color=$1]$2[/color]"); + 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]$1[/img]"); + + + rep(/
    (.*?)<\/ul>/gi,"[list]$1[/list]"); + rep(/
      (.*?)<\/ul>/gi,"[list=]$1[/list]"); + rep(/
        (.*?)<\/ul>/gi,"[list=1]$1[/list]"); + rep(/
          (.*?)<\/ul>/gi,"[list=i]$1[/list]"); + rep(/
            (.*?)<\/ul>/gi,"[list=I]$1[/list]"); + rep(/
              (.*?)<\/ul>/gi,"[list=a]$1[/list]"); + rep(/
                (.*?)<\/ul>/gi,"[list=A]$1[/list]"); + rep(/
              • (.*?)<\/li>/gi,"[li]$1[/li]"); + + rep(/(.*?)<\/code>/gi,"[code]$1[/code]"); + rep(/<\/(strong|b)>/gi,"[/b]"); + rep(/<(strong|b)>/gi,"[b]"); + rep(/<\/(em|i)>/gi,"[/i]"); + rep(/<(em|i)>/gi,"[i]"); + rep(/<\/u>/gi,"[/u]"); + + + rep(/(.*?)<\/span>/gi,"[u]$1[/u]"); + rep(//gi,"[u]"); + rep(/]*>/gi,"[quote]"); + rep(/<\/blockquote>/gi,"[/quote]"); + rep(/
                /gi,"[hr]"); + rep(/
                /gi,"\n"); + rep(//gi,"\n"); + rep(/
                /gi,"\n"); + rep(/

                /gi,""); + rep(/<\/p>/gi,"\n"); + rep(/ /gi," "); + rep(/"/gi,"\""); + rep(/</gi,"<"); + rep(/>/gi,">"); + rep(/&/gi,"&"); + + return y; + }; + + + function b2h(s) { + var y = s; + function rep(re, str) { + y = y.replace(re,str); + }; + + rep(/\&/gi,"&"); + rep(/\/gi,">"); + rep(/\"/gi,"""); + + rep(/\n/gi,"
                "); + rep(/\[b\]/gi,""); + rep(/\[\/b\]/gi,""); + rep(/\[i\]/gi,""); + rep(/\[\/i\]/gi,""); + rep(/\[u\]/gi,""); + rep(/\[\/u\]/gi,""); + rep(/\[hr\]/gi,"


                "); + rep(/\[url=([^\]]+)\](.*?)\[\/url\]/gi,"$2"); + rep(/\[url\](.*?)\[\/url\]/gi,"$1"); + rep(/\[img=(.*?)x(.*?)\](.*?)\[\/img\]/gi,""); + rep(/\[img\](.*?)\[\/img\]/gi,""); + + // FIXME - add zid() + rep(/\[zrl=([^\]]+)\](.*?)\[\/zrl\]/gi,"$2"); + rep(/\[zrl\](.*?)\[\/zrl\]/gi,"$1"); + rep(/\[zmg=(.*?)x(.*?)\](.*?)\[\/zmg\]/gi,""); + rep(/\[zmg\](.*?)\[\/zmg\]/gi,""); + + rep(/\[list\](.*?)\[\/list\]/gi, '
                  $1
                '); + rep(/\[list=\](.*?)\[\/list\]/gi, '
                  $1
                '); + rep(/\[list=1\](.*?)\[\/list\]/gi, '
                  $1
                '); + rep(/\[list=i\](.*?)\[\/list\]/gi,'
                  $1
                '); + rep(/\[list=I\](.*?)\[\/list\]/gi, '
                  $1
                '); + rep(/\[list=a\](.*?)\[\/list\]/gi, '
                  $1
                '); + rep(/\[list=A\](.*?)\[\/list\]/gi, '
                  $1
                '); + rep(/\[li\](.*?)\[\/li\]/gi, '
              • $1
              • '); + rep(/\[color=(.*?)\](.*?)\[\/color\]/gi,"$2"); + rep(/\[size=(.*?)\](.*?)\[\/size\]/gi,"$2"); + rep(/\[code\](.*?)\[\/code\]/gi,"$1"); + rep(/\[quote.*?\](.*?)\[\/quote\]/gi,"
                $1
                "); + + rep(/\[video\](.*?)\[\/video\]/gi,"$1"); + rep(/\[audio\](.*?)\[\/audio\]/gi,"$1"); + + rep(/\[\&\;([#a-z0-9]+)\;\]/gi,'&$1;'); + + rep(/\<(.*?)(src|href)=\"[^hfm](.*?)\>/gi,'<$1$2="">'); + + return y; + }; + + +function zid(s) { + if((! s.length) || (s.indexOf('zid=') != (-1))) + return s; + if(! zid.length) + return s; + var has_params = ((s.indexOf('?') == (-1)) ? false : true); + var achar = ((has_params) ? '&' : '?'); + s = s + achar + 'f=&zid=' + zid; + return s; +} diff --git a/view/tpl/jot-header.tpl b/view/tpl/jot-header.tpl index c3e020619..97c638fd4 100755 --- a/view/tpl/jot-header.tpl +++ b/view/tpl/jot-header.tpl @@ -292,129 +292,6 @@ function enableOnUser(){ } - function addhtmltext(data) { - data = h2b(data); - addeditortext(data); - } - - - function addeditortext(data) { - if(typeof tinyMCE !== "undefined") { - tinyMCE.execCommand('mceInsertRawHTML',false,data); - } - else { - var currentText = $("#profile-jot-text").val(); - $("#profile-jot-text").val(currentText + data); - } - } - - function h2b(s) { - var y = s; - function rep(re, str) { - y = y.replace(re,str); - }; - - rep(/(.*?)<\/a>/gi,"[url=$1]$2[/url]"); - rep(/(.*?)<\/span>/gi,"[size=$1]$2[/size]"); - rep(/(.*?)<\/span>/gi,"[color=$1]$2[/color]"); - 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]$1[/img]"); - - - rep(/
                  (.*?)<\/ul>/gi,"[list]$1[/list]"); - rep(/
                    (.*?)<\/ul>/gi,"[list=]$1[/list]"); - rep(/
                      (.*?)<\/ul>/gi,"[list=1]$1[/list]"); - rep(/
                        (.*?)<\/ul>/gi,"[list=i]$1[/list]"); - rep(/
                          (.*?)<\/ul>/gi,"[list=I]$1[/list]"); - rep(/
                            (.*?)<\/ul>/gi,"[list=a]$1[/list]"); - rep(/
                              (.*?)<\/ul>/gi,"[list=A]$1[/list]"); - rep(/
                            • (.*?)<\/li>/gi,"[li]$1[/li]"); - - rep(/(.*?)<\/code>/gi,"[code]$1[/code]"); - rep(/<\/(strong|b)>/gi,"[/b]"); - rep(/<(strong|b)>/gi,"[b]"); - rep(/<\/(em|i)>/gi,"[/i]"); - rep(/<(em|i)>/gi,"[i]"); - rep(/<\/u>/gi,"[/u]"); - - - rep(/(.*?)<\/span>/gi,"[u]$1[/u]"); - rep(//gi,"[u]"); - rep(/]*>/gi,"[quote]"); - rep(/<\/blockquote>/gi,"[/quote]"); - rep(/
                              /gi,"[hr]"); - rep(/
                              /gi,"\n"); - rep(//gi,"\n"); - rep(/
                              /gi,"\n"); - rep(/

                              /gi,""); - rep(/<\/p>/gi,"\n"); - rep(/ /gi," "); - rep(/"/gi,"\""); - rep(/</gi,"<"); - rep(/>/gi,">"); - rep(/&/gi,"&"); - - return y; - }; - - - function b2h(s) { - var y = s; - function rep(re, str) { - y = y.replace(re,str); - }; - - rep(/\&/gi,"&"); - rep(/\/gi,">"); - rep(/\"/gi,"""); - - rep(/\n/gi,"
                              "); - rep(/\[b\]/gi,""); - rep(/\[\/b\]/gi,""); - rep(/\[i\]/gi,""); - rep(/\[\/i\]/gi,""); - rep(/\[u\]/gi,""); - rep(/\[\/u\]/gi,""); - rep(/\[hr\]/gi,"


                              "); - rep(/\[url=([^\]]+)\](.*?)\[\/url\]/gi,"$2"); - rep(/\[url\](.*?)\[\/url\]/gi,"$1"); - rep(/\[img=(.*?)x(.*?)\](.*?)\[\/img\]/gi,""); - rep(/\[img\](.*?)\[\/img\]/gi,""); - - // FIXME - add zid - rep(/\[zrl=([^\]]+)\](.*?)\[\/zrl\]/gi,"$2"); - rep(/\[zrl\](.*?)\[\/zrl\]/gi,"$1"); - rep(/\[zmg=(.*?)x(.*?)\](.*?)\[\/zmg\]/gi,""); - rep(/\[zmg\](.*?)\[\/zmg\]/gi,""); - - rep(/\[list\](.*?)\[\/list\]/gi, '
                                $1
                              '); - rep(/\[list=\](.*?)\[\/list\]/gi, '
                                $1
                              '); - rep(/\[list=1\](.*?)\[\/list\]/gi, '
                                $1
                              '); - rep(/\[list=i\](.*?)\[\/list\]/gi,'
                                $1
                              '); - rep(/\[list=I\](.*?)\[\/list\]/gi, '
                                $1
                              '); - rep(/\[list=a\](.*?)\[\/list\]/gi, '
                                $1
                              '); - rep(/\[list=A\](.*?)\[\/list\]/gi, '
                                $1
                              '); - rep(/\[li\](.*?)\[\/li\]/gi, '
                            • $1
                            • '); - rep(/\[color=(.*?)\](.*?)\[\/color\]/gi,"$2"); - rep(/\[size=(.*?)\](.*?)\[\/size\]/gi,"$2"); - rep(/\[code\](.*?)\[\/code\]/gi,"$1"); - rep(/\[quote.*?\](.*?)\[\/quote\]/gi,"
                              $1
                              "); - - rep(/\[video\](.*?)\[\/video\]/gi,"$1"); - rep(/\[audio\](.*?)\[\/audio\]/gi,"$1"); - - rep(/\[\&\;([#a-z0-9]+)\;\]/gi,'&$1;'); - - rep(/\<(.*?)(src|href)=\"[^hfm](.*?)\>/gi,'<$1$2="">'); - - return y; - }; - {{$geotag}}