field_before(); $args = wp_parse_args( $this->field, array( 'font_family' => true, 'font_weight' => true, 'font_style' => true, 'font_size' => true, 'line_height' => true, 'tablet_font_size' => true, 'tablet_line_height' => true, 'mobile_font_size' => true, 'mobile_line_height' => true, 'letter_spacing' => true, 'text_align' => true, 'text_transform' => true, 'color' => true, 'hover_color' => false, 'chosen' => true, 'preview' => true, 'subset' => true, 'multi_subset' => false, 'extra_styles' => false, 'backup_font_family' => false, 'font_variant' => false, 'word_spacing' => false, 'text_decoration' => false, 'custom_style' => false, 'exclude' => '', 'unit' => 'px', 'preview_text' => 'The quick brown fox jumps over the lazy dog', ) ); $default_value = array( 'font-family' => '', 'font-weight' => '', 'font-style' => '', 'font-variant' => '', 'font-size' => '', 'line-height' => '', 'tablet-font-size' => '', 'tablet-line-height' => '', 'mobile-font-size' => '', 'mobile-line-height' => '', 'letter-spacing' => '', 'word-spacing' => '', 'text-align' => '', 'text-transform' => '', 'text-decoration' => '', 'backup-font-family' => '', 'color' => '', 'hover_color' => '', 'custom-style' => '', 'type' => '', 'subset' => '', 'extra-styles' => array(), ); $default_value = ( ! empty( $this->field['default'] ) ) ? wp_parse_args( $this->field['default'], $default_value ) : $default_value; $this->value = wp_parse_args( $this->value, $default_value ); $this->chosen = $args['chosen']; $chosen_class = ( $this->chosen ) ? ' spf--chosen' : ''; echo '
'; echo '
'; // // Font Family. if ( ! empty( $args['font_family'] ) ) { echo '
'; echo '
' . esc_html__( 'Font Family', 'smart-post-show' ) . '
'; echo $this->create_select( array( $this->value['font-family'] => $this->value['font-family'] ), 'font-family', esc_html__( 'Select a font', 'smart-post-show' ) ); echo '
'; } // // Backup Font Family. if ( ! empty( $args['backup_font_family'] ) ) { echo ''; } // // Font Style and Extra Style Select. if ( ! empty( $args['font_weight'] ) || ! empty( $args['font_style'] ) ) { // // Font Style Select. echo ''; } // // Subset. if ( ! empty( $args['subset'] ) ) { echo ''; } // // Text Align. if ( ! empty( $args['text_align'] ) ) { echo '
'; echo '
' . esc_html__( 'Text Align', 'smart-post-show' ) . '
'; echo $this->create_select( array( 'inherit' => esc_html__( 'Inherit', 'smart-post-show' ), 'left' => esc_html__( 'Left', 'smart-post-show' ), 'center' => esc_html__( 'Center', 'smart-post-show' ), 'right' => esc_html__( 'Right', 'smart-post-show' ), 'justify' => esc_html__( 'Justify', 'smart-post-show' ), 'initial' => esc_html__( 'Initial', 'smart-post-show' ), ), 'text-align', esc_html__( 'Default', 'smart-post-show' ) ); echo '
'; } // // Font Variant. if ( ! empty( $args['font_variant'] ) ) { echo '
'; echo '
' . esc_html__( 'Font Variant', 'smart-post-show' ) . '
'; echo $this->create_select( array( 'normal' => esc_html__( 'Normal', 'smart-post-show' ), 'small-caps' => esc_html__( 'Small Caps', 'smart-post-show' ), 'all-small-caps' => esc_html__( 'All Small Caps', 'smart-post-show' ), ), 'font-variant', esc_html__( 'Default', 'smart-post-show' ) ); echo '
'; } // // Text Transform. if ( ! empty( $args['text_transform'] ) ) { echo '
'; echo '
' . esc_html__( 'Text Transform', 'smart-post-show' ) . '
'; echo $this->create_select( array( 'none' => esc_html__( 'None', 'smart-post-show' ), 'capitalize' => esc_html__( 'Capitalize', 'smart-post-show' ), 'uppercase' => esc_html__( 'Uppercase', 'smart-post-show' ), 'lowercase' => esc_html__( 'Lowercase', 'smart-post-show' ), ), 'text-transform', esc_html__( 'Default', 'smart-post-show' ) ); echo '
'; } // // Text Decoration. if ( ! empty( $args['text_decoration'] ) ) { echo '
'; echo '
' . esc_html__( 'Text Decoration', 'smart-post-show' ) . '
'; echo $this->create_select( array( 'none' => esc_html__( 'None', 'smart-post-show' ), 'underline' => esc_html__( 'Solid', 'smart-post-show' ), 'underline double' => esc_html__( 'Double', 'smart-post-show' ), 'underline dotted' => esc_html__( 'Dotted', 'smart-post-show' ), 'underline dashed' => esc_html__( 'Dashed', 'smart-post-show' ), 'underline wavy' => esc_html__( 'Wavy', 'smart-post-show' ), 'underline overline' => esc_html__( 'Overline', 'smart-post-show' ), 'line-through' => esc_html__( 'Line-through', 'smart-post-show' ), ), 'text-decoration', esc_html__( 'Default', 'smart-post-show' ) ); echo '
'; } echo '
'; // End of .spf--blocks-selects. echo '
'; // // Font Size and Line Height. if ( ! empty( $args['font_size'] ) ) { echo '
'; echo '
' . esc_html__( 'Font Size', 'smart-post-show' ) . '
'; echo '
'; echo ''; echo '' . $args['unit'] . ''; echo '
'; echo '
'; } if ( ! empty( $args['line_height'] ) ) { echo '
'; echo '
' . esc_html__( 'Line Height', 'smart-post-show' ) . '
'; echo '
'; echo ''; echo '' . $args['unit'] . ''; echo '
'; echo '
'; } if ( ! empty( $args['tablet_font_size'] ) ) { echo '
'; echo '
' . esc_html__( 'Font Size (Tablet)', 'smart-post-show' ) . '
'; echo '
'; echo ''; echo '' . $args['unit'] . ''; echo '
'; echo '
'; } if ( ! empty( $args['tablet_line_height'] ) ) { echo '
'; echo '
' . esc_html__( 'Line Height (Tablet)', 'smart-post-show' ) . '
'; echo '
'; echo ''; echo '' . $args['unit'] . ''; echo '
'; echo '
'; } if ( ! empty( $args['mobile_font_size'] ) ) { echo '
'; echo '
' . esc_html__( 'Font Size (Mobile)', 'smart-post-show' ) . '
'; echo '
'; echo ''; echo '' . $args['unit'] . ''; echo '
'; echo '
'; } if ( ! empty( $args['mobile_line_height'] ) ) { echo '
'; echo '
' . esc_html__( 'Line Height (Mobile)', 'smart-post-show' ) . '
'; echo '
'; echo ''; echo '' . $args['unit'] . ''; echo '
'; echo '
'; } // // Letter Spacing. if ( ! empty( $args['letter_spacing'] ) ) { echo '
'; echo '
' . esc_html__( 'Letter Spacing', 'smart-post-show' ) . '
'; echo '
'; echo ''; echo '' . $args['unit'] . ''; echo '
'; echo '
'; } // // Word Spacing. if ( ! empty( $args['word_spacing'] ) ) { echo '
'; echo '
' . esc_html__( 'Word Spacing', 'smart-post-show' ) . '
'; echo '
'; echo ''; echo '' . $args['unit'] . ''; echo '
'; echo '
'; } echo '
'; // End of spf--blocks-inputs. // // Font Color. if ( ! empty( $args['color'] ) ) { echo '
'; $default_color_attr = ( ! empty( $default_value['color'] ) ) ? ' data-default-color="' . $default_value['color'] . '"' : ''; echo '
'; echo '
' . esc_html__( 'Font Color', 'smart-post-show' ) . '
'; echo '
'; echo ''; echo '
'; echo '
'; // // Font Hover Color. if ( ! empty( $args['hover_color'] ) ) { $default_hover_color_attr = ( ! empty( $default_value['hover_color'] ) ) ? ' data-default-color="' . $default_value['hover_color'] . '"' : ''; echo '
'; echo '
' . esc_html__( 'Hover Color', 'smart-post-show' ) . '
'; echo '
'; echo ''; echo '
'; echo '
'; } echo '
'; // End of spf--blocks-color } // // Custom style. if ( ! empty( $args['custom_style'] ) ) { echo '
'; echo '
' . esc_html__( 'Custom Style', 'smart-post-show' ) . '
'; echo ''; echo '
'; } // // Preview. $always_preview = ( $args['preview'] !== 'always' ) ? ' hidden' : ''; if ( ! empty( $args['preview'] ) ) { echo '
'; echo '
'; echo '
' . $args['preview_text'] . '
'; echo '
'; } echo ''; echo ''; echo '
'; echo $this->field_after(); } public function create_select( $options, $name, $placeholder = '', $is_multiple = false ) { $multiple_name = ( $is_multiple ) ? '[]' : ''; $multiple_attr = ( $is_multiple ) ? ' multiple data-multiple="true"' : ''; $chosen_rtl = ( $this->chosen && is_rtl() ) ? ' chosen-rtl' : ''; $output = ''; return $output; } public function enqueue() { if ( ! wp_style_is( 'spf-webfont-loader' ) ) { SP_PC::include_plugin_file( 'fields/typography/google-fonts.php' ); wp_enqueue_script( 'spf-webfont-loader', 'https://ajax.googleapis.com/ajax/libs/webfont/1.6.26/webfont.js', array( 'spf' ), '1.6.28', true ); $webfonts = array(); $customwebfonts = apply_filters( 'spf_field_typography_customwebfonts', array() ); if ( ! empty( $customwebfonts ) ) { $webfonts['custom'] = array( 'label' => esc_html__( 'Custom Web Fonts', 'smart-post-show' ), 'fonts' => $customwebfonts, ); } $webfonts['safe'] = array( 'label' => esc_html__( 'Safe Web Fonts', 'smart-post-show' ), 'fonts' => apply_filters( 'spf_field_typography_safewebfonts', array( 'Arial', 'Arial Black', 'Helvetica', 'Times New Roman', 'Courier New', 'Tahoma', 'Verdana', 'Impact', 'Trebuchet MS', 'Comic Sans MS', 'Lucida Console', 'Lucida Sans Unicode', 'Georgia, serif', 'Palatino Linotype', ) ), ); $webfonts['google'] = array( 'label' => esc_html__( 'Google Web Fonts', 'smart-post-show' ), 'fonts' => apply_filters( 'spf_field_typography_googlewebfonts', spf_get_google_fonts() ), ); $defaultstyles = apply_filters( 'spf_field_typography_defaultstyles', array( 'normal', 'italic', '700', '700italic' ) ); $googlestyles = apply_filters( 'spf_field_typography_googlestyles', array( '100' => 'Thin 100', '100italic' => 'Thin 100 Italic', '200' => 'Extra-Light 200', '200italic' => 'Extra-Light 200 Italic', '300' => 'Light 300', '300italic' => 'Light 300 Italic', 'normal' => 'Normal 400', 'italic' => 'Normal 400 Italic', '500' => 'Medium 500', '500italic' => 'Medium 500 Italic', '600' => 'Semi-Bold 600', '600italic' => 'Semi-Bold 600 Italic', '700' => 'Bold 700', '700italic' => 'Bold 700 Italic', '800' => 'Extra-Bold 800', '800italic' => 'Extra-Bold 800 Italic', '900' => 'Black 900', '900italic' => 'Black 900 Italic', ) ); $webfonts = apply_filters( 'spf_field_typography_webfonts', $webfonts ); wp_localize_script( 'spf', 'spf_typography_json', array( 'webfonts' => $webfonts, 'defaultstyles' => $defaultstyles, 'googlestyles' => $googlestyles, ) ); } } public function enqueue_google_fonts() { $value = $this->value; $families = array(); $is_google = false; if ( ! empty( $this->value['type'] ) ) { $is_google = ( $this->value['type'] === 'google' ) ? true : false; } else { SP_PC::include_plugin_file( 'fields/typography/google-fonts.php' ); $is_google = ( array_key_exists( $this->value['font-family'], spf_get_google_fonts() ) ) ? true : false; } if ( $is_google ) { // set style $font_weight = ( ! empty( $value['font-weight'] ) ) ? $value['font-weight'] : ''; $font_style = ( ! empty( $value['font-style'] ) ) ? $value['font-style'] : ''; if ( $font_weight || $font_style ) { $style = $font_weight . $font_style; $families['style'][ $style ] = $style; } // set extra styles if ( ! empty( $value['extra-styles'] ) ) { foreach ( $value['extra-styles'] as $extra_style ) { $families['style'][ $extra_style ] = $extra_style; } } // set subsets if ( ! empty( $value['subset'] ) ) { $value['subset'] = ( is_array( $value['subset'] ) ) ? $value['subset'] : array_filter( (array) $value['subset'] ); foreach ( $value['subset'] as $subset ) { $families['subset'][ $subset ] = $subset; } } $all_styles = ( ! empty( $families['style'] ) ) ? ':' . implode( ',', $families['style'] ) : ''; $all_subsets = ( ! empty( $families['subset'] ) ) ? ':' . implode( ',', $families['subset'] ) : ''; $families = $this->value['font-family'] . str_replace( array( 'normal', 'italic' ), array( 'n', 'i' ), $all_styles ) . $all_subsets; $this->parent->typographies[] = $families; return $families; } return false; } public function output() { $output = ''; $bg_image = array(); $important = ( ! empty( $this->field['output_important'] ) ) ? '!important' : ''; $element = ( is_array( $this->field['output'] ) ) ? join( ',', $this->field['output'] ) : $this->field['output']; $font_family = ( ! empty( $this->value['font-family'] ) ) ? $this->value['font-family'] : ''; $backup_family = ( ! empty( $this->value['backup-font-family'] ) ) ? ', ' . $this->value['backup-font-family'] : ''; if ( $font_family ) { $output .= 'font-family:"' . $font_family . '"' . $backup_family . $important . ';'; } // Common font properties $properties = array( 'color', 'hover_color', 'font-weight', 'font-style', 'font-variant', 'text-align', 'text-transform', 'text-decoration', ); foreach ( $properties as $property ) { if ( isset( $this->value[ $property ] ) && $this->value[ $property ] !== '' ) { $output .= $property . ':' . $this->value[ $property ] . $important . ';'; } } $properties = array( 'font-size', 'line-height', 'letter-spacing', 'word-spacing', ); $unit = ( ! empty( $this->value['unit'] ) ) ? $this->value['unit'] : ''; foreach ( $properties as $property ) { if ( isset( $this->value[ $property ] ) && $this->value[ $property ] !== '' ) { $output .= $property . ':' . $this->value[ $property ] . $unit . $important . ';'; } } $custom_style = ( ! empty( $this->value['custom-style'] ) ) ? $this->value['custom-style'] : ''; if ( $output ) { $output = $element . '{' . $output . $custom_style . '}'; } $this->parent->output_css .= $output; return $output; } } }