se; } endif; /** * Get category level * * @since 1.0 */ if ( ! function_exists( 'martfury_get_product_category_level' ) ) : function martfury_get_product_category_level() { global $wp_query; $current_cat = $wp_query->get_queried_object(); if ( empty( $current_cat ) ) { return 0; } $term_id = $current_cat->term_id; return count( get_ancestors( $term_id, 'product_cat' ) ); } endif; /** * Get catalog layout * * @since 1.0 */ if ( ! function_exists( 'martfury_get_filtered_term_product_counts' ) ) : function martfury_get_filtered_term_product_counts( $term_ids, $taxonomy = false, $query_type = false ) { global $wpdb; if ( ! class_exists( 'WC_Query' ) ) { return false; } $tax_query = WC_Query::get_main_tax_query(); $meta_query = WC_Query::get_main_meta_query(); if ( 'or' === $query_type ) { foreach ( $tax_query as $key => $query ) { if ( is_array( $query ) && $taxonomy === $query['taxonomy'] ) { unset( $tax_query[ $key ] ); } } } if ( 'product_brand' === $taxonomy ) { foreach ( $tax_query as $key => $query ) { if ( is_array( $query ) ) { if ( $query['taxonomy'] === 'product_brand' ) { unset( $tax_query[ $key ] ); if ( preg_match( '/pa_/', $query['taxonomy'] ) ) { unset( $tax_query[ $key ] ); } } } } } $meta_query = new WP_Meta_Query( $meta_query ); $tax_query = new WP_Tax_Query( $tax_query ); $meta_query_sql = $meta_query->get_sql( 'post', $wpdb->posts, 'ID' ); $tax_query_sql = $tax_query->get_sql( $wpdb->posts, 'ID' ); // Generate query $query = array(); $query['select'] = "SELECT COUNT( DISTINCT {$wpdb->posts}.ID ) as term_count, terms.term_id as term_count_id"; $query['from'] = "FROM {$wpdb->posts}"; $query['join'] = " INNER JOIN {$wpdb->term_relationships} AS term_relationships ON {$wpdb->posts}.ID = term_relationships.object_id INNER JOIN {$wpdb->term_taxonomy} AS term_taxonomy USING( term_taxonomy_id ) INNER JOIN {$wpdb->terms} AS terms USING( term_id ) " . $tax_query_sql['join'] . $meta_query_sql['join']; $query['where'] = " WHERE {$wpdb->posts}.post_type IN ( 'product' ) AND {$wpdb->posts}.post_status = 'publish' " . $tax_query_sql['where'] . $meta_query_sql['where'] . " AND terms.term_id IN (" . implode( ',', array_map( 'absint', $term_ids ) ) . ") "; if ( $search = WC_Query::get_main_search_query_sql() ) { $query['where'] .= ' AND ' . $search; } $query['group_by'] = "GROUP BY terms.term_id"; $query = apply_filters( 'woocommerce_get_filtered_term_product_counts_query', $query ); $query = implode( ' ', $query ); // We have a query - let's see if cached results of this query already exist. $query_hash = md5( $query ); $cache = apply_filters( 'woocommerce_layered_nav_count_maybe_cache', true ); if ( true === $cache ) { $cached_counts = (array) get_transient( 'wc_layered_nav_counts_' . sanitize_title( $taxonomy ) ); } else { $cached_counts = array(); } if ( ! isset( $cached_counts[ $query_hash ] ) ) { $results = $wpdb->get_results( $query, ARRAY_A ); $counts = array_map( 'absint', wp_list_pluck( $results, 'term_count', 'term_count_id' ) ); $cached_counts[ $query_hash ] = $counts; set_transient( 'wc_layered_nav_counts_' . sanitize_title( $taxonomy ), $cached_counts, DAY_IN_SECONDS ); } return array_map( 'absint', (array) $cached_counts[ $query_hash ] ); } endif; /** * Get socials * * @since 1.0.0 * * * @return string */ if ( ! function_exists( 'martfury_get_socials' ) ) : function martfury_get_socials() { $socials = array( 'facebook' => esc_html__( 'Facebook', 'martfury' ), 'twitter' => esc_html__( 'Twitter', 'martfury' ), 'google' => esc_html__( 'Google', 'martfury' ), 'tumblr' => esc_html__( 'Tumblr', 'martfury' ), 'flickr' => esc_html__( 'Flickr', 'martfury' ), 'vimeo' => esc_html__( 'Vimeo', 'martfury' ), 'youtube' => esc_html__( 'Youtube', 'martfury' ), 'linkedin' => esc_html__( 'LinkedIn', 'martfury' ), 'pinterest' => esc_html__( 'Pinterest', 'martfury' ), 'dribbble' => esc_html__( 'Dribbble', 'martfury' ), 'spotify' => esc_html__( 'Spotify', 'martfury' ), 'instagram' => esc_html__( 'Instagram', 'martfury' ), 'tumbleupon' => esc_html__( 'Tumbleupon', 'martfury' ), 'wordpress' => esc_html__( 'WordPress', 'martfury' ), 'rss' => esc_html__( 'Rss', 'martfury' ), 'deviantart' => esc_html__( 'Deviantart', 'martfury' ), 'share' => esc_html__( 'Share', 'martfury' ), 'skype' => esc_html__( 'Skype', 'martfury' ), 'behance' => esc_html__( 'Behance', 'martfury' ), 'apple' => esc_html__( 'Apple', 'martfury' ), 'yelp' => esc_html__( 'Yelp', 'martfury' ), ); return apply_filters( 'martfury_header_socials', $socials ); } endif; /** * Get page header layout * * @return array */ if ( ! function_exists( 'martfury_get_page_header' ) ) : function martfury_get_page_header() { if ( is_404() || is_page_template( 'template-homepage.php' ) || is_page_template( 'template-home-full-width.php' ) || is_page_template( 'template-coming-soon-page.php' ) ) { return false; } $page_header = array( 'title', 'breadcrumb' ); if ( martfury_is_blog() ) { if ( ! intval( martfury_get_option( 'page_header_blog' ) ) ) { return false; } $page_header = martfury_get_option( 'page_header_blog_els' ); } elseif ( is_page() ) { if ( ! intval( martfury_get_option( 'page_header_page' ) ) ) { return false; } $custom_layout = get_post_meta( get_the_ID(), 'custom_page_header', true ); if ( $custom_layout ) { $hide_page_header = get_post_meta( get_the_ID(), 'hide_page_header', true ); if ( $hide_page_header ) { return false; } if ( get_post_meta( get_the_ID(), 'hide_breadcrumb', true ) ) { $key = array_search( 'breadcrumb', $page_header ); if ( $key !== false ) { unset( $page_header[ $key ] ); } } if ( get_post_meta( get_the_ID(), 'hide_title', true ) ) { $key = array_search( 'title', $page_header ); if ( $key !== false ) { unset( $page_header[ $key ] ); } } } else { $page_header = martfury_get_option( 'page_header_pages_els' ); } } elseif ( is_search() ) { $page_header = array( 'title', 'breadcrumb' ); } elseif ( function_exists( 'is_shop' ) && is_shop() ) { $shop_id = get_option( 'woocommerce_shop_page_id' ); $custom_layout = get_post_meta( $shop_id, 'custom_page_header', true ); if ( $custom_layout ) { $hide_page_header = get_post_meta( $shop_id, 'hide_page_header', true ); if ( $hide_page_header ) { return false; } if ( get_post_meta( $shop_id, 'hide_breadcrumb', true ) ) { $key = array_search( 'breadcrumb', $page_header ); if ( $key !== false ) { unset( $page_header[ $key ] ); } } if ( get_post_meta( $shop_id, 'hide_title', true ) ) { $key = array_search( 'title', $page_header ); if ( $key !== false ) { unset( $page_header[ $key ] ); } } } } if ( martfury_is_vendor_page() ) { $page_header = martfury_get_option( 'page_header_vendor_els' ); } return apply_filters( 'martfury_get_page_header', $page_header ); } endif; /** * Get recently viewed products * * @return string */ if ( ! function_exists( 'martfury_recently_viewed_products' ) ) : function martfury_recently_viewed_products( $atts ) { $viewed_products = ! empty( $_COOKIE['woocommerce_recently_viewed'] ) ? (array) explode( '|', $_COOKIE['woocommerce_recently_viewed'] ) : array(); $viewed_products = array_reverse( array_filter( array_map( 'absint', $viewed_products ) ) ); $output = array(); $thumbnail_size = 'thumbnail'; if ( function_exists( 'wc_get_image_size' ) ) { $gallery_thumbnail = wc_get_image_size( 'gallery_thumbnail' ); $thumbnail_size = apply_filters( 'woocommerce_gallery_thumbnail_size', array( $gallery_thumbnail['width'], $gallery_thumbnail['height'] ) ); } $output[] = '
'; if ( isset( $atts['title'] ) && $atts['title'] ) { $output[] = sprintf( '

%s

', esc_html( $atts['title'] ) ); } if ( isset( $atts['link_text'] ) && $atts['link_text'] ) { $output[] = sprintf( '%s', esc_url( $atts['link_url'] ), esc_html( $atts['link_text'] ) ); } $output[] = '
'; if ( empty( $viewed_products ) ) { $output[] = sprintf( '', esc_html__( 'Recently Viewed Products is a function which helps you keep track of your recent viewing history.', 'martfury' ), esc_url( get_permalink( get_option( 'woocommerce_shop_page_id' ) ) ), esc_html__( 'Shop Now', 'martfury' ) ); } else { if ( ! function_exists( 'wc_get_product' ) ) { $output[] = sprintf( '', esc_html__( 'Recently Viewed Products is a function which helps you keep track of your recent viewing history.', 'martfury' ), esc_url( get_permalink( get_option( 'woocommerce_shop_page_id' ) ) ), esc_html__( 'Shop Now', 'martfury' ) ); } $output[] = ''; } return sprintf( '
%s
', implode( ' ', $output ) ); } endif; /** * Print HTML of currency switcher * It requires plugin WooCommerce Currency Switcher installed */ if ( ! function_exists( 'martfury_currency_switcher' ) ) : function martfury_currency_switcher( $show_desc = false ) { $currency_dd = ''; if ( class_exists( 'WOOCS' ) ) { global $WOOCS; $key_cur = 'name'; if ( $show_desc ) { $key_cur = 'description'; } $currencies = $WOOCS->get_currencies(); $currency_list = array(); foreach ( $currencies as $key => $currency ) { $currency_value = empty($currency[ $key_cur ]) ? $currency['name'] : $currency[ $key_cur ]; if ( $WOOCS->current_currency == $key ) { array_unshift( $currency_list, sprintf( '
  • %s
  • ', esc_attr( $currency['name'] ), esc_html( $currency_value ) ) ); } else { $currency_list[] = sprintf( '
  • %s
  • ', esc_attr( $currency['name'] ), esc_html( $currency_value ) ); } } $currency_value = empty($currencies[ $WOOCS->current_currency ][ $key_cur ]) ? $currencies[ $WOOCS->current_currency ][ 'name' ] : $currencies[ $WOOCS->current_currency ][ $key_cur ]; $currency_dd = sprintf( '%s' . '', $currency_value, implode( "\n\t", $currency_list ) ); } elseif ( class_exists( 'Alg_WC_Currency_Switcher' ) ) { $function_currencies = alg_get_enabled_currencies(); $currencies = get_woocommerce_currencies(); $selected_currency = alg_get_current_currency_code(); $selected_currency_name = ''; $currency_list = array(); $first_link = ''; foreach ( $function_currencies as $currency_code ) { if ( isset( $currencies[ $currency_code ] ) ) { $the_text = function_exists('alg_format_currency_switcher') ? alg_format_currency_switcher( $currencies[ $currency_code ], $currency_code, false ) : ''; $the_link = '
  • ' . $the_text . '
  • '; if ( $currency_code != $selected_currency ) { $currency_list[] = $the_link; } else { $first_link = $the_link; $selected_currency_name = $the_text; } } } if ( '' != $first_link ) { $currency_list = array_merge( array( $first_link ), $currency_list ); } if ( ! empty( $currency_list ) && ! empty( $selected_currency_name ) ) { $currency_dd = sprintf( '%s' . '', $selected_currency_name, implode( "\n\t", $currency_list ) ); } } return $currency_dd; } endif; if ( ! function_exists( 'martfury_product_video' ) ) : function martfury_product_video() { global $product; $video_image = get_post_meta( $product->get_id(), 'video_thumbnail', true ); $video_url = get_post_meta( $product->get_id(), 'video_url', true ); $video_first = get_post_meta( $product->get_id(), 'video_position', true ); $video_width = 1024; $video_height = 768; $video_html = ''; if ( $video_image ) { $video_thumb = wp_get_attachment_image_src( $video_image, apply_filters( 'single_product_small_thumbnail_size', 'shop_thumbnail' ) ); $video_thumb = $video_thumb[0]; // If URL: show oEmbed HTML if ( filter_var( $video_url, FILTER_VALIDATE_URL ) ) { $atts = array( 'width' => $video_width, 'height' => $video_height ); if ( $oembed = @wp_oembed_get( $video_url, $atts ) ) { $video_html = $oembed; } else { $atts = array( 'src' => $video_url, 'width' => $video_width, 'height' => $video_height ); $video_html = wp_video_shortcode( $atts ); } } if ( $video_html ) { $vid_html = '
    ' . $video_html . '
    '; if ( $video_first == '2' ) { $vid_html .= ''; } $video_wrapper = sprintf( '
    %s
    ', $vid_html ); $video_html = ''; } } return $video_html; } endif; /** * Wrapper function to deal with backwards compatibility. */ if ( ! function_exists( 'martfury_body_open' ) ) { function martfury_body_open() { if ( function_exists( 'wp_body_open' ) ) { wp_body_open(); } else { do_action( 'wp_body_open' ); } } } if ( ! function_exists( 'martfury_cartflows_template' ) ) { function martfury_cartflows_template() { if ( ! class_exists( 'Cartflows_Loader' ) || ! function_exists('_get_wcf_step_id')) { return false; } $page_template = get_post_meta( _get_wcf_step_id(), '_wp_page_template', true ); if( !$page_template || $page_template == 'default' ) { return false; } return true; } } /** * Sanitize SVG code. * * @since 1.0.0 * * @param string $svg SVG code. * * @return string */ function martfury_sanitize_svg( $svg ) { $allowed = array(); $whitelist = array( 'a' => array( 'class', 'clip-path', 'clip-rule', 'fill', 'fill-opacity', 'fill-rule', 'filter', 'id', 'mask', 'opacity', 'stroke', 'stroke-dasharray', 'stroke-dashoffset', 'stroke-linecap', 'stroke-linejoin', 'stroke-miterlimit', 'stroke-opacity', 'stroke-width', 'style', 'systemLanguage', 'transform', 'href', 'xlink:href', 'xlink:title', ), 'circle' => array( 'class', 'clip-path', 'clip-rule', 'cx', 'cy', 'fill', 'fill-opacity', 'fill-rule', 'filter', 'id', 'mask', 'opacity', 'r', 'requiredFeatures', 'stroke', 'stroke-dasharray', 'stroke-dashoffset', 'stroke-linecap', 'stroke-linejoin', 'stroke-miterlimit', 'stroke-opacity', 'stroke-width', 'style', 'systemLanguage', 'transform', ), 'clipPath' => array( 'class', 'clipPathUnits', 'id' ), 'defs' => array(), 'style' => array( 'type' ), 'desc' => array(), 'ellipse' => array( 'class', 'clip-path', 'clip-rule', 'cx', 'cy', 'fill', 'fill-opacity', 'fill-rule', 'filter', 'id', 'mask', 'opacity', 'requiredFeatures', 'rx', 'ry', 'stroke', 'stroke-dasharray', 'stroke-dashoffset', 'stroke-linecap', 'stroke-linejoin', 'stroke-miterlimit', 'stroke-opacity', 'stroke-width', 'style', 'systemLanguage', 'transform', ), 'feGaussianBlur' => array( 'class', 'color-interpolation-filters', 'id', 'requiredFeatures', 'stdDeviation' ), 'filter' => array( 'class', 'color-interpolation-filters', 'filterRes', 'filterUnits', 'height', 'id', 'primitiveUnits', 'requiredFeatures', 'width', 'x', 'xlink:href', 'y', ), 'foreignObject' => array( 'class', 'font-size', 'height', 'id', 'opacity', 'requiredFeatures', 'style', 'transform', 'width', 'x', 'y', ), 'g' => array( 'class', 'clip-path', 'clip-rule', 'id', 'display', 'fill', 'fill-opacity', 'fill-rule', 'filter', 'mask', 'opacity', 'requiredFeatures', 'stroke', 'stroke-dasharray', 'stroke-dashoffset', 'stroke-linecap', 'stroke-linejoin', 'stroke-miterlimit', 'stroke-opacity', 'stroke-width', 'style', 'systemLanguage', 'transform', 'font-family', 'font-size', 'font-style', 'font-weight', 'text-anchor', ), 'image' => array( 'class', 'clip-path', 'clip-rule', 'filter', 'height', 'id', 'mask', 'opacity', 'requiredFeatures', 'style', 'systemLanguage', 'transform', 'width', 'x', 'xlink:href', 'xlink:title', 'y', ), 'line' => array( 'class', 'clip-path', 'clip-rule', 'fill', 'fill-opacity', 'fill-rule', 'filter', 'id', 'marker-end', 'marker-mid', 'marker-start', 'mask', 'opacity', 'requiredFeatures', 'stroke', 'stroke-dasharray', 'stroke-dashoffset', 'stroke-linecap', 'stroke-linejoin', 'stroke-miterlimit', 'stroke-opacity', 'stroke-width', 'style', 'systemLanguage', 'transform', 'x1', 'x2', 'y1', 'y2', ), 'linearGradient' => array( 'class', 'id', 'gradientTransform', 'gradientUnits', 'requiredFeatures', 'spreadMethod', 'systemLanguage', 'x1', 'x2', 'xlink:href', 'y1', 'y2', ), 'marker' => array( 'id', 'class', 'markerHeight', 'markerUnits', 'markerWidth', 'orient', 'preserveAspectRatio', 'refX', 'refY', 'systemLanguage', 'viewBox', ), 'mask' => array( 'class', 'height', 'id', 'maskContentUnits', 'maskUnits', 'width', 'x', 'y' ), 'metadata' => array( 'class', 'id' ), 'path' => array( 'class', 'clip-path', 'clip-rule', 'd', 'fill', 'fill-opacity', 'fill-rule', 'filter', 'id', 'marker-end', 'marker-mid', 'marker-start', 'mask', 'opacity', 'requiredFeatures', 'stroke', 'stroke-dasharray', 'stroke-dashoffset', 'stroke-linecap', 'stroke-linejoin', 'stroke-miterlimit', 'stroke-opacity', 'stroke-width', 'style', 'systemLanguage', 'transform', ), 'pattern' => array( 'class', 'height', 'id', 'patternContentUnits', 'patternTransform', 'patternUnits', 'requiredFeatures', 'style', 'systemLanguage', 'viewBox', 'width', 'x', 'xlink:href', 'y', ), 'polygon' => array( 'class', 'clip-path', 'clip-rule', 'id', 'fill', 'fill-opacity', 'fill-rule', 'filter', 'id', 'class', 'marker-end', 'marker-mid', 'marker-start', 'mask', 'opacity', 'points', 'requiredFeatures', 'stroke', 'stroke-dasharray', 'stroke-dashoffset', 'stroke-linecap', 'stroke-linejoin', 'stroke-miterlimit', 'stroke-opacity', 'stroke-width', 'style', 'systemLanguage', 'transform', ), 'polyline' => array( 'class', 'clip-path', 'clip-rule', 'id', 'fill', 'fill-opacity', 'fill-rule', 'filter', 'marker-end', 'marker-mid', 'marker-start', 'mask', 'opacity', 'points', 'requiredFeatures', 'stroke', 'stroke-dasharray', 'stroke-dashoffset', 'stroke-linecap', 'stroke-linejoin', 'stroke-miterlimit', 'stroke-opacity', 'stroke-width', 'style', 'systemLanguage', 'transform', ), 'radialGradient' => array( 'class', 'cx', 'cy', 'fx', 'fy', 'gradientTransform', 'gradientUnits', 'id', 'r', 'requiredFeatures', 'spreadMethod', 'systemLanguage', 'xlink:href', ), 'rect' => array( 'class', 'clip-path', 'clip-rule', 'fill', 'fill-opacity', 'fill-rule', 'filter', 'height', 'id', 'mask', 'opacity', 'requiredFeatures', 'rx', 'ry', 'stroke', 'stroke-dasharray', 'stroke-dashoffset', 'stroke-linecap', 'stroke-linejoin', 'stroke-miterlimit', 'stroke-opacity', 'stroke-width', 'style', 'systemLanguage', 'transform', 'width', 'x', 'y', ), 'stop' => array( 'class', 'id', 'offset', 'requiredFeatures', 'stop-color', 'stop-opacity', 'style', 'systemLanguage', ), 'svg' => array( 'class', 'clip-path', 'clip-rule', 'filter', 'id', 'mask', 'preserveaspectRatio', 'requiredfeatures', 'style', 'systemlanguage', 'viewbox', 'fill', 'fill-opacity', 'fill-rule', 'stroke', 'stroke-dasharray', 'stroke-dashoffset', 'stroke-linecap', 'stroke-linejoin', 'stroke-miterlimit', 'stroke-opacity', 'stroke-width', 'width', 'height', 'xmlns', 'xmlns:se', 'xmlns:xlink', 'x', 'y', 'enable-background', ), 'switch' => array( 'class', 'id', 'requiredFeatures', 'systemLanguage' ), 'symbol' => array( 'class', 'fill', 'fill-opacity', 'fill-rule', 'filter', 'font-family', 'font-size', 'font-style', 'font-weight', 'id', 'opacity', 'preserveAspectRatio', 'requiredFeatures', 'stroke', 'stroke-dasharray', 'stroke-dashoffset', 'stroke-linecap', 'stroke-linejoin', 'stroke-miterlimit', 'stroke-opacity', 'stroke-width', 'style', 'systemLanguage', 'transform', 'viewBox', ), 'text' => array( 'class', 'clip-path', 'clip-rule', 'fill', 'fill-opacity', 'fill-rule', 'filter', 'font-family', 'font-size', 'font-style', 'font-weight', 'id', 'mask', 'opacity', 'requiredFeatures', 'stroke', 'stroke-dasharray', 'stroke-dashoffset', 'stroke-linecap', 'stroke-linejoin', 'stroke-miterlimit', 'stroke-opacity', 'stroke-width', 'style', 'systemLanguage', 'text-anchor', 'transform', 'x', 'xml:space', 'y', ), 'textPath' => array( 'class', 'id', 'method', 'requiredFeatures', 'spacing', 'startOffset', 'style', 'systemLanguage', 'transform', 'xlink:href', ), 'title' => array(), 'tspan' => array( 'class', 'clip-path', 'clip-rule', 'dx', 'dy', 'fill', 'fill-opacity', 'fill-rule', 'filter', 'font-family', 'font-size', 'font-style', 'font-weight', 'id', 'mask', 'opacity', 'requiredFeatures', 'rotate', 'stroke', 'stroke-dasharray', 'stroke-dashoffset', 'stroke-linecap', 'stroke-linejoin', 'stroke-miterlimit', 'stroke-opacity', 'stroke-width', 'style', 'systemLanguage', 'text-anchor', 'textLength', 'transform', 'x', 'xml:space', 'y', ), 'use' => array( 'class', 'clip-path', 'clip-rule', 'fill', 'fill-opacity', 'fill-rule', 'filter', 'height', 'id', 'mask', 'stroke', 'stroke-dasharray', 'stroke-dashoffset', 'stroke-linecap', 'stroke-linejoin', 'stroke-miterlimit', 'stroke-opacity', 'stroke-width', 'style', 'transform', 'width', 'x', 'xlink:href', 'y', ), ); foreach ( $whitelist as $tag => $attributes ) { $allowed[ $tag ] = array(); foreach ( $attributes as $attribute ) { $allowed[ $tag ][ $attribute ] = true; } } return wp_kses( $svg, $allowed ); }