Skip to content

Commit

Permalink
Merge pull request #741 from udx/develop-alexey
Browse files Browse the repository at this point in the history
4.0.3 - Info section and minor fixes
  • Loading branch information
balexey88 committed Apr 16, 2024
2 parents 7b1c727 + 1923a1c commit 8a91374
Show file tree
Hide file tree
Showing 28 changed files with 1,066 additions and 112 deletions.
14 changes: 14 additions & 0 deletions changelog.txt
@@ -1,4 +1,18 @@
== Changelog ==
= 4.0.3 =
* NEW - added `Info` section to the `Status` tab on the Settings page, which contains the system info and the ability to copy report to clipboard.
* ENHANCEMENT - added `Documentation` link on the Plugins page.
* ENHANCEMENT - added `Addons` link on the Plugins page.
* ENHANCEMENT - added `Documentation` link on the Settings page.
* FIX - fixed `Settings` shortcut on the Plugins page.
* FIX - in multisite network, do not show Data Optimization on the Network Admin Page.
* FIX - properly set `Content Disposition` fields for media objects.
* FIX - properly use `Cache Control` setting for media objects.
* FIX - fixed `Creation of dynamic property` PHP deprecation notice.
* FIX - fixed `Cannot use ::class with dynamic class name` PHP warning.
* FIX - avoid PHP warning when unable to get file path in `Stateless` mode [728](https://github.com/udx/wp-stateless/issues/728).
* FIX - fixed links to the constants documentation.

= 4.0.2 =
* FIX - in multisite network, deleting site can potentially remove WP-Stateless tables from another site.
* COMPATIBILITY - Gravity Forms Compatibility updated for the newest Gravity Forms version.
Expand Down
14 changes: 14 additions & 0 deletions changes.md
@@ -1,3 +1,17 @@
#### 4.0.3
* NEW - added `Info` section to the `Status` tab on the Settings page, which contains the system info and the ability to copy report to clipboard.
* ENHANCEMENT - added `Documentation` link on the Plugins page.
* ENHANCEMENT - added `Addons` link on the Plugins page.
* ENHANCEMENT - added `Documentation` link on the Settings page.
* FIX - fixed `Settings` shortcut on the Plugins page.
* FIX - in multisite network, do not show Data Optimization on the Network Admin Page.
* FIX - properly set `Content Disposition` fields for media objects.
* FIX - properly use `Cache Control` setting for media objects.
* FIX - fixed `Creation of dynamic property` PHP deprecation notice.
* FIX - fixed `Cannot use ::class with dynamic class name` PHP warning.
* FIX - avoid PHP warning when unable to get file path in `Stateless` mode [728](https://github.com/udx/wp-stateless/issues/728).
* FIX - fixed links to the constants documentation.

#### 4.0.2
* FIX - in multisite network, deleting site can potentially remove WP-Stateless tables from another site.
* COMPATIBILITY - Gravity Forms Compatibility updated for the newest Gravity Forms version.
Expand Down
4 changes: 2 additions & 2 deletions lib/classes/batch/class-batch-task-manager.php
Expand Up @@ -230,7 +230,7 @@ protected function complete() {
// Check if we have more batched to run
try {
$object = $this->_get_batch_task_object();
$class = $object::class;
$class = get_class($object);
$batch = $object->get_batch();

if ( !empty($batch) ) {
Expand All @@ -242,7 +242,7 @@ protected function complete() {
return;
}

Helper::log( 'Batch task completed: ' . $object::class );
Helper::log( 'Batch task completed: ' . $class );
} catch (\Throwable $e) {
Helper::log( "Unable to process next batch: " . $e->getMessage() );
}
Expand Down
2 changes: 1 addition & 1 deletion lib/classes/class-addons.php
Expand Up @@ -203,7 +203,7 @@ private function get_addons_view($addons) {
$plugin_desc = __('Provides compatibility between the %s and the WP-Stateless plugins.', ud_get_stateless_media()->domain);
$theme_desc = __('Provides compatibility between the %s theme and the WP-Stateless plugin.', ud_get_stateless_media()->domain);

$link = 'https://stateless.udx.io/addons/%s';
$link = ud_get_stateless_media()->get_docs_page_url('addons/%s');

$defaults = [
'title' => '',
Expand Down
56 changes: 27 additions & 29 deletions lib/classes/class-bootstrap.php
Expand Up @@ -356,12 +356,9 @@ private function _init_filters($type = '') {
}

/**
* Override Cache Control is option is enabled
* Override Cache Control if option is enabled
*/
$cacheControl = trim($this->get('sm.cache_control'));
if (!empty($cacheControl)) {
add_filter('sm:item:cacheControl', array($this, 'override_cache_control'));
}
add_filter('sm:item:cacheControl', array($this->settings, 'override_cache_control'));

add_filter('wp_stateless_file_name', array($this, 'handle_root_dir'), 10, 4);

Expand Down Expand Up @@ -645,6 +642,18 @@ public function get_settings_page_url($path = '') {
return $url . $path;
}

/**
* Return docs page url.
*
* @param string $path
* @return string
*/
public function get_docs_page_url($path = '') {
$path = ltrim($path, '/');

return 'https://stateless.udx.io/' . $path;
}

/**
* Get new blog settings once switched blog.
* @param $new_blog
Expand Down Expand Up @@ -1190,26 +1199,6 @@ public function _convert_to_gs_link($meta, $image_host, $url, $file_ext) {
return $meta;
}

/**
* @param $links
* @param $file
* @return mixed
*/
public function plugin_action_links($links, $file) {

if ($file == plugin_basename(dirname(__DIR__) . '/wp-stateless-media.php')) {
$settings_link = '<a href="' . '' . '">' . __('Settings', 'ssd') . '</a>';
array_unshift($links, $settings_link);
}

if ($file == plugin_basename(dirname(__DIR__) . '/wp-stateless.php')) {
$settings_link = '<a href="' . '' . '">' . __('Settings', 'ssd') . '</a>';
array_unshift($links, $settings_link);
}

return $links;
}

/**
* Determines if plugin is loaded via mu-plugins
* or Network Enabled.
Expand Down Expand Up @@ -1265,7 +1254,7 @@ public function admin_init() {
wp_register_script('wp-stateless-select2', ud_get_stateless_media()->path('static/scripts/select2.min.js', 'url'), array('jquery'), self::$version, true);

/* Stateless settings page */
wp_register_script('wp-stateless-settings', ud_get_stateless_media()->path('static/scripts/wp-stateless-settings.js', 'url'), array(), self::$version);
wp_register_script('wp-stateless-settings', ud_get_stateless_media()->path('static/scripts/wp-stateless-settings.js', 'url'), array('clipboard'), self::$version);
wp_localize_script('wp-stateless-settings', 'stateless_l10n', $this->get_l10n_data());

wp_register_style('wp-stateless-settings', $this->path('static/styles/wp-stateless-settings.css', 'url'), array(), self::$version);
Expand Down Expand Up @@ -1371,7 +1360,7 @@ public function admin_enqueue_scripts($hook) {
'title' => sprintf(__("Stateless and Ephemeral modes enables and requires the Cache-Busting option.", ud_get_stateless_media()->domain)),
'message' => sprintf(__("WordPress looks at local files to prevent files with the same filenames.
Since Stateless mode bypasses this check, there is a potential for files to be stored with the same file name. We enforce the Cache-Busting option to prevent this.
Override with the <a href='%s' target='_blank'>%s</a> constant.", ud_get_stateless_media()->domain), "https://stateless.udx.io/docs/constants/#wp_stateless_media_cache_busting", "WP_STATELESS_MEDIA_CACHE_BUSTING"),
Override with the <a href='%s' target='_blank'>%s</a> constant.", ud_get_stateless_media()->domain), ud_get_stateless_media()->get_docs_page_url('docs/constants/#wpstatelessmediacachebusting'), "WP_STATELESS_MEDIA_CACHE_BUSTING"),
);
echo "<script id='template-stateless-cache-busting' type='text/html'>";
include ud_get_stateless_media()->path('/static/views/error-notice.php', 'dir');
Expand Down Expand Up @@ -1555,7 +1544,7 @@ public function wp_get_attachment_metadata($metadata, $attachment_id) {
$metadata['file'] = "sites/$blog_id/{$metadata['file']}";
}
}
} elseif (empty($sm_cloud) && $this->get('sm.mode') == 'stateless') {
} elseif ( empty($sm_cloud) && $this->get('sm.mode') == 'stateless' && isset($metadata['file']) ) {
$default_dir = true;
$uploads = wp_get_upload_dir();
$default_dir = false;
Expand Down Expand Up @@ -1816,7 +1805,7 @@ public function show_notice_stateless_cache_busting() {
'title' => sprintf(__("Stateless mode now requires the Cache-Busting option.", ud_get_stateless_media()->domain)),
'message' => sprintf(__("WordPress looks at local files to prevent files with the same filenames.
Since Stateless mode bypasses this check, there is a potential for files to be stored with the same file name. We enforce the Cache-Busting option to prevent this.
Override with the <a href='%s' target='_blank'>%s</a> constant.", ud_get_stateless_media()->domain), "https://stateless.udx.io/docs/constants/#wp_stateless_media_cache_busting", "WP_STATELESS_MEDIA_CACHE_BUSTING"),
Override with the <a href='%s' target='_blank'>%s</a> constant.", ud_get_stateless_media()->domain), ud_get_stateless_media()->get_docs_page_url('docs/constants/#wpstatelessmediacachebusting'), "WP_STATELESS_MEDIA_CACHE_BUSTING"),
), 'notice');
}

Expand Down Expand Up @@ -2112,6 +2101,15 @@ public function is_mode($mode) {

return in_array($this->get('sm.mode'), $mode);
}

/**
* Get default cache control value
*
* @return string
*/
public function get_default_cache_control() {
return Settings::DEFAULT_CACHE_CONTROL;
}
}
}
}
24 changes: 21 additions & 3 deletions lib/classes/class-db.php
Expand Up @@ -14,6 +14,7 @@
class DB {
use Singleton;

const DB_VERSION_KEY = 'sm_db_version';
const DB_VERSION = '1.0';
const FULL_SIZE = '__full';

Expand Down Expand Up @@ -140,7 +141,7 @@ public function __get($property) {
* Creates or updates DB structure
*/
public function create_db() {
$version = get_option('sm_db_version');
$version = get_option(self::DB_VERSION_KEY, '');

if ($version === self::DB_VERSION) {
return;
Expand Down Expand Up @@ -197,7 +198,7 @@ public function create_db() {
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
dbDelta($sql);

update_option('sm_db_version', self::DB_VERSION);
update_option(self::DB_VERSION_KEY, self::DB_VERSION);
}

/**
Expand Down Expand Up @@ -703,7 +704,24 @@ public function get_total_files() {
global $wpdb;

try {
$query = "SELECT COUNT(post_id) FROM $this->files";
$query = "SELECT COUNT(id) FROM $this->files";

return $wpdb->get_var($query);
} catch (\Throwable $e) {
return 0;
}
}

/**
* Get the total file sizes count known to WP-Stateless
*
* @return int
*/
public function get_total_file_sizes() {
global $wpdb;

try {
$query = "SELECT COUNT(id) FROM $this->file_sizes";

return $wpdb->get_var($query);
} catch (\Throwable $e) {
Expand Down
2 changes: 1 addition & 1 deletion lib/classes/class-dynamic-image-support.php
Expand Up @@ -75,7 +75,7 @@ public function handle_on_fly($file) {
$client->add_media(apply_filters('sm:item:on_fly:before_add', array_filter(array(
'name' => $file_path,
'absolutePath' => wp_normalize_path($file),
'cacheControl' => apply_filters('sm:item:cacheControl', 'public, max-age=36000, must-revalidate', $_metadata),
'cacheControl' => apply_filters('sm:item:cacheControl', ud_get_stateless_media()->get_default_cache_control(), $_metadata),
'contentDisposition' => null,
'mimeType' => $mimeType['type'],
'metadata' => $_metadata
Expand Down
7 changes: 6 additions & 1 deletion lib/classes/class-gs-client.php
Expand Up @@ -53,6 +53,11 @@ final class GS_Client {
*/
private $temp_objects = array();

/**
* @var
*/
private $key_json = '';

/**
* Constructor.
* Must not be called directly.
Expand Down Expand Up @@ -220,7 +225,7 @@ public function add_media($args = array()) {
}

if (isset($args['contentDisposition'])) {
$media->getContentDisposition($args['contentDisposition']);
$media->setContentDisposition($args['contentDisposition']);
}

// If chunk size is defined, we assume user needs the file to be sent by chunks
Expand Down
4 changes: 4 additions & 0 deletions lib/classes/class-migrator.php
Expand Up @@ -229,6 +229,10 @@ public function migrate() {
* Outputs the message that migrations are required
*/
public function show_messages() {
if ( is_network_admin() ) {
return;
}

$is_running = BatchTaskManager::instance()->is_processing() || BatchTaskManager::instance()->is_paused();
$notify = get_option(self::MIGRATIONS_NOTIFY_KEY, false);

Expand Down
75 changes: 75 additions & 0 deletions lib/classes/class-settings.php
Expand Up @@ -10,6 +10,8 @@

final class Settings extends \UDX\Settings {

const DEFAULT_CACHE_CONTROL = 'public, max-age=36000, must-revalidate';

/**
* @var false|null|string
*/
Expand All @@ -25,6 +27,11 @@ final class Settings extends \UDX\Settings {
*/
public $stateless_settings = null;

/**
* @var string
*/
private $plugin_file = '';

/**
* Instance of
* - ud_get_stateless_media
Expand Down Expand Up @@ -70,6 +77,9 @@ final class Settings extends \UDX\Settings {
public function __construct($bootstrap = null) {
$this->bootstrap = $bootstrap ? $bootstrap : ud_get_stateless_media();

// Defile the main plugin file
$realpath = realpath( __DIR__ . '/../..');
$this->plugin_file = basename( $realpath ) . '/wp-stateless-media.php';

/* Add 'Settings' link for SM plugin on plugins page. */
$_basename = plugin_basename( $this->bootstrap->boot_file );
Expand All @@ -90,6 +100,12 @@ public function __construct($bootstrap = null) {

/** Register options */
add_action( 'init', array( $this, 'init' ), 3 );

// additional links on plugins page
add_filter( 'plugin_action_links', array( $this, 'plugin_action_links' ), 10, 2);
add_filter( 'network_admin_plugin_action_links', array( $this, 'plugin_action_links' ), 10, 2);
add_filter( 'plugin_row_meta', array( $this, 'plugin_row_meta' ), 10, 2 );

// apply wildcard to root dir.
add_filter( 'wp_stateless_handle_root_dir', array( $this, 'root_dir_wildcards' ), 10, 3);

Expand Down Expand Up @@ -649,6 +665,65 @@ public function get( $key = false, $default = false ) {

return $value;
}

/**
* Override Cache Control
*
* @param $value
* @return mixed
*/
public function override_cache_control($value) {
if ( !empty($value) && $value !== self::DEFAULT_CACHE_CONTROL ) {
return $value;
}

$cache_control = trim($this->get('sm.cache_control'));

return empty($cache_control) ? self::DEFAULT_CACHE_CONTROL : $cache_control;
}

/**
* Add 'Settings' on Plugins page
*
* @param array $actions
* @param string $file
*
* @return array
*/
public function plugin_action_links($actions, $file) {
if ( $file !== $this->plugin_file ) {
return $actions;
}

$url = ud_get_stateless_media()->get_settings_page_url('?page=stateless-settings');

$settings = [
'settings' => sprintf( '<a href="%s">%s</a>', $url, __('Settings', ud_get_stateless_media()->domain) ),
];

$actions['addons'] = sprintf( '<a href="%s" style="color: #f05323" target="_blank">%s</a>', ud_get_stateless_media()->get_docs_page_url('addons'), __('Addons', ud_get_stateless_media()->domain) );

return $settings + $actions;
}

/**
* Add link to docs on Plugins page
*
* @param $meta
* @param $file
*
* @return array
*/
public function plugin_row_meta($meta, $file) {
if ( $file !== $this->plugin_file ) {
return $meta;
}

$meta['documentation'] = sprintf( '<a href="%s" target="_blank">%s</a>', ud_get_stateless_media()->get_docs_page_url(), __('Documentation', ud_get_stateless_media()->domain) );

return $meta;
}

}

}
Expand Down
4 changes: 2 additions & 2 deletions lib/classes/class-sync-non-media.php
Expand Up @@ -144,7 +144,7 @@ public function sync_file($name, $absolutePath, $forced = false, $args = array()
try {
$media = $object->update(array('metadata' => $args['metadata']) +
array(
'cacheControl' => apply_filters('sm:item:cacheControl', 'public, max-age=36000, must-revalidate', $absolutePath),
'cacheControl' => apply_filters('sm:item:cacheControl', ud_get_stateless_media()->get_default_cache_control(), $absolutePath),
'predefinedAcl' => 'publicRead',
'contentDisposition' => apply_filters('sm:item:contentDisposition', null, $absolutePath)
));
Expand All @@ -157,7 +157,7 @@ public function sync_file($name, $absolutePath, $forced = false, $args = array()
'name' => $name,
'force' => ($forced == 2),
'absolutePath' => $absolutePath,
'cacheControl' => apply_filters('sm:item:cacheControl', 'public, max-age=36000, must-revalidate', $absolutePath), //@todo use cacheControl from settings page.
'cacheControl' => apply_filters('sm:item:cacheControl', ud_get_stateless_media()->get_default_cache_control(), $absolutePath), //@todo use cacheControl from settings page.
'contentDisposition' => apply_filters('sm:item:contentDisposition', null, $absolutePath),
'mimeType' => $file_type,
'metadata' => array(
Expand Down

0 comments on commit 8a91374

Please sign in to comment.