From 0ce798d40bd16e7fb3b9fcd7b2b2012e6226dd24 Mon Sep 17 00:00:00 2001 From: Alexis Degrugillier Date: Fri, 26 Feb 2021 12:42:10 -0500 Subject: Add support for extension user files (#3433) Extension user files can be stored easily in the user folder instead of the static folder. --- p/ext.php | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'p') diff --git a/p/ext.php b/p/ext.php index d283e5f8c..daa4848d6 100644 --- a/p/ext.php +++ b/p/ext.php @@ -32,10 +32,15 @@ function get_absolute_filename(string $file_name) { return $third_party_extension; } + $user = realpath(USERS_PATH . '/' . $file_name); + if (false !== $user) { + return $user; + } + return ''; } -function is_valid_path_extension($path, $extensionPath) { +function is_valid_path_extension($path, $extensionPath, $isStatic = true) { // It must be under the extension path. $real_ext_path = realpath($extensionPath); @@ -48,7 +53,12 @@ function is_valid_path_extension($path, $extensionPath) { return false; } - // File to serve must be under a `ext_dir/static/` directory. + // User files do not need further validations + if (!$isStatic) { + return true; + } + + // Static files to serve must be under a `ext_dir/static/` directory. $path_relative_to_ext = substr($path, strlen($real_ext_path) + 1); list(,$static,$file) = sscanf($path_relative_to_ext, '%[^/]/%[^/]/%s'); if (null === $file || 'static' !== $static) { @@ -69,7 +79,7 @@ function is_valid_path_extension($path, $extensionPath) { * */ function is_valid_path($path) { - return is_valid_path_extension($path, CORE_EXTENSIONS_PATH) || is_valid_path_extension($path, THIRDPARTY_EXTENSIONS_PATH); + return is_valid_path_extension($path, CORE_EXTENSIONS_PATH) || is_valid_path_extension($path, THIRDPARTY_EXTENSIONS_PATH) || is_valid_path_extension($path, USERS_PATH, $false); } function sendBadRequestResponse(string $message = null) { -- cgit v1.2.3