first commit

This commit is contained in:
User A0264400
2026-04-01 23:20:16 +03:00
commit a766acdc90
23071 changed files with 4933189 additions and 0 deletions

View File

@@ -0,0 +1,690 @@
<?php
/**
* License Page class
*
* Self-contained license management page without Factory Templates dependency.
* Reuses existing factory-bootstrap-500 CSS framework.
*
* @package Robin_Image_Optimizer
* @subpackage Admin\Pages
*/
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Class WRIO_License_Page_View
*
* Handles the license management admin page.
*/
class WRIO_License_Page_View {
/**
* Page ID
*
* @var string
*/
public $id = 'wrio_license';
/**
* Page hook suffix
*
* @var string|false
*/
private $page_hook;
/**
* Premium provider instance
*
* @var WRIO_Premium_Provider
* @phpstan-ignore-next-line property.onlyRead
*/
private $premium;
/**
* License instance
*
* @var WRIO_License
* @phpstan-ignore-next-line property.onlyRead
*/
private $license;
/**
* Whether premium is activated
*
* @var bool|null
*/
private $is_premium;
/**
* Plan name
*
* @var string
*/
public $plan_name;
/**
* Subscribe widget instance
*
* @var WRIO_Subscribe_Widget
*/
private $subscribe_widget;
/**
* Constructor
*/
public function __construct() {
$this->is_premium = null;
$this->plan_name = __( 'Robin image optimizer Premium', 'robin-image-optimizer' );
// Initialize subscribe widget.
$this->subscribe_widget = new WRIO_Subscribe_Widget();
add_action( 'admin_menu', [ $this, 'register_page' ], 9 );
add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_assets' ] );
add_action( 'wp_ajax_wrio_license_action', [ $this, 'ajax_handler' ] );
// Register this page in the Factory navigation menu
$this->register_in_factory_menu();
}
/**
* Register this page in the Factory impressive menu system
*
* This allows the license page to appear in the left navigation bar
* alongside other Factory-registered pages.
*
* @return void
*/
private function register_in_factory_menu() {
global $factory_impressive_page_menu;
$page_url = admin_url( 'admin.php?page=' . $this->id );
$factory_impressive_page_menu['robin-image-optimizer'][ $this->id ] = [
'type' => 'page',
'url' => $page_url,
'title' => __( 'License', 'robin-image-optimizer' ) . ' <span class="dashicons dashicons-admin-network"></span>',
'short_description' => __( 'Product activation', 'robin-image-optimizer' ),
'position' => 10,
'parent' => 'rio_general',
];
}
/**
* Initialize premium data
*
* Called late to ensure WRIO_Plugin is available.
*
* @return void
*/
private function init_premium() {
if ( null !== $this->premium ) {
return;
}
/**
* Initializes the premium provider instance.
*
* @var WRIO_Premium_Provider $premium
*/
$premium = WRIO_Plugin::app()->premium;
$this->premium = $premium;
/**
* Gets the license instance from premium provider.
*
* @var WRIO_License $license
*/
$license = $premium->get_license();
$this->license = $license;
$this->is_premium = $premium->is_activate();
}
/**
* Register the admin page
*
* @return void
*/
public function register_page() {
// Parent slug follows Factory pattern: {page_id}-{plugin_name}
$parent_slug = 'rio_general-robin-image-optimizer';
$this->page_hook = add_submenu_page(
$parent_slug,
__( 'License', 'robin-image-optimizer' ),
__( 'License', 'robin-image-optimizer' ),
'manage_options',
$this->id,
[ $this, 'render_page' ],
90 // Position before About Us (which uses 100)
);
}
/**
* Enqueue page assets
*
* @param string $hook Current admin page hook.
* @return void
*/
public function enqueue_assets( $hook ) {
if ( $this->page_hook !== $hook ) {
return;
}
wp_enqueue_script(
'wrio-license-manager',
WRIO_PLUGIN_URL . '/admin/assets/js/wrio-license-manager.js',
[ 'jquery' ],
WRIO_Plugin::app()->getPluginVersion(),
true
);
// Enqueue the Factory bootstrap core CSS (provides .btn, .form-control, etc.)
wp_enqueue_style(
'wrio-bootstrap-core',
WRIO_PLUGIN_URL . '/libs/factory/bootstrap/assets/css-min/bootstrap.core.min.css',
[],
WRIO_Plugin::app()->getPluginVersion()
);
// Enqueue the license manager CSS from Factory templates
wp_enqueue_style(
'wrio-license-manager',
WRIO_PLUGIN_URL . '/libs/factory/templates/assets/css/license-manager.css',
[ 'wrio-bootstrap-core' ],
WRIO_Plugin::app()->getPluginVersion()
);
// Enqueue the impressive page template CSS for full layout
wp_enqueue_style(
'wrio-impressive-template',
WRIO_PLUGIN_URL . '/libs/factory/templates/pages/templates/impressive/assets/css/impressive.page.template.css',
[ 'wrio-bootstrap-core' ],
WRIO_Plugin::app()->getPluginVersion()
);
// Enqueue subscribe widget CSS.
wp_enqueue_style(
'wrio-subscribe-widget',
WRIO_PLUGIN_URL . '/admin/assets/css/wrio-subscribe-widget.css',
[],
WRIO_Plugin::app()->getPluginVersion()
);
// Hide internal pages from sidebar (Custom Folders, Nextgen Gallery)
wp_add_inline_style(
'wrio-impressive-template',
'#io_folders_statistic-robin-image-optimizer-tab, #io_nextgen_gallery_statistic-robin-image-optimizer-tab { display: none !important; }'
);
}
/**
* Handle AJAX license actions
*
* @return void
*/
public function ajax_handler() {
// Verify nonce
if ( ! isset( $_POST['_wpnonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['_wpnonce'] ) ), 'wrio_license_action' ) ) {
wp_send_json_error( [ 'message' => __( 'Security check failed.', 'robin-image-optimizer' ) ] );
}
// Check capabilities
if ( ! current_user_can( 'manage_options' ) ) {
wp_send_json_error( [ 'message' => __( 'You do not have permission to perform this action.', 'robin-image-optimizer' ) ] );
}
$this->init_premium();
$action = isset( $_POST['license_action'] ) ? sanitize_text_field( wp_unslash( $_POST['license_action'] ) ) : '';
$license_key = isset( $_POST['licensekey'] ) ? trim( wp_unslash( $_POST['licensekey'] ) ) : '';
$allowed_actions = [ 'activate', 'deactivate', 'unsubscribe' ];
if ( empty( $action ) || ! in_array( $action, $allowed_actions, true ) ) {
wp_send_json_error( [ 'message' => __( 'Invalid action.', 'robin-image-optimizer' ) ] );
}
try {
switch ( $action ) {
case 'activate':
if ( empty( $license_key ) ) {
wp_send_json_error( [ 'message' => __( 'Please enter a license key.', 'robin-image-optimizer' ) ] );
}
$this->premium->activate( $license_key );
$message = __( 'Your license has been successfully activated.', 'robin-image-optimizer' );
break;
case 'deactivate':
$this->premium->deactivate();
$message = __( 'Your license has been deactivated.', 'robin-image-optimizer' );
break;
case 'unsubscribe':
$this->premium->cancel_paid_subscription();
$message = __( 'Your subscription has been cancelled.', 'robin-image-optimizer' );
break;
default:
wp_send_json_error( [ 'message' => __( 'Unknown action.', 'robin-image-optimizer' ) ] );
}
wp_send_json_success( [ 'message' => $message ] );
} catch ( Exception $e ) {
wp_send_json_error( [ 'message' => $e->getMessage() ] );
}
}
/**
* Render the admin page
*
* @return void
*/
public function render_page() {
$this->init_premium();
$min_height = $this->calculate_menu_height();
?>
<div id="WBCR" class="wrap">
<div class="wbcr-factory-templates-759-impressive-page-template factory-bootstrap-500 factory-fontawesome-000">
<div class="wbcr-factory-page wbcr-factory-page-<?php echo esc_attr( $this->id ); ?>">
<?php $this->render_header(); ?>
<div class="wbcr-factory-left-navigation-bar">
<?php $this->render_page_menu(); ?>
</div>
<div class="wbcr-factory-page-inner-wrap">
<div class="wbcr-factory-content-section wbcr-fullwidth">
<div class="wbcr-factory-content" style="min-height:<?php echo esc_attr( (string) $min_height ); ?>px">
<div id="wrio-license-wrapper"
data-loader="<?php echo esc_url( admin_url( 'images/spinner.gif' ) ); ?>"
data-nonce="<?php echo esc_attr( wp_create_nonce( 'wrio_license_action' ) ); ?>">
<?php $this->render_license_form(); ?>
</div>
</div>
</div>
</div>
</div>
<div class="clearfix"></div>
</div>
</div>
<?php
}
/**
* Calculate minimum height for content based on menu items
*
* @return int
*/
private function calculate_menu_height() {
global $factory_impressive_page_menu;
$menu_scope = 'robin-image-optimizer';
$min_height = 0;
if ( isset( $factory_impressive_page_menu[ $menu_scope ] ) ) {
foreach ( $factory_impressive_page_menu[ $menu_scope ] as $page ) {
if ( ! isset( $page['parent'] ) || empty( $page['parent'] ) ) {
$min_height += 77;
}
}
}
return $min_height;
}
/**
* Render the page header
*
* @return void
*/
private function render_header() {
?>
<div class="wbcr-factory-page-header">
<div class="wbcr-factory-header-logo">
<?php echo esc_html( WRIO_Plugin::app()->getPluginTitle() ); ?>
<span class="version"><?php echo esc_html( WRIO_Plugin::app()->getPluginVersion() ); ?></span>
<span class="dash">—</span>
</div>
<div class="wbcr-factory-header-title">
<h2><?php esc_html_e( 'Page', 'robin-image-optimizer' ); ?>: <?php esc_html_e( 'License', 'robin-image-optimizer' ); ?></h2>
</div>
<div class="wbcr-factory-control">
<?php do_action( 'wbcr_factory_pages_impressive_header', WRIO_Plugin::app()->getPluginName() ); ?>
</div>
</div>
<?php
}
/**
* Render the left navigation menu
*
* @return void
*/
private function render_page_menu() {
global $factory_impressive_page_menu;
$menu_scope = 'robin-image-optimizer';
$self_page_id = $this->id;
if ( ! isset( $factory_impressive_page_menu[ $menu_scope ] ) ) {
return;
}
$page_menu = $factory_impressive_page_menu[ $menu_scope ];
// Sort by position (descending - higher position = higher in menu)
uasort(
$page_menu,
function ( $a, $b ) {
return $b['position'] <=> $a['position'];
}
);
?>
<ul>
<?php
// First, render parent pages
foreach ( $page_menu as $page_screen => $page ) :
if ( ! empty( $page['parent'] ) ) {
continue;
}
$active_tab = ( $page_screen === $self_page_id ) ? ' wbcr-factory-active-tab' : '';
?>
<li class="wbcr-factory-nav-tab<?php echo esc_attr( $active_tab ); ?>">
<a href="<?php echo esc_url( $page['url'] ); ?>"
id="<?php echo esc_attr( $page_screen ); ?>-tab"
class="wbcr-factory-tab__link js-wbcr-factory-tab__link">
<div class="wbcr-factory-tab__title">
<?php echo wp_kses( $page['title'], [ 'span' => [ 'class' => [] ] ] ); ?>
</div>
<?php if ( ! empty( $page['short_description'] ) ) : ?>
<div class="wbcr-factory-tab__short-description">
<?php echo esc_html( $page['short_description'] ); ?>
</div>
<?php endif; ?>
</a>
</li>
<?php endforeach; ?>
<?php
// Then, render child pages
foreach ( $page_menu as $page_screen => $page ) :
if ( empty( $page['parent'] ) ) {
continue;
}
$active_tab = ( $page_screen === $self_page_id ) ? ' wbcr-factory-active-tab' : '';
?>
<li class="wbcr-factory-nav-tab<?php echo esc_attr( $active_tab ); ?>">
<a href="<?php echo esc_url( $page['url'] ); ?>"
id="<?php echo esc_attr( $page_screen ); ?>-tab"
class="wbcr-factory-tab__link js-wbcr-factory-tab__link">
<div class="wbcr-factory-tab__title">
<?php echo wp_kses( $page['title'], [ 'span' => [ 'class' => [] ] ] ); ?>
</div>
<?php if ( ! empty( $page['short_description'] ) ) : ?>
<div class="wbcr-factory-tab__short-description">
<?php echo esc_html( $page['short_description'] ); ?>
</div>
<?php endif; ?>
</a>
</li>
<?php endforeach; ?>
</ul>
<?php
}
/**
* Get license type for CSS class
*
* @return string free|gift|trial|paid
*/
private function get_license_type() {
if ( ! $this->is_premium || null === $this->license ) {
return 'free';
}
if ( $this->license->is_lifetime() ) {
return 'gift';
}
if ( $this->license->get_expiration_time( 'days' ) < 1 ) {
return 'trial';
}
return 'paid';
}
/**
* Get hidden license key (first 8 + last 4 characters)
*
* @return string
*/
private function get_hidden_license_key() {
if ( ! $this->is_premium || null === $this->license ) {
return '';
}
return $this->license->get_masked_key();
}
/**
* Get unified expiration display string
*
* @return string
*/
private function get_expiration_display() {
if ( ! $this->is_premium || null === $this->license ) {
return __( 'N/A', 'robin-image-optimizer' );
}
return $this->license->get_expiration_display();
}
/**
* Render the license form
*
* @return void
*/
private function render_license_form() {
$license_type = $this->get_license_type();
$plan_title = __( 'Free', 'robin-image-optimizer' );
$has_pro = null !== $this->premium && null !== $this->premium->get_plan_id();
if ( $has_pro ) {
$plan_title = __( 'Pro', 'robin-image-optimizer' );
}
$license_status_label = __( 'License', 'robin-image-optimizer' );
?>
<div id="license-manager"
class="factory-bootstrap-500 onp-page-wrap <?php echo esc_attr( $license_type ); ?>-license-manager-content">
<?php if ( ! $has_pro ) : ?>
<?php $this->render_upgrade_banner(); ?>
<?php endif; ?>
<div class="onp-container">
<div class="license-details">
<h3>
<?php echo esc_html( $license_status_label ); ?>
<span class="license-info-badge <?php echo esc_attr( 'license-info-badge--plan-' . ( $has_pro ? 'pro' : 'free' ) ); ?>">
<?php echo esc_html( $plan_title ); ?>
</span>
<?php if ( $this->is_premium ) : ?>
<span class="license-info-badge license-info-badge--expiration">
<?php echo esc_html( $this->get_expiration_display() ); ?>
</span>
<?php endif; ?>
</h3>
</div>
<div class="license-input">
<form action="" method="post">
<?php if ( $this->is_premium ) : ?>
<p><?php esc_html_e( 'Have a key to activate the premium version? Paste it here:', 'robin-image-optimizer' ); ?></p>
<?php else : ?>
<p><?php esc_html_e( 'Have a key to activate the plugin? Paste it here:', 'robin-image-optimizer' ); ?></p>
<?php endif; ?>
<div class="license-key-wrap">
<input
type="text"
id="license-key"
name="licensekey"
value=""
class="form-control"
placeholder="<?php echo esc_html( $this->get_hidden_license_key() ); ?>"
/>
<?php if ( $this->is_premium ) : ?>
<button data-action="deactivate" class="button button-primary wrio-license-btn" type="button" id="license-submit">
<?php esc_html_e( 'Deactivate', 'robin-image-optimizer' ); ?>
</button>
<?php else : ?>
<button data-action="activate" class="button button-primary wrio-license-btn" type="button" id="license-submit">
<?php esc_html_e( 'Activate', 'robin-image-optimizer' ); ?>
</button>
<?php endif; ?>
</div>
<?php $this->render_learnmore_section(); ?>
<div id="license-form-error-container"></div>
<?php $this->render_freemius_migration_notice(); ?>
</form>
</div>
</div>
<?php $this->subscribe_widget->render(); ?>
</div>
<?php
}
/**
* Render the upgrade banner for free users
*
* @return void
*/
private function render_upgrade_banner() {
$support = WRIO_Plugin::app()->get_support();
$pricing_url = $support->get_pricing_url( true, 'license_banner' );
?>
<div class="wrio-license-upgrade-banner">
<div class="wrio-license-upgrade-icon">
<span>⚡</span>
</div>
<div class="wrio-license-upgrade-content">
<h2 class="wrio-license-upgrade-title"><?php esc_html_e( 'Supercharge Your Image Optimization', 'robin-image-optimizer' ); ?></h2>
<p class="wrio-license-upgrade-subtitle"><?php esc_html_e( "You're using the free version. Upgrade to unlock unlimited conversions and premium features.", 'robin-image-optimizer' ); ?></p>
<div class="wrio-license-upgrade-features">
<div class="wrio-license-upgrade-feature">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7"></path>
</svg>
<span><?php esc_html_e( 'Unlimited AVIF', 'robin-image-optimizer' ); ?></span>
</div>
<div class="wrio-license-upgrade-feature">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7"></path>
</svg>
<span><?php esc_html_e( 'Custom Folders Optimization', 'robin-image-optimizer' ); ?></span>
</div>
<div class="wrio-license-upgrade-feature">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7"></path>
</svg>
<span><?php esc_html_e( 'NextGen Gallery Support', 'robin-image-optimizer' ); ?></span>
</div>
<div class="wrio-license-upgrade-feature">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7"></path>
</svg>
<span><?php esc_html_e( 'Priority Support', 'robin-image-optimizer' ); ?></span>
</div>
<div class="wrio-license-upgrade-feature">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7"></path>
</svg>
<span><?php esc_html_e( 'More Compression Modes', 'robin-image-optimizer' ); ?></span>
</div>
<div class="wrio-license-upgrade-feature">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7"></path>
</svg>
<span><?php esc_html_e( 'Super Page Cache Pro', 'robin-image-optimizer' ); ?></span>
</div>
</div>
<a href="<?php echo esc_url( $pricing_url ); ?>" class="wrio-license-upgrade-button" target="_blank" rel="noopener">
<?php esc_html_e( 'View Pro Plans', 'robin-image-optimizer' ); ?> →
</a>
</div>
</div>
<?php
}
/**
* Render learn more section
*
* @return void
*/
private function render_learnmore_section() {
$support = WRIO_Plugin::app()->get_support();
if ( ! $this->is_premium ) :
?>
<p style="margin-top: 10px;">
<?php
printf(
wp_kses(
/* translators: %1$s: opening link tag, %2$s: closing link tag */
__( 'Can\'t find your key? Go to %1$sthis page%2$s and login using the e-mail address associated with your purchase.', 'robin-image-optimizer' ),
[
'a' => [
'href' => [],
'target' => [],
'rel' => [],
],
]
),
'<a href="' . esc_url( $support->get_contacts_url( true, 'license_page' ) ) . '" target="_blank" rel="noopener">',
'</a>'
);
?>
</p>
<?php
endif;
}
/**
* Render migration notice for Freemius license holders
*
* @return void
*/
private function render_freemius_migration_notice() {
if ( ! $this->is_premium || null === $this->license || $this->license->get_source() !== WRIO_License::SOURCE_FREEMIUS ) {
return;
}
?>
<div class="wrio-migration-notice">
<p>
<strong><?php esc_html_e( 'Action Required:', 'robin-image-optimizer' ); ?></strong>
<?php esc_html_e( 'Your license was issued through our previous licensing system (Freemius). Please contact support to receive a new Themeisle license key for continued access to updates and support.', 'robin-image-optimizer' ); ?>
</p>
<p>
<a href="<?php echo esc_url( WRIO_Plugin::app()->get_support()->get_contacts_url( true, 'license_migration' ) ); ?>" target="_blank" rel="noopener" class="button button-primary">
<?php esc_html_e( 'Contact Support', 'robin-image-optimizer' ); ?>
</a>
</p>
</div>
<?php
}
}

View File

@@ -0,0 +1,131 @@
<?php
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Класс отвечает за работу страницы логов.
*
* @version 1.0
*/
class WRIO_LogPage extends Wbcr_FactoryLogger359_PageBase {
/**
* {@inheritdoc}
*/
public $id = 'rio_logs'; // Уникальный идентификатор страницы
/**
* Hide bottom sidebar - only show on Settings page
*
* @var bool
*/
public $show_bottom_sidebar = false;
/**
* {@inheritdoc}
*
* @var string
*/
public $page_parent_page = 'rio_general';
/**
* {@inheritdoc}
*/
public $available_for_multisite = false;
/**
* {@inheritdoc}
*/
public $clearfy_collaboration = false;
/**
*
* Whether to show the right sidebar in options.
*
* @var bool
*/
public $show_right_sidebar_in_options = true;
/**
* Menu target for WordPress admin submenu.
*
* @var string
*/
public $menu_target = 'rio_general-robin-image-optimizer';
/**
* Use admin.php as base URL instead of menu_target.
*
* @var bool
*/
public $custom_target = true;
/**
* The page is internal and should not be displayed in the menu.
*
* @var bool
*/
public $internal = false;
/**
* View instance for rendering templates.
*
* @since 1.3.0
* @var WRIO_Views
*/
protected $view;
/**
* Подменяем пространство имен для меню плагина, если активирован плагин
* Меню текущего плагина будет добавлено в общее меню
*
* @return string
*/
public function getMenuScope() {
if ( $this->clearfy_collaboration ) {
$this->page_parent_page = 'rio_general';
return 'wbcr_clearfy';
}
return 'robin-image-optimizer';
}
/**
* @param WRIO_Plugin $plugin
*/
public function __construct( WRIO_Plugin $plugin ) {
$this->menu_title = __( 'Error Log', 'robin-image-optimizer' );
$this->page_menu_short_description = __( 'Plugin debug report', 'robin-image-optimizer' );
$this->view = WRIO_Views::get_instance( WRIO_PLUGIN_DIR );
if ( is_multisite() && defined( 'WCL_PLUGIN_ACTIVE' ) ) {
if ( WRIO_Plugin::app()->isNetworkActive() && WCL_Plugin::app()->isNetworkActive() ) {
$this->clearfy_collaboration = true;
}
} elseif ( defined( 'WCL_PLUGIN_ACTIVE' ) ) {
$this->clearfy_collaboration = true;
}
parent::__construct( $plugin );
}
/**
* {@inheritdoc}
*
* @return void
* @since 1.0.0
*/
public function assets( $scripts, $styles ) {
parent::assets( $scripts, $styles );
}
/**
* {@inheritdoc}
*/
public function getMenuTitle() {
return defined( 'LOADING_ROBIN_IMAGE_OPTIMIZER_AS_ADDON' ) ? __( 'Image optimizer', 'robin-image-optimizer' ) : __( 'Error Log', 'robin-image-optimizer' );
}
}

View File

@@ -0,0 +1,89 @@
<?php
/**
* The page Settings.
*
* @since 1.0.0
*/
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Класс отвечает за работу страницы настроек
*
* @version 1.0
*/
class WRIO_Page extends WBCR\Factory_Templates_759\Impressive {
/**
* {@inheritdoc}
*/
public $page_parent_page = null;
/**
* {@inheritdoc}
*/
public $available_for_multisite = false;
/**
* {@inheritdoc}
*/
public $clearfy_collaboration = false;
/**
* {@inheritdoc}
*
* @var bool
*/
public $show_right_sidebar_in_options = false;
/**
* Hide bottom sidebar by default - only show on Settings page
*
* @var bool
*/
public $show_bottom_sidebar = false;
/**
* @since 1.3.0
* @var WRIO_Views
*/
protected $view;
/**
* @param WRIO_Plugin $plugin
*/
public function __construct( WRIO_Plugin $plugin ) {
$this->view = WRIO_Views::get_instance( WRIO_PLUGIN_DIR );
if ( is_multisite() && defined( 'WCL_PLUGIN_ACTIVE' ) ) {
if ( WRIO_Plugin::app()->isNetworkActive() && WCL_Plugin::app()->isNetworkActive() ) {
$this->clearfy_collaboration = true;
}
} elseif ( defined( 'WCL_PLUGIN_ACTIVE' ) ) {
$this->clearfy_collaboration = true;
}
parent::__construct( $plugin );
}
/**
* Подменяем простраинство имен для меню плагина, если активирован плагин
* Меню текущего плагина будет добавлено в общее меню
*
* @return string
*/
public function getMenuScope() {
if ( $this->clearfy_collaboration ) {
$this->page_parent_page = 'rio_general';
return 'wbcr_clearfy';
}
return 'robin-image-optimizer';
}
}

View File

@@ -0,0 +1,687 @@
<?php
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Класс отвечает за работу страницы настроек
*
* @version 1.0
*/
class WRIO_SettingsPage extends WRIO_Page {
/**
* {@inheritdoc}
*/
public $id = 'rio_settings';
/**
* {@inheritdoc}
*/
public $page_menu_dashicon = 'dashicons-admin-generic';
/**
* {@inheritdoc}
*
* @var string
*/
public $page_parent_page = 'rio_general';
/**
* {@inheritdoc}
*
* @var bool
*/
public $show_right_sidebar_in_options = false;
/**
* {@inheritDoc}
*
* @since 1.1.3 - Added
* @var bool
*/
public $show_bottom_sidebar = true;
/**
* @var bool
*/
public $show_search_options_form = false;
/**
* Menu target for WordPress admin submenu.
*
* @var string
*/
public $menu_target = 'rio_general-robin-image-optimizer';
/**
* Use admin.php as base URL instead of menu_target.
*
* @var bool
*/
public $custom_target = true;
/**
* @var bool
*/
public $internal = false;
/**
* @param WRIO_Plugin $plugin
*/
public function __construct( WRIO_Plugin $plugin ) {
$this->menu_title = __( 'Settings', 'robin-image-optimizer' );
$this->page_menu_short_description = __( 'Plugin configuration', 'robin-image-optimizer' );
if ( defined( 'WBCR_CLEARFY_PLUGIN_ACTIVE' ) ) {
$this->show_search_options_form = true;
}
add_filter(
'wbcr/factory/option_image_optimization_type',
function ( $option_value ) {
if ( ! wrio_is_license_activate() && $option_value === 'background' ) {
$option_value = 'schedule';
}
return $option_value;
}
);
add_filter(
'wbcr/factory/option_convert_avif_format',
function ( $option_value ) {
if ( ! wrio_is_license_activate() && $option_value ) {
$option_value = false;
}
return $option_value;
}
);
parent::__construct( $plugin );
}
/**
* Подключаем скрипты и стили для страницы
*
* @return void
* @since 1.0.0
* @see Wbcr_FactoryPages600_AdminPage
*/
public function assets( $scripts, $styles ) {
parent::assets( $scripts, $styles );
$this->styles->add( WRIO_PLUGIN_URL . '/admin/assets/css/base-statistic.css' );
$this->scripts->add( WRIO_PLUGIN_URL . '/admin/assets/js/restore-backup.js' );
if ( ! wrio_is_license_activate() ) {
$this->styles->add( WRIO_PLUGIN_URL . '/admin/assets/css/settings-premium.css' );
$this->scripts->add( WRIO_PLUGIN_URL . '/admin/assets/js/settings-premium.js' );
}
if ( defined( 'WBCR_CLEARFY_PLUGIN_ACTIVE' ) ) {
$this->styles->add( WCL_PLUGIN_URL . '/admin/assets/css/general.css' );
}
}
/**
* Выводим предупреждения
*/
protected function warningNotice() {
$upload_dir = wp_upload_dir();
if ( ! wp_is_writable( $upload_dir['basedir'] ) ) {
$this->printErrorNotice(
sprintf(
// translators: %s is the folder path.
__( 'Folder %s is unavailable for writing', 'robin-image-optimizer' ),
'wp-content/uploads/'
)
);
}
$wio_backup = $upload_dir['basedir'] . '/wio_backup/';
if ( file_exists( $wio_backup ) && ! wp_is_writable( $wio_backup ) ) {
$this->printErrorNotice(
sprintf(
// translators: %s is the folder path.
__( 'Folder %s is unavailable for writing', 'robin-image-optimizer' ),
'wp-content/uploads/wio-backup/'
)
);
}
if ( defined( 'DISABLE_WP_CRON' ) && DISABLE_WP_CRON == true ) {
$this->printErrorNotice(
sprintf(
// translators: %s is the file name (wp-config.php).
__( 'Cron is disabled in %s', 'robin-image-optimizer' ),
'wp-config.php'
)
);
}
}
/**
* Метод должен передать массив опций для создания формы с полями.
* Созданием страницы и формы занимается фреймворк
*
* @return mixed[]
* @since 1.0.0
*/
public function getPageOptions() {
$options = [];
$options[] = [
'type' => 'html',
'html' => '<div class="wbcr-factory-page-group-header"><strong>' . __( 'Main Settings', 'robin-image-optimizer' ) . '</strong><p>' . __( 'Configure image optimization settings.', 'robin-image-optimizer' ) . '</p></div>',
];
// Радио переключатель
$options[] = [
'type' => 'dropdown',
'name' => 'image_optimization_level',
'way' => 'buttons',
'title' => __( 'Compression mode', 'robin-image-optimizer' ),
'data' => [
[
'normal',
__( 'Lossless', 'robin-image-optimizer' ),
__( 'This mode provides lossless compression and your images will be optimized without visible changes. If you want an ideal image quality, we recommend this mode. The size of the files will be reduced approximately 2 times. If this is not enough for you, try other modes.', 'robin-image-optimizer' ),
],
[
'aggresive',
__( 'Lossy', 'robin-image-optimizer' ),
__( 'This mode provides an ideal optimization of your images without significant quality loss. The file size will be reduced approximately 5 times with a slight decrease in image quality. In most cases that cannot be seen with the naked eye.', 'robin-image-optimizer' ),
],
[
'ultra',
__( 'High', 'robin-image-optimizer' ),
__( 'This mode will use all available optimization methods for maximum image compression. The file size will be reduced approximately 7 times. The quality of some images may deteriorate slightly. Use this mode if you need the maximum weight reduction, and you are ready to accept the loss of image quality.', 'robin-image-optimizer' ),
],
[
'googlepage',
__( 'G PageSpeed', 'robin-image-optimizer' ),
__( 'This mode uses the optimal settings for Google Page Speed', 'robin-image-optimizer' ),
],
[
'custom',
__( 'Custom', 'robin-image-optimizer' ),
__( 'This mode allows you to configure your own compression ratio.', 'robin-image-optimizer' ),
],
],
'layout' => [
'hint-type' => 'icon',
'hint-icon-color' => 'grey',
],
'hint' => __( 'Select the compression mode appropriate for your case.', 'robin-image-optimizer' ),
'default' => 'normal',
'events' => [
'normal' => [
'hide' => '.factory-control-image_optimization_level_custom',
],
'aggresive' => [
'hide' => '.factory-control-image_optimization_level_custom',
],
'ultra' => [
'hide' => '.factory-control-image_optimization_level_custom',
],
'googlepage' => [
'hide' => '.factory-control-image_optimization_level_custom',
],
'custom' => [
'show' => '.factory-control-image_optimization_level_custom',
],
],
];
// Текстовое поле
$options[] = [
'type' => 'textbox',
'name' => 'image_optimization_level_custom',
'title' => __( 'Enter custom quality', 'robin-image-optimizer' ),
'layout' => [
'hint-type' => 'icon',
'hint-icon-color' => 'grey',
],
'hint' => __( 'Custom quality 1-100', 'robin-image-optimizer' ),
'default' => '70',
];
// Переключатель
$options[] = [
'type' => 'checkbox',
'way' => 'buttons',
'name' => 'auto_optimize_when_upload',
'title' => __( 'Auto optimization on upload', 'robin-image-optimizer' ),
'layout' => [
'hint-type' => 'icon',
'hint-icon-color' => 'grey',
],
'hint' => __( 'Automatically compress all images that you upload directly to the WordPress media library, when editing pages and posts or using themes and plugins.', 'robin-image-optimizer' ),
'default' => false,
];
// Переключатель
$options[] = [
'type' => 'checkbox',
'way' => 'buttons',
'name' => 'backup_origin_images',
'title' => __( 'Backup images', 'robin-image-optimizer' ),
'layout' => [
'hint-type' => 'icon',
'hint-icon-color' => 'green',
],
'hint' => __( 'Before optimizing, all your images will be saved in a separate folder for future recovery.', 'robin-image-optimizer' ),
'default' => true,
];
// Переключатель
$options[] = [
'type' => 'checkbox',
'way' => 'buttons',
'name' => 'error_log',
'title' => __( 'Error Log', 'robin-image-optimizer' ),
'layout' => [
'hint-type' => 'icon',
'hint-icon-color' => 'grey',
],
'hint' => __( 'Enable error logging. The log will be displayed on a separate tab.', 'robin-image-optimizer' ),
'default' => false,
'eventsOn' => [
'show' => '#wrio-error-log-options',
],
'eventsOff' => [
'hide' => '#wrio-error-log-options',
],
];
$options[] = [
'type' => 'html',
'html' => [ $this, 'error_log_options' ],
];
// WebP conversion option (FREE)
$options[] = [
'type' => 'checkbox',
'way' => 'buttons',
'name' => 'convert_webp_format',
'title' => __( 'Convert Images to WebP', 'robin-image-optimizer' ),
'layout' => [
'hint-type' => 'icon',
'hint-icon-color' => 'grey',
],
'hint' => __( 'Convert JPEG & PNG images into WebP format and replace them for browsers which support it. Unsupported browsers would be skipped.', 'robin-image-optimizer' ),
'default' => false,
];
// AVIF conversion option (PRO only)
$options[] = [
'type' => 'checkbox',
'way' => 'buttons',
'name' => 'convert_avif_format',
'title' => __( 'Convert Images to AVIF', 'robin-image-optimizer' ),
'layout' => [
'hint-type' => 'icon',
'hint-icon-color' => 'grey',
],
'hint' => __( 'Convert JPEG & PNG images into AVIF format. AVIF provides superior compression but requires a premium license.', 'robin-image-optimizer' ),
'default' => false,
'cssClass' => ! wrio_is_license_activate() ? [ 'factory-checkbox-disabled', 'wrio-checkbox-premium-label' ] : [],
];
$options[] = [
'type' => 'html',
'html' => [ $this, 'conver_webp_options' ],
];
// восстановление
$options[] = [
'type' => 'html',
'html' => [ $this, 'rollbackButton' ],
];
// Переключатель
$options[] = [
'type' => 'checkbox',
'way' => 'buttons',
'name' => 'save_exif_data',
'title' => __( 'Strip EXIF data', 'robin-image-optimizer' ),
'layout' => [
'hint-type' => 'icon',
'hint-icon-color' => 'grey',
],
'hint' => __( 'EXIF is information stored in photos: camera model, shutter speed, exposure compensation, ISO, GPS, etc. By default, the plugin removes EXIF extended data. If your project is dedicated to photography and you need to display this data, then enable this option.', 'robin-image-optimizer' ),
'default' => true,
];
$options[] = [
'type' => 'html',
'html' => '<div class="wbcr-factory-page-group-header"><strong>' . __( 'Optimization', 'robin-image-optimizer' ) . '</strong><p>' . __( 'Here you can specify additional image optimization options.', 'robin-image-optimizer' ) . '</p></div>',
];
$options[] = [
'type' => 'dropdown',
'name' => 'image_optimization_order',
'way' => 'buttons',
'title' => __( 'Optimization order', 'robin-image-optimizer' ),
'data' => [
[
'asc',
__( 'Ascending', 'robin-image-optimizer' ),
__( 'Optimization will start with old images in the media library', 'robin-image-optimizer' ),
],
[
'desc',
__( 'Descending', 'robin-image-optimizer' ),
__( 'Optimization will start with new images in the media library', 'robin-image-optimizer' ),
],
],
'layout' => [
'hint-type' => 'icon',
'hint-icon-color' => 'grey',
],
'hint' => __( /** @lang text */ 'Select the optimization order from the media library.', 'robin-image-optimizer' ),
'default' => 'asc',
];
// Переключатель
$options[] = [
'type' => 'checkbox',
'way' => 'buttons',
'name' => 'resize_larger',
'title' => __( 'Resizing large images', 'robin-image-optimizer' ),
'layout' => [
'hint-type' => 'icon',
'hint-icon-color' => 'grey',
],
'hint' => __( 'When you upload images from a camera or stock, they may be too high resolution and it is not necessary for web. The option allows you to automatically change images resolution on upload.', 'robin-image-optimizer' ),
'default' => false,
// когда чекбокс включен показываем поле с классом .factory-control-resize_larger_w
'eventsOn' => [
'show' => '.factory-control-resize_larger_w,.factory-control-resize_larger_h',
],
// когда чекбокс выключен, скрываем поле с классом .factory-control-resize_larger_w
'eventsOff' => [
'hide' => '.factory-control-resize_larger_w,.factory-control-resize_larger_h',
],
];
// Текстовое поле
$options[] = [
'type' => 'textbox',
'name' => 'resize_larger_w',
'title' => __( 'Enter the maximum width (px)', 'robin-image-optimizer' ),
'layout' => [
'hint-type' => 'icon',
'hint-icon-color' => 'grey',
],
'hint' => __( 'Set the maximum images resolution on the long side. For horizontal images, this will be the width, and for vertical images - the height. The resolution of the images will be changed proportionally according to the set value.', 'robin-image-optimizer' ),
'default' => '1600',
];
// Текстовое поле
$options[] = [
'type' => 'textbox',
'name' => 'resize_larger_h',
'title' => __( 'Enter the maximum height (px)', 'robin-image-optimizer' ),
'layout' => [
'hint-type' => 'icon',
'hint-icon-color' => 'grey',
],
'hint' => __( 'Set the maximum images resolution on the long side. For horizontal images, this will be the width, and for vertical images - the height. The resolution of the images will be changed proportionally according to the set value.', 'robin-image-optimizer' ),
'default' => '1600',
];
$options[] = [
'type' => 'list',
'way' => 'checklist',
'name' => 'allowed_formats',
'title' => __( 'Optimize formats', 'robin-image-optimizer' ),
'data' => [
[ 'image/jpeg', 'JPG' ],
[ 'image/png', 'PNG' ],
[ 'image/gif', 'GIF' ],
],
'layout' => [
'hint-type' => 'icon',
'hint-icon-color' => 'grey',
],
'hint' => __( 'Choose which formats of images should be optimized and uncheck those that do not need optimization.', 'robin-image-optimizer' ),
'default' => 'image/jpeg,image/png,image/gif',
];
// получаем зарегистрированные размеры изображений
$wp_image_sizes = wrio_get_image_sizes();
$wio_image_sizes = [];
foreach ( $wp_image_sizes as $key => $value ) {
$wio_image_sizes[] = [
$key,
$key . ' - ' . $value['width'] . 'x' . $value['height'],
];
}
$options[] = [
'type' => 'list',
'way' => 'checklist',
'name' => 'allowed_sizes_thumbnail',
'title' => __( 'Optimize thumbnails', 'robin-image-optimizer' ),
'data' => $wio_image_sizes,
'layout' => [
'hint-type' => 'icon',
'hint-icon-color' => 'grey',
],
'hint' => __( 'Choose which sizes of thumbnails should be optimized and uncheck those that do not need optimization.', 'robin-image-optimizer' ),
'default' => 'thumbnail,medium',
];
// cron
$options[] = [
'type' => 'html',
'html' => '<div class="wbcr-factory-page-group-header"><strong>' . __( 'Scheduled and background optimization', 'robin-image-optimizer' ) . '</strong><p>' . __( 'Settings for scheduled and background image optimization.', 'robin-image-optimizer' ) . '</p></div>',
];
$options[] = [
'type' => 'dropdown',
'name' => 'image_optimization_type',
'way' => 'buttons',
'title' => __( 'Background optimization type', 'robin-image-optimizer' ),
'data' => [
[
'schedule',
__( 'Scheduled', 'robin-image-optimizer' ),
__( 'Optimization will take place on a schedule', 'robin-image-optimizer' ),
],
[
'background',
__( 'Background', 'robin-image-optimizer' ),
__( 'Optimization will occur in the background constantly', 'robin-image-optimizer' ),
],
],
'layout' => [
'hint-type' => 'icon',
'hint-icon-color' => 'grey',
],
'hint' => sprintf(
// translators: %1$s is the bold start tag, %2$s is the bold end tag.
__( '%1$sScheduled optimization%2$s will occur on a scheduled basis.', 'robin-image-optimizer' ),
'<b>',
'</b>'
) . '<br>' . sprintf(
// translators: %1$s is the bold start tag, %2$s is the bold end tag.
__( '%1$sBackground optimization%2$s will occur in the background constantly.', 'robin-image-optimizer' ),
'<b>',
'</b>'
),
'default' => 'schedule',
'events' => [
'schedule' => [
'show' => '#wbcr-io-shedule-options',
],
'background' => [
'hide' => '#wbcr-io-shedule-options',
],
],
];
$group_items[] = [
'type' => 'dropdown',
'way' => 'buttons',
'name' => 'image_autooptimize_shedule_time',
'data' => [
[ 'wio_1_min', __( '1 minute', 'robin-image-optimizer' ) ],
// translators: %s is the number of minutes.
[ 'wio_2_min', sprintf( __( '%s minutes', 'robin-image-optimizer' ), '2' ) ],
// translators: %s is the number of minutes.
[ 'wio_5_min', sprintf( __( '%s minutes', 'robin-image-optimizer' ), '5' ) ],
// translators: %s is the number of minutes.
[ 'wio_10_min', sprintf( __( '%s minutes', 'robin-image-optimizer' ), '10' ) ],
// translators: %s is the number of minutes.
[ 'wio_30_min', sprintf( __( '%s minutes', 'robin-image-optimizer' ), '30' ) ],
[ 'wio_hourly', __( 'Hour', 'robin-image-optimizer' ) ],
[ 'wio_daily', __( 'Day', 'robin-image-optimizer' ) ],
],
'default' => 'wio_5_min',
'title' => __( 'Run every', 'robin-image-optimizer' ),
'hint' => __( 'Select time at which the task will be repeated.', 'robin-image-optimizer' ),
];
$group_items[] = [
'type' => 'textbox',
'name' => 'image_autooptimize_items_number_per_interation',
'title' => __( 'Images per iteration', 'robin-image-optimizer' ),
'layout' => [
'hint-type' => 'icon',
'hint-icon-color' => 'grey',
],
'hint' => __( 'Specify the number of images that will be optimized during the job. For example, if you enter 5 and select 5 min, the plugin will optimize 5 images every 5 minutes.', 'robin-image-optimizer' ),
'default' => '3',
'htmlAttrs' => [
'type' => 'number',
'min' => '1',
'step' => '1',
],
'filter_value' => function ( $value ) {
$int_value = intval( $value );
return $int_value < 1 ? 1 : $int_value;
},
];
$options[] = [
'type' => 'div',
'id' => 'wbcr-io-shedule-options',
'items' => $group_items,
];
$options = apply_filters( 'wbcr/rio/settings_page/options', $options );
$formOptions = [];
$formOptions[] = [
'type' => 'form-group',
'items' => $options,
// 'cssClass' => 'postbox'
];
return $formOptions;
}
/**
* Save advanced options in database
*
* @since 1.3.6
*/
public function beforeFormSave() {
/**
* Used to save webp options. It can also be used to intercept
* other unregistered fields.
*
* @since 1.3.6
*/
do_action( 'wrio/settings_page/berfore_form_save' );
$error_log = (int) WRIO_Plugin::app()->request->post( WRIO_Plugin::app()->getPrefix() . 'error_log', 0 );
if ( ! $error_log ) {
return;
}
$keep_error_log_on_frontend = (int) WRIO_Plugin::app()->request->post( 'wrio_keep_error_log_on_frontend', 0 );
WRIO_Plugin::app()->updatePopulateOption( 'keep_error_log_on_frontend', $keep_error_log_on_frontend );
}
/**
* This method adds advanced options for the "Convert Images to WebP" checkbox.
*
* @since 1.3.6
*/
public function conver_webp_options() {
/**
* This hook prints options for delivering webp images.
*
* @since 1.3.6
*/
do_action( 'wrio/settings_page/conver_webp_options' );
}
/**
* This method adds advanced options for the "Error log" checkbox.
*
* @since 1.3.6
*/
public function error_log_options() {
$this->view->print_template(
'part-settings-page-error-log-options',
[
'keep_error_log_on_frontend' => (int) WRIO_Plugin::app()->getPopulateOption( 'keep_error_log_on_frontend', 0 ),
]
);
}
/**
* Кнопка восстановления изображений
*/
public function rollbackButton() {
?>
<div class="form-group form-group-checkbox factory-control-rollback-button">
<label for="wio-clear-backup-btn" class="col-sm-4 control-label">
<?php esc_html_e( 'Manage backups', 'robin-image-optimizer' ); ?>
<span class="factory-hint-icon factory-hint-icon-red" data-toggle="factory-tooltip"
data-placement="right" title=""
data-original-title="<?php esc_html_e( 'You can restore the original images from a backup or clear them.', 'robin-image-optimizer' ); ?>"
>
?
</span>
</label>
<input type="hidden" value="<?php echo wp_create_nonce( 'wio-iph' ); ?>" id="wio-iph-nonce">
<div class="control-group col-sm-8">
<div class="factory-buttons-way btn-group">
<a class="btn btn-default" id="wio-restore-backup-btn"
data-confirm="<?php esc_html_e( 'Are you sure you want to restore all images? This cannot be undone.', 'robin-image-optimizer' ); ?>"
href="#"><?php esc_html_e( 'Restore', 'robin-image-optimizer' ); ?></a>
<a class="btn btn-default" id="wio-clear-backup-btn"
data-confirm="<?php esc_html_e( 'Are you sure you want to clear the backup folder? All backup images will be permanently deleted.', 'robin-image-optimizer' ); ?>"
href="#"><?php esc_html_e( 'Clear Backup', 'robin-image-optimizer' ); ?></a>
</div>
<div class="progress" id="wio-restore-backup-progress" style="display:none;">
<div class="progress-bar progress-bar-success" role="progressbar" aria-valuenow="0"
aria-valuemin="0" aria-valuemax="100" style="width:0%">
</div>
</div>
<p id="wio-restore-backup-msg"
style="display:none;"><?php esc_html_e( 'Restore completed.', 'robin-image-optimizer' ); ?></p>
<p id="wio-clear-backup-msg"
style="display:none;"><?php esc_html_e( 'The backup folder was cleared.', 'robin-image-optimizer' ); ?></p>
</div>
</div>
<?php
}
}

View File

@@ -0,0 +1,359 @@
<?php
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Class WRIO_StatisticPage
* Класс отвечает за работу страницы статистики
*/
class WRIO_StatisticPage extends WRIO_Page {
/**
* {@inheritdoc}
*/
public $id = 'rio_general';
/**
* {@inheritdoc}
*/
public $type = 'page';
/**
* {@inheritdoc}
*/
public $plugin;
/**
* {@inheritdoc}
*/
public $page_menu_position = 20;
/**
* {@inheritdoc}
*/
public $page_menu_dashicon = 'dashicons-chart-line';
/**
* Menu icon for WordPress admin sidebar.
*
* @var string
*/
public $menu_icon = 'dashicons-images-alt';
/**
* Position in WordPress admin menu (58 = between Comments and Appearance).
*
* @var string
*/
public $menu_position = '58';
/**
* @var string
*/
public $menu_target = null;
/**
* {@inheritdoc}
*
* @var null
*/
public $page_parent_page = null;
/**
* @var bool
*/
public $internal = false;
/**
* @var bool
*/
public $add_link_to_plugin_actions = true;
/**
* Page type
*
* @since 1.3.0
* @var string
*/
protected $scope = 'media-library';
/**
* @param WRIO_Plugin $plugin
*/
public function __construct( WRIO_Plugin $plugin ) {
$this->menu_title = __( 'Robin Image Optimizer', 'robin-image-optimizer' );
$this->menu_sub_title = __( 'Optimize', 'robin-image-optimizer' );
$this->page_menu_short_description = __( 'Compress bulk of images', 'robin-image-optimizer' );
$this->plugin = $plugin;
parent::__construct( $plugin );
add_action( 'admin_enqueue_scripts', [ $this, 'print_i18n' ] );
add_filter( 'wbcr/factory/pages/impressive/print_all_notices', [ $this, 'register_limit_notice' ], 10, 2 );
}
/**
* @param $plugin
* @param $obj
*
* @return void|bool
*/
public function register_limit_notice( $plugin, $obj ) {
if ( ( $this->plugin->getPluginName() !== $plugin->getPluginName() ) || ( 'rio_general' !== $obj->id ) ) {
return false;
}
}
/**
* Подменяем простраинство имен для меню плагина, если активирован плагин
* Меню текущего плагина будет добавлено в общее мен
*
* @return string
*/
public function getMenuScope() {
if ( $this->clearfy_collaboration ) {
// $this->internal = true;
return 'wbcr_clearfy';
}
return 'robin-image-optimizer';
}
/**
* {@inheritdoc}
*/
public function getMenuTitle() {
return $this->menu_title;
}
/**
* {@inheritdoc}
*/
public function getPageTitle() {
return $this->clearfy_collaboration ? __( 'Image optimizer', 'robin-image-optimizer' ) : __( 'Bulk optimization', 'robin-image-optimizer' );
}
/**
* {@inheritdoc}
*/
public function assets( $scripts, $styles ) {
parent::assets( $scripts, $styles );
$this->styles->add( WRIO_PLUGIN_URL . '/admin/assets/css/base-statistic.css' );
$this->scripts->add( WRIO_PLUGIN_URL . '/admin/assets/js/sweetalert2.js' );
$this->styles->add( WRIO_PLUGIN_URL . '/admin/assets/css/sweetalert2.css' );
$this->styles->add( WRIO_PLUGIN_URL . '/admin/assets/css/sweetalert-custom.css' );
$this->scripts->add( WRIO_PLUGIN_URL . '/admin/assets/js/Chart.min.js' );
// $this->scripts->add( WRIO_PLUGIN_URL . '/admin/assets/js/statistic.js' );
$this->scripts->add( WRIO_PLUGIN_URL . '/admin/assets/js/modals.js', [ 'jquery' ], 'wrio-modals' );
$this->scripts->add(
WRIO_PLUGIN_URL . '/admin/assets/js/bulk-optimization.js',
[
'jquery',
'wrio-modals',
]
);
$this->scripts->add( WRIO_PLUGIN_URL . '/admin/assets/js/calculate-attachments.js' );
$this->scripts->add(
WRIO_PLUGIN_URL . '/admin/assets/js/bulk-conversion.js',
[
'jquery',
'wrio-modals',
]
);
if ( defined( 'WBCR_CLEARFY_PLUGIN_ACTIVE' ) ) {
$this->styles->add( WCL_PLUGIN_URL . '/admin/assets/css/general.css' );
}
}
/**
* Print localization only current page
*
* @throws \Exception
* @since 1.3.0
*/
public function print_i18n() {
$page = $this->plugin->request->get( 'page', null );
if ( $page !== $this->getResultId() ) {
return;
}
$backup = new WIO_Backup();
wp_enqueue_script( 'wio-statistic-page', WRIO_PLUGIN_URL . '/admin/assets/js/statistic.js', [ 'jquery' ], WRIO_Plugin::app()->getPluginVersion(), true );
wp_localize_script( 'wio-statistic-page', 'wrio_l18n_bulk_page', $this->get_i18n() );
wp_localize_script(
'wio-statistic-page',
'wrio_settings_bulk_page',
[
'is_premium' => wrio_is_license_activate(),
'is_network_admin' => WRIO_Plugin::app()->isNetworkAdmin() ? 1 : 0,
'is_writable_backup_dir' => $backup->isBackupWritable() ? 1 : 0,
'images_backup' => WRIO_Plugin::app()->getPopulateOption( 'backup_origin_images', false ) ? 1 : 0,
'need_migration' => wbcr_rio_has_meta_to_migrate() ? 1 : 0,
'scope' => $this->scope,
'optimization_nonce' => wp_create_nonce( 'bulk_optimization' ),
'conversion_nonce' => wp_create_nonce( 'bulk_conversion' ),
]
);
}
/**
* {@inheritdoc}
*/
public function showPageContent() {
$is_premium = wrio_is_license_activate();
$statistics = $this->get_statisctic_data();
$template_data = [
'is_premium' => $is_premium,
'scope' => $this->scope,
];
// do_action( 'wbcr/rio/multisite_current_blog' );
// Page header
$this->view->print_template(
'part-page-header',
[
'title' => __( 'Image optimization dashboard', 'robin-image-optimizer' ),
'description' => __( 'Monitor image optimization statistics and run on demand or scheduled optimization.', 'robin-image-optimizer' ),
],
$this
);
// Page tabs
$this->view->print_template( 'part-bulk-optimization-tabs', $template_data, $this );
?>
<div class="wbcr-factory-page-group-body" style="padding:0; border-top: 1px solid #d4d4d4;">
<?php
// Servers
$this->view->print_template( 'part-bulk-optimization-servers', $template_data, $this );
// Total
$this->view->print_template(
'part-bulk-optimization-total',
array_merge(
$template_data,
[
'stats' => $statistics->get(),
]
),
$this
);
// Statistic
$this->view->print_template(
'part-bulk-optimization-statistic',
array_merge(
$template_data,
[
'stats' => $statistics->get(),
]
),
$this
);
// Optimization log
$this->view->print_template(
'part-bulk-optimization-log',
array_merge(
$template_data,
[
'process_log' => $statistics->get_last_optimized_images(),
]
),
$this
);
?>
</div>
<script type="text/html" id="wrio-tmpl-bulk-optimization">
<?php $this->view->print_template( 'modal-bulk-optimization' ); ?>
</script>
<script type="text/html" id="wrio-tmpl-webp-conversion">
<?php $this->view->print_template( 'modal-webp-conversion' ); ?>
</script>
<?php
// do_action( 'wbcr/rio/multisite_restore_blog' );
}
/**
* @return object|\WRIO_Image_Statistic
* @since 1.3.0
*/
protected function get_statisctic_data() {
return WRIO_Image_Statistic::get_instance();
}
/**
* @return array
* @since 1.3.0
*/
protected function get_i18n() {
$modal_optimization_cron_button = __( 'Scheduled optimization', 'robin-image-optimizer' );
$modal_conversion_cron_button = __( 'Scheduled conversion', 'robin-image-optimizer' );
$modal_optimization_cron_button_stop = __( 'Stop schedule optimization', 'robin-image-optimizer' );
$modal_conversion_cron_button_stop = __( 'Stop schedule conversion', 'robin-image-optimizer' );
$optimize_type = WRIO_Plugin::app()->getOption( 'image_optimization_type', 'schedule' );
if ( wrio_is_license_activate() && $optimize_type === 'background' ) {
$modal_optimization_cron_button = __( 'Background optimization', 'robin-image-optimizer' );
$modal_conversion_cron_button = __( 'Background conversion', 'robin-image-optimizer' );
$modal_optimization_cron_button_stop = __( 'Stop background optimization', 'robin-image-optimizer' );
$modal_conversion_cron_button_stop = __( 'Stop background conversion', 'robin-image-optimizer' );
}
return [
'server_down_warning' => __( 'Your selected optimization server is down. This means that you cannot optimize images through this server. Try selecting another optimization server.', 'robin-image-optimizer' ),
// translators: the status of server.
'server_status_down' => __( 'Down', 'robin-image-optimizer' ),
// translators: the status of server.
'server_status_stable' => __( 'Stable', 'robin-image-optimizer' ),
'modal_error' => __( 'Error', 'robin-image-optimizer' ),
'modal_cancel' => __( 'Cancel', 'robin-image-optimizer' ),
'modal_confirm' => __( 'Confirm', 'robin-image-optimizer' ),
'modal_optimization_title' => __( 'Select optimization way', 'robin-image-optimizer' ),
'modal_optimization_manual_button' => __( 'Optimize now', 'robin-image-optimizer' ),
'modal_optimization_cron_button' => $modal_optimization_cron_button,
'modal_optimization_cron_button_stop' => $modal_optimization_cron_button_stop,
'optimization_complete' => __( 'All images from the media library are optimized.', 'robin-image-optimizer' ),
// translators: %s is the number of remaining images
'optimization_inprogress' => sprintf( __( 'Optimization in progress. %s images remaining.', 'robin-image-optimizer' ), '<span id="wio-total-unoptimized">%s</span>' ),
'modal_conversion_title' => __( 'Select conversion way', 'robin-image-optimizer' ),
'modal_conversion_manual_button' => __( 'Convert now', 'robin-image-optimizer' ),
'modal_conversion_cron_button' => $modal_conversion_cron_button,
'modal_conversion_cron_button_stop' => $modal_conversion_cron_button_stop,
'conversion_complete' => __( 'All images from the media library are optimized.', 'robin-image-optimizer' ),
// translators: %s is the number of remaining images
'conversion_inprogress' => sprintf( __( 'Conversion in progress. %s images remaining.', 'robin-image-optimizer' ), '<span id="wio-total-unoptimized">%s</span>' ),
'webp_button_start' => __( 'Convert to WebP', 'robin-image-optimizer' ),
'avif_button_start' => __( 'Convert to AVIF', 'robin-image-optimizer' ),
'modal_avif_conversion_title' => __( 'Select AVIF conversion way', 'robin-image-optimizer' ),
'need_migrations' => __( 'To start optimizing, you must complete migration from old plugin version.', 'robin-image-optimizer' ),
'leave_page_warning' => __( 'Optimization is still in progress. Are you sure you want to leave?', 'robin-image-optimizer' ),
'process_without_backup' => __( 'Do you want to start optimization without backup?', 'robin-image-optimizer' ),
'button_resume' => __( 'Resume', 'robin-image-optimizer' ),
'button_completed' => __( 'Completed', 'robin-image-optimizer' ),
'button_start' => __( 'Optimize', 'robin-image-optimizer' ),
'button_stop' => __( 'Stop', 'robin-image-optimizer' ),
// Don't Need a Parachute?
// If you keep this option deactivated, you won't be able to re-optimize your images to another compression level and restore your original images in case of need.
];
}
}

View File

@@ -0,0 +1,2 @@
<?php
// silence is golden