From 0394a3e93957b5bb6574ca95e290e414ed049404 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Tue, 13 Dec 2016 20:01:38 -0800 Subject: tag and mention handling in private mail (which required refactoring the bbcode cleanup stuff in mod_item) --- include/text.php | 48 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) (limited to 'include/text.php') diff --git a/include/text.php b/include/text.php index b25eb8e46..e014024c2 100644 --- a/include/text.php +++ b/include/text.php @@ -3061,4 +3061,50 @@ function create_table_from_array($table, $arr) { } return $r; -} \ No newline at end of file +} + + + +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; + +} -- cgit v1.2.3 From cbffd32d8ea14d38da65b646c205dc6518eeb7e0 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Tue, 13 Dec 2016 20:05:36 -0800 Subject: use absolute namespace in case this gets moved --- include/text.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/text.php') diff --git a/include/text.php b/include/text.php index e014024c2..593822bc7 100644 --- a/include/text.php +++ b/include/text.php @@ -3080,7 +3080,7 @@ function cleanup_bbcode($body) { $body = preg_replace_callback("/([^\]\='".'"'."\/]|^|\#\^)(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\@\_\~\#\%\$\!\\ -+\,\(\)]+)/ism", 'nakedoembed', $body); ++\,\(\)]+)/ism", '\nakedoembed', $body); $body = preg_replace_callback("/([^\]\='".'"'."\/]|^|\#\^)(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\@\_\~\#\%\$\!\\ +\,\(\)]+)/ism", '\red_zrl_callback', $body); -- cgit v1.2.3 From 350627988eb7813dac69450ff97f03a33e70d9f2 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Mon, 19 Dec 2016 14:35:13 -0800 Subject: zidify private mail --- include/text.php | 1 - 1 file changed, 1 deletion(-) (limited to 'include/text.php') diff --git a/include/text.php b/include/text.php index 593822bc7..d6151d8ef 100644 --- a/include/text.php +++ b/include/text.php @@ -3088,7 +3088,6 @@ function cleanup_bbcode($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); -- cgit v1.2.3 From f2bfdfdeddea86784ce2d17b3c35e46a1c582b79 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Wed, 21 Dec 2016 23:35:54 -0800 Subject: provide separate logging (if configured) for btlogger which is used to catch really subtle issues which don't always leave an audit trail. Similar to dbfail.out, the file btlogger.out (if it exists and is write-able) will only log these unusual situations with backtraces so we can find the culprits. --- include/text.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'include/text.php') diff --git a/include/text.php b/include/text.php index d6151d8ef..c4fafd8ef 100644 --- a/include/text.php +++ b/include/text.php @@ -656,11 +656,24 @@ function logger($msg, $level = LOGGER_NORMAL, $priority = LOG_INFO) { function btlogger($msg, $level = LOGGER_NORMAL, $priority = LOG_INFO) { logger($msg, $level, $priority); + + if(file_exists('btlogger.log') && is_writable('btlogger.log')) { + $stack = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2); + $where = basename($stack[0]['file']) . ':' . $stack[0]['line'] . ':' . $stack[1]['function'] . ': '; + $s = datetime_convert() . ':' . log_priority_str($priority) . ':' . session_id() . ':' . $where . $msg . PHP_EOL; + @file_put_contents('btlogger.log', $s, FILE_APPEND); + } + if(version_compare(PHP_VERSION, '5.4.0') >= 0) { $stack = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); if($stack) { for($x = 1; $x < count($stack); $x ++) { - logger('stack: ' . basename($stack[$x]['file']) . ':' . $stack[$x]['line'] . ':' . $stack[$x]['function'] . '()',$level, $priority); + $s = 'stack: ' . basename($stack[$x]['file']) . ':' . $stack[$x]['line'] . ':' . $stack[$x]['function'] . '()'; + logger($s,$level, $priority); + + if(file_exists('btlogger.log') && is_writable('btlogger.log')) { + @file_put_contents('btlogger.log', $s, FILE_APPEND); + } } } } -- cgit v1.2.3 From 2312302deade5ccc2e65cd58483a4f40a8d4aea4 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Thu, 5 Jan 2017 14:17:56 -0800 Subject: setup: check disabled functions more precisely than using a string match --- include/text.php | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'include/text.php') diff --git a/include/text.php b/include/text.php index c4fafd8ef..fbf6df49e 100644 --- a/include/text.php +++ b/include/text.php @@ -3120,3 +3120,9 @@ function cleanup_bbcode($body) { return $body; } + +// callback for array_walk + +function array_trim(&$v,$k) { + $v = trim($v); +} \ No newline at end of file -- cgit v1.2.3 From 9ad44a2060b9f294423376f1fad43fa17d1dffe4 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Tue, 10 Jan 2017 17:37:41 -0800 Subject: btlogger trace file logging not working as desired. --- include/text.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'include/text.php') diff --git a/include/text.php b/include/text.php index fbf6df49e..bc1eff7db 100644 --- a/include/text.php +++ b/include/text.php @@ -655,13 +655,16 @@ function logger($msg, $level = LOGGER_NORMAL, $priority = LOG_INFO) { */ function btlogger($msg, $level = LOGGER_NORMAL, $priority = LOG_INFO) { + if(! defined('BTLOGGER_DEBUG_FILE')) + define('BTLOGGER_DEBUG_FILE','btlogger.out'); + logger($msg, $level, $priority); - if(file_exists('btlogger.log') && is_writable('btlogger.log')) { + if(file_exists(BTLOGGER_DEBUG_FILE) && is_writable(BTLOGGER_DEBUG_FILE)) { $stack = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2); $where = basename($stack[0]['file']) . ':' . $stack[0]['line'] . ':' . $stack[1]['function'] . ': '; $s = datetime_convert() . ':' . log_priority_str($priority) . ':' . session_id() . ':' . $where . $msg . PHP_EOL; - @file_put_contents('btlogger.log', $s, FILE_APPEND); + @file_put_contents(BTLOGGER_DEBUG_FILE, $s, FILE_APPEND); } if(version_compare(PHP_VERSION, '5.4.0') >= 0) { @@ -671,8 +674,8 @@ function btlogger($msg, $level = LOGGER_NORMAL, $priority = LOG_INFO) { $s = 'stack: ' . basename($stack[$x]['file']) . ':' . $stack[$x]['line'] . ':' . $stack[$x]['function'] . '()'; logger($s,$level, $priority); - if(file_exists('btlogger.log') && is_writable('btlogger.log')) { - @file_put_contents('btlogger.log', $s, FILE_APPEND); + if(file_exists(BTLOGGER_DEBUG_FILE) && is_writable(BTLOGGER_DEBUG_FILE)) { + @file_put_contents(BTLOGGER_DEBUG_FILE, $s . PHP_EOL, FILE_APPEND); } } } -- cgit v1.2.3 From c32bc9dda4dc08f2e4e72dc91c78457a0383244e Mon Sep 17 00:00:00 2001 From: zotlabs Date: Sun, 15 Jan 2017 19:51:14 -0800 Subject: more integration of vcard and profiles --- include/text.php | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'include/text.php') diff --git a/include/text.php b/include/text.php index bc1eff7db..f5b1803c2 100644 --- a/include/text.php +++ b/include/text.php @@ -3128,4 +3128,8 @@ function cleanup_bbcode($body) { function array_trim(&$v,$k) { $v = trim($v); +} + +function array_escape_tags(&$v,$k) { + $v = escape_tags($v); } \ No newline at end of file -- cgit v1.2.3 From 96f196febda488e1db2d9a677fd5eb736aa76ae6 Mon Sep 17 00:00:00 2001 From: Hubzilla Date: Thu, 19 Jan 2017 15:37:30 -0800 Subject: add gen_link_id() function to selectively encode/decode the message-id component of /display/ links for message-ids that contain troublesome characters --- include/text.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'include/text.php') diff --git a/include/text.php b/include/text.php index f5b1803c2..1beefc6eb 100644 --- a/include/text.php +++ b/include/text.php @@ -3124,6 +3124,12 @@ function cleanup_bbcode($body) { } +function gen_link_id($mid) { + if(strpbrk($mid,':/&?<>"\'') !== false) + return 'b64.' . base64url_encode($mid); + return $mid; +} + // callback for array_walk function array_trim(&$v,$k) { @@ -3132,4 +3138,5 @@ function array_trim(&$v,$k) { function array_escape_tags(&$v,$k) { $v = escape_tags($v); -} \ No newline at end of file +} + -- cgit v1.2.3 From 7b065365e0d64a06ddfb7ade55e713a4b6a0f802 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Mon, 30 Jan 2017 15:01:22 -0800 Subject: consolidate hubloc storage --- include/text.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/text.php') diff --git a/include/text.php b/include/text.php index 1beefc6eb..4f0dc869b 100644 --- a/include/text.php +++ b/include/text.php @@ -4,7 +4,7 @@ */ require_once("include/bbcode.php"); -require_once('include/hubloc.php'); + // random string, there are 86 characters max in text mode, 128 for hex // output is urlsafe -- cgit v1.2.3 From 732065bf13af96f680bc9874afee71c07f74e40a Mon Sep 17 00:00:00 2001 From: zotlabs Date: Tue, 31 Jan 2017 15:28:25 -0800 Subject: channel export - use a selected list of functional data categories to export; this allows one to export single data sets instead of always exporting everything we know about --- include/text.php | 1 + 1 file changed, 1 insertion(+) (limited to 'include/text.php') diff --git a/include/text.php b/include/text.php index 4f0dc869b..8c01ed1d2 100644 --- a/include/text.php +++ b/include/text.php @@ -3130,6 +3130,7 @@ function gen_link_id($mid) { return $mid; } + // callback for array_walk function array_trim(&$v,$k) { -- cgit v1.2.3 From 07d92796d263d5add84793064e03108eec85db94 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Tue, 14 Feb 2017 20:57:14 -0800 Subject: provide HTTP header parser which honours continuation lines and despite the fact that continuation lines have been deprecated - as they still exist in the wild. --- include/text.php | 5 ----- 1 file changed, 5 deletions(-) (limited to 'include/text.php') diff --git a/include/text.php b/include/text.php index 8c01ed1d2..cfec1ddf6 100644 --- a/include/text.php +++ b/include/text.php @@ -1581,11 +1581,6 @@ function prepare_body(&$item,$attach = false) { $photo = $prep_arr['photo']; $event = $prep_arr['event']; -// q("update item set html = '%s' where id = %d", -// dbesc($s), -// intval($item['id']) -// ); - if(! $attach) { return $s; } -- cgit v1.2.3 From 5db3b71c6aad7b27e440dcf32978b9a5d39b97b3 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Wed, 15 Feb 2017 11:35:36 -0800 Subject: strip possible quotes from attribute_contains() haystacks --- include/text.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'include/text.php') diff --git a/include/text.php b/include/text.php index cfec1ddf6..eb8147f9a 100644 --- a/include/text.php +++ b/include/text.php @@ -586,8 +586,10 @@ function photo_new_resource() { * @return boolean true if found */ function attribute_contains($attr, $s) { + // remove quotes + $attr = str_replace([ '"',"'" ],['',''],$attr); $a = explode(' ', $attr); - if(count($a) && in_array($s, $a)) + if($a && in_array($s, $a)) return true; return false; -- cgit v1.2.3