<?php
/**
* The class to optimize image.
*
* @since 2.0
* @package LiteSpeed
*/
namespace LiteSpeed;
use WpOrg\Requests\Autoload;
use WpOrg\Requests\Requests;
defined( 'WPINC' ) || exit();
/**
* Class Img_Optm
*
* Handles image optimization operations with QUIC.cloud service.
*/
class Img_Optm extends Base {
use Img_Optm_Send;
use Img_Optm_Pull;
use Img_Optm_Manage;
const LOG_TAG = '🗜️';
const CLOUD_ACTION_NEW_REQ = 'new_req';
const CLOUD_ACTION_TAKEN = 'taken';
const CLOUD_ACTION_REQUEST_DESTROY = 'imgoptm_destroy';
const CLOUD_ACTION_CLEAN = 'clean';
const TYPE_NEW_REQ = 'new_req';
const TYPE_RESCAN = 'rescan';
const TYPE_DESTROY = 'destroy';
const TYPE_RESET_COUNTER = 'reset_counter';
const TYPE_CLEAN = 'clean';
const TYPE_PULL = 'pull';
const TYPE_BATCH_SWITCH_ORI = 'batch_switch_ori';
const TYPE_BATCH_SWITCH_OPTM = 'batch_switch_optm';
const TYPE_CALC_BKUP = 'calc_bkup';
const TYPE_RESET_ROW = 'reset_row';
const TYPE_RM_BKUP = 'rm_bkup';
const STATUS_NEW = 0; // 'new';
const STATUS_RAW = 1; // 'raw';
const STATUS_REQUESTED = 3; // 'requested';
const STATUS_NOTIFIED = 6; // 'notified';
const STATUS_DUPLICATED = 8; // 'duplicated';
const STATUS_PULLED = 9; // 'pulled';
const STATUS_FAILED = -1; // 'failed';
const STATUS_MISS = -3; // 'miss';
const STATUS_ERR_FETCH = -5; // 'err_fetch';
const STATUS_ERR_404 = -6; // 'err_404';
const STATUS_ERR_OPTM = -7; // 'err_optm';
const STATUS_XMETA = -8; // 'xmeta';
const STATUS_ERR = -9; // 'err';
const DB_SIZE = 'litespeed-optimize-size';
const DB_SET = 'litespeed-optimize-set';
const DB_NEED_PULL = 'need_pull';
/**
* WordPress upload directory info.
*
* @var array
*/
private $wp_upload_dir;
/**
* Temporary post ID for current operation.
*
* @var int
*/
private $tmp_pid;
/**
* Temporary type for current operation.
*
* @var string
*/
private $tmp_type;
/**
* Temporary path for current operation.
*
* @var string
*/
private $tmp_path;
/**
* Images queued for optimization.
*
* @var array
*/
private $_img_in_queue = [];
/**
* List of existing source files.
*
* @var array
*/
private $_existed_src_list = [];
/**
* Set of post IDs.
*
* @var array
*/
private $_pids_set = [];
/**
* Thumbnail set string.
*
* @var string
*/
private $_thumbnail_set = '';
/**
* Image optimization table name.
*
* @var string
*/
private $_table_img_optm;
/**
* Image optimization working table name.
*
* @var string
*/
private $_table_img_optming;
/**
* Flag indicating if cron has run.
*
* @var bool
*/
private $_cron_ran = false;
/**
* Sizes to skip during optimization.
*
* @var array
*/
private $_sizes_skipped = [];
/**
* Media class instance.
*
* @var Media
*/
private $__media;
/**
* Data class instance.
*
* @var Data
*/
private $__data;
/**
* Summary data.
*
* @var array
*/
protected $_summary;
/**
* Output format (webp/avif).
*
* @var string
*/
private $_format = '';
/**
* Init
*
* @since 2.0
*/
public function __construct() {
Debug2::debug2( '[ImgOptm] init' );
$this->wp_upload_dir = wp_upload_dir();
$this->__media = $this->cls( 'Media' );
$this->__data = $this->cls( 'Data' );
$this->_table_img_optm = $this->__data->tb( 'img_optm' );
$this->_table_img_optming = $this->__data->tb( 'img_optming' );
$this->_summary = self::get_summary();
if ( empty( $this->_summary['next_post_id'] ) ) {
$this->_summary['next_post_id'] = 0;
}
if ( $this->conf( Base::O_IMG_OPTM_WEBP ) ) {
$this->_format = 'webp';
if ( $this->conf( Base::O_IMG_OPTM_WEBP ) === 2 ) {
$this->_format = 'avif';
}
}
// Allow users to ignore custom sizes.
$this->_sizes_skipped = apply_filters( 'litespeed_imgoptm_sizes_skipped', $this->conf( Base::O_IMG_OPTM_SIZES_SKIPPED ) );
}
/**
* Handle all request actions from main cls
*
* @since 2.0
* @access public
*/
public function handler() {
$type = Router::verify_type();
switch ( $type ) {
case self::TYPE_RESET_ROW:
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
$id = ! empty( $_GET['id'] ) ? absint( wp_unslash( $_GET['id'] ) ) : false;
$this->reset_row( $id );
break;
case self::TYPE_CALC_BKUP:
$this->_calc_bkup();
break;
case self::TYPE_RM_BKUP:
$this->rm_bkup();
break;
case self::TYPE_NEW_REQ:
$this->new_req();
break;
case self::TYPE_RESCAN:
$this->_rescan();
break;
case self::TYPE_RESET_COUNTER:
$this->_reset_counter();
break;
case self::TYPE_DESTROY:
$this->_destroy();
break;
case self::TYPE_CLEAN:
$this->clean();
break;
case self::TYPE_PULL:
self::start_async();
break;
case self::TYPE_BATCH_SWITCH_ORI:
case self::TYPE_BATCH_SWITCH_OPTM:
$this->batch_switch( $type );
break;
case substr( $type, 0, 4 ) === 'avif':
case substr( $type, 0, 4 ) === 'webp':
case substr( $type, 0, 4 ) === 'orig':
$this->_switch_optm_file( $type );
break;
default:
break;
}
Admin::redirect();
}
}
| nama | waktu | ukuran | owner | perm | aksi |
|---|---|---|---|---|---|
| .. | |||||
| cdn/ | 2026-06-06 16:18 | 11.25 KB | 76129f60960:kunden | dxwrx-r--r | |
| data_structure/ | 2026-06-06 16:18 | 2.62 KB | 76129f60960:kunden | dxwrx-r--r | |
| activation.cls.php | 2026-06-06 16:18 | 17.31 KB | 76129f60960:kunden | -xw-x----- | |
| admin-display.cls.php | 2026-06-06 16:18 | 48.47 KB | 76129f60960:kunden | -xw-x----- | |
| admin-settings.cls.php | 2026-06-06 16:18 | 11.12 KB | 76129f60960:kunden | -xw-x----- | |
| admin.cls.php | 2026-06-06 16:18 | 6.13 KB | 76129f60960:kunden | -xw-x----- | |
| api.cls.php | 2026-06-06 16:18 | 10.36 KB | 76129f60960:kunden | -xw-x----- | |
| avatar.cls.php | 2026-06-06 16:18 | 8.65 KB | 76129f60960:kunden | -xw-x----- | |
| base.cls.php | 2026-06-06 16:18 | 37.66 KB | 76129f60960:kunden | -xw-x----- | |
| cdn.cls.php | 2026-06-06 16:18 | 15.92 KB | 76129f60960:kunden | -xw-x----- | |
| cloud-auth-callback.trait.php | 2026-06-06 16:18 | 10.43 KB | 76129f60960:kunden | -xw-x----- | |
| cloud-auth-ip.trait.php | 2026-06-06 16:18 | 4.33 KB | 76129f60960:kunden | -xw-x----- | |
| cloud-auth.trait.php | 2026-06-06 16:18 | 9.38 KB | 76129f60960:kunden | -xw-x----- | |
| cloud-misc.trait.php | 2026-06-06 16:18 | 10.32 KB | 76129f60960:kunden | -xw-x----- | |
| cloud-node.trait.php | 2026-06-06 16:18 | 5.95 KB | 76129f60960:kunden | -xw-x----- | |
| cloud-request.trait.php | 2026-06-06 16:18 | 19.68 KB | 76129f60960:kunden | -xw-x----- | |
| cloud.cls.php | 2026-06-06 16:18 | 7.32 KB | 76129f60960:kunden | -xw-x----- | |
| conf.cls.php | 2026-06-06 16:18 | 19.53 KB | 76129f60960:kunden | -xw-x----- | |
| control.cls.php | 2026-06-06 16:18 | 24.35 KB | 76129f60960:kunden | -xw-x----- | |
| core.cls.php | 2026-06-06 16:18 | 20.97 KB | 76129f60960:kunden | -xw-x----- | |
| crawler-map.cls.php | 2026-06-06 16:18 | 19.41 KB | 76129f60960:kunden | -xw-x----- | |
| crawler.cls.php | 2026-06-06 16:18 | 44.72 KB | 76129f60960:kunden | -xw-x----- | |
| css.cls.php | 2026-06-06 16:18 | 17.77 KB | 76129f60960:kunden | -xw-x----- | |
| data.cls.php | 2026-06-06 16:18 | 22.21 KB | 76129f60960:kunden | -xw-x----- | |
| data.upgrade.func.php | 2026-06-06 16:18 | 5.72 KB | 76129f60960:kunden | -xw-x----- | |
| db-optm.cls.php | 2026-06-06 16:18 | 15.35 KB | 76129f60960:kunden | -xw-x----- | |
| debug2.cls.php | 2026-06-06 16:18 | 18.4 KB | 76129f60960:kunden | -xw-x----- | |
| doc.cls.php | 2026-06-06 16:18 | 5.45 KB | 76129f60960:kunden | -xw-x----- | |
| error.cls.php | 2026-06-06 16:18 | 7.35 KB | 76129f60960:kunden | -xw-x----- | |
| esi.cls.php | 2026-06-06 16:18 | 27.18 KB | 76129f60960:kunden | -xw-x----- | |
| file.cls.php | 2026-06-06 16:18 | 10.57 KB | 76129f60960:kunden | -xw-x----- | |
| guest.cls.php | 2026-06-06 16:18 | 2.75 KB | 76129f60960:kunden | -xw-x----- | |
| gui.cls.php | 2026-06-06 16:18 | 36.57 KB | 76129f60960:kunden | -xw-x----- | |
| health.cls.php | 2026-06-06 16:18 | 2.83 KB | 76129f60960:kunden | -xw-x----- | |
| htaccess.cls.php | 2026-06-06 16:18 | 29.81 KB | 76129f60960:kunden | -xw-x----- | |
| img-optm-manage.trait.php | 2026-06-06 16:18 | 30.85 KB | 76129f60960:kunden | -xw-x----- | |
| img-optm-pull.trait.php | 2026-06-06 16:18 | 22.1 KB | 76129f60960:kunden | -xw-x----- | |
| img-optm-send.trait.php | 2026-06-06 16:18 | 21.9 KB | 76129f60960:kunden | -xw-x----- | |
| img-optm.cls.php | 2026-06-06 16:18 | 5.26 KB | 76129f60960:kunden | -xw-x----- | |
| import.cls.php | 2026-06-06 16:18 | 4.29 KB | 76129f60960:kunden | -xw-x----- | |
| import.preset.cls.php | 2026-06-06 16:18 | 5.5 KB | 76129f60960:kunden | -xw-x----- | |
| lang.cls.php | 2026-06-06 16:18 | 17.02 KB | 76129f60960:kunden | -xw-x----- | |
| localization.cls.php | 2026-06-06 16:18 | 4.03 KB | 76129f60960:kunden | -xw-x----- | |
| media.cls.php | 2026-06-06 16:18 | 44.08 KB | 76129f60960:kunden | -xw-x----- | |
| metabox.cls.php | 2026-06-06 16:18 | 5.29 KB | 76129f60960:kunden | -xw-x----- | |
| object-cache-wp.cls.php | 2026-06-06 16:18 | 18.82 KB | 76129f60960:kunden | -xw-x----- | |
| object-cache.cls.php | 2026-06-06 16:18 | 20.95 KB | 76129f60960:kunden | -xw-x----- | |
| object.lib.php | 2026-06-06 16:18 | 14.16 KB | 76129f60960:kunden | -xw-x----- | |
| optimize.cls.php | 2026-06-06 16:18 | 38.64 KB | 76129f60960:kunden | -xw-x----- | |
| optimizer.cls.php | 2026-06-06 16:18 | 10.5 KB | 76129f60960:kunden | -xw-x----- | |
| placeholder.cls.php | 2026-06-06 16:18 | 17.93 KB | 76129f60960:kunden | -xw-x----- | |
| purge.cls.php | 2026-06-06 16:18 | 34.41 KB | 76129f60960:kunden | -xw-x----- | |
| report.cls.php | 2026-06-06 16:18 | 6.12 KB | 76129f60960:kunden | -xw-x----- | |
| rest.cls.php | 2026-06-06 16:18 | 9.08 KB | 76129f60960:kunden | -xw-x----- | |
| root.cls.php | 2026-06-06 16:18 | 14.29 KB | 76129f60960:kunden | -xw-x----- | |
| router.cls.php | 2026-06-06 16:18 | 20.76 KB | 76129f60960:kunden | -xw-x----- | |
| str.cls.php | 2026-06-06 16:18 | 3.08 KB | 76129f60960:kunden | -xw-x----- | |
| tag.cls.php | 2026-06-06 16:18 | 9.26 KB | 76129f60960:kunden | -xw-x----- | |
| task.cls.php | 2026-06-06 16:18 | 7.05 KB | 76129f60960:kunden | -xw-x----- | |
| tool.cls.php | 2026-06-06 16:18 | 4.17 KB | 76129f60960:kunden | -xw-x----- | |
| ucss.cls.php | 2026-06-06 16:18 | 16.35 KB | 76129f60960:kunden | -xw-x----- | |
| utility.cls.php | 2026-06-06 16:18 | 26.01 KB | 76129f60960:kunden | -xw-x----- | |
| vary.cls.php | 2026-06-06 16:18 | 21.33 KB | 76129f60960:kunden | -xw-x----- | |
| vpi.cls.php | 2026-06-06 16:18 | 9.38 KB | 76129f60960:kunden | -xw-x----- | |