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