3.0.0
This commit is contained in:
parent
e46b8de1cb
commit
fb9f2726b8
|
|
@ -1,77 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
return [
|
|
||||||
'provider' => 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',
|
|
||||||
],
|
|
||||||
];
|
|
||||||
|
|
@ -73,11 +73,29 @@ class ConfigLoader
|
||||||
{
|
{
|
||||||
$config = [];
|
$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'
|
// Extraer 'provider'
|
||||||
if (isset($rawConfig['provider'])) {
|
if (isset($rawConfig['provider'])) {
|
||||||
$config['provider'] = $rawConfig['provider'];
|
$config['provider'] = $rawConfig['provider'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Extraer visibility global si existe
|
||||||
|
if (isset($rawConfig['visibility'])) {
|
||||||
|
$config['visibility'] = $rawConfig['visibility'];
|
||||||
|
}
|
||||||
|
|
||||||
// Extraer prefijo global si existe
|
// Extraer prefijo global si existe
|
||||||
if (isset($rawConfig['stream']['root_prefix'])) {
|
if (isset($rawConfig['stream']['root_prefix'])) {
|
||||||
$config['prefix'] = $rawConfig['stream']['root_prefix'];
|
$config['prefix'] = $rawConfig['stream']['root_prefix'];
|
||||||
|
|
@ -106,6 +124,9 @@ class ConfigLoader
|
||||||
if (isset($rawConfig['uploads']['base_url'])) {
|
if (isset($rawConfig['uploads']['base_url'])) {
|
||||||
$config['cdn_url'] = $rawConfig['uploads']['base_url'];
|
$config['cdn_url'] = $rawConfig['uploads']['base_url'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Preservar configuración completa de S3
|
||||||
|
$config['s3'] = $s3Config;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
@ -130,16 +151,19 @@ class ConfigLoader
|
||||||
$config['prefix'] = $webdavConfig['prefix'];
|
$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)
|
// Permisos (usar valores por defecto si no están definidos)
|
||||||
$config['file_public'] = '0644';
|
$config['file_public'] = '0644';
|
||||||
$config['file_private'] = '0600';
|
$config['file_private'] = '0600';
|
||||||
$config['dir_public'] = '0755';
|
$config['dir_public'] = '0755';
|
||||||
$config['dir_private'] = '0700';
|
$config['dir_private'] = '0700';
|
||||||
|
|
||||||
// Visibilidad por defecto
|
// Preservar configuración completa de WebDAV
|
||||||
if (isset($webdavConfig['default_visibility'])) {
|
$config['webdav'] = $webdavConfig;
|
||||||
$config['default_visibility'] = $webdavConfig['default_visibility'];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
@ -160,6 +184,9 @@ class ConfigLoader
|
||||||
$config['file_private'] = $sftpConfig['file_private'] ?? '0600';
|
$config['file_private'] = $sftpConfig['file_private'] ?? '0600';
|
||||||
$config['dir_public'] = $sftpConfig['dir_public'] ?? '0755';
|
$config['dir_public'] = $sftpConfig['dir_public'] ?? '0755';
|
||||||
$config['dir_private'] = $sftpConfig['dir_private'] ?? '0700';
|
$config['dir_private'] = $sftpConfig['dir_private'] ?? '0700';
|
||||||
|
|
||||||
|
// Preservar configuración completa de SFTP
|
||||||
|
$config['sftp'] = $sftpConfig;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -429,6 +456,23 @@ class ConfigLoader
|
||||||
$config['prefix'] = trim($config['prefix'], '/');
|
$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));
|
error_log('[Flysystem Offload] Final normalized config: ' . print_r($config, true));
|
||||||
|
|
||||||
return $config;
|
return $config;
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,11 @@ class Plugin
|
||||||
*/
|
*/
|
||||||
private static ?MediaHooks $mediaHooks = null;
|
private static ?MediaHooks $mediaHooks = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instancia de SettingsPage
|
||||||
|
*/
|
||||||
|
private static ?SettingsPage $settingsPage = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bootstrap del plugin
|
* Bootstrap del plugin
|
||||||
*
|
*
|
||||||
|
|
@ -72,9 +77,10 @@ class Plugin
|
||||||
self::$mediaHooks = new MediaHooks(self::$filesystem, self::$config);
|
self::$mediaHooks = new MediaHooks(self::$filesystem, self::$config);
|
||||||
self::$mediaHooks->register();
|
self::$mediaHooks->register();
|
||||||
|
|
||||||
// Registrar página de ajustes
|
// Registrar página de ajustes (instanciar la clase)
|
||||||
if (is_admin()) {
|
if (is_admin()) {
|
||||||
SettingsPage::register();
|
self::$settingsPage = new SettingsPage(self::$filesystem, self::$config);
|
||||||
|
self::$settingsPage->register();
|
||||||
}
|
}
|
||||||
|
|
||||||
self::$initialized = true;
|
self::$initialized = true;
|
||||||
|
|
@ -154,6 +160,7 @@ class Plugin
|
||||||
self::$initialized = false;
|
self::$initialized = false;
|
||||||
self::$filesystem = null;
|
self::$filesystem = null;
|
||||||
self::$mediaHooks = null;
|
self::$mediaHooks = null;
|
||||||
|
self::$settingsPage = null;
|
||||||
self::$config = [];
|
self::$config = [];
|
||||||
|
|
||||||
// Desregistrar stream wrapper si existe
|
// Desregistrar stream wrapper si existe
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue