| 1 |
<?php |
| 2 |
/** |
| 3 |
* Plugin Name: Countdown Timer |
| 4 |
* Description: Display your events date into a timer to your visitor with countdown time block |
| 5 |
* Version: 1.3.2 |
| 6 |
* Author: bPlugins |
| 7 |
* Author URI: https://bplugins.com |
| 8 |
* License: GPLv3 |
| 9 |
* License URI: https://www.gnu.org/licenses/gpl-3.0.txt |
| 10 |
* Text Domain: countdown-time |
| 11 |
*/ |
| 12 |
|
| 13 |
// ABS PATH |
| 14 |
if ( !defined( 'ABSPATH' ) ) { exit; } |
| 15 |
|
| 16 |
if ( function_exists( 'ctb_fs' ) ) { |
| 17 |
ctb_fs()->set_basename( false, __FILE__ ); |
| 18 |
}else{ |
| 19 |
define( 'CTB_VERSION', isset( $_SERVER['HTTP_HOST'] ) && ( 'localhost' === $_SERVER['HTTP_HOST'] || 'plugins.local' === $_SERVER['HTTP_HOST'] ) ? time() : '1.3.2' ); |
| 20 |
define( 'CTB_DIR_URL', plugin_dir_url( __FILE__ ) ); |
| 21 |
define( 'CTB_DIR_PATH', plugin_dir_path( __FILE__ ) ); |
| 22 |
define( 'CTB_HAS_PRO', file_exists( CTB_DIR_PATH . 'vendor/freemius/start.php' ) ); |
| 23 |
|
| 24 |
if ( CTB_HAS_PRO ) { |
| 25 |
require_once CTB_DIR_PATH . 'includes/fs.php'; |
| 26 |
require_once CTB_DIR_PATH . 'includes/admin/CPT.php'; |
| 27 |
require_once CTB_DIR_PATH . 'includes/LicenseActivation.php'; |
| 28 |
}else{ |
| 29 |
require_once CTB_DIR_PATH . 'includes/fs-lite.php'; |
| 30 |
require_once CTB_DIR_PATH . 'includes/admin/SubMenu.php'; |
| 31 |
} |
| 32 |
|
| 33 |
require_once CTB_DIR_PATH . 'includes/Patterns.php'; |
| 34 |
|
| 35 |
function ctbIsPremium(){ |
| 36 |
return CTB_HAS_PRO ? ctb_fs()->can_use_premium_code() : false; |
| 37 |
} |
| 38 |
|
| 39 |
if( !class_exists( 'CTBPlugin' ) ){ |
| 40 |
class CTBPlugin{ |
| 41 |
function __construct(){ |
| 42 |
add_action( 'init', [ $this, 'onInit' ] ); |
| 43 |
add_filter( 'block_categories_all', [$this, 'blockCategories'] ); |
| 44 |
add_action( 'admin_enqueue_scripts', [$this, 'adminEnqueueScripts'] ); |
| 45 |
add_action( 'enqueue_block_editor_assets', [$this, 'enqueueBlockEditorAssets'] ); |
| 46 |
|
| 47 |
add_filter( 'plugin_action_links', [$this, 'pluginActionLinks'], 10, 2 ); |
| 48 |
add_filter( 'default_title', [$this, 'defaultTitle'], 10, 2 ); |
| 49 |
add_filter( 'default_content', [$this, 'defaultContent'], 10, 2 ); |
| 50 |
} |
| 51 |
|
| 52 |
function defaultTitle( $title, $post ) { |
| 53 |
if ( 'page' === $post->post_type && isset( $_GET['title'] ) ) { |
| 54 |
$nonce = isset( $_GET['nonce'] ) ? sanitize_text_field( wp_unslash( $_GET['nonce'] ) ) : ''; |
| 55 |
|
| 56 |
if ( wp_verify_nonce( $nonce, 'ctbCreatePage' ) ) { |
| 57 |
return sanitize_text_field( wp_unslash( $_GET['title'] ) ); |
| 58 |
} |
| 59 |
} |
| 60 |
return $title; |
| 61 |
} |
| 62 |
|
| 63 |
function defaultContent( $content, $post ) { |
| 64 |
if ( 'page' === $post->post_type && isset( $_GET['content'] ) ) { |
| 65 |
$nonce = isset( $_GET['nonce'] ) ? sanitize_text_field( wp_unslash( $_GET['nonce'] ) ) : ''; |
| 66 |
|
| 67 |
if ( wp_verify_nonce( $nonce, 'ctbCreatePage' ) ) { |
| 68 |
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Content is secured by nonce verification and unslashed to preserve Gutenberg block markup. |
| 69 |
return wp_unslash( $_GET['content'] ); |
| 70 |
} |
| 71 |
} |
| 72 |
return $content; |
| 73 |
} |
| 74 |
|
| 75 |
function pluginActionLinks( $links, $file ) { |
| 76 |
if( plugin_basename( __FILE__ ) === $file ) { |
| 77 |
$helpDemosLink = admin_url( CTB_HAS_PRO ? 'edit.php?post_type=ctb&page=countdown-time#/welcome' : 'tools.php?page=countdown-time#/welcome' ); |
| 78 |
|
| 79 |
$links['help-and-demos'] = sprintf( '<a href="%s" style="%s">%s</a>', $helpDemosLink, 'color:#FF7A00;font-weight:bold', __( 'Help & Demos', 'countdown-time' ) ); |
| 80 |
} |
| 81 |
|
| 82 |
return $links; |
| 83 |
} |
| 84 |
|
| 85 |
function onInit(){ |
| 86 |
register_block_type( __DIR__ . '/build' ); |
| 87 |
} |
| 88 |
|
| 89 |
function blockCategories( $categories ){ |
| 90 |
return array_merge( [ [ |
| 91 |
'slug' => 'CTBlock', |
| 92 |
'title' => 'Countdown Time' |
| 93 |
] ], $categories ); |
| 94 |
} |
| 95 |
|
| 96 |
function adminEnqueueScripts( $hook ) { |
| 97 |
if( strpos( $hook, 'countdown-time' ) ){ |
| 98 |
wp_enqueue_style( 'ctb-admin-dashboard', CTB_DIR_URL . 'build/admin/dashboard.css', [], CTB_VERSION ); |
| 99 |
|
| 100 |
$asset_file = include CTB_DIR_PATH . 'build/admin/dashboard.asset.php'; |
| 101 |
wp_enqueue_script( 'ctb-admin-dashboard', CTB_DIR_URL . 'build/admin/dashboard.js', array_merge( $asset_file['dependencies'], [ 'wp-util' ] ), CTB_VERSION, true ); |
| 102 |
wp_set_script_translations( 'ctb-admin-dashboard', 'countdown-time', CTB_DIR_PATH . 'languages' ); |
| 103 |
} |
| 104 |
} |
| 105 |
|
| 106 |
function enqueueBlockEditorAssets(){ |
| 107 |
wp_add_inline_script( 'ctb-countdown-time-editor-script', 'const ctppipecheck = ' . wp_json_encode( ctbIsPremium() ) .'; const ctbpricingurl = "'. admin_url( CTB_HAS_PRO ? 'edit.php?post_type=ctb&page=countdown-time#/pricing' : 'tools.php?page=countdown-time#/pricing' ) .'";', 'before' ); |
| 108 |
} |
| 109 |
|
| 110 |
static function renderDashboard(){ ?> |
| 111 |
<div |
| 112 |
id='ctbDashboard' |
| 113 |
data-info='<?php echo esc_attr( wp_json_encode( [ |
| 114 |
'version' => CTB_VERSION, |
| 115 |
'isPremium' => ctbIsPremium(), |
| 116 |
'hasPro' => CTB_HAS_PRO, |
| 117 |
'nonce' => wp_create_nonce( 'ctbCreatePage' ), |
| 118 |
'licenseActiveNonce' => wp_create_nonce( 'bPlLicenseActivation' ) |
| 119 |
] ) ); ?>' |
| 120 |
></div> |
| 121 |
<?php } |
| 122 |
} |
| 123 |
new CTBPlugin; |
| 124 |
} |
| 125 |
} |