array());
private static $done = array();
private static $localiztion = array();
private static $theme_css_support = array('mobile-menu'=>true,'rtl'=>true);
private static $concateFile = null;
private static $bufferLevel = 0;
private static $googleFonts = array();
private static $guttenbergCss = array();
public static $preLoadMedia = array();
public static $disableGoogleFontsLoad = null;
public static $isHeader = false;
public static $isFooter = false;
public static $mediaMaxWidth = 1200;
public static $mobileMenuActive = 1100;
public static $THEME_CSS_MODULES_URI = null;
public static $THEME_CSS_MODULES_DIR = null;
public static $THEME_WC_CSS_MODULES_DIR = null;
public static $THEME_WC_CSS_MODULES_URI = null;
public static $themeVersion = null;
public static function init() {
if (themify_is_themify_theme()) {
self::$THEME_CSS_MODULES_DIR = THEME_DIR . '/styles/modules/';
self::$THEME_CSS_MODULES_URI = THEME_URI . '/styles/modules/';
self::$THEME_WC_CSS_MODULES_DIR = THEME_DIR . '/styles/wc/modules/';
self::$THEME_WC_CSS_MODULES_URI = THEME_URI . '/styles/wc/modules/';
self::$themeVersion = wp_get_theme(get_template())->display('Version');
self::$mobileMenuActive = (int) themify_get('setting-mobile_menu_trigger_point', self::$mobileMenuActive, true);
}
if (!is_admin()) {
add_action('wp_body_open', array(__CLASS__, 'body_open'), 1);
add_filter('wp_default_scripts', array(__CLASS__, 'remove_default_js'));
add_action('wp', array(__CLASS__, 'lazy_init'), 1);
} else {
add_action('wp_loaded', array(__CLASS__, 'lazy_init'), 1);
add_action('admin_init', array(__CLASS__, 'loadMainScript'));
add_action('admin_footer', array(__CLASS__, 'js_localize'), 18);
}
add_filter('themify_loops_wrapper_class', array(__CLASS__, 'load_loop_css'), 100, 6);
add_filter('kses_allowed_protocols', array(__CLASS__, 'allow_lazy_protocols'), 100, 1);
add_filter('sgo_js_minify_exclude', array(__CLASS__,'exclude_main_js' ),1);
add_filter('sgo_javascript_combine_exclude', array( __CLASS__, 'exclude_main_js' ),1 );
add_filter('autoptimize_filter_js_exclude', array(__CLASS__,'exclude_main_js' ),1);
add_filter('autoptimize_filter_js_consider_minified',array(__CLASS__,'exclude_main_js' ),1);
add_filter('rocket_delay_js_exclusions', array( __CLASS__, 'exclude_main_js' ),1 );
add_filter('rocket_exclude_js',array( __CLASS__, 'exclude_main_js' ),1 );
add_filter( 'js_do_concat', [ __CLASS__, 'Automattic_page_optimize_js_exclude' ], 10, 2 );
add_action('pre_get_search_form', array(__CLASS__, 'load_search_form_css'), 9);
if (!is_admin() || themify_is_ajax()) {
add_filter('post_playlist', array(__CLASS__, 'wp_media_playlist'), 100, 3);
}
add_filter('cron_schedules', array(__CLASS__, 'cron_schedules'));
add_action('themify_cron_clear_css', array(__CLASS__, 'cron'));
if (!wp_next_scheduled('themify_cron_clear_css')) {
wp_schedule_event(time() + WEEK_IN_SECONDS * 4, 'four_week', 'themify_cron_clear_css');
}
}
public static function lazy_init() {
if (!is_admin() && !themify_is_login_page()) {
remove_action('wp_head', 'wp_resource_hints', 2);
if (self::$themeVersion !== null) {
add_action('wp_head', array(__CLASS__, 'header_meta'),-1111);
add_action('wp_head', array(__CLASS__, 'header_html'));
add_filter('wp_title', array(__CLASS__, 'wp_title'), 10, 2);
remove_action('wp_head', 'locale_stylesheet'); //remove rtl loading
}
add_action( 'template_redirect', array( __CLASS__, 'start_buffer' ), 1 );
add_action('wp_enqueue_scripts', array(__CLASS__, 'before_enqueue'), 7);
add_action('wp_enqueue_scripts', array(__CLASS__, 'after_enqueue'), 11);
add_filter('style_loader_tag', array(__CLASS__, 'style_header_tag'), 10, 4);
add_filter('render_block_data', array(__CLASS__, 'loadGuttenbergCss'), PHP_INT_MAX, 2);
add_action('wp_head', array(__CLASS__, 'css_position'),100);
add_action('wp_head', array(__CLASS__, 'wp_head'),-100);
add_action('wp_footer', array(__CLASS__, 'before_footer'), -1111);
add_action('wp_footer', array(__CLASS__, 'js_localize'), 18);
add_action('wp_footer', array(__CLASS__, 'wp_footer'), 100);
}
elseif(is_admin()){
add_action('admin_head', array(__CLASS__, 'dev_mode_styles'));
}
if(!is_admin() || themify_is_ajax()){
add_filter('widget_display_callback', array(__CLASS__, 'widget_css'), 100, 3);
add_action('wp_playlist_scripts',array(__CLASS__,'disable_playlist_template'),0,1);
}
add_filter('wp_audio_shortcode_library', array(__CLASS__, 'media_shortcode_library'), 100, 1);
add_filter('wp_video_shortcode_library', array(__CLASS__, 'media_shortcode_library'), 10, 1);
add_filter('wp_audio_shortcode', array(__CLASS__, 'audio_shortcode'), 100, 5);
add_filter('wp_video_shortcode_override', array(__CLASS__, 'video_shortcode'), 100, 4);
add_filter('embed_oembed_html',array(__CLASS__,'embed'),100,4);
if (themify_is_lazyloading()) {
themify_disable_other_lazy();
}
$cdn=' https://cdn.jsdelivr.net https://cdnjs.cloudflare.com *.lottiefiles.com';
themify_set_headers(array(
'CONTENT-SECURITY-POLICY'=>array(
'img-src'=>'data:',
'style-src'=>"'unsafe-inline'".$cdn,
'style-src-elem'=>"'unsafe-inline'".$cdn,
'script-src'=>"'unsafe-inline' data:".$cdn,
'script-src-elem'=>"'unsafe-inline' data:".$cdn,
'connect-src'=>'https://themify.org *.lottiefiles.com',
'default-src'=>'https://themify.org data:'.$cdn
)
));
}
public static function start_buffer(){
self::createDir();
ob_start(array(__CLASS__, 'getBuffer'));
self::$bufferLevel = ob_get_level();
}
public static function createDir():bool {
if (self::$concateFile === null) {
self::$concateFile = self::getCurrentVersionFolder();
if (!is_dir(self::$concateFile)) {
Themify_Filesystem::mkdir(self::$concateFile,true);
if (!Themify_Filesystem::is_dir(self::$concateFile)) {
clearstatcache();
Themify_Filesystem::mkdir(self::$concateFile,true);
if (!Themify_Filesystem::is_dir(self::$concateFile)) {
self::$concateFile = null;
return false;
}
}
}
}
return true;
}
public static function remove_default_js($scripts) {
if (!themify_builder_check('setting-jquery-migrate', 'performance-jquery_migrate') && !themify_is_login_page()) {
$script = $scripts->registered['jquery'];
if (!empty($script->deps)) { // Check whether the script has any dependencies
$key = 'jquery-migrate';
$index = isset($script->deps[1]) && $script->deps[1] === $key ? 1 : array_search($key, $script->deps, true);
if ($index !== false) {
unset($script->deps[$index]);
}
}
}
return $scripts;
}
public static function before_enqueue() {
self::add_css('tf_base', THEMIFY_URI . '/css/base.min.css', null, THEMIFY_VERSION);
if (self::$themeVersion !== null) {
self::add_css('themify_common', THEMIFY_URI . '/css/themify-common.css', null, THEMIFY_VERSION);
if(is_admin_bar_showing()){
self::add_css('themify_common_logged', THEMIFY_URI . '/css/themify-common-logged.css', null, THEMIFY_VERSION,'',true);
}
}
self::loadMainScript();
}
public static function after_enqueue() {
global $wp_styles, $wp_version;
$css = array('wp-block-library');
$is_theme = self::$themeVersion !== null;
if ($is_theme === true && themify_is_woocommerce_active()) {
add_filter('woocommerce_shortcode_products_query', array(__CLASS__, 'wc_shortcode_product'), 10, 3);
add_action('woocommerce_before_single_product_summary', array(__CLASS__, 'wc_shortcode_product_page'));
add_action('woocommerce_before_checkout_form_cart_notices', array(__CLASS__, 'wc_shortcode_checkout'));
add_action('woocommerce_account_content', array(__CLASS__, 'wc_shortcode_account'));
$wc_ver = WC()->version;
self::$localiztion['wc_version'] = $wc_ver;
wp_enqueue_script('wc-cart-fragments');//default load has been removed from wc 7.8.0
if (themify_is_shop() || is_product() || (!is_checkout() && !is_account_page() && !is_checkout_pay_page() && !is_edit_account_page() && !is_order_received_page() && !is_add_payment_method_page())) {
wp_enqueue_script('wc-add-to-cart-variation'); //load tmpl files
wp_enqueue_script('wc-single-product');
wp_enqueue_script(themify_wc_get_script_handle('wc-jquery-blockui'));
WC_Frontend_Scripts::localize_printed_scripts();
global $wp_scripts;
$js = array(themify_wc_get_script_handle('js-cookie'), 'wc-add-to-cart', 'wc-add-to-cart-variation', 'wc-cart-fragments', 'woocommerce', 'wc_additional_variation_images_script', 'wc-single-product');
$arr = array();
$disableOptimize = themify_check('setting-optimize-wc', true);
$isDefered=themify_check('setting-jquery', true)?true:($disableOptimize?false:!themify_check('setting-defer-wc', true));
foreach ($js as $v) {
if (isset($wp_scripts->registered[$v]) && wp_script_is($v)) {
if ($isDefered === true && !empty($wp_scripts->registered[$v]->extra['data'])) {
self::$wc_data[] = $wp_scripts->registered[$v]->extra['data'];
$wp_scripts->registered[$v]->extra['data']='';
}
if ($v === 'wc-single-product' && is_product()) {
continue;
}
if ($disableOptimize === false) {
$wp_scripts->done[] = $v;
}
$arr[$v] = $wp_scripts->registered[$v]->src;
if ($wc_ver !== $wp_scripts->registered[$v]->ver) {
$arr[$v] .= '?ver=' . $wp_scripts->registered[$v]->ver;
}
}
}
self::$localiztion['wc_js'] = $arr;
if ($disableOptimize === true) {
self::$localiztion['wc_js_normal'] = true;
}
// Localize photoswipe css
if (!empty($wp_styles->registered['photoswipe']->src)) {
wp_dequeue_style('photoswipe');
wp_dequeue_style('photoswipe-default-skin');
self::$localiztion['photoswipe'] = array('main' => $wp_styles->registered['photoswipe']->src, 'skin' => $wp_styles->registered['photoswipe-default-skin']->src);
}
$js = $arr = null;
}
$wc_block_prefix = 'wc-block';
if (intval($wc_ver[0]) >= 6) {
$wc_block_prefix .= 's';
}
$css[] = $wc_block_prefix . '-vendors-style';
$css[] = $wc_block_prefix . '-style';
$css[] = 'wp-block-library-theme';
$css[] = 'woocommerce-layout';
$css[] = 'woocommerce-smallscreen';
$css[] = 'woocommerce-general';
$css[] = 'select2';
$css[]='woocommerce-blocktheme';
$css[] = 'woocommerce_prettyPhoto_css';
}
$css = apply_filters('themify_deq_css', $css);
foreach ($css as $v) {
if (isset($wp_styles->registered[$v]) && wp_style_is($v)) {
$src = $wp_styles->registered[$v]->src;
if ($v === 'wp-block-library' || $v === 'wp-block-library-theme' || $v === $wc_block_prefix . '-style' || $v === $wc_block_prefix . '-vendors-style') {
if (empty($wp_styles->registered[$v]->deps) || ($v === $wc_block_prefix . '-style' && count($wp_styles->registered[$v]->deps) === 1 && $wp_styles->registered[$v]->deps[0] === $wc_block_prefix . '-vendors-style')) {
$wp_styles->done[] = $v;
self::$guttenbergCss[$v] = $src;
}
continue;
}
$wp_styles->done[] = $v;
$ver = $wp_styles->registered[$v]->ver;
if ($src[0] === '/' && $src[1] === '/') {
$src = (is_ssl() ? 'https:' : 'http:') . $src;
}
if (strpos($src, 'http') === false) {
$src = home_url($src);
}
if (empty($ver)) {
$ver = $wp_version;
}
wp_dequeue_style($v);
self::add_css($v, $src, $wp_styles->registered[$v]->deps, $ver, $wp_styles->registered[$v]->args);
}
}
$css = null;
if ($is_theme === true) {
if (isset(self::$theme_css_support['mobile-menu'])) {
self::addMobileMenuCss('mobile-menu', THEME_URI . '/mobile-menu.css');
}
if (function_exists('themify_theme_enqueue_header')) {
themify_theme_enqueue_header();
}
/* Disabel Guttenberg Global Style WP 5.9 */
// remove_action( 'wp_body_open', 'wp_global_styles_render_svg_filters' );
// wp_dequeue_style('global-styles');
}
}
public static function add_css(string $handle, string $src,?array $deps,?string $ver,?string $media = '',bool $in_footer = false) {
if (!isset(self::$css[$handle], self::$done[$src])) {
self::$done[$src] = true;
if (!$media) {
$media = 'all';
}
if (self::$concateFile === null || is_admin()) {
if (strpos($handle, 'http') !== false) {
$handle = crc32($handle);
}
self::$css[$handle] = array('s' => $src, 'v' => $ver);
if ($media !== 'all') {//need to get css files in ajax call(e.g builder live preview)
self::$css[$handle]['m'] = $media;
}
wp_enqueue_style($handle, $src, $deps, $ver, $media);
return;
}
if ($in_footer === true || self::$isFooter === true) {
if (!isset(self::$css['in_footer'])) {
self::$css['in_footer'] = array();
}
self::$css['in_footer'][$handle] = array('s' => $src, 'v' => $ver);
if ($media !== 'all') {
self::$css['in_footer'][$handle]['m'] = $media;
}
} else {
self::$css[$handle] = array('s' => $src, 'v' => $ver);
if ($media !== 'all') {
self::$css[$handle]['m'] = $media;
}
}
}
}
/**
* Deregister an stylesheet
*
* @param string $handle
* @param string $both
*/
public static function remove_css(string $handle, string $type = 'both') {
if ($handle !== 'in_footer' && self::$css !== null) {
if ($type === 'both' || $type === 'main') {
unset(self::$css[$handle], self::$css['in_footer'][$handle]);
}
if ($type === 'both' || $type === 'mobile') {
unset(self::$css['mobile_concate'][$handle]);
}
}
}
public static function header_meta() {
?>
';//bug in chrome https://bugs.chromium.org/p/chromium/issues/detail?id=332189x
}
public static function style_header_tag(string $tag, string $handle,string $href,string $media):string {
$src = strtok($href, '?');
unset(self::$preLoadMedia[$src]);
$preload = 'registered['themify-main-script'] ) ) {
/* either something has gone horribly wrong, or the script is intentionally removed; bail. */
return;
}
self::localize_script('themify-main-script', 'themify_vars', apply_filters('themify_main_script_vars', self::$localiztion));
if(!is_admin()){
global $wp_scripts;
$inline_js=$wp_scripts->registered['themify-main-script']->extra['data'];
if(!empty(self::$wc_data)){
$inline_js.=implode('',self::$wc_data);
}
?>
registered['themify-main-script']->extra['data'] = $inline_js=self::$wc_data=null;
do_action('tf_load_styles');
self::$isFooter = true;
}
else {
self::loadIcons();
}
self::$localiztion = array();
}
/**
* Copy of WP_Scripts::localize() except it uses JSON_UNESCAPED_SLASHES
*
* @documented in wp-includes/class.wp.scripts.php
*/
public static function localize_script(string $handle,string $object_name,array $l10n) {
global $wp_scripts;
if ('jquery' === $handle) {
$handle = 'jquery-core';
}
if (is_array($l10n) && isset($l10n['l10n_print_after'])) { // back compat, preserve the code in 'l10n_print_after' if present.
$after = $l10n['l10n_print_after'];
unset($l10n['l10n_print_after']);
}
foreach ((array) $l10n as $key => $value) {
if (!is_scalar($value)) {
continue;
}
$l10n[$key] = html_entity_decode((string) $value, ENT_QUOTES, 'UTF-8');
}
$script = "var $object_name = " . wp_json_encode($l10n, JSON_UNESCAPED_SLASHES) . ';';
if (!empty($after)) {
$script .= "\n$after;";
}
$data = $wp_scripts->get_data($handle, 'data');
if (!empty($data)) {
$script = "$data\n$script";
}
return $wp_scripts->add_data($handle, 'data', $script);
}
public static function before_footer() {
if (themify_is_woocommerce_active()) {
remove_action('wp_footer', 'wc_no_js');
}
if (self::$themeVersion !== null && !is_admin()) {
self::add_css('theme-style', THEME_URI . '/style.css', null, self::$themeVersion);
if (self::$mediaMaxWidth !== false) {
self::add_css('themify-media-queries', THEME_URI . '/media-queries.css', null, self::$themeVersion, '(max-width:' . self::$mediaMaxWidth . 'px)');
}
if (isset(self::$theme_css_support['wc'])) {
self::add_css('tf_theme_wc', THEME_URI . '/styles/wc/woocommerce.css', null, self::$themeVersion);
if (isset(self::$theme_css_support['wc_single_product']) && (isset(self::$wc_shortcode_type['product']) || is_product())) {
self::loadThemeWCStyleModule('single/product');
}
if ((isset(self::$theme_css_support['wc_account']) || isset(self::$theme_css_support['wc_register_form'])) && (isset(self::$wc_shortcode_type['account']) || is_account_page())) {
if (is_user_logged_in()) {
if(isset(self::$theme_css_support['wc_account'])){
self::loadThemeWCStyleModule('pages/account');
}
} elseif(isset(self::$theme_css_support['wc_register_form'])) {
self::loadThemeWCStyleModule('pages/register-form');
}
}
if (isset(self::$theme_css_support['wc_checkout']) && (isset(self::$wc_shortcode_type['checkout']) || is_checkout())) {
self::loadThemeWCStyleModule('pages/checkout');
}
if (isset(self::$theme_css_support['wc_cart']) && is_cart()) {
self::loadThemeWCStyleModule('pages/cart');
}
}
self::$wc_shortcode_type = null;
if (function_exists('themify_theme_enqueue_footer')) {
themify_theme_enqueue_footer();
}
if (is_rtl() && isset(self::$theme_css_support['rtl'])) {
self::add_css('theme-style-rtl', THEME_URI . '/rtl.css', null, self::$themeVersion);
}
themify_enqueue_framework_assets();
// Themify child base styling
if (is_child_theme()) {
$modified = filemtime(get_stylesheet_directory() . '/style.css');
if ($modified === false) {
$modified = '';
}
self::add_css('theme-style-child', get_stylesheet_uri(), null, self::$themeVersion . $modified);
}
// User stylesheet
$custom_css = get_template_directory() . '/custom_style.css';
if (is_file($custom_css)) {
$modified = filemtime($custom_css);
if ($modified === false) {
$modified = '';
}
self::add_css('custom-style', THEME_URI . '/custom_style.css', null, THEMIFY_VERSION . $modified);
}
unset($custom_css);
if (is_admin_bar_showing() && is_file(self::$THEME_CSS_MODULES_DIR . 'admin-bar.css')) {
self::loadThemeStyleModule('admin-bar', false, true);
}
if (class_exists('Themify_Builder',false) && Themify_Builder_Model::is_front_builder_activate() === true && is_file(self::$THEME_CSS_MODULES_DIR . 'builder-active.css')) {
self::loadThemeStyleModule('builder-active', false, true);
}
}
}
public static function wp_footer() {
if (!empty(self::$css['in_footer'])) {
foreach (self::$css['in_footer'] as $k => $v) {
$m = isset($v['m']) ? ' media="' . $v['m'] . '"' : '';
$href = $v['s'];
if (!empty($v['v'])) {
$href .= strpos($href, '?') === false ? '?' : '&';
$href .= 'ver=' . $v['v'];
}
?>
>>
self::$bufferLevel) {
ob_end_flush();
}
if (ob_get_level() === self::$bufferLevel) {
ob_end_flush();
}
}
private static function minify_concate_css_should_preserve_comment(string $inner):bool {
$inner = trim($inner);
if ($inner === '') {
return false;
}
if (preg_match('/^(.+\s+)?framework\s+[\w.+-]+$/i', $inner) === 1) {
return true;
}
if (preg_match('/\.css$/i', $inner) === 1) {
return true;
}
return false;
}
/**
* Strip block comments; leaves quoted strings unchanged (handles \\ escapes).
* Keeps theme/framework version and per-file path comments from getBuffer().
*/
private static function minify_concate_css_strip_comments(string $css):string {
$len = strlen($css);
$out = '';
for ($i = 0; $i < $len; $i++) {
$c = $css[$i];
if ($c === '"' || $c === "'") {
$q = $c;
$out .= $q;
for ($i++; $i < $len; $i++) {
$c = $css[$i];
$out .= $c;
if ($c === '\\' && $i + 1 < $len) {
$out .= $css[++$i];
continue;
}
if ($c === $q) {
break;
}
}
continue;
}
if ($c === '/' && $i + 1 < $len && $css[$i + 1] === '*') {
$commentStart = $i;
$innerStart = $i + 2;
for ($i += 2; $i < $len; $i++) {
if ($css[$i] === '*' && $i + 1 < $len && $css[$i + 1] === '/') {
$inner = substr($css, $innerStart, $i - $innerStart);
if (self::minify_concate_css_should_preserve_comment($inner)) {
$out .= substr($css, $commentStart, $i - $commentStart + 2);
}
$i++;
break;
}
}
continue;
}
$out .= $c;
}
return $out;
}
/**
* Compress whitespace and braces/semicolons in concatenated cache CSS.
*
* Only normalizes whitespace runs to a single space, then trims around { } ; — we do not
* strip spaces around :, commas, +, ~, or >. That keeps transition/animation/background/
* grid-template shorthands, !important, and multi-token values intact.
*
* Avoids stripping around > (child combinator): the same character appears in @container
* (width > 700px), @supports selector(...), and arbitrary custom-property values.
*
* Native CSS nesting (&) is unchanged by comment removal; avoid adding combinator-only
* regex passes without tracking parens/at-rules if minification is extended later.
*/
private static function minify_concate_css(string $css):string {
if ($css === '') {
return '';
}
if (strncmp($css, "\xEF\xBB\xBF", 3) === 0) {
$css = substr($css, 3);
}
$css = self::minify_concate_css_strip_comments($css);
if ($css === '') {
return '';
}
$quoted = array();
$css = preg_replace_callback(
'/"(?:\\\\.|[^\\\\"])*"|\'(?:\\\\.|[^\\\\\'])*\'/',
static function (array $m) use (&$quoted): string {
$quoted[] = $m[0];
return '##TFQ' . (count($quoted) - 1) . '##';
},
$css
);
if (!is_string($css)) {
return '';
}
$css = preg_replace('/\s+/', ' ', $css);
$css = preg_replace('/\s*{\s*/', '{', $css);
$css = preg_replace('/\s*;\s*/', ';', $css);
$css = preg_replace('/\s*}\s*/', '}', $css);
$css = trim($css);
for ($i = count($quoted) - 1; $i >= 0; $i--) {
$css = str_replace('##TFQ' . $i . '##', $quoted[$i], $css);
}
return $css;
}
private static function getBuffer(string $body):string{
$key = '';
$exist = $hasFonts = false;
self::$css = apply_filters('themify_main_concate', self::$css);
self::$css['mobile_concate'] = apply_filters('themify_mobile_concate', self::$css['mobile_concate']);
foreach (self::$css as $k => $v) {
if ($k !== 'in_footer' && $k !== 'mobile_concate') {
$key .= $k . $v['v'];
}
}
$output = '';
if ($key !== '') {
if (isset(self::$css['woocommerce-general']) && strpos($body, 'star-rating') !== false) {
self::addPreLoadMedia(dirname(self::$css['woocommerce-general']['s'],2) . '/fonts/star.woff', 'preload', 'font', null, null, 'high');
}
$isDevMode=themify_is_dev_mode() && (!class_exists('Themify_Builder_Model',false) || !Themify_Builder_Model::is_front_builder_activate());
if(self::$concateFile===null){
$isDevMode=true;
$exist=false;
$key='';
}
else{
$key .= implode('', array_keys(self::$css['mobile_concate']));
$key = crc32($key);
self::$concateFile .= 'themify-' . $key . '.css';
$exist = Themify_Filesystem::is_file(self::$concateFile);
$regenerate = false;
if ($exist === true) {
$regenerate = !apply_filters('themify_concate_css', !$isDevMode, self::$concateFile); //opposite logic for backward compatibility
$isDeleted = Themify_Filesystem::is_file(self::$concateFile . 'del');
$regenerate = $regenerate === true || $isDeleted === true;
if ($regenerate === true) {
if ($isDeleted === true) {
Themify_Filesystem::delete(self::$concateFile . 'del','f');
}
$exist = false;
}
unset($isDeleted);
}
}
if ($exist === false) {
if (!isset($str)) {
$str = '';
}
// Add theme and fw version
$theme_name = '';
$replace = array(THEMIFY_URI, home_url());
if (self::$themeVersion !== null) {
$theme = wp_get_theme();
$theme_name = (is_child_theme() ? $theme->parent()->Name : $theme->display('Name')) . ' ' . self::$themeVersion . ' ';
$replace[] = THEME_URI;
$theme = null;
}
$str = PHP_EOL . '/* ' . $theme_name . 'framework ' . THEMIFY_VERSION . ' */' . $str . PHP_EOL;
$str = '@charset "UTF-8";' . $str;
unset($theme_name);
if($isDevMode===true && self::$themeVersion!==null && (self::$concateFile===null || themify_is_concate_disabled())){
$key='';
}
foreach (self::$css as $k => $v) {
if ($k !== 'in_footer' && $k !== 'mobile_concate') {
$content = $key !== ''? Themify_Filesystem::get_file_content($v['s']) : null;
if (!empty($content)) {
$dir = dirname($v['s']);
$content = strtr($content,
array(
'@charset "UTF-8";'=>'',
'..'=>dirname($dir),
"url('fonts/"=>"url({'$dir}/fonts/",
"url('images/"=>"url('{$dir}/images/",
"url(fonts/"=>"url({$dir}/fonts/",
"url(images/"=>"url({$dir}/images/"
));
if ($k === 'woocommerce-general') {
$content = str_replace('@font-face{', '@font-face{font-display:swap;', $content);
}
if (isset($v['m'])) {
$content = '@media ' . $v['m'] . '{' . PHP_EOL . $content . PHP_EOL . '}';
}
$str .= PHP_EOL . '/*' . str_replace($replace, '', $v['s']) . '*/' . PHP_EOL . $content;
}
elseif (!Themify_Filesystem::get_file_content($v['s'], true)) {
$key = $str = '';
}
if (isset(self::$preLoadMedia[$k])) {
unset(self::$preLoadMedia[$k]);
}
$media = isset($v['m'])?' media="'.$v['m'].'"':'';
$output .= '' . "\n" . '' . "\n";
}
}
unset($content);
if (!empty(self::$css['mobile_concate'])) {
$media = 'screen and (max-width:' . self::$mobileMenuActive . 'px)';
$mobileStr = PHP_EOL . '/* START MOBILE MENU CSS */' . PHP_EOL . '@media ' . $media . '{';
foreach (self::$css['mobile_concate'] as $k => $v) {
$content = $key !== '' ? Themify_Filesystem::get_file_content($v) : null;
if (!empty($content)) {
$mobileStr .= PHP_EOL . '/*' . str_replace($replace, '', $v) . '*/' . PHP_EOL . trim($content);
} else {
$mobileStr = $key = '';
}
if (isset(self::$preLoadMedia[$k])) {
unset(self::$preLoadMedia[$k]);
}
$output .= '';
}
unset(self::$css['mobile_concate'], $content);
if ($mobileStr !== '') {
$mobileStr .= PHP_EOL . '}' . PHP_EOL . '/* END MOBILE MENU CSS */';
$str .= $mobileStr;
unset($mobileStr);
}
}
if ($key !== '' && (empty(self::$concateFile) || (($regenerate === true || !Themify_Filesystem::is_file(self::$concateFile))))) {
if (apply_filters('themify_minify_concate_css', !$isDevMode)) {
$str = self::minify_concate_css($str);
}
if(!file_put_contents(self::$concateFile.'tmp', $str) || Themify_Filesystem::rename(self::$concateFile.'tmp',self::$concateFile)===false){//tmp file need because file_put_contents isn't atomic(another process can read not ready file),locking file(LOCK_EX) is slow,that is why we are using rename(it is atomic)
$key = '';
Themify_Filesystem::delete(self::$concateFile.'tmp','f');
}
}
unset($str, $replace);
}
}
if ( true === apply_filters( 'themify_enable_lazyload', true ) ) {
$body = themify_make_lazy($body);
}
$path = self::getPreLoad();
if (self::$disableGoogleFontsLoad === null) {
$path.= self::loadGoogleFonts();
}
if ($key !== '') {
$upload_dir = themify_upload_dir();
$href = str_replace($upload_dir['basedir'], $upload_dir['baseurl'], self::$concateFile);
unset($upload_dir);
$path .= '';
} else {
$path .= $output.'';//need when dev mode is enabled
}
unset($output);
self::$concateFile = null;
if (strpos($body, 'fonts.googleapis.com') !== false) {
$path .= '';
}
if (strpos($body, '//www.youtube.com/embed') !== false) {
$path .= '';
}
if (strpos($body, '//player.vimeo.com/video') !== false) {
$path .= '';
}
if (themify_get('setting-ga_m_id', '', true) !== '' || strpos($body, 'googletagmanager.com') !== false) {
$path .= '';
}
if ( class_exists( 'TF_SV_Framework', false ) ) {
$path .= TF_SV_Framework::get_frontend_head_fragment();
}
if (self::$themeVersion !== null && ($custom_css = themify_get('setting-custom_css', false, true))) {
$path.='';
}
self::$css = self::$googleFonts = self::$preLoadMedia = $rep=array();
if(strpos($body,'')!==false){
$rep['']=self::loadIcons(false);
}
else{
$rep['