| Server IP : 60.247.133.247 / Your IP : 216.73.217.108 Web Server : Apache System : Linux ebs-119054 5.10.0-14-amd64 #1 SMP Debian 5.10.113-1 (2022-04-29) x86_64 User : goodwill ( 65985) PHP Version : 8.2.20 Disable Function : link,symlink,passthru,exec,system,shell_exec,proc_open,popen,pcntl_exec,socket_bind,stream_socket_server,pcntl_fork,pcntl_rfork MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /home/wwwroot/goodwill/wwwroot/wp-content/themes/GoodWill/inc/ |
Upload File : |
<?php
/**
* @package The7
*/
defined( 'ABSPATH' ) || exit;
class The7_Web_Fonts_Compressor {
/**
* @var array
*/
protected $fonts = array();
/**
* @var string
*/
protected $display = '';
/**
* The7_Web_Fonts_Compressor constructor.
*
* @param array $fonts
*/
public function __construct( array $fonts ) {
foreach ( $fonts as &$font ) {
if ( ! $font instanceof The7_Web_Font_Interface ) {
$font = new The7_Web_Font( $font );
}
}
$this->fonts = $fonts;
}
/**
* @param string $display
*/
public function add_display_prop( $display ) {
$this->display = $display;
}
/**
* @return string
*/
public function compress_to_url() {
$compressed_fonts = $this->compress_fonts_to_array( $this->fonts );
$query_args = array(
'family' => implode( '%7C', $compressed_fonts ),
);
if ( $this->display ) {
$query_args['display'] = sanitize_key( $this->display );
}
return add_query_arg( $query_args, 'https://fonts.googleapis.com/css' );
}
/**
* @param array $fonts
*
* @return array
*/
protected function compress_fonts_to_array( array $fonts ) {
$compressed_fonts = array();
foreach ( $fonts as $font ) {
$family = $font->get_family();
if ( ! $family ) {
continue;
}
if ( ! array_key_exists( $family, $compressed_fonts ) ) {
$compressed_fonts[ $family ] = array();
}
$weight = $font->get_weight();
if ( $weight ) {
$compressed_fonts[ $family ] = array_merge( $compressed_fonts[ $family ], $weight );
}
}
$composed_string_parts = array();
foreach ( $compressed_fonts as $font_family => $font_data ) {
$composed_font = str_replace( ' ', '+', $font_family );
if ( ! empty( $font_data ) ) {
$font_data = array_unique( $font_data );
sort( $font_data );
$composed_font .= ':' . implode( ',', $font_data );
}
$composed_string_parts[] = $composed_font;
}
return $composed_string_parts;
}
}