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-.../classes
File: class-themify-builder-stylesheet.php
<?php
[0] Fix | Delete
[1] Fix | Delete
final class Themify_Builder_Stylesheet {
[2] Fix | Delete
[3] Fix | Delete
public static $generateStyles = array();
[4] Fix | Delete
private static $isLoaded = array();
[5] Fix | Delete
[6] Fix | Delete
/**
[7] Fix | Delete
* Constructor
[8] Fix | Delete
*
[9] Fix | Delete
* @access public
[10] Fix | Delete
* @param object Themify_Builder $builder
[11] Fix | Delete
*/
[12] Fix | Delete
public static function init() {
[13] Fix | Delete
if (themify_is_ajax()) {
[14] Fix | Delete
add_action('wp_ajax_tb_slider_live_styling', array(__CLASS__, 'slider_live_styling'), 10);
[15] Fix | Delete
add_action('wp_ajax_nopriv_tb_generate_on_fly', array(__CLASS__, 'save_builder_css'), 10);
[16] Fix | Delete
add_action('wp_ajax_tb_generate_on_fly', array(__CLASS__, 'save_builder_css'), 10);
[17] Fix | Delete
// Regenerate CSS Files
[18] Fix | Delete
add_action('wp_ajax_themify_regenerate_css_files_ajax', array(__CLASS__, 'regenerate_css_files_ajax'));
[19] Fix | Delete
} elseif (defined('THEMIFY_BUILDER_REGENERATE_CSS') && THEMIFY_BUILDER_REGENERATE_CSS !== false && current_user_can('manage_options')) {
[20] Fix | Delete
add_action('admin_head', array(__CLASS__, 'auto_regenerate_css'));
[21] Fix | Delete
}
[22] Fix | Delete
if (!is_admin()) {
[23] Fix | Delete
add_action('tf_load_styles', array(__CLASS__, 'load_styles'), 9); //10 is customizer
[24] Fix | Delete
}
[25] Fix | Delete
}
[26] Fix | Delete
[27] Fix | Delete
/**
[28] Fix | Delete
* Checks if the builder stylesheet exists and enqueues it.
[29] Fix | Delete
*
[30] Fix | Delete
* @since 2.2.5
[31] Fix | Delete
*
[32] Fix | Delete
* @return bool True if enqueue was successful, false otherwise.
[33] Fix | Delete
*/
[34] Fix | Delete
public static function enqueue_stylesheet(bool $return = false, ?int $post_id = null) {
[35] Fix | Delete
$isActive = Themify_Builder::$frontedit_active === true || Themify_Builder_Model::is_front_builder_activate();
[36] Fix | Delete
if (($isActive === false && isset(self::$isLoaded[$post_id])) || themify_is_rest()) {
[37] Fix | Delete
return false;
[38] Fix | Delete
}
[39] Fix | Delete
$stylesheet_path = self::get_stylesheet('basedir', $post_id);
[40] Fix | Delete
if (!self::is_readable_and_not_empty($stylesheet_path['url'])) {
[41] Fix | Delete
if (!is_admin() && !isset(self::$generateStyles[$post_id]) && !Themify_Filesystem::is_file(self::getTmpPath($stylesheet_path['url']))) {
[42] Fix | Delete
[43] Fix | Delete
self::$generateStyles[$post_id] = true;
[44] Fix | Delete
$post_data = ThemifyBuilder_Data_Manager::get_data($post_id);
[45] Fix | Delete
if (!empty($post_data)) {
[46] Fix | Delete
static $strucutre = null;
[47] Fix | Delete
if ($strucutre === null) {
[48] Fix | Delete
$strucutre = true;
[49] Fix | Delete
Themify_Builder_Component_Module::load_modules();
[50] Fix | Delete
themify_enque_script('tb_builder_js_style', THEMIFY_URI . '/js/generate-style.js', THEMIFY_VERSION, array('themify-main-script'));
[51] Fix | Delete
[52] Fix | Delete
add_filter('themify_google_fonts_full_list', '__return_true');
[53] Fix | Delete
//backward
[54] Fix | Delete
$styles = [];
[55] Fix | Delete
$modules=Themify_Builder_Component_Module::load_modules();
[56] Fix | Delete
foreach ($modules as $id => $c) {
[57] Fix | Delete
if (is_object($c)) {
[58] Fix | Delete
$styles[$id] = $c->get_form_settings();
[59] Fix | Delete
}
[60] Fix | Delete
}
[61] Fix | Delete
unset($modules);
[62] Fix | Delete
$jsonFiles = Themify_Builder_Component_Module::get_styles_json();
[63] Fix | Delete
wp_localize_script('tb_builder_js_style', 'ThemifyBuilderStyle', array(
[64] Fix | Delete
'builder_url' => THEMIFY_BUILDER_URI,
[65] Fix | Delete
'style_json' => $jsonFiles,
[66] Fix | Delete
'styles' => $styles,
[67] Fix | Delete
'gutters' => Themify_Builder_Model::get_gutters(),
[68] Fix | Delete
'points' => themify_get_breakpoints(),
[69] Fix | Delete
'nonce' => wp_create_nonce('tf_nonce'),
[70] Fix | Delete
'ajaxurl' => admin_url('admin-ajax.php'),
[71] Fix | Delete
'google' => themify_get_google_web_fonts_list(),
[72] Fix | Delete
'cf' => Themify_Custom_Fonts::get_list(),
[73] Fix | Delete
'cf_api_url' => Themify_Custom_Fonts::$api_url
[74] Fix | Delete
));
[75] Fix | Delete
remove_filter('themify_google_fonts_full_list', '__return_true');
[76] Fix | Delete
foreach ($jsonFiles as $f) {
[77] Fix | Delete
Themify_Enqueue_Assets::addPreLoadMedia($f, 'prefetch', 'json');
[78] Fix | Delete
}
[79] Fix | Delete
$styles = $jsonFiles = null;
[80] Fix | Delete
}
[81] Fix | Delete
$js_data = array('data' => $post_data);
[82] Fix | Delete
$gs = Themify_Global_Styles::used_global_styles($post_id);
[83] Fix | Delete
if (!empty($gs)) {
[84] Fix | Delete
$js_data['gs'] = $gs;
[85] Fix | Delete
}
[86] Fix | Delete
$custom_css = get_post_meta($post_id, 'tbp_custom_css', true);
[87] Fix | Delete
if (!empty($custom_css)) {
[88] Fix | Delete
$js_data['custom_css'] = $custom_css;
[89] Fix | Delete
}
[90] Fix | Delete
wp_localize_script('tb_builder_js_style', 'themify_builder_data_' . $post_id, $js_data);
[91] Fix | Delete
$gs = $post_data = $custom_css = null;
[92] Fix | Delete
TFCache::$stopCache = true;
[93] Fix | Delete
Themify_Builder::get_builder_stylesheet('', true);
[94] Fix | Delete
}
[95] Fix | Delete
}
[96] Fix | Delete
}
[97] Fix | Delete
elseif (!is_admin() || themify_is_ajax()) {
[98] Fix | Delete
$handler = pathinfo($stylesheet_path['url']);
[99] Fix | Delete
$handlerId = $handler['filename'];
[100] Fix | Delete
$version = filemtime($stylesheet_path['url']);
[101] Fix | Delete
$url = self::get_stylesheet('baseurl', $post_id);
[102] Fix | Delete
$url = themify_https_esc($url['url']);
[103] Fix | Delete
self::$isLoaded[$post_id] = array(
[104] Fix | Delete
'handler' => $handlerId,
[105] Fix | Delete
'url' => $url,
[106] Fix | Delete
'v' => $version
[107] Fix | Delete
);
[108] Fix | Delete
if ($return === true) {
[109] Fix | Delete
return self::$isLoaded[$post_id];
[110] Fix | Delete
} else {
[111] Fix | Delete
$fonts = self::getFonts($post_id);
[112] Fix | Delete
if (!empty($fonts)) {
[113] Fix | Delete
Themify_Enqueue_Assets::addGoogleFont($fonts);
[114] Fix | Delete
}
[115] Fix | Delete
// custom fonts
[116] Fix | Delete
$custom_fonts = Themify_Custom_Fonts::load_fonts($post_id);
[117] Fix | Delete
if (!empty($custom_fonts)) {
[118] Fix | Delete
echo '<style id="', $handlerId, '-cffonts">', $custom_fonts, '</style>', PHP_EOL;
[119] Fix | Delete
}
[120] Fix | Delete
unset($custom_fonts, $fonts);
[121] Fix | Delete
if ($isActive === true && Themify_Builder::$is_loop === true && $post_id != Themify_Builder::$builder_active_id) {
[122] Fix | Delete
echo '<link class="themify-builder-generated-css" id="', $handlerId, '" rel="stylesheet" href="', $url, '?ver=', $version, '" type="text/css">';
[123] Fix | Delete
}
[124] Fix | Delete
}
[125] Fix | Delete
return true;
[126] Fix | Delete
}
[127] Fix | Delete
return false;
[128] Fix | Delete
}
[129] Fix | Delete
[130] Fix | Delete
public static function load_styles() {
[131] Fix | Delete
foreach (self::$isLoaded as $post_id => $v) {
[132] Fix | Delete
if (Themify_Builder::$builder_active_id === $post_id && Themify_Builder_Model::is_front_builder_activate()) {
[133] Fix | Delete
continue;
[134] Fix | Delete
}
[135] Fix | Delete
\themify_enque_style($v['handler'], $v['url'], null, $v['v']);
[136] Fix | Delete
}
[137] Fix | Delete
self::$isLoaded = array();
[138] Fix | Delete
}
[139] Fix | Delete
[140] Fix | Delete
/**
[141] Fix | Delete
* This function check the CSS generated files version and if
[142] Fix | Delete
* it requires to update or not
[143] Fix | Delete
*/
[144] Fix | Delete
public static function auto_regenerate_css() {
[145] Fix | Delete
if (get_option('tb_css_version', false) !== THEMIFY_VERSION && Themify_Filesystem::is_dir(self::get_stylesheet_dir()) && 'finished' === self::regenerate_css_files()) {
[146] Fix | Delete
update_option('tb_css_version', THEMIFY_VERSION, false);
[147] Fix | Delete
}
[148] Fix | Delete
}
[149] Fix | Delete
[150] Fix | Delete
/**
[151] Fix | Delete
* Generate css file on the fly, if builder doesn't have style created an empty file,
[152] Fix | Delete
* which will help to detect there is no need to create css file.
[153] Fix | Delete
* @return void
[154] Fix | Delete
*/
[155] Fix | Delete
public static function save_builder_css(bool $echo = false) {
[156] Fix | Delete
check_ajax_referer('tf_nonce', 'nonce');
[157] Fix | Delete
if (!empty($_POST['bid'])) {
[158] Fix | Delete
$id = (int) $_POST['bid'];
[159] Fix | Delete
if (!empty($_FILES['css'])) {
[160] Fix | Delete
$data = file_get_contents($_FILES['css']['tmp_name']);
[161] Fix | Delete
}
[162] Fix | Delete
elseif (isset($_POST['css'])) {//don`t use empty
[163] Fix | Delete
if (isset($_POST['mode']) && $_POST['mode'] === 'gzip') {
[164] Fix | Delete
if (!function_exists('gzdecode')) {
[165] Fix | Delete
wp_send_json_error(__('gzdecode is disabled', 'themify'));
[166] Fix | Delete
}
[167] Fix | Delete
$data = gzdecode(base64_decode($_POST['css']));
[168] Fix | Delete
}
[169] Fix | Delete
else {
[170] Fix | Delete
$data = !empty($_POST['css']) ? stripslashes_deep($_POST['css']) : array();
[171] Fix | Delete
}
[172] Fix | Delete
}
[173] Fix | Delete
if (isset($data)) {
[174] Fix | Delete
if (is_string($data)) {
[175] Fix | Delete
$data = json_decode($data, true);
[176] Fix | Delete
} elseif (!is_array($data)) {
[177] Fix | Delete
$data = array();
[178] Fix | Delete
}
[179] Fix | Delete
$res = self::write_stylesheet($id, $data, !empty($_POST['custom_css']) ? stripcslashes($_POST['custom_css']) : '');
[180] Fix | Delete
$stylesheet_path = self::get_stylesheet('basedir', $id)['url'];
[181] Fix | Delete
$tmpFile=self::getTmpPath($stylesheet_path);
[182] Fix | Delete
if (!empty($res['css_file'])) {
[183] Fix | Delete
Themify_Filesystem::delete($tmpFile, 'f');
[184] Fix | Delete
}
[185] Fix | Delete
elseif (!Themify_Filesystem::is_file($stylesheet_path)) {
[186] Fix | Delete
Themify_Filesystem::put_contents($tmpFile, 'done');
[187] Fix | Delete
}
[188] Fix | Delete
echo json_encode($echo === true?$res:['success'=>1]);
[189] Fix | Delete
[190] Fix | Delete
if (!empty($_POST['images']) && is_user_logged_in()) {
[191] Fix | Delete
$images = json_decode(stripslashes_deep($_POST['images']), true);
[192] Fix | Delete
if (!empty($images) && is_array($images)) {
[193] Fix | Delete
foreach ($images as $img) {
[194] Fix | Delete
$ext=strtolower(strtok(pathinfo($img,PATHINFO_EXTENSION ),'?'));
[195] Fix | Delete
if($ext==='png' || $ext==='jpg' || $ext==='jpeg' || $ext==='webp' || $ext==='gif' ||$ext==='bmp' ){
[196] Fix | Delete
themify_get_image_size($img);
[197] Fix | Delete
themify_create_webp($img);
[198] Fix | Delete
}
[199] Fix | Delete
}
[200] Fix | Delete
}
[201] Fix | Delete
unset($images);
[202] Fix | Delete
}
[203] Fix | Delete
}
[204] Fix | Delete
}
[205] Fix | Delete
wp_die();
[206] Fix | Delete
}
[207] Fix | Delete
[208] Fix | Delete
/* Return tmp path of original file */
[209] Fix | Delete
[210] Fix | Delete
private static function getTmpPath(string $path): string {
[211] Fix | Delete
return str_replace('.css', '-tmp.css', $path);
[212] Fix | Delete
}
[213] Fix | Delete
[214] Fix | Delete
/**
[215] Fix | Delete
* Regenerate CSS files Ajax
[216] Fix | Delete
*
[217] Fix | Delete
*/
[218] Fix | Delete
public static function regenerate_css_files_ajax() {
[219] Fix | Delete
check_ajax_referer('tf_nonce', 'nonce');
[220] Fix | Delete
$type = !empty($_POST['all']) && is_multisite() ? 'all' : '';
[221] Fix | Delete
$result = self::regenerate_css_files($type);
[222] Fix | Delete
if ($result === 'finished') {
[223] Fix | Delete
Themify_Enqueue_Assets::clearConcateCss($type);
[224] Fix | Delete
wp_send_json_success();
[225] Fix | Delete
} else {
[226] Fix | Delete
wp_send_json_error($result);
[227] Fix | Delete
}
[228] Fix | Delete
}
[229] Fix | Delete
[230] Fix | Delete
/**
[231] Fix | Delete
* Find for old URLs in generated CSS files and regenerates them base on new URLs
[232] Fix | Delete
*
[233] Fix | Delete
*/
[234] Fix | Delete
public static function regenerate_css_files(string $type = ''): string {
[235] Fix | Delete
if (current_user_can('manage_options')) {
[236] Fix | Delete
$path = self::get_stylesheet_dir();
[237] Fix | Delete
$error = true;
[238] Fix | Delete
if ($type === 'all' && is_multisite()) {
[239] Fix | Delete
$generatedDir = '/themify-css/';
[240] Fix | Delete
$path = dirname($path, 2);
[241] Fix | Delete
if (strpos($path, '/blogs.dir/') !== false) {
[242] Fix | Delete
$path = dirname($path);
[243] Fix | Delete
$generatedDir = '/files' . $generatedDir;
[244] Fix | Delete
}
[245] Fix | Delete
$path = rtrim($path, '/') . '/';
[246] Fix | Delete
if (Themify_Filesystem::is_dir($path) && ($handle = opendir($path))) {
[247] Fix | Delete
$error = false;
[248] Fix | Delete
set_time_limit(0);
[249] Fix | Delete
while (false !== ($f = readdir($handle))) {
[250] Fix | Delete
if ($f !== '.' && $f !== '..') {
[251] Fix | Delete
$f = $path . $f . $generatedDir;
[252] Fix | Delete
if (Themify_Filesystem::is_dir($f) && !Themify_Filesystem::delete($f)) {
[253] Fix | Delete
$error = true;
[254] Fix | Delete
break;
[255] Fix | Delete
}
[256] Fix | Delete
}
[257] Fix | Delete
}
[258] Fix | Delete
closedir($handle);
[259] Fix | Delete
}
[260] Fix | Delete
} else {
[261] Fix | Delete
$error = Themify_Filesystem::is_dir($path) && !Themify_Filesystem::delete($path);
[262] Fix | Delete
}
[263] Fix | Delete
[264] Fix | Delete
return $error ? __('Something goes wrong. Please check the if the upload folder is writtable.') : 'finished';
[265] Fix | Delete
}
[266] Fix | Delete
return '';
[267] Fix | Delete
}
[268] Fix | Delete
[269] Fix | Delete
/**
[270] Fix | Delete
* Find for old URLs in generated CSS files and delete them
[271] Fix | Delete
*
[272] Fix | Delete
*/
[273] Fix | Delete
public static function remove_css_files(?int $post_id) {
[274] Fix | Delete
$css_file = self::get_stylesheet('basedir', $post_id)['url'];
[275] Fix | Delete
Themify_Filesystem::delete($css_file, 'f');
[276] Fix | Delete
Themify_Filesystem::delete(self::getTmpPath($css_file), 'f');
[277] Fix | Delete
}
[278] Fix | Delete
[279] Fix | Delete
/**
[280] Fix | Delete
* Write stylesheet file.
[281] Fix | Delete
*
[282] Fix | Delete
* @since 2.2.5
[283] Fix | Delete
*
[284] Fix | Delete
* @return array
[285] Fix | Delete
*/
[286] Fix | Delete
public static function write_stylesheet($style_id, $data, string $custom_css = ''):array {
[287] Fix | Delete
// Information about how writing went.
[288] Fix | Delete
[289] Fix | Delete
$results = array();
[290] Fix | Delete
$css = '';
[291] Fix | Delete
if (!empty($data)) {
[292] Fix | Delete
$breakpoints = themify_get_breakpoints();
[293] Fix | Delete
$fonts = array('fonts' => array(), 'cf_fonts' => array());
[294] Fix | Delete
$breakpoints = array('desktop' => '') + $breakpoints;
[295] Fix | Delete
if (!empty($data['gs'])) {
[296] Fix | Delete
$css .= '/*Builder GLOBAL CSS START*/' . PHP_EOL;
[297] Fix | Delete
if (!empty($data['gs']['used'])) {
[298] Fix | Delete
$css .= '/*GS: ' . $data['gs']['used'] . '*/' . PHP_EOL;
[299] Fix | Delete
unset($data['gs']['used']);
[300] Fix | Delete
}
[301] Fix | Delete
foreach ($breakpoints as $b => $bpoint) {
[302] Fix | Delete
if (!empty($data['gs'][$b])) {
[303] Fix | Delete
$styles = '';
[304] Fix | Delete
foreach ($data['gs'][$b] as $selector => $arr) {
[305] Fix | Delete
$styles .= $selector . '{' . implode('', $arr) . '}';
[306] Fix | Delete
if ($selector[0] === '@') {
[307] Fix | Delete
$styles .= '}';
[308] Fix | Delete
}
[309] Fix | Delete
$styles .= PHP_EOL;
[310] Fix | Delete
}
[311] Fix | Delete
if ($b !== 'desktop') {
[312] Fix | Delete
$max = is_array($bpoint) ? $bpoint[1] : $bpoint;
[313] Fix | Delete
$styles = PHP_EOL . sprintf('@media(max-width:%spx){', $max) . PHP_EOL . $styles . '}';
[314] Fix | Delete
}
[315] Fix | Delete
$css .= $styles;
[316] Fix | Delete
}
[317] Fix | Delete
}
[318] Fix | Delete
unset($data['gs']);
[319] Fix | Delete
$css .= '/*Builder GLOBAL CSS END*/' . PHP_EOL;
[320] Fix | Delete
}
[321] Fix | Delete
foreach ($breakpoints as $b => $bpoint) {
[322] Fix | Delete
if (!empty($data[$b])) {
[323] Fix | Delete
$styles = '';
[324] Fix | Delete
foreach ($data[$b] as $selector => $arr) {
[325] Fix | Delete
$styles .= $selector . '{' . implode('', $arr) . '}';
[326] Fix | Delete
if ($selector[0] === '@') {
[327] Fix | Delete
$styles .= '}';
[328] Fix | Delete
}
[329] Fix | Delete
$styles .= PHP_EOL;
[330] Fix | Delete
}
[331] Fix | Delete
if ($b !== 'desktop') {
[332] Fix | Delete
$max = is_array($bpoint) ? $bpoint[1] : $bpoint;
[333] Fix | Delete
$styles = PHP_EOL . sprintf('@media(max-width:%spx){', $max) . PHP_EOL . $styles . '}';
[334] Fix | Delete
}
[335] Fix | Delete
$css .= $styles;
[336] Fix | Delete
unset($data[$b]);
[337] Fix | Delete
}
[338] Fix | Delete
}
[339] Fix | Delete
foreach (array_keys($fonts) as $ftype) {
[340] Fix | Delete
if (!empty($data[$ftype])) {
[341] Fix | Delete
foreach ($data[$ftype] as $f => $w) {
[342] Fix | Delete
$v = 'fonts' === $ftype ? str_replace(' ', '+', $f) : $f;
[343] Fix | Delete
if (!empty($w)) {
[344] Fix | Delete
$v .= ':' . implode(',', $w);
[345] Fix | Delete
}
[346] Fix | Delete
$fonts[$ftype][] = $v;
[347] Fix | Delete
}
[348] Fix | Delete
}
[349] Fix | Delete
}
[350] Fix | Delete
if (!empty($data['bg']) && is_user_logged_in()) {
[351] Fix | Delete
$created = array();
[352] Fix | Delete
foreach ($data['bg'] as $bg) {
[353] Fix | Delete
if (!isset($created[$bg])) {
[354] Fix | Delete
$created[$bg] = true;
[355] Fix | Delete
themify_generateWebp($bg);
[356] Fix | Delete
}
[357] Fix | Delete
}
[358] Fix | Delete
$created = null;
[359] Fix | Delete
}
[360] Fix | Delete
}
[361] Fix | Delete
$data = null;
[362] Fix | Delete
self::remove_css_files($style_id);
[363] Fix | Delete
if (!empty($custom_css)) {
[364] Fix | Delete
$css .= '/*Builder Custom CSS START*/' . PHP_EOL . $custom_css . PHP_EOL . '/*Builder Custom CSS END*/';
[365] Fix | Delete
}
[366] Fix | Delete
unset($custom_css);
[367] Fix | Delete
if (!empty($css)) {
[368] Fix | Delete
$css_file = self::get_stylesheet('basedir', $style_id)['url'];
[369] Fix | Delete
$css = apply_filters('themify_builder_stylesheet_css', $css, $style_id, $css_file);
[370] Fix | Delete
$css = '/* Generated from ' . get_post_type($style_id) . ': ' . get_post_field('post_name', $style_id) . " */\r\n" . $css;
[371] Fix | Delete
$write = Themify_Filesystem::put_contents($css_file, $css);
[372] Fix | Delete
unset($css_file, $css);
[373] Fix | Delete
if ($write) {
[374] Fix | Delete
// Add information about writing.
[375] Fix | Delete
$tmp = self::get_stylesheet('baseurl', $style_id);
[376] Fix | Delete
$results['css_file'] = $tmp['url'];
[377] Fix | Delete
$results['write'] = $write;
[378] Fix | Delete
unset($tmp);
[379] Fix | Delete
// Save Fonts
[380] Fix | Delete
if (!empty($fonts)) {
[381] Fix | Delete
foreach (array_keys($fonts) as $ftype) {
[382] Fix | Delete
$option_key = 'fonts' === $ftype ? 'themify_builder_google_fonts' : 'themify_builder_cf_fonts';
[383] Fix | Delete
$builder_fonts = get_option($option_key);
[384] Fix | Delete
if (!empty($fonts[$ftype])) {
[385] Fix | Delete
$fonts[$ftype] = implode('|', $fonts[$ftype]);
[386] Fix | Delete
if (!is_array($builder_fonts)) {
[387] Fix | Delete
$builder_fonts = array();
[388] Fix | Delete
}
[389] Fix | Delete
if (isset($builder_fonts[$style_id])) {
[390] Fix | Delete
$builder_fonts[$style_id] = $fonts[$ftype];
[391] Fix | Delete
$entry_fonts = $builder_fonts;
[392] Fix | Delete
} else {
[393] Fix | Delete
$entry_fonts = array($style_id => $fonts[$ftype]) + $builder_fonts;
[394] Fix | Delete
}
[395] Fix | Delete
update_option($option_key, $entry_fonts);
[396] Fix | Delete
}
[397] Fix | Delete
elseif (isset($builder_fonts[$style_id])) {
[398] Fix | Delete
unset($builder_fonts[$style_id]);
[399] Fix | Delete
update_option($option_key, $builder_fonts);
[400] Fix | Delete
}
[401] Fix | Delete
}
[402] Fix | Delete
}
[403] Fix | Delete
} else {
[404] Fix | Delete
$results['write'] = esc_html__('Styles can`t be written.Please check permission of uploading folder', 'themify');
[405] Fix | Delete
}
[406] Fix | Delete
} else {
[407] Fix | Delete
// Add information about writing.
[408] Fix | Delete
$results['write'] = esc_html__('Nothing written. Empty CSS.', 'themify');
[409] Fix | Delete
}
[410] Fix | Delete
return $results;
[411] Fix | Delete
}
[412] Fix | Delete
[413] Fix | Delete
public static function get_stylesheet_dir(string $mode = 'basedir'):string {
[414] Fix | Delete
return \themify_upload_dir($mode) . '/themify-css';
[415] Fix | Delete
}
[416] Fix | Delete
[417] Fix | Delete
/**
[418] Fix | Delete
* Return the URL or the directory path for a template, template part or content builder styling stylesheet.
[419] Fix | Delete
*
[420] Fix | Delete
* @since 2.2.5
[421] Fix | Delete
*
[422] Fix | Delete
* @param string $mode Whether to return the directory or the URL. Can be 'basedir' or 'baseurl' correspondingly.
[423] Fix | Delete
* @param int $single ID of layout, layour part or entry that we're working with.
[424] Fix | Delete
*
[425] Fix | Delete
* @return string
[426] Fix | Delete
*/
[427] Fix | Delete
private static function get_stylesheet(string $mode = 'basedir', ?int $id = null):array {
[428] Fix | Delete
if ($id === null) {
[429] Fix | Delete
$id = Themify_Builder_Model::get_ID();
[430] Fix | Delete
}
[431] Fix | Delete
$path = self::get_stylesheet_dir($mode);
[432] Fix | Delete
if ('basedir' === $mode && !Themify_Filesystem::is_dir($path)) {
[433] Fix | Delete
wp_mkdir_p($path);
[434] Fix | Delete
}
[435] Fix | Delete
[436] Fix | Delete
/**
[437] Fix | Delete
* Filters the return URL or directory path including the file name.
[438] Fix | Delete
*
[439] Fix | Delete
* @param string $stylesheet Path or URL for the global styling stylesheet.
[440] Fix | Delete
* @param string $mode What was being retrieved, 'basedir' or 'baseurl'.
[441] Fix | Delete
* @param int $id ID of the template, template part or content builder that we're fetching.
[442] Fix | Delete
*
[443] Fix | Delete
*/
[444] Fix | Delete
return array('id' => $id, 'url' => apply_filters('themify_builder_get_stylesheet', "$path/themify-builder-$id-generated.css", $mode, $id));
[445] Fix | Delete
}
[446] Fix | Delete
[447] Fix | Delete
/**
[448] Fix | Delete
* Enqueues Google Fonts
[449] Fix | Delete
*
[450] Fix | Delete
* @since 2.2.6
[451] Fix | Delete
*/
[452] Fix | Delete
public static function getFonts(?int $post_id = null):array {
[453] Fix | Delete
if (!defined('THEMIFY_GOOGLE_FONTS') || THEMIFY_GOOGLE_FONTS !== false) {
[454] Fix | Delete
$entry_google_fonts = get_option('themify_builder_google_fonts');
[455] Fix | Delete
if (!empty($entry_google_fonts) && is_array($entry_google_fonts)) {
[456] Fix | Delete
$gsFonts = Themify_Global_Styles::used_global_styles($post_id);
[457] Fix | Delete
$gsFonts[] = array('id' => $post_id ? $post_id : Themify_Builder_Model::get_ID());
[458] Fix | Delete
$str = '';
[459] Fix | Delete
foreach ($gsFonts as $gs) {
[460] Fix | Delete
if (isset($entry_google_fonts[$gs['id']])) {
[461] Fix | Delete
$str .= '|' . $entry_google_fonts[$gs['id']];
[462] Fix | Delete
}
[463] Fix | Delete
}
[464] Fix | Delete
return explode('|', $str);
[465] Fix | Delete
}
[466] Fix | Delete
}
[467] Fix | Delete
return array();
[468] Fix | Delete
}
[469] Fix | Delete
[470] Fix | Delete
/**
[471] Fix | Delete
* Checks whether a file exists, can be loaded and is not empty.
[472] Fix | Delete
*
[473] Fix | Delete
* @since 2.2.5
[474] Fix | Delete
*
[475] Fix | Delete
* @param string $file_path Path in server to the file to check.
[476] Fix | Delete
*
[477] Fix | Delete
* @return bool
[478] Fix | Delete
*/
[479] Fix | Delete
private static function is_readable_and_not_empty(string $file_path = ''):bool {
[480] Fix | Delete
return empty($file_path) ? false : is_readable($file_path) && 0 !== filesize($file_path);
[481] Fix | Delete
}
[482] Fix | Delete
[483] Fix | Delete
public static function slider_live_styling():void {
[484] Fix | Delete
check_ajax_referer('tf_nonce', 'nonce');
[485] Fix | Delete
$bg_slider_data = json_decode(stripslashes($_POST['tb_background_slider_data']), true);
[486] Fix | Delete
$row_or_col = array(
[487] Fix | Delete
'styling' => array(
[488] Fix | Delete
'background_slider' => urldecode($bg_slider_data['shortcode']),
[489] Fix | Delete
'background_type' => 'slider',
[490] Fix | Delete
'background_slider_mode' => $bg_slider_data['mode'],
[491] Fix | Delete
'background_slider_speed' => $bg_slider_data['speed'],
[492] Fix | Delete
'background_slider_size' => $bg_slider_data['size'],
[493] Fix | Delete
)
[494] Fix | Delete
);
[495] Fix | Delete
Themify_Builder_Component_Row::do_slider_background($row_or_col, $bg_slider_data['type']);
[496] Fix | Delete
wp_die();
[497] Fix | Delete
}
[498] Fix | Delete
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function