From 410fea03c16a5abe93ea567a67ed889b64764f9e Mon Sep 17 00:00:00 2001 From: Gautham Warrier Date: Mon, 11 Aug 2014 23:58:59 +0530 Subject: [PATCH] Ensure that pathinfo() does not skip Chinese filenames --- libs/daux_directory.php | 3 ++- libs/daux_helper.php | 18 +++++++++++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/libs/daux_directory.php b/libs/daux_directory.php index 96ae23f..a34875a 100644 --- a/libs/daux_directory.php +++ b/libs/daux_directory.php @@ -20,7 +20,8 @@ $this->local_path = $path; $this->parents = $parents; $this->last_modified = filemtime($path); - $this->name = pathinfo($path, PATHINFO_FILENAME); + $this->name = DauxHelper::pathinfo($path); + $this->name = $this->name['filename']; $this->title = DauxHelper::get_title_from_file($this->name); $this->uri = DauxHelper::get_url_from_filename($this->name); $this->index_page = false; diff --git a/libs/daux_helper.php b/libs/daux_helper.php index 901efed..c4dbb10 100644 --- a/libs/daux_helper.php +++ b/libs/daux_helper.php @@ -24,7 +24,8 @@ } public static function get_title_from_file($file) { - return static::get_title_from_filename(pathinfo($file, PATHINFO_FILENAME)); + $file = static::pathinfo($file); + return static::get_title_from_filename($file['filename']); } public static function get_title_from_filename($filename) { @@ -36,7 +37,8 @@ } public static function get_url_from_file($file) { - return static::get_url_from_filename(pathinfo($file, PATHINFO_FILENAME)); + $file = static::pathinfo($file); + return static::get_url_from_filename($file['filename']); } public static function get_url_from_filename($filename) { @@ -172,8 +174,9 @@ EOT; if (is_dir($path) && in_array($entry, $ignore['folders'])) continue; if (!is_dir($path) && in_array($entry, $ignore['files'])) continue; + $file_details = static::pathinfo($path); if (is_dir($path)) $entry = static::directory_tree_builder($path, $ignore, $mode, $new_parents); - else if (in_array(pathinfo($path, PATHINFO_EXTENSION), Daux::$VALID_MARKDOWN_EXTENSIONS)) + else if (in_array($file_details['extension'], Daux::$VALID_MARKDOWN_EXTENSIONS)) { $entry = new Directory_Entry($path, $new_parents); if ($mode === Daux::STATIC_MODE) $entry->uri .= '.html'; @@ -191,6 +194,15 @@ EOT; } } + public static function pathinfo($path) { + preg_match('%^(.*?)[\\\\/]*(([^/\\\\]*?)(\.([^\.\\\\/]+?)|))[\\\\/\.]*$%im', $path, $m); + if (isset($m[1])) $ret['dir']=$m[1]; + if (isset($m[2])) $ret['basename']=$m[2]; + if (isset($m[5])) $ret['extension']=$m[5]; + if (isset($m[3])) $ret['filename']=$m[3]; + return $ret; + } + public static function clean_copy_assets($path, $local_base){ @mkdir($path); static::clean_directory($path);