summaryrefslogtreecommitdiff
path: root/inc
diff options
context:
space:
mode:
Diffstat (limited to 'inc')
-rw-r--r--inc/load.php1
-rw-r--r--inc/pageutils.php50
-rw-r--r--inc/utf8.php39
3 files changed, 51 insertions, 39 deletions
diff --git a/inc/load.php b/inc/load.php
index faf4e9570..2f5be6d63 100644
--- a/inc/load.php
+++ b/inc/load.php
@@ -73,6 +73,7 @@ function load_autoload($name){
'ZipLib' => DOKU_INC.'inc/ZipLib.class.php',
'DokuWikiFeedCreator' => DOKU_INC.'inc/feedcreator.class.php',
'Doku_Parser_Mode' => DOKU_INC.'inc/parser/parser.php',
+ 'SafeFN' => DOKU_INC.'inc/SafeFN.class.php',
'DokuWiki_Action_Plugin' => DOKU_PLUGIN.'action.php',
'DokuWiki_Admin_Plugin' => DOKU_PLUGIN.'admin.php',
diff --git a/inc/pageutils.php b/inc/pageutils.php
index cd3cf1fce..43c84038f 100644
--- a/inc/pageutils.php
+++ b/inc/pageutils.php
@@ -543,3 +543,53 @@ function prettyprint_id($id) {
}
return hsc($id);
}
+
+/**
+ * Encode a UTF-8 filename to use on any filesystem
+ *
+ * Uses the 'fnencode' option to determine encoding
+ *
+ * When the second parameter is true the string will
+ * be encoded only if non ASCII characters are detected -
+ * This makes it safe to run it multiple times on the
+ * same string (default is true)
+ *
+ * @author Andreas Gohr <andi@splitbrain.org>
+ * @see urlencode
+ */
+function utf8_encodeFN($file,$safe=true){
+ global $conf;
+ if($conf['fnencode'] == 'utf-8') return $file;
+
+ if($safe && preg_match('#^[a-zA-Z0-9/_\-\.%]+$#',$file)){
+ return $file;
+ }
+
+ if($conf['fnencode'] == 'safe'){
+ return SafeFN::encode($file);
+ }
+
+ $file = urlencode($file);
+ $file = str_replace('%2F','/',$file);
+ return $file;
+}
+
+/**
+ * Decode a filename back to UTF-8
+ *
+ * Uses the 'fnencode' option to determine encoding
+ *
+ * @author Andreas Gohr <andi@splitbrain.org>
+ * @see urldecode
+ */
+function utf8_decodeFN($file){
+ global $conf;
+ if($conf['fnencode'] == 'utf-8') return $file;
+
+ if($conf['fnencode'] == 'safe'){
+ return SafeFN::decode($file);
+ }
+
+ return urldecode($file);
+}
+
diff --git a/inc/utf8.php b/inc/utf8.php
index b078540d2..c10e33ffa 100644
--- a/inc/utf8.php
+++ b/inc/utf8.php
@@ -19,45 +19,6 @@ if(!defined('UTF8_MBSTRING')){
if(UTF8_MBSTRING){ mb_internal_encoding('UTF-8'); }
-if(!function_exists('utf8_encodeFN')){
- /**
- * URL-Encode a filename to allow unicodecharacters
- *
- * Slashes are not encoded
- *
- * When the second parameter is true the string will
- * be encoded only if non ASCII characters are detected -
- * This makes it safe to run it multiple times on the
- * same string (default is true)
- *
- * @author Andreas Gohr <andi@splitbrain.org>
- * @see urlencode
- */
- function utf8_encodeFN($file,$safe=true){
- if($safe && preg_match('#^[a-zA-Z0-9/_\-.%]+$#',$file)){
- return $file;
- }
- $file = urlencode($file);
- $file = str_replace('%2F','/',$file);
- return $file;
- }
-}
-
-if(!function_exists('utf8_decodeFN')){
- /**
- * URL-Decode a filename
- *
- * This is just a wrapper around urldecode
- *
- * @author Andreas Gohr <andi@splitbrain.org>
- * @see urldecode
- */
- function utf8_decodeFN($file){
- $file = urldecode($file);
- return $file;
- }
-}
-
if(!function_exists('utf8_isASCII')){
/**
* Checks if a string contains 7bit ASCII only