aboutsummaryrefslogtreecommitdiff
path: root/scripts/utils.php
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/utils.php')
-rw-r--r--scripts/utils.php77
1 files changed, 30 insertions, 47 deletions
diff --git a/scripts/utils.php b/scripts/utils.php
index bcbdcf10..a26b786c 100644
--- a/scripts/utils.php
+++ b/scripts/utils.php
@@ -21,17 +21,18 @@
To disable all these functions, add to config.php:
$EnablePmUtils = 0;
*/
-function PmUtilsJS() {
+function PmUtilsJS($pagename) {
global $PmTOC, $EnableSortable, $EnableHighlight, $EnableLocalTimes, $ToggleNextSelector,
$LinkFunctions, $FarmD, $HTMLStylesFmt, $HTMLHeaderFmt, $EnablePmSyntax, $CustomSyntax,
- $EnableCopyCode, $EnableDarkThemeToggle, $EnableRedirectQuiet;
+ $EnableCopyCode, $EnableDarkThemeToggle, $EnableRedirectQuiet,
+ $EnableUploadDrop, $UploadExtSize, $EnableUploadAuthorRequired;
$utils = "$FarmD/pub/pmwiki-utils.js";
$dark = "$FarmD/pub/pmwiki-darktoggle.js";
$cc = IsEnabled($EnableCopyCode, 0)? XL('Copy code') : '';
- if($cc) {
+ if ($cc) {
SDVA($HTMLStylesFmt, array('copycode'=>'
.pmcopycode { cursor:pointer; display:block; border-radius:.2em; opacity:.2; position:relative; z-index:2; }
.pmcopycode::before { content:"+"; display:block; width:.8em; height:.8em; line-height:.8em; text-align:center; }
@@ -41,6 +42,24 @@ function PmUtilsJS() {
pre:hover .pmcopycode { opacity:1; }
'));
}
+ if (IsEnabled($EnableUploadDrop, 0) && CondAuth($pagename, 'upload', 1)) {
+ $ddmu = array(
+ 'action' => '{$PageUrl}?action=postupload',
+ 'token' => ['$TokenName', pmtoken()],
+ 'label' => XL('ULdroplabel'),
+ 'badtype' => str_replace('$', '#', XL('ULbadtype')),
+ 'toobig' => str_replace('$', '#', preg_replace('/\\s+/',' ', XL('ULtoobigext'))),
+ 'sizes' => array(),
+ );
+ if(IsEnabled($EnableUploadAuthorRequired, 0)) {
+ $ddmu['areq'] = XL('ULauthorrequired');
+ }
+
+ foreach($UploadExtSize as $ext=>$bytes) {
+ if($bytes>0) $ddmu['sizes'][$ext] = $bytes;
+ }
+ }
+ else $ddmu = false;
if (file_exists($utils)) {
$mtime = filemtime($utils);
@@ -51,6 +70,7 @@ function PmUtilsJS() {
'toggle' => IsEnabled($ToggleNextSelector, 0),
'localtimes' => IsEnabled($EnableLocalTimes, 0),
'rediquiet' => IsEnabled($EnableRedirectQuiet, 0),
+ 'updrop' => $ddmu,
);
$enabled = $PmTOC['Enable'];
foreach($config as $i) {
@@ -69,12 +89,15 @@ function PmUtilsJS() {
if (IsEnabled($EnablePmSyntax, 0)) { # inject before skins and local.css
$cs = is_array(@$CustomSyntax) ?
pm_json_encode(array_values($CustomSyntax), true) : '';
- array_unshift($HTMLHeaderFmt, "<link rel='stylesheet'
- href='\$FarmPubDirUrl/guiedit/pmwiki.syntax.css'>
- <script src='\$FarmPubDirUrl/guiedit/pmwiki.syntax.js' data-imap='{\$EnabledIMap}'
+ array_unshift($HTMLHeaderFmt, "<script data-imap='{\$EnabledIMap}'
+ src='\$FarmPubDirUrl/guiedit/pmwiki.syntax.js'
data-label=\"$[Highlight]\" data-mode='$EnablePmSyntax'
data-custom=\"$cs\"></script>");
}
+ if (IsEnabled($EnablePmSyntax, 0) || $ddmu) {
+ array_unshift($HTMLHeaderFmt, "<link rel='stylesheet'
+ href='\$FarmPubDirUrl/guiedit/pmwiki.syntax.css'>");
+ }
// Dark theme toggle, needs to be very early
$enabled = IsEnabled($EnableDarkThemeToggle, 0);
@@ -89,45 +112,5 @@ function PmUtilsJS() {
data-config='$json'></script>");
}
}
-PmUtilsJS();
-
-## 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]));
-}
+PmUtilsJS($pagename);