display encrypted text inline

This commit is contained in:
friendica 2013-11-11 00:21:00 -08:00
parent 0adf31eef2
commit 435e2dae0e
4 changed files with 58 additions and 5 deletions

View File

@ -121,7 +121,9 @@ function bb_parse_crypt($match) {
if ($matches[1] != "") if ($matches[1] != "")
$hint = html_entity_decode($matches[1],ENT_QUOTES,'UTF-8'); $hint = html_entity_decode($matches[1],ENT_QUOTES,'UTF-8');
$Text = '<br/><img src="' . z_root() . '/images/lock_icon.gif" onclick="red_decrypt(\'' . $algorithm . '\',\'' . $hint . '\',\'' . $match[2] . '\');" alt="' . t('Encrypted content') . '" title="' . t('Encrypted content') . '" /><br />'; $x = random_string();
$Text = '<br/><div id="' . $x . '"><img src="' . z_root() . '/images/lock_icon.gif" onclick="red_decrypt(\'' . $algorithm . '\',\'' . $hint . '\',\'' . $match[2] . '\',\'#' . $x . '\');" alt="' . t('Encrypted content') . '" title="' . t('Encrypted content') . '" /></div><br />';
return $Text; return $Text;
@ -496,7 +498,8 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) {
} }
if (strpos($Text,'[/crypt]') !== false) { if (strpos($Text,'[/crypt]') !== false) {
$Text = preg_replace("/\[crypt\](.*?)\[\/crypt\]/ism",'<br/><img src="' .$a->get_baseurl() . '/images/lock_icon.gif" onclick="red_decrypt(\'rot13\',\'\',\'$1\');" alt="' . t('Encrypted content') . '" title="' . t('Encrypted content') . '" /><br />', $Text); $x = random_string();
$Text = preg_replace("/\[crypt\](.*?)\[\/crypt\]/ism",'<br/><div id="' . $x . '"><img src="' .$a->get_baseurl() . '/images/lock_icon.gif" onclick="red_decrypt(\'rot13\',\'\',\'$1\',\'#' . $x . '\');" alt="' . t('Encrypted content') . '" title="' . t('Encrypted content') . '" /><br /></div>', $Text);
$Text = preg_replace_callback("/\[crypt (.*?)\](.*?)\[\/crypt\]/ism", 'bb_parse_crypt', $Text); $Text = preg_replace_callback("/\[crypt (.*?)\](.*?)\[\/crypt\]/ism", 'bb_parse_crypt', $Text);
} }
// Try to Oembed // Try to Oembed

View File

@ -33,14 +33,23 @@ function red_encrypt(alg, elem,text) {
var text = $(elem).val(); var text = $(elem).val();
// key and hint need to be localised
var enc_key = prompt('key'); var enc_key = prompt('key');
// If you don't provide a key you get rot13, which doesn't need a key
// but consequently isn't secure.
if(! enc_key) if(! enc_key)
alg = 'rot13'; alg = 'rot13';
if((alg == 'rot13') || (alg == 'triple-rot13')) if((alg == 'rot13') || (alg == 'triple-rot13'))
newdiv = "[crypt alg='rot13']" + str_rot13(text) + '[/crypt]'; newdiv = "[crypt alg='rot13']" + str_rot13(text) + '[/crypt]';
else if(alg == 'aes256') { else if(alg == 'aes256') {
// This is the prompt we're going to use when the receiver tries to open it.
// Maybe "Grandma's maiden name" or "our secret place" or something.
var enc_hint = prompt('hint'); var enc_hint = prompt('hint');
enc_text = CryptoJS.AES.encrypt(text,enc_key); enc_text = CryptoJS.AES.encrypt(text,enc_key);
@ -66,7 +75,7 @@ function red_encrypt(alg, elem,text) {
// } // }
} }
function red_decrypt(alg,hint,text) { function red_decrypt(alg,hint,text,elem) {
var enc_text = ''; var enc_text = '';
@ -78,8 +87,13 @@ function red_decrypt(alg,hint,text) {
enc_text = CryptoJS.AES.decrypt(text,enc_key); enc_text = CryptoJS.AES.decrypt(text,enc_key);
} }
alert(enc_text.toString(CryptoJS.enc.Utf8)); // Not sure whether to drop this back in the conversation display.
// It probably needs a lightbox or popup window because any conversation
// updates could
// wipe out the text and make you re-enter the key if it was in the
// conversation. For now we do that so you can read it.
$(elem).html(b2h(enc_text.toString(CryptoJS.enc.Utf8)));
} }

View File

@ -1 +1 @@
2013-11-10.493 2013-11-11.494

View File

@ -361,6 +361,42 @@ function enableOnUser(){
}; };
function b2h(s) {
var y = s;
function rep(re, str) {
y = y.replace(re,str);
};
rep(/\n/gi,"<br />");
rep(/\[b\]/gi,"<strong>");
rep(/\[\/b\]/gi,"</strong>");
rep(/\[i\]/gi,"<em>");
rep(/\[\/i\]/gi,"</em>");
rep(/\[u\]/gi,"<u>");
rep(/\[\/u\]/gi,"</u>");
rep(/\[hr\]/gi,"<hr />");
rep(/\[url=([^\]]+)\](.*?)\[\/url\]/gi,"<a href=\"$1\">$2</a>");
rep(/\[url\](.*?)\[\/url\]/gi,"<a href=\"$1\">$1</a>");
rep(/\[img=(.*?)x(.*?)\](.*?)\[\/img\]/gi,"<img width=\"$1\" height=\"$2\" src=\"$3\" />");
rep(/\[img\](.*?)\[\/img\]/gi,"<img src=\"$1\" />");
rep(/\[list\](.*?)\[\/list\]/gi, '<ul class="listbullet" style="list-style-type: circle;">$1</ul>');
rep(/\[list=\](.*?)\[\/list\]/gi, '<ul class="listnone" style="list-style-type: none;">$1</ul>');
rep(/\[list=1\](.*?)\[\/list\]/gi, '<ul class="listdecimal" style="list-style-type: decimal;">$1</ul>');
rep(/\[list=i\](.*?)\[\/list\]/gi,'<ul class="listlowerroman" style="list-style-type: lower-roman;">$1</ul>');
rep(/\[list=I\](.*?)\[\/list\]/gi, '<ul class="listupperroman" style="list-style-type: upper-roman;">$1</ul>');
rep(/\[list=a\](.*?)\[\/list\]/gi, '<ul class="listloweralpha" style="list-style-type: lower-alpha;">$1</ul>');
rep(/\[list=A\](.*?)\[\/list\]/gi, '<ul class="listupperalpha" style="list-style-type: upper-alpha;">$1</ul>');
rep(/\[li\](.*?)\[\/li\]/gi, '<li>$1</li>');
rep(/\[color=(.*?)\](.*?)\[\/color\]/gi,"<span style=\"color: $1;\">$2</span>");
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>");
return y;
};
{{$geotag}} {{$geotag}}
</script> </script>