=> 'Barlow:400,500,600,700', 'Bitter' => 'Bitter', 'Cabin' => 'Cabin', 'Cardo' => 'Cardo', 'Carme' => 'Carme', 'Caveat' => 'Caveat:400,700', 'Coda' => 'Coda', 'Codystar' => 'Codystar:300,400', 'Cormorant Garamond' => 'Cormorant Garamond:300,400,700', 'Comfortaa' => 'Comfortaa:300,400,700', 'Coustard' => 'Coustard', 'Gruppo' => 'Gruppo', 'Damion' => 'Damion', 'Dancing Script' => 'Dancing Script', 'Dosis' => 'Dosis:200,300,400,500,600,700,800', 'Droid Sans' => 'Droid Sans', 'Droid Serif' => 'Droid Serif', 'EB Garamond' => 'EB Garamond', 'Exo' => 'Exo:900,700,400,100', 'Finger Paint' => 'Finger Paint', 'Fira Sans' => 'Fira Sans:100,400,700', 'Fjord One' => 'Fjord One', 'Flamenco' => 'Flamenco:400,300', 'Great Vibes' => 'Great Vibes', 'Heebo' => 'Heebo:100,400,700', 'Herr Von Muellerhoff' => 'Herr Von Muellerhoff', 'IBM Plex Serif' => 'IBM Plex Serif:300,400,700', 'Inconsolata' => 'Inconsolata', 'Josefin Sans' => 'Josefin Sans', 'Josefin Slab' => 'Josefin Slab', 'Kameron' => 'Kameron', 'Karla' => 'Karla:400,700', 'Kreon' => 'Kreon', 'Lato' => 'Lato:300,400,700', 'Lobster' => 'Lobster', 'Lora' => 'Lora', 'League Script' => 'League Script', 'Mate SC' => 'Mate SC', 'Marck Script' => 'Marck Script', 'Mako' => 'Mako', 'Megrim' => 'Megrim', 'Merienda' => 'Merienda:400,700', 'Merriweather' => 'Merriweather:300,400,700', 'Metrophobic' => 'Metrophobic', 'Molengo' => 'Molengo', 'Montserrat' => 'Montserrat', 'Muli' => 'Muli', 'Nixie One' => 'Nixie One', 'Nobile' => 'Nobile', 'News Cycle' => 'News Cycle', 'Open Sans' => 'Open Sans:400,600', 'Open Sans Condensed' => 'Open Sans Condensed:300,700', 'Orbitron' => 'Orbitron', 'Oregano' => 'Oregano', 'Oswald' => 'Oswald', 'Pacifico' => 'Pacifico', 'Parisienne' => 'Parisienne', 'Petit Formal Script' => 'Petit Formal Script', 'Pinyon Script' => 'Pinyon Script', 'Playfair Display' => 'Playfair Display:400,700', 'Podkova' => 'Podkova', 'Poiret One' => 'Poiret One', 'Poly' => 'Poly', 'Press Start 2P (Retro Pixelfont)' => 'Press Start 2P', 'PT Sans' => 'PT Sans', 'Quattrocento' => 'Quattrocento', 'Questrial' => 'Questrial', 'Quicksand' => 'Quicksand:400,600', 'Raleway' => 'Raleway', 'Righteous' => 'Righteous', 'Roboto' => 'Roboto:100,400,700', 'Sacramento' => 'Sacramento', 'Salsa' => 'Salsa', 'Signika Negative' => 'Signika Negative', 'Source Serif Pro' => 'Source Serif Pro:400,600,700', 'Sunshiney' => 'Sunshiney', 'Special Elite' => 'Special Elite', 'Tangerine' => 'Tangerine', 'Tenor Sans' => 'Tenor Sans', 'Varela Round' => 'Varela Round', 'Work Sans' => 'Work Sans:700,400,100', 'Yellowtail' => 'Yellowtail', ); /** * Kept for backwards compatibility - will be replaced by next filter */ $fonts = apply_filters('avf_google_heading_font', $fonts ); /** * @since 4.3 * @return array */ $fonts = apply_filters('avf_available_google_fonts', $fonts ); return $fonts; } /** * Returns a list of websafe fonts that can be merged in the select box for selecting fonts * Keys are extended by -websave at the end to be able to recognise them before the array is returned * * For enhancements see https://www.cssfontstack.com/ * * @since 4.3 * @return array */ public function websafe_fonts_select_list() { $fonts = array( 'Arial' => 'Arial', 'Arial Black' => 'Arial-Black', 'Arial Narrow' => 'Arial-Narrow', 'Helvetica' => 'Helvetica', 'Helvetica Neue' => 'Helvetica-Neue,Helvetica', 'Lucida Sans' => 'Lucida-Sans,Lucida-Grande,Lucida-Sans-Unicode', 'Tahoma' => 'Tahoma', 'Trebuchet MS' => 'Trebuchet-MS', 'Verdana' => 'Verdana', 'Georgia' => 'Georgia', 'Lucida Bright' => 'Lucida-Bright', 'Palatino' => 'Palatino', 'Times New Roman' => 'Times-New-Roman', 'Courier New' => 'Courier-New', 'Lucida Sans Typewriter' => 'Lucida-Sans-Typewriter', 'Copperplate' => 'Copperplate', 'Papyrus' => 'Papyrus', 'Brush Script MT' => 'Brush-Script-MT' ); /** * @since 4.3 */ $fonts = apply_filters('avf_available_websafe_fonts', $fonts ); foreach( $fonts as $key => $value ) { if( false === ( strpos( $value, '-websafe' ) ) ) { $value .= '-websave'; } $fonts[ $key ] = $value; } return $fonts; } /** * Returns a list of custom uploaded fonts that can be merged in the select box for selecting fonts * Keys are extended by -customfont at the end to be able to recognise them before the array is returned * * @since 4.3 * @return array */ public function custom_font_select_list() { $fonts = array(); $uploaded = $this->get_font_list(); /** * Sort alphabetically */ $keys = array_keys( $uploaded ); sort( $keys, SORT_STRING ); foreach( $keys as $font_key ) { /** * framework\php\class-htmlhelper.php function select() eliminates fonts with the same name (= key). * To avoid this we add the uploaded font weights to the name of the font. */ $weight = array(); foreach( $uploaded[ $font_key ]['config'] as $key => $desc ) { if( isset( $desc['weight'] ) ) { $weight[] = $desc['weight']; } } $weight = array_unique( $weight ); sort( $weight ); $name = isset( $uploaded[ $font_key ]['config'][0]['name'] ) ? $uploaded[ $font_key ]['config'][0]['name'] : $font_key; $name .= ' (' . implode( ', ', $weight ) . ')'; $fonts[ $name ] = $font_key; } /** * @since 4.3 * @param array $fonts * @return array */ $fonts = apply_filters( 'avf_available_custom_fonts', $fonts ); foreach( $fonts as $key => &$value ) { if( false === ( strpos( $value, '-custom' ) ) ) { $value .= '-custom'; } } return $fonts; } /** * Returns the options array for a font select box. Adds optgroup so the user knows what type of font he selects. * * @since 4.3 * @param array $source 'all' | 'websafe' | 'custom' | 'google' * @param string $cache 'cache' | 'no_cache' * @param string|array $default 'add_default' | 'no_default' | array ( 'value' => 'key' ) * @return array */ public function get_font_select_options_list( array $source = array( 'all' ), $cache = 'cache', $default = 'add_default' ) { if( ! empty( $this->select_options_font_list ) && ( 'cache' == $cache ) ) { return $this->select_options_font_list; } $font_types = apply_filters( 'avf_font_select_options_order', array( 'websafe', 'google', 'custom' ) ); $options = array(); if( 'add_default' == $default ) { $options[ __( 'Default', 'avia_framework' ) ] = ''; } else if( is_array( $default ) && ! empty( $default ) ) { $options = $default; } foreach( $font_types as $font_type ) { $intersect = array_intersect( array( 'all', $font_type ), $source ); if( ! empty( $intersect ) ) { $fonts = array(); switch( $font_type ) { case 'custom': $fonts = $this->custom_font_select_list(); $optgroup = __( 'Uploaded Fonts (located at Enfold -> Import/Export)', 'avia_framework' ); break; case 'websafe'; $fonts = $this->websafe_fonts_select_list(); $optgroup = __( 'Websafe Fonts', 'avia_framework' ); break; case 'google'; $fonts = $this->google_fonts_select_list(); $optgroup = __( 'Google Fonts', 'avia_framework' ); break; } if( ! empty( $fonts ) ) { $options[ $optgroup ] = $fonts; } } } if( 'cache' == $cache ) { $this->select_options_font_list = $options; } return $options; } /** * Returns the CSS for a single font. * $font must have the stucture from an entry of $this->add_font * * @since 4.3 * @param array $font_info * @return sting */ public function get_css_custom_font_face( array $font_info ) { $font = $font_info['config']; $css = ''; foreach( $font as $key => $info ) { if( ! is_numeric( $key ) ) { continue; } $urls = array(); foreach( $info['files'] as $ext => $file ) { if( ! array_key_exists( $ext, $this->css_formats ) ) { continue; } $url = trailingslashit( $font_info['origin_url'] . $font_info['folder'] ) . $file; switch( $ext ) { case 'eot': $iefix = $url . "?#iefix"; // IE6-IE8 $urls[] = " url('{$url}') {$this->css_formats[ $ext ]}"; $urls[] = " url('{$iefix}') {$this->css_formats[ $ext ]}"; break; case 'svg': $urls[] = " url('{$url}#{$font['key']}') {$this->css_formats[ $ext ]}"; break; default: $urls[] = " url('{$url}') {$this->css_formats[ $ext ]}"; break; } } if( empty( $urls ) ) { continue; } /** * Allow to change default behaviour of browsers when loading external fonts * https://developers.google.com/web/updates/2016/02/font-display * * @since 4.5.6 * @param string $font_display * @param string $font_name * @return string auto | block | swap | fallback | optional */ $font_display = apply_filters( 'avf_font_display', avia_get_option( 'custom_font_display', '' ), $font['key'] ); $font_display = empty( $font_display ) ? 'auto' : $font_display; $css .= "@font-face { \r\n"; $css .= " font-family: '{$font['key']}';\r\n"; $css .= " src: "; $css .= implode( ",\r\n ", $urls ); $css .= ";\r\n"; $css .= " font-style: {$info['style']};\r\n"; $css .= " font-weight: {$info['weight']};\r\n"; $css .= " font-display: {$font_display};\r\n"; $css .= "}\r\n"; } return $css; } /** * Output styles for custom uploaded fonts * * @since 4.3 */ public function handler_wp_print_styles() { $uploaded = $this->get_font_list(); $out = '' . "\r\n"; echo $out; } /** * Output styles for custom uploaded fonts to dynamic stylesheet * * @param string $output * @param avia_style_generator $style_generator * @param string $context 'before' | 'after' * @return string */ public function handler_create_dynamic_stylesheet( $output, avia_style_generator $style_generator, $context = '' ) { if( ! in_array( $context, array( 'before' ) ) ) { return $output; } $uploaded = $this->get_font_list(); $output .= "\r\n"; foreach( $uploaded as $font_info ) { $output .= $this->get_css_custom_font_face( $font_info ); } $output .= "\r\n"; return $output; } /** * Splits the selected font string (option value from font select box) * * @since 4.3 * @param string $selection * @return array */ public function split_font_info( $selection ) { /** * Split font sizes for Google fonts */ $info = explode( ':', $selection ); $font = array( 'family' => trim( $info[0] ), 'weight' => isset( $info[1] ) ? trim( $info[1] ) : '' ); return $font; } /** * Returns the type of font selected from a select box * * @since 4.3 * @param array $font_info * @return string 'websave' | 'custom' | 'google' */ public function get_selected_font_type( array $font_info ) { if( strpos( $font_info['family'], '-websave' ) !== false ) { return 'websave'; } if( strpos( $font_info['family'], '-custom' ) !== false ) { return 'custom'; } return 'google'; } /** * Removes any font type mark from first font name, removes ",' and returns the fontname in lowercase * * @since 4.3 * @param array $font_info * @return array */ public function set_font_family( array $font_info ) { $type = $this->get_selected_font_type( $font_info ); switch( $type ) { case 'websave': case 'custom': $replace = '-' . $type; break; default: return $font_info; } /** * In case we have several fonts we only take the first one */ $font_family = explode( ',', $font_info['family'] ); $font_family = strtolower( $font_family[0] ); $font_family = str_replace( array( '"', "'" ), '', $font_family ); $font_info['family'] = str_replace( $replace, '', $font_family ); return $font_info; } }