OSDN Git Service

BugTrack/2420 AutoTicketLink - Improve regex and JSON encode
[pukiwiki/pukiwiki.git] / lib / func.php
index 41bcd81..4650529 100644 (file)
@@ -2,7 +2,7 @@
 // PukiWiki - Yet another WikiWikiWeb clone.
 // func.php
 // Copyright
-//   2002-2018 PukiWiki Development Team
+//   2002-2019 PukiWiki Development Team
 //   2001-2002 Originally written by yu-ji
 // License: GPL v2 or (at your option) any later version
 //
@@ -1048,6 +1048,21 @@ function htmlsc($string = '', $flags = ENT_COMPAT, $charset = CONTENT_CHARSET)
 }
 
 /**
+ * Get JSON string with htmlspecialchars().
+ */
+function htmlsc_json($obj)
+{
+       // json_encode: PHP 5.2+
+       // JSON_UNESCAPED_UNICODE: PHP 5.4+
+       // JSON_UNESCAPED_SLASHES: PHP 5.4+
+       if (defined('JSON_UNESCAPED_UNICODE')) {
+               return htmlsc(json_encode($obj,
+                       JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES));
+       }
+       return '';
+}
+
+/**
  * Get redirect page name on Page Redirect Rules
  *
  * This function returns exactly false if it doesn't need redirection.