diff options
author | Joas Schilling <nickvergessen@gmx.de> | 2013-04-17 17:45:49 +0200 |
---|---|---|
committer | Joas Schilling <nickvergessen@gmx.de> | 2013-04-17 17:46:58 +0200 |
commit | 869e00a23b0400b9ad81c1130227cc4c29d6a38d (patch) | |
tree | 997d3015d0479c0d2186bb6c873e1a2ddd9f0957 /phpBB/includes/filesystem.php | |
parent | 1fd5be859e3fe85e67fe7f5632e4630b96ca3634 (diff) | |
download | forums-869e00a23b0400b9ad81c1130227cc4c29d6a38d.tar forums-869e00a23b0400b9ad81c1130227cc4c29d6a38d.tar.gz forums-869e00a23b0400b9ad81c1130227cc4c29d6a38d.tar.bz2 forums-869e00a23b0400b9ad81c1130227cc4c29d6a38d.tar.xz forums-869e00a23b0400b9ad81c1130227cc4c29d6a38d.zip |
[ticket/11362] Move phpbb_clean_path into a simple filesystem service
PHPBB3-11362
Diffstat (limited to 'phpBB/includes/filesystem.php')
-rw-r--r-- | phpBB/includes/filesystem.php | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/phpBB/includes/filesystem.php b/phpBB/includes/filesystem.php new file mode 100644 index 0000000000..27cab48fb0 --- /dev/null +++ b/phpBB/includes/filesystem.php @@ -0,0 +1,52 @@ +<?php +/** +* +* @package phpBB3 +* @copyright (c) 2013 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ +/** +* @ignore +*/ +if (!defined('IN_PHPBB')) +{ + exit; +} + +/** +* A class with various functions that are related to paths, files and the filesystem +* @package phpBB3 +*/ +class phpbb_filesystem +{ + /** + * Eliminates useless . and .. components from specified path. + * + * @param string $path Path to clean + * @return string Cleaned path + */ + public function clean_path($path) + { + $exploded = explode('/', $path); + $filtered = array(); + foreach ($exploded as $part) + { + if ($part === '.' && !empty($filtered)) + { + continue; + } + + if ($part === '..' && !empty($filtered) && $filtered[sizeof($filtered) - 1] !== '..') + { + array_pop($filtered); + } + else + { + $filtered[] = $part; + } + } + $path = implode('/', $filtered); + return $path; + } +} |