he peer's name // ] // ]; // $context = stream_context_create($options); // $file_contents = file_get_contents($remote_file, false, $context); // // Save the file locally. // if ($file_contents !== false) { // // Local path to save the downloaded file. // $local_file = wp_upload_dir()['basedir'] . '/' . $new_name; // file_put_contents($local_file, $file_contents); // return $local_file; // } // } catch (\Throwable $th) { // // throw $th; // } // return false; } public static function filterZipFile($zip, $zip_file_path) { // Temporary filtered ZIP path $filtered_zip_path = sys_get_temp_dir() . '/filtered.zip'; $filtered_zip = new \ZipArchive; if ($filtered_zip->open($filtered_zip_path, \ZipArchive::CREATE | \ZipArchive::OVERWRITE) === TRUE) { // Loop through all files in the archive for ($i = 0; $i < $zip->numFiles; $i++) { $filename = $zip->getNameIndex($i); $file_path = 'zip://' . $zip_file_path . '#' . $filename; // Get MIME type based on file extensioncm_f $file_mime = self::getMimeTypeByExtension($filename); // Additional JSON validation if ($file_mime === 'application/json' && !self::isJsonFile($file_path)) { $file_mime = 'text/plain'; // Fallback if not valid JSON } // Check if the file MIME type matches supported types $is_supported = false; foreach (KIRKI_SUPPORTED_MEDIA_TYPES as $types) { if (in_array($file_mime, $types)) { $is_supported = true; break; } } // Add the file to the filtered archive if supported if ($is_supported) { $file_contents = $zip->getFromIndex($i); $filtered_zip->addFromString($filename, $file_contents); } } $filtered_zip->close(); return $filtered_zip_path; } else { return false; } } // Helper function to get MIME type by file extension private static function getMimeTypeByExtension($filename) { $extension_to_mime = [ 'json' => 'application/json', 'jpg' => 'image/jpeg', 'jpeg' => 'image/jpeg', 'png' => 'image/png', 'gif' => 'image/gif', 'webp' => 'image/webp', 'svg' => 'image/svg+xml', 'pdf' => 'application/pdf', 'mp4' => 'video/mp4', 'ogg' => 'audio/ogg', 'lottie' => 'text/plain', 'mov' => 'video/quicktime', 'mp3' => 'audio/mpeg', 'wav' => 'audio/wav', // Add more extensions as needed ]; $ext = pathinfo($filename, PATHINFO_EXTENSION); return $extension_to_mime[strtolower($ext)] ?? 'application/octet-stream'; } // Helper function to validate JSON file content private static function isJsonFile($file_path) { $file_contents = @file_get_contents($file_path); $trimmed = trim($file_contents); return $trimmed[0] === '{' || $trimmed[0] === '['; } public static function is_remote_url($url) { // Parse the URL to get components $parsed_url = wp_parse_url($url); return isset($parsed_url['scheme']); } public static function is_element_accessible($access) { switch ($access) { case 'all': return true; // Accessible to everyone case 'guest': return !is_user_logged_in(); case 'logged-in': return is_user_logged_in(); // Accessible to any logged-in user case 'admin': // Administrators and Super Admins return current_user_can('manage_options'); case 'editor': // Editors, Admins, and Super Admins can see this return current_user_can('edit_pages'); case 'author': // Authors, Editors, Admins, etc. return current_user_can('publish_posts'); case 'subscriber': // Subscribers and EVERY logged-in user above them return current_user_can('read'); default: return false; // Safely hide if the access rule is unrecognized } } /** * Find symbol for post id using condition * it will find and return selected symbols html and css; * * @param string $type : symbol type. * @param string $post : post object. * @return symbol || bool(false) */ public static function find_symbol_for_this_page($type) { $all_symbols = Symbol::fetch_list(true, false); foreach ($all_symbols as $key => $symbol) { if (isset($symbol['setAs']) && $symbol['setAs'] === $type) { return $symbol; } } return false; } /** * Get Custom Header * it will find and return selected symbols html and css; * * @param string $type stymbol type header|footer. * @param string $html if true the function will return html otherwise return symbol object. * @return string|object custom section html or stymbol object. */ public static function get_page_custom_section($type, $html = true) { $show = apply_filters('kirki_show_custom_section_' . $type, true); if (!$show) { return ''; } $symbol = self::find_symbol_for_this_page($type); if (!$html) { return $symbol; } if (isset(self::$custom_sections[$type])) { return self::$custom_sections[$type]; } $s = self::isShowWPThemeHeaderFooter() ? '' : ' '; // this is for disableing theme header footer forcefully if is_show_wp_theme_header_footer is false if ($symbol) { $action = HelperFunctions::sanitize_text(isset($_GET['action']) ? $_GET['action'] : ''); $symbol_data = $symbol['symbolData']; $set_as = isset($symbol['setAs']) ? $symbol['setAs'] : ''; $post_id = self::get_post_id_if_possible_from_url(); $template_data = self::get_template_data_if_current_page_is_kirki_template(); if ($template_data) $post_id = $template_data['template_id']; $custom_page_data = self::get_custom_data_if_current_page_is_kirki_custom_post(); if ($custom_page_data) $post_id = $custom_page_data['post_id']; $is_page_symbol_disabled = get_post_meta($post_id, KIRKI_META_NAME_FOR_PAGE_HF_SYMBOL_DISABLE_STATUS, true); if (isset($is_page_symbol_disabled) && is_array($is_page_symbol_disabled) && isset($is_page_symbol_disabled[$type])) { $is_page_symbol_disabled = $is_page_symbol_disabled[$type]; } else { $is_page_symbol_disabled = false; } $params = array( 'blocks' => $symbol_data['data'], 'style_blocks' => $symbol_data['styleBlocks'], 'root' => $symbol_data['root'], 'post_id' => $symbol['id'], 'options' => [], 'get_style' => true, 'get_variable' => false, 'should_take_app_script' => false, 'prefix' => 'kirki-s' . $symbol['id'] ); if ($action === KIRKI_EDITOR_ACTION) { $extra_attr_for_hf_symbol = ''; if ($is_page_symbol_disabled) $extra_attr_for_hf_symbol = ' style="display:none;"'; $s = '<' . $type . $extra_attr_for_hf_symbol . ' data-kirki-symbol_set_as="' . $set_as . '" data-kirki-symbol="' . $symbol['id'] . '" data-kirki="' . $type . '">' . self::get_html_using_preview_script($params) . ''; //added data-kirki="$type" => We removed theme header and footer using preg_replace in TheFrontendHooks.php file } else if (!$is_page_symbol_disabled) { $params['should_take_app_script'] = true; $params['get_variable'] = true; $s = self::get_html_using_preview_script($params); } else if ($is_page_symbol_disabled) { $s = ''; } } $s = do_shortcode($s); self::$custom_sections[$type] = $s; return $s; } public static function isShowWPThemeHeaderFooter() { $common_data = WpAdmin::get_common_data(true); return $common_data['is_show_wp_theme_header_footer']; } /** * Check if a value is considered true or false. * * @param mixed $value The value to check. * @return bool Returns true if the value is considered "truthy", otherwise false. * * @deprecated * @see function \Kirki\App\is_truthy() */ public static function isTruthy($value): bool { return filter_var($value, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE) ?? false; } /** * Get the upload directory path has upload or write permission. * * @deprecated * @see Kirki\Framework\Supports\Facades\File::is_writable() * @see function Kirki\App\get_upload_directory() */ public static function get_upload_dir_has_write_permission() { if (!function_exists('request_filesystem_credentials')) { require_once ABSPATH . 'wp-admin/includes/file.php'; } if (WP_Filesystem()) { global $wp_filesystem; $upload_dir = wp_upload_dir(); return $wp_filesystem->is_writable($upload_dir['basedir']); } return false; } /** * $name = [] or string * @deprecated * @see Kirki\App\Supports\Template::add_prefix_to_class_name() */ public static function add_prefix_to_class_name($prefix, $name) { if (is_array($name)) { foreach ($name as $key => $c) { $c = strtolower($c); if (in_array($c, KIRKI_PRESERVED_CLASS_LIST)) { $name[$key] = $c; } else { $name[$key] = $prefix ? strtolower($prefix) . '-' . $c : $c; } } } else { $name = strtolower($name); if (!in_array($name, KIRKI_PRESERVED_CLASS_LIST)) { $name = $prefix ? strtolower($prefix) . '-' . $name : $name; } } return $name; } public static function checkVisibilityConditions($element, $options) { $conditions = $element['properties']['visibilityConditions'] ?? []; if (!count($conditions)) return true; foreach ($conditions as $and_group) { $and_result = true; foreach ($and_group as $condition) { $source = (string) ($condition['source'] ?? 'kirki'); $condition_result = apply_filters('kirki_visibility_condition_check_' . $source, false, $condition, $options); if (!$condition_result) { $and_result = false; break; // If any condition fails in AND group } } if ($and_result) { return true; // If any OR group passes } } return false; // No group passed } private static function update_slider_style_blocks($blocks, $styles) { $slider_mask_styleIds = []; $slider_item_styleIds = []; // slider_item foreach ($blocks as $id => $block) { // Check if the block has a 'name' key if (isset($block['name'])) { if (isset($block['name']) && $block['name'] === 'slider_mask') { // Loop through each item in $block['styleIds'] foreach ($block['styleIds'] as $styleId) { // Check if the styleId is NOT already in the $slider_mask_styleIds array if (!in_array($styleId, $slider_mask_styleIds)) { // If not present, push it into the array $slider_mask_styleIds[] = $styleId; } } } if (isset($block['name']) && $block['name'] === 'slider_item') { // Loop through each item in $block['styleIds'] foreach ($block['styleIds'] as $styleId) { // Check if the styleId is NOT already in the $slider_item_styleIds array if (!in_array($styleId, $slider_item_styleIds)) { // If not present, push it into the array $slider_item_styleIds[] = $styleId; } } } } } if (count($slider_mask_styleIds) > 0) { foreach ($slider_mask_styleIds as $styleId) { if ($styles[$styleId]) { $style = $styles[$styleId]; $style_variants = $style['variant']; $styleVariants = []; if ($style_variants && count($style_variants) > 0) { foreach ($style_variants as $key => $css) { $css = preg_replace('/overflow\s*:\s*hidden;?/', '', $css); $css = preg_replace('/pointer-events\s*:\s*none;?/', '', $css); $css = trim($css); $styleVariants[$key] = $css; } } $styles[$styleId]['variant'] = $styleVariants; } } } if (count($slider_item_styleIds) > 0) { foreach ($slider_item_styleIds as $styleId) { $style = $styles[$styleId]; $style_variants = $style['variant']; $styleVariants = []; if ($style_variants && count($style_variants) > 0) { foreach ($style_variants as $key => $css) { $css = preg_replace('/position\s*:\s*absolute;?/', '', $css); $css = preg_replace('/display\s*:\s*none;?/', '', $css); $css = trim($css); $styleVariants[$key] = $css; } $styles[$styleId]['variant'] = $styleVariants; } } } return $styles; } public static function handle_legacy_slider_class() { $data = Page::get_all_data_by_kirki_meta_key(); foreach ($data as $key => $value) { $post_id = $value['post_id']; // ID of the post $meta_key = $value['meta_key']; // Meta key name $meta_value = $value['meta_value']; // Serialized meta value $meta_value = unserialize($meta_value, ['allowed_classes' => false]); // Convert serialized data to array // If the meta value has a 'blocks' key, handle it as a full page data if (isset($meta_value['blocks'])) { $blocks = $meta_value['blocks']; // Get the blocks array $styles = self::get_page_styleblocks($post_id); $updated_styles = self::update_slider_style_blocks($blocks, $styles); // Update block names self::update_page_styleblocks($post_id, $updated_styles); } else { // If no 'blocks' key, treat entire value as blocks array $blocks = $meta_value; $post = get_post($post_id); if (isset($post->post_type) && $post->post_type === 'kirki_symbol') { $styles = $blocks['styleBlocks']; $updated_styles = self::update_slider_style_blocks($blocks['data'], $styles); $blocks['styleBlocks'] = $updated_styles; update_post_meta($post_id, $meta_key, $blocks); } } } } public static function handle_legacy_slider_default_class() { $styles = self::get_global_data_using_key(KIRKI_GLOBAL_STYLE_BLOCK_META_KEY); if (!$styles) { $styles = array(); } if (count($styles) > 0) { if (isset($styles['kirki_slider_slide'])) { // Handle kirki_slider_mask if (isset($styles['kirki_slider_mask'])) { $variants = $styles['kirki_slider_mask']['variant']; if (count($variants) > 0) { $styleVariants = []; foreach ($variants as $key => $css) { $css = preg_replace('/overflow\s*:\s*hidden;?/', '', $css); $css = preg_replace('/pointer-events\s*:\s*none;?/', '', $css); $css = trim($css); $styleVariants[$key] = $css; } $styles['kirki_slider_mask']['variant'] = $styleVariants; } } // Handle kirki_slider_slide if (isset($styles['kirki_slider_slide'])) { $variants = $styles['kirki_slider_slide']['variant']; if (count($variants) > 0) { $styleVariants = []; foreach ($variants as $key => $css) { $css = preg_replace('/position\s*:\s*absolute;?/', '', $css); $css = preg_replace('/display\s*:\s*none;?/', '', $css); $css = trim($css); $styleVariants[$key] = $css; } $styles['kirki_slider_slide']['variant'] = $styleVariants; } } } } } public static function get_current_item_index($index, $options) { $pagination = isset($options['pagination']) ? $options['pagination'] : false; $items_per_page = isset($options['items_per_page']) ? $options['items_per_page'] : 3; $page_no = isset($options['page_no']) ? $options['page_no'] : 1; if ($pagination && $items_per_page > 0 && $page_no > 0) { // Calculate the start index based on the current page and items per page $index = (($page_no - 1) * $items_per_page) + $index; } return $index; } public static function convertToBytes($val) { $val = trim($val); $last = strtolower($val[strlen($val) - 1]); $val = (int) $val; switch ($last) { case 'g': $val *= 1024; case 'm': $val *= 1024; case 'k': $val *= 1024; } return $val; } /** * @deprecated * @see Kirki\App\Supports\Canvas::get_full_canvas_template_path() */ public static function get_kirki_full_canvas_template_path() { return self::normalize_kirki_full_canvas_template_path(KIRKI_FULL_CANVAS_TEMPLATE_PATH); } /** * @deprecated * @see Kirki\App\Supports\Canvas::normalize_full_canvas_template_path() */ public static function normalize_kirki_full_canvas_template_path($path) { // replace if has kirki-pro => kirki if (strpos($path, 'kirki-pro') !== false) { $path = str_replace('kirki-pro', 'kirki', $path); } return $path; } public static function normalize_variable_mode($mode) { if (!$mode) { return ['color' => 'inherit', 'size' => 'inherit', 'text-style' => 'inherit', 'font-family' => 'inherit']; } // if v is string if (is_string($mode)) { return ['color' => $mode, 'size' => $mode, 'text-style' => $mode, 'font-family' => $mode]; } if (is_array($mode)) { return $mode; } return $mode; } /** * Whether the target url is a safe, externally reachable http(s) URL. * * Rejects loopback, private, link-local and cloud-metadata addresses so a * planted form config cannot be used to probe the server's own network. * * @param string $url The URL. * @return bool */ public static function is_safe_url($url) { if (!is_string($url) || filter_var($url, FILTER_VALIDATE_URL) === false) { return false; } $scheme = wp_parse_url($url, PHP_URL_SCHEME); $host = wp_parse_url($url, PHP_URL_HOST); if (!is_string($scheme) || !in_array(strtolower($scheme), array('http', 'https'), true)) { return false; } if (!is_string($host) || '' === $host) { return false; } if (filter_var($host, FILTER_VALIDATE_IP)) { return (bool) filter_var($host, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE); } $ip = gethostbyname($host); if (!filter_var($ip, FILTER_VALIDATE_IP) || $ip === $host) { return false; } return (bool) filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE); } }