Edit File by line
/home/zeestwma/richards.../wp-conte.../plugins/litespee.../src
File: media.cls.php
<?php
[0] Fix | Delete
[1] Fix | Delete
/**
[2] Fix | Delete
* The class to operate media data.
[3] Fix | Delete
*
[4] Fix | Delete
* @since 1.4
[5] Fix | Delete
* @since 1.5 Moved into /inc
[6] Fix | Delete
* @package Core
[7] Fix | Delete
* @subpackage Core/inc
[8] Fix | Delete
* @author LiteSpeed Technologies <info@litespeedtech.com>
[9] Fix | Delete
*/
[10] Fix | Delete
[11] Fix | Delete
namespace LiteSpeed;
[12] Fix | Delete
[13] Fix | Delete
defined('WPINC') || exit();
[14] Fix | Delete
[15] Fix | Delete
class Media extends Root
[16] Fix | Delete
{
[17] Fix | Delete
const LOG_TAG = '📺';
[18] Fix | Delete
[19] Fix | Delete
const LIB_FILE_IMG_LAZYLOAD = 'assets/js/lazyload.min.js';
[20] Fix | Delete
[21] Fix | Delete
private $content;
[22] Fix | Delete
private $_wp_upload_dir;
[23] Fix | Delete
private $_vpi_preload_list = array();
[24] Fix | Delete
[25] Fix | Delete
/**
[26] Fix | Delete
* Init
[27] Fix | Delete
*
[28] Fix | Delete
* @since 1.4
[29] Fix | Delete
*/
[30] Fix | Delete
public function __construct()
[31] Fix | Delete
{
[32] Fix | Delete
Debug2::debug2('[Media] init');
[33] Fix | Delete
[34] Fix | Delete
$this->_wp_upload_dir = wp_upload_dir();
[35] Fix | Delete
}
[36] Fix | Delete
[37] Fix | Delete
/**
[38] Fix | Delete
* Init optm features
[39] Fix | Delete
*
[40] Fix | Delete
* @since 3.0
[41] Fix | Delete
* @access public
[42] Fix | Delete
*/
[43] Fix | Delete
public function init()
[44] Fix | Delete
{
[45] Fix | Delete
if (is_admin()) {
[46] Fix | Delete
return;
[47] Fix | Delete
}
[48] Fix | Delete
[49] Fix | Delete
// Due to ajax call doesn't send correct accept header, have to limit webp to HTML only
[50] Fix | Delete
if (defined('LITESPEED_GUEST_OPTM') || $this->conf(Base::O_IMG_OPTM_WEBP)) {
[51] Fix | Delete
if ($this->webp_support()) {
[52] Fix | Delete
// Hook to srcset
[53] Fix | Delete
if (function_exists('wp_calculate_image_srcset')) {
[54] Fix | Delete
add_filter('wp_calculate_image_srcset', array($this, 'webp_srcset'), 988);
[55] Fix | Delete
}
[56] Fix | Delete
// Hook to mime icon
[57] Fix | Delete
// add_filter( 'wp_get_attachment_image_src', array( $this, 'webp_attach_img_src' ), 988 );// todo: need to check why not
[58] Fix | Delete
// add_filter( 'wp_get_attachment_url', array( $this, 'webp_url' ), 988 ); // disabled to avoid wp-admin display
[59] Fix | Delete
}
[60] Fix | Delete
}
[61] Fix | Delete
[62] Fix | Delete
if ($this->conf(Base::O_MEDIA_LAZY) && !$this->cls('Metabox')->setting('litespeed_no_image_lazy')) {
[63] Fix | Delete
self::debug('Suppress default WP lazyload');
[64] Fix | Delete
add_filter('wp_lazy_loading_enabled', '__return_false');
[65] Fix | Delete
}
[66] Fix | Delete
[67] Fix | Delete
/**
[68] Fix | Delete
* Replace gravatar
[69] Fix | Delete
* @since 3.0
[70] Fix | Delete
*/
[71] Fix | Delete
$this->cls('Avatar');
[72] Fix | Delete
[73] Fix | Delete
add_filter('litespeed_buffer_finalize', array($this, 'finalize'), 4);
[74] Fix | Delete
[75] Fix | Delete
add_filter('litespeed_optm_html_head', array($this, 'finalize_head'));
[76] Fix | Delete
}
[77] Fix | Delete
[78] Fix | Delete
/**
[79] Fix | Delete
* Add featured image to head
[80] Fix | Delete
*/
[81] Fix | Delete
public function finalize_head($content)
[82] Fix | Delete
{
[83] Fix | Delete
global $wp_query;
[84] Fix | Delete
[85] Fix | Delete
// <link rel="preload" as="image" href="xx">
[86] Fix | Delete
if ($this->_vpi_preload_list) {
[87] Fix | Delete
foreach ($this->_vpi_preload_list as $v) {
[88] Fix | Delete
$content .= '<link rel="preload" as="image" href="' . $v . '">';
[89] Fix | Delete
}
[90] Fix | Delete
}
[91] Fix | Delete
// $featured_image_url = get_the_post_thumbnail_url();
[92] Fix | Delete
// if ($featured_image_url) {
[93] Fix | Delete
// self::debug('Append featured image to head: ' . $featured_image_url);
[94] Fix | Delete
// if ((defined('LITESPEED_GUEST_OPTM') || $this->conf(Base::O_IMG_OPTM_WEBP)) && $this->webp_support()) {
[95] Fix | Delete
// $featured_image_url = $this->replace_webp($featured_image_url) ?: $featured_image_url;
[96] Fix | Delete
// }
[97] Fix | Delete
// }
[98] Fix | Delete
// }
[99] Fix | Delete
[100] Fix | Delete
return $content;
[101] Fix | Delete
}
[102] Fix | Delete
[103] Fix | Delete
/**
[104] Fix | Delete
* Adjust WP default JPG quality
[105] Fix | Delete
*
[106] Fix | Delete
* @since 3.0
[107] Fix | Delete
* @access public
[108] Fix | Delete
*/
[109] Fix | Delete
public function adjust_jpg_quality($quality)
[110] Fix | Delete
{
[111] Fix | Delete
$v = $this->conf(Base::O_IMG_OPTM_JPG_QUALITY);
[112] Fix | Delete
[113] Fix | Delete
if ($v) {
[114] Fix | Delete
return $v;
[115] Fix | Delete
}
[116] Fix | Delete
[117] Fix | Delete
return $quality;
[118] Fix | Delete
}
[119] Fix | Delete
[120] Fix | Delete
/**
[121] Fix | Delete
* Register admin menu
[122] Fix | Delete
*
[123] Fix | Delete
* @since 1.6.3
[124] Fix | Delete
* @access public
[125] Fix | Delete
*/
[126] Fix | Delete
public function after_admin_init()
[127] Fix | Delete
{
[128] Fix | Delete
/**
[129] Fix | Delete
* JPG quality control
[130] Fix | Delete
* @since 3.0
[131] Fix | Delete
*/
[132] Fix | Delete
add_filter('jpeg_quality', array($this, 'adjust_jpg_quality'));
[133] Fix | Delete
[134] Fix | Delete
add_filter('manage_media_columns', array($this, 'media_row_title'));
[135] Fix | Delete
add_filter('manage_media_custom_column', array($this, 'media_row_actions'), 10, 2);
[136] Fix | Delete
[137] Fix | Delete
add_action('litespeed_media_row', array($this, 'media_row_con'));
[138] Fix | Delete
[139] Fix | Delete
// Hook to attachment delete action
[140] Fix | Delete
add_action('delete_attachment', __CLASS__ . '::delete_attachment');
[141] Fix | Delete
}
[142] Fix | Delete
[143] Fix | Delete
/**
[144] Fix | Delete
* Media delete action hook
[145] Fix | Delete
*
[146] Fix | Delete
* @since 2.4.3
[147] Fix | Delete
* @access public
[148] Fix | Delete
*/
[149] Fix | Delete
public static function delete_attachment($post_id)
[150] Fix | Delete
{
[151] Fix | Delete
// if (!Data::cls()->tb_exist('img_optm')) {
[152] Fix | Delete
// return;
[153] Fix | Delete
// }
[154] Fix | Delete
[155] Fix | Delete
self::debug('delete_attachment [pid] ' . $post_id);
[156] Fix | Delete
Img_Optm::cls()->reset_row($post_id);
[157] Fix | Delete
}
[158] Fix | Delete
[159] Fix | Delete
/**
[160] Fix | Delete
* Return media file info if exists
[161] Fix | Delete
*
[162] Fix | Delete
* This is for remote attachment plugins
[163] Fix | Delete
*
[164] Fix | Delete
* @since 2.9.8
[165] Fix | Delete
* @access public
[166] Fix | Delete
*/
[167] Fix | Delete
public function info($short_file_path, $post_id)
[168] Fix | Delete
{
[169] Fix | Delete
$short_file_path = wp_normalize_path($short_file_path);
[170] Fix | Delete
$basedir = $this->_wp_upload_dir['basedir'] . '/';
[171] Fix | Delete
if (strpos($short_file_path, $basedir) === 0) {
[172] Fix | Delete
$short_file_path = substr($short_file_path, strlen($basedir));
[173] Fix | Delete
}
[174] Fix | Delete
[175] Fix | Delete
$real_file = $basedir . $short_file_path;
[176] Fix | Delete
[177] Fix | Delete
if (file_exists($real_file)) {
[178] Fix | Delete
return array(
[179] Fix | Delete
'url' => $this->_wp_upload_dir['baseurl'] . '/' . $short_file_path,
[180] Fix | Delete
'md5' => md5_file($real_file),
[181] Fix | Delete
'size' => filesize($real_file),
[182] Fix | Delete
);
[183] Fix | Delete
}
[184] Fix | Delete
[185] Fix | Delete
/**
[186] Fix | Delete
* WP Stateless compatibility #143 https://github.com/litespeedtech/lscache_wp/issues/143
[187] Fix | Delete
* @since 2.9.8
[188] Fix | Delete
* @return array( 'url', 'md5', 'size' )
[189] Fix | Delete
*/
[190] Fix | Delete
$info = apply_filters('litespeed_media_info', array(), $short_file_path, $post_id);
[191] Fix | Delete
if (!empty($info['url']) && !empty($info['md5']) && !empty($info['size'])) {
[192] Fix | Delete
return $info;
[193] Fix | Delete
}
[194] Fix | Delete
[195] Fix | Delete
return false;
[196] Fix | Delete
}
[197] Fix | Delete
[198] Fix | Delete
/**
[199] Fix | Delete
* Delete media file
[200] Fix | Delete
*
[201] Fix | Delete
* @since 2.9.8
[202] Fix | Delete
* @access public
[203] Fix | Delete
*/
[204] Fix | Delete
public function del($short_file_path, $post_id)
[205] Fix | Delete
{
[206] Fix | Delete
$real_file = $this->_wp_upload_dir['basedir'] . '/' . $short_file_path;
[207] Fix | Delete
[208] Fix | Delete
if (file_exists($real_file)) {
[209] Fix | Delete
unlink($real_file);
[210] Fix | Delete
self::debug('deleted ' . $real_file);
[211] Fix | Delete
}
[212] Fix | Delete
[213] Fix | Delete
do_action('litespeed_media_del', $short_file_path, $post_id);
[214] Fix | Delete
}
[215] Fix | Delete
[216] Fix | Delete
/**
[217] Fix | Delete
* Rename media file
[218] Fix | Delete
*
[219] Fix | Delete
* @since 2.9.8
[220] Fix | Delete
* @access public
[221] Fix | Delete
*/
[222] Fix | Delete
public function rename($short_file_path, $short_file_path_new, $post_id)
[223] Fix | Delete
{
[224] Fix | Delete
// self::debug('renaming ' . $short_file_path . ' -> ' . $short_file_path_new);
[225] Fix | Delete
$real_file = $this->_wp_upload_dir['basedir'] . '/' . $short_file_path;
[226] Fix | Delete
$real_file_new = $this->_wp_upload_dir['basedir'] . '/' . $short_file_path_new;
[227] Fix | Delete
[228] Fix | Delete
if (file_exists($real_file)) {
[229] Fix | Delete
rename($real_file, $real_file_new);
[230] Fix | Delete
self::debug('renamed ' . $real_file . ' to ' . $real_file_new);
[231] Fix | Delete
}
[232] Fix | Delete
[233] Fix | Delete
do_action('litespeed_media_rename', $short_file_path, $short_file_path_new, $post_id);
[234] Fix | Delete
}
[235] Fix | Delete
[236] Fix | Delete
/**
[237] Fix | Delete
* Media Admin Menu -> Image Optimization Column Title
[238] Fix | Delete
*
[239] Fix | Delete
* @since 1.6.3
[240] Fix | Delete
* @access public
[241] Fix | Delete
*/
[242] Fix | Delete
public function media_row_title($posts_columns)
[243] Fix | Delete
{
[244] Fix | Delete
$posts_columns['imgoptm'] = __('LiteSpeed Optimization', 'litespeed-cache');
[245] Fix | Delete
[246] Fix | Delete
return $posts_columns;
[247] Fix | Delete
}
[248] Fix | Delete
[249] Fix | Delete
/**
[250] Fix | Delete
* Media Admin Menu -> Image Optimization Column
[251] Fix | Delete
*
[252] Fix | Delete
* @since 1.6.2
[253] Fix | Delete
* @access public
[254] Fix | Delete
*/
[255] Fix | Delete
public function media_row_actions($column_name, $post_id)
[256] Fix | Delete
{
[257] Fix | Delete
if ($column_name !== 'imgoptm') {
[258] Fix | Delete
return;
[259] Fix | Delete
}
[260] Fix | Delete
[261] Fix | Delete
do_action('litespeed_media_row', $post_id);
[262] Fix | Delete
}
[263] Fix | Delete
[264] Fix | Delete
/**
[265] Fix | Delete
* Display image optm info
[266] Fix | Delete
*
[267] Fix | Delete
* @since 3.0
[268] Fix | Delete
*/
[269] Fix | Delete
public function media_row_con($post_id)
[270] Fix | Delete
{
[271] Fix | Delete
$att_info = wp_get_attachment_metadata($post_id);
[272] Fix | Delete
if (empty($att_info['file'])) {
[273] Fix | Delete
return;
[274] Fix | Delete
}
[275] Fix | Delete
[276] Fix | Delete
$short_path = $att_info['file'];
[277] Fix | Delete
[278] Fix | Delete
$size_meta = get_post_meta($post_id, Img_Optm::DB_SIZE, true);
[279] Fix | Delete
[280] Fix | Delete
echo '<p>';
[281] Fix | Delete
// Original image info
[282] Fix | Delete
if ($size_meta && !empty($size_meta['ori_saved'])) {
[283] Fix | Delete
$percent = ceil(($size_meta['ori_saved'] * 100) / $size_meta['ori_total']);
[284] Fix | Delete
[285] Fix | Delete
$extension = pathinfo($short_path, PATHINFO_EXTENSION);
[286] Fix | Delete
$bk_file = substr($short_path, 0, -strlen($extension)) . 'bk.' . $extension;
[287] Fix | Delete
$bk_optm_file = substr($short_path, 0, -strlen($extension)) . 'bk.optm.' . $extension;
[288] Fix | Delete
[289] Fix | Delete
$link = Utility::build_url(Router::ACTION_IMG_OPTM, 'orig' . $post_id);
[290] Fix | Delete
$desc = false;
[291] Fix | Delete
[292] Fix | Delete
$cls = '';
[293] Fix | Delete
[294] Fix | Delete
if ($this->info($bk_file, $post_id)) {
[295] Fix | Delete
$curr_status = __('(optm)', 'litespeed-cache');
[296] Fix | Delete
$desc = __('Currently using optimized version of file.', 'litespeed-cache') . '&#10;' . __('Click to switch to original (unoptimized) version.', 'litespeed-cache');
[297] Fix | Delete
} elseif ($this->info($bk_optm_file, $post_id)) {
[298] Fix | Delete
$cls .= ' litespeed-warning';
[299] Fix | Delete
$curr_status = __('(non-optm)', 'litespeed-cache');
[300] Fix | Delete
$desc = __('Currently using original (unoptimized) version of file.', 'litespeed-cache') . '&#10;' . __('Click to switch to optimized version.', 'litespeed-cache');
[301] Fix | Delete
}
[302] Fix | Delete
[303] Fix | Delete
echo GUI::pie_tiny(
[304] Fix | Delete
$percent,
[305] Fix | Delete
24,
[306] Fix | Delete
sprintf(__('Original file reduced by %1$s (%2$s)', 'litespeed-cache'), $percent . '%', Utility::real_size($size_meta['ori_saved'])),
[307] Fix | Delete
'left'
[308] Fix | Delete
);
[309] Fix | Delete
[310] Fix | Delete
echo sprintf(__('Orig saved %s', 'litespeed-cache'), $percent . '%');
[311] Fix | Delete
[312] Fix | Delete
if ($desc) {
[313] Fix | Delete
echo sprintf(
[314] Fix | Delete
' <a href="%1$s" class="litespeed-media-href %2$s" data-balloon-pos="left" data-balloon-break aria-label="%3$s">%4$s</a>',
[315] Fix | Delete
$link,
[316] Fix | Delete
$cls,
[317] Fix | Delete
$desc,
[318] Fix | Delete
$curr_status
[319] Fix | Delete
);
[320] Fix | Delete
} else {
[321] Fix | Delete
echo sprintf(
[322] Fix | Delete
' <span class="litespeed-desc" data-balloon-pos="left" data-balloon-break aria-label="%1$s">%2$s</span>',
[323] Fix | Delete
__('Using optimized version of file. ', 'litespeed-cache') . '&#10;' . __('No backup of original file exists.', 'litespeed-cache'),
[324] Fix | Delete
__('(optm)', 'litespeed-cache')
[325] Fix | Delete
);
[326] Fix | Delete
}
[327] Fix | Delete
} elseif ($size_meta && $size_meta['ori_saved'] === 0) {
[328] Fix | Delete
echo GUI::pie_tiny(0, 24, __('Congratulation! Your file was already optimized', 'litespeed-cache'), 'left');
[329] Fix | Delete
echo sprintf(__('Orig %s', 'litespeed-cache'), '<span class="litespeed-desc">' . __('(no savings)', 'litespeed-cache') . '</span>');
[330] Fix | Delete
} else {
[331] Fix | Delete
echo __('Orig', 'litespeed-cache') . '<span class="litespeed-left10">—</span>';
[332] Fix | Delete
}
[333] Fix | Delete
echo '</p>';
[334] Fix | Delete
[335] Fix | Delete
echo '<p>';
[336] Fix | Delete
// WebP info
[337] Fix | Delete
if ($size_meta && !empty($size_meta['webp_saved'])) {
[338] Fix | Delete
$percent = ceil(($size_meta['webp_saved'] * 100) / $size_meta['webp_total']);
[339] Fix | Delete
[340] Fix | Delete
$link = Utility::build_url(Router::ACTION_IMG_OPTM, 'webp' . $post_id);
[341] Fix | Delete
$desc = false;
[342] Fix | Delete
[343] Fix | Delete
$cls = '';
[344] Fix | Delete
[345] Fix | Delete
if ($this->info($short_path . '.webp', $post_id)) {
[346] Fix | Delete
$curr_status = __('(optm)', 'litespeed-cache');
[347] Fix | Delete
$desc =
[348] Fix | Delete
__('Currently using optimized version of WebP file.', 'litespeed-cache') .
[349] Fix | Delete
'&#10;' .
[350] Fix | Delete
__('Click to switch to original (unoptimized) version.', 'litespeed-cache');
[351] Fix | Delete
} elseif ($this->info($short_path . '.optm.webp', $post_id)) {
[352] Fix | Delete
$cls .= ' litespeed-warning';
[353] Fix | Delete
$curr_status = __('(non-optm)', 'litespeed-cache');
[354] Fix | Delete
$desc =
[355] Fix | Delete
__('Currently using original (unoptimized) version of WebP file.', 'litespeed-cache') .
[356] Fix | Delete
'&#10;' .
[357] Fix | Delete
__('Click to switch to optimized version.', 'litespeed-cache');
[358] Fix | Delete
}
[359] Fix | Delete
[360] Fix | Delete
echo GUI::pie_tiny(
[361] Fix | Delete
$percent,
[362] Fix | Delete
24,
[363] Fix | Delete
sprintf(__('WebP file reduced by %1$s (%2$s)', 'litespeed-cache'), $percent . '%', Utility::real_size($size_meta['webp_saved'])),
[364] Fix | Delete
'left'
[365] Fix | Delete
);
[366] Fix | Delete
echo sprintf(__('WebP saved %s', 'litespeed-cache'), $percent . '%');
[367] Fix | Delete
[368] Fix | Delete
if ($desc) {
[369] Fix | Delete
echo sprintf(
[370] Fix | Delete
' <a href="%1$s" class="litespeed-media-href %2$s" data-balloon-pos="left" data-balloon-break aria-label="%3$s">%4$s</a>',
[371] Fix | Delete
$link,
[372] Fix | Delete
$cls,
[373] Fix | Delete
$desc,
[374] Fix | Delete
$curr_status
[375] Fix | Delete
);
[376] Fix | Delete
} else {
[377] Fix | Delete
echo sprintf(
[378] Fix | Delete
' <span class="litespeed-desc" data-balloon-pos="left" data-balloon-break aria-label="%1$s">%2$s</span>',
[379] Fix | Delete
__('Using optimized version of file. ', 'litespeed-cache') . '&#10;' . __('No backup of unoptimized WebP file exists.', 'litespeed-cache'),
[380] Fix | Delete
__('(optm)', 'litespeed-cache')
[381] Fix | Delete
);
[382] Fix | Delete
}
[383] Fix | Delete
} else {
[384] Fix | Delete
echo __('WebP', 'litespeed-cache') . '<span class="litespeed-left10">—</span>';
[385] Fix | Delete
}
[386] Fix | Delete
[387] Fix | Delete
echo '</p>';
[388] Fix | Delete
[389] Fix | Delete
// Delete row btn
[390] Fix | Delete
if ($size_meta) {
[391] Fix | Delete
echo sprintf(
[392] Fix | Delete
'<div class="row-actions"><span class="delete"><a href="%1$s" class="">%2$s</a></span></div>',
[393] Fix | Delete
Utility::build_url(Router::ACTION_IMG_OPTM, Img_Optm::TYPE_RESET_ROW, false, null, array('id' => $post_id)),
[394] Fix | Delete
__('Restore from backup', 'litespeed-cache')
[395] Fix | Delete
);
[396] Fix | Delete
echo '</div>';
[397] Fix | Delete
}
[398] Fix | Delete
}
[399] Fix | Delete
[400] Fix | Delete
/**
[401] Fix | Delete
* Get wp size info
[402] Fix | Delete
*
[403] Fix | Delete
* NOTE: this is not used because it has to be after admin_init
[404] Fix | Delete
*
[405] Fix | Delete
* @since 1.6.2
[406] Fix | Delete
* @return array $sizes Data for all currently-registered image sizes.
[407] Fix | Delete
*/
[408] Fix | Delete
public function get_image_sizes()
[409] Fix | Delete
{
[410] Fix | Delete
global $_wp_additional_image_sizes;
[411] Fix | Delete
$sizes = array();
[412] Fix | Delete
[413] Fix | Delete
foreach (get_intermediate_image_sizes() as $_size) {
[414] Fix | Delete
if (in_array($_size, array('thumbnail', 'medium', 'medium_large', 'large'))) {
[415] Fix | Delete
$sizes[$_size]['width'] = get_option($_size . '_size_w');
[416] Fix | Delete
$sizes[$_size]['height'] = get_option($_size . '_size_h');
[417] Fix | Delete
$sizes[$_size]['crop'] = (bool) get_option($_size . '_crop');
[418] Fix | Delete
} elseif (isset($_wp_additional_image_sizes[$_size])) {
[419] Fix | Delete
$sizes[$_size] = array(
[420] Fix | Delete
'width' => $_wp_additional_image_sizes[$_size]['width'],
[421] Fix | Delete
'height' => $_wp_additional_image_sizes[$_size]['height'],
[422] Fix | Delete
'crop' => $_wp_additional_image_sizes[$_size]['crop'],
[423] Fix | Delete
);
[424] Fix | Delete
}
[425] Fix | Delete
}
[426] Fix | Delete
[427] Fix | Delete
return $sizes;
[428] Fix | Delete
}
[429] Fix | Delete
[430] Fix | Delete
/**
[431] Fix | Delete
* Exclude role from optimization filter
[432] Fix | Delete
*
[433] Fix | Delete
* @since 1.6.2
[434] Fix | Delete
* @access public
[435] Fix | Delete
*/
[436] Fix | Delete
public function webp_support()
[437] Fix | Delete
{
[438] Fix | Delete
if (!empty($_SERVER['HTTP_ACCEPT']) && strpos($_SERVER['HTTP_ACCEPT'], 'image/webp') !== false) {
[439] Fix | Delete
return true;
[440] Fix | Delete
}
[441] Fix | Delete
[442] Fix | Delete
if (!empty($_SERVER['HTTP_USER_AGENT'])) {
[443] Fix | Delete
$user_agents = array('chrome-lighthouse', 'googlebot', 'page speed');
[444] Fix | Delete
foreach ($user_agents as $user_agent) {
[445] Fix | Delete
if (stripos($_SERVER['HTTP_USER_AGENT'], $user_agent) !== false) {
[446] Fix | Delete
return true;
[447] Fix | Delete
}
[448] Fix | Delete
}
[449] Fix | Delete
[450] Fix | Delete
if (preg_match('/iPhone OS (\d+)_/i', $_SERVER['HTTP_USER_AGENT'], $matches)) {
[451] Fix | Delete
$lscwp_ios_version = $matches[1];
[452] Fix | Delete
if ($lscwp_ios_version >= 14) {
[453] Fix | Delete
return true;
[454] Fix | Delete
}
[455] Fix | Delete
}
[456] Fix | Delete
}
[457] Fix | Delete
[458] Fix | Delete
return false;
[459] Fix | Delete
}
[460] Fix | Delete
[461] Fix | Delete
/**
[462] Fix | Delete
* Run lazy load process
[463] Fix | Delete
* NOTE: As this is after cache finalized, can NOT set any cache control anymore
[464] Fix | Delete
*
[465] Fix | Delete
* Only do for main page. Do NOT do for esi or dynamic content.
[466] Fix | Delete
*
[467] Fix | Delete
* @since 1.4
[468] Fix | Delete
* @access public
[469] Fix | Delete
* @return string The buffer
[470] Fix | Delete
*/
[471] Fix | Delete
public function finalize($content)
[472] Fix | Delete
{
[473] Fix | Delete
if (defined('LITESPEED_NO_LAZY')) {
[474] Fix | Delete
Debug2::debug2('[Media] bypass: NO_LAZY const');
[475] Fix | Delete
return $content;
[476] Fix | Delete
}
[477] Fix | Delete
[478] Fix | Delete
if (!defined('LITESPEED_IS_HTML')) {
[479] Fix | Delete
Debug2::debug2('[Media] bypass: Not frontend HTML type');
[480] Fix | Delete
return $content;
[481] Fix | Delete
}
[482] Fix | Delete
[483] Fix | Delete
if (!Control::is_cacheable()) {
[484] Fix | Delete
self::debug('bypass: Not cacheable');
[485] Fix | Delete
return $content;
[486] Fix | Delete
}
[487] Fix | Delete
[488] Fix | Delete
self::debug('finalize');
[489] Fix | Delete
[490] Fix | Delete
$this->content = $content;
[491] Fix | Delete
$this->_finalize();
[492] Fix | Delete
return $this->content;
[493] Fix | Delete
}
[494] Fix | Delete
[495] Fix | Delete
/**
[496] Fix | Delete
* Run lazyload replacement for images in buffer
[497] Fix | Delete
*
[498] Fix | Delete
* @since 1.4
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function