PluginProbe
Smart Post – Post Grid, Post Carousel, Post Slider Gutenberg Blocks for Blog & News / 2.2.10
Smart Post – Post Grid, Post Carousel, Post Slider Gutenberg Blocks for Blog & News v2.2.10
4.0.8 4.0.7 4.0.6 4.0.5 4.0.4 4.0.3 4.0.2 4.0.1 2.3.5 2.3.6 2.4.0 2.4.1 2.4.10 2.4.11 2.4.12 2.4.13 2.4.14 2.4.15 2.4.16 2.4.17 2.4.18 2.4.19 2.4.2 2.4.20 2.4.21 All 88 releases
post-carousel / admin / views / sp-framework / fields / typography / typography.php

typography.php in Smart Post – Post Grid, Post Carousel, Post Slider Gutenberg Blocks for Blog & News 2.2.10, at admin/views/sp-framework/fields/typography/typography.php

625 lines 23.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php if ( ! defined( 'ABSPATH' ) ) {
2 die; } // Cannot access directly.
3 /**
4 *
5 * Field: typography
6 *
7 * @since 1.0.0
8 * @version 1.0.0
9 */
10 if ( ! class_exists( 'SP_PC_Field_typography' ) ) {
11 class SP_PC_Field_typography extends SP_PC_Fields {
12
13 public $chosen = false;
14
15 public $value = array();
16
17 public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) {
18 parent::__construct( $field, $value, $unique, $where, $parent );
19 }
20
21 public function render() {
22
23 echo $this->field_before();
24
25 $args = wp_parse_args(
26 $this->field,
27 array(
28 'font_family' => true,
29 'font_weight' => true,
30 'font_style' => true,
31 'font_size' => true,
32 'line_height' => true,
33 'tablet_font_size' => true,
34 'tablet_line_height' => true,
35 'mobile_font_size' => true,
36 'mobile_line_height' => true,
37 'letter_spacing' => true,
38 'text_align' => true,
39 'text_transform' => true,
40 'color' => true,
41 'hover_color' => false,
42 'chosen' => true,
43 'preview' => true,
44 'subset' => true,
45 'multi_subset' => false,
46 'extra_styles' => false,
47 'backup_font_family' => false,
48 'font_variant' => false,
49 'word_spacing' => false,
50 'text_decoration' => false,
51 'custom_style' => false,
52 'exclude' => '',
53 'unit' => 'px',
54 'preview_text' => 'The quick brown fox jumps over the lazy dog',
55 )
56 );
57
58 $default_value = array(
59 'font-family' => '',
60 'font-weight' => '',
61 'font-style' => '',
62 'font-variant' => '',
63 'font-size' => '',
64 'line-height' => '',
65 'tablet-font-size' => '',
66 'tablet-line-height' => '',
67 'mobile-font-size' => '',
68 'mobile-line-height' => '',
69 'letter-spacing' => '',
70 'word-spacing' => '',
71 'text-align' => '',
72 'text-transform' => '',
73 'text-decoration' => '',
74 'backup-font-family' => '',
75 'color' => '',
76 'hover_color' => '',
77 'custom-style' => '',
78 'type' => '',
79 'subset' => '',
80 'extra-styles' => array(),
81 );
82
83 $default_value = ( ! empty( $this->field['default'] ) ) ? wp_parse_args( $this->field['default'], $default_value ) : $default_value;
84 $this->value = wp_parse_args( $this->value, $default_value );
85 $this->chosen = $args['chosen'];
86 $chosen_class = ( $this->chosen ) ? ' spf--chosen' : '';
87
88 echo '<div class="spf--typography' . $chosen_class . '" data-unit="' . $args['unit'] . '" data-exclude="' . $args['exclude'] . '">';
89
90 echo '<div class="spf--blocks spf--blocks-selects">';
91
92 //
93 // Font Family.
94 if ( ! empty( $args['font_family'] ) ) {
95 echo '<div class="spf--block">';
96 echo '<div class="spf--title">' . esc_html__( 'Font Family', 'smart-post-show' ) . '</div>';
97 echo $this->create_select( array( $this->value['font-family'] => $this->value['font-family'] ), 'font-family', esc_html__( 'Select a font', 'smart-post-show' ) );
98 echo '</div>';
99 }
100
101 //
102 // Backup Font Family.
103 if ( ! empty( $args['backup_font_family'] ) ) {
104 echo '<div class="spf--block spf--block-backup-font-family hidden">';
105 echo '<div class="spf--title">' . esc_html__( 'Backup Font Family', 'smart-post-show' ) . '</div>';
106 echo $this->create_select(
107 apply_filters(
108 'spf_field_typography_backup_font_family',
109 array(
110 'Arial, Helvetica, sans-serif',
111 "'Arial Black', Gadget, sans-serif",
112 "'Comic Sans MS', cursive, sans-serif",
113 'Impact, Charcoal, sans-serif',
114 "'Lucida Sans Unicode', 'Lucida Grande', sans-serif",
115 'Tahoma, Geneva, sans-serif',
116 "'Trebuchet MS', Helvetica, sans-serif'",
117 'Verdana, Geneva, sans-serif',
118 "'Courier New', Courier, monospace",
119 "'Lucida Console', Monaco, monospace",
120 'Georgia, serif',
121 'Palatino Linotype',
122 )
123 ),
124 'backup-font-family',
125 esc_html__( 'Default', 'smart-post-show' )
126 );
127 echo '</div>';
128 }
129
130 //
131 // Font Style and Extra Style Select.
132 if ( ! empty( $args['font_weight'] ) || ! empty( $args['font_style'] ) ) {
133
134 //
135 // Font Style Select.
136 echo '<div class="spf--block spf--block-font-style hidden">';
137 echo '<div class="spf--title">' . esc_html__( 'Font Style', 'smart-post-show' ) . '</div>';
138 echo '<select class="spf--font-style-select" data-placeholder="Default">';
139 echo '<option value="">' . ( ! $this->chosen ? esc_html__( 'Default', 'smart-post-show' ) : '' ) . '</option>';
140 if ( ! empty( $this->value['font-weight'] ) || ! empty( $this->value['font-style'] ) ) {
141 echo '<option value="' . strtolower( $this->value['font-weight'] . $this->value['font-style'] ) . '" selected></option>';
142 }
143 echo '</select>';
144 echo '<input type="hidden" name="' . $this->field_name( '[font-weight]' ) . '" class="spf--font-weight" value="' . $this->value['font-weight'] . '" />';
145 echo '<input type="hidden" name="' . $this->field_name( '[font-style]' ) . '" class="spf--font-style" value="' . $this->value['font-style'] . '" />';
146
147 //
148 // Extra Font Style Select.
149 if ( ! empty( $args['extra_styles'] ) ) {
150 echo '<div class="spf--block-extra-styles hidden">';
151 echo ( ! $this->chosen ) ? '<div class="spf--title">' . esc_html__( 'Load Extra Styles', 'smart-post-show' ) . '</div>' : '';
152 $placeholder = ( $this->chosen ) ? esc_html__( 'Load Extra Styles', 'smart-post-show' ) : esc_html__( 'Default', 'smart-post-show' );
153 echo $this->create_select( $this->value['extra-styles'], 'extra-styles', $placeholder, true );
154 echo '</div>';
155 }
156
157 echo '</div>';
158
159 }
160
161 //
162 // Subset.
163 if ( ! empty( $args['subset'] ) ) {
164 echo '<div class="spf--block spf--block-subset hidden">';
165 echo '<div class="spf--title">' . esc_html__( 'Subset', 'smart-post-show' ) . '</div>';
166 $subset = ( is_array( $this->value['subset'] ) ) ? $this->value['subset'] : array_filter( (array) $this->value['subset'] );
167 echo $this->create_select( $subset, 'subset', esc_html__( 'Default', 'smart-post-show' ), $args['multi_subset'] );
168 echo '</div>';
169 }
170
171 //
172 // Text Align.
173 if ( ! empty( $args['text_align'] ) ) {
174 echo '<div class="spf--block">';
175 echo '<div class="spf--title">' . esc_html__( 'Text Align', 'smart-post-show' ) . '</div>';
176 echo $this->create_select(
177 array(
178 'inherit' => esc_html__( 'Inherit', 'smart-post-show' ),
179 'left' => esc_html__( 'Left', 'smart-post-show' ),
180 'center' => esc_html__( 'Center', 'smart-post-show' ),
181 'right' => esc_html__( 'Right', 'smart-post-show' ),
182 'justify' => esc_html__( 'Justify', 'smart-post-show' ),
183 'initial' => esc_html__( 'Initial', 'smart-post-show' ),
184 ),
185 'text-align',
186 esc_html__( 'Default', 'smart-post-show' )
187 );
188 echo '</div>';
189 }
190
191 //
192 // Font Variant.
193 if ( ! empty( $args['font_variant'] ) ) {
194 echo '<div class="spf--block">';
195 echo '<div class="spf--title">' . esc_html__( 'Font Variant', 'smart-post-show' ) . '</div>';
196 echo $this->create_select(
197 array(
198 'normal' => esc_html__( 'Normal', 'smart-post-show' ),
199 'small-caps' => esc_html__( 'Small Caps', 'smart-post-show' ),
200 'all-small-caps' => esc_html__( 'All Small Caps', 'smart-post-show' ),
201 ),
202 'font-variant',
203 esc_html__( 'Default', 'smart-post-show' )
204 );
205 echo '</div>';
206 }
207
208 //
209 // Text Transform.
210 if ( ! empty( $args['text_transform'] ) ) {
211 echo '<div class="spf--block">';
212 echo '<div class="spf--title">' . esc_html__( 'Text Transform', 'smart-post-show' ) . '</div>';
213 echo $this->create_select(
214 array(
215 'none' => esc_html__( 'None', 'smart-post-show' ),
216 'capitalize' => esc_html__( 'Capitalize', 'smart-post-show' ),
217 'uppercase' => esc_html__( 'Uppercase', 'smart-post-show' ),
218 'lowercase' => esc_html__( 'Lowercase', 'smart-post-show' ),
219 ),
220 'text-transform',
221 esc_html__( 'Default', 'smart-post-show' )
222 );
223 echo '</div>';
224 }
225
226 //
227 // Text Decoration.
228 if ( ! empty( $args['text_decoration'] ) ) {
229 echo '<div class="spf--block">';
230 echo '<div class="spf--title">' . esc_html__( 'Text Decoration', 'smart-post-show' ) . '</div>';
231 echo $this->create_select(
232 array(
233 'none' => esc_html__( 'None', 'smart-post-show' ),
234 'underline' => esc_html__( 'Solid', 'smart-post-show' ),
235 'underline double' => esc_html__( 'Double', 'smart-post-show' ),
236 'underline dotted' => esc_html__( 'Dotted', 'smart-post-show' ),
237 'underline dashed' => esc_html__( 'Dashed', 'smart-post-show' ),
238 'underline wavy' => esc_html__( 'Wavy', 'smart-post-show' ),
239 'underline overline' => esc_html__( 'Overline', 'smart-post-show' ),
240 'line-through' => esc_html__( 'Line-through', 'smart-post-show' ),
241 ),
242 'text-decoration',
243 esc_html__( 'Default', 'smart-post-show' )
244 );
245 echo '</div>';
246 }
247
248 echo '</div>'; // End of .spf--blocks-selects.
249
250 echo '<div class="spf--blocks spf--blocks-inputs">';
251
252 //
253 // Font Size and Line Height.
254 if ( ! empty( $args['font_size'] ) ) {
255 echo '<div class="spf--block">';
256 echo '<div class="spf--title">' . esc_html__( 'Font Size', 'smart-post-show' ) . '</div>';
257 echo '<div class="spf--input-wrap">';
258 echo '<input type="number" disabled="disabled" name="' . $this->field_name( '[font-size]' ) . '" class="spf--font-size spf--input spf-input-number" value="' . $this->value['font-size'] . '" />';
259 echo '<span class="spf--unit">' . $args['unit'] . '</span>';
260 echo '</div>';
261 echo '</div>';
262 }
263 if ( ! empty( $args['line_height'] ) ) {
264 echo '<div class="spf--block">';
265 echo '<div class="spf--title">' . esc_html__( 'Line Height', 'smart-post-show' ) . '</div>';
266 echo '<div class="spf--input-wrap">';
267 echo '<input type="number" disabled="disabled" name="' . $this->field_name( '[line-height]' ) . '" class="spf--line-height spf--input spf-input-number" value="' . $this->value['line-height'] . '" />';
268 echo '<span class="spf--unit">' . $args['unit'] . '</span>';
269 echo '</div>';
270 echo '</div>';
271 }
272 if ( ! empty( $args['tablet_font_size'] ) ) {
273 echo '<div class="spf--block">';
274 echo '<div class="spf--title">' . esc_html__( 'Font Size (Tablet)', 'smart-post-show' ) . '</div>';
275 echo '<div class="spf--input-wrap">';
276 echo '<input type="number" disabled="disabled" name="' . $this->field_name( '[tablet-font-size]' ) . '" class="spf--font-size spf--input spf-input-number" value="' . $this->value['tablet-font-size'] . '" />';
277 echo '<span class="spf--unit">' . $args['unit'] . '</span>';
278 echo '</div>';
279 echo '</div>';
280 }
281 if ( ! empty( $args['tablet_line_height'] ) ) {
282 echo '<div class="spf--block">';
283 echo '<div class="spf--title">' . esc_html__( 'Line Height (Tablet)', 'smart-post-show' ) . '</div>';
284 echo '<div class="spf--input-wrap">';
285 echo '<input type="number" disabled="disabled" name="' . $this->field_name( '[tablet-line-height]' ) . '" class="spf--line-height spf--input spf-input-number" value="' . $this->value['tablet-line-height'] . '" />';
286 echo '<span class="spf--unit">' . $args['unit'] . '</span>';
287 echo '</div>';
288 echo '</div>';
289 }
290 if ( ! empty( $args['mobile_font_size'] ) ) {
291 echo '<div class="spf--block">';
292 echo '<div class="spf--title">' . esc_html__( 'Font Size (Mobile)', 'smart-post-show' ) . '</div>';
293 echo '<div class="spf--input-wrap">';
294 echo '<input type="number" disabled="disabled" name="' . $this->field_name( '[mobile-font-size]' ) . '" class="spf--font-size spf--input spf-input-number" value="' . $this->value['mobile-font-size'] . '" />';
295 echo '<span class="spf--unit">' . $args['unit'] . '</span>';
296 echo '</div>';
297 echo '</div>';
298 }
299 if ( ! empty( $args['mobile_line_height'] ) ) {
300 echo '<div class="spf--block">';
301 echo '<div class="spf--title">' . esc_html__( 'Line Height (Mobile)', 'smart-post-show' ) . '</div>';
302 echo '<div class="spf--input-wrap">';
303 echo '<input type="number" disabled="disabled" name="' . $this->field_name( '[mobile-line-height]' ) . '" class="spf--line-height spf--input spf-input-number" disabled="disabled" value="' . $this->value['mobile-line-height'] . '" />';
304 echo '<span class="spf--unit">' . $args['unit'] . '</span>';
305 echo '</div>';
306 echo '</div>';
307 }
308
309 //
310 // Letter Spacing.
311 if ( ! empty( $args['letter_spacing'] ) ) {
312 echo '<div class="spf--block">';
313 echo '<div class="spf--title">' . esc_html__( 'Letter Spacing', 'smart-post-show' ) . '</div>';
314 echo '<div class="spf--input-wrap">';
315 echo '<input type="number" disabled="disabled" name="' . $this->field_name( '[letter-spacing]' ) . '" class="spf--letter-spacing spf--input spf-input-number" value="' . $this->value['letter-spacing'] . '" />';
316 echo '<span class="spf--unit">' . $args['unit'] . '</span>';
317 echo '</div>';
318 echo '</div>';
319 }
320
321 //
322 // Word Spacing.
323 if ( ! empty( $args['word_spacing'] ) ) {
324 echo '<div class="spf--block">';
325 echo '<div class="spf--title">' . esc_html__( 'Word Spacing', 'smart-post-show' ) . '</div>';
326 echo '<div class="spf--input-wrap">';
327 echo '<input type="number" disabled="disabled" name="' . $this->field_name( '[word-spacing]' ) . '" class="spf--word-spacing spf--input spf-input-number" value="' . $this->value['word-spacing'] . '" />';
328 echo '<span class="spf--unit">' . $args['unit'] . '</span>';
329 echo '</div>';
330 echo '</div>';
331 }
332
333 echo '</div>'; // End of spf--blocks-inputs.
334
335 //
336 // Font Color.
337 if ( ! empty( $args['color'] ) ) {
338 echo '<div class="spf--blocks spf--blocks-color">';
339 $default_color_attr = ( ! empty( $default_value['color'] ) ) ? ' data-default-color="' . $default_value['color'] . '"' : '';
340 echo '<div class="spf--block spf--block-font-color">';
341 echo '<div class="spf--title">' . esc_html__( 'Font Color', 'smart-post-show' ) . '</div>';
342 echo '<div class="spf-field-color">';
343 echo '<input type="text" name="' . $this->field_name( '[color]' ) . '" class="spf-color spf--color" value="' . $this->value['color'] . '"' . $default_color_attr . ' />';
344 echo '</div>';
345 echo '</div>';
346
347 //
348 // Font Hover Color.
349 if ( ! empty( $args['hover_color'] ) ) {
350 $default_hover_color_attr = ( ! empty( $default_value['hover_color'] ) ) ? ' data-default-color="' . $default_value['hover_color'] . '"' : '';
351 echo '<div class="spf--block spf--block-font-color">';
352 echo '<div class="spf--title">' . esc_html__( 'Hover Color', 'smart-post-show' ) . '</div>';
353 echo '<div class="spf-field-color">';
354 echo '<input type="text" name="' . $this->field_name( '[hover_color]' ) . '" class="spf-color spf--color" value="' . $this->value['hover_color'] . '"' . $default_hover_color_attr . ' />';
355 echo '</div>';
356 echo '</div>';
357 }
358 echo '</div>'; // End of spf--blocks-color
359 }
360
361 //
362 // Custom style.
363 if ( ! empty( $args['custom_style'] ) ) {
364 echo '<div class="spf--block spf--block-custom-style">';
365 echo '<div class="spf--title">' . esc_html__( 'Custom Style', 'smart-post-show' ) . '</div>';
366 echo '<textarea disabled="disabled" name="' . $this->field_name( '[custom-style]' ) . '" class="spf--custom-style">' . $this->value['custom-style'] . '</textarea>';
367 echo '</div>';
368 }
369
370 //
371 // Preview.
372 $always_preview = ( $args['preview'] !== 'always' ) ? ' hidden' : '';
373
374 if ( ! empty( $args['preview'] ) ) {
375 echo '<div class="spf--block spf--block-preview' . $always_preview . '">';
376 echo '<div class="spf--toggle fa fa-toggle-off"></div>';
377 echo '<div class="spf--preview">' . $args['preview_text'] . '</div>';
378 echo '</div>';
379 }
380
381 echo '<input type="hidden" name="' . $this->field_name( '[type]' ) . '" class="spf--type" value="' . $this->value['type'] . '" />';
382 echo '<input type="hidden" name="' . $this->field_name( '[unit]' ) . '" class="spf--unit-save" value="' . $args['unit'] . '" />';
383
384 echo '</div>';
385
386 echo $this->field_after();
387
388 }
389
390 public function create_select( $options, $name, $placeholder = '', $is_multiple = false ) {
391
392 $multiple_name = ( $is_multiple ) ? '[]' : '';
393 $multiple_attr = ( $is_multiple ) ? ' multiple data-multiple="true"' : '';
394 $chosen_rtl = ( $this->chosen && is_rtl() ) ? ' chosen-rtl' : '';
395
396 $output = '<select disabled="disabled" name="' . $this->field_name( '[' . $name . ']' . $multiple_name ) . '" class="spf--' . $name . $chosen_rtl . '" data-placeholder="' . $placeholder . '"' . $multiple_attr . '>';
397 $output .= ( ! empty( $placeholder ) ) ? '<option value="">' . ( ( ! $this->chosen ) ? $placeholder : '' ) . '</option>' : '';
398
399 if ( ! empty( $options ) ) {
400 foreach ( $options as $option_key => $pcp_metabox_value ) {
401 if ( $is_multiple ) {
402 $selected = ( in_array( $pcp_metabox_value, $this->value[ $name ] ) ) ? ' selected' : '';
403 $output .= '<option value="' . $pcp_metabox_value . '"' . $selected . '>' . $pcp_metabox_value . '</option>';
404 } else {
405 $option_key = ( is_numeric( $option_key ) ) ? $pcp_metabox_value : $option_key;
406 $selected = ( $option_key === $this->value[ $name ] ) ? ' selected' : '';
407 $output .= '<option value="' . $option_key . '"' . $selected . '>' . $pcp_metabox_value . '</option>';
408 }
409 }
410 }
411
412 $output .= '</select>';
413
414 return $output;
415
416 }
417
418 public function enqueue() {
419
420 if ( ! wp_style_is( 'spf-webfont-loader' ) ) {
421
422 SP_PC::include_plugin_file( 'fields/typography/google-fonts.php' );
423
424 wp_enqueue_script( 'spf-webfont-loader', 'https://ajax.googleapis.com/ajax/libs/webfont/1.6.26/webfont.js', array( 'spf' ), '1.6.28', true );
425
426 $webfonts = array();
427
428 $customwebfonts = apply_filters( 'spf_field_typography_customwebfonts', array() );
429
430 if ( ! empty( $customwebfonts ) ) {
431 $webfonts['custom'] = array(
432 'label' => esc_html__( 'Custom Web Fonts', 'smart-post-show' ),
433 'fonts' => $customwebfonts,
434 );
435 }
436
437 $webfonts['safe'] = array(
438 'label' => esc_html__( 'Safe Web Fonts', 'smart-post-show' ),
439 'fonts' => apply_filters(
440 'spf_field_typography_safewebfonts',
441 array(
442 'Arial',
443 'Arial Black',
444 'Helvetica',
445 'Times New Roman',
446 'Courier New',
447 'Tahoma',
448 'Verdana',
449 'Impact',
450 'Trebuchet MS',
451 'Comic Sans MS',
452 'Lucida Console',
453 'Lucida Sans Unicode',
454 'Georgia, serif',
455 'Palatino Linotype',
456 )
457 ),
458 );
459
460 $webfonts['google'] = array(
461 'label' => esc_html__( 'Google Web Fonts', 'smart-post-show' ),
462 'fonts' => apply_filters(
463 'spf_field_typography_googlewebfonts',
464 spf_get_google_fonts()
465 ),
466 );
467
468 $defaultstyles = apply_filters( 'spf_field_typography_defaultstyles', array( 'normal', 'italic', '700', '700italic' ) );
469
470 $googlestyles = apply_filters(
471 'spf_field_typography_googlestyles',
472 array(
473 '100' => 'Thin 100',
474 '100italic' => 'Thin 100 Italic',
475 '200' => 'Extra-Light 200',
476 '200italic' => 'Extra-Light 200 Italic',
477 '300' => 'Light 300',
478 '300italic' => 'Light 300 Italic',
479 'normal' => 'Normal 400',
480 'italic' => 'Normal 400 Italic',
481 '500' => 'Medium 500',
482 '500italic' => 'Medium 500 Italic',
483 '600' => 'Semi-Bold 600',
484 '600italic' => 'Semi-Bold 600 Italic',
485 '700' => 'Bold 700',
486 '700italic' => 'Bold 700 Italic',
487 '800' => 'Extra-Bold 800',
488 '800italic' => 'Extra-Bold 800 Italic',
489 '900' => 'Black 900',
490 '900italic' => 'Black 900 Italic',
491 )
492 );
493
494 $webfonts = apply_filters( 'spf_field_typography_webfonts', $webfonts );
495
496 wp_localize_script(
497 'spf',
498 'spf_typography_json',
499 array(
500 'webfonts' => $webfonts,
501 'defaultstyles' => $defaultstyles,
502 'googlestyles' => $googlestyles,
503 )
504 );
505
506 }
507
508 }
509
510 public function enqueue_google_fonts() {
511
512 $value = $this->value;
513 $families = array();
514 $is_google = false;
515
516 if ( ! empty( $this->value['type'] ) ) {
517 $is_google = ( $this->value['type'] === 'google' ) ? true : false;
518 } else {
519 SP_PC::include_plugin_file( 'fields/typography/google-fonts.php' );
520 $is_google = ( array_key_exists( $this->value['font-family'], spf_get_google_fonts() ) ) ? true : false;
521 }
522
523 if ( $is_google ) {
524
525 // set style
526 $font_weight = ( ! empty( $value['font-weight'] ) ) ? $value['font-weight'] : '';
527 $font_style = ( ! empty( $value['font-style'] ) ) ? $value['font-style'] : '';
528
529 if ( $font_weight || $font_style ) {
530 $style = $font_weight . $font_style;
531 $families['style'][ $style ] = $style;
532 }
533
534 // set extra styles
535 if ( ! empty( $value['extra-styles'] ) ) {
536 foreach ( $value['extra-styles'] as $extra_style ) {
537 $families['style'][ $extra_style ] = $extra_style;
538 }
539 }
540
541 // set subsets
542 if ( ! empty( $value['subset'] ) ) {
543 $value['subset'] = ( is_array( $value['subset'] ) ) ? $value['subset'] : array_filter( (array) $value['subset'] );
544 foreach ( $value['subset'] as $subset ) {
545 $families['subset'][ $subset ] = $subset;
546 }
547 }
548
549 $all_styles = ( ! empty( $families['style'] ) ) ? ':' . implode( ',', $families['style'] ) : '';
550 $all_subsets = ( ! empty( $families['subset'] ) ) ? ':' . implode( ',', $families['subset'] ) : '';
551
552 $families = $this->value['font-family'] . str_replace( array( 'normal', 'italic' ), array( 'n', 'i' ), $all_styles ) . $all_subsets;
553
554 $this->parent->typographies[] = $families;
555
556 return $families;
557
558 }
559
560 return false;
561
562 }
563
564 public function output() {
565
566 $output = '';
567 $bg_image = array();
568 $important = ( ! empty( $this->field['output_important'] ) ) ? '!important' : '';
569 $element = ( is_array( $this->field['output'] ) ) ? join( ',', $this->field['output'] ) : $this->field['output'];
570
571 $font_family = ( ! empty( $this->value['font-family'] ) ) ? $this->value['font-family'] : '';
572 $backup_family = ( ! empty( $this->value['backup-font-family'] ) ) ? ', ' . $this->value['backup-font-family'] : '';
573
574 if ( $font_family ) {
575 $output .= 'font-family:"' . $font_family . '"' . $backup_family . $important . ';';
576 }
577
578 // Common font properties
579 $properties = array(
580 'color',
581 'hover_color',
582 'font-weight',
583 'font-style',
584 'font-variant',
585 'text-align',
586 'text-transform',
587 'text-decoration',
588 );
589
590 foreach ( $properties as $property ) {
591 if ( isset( $this->value[ $property ] ) && $this->value[ $property ] !== '' ) {
592 $output .= $property . ':' . $this->value[ $property ] . $important . ';';
593 }
594 }
595
596 $properties = array(
597 'font-size',
598 'line-height',
599 'letter-spacing',
600 'word-spacing',
601 );
602
603 $unit = ( ! empty( $this->value['unit'] ) ) ? $this->value['unit'] : '';
604
605 foreach ( $properties as $property ) {
606 if ( isset( $this->value[ $property ] ) && $this->value[ $property ] !== '' ) {
607 $output .= $property . ':' . $this->value[ $property ] . $unit . $important . ';';
608 }
609 }
610
611 $custom_style = ( ! empty( $this->value['custom-style'] ) ) ? $this->value['custom-style'] : '';
612
613 if ( $output ) {
614 $output = $element . '{' . $output . $custom_style . '}';
615 }
616
617 $this->parent->output_css .= $output;
618
619 return $output;
620
621 }
622
623 }
624 }
625