Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../public_h.../wp-conte.../plugins/themify-.../themify/cache
File: class-themify-cache.php
<?php
[0] Fix | Delete
[1] Fix | Delete
defined('ABSPATH') || exit;
[2] Fix | Delete
if (!class_exists('TFCache',false)) {
[3] Fix | Delete
if (!class_exists('Themify_Filesystem',false) && defined('TF_CACHE_FW')) {
[4] Fix | Delete
require_once dirname(TF_CACHE_FW) . '/class-themify-filesystem.php';
[5] Fix | Delete
}
[6] Fix | Delete
[7] Fix | Delete
/**
[8] Fix | Delete
* Class to work with post cache
[9] Fix | Delete
*
[10] Fix | Delete
* @package default
[11] Fix | Delete
*/
[12] Fix | Delete
class TFCache {
[13] Fix | Delete
[14] Fix | Delete
const SEP = DIRECTORY_SEPARATOR;
[15] Fix | Delete
[16] Fix | Delete
private static $cache_dir = null;
[17] Fix | Delete
public static $stopCache = false;
[18] Fix | Delete
private static $error = false;
[19] Fix | Delete
[20] Fix | Delete
/**
[21] Fix | Delete
* Start Caching
[22] Fix | Delete
*
[23] Fix | Delete
* @param string $tag
[24] Fix | Delete
* @param integer $post_id
[25] Fix | Delete
* @param array $args
[26] Fix | Delete
* @param integer $time
[27] Fix | Delete
*
[28] Fix | Delete
* return boolean
[29] Fix | Delete
*/
[30] Fix | Delete
public static function start_cache($tag, $post_id = false, array $args = array(), $time = false) {//backward compatibility for addons
[31] Fix | Delete
return true;
[32] Fix | Delete
}
[33] Fix | Delete
[34] Fix | Delete
public static function end_cache() {//backward compatibility for addons
[35] Fix | Delete
}
[36] Fix | Delete
[37] Fix | Delete
/**
[38] Fix | Delete
* remove cache after some updates
[39] Fix | Delete
*/
[40] Fix | Delete
public static function remove_cache($item_id = 'blog', $type = false, $blog_id = false) {
[41] Fix | Delete
static $queue = array();
[42] Fix | Delete
if (isset($queue['all'])) {
[43] Fix | Delete
return true;
[44] Fix | Delete
}
[45] Fix | Delete
if ($item_id === 'all') {
[46] Fix | Delete
$queue['all'] = true;
[47] Fix | Delete
$dir = self::get_cache_main_dir();
[48] Fix | Delete
if (!Themify_Filesystem::is_dir($dir)) {
[49] Fix | Delete
return true;
[50] Fix | Delete
}
[51] Fix | Delete
return Themify_Filesystem::delete($dir);
[52] Fix | Delete
}
[53] Fix | Delete
$cache_dir = self::get_cache_blog_dir($blog_id);
[54] Fix | Delete
if (!isset($queue['blog']) && Themify_Filesystem::is_dir($cache_dir)) {
[55] Fix | Delete
if ($item_id === 'blog') {
[56] Fix | Delete
$queue['blog'] = true;
[57] Fix | Delete
return Themify_Filesystem::delete($cache_dir);
[58] Fix | Delete
} else {
[59] Fix | Delete
if ($type === false) {
[60] Fix | Delete
$the_post = wp_is_post_revision($item_id);
[61] Fix | Delete
if ($the_post) {
[62] Fix | Delete
$item_id = $the_post;
[63] Fix | Delete
}
[64] Fix | Delete
$post = get_post($item_id);
[65] Fix | Delete
if (empty($post)) {
[66] Fix | Delete
return true;
[67] Fix | Delete
}
[68] Fix | Delete
$type = $post->post_type;
[69] Fix | Delete
$post = null;
[70] Fix | Delete
}
[71] Fix | Delete
if (empty($type)) {
[72] Fix | Delete
return self::remove_cache();
[73] Fix | Delete
}
[74] Fix | Delete
$k = $type . $item_id;
[75] Fix | Delete
if (!isset($queue[$k])) {
[76] Fix | Delete
$queue[$k] = true;
[77] Fix | Delete
$find = array(' post-' . $item_id);
[78] Fix | Delete
$item_id = (int) $item_id;
[79] Fix | Delete
$find[] = get_post_type($item_id) === 'page' ? ' page-id-' . $item_id : ' postid-' . $item_id; //if there is any html associated with updated post
[80] Fix | Delete
if ($type === 'comment' || $type === 'term' || $type === 'category') {
[81] Fix | Delete
$find[] = $type . '-' . $item_id;
[82] Fix | Delete
if ($type !== 'comment') {
[83] Fix | Delete
$find[] = $type === 'category' ? get_category_link($item_id) : get_term_link($item_id);
[84] Fix | Delete
$temp = get_term($item_id);
[85] Fix | Delete
$find[] = 'term-' . $temp->slug;
[86] Fix | Delete
$temp = null;
[87] Fix | Delete
}
[88] Fix | Delete
}
[89] Fix | Delete
@set_time_limit(0);
[90] Fix | Delete
$type = $item_id = null;
[91] Fix | Delete
if (!self::clear_recursive($cache_dir, $find)) {
[92] Fix | Delete
return self::remove_cache();
[93] Fix | Delete
}
[94] Fix | Delete
}
[95] Fix | Delete
}
[96] Fix | Delete
}
[97] Fix | Delete
return true;
[98] Fix | Delete
}
[99] Fix | Delete
[100] Fix | Delete
private static function clear_recursive($cache_dir, array $find) {
[101] Fix | Delete
$dirHandle = opendir($cache_dir);
[102] Fix | Delete
if (empty($dirHandle)) {
[103] Fix | Delete
return false;
[104] Fix | Delete
}
[105] Fix | Delete
while ($f = readdir($dirHandle)) {
[106] Fix | Delete
if ($f !== '.' && $f !== '..') {
[107] Fix | Delete
$item = rtrim($cache_dir, self::SEP) . self::SEP . $f;
[108] Fix | Delete
if (Themify_Filesystem::is_dir($item)) {
[109] Fix | Delete
self::clear_recursive($item, $find);
[110] Fix | Delete
} elseif (strpos($item, '.html', 5) !== false && strpos($item, '.html.gz', 5) === false && Themify_Filesystem::is_file($item)) {
[111] Fix | Delete
$content = file_get_contents($item, FALSE, NULL, 2000);
[112] Fix | Delete
if (!empty($content)) {
[113] Fix | Delete
foreach ($find as $v) {
[114] Fix | Delete
if (strpos($content, $v, 10) !== false) {
[115] Fix | Delete
Themify_Filesystem::delete($item, 'f');
[116] Fix | Delete
Themify_Filesystem::delete($item . '.gz', 'f');
[117] Fix | Delete
break;
[118] Fix | Delete
}
[119] Fix | Delete
}
[120] Fix | Delete
}
[121] Fix | Delete
$content = null;
[122] Fix | Delete
}
[123] Fix | Delete
}
[124] Fix | Delete
}
[125] Fix | Delete
closedir($dirHandle);
[126] Fix | Delete
$dirHandle = null;
[127] Fix | Delete
return true;
[128] Fix | Delete
}
[129] Fix | Delete
[130] Fix | Delete
/**
[131] Fix | Delete
* init hooks to update cache
[132] Fix | Delete
*/
[133] Fix | Delete
public static function hooks() {
[134] Fix | Delete
add_action('save_post', array(__CLASS__, 'save'), 100, 3);
[135] Fix | Delete
add_action('deleted_post', array(__CLASS__, 'save'), 100, 1);
[136] Fix | Delete
add_action('comment_post', array(__CLASS__, 'comment_update'), 100, 2);
[137] Fix | Delete
add_action('deleted_comment', array(__CLASS__, 'comment_update'), 100, 2);
[138] Fix | Delete
add_action('wp_update_nav_menu', array(__CLASS__, 'menu_update'), 100);
[139] Fix | Delete
add_action('wp_update_nav_menu_item', array(__CLASS__, 'menu_update'), 100);
[140] Fix | Delete
add_action('activated_plugin', array(__CLASS__, 'plugin_active_deactive'), 100, 2);
[141] Fix | Delete
add_action('deactivated_plugin', array(__CLASS__, 'plugin_active_deactive'), 100, 2);
[142] Fix | Delete
add_action('admin_footer', array(__CLASS__, 'admin_check'));
[143] Fix | Delete
add_action('wp_ajax_themify_write_config', array(__CLASS__, 'ajax_write_wp_cache'));
[144] Fix | Delete
add_action('customize_save_after', array(__CLASS__, 'customizer'));
[145] Fix | Delete
add_action('switch_theme', array(__CLASS__, 'disable_cache'), 5);
[146] Fix | Delete
[147] Fix | Delete
add_action('edit_term', array(__CLASS__, 'edit_term'), 100, 3);
[148] Fix | Delete
add_action('delete_term_taxonomy', array(__CLASS__, 'edit_term'), 100, 1);
[149] Fix | Delete
[150] Fix | Delete
add_action('check_ajax_referer', array(__CLASS__, 'widget_update'), 100, 2); //for widgets order,there is no hook
[151] Fix | Delete
[152] Fix | Delete
[153] Fix | Delete
$metas = array('post', 'comment', 'term', 'user');
[154] Fix | Delete
foreach ($metas as $m) {
[155] Fix | Delete
if ($m !== 'term' && $m !== 'user') {
[156] Fix | Delete
add_action('added_' . $m . '_meta', array(__CLASS__, 'meta_update'), 100, 4);
[157] Fix | Delete
}
[158] Fix | Delete
add_action('updated_' . $m . '_meta', array(__CLASS__, 'meta_update'), 100, 4);
[159] Fix | Delete
add_action('deleted_' . $m . '_meta', array(__CLASS__, 'meta_update'), 100, 4);
[160] Fix | Delete
}
[161] Fix | Delete
if (is_user_logged_in()) {
[162] Fix | Delete
add_action('admin_bar_menu', array(__CLASS__, 'cache_menu'), 100);
[163] Fix | Delete
if (isset($_GET['tf-cache']) && ($_GET['tf-cache'] === '2' || $_GET['tf-cache'] === '4')) {
[164] Fix | Delete
add_action('init', array(__CLASS__, 'check_clear'), 1);
[165] Fix | Delete
}
[166] Fix | Delete
}
[167] Fix | Delete
add_action('upgrader_process_complete', array(__CLASS__, 'themify_updated'), 10, 2);
[168] Fix | Delete
}
[169] Fix | Delete
[170] Fix | Delete
/**
[171] Fix | Delete
* comment update
[172] Fix | Delete
*/
[173] Fix | Delete
public static function comment_update($comment_ID, $comment_approved) {
[174] Fix | Delete
$comment = get_comment($comment_ID);
[175] Fix | Delete
if (!empty($comment)) {
[176] Fix | Delete
self::remove_cache($comment->comment_post_ID, 'comment');
[177] Fix | Delete
}
[178] Fix | Delete
}
[179] Fix | Delete
[180] Fix | Delete
/**
[181] Fix | Delete
* plugin activatiion/deactivation
[182] Fix | Delete
*/
[183] Fix | Delete
public static function plugin_active_deactive($plugin, $network_wide) {
[184] Fix | Delete
$type = $network_wide ? 'all' : 'blog';
[185] Fix | Delete
self::remove_cache($type);
[186] Fix | Delete
}
[187] Fix | Delete
[188] Fix | Delete
/**
[189] Fix | Delete
* menu update
[190] Fix | Delete
*/
[191] Fix | Delete
public static function menu_update($_menu_id) {
[192] Fix | Delete
themify_clear_menu_cache();
[193] Fix | Delete
remove_action('wp_update_nav_menu', array(__CLASS__, 'menu_update'), 100);
[194] Fix | Delete
remove_action('wp_update_nav_menu_item', array(__CLASS__, 'menu_update'), 100);
[195] Fix | Delete
self::remove_cache();
[196] Fix | Delete
}
[197] Fix | Delete
[198] Fix | Delete
public static function customizer($manager) {
[199] Fix | Delete
if (!empty($manager)) {
[200] Fix | Delete
$post_id = $manager->changeset_post_id();
[201] Fix | Delete
if (!empty($post_id)) {
[202] Fix | Delete
self::remove_cache($post_id);
[203] Fix | Delete
}
[204] Fix | Delete
}
[205] Fix | Delete
}
[206] Fix | Delete
[207] Fix | Delete
public static function edit_term($term, $tt_id = null, $taxonomy = null) {
[208] Fix | Delete
if (empty($taxonomy)) {
[209] Fix | Delete
$temp = get_term($term);
[210] Fix | Delete
$taxonomy = $temp->taxonomy;
[211] Fix | Delete
$temp = null;
[212] Fix | Delete
}
[213] Fix | Delete
$type = $taxonomy === 'category' ? 'category' : 'term';
[214] Fix | Delete
self::remove_cache($term, $type);
[215] Fix | Delete
}
[216] Fix | Delete
[217] Fix | Delete
/**
[218] Fix | Delete
* meta update
[219] Fix | Delete
*/
[220] Fix | Delete
public static function meta_update($meta_id, $post_id, $meta_key, $meta_value) {
[221] Fix | Delete
if (!empty($post_id)) {
[222] Fix | Delete
$actions = explode('_', current_action());
[223] Fix | Delete
self::remove_cache($post_id, $actions[1]);
[224] Fix | Delete
}
[225] Fix | Delete
}
[226] Fix | Delete
[227] Fix | Delete
public static function widget_update($action, $result) {
[228] Fix | Delete
if ($result !== false && $action === 'save-sidebar-widgets') {
[229] Fix | Delete
self::remove_cache();
[230] Fix | Delete
}
[231] Fix | Delete
}
[232] Fix | Delete
[233] Fix | Delete
public static function save($post_id, $post = false, $update = true) {
[234] Fix | Delete
if ($update || current_action() === 'deleted_post') {
[235] Fix | Delete
self::remove_cache($post_id);
[236] Fix | Delete
} elseif (!is_object($post) || $post->post_status !== 'auto-draft') {
[237] Fix | Delete
self::remove_cache();
[238] Fix | Delete
}
[239] Fix | Delete
}
[240] Fix | Delete
[241] Fix | Delete
public static function get_current_url():string {
[242] Fix | Delete
if (empty($_SERVER['REQUEST_URI']) || empty($_SERVER['HTTP_HOST'])) {
[243] Fix | Delete
return '';
[244] Fix | Delete
}
[245] Fix | Delete
$protocol = is_ssl() ? 'https://' : 'http://';
[246] Fix | Delete
return $protocol . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
[247] Fix | Delete
}
[248] Fix | Delete
[249] Fix | Delete
/**
[250] Fix | Delete
* will be called in advanced-cache.php before wp full core load,a lot of functions from wp api and FW functions are't available in in this function be carefull!
[251] Fix | Delete
*/
[252] Fix | Delete
public static function run() {
[253] Fix | Delete
if (self::$stopCache === true) {
[254] Fix | Delete
return;
[255] Fix | Delete
}
[256] Fix | Delete
if (!function_exists('wp_get_nocache_headers')) {
[257] Fix | Delete
add_action('init', array(__CLASS__, 'run'), 0);
[258] Fix | Delete
return;
[259] Fix | Delete
}
[260] Fix | Delete
self::$cache_dir = self::get_cache_main_dir();
[261] Fix | Delete
if (Themify_Filesystem::mkdir(self::$cache_dir)) {
[262] Fix | Delete
$isMulti = is_multisite();
[263] Fix | Delete
if ($isMulti !== false) {
[264] Fix | Delete
self::$cache_dir = self::get_cache_blog_dir();
[265] Fix | Delete
}
[266] Fix | Delete
if ($isMulti === false || Themify_Filesystem::mkdir(self::$cache_dir, true)) {
[267] Fix | Delete
if (defined('TF_CACHE_RULES') && TF_CACHE_RULES) {
[268] Fix | Delete
$ignore = explode('|TF|', TF_CACHE_RULES);
[269] Fix | Delete
if (!empty($ignore) && !empty($_SERVER['HTTP_HOST'])) {
[270] Fix | Delete
$request = $_SERVER['REQUEST_URI'];
[271] Fix | Delete
$server = is_ssl() ? 'https://' : 'http://';
[272] Fix | Delete
$server .= $_SERVER['HTTP_HOST'];
[273] Fix | Delete
$del = '~';
[274] Fix | Delete
foreach ($ignore as $r) {
[275] Fix | Delete
$r = str_replace($server, '', $r);
[276] Fix | Delete
$p = $del . $r . $del;
[277] Fix | Delete
if (preg_match($p, $request)) {
[278] Fix | Delete
self::$cache_dir = null;
[279] Fix | Delete
return;
[280] Fix | Delete
}
[281] Fix | Delete
}
[282] Fix | Delete
$request = $server = $ignore = null;
[283] Fix | Delete
}
[284] Fix | Delete
}
[285] Fix | Delete
$dir = null;
[286] Fix | Delete
self::$cache_dir = self::get_current_cache('', true).'.html';
[287] Fix | Delete
if (Themify_Filesystem::is_file(self::$cache_dir)) {
[288] Fix | Delete
$ftime = filemtime(self::$cache_dir);
[289] Fix | Delete
$expire = defined('TF_CACHE_TIME') && TF_CACHE_TIME ? (TF_CACHE_TIME * 60) : WEEK_IN_SECONDS;
[290] Fix | Delete
$liveTime = $expire + $ftime;
[291] Fix | Delete
if ($liveTime > time()) {
[292] Fix | Delete
global $wp;
[293] Fix | Delete
$headers = apply_filters('wp_headers', wp_get_nocache_headers(), $wp);
[294] Fix | Delete
[295] Fix | Delete
if (!isset($headers['Cache-Control'])) {
[296] Fix | Delete
$headers['Content-Type'] = 'no-cache, must-revalidate, max-age=0';
[297] Fix | Delete
}
[298] Fix | Delete
if (!isset($headers['Content-Type'])) {
[299] Fix | Delete
$headers['Content-Type'] = 'text/html;charset=UTF-8';
[300] Fix | Delete
}
[301] Fix | Delete
// header('Content-Length: '.filesize(self::$cache_dir));//temprorary disable,because when cd of cloudfare is enabled it will return compress brottil size
[302] Fix | Delete
$headers['Last-Modified'] = gmdate('D, d M Y H:i:s', $ftime) . ' GMT';
[303] Fix | Delete
$headers['Expires'] = gmdate('D, d M Y H:i:s', $liveTime) . 'GMT';
[304] Fix | Delete
if (Themify_Filesystem::is_file(self::$cache_dir)) {//maybe another proccess has already removed it?
[305] Fix | Delete
$type = false; //self::get_available_gzip();temprorary disable gzip caching,because bug of cloudfare
[306] Fix | Delete
if ($type !== false && Themify_Filesystem::is_file(self::$cache_dir . '.gz')) {
[307] Fix | Delete
$type = key($type);
[308] Fix | Delete
if (isset($_SERVER['HTTP_ACCEPT_ENCODING']) && strpos($_SERVER['HTTP_ACCEPT_ENCODING'], $type) !== false) {
[309] Fix | Delete
self::$cache_dir .= '.gz';
[310] Fix | Delete
$headers['Content-Encoding'] = $type;
[311] Fix | Delete
}
[312] Fix | Delete
}
[313] Fix | Delete
foreach ($headers as $name => $field_value) {
[314] Fix | Delete
header("{$name}: {$field_value}");
[315] Fix | Delete
}
[316] Fix | Delete
do_action_ref_array('send_headers', array(&$wp));
[317] Fix | Delete
readfile(self::$cache_dir);
[318] Fix | Delete
die;
[319] Fix | Delete
}
[320] Fix | Delete
} else {
[321] Fix | Delete
Themify_Filesystem::delete(self::$cache_dir, 'f');
[322] Fix | Delete
Themify_Filesystem::delete(self::$cache_dir . '.gz', 'f');
[323] Fix | Delete
}
[324] Fix | Delete
}
[325] Fix | Delete
add_action('template_redirect', array(__CLASS__, 'template_include'), -9999999);
[326] Fix | Delete
} else {
[327] Fix | Delete
self::$cache_dir = null;
[328] Fix | Delete
}
[329] Fix | Delete
} else {
[330] Fix | Delete
self::$cache_dir = null;
[331] Fix | Delete
}
[332] Fix | Delete
}
[333] Fix | Delete
[334] Fix | Delete
public static function get_current_cache(string $request = '',bool $create_dir = false):string {
[335] Fix | Delete
if ($request === '') {
[336] Fix | Delete
$request = self::get_current_url();
[337] Fix | Delete
}
[338] Fix | Delete
return self::get_cache_folder($request, $create_dir) . md5($request);
[339] Fix | Delete
}
[340] Fix | Delete
[341] Fix | Delete
/**
[342] Fix | Delete
* Initiate cache, just before page renders on frontend
[343] Fix | Delete
*
[344] Fix | Delete
* Hooked to "template_redirect"[0]
[345] Fix | Delete
*/
[346] Fix | Delete
public static function template_include() {
[347] Fix | Delete
if (!themify_is_dev_mode()) {
[348] Fix | Delete
self::cache_start();
[349] Fix | Delete
}
[350] Fix | Delete
}
[351] Fix | Delete
[352] Fix | Delete
private static function cache_start() {
[353] Fix | Delete
global $post;
[354] Fix | Delete
if (self::$stopCache === true || (isset($post, $post->post_password) && $post->post_password !== '') || is_user_logged_in() || is_admin() || self::$cache_dir === null || is_404() || is_search() || themify_is_ajax() || post_password_required() || is_trackback() || is_robots() || is_preview() || is_customize_preview() || themify_is_login_page() || (themify_is_woocommerce_active() && (is_checkout() || is_cart() || is_account_page()))) {
[355] Fix | Delete
return;
[356] Fix | Delete
}
[357] Fix | Delete
if (defined('TF_CACHE_IGNORE') && TF_CACHE_IGNORE) {
[358] Fix | Delete
$ignore = explode(',', trim(TF_CACHE_IGNORE));
[359] Fix | Delete
if (!empty($ignore)) {
[360] Fix | Delete
foreach ($ignore as $f) {
[361] Fix | Delete
if (($f === 'is_shop' && themify_is_shop()) || ($f !== 'is_shop' && is_callable($f) && call_user_func($f))) {
[362] Fix | Delete
return;
[363] Fix | Delete
}
[364] Fix | Delete
}
[365] Fix | Delete
}
[366] Fix | Delete
$ignore = null;
[367] Fix | Delete
}
[368] Fix | Delete
if (false !== self::get_cache_plugins()) {
[369] Fix | Delete
self::disable_cache();
[370] Fix | Delete
return;
[371] Fix | Delete
}
[372] Fix | Delete
define('TF_CACHE', true);
[373] Fix | Delete
self::$error = true;
[374] Fix | Delete
ob_start(array(__CLASS__, 'getBuffer'));
[375] Fix | Delete
add_action('wp_footer', array(__CLASS__, 'body_end'), 9999999);
[376] Fix | Delete
}
[377] Fix | Delete
[378] Fix | Delete
public static function getBuffer(?string $html=''):string {
[379] Fix | Delete
if (!$html) {
[380] Fix | Delete
$html = ob_get_contents();
[381] Fix | Delete
}
[382] Fix | Delete
if (self::$error === false && !empty($html)) {
[383] Fix | Delete
$html = preg_replace(array(
[384] Fix | Delete
'/<!--(.|\S)*?-->/s',
[385] Fix | Delete
'/\>[^\S ]{2,}/s', // remove whitespaces after tags
[386] Fix | Delete
'/[^\S ]{2,}\</s', // remove whitespaces before tags
[387] Fix | Delete
'/([\t ])+/s', //shorten multiple whitespace sequences; keep new-line characters because they matter in JS!!!
[388] Fix | Delete
'/\>[\r\n\t ]{2,}\</s', //remove empty lines (between HTML tags); cannot remove just any line-end characters because in inline JS they can matter!
[389] Fix | Delete
), array('', '>', '<', ' ', '><'), $html);
[390] Fix | Delete
if (self::$stopCache === false) {
[391] Fix | Delete
$dir = rtrim(dirname(self::$cache_dir), self::SEP) . self::SEP;
[392] Fix | Delete
if (Themify_Filesystem::mkdir($dir, true) && !is_file(self::$cache_dir)) {
[393] Fix | Delete
//tmp file need because file_put_contents isn't atomic(another process can read not ready file),locking file(LOCK_EX) is slow and not work always,that is why we are using rename(it is atomic)
[394] Fix | Delete
if (file_put_contents(self::$cache_dir . 'tmp', '<!--THEMIFY CACHE-->' . $html) && Themify_Filesystem::rename(self::$cache_dir . 'tmp', self::$cache_dir) !== false) {
[395] Fix | Delete
if (false && themify_get_server() !== 'litespeed' && themify_check('setting-cache_gzip', true)) {
[396] Fix | Delete
$func = self::get_available_gzip();
[397] Fix | Delete
if ($func !== false) {
[398] Fix | Delete
$func = current($func);
[399] Fix | Delete
$html = call_user_func($func['f'], $html, $func['l']);
[400] Fix | Delete
$func = null;
[401] Fix | Delete
if (!empty($html)) {
[402] Fix | Delete
file_put_contents(self::$cache_dir . '.gz', '<!--THEMIFY CACHE-->' . $html, LOCK_EX);
[403] Fix | Delete
}
[404] Fix | Delete
}
[405] Fix | Delete
}
[406] Fix | Delete
} else {
[407] Fix | Delete
Themify_Filesystem::delete(self::$cache_dir . 'tmp', 'f');
[408] Fix | Delete
}
[409] Fix | Delete
}
[410] Fix | Delete
}
[411] Fix | Delete
}
[412] Fix | Delete
return $html;
[413] Fix | Delete
}
[414] Fix | Delete
[415] Fix | Delete
public static function body_end():void {
[416] Fix | Delete
add_action('shutdown', array(__CLASS__, 'cache_end'), 0);
[417] Fix | Delete
}
[418] Fix | Delete
[419] Fix | Delete
public static function cache_end():void {
[420] Fix | Delete
self::$error = false;
[421] Fix | Delete
ob_end_flush();
[422] Fix | Delete
}
[423] Fix | Delete
[424] Fix | Delete
public static function get_available_gzip() {
[425] Fix | Delete
if (function_exists('brotli_compress') && ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on') || (isset($_SERVER['SERVER_PORT']) && (int) $_SERVER['SERVER_PORT'] === 443))) {
[426] Fix | Delete
return array('br' => array('f' => 'brotli_compress', 'l' => 10));
[427] Fix | Delete
}
[428] Fix | Delete
if (function_exists('gzdeflate')) {
[429] Fix | Delete
return array('deflate' => array('f' => 'gzdeflate', 'l' => 8));
[430] Fix | Delete
}
[431] Fix | Delete
if (function_exists('gzcompress')) {
[432] Fix | Delete
return array('deflate' => array('f' => 'gzcompress', 'l' => 8));
[433] Fix | Delete
}
[434] Fix | Delete
if (function_exists('gzencode')) {
[435] Fix | Delete
return array('gzip' => array('f' => 'gzencode', 'l' => 8));
[436] Fix | Delete
}
[437] Fix | Delete
return false;
[438] Fix | Delete
}
[439] Fix | Delete
[440] Fix | Delete
public static function create_config(array $data) {
[441] Fix | Delete
$cache_dir = self::get_wp_content_dir();
[442] Fix | Delete
if (Themify_Filesystem::is_writable($cache_dir)) {
[443] Fix | Delete
if (!empty($data['setting-cache-html']) && false === self::get_cache_plugins()) {
[444] Fix | Delete
$fw_dir = THEMIFY_DIR . self::SEP . 'cache' . self::SEP;
[445] Fix | Delete
$fw_config = $fw_dir . 'config.php';
[446] Fix | Delete
$cache_config = self::get_cache_config_file();
[447] Fix | Delete
$msg = sprintf(__('Can`t copy %s to %s. Please check permission or do manually it.', 'themify'), $fw_config, $cache_config);
[448] Fix | Delete
if (Themify_Filesystem::is_file($cache_config)) {
[449] Fix | Delete
include_once $cache_config;
[450] Fix | Delete
}
[451] Fix | Delete
$rules = '';
[452] Fix | Delete
if (!empty($data['setting-cache-rule'])) {
[453] Fix | Delete
$rules = explode(PHP_EOL, $data['setting-cache-rule']);
[454] Fix | Delete
foreach ($rules as $i => $r) {
[455] Fix | Delete
$rules[$i] = trim(str_replace(array('"', "'"), '', $r));
[456] Fix | Delete
if (empty($rules[$i])) {
[457] Fix | Delete
unset($rules[$i]);
[458] Fix | Delete
}
[459] Fix | Delete
}
[460] Fix | Delete
$rules = !empty($rules) ? implode('|TF|', $rules) : '';
[461] Fix | Delete
}
[462] Fix | Delete
$config = array(
[463] Fix | Delete
'#TF_CACHE_FW#' => trailingslashit($fw_dir),
[464] Fix | Delete
'#TF_CACHE_TIME#' => !empty($data['setting-cache-live']) ? ((int) $data['setting-cache-live']) : WEEK_IN_SECONDS,
[465] Fix | Delete
'#TF_CACHE_RULES#' => $rules,
[466] Fix | Delete
'#TF_CACHE_IGNORE#' => ''
[467] Fix | Delete
);
[468] Fix | Delete
$rules = null;
[469] Fix | Delete
$ignores = array();
[470] Fix | Delete
foreach ($data as $k => $v) {
[471] Fix | Delete
if (strpos($k, 'setting-cache-ignore_') === 0 && !empty($v)) {
[472] Fix | Delete
$ignores[] = $v;
[473] Fix | Delete
}
[474] Fix | Delete
}
[475] Fix | Delete
if (!empty($ignores)) {
[476] Fix | Delete
$config['#TF_CACHE_IGNORE#'] = implode(',', $ignores);
[477] Fix | Delete
}
[478] Fix | Delete
$ignores = $data = null;
[479] Fix | Delete
$hasUpdate = (!defined('TF_CACHE_FW') || TF_CACHE_FW !== $config['#TF_CACHE_FW#']) || (!defined('TF_CACHE_RULES') || $config['#TF_CACHE_RULES#'] !== TF_CACHE_RULES) || (!defined('TF_CACHE_IGNORE') || $config['#TF_CACHE_IGNORE#'] !== TF_CACHE_IGNORE) || (!defined('TF_CACHE_TIME') || $config['#TF_CACHE_TIME#'] != TF_CACHE_TIME);
[480] Fix | Delete
if ($hasUpdate === true) {
[481] Fix | Delete
if (!copy($fw_config, $cache_config)) {
[482] Fix | Delete
self::disable_cache();
[483] Fix | Delete
return $msg;
[484] Fix | Delete
}
[485] Fix | Delete
$content = Themify_Filesystem::get_contents($cache_config);
[486] Fix | Delete
if (empty($content)) {
[487] Fix | Delete
self::disable_cache();
[488] Fix | Delete
return $msg;
[489] Fix | Delete
}
[490] Fix | Delete
if (!file_put_contents($cache_config, str_replace(array_keys($config), $config, $content), LOCK_EX)) {
[491] Fix | Delete
self::disable_cache();
[492] Fix | Delete
return false;
[493] Fix | Delete
}
[494] Fix | Delete
$content = null;
[495] Fix | Delete
}
[496] Fix | Delete
$copy = true;
[497] Fix | Delete
if (Themify_Filesystem::is_file($cache_dir . 'advanced-cache.php')) {
[498] Fix | Delete
$content = Themify_Filesystem::get_contents($cache_dir . 'advanced-cache.php');
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function