Файловый менеджер - Редактировать - /home/kunzqhe/photostocker/wp-content/themes/themify-ultra/themify/themify-utils.php
Назад
<?php /* * ************************************************************************* * * ---------------------------------------------------------------------- * DO NOT EDIT THIS FILE * ---------------------------------------------------------------------- * * Copyright (C) Themify * * ---------------------------------------------------------------------- * * ************************************************************************* */ if (!defined('ABSPATH')) exit; // Exit if accessed directly /* Utilities /************************************************************************** */ function themify_clear_menu_cache() { global $wpdb; $wpdb->query("DELETE FROM $wpdb->options WHERE `option_name` LIKE ('_transient_tf_menu_%')"); return Themify_Storage::deleteByPrefix('tf_menu_'); } /////////////////////////////////////////// // Create ZIP Package /////////////////////////////////////////// function themify_create_zip($files = array(), $destination = "", $overwrite = false) {//deprecated use js for ceating this if (!class_exists('ZipArchive') || (!$overwrite && is_file($destination))) { return false; } $valid_files = array(); if (is_array($files)) { foreach ($files as $file) { if (is_file($file)) { $valid_files[] = $file; } } } if (!empty($valid_files)) { $zip = new ZipArchive(); $zip_opened = $overwrite ? $zip->open($destination, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE) : $zip->open($destination, ZIPARCHIVE::CREATE); if ($zip_opened !== true) { return false; } foreach ($valid_files as $file) { $zip->addFile($file, pathinfo($file, PATHINFO_BASENAME)); } $zip->close(); return is_file($destination); } else { return false; } } /** * Image Helper - Echoes themify_get_image * @param string $args Format string. */ function themify_image($args) { echo themify_get_image($args); } /** * Returns the post image, either from Themify Custom Panel fields or from WordPress Featured Image. * @param string|array $args Format string. * @return string String with <img> tag and optional content prepended and/or appended */ function themify_get_image($args) { global $themify; /** * List of parameters * @var array */ $defaults = array( 'src' => '', 'class' => '', 'style' => '', 'preload' => false, 'prefetch' => false, 'lazy_load' => true, 'is_slider' => false, 'disable_responsive' => false, 'w' => '', // width 'h' => '', // height 'before' => '', 'after' => '', 'alt' => '', 'title' => '', 'crop' => true, 'field_name' => 'post_image,image,wp_thumb,feature_image', 'urlonly' => false, 'image_size' => '', 'image_meta' => false, 'f_image' => false, 'attr' => array(), 'fallback' => ''//when there is no image ); if (is_string($args)) { $arr=array(); parse_str($args, $arr); $args=array(); foreach ($arr as $k => $v) { if ($v === 'true') { $args[$k] = true; } elseif ($v === 'false') { $args[$k] = false; } else { $args[$k] = $v; } } } $args = array_merge($defaults, $args); unset($defaults); /** * Post ID for single, query or archive views. * Page ID is stored separately in $themify->page_id. * @var string */ $post_id = get_the_ID(); /** * URL of the image to use * @var string */ $img_url = ''; /** * Image width * @var string */ $width = $args['w']; if ($width !== '') { $width = (int) $width; } /** * Image height * @var string */ $height = $args['h']; if ($height !== '') { $height = (int) $height; } $attachment_id = 0; $is_disabled = themify_is_image_script_disabled(); if (is_numeric($args['src'])) { $attachment_id = $args['src']; $img = wp_get_attachment_image_src($attachment_id, 'large'); $args['src'] = !empty($img[0]) ? $img[0] : ''; unset($img); } elseif ($args['fallback'] !== '' && empty($args['src']) && !has_post_thumbnail()) { $args['src'] = $args['fallback']; } if ($is_disabled === true) { // Use WP standard image sizes if (!empty($args['image_size'])) { // If image_size parameter is set $feature_size = $args['image_size']; } elseif (!empty($themify->image_size)) { // or if Themify::image_size is set $feature_size = $themify->image_size; } elseif (empty($themify->is_shortcode) && in_the_loop()) { // Main query area if (is_single()) { $feature_size = get_post_meta($post_id, 'feature_size', true); if (empty($feature_size) || 'blank' === $feature_size) { $feature_size = themify_get('setting-image_post_single_feature_size', null, true); } } elseif (!empty($themify->page_id) && !empty($themify->query_post_type) && themify_is_query_page()) { $feature_size = get_post_meta($themify->page_id, $themify->query_post_type . 'feature_size_page', true); if (empty($feature_size)) { $feature_size = null; } } elseif (is_archive() || is_tax() || is_search() || is_home()) { $feature_size = themify_get('setting-image_post_feature_size', null, true); } } if (!isset($feature_size) || 'blank' === $feature_size) { $feature_size = apply_filters('themify_global_feature_size', themify_get('setting-global_feature_size', 'large', true)); } if (!empty($args['src'])) { $attachment_id = themify_get_attachment_id_from_url($args['src']); if (!empty($attachment_id)) { $tmp = wp_get_attachment_image_src($attachment_id, $feature_size); if (!empty($tmp)) { $img_url = $tmp[0]; } unset($tmp); } } if ($img_url === '') { // Set URL to use for final output. $img_url = empty($args['src']) ? themify_image_url(false, $feature_size) : $args['src']; $img_url = trim($img_url); // Fix for showing feature_image when Themify Image Script is disabled if ('' === $img_url) { foreach (explode(',', $args['field_name']) as $field) { if ($img_url = get_post_meta($post_id, trim($field), true)) break; } } } } else { // Use Image Script if (empty($args['src'])) { if (has_post_thumbnail()) { $img_url = $width !== '' && $height !== '' ? ((int) get_post_thumbnail_id()) : get_the_post_thumbnail_url(); /* Image script works with thumbnail IDs as well as URLs, use ID which is faster */ } elseif ('attachment' === get_post_type()) { $img_url = wp_get_attachment_url($post_id); } else { foreach (explode(',', $args['field_name']) as $field) { if ($img_url = get_post_meta($post_id, trim($field), true)) { break; } } } } else { $img_url = $args['src']; } if ($height !== '' && 0 === ((int) $height )) { $height = 0; $args['crop'] = false; } /** filter $img_url before it goes off to themify_do_img for processing * */ $img_url = apply_filters('themify_get_image_before_do_img', $img_url, $width, $height, $args); // Set URL to use for final output. $temp = themify_do_img((empty($attachment_id) ? $img_url : $attachment_id), $width, $height, (bool) $args['crop']); $img_url = $temp['url']; if ($temp['width'] !== '' && $temp['height'] !== '') { $width = (int) $temp['width']; $height = (int) $temp['height']; } // Get title/alt text by attachment id if it was returned. if (!$attachment_id && isset($temp['attachment_id'])) { $attachment_id = $temp['attachment_id']; } } if ( $attachment_id ) { $attachment_id = themify_maybe_translate_object_id( $attachment_id ); } // No image was defined, parse content to find the first image. if (empty($img_url) && ($args['f_image'] || themify_check('setting-auto_featured_image', true) )) { $content = get_the_content(); $upload_dir = themify_upload_dir('baseurl'); foreach (array('img', 'embed', 'iframe') as $tag) { $count = substr_count($content, '<' . $tag); if ($count >= 1) { $start = strpos($content, '<' . $tag, 0); $pos = substr($content, $start); $end = strpos($pos, '>'); $temp = themify_prep_image(substr($pos, 0, $end + 1)); $src = $temp['src']; $parse = parse_url($src); if (!empty($parse['query'])) { $src = str_replace('?' . $parse['query'], '', $src); } $ext = strtolower(pathinfo($src, PATHINFO_EXTENSION)); if (strpos($temp['src'], '.') && ( $ext === 'jpg' || $ext === 'jpeg' || $ext === 'gif' || $ext === 'png' || $ext === 'webp' || $ext === 'apng')) { $auto_image_url = isset($temp['src']) ? $temp['src'] : ''; if(isset($temp['class'])){ $args['class'] .=' '.$temp['class']; } $args['alt'] = $temp['alt']; if ($is_disabled === true) { $img_url = themify_image_url(false, $feature_size, themify_get_attachment_id_from_url($auto_image_url, $upload_dir)); if (empty($img_url)) { $img_url = esc_url($auto_image_url); } } elseif ($temp = themify_do_img($auto_image_url, $width, $height, (bool) $args['crop'])) { $img_url = $temp['url']; } break; } } } unset($content,$upload_dir); } if (!empty($img_url)) { if(isset($temp['is_large']) && current_user_can( 'edit_post', $post_id )){ $args['class'].=' tf_large_img'; } else{ if ($args['preload'] !== false || $args['prefetch'] !== false) { Themify_Enqueue_Assets::addPreLoadMedia($img_url, $args['preload'] !== false ? 'preload' : 'prefetch'); } themify_generateWebp($img_url); } unset($temp); if ($args['urlonly']) { $out = $img_url; } else { // Build final image $out = '<img src="' . $img_url . '"'; if ($width !== '' && $width !== 0) { $out .= ' width="' . $width . '"'; } if ($height !== '' && $height !== 0) { $out .= ' height="' . $height . '"'; } if ($attachment_id != 0) { $args['class'] .= ' wp-post-image wp-image-' . $attachment_id; /* add attachment_id class to img tag */ } if ($args['class'] !== '') { $out .= ' class="' . trim($args['class']) . '"'; } if ($args['style'] !== '') { $out .= ' style="' . $args['style'] . '"'; } $title = ''; if (!empty($args['alt'])) { $out_alt = $args['alt']; } else { $out_alt = $attachment_id ? get_post_meta($attachment_id, '_wp_attachment_image_alt', true) : ''; if (!$out_alt) { $out_alt = !empty($args['title']) ? $args['title'] : ''; if (!$out_alt && $attachment_id) { $p = get_post($attachment_id); $out_alt = !empty($p)?$p->post_title:''; $p = null; } if (!$out_alt) { $out_alt = the_title_attribute('echo=0'); } $title = $out_alt; } } if ($title === '') { if (!empty($args['title'])) { $title = $args['title']; } elseif ($attachment_id) { $p = get_post($attachment_id); if (!empty($p)) { $title = $p->post_title; } $p = null; } } // Add title attribute only if explicitly set in $args if (!empty($title)) { $out .= ' title="' . esc_attr($title) . '"'; } if ($args['lazy_load'] === false || $args['lazy_load']==='eager' ) { $out .= ' data-tf-not-load="1"'; if($args['lazy_load']==='eager'){ $out.=' loading="eager" decoding="sync"'; } } if (!empty($args['attr'])) { foreach ($args['attr'] as $k => $v) { $out .= ' ' . $k . '="' . esc_attr($v) . '"'; } } if (!empty($out_alt)) { $out .= ' alt="' . esc_attr($out_alt) . '"'; } $out .= '>'; if ($attachment_id && $args['disable_responsive'] === false) { $out = function_exists('wp_filter_content_tags') ? wp_img_tag_add_srcset_and_sizes_attr($out,null,$attachment_id) // WP 5.5 : wp_make_content_images_responsive($out); } if (($args['is_slider'] === true || $themify->post_layout === 'slider') && $args['lazy_load'] === true) { $out = themify_make_lazy($out, false); } if ($args['image_meta'] == true) { $out .= "<meta itemprop=\"width\" content=\"{$width}\"><meta itemprop=\"height\" content=\"{$height}\"><meta itemprop=\"url\" content=\"{$img_url}\">" . $out; } $out = $args['before'] . $out . $args['after']; } } else { $out = ''; } return $out; } if (!function_exists('themify_edit_link')) { function themify_edit_link($title = '') { static $is = null; if ($is === null) { $is = is_user_logged_in() && (!class_exists('Themify_Builder_Model') || !Themify_Builder_Model::is_front_builder_activate()); } if ($is === true) { if ($title === '') { $title = __('Edit', 'themify'); } edit_post_link($title, '<span class="edit-button tf_edit_post_'.get_the_ID().'">[', ']</span>'); } } } if (!function_exists('themify_image_url')) { /** * Returns the featured image url * @param bool $echo Specify to echo or return the url * @param string $size The image size to return * @param null|int $attachment_id ID of image to load. * @return void|string */ function themify_image_url($echo = false, $size = 'full', $attachment_id = null) { $url = ''; if (has_post_thumbnail()) { $image = wp_get_attachment_image_src(get_post_thumbnail_id(), $size); $url = $image === false ? '' : $image[0]; } elseif ($attachment_id !== null) { $image = wp_get_attachment_image_src($attachment_id, $size); if ($image) { $url = $image[0]; } } $url = apply_filters('themify_image_url', $url); if ($echo) { echo esc_url($url); return ''; } else { return $url; } } } /** * Image Helper - Prep Image * @param $tag * @return array */ function themify_prep_image($tag) { $image = array('src' => '', 'alt' => '', 'title' => ''); preg_match_all('/(alt|title|src)=(("|\')[^("|\')]*("|\'))/i', $tag, $image_reg); foreach ($image_reg[0] as $attr) { parse_str($attr, $tempAttr); foreach ($tempAttr as $key => $val) { if (isset($image[$key])) { $image[$key] = str_replace(array('"', "'"), array('', ''), $val); } } } if (strpos($image['src'], 'youtube.com') !== false || strpos($image['src'], 'vimeo.com') !== false) { $image['src'] = themify_video_image($image['src']); } $image['src'] = preg_replace('/(-\d+x\d+)(?=\.\w{3,4})/', '', $image['src']); return $image; } /** * Vimeo / Youtube Thumbnail grab * * @param $url * * @return string */ function themify_video_image($url) { $image_url = parse_url($url); $return_url = ''; if ($image_url['host'] === 'www.youtube.com' || $image_url['host'] === 'youtube.com') { parse_str($image_url['query'], $query); if (!empty($query['v'])) { $id = $query['v']; } else { $path = explode('/', $image_url['path']); $id = $path[count($path) - 1]; } $return_url = 'https://img.youtube.com/vi/' . $id . '/hqdefault.jp'; } elseif ($image_url['host'] === 'www.vimeo.com' || $image_url['host'] === 'vimeo.com' || $image_url['host'] === 'player.vimeo.com') { parse_str($image_url['query'], $query); if (!empty($query['clip_id'])) { $id = $query['clip_id']; } else { $path = explode('/', $image_url['path']); $id = $path[(count($path) - 1)]; } $content = Themify_Filesystem::get_contents('https://vimeo.com/api/v2/video/' . $id . '.php'); if (!empty($content)) { $hash = themify_unserialize($content); if (!empty($hash[0])) { $return_url = $hash[0]["thumbnail_large"]; } } } return $return_url; } /** * Checks if a value referenced by $var exists in theme settings or post meta data. * @param $var * @return bool */ function themify_check($var, $data_only = false) { $val = themify_get($var, null, $data_only); return $val !== null && $val !== '' && $val !== 'off'; } /** * Returns a value referenced by $var checking in theme settings or post meta data. * @param $var * @return mixed */ function themify_get($var, $default = null, $data_only = false) { $data = themify_get_data(); if (isset($data[$var]) && $data[$var] !== '') { return $data[$var]; } elseif ($data_only !== true) { global $post; if (themify_is_shop() && !in_the_loop()) { $id = themify_shop_pageId(); } elseif (is_object($post)) { $id = $post->ID; } else { $id = false; } $val = ( $id !== false && $id !== 0 ) ? get_post_meta($id, $var, true) : ''; if ($val !== '') { return $val; } } return $default; } /** * Returns a value referenced by $meta,$var checking in theme settings or post meta data. * @param $meta - post meta * @param $var - theme settings * @param $default * @return mixed */ function themify_get_both($meta, $var, $default = null) { $val = themify_get($meta); if ($val === null || $val === 'default') { $val = themify_get($var, $default, true); } return $val; } /** * Get a color value, uses themify_get and sanitizes the value * * @return string */ function themify_get_color_both($meta, $var, $default = null) { $val = themify_get_color($meta); if ($val === null || $val === 'default') { $val = themify_get_color($var, $default, true); } return $val; } /** * Returns a value referenced by $meta,$var checking in theme settings or post meta data. * @param $meta - post meta * @param $var - theme settings * @return mixed */ function themify_check_both($meta, $var) { $val = themify_get($meta, null); if ($val === null || $val === 'default') { $val = themify_get($var, null, true); } return $val !== null && $val !== '' && $val !== 'off'; } function themify_shop_pageId() { static $id = null; if ($id === null) { if (themify_is_woocommerce_active()) { $id = wc_get_page_id('shop'); if ($id <= 0) {//wc bug, page id isn't from wc settings,the default should be page with slug 'shop' $page = get_page_by_path('shop'); $id = !empty($page) ? (int) $page->ID : false; } } else { $id = false; } } return $id; } /** * Get a color value, uses themify_get and sanitizes the value * * @return string */ function themify_get_color($var, $default = null, $data_only = false) { return themify_sanitize_hex_color(themify_get($var, $default, $data_only)); } /** * Sanitize a string to ensure it's valid hex color code * * @since 3.1.2 */ function themify_sanitize_hex_color($value) { if ( is_null( $value ) || false === $value ) { return $value; } $value = ltrim( $value, '#' ); /* match 3 to 6 hex digits */ if (preg_match('|^([A-Fa-f0-9]{3}){1,2}$|', $value)) { $value = '#' . $value; } return $value; } if (!function_exists('themify_get_image_sizes_list')) { /** * Return list of image sizes with labels for translation. * @param bool $nested * @return mixed|void * @since 1.6.8 */ function themify_get_image_sizes_list($nested = true) { $size_names = apply_filters('image_size_names_choose', array( 'thumbnail' => __('Thumbnail', 'themify'), 'medium' => __('Medium', 'themify'), 'large' => __('Large', 'themify'), 'full' => __('Original Image', 'themify') ) ); $out = array( array('value' => 'blank', 'name' => ''), ); foreach ($size_names as $size => $label) { $out[] = array('value' => $size, 'name' => $label); } return apply_filters('themify_get_image_sizes_list', $nested ? $out : $size_names, $nested); } } /** * Check if the site is using an HTTPS scheme and returns the proper url * @param String $url requested url * @return String * @since 1.1.5 */ function themify_https_esc($url = '') { if (is_ssl()) { $url = str_replace('http:', 'https:', $url); } return $url; } /** * Returns an array with the post types managed by Themify, * where the Themify Custom Panel is initialized. * Filterable using themify_post_types * @param Array $types additional post types * @return Array * @since 1.1.5 */ function themify_post_types($types = array()) { $defaults = array('post', 'page') + apply_filters('themify_specific_post_types', array( 'menu','slider','highlight', 'portfolio','testimonial','section'))+$types; if (themify_is_themify_theme() && themify_is_woocommerce_active() && is_file(THEME_DIR . '/admin/post-type-product.php')) { $defaults[] = 'product'; } return array_keys(array_flip(apply_filters('themify_post_types', $defaults))); } if (!function_exists('themify_options_module')) { /** * Returns list of <option> * @param array $options List of options * @param string $key * @param bool $associative * @param string $default * @return string * @since 1.3.5 */ function themify_options_module($options = array(), $key = '', $associative = true, $default = '') { $data = themify_get_data(); $sel = isset($data[$key]) ? $data[$key] : $default; $data = null; $output = ''; if (true === $associative) { foreach ($options as $option) { $output .= '<option ' . selected($option['value'], $sel, false) . ' value="' . esc_attr($option['value']) . '">' . esc_html($option['name']) . '</option>'; } } else { foreach ($options as $option) { $option = esc_attr($option); $selected = $sel === $option ? ' selected="selected"' : ''; $output .= '<option value="' . $option . '"' . $selected . '>' . esc_html($option) . '</option>'; } } return $output; } } if (!function_exists('themify_lightbox_vars_init')) { /** * Post Gallery lightbox/fullscreen and single lightbox definition * @return array Lightbox/Fullscreen galleries initialization parameters */ function themify_lightbox_vars_init() { $gallery_lightbox = themify_get('setting-gallery_lightbox', 'lightbox', true); // Lightbox default settings $overlay_args = array(); if (themify_check('setting-lightbox_content_images', true)) { $overlay_args['contentImagesAreas'] = '.post, .type-page, .type-highlight, .type-slider'; } if (themify_check('setting-lightbox_disable_share', true)) { $overlay_args['disable_sharing'] = true; } if ($gallery_lightbox === 'none') { $overlay_args['gallerySelector'] = ''; } $overlay_args = apply_filters('themify_gallery_plugins_args', $overlay_args); // sanitize contentImagesAreas, ensure it's a valid CSS selector if (isset($overlay_args['contentImagesAreas'])) { $overlay_args['contentImagesAreas'] = trim($overlay_args['contentImagesAreas'], ','); } $overlay_args['i18n'] = array( 'tCounter' => __('%curr% of %total%', 'themify'), ); return $overlay_args; } } if (!function_exists('themify_get_shortcode_template')) { /** * Returns markup * @param $posts * @param string $slug * @param string $name * @return mixed|void */ function themify_get_shortcode_template($posts, $slug = 'includes/loop', $name = 'index', $args = array()) { global $post, $themify, $ThemifyBuilder; Themify_Enqueue_Assets::loadGridCss($themify->post_layout); if (is_object($post)) $saved_post = clone $post; $isShortcode = isset($themify->is_shortcode) && $themify->is_shortcode === true; $themify->is_shortcode = true; // Add flag that template loop is in builder loop if (is_object($ThemifyBuilder)) { $isLoop = $ThemifyBuilder->in_the_loop === true; $ThemifyBuilder->in_the_loop = true; } // get_template_part, defined in wp-includes/general-template.php $templates = array(); if ('' !== $name) { $templates[] = "{$slug}-{$name}.php"; } $templates[] = "{$slug}.php"; $template_file = apply_filters('themify_get_shortcode_template_file', locate_template($templates, false, false), $slug, $name); $isSlider = $themify->post_layout === 'slider' || (isset($args['isSlider']) && $args['isSlider'] === true); ob_start(); if (!empty($template_file)) { $before = isset($args['before_post']) ? $args['before_post'] : ''; $after = isset($args['after_post']) ? $args['after_post'] : ''; foreach ($posts as $post) { setup_postdata($post); if ($isSlider === true) { echo '<div class="tf_lazy tf_swiper-slide">'; } echo $before; include $template_file; echo $after; if ($isSlider === true) { echo '</div>'; } } $posts = null; } if (isset($saved_post) && is_object($saved_post)) { $post = $saved_post; /** * WooCommerce plugin resets the global $product on the_post hook, * call setup_postdata on the original $post object to prevent fatal error from WC */ setup_postdata($saved_post); } // Add flag that template loop is in builder loop if (isset($isLoop)) { $ThemifyBuilder->in_the_loop = $isLoop; } $themify->is_shortcode = $isShortcode; return ob_get_clean(); } } if (!function_exists('themify_get_gallery_shortcode')) { /** * Get images from gallery shortcode * @return object */ function themify_get_gallery_shortcode($shortcode) { if ($shortcode) { preg_match('/\[gallery.*ids.*?=.(.*).\]/si', $shortcode, $ids); if (isset($ids[1])) { $ids = trim($ids[1], '\\'); $ids = trim($ids, '"'); $image_ids = explode(',', $ids); // Check if post has more than one image in gallery return get_posts(array( 'post__in' => $image_ids, 'post_type' => 'attachment', 'post_mime_type' => 'image', 'numberposts' => -1, 'no_found_rows' => true, 'cache_results' => false, 'update_post_term_cache' => false, 'update_post_meta_cache' => false, 'orderby' => themify_get_gallery_shortcode_params($shortcode, 'orderby', 'post__in'), 'order' => themify_get_gallery_shortcode_params($shortcode, 'order', 'ASC') )); } } return array(); } } if (!function_exists('themify_get_gallery_shortcode_params')) { /** * Get gallery shortcode options * @param $shortcode * @param $param */ function themify_get_gallery_shortcode_params($shortcode, $param = 'link', $default = '') { $pattern = '/\[gallery .*?(?=' . $param . ')' . $param . '=.([^\']+)./si'; preg_match($pattern, $shortcode, $out); $out = isset($out[1]) ? explode('"', $out[1]) : array(''); return $out[0] !== '' ? $out[0] : $default; } } function themify_get_additional_image_sizes($size = 'all', $default = false) { $allSizes = wp_get_additional_image_sizes(); if ($size === 'all') { return $allSizes; } return isset($allSizes[$size]) ? $allSizes[$size] : $default; } if (!function_exists('themify_get_all_terms_ids')) { /** * Returns all IDs from the given taxonomy * @param string $tax Taxonomy to retrieve terms from. * @return array $term_ids Array of all taxonomy terms * @since 1.5.6 */ function themify_get_all_terms_ids($tax = 'category') { if (!$term_ids = wp_cache_get('all_' . $tax . '_ids', $tax)) { $term_ids = get_terms(array('taxonomy'=>$tax, 'fields' => 'ids', 'get' => 'all')); wp_cache_add('all_' . $tax . '_ids', $term_ids, $tax); } return $term_ids; } } if (!function_exists('themify_is_touch')) { /** * According to what $check parameter specifies to check, returns true if it's a phone, tablet, or both. * @param string $check * @return mixed * @since 1.6.8 */ function themify_is_touch($check = 'all') { static $arr = array(); if (!isset($arr[$check])) { if (!class_exists('Themify_Mobile_Detect')) { require_once 'class-themify-mobile-detect.php'; } $detect = new Themify_Mobile_Detect(); $is_tablet = isset($arr['tablet']) ? $arr['tablet'] : $detect->isTablet(); $is_mobile = isset($arr['phone']) ? $arr['phone'] : (wp_is_mobile() || $detect->isMobile()); $arr = array( 'phone' => $is_mobile && !$is_tablet, 'tablet' => $is_tablet, 'all' => $is_mobile ); $detect = null; } return $arr[$check]; } } /** * Checks that status of the image script. * @return bool * @since 1.7.4 */ function themify_is_image_script_disabled() { static $is = null; if ($is === null) { $is = _wp_image_editor_choose() ? themify_check('setting-img_settings_use', true) : false; } return $is; } /** * Get demo cache dir * @return array */ function themify_get_cache_dir() { static $dir_info = null; if ($dir_info === null) { $upload_dir = themify_upload_dir(); $dir_info = array( 'path' => $upload_dir['basedir'] . '/themify/', 'url' => $upload_dir['baseurl'] . '/themify/' ); if (!is_file($dir_info['path'])) { wp_mkdir_p($dir_info['path']); } } return $dir_info; } /** * Uncompress GZip file * @param string $srcName * @param string $dstName */ function themify_uncompress_gzip($srcName, $dstName) { $sfp = gzopen($srcName, "rb"); if (!function_exists('WP_Filesystem')) { require_once( ABSPATH . 'wp-admin/includes/file.php' ); } WP_Filesystem(); global $wp_filesystem; $string = ''; while (!gzeof($sfp)) { $string .= gzgets($sfp, 8192); } $wp_filesystem->put_contents($dstName, $string, FS_CHMOD_FILE); gzclose($sfp); } if (!function_exists('themify_get_available_menus')) { /** * Returns available navigation menus. * * @since 1.9.5 * * @return array */ function themify_get_available_menus() { $out = array(array('name' => '', 'value' => '', 'selected' => true)); $menus = get_terms( array( 'taxonomy'=>'nav_menu', 'hide_empty' => false, )); if (!empty($menus) && !is_wp_error($menus)) { foreach ($menus as $menu) { $out[] = array('name' => $menu->name, 'value' => $menu->slug); } } return apply_filters('themify_get_available_menus', $out); } } /** * Returns true if the active theme is using Themify framework * * @since 2.2.5 * @return bool */ function themify_is_themify_theme() { static $is = null; if ($is === null) { $is = is_file(trailingslashit(get_template_directory()) . 'themify/themify-utils.php'); } return $is; } if (!function_exists('themify_is_woocommerce_active')) { /** * Checks if Woocommerce plugin is active and returns the proper value * @return bool * @since 1.4.6 */ function themify_is_woocommerce_active() { static $is = null; if ($is === null) { $plugin = 'woocommerce/woocommerce.php'; include_once( ABSPATH . 'wp-admin/includes/plugin.php' ); return is_plugin_active($plugin) // validate if $plugin actually exists, the plugin might be active however not installed. && is_file(trailingslashit(WP_PLUGIN_DIR) . $plugin); } return $is; } } /** * Calls is_shop() in a safe manner * * @note: this function should not be called before template_redirect. * * @since 2.9.0 * @return bool */ function themify_is_shop($pageId = false) { static $is = null; if ($is === null) { $is = themify_is_woocommerce_active(); if ($is === true) { $is = is_post_type_archive('product') || ($pageId > 0 && $pageId === themify_shop_pageId()); //don't use shop function will give error if ($is === false) { $shop_url = themify_get_shop_permalink(); //wc bug, page id isn't set from wc settings,the default should be page with slug 'shop' if ($shop_url !== '') { $current_url = 'http'; if (is_ssl()) { $current_url .= 's'; } $current_url .= '://'; if(isset($_SERVER['HTTP_HOST'])){ $current_url .= $_SERVER['HTTP_HOST']; }else{ $host=parse_url(home_url(),PHP_URL_HOST); if($host!==false){ $current_url.=$host; } unset($host); } $current_url .= strtok($_SERVER['REQUEST_URI'], '?'); $is = $current_url === $shop_url; } else { $is = false; } } } } return $is; } /** * Modified version of wp_parse_args which adds filters to modify the args * * @return array * @since 2.7.7 */ function themify_parse_args($args, $defaults = '', $filter_key = '') { // Setup a temporary array from $args if (is_object($args)) { $r = get_object_vars($args); } elseif (is_array($args)) { $r = & $args; } else { wp_parse_str($args, $r); } // Passively filter the args before the parse if (!empty($filter_key)) { $r = apply_filters('themify_before_' . $filter_key . '_parse_args', $r); } // Parse if (is_array($defaults)) { $r = array_merge($defaults, $r); } // Aggressively filter the args after the parse if (!empty($filter_key)) { $r = apply_filters('themify_after_' . $filter_key . '_parse_args', $r); } // Return the parsed results return $r; } /** * Display the Builder's backend editor in Themify Custom Panel * * @return null * @since 2.8.8 */ function themify_meta_field_page_builder() { do_action('themify_builder_metabox'); } /** * Get an array of key => value pairs and outputs them as HTML attributes * * @since 2.9.1 * @return string */ function themify_get_element_attributes($props) { $out = ''; foreach ($props as $k => $v) { $out .= ' ' . $k . '="' . esc_attr($v) . '"'; } return $out; } /** * Get contents of a file * * return string|bool */ function themify_get_file_contents($path) { if (!function_exists('WP_Filesystem')) { require_once( ABSPATH . 'wp-admin/includes/file.php' ); } WP_Filesystem(); global $wp_filesystem; if ($wp_filesystem->exists($path)) { return $wp_filesystem->get_contents($path); } return false; } /** * Get breakpoints settings * if it's framework return customizer breakpoints,else if it's builder plugin builder breakpoints * @since 3.0.0 * @return mixed array/int */ function themify_get_breakpoints($select = 'all', $max_min = false) { static $res = array(); if (($select === 'all' && empty($res)) || (empty($res[$select]))) { $breakpoints = array( 'tablet_landscape' => array(769, 1280), 'tablet' => array(681, 768), 'mobile' => 680 ); if ($max_min === true) { return $breakpoints; } foreach ($breakpoints as $bp => $value) { $v = themify_builder_get('setting-customizer_responsive_design_' . $bp, 'builder_responsive_design_' . $bp); if ('' != $v) { if (is_array($value)) { $res[$bp] = array(); $res[$bp][0] = $value[0]; $res[$bp][1] = (int) $v; } else { $res[$bp] = (int) $v; } } else { $res[$bp] = $value; } } $res['tablet'][0] = $res['mobile'] + 1; $res['tablet_landscape'][0] = $res['tablet'][1] + 1; } return 'all' === $select ? $res : $res[$select]; } /** * Unserialize data if it is serialized * * If PHP supports it disables unserializing PHP objects in order to prevent object injection. * * @param string $original Maybe unserialized original, if is needed. * @return mixed Unserialized data can be any type. */ function themify_maybe_unserialize($original) { if (is_serialized($original)) { // don't attempt to unserialize data that wasn't serialized going in return version_compare(PHP_VERSION, '7.0.0') >= 0?@unserialize($original, array('allowed_classes' => false)):@unserialize($original); } return $original; } /** * Display the post video * Must be used inside the loop * * @since 2.7.3 */ function themify_post_video($url = false, $echo = true) { $video_file = $url ? $url : themify_get('video_url'); $output = ''; if (!empty($video_file)) { if ('mp4' !== pathinfo($video_file, PATHINFO_EXTENSION)) { global $wp_embed; $output = $wp_embed->run_shortcode('[embed]' . $video_file . '[/embed]'); } else { $output = '<div class="post-video">'; $output .= do_shortcode('[video src="' . $video_file . '"]'); $output .= '</div>'; } } if ($echo === true) { echo $output; } else { return $output; } } function themify_get_embed($url,array $args){ $reg='#(vimeo\.com|youtu(be\.com|\.be|be))\/(video\/|embed\/|watch\?v=|v\/)?([A-Za-z0-9._%-]*)(\&\S+)?\/?([A-Za-z0-9._%-]*)(\&\S+)?#i'; preg_match($reg,$url,$m); if(!empty($m) && isset($m[1],$m[4])){ $type=($m[1]==='youtube.com' || strpos($m[1],'youtu')!==false)?'youtube':($m[1]==='vimeo.com' || strpos($m[1],'vimeo')?'vimeo':false); if($type!==false){ $id=$m[4]; $query_args=array(); if($type!=='youtube' && isset($m[6])){//h query argument should be first in vimeo $query_args['h'] = $m[6]; } $query_args+=array( 'pip'=>1, 'playsinline'=>1 ); $params=parse_url($url); if(!empty($params['query'])){ parse_str($params['query'], $output); unset($output['v']); $query_args+=$output; unset($output); } if($type==='youtube'){ $allow='accelerometer;encrypted-media;gyroscope;picture-in-picture;fullscreen'; $src='https://www.youtube'; if(!empty($args['privacy'])){ $src.='-nocookie'; } $query_args['autohide']=1; $query_args['border']=0; $query_args['wmode']='opaque'; if(!empty($args['start'])){ $query_args['start']=(float)$args['start']; } if(!empty($args['end'])){ $query_args['end']=(float)$args['end']; } if(!empty($args['branding'])){ $query_args['modestbranding']=1; } $src.='.com/embed/'.$id; } else{ $allow='fullscreen'; $src='https://player.vimeo.com/video/'.$id; if(!empty($args['start'])){ $src.='#t='.$args['start']; } elseif(!empty($params['fragment'])){ $src.='#'.$params['fragment']; } if(!empty($args['privacy'])){ $query_args['dnt']=1; } $query_args['badge']=$query_args['title']=$query_args['portrait']=0; } unset( $params, $query_args['modestbranding'], $query_args['controls'], $query_args['loop'], $query_args['auoplay'], $query_args['mute'], $query_args['muted'] ); if(!empty($args['hide_controls'])){ $query_args['controls']=0; } if(!empty($args['loop'])){ $query_args['loop']=1; if(!isset($query_args['playlist'])){ $query_args['playlist']=$id; } } if(!empty($args['autoplay'])){ $allow.=';autoplay'; $query_args['autoplay']=1; } if(!empty($args['muted'])){ if($type==='youtube'){ $query_args['mute']=1; } else{ $query_args['muted']=1; } } $lazy=!empty($args['disable_lazy'])?' data-no-script':''; $src.='?'.http_build_query($query_args); return '<iframe'.$lazy.' src="'.$src.'" allow="'.$allow.'" class="tf_abs tf_w tf_h"></iframe>'; } } return ''; } function themify_is_minify_enabled() { static $is = null; if ($is === null) { $is = ! ( ( defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ) || defined('THEMIFY_DISABLE_MIN') || themify_is_dev_mode() ); if ( $is === true ) { $is = function_exists('themify_builder_get') && themify_builder_get('setting-script_minification-min', 'performance-script_minification-min') === null; if ($is === false && function_exists('get_rocket_option')) { $is = get_rocket_option('minify_js') ? true : false; } } } return $is; } /** * Load/Check minified file is exist * * @return string/bool */ function themify_enque($url, $check = false, $cdn = true) { static $is = null; if ($is === null) { $is = themify_is_minify_enabled(); } $return = 0; if ($is === true) { $f = pathinfo($url); if (isset($f['extension']) && strpos($f['basename'], '.min.', 2) === false) { $name = $f['filename'] . '.min.' . $f['extension']; if (is_file(trailingslashit(WP_CONTENT_DIR) . trailingslashit(str_replace(WP_CONTENT_URL, '', $f['dirname'])) . $name)) { if ($check === true) { $return = 1; } else { $url = trailingslashit($f['dirname']) . $name; } } } } if ($check === true) { return $return; } if ($cdn === true && function_exists('get_rocket_cdn_url')) { /** * WP Rocket CDN * @link https://wp-rocket.me */ $url = get_rocket_cdn_url($url); } return $url; } function themify_enque_style($handle, $src = '', $deps = array(), $ver = false, $media = 'all', $in_footer = false) { Themify_Enqueue_Assets::add_css($handle, $src, $deps, $ver, $media, $in_footer); } function themify_enque_script($handle, $src = '', $ver = THEMIFY_VERSION, $deps = array(), $in_footer = true) { Themify_Enqueue_Assets::add_js($handle, $src, $deps, $ver, $in_footer); } if (!function_exists('themify_get_query_categories')) { function themify_get_query_categories() { global $themify; $taxes = $themify->query_category == '0' ? themify_get_all_terms_ids($themify->query_taxonomy) : explode(',', str_replace(' ', '', $themify->query_category)); if (empty($taxes) || is_wp_error($taxes)) { return array(); } return $taxes; } } /** * Returns the URL to the WooCommerce Shop page * * @return string * @since 4.5.7 */ function themify_get_shop_permalink() { static $link = null; if ($link === null) { $id = themify_shop_pageId(); $link = !empty($id) ? get_permalink($id) : ''; } return $link; } function themify_is_login_page() { static $is = null; if ($is === null) { global $pagenow; $is = !empty($pagenow) && in_array($pagenow, array('wp-login.php', 'wp-register.php'), true); } return $is; } function themify_is_ajax() { static $is = null; if ($is === null) { $is = defined('DOING_AJAX') || (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) === 'xmlhttprequest'); } return $is; } function themify_is_rest() { static $is = null; if ($is === null) { $is = (defined('REST_REQUEST') && REST_REQUEST) || strpos($_SERVER['REQUEST_URI'], '/wp-json/') !== false; } return $is; } function themify_is_lazyloading() { static $is = null; if ($is === null) { $is = !themify_builder_check('setting-disable-lazy', 'performance-disable-lazy', true); if ($is === true) { global $wp_customize; $is = !is_admin() && themify_is_ajax() === false && !isset($_GET['tf-scroll']) && !isset($_GET['post_in_lightbox']) && themify_is_prefetch_request() === false && (!class_exists('Themify_Builder') || !Themify_Builder_Model::is_front_builder_activate()) && !( $wp_customize instanceof WP_Customize_Manager && $wp_customize->is_preview()); if ($is === true) { $is = apply_filters('tf_lazy_enable', true); } } else { add_filter('wp_lazy_loading_enabled', '__return_false', 100); } } return $is; } function themify_make_lazy($html, $load = true) { if (isset($html) && (strpos($html, ' src=') !== false || strpos($html, '<audio') !== false)) { $hasLazy = themify_is_lazyloading(); static $isSafari = null; if ($isSafari === null) { //if there is any cache plugin and native lazy isn't check in themify settings,use js lazy load $isSafari = $hasLazy === true && false !== TFCache::get_cache_plugins() ? !themify_builder_check('setting-disable-lazy-native', 'performance-disable-lazy-native', true) : TFCache::is_safari(); } $isJsLazy = $load === false || $isSafari === true; //$load need for some modules,which should be init and than load images(e.g slider) $tags = array( 'img' => '<img.+?>', 'iframe' => '<iframe.+?>.*?<\/iframe>', 'audio' => '<audio.+?>.*?<\/audio>', 'video' => '<video.+?>.*?<\/video>' ); foreach ($tags as $k => $v) { if (strpos($html, '<' . $k) === false) { unset($tags[$k]); } } if(empty($tags)){ return $html; } if(isset($tags['img']) || isset($tags['iframe'])){//skip noscript img/iframe preg_match_all('/<noscript>.*?<\/noscript>/is', $html, $m); if (!empty($m[0])) { $search=$replace=array(); $m = !is_array($m[0]) ? array($m[0]) : $m[0]; foreach ($m as $item) { $orig=$item; $item=str_replace(array("\r".'src=', "\n".'src='),' src=',$item); if(strpos($item,' src=')!==false && strpos($item,'data-no-script')===false && (strpos($item,'<img')!==false || strpos($item,'<iframe')!==false)){ $search[]=$orig; $replace[]=str_replace(' src=',' data-no-script src=',$item); } } unset($m); if(!empty($search)){ $html = str_replace($search, $replace, $html); } } } $_WITHOUTLAZY_ = 2; $count =0; $stopLazy = $useJs = false; $reg = '/' . implode('|', $tags) . '/is'; $tags = array_keys($tags); $extCount = count($tags) - 1; preg_match_all($reg, $html, $matches); unset($reg); if (!empty($matches[0])) { $search=$replace=array(); $matches = !is_array($matches[0]) ? array($matches[0]) : $matches[0]; foreach ($matches as $item) { if (!empty($item) && strpos($item, 'data-lazy', 4) === false && strpos($item, 'data-tf-src', 4) === false && strpos($item, 'data-no-script', 4) === false && strpos($item, 'data:image/', 4) === false && strpos($item, 'display:none', 4) === false && strpos($item,'application/x-mpegURL',4)===false && strpos($item, 'display: none', 4) === false && ($count!==0 || strpos($item, 'gravatar.com', 4) === false)) { if(strpos($item, 'data-tf-not-load', 4) === false){ for ($i = $extCount; $i > -1; --$i) { if (strpos($item, '<' . $tags[$i]) !== false) { $ext = $tags[$i]; break; } } if (!isset($ext)) { continue; } $orig = $item; $item = preg_replace('/\s+/', ' ', $item); if ($ext !== 'audio') { preg_match('/ src=["\']([^"]+?)["\']/', $item, $image_src); } if ($ext === 'audio' || $ext === 'video' || !empty($image_src[1])) { $url = $ext === 'audio' ? true : (isset($image_src[1])?trim($image_src[1]):''); unset($image_src); if($url === '' && $ext === 'video'){ $url=true; } if ($url !== '') { if($url!==true && $url[0]==='{'){ continue; } if ($ext === 'img' && strpos($item,'tf_large_img')===false) {//skip large images converting,otherwise can crash the site themify_generateWebp($url); if (strpos($item, ' srcset', 4) !== false) { preg_match('/ srcset=["\']([^"]+?)["\']/', $item, $srcset); if (!empty($srcset[1])) { themify_generate_srcset_webp($srcset[1]); } if($count>1){ $srcset = null; } } if (strpos($item, ' data-src', 4) !== false) { preg_match('/ data-src=["\']([^"]+?)["\']/', $item, $s); if (!empty($s[1])) { themify_generateWebp($s[1]); } if($count===1){ if(!empty($srcset)){ $srcset=$srcset[1]; preg_match('/sizes=["\']([^"]+?)["\']/', $item, $sizes); $sizes=!empty($sizes)?$sizes[1]:null; } else{ $sizes=$srcset=null; } Themify_Enqueue_Assets::addPreLoadMedia($url, 'preload', 'image',$srcset,$sizes,'high'); //load the first images in the page with preload for fast LCP $sizes=$srcset=null; } $s = null; } } if (strpos($item, 'data-src', 4) !== false || ($hasLazy === false && $ext !== 'audio' && $ext !== 'video')) { continue; } $s = ''; if ($ext === 'audio' || $ext === 'video') { $s = ' data-lazy="1"'; if (strpos($item,'preload="none"', 6) === false) { $s .= ' preload="none"'; $item = str_replace(array('preload="auto"', 'preload="metadata"'), '', $item); } } else { if ($load === false) { $stopLazy = false; $useJs = true; } else { $stopLazy = $count < $_WITHOUTLAZY_; /* skip the first $_WITHOUTLAZY_ matches, assume they're above the fold */ $useJs = $count>9; ++$count; } if ($ext === 'iframe') { if ($stopLazy === false) { if (strpos($item, ' loading=', 6) === false) { $s .= ' loading="lazy"'; } if ($isJsLazy === true) { $s .= ' data-lazy="1" src="about:blank"'; $class = 'tf_iframe_lazy'; if (strpos($item, 'class=', 6) === false) { $s .= ' class="' . $class . '"'; } else { $item = str_replace(' class="', ' class="' . $class . ' ', $item); } $item = strtr($item, array(' src=' => ' data-tf-src=')); } } else { $s .= ' data-tf-not-load="1"'; } } elseif ($ext === 'img') { $placeholder = themify_get_placeholder($url, $count < 15); if ($stopLazy === false) { $useJs = $isJsLazy === true || $useJs === true; if ($placeholder === false) { $placeholder = array( 's' => 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7' ); } elseif (strpos($item, ' loading=', 4) === false) { $s .= ' loading="lazy"'; } if ($useJs === true) { $s .= ' data-lazy="1"'; $class = 'tf_svg_lazy'; if (strpos($item, ' class=', 4) === false) { $s .= ' class="' . $class . '"'; } else { $item = str_replace(' class="', ' class="' . $class . ' ', $item); } $item = strtr($item, array(' srcset=' => ' data-tf-srcset=', ' sizes=' => ' data-tf-sizes=', ' src=' => ' data-tf-src=')); //sizes need to be replaced to pass html validation $s = ' src="' . $placeholder['s'] . '"' . $s; } } else{ $s .= ' data-tf-not-load="1"'; if($count===1){ if (strpos($s, 'fetchpriority=') === false) { $s .= ' fetchpriority="high"'; } $s.=' loading="auto" decoding="sync"'; if(!empty($srcset)){ $srcset=$srcset[1]; preg_match('/sizes=["\']([^"]+?)["\']/', $item, $sizes); $sizes=!empty($sizes)?$sizes[1]:null; } else{ $sizes=$srcset=null; } Themify_Enqueue_Assets::addPreLoadMedia($url, 'preload', 'image',$srcset,$sizes,'high'); //load the first images in the page with preload for fast LCP $sizes=$srcset=null; } } if (strpos($item, ' decoding=', 4) === false) { $s .= ' decoding="async"'; } if (isset($placeholder['w'])) { if (strpos($item, ' width=', 4) === false) { $s .= ' width="' . $placeholder['w'] . '"'; } if (strpos($item, ' height=', 4) === false) { $s .= ' height="' . $placeholder['h'] . '"'; } } unset($placeholder); } } $item = str_replace('<' . $ext, '<' . $ext . $s, $item); if ($ext === 'audio' || $ext === 'video') { $c = 'tf_lazy tf_' . ($ext==='video'?'vd':$ext) . '_lazy tf_w tf_rel tf_box'; $r=array(); if ($ext === 'video') { $c .= ' tf_rel tf_overflow'; themify_get_icon('fas volume-mute', 'fa'); themify_get_icon('fas volume-up', 'fa'); //themify_get_icon('fas undo', 'fa'); //themify_get_icon('fas redo', 'fa'); //themify_get_icon('far closed-captioning', 'fa'); themify_get_icon('fas external-link-alt', 'fa'); themify_get_icon('fas airplay', 'fa'); themify_get_icon('fas expand', 'fa'); themify_get_icon('fas download', 'fa'); if(strpos($item,' poster')!==false){ $r[' poster']=' data-poster'; } if($url && $url!==true && strpos($item,' width')===false || strpos($item,' height')===false){ $size=themify_get_video_size($url); if($size!==false){ $sv=''; if($size['w']!=='' && strpos($item,' width')===false){ $sv=' width="'.$size['w'].'"'; } if($size['h']!=='' && strpos($item,' height')===false){ $sv.=' height="'.$size['h'].'"'; } if($sv!==''){ $r[' preload']=$sv.' preload'; } $sv=null; } } } if(strpos($item,' autoplay')!==false){ $r[' autoplay']=' data-autoplay'; } if(!empty($r)){ $item = strtr($item,$r); } unset($r); $item = '<div class="' . $c . '">' . $item . '</div>'; $c=null; } $part = $item; if ($ext === 'img' && $stopLazy === false && $useJs === true) { $part .= '<noscript>' . strtr($orig, array(' src=' => ' data-tf-not-load src=')) . '</noscript>'; } $search[]=$orig; $replace[]=$part; } } } else{ ++$count; } } } unset($matches, $tags,$extCount); $html = str_replace($search, $replace, $html); } } return $html; } function themify_generate_srcset_webp($srcset) { $srcset = trim($srcset); if (!empty($srcset)) { $srcset = explode(',', $srcset); foreach ($srcset as $s) { $s = explode(' ', trim($s)); $s = trim($s[0]); if ($s !== '' && strpos($s, 'data:image') === false) { themify_generateWebp($s); } } } } function themify_upload_dir($mode = 'all',$reinit=false) { static $dir = null; if ($dir === null || $reinit === true) { $dir = wp_get_upload_dir(); /* foolproof the paths, in case they mistakenly have trailing slash */ $dir = array_map('untrailingslashit', $dir); $dir['baseurl'] = themify_https_esc($dir['baseurl']); } return $mode==='all'?$dir:$dir[$mode]; } function themify_generateWebp($url) { if (empty($url)) { return $url; } static $is = null; if ($is === null) { $is = !themify_builder_check('setting-webp', 'performance-webp', true) ? true : (is_admin() && !themify_is_ajax()); } if ($is === true) { return $url; } return themify_create_webp($url); } function themify_is_prefetch_request() { static $is = null; if ($is === null) { if (isset($_SERVER['HTTP_PURPOSE'])) { $prev = 'HTTP_PURPOSE'; } elseif (isset($_SERVER["HTTP_X_PURPOSE"])) { $prev = 'HTTP_X_PURPOSE'; } elseif (isset($_SERVER['HTTP_X_MOZ'])) { $prev = 'HTTP_X_MOZ'; } else { $prev = false; } if ($prev !== false) { $prev = strtolower($_SERVER[$prev]); $is = $prev === 'prefetch' || $prev === 'preview'; } else { $is = false; } } return $is; } function themify_is_dev_mode() { static $is = null; if($is===null){ $is=themify_check('setting-dev-mode', true) || (defined('THEMIFY_DEV') && THEMIFY_DEV); $is=apply_filters('themify_dev_mode',$is); } return $is; } function themify_is_concate_disabled(){ return themify_is_dev_mode() && (themify_check('setting-dev-mode-concate',true) || (defined('THEMIFY_DEV') && THEMIFY_DEV)); } function themify_disable_other_lazy() { add_filter('wp_lazy_loading_enabled', '__return_false', 100); add_filter('lazyload_is_enabled', '__return_false', 1, 100); //disable jetpack lazy load add_filter('rocket_use_native_lazyload', '__return_false', 1, 100); } function themify_get_server() { static $is = null; if ($is === null) { $is = 'apache'; if (!empty($_SERVER['SERVER_SOFTWARE'])) { $is = explode('/', $_SERVER['SERVER_SOFTWARE']); $is = str_replace('microsoft-', '', strtolower($is[0])); } elseif (is_file(get_home_path() . 'web.config')) { $is = 'iis'; } elseif (!is_file(Themify_Enqueue_Assets::getHtaccessFile()) || is_file('/etc/nginx/nginx.conf')) { $is = 'nginx'; } } return $is; } /** * Help tooltip Module * * @return string */ function themify_help($content) { return sprintf('<span class="tf_help"><i tabindex="-1" class="icon" onclick="return false;">%s</i><span class="tf_help_content">%s</span></span>', themify_get_icon('ti-help', 'ti'), $content ); } /** * Search $subject for $search and replace the first occurrence of it. * * @return string */ function themify_str_replace_first($search, $replace, $subject) { return implode($replace, explode($search, $subject, 2)); } /** * Search $subject for $search and replace the last occurrence of it. * * @return string */ function themify_str_replace_last($search, $replace, $subject) { if (( $pos = strrpos($subject, $search) ) !== false) { $subject = substr_replace($subject, $replace, $pos, strlen($search)); } return $subject; } /** * Gets the ID of an object (post or term) and returns that object ID in current language. * * @return int|mixed */ function themify_maybe_translate_object_id($id, $type = 'page') { if (!empty($id)) { if (defined('ICL_SITEPRESS_VERSION')) { $id = apply_filters('wpml_object_id', $id, $type, true); } elseif (defined('POLYLANG_VERSION') && function_exists('pll_get_post')) { $translatedpageid = pll_get_post($id); if (!empty($translatedpageid) && 'publish' === get_post_status($translatedpageid)) { $id = $translatedpageid; } } } return $id; } /** * Returns and caches URL to the homepage, properly filtered for multilingual setups * * @return string */ function themify_home_url() { static $url = null; if ($url === null) { $url = function_exists('pll_home_url')?pll_home_url():home_url(); } return $url; } /** * Download file from external URL and returns the file * * @param $post_id Attachments may be associated with a parent post or page. * * @return WP_Error|int ID of created attachment, or WP_Error */ function tf_fetch_remote_file( $url, $post_id = null, $title = '' ) { // extract the file name and extension from the url $file_name = basename( $url ); // get placeholder file in the upload dir with a unique, sanitized filename $upload = wp_upload_bits( $file_name, 0, '' ); if ( $upload['error'] ) return new WP_Error( 'upload_dir_error', $upload['error'] ); // fetch the remote url and write it to the placeholder file $remote_response = wp_safe_remote_get( $url, array( 'timeout' => 300, 'stream' => true, 'filename' => $upload['file'], ) ); $headers = wp_remote_retrieve_headers( $remote_response ); // request failed if ( ! $headers ) { @unlink( $upload['file'] ); return new WP_Error( 'import_file_error', __('Remote server did not respond', 'themify') ); } $remote_response_code = wp_remote_retrieve_response_code( $remote_response ); // make sure the fetch was successful if ( $remote_response_code != '200' ) { @unlink( $upload['file'] ); return new WP_Error( 'import_file_error', sprintf( __('Remote server returned error response %1$d %2$s', 'themify'), esc_html( $remote_response_code ), get_status_header_desc( $remote_response_code ) ) ); } $filesize = filesize( $upload['file'] ); if ( 0 == $filesize ) { @unlink( $upload['file'] ); return new WP_Error( 'import_file_error', __('Zero size file downloaded', 'themify') ); } $post = array( 'post_title' => $title, 'post_content' => '', 'post_status' => 'inherit', ); if ( $info = wp_check_filetype( $upload['file'] ) ) $post['post_mime_type'] = $info['type']; else return new WP_Error( 'mime_type_error', __('Invalid file type', 'themify') ); $attach_id = wp_insert_attachment( $post, $upload['file'], $post_id ); wp_update_attachment_metadata( $attach_id, wp_generate_attachment_metadata( $attach_id, $upload['file'] ) ); return $attach_id; } /** * Mimics get_template_part but loads a template from THEMIFY_DIR * * @since 5.5.3 */ function themify_get_template( $slug, $name = '', $args = array() ) { $base_dir = THEMIFY_DIR; $templates = array(); $located = ''; if ($name!==null && '' !== $name) { $templates[] = "{$base_dir}/{$slug}-{$name}.php"; } $templates[] = "{$base_dir}/{$slug}.php"; foreach ( $templates as $template ) { if ( is_file( $template ) ) { $located = $template; break; } } if ( $located!=='' ) { load_template( $located, false, $args ); } } /* Add category id class in post loop for Masonry filter */ if ( ! function_exists( 'themify_post_filter_class' ) ){ function themify_post_filter_class( $classes, $class, $post_id ) { $categories = wp_get_object_terms($post_id, get_query_var( 'tf_query_tax', 'category' ) ); foreach ( $categories as $category ) { $classes[] =' cat-' . $category->term_id; } $is_ajax=get_query_var( 'tf_ajax_filter',false); if(true===$is_ajax){ if(isset($_POST['action'],$_POST['tax']) && $_POST['action']==='themify_ajax_load_more'){ $classes[]='ajax-cat-'.(int)$_POST['tax']; }else{ $classes[]='initial-cat'; } } return $classes; } } function themify_custom_except($excerpt) { if (has_excerpt()) { $excerpt = wp_trim_words(get_the_excerpt(), apply_filters('excerpt_length', 55)); } return $excerpt; } function themify_set_headers(array $headers){ if (!headers_sent()) { $list=headers_list(); foreach($list as $h){ $head=strtoupper(trim(explode(':',$h)[0])); if(isset($headers[$head])){ $vals=trim(trim(str_ireplace($head,'',$h)),':'); if($head==='CONTENT-SECURITY-POLICY' || is_array($headers[$head])) { $vals=explode(';',$vals); $policy=$headers[$head]; $hasChange=false; foreach ($vals as $i => $c) { $c = trim($c); if ($c !== '') { $c = preg_replace('!\s+!', ' ', $c); $values = explode(' ', $c); if (isset($policy[$values[0]])) { $none=array_search('none',$values,true); if($none!==false){ unset($values[$none]); } $values = array_merge($values, explode(' ', $policy[$values[0]])); $vals[$i] = implode(' ', array_keys( array_flip($values))); $hasChange = true; } } else { unset($vals[$i]); } } if ($hasChange === true) { header($head . ':' . implode(';', $vals)); } } elseif($vals!==$headers[$head]) { header($head . ':' . $headers[$head]); } unset($headers[$head]); if(empty($headers)){ break; } } } } } function themify_get_lottie(array $arr,$sel=''){ if(!empty($arr['path']) && !empty($arr['seg'])){ $lottie=array( 'path'=>$arr['path'], 'seg'=>$arr['seg'] ); if(!empty($arr['st'])){ $lottie['st']=$arr['st']; } if(isset($arr['sp']) && $arr['sp']!=1){ $lottie['sp']=$arr['sp']; } if(!empty($arr['dir'])){ $lottie['dir']=$arr['dir']; } if(!empty($arr['fid'])){ $lottie['fid']=$arr['fid']; } if(isset($arr['r']) && $arr['r']!=='svg'){ $lottie['r']=$arr['r']; } if(isset($arr['count']) && ($arr['count']>1 || $arr['count']==-1)){ $lottie['count']=$arr['count']; } if($sel!==''){ $lottie['sel']=$sel; } if(!isset($arr['lp'])){ $lottie=array('actions'=>$lottie,'loop'=>1); } return sprintf('<tf-lottie data-lazy="1" class="tf_lazy"><template>%s</template></tf-lottie>', json_encode($lottie)); } return ''; } /** * Extract a ZIP file, then gets the contents of $data files and then removes the files. * * @return string|WP_Error|array */ function themify_get_data_from_zip( $zip_file, $data_files, $delete_zip = true ) { $base_path = themify_upload_dir(); $base_path = trailingslashit( $base_path['path'] ) . 'tf_zip_temp/'; Themify_Filesystem::get_instance(); $result = unzip_file( $zip_file, $base_path ); if ( true === $result ) { $result = []; foreach ( (array) $data_files as $filename ) { if ( Themify_Filesystem::is_readable( $base_path . $filename ) ) { $result[ $filename ] = Themify_Filesystem::get_contents( $base_path . $filename ); } } /* cleaner return value */ if ( is_string( $data_files ) ) { $result = $result[ $filename ]; } Themify_Filesystem::delete( $base_path ); if ( $delete_zip === true ) { Themify_Filesystem::delete( $zip_file, 'f' ); } } return $result; } /** * Unserialize data, only if it's possible to do it securely. * * @return */ function themify_unserialize( $data ) { if ( version_compare( PHP_VERSION, '7.0.0', '>=' ) ) { return unserialize( $data, [ 'allowed_classes' => false ] ); } return false; }
| ver. 1.4 |
Github
|
.
| PHP 7.4.33 | Генерация страницы: 0 |
proxy
|
phpinfo
|
Настройка