From a6165c00ce286a9b9ee84bb104c1b5d9d944823a Mon Sep 17 00:00:00 2001 From: Zot Date: Fri, 8 Nov 2019 10:47:00 +0100 Subject: svg stuff --- include/text.php | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'include/text.php') diff --git a/include/text.php b/include/text.php index 54ad9ec7a..2496ca934 100644 --- a/include/text.php +++ b/include/text.php @@ -9,6 +9,8 @@ use Michelf\MarkdownExtra; use Ramsey\Uuid\Uuid; use Ramsey\Uuid\Exception\UnsatisfiedDependencyException; +use Zotlabs\Lib\SvgSanitizer; + require_once("include/bbcode.php"); // random string, there are 86 characters max in text mode, 128 for hex @@ -3648,3 +3650,23 @@ function new_uuid() { return $hash; } + + +function svg2bb($s) { + + $s = preg_replace("/\(.*?)\<(.*?)\<\/text\>/", '$2<$3', $s); + $s = preg_replace("/\(.*?)\>(.*?)\<\/text\>/", '$2>$3', $s); + $s = preg_replace("/\(.*?)\[(.*?)\<\/text\>/", '$2[$3', $s); + $s = preg_replace("/\(.*?)\](.*?)\<\/text\>/", '$2]$3', $s); + $s = utf8_encode($s); + $purify = new SvgSanitizer(); + if ($purify->loadXML($s)) { + $purify->sanitize(); + $output = $purify->saveSVG(); + $output = preg_replace("/\<\?xml(.*?)\>/",'',$output); + $output = preg_replace("/\<\!\-\-(.*?)\-\-\>/",'',$output); + $output = str_replace(['<','>'],['[',']'],$output); + return $output; + } + return EMPTY_STR; +} -- cgit v1.2.3