diff --git a/common/functions.php b/common/functions.php index 154d60455..6840cdcaa 100644 --- a/common/functions.php +++ b/common/functions.php @@ -133,6 +133,19 @@ function class_basename($class) return basename(str_replace('\\', '/', is_object($class) ? get_class($class) : $class)); } +/** + * Clean a path to remove ./, ../, trailing slashes, etc. + * + * This function is an alias to Rhymix\Framework\Filters\FilenameFilter::cleanPath(). + * + * @param string $path + * @return string + */ +function clean_path($path) +{ + return Rhymix\Framework\Filters\FilenameFilter::cleanPath($path); +} + /** * This function is a shortcut to htmlspecialchars(). * @@ -337,6 +350,34 @@ function base64_decode_urlsafe($str) return @base64_decode(str_pad(strtr($str, '-_', '+/'), ceil(strlen($str) / 4) * 4, '=', STR_PAD_RIGHT)); } +/** + * Convert a server-side path to a URL. + * + * This function is an alias to Rhymix\Framework\URL::fromServerPath(). + * It returns false if the path cannot be converted. + * + * @param string $path + * @return string|false + */ +function path2url($path) +{ + return Rhymix\Framework\URL::fromServerPath($path); +} + +/** + * Convert a URL to a server-side path. + * + * This function is an alias to Rhymix\Framework\URL::toServerPath(). + * It returns false if the URL cannot be converted. + * + * @param string $url + * @return string|false + */ +function url2path($url) +{ + return Rhymix\Framework\URL::toServerPath($url); +} + /** * Convert hexadecimal color codes to an array of R, G, B values. * This function can handle both 6-digit and 3-digit notations, optionally prefixed with '#'.