晋太元中,武陵人捕鱼为业。缘溪行,忘路之远近。忽逢桃花林,夹岸数百步,中无杂树,芳草鲜美,落英缤纷。渔人甚异之,复前行,欲穷其林。   林尽水源,便得一山,山有小口,仿佛若有光。便舍船,从口入。初极狭,才通人。复行数十步,豁然开朗。土地平旷,屋舍俨然,有良田、美池、桑竹之属。阡陌交通,鸡犬相闻。其中往来种作,男女衣着,悉如外人。黄发垂髫,并怡然自乐。   见渔人,乃大惊,问所从来。具答之。便要还家,设酒杀鸡作食。村中闻有此人,咸来问讯。自云先世避秦时乱,率妻子邑人来此绝境,不复出焉,遂与外人间隔。问今是何世,乃不知有汉,无论魏晋。此人一一为具言所闻,皆叹惋。余人各复延至其家,皆出酒食。停数日,辞去。此中人语云:“不足为外人道也。”(间隔 一作:隔绝)   既出,得其船,便扶向路,处处志之。及郡下,诣太守,说如此。太守即遣人随其往,寻向所志,遂迷,不复得路。   南阳刘子骥,高尚士也,闻之,欣然规往。未果,寻病终。后遂无问津者。 .
Prv8 Shell
Server : Apache
System : Linux srv.rainic.com 4.18.0-553.47.1.el8_10.x86_64 #1 SMP Wed Apr 2 05:45:37 EDT 2025 x86_64
User : rainic ( 1014)
PHP Version : 7.4.33
Disable Function : exec,passthru,shell_exec,system
Directory :  /home/tabatabaei/.trash/wp-content.1/themes/blockbase/inc/fonts/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/tabatabaei/.trash/wp-content.1/themes/blockbase/inc/fonts/custom-fonts.php
<?php

// Font settings deprecation message
require get_template_directory() . '/inc/customizer/wp-customize-fonts.php';

// Font Migration
require get_template_directory() . '/inc/fonts/custom-font-migration.php';

add_action( 'init', 'enqueue_global_styles_fonts', 100 );
add_action( 'admin_init', 'enqueue_fse_font_styles' );
add_filter( 'pre_render_block', 'enqueue_block_fonts', 10, 2 );
add_filter( 'jetpack_google_fonts_list', 'blockbase_filter_jetpack_google_fonts_list' );

$blockbase_enqueued_font_slugs = array();

/**
 * Get the CSS containing font_face values for a given slug
 *
 * @return string String of CSS
 */
function get_style_css( $slug ) {
	$font_face_file = get_template_directory() . '/assets/fonts/' . $slug . '/font-face.css';
	if ( ! file_exists( $font_face_file ) ) {
		return '';
	}
	$contents = file_get_contents( $font_face_file );
	return str_replace( 'src: url(./', 'src: url(' . get_template_directory_uri() . '/assets/fonts/' . $slug . '/', $contents );
}

/**
 * Collect fonts set in Global Styles settings.
 *
 * @return array Font faces from Global Styles settings.
 */
function collect_fonts_from_global_styles() {
	// NOTE: We have to use gutenberg_get_global_styles() here due to the potential changes to Global Styles on page load happening in font migration.
	// Since core users don't have anything to migrate we can use core get_styles
	if ( function_exists( 'gutenberg_get_global_styles' ) ) {
		$global_styles = gutenberg_get_global_styles();
	} else {
		$global_styles = wp_get_global_styles();
	}

	$found_webfonts = array();

	// Look for fonts in block presets...
	if ( isset( $global_styles['blocks'] ) ) {
		foreach ( $global_styles['blocks'] as $setting ) {
			$font_slug = extract_font_slug_from_setting( $setting );

			if ( $font_slug ) {
				$found_webfonts[] = $font_slug;
			}
		}
	}

	// Look for fonts in HTML element presets...
	if ( isset( $global_styles['elements'] ) ) {
		foreach ( $global_styles['elements'] as $setting ) {

			// die(json_encode($global_styles));
			// NOTE: It seems that the Global Styles assignment of fonts writes the font family string rather than the
			// global styles shorthand that is assigned to the body.  This should be confirmed and reported if it isn't already.
			$font_slug = extract_font_slug_from_setting( $setting );

			if ( $font_slug ) {
				$found_webfonts[] = $font_slug;
			}
		}
	}

	// Check if a global typography setting was defined.
	$font_slug = extract_font_slug_from_setting( $global_styles );

	if ( $font_slug ) {
		$found_webfonts[] = $font_slug;
	}

	return array_unique( $found_webfonts );
}

/**
 * Extract the font family slug from a settings array.
 *
 * @param array $setting The settings object.
 *
 * @return string|null
 */
function extract_font_slug_from_setting( $setting ) {
	if ( ! isset( $setting['typography']['fontFamily'] ) ) {
		return null;
	}

	$font_family = $setting['typography']['fontFamily'];

	// Full string: var(--wp--preset--font-family--slug).
	// We do not care about the origin of the font, only its slug.
	preg_match( '/font-family--(?P<slug>.+)\)$/', $font_family, $matches );

	if ( isset( $matches['slug'] ) ) {
		return $matches['slug'];
	}

	// Full string: var:preset|font-family|slug
	// We do not care about the origin of the font, only its slug.
	preg_match( '/font-family\|(?P<slug>.+)$/', $font_family, $matches );

	if ( isset( $matches['slug'] ) ) {
		return $matches['slug'];
	}

	return $font_family;
}

/**
 * Build a list of all font slugs provided by Blockbase from theme.json
 *
 * @return array Collection of all font slugs defined in the theme.json file
 */
function collect_fonts_from_blockbase() {
	$fonts                  = array();
	$parent_theme_json_data = json_decode( file_get_contents( get_template_directory() . '/theme.json' ), true );
	$font_families          = $parent_theme_json_data['settings']['typography']['fontFamilies'];

	foreach ( $font_families as $font ) {
		// Only pick it up if we're claiming it as ours to manage
		if ( array_key_exists( 'provider', $font ) && 'blockbase-fonts' === $font['provider'] ) {
			$fonts[] = $font;
		}
	}

	return $fonts;
}

/**
 * Enqeue all of the fonts used in global styles settings.
 *
 * @return void
 */
function enqueue_global_styles_fonts() {

	global $blockbase_enqueued_font_slugs;

	$font_slugs = array();
	$font_css   = '';

	if ( is_admin() ) {
		$font_families = collect_fonts_from_blockbase();
		foreach ( $font_families as $font_family ) {
			$font_slugs[] = $font_family['slug'];
		}
	} else {
		$font_slugs = collect_fonts_from_global_styles();
	}

	$blockbase_enqueued_font_slugs = $font_slugs;

	foreach ( $font_slugs as $font_slug ) {
		$font_css .= get_style_css( $font_slug );
	}

	// Bail out if there are no styles to enqueue.
	if ( '' === $font_css ) {
		return;
	}

	// Enqueue the stylesheet.
	wp_register_style( 'blockbase_font_faces', '' );
	wp_enqueue_style( 'blockbase_font_faces' );

	// Add the styles to the stylesheet.
	wp_add_inline_style( 'blockbase_font_faces', $font_css );
}

/**
 * Enqueue all of the fonts provided by Blockbase for FSE use
 */
function enqueue_fse_font_styles( $fonts ) {
	$fonts    = collect_fonts_from_blockbase();
	$font_css = '';

	foreach ( $fonts as $font ) {
		$font_css .= get_style_css( $font['slug'] );
	}

	wp_enqueue_style( 'wp-block-library' );
	wp_add_inline_style( 'wp-block-library', $font_css );
}

/**
 * Add fonts that have been assigned via CSS
 */
function enqueue_block_fonts( $content, $parsed_block ) {
	global $blockbase_enqueued_font_slugs;
	if ( ! is_admin() && isset( $parsed_block['attrs']['fontFamily'] ) ) {
		$font_slug = $parsed_block['attrs']['fontFamily'];
		if ( ! in_array( $font_slug, $blockbase_enqueued_font_slugs, true ) ) {
			$font_css = get_style_css( $font_slug );
			if ( $font_css ) {
				$blockbase_enqueued_font_slugs[] = $font_slug;
				wp_add_inline_style( 'blockbase_font_faces', $font_css );
			}
		}
	}
	return $content;
}

/**
 * Jetpack may attempt to register fonts for the Google Font Provider.
 * This filters out all of the fonts Blockbase has already registered.
 */
function blockbase_filter_jetpack_google_fonts_list( $jetpack_fonts ) {
	$theme_fonts         = collect_fonts_from_blockbase();
	$theme_font_families = array_column( $theme_fonts, 'name' );
	$filtered_list       = array();

	// If the Jetpack font isn't in theme already, let Jetpack register it
	foreach ( $jetpack_fonts as $jetpack_font_family ) {
		if ( ! in_array( $jetpack_font_family, $theme_font_families, true ) ) {
			$filtered_list[] = $jetpack_font_family;
		}
	}
	return $filtered_list;
}

haha - 2025