Completed
Push — master ( 6b2386...2bf093 )
by Ahmad
04:44
created

TitanFrameworkOptionFont   D

Complexity

Total Complexity 86

Size/Duplication

Total Lines 924
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 3
Metric Value
wmc 86
lcom 2
cbo 3
dl 0
loc 924
rs 4.4444

12 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 17 2
A generateCustomizerPreviewJS() 0 16 1
A generateCustomizerPreviewCSS() 0 7 2
C getGoogleFontURLs() 0 70 13
A enqueueGooglefonts() 0 7 2
D generateCSS() 0 113 19
A loadAdminScripts() 0 4 1
B createFontScript() 0 142 1
F display() 0 345 37
A cleanValueForSaving() 0 6 2
B cleanValueForGetting() 0 12 5
A registerCustomizerControl() 0 10 1

How to fix   Complexity   

Complex Class

Complex classes like TitanFrameworkOptionFont often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use TitanFrameworkOptionFont, and based on these observations, apply Extract Interface, too.

1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 15 and the first side effect is on line 8.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
/**
3
 * Font Option Class
4
 *
5
 * @since	1.4
6
 */
7
8
if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly
9
}
10
/**
11
 * Font Option Class
12
 *
13
 * @since	1.4
14
 */
15
class TitanFrameworkOptionFont extends TitanFrameworkOption {
16
17
	// Default settings specific to this option
18
	public $defaultSecondarySettings = array(
19
		'show_font_family' => true,
20
		'show_color' => true,
21
		'show_font_size' => true,
22
		'show_font_weight' => true,
23
		'show_font_style' => true,
24
		'show_line_height' => true,
25
		'show_letter_spacing' => true,
26
		'show_text_transform' => true,
27
		'show_font_variant' => true,
28
		'show_text_shadow' => true,
29
		'show_preview' => true,
30
		'enqueue' => true,
31
		'preview_text' => '',
32
		'include_fonts' => '', // A regex string or array of regex strings to match font names to include.
33
		'show_websafe_fonts' => true,
34
		'show_google_fonts' => true,
35
	);
36
37
	// Default style options
38
	public static $defaultStyling = array(
39
		'font-family' => 'inherit',
40
		'color' => '#333333',
41
		'font-size' => 'inherit',
42
		'font-weight' => 'inherit',
43
		'font-style' => 'normal',
44
		'line-height' => '1.5em',
45
		'letter-spacing' => 'normal',
46
		'text-transform' => 'none',
47
		'font-variant' => 'normal',
48
		'text-shadow-location' => 'none',
49
		'text-shadow-distance' => '0px',
50
		'text-shadow-blur' => '0px',
51
		'text-shadow-color' => '#333333',
52
		'text-shadow-opacity' => '1',
53
		'font-type' => 'google', // Only used internally to determine if the font is a
54
		'dark' => '', // only used to toggle the preview background
55
	);
56
57
	// The list of web safe fonts
58
	public static $webSafeFonts = array(
59
		'Arial, Helvetica, sans-serif' => 'Arial',
60
		'"Arial Black", Gadget, sans-serif' => 'Arial Black',
61
		'"Comic Sans MS", cursive, sans-serif' => 'Comic Sans',
62
		'"Courier New", Courier, monospace' => 'Courier New',
63
		'Georgia, serif' => 'Geogia',
64
		'Impact, Charcoal, sans-serif' => 'Impact',
65
		'"Lucida Console", Monaco, monospace' => 'Lucida Console',
66
		'"Lucida Sans Unicode", "Lucida Grande", sans-serif' => 'Lucida Sans',
67
		'"Palatino Linotype", "Book Antiqua", Palatino, serif' => 'Palatino',
68
		'Tahoma, Geneva, sans-serif' => 'Tahoma',
69
		'"Times New Roman", Times, serif' => 'Times New Roman',
70
		'"Trebuchet MS", Helvetica, sans-serif' => 'Trebuchet',
71
		'Verdana, Geneva, sans-serif' => 'Verdana',
72
	);
73
74
	// Holds all the options with Google Fonts for enqueuing.
75
	// We need to do this since we want to gather all the fonts first then enqueue only the unique fonts
76
	private static $optionsToEnqueue = array();
77
78
79
	/**
80
	 * Constructor
81
	 *
82
	 * @return	void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
83
	 * @since	1.4
84
	 */
85
	function __construct( $settings, $owner ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
86
		parent::__construct( $settings, $owner );
87
88
		tf_add_action_once( 'admin_enqueue_scripts', array( $this, 'loadAdminScripts' ) );
89
		tf_add_action_once( 'customize_controls_enqueue_scripts', array( $this, 'loadAdminScripts' ) );
90
		tf_add_action_once( 'admin_head', array( __CLASS__, 'createFontScript' ) );
91
		tf_add_action_once( 'wp_enqueue_scripts', array( $this, 'enqueueGooglefonts' ) );
92
		add_filter( 'tf_generate_css_font_' . $this->getOptionNamespace(), array( $this, 'generateCSS' ), 10, 2 );
93
94
		// Customizer preview handling
95
		tf_add_action_once( 'tf_generate_customizer_preview_js', array( $this, 'generateCustomizerPreviewJS' ) );
96
		tf_add_filter_once( 'tf_generate_customizer_preview_css_' . $this->getOptionNamespace(), array( $this, 'generateCustomizerPreviewCSS' ) );
97
98
		if ( $this->settings['enqueue'] ) {
99
			self::$optionsToEnqueue[] = $this;
100
		}
101
	}
102
103
104
	/**
105
	 * Adds the Javascript code that adds Google fonts straight into the customizer preview.
106
	 *
107
	 * @since 1.9.2
108
	 *
109
	 * @return void
110
	 *
111
	 * @see TitanFrameworkCustomizer->livePreviewMainScript()
112
	 */
113
	public function generateCustomizerPreviewJS() {
114
		?>
115
		for ( var fontName in data.google_fonts ) {
116
			if ( document.querySelector( '#tf-preview-' + fontName ) ) {
117
				continue;
118
			}
119
			var link = document.createElement('LINK');
120
			link.setAttribute( 'rel', 'stylesheet' );
121
			link.setAttribute( 'type', 'text/css' );
122
			link.setAttribute( 'media', 'all' );
123
			link.setAttribute( 'id', 'tf-preview' + fontName );
124
			link.setAttribute( 'href', data.google_fonts[ fontName ] );
125
			document.head.appendChild( link );
126
		}
127
		<?php
128
	}
129
130
131
	/**
132
	 * Adds the list of all Google fonts into the customizer live preview
133
	 *
134
	 * @since 1.9.2
135
	 *
136
	 * @param array $generated The parameters to pass to the ajax handler during customizer live previews.
137
	 *
138
	 * @return array An array containing modified ajax values to pass
139
	 */
140
	public function generateCustomizerPreviewCSS( $generated ) {
141
		if ( empty( $generated['google_fonts'] ) ) {
142
			$generated['google_fonts'] = array();
143
		}
144
		$generated['google_fonts'] = array_merge( $generated['google_fonts'], $this->getGoogleFontURLs() );
145
		return $generated;
146
	}
147
148
149
	/**
150
	 * Gets all the Google font URLs for enqueuing. This was previously inside $this->enqueueGooglefonts()
151
	 * but was split off so it can be used by other functions.
152
	 *
153
	 * @since 1.9.2
154
	 *
155
	 * @return array An array containing the font names as keys and the font URLs as values.
156
	 */
157
	public function getGoogleFontURLs() {
158
159
		$urls = array();
160
161
		// Gather all the fonts that we need to load, some may be repeated so we need to
162
		// load them once after gathering them
163
		$fontsToLoad = array();
164
		foreach ( self::$optionsToEnqueue as $option ) {
165
			$fontValue = $option->getValue();
166
167
			if ( empty( $fontValue['font-family'] ) ) {
168
				continue;
169
			}
170
			if ( $fontValue['font-family'] == 'inherit' ) {
171
				continue;
172
			}
173
174
			if ( $fontValue['font-type'] != 'google' ) {
175
				continue;
176
			}
177
178
			// Get all the fonts that we need to load
179
			if ( empty( $fontsToLoad[ $fontValue['font-family'] ] ) ) {
180
				$fontsToLoad[ $fontValue['font-family'] ] = array();
181
			}
182
183
			// Get the weight
184
			$variant = $fontValue['font-weight'];
185
			if ( $variant == 'normal' ) {
186
				$variant = '400';
187
			} else if ( $variant == 'bold' ) {
188
				$variant = '500';
189
			} else if ( $variant == 'bolder' ) {
190
				$variant = '800';
191
			} else if ( $variant == 'lighter' ) {
192
				$variant = '100';
193
			}
194
195
			if ( $fontValue['font-style'] == 'italic' ) {
196
				$variant .= 'italic';
197
			}
198
199
			$fontsToLoad[ $fontValue['font-family'] ][] = $variant;
200
		}
201
202
		// Font subsets, allow others to change this
203
		$subsets = apply_filters( 'tf_google_font_subsets_' . $this->getOptionNamespace(), array( 'latin', 'latin-ext' ) );
204
205
		// Enqueue the Google Font
206
		foreach ( $fontsToLoad as $fontName => $variants ) {
207
208
			// Always include the normal weight so that we don't error out
209
			$variants[] = '400';
210
			$variants = array_unique( $variants );
211
212
			$fontUrl = sprintf( '//fonts.googleapis.com/css?family=%s:%s&subset=%s',
213
				str_replace( ' ', '+', $fontName ),
214
				implode( ',', $variants ),
215
				implode( ',', $subsets )
216
			);
217
218
			$fontUrl = apply_filters( 'tf_enqueue_google_webfont_' . $this->getOptionNamespace(), $fontUrl, $fontName );
219
220
			if ( $fontUrl != false ) {
221
				$urls[ $fontName ] = $fontUrl;
222
			}
223
		}
224
225
		return $urls;
226
	}
227
228
229
	/**
230
	 * Enqueues all the Google fonts, used in wp_enqueue_scripts
231
	 *
232
	 * @since	1.4
233
	 *
234
	 * @return	void
235
	 */
236
	public function enqueueGooglefonts() {
237
		$urls = $this->getGoogleFontURLs();
238
239
		foreach ( $urls as $fontName => $url ) {
240
			wp_enqueue_style( 'tf-google-webfont-' . strtolower( str_replace( ' ', '-', $fontName ) ), $url );
241
		}
242
	}
243
244
245
	/**
246
	 * Generates CSS for the font, this is used in TitanFrameworkCSS
247
	 *
248
	 * @param	string               $css The CSS generated
249
	 * @param	TitanFrameworkOption $option The current option being processed
250
	 * @return	string The CSS generated
251
	 * @since	1.4
252
	 */
253
	public function generateCSS( $css, $option ) {
254
		if ( $this->settings['id'] != $option->settings['id'] ) {
255
			return $css;
256
		}
257
258
		$skip = array( 'dark', 'font-type', 'text-shadow-distance', 'text-shadow-blur', 'text-shadow-color', 'text-shadow-opacity' );
259
260
		// If the value is blank, use the defaults
261
		$value = $this->getValue();
262
		$value = array_merge( self::$defaultStyling, $value );
263
264
		foreach ( $value as $key => $val ) {
265
266
			// Force skip other keys, those are processed under another key, e.g. text-shadow-distance is
267
			// used by text-shadow-location
268
			if ( in_array( $key, $skip ) ) {
269
				continue;
270
			}
271
272
			// Don't include keys which are not in the default styles
273
			if ( ! in_array( $key, array_keys( self::$defaultStyling ) ) ) {
274
				continue;
275
			}
276
277
			if ( $key == 'font-family' ) {
278
				if ( $value[ $key ] == 'inherit' ) {
279
					$css .= '$' . $option->settings['id'] . '-' . $key . ': ' . $value[ $key ] . ';';
280
					continue;
281
				}
282
				if ( ! empty( $value['font-type'] ) ) {
283
					if ( $value['font-type'] == 'google' ) {
284
						$css .= '$' . $option->settings['id'] . '-' . $key . ': "' . $value[ $key ] . '";';
285
						continue;
286
					}
287
				}
288
				$css .= '$' . $option->settings['id'] . '-' . $key . ': ' . $value[ $key ] . ';';
289
				continue;
290
			}
291
292
			if ( $key == 'text-shadow-location' ) {
293
				$textShadow = '';
294
				if ( $value[ $key ] != 'none' ) {
295
					if ( stripos( $value[ $key ], 'left' ) !== false ) {
296
						$textShadow .= '-' . $value['text-shadow-distance'];
297
					} else if ( stripos( $value[ $key ], 'right' ) !== false ) {
298
						$textShadow .= $value['text-shadow-distance'];
299
					} else {
300
						$textShadow .= '0';
301
					}
302
					$textShadow .= ' ';
303
					if ( stripos( $value[ $key ], 'top' ) !== false ) {
304
						$textShadow .= '-' . $value['text-shadow-distance'];
305
					} else if ( stripos( $value[ $key ], 'bottom' ) !== false ) {
306
						$textShadow .= $value['text-shadow-distance'];
307
					} else {
308
						$textShadow .= '0';
309
					}
310
					$textShadow .= ' ';
311
					$textShadow .= $value['text-shadow-blur'];
312
					$textShadow .= ' ';
313
314
					$rgb = tf_hex2rgb( $value['text-shadow-color'] );
315
					$rgb[] = $value['text-shadow-opacity'];
316
317
					$textShadow .= 'rgba(' . implode( ',', $rgb ) . ')';
318
				} else {
319
					$textShadow .= $value[ $key ];
320
				}
321
322
				$css .= '$' . $option->settings['id'] . '-text-shadow: ' . $textShadow . ';';
323
				continue;
324
			}
325
326
			$css .= '$' . $option->settings['id'] . '-' . $key . ': ' . $value[ $key ] . ';';
327
		}
328
329
		/*
330
		 * There are 2 ways to include the values for the CSS. The normal `value-arraykey`, or just `value`
331
		 * Using `value` will print out the entire font CSS.
332
		 */
333
334
		// Create the entire CSS for the font, this should just be used to replace the `value` variable.
335
		$cssVariables = '';
336
		$cssChecking = array( 'font_family', 'color', 'font_size', 'font_weight', 'font_style', 'line_height', 'letter_spacing', 'text_transform', 'font_variant', 'text_shadow' );
337
338
		// Enter values that are not marked as false.
339
		foreach ( $cssChecking as $subject ) {
340
			if ( $option->settings[ 'show_'.$subject ] ) {
341
				$cssVariableArray[] = str_replace( '_', '-', $subject );
0 ignored issues
show
Coding Style Comprehensibility introduced by
$cssVariableArray was never initialized. Although not strictly required by PHP, it is generally a good practice to add $cssVariableArray = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
342
			}
343
		}
344
345
		// Now, integrate these values with their corresponding keys.
346
		foreach ( $cssVariableArray as $param ) {
0 ignored issues
show
Bug introduced by
The variable $cssVariableArray does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
347
			$cssVariables .= $param . ': $' . $option->settings['id'] . '-' . $param . ";\n";
348
		}
349
350
		// Replace the `value` parameters in the given css.
351
		$modifiedCss = '';
352
		if ( ! empty( $option->settings['css'] ) ) {
353
			$modifiedCss = $option->settings['css'];
354
355
			// If `value` is given, replace it with the entire css we created above in $cssVariables.
356
			$modifiedCss = preg_replace( '/value[^-]/', $cssVariables, $modifiedCss );
357
358
			// Normal `value-arraykey` values.
359
			$modifiedCss = str_replace( 'value-', '$' . $option->settings['id'] . '-', $modifiedCss );
360
		}
361
362
		$css .= $modifiedCss;
363
364
		return $css;
365
	}
366
367
368
	/**
369
	 * Enqueues the needed scripts for the admin
370
	 *
371
	 * @return	void
372
	 * @since	1.4
373
	 */
374
	public function loadAdminScripts() {
375
		wp_enqueue_script( 'wp-color-picker' );
376
		wp_enqueue_style( 'wp-color-picker' );
377
	}
378
379
380
	/**
381
	 * Creates the Javascript for running the font option
382
	 *
383
	 * @return	void
384
	 * @since	1.4
385
	 */
386
	public static function createFontScript() {
387
388
		?>
389
		<script>
390
		jQuery(document).ready(function($) {
391
			"use strict";
392
393
			var _tf_select_font_throttle = null;
394
395
			// Initialize color pickers
396
			$('.tf-font .tf-font-sel-color, .tf-font .tf-font-sel-shadow-color').wpColorPicker({
397
				change: function ( event, ui ) {
398
					// update the preview, but throttle it to prevent fast loading
399
					if ( _tf_select_font_throttle != null ) {
400
						clearTimeout( _tf_select_font_throttle );
401
						_tf_select_font_throttle = null;
402
					}
403
					var $this = $(this);
404
					_tf_select_font_throttle = setTimeout( function() {
405
						tf_select_font_update_preview( $this.parents('.tf-font:eq(0)'), true );
406
					}, 300 );
407
				}
408
			});
409
410
411
			// Initialize the option
412
			$('.tf-font').each(function() {
413
414
				// Update save field on change
415
				$(this).find('select,.tf-font-sel-dark').change(function() {
416
					tf_select_font_update_preview( $(this).parents('.tf-font:eq(0)'), true );
417
				});
418
419
				// Trigger for toggling light/dark preview backgrounds
420
				$(this).find('.btn-dark').click(function() {
421
					var darkInput = $(this).parent().find('.tf-font-sel-dark');
422
					if ( darkInput.val() == '' ) {
423
						darkInput.val('dark').trigger('change');
424
					} else {
425
						darkInput.val('').trigger('change');
426
					}
427
				})
428
429
				// initialize preview
430
				tf_select_font_update_preview( $(this), true );
431
432
				// We have to do this after 1ms for the theme customizer, or else the field's value
433
				// gets changed to a weird value
434
				var $this = $(this);
435
				setTimeout( function() {
436
					tf_select_font_update_preview( $this, false )
437
				}, 1 );
438
			});
439
			
440
			
441
			/**
442
			 * Theme Customizer scripts
443
			 */
444
			
445
			// Check for font selector clicks, we need to adjust styles to make it look nice
446
			$('body.wp-customizer .tf-font').on('mouseup', function(e) {
447
				if ( $(e.target).is('.wp-color-result') ) {
448
					if ( ! $(e.target).is('.wp-picker-open') ) {
449
						$(e.target).parents('label:eq(0)').addClass('tf-picker-open');
450
					} else {
451
						$(e.target).parents('label:eq(0)').removeClass('tf-picker-open');
452
					}
453
				}
454
			});
455
			
456
			// Check for close clicks (clicking outside while the picker is open)
457
			$('body.wp-customizer').on('mouseup', '*', function(e) {
458
				var $target = $(e.target);
459
				if ( $target.is('.wp-color-result, .wp-color-picker, .wp-picker-default') ) { 
460
					return;
461
				}
462
				if ( $target.parents('.wp-picker-holder').length > 0 ) {
463
					return;
464
				}
465
				if ( $('.tf-picker-open').length > 0 ) {
466
					$('.tf-picker-open').removeClass('tf-picker-open');
467
				}
468
			});
469
		});
470
471
472
		// Updates the option elements
473
		function tf_select_font_update_preview( $container, doTrigger ) {
474
			"use strict";
475
			var $ = jQuery;
476
477
			// Show / hide shadow fields
478
			if ( $container.find(".tf-font-sel-location").val() == 'none'
479
				 || $container.find('.tf-font-sel-location').parents('label:eq(0)').attr('data-visible') == 'false' ) {
480
				$container.find(".tf-font-sel-distance").parents('label:eq(0)').fadeOut();
481
				$container.find(".tf-font-sel-blur").parents('label:eq(0)').fadeOut();
482
				$container.find(".tf-font-sel-shadow-color").parents('label:eq(0)').fadeOut();
483
				$container.find(".tf-font-sel-opacity").parents('label:eq(0)').fadeOut();
484
			} else {
485
				$container.find(".tf-font-sel-distance").parents('label:eq(0)').fadeIn();
486
				$container.find(".tf-font-sel-blur").parents('label:eq(0)').fadeIn();
487
				$container.find(".tf-font-sel-shadow-color").parents('label:eq(0)').fadeIn();
488
				$container.find(".tf-font-sel-opacity").parents('label:eq(0)').fadeIn();
489
			}
490
491
			var family = $container.find('.tf-font-sel-family').val();
492
493
			// These are all our parameters
494
			var params = {
495
				'font-family': family,
496
				'font-type': $container.find(".tf-font-sel-family option[value='" + family + "']").parent().attr('class'),
497
				'color': $container.find(".tf-font-sel-color").val(),
498
				'font-size': $container.find(".tf-font-sel-size").val(),
499
				'font-weight': $container.find(".tf-font-sel-weight").val(),
500
				'font-style': $container.find(".tf-font-sel-style").val(),
501
				'line-height': $container.find(".tf-font-sel-height").val(),
502
				'letter-spacing': $container.find(".tf-font-sel-spacing").val(),
503
				'text-transform': $container.find(".tf-font-sel-transform").val(),
504
				'font-variant': $container.find(".tf-font-sel-variant").val(),
505
				'text-shadow-location': $container.find(".tf-font-sel-location").val(),
506
				'text-shadow-distance': $container.find(".tf-font-sel-distance").val(),
507
				'text-shadow-blur': $container.find(".tf-font-sel-blur").val(),
508
				'text-shadow-color': $container.find(".tf-font-sel-shadow-color").val(),
509
				'text-shadow-opacity': $container.find(".tf-font-sel-opacity").val(),
510
				'dark': $container.find(".tf-font-sel-dark").val(),
511
				'text': $container.find("iframe").attr('data-preview-text')
512
			}
513
514
			// Update preview
515
			if ( $container.find('iframe').is(':not([data-visible=false])') ) {
516
				$container.find('iframe').attr('src', '<?php echo TitanFramework::getURL( 'iframe-font-preview.php?', __FILE__ ) ?>' + $.param(params) );
517
			}
518
519
			// Update hidden save field
520
			$container.find('.tf-for-saving').val(serialize(params));
521
			if ( doTrigger ) {
522
				$container.find('.tf-for-saving').trigger('change');
523
			}
524
		}
525
		</script>
526
		<?php
527
	}
528
529
530
	/**
531
	 * Displays the option in admin panels and meta boxes
532
	 *
533
	 * @return	void
534
	 * @since	1.4
535
	 */
536
	public function display() {
537
		$this->echoOptionHeader( true );
538
539
		// Get the current value and merge with defaults
540
		$value = $this->getValue();
541
		$value = array_merge( self::$defaultStyling, $value );
542
543
		/*
544
		 * Create all the fields
545
		 */
546
		$visibilityAttrs = '';
547
		if ( ! $this->settings['show_font_family'] ) {
548
			$visibilityAttrs = "data-visible='false' style='display: none'";
549
		}
550
		?>
551
		<div>
552
		<label <?php echo $visibilityAttrs ?>>
553
			Font Family
554
			<select class='tf-font-sel-family'>
555
				<option value='inherit'>inherit</option>
556
				<?php
557
558
				if ( $this->settings['show_websafe_fonts'] ) {
559
					?>
560
					<optgroup label="Web Safe Fonts" class='safe'>
561
						<?php
562
						foreach ( self::$webSafeFonts as $family => $label ) {
563
							printf( "<option value='%s'%s>%s</option>",
564
								$family,
565
								selected( $value['font-family'], $family, false ),
566
								$label
567
							);
568
						}
569
						?>
570
					</optgroup>
571
					<?php
572
				}
573
574
				if ( $this->settings['show_google_fonts'] ) {
575
					?>
576
					<optgroup label="Google WebFonts" class='google'>
577
						<?php
578
						$allFonts = titan_get_googlefonts();
579
						foreach ( $allFonts as $key => $fontStuff ) {
580
581
							// Show only the include_fonts (font names) if provided, uses regex.
582
							if ( ! empty( $this->settings['include_fonts'] ) ) {
583
								if ( is_array( $this->settings['include_fonts'] ) ) {
584
									$fontNameMatch = false;
585
									foreach ( $this->settings['include_fonts'] as $fontNamePattern ) {
586
										if ( ! is_string( $fontNamePattern ) ) {
587
											continue;
588
										}
589
										$fontNamePattern = '/' . trim( $fontNamePattern, '/' ) . '/';
590
										if ( preg_match( $fontNamePattern . 'i', $fontStuff['name'] ) ) {
591
											$fontNameMatch = true;
592
											break;
593
										}
594
									}
595
									if ( ! $fontNameMatch ) {
596
										continue;
597
									}
598
								} else if ( is_string( $this->settings['include_fonts'] ) ) {
599
									$fontNamePattern = '/' . trim( $this->settings['include_fonts'], '/' ) . '/';
600
									if ( ! preg_match( $fontNamePattern . 'i', $fontStuff['name'] ) ) {
601
										continue;
602
									}
603
								}
604
							}
605
606
							printf( "<option value='%s'%s>%s</option>",
607
								esc_attr( $fontStuff['name'] ),
608
								selected( $value['font-family'], $fontStuff['name'], false ),
609
								$fontStuff['name']
610
							);
611
						}
612
						?>
613
					</optgroup>
614
					<?php
615
				}
616
				?>
617
			</select>
618
		</label>
619
		<?php
620
621
		$visibilityAttrs = '';
622
		if ( ! $this->settings['show_color'] ) {
623
			$visibilityAttrs = "data-visible='false' style='display: none'";
624
		}
625
		?>
626
		<label <?php echo $visibilityAttrs ?>>
627
			Color
628
			<input class='tf-font-sel-color' type="text" value="<?php echo esc_attr( $value['color'] ) ?>"  data-default-color="<?php echo esc_attr( $value['color'] ) ?>"/>
629
		</label>
630
		<?php
631
632
		$visibilityAttrs = '';
633
		if ( ! $this->settings['show_font_size'] ) {
634
			$visibilityAttrs = "data-visible='false' style='display: none'";
635
		}
636
		?>
637
		<label <?php echo $visibilityAttrs ?>>
638
			Font Size
639
			<select class='tf-font-sel-size'>
640
				<option value='inherit'>inherit</option>
641
				<?php
642
				for ( $i = 1; $i <= 150; $i++ ) {
643
					printf( "<option value='%s'%s>%s</option>",
644
						esc_attr( $i . 'px' ),
645
						selected( $value['font-size'], $i . 'px', false ),
646
						$i . 'px'
647
					);
648
				}
649
				?>
650
			</select>
651
		</label>
652
		<?php
653
654
		$visibilityAttrs = '';
655
		if ( ! $this->settings['show_font_weight'] ) {
656
			$visibilityAttrs = "data-visible='false' style='display: none'";
657
		}
658
		?>
659
		<label <?php echo $visibilityAttrs ?>>
660
			Font Weight
661
			<select class='tf-font-sel-weight'>
662
				<option value='inherit'>inherit</option>
663
				<?php
664
				$options = array( 'normal', 'bold', 'bolder', 'lighter', '100', '200', '300', '400', '500', '600', '700', '800', '900' );
665
				foreach ( $options as $option ) {
666
					printf( "<option value='%s'%s>%s</option>",
667
						esc_attr( $option ),
668
						selected( $value['font-weight'], $option, false ),
669
						$option
670
					);
671
				}
672
				?>
673
			</select>
674
		</label>
675
		<?php
676
677
		$visibilityAttrs = '';
678
		if ( ! $this->settings['show_font_style'] ) {
679
			$visibilityAttrs = "data-visible='false' style='display: none'";
680
		}
681
		?>
682
		<label <?php echo $visibilityAttrs ?>>
683
			Font Style
684
			<select class='tf-font-sel-style'>
685
				<?php
686
				$options = array( 'normal', 'italic' );
687
				foreach ( $options as $option ) {
688
					printf( "<option value='%s'%s>%s</option>",
689
						esc_attr( $option ),
690
						selected( $value['font-style'], $option, false ),
691
						$option
692
					);
693
				}
694
				?>
695
			</select>
696
		</label>
697
		<?php
698
699
		$visibilityAttrs = '';
700
		if ( ! $this->settings['show_line_height'] ) {
701
			$visibilityAttrs = "data-visible='false' style='display: none'";
702
		}
703
		?>
704
		<label <?php echo $visibilityAttrs ?>>
705
			Line Height
706
			<select class='tf-font-sel-height'>
707
				<?php
708
				for ( $i = .5; $i <= 3; $i += 0.1 ) {
709
					printf( "<option value='%s'%s>%s</option>",
710
						esc_attr( $i . 'em' ),
711
						selected( $value['line-height'], $i . 'em', false ),
712
						$i . 'em'
713
					);
714
				}
715
				?>
716
			</select>
717
		</label>
718
		<?php
719
720
		$visibilityAttrs = '';
721
		if ( ! $this->settings['show_letter_spacing'] ) {
722
			$visibilityAttrs = "data-visible='false' style='display: none'";
723
		}
724
		?>
725
		<label <?php echo $visibilityAttrs ?>>
726
			Letter Spacing
727
			<select class='tf-font-sel-spacing'>
728
				<option value='normal'>normal</option>
729
				<?php
730
				for ( $i = -20; $i <= 20; $i++ ) {
731
					printf( "<option value='%s'%s>%s</option>",
732
						esc_attr( $i . 'px' ),
733
						selected( $value['letter-spacing'], $i . 'px', false ),
734
						$i . 'px'
735
					);
736
				}
737
				?>
738
			</select>
739
		</label>
740
		<?php
741
742
		$visibilityAttrs = '';
743
		if ( ! $this->settings['show_text_transform'] ) {
744
			$visibilityAttrs = "data-visible='false' style='display: none'";
745
		}
746
		?>
747
		<label <?php echo $visibilityAttrs ?>>
748
			Text Transform
749
			<select class='tf-font-sel-transform'>
750
				<?php
751
				$options = array( 'none', 'capitalize', 'uppercase', 'lowercase' );
752
				foreach ( $options as $option ) {
753
					printf( "<option value='%s'%s>%s</option>",
754
						esc_attr( $option ),
755
						selected( $value['text-transform'], $option, false ),
756
						$option
757
					);
758
				}
759
				?>
760
			</select>
761
		</label>
762
		<?php
763
764
		$visibilityAttrs = '';
765
		if ( ! $this->settings['show_font_variant'] ) {
766
			$visibilityAttrs = "data-visible='false' style='display: none'";
767
		}
768
		?>
769
		<label <?php echo $visibilityAttrs ?>>
770
			Font Variant
771
			<select class='tf-font-sel-variant'>
772
				<?php
773
				$options = array( 'normal', 'small-caps' );
774
				foreach ( $options as $option ) {
775
					printf( "<option value='%s'%s>%s</option>",
776
						esc_attr( $option ),
777
						selected( $value['font-variant'], $option, false ),
778
						$option
779
					);
780
				}
781
				?>
782
			</select>
783
		</label>
784
		<?php
785
786
		$visibilityAttrs = '';
787
		if ( ! $this->settings['show_text_shadow'] ) {
788
			$visibilityAttrs = "data-visible='false' style='display: none'";
789
		}
790
		?>
791
		<label <?php echo $visibilityAttrs ?>>
792
			Shadow Location
793
			<select class='tf-font-sel-location'>
794
				<?php
795
				$options = array( 'none', 'top', 'bottom', 'left', 'right', 'top-left', 'top-right', 'bottom-left', 'bottom-right' );
796
				foreach ( $options as $option ) {
797
					printf( "<option value='%s'%s>%s</option>",
798
						esc_attr( $option ),
799
						selected( $value['text-shadow-location'], $option, false ),
800
						$option
801
					);
802
				}
803
				?>
804
			</select>
805
		</label>
806
		<label style='display: none'>
807
			Shadow Distance
808
			<select class='tf-font-sel-distance'>
809
				<?php
810
				for ( $i = 0; $i <= 10; $i++ ) {
811
					printf( "<option value='%s'%s>%s</option>",
812
						esc_attr( $i . 'px' ),
813
						selected( $value['text-shadow-distance'], $i . 'px', false ),
814
						$i . 'px'
815
					);
816
				}
817
				?>
818
			</select>
819
		</label>
820
		<label style='display: none'>
821
			Shadow Blur
822
			<select class='tf-font-sel-blur'>
823
				<?php
824
				$options = array( '0px', '1px', '2px', '3px', '4px', '5px', '10px', '20px' );
825
				foreach ( $options as $option ) {
826
					printf( "<option value='%s'%s>%s</option>",
827
						esc_attr( $option ),
828
						selected( $value['text-shadow-blur'], $option, false ),
829
						$option
830
					);
831
				}
832
				?>
833
			</select>
834
		</label>
835
		<label style='display: none'>
836
			Shadow Color
837
			<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'] ) ?>"/>
838
		</label>
839
		<label style='display: none'>
840
			Shadow Opacity
841
			<select class='tf-font-sel-opacity'>
842
				<?php
843
				$options = array( '1', '0.9', '0.8', '0.7', '0.6', '0.5', '0.4', '0.3', '0.2', '0.1', '0' );
844
				foreach ( $options as $option ) {
845
					printf( "<option value='%s'%s>%s</option>",
846
						esc_attr( $option ),
847
						selected( $value['text-shadow-opacity'], $option, false ),
848
						$option
849
					);
850
				}
851
				?>
852
			</select>
853
		</label>
854
		</div>
855
		<?php
856
857
		$visibilityAttrs = '';
858
		if ( ! $this->settings['show_preview'] ) {
859
			$visibilityAttrs = "data-visible='false' style='display: none'";
860
		}
861
		?>
862
		<div <?php echo $visibilityAttrs ?>>
863
			<iframe data-preview-text='<?php echo esc_attr( $this->settings['preview_text'] ) ?>'></iframe>
864
			<i class='dashicons dashicons-admin-appearance btn-dark'></i>
865
			<input type='hidden' class='tf-font-sel-dark' value='<?php echo esc_attr( $value['dark'] ? 'dark' : '' ) ?>'/>
866
		</div>
867
		<?php
868
869
		if ( ! is_serialized( $value ) ) {
870
			$value = serialize( $value );
871
		}
872
873
		printf("<input type='hidden' class='tf-for-saving' name='%s' id='%s' value='%s' />",
874
			$this->getID(),
875
			$this->getID(),
876
			esc_attr( $value )
877
		);
878
879
		$this->echoOptionFooter( false );
880
	}
881
882
883
	/**
884
	 * Cleans up the serialized value before saving
885
	 *
886
	 * @param	string $value The serialized value
887
	 * @return	string The cleaned value
888
	 * @since	1.4
889
	 */
890
	public function cleanValueForSaving( $value ) {
891
		if ( is_array( $value ) ) {
892
			$value = serialize( $value );
893
		}
894
		return stripslashes( $value );
895
	}
896
897
898
	/**
899
	 * Cleans the raw value for getting
900
	 *
901
	 * @param	string $value The raw value
902
	 * @return	string The cleaned value
903
	 * @since	1.4
904
	 */
905
	public function cleanValueForGetting( $value ) {
906
		if ( is_string( $value ) ) {
907
			$value = maybe_unserialize( stripslashes( $value ) );
908
		}
909
		if ( is_array( $value ) ) {
910
			$value = array_merge( self::$defaultStyling, $value );
911
		}
912
		if ( ! empty( $value['font-family'] ) ) {
913
			$value['font-type'] = in_array( $value['font-family'], array_keys( self::$webSafeFonts ) ) ? 'websafe' : 'google';
914
		}
915
		return $value;
916
	}
917
918
919
	/**
920
	 * Registers the theme customizer control, for displaying the option
921
	 *
922
	 * @param	WP_Customize                    $wp_enqueue_script The customize object
0 ignored issues
show
Bug introduced by
There is no parameter named $wp_enqueue_script. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
923
	 * @param	TitanFrameworkCustomizerSection $section The section where this option will be placed
924
	 * @param	int                             $priority The order of this control in the section
925
	 * @return	void
926
	 * @since	1.4
927
	 */
928
	public function registerCustomizerControl( $wp_customize, $section, $priority = 1 ) {
929
		$wp_customize->add_control( new TitanFrameworkOptionFontControl( $wp_customize, $this->getID(), array(
930
			'label' => $this->settings['name'],
931
			'section' => $section->settings['id'],
932
			'settings' => $this->getID(),
933
			'description' => $this->settings['desc'],
934
			'priority' => $priority,
935
			'params' => $this->settings,
936
		) ) );
937
	}
938
}
939
940
941
942
/*
943
 * We create a new control for the theme customizer
944
 */
945
add_action( 'customize_register', 'registerTitanFrameworkOptionFontControl', 1 );
946
947
948
/**
949
 * Creates the option for the theme customizer
950
 *
951
 * @return	void
952
 * @since	1.4
953
 */
954
function registerTitanFrameworkOptionFontControl() {
955
	class TitanFrameworkOptionFontControl extends WP_Customize_Control {
956
		public $description;
957
		public $params;
958
959
		public function render_content() {
960
			$this->params['show_preview'] = false;
961
			TitanFrameworkOptionFont::createFontScript();
962
963
			?>
964
			<div class='tf-font'>
965
				<span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
966
			<?php
967
968
			// Get the current value and merge with defaults
969
			$value = $this->value();
970
			if ( is_serialized( $value ) ) {
971
				$value = unserialize( $value );
972
			}
973
			if ( ! is_array( $value ) ) {
974
				$value = array();
975
			}
976
			$value = array_merge( TitanFrameworkOptionFont::$defaultStyling, $value );
977
978
			/*
979
			 * Create all the fields
980
			 */
981
			$visibilityAttrs = '';
982
			if ( ! $this->params['show_font_family'] ) {
983
				$visibilityAttrs = "data-visible='false' style='display: none'";
984
			}
985
			?>
986
			<div>
987
			<label <?php echo $visibilityAttrs ?>>
988
				Font Family
989
				<select class='tf-font-sel-family'>
990
					<option value='inherit'>inherit</option>
991
				    <optgroup label="Web Safe Fonts" class='safe'>
992
						<?php
993
						foreach ( TitanFrameworkOptionFont::$webSafeFonts as $family => $label ) {
994
							printf( "<option value='%s'%s>%s</option>",
995
								$family,
996
								selected( $value['font-family'], $family, false ),
997
								$label
998
							);
999
						}
1000
						?>
1001
					</optgroup>
1002
				    <optgroup label="Google WebFonts" class='google'>
1003
						<?php
1004
						$allFonts = titan_get_googlefonts();
1005
						foreach ( $allFonts as $key => $fontStuff ) {
1006
							printf( "<option value='%s'%s>%s</option>",
1007
								esc_attr( $fontStuff['name'] ),
1008
								selected( $value['font-family'], $fontStuff['name'], false ),
1009
								$fontStuff['name']
1010
							);
1011
						}
1012
						?>
1013
					</optgroup>
1014
				</select>
1015
			</label>
1016
			<?php
1017
1018
			$visibilityAttrs = '';
1019
			if ( ! $this->params['show_color'] ) {
1020
				$visibilityAttrs = "data-visible='false' style='display: none'";
1021
			}
1022
			?>
1023
			<label <?php echo $visibilityAttrs ?>>
1024
				Color
1025
				<input class='tf-font-sel-color' type="text" value="<?php echo esc_attr( $value['color'] ) ?>"  data-default-color="<?php echo esc_attr( $value['color'] ) ?>"/>
1026
			</label>
1027
			<?php
1028
1029
			$visibilityAttrs = '';
1030
			if ( ! $this->params['show_font_size'] ) {
1031
				$visibilityAttrs = "data-visible='false' style='display: none'";
1032
			}
1033
			?>
1034
			<label <?php echo $visibilityAttrs ?>>
1035
				Font Size
1036
				<select class='tf-font-sel-size'>
1037
					<option value='inherit'>inherit</option>
1038
					<?php
1039
					for ( $i = 1; $i <= 150; $i++ ) {
1040
						printf( "<option value='%s'%s>%s</option>",
1041
							esc_attr( $i . 'px' ),
1042
							selected( $value['font-size'], $i . 'px', false ),
1043
							$i . 'px'
1044
						);
1045
					}
1046
					?>
1047
				</select>
1048
			</label>
1049
			<?php
1050
1051
			$visibilityAttrs = '';
1052
			if ( ! $this->params['show_font_weight'] ) {
1053
				$visibilityAttrs = "data-visible='false' style='display: none'";
1054
			}
1055
			?>
1056
			<label <?php echo $visibilityAttrs ?>>
1057
				Font Weight
1058
				<select class='tf-font-sel-weight'>
1059
					<option value='inherit'>inherit</option>
1060
					<?php
1061
					$options = array( 'normal', 'bold', 'bolder', 'lighter', '100', '200', '300', '400', '500', '600', '700', '800', '900' );
1062
					foreach ( $options as $option ) {
1063
						printf( "<option value='%s'%s>%s</option>",
1064
							esc_attr( $option ),
1065
							selected( $value['font-weight'], $option, false ),
1066
							$option
1067
						);
1068
					}
1069
					?>
1070
				</select>
1071
			</label>
1072
			<?php
1073
1074
			$visibilityAttrs = '';
1075
			if ( ! $this->params['show_font_style'] ) {
1076
				$visibilityAttrs = "data-visible='false' style='display: none'";
1077
			}
1078
			?>
1079
			<label <?php echo $visibilityAttrs ?>>
1080
				Font Style
1081
				<select class='tf-font-sel-style'>
1082
					<?php
1083
					$options = array( 'normal', 'italic' );
1084
					foreach ( $options as $option ) {
1085
						printf( "<option value='%s'%s>%s</option>",
1086
							esc_attr( $option ),
1087
							selected( $value['font-style'], $option, false ),
1088
							$option
1089
						);
1090
					}
1091
					?>
1092
				</select>
1093
			</label>
1094
			<?php
1095
1096
			$visibilityAttrs = '';
1097
			if ( ! $this->params['show_line_height'] ) {
1098
				$visibilityAttrs = "data-visible='false' style='display: none'";
1099
			}
1100
			?>
1101
			<label <?php echo $visibilityAttrs ?>>
1102
				Line Height
1103
				<select class='tf-font-sel-height'>
1104
					<?php
1105
					for ( $i = .5; $i <= 3; $i += 0.1 ) {
1106
						printf( "<option value='%s'%s>%s</option>",
1107
							esc_attr( $i . 'em' ),
1108
							selected( $value['line-height'], $i . 'em', false ),
1109
							$i . 'em'
1110
						);
1111
					}
1112
					?>
1113
				</select>
1114
			</label>
1115
			<?php
1116
1117
			$visibilityAttrs = '';
1118
			if ( ! $this->params['show_letter_spacing'] ) {
1119
				$visibilityAttrs = "data-visible='false' style='display: none'";
1120
			}
1121
			?>
1122
			<label <?php echo $visibilityAttrs ?>>
1123
				Letter Spacing
1124
				<select class='tf-font-sel-spacing'>
1125
					<option value='normal'>normal</option>
1126
					<?php
1127
					for ( $i = -20; $i <= 20; $i++ ) {
1128
						printf( "<option value='%s'%s>%s</option>",
1129
							esc_attr( $i . 'px' ),
1130
							selected( $value['letter-spacing'], $i . 'px', false ),
1131
							$i . 'px'
1132
						);
1133
					}
1134
					?>
1135
				</select>
1136
			</label>
1137
			<?php
1138
1139
			$visibilityAttrs = '';
1140
			if ( ! $this->params['show_text_transform'] ) {
1141
				$visibilityAttrs = "data-visible='false' style='display: none'";
1142
			}
1143
			?>
1144
			<label <?php echo $visibilityAttrs ?>>
1145
				Text Transform
1146
				<select class='tf-font-sel-transform'>
1147
					<?php
1148
					$options = array( 'none', 'capitalize', 'uppercase', 'lowercase' );
1149
					foreach ( $options as $option ) {
1150
						printf( "<option value='%s'%s>%s</option>",
1151
							esc_attr( $option ),
1152
							selected( $value['text-transform'], $option, false ),
1153
							$option
1154
						);
1155
					}
1156
					?>
1157
				</select>
1158
			</label>
1159
			<?php
1160
1161
			$visibilityAttrs = '';
1162
			if ( ! $this->params['show_font_variant'] ) {
1163
				$visibilityAttrs = "data-visible='false' style='display: none'";
1164
			}
1165
			?>
1166
			<label <?php echo $visibilityAttrs ?>>
1167
				Font Variant
1168
				<select class='tf-font-sel-variant'>
1169
					<?php
1170
					$options = array( 'normal', 'small-caps' );
1171
					foreach ( $options as $option ) {
1172
						printf( "<option value='%s'%s>%s</option>",
1173
							esc_attr( $option ),
1174
							selected( $value['font-variant'], $option, false ),
1175
							$option
1176
						);
1177
					}
1178
					?>
1179
				</select>
1180
			</label>
1181
			<?php
1182
1183
			$visibilityAttrs = '';
1184
			if ( ! $this->params['show_text_shadow'] ) {
1185
				$visibilityAttrs = "data-visible='false' style='display: none'";
1186
			}
1187
			?>
1188
			<label <?php echo $visibilityAttrs ?>>
1189
				Shadow Location
1190
				<select class='tf-font-sel-location'>
1191
					<?php
1192
					$options = array( 'none', 'top', 'bottom', 'left', 'right', 'top-left', 'top-right', 'bottom-left', 'bottom-right' );
1193
					foreach ( $options as $option ) {
1194
						printf( "<option value='%s'%s>%s</option>",
1195
							esc_attr( $option ),
1196
							selected( $value['text-shadow-location'], $option, false ),
1197
							$option
1198
						);
1199
					}
1200
					?>
1201
				</select>
1202
			</label>
1203
			<label style='display: none'>
1204
				Shadow Distance
1205
				<select class='tf-font-sel-distance'>
1206
					<?php
1207
					for ( $i = 0; $i <= 10; $i++ ) {
1208
						printf( "<option value='%s'%s>%s</option>",
1209
							esc_attr( $i . 'px' ),
1210
							selected( $value['text-shadow-distance'], $i . 'px', false ),
1211
							$i . 'px'
1212
						);
1213
					}
1214
					?>
1215
				</select>
1216
			</label>
1217
			<label style='display: none'>
1218
				Shadow Blur
1219
				<select class='tf-font-sel-blur'>
1220
					<?php
1221
					$options = array( '0px', '1px', '2px', '3px', '4px', '5px', '10px', '20px' );
1222
					foreach ( $options as $option ) {
1223
						printf( "<option value='%s'%s>%s</option>",
1224
							esc_attr( $option ),
1225
							selected( $value['text-shadow-blur'], $option, false ),
1226
							$option
1227
						);
1228
					}
1229
					?>
1230
				</select>
1231
			</label>
1232
			<label style='display: none'>
1233
				Shadow Color
1234
				<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'] ) ?>"/>
1235
			</label>
1236
			<label style='display: none'>
1237
				Shadow Opacity
1238
				<select class='tf-font-sel-opacity'>
1239
					<?php
1240
					$options = array( '1', '0.9', '0.8', '0.7', '0.6', '0.5', '0.4', '0.3', '0.2', '0.1', '0' );
1241
					foreach ( $options as $option ) {
1242
						printf( "<option value='%s'%s>%s</option>",
1243
							esc_attr( $option ),
1244
							selected( $value['text-shadow-opacity'], $option, false ),
1245
							$option
1246
						);
1247
					}
1248
					?>
1249
				</select>
1250
			</label>
1251
			</div>
1252
			<?php
1253
1254
			$visibilityAttrs = '';
1255
			if ( ! $this->params['show_preview'] ) {
1256
				$visibilityAttrs = "data-visible='false' style='display: none'";
1257
			}
1258
			?>
1259
			<div <?php echo $visibilityAttrs ?>>
1260
				<iframe></iframe>
1261
				<i class='dashicons dashicons-admin-appearance btn-dark'></i>
1262
				<input type='hidden' class='tf-font-sel-dark' value='<?php echo esc_attr( $value['dark'] ? 'dark' : '' ) ?>'/>
1263
			</div>
1264
			<?php
1265
1266
			if ( ! is_serialized( $value ) ) {
1267
				$value = serialize( $value );
1268
			}
1269
1270
			?>
1271
			<input type='hidden' class='tf-for-saving' <?php $this->link() ?> value='<?php echo esc_attr( $value ) ?>'/>
1272
			</div>
1273
			<?php
1274
			echo "<p class='description'>{$this->description}</p>";
1275
		}
1276
	}
1277
}
1278