From: Adam Magness Date: Sat, 3 Nov 2018 17:08:01 +0000 (-0400) Subject: Move to XML X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=84e900d96fd7343302490e29a0702eac271c8282;p=friendica.git Move to XML move functions from text to xml --- diff --git a/include/text.php b/include/text.php index 7f66268ad4..fadd375921 100644 --- a/include/text.php +++ b/include/text.php @@ -26,6 +26,7 @@ use Friendica\Util\Proxy as ProxyUtils; use Friendica\Core\Logger; use Friendica\Core\Renderer; use Friendica\Model\FileTag; +use Friendica\Util\XML; require_once "include/conversation.php"; @@ -162,80 +163,6 @@ function autoname($len) { return $word; } - -/** - * escape text ($str) for XML transport - * @param string $str - * @return string Escaped text. - */ -function xmlify($str) { - /// @TODO deprecated code found? -/* $buffer = ''; - - $len = mb_strlen($str); - for ($x = 0; $x < $len; $x ++) { - $char = mb_substr($str,$x,1); - - switch($char) { - - case "\r" : - break; - case "&" : - $buffer .= '&'; - break; - case "'" : - $buffer .= '''; - break; - case "\"" : - $buffer .= '"'; - break; - case '<' : - $buffer .= '<'; - break; - case '>' : - $buffer .= '>'; - break; - case "\n" : - $buffer .= "\n"; - break; - default : - $buffer .= $char; - break; - } - }*/ - /* - $buffer = mb_ereg_replace("&", "&", $str); - $buffer = mb_ereg_replace("'", "'", $buffer); - $buffer = mb_ereg_replace('"', """, $buffer); - $buffer = mb_ereg_replace("<", "<", $buffer); - $buffer = mb_ereg_replace(">", ">", $buffer); - */ - $buffer = htmlspecialchars($str, ENT_QUOTES, "UTF-8"); - $buffer = trim($buffer); - - return $buffer; -} - - -/** - * undo an xmlify - * @param string $s xml escaped text - * @return string unescaped text - */ -function unxmlify($s) { - /// @TODO deprecated code found? -// $ret = str_replace('&','&', $s); -// $ret = str_replace(array('<','>','"','''),array('<','>','"',"'"),$ret); - /*$ret = mb_ereg_replace('&', '&', $s); - $ret = mb_ereg_replace(''', "'", $ret); - $ret = mb_ereg_replace('"', '"', $ret); - $ret = mb_ereg_replace('<', "<", $ret); - $ret = mb_ereg_replace('>', ">", $ret); - */ - $ret = htmlspecialchars_decode($s, ENT_QUOTES); - return $ret; -} - /** * Loader for infinite scrolling * @return string html for loader @@ -1047,9 +974,9 @@ function get_cats_and_terms($item) if ($cnt) { foreach ($matches as $mtch) { $categories[] = [ - 'name' => xmlify(FileTag::decode($mtch[1])), + 'name' => XML::xmlify(FileTag::decode($mtch[1])), 'url' => "#", - 'removeurl' => ((local_user() == $item['uid'])?'filerm/' . $item['id'] . '?f=&cat=' . xmlify(FileTag::decode($mtch[1])):""), + 'removeurl' => ((local_user() == $item['uid'])?'filerm/' . $item['id'] . '?f=&cat=' . XML::xmlify(FileTag::decode($mtch[1])):""), 'first' => $first, 'last' => false ]; @@ -1068,9 +995,9 @@ function get_cats_and_terms($item) if ($cnt) { foreach ($matches as $mtch) { $folders[] = [ - 'name' => xmlify(FileTag::decode($mtch[1])), + 'name' => XML::xmlify(FileTag::decode($mtch[1])), 'url' => "#", - 'removeurl' => ((local_user() == $item['uid']) ? 'filerm/' . $item['id'] . '?f=&term=' . xmlify(FileTag::decode($mtch[1])) : ""), + 'removeurl' => ((local_user() == $item['uid']) ? 'filerm/' . $item['id'] . '?f=&term=' . XML::xmlify(FileTag::decode($mtch[1])) : ""), 'first' => $first, 'last' => false ]; @@ -1234,21 +1161,6 @@ function html2bb_video($s) { return $s; } -/** - * apply xmlify() to all values of array $val, recursively - * @param array $val - * @return array - */ -function array_xmlify($val){ - if (is_bool($val)) { - return $val?"true":"false"; - } elseif (is_array($val)) { - return array_map('array_xmlify', $val); - } - return xmlify((string) $val); -} - - /** * transform link href and img src from relative to absolute * diff --git a/src/Util/XML.php b/src/Util/XML.php index 865c60406b..9a3108ca98 100644 --- a/src/Util/XML.php +++ b/src/Util/XML.php @@ -462,4 +462,43 @@ class XML return $first_item->attributes; } + + /** + * escape text ($str) for XML transport + * @param string $str + * @return string Escaped text. + */ + public static function xmlify($str) + { + $buffer = htmlspecialchars($str, ENT_QUOTES, "UTF-8"); + $buffer = trim($buffer); + + return $buffer; + } + + /** + * undo an xmlify + * @param string $s xml escaped text + * @return string unescaped text + */ + public static function unxmlify($s) + { + $ret = htmlspecialchars_decode($s, ENT_QUOTES); + return $ret; + } + + /** + * apply xmlify() to all values of array $val, recursively + * @param array $val + * @return array + */ + public static function arrayXmlify($val) + { + if (is_bool($val)) { + return $val?"true":"false"; + } elseif (is_array($val)) { + return array_map('XML::arrayXmlify', $val); + } + return self::xmlify((string) $val); + } }