aboutsummaryrefslogtreecommitdiff
path: root/pmwiki.php
diff options
context:
space:
mode:
authorpetko <petko@524c5546-5005-0410-9a3e-e25e191bd360>2024-07-26 16:04:48 +0000
committerpetko <petko@524c5546-5005-0410-9a3e-e25e191bd360>2024-07-26 16:04:48 +0000
commit58a411afb156c962d2b62d0a01e23e769a3aacf3 (patch)
tree853e7d94aec68e31ad7ed19959725b714dfb8d4a /pmwiki.php
parent5ae73e69e396caa528808354e9f88ee5a93b5676 (diff)
downloadpmwiki.svn-58a411afb156c962d2b62d0a01e23e769a3aacf3.tar.bz2
Add $EnableUploadDrop based on Cookbook:DragDropMultiUpload.
git-svn-id: svn://pmwiki.org/pmwiki/trunk@4739 524c5546-5005-0410-9a3e-e25e191bd360
Diffstat (limited to 'pmwiki.php')
-rw-r--r--pmwiki.php48
1 files changed, 48 insertions, 0 deletions
diff --git a/pmwiki.php b/pmwiki.php
index 1bcba98b..5a897739 100644
--- a/pmwiki.php
+++ b/pmwiki.php
@@ -846,6 +846,47 @@ function PRCB($pat, $repl, $subj, $vars=null, $limit=-1, &$count=null, $flags=0)
return preg_replace_callback($pat, $repl, $subj, $limit, $count, $flags);
return preg_replace_callback($pat, $repl, $subj, $limit, $count);
}
+
+## This is a replacement for json_encode+PHSC, but only for arrays that
+## are used by the PmWiki core. It may or may not work in other cases.
+## This may fail with international characters if UTF-8 is not enabled.
+function pm_json_encode($x, $encodespecial=false) {
+ if (!isset($x) || is_null($x)) return 'null';
+ if (is_bool($x)) return $x? "true" : "false";
+ if (is_int($x) || is_float($x)) return strval($x);
+
+ if (function_exists('json_encode'))
+ $out = json_encode($x);
+
+ elseif (is_string($x)) ## escape controls and specials per RFC:8259
+ $out = '"'.preg_replace_callback("/[\x00-\x1f\\/\\\\\"]/",'cb_rfc8259',$x).'"';
+
+ elseif (is_array($x)) {
+ $a = array();
+ if (array_values($x) === $x) { # numeric sequential array
+ foreach($x as $v)
+ $a[] = pm_json_encode($v);
+
+ $out = "[".implode(',', $a)."]";
+ }
+ else { # associative array -> json object
+ foreach($x as $k=>$v) {
+ $jk = is_int($k)? "\"$k\"" : pm_json_encode($k);
+ $jv = pm_json_encode($v);
+ $a[] = "$jk:$jv";
+ }
+ $out = "{".implode(',', $a)."}";
+ }
+ }
+ else return 'null'; # other types not yet supported
+
+ return $encodespecial? PHSC($out, ENT_QUOTES) : $out;
+}
+function cb_rfc8259($m) {
+ return sprintf('\\u00%02x', ord($m[0]));
+}
+
+
## callback functions
class PPRC { # PmWiki preg replace callbacks + pass local vars
var $vars;
@@ -1813,6 +1854,13 @@ function Redirect($pagename, $urlfmt='$PageUrl', $redirecturl=null) {
exit;
}
+function PrintJSON($pagename, $out) {
+ $json = pm_json_encode($out);
+ header('Content-Type: application/json');
+ print $json;
+ exit;
+}
+
function PrintFmt($pagename,$fmt) {
global $EnablePrePrintFmt;
if (IsEnabled($EnablePrePrintFmt, 1)) PrePrintFmt($pagename,$fmt);