From fb9f2726b8cc4774b8cbdf2efad02aa732787269 Mon Sep 17 00:00:00 2001 From: Brasdrive Date: Sun, 9 Nov 2025 22:22:52 -0400 Subject: [PATCH] 3.0.0 --- config/flysystem-offload.example.php | 77 ---------------------------- src/Config/ConfigLoader.php | 52 +++++++++++++++++-- src/Plugin.php | 11 +++- 3 files changed, 57 insertions(+), 83 deletions(-) delete mode 100644 config/flysystem-offload.example.php diff --git a/config/flysystem-offload.example.php b/config/flysystem-offload.example.php deleted file mode 100644 index 9e8ab33..0000000 --- a/config/flysystem-offload.example.php +++ /dev/null @@ -1,77 +0,0 @@ - getenv('FLYSYSTEM_OFFLOAD_PROVIDER') ?: 's3', - 'visibility' => getenv('FLYSYSTEM_OFFLOAD_DEFAULT_VISIBILITY') ?: 'public', - - 'stream' => [ - 'protocol' => getenv('FLYSYSTEM_OFFLOAD_STREAM_PROTOCOL') ?: 'flysystem', - 'root_prefix' => getenv('FLYSYSTEM_OFFLOAD_STREAM_ROOT_PREFIX') ?: '', - 'host' => getenv('FLYSYSTEM_OFFLOAD_STREAM_HOST') ?: 'uploads', - ], - - 'uploads' => [ - 'base_url' => getenv('FLYSYSTEM_OFFLOAD_BASE_URL') ?: 'https://your-bucket.s3.amazonaws.com', - 'delete_remote' => filter_var( - getenv('FLYSYSTEM_OFFLOAD_DELETE_REMOTE') ?: 'true', - FILTER_VALIDATE_BOOLEAN - ), - 'prefer_local_for_missing' => filter_var( - getenv('FLYSYSTEM_OFFLOAD_PREFER_LOCAL_FOR_MISSING') ?: 'false', - FILTER_VALIDATE_BOOLEAN - ), - ], - - 'admin' => [ - 'enabled' => filter_var( - getenv('FLYSYSTEM_OFFLOAD_ADMIN_ENABLED') ?: 'false', - FILTER_VALIDATE_BOOLEAN - ), - ], - - 's3' => [ - 'key' => getenv('AWS_ACCESS_KEY_ID') ?: null, - 'secret' => getenv('AWS_SECRET_ACCESS_KEY') ?: null, - 'session_token' => getenv('AWS_SESSION_TOKEN') ?: null, - 'region' => getenv('AWS_DEFAULT_REGION') ?: 'us-east-1', - 'bucket' => getenv('FLYSYSTEM_OFFLOAD_BUCKET') ?: 'your-bucket-name', - 'prefix' => getenv('FLYSYSTEM_OFFLOAD_PREFIX') ?: null, - 'endpoint' => getenv('FLYSYSTEM_OFFLOAD_ENDPOINT') ?: null, - 'use_path_style_endpoint' => filter_var( - getenv('AWS_USE_PATH_STYLE_ENDPOINT') ?: 'false', - FILTER_VALIDATE_BOOLEAN - ), - 'version' => 'latest', - 'options' => [], - ], - - 'webdav' => [ - 'enabled' => filter_var( - getenv('FLYSYSTEM_OFFLOAD_WEBDAV_ENABLED') ?: 'false', - FILTER_VALIDATE_BOOLEAN - ), - 'base_url' => getenv('FLYSYSTEM_OFFLOAD_WEBDAV_BASE_URL') ?: '', - 'endpoint' => getenv('FLYSYSTEM_OFFLOAD_WEBDAV_ENDPOINT') ?: '', - 'prefix' => getenv('FLYSYSTEM_OFFLOAD_WEBDAV_PREFIX') ?: 'wordpress/uploads', - 'credentials' => [ - 'username' => getenv('FLYSYSTEM_OFFLOAD_WEBDAV_USERNAME') ?: '', - 'password' => getenv('FLYSYSTEM_OFFLOAD_WEBDAV_PASSWORD') ?: '', - 'auth_type' => getenv('FLYSYSTEM_OFFLOAD_WEBDAV_AUTH_TYPE') ?: null, - ], - 'stream' => [ - 'register' => filter_var( - getenv('FLYSYSTEM_OFFLOAD_WEBDAV_STREAM_REGISTER') ?: 'true', - FILTER_VALIDATE_BOOLEAN - ), - 'protocol' => getenv('FLYSYSTEM_OFFLOAD_WEBDAV_STREAM_PROTOCOL') ?: 'webdav', - ], - 'default_headers' => [ - 'Cache-Control' => getenv('FLYSYSTEM_OFFLOAD_WEBDAV_CACHE_CONTROL') ?: 'public, max-age=31536000', - 'Expires' => getenv('FLYSYSTEM_OFFLOAD_WEBDAV_EXPIRES') - ?: gmdate('D, d M Y H:i:s \G\M\T', strtotime('+1 year')), - ], - 'default_visibility' => getenv('FLYSYSTEM_OFFLOAD_WEBDAV_VISIBILITY') ?: 'private', - ], -]; diff --git a/src/Config/ConfigLoader.php b/src/Config/ConfigLoader.php index f64b001..1a6cb4e 100644 --- a/src/Config/ConfigLoader.php +++ b/src/Config/ConfigLoader.php @@ -73,11 +73,29 @@ class ConfigLoader { $config = []; + // ✅ PRESERVAR las secciones 'stream' y 'uploads' del archivo base + if (isset($rawConfig['stream'])) { + $config['stream'] = $rawConfig['stream']; + } + + if (isset($rawConfig['uploads'])) { + $config['uploads'] = $rawConfig['uploads']; + } + + if (isset($rawConfig['admin'])) { + $config['admin'] = $rawConfig['admin']; + } + // Extraer 'provider' if (isset($rawConfig['provider'])) { $config['provider'] = $rawConfig['provider']; } + // Extraer visibility global si existe + if (isset($rawConfig['visibility'])) { + $config['visibility'] = $rawConfig['visibility']; + } + // Extraer prefijo global si existe if (isset($rawConfig['stream']['root_prefix'])) { $config['prefix'] = $rawConfig['stream']['root_prefix']; @@ -106,6 +124,9 @@ class ConfigLoader if (isset($rawConfig['uploads']['base_url'])) { $config['cdn_url'] = $rawConfig['uploads']['base_url']; } + + // Preservar configuración completa de S3 + $config['s3'] = $s3Config; } break; @@ -130,16 +151,19 @@ class ConfigLoader $config['prefix'] = $webdavConfig['prefix']; } + // Visibility específica de WebDAV + if (isset($webdavConfig['default_visibility'])) { + $config['visibility'] = $webdavConfig['default_visibility']; + } + // Permisos (usar valores por defecto si no están definidos) $config['file_public'] = '0644'; $config['file_private'] = '0600'; $config['dir_public'] = '0755'; $config['dir_private'] = '0700'; - // Visibilidad por defecto - if (isset($webdavConfig['default_visibility'])) { - $config['default_visibility'] = $webdavConfig['default_visibility']; - } + // Preservar configuración completa de WebDAV + $config['webdav'] = $webdavConfig; } break; @@ -160,6 +184,9 @@ class ConfigLoader $config['file_private'] = $sftpConfig['file_private'] ?? '0600'; $config['dir_public'] = $sftpConfig['dir_public'] ?? '0755'; $config['dir_private'] = $sftpConfig['dir_private'] ?? '0700'; + + // Preservar configuración completa de SFTP + $config['sftp'] = $sftpConfig; } break; } @@ -429,6 +456,23 @@ class ConfigLoader $config['prefix'] = trim($config['prefix'], '/'); } + // ✅ Asegurar valores por defecto para 'stream' y 'uploads' + if (!isset($config['stream'])) { + $config['stream'] = [ + 'protocol' => 'flysystem', + 'root_prefix' => '', + 'host' => 'uploads', + ]; + } + + if (!isset($config['uploads'])) { + $config['uploads'] = [ + 'base_url' => content_url('uploads'), + 'delete_remote' => true, + 'prefer_local_for_missing' => false, + ]; + } + error_log('[Flysystem Offload] Final normalized config: ' . print_r($config, true)); return $config; diff --git a/src/Plugin.php b/src/Plugin.php index 8b9da31..6399b5d 100644 --- a/src/Plugin.php +++ b/src/Plugin.php @@ -37,6 +37,11 @@ class Plugin */ private static ?MediaHooks $mediaHooks = null; + /** + * Instancia de SettingsPage + */ + private static ?SettingsPage $settingsPage = null; + /** * Bootstrap del plugin * @@ -72,9 +77,10 @@ class Plugin self::$mediaHooks = new MediaHooks(self::$filesystem, self::$config); self::$mediaHooks->register(); - // Registrar página de ajustes + // Registrar página de ajustes (instanciar la clase) if (is_admin()) { - SettingsPage::register(); + self::$settingsPage = new SettingsPage(self::$filesystem, self::$config); + self::$settingsPage->register(); } self::$initialized = true; @@ -154,6 +160,7 @@ class Plugin self::$initialized = false; self::$filesystem = null; self::$mediaHooks = null; + self::$settingsPage = null; self::$config = []; // Desregistrar stream wrapper si existe