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