Files
WPS3Media/classes/upgrades/upgrade-content-replace-urls.php
Malin 3248cbb029 feat: add S3-compatible storage provider (MinIO, Ceph, R2, etc.)
Adds a new 'S3-Compatible Storage' provider that works with any
S3-API-compatible object storage service, including MinIO, Ceph,
Cloudflare R2, Backblaze B2, and others.

Changes:
- New provider class: classes/providers/storage/s3-compatible-provider.php
  - Provider key: s3compatible
  - Reads user-configured endpoint URL from settings
  - Uses path-style URL access (required by most S3-compatible services)
  - Supports credentials via AS3CF_S3COMPAT_ACCESS_KEY_ID /
    AS3CF_S3COMPAT_SECRET_ACCESS_KEY wp-config.php constants
  - Disables AWS-specific features (Block Public Access, Object Ownership)
- New provider SVG icons (s3compatible.svg, -link.svg, -round.svg)
- Registered provider in main plugin class with endpoint setting support
- Updated StorageProviderSubPage to show endpoint URL input for S3-compatible
- Built pro settings bundle with rollup (Svelte 4.2.19)
- Added package.json and updated rollup.config.mjs for pro-only builds
2026-03-03 12:30:18 +01:00

93 lines
2.3 KiB
PHP

<?php
namespace DeliciousBrains\WP_Offload_Media\Upgrades;
use AS3CF_Utils;
/**
* Upgrade_Content_Replace_URLs Class
*
* This class handles replacing all S3 URLs in post
* content with the local URL.
*
* @since 1.2
*/
class Upgrade_Content_Replace_URLs extends Upgrade_Filter_Post {
/**
* @var int
*/
protected $upgrade_id = 4;
/**
* @var string
*/
protected $upgrade_name = 'replace_provider_urls';
/**
* @var string
*/
protected $column_name = 'post_content';
/**
* Get running update text.
*
* @return string
*/
protected function get_running_update_text() {
return __( 'and ensuring that only the local URL exists in post content.', 'amazon-s3-and-cloudfront' );
}
/**
* Get running message.
*
* @return string
*/
protected function get_running_message() {
return sprintf( __( '<strong>Running Content Upgrade%1$s</strong><br>A find &amp; replace is running in the background to update URLs in your post content. %2$s', 'amazon-s3-and-cloudfront' ), $this->get_progress_text(), $this->get_generic_message() );
}
/**
* Switch to a new blog for processing.
*
* @return bool
*/
protected function upgrade_blog() {
$this->upgrade_theme_mods();
return parent::upgrade_blog();
}
/**
* Upgrade theme mods. Ensures background and header images have local URLs saved to the database.
*/
protected function upgrade_theme_mods() {
global $wpdb;
$mods = $wpdb->get_results( "SELECT * FROM `{$wpdb->options}` WHERE option_name LIKE 'theme_mods_%'" );
foreach ( $mods as $mod ) {
$value = AS3CF_Utils::maybe_unserialize( $mod->option_value );
if ( isset( $value['background_image'] ) ) {
$value['background_image'] = $this->as3cf->filter_provider->filter_customizer_image( $value['background_image'] );
}
if ( isset( $value['header_image'] ) ) {
$value['header_image'] = $this->as3cf->filter_provider->filter_customizer_image( $value['header_image'] );
}
if ( isset( $value['header_image_data'] ) ) {
$value['header_image_data'] = $this->as3cf->filter_provider->filter_header_image_data( $value['header_image_data'] );
}
$value = maybe_serialize( $value );
if ( $value !== $mod->option_value ) {
$wpdb->query( "UPDATE `{$wpdb->options}` SET option_value = '{$value}' WHERE option_id = '{$mod->option_id}'" );
}
}
}
}