PluginProbe
StreamCast – bring live radio to your site with a sleek player / 2.2.3
StreamCast – bring live radio to your site with a sleek player v2.2.3
2.4.5 2.4.4 trunk 1.0 1.1 2.0.0 2.1.10 2.1.2 2.1.4 2.1.5 2.1.8 2.2.1 2.2.3 2.2.4 2.2.5 2.3.0 2.3.1 2.3.2 2.3.3 2.3.4 2.3.5 2.3.6 2.3.7 2.3.8 2.3.9 All 29 releases
streamcast / admin / codestar-framework / fields / typography / typography.php

typography.php in StreamCast – bring live radio to your site with a sleek player 2.2.3, at admin/codestar-framework/fields/typography/typography.php

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