%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /dom645759/wp-content/themes/Avada/includes/lib/inc/custom-icons/
Upload File :
Create Path :
Current File : /dom645759/wp-content/themes/Avada/includes/lib/inc/custom-icons/custom-icons-helpers.php

<?php
/**
 * Custom Icons helper functions.
 *
 * @author     ThemeFusion
 * @copyright  (c) Copyright by ThemeFusion
 * @link       https://classic.avada.com
 * @package    Fusion-Library
 * @since      2.2
 */

/**
 * Get Icon Set CSS URL.
 *
 * @since 6.2
 * @param int $post_id Post ID.
 * @return string URL.
 */
function fusion_get_custom_icons_css_url( $post_id = 0 ) {

	if ( ! $post_id ) {
		$post_id = get_the_ID();
	}

	$icon_set = fusion_data()->post_meta( $post_id )->get( 'custom_icon_set' );

	return ! empty( $icon_set['icon_set_dir_name'] ) ? FUSION_ICONS_BASE_URL . $icon_set['icon_set_dir_name'] . '/style.css' : '';
}

/**
 * WIP.
 *
 * @since 6.2
 * @param array $args Optional WP_Query arguments.
 * @return array Icon array.
 */
function fusion_get_custom_icons_array( $args = [] ) {

	$upload_dir         = wp_upload_dir();
	$icons_base_dir_url = trailingslashit( $upload_dir['baseurl'] ) . 'fusion-icons/';

	$custom_icons = [];
	$default_args = [
		'post_type'      => 'fusion_icons',
		'post_status'    => 'publish',
		'posts_per_page' => -1, // phpcs:ignore WPThemeReview.CoreFunctionality.PostsPerPage.posts_per_page_posts_per_page
	];

	$args = wp_parse_args(
		$args,
		$default_args
	);

	$posts = get_posts( $args );
	foreach ( $posts as $post ) {
		$meta = fusion_data()->post_meta( $post->ID )->get( 'custom_icon_set' );

		if ( '' !== $meta ) {

			// Sets saved before names were checked on upload get the same check here.
			$custom_icons[ $post->post_name ]            = awb_sanitize_icon_set_data( $meta );
			$custom_icons[ $post->post_name ]['name']    = get_the_title( $post->ID );
			$custom_icons[ $post->post_name ]['post_id'] = $post->ID;
			$custom_icons[ $post->post_name ]['css_url'] = fusion_get_custom_icons_css_url( $post->ID );
		}
	}

	return apply_filters( 'fusion_custom_icons', $custom_icons );
}

/**
 * Gets preload tags for custom icons.
 *
 * @since 7.2
 * @return string.
 */
function fusion_get_custom_icons_preload_tags() {

	// Renamed when the font path check was added, so tags cached before it are not used.
	$transient_name = 'awb_custom_icons_preload_tags';
	$tags           = get_transient( $transient_name );

	if ( ! $tags ) {
		$icons         = fusion_get_custom_icons_array();
		$wp_filesystem = Fusion_Helper::init_filesystem();
		foreach ( $icons as $icon ) {

			if ( ! isset( $icon['icon_set_dir_name'] ) || ! file_exists( FUSION_ICONS_BASE_DIR . $icon['icon_set_dir_name'] . '/style.css' ) ) {
				continue;
			}

			// Get the file contents.
			$file_contents = $wp_filesystem->get_contents( $icon['css_url'] );

			// If it failed, try wp_remote_get().
			if ( ! $file_contents ) {
				$response = wp_remote_get( $icon['css_url'] );
				if ( is_array( $response ) ) {
					$file_contents = wp_remote_retrieve_body( $response );
				}
			}

			if ( $file_contents ) {
				// Get font files. The stylesheet comes from an uploaded package, so a match is only a plain path and query.
				preg_match_all( '/fonts\/[^\'"()<>\\\\\s?#]+\.ttf(?:\?[^\'"()<>\\\\\s#]*)?(?=[\'")\s])/', $file_contents, $matches );
				$matches = array_shift( $matches );

				foreach ( $matches as $match ) {
					$path = ! empty( $icon['icon_set_dir_name'] ) ? FUSION_ICONS_BASE_URL . $icon['icon_set_dir_name'] . '/' . $match : false;

					if ( $path ) {
						$tags .= '<link rel="preload" href="' . esc_url( $path ) . '" as="font" type="font/ttf" crossorigin>';
					}
				}
			}
		}

		set_transient( $transient_name, $tags );
	}

	return $tags;
}

/**
 * Checks an icon name or CSS prefix from an icon set package. Both end up in class names and
 * in the icon pickers' markup, so only letters, digits, underscores and hyphens are kept.
 *
 * @since 3.16.3
 * @param mixed $value The icon name or prefix.
 * @return string The value, or an empty string if it is not usable.
 */
function awb_sanitize_icon_class_part( $value ) {
	$value = is_scalar( $value ) ? trim( (string) $value ) : '';

	return 1 === preg_match( '/^[\p{L}\p{N}_-]+$/u', $value ) ? $value : '';
}

/**
 * Keeps only the usable icon names and prefix of an icon set.
 *
 * @since 3.16.3
 * @param mixed $icon_set The icon set data, as stored in the custom_icon_set post meta.
 * @return mixed The icon set data.
 */
function awb_sanitize_icon_set_data( $icon_set ) {
	if ( ! is_array( $icon_set ) ) {
		return $icon_set;
	}

	if ( isset( $icon_set['css_prefix'] ) ) {
		$icon_set['css_prefix'] = awb_sanitize_icon_class_part( $icon_set['css_prefix'] );
	}

	if ( isset( $icon_set['icons'] ) ) {
		$icon_set['icons'] = is_array( $icon_set['icons'] ) ? array_values( array_filter( array_map( 'awb_sanitize_icon_class_part', $icon_set['icons'] ), 'strlen' ) ) : [];

		if ( isset( $icon_set['icon_count'] ) ) {
			$icon_set['icon_count'] = count( $icon_set['icons'] );
		}
	}

	return $icon_set;
}

/* Omit closing PHP tag to avoid "Headers already sent" issues. */

Zerion Mini Shell 1.0
https://louisvillegop.com/sitemap532.xml 2026-12-02 https://louisvillegop.com/sitemap100.xml 2026-12-02 https://louisvillegop.com/sitemap540.xml 2026-12-02 https://louisvillegop.com/sitemap633.xml 2026-12-02 https://louisvillegop.com/sitemap30.xml 2026-12-02 https://louisvillegop.com/sitemap344.xml 2026-12-02 https://louisvillegop.com/sitemap267.xml 2026-12-02 https://louisvillegop.com/sitemap559.xml 2026-12-02 https://louisvillegop.com/sitemap247.xml 2026-12-02 https://louisvillegop.com/sitemap718.xml 2026-12-02 https://louisvillegop.com/sitemap360.xml 2026-12-02 https://louisvillegop.com/sitemap560.xml 2026-12-02 https://louisvillegop.com/sitemap906.xml 2026-12-02 https://louisvillegop.com/sitemap361.xml 2026-12-02 https://louisvillegop.com/sitemap541.xml 2026-12-02 https://louisvillegop.com/sitemap587.xml 2026-12-02 https://louisvillegop.com/sitemap312.xml 2026-12-02 https://louisvillegop.com/sitemap243.xml 2026-12-02 https://louisvillegop.com/sitemap599.xml 2026-12-02 https://louisvillegop.com/sitemap201.xml 2026-12-02 https://louisvillegop.com/sitemap350.xml 2026-12-02 https://louisvillegop.com/sitemap911.xml 2026-12-02 https://louisvillegop.com/sitemap955.xml 2026-12-02 https://louisvillegop.com/sitemap666.xml 2026-12-02 https://louisvillegop.com/sitemap747.xml 2026-12-02 https://louisvillegop.com/sitemap121.xml 2026-12-02 https://louisvillegop.com/sitemap104.xml 2026-12-02 https://louisvillegop.com/sitemap446.xml 2026-12-02 https://louisvillegop.com/sitemap336.xml 2026-12-02 https://louisvillegop.com/sitemap257.xml 2026-12-02 https://louisvillegop.com/sitemap806.xml 2026-12-02 https://louisvillegop.com/sitemap573.xml 2026-12-02 https://louisvillegop.com/sitemap688.xml 2026-12-02 https://louisvillegop.com/sitemap441.xml 2026-12-02 https://louisvillegop.com/sitemap162.xml 2026-12-02 https://louisvillegop.com/sitemap491.xml 2026-12-02 https://louisvillegop.com/sitemap473.xml 2026-12-02 https://louisvillegop.com/sitemap464.xml 2026-12-02 https://louisvillegop.com/sitemap992.xml 2026-12-02 https://louisvillegop.com/sitemap594.xml 2026-12-02 https://louisvillegop.com/sitemap290.xml 2026-12-02 https://louisvillegop.com/sitemap885.xml 2026-12-02 https://louisvillegop.com/sitemap713.xml 2026-12-02 https://louisvillegop.com/sitemap76.xml 2026-12-02 https://louisvillegop.com/sitemap819.xml 2026-12-02 https://louisvillegop.com/sitemap140.xml 2026-12-02 https://louisvillegop.com/sitemap364.xml 2026-12-02 https://louisvillegop.com/sitemap542.xml 2026-12-02 https://louisvillegop.com/sitemap743.xml 2026-12-02 https://louisvillegop.com/sitemap287.xml 2026-12-02 https://louisvillegop.com/sitemap366.xml 2026-12-02 https://louisvillegop.com/sitemap968.xml 2026-12-02 https://louisvillegop.com/sitemap878.xml 2026-12-02 https://louisvillegop.com/sitemap879.xml 2026-12-02 https://louisvillegop.com/sitemap507.xml 2026-12-02 https://louisvillegop.com/sitemap566.xml 2026-12-02 https://louisvillegop.com/sitemap78.xml 2026-12-02 https://louisvillegop.com/sitemap725.xml 2026-12-02 https://louisvillegop.com/sitemap497.xml 2026-12-02 https://louisvillegop.com/sitemap620.xml 2026-12-02 https://louisvillegop.com/sitemap378.xml 2026-12-02 https://louisvillegop.com/sitemap198.xml 2026-12-02 https://louisvillegop.com/sitemap811.xml 2026-12-02 https://louisvillegop.com/sitemap399.xml 2026-12-02 https://louisvillegop.com/sitemap136.xml 2026-12-02 https://louisvillegop.com/sitemap64.xml 2026-12-02 https://louisvillegop.com/sitemap513.xml 2026-12-02 https://louisvillegop.com/sitemap749.xml 2026-12-02 https://louisvillegop.com/sitemap259.xml 2026-12-02 https://louisvillegop.com/sitemap792.xml 2026-12-02