diff options
author | rvelices <rv-github@modusoptimus.com> | 2008-02-27 02:31:51 +0000 |
---|---|---|
committer | rvelices <rv-github@modusoptimus.com> | 2008-02-27 02:31:51 +0000 |
commit | 75bb450a6ece6b2e30ad4c148083b7192d7d7224 (patch) | |
tree | 6b3e6c0da5baa7ba7e736e79a4b49a83918f25c9 /include/smarty/libs/internals/core.create_dir_structure.php | |
parent | 01687607ec04f32ca03370456c112b64f66ca599 (diff) |
- first smarty use ... (in admin.php and admin plugins page)
git-svn-id: http://piwigo.org/svn/trunk@2216 68402e56-0260-453c-a942-63ccdbb3a9ee
Diffstat (limited to 'include/smarty/libs/internals/core.create_dir_structure.php')
-rw-r--r-- | include/smarty/libs/internals/core.create_dir_structure.php | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/include/smarty/libs/internals/core.create_dir_structure.php b/include/smarty/libs/internals/core.create_dir_structure.php new file mode 100644 index 000000000..3eecc4972 --- /dev/null +++ b/include/smarty/libs/internals/core.create_dir_structure.php @@ -0,0 +1,79 @@ +<?php +/** + * Smarty plugin + * @package Smarty + * @subpackage plugins + */ + +/** + * create full directory structure + * + * @param string $dir + */ + +// $dir + +function smarty_core_create_dir_structure($params, &$smarty) +{ + if (!file_exists($params['dir'])) { + $_open_basedir_ini = ini_get('open_basedir'); + + if (DIRECTORY_SEPARATOR=='/') { + /* unix-style paths */ + $_dir = $params['dir']; + $_dir_parts = preg_split('!/+!', $_dir, -1, PREG_SPLIT_NO_EMPTY); + $_new_dir = (substr($_dir, 0, 1)=='/') ? '/' : getcwd().'/'; + if($_use_open_basedir = !empty($_open_basedir_ini)) { + $_open_basedirs = explode(':', $_open_basedir_ini); + } + + } else { + /* other-style paths */ + $_dir = str_replace('\\','/', $params['dir']); + $_dir_parts = preg_split('!/+!', $_dir, -1, PREG_SPLIT_NO_EMPTY); + if (preg_match('!^((//)|([a-zA-Z]:/))!', $_dir, $_root_dir)) { + /* leading "//" for network volume, or "[letter]:/" for full path */ + $_new_dir = $_root_dir[1]; + /* remove drive-letter from _dir_parts */ + if (isset($_root_dir[3])) array_shift($_dir_parts); + + } else { + $_new_dir = str_replace('\\', '/', getcwd()).'/'; + + } + + if($_use_open_basedir = !empty($_open_basedir_ini)) { + $_open_basedirs = explode(';', str_replace('\\', '/', $_open_basedir_ini)); + } + + } + + /* all paths use "/" only from here */ + foreach ($_dir_parts as $_dir_part) { + $_new_dir .= $_dir_part; + + if ($_use_open_basedir) { + // do not attempt to test or make directories outside of open_basedir + $_make_new_dir = false; + foreach ($_open_basedirs as $_open_basedir) { + if (substr($_new_dir, 0, strlen($_open_basedir)) == $_open_basedir) { + $_make_new_dir = true; + break; + } + } + } else { + $_make_new_dir = true; + } + + if ($_make_new_dir && !file_exists($_new_dir) && !@mkdir($_new_dir, $smarty->_dir_perms) && !is_dir($_new_dir)) { + $smarty->trigger_error("problem creating directory '" . $_new_dir . "'"); + return false; + } + $_new_dir .= '/'; + } + } +} + +/* vim: set expandtab: */ + +?> |