]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - lib/util.php
Twitter-compatible API - don't strip XML-illegal chars from JSON output
[quix0rs-gnu-social.git] / lib / util.php
index 88841d3f6aa69f2210a87ac1f210ae46f8839e64..6ec557b2f915f9ba08e1ab8989caea9a5e0e47e8 100644 (file)
@@ -146,7 +146,9 @@ function common_init_language() {
        bind_textdomain_codeset("laconica", "UTF-8");
        textdomain("laconica");
        setlocale(LC_CTYPE, 'C');
-       common_log(LOG_INFO,'Language requested:'.$language.' Locale set:'.$locale_set,__FILE__);
+       if(!$locale_set) {
+               common_log(LOG_INFO,'Language requested:'.$language.' - locale could not be set:',__FILE__);
+       }
 }
 
 define('PAGE_TYPE_PREFS', 'text/html,application/xhtml+xml,application/xml;q=0.3,text/xml;q=0.2');
@@ -708,7 +710,7 @@ function common_render_content($text, $notice) {
 }
 
 function common_render_text($text) {
-       $r = htmlentities($text, ENT_NOQUOTES, 'UTF-8');
+       $r = htmlspecialchars($text);
 
        $r = preg_replace('/[\x{0}-\x{8}\x{b}-\x{c}\x{e}-\x{19}]/', '', $r);
        $r = preg_replace_callback('@https?://[^\]>\s]+@', 'common_render_uri_thingy', $r);
@@ -745,6 +747,13 @@ function common_render_uri_thingy($matches) {
        return '<a href="' . $uri . '" class="extlink">' . $uri . '</a>' . $trailer;
 }
 
+function common_xml_safe_str($str) {
+       $xmlStr = htmlentities(iconv('UTF-8', 'UTF-8//IGNORE', $str), ENT_NOQUOTES, 'UTF-8');
+       
+       // Replace control, formatting, and surrogate characters with '*', ala Twitter
+       return preg_replace('/[\p{Cc}\p{Cf}\p{Cs}]/u', '*', $str);
+}
+
 function common_tag_link($tag) {
        $canonical = common_canonical_tag($tag);
        $url = common_local_url('tag', array('tag' => $canonical));