JFIF $ d d 7 * Z qn )ZP 0 !1 A "#a$2Qr D8 a Ri [f \m I ykI w0 c u F c Rı?lO7 к _f˓ [C $殷WF< _W ԣ s Kc ëI zyQy /_LK ℂ ;C",p F A : /] =H ~ , l s / 9 ć: [=/#f ; ) x { ٛE Q )~ = 𘙲r*2~ a _V = ' ku m F D } KYYC )( { * g& f `툪 r y ` = ^ c J. I ]( * `wq 1dđ #̩ ͑ 0 ; H ] u 搂 @:~ ו K L N s h } O I R* 8 :2 ! lD JV o ( 3 = M ( z Ȱ+i *N A r6K n S l ) ! J J Ӂ* % ݉?|D } d5: eP0 R; {$X' x F @ .ÊB {,WJ uQ ɲRI ;9 Q E琯 6 2fT .DU J ;*c P A\IL Nj! J ۱+ O\ ͔ ] ޒ S J ȧ c%A N ol ՎprU L Zԛe r E2= X D Xg VQeӓ k y P7 U* o m Q I s ,K `) 6\G3t?pgjr m ۛجw luGt f h 9uyP 0D;Uڽ"OXl i f $ ) &|ML 0 Z rm1 [ H XP l P R0 'G=i 2N +0 e 2 ]] 9 VT P O 7 h(F * 癈 ' = Q VZD F,d ߬ ~ T X G[ `le 69C R(!S2! P < 0 x < !1AQ "Raq 02Br #S CTb ? Ζ "]mH5WR 7 k.ۛ ! } Q~ + yԏ z |@ T20 S~ K e k *zF f^2X *( @ 8 r ? C I uI|֓>^Ex LgNU Y+{.R Ѫ τV YT D I 6 2 '8Y2 7'\T P.6 d &˦ @V q i |8 -O Ε ] ʔ U= T L 8= ;6c | !qfF3 a ů& ~$ l} 'NW U s$U k^S V : U#6w + +s &r+n ڐ { @ 29gL u " T Ù M=6 (^ "7 r}=6Yݾ lC u hquymp Ǧ G jhs ǜNl ɻ} o 7 #S6 a w 4 ! OS r D 5 7 % | ?x> L | / nD 6?/8 w # [ ) L 7 +6〼T A T g ! %5 Mm Z /c -{1_Je "| ^$ 'O & ޱմ < H vNqϡQ$ < 6 &Nݛ ֨tǻN (9 n ru~'όN sMG& ,uH Kw *Ī 5@ u6 BԒ i YN * f 0 _ GhKW u lT <nj- 0{ M L~ | /a v\ E = ?1 \ɟuq Ђ Y O a K ޡP q $ H8o Q˼EV ~ k 0 h' L Pp M -M" m^ !6l nմ 쮝C U T . ! :vMǨb h ډ Vc r @~p # !1QAa q ? AL0L x LU 4 d ; x " 16ad0 7.\ߋ 0 = P l v/ " c A Ay A|2pO8"d MV #1] = \ " ˡ ] k v I9 d ۓ & q ) ǐq E ꞅ v "P )q X &Q З non]я u ג./ ; gZ$ M QР 2M ]h ni 0 P $ێ 3CɏGjώy : m c # S_ l@ '_ \m|C 2`K _ 1 cIvGc $? PCQ S+D ? K aײ k Fr b 8 ύ NEدg ĝ U 3 6 #Ik+ v { v i ( ވ ? a e) X xy/*@Q Ǽ Ծ ) $ IWO l c G; !i k{ gOŀ L ('x T rb $ w) R $ & N1E td U3Uȉ1p M"N* (DNy d96.(jQ) X 5 c QɎMy W ? Q *!R > 6=7)Xj 5`J ] e 8%t ! + ' ! 1Q 5 !1 AQaq ё #2 "0BRb ? G t^ ## .l lQ T $ v , ,m 㵜5u bV =sY+ @d { N ! dn O < .- B; _w J t 6;Q Jd. Q c%p{ 1 ,sND dF H I0 Гo X ш e黅X ۢ F :)[ F G X ƹ / w _c MeD ,ʡc c . W D tA $ j@ : ) - #u c1< @ۗ9F ) KJ- hpP] _ x [ q B lb p ʖ w q " LFGd ƶ * s +ډ_Zc " ? % t[I P 6 J ]# =ɺ V v v CGs Gh1 > )6 |e y ? L ӣ m,4 G W Ui ` ] uJVo VDG< SB 6ϏQ @ TiU l y O U 0 kfV ~ ~}S Z @ *WU Ui ## ; s /[ = ! 7}" W N ] ' (L ! ~ y5 g9T̅J kbM' +s :S +B) v @ M j e C f j E 0 Y\Qn z G 1 д~ W o{T 9?` Rm yhsy3 !HAD ] m c1 ~ 2 L S u7x T ;j$ `} 4-> L# vzŏ I L S ֭ T { r jGK C ; b pU= - ` Bs K. S F w4 M q] Z dH S 0 ) tLg
<?php
/**
* LiteSpeed Cache option Interface CLI.
*
* @package LiteSpeed\CLI
*/
namespace LiteSpeed\CLI;
defined( 'WPINC' ) || exit();
use LiteSpeed\Base;
use LiteSpeed\Admin_Settings;
use LiteSpeed\Utility;
use WP_CLI;
use WP_Filesystem;
/**
* LiteSpeed Cache option Interface
*/
class Option extends Base {
/**
* Set an individual LiteSpeed Cache option.
*
* ## OPTIONS
*
* <key>
* : The option key to update.
*
* <newvalue>
* : The new value to set the option to.
*
* ## EXAMPLES
*
* # Set to not cache the login page
* $ wp litespeed-option set cache-priv false
* $ wp litespeed-option set 'cdn-mapping[url][0]' https://cdn.EXAMPLE.com
* $ wp litespeed-option set media-lqip_exc $'line1\nline2'
*
* @param array $args Positional arguments (key, newvalue).
* @param array $assoc_args Associative arguments.
*/
public function set( $args, $assoc_args ) {
// Note: If the value is multiple dimensions like cdn-mapping, need to specially handle it both here and in `const.default.json`
// For CDN/Crawler multi dimension settings, if all children are empty in one line, will delete that line. To delete one line, just set all to empty.
// E.g. to delete cdn-mapping[0], need to run below:
// `set cdn-mapping[url][0] ''`
// `set cdn-mapping[inc_img][0] ''`
// `set cdn-mapping[inc_css][0] ''`
// `set cdn-mapping[inc_js][0] ''`
// `set cdn-mapping[filetype][0] ''`
$key = $args[0];
$val = $args[1];
// For CDN mapping, allow:
// `set 'cdn-mapping[url][0]' https://the1st_cdn_url`
// `set 'cdn-mapping[inc_img][0]' true`
// `set 'cdn-mapping[inc_img][0]' 1`
//
// For Crawler cookies:
// `set 'crawler-cookies[name][0]' my_currency`
// `set 'crawler-cookies[vals][0]' "USD\nTWD"`
//
// For multi lines setting:
// `set media-lqip_exc $'img1.jpg\nimg2.jpg'`
// Build raw data
$raw_data = array(
Admin_Settings::ENROLL => array( $key ),
);
// Contains child set
if ( false !== strpos( $key, '[' ) ) {
parse_str( $key . '=' . $val, $key2 );
$raw_data = array_merge( $raw_data, $key2 );
} else {
$raw_data[ $key ] = $val;
}
$this->cls( 'Admin_Settings' )->save( $raw_data );
WP_CLI::line( "$key:" );
$this->get( $args, $assoc_args );
}
/**
* Get all plugin options.
*
* ## OPTIONS
*
* [--format=<format>]
* : Output format (e.g., json).
*
* ## EXAMPLES
*
* # Get all options
* $ wp litespeed-option all
* $ wp litespeed-option all --json
* $ wp litespeed-option all --format=json
*
* @param array $args Positional arguments.
* @param array $assoc_args Associative arguments.
*/
public function all( $args, $assoc_args ) {
$options = $this->get_options();
if ( ! empty( $assoc_args['format'] ) ) {
WP_CLI::print_value( $options, $assoc_args );
return;
}
$option_out = array();
$buf = WP_CLI::colorize( '%CThe list of options:%n' );
WP_CLI::line( $buf );
foreach ( $options as $k => $v ) {
if ( self::O_CDN_MAPPING === $k || self::O_CRAWLER_COOKIES === $k ) {
foreach ( $v as $k2 => $v2 ) {
// $k2 is numeric
if ( is_array( $v2 ) ) {
foreach ( $v2 as $k3 => $v3 ) {
// $k3 is 'url/inc_img/name/vals'
if ( is_array( $v3 ) ) {
$option_out[] = array(
'key' => '',
'value' => '',
);
foreach ( $v3 as $k4 => $v4 ) {
$option_out[] = array(
'key' => 0 === $k4 ? "{$k}[$k3][$k2]" : '',
'value' => $v4,
);
}
$option_out[] = array(
'key' => '',
'value' => '',
);
} else {
$option_out[] = array(
'key' => "{$k}[$k3][$k2]",
'value' => $v3,
);
}
}
}
}
continue;
} elseif ( is_array( $v ) && $v ) {
$option_out[] = array(
'key' => '',
'value' => '',
);
foreach ( $v as $k2 => $v2 ) {
$option_out[] = array(
'key' => 0 === $k2 ? $k : '',
'value' => $v2,
);
}
$option_out[] = array(
'key' => '',
'value' => '',
);
continue;
}
if ( array_key_exists( $k, self::$_default_options ) && is_bool( self::$_default_options[ $k ] ) && ! $v ) {
$v = 0;
}
if ( '' === $v || array() === $v ) {
$v = "''";
}
$option_out[] = array(
'key' => $k,
'value' => $v,
);
}
WP_CLI\Utils\format_items( 'table', $option_out, array( 'key', 'value' ) );
}
/**
* Get a specific plugin option.
*
* ## OPTIONS
*
* <id>
* : The option ID to retrieve (e.g., cache-priv, cdn-mapping[url][0]).
*
* ## EXAMPLES
*
* # Get one option
* $ wp litespeed-option get cache-priv
* $ wp litespeed-option get 'cdn-mapping[url][0]'
*
* @param array $args Positional arguments (id).
* @param array $assoc_args Associative arguments.
*/
public function get( $args, $assoc_args ) {
$id = $args[0];
$child = false;
if ( false !== strpos( $id, '[' ) ) {
parse_str( $id, $id2 );
Utility::compatibility();
$id = array_key_first( $id2 );
$child = array_key_first( $id2[ $id ] ); // is `url`
if ( ! $child ) {
WP_CLI::error( 'Wrong child key' );
return;
}
$numeric = array_key_first( $id2[ $id ][ $child ] ); // `0`
if ( null === $numeric ) {
WP_CLI::error( 'Wrong 2nd level numeric key' );
return;
}
}
if ( ! isset( self::$_default_options[ $id ] ) ) {
WP_CLI::error( 'ID not exist [id] ' . $id );
return;
}
$v = $this->conf( $id );
$default_v = self::$_default_options[ $id ];
// For CDN_mapping and crawler_cookies
// Examples of option name:
// cdn-mapping[url][0]
// crawler-cookies[name][1]
if ( self::O_CDN_MAPPING === $id ) {
if ( ! in_array( $child, array( self::CDN_MAPPING_URL, self::CDN_MAPPING_INC_IMG, self::CDN_MAPPING_INC_CSS, self::CDN_MAPPING_INC_JS, self::CDN_MAPPING_FILETYPE ), true ) ) {
WP_CLI::error( 'Wrong child key' );
return;
}
}
if ( self::O_CRAWLER_COOKIES === $id ) {
if ( ! in_array( $child, array( self::CRWL_COOKIE_NAME, self::CRWL_COOKIE_VALS ), true ) ) {
WP_CLI::error( 'Wrong child key' );
return;
}
}
if ( self::O_CDN_MAPPING === $id || self::O_CRAWLER_COOKIES === $id ) {
if ( ! empty( $v[ $numeric ][ $child ] ) ) {
$v = $v[ $numeric ][ $child ];
} elseif ( self::O_CDN_MAPPING === $id ) {
if ( in_array( $child, array( self::CDN_MAPPING_INC_IMG, self::CDN_MAPPING_INC_CSS, self::CDN_MAPPING_INC_JS ), true ) ) {
$v = 0;
} else {
$v = "''";
}
} else {
$v = "''";
}
}
if ( is_array( $v ) ) {
$v = implode( PHP_EOL, $v );
}
if ( ! $v && self::O_CDN_MAPPING !== $id && self::O_CRAWLER_COOKIES !== $id ) {
// empty array for CDN/crawler has been handled
if ( is_bool( $default_v ) ) {
$v = 0;
} elseif ( ! is_array( $default_v ) ) {
$v = "''";
}
}
WP_CLI::line( $v );
}
/**
* Export plugin options to a file.
*
* ## OPTIONS
*
* [--filename=<path>]
* : The default path used is CURRENTDIR/lscache_wp_options_DATE-TIME.txt.
* To select a different file, use this option.
*
* ## EXAMPLES
*
* # Export options to a file.
* $ wp litespeed-option export
*
* @param array $args Positional arguments.
* @param array $assoc_args Associative arguments.
*/
public function export( $args, $assoc_args ) {
if ( isset( $assoc_args['filename'] ) ) {
$file = $assoc_args['filename'];
} else {
$file = getcwd() . '/litespeed_options_' . gmdate( 'd_m_Y-His' ) . '.data';
}
global $wp_filesystem;
if ( ! $wp_filesystem ) {
require_once ABSPATH . '/wp-admin/includes/file.php';
WP_Filesystem();
}
if ( ! $wp_filesystem->is_writable( dirname( $file ) ) ) {
WP_CLI::error( 'Directory not writable.' );
return;
}
$data = $this->cls( 'Import' )->export( true );
if ( false === $wp_filesystem->put_contents( $file, $data ) ) {
WP_CLI::error( 'Failed to create file.' );
return;
}
WP_CLI::success( 'Created file ' . $file );
}
/**
* Import plugin options from a file.
*
* The file must be formatted as such:
* option_key=option_value
* One per line.
* A semicolon at the beginning of the line indicates a comment and will be skipped.
*
* ## OPTIONS
*
* <file>
* : The file to import options from.
*
* ## EXAMPLES
*
* # Import options from CURRENTDIR/options.txt
* $ wp litespeed-option import options.txt
*
* @param array $args Positional arguments (file).
* @param array $assoc_args Associative arguments.
*/
public function import( $args, $assoc_args ) {
$file = $args[0];
global $wp_filesystem;
if ( ! $wp_filesystem ) {
require_once ABSPATH . '/wp-admin/includes/file.php';
WP_Filesystem();
}
if ( ! $wp_filesystem->exists( $file ) || ! $wp_filesystem->is_readable( $file ) ) {
WP_CLI::error( 'File does not exist or is not readable.' );
return;
}
$res = $this->cls( 'Import' )->import( $file );
if ( ! $res ) {
WP_CLI::error( 'Failed to parse serialized data from file.' );
return;
}
WP_CLI::success( 'Options imported. [File] ' . $file );
}
/**
* Import plugin options from a remote file.
*
* The file must be formatted as such:
* option_key=option_value
* One per line.
* A semicolon at the beginning of the line indicates a comment and will be skipped.
*
* ## OPTIONS
*
* <url>
* : The URL to import options from.
*
* ## EXAMPLES
*
* # Import options from https://domain.com/options.txt
* $ wp litespeed-option import_remote https://domain.com/options.txt
*
* @param array $args Positional arguments (url).
*/
public function import_remote( $args ) {
$file = $args[0];
$tmp_file = download_url( $file );
if ( is_wp_error( $tmp_file ) ) {
WP_CLI::error( 'Failed to download file.' );
return;
}
$res = $this->cls( 'Import' )->import( $tmp_file );
if ( ! $res ) {
WP_CLI::error( 'Failed to parse serialized data from file.' );
return;
}
WP_CLI::success( 'Options imported. [File] ' . $file );
}
/**
* Reset all options to default.
*
* ## EXAMPLES
*
* # Reset all options
* $ wp litespeed-option reset
*/
public function reset() {
$this->cls( 'Import' )->reset();
}
}