Mercurial > hg > fapweb
changeset 780:f8d09e0de027
Properly implement stMakePath() replacing the stub function.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Thu, 20 Nov 2014 16:35:15 +0200 |
parents | 5ee9041c9c90 |
children | 6e9e42005701 |
files | msite.inc.php |
diffstat | 1 files changed, 37 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/msite.inc.php Thu Nov 20 15:47:41 2014 +0200 +++ b/msite.inc.php Thu Nov 20 16:35:15 2014 +0200 @@ -647,7 +647,43 @@ function stMakePath($isURL, $repExt, $components) { - return implode("/", $components); + $res = array(); + + // If this is URL, the first component is passed as is + if ($isURL) + { + $res[] = array_shift($components); + $first = FALSE; + } + else + $first = TRUE; + + // Handle each path component + foreach ($components as $subComponent) + { + foreach (explode("/", $subComponent) as $item) + { + if ($item == "..") + array_pop($res); + else + if ($item != "." && ($item != "" || $first)) + $res[] = preg_replace("/[^a-zA-Z0-9\,\.\/_-]/", "_", $item); + + $first = FALSE; + } + } + + if ($repExt !== FALSE && ($tmp = array_pop($res)) !== false) + { + if (($spos = strrpos($tmp, ".")) !== FALSE) + $tmp = substr($tmp, 0, $spos).$repExt; + else + $tmp .= $repExt; + + $res[] = $tmp; + } + + return implode("/", $res); }