forked from gambitph/Titan-Framework
-
Notifications
You must be signed in to change notification settings - Fork 1
/
class-option-font.php
1254 lines (1112 loc) · 35.9 KB
/
class-option-font.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* Font Option Class
*
* @since 1.4
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
/**
* Font Option Class
*
* @since 1.4
*/
class TitanFrameworkOptionFont extends TitanFrameworkOption {
// Default settings specific to this option
public $defaultSecondarySettings = array(
'show_font_family' => true,
'show_color' => true,
'show_font_size' => true,
'show_font_weight' => true,
'show_font_style' => true,
'show_line_height' => true,
'show_letter_spacing' => true,
'show_text_transform' => true,
'show_font_variant' => true,
'show_text_shadow' => true,
'show_preview' => true,
'enqueue' => true,
'preview_text' => '',
'include_fonts' => '', // A regex string or array of regex strings to match font names to include.
'show_websafe_fonts' => true,
'show_google_fonts' => true,
);
// Default style options
public static $defaultStyling = array(
'font-family' => 'Open Sans',
'color' => '#333333',
'font-size' => '13px',
'font-weight' => 'normal',
'font-style' => 'normal',
'line-height' => '1.5em',
'letter-spacing' => 'normal',
'text-transform' => 'none',
'font-variant' => 'normal',
'text-shadow-location' => 'none',
'text-shadow-distance' => '0px',
'text-shadow-blur' => '0px',
'text-shadow-color' => '#333333',
'text-shadow-opacity' => '1',
'font-type' => 'google', // Only used internally to determine if the font is a
'dark' => '', // only used to toggle the preview background
);
// The list of web safe fonts
public static $webSafeFonts = array(
'Arial, Helvetica, sans-serif' => 'Arial',
'"Arial Black", Gadget, sans-serif' => 'Arial Black',
'"Comic Sans MS", cursive, sans-serif' => 'Comic Sans',
'"Courier New", Courier, monospace' => 'Courier New',
'Georgia, serif' => 'Geogia',
'Impact, Charcoal, sans-serif' => 'Impact',
'"Lucida Console", Monaco, monospace' => 'Lucida Console',
'"Lucida Sans Unicode", "Lucida Grande", sans-serif' => 'Lucida Sans',
'"Palatino Linotype", "Book Antiqua", Palatino, serif' => 'Palatino',
'Tahoma, Geneva, sans-serif' => 'Tahoma',
'"Times New Roman", Times, serif' => 'Times New Roman',
'"Trebuchet MS", Helvetica, sans-serif' => 'Trebuchet',
'Verdana, Geneva, sans-serif' => 'Verdana',
);
// Holds all the Google Fonts for enqueuing
private static $googleFontsOptions = array();
private static $firstLoad = true;
/**
* Constructor
*
* @return void
* @since 1.4
*/
function __construct( $settings, $owner ) {
parent::__construct( $settings, $owner );
add_action( 'admin_enqueue_scripts', array( $this, "loadAdminScripts" ) );
add_action( 'customize_controls_enqueue_scripts', array( $this, 'loadAdminScripts' ) );
add_action( 'admin_head', array( __CLASS__, 'createFontScript' ) );
add_action( 'tf_create_option_' . $this->getOptionNamespace(), array( $this, "rememberGoogleFonts" ) );
add_action( 'wp_enqueue_scripts', array( $this, "enqueueGooglefonts" ) );
add_filter( 'tf_generate_css_font_' . $this->getOptionNamespace(), array( $this, 'generateCSS' ), 10, 2 );
}
/**
* Keeps track of all the Google Fonts used for enqueueing later in wp_enqueue_scripts
*
* @param TitanFramework $option The option being enqueued
* @return void
* @since 1.4
*/
public function rememberGoogleFonts( $option ) {
if ( is_a( $option, __CLASS__ ) ) {
if ( $option->settings['enqueue'] ) {
self::$googleFontsOptions[] = $option;
}
}
}
/**
* Enqueues all the Google fonts, used in wp_enqueue_scripts
*
* @return void
* @since 1.4
*/
public function enqueueGooglefonts() {
if ( ! count( self::$googleFontsOptions ) ) {
return;
}
// Gather all the fonts that we need to load, some may be repeated so we need to
// load them once after gathering them
$fontsToLoad = array();
foreach ( self::$googleFontsOptions as $option ) {
$fontValue = $option->getFramework()->getOption( $option->settings['id'] );
if ( empty( $fontValue['font-family'] ) ) {
continue;
}
if ( $fontValue['font-type'] != 'google' ) {
continue;
}
// Get all the fonts that we need to load
if ( empty( $fontsToLoad[ $fontValue['font-family'] ] ) ) {
$fontsToLoad[ $fontValue['font-family'] ] = array();
}
// Get the weight
$variant = $fontValue['font-weight'];
if ( $variant == 'normal' ) {
$variant = '400';
} else if ( $variant == 'bold' ) {
$variant = '500';
} else if ( $variant == 'bolder' ) {
$variant = '800';
} else if ( $variant == 'lighter' ) {
$variant = '100';
}
if ( $fontValue['font-style'] == 'italic' ) {
$variant .= 'italic';
}
$fontsToLoad[ $fontValue['font-family'] ][] = $variant;
}
// Font subsets, allow others to change this
$subsets = apply_filters( 'tf_google_font_subsets_' . $this->getOptionNamespace(), array( 'latin', 'latin-ext', ) );
// Enqueue the Google Font
foreach ( $fontsToLoad as $fontName => $variants ) {
// Always include the normal weight so that we don't error out
$variants[] = '400';
$variants = array_unique( $variants );
$fontUrl = sprintf( "http://fonts.googleapis.com/css?family=%s:%s&subset=%s",
str_replace( ' ', '+', $fontName ),
implode( ',', $variants ),
implode( ',', $subsets )
);
$fontUrl = apply_filters( 'tf_enqueue_google_webfont_' . $this->getOptionNamespace(), $fontUrl, $fontName );
if ( $fontUrl !== false ) {
wp_enqueue_style( 'tf-google-webfont-' . strtolower( str_replace( ' ', '-', $fontName ) ), $fontUrl );
}
}
// Don't repeat
self::$googleFontsOptions = array();
}
/**
* Generates CSS for the font, this is used in TitanFrameworkCSS
*
* @param string $css The CSS generated
* @param TitanFrameworkOption $option The current option being processed
* @return string The CSS generated
* @since 1.4
*/
public function generateCSS( $css, $option ) {
if ( $this->settings['id'] != $option->settings['id'] ) {
return $css;
}
$value = $this->getFramework()->getOption( $option->settings['id'] );
$skip = array( 'dark', 'font-type', 'text-shadow-distance', 'text-shadow-blur', 'text-shadow-color', 'text-shadow-opacity' );
// If the value is blank, use the defaults
if ( empty( $value ) ) {
$value = $this->getValue();
if ( is_serialized( $value ) ) {
$value = unserialize( $value );
}
if ( ! is_array( $value ) ) {
$value = array();
}
$value = array_merge( self::$defaultStyling, $value );
}
foreach ( $value as $key => $val ) {
// Force skip other keys, those are processed under another key, e.g. text-shadow-distance is
// used by text-shadow-location
if ( in_array( $key, $skip ) ) {
continue;
}
// Don't include keys which are not in the default styles
if ( ! in_array( $key, array_keys( self::$defaultStyling ) ) ) {
continue;
}
if ( $key == 'font-family' ) {
if ( ! empty( $value['font-type'] ) ) {
if ( $value['font-type'] == 'google' ) {
$css .= "\$" . $option->settings['id'] . "-" . $key . ": \"" . $value[ $key ] . "\";";
continue;
}
}
$css .= "\$" . $option->settings['id'] . "-" . $key . ": " . $value[ $key ] . ";";
continue;
}
if ( $key == 'text-shadow-location' ) {
$textShadow = '';
if ( $value[ $key ] != 'none' ) {
if ( stripos( $value[ $key ], 'left' ) !== false ) {
$textShadow .= '-' . $value['text-shadow-distance'];
} else if ( stripos( $value[ $key ], 'right' ) !== false ) {
$textShadow .= $value['text-shadow-distance'];
} else {
$textShadow .= '0';
}
$textShadow .= ' ';
if ( stripos( $value[ $key ], 'top' ) !== false ) {
$textShadow .= '-' . $value['text-shadow-distance'];
} else if ( stripos( $value[ $key ], 'bottom' ) !== false ) {
$textShadow .= $value['text-shadow-distance'];
} else {
$textShadow .= '0';
}
$textShadow .= ' ';
$textShadow .= $value['text-shadow-blur'];
$textShadow .= ' ';
$rgb = tf_hex2rgb( $value['text-shadow-color'] );
$rgb[] = $value['text-shadow-opacity'];
$textShadow .= 'rgba(' . implode( ',', $rgb ) . ')';
} else {
$textShadow .= $value[ $key ];
}
$css .= "\$" . $option->settings['id'] . "-text-shadow: " . $textShadow . ";";
continue;
}
$css .= "\$" . $option->settings['id'] . "-" . $key . ": " . $value[ $key ] . ";";
}
/*
* There are 2 ways to include the values for the CSS. The normal `value-arraykey`, or just `value`
* Using `value` will print out the entire font CSS
*/
// Create the entire CSS for the font, this should just be used to replace the `value` variable
$cssVariables = '';
$cssChecking = array( 'font_family', 'color', 'font_size', 'font_weight', 'font_style', 'line_height', 'letter_spacing', 'text_transform', 'font_variant', 'text_shadow' );
//Enter values that are not marked as false.
foreach ( $cssChecking as $subject ) {
if ( $option->settings['show_'.$subject] ) {
$cssVariableArray[] = str_replace( "_", "-", $subject );
}
}
//Now, integrate these values with their corresponding keys
foreach ( $cssVariableArray as $param ) {
$cssVariables .= $param . ": \$" . $option->settings['id'] . "-" . $param . ";\n";
}
// Replace the `value` parameters in the given css
$modifiedCss = '';
if ( ! empty( $option->settings['css'] ) ) {
$modifiedCss = $option->settings['css'];
// if `value` is given, replace it with the entire css we created above in $cssVariables
$modifiedCss = preg_replace( '/value[^-]/', $cssVariables, $modifiedCss );
// normal `value-arraykey` values
$modifiedCss = str_replace( 'value-', '$' . $option->settings['id'] . '-', $modifiedCss );
}
$css .= $modifiedCss;
return $css;
}
/**
* Enqueues the needed scripts for the admin
*
* @return void
* @since 1.4
*/
public function loadAdminScripts() {
wp_enqueue_script( 'wp-color-picker' );
wp_enqueue_style( 'wp-color-picker' );
}
/**
* Creates the Javascript for running the font option
*
* @return void
* @since 1.4
*/
public static function createFontScript() {
if ( ! self::$firstLoad ) {
return;
}
self::$firstLoad = false;
?>
<script>
jQuery(document).ready(function($) {
"use strict";
var _tf_select_font_throttle = null;
// Initialize color pickers
$('.tf-font .tf-font-sel-color, .tf-font .tf-font-sel-shadow-color').wpColorPicker({
change: function ( event, ui ) {
// update the preview, but throttle it to prevent fast loading
if ( _tf_select_font_throttle != null ) {
clearTimeout( _tf_select_font_throttle );
_tf_select_font_throttle = null;
}
var $this = $(this);
_tf_select_font_throttle = setTimeout( function() {
tf_select_font_update_preview( $this.parents('.tf-font:eq(0)'), true );
}, 300 );
}
});
// Initialize the option
$('.tf-font').each(function() {
// Update save field on change
$(this).find('select,.tf-font-sel-dark').change(function() {
tf_select_font_update_preview( $(this).parents('.tf-font:eq(0)'), true );
});
// Trigger for toggling light/dark preview backgrounds
$(this).find('.btn-dark').click(function() {
var darkInput = $(this).parent().find('.tf-font-sel-dark');
if ( darkInput.val() == '' ) {
darkInput.val('dark').trigger('change');
} else {
darkInput.val('').trigger('change');
}
})
// initialize preview
tf_select_font_update_preview( $(this), true );
// We have to do this after 1ms for the theme customizer, or else the field's value
// gets changed to a weird value
var $this = $(this);
setTimeout( function() {
tf_select_font_update_preview( $this, false )
}, 1 );
});
/**
* Theme Customizer scripts
*/
// Check for font selector clicks, we need to adjust styles to make it look nice
$('body.wp-customizer .tf-font').on('mouseup', function(e) {
if ( $(e.target).is('.wp-color-result') ) {
if ( ! $(e.target).is('.wp-picker-open') ) {
$(e.target).parents('label:eq(0)').addClass('tf-picker-open');
} else {
$(e.target).parents('label:eq(0)').removeClass('tf-picker-open');
}
}
});
// Check for close clicks (clicking outside while the picker is open)
$('body.wp-customizer').on('mouseup', '*', function(e) {
var $target = $(e.target);
if ( $target.is('.wp-color-result, .wp-color-picker, .wp-picker-default') ) {
return;
}
if ( $target.parents('.wp-picker-holder').length > 0 ) {
return;
}
if ( $('.tf-picker-open').length > 0 ) {
$('.tf-picker-open').removeClass('tf-picker-open');
}
});
});
// Updates the option elements
function tf_select_font_update_preview( $container, doTrigger ) {
"use strict";
var $ = jQuery;
// Show / hide shadow fields
if ( $container.find(".tf-font-sel-location").val() == 'none'
|| $container.find('.tf-font-sel-location').parents('label:eq(0)').attr('data-visible') == 'false' ) {
$container.find(".tf-font-sel-distance").parents('label:eq(0)').fadeOut();
$container.find(".tf-font-sel-blur").parents('label:eq(0)').fadeOut();
$container.find(".tf-font-sel-shadow-color").parents('label:eq(0)').fadeOut();
$container.find(".tf-font-sel-opacity").parents('label:eq(0)').fadeOut();
} else {
$container.find(".tf-font-sel-distance").parents('label:eq(0)').fadeIn();
$container.find(".tf-font-sel-blur").parents('label:eq(0)').fadeIn();
$container.find(".tf-font-sel-shadow-color").parents('label:eq(0)').fadeIn();
$container.find(".tf-font-sel-opacity").parents('label:eq(0)').fadeIn();
}
var family = $container.find('.tf-font-sel-family').val();
// These are all our parameters
var params = {
'font-family': family,
'font-type': $container.find(".tf-font-sel-family option[value='" + family + "']").parent().attr('class'),
'color': $container.find(".tf-font-sel-color").val(),
'font-size': $container.find(".tf-font-sel-size").val(),
'font-weight': $container.find(".tf-font-sel-weight").val(),
'font-style': $container.find(".tf-font-sel-style").val(),
'line-height': $container.find(".tf-font-sel-height").val(),
'letter-spacing': $container.find(".tf-font-sel-spacing").val(),
'text-transform': $container.find(".tf-font-sel-transform").val(),
'font-variant': $container.find(".tf-font-sel-variant").val(),
'text-shadow-location': $container.find(".tf-font-sel-location").val(),
'text-shadow-distance': $container.find(".tf-font-sel-distance").val(),
'text-shadow-blur': $container.find(".tf-font-sel-blur").val(),
'text-shadow-color': $container.find(".tf-font-sel-shadow-color").val(),
'text-shadow-opacity': $container.find(".tf-font-sel-opacity").val(),
'dark': $container.find(".tf-font-sel-dark").val(),
'text': $container.find("iframe").attr('data-preview-text')
}
// Update preview
if ( $container.find('iframe').is(':not([data-visible=false])') ) {
$container.find('iframe').attr('src', '<?php echo TitanFramework::getURL( 'iframe-font-preview.php?', __FILE__ ) ?>' + $.param(params) );
}
// Update hidden save field
$container.find('.tf-for-saving').val(serialize(params));
if ( doTrigger ) {
$container.find('.tf-for-saving').trigger('change');
}
}
</script>
<?php
}
/**
* Displays the option in admin panels and meta boxes
*
* @return void
* @since 1.4
*/
public function display() {
$this->echoOptionHeader( true );
// Get the current value and merge with defaults
$value = $this->getValue();
if ( is_serialized( $value ) ) {
$value = unserialize( $value );
}
if ( ! is_array( $value ) ) {
$value = array();
}
$value = array_merge( self::$defaultStyling, $value );
/*
* Create all the fields
*/
$visibilityAttrs = '';
if ( ! $this->settings['show_font_family'] ) {
$visibilityAttrs = "data-visible='false' style='display: none'";
}
?>
<div>
<label <?php echo $visibilityAttrs ?>>
Font Family
<select class='tf-font-sel-family'>
<?php
if ( $this->settings['show_websafe_fonts'] ) {
?>
<optgroup label="Web Safe Fonts" class='safe'>
<?php
foreach ( self::$webSafeFonts as $family => $label ) {
printf( "<option value='%s'%s>%s</option>",
$family,
selected( $value['font-family'], $family, false ),
$label
);
}
?>
</optgroup>
<?php
}
if ( $this->settings['show_google_fonts'] ) {
?>
<optgroup label="Google WebFonts" class='google'>
<?php
$allFonts = titan_get_googlefonts();
foreach ( $allFonts as $key => $fontStuff ) {
// Show only the include_fonts (font names) if provided, uses regex
if ( ! empty( $this->settings['include_fonts'] ) ) {
if ( is_array( $this->settings['include_fonts'] ) ) {
$fontNameMatch = false;
foreach ( $this->settings['include_fonts'] as $fontNamePattern ) {
if ( ! is_string( $fontNamePattern ) ) {
continue;
}
$fontNamePattern = '/' . trim( $fontNamePattern, '/' ) . '/';
if ( preg_match( $fontNamePattern . 'i', $fontStuff['name'] ) ) {
$fontNameMatch = true;
break;
}
}
if ( ! $fontNameMatch ) {
continue;
}
} else if ( is_string( $this->settings['include_fonts'] ) ) {
$fontNamePattern = '/' . trim( $this->settings['include_fonts'], '/' ) . '/';
if ( ! preg_match( $fontNamePattern . 'i', $fontStuff['name'] ) ) {
continue;
}
}
}
printf( "<option value='%s'%s>%s</option>",
esc_attr( $fontStuff['name'] ),
selected( $value['font-family'], $fontStuff['name'], false ),
$fontStuff['name']
);
}
?>
</optgroup>
<?php
}
?>
</select>
</label>
<?php
$visibilityAttrs = '';
if ( ! $this->settings['show_color'] ) {
$visibilityAttrs = "data-visible='false' style='display: none'";
}
?>
<label <?php echo $visibilityAttrs ?>>
Color
<input class='tf-font-sel-color' type="text" value="<?php echo esc_attr( $value['color'] ) ?>" data-default-color="<?php echo esc_attr( $value['color'] ) ?>"/>
</label>
<?php
$visibilityAttrs = '';
if ( ! $this->settings['show_font_size'] ) {
$visibilityAttrs = "data-visible='false' style='display: none'";
}
?>
<label <?php echo $visibilityAttrs ?>>
Font Size
<select class='tf-font-sel-size'>
<?php
for ( $i = 1; $i <= 150; $i++ ) {
printf( "<option value='%s'%s>%s</option>",
esc_attr( $i . 'px' ),
selected( $value['font-size'], $i . 'px', false ),
$i . 'px'
);
}
?>
</select>
</label>
<?php
$visibilityAttrs = '';
if ( ! $this->settings['show_font_weight'] ) {
$visibilityAttrs = "data-visible='false' style='display: none'";
}
?>
<label <?php echo $visibilityAttrs ?>>
Font Weight
<select class='tf-font-sel-weight'>
<?php
$options = array( 'normal', 'bold', 'bolder', 'lighter', '100', '200', '300', '400', '500', '600', '700', '800', '900' );
foreach ( $options as $option ) {
printf( "<option value='%s'%s>%s</option>",
esc_attr( $option ),
selected( $value['font-weight'], $option, false ),
$option
);
}
?>
</select>
</label>
<?php
$visibilityAttrs = '';
if ( ! $this->settings['show_font_style'] ) {
$visibilityAttrs = "data-visible='false' style='display: none'";
}
?>
<label <?php echo $visibilityAttrs ?>>
Font Style
<select class='tf-font-sel-style'>
<?php
$options = array( 'normal', 'italic' );
foreach ( $options as $option ) {
printf( "<option value='%s'%s>%s</option>",
esc_attr( $option ),
selected( $value['font-style'], $option, false ),
$option
);
}
?>
</select>
</label>
<?php
$visibilityAttrs = '';
if ( ! $this->settings['show_line_height'] ) {
$visibilityAttrs = "data-visible='false' style='display: none'";
}
?>
<label <?php echo $visibilityAttrs ?>>
Line Height
<select class='tf-font-sel-height'>
<?php
for ( $i = .5; $i <= 3; $i += 0.1 ) {
printf( "<option value='%s'%s>%s</option>",
esc_attr( $i . 'em' ),
selected( $value['line-height'], $i . 'em', false ),
$i . 'em'
);
}
?>
</select>
</label>
<?php
$visibilityAttrs = '';
if ( ! $this->settings['show_letter_spacing'] ) {
$visibilityAttrs = "data-visible='false' style='display: none'";
}
?>
<label <?php echo $visibilityAttrs ?>>
Letter Spacing
<select class='tf-font-sel-spacing'>
<option value='normal'>normal</option>
<?php
for ( $i = -20; $i <= 20; $i++ ) {
printf( "<option value='%s'%s>%s</option>",
esc_attr( $i . 'px' ),
selected( $value['letter-spacing'], $i . 'px', false ),
$i . 'px'
);
}
?>
</select>
</label>
<?php
$visibilityAttrs = '';
if ( ! $this->settings['show_text_transform'] ) {
$visibilityAttrs = "data-visible='false' style='display: none'";
}
?>
<label <?php echo $visibilityAttrs ?>>
Text Transform
<select class='tf-font-sel-transform'>
<?php
$options = array( 'none', 'capitalize', 'uppercase', 'lowercase' );
foreach ( $options as $option ) {
printf( "<option value='%s'%s>%s</option>",
esc_attr( $option ),
selected( $value['text-transform'], $option, false ),
$option
);
}
?>
</select>
</label>
<?php
$visibilityAttrs = '';
if ( ! $this->settings['show_font_variant'] ) {
$visibilityAttrs = "data-visible='false' style='display: none'";
}
?>
<label <?php echo $visibilityAttrs ?>>
Font Variant
<select class='tf-font-sel-variant'>
<?php
$options = array( 'normal', 'small-caps' );
foreach ( $options as $option ) {
printf( "<option value='%s'%s>%s</option>",
esc_attr( $option ),
selected( $value['font-variant'], $option, false ),
$option
);
}
?>
</select>
</label>
<?php
$visibilityAttrs = '';
if ( ! $this->settings['show_text_shadow'] ) {
$visibilityAttrs = "data-visible='false' style='display: none'";
}
?>
<label <?php echo $visibilityAttrs ?>>
Shadow Location
<select class='tf-font-sel-location'>
<?php
$options = array( 'none', 'top', 'bottom', 'left', 'right', 'top-left', 'top-right', 'bottom-left', 'bottom-right' );
foreach ( $options as $option ) {
printf( "<option value='%s'%s>%s</option>",
esc_attr( $option ),
selected( $value['text-shadow-location'], $option, false ),
$option
);
}
?>
</select>
</label>
<label style='display: none'>
Shadow Distance
<select class='tf-font-sel-distance'>
<?php
for ( $i = 0; $i <= 10; $i++ ) {
printf( "<option value='%s'%s>%s</option>",
esc_attr( $i . 'px' ),
selected( $value['text-shadow-distance'], $i . 'px', false ),
$i . 'px'
);
}
?>
</select>
</label>
<label style='display: none'>
Shadow Blur
<select class='tf-font-sel-blur'>
<?php
$options = array( '0px', '1px', '2px', '3px', '4px', '5px', '10px', '20px' );
foreach ( $options as $option ) {
printf( "<option value='%s'%s>%s</option>",
esc_attr( $option ),
selected( $value['text-shadow-blur'], $option, false ),
$option
);
}
?>
</select>
</label>
<label style='display: none'>
Shadow Color
<input class="tf-font-sel-shadow-color" type="text" value="<?php echo esc_attr( $value['text-shadow-color'] ) ?>" data-default-color="<?php echo esc_attr( $value['text-shadow-color'] ) ?>"/>
</label>
<label style='display: none'>
Shadow Opacity
<select class='tf-font-sel-opacity'>
<?php
$options = array( '1', '0.9', '0.8', '0.7', '0.6', '0.5', '0.4', '0.3', '0.2', '0.1', '0' );
foreach ( $options as $option ) {
printf( "<option value='%s'%s>%s</option>",
esc_attr( $option ),
selected( $value['text-shadow-opacity'], $option, false ),
$option
);
}
?>
</select>
</label>
</div>
<?php
$visibilityAttrs = '';
if ( ! $this->settings['show_preview'] ) {
$visibilityAttrs = "data-visible='false' style='display: none'";
}
?>
<div <?php echo $visibilityAttrs ?>>
<iframe data-preview-text='<?php echo esc_attr( $this->settings['preview_text'] ) ?>'></iframe>
<i class='dashicons dashicons-admin-appearance btn-dark'></i>
<input type='hidden' class='tf-font-sel-dark' value='<?php echo esc_attr( $value['dark'] ? 'dark' : '' ) ?>'/>
</div>
<?php
if ( ! is_serialized( $value ) ) {
$value = serialize( $value );
}
printf("<input type='hidden' class='tf-for-saving' name='%s' id='%s' value='%s' />",
$this->getID(),
$this->getID(),
esc_attr( $value )
);
$this->echoOptionFooter( false );
}
/**
* Cleans up the serialized value before saving
*
* @param string $value The serialized value
* @return string The cleaned value
* @since 1.4
*/
public function cleanValueForSaving( $value ) {
if ( is_array( $value ) ) {
$value = serialize( $value );
}
return stripslashes( $value );
}
/**
* Cleans the raw value for getting
*
* @param string $value The raw value
* @return string The cleaned value
* @since 1.4
*/
public function cleanValueForGetting( $value ) {
if ( is_string( $value ) ) {
if ( is_serialized( stripslashes( $value ) ) ) {
$value = unserialize( $value );
}
}
if ( is_array( $value ) ) {
$value = array_merge( self::$defaultStyling, $value );
}
if ( ! empty( $value['font-family'] ) ) {
$value['font-type'] = in_array( $value['font-family'], array_keys( self::$webSafeFonts ) ) ? 'websafe' : 'google';
}
return $value;
}
/**
* Registers the theme customizer control, for displaying the option
*
* @param WP_Customize $wp_enqueue_script The customize object
* @param TitanFrameworkCustomizerSection $section The section where this option will be placed
* @param int $priority The order of this control in the section
* @return void
* @since 1.4
*/
public function registerCustomizerControl( $wp_customize, $section, $priority = 1 ) {
$wp_customize->add_control( new TitanFrameworkOptionFontControl( $wp_customize, $this->getID(), array(
'label' => $this->settings['name'],
'section' => $section->settings['id'],
'settings' => $this->getID(),
'description' => $this->settings['desc'],
'priority' => $priority,
'params' => $this->settings,
) ) );
}
}
/*
* We create a new control for the theme customizer
*/
add_action( 'customize_register', 'registerTitanFrameworkOptionFontControl', 1 );
/**
* Creates the option for the theme customizer
*
* @return void
* @since 1.4
*/
function registerTitanFrameworkOptionFontControl() {
class TitanFrameworkOptionFontControl extends WP_Customize_Control {
public $description;
public $params;
public function render_content() {
$this->params['show_preview'] = false;
TitanFrameworkOptionFont::createFontScript();
?>
<div class='tf-font'>
<span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
<?php
// Get the current value and merge with defaults
$value = $this->value();
if ( is_serialized( $value ) ) {
$value = unserialize( $value );
}
if ( ! is_array( $value ) ) {
$value = array();
}
$value = array_merge( TitanFrameworkOptionFont::$defaultStyling, $value );
/*
* Create all the fields
*/
$visibilityAttrs = '';
if ( ! $this->params['show_font_family'] ) {
$visibilityAttrs = "data-visible='false' style='display: none'";
}
?>
<div>
<label <?php echo $visibilityAttrs ?>>
Font Family
<select class='tf-font-sel-family'>
<optgroup label="Web Safe Fonts" class='safe'>
<?php
foreach ( TitanFrameworkOptionFont::$webSafeFonts as $family => $label ) {
printf( "<option value='%s'%s>%s</option>",
$family,
selected( $value['font-family'], $family, false ),
$label
);
}
?>
</optgroup>
<optgroup label="Google WebFonts" class='google'>
<?php
$allFonts = titan_get_googlefonts();
foreach ( $allFonts as $key => $fontStuff ) {
printf( "<option value='%s'%s>%s</option>",
esc_attr( $fontStuff['name'] ),
selected( $value['font-family'], $fontStuff['name'], false ),
$fontStuff['name']
);
}
?>
</optgroup>
</select>
</label>
<?php
$visibilityAttrs = '';
if ( ! $this->params['show_color'] ) {
$visibilityAttrs = "data-visible='false' style='display: none'";
}
?>
<label <?php echo $visibilityAttrs ?>>
Color
<input class='tf-font-sel-color' type="text" value="<?php echo esc_attr( $value['color'] ) ?>" data-default-color="<?php echo esc_attr( $value['color'] ) ?>"/>
</label>
<?php
$visibilityAttrs = '';
if ( ! $this->params['show_font_size'] ) {