PluginProbe
Cool Timeline (Horizontal & Vertical Timeline) / trunk
Cool Timeline (Horizontal & Vertical Timeline) vtrunk
3.4.0 3.3.6 3.3.5 3.3.4 3.3.3 3.3.2 2.2.3 2.3.3 2.4 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 2.6.1 2.7.1 2.8.3 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7 2.9.8 2.9.9 3.0.0 All 79 releases
cool-timeline / admin / codestar-framework / fields / dimensions / dimensions.php

dimensions.php in Cool Timeline (Horizontal & Vertical Timeline) trunk, at admin/codestar-framework/fields/dimensions/dimensions.php

112 lines 4.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php if ( ! defined( 'ABSPATH' ) ) {
2 die;
3 } // Cannot access directly.
4 // phpcs:ignoreFile WordPress.Security.EscapeOutput.OutputNotEscaped
5 /**
6 *
7 * Field: dimensions
8 *
9 * @since 1.0.0
10 * @version 1.0.0
11 */
12 if ( ! class_exists( 'CSF_Field_dimensions' ) ) {
13 class CSF_Field_dimensions extends CSF_Fields {
14
15
16 public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) {
17
18 parent::__construct( $field, $value, $unique, $where, $parent );
19 }
20
21 public function render() {
22
23 // phpcs:disable WordPress.WP.I18n.TextDomainMismatch
24 $args = wp_parse_args(
25 $this->field,
26 array(
27 'width_icon' => '<i class="fas fa-arrows-alt-h"></i>',
28 'height_icon' => '<i class="fas fa-arrows-alt-v"></i>',
29 'width_placeholder' => esc_html__( 'width', 'csf' ),
30 'height_placeholder' => esc_html__( 'height', 'csf' ),
31 'width' => true,
32 'height' => true,
33 'unit' => true,
34 'show_units' => true,
35 'units' => array( 'px', '%', 'em' ),
36 )
37 );
38 // phpcs:enable WordPress.WP.I18n.TextDomainMismatch
39
40 $default_values = array(
41 'width' => '',
42 'height' => '',
43 'unit' => 'px',
44 );
45
46 $value = wp_parse_args( $this->value, $default_values );
47 $unit = ( count( $args['units'] ) === 1 && ! empty( $args['unit'] ) ) ? $args['units'][0] : '';
48 $is_unit = ( ! empty( $unit ) ) ? ' csf--is-unit' : '';
49
50 echo $this->field_before();
51
52 echo '<div class="csf--inputs" data-depend-id="' . esc_attr( $this->field['id'] ) . '">';
53
54 if ( ! empty( $args['width'] ) ) {
55 $placeholder = ( ! empty( $args['width_placeholder'] ) ) ? ' placeholder="' . esc_attr( $args['width_placeholder'] ) . '"' : '';
56 echo '<div class="csf--input">';
57 echo ( ! empty( $args['width_icon'] ) ) ? '<span class="csf--label csf--icon">' . $args['width_icon'] . '</span>' : '';
58 echo '<input type="number" name="' . esc_attr( $this->field_name( '[width]' ) ) . '" value="' . esc_attr( $value['width'] ) . '"' . $placeholder . ' class="csf-input-number' . esc_attr( $is_unit ) . '" step="any" />';
59 echo ( ! empty( $unit ) ) ? '<span class="csf--label csf--unit">' . esc_attr( $args['units'][0] ) . '</span>' : '';
60 echo '</div>';
61 }
62
63 if ( ! empty( $args['height'] ) ) {
64 $placeholder = ( ! empty( $args['height_placeholder'] ) ) ? ' placeholder="' . esc_attr( $args['height_placeholder'] ) . '"' : '';
65 echo '<div class="csf--input">';
66 echo ( ! empty( $args['height_icon'] ) ) ? '<span class="csf--label csf--icon">' . $args['height_icon'] . '</span>' : '';
67 echo '<input type="number" name="' . esc_attr( $this->field_name( '[height]' ) ) . '" value="' . esc_attr( $value['height'] ) . '"' . $placeholder . ' class="csf-input-number' . esc_attr( $is_unit ) . '" step="any" />';
68 echo ( ! empty( $unit ) ) ? '<span class="csf--label csf--unit">' . esc_attr( $args['units'][0] ) . '</span>' : '';
69 echo '</div>';
70 }
71
72 if ( ! empty( $args['unit'] ) && ! empty( $args['show_units'] ) && count( $args['units'] ) > 1 ) {
73 echo '<div class="csf--input">';
74 echo '<select name="' . esc_attr( $this->field_name( '[unit]' ) ) . '">';
75 foreach ( $args['units'] as $unit ) {
76 $selected = ( $value['unit'] === $unit ) ? ' selected' : '';
77 echo '<option value="' . esc_attr( $unit ) . '"' . esc_attr( $selected ) . '>' . esc_attr( $unit ) . '</option>';
78 }
79 echo '</select>';
80 echo '</div>';
81 }
82
83 echo '</div>';
84
85 echo $this->field_after();
86
87 }
88
89 public function output() {
90
91 $output = '';
92 $element = ( is_array( $this->field['output'] ) ) ? join( ',', $this->field['output'] ) : $this->field['output'];
93 $prefix = ( ! empty( $this->field['output_prefix'] ) ) ? $this->field['output_prefix'] . '-' : '';
94 $important = ( ! empty( $this->field['output_important'] ) ) ? '!important' : '';
95 $unit = ( ! empty( $this->value['unit'] ) ) ? $this->value['unit'] : 'px';
96 $width = ( isset( $this->value['width'] ) && $this->value['width'] !== '' ) ? $prefix . 'width:' . $this->value['width'] . $unit . $important . ';' : '';
97 $height = ( isset( $this->value['height'] ) && $this->value['height'] !== '' ) ? $prefix . 'height:' . $this->value['height'] . $unit . $important . ';' : '';
98
99 if ( $width !== '' || $height !== '' ) {
100 $output = $element . '{' . $width . $height . '}';
101 }
102
103 $this->parent->output_css .= $output;
104
105 return $output;
106
107 }
108
109 }
110 }
111
112