| 1 | <?php |
|---|
| 2 | /** |
|---|
| 3 | * Class to Build the Countdown Block. |
|---|
| 4 | * |
|---|
| 5 | * @package Kadence Blocks |
|---|
| 6 | */ |
|---|
| 7 | |
|---|
| 8 | // Exit if accessed directly. |
|---|
| 9 | if ( ! defined( 'ABSPATH' ) ) { |
|---|
| 10 | exit; |
|---|
| 11 | } |
|---|
| 12 | |
|---|
| 13 | /** |
|---|
| 14 | * Class to Build the Countdown Block. |
|---|
| 15 | * |
|---|
| 16 | * @category class |
|---|
| 17 | */ |
|---|
| 18 | class Kadence_Blocks_Countdown_Block extends Kadence_Blocks_Abstract_Block { |
|---|
| 19 | |
|---|
| 20 | /** |
|---|
| 21 | * Instance of this class |
|---|
| 22 | * |
|---|
| 23 | * @var null |
|---|
| 24 | */ |
|---|
| 25 | private static $instance = null; |
|---|
| 26 | |
|---|
| 27 | /** |
|---|
| 28 | * Block name within this namespace. |
|---|
| 29 | * |
|---|
| 30 | * @var string |
|---|
| 31 | */ |
|---|
| 32 | protected $block_name = 'countdown'; |
|---|
| 33 | |
|---|
| 34 | /** |
|---|
| 35 | * Block determines in scripts need to be loaded for block. |
|---|
| 36 | * |
|---|
| 37 | * @var string |
|---|
| 38 | */ |
|---|
| 39 | protected $has_script = true; |
|---|
| 40 | |
|---|
| 41 | /** |
|---|
| 42 | * Instance Control |
|---|
| 43 | */ |
|---|
| 44 | public static function get_instance() { |
|---|
| 45 | if ( is_null( self::$instance ) ) { |
|---|
| 46 | self::$instance = new self(); |
|---|
| 47 | } |
|---|
| 48 | |
|---|
| 49 | return self::$instance; |
|---|
| 50 | } |
|---|
| 51 | |
|---|
| 52 | /** |
|---|
| 53 | * Builds CSS for block. |
|---|
| 54 | * |
|---|
| 55 | * @param array $attributes the blocks attributes. |
|---|
| 56 | * @param Kadence_Blocks_CSS $css the css class for blocks. |
|---|
| 57 | * @param string $unique_id the blocks attr ID. |
|---|
| 58 | * @param string $unique_style_id the blocks alternate ID for queries. |
|---|
| 59 | */ |
|---|
| 60 | public function build_css( $attributes, $css, $unique_id, $unique_style_id ) { |
|---|
| 61 | |
|---|
| 62 | $css->set_style_id( 'kb-' . $this->block_name . $unique_style_id ); |
|---|
| 63 | |
|---|
| 64 | if ( isset( $attributes['background'] ) || isset( $attributes['border'] ) || ( isset( $attributes['borderRadius'] ) && is_array( $attributes['borderRadius'] ) ) || ( isset( $attributes['borderWidth'] ) && is_array( $attributes['borderWidth'] ) ) ) { |
|---|
| 65 | $css->set_selector( '.kb-countdown-container-' . $unique_id ); |
|---|
| 66 | if ( isset( $attributes['background'] ) && ! empty( $attributes['background'] ) ) { |
|---|
| 67 | $css->add_property( 'background', $css->render_color( $attributes['background'] ) ); |
|---|
| 68 | } |
|---|
| 69 | if ( isset( $attributes['border'] ) && ! empty( $attributes['border'] ) ) { |
|---|
| 70 | $css->add_property( 'border-color', $css->render_color( $attributes['border'] ) ); |
|---|
| 71 | } |
|---|
| 72 | if ( isset( $attributes['borderRadius'] ) && is_array( $attributes['borderRadius'] ) ) { |
|---|
| 73 | if ( isset( $attributes['borderRadius'][0] ) && is_numeric( $attributes['borderRadius'][0] ) ) { |
|---|
| 74 | $css->add_property( 'border-top-left-radius', $attributes['borderRadius'][0] . 'px' ); |
|---|
| 75 | } |
|---|
| 76 | if ( isset( $attributes['borderRadius'][1] ) && is_numeric( $attributes['borderRadius'][1] ) ) { |
|---|
| 77 | $css->add_property( 'border-top-right-radius', $attributes['borderRadius'][1] . 'px' ); |
|---|
| 78 | } |
|---|
| 79 | if ( isset( $attributes['borderRadius'][2] ) && is_numeric( $attributes['borderRadius'][2] ) ) { |
|---|
| 80 | $css->add_property( 'border-bottom-right-radius', $attributes['borderRadius'][2] . 'px' ); |
|---|
| 81 | } |
|---|
| 82 | if ( isset( $attributes['borderRadius'][3] ) && is_numeric( $attributes['borderRadius'][3] ) ) { |
|---|
| 83 | $css->add_property( 'border-bottom-left-radius', $attributes['borderRadius'][3] . 'px' ); |
|---|
| 84 | } |
|---|
| 85 | } |
|---|
| 86 | if ( isset( $attributes['borderWidth'] ) && is_array( $attributes['borderWidth'] ) ) { |
|---|
| 87 | if ( isset( $attributes['borderWidth'][0] ) && is_numeric( $attributes['borderWidth'][0] ) ) { |
|---|
| 88 | $css->add_property( 'border-top-width', $attributes['borderWidth'][0] . 'px' ); |
|---|
| 89 | } |
|---|
| 90 | if ( isset( $attributes['borderWidth'][1] ) && is_numeric( $attributes['borderWidth'][1] ) ) { |
|---|
| 91 | $css->add_property( 'border-right-width', $attributes['borderWidth'][1] . 'px' ); |
|---|
| 92 | } |
|---|
| 93 | if ( isset( $attributes['borderWidth'][2] ) && is_numeric( $attributes['borderWidth'][2] ) ) { |
|---|
| 94 | $css->add_property( 'border-bottom-width', $attributes['borderWidth'][2] . 'px' ); |
|---|
| 95 | } |
|---|
| 96 | if ( isset( $attributes['borderWidth'][3] ) && is_numeric( $attributes['borderWidth'][3] ) ) { |
|---|
| 97 | $css->add_property( 'border-left-width', $attributes['borderWidth'][3] . 'px' ); |
|---|
| 98 | } |
|---|
| 99 | } |
|---|
| 100 | } |
|---|
| 101 | if ( isset( $attributes['tabletBorderWidth'] ) && is_array( $attributes['tabletBorderWidth'] ) ) { |
|---|
| 102 | $css->set_media_state( 'tablet' ); |
|---|
| 103 | $css->set_selector( '.kb-countdown-container-' . $unique_id ); |
|---|
| 104 | if ( isset( $attributes['tabletBorderWidth'][0] ) && is_numeric( $attributes['tabletBorderWidth'][0] ) ) { |
|---|
| 105 | $css->add_property( 'border-top-width', $attributes['tabletBorderWidth'][0] . 'px' ); |
|---|
| 106 | } |
|---|
| 107 | if ( isset( $attributes['tabletBorderWidth'][1] ) && is_numeric( $attributes['tabletBorderWidth'][1] ) ) { |
|---|
| 108 | $css->add_property( 'border-right-width', $attributes['tabletBorderWidth'][1] . 'px' ); |
|---|
| 109 | } |
|---|
| 110 | if ( isset( $attributes['tabletBorderWidth'][2] ) && is_numeric( $attributes['tabletBorderWidth'][2] ) ) { |
|---|
| 111 | $css->add_property( 'border-bottom-width', $attributes['tabletBorderWidth'][2] . 'px' ); |
|---|
| 112 | } |
|---|
| 113 | if ( isset( $attributes['tabletBorderWidth'][3] ) && is_numeric( $attributes['tabletBorderWidth'][3] ) ) { |
|---|
| 114 | $css->add_property( 'border-left-width', $attributes['tabletBorderWidth'][3] . 'px' ); |
|---|
| 115 | } |
|---|
| 116 | $css->set_media_state( 'desktop' ); |
|---|
| 117 | } |
|---|
| 118 | if ( isset( $attributes['mobileBorderWidth'] ) && is_array( $attributes['mobileBorderWidth'] ) ) { |
|---|
| 119 | $css->set_media_state( 'mobile' ); |
|---|
| 120 | $css->set_selector( '.kb-countdown-container-' . $unique_id ); |
|---|
| 121 | if ( isset( $attributes['mobileBorderWidth'][0] ) && is_numeric( $attributes['mobileBorderWidth'][0] ) ) { |
|---|
| 122 | $css->add_property( 'border-top-width', $attributes['mobileBorderWidth'][0] . 'px' ); |
|---|
| 123 | } |
|---|
| 124 | if ( isset( $attributes['mobileBorderWidth'][1] ) && is_numeric( $attributes['mobileBorderWidth'][1] ) ) { |
|---|
| 125 | $css->add_property( 'border-right-width', $attributes['mobileBorderWidth'][1] . 'px' ); |
|---|
| 126 | } |
|---|
| 127 | if ( isset( $attributes['mobileBorderWidth'][2] ) && is_numeric( $attributes['mobileBorderWidth'][2] ) ) { |
|---|
| 128 | $css->add_property( 'border-bottom-width', $attributes['mobileBorderWidth'][2] . 'px' ); |
|---|
| 129 | } |
|---|
| 130 | if ( isset( $attributes['mobileBorderWidth'][3] ) && is_numeric( $attributes['mobileBorderWidth'][3] ) ) { |
|---|
| 131 | $css->add_property( 'border-left-width', $attributes['mobileBorderWidth'][3] . 'px' ); |
|---|
| 132 | } |
|---|
| 133 | $css->set_media_state( 'desktop' ); |
|---|
| 134 | } |
|---|
| 135 | $css->set_selector( '.kb-countdown-container-' . $unique_id ); |
|---|
| 136 | $css->render_measure_output( $attributes, 'containerPadding', 'padding', [ 'unit_key' => 'paddingType', 'tablet_key' => 'containerTabletPadding', 'mobile_key' => 'containerMobilePadding' ] ); |
|---|
| 137 | |
|---|
| 138 | $css->render_measure_output( $attributes, 'containerMargin', 'margin', [ 'unit_key' => 'marginType', 'tablet_key' => 'containerTabletMargin', 'mobile_key' => 'containerMobileMargin' ] ); |
|---|
| 139 | |
|---|
| 140 | if ( isset( $attributes['itemBackground'] ) || isset( $attributes['itemBorder'] ) || ( isset( $attributes['itemBorderRadius'] ) && is_array( $attributes['itemBorderRadius'] ) ) || ( isset( $attributes['itemBorderWidth'] ) && is_array( $attributes['itemBorderWidth'] ) ) || ( isset( $attributes['itemPadding'] ) && is_array( $attributes['itemPadding'] ) ) ) { |
|---|
| 141 | $css->set_selector( '.kb-countdown-container-' . $unique_id . ' .kb-countdown-date-item:not( .kb-countdown-divider-item )' ); |
|---|
| 142 | if ( isset( $attributes['itemBackground'] ) && ! empty( $attributes['itemBackground'] ) ) { |
|---|
| 143 | $css->add_property( 'background', $css->render_color( $attributes['itemBackground'] ) ); |
|---|
| 144 | } |
|---|
| 145 | if ( isset( $attributes['itemBorder'] ) && ! empty( $attributes['itemBorder'] ) ) { |
|---|
| 146 | $css->add_property( 'border-color', $css->render_color( $attributes['itemBorder'] ) ); |
|---|
| 147 | } |
|---|
| 148 | if ( isset( $attributes['itemBorderRadius'] ) && is_array( $attributes['itemBorderRadius'] ) ) { |
|---|
| 149 | if ( isset( $attributes['itemBorderRadius'][0] ) && is_numeric( $attributes['itemBorderRadius'][0] ) ) { |
|---|
| 150 | $css->add_property( 'border-top-left-radius', $attributes['itemBorderRadius'][0] . 'px' ); |
|---|
| 151 | } |
|---|
| 152 | if ( isset( $attributes['itemBorderRadius'][1] ) && is_numeric( $attributes['itemBorderRadius'][1] ) ) { |
|---|
| 153 | $css->add_property( 'border-top-right-radius', $attributes['itemBorderRadius'][1] . 'px' ); |
|---|
| 154 | } |
|---|
| 155 | if ( isset( $attributes['itemBorderRadius'][2] ) && is_numeric( $attributes['itemBorderRadius'][2] ) ) { |
|---|
| 156 | $css->add_property( 'border-bottom-right-radius', $attributes['itemBorderRadius'][2] . 'px' ); |
|---|
| 157 | } |
|---|
| 158 | if ( isset( $attributes['itemBorderRadius'][3] ) && is_numeric( $attributes['itemBorderRadius'][3] ) ) { |
|---|
| 159 | $css->add_property( 'border-bottom-left-radius', $attributes['itemBorderRadius'][3] . 'px' ); |
|---|
| 160 | } |
|---|
| 161 | } |
|---|
| 162 | if ( isset( $attributes['itemBorderWidth'] ) && is_array( $attributes['itemBorderWidth'] ) ) { |
|---|
| 163 | if ( isset( $attributes['itemBorderWidth'][0] ) && is_numeric( $attributes['itemBorderWidth'][0] ) ) { |
|---|
| 164 | $css->add_property( 'border-top-width', $attributes['itemBorderWidth'][0] . 'px' ); |
|---|
| 165 | } |
|---|
| 166 | if ( isset( $attributes['itemBorderWidth'][1] ) && is_numeric( $attributes['itemBorderWidth'][1] ) ) { |
|---|
| 167 | $css->add_property( 'border-right-width', $attributes['itemBorderWidth'][1] . 'px' ); |
|---|
| 168 | } |
|---|
| 169 | if ( isset( $attributes['itemBorderWidth'][2] ) && is_numeric( $attributes['itemBorderWidth'][2] ) ) { |
|---|
| 170 | $css->add_property( 'border-bottom-width', $attributes['itemBorderWidth'][2] . 'px' ); |
|---|
| 171 | } |
|---|
| 172 | if ( isset( $attributes['itemBorderWidth'][3] ) && is_numeric( $attributes['itemBorderWidth'][3] ) ) { |
|---|
| 173 | $css->add_property( 'border-left-width', $attributes['itemBorderWidth'][3] . 'px' ); |
|---|
| 174 | } |
|---|
| 175 | } |
|---|
| 176 | if ( isset( $attributes['itemPadding'] ) && is_array( $attributes['itemPadding'] ) ) { |
|---|
| 177 | if ( isset( $attributes['itemPadding'][0] ) && is_numeric( $attributes['itemPadding'][0] ) ) { |
|---|
| 178 | $css->add_property( 'padding-top', $attributes['itemPadding'][0] . ( isset( $attributes['itemPaddingType'] ) ? $attributes['itemPaddingType'] : 'px' ) ); |
|---|
| 179 | } |
|---|
| 180 | if ( isset( $attributes['itemPadding'][1] ) && is_numeric( $attributes['itemPadding'][1] ) ) { |
|---|
| 181 | $css->add_property( 'padding-right', $attributes['itemPadding'][1] . ( isset( $attributes['itemPaddingType'] ) ? $attributes['itemPaddingType'] : 'px' ) ); |
|---|
| 182 | } |
|---|
| 183 | if ( isset( $attributes['itemPadding'][2] ) && is_numeric( $attributes['itemPadding'][2] ) ) { |
|---|
| 184 | $css->add_property( 'padding-bottom', $attributes['itemPadding'][2] . ( isset( $attributes['itemPaddingType'] ) ? $attributes['itemPaddingType'] : 'px' ) ); |
|---|
| 185 | } |
|---|
| 186 | if ( isset( $attributes['itemPadding'][3] ) && is_numeric( $attributes['itemPadding'][3] ) ) { |
|---|
| 187 | $css->add_property( 'padding-left', $attributes['itemPadding'][3] . ( isset( $attributes['itemPaddingType'] ) ? $attributes['itemPaddingType'] : 'px' ) ); |
|---|
| 188 | } |
|---|
| 189 | } |
|---|
| 190 | $css->set_selector( '.kb-countdown-container-' . $unique_id . ' .kb-countdown-date-item.kb-countdown-divider-item' ); |
|---|
| 191 | if ( isset( $attributes['itemPadding'] ) && is_array( $attributes['itemPadding'] ) ) { |
|---|
| 192 | if ( isset( $attributes['itemPadding'][0] ) && is_numeric( $attributes['itemPadding'][0] ) ) { |
|---|
| 193 | $css->add_property( 'padding-top', $attributes['itemPadding'][0] . ( isset( $attributes['itemPaddingType'] ) ? $attributes['itemPaddingType'] : 'px' ) ); |
|---|
| 194 | } |
|---|
| 195 | if ( isset( $attributes['itemPadding'][2] ) && is_numeric( $attributes['itemPadding'][2] ) ) { |
|---|
| 196 | $css->add_property( 'padding-bottom', $attributes['itemPadding'][2] . ( isset( $attributes['itemPaddingType'] ) ? $attributes['itemPaddingType'] : 'px' ) ); |
|---|
| 197 | } |
|---|
| 198 | } |
|---|
| 199 | if ( isset( $attributes['itemBorderWidth'] ) && is_array( $attributes['itemBorderWidth'] ) ) { |
|---|
| 200 | if ( isset( $attributes['itemBorderWidth'][0] ) && is_numeric( $attributes['itemBorderWidth'][0] ) ) { |
|---|
| 201 | $css->add_property( 'border-top-width', $attributes['itemBorderWidth'][0] . 'px' ); |
|---|
| 202 | } |
|---|
| 203 | if ( isset( $attributes['itemBorderWidth'][2] ) && is_numeric( $attributes['itemBorderWidth'][2] ) ) { |
|---|
| 204 | $css->add_property( 'border-bottom-width', $attributes['itemBorderWidth'][2] . 'px' ); |
|---|
| 205 | } |
|---|
| 206 | } |
|---|
| 207 | } |
|---|
| 208 | if ( ( isset( $attributes['itemTabletBorderWidth'] ) && is_array( $attributes['itemTabletBorderWidth'] ) ) || ( isset( $attributes['itemTabletPadding'] ) && is_array( $attributes['itemTabletPadding'] ) ) ) { |
|---|
| 209 | $css->set_media_state( 'tablet' ); |
|---|
| 210 | $css->set_selector( '.kb-countdown-container-' . $unique_id . ' .kb-countdown-date-item:not( .kb-countdown-divider-item )' ); |
|---|
| 211 | if ( isset( $attributes['itemTabletPadding'] ) && is_array( $attributes['itemTabletPadding'] ) ) { |
|---|
| 212 | if ( isset( $attributes['itemTabletPadding'][0] ) && is_numeric( $attributes['itemTabletPadding'][0] ) ) { |
|---|
| 213 | $css->add_property( 'padding-top', $attributes['itemTabletPadding'][0] . ( isset( $attributes['itemPaddingType'] ) ? $attributes['itemPaddingType'] : 'px' ) ); |
|---|
| 214 | } |
|---|
| 215 | if ( isset( $attributes['itemTabletPadding'][1] ) && is_numeric( $attributes['itemTabletPadding'][1] ) ) { |
|---|
| 216 | $css->add_property( 'padding-right', $attributes['itemTabletPadding'][1] . ( isset( $attributes['itemPaddingType'] ) ? $attributes['itemPaddingType'] : 'px' ) ); |
|---|
| 217 | } |
|---|
| 218 | if ( isset( $attributes['itemTabletPadding'][2] ) && is_numeric( $attributes['itemTabletPadding'][2] ) ) { |
|---|
| 219 | $css->add_property( 'padding-bottom', $attributes['itemTabletPadding'][2] . ( isset( $attributes['itemPaddingType'] ) ? $attributes['itemPaddingType'] : 'px' ) ); |
|---|
| 220 | } |
|---|
| 221 | if ( isset( $attributes['itemTabletPadding'][3] ) && is_numeric( $attributes['itemTabletPadding'][3] ) ) { |
|---|
| 222 | $css->add_property( 'padding-left', $attributes['itemTabletPadding'][3] . ( isset( $attributes['itemPaddingType'] ) ? $attributes['itemPaddingType'] : 'px' ) ); |
|---|
| 223 | } |
|---|
| 224 | } |
|---|
| 225 | if ( isset( $attributes['itemTabletBorderWidth'] ) && is_array( $attributes['itemTabletBorderWidth'] ) ) { |
|---|
| 226 | if ( isset( $attributes['itemTabletBorderWidth'][0] ) && is_numeric( $attributes['itemTabletBorderWidth'][0] ) ) { |
|---|
| 227 | $css->add_property( 'border-top-width', $attributes['itemTabletBorderWidth'][0] . 'px' ); |
|---|
| 228 | } |
|---|
| 229 | if ( isset( $attributes['itemTabletBorderWidth'][1] ) && is_numeric( $attributes['itemTabletBorderWidth'][1] ) ) { |
|---|
| 230 | $css->add_property( 'border-right-width', $attributes['itemTabletBorderWidth'][1] . 'px' ); |
|---|
| 231 | } |
|---|
| 232 | if ( isset( $attributes['itemTabletBorderWidth'][2] ) && is_numeric( $attributes['itemTabletBorderWidth'][2] ) ) { |
|---|
| 233 | $css->add_property( 'border-bottom-width', $attributes['itemTabletBorderWidth'][2] . 'px' ); |
|---|
| 234 | } |
|---|
| 235 | if ( isset( $attributes['itemTabletBorderWidth'][3] ) && is_numeric( $attributes['itemTabletBorderWidth'][3] ) ) { |
|---|
| 236 | $css->add_property( 'border-left-width', $attributes['itemTabletBorderWidth'][3] . 'px' ); |
|---|
| 237 | } |
|---|
| 238 | } |
|---|
| 239 | $css->set_selector( '.kb-countdown-container-' . $unique_id . ' .kb-countdown-date-item.kb-countdown-divider-item' ); |
|---|
| 240 | if ( isset( $attributes['itemTabletPadding'] ) && is_array( $attributes['itemTabletPadding'] ) ) { |
|---|
| 241 | if ( isset( $attributes['itemTabletPadding'][0] ) && is_numeric( $attributes['itemTabletPadding'][0] ) ) { |
|---|
| 242 | $css->add_property( 'padding-top', $attributes['itemTabletPadding'][0] . ( isset( $attributes['itemPaddingType'] ) ? $attributes['itemPaddingType'] : 'px' ) ); |
|---|
| 243 | } |
|---|
| 244 | if ( isset( $attributes['itemTabletPadding'][2] ) && is_numeric( $attributes['itemTabletPadding'][2] ) ) { |
|---|
| 245 | $css->add_property( 'padding-bottom', $attributes['itemTabletPadding'][2] . ( isset( $attributes['itemPaddingType'] ) ? $attributes['itemPaddingType'] : 'px' ) ); |
|---|
| 246 | } |
|---|
| 247 | } |
|---|
| 248 | if ( isset( $attributes['itemTabletBorderWidth'] ) && is_array( $attributes['itemTabletBorderWidth'] ) ) { |
|---|
| 249 | if ( isset( $attributes['itemTabletBorderWidth'][0] ) && is_numeric( $attributes['itemTabletBorderWidth'][0] ) ) { |
|---|
| 250 | $css->add_property( 'border-top-width', $attributes['itemTabletBorderWidth'][0] . 'px' ); |
|---|
| 251 | } |
|---|
| 252 | if ( isset( $attributes['itemTabletBorderWidth'][2] ) && is_numeric( $attributes['itemTabletBorderWidth'][2] ) ) { |
|---|
| 253 | $css->add_property( 'border-bottom-width', $attributes['itemTabletBorderWidth'][2] . 'px' ); |
|---|
| 254 | } |
|---|
| 255 | } |
|---|
| 256 | $css->set_media_state( 'desktop' ); |
|---|
| 257 | } |
|---|
| 258 | if ( ( isset( $attributes['itemMobileBorderWidth'] ) && is_array( $attributes['itemMobileBorderWidth'] ) ) || ( isset( $attributes['itemMobilePadding'] ) && is_array( $attributes['itemMobilePadding'] ) ) ) { |
|---|
| 259 | $css->set_media_state( 'mobile' ); |
|---|
| 260 | $css->set_selector( '.kb-countdown-container-' . $unique_id . ' .kb-countdown-date-item:not( .kb-countdown-divider-item )' ); |
|---|
| 261 | if ( isset( $attributes['itemMobilePadding'] ) && is_array( $attributes['itemMobilePadding'] ) ) { |
|---|
| 262 | if ( isset( $attributes['itemMobilePadding'][0] ) && is_numeric( $attributes['itemMobilePadding'][0] ) ) { |
|---|
| 263 | $css->add_property( 'padding-top', $attributes['itemMobilePadding'][0] . ( isset( $attributes['itemPaddingType'] ) ? $attributes['itemPaddingType'] : 'px' ) ); |
|---|
| 264 | } |
|---|
| 265 | if ( isset( $attributes['itemMobilePadding'][1] ) && is_numeric( $attributes['itemMobilePadding'][1] ) ) { |
|---|
| 266 | $css->add_property( 'padding-right', $attributes['itemMobilePadding'][1] . ( isset( $attributes['itemPaddingType'] ) ? $attributes['itemPaddingType'] : 'px' ) ); |
|---|
| 267 | } |
|---|
| 268 | if ( isset( $attributes['itemMobilePadding'][2] ) && is_numeric( $attributes['itemMobilePadding'][2] ) ) { |
|---|
| 269 | $css->add_property( 'padding-bottom', $attributes['itemMobilePadding'][2] . ( isset( $attributes['itemPaddingType'] ) ? $attributes['itemPaddingType'] : 'px' ) ); |
|---|
| 270 | } |
|---|
| 271 | if ( isset( $attributes['itemMobilePadding'][3] ) && is_numeric( $attributes['itemMobilePadding'][3] ) ) { |
|---|
| 272 | $css->add_property( 'padding-left', $attributes['itemMobilePadding'][3] . ( isset( $attributes['itemPaddingType'] ) ? $attributes['itemPaddingType'] : 'px' ) ); |
|---|
| 273 | } |
|---|
| 274 | } |
|---|
| 275 | if ( isset( $attributes['itemMobileBorderWidth'] ) && is_array( $attributes['itemMobileBorderWidth'] ) ) { |
|---|
| 276 | if ( isset( $attributes['itemMobileBorderWidth'][0] ) && is_numeric( $attributes['itemMobileBorderWidth'][0] ) ) { |
|---|
| 277 | $css->add_property( 'border-top-width', $attributes['itemMobileBorderWidth'][0] . 'px' ); |
|---|
| 278 | } |
|---|
| 279 | if ( isset( $attributes['itemMobileBorderWidth'][1] ) && is_numeric( $attributes['itemMobileBorderWidth'][1] ) ) { |
|---|
| 280 | $css->add_property( 'border-right-width', $attributes['itemMobileBorderWidth'][1] . 'px' ); |
|---|
| 281 | } |
|---|
| 282 | if ( isset( $attributes['itemMobileBorderWidth'][2] ) && is_numeric( $attributes['itemMobileBorderWidth'][2] ) ) { |
|---|
| 283 | $css->add_property( 'border-bottom-width', $attributes['itemMobileBorderWidth'][2] . 'px' ); |
|---|
| 284 | } |
|---|
| 285 | if ( isset( $attributes['itemMobileBorderWidth'][3] ) && is_numeric( $attributes['itemMobileBorderWidth'][3] ) ) { |
|---|
| 286 | $css->add_property( 'border-left-width', $attributes['itemMobileBorderWidth'][3] . 'px' ); |
|---|
| 287 | } |
|---|
| 288 | } |
|---|
| 289 | $css->set_media_state( 'desktop' ); |
|---|
| 290 | } |
|---|
| 291 | $number_font = ( isset( $attributes['numberFont'] ) && is_array( $attributes['numberFont'] ) && isset( $attributes['numberFont'][0] ) && is_array( $attributes['numberFont'][0] ) ? $attributes['numberFont'][0] : array() ); |
|---|
| 292 | if ( ! empty( $number_font ) || ( isset( $attributes['numberColor'] ) && ! empty( $attributes['numberColor'] ) ) ) { |
|---|
| 293 | $css->set_selector( '.kb-countdown-container.kb-countdown-container-' . $unique_id . ' .kb-countdown-date-item .kb-countdown-number' ); |
|---|
| 294 | if ( isset( $attributes['numberColor'] ) && ! empty( $attributes['numberColor'] ) ) { |
|---|
| 295 | $css->add_property( 'color', $css->render_color( $attributes['numberColor'] ) ); |
|---|
| 296 | } |
|---|
| 297 | if ( isset( $number_font['size'] ) && is_array( $number_font['size'] ) && isset( $number_font['size'][0] ) && ! empty( $number_font['size'][0] ) ) { |
|---|
| 298 | if( $css->is_variable_font_size_value( $number_font['size'][0] ) ) { |
|---|
| 299 | $css->add_property( 'font-size', $css->get_variable_font_size_value( $number_font['size'][0] ) ); |
|---|
| 300 | } else { |
|---|
| 301 | $css->add_property( 'font-size', $number_font['size'][0] . ( ! isset( $number_font['sizeType'] ) ? 'px' : $number_font['sizeType'] ) ); |
|---|
| 302 | } |
|---|
| 303 | } |
|---|
| 304 | if ( isset( $number_font['lineHeight'] ) && is_array( $number_font['lineHeight'] ) && isset( $number_font['lineHeight'][0] ) && ! empty( $number_font['lineHeight'][0] ) ) { |
|---|
| 305 | $css->add_property( 'line-height', $number_font['lineHeight'][0] . ( ! isset( $number_font['lineType'] ) ? 'px' : $number_font['lineType'] ) ); |
|---|
| 306 | } |
|---|
| 307 | if ( isset( $number_font['letterSpacing'] ) && is_array( $number_font['letterSpacing'] ) && isset( $number_font['letterSpacing'][0] ) && ! empty( $number_font['letterSpacing'][0] ) ) { |
|---|
| 308 | $css->add_property( 'letter-spacing', $number_font['letterSpacing'][0] . ( ! isset( $number_font['letterType'] ) ? 'px' : $number_font['letterType'] ) ); |
|---|
| 309 | } |
|---|
| 310 | if ( isset( $number_font['textTransform'] ) && ! empty( $number_font['textTransform'] ) ) { |
|---|
| 311 | $css->add_property( 'text-transform', $number_font['textTransform'] ); |
|---|
| 312 | } |
|---|
| 313 | if ( isset( $number_font['family'] ) && ! empty( $number_font['family'] ) ) { |
|---|
| 314 | $google = isset( $number_font['google'] ) && $number_font['google'] ? true : false; |
|---|
| 315 | $google = $google && ( isset( $number_font['loadGoogle'] ) && $number_font['loadGoogle'] || ! isset( $number_font['loadGoogle'] ) ) ? true : false; |
|---|
| 316 | $css->add_property( 'font-family', $css->render_font_family( $number_font['family'], $google, ( isset( $number_font['variant'] ) ? $number_font['variant'] : '' ), ( isset( $number_font['subset'] ) ? $number_font['subset'] : '' ) ) ); |
|---|
| 317 | } |
|---|
| 318 | if ( isset( $number_font['style'] ) && ! empty( $number_font['style'] ) ) { |
|---|
| 319 | $css->add_property( 'font-style', $number_font['style'] ); |
|---|
| 320 | } |
|---|
| 321 | if ( isset( $number_font['weight'] ) && ! empty( $number_font['weight'] ) && 'regular' !== $number_font['weight'] ) { |
|---|
| 322 | $css->add_property( 'font-weight', $number_font['weight'] ); |
|---|
| 323 | } |
|---|
| 324 | if ( isset( $number_font['size'] ) && is_array( $number_font['size'] ) && isset( $number_font['size'][0] ) && ! empty( $number_font['size'][0] ) ) { |
|---|
| 325 | $css->set_selector( '.kb-countdown-container.kb-countdown-container-' . $unique_id . ' .kb-countdown-date-item' ); |
|---|
| 326 | if( $css->is_variable_font_size_value( $number_font['size'][0] ) ) { |
|---|
| 327 | $css->add_property( 'font-size', $css->get_variable_font_size_value( $number_font['size'][0] ) ); |
|---|
| 328 | } else { |
|---|
| 329 | $css->add_property( 'font-size', $number_font['size'][0] . ( ! isset( $number_font['sizeType'] ) ? 'px' : $number_font['sizeType'] ) ); |
|---|
| 330 | } |
|---|
| 331 | } |
|---|
| 332 | $css->set_media_state( 'tablet' ); |
|---|
| 333 | $css->set_selector( '.kb-countdown-container.kb-countdown-container-' . $unique_id . ' .kb-countdown-date-item .kb-countdown-number' ); |
|---|
| 334 | if ( isset( $number_font['size'] ) && is_array( $number_font['size'] ) && isset( $number_font['size'][1] ) && ! empty( $number_font['size'][1] ) ) { |
|---|
| 335 | if( $css->is_variable_font_size_value( $number_font['size'][1] ) ) { |
|---|
| 336 | $css->add_property( 'font-size', $css->get_variable_font_size_value( $number_font['size'][1] ) ); |
|---|
| 337 | } else { |
|---|
| 338 | $css->add_property( 'font-size', $number_font['size'][1] . ( ! isset( $number_font['sizeType'] ) ? 'px' : $number_font['sizeType'] ) ); |
|---|
| 339 | } |
|---|
| 340 | } |
|---|
| 341 | if ( isset( $number_font['lineHeight'] ) && is_array( $number_font['lineHeight'] ) && isset( $number_font['lineHeight'][1] ) && ! empty( $number_font['lineHeight'][1] ) ) { |
|---|
| 342 | $css->add_property( 'line-height', $number_font['lineHeight'][1] . ( ! isset( $number_font['lineType'] ) ? 'px' : $number_font['lineType'] ) ); |
|---|
| 343 | } |
|---|
| 344 | if ( isset( $number_font['letterSpacing'] ) && is_array( $number_font['letterSpacing'] ) && isset( $number_font['letterSpacing'][1] ) && ! empty( $number_font['letterSpacing'][1] ) ) { |
|---|
| 345 | $css->add_property( 'letter-spacing', $number_font['letterSpacing'][1] . ( ! isset( $number_font['letterType'] ) ? 'px' : $number_font['letterType'] ) ); |
|---|
| 346 | } |
|---|
| 347 | if ( isset( $number_font['size'] ) && is_array( $number_font['size'] ) && isset( $number_font['size'][1] ) && ! empty( $number_font['size'][1] ) ) { |
|---|
| 348 | $css->set_selector( '.kb-countdown-container.kb-countdown-container-' . $unique_id . ' .kb-countdown-date-item' ); |
|---|
| 349 | if( $css->is_variable_font_size_value( $number_font['size'][1] ) ) { |
|---|
| 350 | $css->add_property( 'font-size', $css->get_variable_font_size_value( $number_font['size'][1] ) ); |
|---|
| 351 | } else { |
|---|
| 352 | $css->add_property( 'font-size', $number_font['size'][1] . ( ! isset( $number_font['sizeType'] ) ? 'px' : $number_font['sizeType'] ) ); |
|---|
| 353 | } |
|---|
| 354 | } |
|---|
| 355 | $css->set_media_state( 'desktop' ); |
|---|
| 356 | $css->set_media_state( 'mobile' ); |
|---|
| 357 | $css->set_selector( '.kb-countdown-container.kb-countdown-container-' . $unique_id . ' .kb-countdown-date-item .kb-countdown-number' ); |
|---|
| 358 | if ( isset( $number_font['size'] ) && is_array( $number_font['size'] ) && isset( $number_font['size'][2] ) && ! empty( $number_font['size'][2] ) ) { |
|---|
| 359 | if( $css->is_variable_font_size_value( $number_font['size'][2] ) ) { |
|---|
| 360 | $css->add_property( 'font-size', $css->get_variable_font_size_value( $number_font['size'][2] ) ); |
|---|
| 361 | } else { |
|---|
| 362 | $css->add_property( 'font-size', $number_font['size'][2] . ( ! isset( $number_font['sizeType'] ) ? 'px' : $number_font['sizeType'] ) ); |
|---|
| 363 | } |
|---|
| 364 | } |
|---|
| 365 | if ( isset( $number_font['lineHeight'] ) && is_array( $number_font['lineHeight'] ) && isset( $number_font['lineHeight'][2] ) && ! empty( $number_font['lineHeight'][2] ) ) { |
|---|
| 366 | $css->add_property( 'line-height', $number_font['lineHeight'][2] . ( ! isset( $number_font['lineType'] ) ? 'px' : $number_font['lineType'] ) ); |
|---|
| 367 | } |
|---|
| 368 | if ( isset( $number_font['letterSpacing'] ) && is_array( $number_font['letterSpacing'] ) && isset( $number_font['letterSpacing'][2] ) && ! empty( $number_font['letterSpacing'][2] ) ) { |
|---|
| 369 | $css->add_property( 'letter-spacing', $number_font['letterSpacing'][2] . ( ! isset( $number_font['letterType'] ) ? 'px' : $number_font['letterType'] ) ); |
|---|
| 370 | } |
|---|
| 371 | if ( isset( $number_font['size'] ) && is_array( $number_font['size'] ) && isset( $number_font['size'][2] ) && ! empty( $number_font['size'][2] ) ) { |
|---|
| 372 | $css->set_selector( '.kb-countdown-container.kb-countdown-container-' . $unique_id . ' .kb-countdown-date-item' ); |
|---|
| 373 | if( $css->is_variable_font_size_value( $number_font['size'][2] ) ) { |
|---|
| 374 | $css->add_property( 'font-size', $css->get_variable_font_size_value( $number_font['size'][2] ) ); |
|---|
| 375 | } else { |
|---|
| 376 | $css->add_property( 'font-size', $number_font['size'][2] . ( ! isset( $number_font['sizeType'] ) ? 'px' : $number_font['sizeType'] ) ); |
|---|
| 377 | } } |
|---|
| 378 | $css->set_media_state( 'desktop' ); |
|---|
| 379 | } |
|---|
| 380 | $label_font = ( isset( $attributes['labelFont'] ) && is_array( $attributes['labelFont'] ) && isset( $attributes['labelFont'][0] ) && is_array( $attributes['labelFont'][0] ) ? $attributes['labelFont'][0] : array() ); |
|---|
| 381 | if ( ! empty( $label_font ) || ( isset( $attributes['labelColor'] ) && ! empty( $attributes['labelColor'] ) ) ) { |
|---|
| 382 | $css->set_selector( '.kb-countdown-container.kb-countdown-container-' . $unique_id . ' .kb-countdown-date-item .kb-countdown-label' ); |
|---|
| 383 | if ( isset( $attributes['labelColor'] ) && ! empty( $attributes['labelColor'] ) ) { |
|---|
| 384 | $css->add_property( 'color', $css->render_color( $attributes['labelColor'] ) ); |
|---|
| 385 | } |
|---|
| 386 | if ( isset( $label_font['size'] ) && is_array( $label_font['size'] ) && isset( $label_font['size'][0] ) && ! empty( $label_font['size'][0] ) ) { |
|---|
| 387 | if( $css->is_variable_font_size_value( $label_font['size'][0] ) ) { |
|---|
| 388 | $css->add_property( 'font-size', $css->get_variable_font_size_value( $label_font['size'][0] ) ); |
|---|
| 389 | } else { |
|---|
| 390 | $css->add_property( 'font-size', $label_font['size'][0] . ( ! isset( $label_font['sizeType'] ) ? 'px' : $label_font['sizeType'] ) ); |
|---|
| 391 | } |
|---|
| 392 | } |
|---|
| 393 | if ( isset( $label_font['lineHeight'] ) && is_array( $label_font['lineHeight'] ) && isset( $label_font['lineHeight'][0] ) && ! empty( $label_font['lineHeight'][0] ) ) { |
|---|
| 394 | $css->add_property( 'line-height', $label_font['lineHeight'][0] . ( ! isset( $label_font['lineType'] ) ? 'px' : $label_font['lineType'] ) ); |
|---|
| 395 | } |
|---|
| 396 | if ( isset( $label_font['letterSpacing'] ) && is_array( $label_font['letterSpacing'] ) && isset( $label_font['letterSpacing'][0] ) && ! empty( $label_font['letterSpacing'][0] ) ) { |
|---|
| 397 | $css->add_property( 'letter-spacing', $label_font['letterSpacing'][0] . ( ! isset( $label_font['letterType'] ) ? 'px' : $label_font['letterType'] ) ); |
|---|
| 398 | } |
|---|
| 399 | if ( isset( $label_font['textTransform'] ) && ! empty( $label_font['textTransform'] ) ) { |
|---|
| 400 | $css->add_property( 'text-transform', $label_font['textTransform'] ); |
|---|
| 401 | } |
|---|
| 402 | if ( isset( $label_font['family'] ) && ! empty( $label_font['family'] ) ) { |
|---|
| 403 | $google = isset( $label_font['google'] ) && $label_font['google'] ? true : false; |
|---|
| 404 | $google = $google && ( isset( $label_font['loadGoogle'] ) && $label_font['loadGoogle'] || ! isset( $label_font['loadGoogle'] ) ) ? true : false; |
|---|
| 405 | $css->add_property( 'font-family', $css->render_font_family( $label_font['family'], $google, ( isset( $label_font['variant'] ) ? $label_font['variant'] : '' ), ( isset( $label_font['subset'] ) ? $label_font['subset'] : '' ) ) ); |
|---|
| 406 | } |
|---|
| 407 | if ( isset( $label_font['style'] ) && ! empty( $label_font['style'] ) ) { |
|---|
| 408 | $css->add_property( 'font-style', $label_font['style'] ); |
|---|
| 409 | } |
|---|
| 410 | if ( isset( $label_font['weight'] ) && ! empty( $label_font['weight'] ) && 'regular' !== $label_font['weight'] ) { |
|---|
| 411 | $css->add_property( 'font-weight', $label_font['weight'] ); |
|---|
| 412 | } |
|---|
| 413 | $css->set_media_state( 'tablet' ); |
|---|
| 414 | $css->set_selector( '.kb-countdown-container.kb-countdown-container-' . $unique_id . ' .kb-countdown-date-item .kb-countdown-label' ); |
|---|
| 415 | if ( isset( $label_font['size'] ) && is_array( $label_font['size'] ) && isset( $label_font['size'][1] ) && ! empty( $label_font['size'][1] ) ) { |
|---|
| 416 | if( $css->is_variable_font_size_value( $label_font['size'][1] ) ) { |
|---|
| 417 | $css->add_property( 'font-size', $css->get_variable_font_size_value( $label_font['size'][1] ) ); |
|---|
| 418 | } else { |
|---|
| 419 | $css->add_property( 'font-size', $label_font['size'][1] . ( ! isset( $label_font['sizeType'] ) ? 'px' : $label_font['sizeType'] ) ); |
|---|
| 420 | } |
|---|
| 421 | } |
|---|
| 422 | if ( isset( $label_font['lineHeight'] ) && is_array( $label_font['lineHeight'] ) && isset( $label_font['lineHeight'][1] ) && ! empty( $label_font['lineHeight'][1] ) ) { |
|---|
| 423 | $css->add_property( 'line-height', $label_font['lineHeight'][1] . ( ! isset( $label_font['lineType'] ) ? 'px' : $label_font['lineType'] ) ); |
|---|
| 424 | } |
|---|
| 425 | if ( isset( $label_font['letterSpacing'] ) && is_array( $label_font['letterSpacing'] ) && isset( $label_font['letterSpacing'][1] ) && ! empty( $label_font['letterSpacing'][1] ) ) { |
|---|
| 426 | $css->add_property( 'letter-spacing', $label_font['letterSpacing'][1] . ( ! isset( $label_font['letterType'] ) ? 'px' : $label_font['letterType'] ) ); |
|---|
| 427 | } |
|---|
| 428 | $css->set_media_state( 'desktop' ); |
|---|
| 429 | $css->set_media_state( 'mobile' ); |
|---|
| 430 | $css->set_selector( '.kb-countdown-container.kb-countdown-container-' . $unique_id . ' .kb-countdown-date-item .kb-countdown-label' ); |
|---|
| 431 | if ( isset( $label_font['size'] ) && is_array( $label_font['size'] ) && isset( $label_font['size'][2] ) && ! empty( $label_font['size'][2] ) ) { |
|---|
| 432 | if( $css->is_variable_font_size_value( $label_font['size'][2] ) ) { |
|---|
| 433 | $css->add_property( 'font-size', $css->get_variable_font_size_value( $label_font['size'][2] ) ); |
|---|
| 434 | } else { |
|---|
| 435 | $css->add_property( 'font-size', $label_font['size'][2] . ( ! isset( $label_font['sizeType'] ) ? 'px' : $label_font['sizeType'] ) ); |
|---|
| 436 | } |
|---|
| 437 | } |
|---|
| 438 | if ( isset( $label_font['lineHeight'] ) && is_array( $label_font['lineHeight'] ) && isset( $label_font['lineHeight'][2] ) && ! empty( $label_font['lineHeight'][2] ) ) { |
|---|
| 439 | $css->add_property( 'line-height', $label_font['lineHeight'][2] . ( ! isset( $label_font['lineType'] ) ? 'px' : $label_font['lineType'] ) ); |
|---|
| 440 | } |
|---|
| 441 | if ( isset( $label_font['letterSpacing'] ) && is_array( $label_font['letterSpacing'] ) && isset( $label_font['letterSpacing'][2] ) && ! empty( $label_font['letterSpacing'][2] ) ) { |
|---|
| 442 | $css->add_property( 'letter-spacing', $label_font['letterSpacing'][2] . ( ! isset( $label_font['letterType'] ) ? 'px' : $label_font['letterType'] ) ); |
|---|
| 443 | } |
|---|
| 444 | $css->set_media_state( 'desktop' ); |
|---|
| 445 | } |
|---|
| 446 | $pre_label_font = ( isset( $attributes['preLabelFont'] ) && is_array( $attributes['preLabelFont'] ) && isset( $attributes['preLabelFont'][0] ) && is_array( $attributes['preLabelFont'][0] ) ? $attributes['preLabelFont'][0] : array() ); |
|---|
| 447 | if ( ! empty( $pre_label_font ) || ( isset( $attributes['preLabelColor'] ) && ! empty( $attributes['preLabelColor'] ) ) ) { |
|---|
| 448 | $css->set_selector( '.kb-countdown-container.kb-countdown-container-' . $unique_id . ' .kb-countdown-item.kb-pre-timer' ); |
|---|
| 449 | if ( isset( $attributes['preLabelColor'] ) && ! empty( $attributes['preLabelColor'] ) ) { |
|---|
| 450 | $css->add_property( 'color', $css->render_color( $attributes['preLabelColor'] ) ); |
|---|
| 451 | } |
|---|
| 452 | if ( isset( $pre_label_font['size'] ) && is_array( $pre_label_font['size'] ) && isset( $pre_label_font['size'][0] ) && ! empty( $pre_label_font['size'][0] ) ) { |
|---|
| 453 | if( $css->is_variable_font_size_value( $pre_label_font['size'][0] ) ) { |
|---|
| 454 | $css->add_property( 'font-size', $css->get_variable_font_size_value( $pre_label_font['size'][0] ) ); |
|---|
| 455 | } else { |
|---|
| 456 | $css->add_property( 'font-size', $pre_label_font['size'][0] . ( ! isset( $pre_label_font['sizeType'] ) ? 'px' : $pre_label_font['sizeType'] ) ); |
|---|
| 457 | } |
|---|
| 458 | } |
|---|
| 459 | if ( isset( $pre_label_font['lineHeight'] ) && is_array( $pre_label_font['lineHeight'] ) && isset( $pre_label_font['lineHeight'][0] ) && ! empty( $pre_label_font['lineHeight'][0] ) ) { |
|---|
| 460 | $css->add_property( 'line-height', $pre_label_font['lineHeight'][0] . ( ! isset( $pre_label_font['lineType'] ) ? 'px' : $pre_label_font['lineType'] ) ); |
|---|
| 461 | } |
|---|
| 462 | if ( isset( $pre_label_font['letterSpacing'] ) && is_array( $pre_label_font['letterSpacing'] ) && isset( $pre_label_font['letterSpacing'][0] ) && ! empty( $pre_label_font['letterSpacing'][0] ) ) { |
|---|
| 463 | $css->add_property( 'letter-spacing', $pre_label_font['letterSpacing'][0] . ( ! isset( $pre_label_font['letterType'] ) ? 'px' : $pre_label_font['letterType'] ) ); |
|---|
| 464 | } |
|---|
| 465 | if ( isset( $pre_label_font['textTransform'] ) && ! empty( $pre_label_font['textTransform'] ) ) { |
|---|
| 466 | $css->add_property( 'text-transform', $pre_label_font['textTransform'] ); |
|---|
| 467 | } |
|---|
| 468 | if ( isset( $pre_label_font['family'] ) && ! empty( $pre_label_font['family'] ) ) { |
|---|
| 469 | $google = isset( $pre_label_font['google'] ) && $pre_label_font['google'] ? true : false; |
|---|
| 470 | $google = $google && ( isset( $pre_label_font['loadGoogle'] ) && $pre_label_font['loadGoogle'] || ! isset( $pre_label_font['loadGoogle'] ) ) ? true : false; |
|---|
| 471 | $css->add_property( 'font-family', $css->render_font_family( $pre_label_font['family'], $google, ( isset( $pre_label_font['variant'] ) ? $pre_label_font['variant'] : '' ), ( isset( $pre_label_font['subset'] ) ? $pre_label_font['subset'] : '' ) ) ); |
|---|
| 472 | } |
|---|
| 473 | if ( isset( $pre_label_font['style'] ) && ! empty( $pre_label_font['style'] ) ) { |
|---|
| 474 | $css->add_property( 'font-style', $pre_label_font['style'] ); |
|---|
| 475 | } |
|---|
| 476 | if ( isset( $pre_label_font['weight'] ) && ! empty( $pre_label_font['weight'] ) && 'regular' !== $pre_label_font['weight'] ) { |
|---|
| 477 | $css->add_property( 'font-weight', $pre_label_font['weight'] ); |
|---|
| 478 | } |
|---|
| 479 | $css->set_media_state( 'tablet' ); |
|---|
| 480 | $css->set_selector( '.kb-countdown-container.kb-countdown-container-' . $unique_id . ' .kb-countdown-item.kb-pre-timer' ); |
|---|
| 481 | if ( isset( $pre_label_font['size'] ) && is_array( $pre_label_font['size'] ) && isset( $pre_label_font['size'][1] ) && ! empty( $pre_label_font['size'][1] ) ) { |
|---|
| 482 | if( $css->is_variable_font_size_value( $pre_label_font['size'][1] ) ) { |
|---|
| 483 | $css->add_property( 'font-size', $css->get_variable_font_size_value( $pre_label_font['size'][1] ) ); |
|---|
| 484 | } else { |
|---|
| 485 | $css->add_property( 'font-size', $pre_label_font['size'][1] . ( ! isset( $pre_label_font['sizeType'] ) ? 'px' : $pre_label_font['sizeType'] ) ); |
|---|
| 486 | } |
|---|
| 487 | } |
|---|
| 488 | if ( isset( $pre_label_font['lineHeight'] ) && is_array( $pre_label_font['lineHeight'] ) && isset( $pre_label_font['lineHeight'][1] ) && ! empty( $pre_label_font['lineHeight'][1] ) ) { |
|---|
| 489 | $css->add_property( 'line-height', $pre_label_font['lineHeight'][1] . ( ! isset( $pre_label_font['lineType'] ) ? 'px' : $pre_label_font['lineType'] ) ); |
|---|
| 490 | } |
|---|
| 491 | if ( isset( $pre_label_font['letterSpacing'] ) && is_array( $pre_label_font['letterSpacing'] ) && isset( $pre_label_font['letterSpacing'][1] ) && ! empty( $pre_label_font['letterSpacing'][1] ) ) { |
|---|
| 492 | $css->add_property( 'letter-spacing', $pre_label_font['letterSpacing'][1] . ( ! isset( $pre_label_font['letterType'] ) ? 'px' : $pre_label_font['letterType'] ) ); |
|---|
| 493 | } |
|---|
| 494 | $css->set_media_state( 'desktop' ); |
|---|
| 495 | $css->set_media_state( 'mobile' ); |
|---|
| 496 | $css->set_selector( '.kb-countdown-container.kb-countdown-container-' . $unique_id . ' .kb-countdown-item.kb-pre-timer' ); |
|---|
| 497 | if ( isset( $pre_label_font['size'] ) && is_array( $pre_label_font['size'] ) && isset( $pre_label_font['size'][2] ) && ! empty( $pre_label_font['size'][2] ) ) { |
|---|
| 498 | if( $css->is_variable_font_size_value( $pre_label_font['size'][2] ) ) { |
|---|
| 499 | $css->add_property( 'font-size', $css->get_variable_font_size_value( $pre_label_font['size'][2] ) ); |
|---|
| 500 | } else { |
|---|
| 501 | $css->add_property( 'font-size', $pre_label_font['size'][2] . ( ! isset( $pre_label_font['sizeType'] ) ? 'px' : $pre_label_font['sizeType'] ) ); |
|---|
| 502 | } |
|---|
| 503 | } |
|---|
| 504 | if ( isset( $pre_label_font['lineHeight'] ) && is_array( $pre_label_font['lineHeight'] ) && isset( $pre_label_font['lineHeight'][2] ) && ! empty( $pre_label_font['lineHeight'][2] ) ) { |
|---|
| 505 | $css->add_property( 'line-height', $pre_label_font['lineHeight'][2] . ( ! isset( $pre_label_font['lineType'] ) ? 'px' : $pre_label_font['lineType'] ) ); |
|---|
| 506 | } |
|---|
| 507 | if ( isset( $pre_label_font['letterSpacing'] ) && is_array( $pre_label_font['letterSpacing'] ) && isset( $pre_label_font['letterSpacing'][2] ) && ! empty( $pre_label_font['letterSpacing'][2] ) ) { |
|---|
| 508 | $css->add_property( 'letter-spacing', $pre_label_font['letterSpacing'][2] . ( ! isset( $pre_label_font['letterType'] ) ? 'px' : $pre_label_font['letterType'] ) ); |
|---|
| 509 | } |
|---|
| 510 | $css->set_media_state( 'desktop' ); |
|---|
| 511 | } |
|---|
| 512 | $post_label_font = ( isset( $attributes['postLabelFont'] ) && is_array( $attributes['postLabelFont'] ) && isset( $attributes['postLabelFont'][0] ) && is_array( $attributes['postLabelFont'][0] ) ? $attributes['postLabelFont'][0] : array() ); |
|---|
| 513 | if ( ! empty( $post_label_font ) || ( isset( $attributes['postLabelColor'] ) && ! empty( $attributes['postLabelColor'] ) ) ) { |
|---|
| 514 | $css->set_selector( '.kb-countdown-container.kb-countdown-container-' . $unique_id . ' .kb-countdown-item.kb-post-timer' ); |
|---|
| 515 | if ( isset( $attributes['postLabelColor'] ) && ! empty( $attributes['postLabelColor'] ) ) { |
|---|
| 516 | $css->add_property( 'color', $css->render_color( $attributes['postLabelColor'] ) ); |
|---|
| 517 | } |
|---|
| 518 | if ( isset( $post_label_font['size'] ) && is_array( $post_label_font['size'] ) && isset( $post_label_font['size'][0] ) && ! empty( $post_label_font['size'][0] ) ) { |
|---|
| 519 | if( $css->is_variable_font_size_value( $post_label_font['size'][0] ) ) { |
|---|
| 520 | $css->add_property( 'font-size', $css->get_variable_font_size_value( $post_label_font['size'][0] ) ); |
|---|
| 521 | } else { |
|---|
| 522 | $css->add_property( 'font-size', $post_label_font['size'][0] . ( ! isset( $post_label_font['sizeType'] ) ? 'px' : $post_label_font['sizeType'] ) ); |
|---|
| 523 | } |
|---|
| 524 | } |
|---|
| 525 | if ( isset( $post_label_font['lineHeight'] ) && is_array( $post_label_font['lineHeight'] ) && isset( $post_label_font['lineHeight'][0] ) && ! empty( $post_label_font['lineHeight'][0] ) ) { |
|---|
| 526 | $css->add_property( 'line-height', $post_label_font['lineHeight'][0] . ( ! isset( $post_label_font['lineType'] ) ? 'px' : $post_label_font['lineType'] ) ); |
|---|
| 527 | } |
|---|
| 528 | if ( isset( $post_label_font['letterSpacing'] ) && is_array( $post_label_font['letterSpacing'] ) && isset( $post_label_font['letterSpacing'][0] ) && ! empty( $post_label_font['letterSpacing'][0] ) ) { |
|---|
| 529 | $css->add_property( 'letter-spacing', $post_label_font['letterSpacing'][0] . ( ! isset( $post_label_font['letterType'] ) ? 'px' : $post_label_font['letterType'] ) ); |
|---|
| 530 | } |
|---|
| 531 | if ( isset( $post_label_font['textTransform'] ) && ! empty( $post_label_font['textTransform'] ) ) { |
|---|
| 532 | $css->add_property( 'text-transform', $post_label_font['textTransform'] ); |
|---|
| 533 | } |
|---|
| 534 | if ( isset( $post_label_font['family'] ) && ! empty( $post_label_font['family'] ) ) { |
|---|
| 535 | $google = isset( $post_label_font['google'] ) && $post_label_font['google'] ? true : false; |
|---|
| 536 | $google = $google && ( isset( $post_label_font['loadGoogle'] ) && $post_label_font['loadGoogle'] || ! isset( $post_label_font['loadGoogle'] ) ) ? true : false; |
|---|
| 537 | $css->add_property( 'font-family', $css->render_font_family( $post_label_font['family'], $google, ( isset( $post_label_font['variant'] ) ? $post_label_font['variant'] : '' ), ( isset( $post_label_font['subset'] ) ? $post_label_font['subset'] : '' ) ) ); |
|---|
| 538 | } |
|---|
| 539 | if ( isset( $post_label_font['style'] ) && ! empty( $post_label_font['style'] ) ) { |
|---|
| 540 | $css->add_property( 'font-style', $post_label_font['style'] ); |
|---|
| 541 | } |
|---|
| 542 | if ( isset( $post_label_font['weight'] ) && ! empty( $post_label_font['weight'] ) && 'regular' !== $post_label_font['weight'] ) { |
|---|
| 543 | $css->add_property( 'font-weight', $post_label_font['weight'] ); |
|---|
| 544 | } |
|---|
| 545 | $css->set_media_state( 'tablet' ); |
|---|
| 546 | $css->set_selector( '.kb-countdown-container.kb-countdown-container-' . $unique_id . ' .kb-countdown-item.kb-post-timer' ); |
|---|
| 547 | if ( isset( $post_label_font['size'] ) && is_array( $post_label_font['size'] ) && isset( $post_label_font['size'][1] ) && ! empty( $post_label_font['size'][1] ) ) { |
|---|
| 548 | if( $css->is_variable_font_size_value( $post_label_font['size'][1] ) ) { |
|---|
| 549 | $css->add_property( 'font-size', $css->get_variable_font_size_value( $post_label_font['size'][1] ) ); |
|---|
| 550 | } else { |
|---|
| 551 | $css->add_property( 'font-size', $post_label_font['size'][1] . ( ! isset( $post_label_font['sizeType'] ) ? 'px' : $post_label_font['sizeType'] ) ); |
|---|
| 552 | } |
|---|
| 553 | } |
|---|
| 554 | if ( isset( $post_label_font['lineHeight'] ) && is_array( $post_label_font['lineHeight'] ) && isset( $post_label_font['lineHeight'][1] ) && ! empty( $post_label_font['lineHeight'][1] ) ) { |
|---|
| 555 | $css->add_property( 'line-height', $post_label_font['lineHeight'][1] . ( ! isset( $post_label_font['lineType'] ) ? 'px' : $post_label_font['lineType'] ) ); |
|---|
| 556 | } |
|---|
| 557 | if ( isset( $post_label_font['letterSpacing'] ) && is_array( $post_label_font['letterSpacing'] ) && isset( $post_label_font['letterSpacing'][1] ) && ! empty( $post_label_font['letterSpacing'][1] ) ) { |
|---|
| 558 | $css->add_property( 'letter-spacing', $post_label_font['letterSpacing'][1] . ( ! isset( $post_label_font['letterType'] ) ? 'px' : $post_label_font['letterType'] ) ); |
|---|
| 559 | } |
|---|
| 560 | $css->set_media_state( 'desktop' ); |
|---|
| 561 | $css->set_media_state( 'mobile' ); |
|---|
| 562 | $css->set_selector( '.kb-countdown-container.kb-countdown-container-' . $unique_id . ' .kb-countdown-item.kb-post-timer' ); |
|---|
| 563 | if ( isset( $post_label_font['size'] ) && is_array( $post_label_font['size'] ) && isset( $post_label_font['size'][2] ) && ! empty( $post_label_font['size'][2] ) ) { |
|---|
| 564 | if( $css->is_variable_font_size_value( $post_label_font['size'][2] ) ) { |
|---|
| 565 | $css->add_property( 'font-size', $css->get_variable_font_size_value( $post_label_font['size'][2] ) ); |
|---|
| 566 | } else { |
|---|
| 567 | $css->add_property( 'font-size', $post_label_font['size'][2] . ( ! isset( $post_label_font['sizeType'] ) ? 'px' : $post_label_font['sizeType'] ) ); |
|---|
| 568 | } |
|---|
| 569 | } |
|---|
| 570 | if ( isset( $post_label_font['lineHeight'] ) && is_array( $post_label_font['lineHeight'] ) && isset( $post_label_font['lineHeight'][2] ) && ! empty( $post_label_font['lineHeight'][2] ) ) { |
|---|
| 571 | $css->add_property( 'line-height', $post_label_font['lineHeight'][2] . ( ! isset( $post_label_font['lineType'] ) ? 'px' : $post_label_font['lineType'] ) ); |
|---|
| 572 | } |
|---|
| 573 | if ( isset( $post_label_font['letterSpacing'] ) && is_array( $post_label_font['letterSpacing'] ) && isset( $post_label_font['letterSpacing'][2] ) && ! empty( $post_label_font['letterSpacing'][2] ) ) { |
|---|
| 574 | $css->add_property( 'letter-spacing', $post_label_font['letterSpacing'][2] . ( ! isset( $post_label_font['letterType'] ) ? 'px' : $post_label_font['letterType'] ) ); |
|---|
| 575 | } |
|---|
| 576 | $css->set_media_state( 'desktop' ); |
|---|
| 577 | } |
|---|
| 578 | |
|---|
| 579 | return $css->css_output(); |
|---|
| 580 | } |
|---|
| 581 | /** |
|---|
| 582 | * Return dynamically generated HTML for block |
|---|
| 583 | * |
|---|
| 584 | * @param $attributes |
|---|
| 585 | * @param $unique_id |
|---|
| 586 | * @param $content |
|---|
| 587 | * @param WP_Block $block_instance The instance of the WP_Block class that represents the block being rendered. |
|---|
| 588 | * |
|---|
| 589 | * @return mixed |
|---|
| 590 | */ |
|---|
| 591 | public function build_html( $attributes, $unique_id, $content, $block_instance ) { |
|---|
| 592 | //$countdown should grow with each countdown that gets loaded to the page |
|---|
| 593 | static $countdown = array(); |
|---|
| 594 | $campaign_id = ( ! empty( $attributes['campaignID'] ) ? $attributes['campaignID'] : $unique_id ); |
|---|
| 595 | $countdown_type = ( ! empty( $attributes['countdownType'] ) ? $attributes['countdownType'] : 'date' ); |
|---|
| 596 | $site_slug = apply_filters( 'kadence_blocks_countdown_site_slug', sanitize_title( get_bloginfo( 'name' ) ) ); |
|---|
| 597 | $reset_days = ( isset( $attributes['evergreenReset'] ) && ! empty( $attributes['evergreenReset'] ) ? $attributes['evergreenReset'] : 30 ); |
|---|
| 598 | $countdown[ $unique_id ] = array( |
|---|
| 599 | 'timestamp' => ( isset( $attributes['timestamp'] ) ? esc_attr( $attributes['timestamp'] ) : '' ), |
|---|
| 600 | 'type' => esc_attr( $countdown_type ), |
|---|
| 601 | 'revealOnLoad' => ( isset( $attributes['revealOnLoad'] ) && $attributes['revealOnLoad'] ? true : false ), |
|---|
| 602 | 'stopWatch' => ( isset( $attributes['timeNumbers'] ) && $attributes['timeNumbers'] ? true : false ), |
|---|
| 603 | 'dividers' => ( isset( $attributes['countdownDivider'] ) && $attributes['countdownDivider'] ? true : false ), |
|---|
| 604 | 'action' => ( isset( $attributes['expireAction'] ) ? esc_attr( $attributes['expireAction'] ) : 'none' ), |
|---|
| 605 | 'redirect' => ( isset( $attributes['redirectURL'] ) ? esc_attr( $attributes['redirectURL'] ) : '' ), |
|---|
| 606 | 'repeat' => ( isset( $attributes['repeat'] ) && $attributes['repeat'] ? true : false ), |
|---|
| 607 | 'frequency' => ( isset( $attributes['frequency'] ) ? esc_attr( $attributes['frequency'] ) : '' ), |
|---|
| 608 | 'stopCount' => ( isset( $attributes['stopRepeating'] ) && $attributes['stopRepeating'] ? true : false ), |
|---|
| 609 | 'endDate' => ( isset( $attributes['endDate'] ) ? esc_attr( $attributes['endDate'] ) : '' ), |
|---|
| 610 | 'reset' => esc_attr( $reset_days ), |
|---|
| 611 | 'time_offset' => get_option( 'gmt_offset' ), |
|---|
| 612 | 'campaign_id' => esc_attr( $campaign_id ), |
|---|
| 613 | 'evergreen' => ( 'evergreen' === $countdown_type ? apply_filters( 'kadence_blocks_countdown_evergreen_config', 'query', $campaign_id, $site_slug, $reset_days ) : '' ), |
|---|
| 614 | 'strict' => ( isset( $attributes['evergreenStrict'] ) && $attributes['evergreenStrict'] ? true : false ), |
|---|
| 615 | 'hours' => ( isset( $attributes['evergreenHours'] ) ? esc_attr( $attributes['evergreenHours'] ) : '' ), |
|---|
| 616 | 'minutes' => ( isset( $attributes['evergreenMinutes'] ) ? esc_attr( $attributes['evergreenMinutes'] ) : '' ), |
|---|
| 617 | 'timer' => ( isset( $attributes['enableTimer'] ) && ! $attributes['enableTimer'] ? false : true ), |
|---|
| 618 | 'units' => array( |
|---|
| 619 | array( |
|---|
| 620 | 'days' => ( isset( $attributes['units'][0]['days'] ) && ! $attributes['units'][0]['days'] ? false : true ), |
|---|
| 621 | 'hours' => ( isset( $attributes['units'][0]['hours'] ) && ! $attributes['units'][0]['hours'] ? false : true ), |
|---|
| 622 | 'minutes' => ( isset( $attributes['units'][0]['minutes'] ) && ! $attributes['units'][0]['minutes'] ? false : true ), |
|---|
| 623 | 'seconds' => ( isset( $attributes['units'][0]['seconds'] ) && ! $attributes['units'][0]['seconds'] ? false : true ), |
|---|
| 624 | ), |
|---|
| 625 | ), |
|---|
| 626 | 'preLabel' => ( ! empty( $attributes['preLabel'] ) ? sanitize_text_field( $attributes['preLabel'] ) : '' ), |
|---|
| 627 | 'postLabel' => ( ! empty( $attributes['postLabel'] ) ? sanitize_text_field( $attributes['postLabel'] ) : '' ), |
|---|
| 628 | 'daysLabel' => ( ! empty( $attributes['daysLabel'] ) ? sanitize_text_field( $attributes['daysLabel'] ) : esc_attr__( 'Days', 'kadence-blocks' ) ), |
|---|
| 629 | 'hoursLabel' => ( ! empty( $attributes['hoursLabel'] ) ? sanitize_text_field( $attributes['hoursLabel'] ) : esc_attr__( 'Hrs', 'kadence-blocks' ) ), |
|---|
| 630 | 'minutesLabel' => ( ! empty( $attributes['minutesLabel'] ) ? sanitize_text_field( $attributes['minutesLabel'] ) : esc_attr__( 'Mins', 'kadence-blocks' ) ), |
|---|
| 631 | 'secondsLabel' => ( ! empty( $attributes['secondsLabel'] ) ? sanitize_text_field( $attributes['secondsLabel'] ) : esc_attr__( 'Secs', 'kadence-blocks' ) ), |
|---|
| 632 | ); |
|---|
| 633 | wp_localize_script( |
|---|
| 634 | 'kadence-blocks-countdown', |
|---|
| 635 | 'kadence_blocks_countdown', |
|---|
| 636 | array( |
|---|
| 637 | 'ajax_url' => admin_url( 'admin-ajax.php' ), |
|---|
| 638 | 'ajax_nonce' => wp_create_nonce( 'kadence_blocks_countdown' ), |
|---|
| 639 | 'site_slug' => apply_filters( 'kadence_blocks_countdown_site_slug', sanitize_title( get_bloginfo( 'name' ) ) ), |
|---|
| 640 | 'timers' => wp_json_encode( $countdown ), |
|---|
| 641 | ) |
|---|
| 642 | ); |
|---|
| 643 | |
|---|
| 644 | return $content; |
|---|
| 645 | } |
|---|
| 646 | |
|---|
| 647 | /** |
|---|
| 648 | * Registers scripts and styles. |
|---|
| 649 | */ |
|---|
| 650 | public function register_scripts() { |
|---|
| 651 | parent::register_scripts(); |
|---|
| 652 | // If in the backend, bail out. |
|---|
| 653 | if ( is_admin() ) { |
|---|
| 654 | return; |
|---|
| 655 | } |
|---|
| 656 | if ( apply_filters( 'kadence_blocks_check_if_rest', false ) && kadence_blocks_is_rest() ) { |
|---|
| 657 | return; |
|---|
| 658 | } |
|---|
| 659 | |
|---|
| 660 | wp_register_script( 'kadence-blocks-countdown', KADENCE_BLOCKS_URL . 'includes/assets/js/kb-countdown.min.js', array(), KADENCE_BLOCKS_VERSION, true ); |
|---|
| 661 | } |
|---|
| 662 | |
|---|
| 663 | |
|---|
| 664 | } |
|---|
| 665 | |
|---|
| 666 | Kadence_Blocks_Countdown_Block::get_instance(); |
|---|