PluginProbe
Countdown Timer Block – build urgency for events and launches / 1.2.8
Countdown Timer Block – build urgency for events and launches v1.2.8
1.3.3 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 All 32 releases
← All changes | plugin.php +114 -110 1.0.81.2.8 View file →
@@ -1,130 +1,134 @@
1 1 <?php
2 +
2 3 /**
3 - * Plugin Name: Countdown Time
4 + * Plugin Name: Countdown Timer - Block
4 5 * Description: Display your events date into a timer to your visitor with countdown time block
5 - * Version: 1.0.8
6 - * Author: bPlugins LLC
7 - * Author URI: http://bplugins.com
6 + * Version: 1.2.8
7 + * Author: bPlugins
8 + * Author URI: https://bplugins.com
8 9 * License: GPLv3
9 10 * License URI: https://www.gnu.org/licenses/gpl-3.0.txt
10 11 * Text Domain: countdown-time
11 12 */
12 -
13 13 // ABS PATH
14 -if ( !defined( 'ABSPATH' ) ) { exit; }
15 -
16 -// Constant
17 -define( 'CTB_PLUGIN_VERSION', 'localhost' === $_SERVER['HTTP_HOST'] ? time() : '1.0.8' );
18 -define( 'CTB_ASSETS_DIR', plugin_dir_url( __FILE__ ) . 'assets/' );
19 -
20 -// Generate Styles
21 -class CTBStyleGenerator {
22 - public static $styles = [];
23 - public static function addStyle( $selector, $styles ){
24 - if( array_key_exists( $selector, self::$styles ) ){
25 - self::$styles[$selector] = wp_parse_args( self::$styles[$selector], $styles );
26 - }else { self::$styles[$selector] = $styles; }
27 - }
28 - public static function renderStyle(){
29 - $output = '';
30 - foreach( self::$styles as $selector => $style ){
31 - $new = '';
32 - foreach( $style as $property => $value ){
33 - if( $value == '' ){ $new .= $property; }else { $new .= " $property: $value;"; }
14 +if ( !defined( 'ABSPATH' ) ) {
15 + exit;
16 +}
17 +if ( function_exists( 'ctb_fs' ) ) {
18 + register_activation_hook( __FILE__, function () {
19 + if ( is_plugin_active( 'countdown-time/plugin.php' ) ) {
20 + deactivate_plugins( 'countdown-time/plugin.php' );
21 + }
22 + if ( is_plugin_active( 'countdown-time-pro/plugin.php' ) ) {
23 + deactivate_plugins( 'countdown-time-pro/plugin.php' );
24 + }
25 + } );
26 +} else {
27 + define( 'CTB_VERSION', ( isset( $_SERVER['HTTP_HOST'] ) && 'localhost' === $_SERVER['HTTP_HOST'] ? time() : '1.2.8' ) );
28 + define( 'CTB_DIR_URL', plugin_dir_url( __FILE__ ) );
29 + define( 'CTB_DIR_PATH', plugin_dir_path( __FILE__ ) );
30 + define( 'CTB_HAS_FREE', 'countdown-time/plugin.php' === plugin_basename( __FILE__ ) );
31 + define( 'CTB_HAS_PRO', 'countdown-time-pro/plugin.php' === plugin_basename( __FILE__ ) );
32 + if ( !function_exists( 'ctb_fs' ) ) {
33 + function ctb_fs() {
34 + global $ctb_fs;
35 + if ( !isset( $ctb_fs ) ) {
36 + $fsStartPath = dirname( __FILE__ ) . '/freemius/start.php';
37 + $bSDKInitPath = dirname( __FILE__ ) . '/bplugins_sdk/init.php';
38 + if ( CTB_HAS_PRO && file_exists( $fsStartPath ) ) {
39 + require_once $fsStartPath;
40 + } else {
41 + if ( CTB_HAS_FREE && file_exists( $bSDKInitPath ) ) {
42 + require_once $bSDKInitPath;
43 + }
44 + }
45 + $ctbConfig = [
46 + 'id' => '14562',
47 + 'slug' => 'countdown-time',
48 + 'premium_slug' => 'countdown-time-pro',
49 + 'type' => 'plugin',
50 + 'public_key' => 'pk_7f62446a2a53154c56c36346db2fa',
51 + 'is_premium' => false,
52 + 'premium_suffix' => 'Pro',
53 + 'has_premium_version' => true,
54 + 'has_addons' => false,
55 + 'has_paid_plans' => true,
56 + 'trial' => [
57 + 'days' => 7,
58 + 'is_require_payment' => true,
59 + ],
60 + 'menu' => [
61 + 'slug' => 'edit.php?post_type=ctb',
62 + 'contact' => false,
63 + 'support' => false,
64 + ],
65 + ];
66 + $ctb_fs = ( CTB_HAS_PRO && file_exists( $fsStartPath ) ? fs_dynamic_init( $ctbConfig ) : fs_lite_dynamic_init( $ctbConfig ) );
34 67 }
35 - $output .= "$selector { $new }";
68 + return $ctb_fs;
36 69 }
37 - return $output;
38 - }
39 -}
40 70
41 -// Countdown Time
42 -class CTBCountdownTimeBlock{
43 - function __construct(){
44 - add_action( 'init', [$this, 'onInit'] );
71 + ctb_fs();
72 + do_action( 'ctb_fs_loaded' );
45 73 }
46 -
47 - function onInit() {
48 - wp_register_style( 'ctb-countdown-time-editor-style', plugins_url( 'dist/editor.css', __FILE__ ), [ 'wp-edit-blocks' ], CTB_PLUGIN_VERSION ); // Backend Style
49 - wp_register_style( 'ctb-countdown-time-style', plugins_url( 'dist/style.css', __FILE__ ), [ 'wp-editor' ], CTB_PLUGIN_VERSION ); // Frontend Style
50 -
51 - register_block_type( __DIR__, [
52 - 'editor_style' => 'ctb-countdown-time-editor-style',
53 - 'style' => 'ctb-countdown-time-style',
54 - 'render_callback' => [$this, 'render']
55 - ] ); // Register Block
56 -
57 - wp_set_script_translations( 'ctb-countdown-time-editor-script', 'countdown-time', plugin_dir_path( __FILE__ ) . 'languages' ); // Translate
74 + function ctbIsPremium() {
75 + return ( CTB_HAS_PRO ? ctb_fs()->can_use_premium_code() : false );
58 76 }
59 77
60 - function render( $attributes ){
61 - extract( $attributes );
78 + require_once CTB_DIR_PATH . '/includes/pattern.php';
79 + require_once CTB_DIR_PATH . '/includes/CustomPost.php';
80 + require_once CTB_DIR_PATH . '/includes/HelpPage.php';
81 + // if( CTB_HAS_FREE ){
82 + // require_once CTB_DIR_PATH . '/includes/UpgradePage.php';
83 + // }
84 + class CTBPlugin {
85 + function __construct() {
86 + add_action( 'init', [$this, 'onInit'] );
87 + add_action( 'wp_ajax_ctbPipeChecker', [$this, 'ctbPipeChecker'] );
88 + add_action( 'wp_ajax_nopriv_ctbPipeChecker', [$this, 'ctbPipeChecker'] );
89 + add_action( 'admin_init', [$this, 'registerSettings'] );
90 + add_action( 'rest_api_init', [$this, 'registerSettings'] );
91 + add_filter( 'block_categories_all', [$this, 'blockCategories'] );
92 + }
62 93
63 - $countdownStyle = new CTBStyleGenerator(); // Generate Styles
64 - $countdownStyle::addStyle( "#ctbCountdownTime-$cId", [
65 - 'align-items' => $alignment,
66 - 'justify-content' => $alignment
67 - ] );
68 - $countdownStyle::addStyle( "#ctbCountdownTime-$cId .countdownItems", [
69 - 'width' => '0px' === $width || '0%' === $width || '0em' === $width ? 'auto' : $width,
70 - $background['styles'] ?? 'background-color: #0000;' => '',
71 - 'padding' => $padding['styles'] ?? '10px 15px',
72 - 'box-shadow' => $shadow['styles'] ?? 'none',
73 - 'justify-content' => $boxPosition
74 - ] );
75 - $countdownStyle::addStyle( "#ctbCountdownTime-$cId .countdownItems .countdownItem", [
76 - $boxBG['styles'] ?? 'background-image: linear-gradient(135deg, #4527a4, #8344c5);' => '',
77 - 'width' => $boxWidth,
78 - 'height' => $boxHeight,
79 - 'margin-left' => "calc( $boxSpace / 2 )",
80 - 'margin-right' => "calc( $boxSpace / 2 )",
81 - $boxBorder['styles'] ?? 'border-radius: 5%;' => '',
82 - 'box-shadow' => $boxShadow['styles'] ?? '0 0 0 0 #0000'
83 - ] );
84 - $countdownStyle::addStyle( "#ctbCountdownTime-$cId .countdownItems .separator::before", [
85 - 'content' => "'$sepType'",
86 - 'font-size' => $sepSize . 'px',
87 - 'color' => $sepColor
88 - ] );
89 - $countdownStyle::addStyle( "#ctbCountdownTime-$cId .countdownItems .countdownItem .digit", [
90 - 'color' => $digitColor,
91 - $digitTypo['styles'] ?? 'font-size: 48px;' => ''
92 - ] );
93 - $countdownStyle::addStyle( "#ctbCountdownTime-$cId .countdownItems .countdownItem .label", [
94 - 'color' => $labelColor,
95 - $labelTypo['styles'] ?? 'font-size: 18px;' => ''
96 - ] );
94 + function onInit() {
95 + register_block_type( __DIR__ . '/build' );
96 + }
97 97
98 - $boxClass = $boxIsInline ? 'inline' : '';
98 + function ctbPipeChecker() {
99 + $nonce = $_POST['_wpnonce'] ?? null;
100 + if ( !wp_verify_nonce( $nonce, 'wp_ajax' ) ) {
101 + wp_send_json_error( 'Invalid Request' );
102 + }
103 + wp_send_json_success( [
104 + 'isPipe' => ctbIsPremium(),
105 + ] );
106 + }
99 107
100 - ob_start(); ?>
101 - <div class='wp-block-ctb-countdown-time <?php echo 'align' . esc_attr( $align ); ?>' id='ctbCountdownTime-<?php echo esc_attr( $cId ) ?>' data-date="<?php echo esc_attr( wp_json_encode( [ 'destDate' => $destDate ] ) ); ?>">
102 - <style>@import url( <?php echo esc_url( $digitTypo['googleFontLink'] ?? '' ); ?> ); @import url( <?php echo esc_url( $labelTypo['googleFontLink'] ?? '' ); ?> ); <?php echo wp_kses( $countdownStyle::renderStyle(), [] ); ?>
103 - @media screen and ( max-width: 575px ) { #ctbCountdownTime-<?php echo esc_html( $cId ); ?> .countdownItems .countdownItem{
104 - margin-top: calc( <?php echo esc_html( $boxSpace ); ?> / 2 ); margin-bottom: calc( <?php echo esc_html( $boxSpace ); ?> / 2 );
105 - } }
106 - </style>
108 + function registerSettings() {
109 + register_setting( 'ctbUtils', 'ctbUtils', [
110 + 'show_in_rest' => [
111 + 'name' => 'ctbUtils',
112 + 'schema' => [
113 + 'type' => 'string',
114 + ],
115 + ],
116 + 'type' => 'string',
117 + 'default' => wp_json_encode( [
118 + 'nonce' => wp_create_nonce( 'wp_ajax' ),
119 + ] ),
120 + 'sanitize_callback' => 'sanitize_text_field',
121 + ] );
122 + }
107 123
108 - <div class='countdownItems'>
109 - <?php $this->box( $isDays, "countdownDays $boxClass", $isLabels, $daysLabel ); ?>
110 - <?php echo $isSep && $isDays && ( $isHours || $isMinutes || $isSeconds ) ? "<span class='separator'></span>" : ''; ?>
111 - <?php $this->box( $isHours, "countdownHours $boxClass", $isLabels, $hoursLabel ); ?>
112 - <?php echo $isSep && $isHours && ( $isMinutes || $isSeconds ) ? "<span class='separator'></span>" : ''; ?>
113 - <?php $this->box( $isMinutes, "countdownMinutes $boxClass", $isLabels, $minutesLabel ); ?>
114 - <?php echo $isSep && $isMinutes && $isSeconds ? "<span class='separator'></span>" : ''; ?>
115 - <?php $this->box( $isSeconds, "countdownSeconds $boxClass", $isLabels, $secondsLabel ); ?>
116 - </div>
117 - </div>
124 + function blockCategories( $categories ) {
125 + return array_merge( [[
126 + 'slug' => 'CTBlock',
127 + 'title' => 'Countdown Time',
128 + ]], $categories );
129 + }
118 130
119 - <?php $countdownStyle::$styles = []; // Empty styles
120 - return ob_get_clean();
121 - } // Render
131 + }
122 132
123 - function box( $is, $boxClass, $isLabels, $label ){
124 - if( $is ){ ?><div class='countdownItem <?php echo esc_attr( $boxClass ) ?>'>
125 - <span class='digit'>00</span>
126 - <?php echo $isLabels ? "<span class='label'>". wp_kses_post( $label ) ."</span>" : ''; ?>
127 - </div><?php }
128 - } // Box
129 -}
130 -new CTBCountdownTimeBlock;
133 + new CTBPlugin();
134 +}