| @@ -1,273 +1,160 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | namespace Getwid\Blocks; |
| 4 | 4 | |
| 5 | -class Countdown extends \Getwid\Blocks\AbstractBlock { | |
| 5 | +class Countdown extends AbstractBlock { | |
| 6 | 6 | |
| 7 | - protected static $blockName = 'getwid/countdown'; | |
| 7 | + public function __construct() { | |
| 8 | 8 | |
| 9 | - public function __construct() { | |
| 9 | + parent::__construct( 'getwid/countdown' ); | |
| 10 | 10 | |
| 11 | - parent::__construct( self::$blockName ); | |
| 11 | + $this->register_vendor_scripts(); | |
| 12 | 12 | |
| 13 | - //Set default date + 1 day | |
| 14 | - $current_date = new \DateTime(current_time('Y-m-d H:i:s')); | |
| 15 | - $current_date->add(new \DateInterval('P1D')); | |
| 16 | - $default_date = $current_date->format('Y-m-d H:i:s'); | |
| 13 | + add_action( 'enqueue_block_editor_assets', array( $this, 'enqueue_editor_assets' ) ); | |
| 17 | 14 | |
| 18 | - register_block_type( | |
| 19 | - 'getwid/countdown', | |
| 20 | - array( | |
| 21 | - 'attributes' => array( | |
| 22 | - 'dateTime' => array( | |
| 23 | - 'type' => 'string', | |
| 24 | - 'default' => $default_date, | |
| 25 | - ), | |
| 26 | - 'years' => array( | |
| 27 | - 'type' => 'boolean', | |
| 28 | - 'default' => false, | |
| 29 | - ), | |
| 30 | - 'months' => array( | |
| 31 | - 'type' => 'boolean', | |
| 32 | - 'default' => false, | |
| 33 | - ), | |
| 34 | - 'weeks' => array( | |
| 35 | - 'type' => 'boolean', | |
| 36 | - 'default' => false, | |
| 37 | - ), | |
| 38 | - 'days' => array( | |
| 39 | - 'type' => 'boolean', | |
| 40 | - 'default' => true, | |
| 41 | - ), | |
| 42 | - 'hours' => array( | |
| 43 | - 'type' => 'boolean', | |
| 44 | - 'default' => true, | |
| 45 | - ), | |
| 46 | - 'minutes' => array( | |
| 47 | - 'type' => 'boolean', | |
| 48 | - 'default' => true, | |
| 49 | - ), | |
| 50 | - 'seconds' => array( | |
| 51 | - 'type' => 'boolean', | |
| 52 | - 'default' => true, | |
| 53 | - ), | |
| 54 | - 'backgroundColor' => array( | |
| 55 | - 'type' => 'string', | |
| 56 | - ), | |
| 57 | - 'textColor' => array( | |
| 58 | - 'type' => 'string', | |
| 59 | - ), | |
| 60 | - 'customTextColor' => array( | |
| 61 | - 'type' => 'string', | |
| 62 | - ), | |
| 15 | + register_block_type( | |
| 16 | + getwid_get_plugin_path( 'assets/blocks/countdown' ), | |
| 17 | + array( | |
| 18 | + 'render_callback' => array( $this, 'render_callback' ), | |
| 19 | + ) | |
| 20 | + ); | |
| 21 | + } | |
| 63 | 22 | |
| 64 | - 'fontGroupID' => array( | |
| 65 | - 'type' => 'string', | |
| 66 | - 'default' => '', | |
| 67 | - ), | |
| 68 | - 'fontFamily' => array( | |
| 69 | - 'type' => 'string', | |
| 70 | - 'default' => '', | |
| 71 | - ), | |
| 72 | - 'fontSize' => array( | |
| 73 | - 'type' => 'string', | |
| 74 | - ), | |
| 75 | - 'fontSizeTablet' => array( | |
| 76 | - 'type' => 'string', | |
| 77 | - 'default' => 'fs-tablet-100', | |
| 78 | - ), | |
| 79 | - 'fontSizeMobile' => array( | |
| 80 | - 'type' => 'string', | |
| 81 | - 'default' => 'fs-mobile-100', | |
| 82 | - ), | |
| 83 | - 'fontWeight' => array( | |
| 84 | - 'type' => 'string', | |
| 85 | - ), | |
| 86 | - 'fontStyle' => array( | |
| 87 | - 'type' => 'string', | |
| 88 | - ), | |
| 89 | - 'textTransform' => array( | |
| 90 | - 'type' => 'string', | |
| 91 | - ), | |
| 92 | - 'lineHeight' => array( | |
| 93 | - 'type' => 'string', | |
| 94 | - ), | |
| 95 | - 'letterSpacing' => array( | |
| 96 | - 'type' => 'string', | |
| 97 | - ), | |
| 23 | + public function get_label() { | |
| 24 | + return __( 'Countdown', 'getwid' ); | |
| 25 | + } | |
| 98 | 26 | |
| 99 | - 'align' => array( | |
| 100 | - 'type' => 'string', | |
| 101 | - ), | |
| 102 | - 'textAlignment' => array( | |
| 103 | - 'type' => 'string', | |
| 104 | - ), | |
| 105 | - 'innerPadding' => array( | |
| 106 | - 'type' => 'string', | |
| 107 | - 'default' => 'default', | |
| 108 | - ), | |
| 109 | - 'innerSpacings' => array( | |
| 110 | - 'type' => 'string', | |
| 111 | - 'default' => 'none', | |
| 112 | - ), | |
| 27 | + private function get_default_date() { | |
| 113 | 28 | |
| 114 | - 'className' => array( | |
| 115 | - 'type' => 'string', | |
| 116 | - ), | |
| 117 | - ), | |
| 118 | - 'render_callback' => [ $this, 'render_callback' ] | |
| 119 | - ) | |
| 120 | - ); | |
| 29 | + $current_date = new \DateTime( current_time( 'Y-m-d H:i:s' ) ); | |
| 30 | + $current_date->add( new \DateInterval( 'P1D' ) ); | |
| 121 | 31 | |
| 122 | - if ( $this->isEnabled() ) { | |
| 32 | + return $current_date->format( 'Y-m-d H:i:s' ); | |
| 33 | + } | |
| 123 | 34 | |
| 124 | - add_filter( 'getwid/editor_blocks_js/dependencies', [ $this, 'block_editor_scripts'] ); | |
| 125 | 35 | |
| 126 | - //Register JS/CSS assets | |
| 127 | - wp_register_script( | |
| 128 | - 'jquery-plugin', | |
| 129 | - getwid_get_plugin_url( 'vendors/jquery.countdown/jquery.plugin.min.js' ), | |
| 130 | - [ 'jquery' ], | |
| 131 | - '1.0', | |
| 132 | - true | |
| 133 | - ); | |
| 36 | + private function get_locale_prefix() { | |
| 134 | 37 | |
| 135 | - wp_register_script( | |
| 136 | - 'jquery-countdown', | |
| 137 | - getwid_get_plugin_url( 'vendors/jquery.countdown/jquery.countdown.min.js' ), | |
| 138 | - [ 'jquery', 'jquery-plugin' ], | |
| 139 | - '2.1.0', | |
| 140 | - true | |
| 141 | - ); | |
| 38 | + preg_match( '/^(.*)_/', get_locale(), $current_locale ); | |
| 142 | 39 | |
| 143 | - preg_match( '/^(.*)_/', get_locale(), $current_locale ); | |
| 144 | - $locale_prefix = isset( $current_locale[ 1 ] ) && $current_locale[ 1 ] !='en' ? $current_locale[ 1 ] : ''; | |
| 40 | + return isset( $current_locale[1] ) && 'en' !== $current_locale[1] ? $current_locale[1] : ''; | |
| 41 | + } | |
| 145 | 42 | |
| 146 | - if ( $locale_prefix != '' ) { | |
| 147 | - $locale_path = 'vendors/jquery.countdown/localization/jquery.countdown-' . $locale_prefix . '.js'; | |
| 43 | + private function register_vendor_scripts() { | |
| 148 | 44 | |
| 149 | - if ( file_exists( getwid_get_plugin_path( $locale_path ) ) ) { | |
| 150 | - wp_register_script( | |
| 151 | - 'jquery-countdown-' . $locale_prefix, | |
| 152 | - getwid_get_plugin_url( $locale_path ), | |
| 153 | - [ 'jquery-countdown' ], | |
| 154 | - '2.1.0', | |
| 155 | - true | |
| 156 | - ); | |
| 157 | - } | |
| 45 | + wp_register_script( | |
| 46 | + 'jquery-plugin', | |
| 47 | + getwid_get_plugin_url( 'vendors/jquery.countdown/jquery.plugin.min.js' ), | |
| 48 | + array( 'jquery' ), | |
| 49 | + '1.0', | |
| 50 | + true | |
| 51 | + ); | |
| 52 | + | |
| 53 | + wp_register_script( | |
| 54 | + 'jquery-countdown', | |
| 55 | + getwid_get_plugin_url( 'vendors/jquery.countdown/jquery.countdown.min.js' ), | |
| 56 | + array( 'jquery', 'jquery-plugin' ), | |
| 57 | + '2.1.0', | |
| 58 | + true | |
| 59 | + ); | |
| 60 | + | |
| 61 | + $locale_prefix = $this->get_locale_prefix(); | |
| 62 | + | |
| 63 | + if ( '' !== $locale_prefix ) { | |
| 64 | + $locale_path = 'vendors/jquery.countdown/localization/jquery.countdown-' . $locale_prefix . '.js'; | |
| 65 | + | |
| 66 | + if ( file_exists( getwid_get_plugin_path( $locale_path ) ) ) { | |
| 67 | + wp_register_script( | |
| 68 | + 'jquery-countdown-' . $locale_prefix, | |
| 69 | + getwid_get_plugin_url( $locale_path ), | |
| 70 | + array( 'jquery-countdown' ), | |
| 71 | + '2.1.0', | |
| 72 | + true | |
| 73 | + ); | |
| 158 | 74 | } |
| 159 | 75 | } |
| 160 | - } | |
| 76 | + } | |
| 161 | 77 | |
| 162 | - public function getLabel() { | |
| 163 | - return __('Countdown', 'getwid'); | |
| 164 | - } | |
| 78 | + public function enqueue_editor_assets() { | |
| 165 | 79 | |
| 166 | - public function block_editor_scripts($scripts) { | |
| 80 | + wp_enqueue_script( 'jquery-countdown' ); | |
| 167 | 81 | |
| 168 | - preg_match( '/^(.*)_/', get_locale(), $current_locale ); | |
| 169 | - $locale_prefix = isset( $current_locale[ 1 ] ) && $current_locale[ 1 ] !='en' ? $current_locale[ 1 ] : ''; | |
| 82 | + $locale_prefix = $this->get_locale_prefix(); | |
| 170 | 83 | |
| 171 | - if ( $locale_prefix != '' ) { | |
| 84 | + if ( '' !== $locale_prefix ) { | |
| 172 | 85 | $locale_path = 'vendors/jquery.countdown/localization/jquery.countdown-' . $locale_prefix . '.js'; |
| 173 | 86 | |
| 174 | 87 | if ( file_exists( getwid_get_plugin_path( $locale_path ) ) ) { |
| 175 | - wp_enqueue_script('jquery-countdown-' . $locale_prefix); | |
| 88 | + wp_enqueue_script( 'jquery-countdown-' . $locale_prefix ); | |
| 176 | 89 | } |
| 177 | 90 | } |
| 91 | + } | |
| 178 | 92 | |
| 179 | - //jquery.countdown.min.js | |
| 180 | - if ( ! in_array( 'jquery-countdown', $scripts ) ) { | |
| 181 | - array_push( $scripts, 'jquery-countdown' ); | |
| 182 | - } | |
| 93 | + public function block_frontend_assets() { | |
| 183 | 94 | |
| 184 | - return $scripts; | |
| 185 | - } | |
| 186 | - | |
| 187 | - public function block_frontend_assets() { | |
| 188 | - | |
| 189 | 95 | if ( is_admin() ) { |
| 190 | 96 | return; |
| 191 | 97 | } |
| 192 | 98 | |
| 193 | - //jquery.countdown.min.js | |
| 194 | - if ( ! wp_script_is( 'jquery-countdown', 'enqueued' ) ) { | |
| 195 | - wp_enqueue_script('jquery-countdown'); | |
| 196 | - } | |
| 99 | + wp_enqueue_script( 'jquery-countdown' ); | |
| 197 | 100 | |
| 198 | - preg_match( '/^(.*)_/', get_locale(), $current_locale ); | |
| 199 | - $locale_prefix = isset( $current_locale[ 1 ] ) && $current_locale[ 1 ] !='en' ? $current_locale[ 1 ] : ''; | |
| 101 | + $locale_prefix = $this->get_locale_prefix(); | |
| 200 | 102 | |
| 201 | - if ( $locale_prefix != '' ) { | |
| 103 | + if ( '' !== $locale_prefix ) { | |
| 202 | 104 | $locale_path = 'vendors/jquery.countdown/localization/jquery.countdown-' . $locale_prefix . '.js'; |
| 203 | 105 | |
| 204 | 106 | if ( file_exists( getwid_get_plugin_path( $locale_path ) ) ) { |
| 205 | - wp_enqueue_script('jquery-countdown-' . $locale_prefix); | |
| 107 | + wp_enqueue_script( 'jquery-countdown-' . $locale_prefix ); | |
| 206 | 108 | } |
| 207 | 109 | } |
| 110 | + } | |
| 208 | 111 | |
| 209 | - if ( FALSE == getwid()->assetsOptimization()->load_assets_on_demand() ) { | |
| 210 | - return; | |
| 211 | - } | |
| 112 | + public function render_callback( $attributes, $content ) { | |
| 212 | 113 | |
| 213 | - add_filter( 'getwid/optimize/assets', | |
| 214 | - function ( $assets ) { | |
| 215 | - $assets[] = getwid()->settings()->getPrefix() . '-blocks-common'; | |
| 216 | - | |
| 217 | - return $assets; | |
| 218 | - } | |
| 114 | + $attributes = wp_parse_args( | |
| 115 | + $attributes, | |
| 116 | + array( | |
| 117 | + 'dateTime' => $this->get_default_date(), | |
| 118 | + 'years' => false, | |
| 119 | + 'months' => false, | |
| 120 | + 'weeks' => false, | |
| 121 | + 'days' => true, | |
| 122 | + 'hours' => true, | |
| 123 | + 'minutes' => true, | |
| 124 | + 'seconds' => true, | |
| 125 | + 'fontGroupID' => '', | |
| 126 | + 'fontFamily' => '', | |
| 127 | + 'fontSizeTablet' => 'fs-tablet-100', | |
| 128 | + 'fontSizeMobile' => 'fs-mobile-100', | |
| 129 | + 'innerPadding' => 'default', | |
| 130 | + 'innerSpacings' => 'none', | |
| 131 | + ) | |
| 219 | 132 | ); |
| 220 | 133 | |
| 221 | - add_filter( 'getwid/optimize/should_load_common_css', '__return_true' ); | |
| 222 | - | |
| 223 | - $rtl = is_rtl() ? '.rtl' : ''; | |
| 224 | - | |
| 225 | - wp_enqueue_style( | |
| 226 | - self::$blockName, | |
| 227 | - getwid_get_plugin_url( 'assets/blocks/countdown/style' . $rtl . '.css' ), | |
| 228 | - [], | |
| 229 | - getwid()->settings()->getVersion() | |
| 230 | - ); | |
| 231 | - | |
| 232 | - wp_enqueue_script( | |
| 233 | - self::$blockName, | |
| 234 | - getwid_get_plugin_url( 'assets/blocks/countdown/frontend.js' ), | |
| 235 | - [ 'jquery', 'jquery-countdown' ], | |
| 236 | - getwid()->settings()->getVersion(), | |
| 237 | - true | |
| 238 | - ); | |
| 239 | - | |
| 240 | - } | |
| 241 | - | |
| 242 | - public function render_callback( $attributes, $content ) { | |
| 243 | - | |
| 244 | - if ( isset( $attributes['fontWeight'] ) && | |
| 245 | - ( $attributes['fontWeight'] == 'regular' || $attributes['fontWeight'] == 'normal') ) { | |
| 246 | - | |
| 134 | + if ( | |
| 135 | + isset( $attributes['fontWeight'] ) && | |
| 136 | + ( 'regular' === $attributes['fontWeight'] || 'normal' === $attributes['fontWeight'] ) | |
| 137 | + ) { | |
| 247 | 138 | $attributes['fontWeight'] = '400'; |
| 248 | 139 | } |
| 249 | 140 | |
| 250 | - $should_load_gf = $this->shouldLoadGoogleFont( $attributes ); | |
| 141 | + if ( $this->should_load_google_font( $attributes ) ) { | |
| 142 | + $font_family = $attributes['fontFamily']; | |
| 143 | + $font_family_handle = strtolower( preg_replace( '/\s+/', '_', $font_family ) ); | |
| 144 | + $font_weight = ''; | |
| 145 | + $font_weight_handle = ''; | |
| 146 | + $font_weight_part = ''; | |
| 251 | 147 | |
| 252 | - if ( $should_load_gf ) { | |
| 253 | - | |
| 254 | - $fontFamily = $attributes['fontFamily']; | |
| 255 | - | |
| 256 | - $fontFamilyHandle = strtolower( preg_replace( '/\s+/', '_', $fontFamily ) ); | |
| 257 | - | |
| 258 | - $fontWeight = ''; | |
| 259 | - $fontWeightHandle = ''; | |
| 260 | - $fontWeightPart = ''; | |
| 261 | - if ( isset( $attributes['fontWeight'] ) && $attributes['fontWeight'] != '400' ) { | |
| 262 | - $fontWeight = $attributes['fontWeight']; | |
| 263 | - $fontWeightHandle = '_' . $fontWeight; | |
| 264 | - $fontWeightPart = ':' . $fontWeight; | |
| 148 | + if ( isset( $attributes['fontWeight'] ) && '400' !== $attributes['fontWeight'] ) { | |
| 149 | + $font_weight = $attributes['fontWeight']; | |
| 150 | + $font_weight_handle = '_' . $font_weight; | |
| 151 | + $font_weight_part = ':' . $font_weight; | |
| 265 | 152 | } |
| 266 | 153 | |
| 267 | 154 | wp_enqueue_style( |
| 268 | - 'google-font-' . esc_attr( $fontFamilyHandle ) . esc_attr( $fontWeightHandle ), | |
| 269 | - 'https://fonts.googleapis.com/css?family=' . esc_attr( $fontFamily ) . esc_attr( $fontWeightPart ), | |
| 155 | + 'google-font-' . esc_attr( $font_family_handle ) . esc_attr( $font_weight_handle ), | |
| 156 | + 'https://fonts.googleapis.com/css?family=' . esc_attr( $font_family ) . esc_attr( $font_weight_part ), | |
| 270 | 157 | null, |
| 271 | 158 | 'all' |
| 272 | 159 | ); |
| 273 | 160 | } |
| @@ -274,9 +161,8 @@ | ||
| 274 | 161 | |
| 275 | 162 | $block_name = 'wp-block-getwid-countdown'; |
| 276 | 163 | $class = $block_name; |
| 277 | 164 | |
| 278 | - //Classes | |
| 279 | 165 | if ( isset( $attributes['className'] ) ) { |
| 280 | 166 | $class .= ' ' . $attributes['className']; |
| 281 | 167 | } |
| 282 | 168 | if ( isset( $attributes['align'] ) ) { |
| @@ -284,13 +170,12 @@ | ||
| 284 | 170 | } |
| 285 | 171 | if ( isset( $attributes['textAlignment'] ) ) { |
| 286 | 172 | $class .= ' has-horizontal-alignment-' . $attributes['textAlignment']; |
| 287 | 173 | } |
| 288 | - | |
| 289 | - if ( isset( $attributes['innerPadding'] ) && $attributes['innerPadding'] != 'default' ) { | |
| 174 | + if ( isset( $attributes['innerPadding'] ) && 'default' !== $attributes['innerPadding'] ) { | |
| 290 | 175 | $class .= ' has-inner-paddings-' . $attributes['innerPadding']; |
| 291 | 176 | } |
| 292 | - if ( isset( $attributes['innerSpacings'] ) && $attributes['innerSpacings'] != 'none' ) { | |
| 177 | + if ( isset( $attributes['innerSpacings'] ) && 'none' !== $attributes['innerSpacings'] ) { | |
| 293 | 178 | $class .= ' has-spacing-' . $attributes['innerSpacings']; |
| 294 | 179 | } |
| 295 | 180 | |
| 296 | 181 | $wrapper_class = $block_name . '__content'; |
| @@ -295,25 +180,24 @@ | ||
| 295 | 180 | |
| 296 | 181 | $wrapper_class = $block_name . '__content'; |
| 297 | 182 | $content_class = $block_name . '__wrapper'; |
| 298 | 183 | |
| 299 | - if ( isset( $attributes['fontSizeTablet'] ) && $attributes['fontSizeTablet'] != 'fs-tablet-100' ) { | |
| 184 | + if ( isset( $attributes['fontSizeTablet'] ) && 'fs-tablet-100' !== $attributes['fontSizeTablet'] ) { | |
| 300 | 185 | $content_class .= ' ' . $attributes['fontSizeTablet']; |
| 301 | 186 | } |
| 302 | - if ( isset( $attributes['fontSizeMobile'] ) && $attributes['fontSizeMobile'] != 'fs-mobile-100' ) { | |
| 187 | + if ( isset( $attributes['fontSizeMobile'] ) && 'fs-mobile-100' !== $attributes['fontSizeMobile'] ) { | |
| 303 | 188 | $content_class .= ' ' . $attributes['fontSizeMobile']; |
| 304 | 189 | } |
| 305 | - if ( isset( $attributes['fontSize'] ) && $attributes['fontSize'] != '' ) { | |
| 190 | + if ( isset( $attributes['fontSize'] ) && '' !== $attributes['fontSize'] ) { | |
| 306 | 191 | $content_class .= ' has-custom-font-size'; |
| 307 | 192 | } |
| 308 | 193 | |
| 309 | 194 | $content_style = ''; |
| 310 | - //Style | |
| 195 | + | |
| 311 | 196 | if ( isset( $attributes['fontSize'] ) ) { |
| 312 | 197 | $content_style .= 'font-size: ' . $attributes['fontSize'] . ';'; |
| 313 | 198 | } |
| 314 | - | |
| 315 | - if ( isset( $attributes['fontFamily'] ) && $attributes['fontFamily'] != '' ) { | |
| 199 | + if ( isset( $attributes['fontFamily'] ) && '' !== $attributes['fontFamily'] ) { | |
| 316 | 200 | $content_style .= 'font-family: ' . $attributes['fontFamily'] . ';'; |
| 317 | 201 | } |
| 318 | 202 | if ( isset( $attributes['fontWeight'] ) ) { |
| 319 | 203 | $content_style .= 'font-weight: ' . $attributes['fontWeight'] . ';'; |
| @@ -320,9 +204,9 @@ | ||
| 320 | 204 | } |
| 321 | 205 | if ( isset( $attributes['fontStyle'] ) ) { |
| 322 | 206 | $content_style .= 'font-style: ' . $attributes['fontStyle'] . ';'; |
| 323 | 207 | } |
| 324 | - if ( isset( $attributes['textTransform'] ) && $attributes['textTransform'] != 'default' ) { | |
| 208 | + if ( isset( $attributes['textTransform'] ) && 'default' !== $attributes['textTransform'] ) { | |
| 325 | 209 | $content_style .= 'text-transform: ' . $attributes['textTransform'] . ';'; |
| 326 | 210 | } |
| 327 | 211 | if ( isset( $attributes['lineHeight'] ) ) { |
| 328 | 212 | $content_style .= 'line-height: ' . $attributes['lineHeight'] . ';'; |
| @@ -330,13 +214,16 @@ | ||
| 330 | 214 | if ( isset( $attributes['letterSpacing'] ) ) { |
| 331 | 215 | $content_style .= 'letter-spacing: ' . $attributes['letterSpacing'] . ';'; |
| 332 | 216 | } |
| 333 | 217 | |
| 334 | - $is_back_end = getwid_is_block_editor(); | |
| 218 | + getwid_custom_color_style_and_class( | |
| 219 | + $content_style, | |
| 220 | + $content_class, | |
| 221 | + $attributes, | |
| 222 | + 'color', | |
| 223 | + getwid_is_block_editor() | |
| 224 | + ); | |
| 335 | 225 | |
| 336 | - //Color style & class | |
| 337 | - getwid_custom_color_style_and_class( $content_style, $content_class, $attributes, 'color', $is_back_end ); | |
| 338 | - | |
| 339 | 226 | try { |
| 340 | 227 | $target_date = new \DateTime( $attributes['dateTime'] ); |
| 341 | 228 | } catch ( \Exception $e ) { |
| 342 | 229 | return esc_html__( 'Invalid date.', 'getwid' ); |
| @@ -341,25 +228,25 @@ | ||
| 341 | 228 | } catch ( \Exception $e ) { |
| 342 | 229 | return esc_html__( 'Invalid date.', 'getwid' ); |
| 343 | 230 | } |
| 344 | 231 | |
| 345 | - $current_date = new \DateTime(current_time('Y-m-d H:i:s')); //Server time | |
| 232 | + $current_date = new \DateTime( current_time( 'Y-m-d H:i:s' ) ); | |
| 346 | 233 | |
| 347 | 234 | if ( $current_date < $target_date ) { |
| 348 | - $dateTime_until = $current_date->diff( $target_date )->format( "+%yy +%mo +%dd +%hh +%im +%ss" ); | |
| 235 | + $date_time_until = $current_date->diff( $target_date )->format( '+%yy +%mo +%dd +%hh +%im +%ss' ); | |
| 349 | 236 | } else { |
| 350 | - $dateTime_until = 'negative'; | |
| 237 | + $date_time_until = 'negative'; | |
| 351 | 238 | } |
| 352 | 239 | |
| 353 | 240 | $countdown_options = array( |
| 354 | - ( ! empty( $attributes['backgroundColor'] ) ? 'data-bg-color="' . esc_attr( $attributes['backgroundColor'] ) . '"' : '' ), | |
| 355 | - ( ! empty( $attributes['years'] ) ? 'data-years="' . esc_attr( $attributes['years'] ) . '"' : '' ), | |
| 356 | - ( ! empty( $attributes['months'] ) ? 'data-months="' . esc_attr( $attributes['months'] ) . '"' : '' ), | |
| 357 | - ( ! empty( $attributes['weeks'] ) ? 'data-weeks="' . esc_attr( $attributes['weeks'] ) . '"' : '' ), | |
| 358 | - ( ! empty( $attributes['days'] ) ? 'data-days="' . esc_attr( $attributes['days'] ) . '"' : '' ), | |
| 359 | - ( ! empty( $attributes['hours'] ) ? 'data-hours="' . esc_attr( $attributes['hours'] ) . '"' : '' ), | |
| 360 | - ( ! empty( $attributes['minutes'] ) ? 'data-minutes="' . esc_attr( $attributes['minutes'] ) . '"' : '' ), | |
| 361 | - ( ! empty( $attributes['seconds'] ) ? 'data-seconds="' . esc_attr( $attributes['seconds'] ) . '"' : '' ), | |
| 241 | + ! empty( $attributes['backgroundColor'] ) ? 'data-bg-color="' . esc_attr( $attributes['backgroundColor'] ) . '"' : '', | |
| 242 | + ! empty( $attributes['years'] ) ? 'data-years="' . esc_attr( $attributes['years'] ) . '"' : '', | |
| 243 | + ! empty( $attributes['months'] ) ? 'data-months="' . esc_attr( $attributes['months'] ) . '"' : '', | |
| 244 | + ! empty( $attributes['weeks'] ) ? 'data-weeks="' . esc_attr( $attributes['weeks'] ) . '"' : '', | |
| 245 | + ! empty( $attributes['days'] ) ? 'data-days="' . esc_attr( $attributes['days'] ) . '"' : '', | |
| 246 | + ! empty( $attributes['hours'] ) ? 'data-hours="' . esc_attr( $attributes['hours'] ) . '"' : '', | |
| 247 | + ! empty( $attributes['minutes'] ) ? 'data-minutes="' . esc_attr( $attributes['minutes'] ) . '"' : '', | |
| 248 | + ! empty( $attributes['seconds'] ) ? 'data-seconds="' . esc_attr( $attributes['seconds'] ) . '"' : '', | |
| 362 | 249 | ); |
| 363 | 250 | |
| 364 | 251 | $countdown_options_str = implode( ' ', $countdown_options ); |
| 365 | 252 | |
| @@ -364,17 +251,19 @@ | ||
| 364 | 251 | $countdown_options_str = implode( ' ', $countdown_options ); |
| 365 | 252 | |
| 366 | 253 | ob_start(); |
| 367 | 254 | ?> |
| 368 | - | |
| 369 | 255 | <div class="<?php echo esc_attr( $class ); ?>"> |
| 370 | - <div class="<?php echo esc_attr( $content_class ); ?>" <?php if ( ! empty( $content_style ) ) { ?> style="<?php echo esc_attr( $content_style ); ?>"<?php } ?>> | |
| 256 | + <div class="<?php echo esc_attr( $content_class ); ?>" | |
| 257 | + <?php | |
| 258 | + if ( ! empty( $content_style ) ) { | |
| 259 | + ?> | |
| 260 | + style="<?php echo esc_attr( $content_style ); ?>"<?php } ?>> | |
| 371 | 261 | <div class="<?php echo esc_attr( $wrapper_class ); ?>" |
| 372 | - data-datetime="<?php echo esc_attr( !empty( $dateTime_until ) ? $dateTime_until : '' ); ?>" <?php echo $countdown_options_str; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>> | |
| 262 | + data-datetime="<?php echo esc_attr( ! empty( $date_time_until ) ? $date_time_until : '' ); ?>" <?php echo $countdown_options_str; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>> | |
| 373 | 263 | </div> |
| 374 | 264 | </div> |
| 375 | 265 | </div> |
| 376 | - | |
| 377 | 266 | <?php |
| 378 | 267 | $result = ob_get_clean(); |
| 379 | 268 | |
| 380 | 269 | $this->block_frontend_assets(); |
| @@ -379,21 +268,23 @@ | ||
| 379 | 268 | |
| 380 | 269 | $this->block_frontend_assets(); |
| 381 | 270 | |
| 382 | 271 | return $result; |
| 383 | - } | |
| 272 | + } | |
| 384 | 273 | |
| 385 | - private function shouldLoadGoogleFont( $attributes ) { | |
| 274 | + private function should_load_google_font( $attributes ) { | |
| 275 | + | |
| 386 | 276 | $should_load = false; |
| 387 | 277 | |
| 388 | - // if fontFamily set maybe GF should be loaded | |
| 389 | - if ( isset( $attributes['fontFamily'] ) && !empty( $attributes['fontFamily'] ) ) { | |
| 278 | + if ( isset( $attributes['fontFamily'] ) && ! empty( $attributes['fontFamily'] ) ) { | |
| 390 | 279 | $should_load = true; |
| 391 | 280 | } |
| 392 | 281 | |
| 393 | - // if fontFamily isset (condition above) check fontGroupID | |
| 394 | - // if fontGroupID isset but not equal to 'google-fonts' or ''(for old plugin versions) it shouldn't be loaded | |
| 395 | - if ( $should_load && isset( $attributes['fontGroupID'] ) && !in_array( $attributes['fontGroupID'], ['', 'google-fonts'] ) ) { | |
| 282 | + if ( | |
| 283 | + $should_load && | |
| 284 | + isset( $attributes['fontGroupID'] ) && | |
| 285 | + ! in_array( $attributes['fontGroupID'], array( '', 'google-fonts' ), true ) | |
| 286 | + ) { | |
| 396 | 287 | $should_load = false; |
| 397 | 288 | } |
| 398 | 289 | |
| 399 | 290 | return $should_load; |
| @@ -400,6 +291,6 @@ | ||
| 400 | 291 | } |
| 401 | 292 | } |
| 402 | 293 | |
| 403 | 294 | getwid()->blocksManager()->addBlock( |
| 404 | - new \Getwid\Blocks\Countdown() | |
| 295 | + new Countdown() | |
| 405 | 296 | ); |