PluginProbe
Uji Countdown / trunk
Uji Countdown vtrunk
3.0 trunk 1.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.6.1 1.0.7 1.0.8 1.0.9 1.1 1.2 1.3 1.3.1 1.3.2 1.3.3 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 All 36 releases
uji-countdown / classes / class-uji-countdown.php

class-uji-countdown.php in Uji Countdown trunk, at classes/class-uji-countdown.php

900 lines 29.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Uji Countdown Main
4 *
5 * Handles main enqueue
6 *
7 * @author WPmanage
8 * @category Main
9 * @package Uji-Countdown/Classes
10 * @version 2.0
11 */
12 if ( ! defined( 'ABSPATH' ) ) {
13 exit;
14 }
15
16 class Uji_Countdown extends Uji_Countdown_Admin
17 {
18
19 /**
20 * Uji Countdown
21 *
22 * @since 2.0
23 *
24 * @var string
25 */
26 protected $pname = UJIC_NAME;
27 /**
28 * Plugin version, used for cache-busting of style and script file references.
29 *
30 * @since 2.0
31 *
32 * @var string
33 */
34 protected $version = UJIC_VERS;
35
36 /**
37 * Counter Options.
38 *
39 * @since 2.0
40 *
41 * @var array
42 */
43 private $options = array();
44
45 /**
46 * Instance of this class.
47 *
48 * @since 2.0
49 *
50 * @var object
51 */
52 protected static $instance = null;
53
54 /**
55 * Slug of the plugin screen.
56 *
57 * @since 2.0
58 *
59 * @var string
60 */
61 protected $plugin_screen_hook_suffix = null;
62
63 /**
64 * Init.
65 *
66 * @since 2.0
67 *
68 * @var string
69 */
70 public $uji;
71
72 /**
73 * Go Plus
74 *
75 * @since 2.1
76 */
77 public function ujic_pro() {
78 return ujic_is_pro_active();
79 }
80
81 /**
82 * Plus sfx
83 *
84 * @since 2.1
85 */
86 public function ujic_pro_sx() {
87 return $this->ujic_pro() ? 'ujicountdownpro' : 'ujicountdown';
88 }
89
90 /**
91 * Initialize the plugin by setting localization, filters, and administration functions.
92 *
93 * @since 2.0
94 */
95 public function __construct() {
96
97 // Register hooks that are fired when the plugin is activated, deactivated, and uninstalled, respectively.
98 register_activation_hook( UJICOUNTDOWN_FILE, array( $this, 'activate' ) );
99 register_deactivation_hook( UJICOUNTDOWN_FILE, array( $this, 'deactivate' ) );
100
101 //Show on front
102 if ( !is_admin() ) {
103 $ujic = new UjiCountdown();
104 }
105 // Load plugin text domain
106 add_action( 'init', array( $this, 'load_plugin_textdomain' ) );
107
108 // Load public-facing style sheet and JavaScript.
109 add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
110
111 // HOOKs Widget
112 global $wp_version;
113
114 if ( version_compare( $wp_version, '5.7', '<=' ) ) {
115 add_action( 'widgets_init', array( $this, 'ujic_register_widgets' ) );
116 }
117
118 if ( is_admin() )
119 {
120
121 // Add the options page and menu item.
122 add_action( 'admin_menu', array( $this, 'add_plugin_admin_menu' ) );
123
124 // Load admin style sheet and JavaScript.
125 add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_styles' ), 1 );
126 add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_scripts' ), 1 );
127
128 // Load admin shortcode style sheet and JavaScript.
129 add_action( 'admin_enqueue_scripts', array( &$this, 'ujic_shortcode_scripts' ) );
130
131 // Add the Link from plugins
132 add_filter('plugin_action_links', array($this, 'plugin_settings_link'),10,2);
133
134 // Normalize legacy admin labels, including labels emitted by Pro extension hooks.
135 add_filter( 'gettext', array( $this, 'ujic_admin_label_text' ), 10, 3 );
136
137 }
138
139 }
140
141 /**
142 * Version
143 *
144 * @since 2.0.3
145 */
146
147 public static function getPluginSavedVersion()
148 {
149 return get_option('uji-countdown-version', null);
150 }
151
152 protected static function savePluginVersion()
153 {
154 return update_option('uji-countdown-version', UJIC_ORIG);
155 }
156
157 protected static function upgradeVerFix ($ver){
158 if ( version_compare( (string) $ver, '2.1.2' ) ) {
159 global $wpdb;
160 $table_name = $wpdb->prefix . "uji_counter";
161 $ujic_datas = $wpdb->get_results( "SELECT * FROM $table_name ORDER BY `time` DESC" );
162 if ( !empty( $ujic_datas ) ) {
163 foreach ( $ujic_datas as $ujic ) {
164 if( $ujic->link == '' && $ujic->title != '' ){
165 $title = sanitize_title( $ujic->title );
166 $wpdb->query( $wpdb->prepare( "UPDATE $table_name SET `link` = %s WHERE (`id` = %d)", $title, $ujic->id ) );
167 }
168 }
169 }
170 }
171 }
172
173 /**
174 * Counter Options.
175 *
176 * @since 2.0
177 */
178 public function ujic_option( $id = NULL, $name = NULL ) {
179 //Default values
180 $style = $this->ujic_request_text( 'style' );
181 $sz = ( 'modern' === $style ) ? 50 : 32;
182 $col = ( 'modern' === $style ) ? '#efefef' : '#c368c3';
183 $txtc = ( 'modern' === $style ) ? '#000000' : '#ffffff';
184 $new_options = array();
185 $options = apply_filters( 'ujic_options', array(
186 "ujic_name" => "", //Name
187 "ujic_style" => "classic", //Style
188 "ujic_size" => esc_attr( $sz ), //Timer Size
189 "ujic_thick" => 10, //Thickness
190 "ujic_goof" => 'none', //Google Font
191 "ujic_col_dw" => '#a61ba6', //Select Box Color Down
192 "ujic_col_up" => esc_attr( $col ), //Select Box Color Up
193 "ujic_col_txt" => esc_attr( $txtc ), //Text Color Number
194 "ujic_col_sw" => '#000000', //Text Color Shadow
195 "ujic_col_lab" => '#000000', //LAbel Text Color
196 "ujic_lab_sz" => 13, //Label size
197 "ujic_pos" => 'none', //Alignment
198 "ujic_d" => "true", //Main format: Days
199 "ujic_h" => "true", //Main format: Hours
200 "ujic_m" => "true", //Main format: Minutes
201 "ujic_s" => "true", //Main format: Seconds
202 "ujic_y" => 0, //Secondary format: Years
203 "ujic_o" => 0, //Secondary format: Months
204 "ujic_w" => 0, //Secondary format: Weeks
205 "ujic_txt" => "true", //Show Label Text
206 "ujic_ani" => 0, //Animation for seconds
207 "ujic_no_box_color" => 0, //Disable classic box color
208 "ujic_no_text_shadow" => 0, //Disable classic number shadow
209 ));
210
211 //Return default values
212 if ( (!isset( $name ) || empty( $name ) ) && (!isset( $id ) || empty( $id ) ) )
213 {
214 if ( $this->cform_is_create() )
215 {
216 $posts = $this->ujic_post_values();
217
218 foreach ( $options as $nm => $val )
219 {
220 $new_options[$nm] = ( isset( $posts[$nm] ) && ! empty( $posts[$nm] ) ) ? esc_attr( $posts[$nm] ) : '';
221 }
222
223 return $new_options;
224 }
225 else
226 {
227 return $options;
228 }
229 }
230
231 //Return all saved values
232 if ( !isset( $name ) && isset( $id ) )
233 {
234 $get_option = $this->sel_ujic_db( $id );
235
236 foreach ( $options as $nm => $val )
237 {
238 $val = $this->cform_is_edit() ? '' : $val;
239 //$new_options[$nm] = ( isset( $get_option[$nm] ) && !empty( $get_option[$nm] ) ) ? $get_option[$nm] : $val;
240
241 $new_options[$nm] = is_array( $get_option ) && ! empty( $get_option[$nm] ) ? $get_option[$nm] : $val;
242 }
243 return $new_options;
244 }
245
246 //Return one saved value
247 if ( isset( $name ) && isset( $id ) && !empty( $name ) && !empty( $id ) )
248 {
249 $one_option = $this->sel_ujic_db( $id, $name );
250 return ( ! empty( $one_option ) ) ? $one_option : ( $options[$name] ?? null );
251 }
252 }
253
254 /**
255 * Short Link
256 *
257 * @since 2.0
258 */
259 public function plugin_settings_link( $links, $file ) {
260 if ( $file != UJICOUNTDOWN_BASE )
261 return $links;
262
263 array_unshift($links, '<a href="options-general.php?page=ujicountdown">' . __( 'Settings', 'ujicountdown' ) . '</a>');
264
265 return $links;
266 }
267
268 /**
269 * Table Name.
270 *
271 * @since 2.0
272 */
273 public static function ujic_tab_name() {
274 global $wpdb;
275 return $wpdb->prefix . "uji_counter";
276 }
277
278 /**
279 * Get Database.
280 *
281 * @since 2.0
282 */
283 public function sel_ujic_db( $id, $name = NULL ) {
284 global $wpdb;
285 $options = $var = array();
286
287 if( empty($id) ) {
288 return false;
289 }
290
291 if ( is_numeric( $id ) ) {
292 $ujic_data = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM " . self::ujic_tab_name() . " WHERE id = %d", $id ) );
293 } else {
294 $ujic_data = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM " . self::ujic_tab_name() . " WHERE link = %s", $id ) );
295 }
296
297 if ( empty($ujic_data) ) {
298 return false;
299 }
300
301 $var['id'] = $ujic_data->id;
302 $var['time'] = $ujic_data->time;
303 $var['ujic_name'] = $ujic_data->title;
304 $var['ujic_style'] = $ujic_data->style;
305
306 if ( !empty( $ujic_data->options ) ) {
307 $options = maybe_unserialize( $ujic_data->options );
308 if ( is_array( $options ) ) {
309 foreach ( $options as $option => $val ) {
310 $var[$option] = $val;
311 }
312 }
313 }
314 if ( $name )
315 return isset( $var[$name] ) ? $var[$name] : null;
316 else
317 return $var;
318 }
319
320 /**
321 * Insert Database.
322 *
323 * @since 2.0
324 */
325 public function ins_ujic_db( $posts ) {
326 global $wpdb;
327
328 //2.0.7 Fix Cross-Site Request Forgery attacks
329 self::ujic_secure( 'ujic_secure', 'ujic_secure_form', $posts );
330
331 $options = array();
332 $default = $this->ujic_option();
333 foreach ( $posts as $name => $val ) {
334 $default_value = is_array( $default ) && array_key_exists( $name, $default ) ? $default[$name] : '';
335 $options[$name] = ( '' !== $val ) ? esc_attr( $val ) : $default_value;
336 }
337 $title = $options['ujic_name'];
338 $style = $options['ujic_style'];
339 unset( $options['ujic_name'], $options['ujic_style'], $options['submit_ujic'] );
340 //insert to DB
341 $wpdb->query( $wpdb->prepare( "INSERT INTO " . self::ujic_tab_name() . "(time, title, link, style, options )
342 VALUES (utc_timestamp(), %s, %s, %s, %s)", esc_html($title), sanitize_title( $title ), trim( $style ), maybe_serialize( $options )
343 ) );
344 }
345
346 /**
347 * Update Database.
348 *
349 * @since 2.0
350 */
351 public function upd_ujic_db( $posts, $id ) {
352 global $wpdb;
353
354 //2.0.7 Fix Cross-Site Request Forgery attacks
355 self::ujic_secure( 'ujic_secure', 'ujic_secure_form', $posts );
356
357 $options = array();
358 $default = $this->ujic_option();
359 foreach ( $posts as $name => $val ) {
360 $default_value = is_array( $default ) && array_key_exists( $name, $default ) ? $default[$name] : '';
361 $options[$name] = ( '' !== $val ) ? esc_attr( $val ) : $default_value;
362 }
363 $title = $options['ujic_name'];
364 $style = $options['ujic_style'];
365 unset( $options['ujic_name'], $options['ujic_style'], $options['submit_ujic'], $options['cancel_ujic'] );
366 //update DB
367 $wpdb->query( $wpdb->prepare( "UPDATE " . self::ujic_tab_name() . " SET title=%s, link=%s, style=%s, options=%s WHERE id=%d", esc_html($title), sanitize_title( $title ), trim( $style ), maybe_serialize( $options ), esc_attr( $id )
368 ) );
369 }
370
371 /**
372 * Delete Database.
373 *
374 * @since 2.0
375 */
376 public function del_ujic_db( $id ) {
377 global $wpdb;
378
379 if ( is_numeric( $id ) ) {
380 $sql = $wpdb->prepare(
381 "DELETE FROM " . self::ujic_tab_name() . " WHERE id = %d",
382 $id
383 );
384 $wpdb->query( $sql );
385 }
386 }
387
388 /**
389 * Create Database.
390 *
391 * @since 2.0
392 */
393 private static function create_ujic_db() {
394 global $wpdb;
395
396 $wpdb->hide_errors();
397 $collate = '';
398
399 if ( $wpdb->has_cap( 'collation' ) ) {
400 if ( ! empty($wpdb->charset ) ) {
401 $collate .= "DEFAULT CHARACTER SET $wpdb->charset";
402 }
403 if ( ! empty($wpdb->collate ) ) {
404 $collate .= " COLLATE $wpdb->collate";
405 }
406 }
407
408
409 $sql = "CREATE TABLE " . self::ujic_tab_name() . " (
410 id int(9) unsigned NOT NULL AUTO_INCREMENT,
411 time datetime not null,
412 title varchar(128) not null,
413 link varchar(128) not null,
414 style varchar(32) not null,
415 options longtext,
416 PRIMARY KEY (id),
417 KEY id (id)
418 ) $collate";
419 require_once( ABSPATH . '/wp-admin/includes/upgrade.php' );
420 dbDelta( $sql );
421 }
422
423 /**
424 * Create/Upgrade Database.
425 *
426 * @since 2.0
427 */
428 private function upgrade_db() {
429 global $wpdb;
430
431 if( $wpdb->get_var( "SHOW TABLES LIKE '" . self::ujic_tab_name()."'") === $wpdb->prefix . self::ujic_tab_name() ) {
432
433 // Create DB
434 self::create_ujic_db();
435
436 $old_data = $wpdb->get_results( "SELECT * FROM " . self::ujic_tab_name() );
437
438 foreach ( $old_data as $data ) {
439
440 $posts["ujic_name"] = $data->title; //Timer Title
441 $posts["ujic_style"] = $data->style; //Timer Style
442 $posts["ujic_size"] = $data->size; //Timer Size
443 if( $data->ujic_thick ) $posts["ujic_thick"] = $data->ujic_thick; //Thickness
444 $posts["ujic_col_dw"] = $data->col_dw; //Select Box Color Down
445 $posts["ujic_col_up"] = $data->col_up; //Select Box Color Up
446 if( $data->col_txt ) $posts["ujic_col_txt"] = $data->col_txt; //Text Color Number
447 if( $data->col_sw ) $posts["ujic_col_sw"] = $data->col_sw; //Text Color Shadow
448 $posts["ujic_pos"] = $data->ujic_pos; //Alignment
449 $posts["ujic_goof"] = 'none'; //Google Font
450 $posts["ujic_txt"] = ($data->ujic_txt) ? "true" : 0; //Show Label Text
451 $posts["ujic_col_lab"] = '#000000'; //LAbel Text Color
452 $posts["ujic_lab_sz"] = 13; //Label size
453 $posts["ujic_ani"] = ($data->ujic_ani) ? "true" : 0; //Animation for seconds
454 $posts["ujic_d"] = "true"; //Main format: Days
455 $posts["ujic_h"] = "true"; //Main format: Hours
456 $posts["ujic_m"] = "true"; //Main format: Minutes
457 $posts["ujic_s"] = "true"; //Main format: Seconds
458 $posts["ujic_y"] = 0; //Secondary format: Years
459 $posts["ujic_o"] = 0; //Secondary format: Months
460 $posts["ujic_w"] = 0; //Secondary format: Weeks
461
462 $this->upd_ujic_db( $posts, $data->id );
463
464 $wpdb->query( "ALTER TABLE " . self::ujic_tab_name() );
465 $wpdb->query( "ALTER TABLE " . self::ujic_tab_name() . " DROP `size`, DROP `col_dw`, DROP `col_up`, DROP `ujic_pos`, DROP `col_txt`, DROP `col_sw`, DROP `ujic_ani`, DROP `ujic_txt`, DROP `ujic_thick`;" );
466
467 }
468
469 }else{
470 // Create DB
471 self::create_ujic_db();
472 }
473
474 }
475
476 /**
477 * Return an instance of this class.
478 *
479 * @since 2.0
480 *
481 */
482 public static function get_instance() {
483
484 // If the single instance hasn't been set, set it now.
485 if ( null == self::$instance ) {
486 self::$instance = new self;
487 }
488
489 return self::$instance;
490 }
491
492 /**
493 * Fired when the plugin is activated.
494 *
495 * @since 2.0
496 *
497 * @param boolean $network_wide True if WPMU superadmin uses "Network Activate" action, false if WPMU is disabled or plugin is activated on an individual blog.
498 */
499 public function activate( $network_wide ) {
500 //Upgrade DB
501 $this->upgrade_db();
502
503 $ver = get_option('uji-countdown-version', null);
504
505 self::upgradeVerFix($ver);
506
507 self::savePluginVersion();
508 }
509
510 /**
511 * Fired when the plugin is deactivated.
512 *
513 * @since 2.0
514 *
515 * @param boolean $network_wide True if WPMU superadmin uses "Network Deactivate" action, false if WPMU is disabled or plugin is deactivated on an individual blog.
516 */
517 public static function deactivate( $network_wide ) {
518 // TODO: Define deactivation functionality here
519 }
520
521 /**
522 * Load the plugin text domain for translation.
523 *
524 * @since 2.0
525 */
526 public function load_plugin_textdomain() {
527
528 $domain = 'ujicountdown';
529 $locale = apply_filters( 'plugin_locale', get_locale(), $domain );
530
531 load_textdomain( $domain, WP_LANG_DIR . '/' . $domain . '/' . $domain . '-' . $locale . '.mo' );
532 load_plugin_textdomain( $domain, FALSE, dirname( plugin_basename( __FILE__ ) ) . '/lang/' );
533 }
534
535 /**
536 * Return a cache-busting version for plugin assets.
537 *
538 * @since 2.0
539 *
540 * @param string $relative_path Relative asset path inside the plugin.
541 * @return string
542 */
543 protected function ujic_asset_version( $relative_path ) {
544 $path = UJICOUNTDOWN . $this->ujic_asset_path( $relative_path );
545
546 if ( file_exists( $path ) ) {
547 return (string) filemtime( $path );
548 }
549
550 return $this->version;
551 }
552
553 /**
554 * Check whether WordPress should load unminified development assets.
555 *
556 * @since 2.0
557 *
558 * @return bool
559 */
560 protected function ujic_is_script_debug() {
561 return defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG;
562 }
563
564 /**
565 * Return the production asset path when available.
566 *
567 * @since 2.0
568 *
569 * @param string $relative_path Relative asset path inside the plugin.
570 * @return string
571 */
572 protected function ujic_asset_path( $relative_path ) {
573 $relative_path = ltrim( $relative_path, '/' );
574
575 if ( $this->ujic_is_script_debug() ) {
576 $dev_path = preg_replace( '/\.js$/', '.dev.js', $relative_path );
577
578 if ( $dev_path && $dev_path !== $relative_path && file_exists( UJICOUNTDOWN . $dev_path ) ) {
579 return $dev_path;
580 }
581
582 return $relative_path;
583 }
584
585 $min_path = preg_replace( '/\.(js|css)$/', '.min.$1', $relative_path );
586
587 if ( $min_path && $min_path !== $relative_path && file_exists( UJICOUNTDOWN . $min_path ) ) {
588 return $min_path;
589 }
590
591 return $relative_path;
592 }
593
594 /**
595 * Return a plugin asset URL using the production asset path when available.
596 *
597 * @since 2.0
598 *
599 * @param string $relative_path Relative asset path inside the plugin.
600 * @return string
601 */
602 protected function ujic_asset_url( $relative_path ) {
603 return esc_url( UJICOUNTDOWN_URL . $this->ujic_asset_path( $relative_path ) );
604 }
605
606 /**
607 * Register and enqueue admin-specific style sheet.
608 *
609 * @since 2.0
610 *
611 * @return null Return early if no settings page is registered.
612 */
613 public function enqueue_admin_styles() {
614
615 if ( !isset( $this->plugin_screen_hook_suffix ) ) {
616 return;
617 }
618
619 $screen = get_current_screen();
620 $tab = $this->ujic_request_text( 'tab' );
621 if ( $screen->id == $this->plugin_screen_hook_suffix ) {
622 if( ! empty( $tab ) && $tab != "tab_ujic_list"){
623 wp_enqueue_style( 'wp-color-picker' );
624 wp_enqueue_style( 'ujicountdown' . '-admin-jqueryui', $this->ujic_asset_url( 'assets/css/jquery-ui-custom.css' ), array(), $this->ujic_asset_version( 'assets/css/jquery-ui-custom.css' ) );
625 wp_enqueue_style( 'ujicountdown' . '-admin-icheck', $this->ujic_asset_url( 'assets/css/pink.css' ), array(), $this->ujic_asset_version( 'assets/css/pink.css' ) );
626 }
627 wp_enqueue_style( 'ujicountdown' . '-admin-styles', $this->ujic_asset_url( 'assets/css/admin.css' ), array(), $this->ujic_asset_version( 'assets/css/admin.css' ) );
628 }
629 }
630
631 /**
632 * Anti Spam Notice
633 *
634 * @since 2.0.3
635 *
636 */
637 public function showAntiSpamAdminNotice()
638 {
639 $screen = get_current_screen();
640 $tab = $this->ujic_request_text( 'tab' );
641 if($screen->id != $this->plugin_screen_hook_suffix)
642 return;
643
644 if(empty($tab) || $tab !== 'tab_ujic_news')
645 return;
646 }
647
648 /**
649 * Register and enqueue admin-specific JavaScript.
650 *
651 * @since 2.0
652 *
653 * @return null Return early if no settings page is registered.
654 */
655 public function enqueue_admin_scripts() {
656
657 if ( !isset( $this->plugin_screen_hook_suffix ) ) {
658 return;
659 }
660 $screen = get_current_screen();
661 $tab = $this->ujic_request_text( 'tab' );
662 if ( $screen->id != $this->plugin_screen_hook_suffix ) {
663 return;
664 }
665
666 wp_enqueue_style( 'dashicons' );
667 if ( $screen->id == $this->plugin_screen_hook_suffix && ( ! empty( $tab ) && $tab != "tab_ujic_list")) {
668 wp_enqueue_script( 'dashboard' );
669 wp_enqueue_script( 'jquery-ui-core' );
670 wp_enqueue_script( 'jquery-ui-slider' );
671 wp_enqueue_script( 'jquery-ui-draggable' );
672
673 if( $tab != "tab_ujic_news")
674 {
675 wp_enqueue_script('ujicountdown-admin-icheck', esc_url( UJICOUNTDOWN_URL ) . 'assets/js/jquery.icheck.min.js');
676 wp_enqueue_script('ujicountdown-admin-script', $this->ujic_asset_url( 'assets/js/admin-ujic.js' ), array('wp-color-picker'), $this->ujic_asset_version( 'assets/js/admin-ujic.js' ));
677 }
678
679 if( $tab == "tab_ujic_shortcode")
680 {
681 wp_enqueue_script('ujicountdown-admin-shortcode', $this->ujic_asset_url( 'assets/js/admin-shortcode.js' ), array( 'jquery', 'ujicountdown-admin-icheck' ), $this->ujic_asset_version( 'assets/js/admin-shortcode.js' ) );
682 }
683 }
684 }
685
686 /**
687 * Register and enqueues public-facing JavaScript files.
688 *
689 * @since 2.0
690 */
691 public function enqueue_scripts() {
692 wp_register_style( 'ujicountdown-uji-countdown', $this->ujic_asset_url( 'css/uji-countdown.css' ), array(), $this->ujic_asset_version( 'css/uji-countdown.css' ) );
693 wp_register_script( 'ujicountdown-core', $this->ujic_asset_url( 'js/jquery.countdown.js' ), array( 'jquery' ), $this->ujic_asset_version( 'js/jquery.countdown.js' ), false );
694
695 $countdown_alias_script = '(function($){'
696 . 'if(!$||!$.fn||!$.fn.countdown){return;}'
697 . '$.fn.ujicCountdown=$.fn.countdown;'
698 . 'if($.countdown){$.ujicCountdown=$.countdown;}'
699 . '})(jQuery);';
700 wp_add_inline_script( 'ujicountdown-core', $countdown_alias_script, 'after' );
701
702 wp_register_script( 'ujicountdown-init', $this->ujic_asset_url( 'js/uji-countdown.js' ), array( 'jquery', 'ujicountdown-core' ), $this->ujic_asset_version( 'js/uji-countdown.js' ), true );
703
704 $countdown_compat_script = '(function($){'
705 . 'if(!$||!$.fn||!$.fn.ujicCountdown){return;}'
706 . 'var ujicFn=$.fn.ujicCountdown;'
707 . 'var ujicManager=$.ujicCountdown||$.countdown;'
708 . 'var otherFn=$.fn.countdown!==ujicFn?$.fn.countdown:null;'
709 . 'if(ujicManager){$.countdown=ujicManager;}'
710 . '$.fn.countdown=function(options){'
711 . 'var isUjic=options&&typeof options==="object"&&("until" in options||"since" in options||"serverSync" in options||"ujic_id" in options);'
712 . 'if(isUjic||!otherFn){if(ujicManager){$.countdown=ujicManager;}return ujicFn.apply(this,arguments);}'
713 . 'return otherFn.apply(this,arguments);'
714 . '};'
715 . '})(jQuery);';
716 wp_add_inline_script( 'ujicountdown-init', $countdown_compat_script, 'before' );
717
718 wp_register_script( 'ujiCountRedirect', $this->ujic_asset_url( 'js/uji-count-expired.js' ), array( 'jquery' ), $this->ujic_asset_version( 'js/uji-count-expired.js' ), true );
719 //Extend enqueues css and js
720 $extent_scripts = apply_filters( 'ujic_scripts_extend', true);
721
722 if( is_array( $extent_scripts ) ){
723 if( !empty($extent_scripts['css']) ){
724 foreach ($extent_scripts['css'] as $nm => $css){
725 wp_register_style( $nm, $css['url'], array(), $css['ver'] );
726 }
727 }
728 if( !empty($extent_scripts['js']) ){
729 foreach ($extent_scripts['js'] as $nm => $js){
730 wp_register_script( $nm, $js['url'], array( 'jquery' ), $js['ver'] );
731 }
732 }
733 }
734
735
736 }
737
738 /**
739 * Register the administration menu for this plugin into the WordPress Dashboard menu.
740 *
741 * @since 2.0
742 */
743 public function add_plugin_admin_menu() {
744 $this->plugin_screen_hook_suffix = add_submenu_page(
745 'options-general.php', ujic_plugin_name() . " " . ujic_plugin_version(), ujic_plugin_name(), 'manage_options', 'ujicountdown', array( $this, 'display_plugin_admin_page' )
746 );
747 }
748
749 /**
750 * Render the settings page for this plugin.
751 *
752 * @since 2.0
753 */
754 public function display_plugin_admin_page() {
755 include_once( UJICOUNTDOWN . 'views/admin.php' );
756 }
757
758 /**
759 * Shortcode Admin Init
760 *
761 * @since 2.0.4
762 */
763 public function ujic_shortcode_scripts() {
764 $screen = get_current_screen();
765 if ( $screen->base == 'post' ):
766 // css
767 wp_enqueue_style( 'ujic-count-ui', esc_url( UJICOUNTDOWN_URL ) . 'assets/css/jquery-ui.min.css', false, '1.0', 'all' );
768 wp_enqueue_style( 'ujic-count', $this->ujic_asset_url( 'assets/css/ujic-style.css' ), false, $this->ujic_asset_version( 'assets/css/ujic-style.css' ), 'all' );
769
770 // js
771 wp_enqueue_script( 'jquery-ui-sortable' );
772 wp_enqueue_script( 'jquery-ui-datepicker' );
773
774 wp_localize_script( 'jquery', 'UjicShortcodes', array( 'plugin_folder' => esc_url( UJICOUNTDOWN_URL ) ) );
775
776 if ( !current_user_can( 'edit_posts' ) && !current_user_can( 'edit_pages' ) )
777 return;
778
779 if ( get_user_option( 'rich_editing' ) == 'true' ) {
780 wp_localize_script('editor', 'ujic_short_vars', array(
781 'ujic_style' => $this->ujic_styles_get(),
782 'ujic_hou' => $this->ujic_datetime_get(23),
783 'ujic_min' => $this->ujic_datetime_get(59),
784 'ujic_reclab' => $this->ujic_reclab_get()
785 ));
786
787 add_filter( 'mce_external_plugins', array( &$this, 'ujic_add_tinymce_plugin' ) );
788 add_filter( 'mce_buttons', array( &$this, 'ujic_register_my_tc_button' ) );
789 }
790 endif;
791 }
792
793 /**
794 * get All Styles
795 *
796 * @since 2.0.4
797 * @update 2.0.7
798 */
799 public function ujic_styles_get() {
800 global $wpdb;
801 $ujic_styles = $wpdb->get_results( "SELECT style, title, link FROM " . $wpdb->prefix . "uji_counter ORDER BY `time` DESC" );
802 $ujic_sel = array();
803 if ( !empty($ujic_styles) ) {
804 $i = 0;
805 foreach ( $ujic_styles as $ujic ) {
806 $ujic_sel[$i]['text'] = esc_attr ( $ujic->title ) . ' - ' . esc_attr ( $ujic->style );
807 $ujic_sel[$i]['value'] = esc_attr ( $ujic->link );
808 $i++;
809 }
810
811 return $ujic_sel;
812 }
813 }
814
815 /**
816 * TinyMCE get Data/Time
817 *
818 * @since 2.0.4
819 */
820 public function ujic_datetime_get($nr) {
821 $ujic_sel = array();
822 for ( $i = 0; $i <= $nr; $i++ ) {
823 $ujic_sel[$i]['text'] = $num[sprintf("%02s", $i)] = sprintf("%02s", $i);
824 $ujic_sel[$i]['value'] = $num[sprintf("%02s", $i)] = sprintf("%02s", $i);
825 }
826
827 return $ujic_sel;
828 }
829
830 /**
831 * TinyMCE get Unit Time labels
832 *
833 * @since 2.0.4
834 */
835 public function ujic_reclab_get() {
836 $tlab = array('second'=> __( 'Second(s)', 'ujicountdown' ),
837 'minute'=> __( 'Minute(s)', 'ujicountdown' ),
838 'hour'=> __('Hour(s)', 'ujicountdown' ),
839 'day'=> __( 'Day(s)', 'ujicountdown' ),
840 'week'=> __( 'Week(s)', 'ujicountdown' ),
841 'month'=> __( 'Month(s)', 'ujicountdown' )
842 );
843 $i=0;
844 foreach ( $tlab as $v => $n ) {
845 $ujic_sel[$i]['text'] = $n;
846 $ujic_sel[$i]['value'] = $v;
847 $i++;
848 }
849
850 return $ujic_sel;
851 }
852
853 /**
854 * TinyMCE Plugin JS
855 *
856 * @since 2.0.4
857 */
858 public function ujic_add_tinymce_plugin( $plugin_array ) {
859 $plugin_array['ujic_tc_button'] = esc_url( UJICOUNTDOWN_URL ) . 'assets/js/ujic-popup-button.js';
860 return $plugin_array;
861 }
862
863 /**
864 * Add TyniMCE Button
865 *
866 * @since 2.0.4
867 */
868 public function ujic_register_my_tc_button( $buttons ) {
869 array_push( $buttons, "ujic_tc_button" );
870 return $buttons;
871 }
872
873 /**
874 * Register widget
875 *
876 * @return void
877 */
878 public function ujic_register_widgets() {
879 // Include - no need to use autoload as WP loads them anyway
880 include_once UJICOUNTDOWN . 'classes/class-uji-widget.php';
881
882 // Register widgets
883 register_widget( 'ujic_Widget' );
884 }
885
886 /**
887 * Get options/option
888 *
889 * @since 2.0
890 */
891 public function ujic_get_option( $name, $opt = 'ujic_set' ) {
892 $vars = is_array( $opt ) ? $opt : get_option( $opt, array() );
893 if( is_array( $vars ) && is_string ( $name ) && isset($vars[$name]) && !empty($vars[$name]) )
894 return $vars[$name];
895 else
896 return false;
897 }
898
899 }
900