tag and mention handling in private mail (which required refactoring the bbcode cleanup stuff in mod_item)
This commit is contained in:
parent
8e400e9e40
commit
0394a3e939
@ -556,42 +556,8 @@ class Item extends \Zotlabs\Web\Controller {
|
|||||||
if($x)
|
if($x)
|
||||||
$body .= "\n\n@group+" . $x[0]['abook_id'] . "\n";
|
$body .= "\n\n@group+" . $x[0]['abook_id'] . "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* fix naked links by passing through a callback to see if this is a hubzilla site
|
|
||||||
* (already known to us) which will get a zrl, otherwise link with url, add bookmark tag to both.
|
|
||||||
* First protect any url inside certain bbcode tags so we don't double link it.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
$body = preg_replace_callback('/\[code(.*?)\[\/(code)\]/ism','\red_escape_codeblock',$body);
|
|
||||||
$body = preg_replace_callback('/\[url(.*?)\[\/(url)\]/ism','\red_escape_codeblock',$body);
|
|
||||||
$body = preg_replace_callback('/\[zrl(.*?)\[\/(zrl)\]/ism','\red_escape_codeblock',$body);
|
|
||||||
|
|
||||||
|
|
||||||
$body = preg_replace_callback("/([^\]\='".'"'."\/]|^|\#\^)(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\@\_\~\#\%\$\!\+\,\(\)]+)/ism", 'nakedoembed', $body);
|
$body = cleanup_bbcode($body);
|
||||||
$body = preg_replace_callback("/([^\]\='".'"'."\/]|^|\#\^)(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\@\_\~\#\%\$\!\+\,\(\)]+)/ism", '\red_zrl_callback', $body);
|
|
||||||
|
|
||||||
$body = preg_replace_callback('/\[\$b64zrl(.*?)\[\/(zrl)\]/ism','\red_unescape_codeblock',$body);
|
|
||||||
$body = preg_replace_callback('/\[\$b64url(.*?)\[\/(url)\]/ism','\red_unescape_codeblock',$body);
|
|
||||||
$body = preg_replace_callback('/\[\$b64code(.*?)\[\/(code)\]/ism','\red_unescape_codeblock',$body);
|
|
||||||
|
|
||||||
|
|
||||||
// fix any img tags that should be zmg
|
|
||||||
|
|
||||||
$body = preg_replace_callback('/\[img(.*?)\](.*?)\[\/img\]/ism','\red_zrlify_img_callback',$body);
|
|
||||||
|
|
||||||
|
|
||||||
$body = bb_translate_video($body);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Fold multi-line [code] sequences
|
|
||||||
*/
|
|
||||||
|
|
||||||
$body = preg_replace('/\[\/code\]\s*\[code\]/ism',"\n",$body);
|
|
||||||
|
|
||||||
$body = scale_external_images($body,false);
|
|
||||||
|
|
||||||
|
|
||||||
// Look for tags and linkify them
|
// Look for tags and linkify them
|
||||||
$results = linkify_tags($a, $body, ($uid) ? $uid : $profile_uid);
|
$results = linkify_tags($a, $body, ($uid) ? $uid : $profile_uid);
|
||||||
|
@ -23,10 +23,12 @@ class Mail extends \Zotlabs\Web\Controller {
|
|||||||
$rstr = ((x($_REQUEST,'messagerecip')) ? notags(trim($_REQUEST['messagerecip'])) : '');
|
$rstr = ((x($_REQUEST,'messagerecip')) ? notags(trim($_REQUEST['messagerecip'])) : '');
|
||||||
$preview = ((x($_REQUEST,'preview')) ? intval($_REQUEST['preview']) : 0);
|
$preview = ((x($_REQUEST,'preview')) ? intval($_REQUEST['preview']) : 0);
|
||||||
$expires = ((x($_REQUEST,'expires')) ? datetime_convert(date_default_timezone_get(),'UTC', $_REQUEST['expires']) : NULL_DATE);
|
$expires = ((x($_REQUEST,'expires')) ? datetime_convert(date_default_timezone_get(),'UTC', $_REQUEST['expires']) : NULL_DATE);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if($preview) {
|
if($preview) {
|
||||||
|
|
||||||
|
$body = cleanup_bbcode($body);
|
||||||
|
$results = linkify_tags($a, $body, local_channel());
|
||||||
|
|
||||||
if(preg_match_all('/(\[attachment\](.*?)\[\/attachment\])/',$body,$match)) {
|
if(preg_match_all('/(\[attachment\](.*?)\[\/attachment\])/',$body,$match)) {
|
||||||
$attachments = array();
|
$attachments = array();
|
||||||
foreach($match[2] as $mtch) {
|
foreach($match[2] as $mtch) {
|
||||||
@ -45,18 +47,11 @@ class Mail extends \Zotlabs\Web\Controller {
|
|||||||
$body = trim(str_replace($match[1],'',$body));
|
$body = trim(str_replace($match[1],'',$body));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
logger('previewing');
|
|
||||||
echo json_encode(['preview' => smilies(bbcode($body))]);
|
echo json_encode(['preview' => smilies(bbcode($body))]);
|
||||||
killme();
|
killme();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// If we have a raw string for a recipient which hasn't been auto-filled,
|
// If we have a raw string for a recipient which hasn't been auto-filled,
|
||||||
// it means they probably aren't in our address book, hence we don't know
|
// it means they probably aren't in our address book, hence we don't know
|
||||||
// if we have permission to send them private messages.
|
// if we have permission to send them private messages.
|
||||||
|
@ -16,6 +16,28 @@ function send_message($uid = 0, $recipient = '', $body = '', $subject = '', $rep
|
|||||||
$a = get_app();
|
$a = get_app();
|
||||||
$observer_hash = get_observer_hash();
|
$observer_hash = get_observer_hash();
|
||||||
|
|
||||||
|
|
||||||
|
if($uid) {
|
||||||
|
$r = q("select * from channel where channel_id = %d limit 1",
|
||||||
|
intval($uid)
|
||||||
|
);
|
||||||
|
if($r)
|
||||||
|
$channel = $r[0];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$channel = App::get_channel();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(! $channel) {
|
||||||
|
$ret['message'] = t('Unable to determine sender.');
|
||||||
|
return $ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$body = cleanup_bbcode($body);
|
||||||
|
$results = linkify_tags($a, $body, $uid);
|
||||||
|
|
||||||
|
|
||||||
if(preg_match_all("/\[attachment\](.*?)\[\/attachment\]/",((strpos($body,'[/crypt]')) ? $_POST['media_str'] : $body),$match))
|
if(preg_match_all("/\[attachment\](.*?)\[\/attachment\]/",((strpos($body,'[/crypt]')) ? $_POST['media_str'] : $body),$match))
|
||||||
$attaches = $match[1];
|
$attaches = $match[1];
|
||||||
|
|
||||||
@ -43,22 +65,6 @@ function send_message($uid = 0, $recipient = '', $body = '', $subject = '', $rep
|
|||||||
$jattach = (($attachments) ? json_encode($attachments) : '');
|
$jattach = (($attachments) ? json_encode($attachments) : '');
|
||||||
|
|
||||||
|
|
||||||
if($preview) {
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if(! $recipient) {
|
if(! $recipient) {
|
||||||
$ret['message'] = t('No recipient provided.');
|
$ret['message'] = t('No recipient provided.');
|
||||||
return $ret;
|
return $ret;
|
||||||
@ -67,22 +73,6 @@ function send_message($uid = 0, $recipient = '', $body = '', $subject = '', $rep
|
|||||||
if(! strlen($subject))
|
if(! strlen($subject))
|
||||||
$subject = t('[no subject]');
|
$subject = t('[no subject]');
|
||||||
|
|
||||||
if($uid) {
|
|
||||||
$r = q("select * from channel where channel_id = %d limit 1",
|
|
||||||
intval($uid)
|
|
||||||
);
|
|
||||||
if($r)
|
|
||||||
$channel = $r[0];
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$channel = App::get_channel();
|
|
||||||
}
|
|
||||||
|
|
||||||
if(! $channel) {
|
|
||||||
$ret['message'] = t('Unable to determine sender.');
|
|
||||||
return $ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// look for any existing conversation structure
|
// look for any existing conversation structure
|
||||||
|
|
||||||
|
@ -3061,4 +3061,50 @@ function create_table_from_array($table, $arr) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return $r;
|
return $r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function cleanup_bbcode($body) {
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* fix naked links by passing through a callback to see if this is a hubzilla site
|
||||||
|
* (already known to us) which will get a zrl, otherwise link with url, add bookmark tag to both.
|
||||||
|
* First protect any url inside certain bbcode tags so we don't double link it.
|
||||||
|
*/
|
||||||
|
|
||||||
|
$body = preg_replace_callback('/\[code(.*?)\[\/(code)\]/ism','\red_escape_codeblock',$body);
|
||||||
|
$body = preg_replace_callback('/\[url(.*?)\[\/(url)\]/ism','\red_escape_codeblock',$body);
|
||||||
|
$body = preg_replace_callback('/\[zrl(.*?)\[\/(zrl)\]/ism','\red_escape_codeblock',$body);
|
||||||
|
|
||||||
|
|
||||||
|
$body = preg_replace_callback("/([^\]\='".'"'."\/]|^|\#\^)(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\@\_\~\#\%\$\!\\
|
||||||
|
+\,\(\)]+)/ism", 'nakedoembed', $body);
|
||||||
|
$body = preg_replace_callback("/([^\]\='".'"'."\/]|^|\#\^)(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\@\_\~\#\%\$\!\\
|
||||||
|
+\,\(\)]+)/ism", '\red_zrl_callback', $body);
|
||||||
|
|
||||||
|
$body = preg_replace_callback('/\[\$b64zrl(.*?)\[\/(zrl)\]/ism','\red_unescape_codeblock',$body);
|
||||||
|
$body = preg_replace_callback('/\[\$b64url(.*?)\[\/(url)\]/ism','\red_unescape_codeblock',$body);
|
||||||
|
$body = preg_replace_callback('/\[\$b64code(.*?)\[\/(code)\]/ism','\red_unescape_codeblock',$body);
|
||||||
|
|
||||||
|
|
||||||
|
// fix any img tags that should be zmg
|
||||||
|
|
||||||
|
$body = preg_replace_callback('/\[img(.*?)\](.*?)\[\/img\]/ism','\red_zrlify_img_callback',$body);
|
||||||
|
|
||||||
|
|
||||||
|
$body = bb_translate_video($body);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fold multi-line [code] sequences
|
||||||
|
*/
|
||||||
|
|
||||||
|
$body = preg_replace('/\[\/code\]\s*\[code\]/ism',"\n",$body);
|
||||||
|
|
||||||
|
$body = scale_external_images($body,false);
|
||||||
|
|
||||||
|
|
||||||
|
return $body;
|
||||||
|
|
||||||
|
}
|
||||||
|
@ -4,4 +4,5 @@ $(document).ready(function() {
|
|||||||
});
|
});
|
||||||
$(".autotime").timeago()
|
$(".autotime").timeago()
|
||||||
$('#prvmail-text').bbco_autocomplete('bbcode');
|
$('#prvmail-text').bbco_autocomplete('bbcode');
|
||||||
|
$("#prvmail-text").editor_autocomplete(baseurl+"/acl");
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user