PluginProbe
HootKit / trunk
HootKit vtrunk
trunk 2.0.21 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5
hootkit / misc / shortcode-timer / admin.php

admin.php in HootKit trunk, at misc/shortcode-timer/admin.php

80 lines 3.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Shortcodes (limited)
4 * This file is loaded at after_setup_theme@96 via class-miscmods
5 *
6 * @package Hootkit
7 */
8
9 // If this file is called directly, abort.
10 if ( ! defined( 'ABSPATH' ) ) {
11 die;
12 }
13
14 /* Add Shortcodes */
15 add_shortcode( 'HKtimer', 'hootkit_shortcode_timer' );
16
17 /**
18 * Display timer
19 *
20 * @since 1.1.1
21 * @access public
22 * @param array $atts
23 * @param string $content
24 * @return string
25 */
26 function hootkit_shortcode_timer( $atts, $content = null ) {
27 if ( is_customize_preview() )
28 return '<span class="hootkit-timer" style="opacity:0.6;font-weight:normal"><em>' . esc_html__( '&laquo; Timer preview is not available in customize view &raquo;', 'hootkit' ) . '</em></span>';
29
30 $display = '';
31 extract( shortcode_atts( array(
32 'year' => '',
33 'month' => '',
34 'day' => '',
35 'hour' => '',
36 'minute' => '',
37 // 'yearlabel' => esc_html__( 'year', 'hootkit' ),
38 // 'yearslabel' => esc_html__( 'years', 'hootkit' ),
39 // 'monthlabel' => esc_html__( 'month', 'hootkit' ),
40 // 'monthslabel' => esc_html__( 'months', 'hootkit' ),
41 'daylabel' => esc_html__( 'day', 'hootkit' ),
42 'dayslabel' => esc_html__( 'days', 'hootkit' ),
43 'expiredlabel' => esc_html__( 'Expired', 'hootkit' ),
44 ), $atts ) );
45
46 // Sanitize values
47 $timezone = wp_timezone(); // https://developer.wordpress.org/reference/functions/current_time/
48 $datetime = new DateTime( 'now', $timezone );
49 foreach ( array( 'year', 'month', 'day', 'hour', 'minute' ) as $v )
50 $$v = absint( $$v );
51 if ( $hour == 24 ) $hour = 0;
52 if ( $minute == 60 ) $minute = 0;
53 $year = ( !empty( $year ) && $year >= 1000 && $year <= 9999 ) ? sprintf( '%04d', $year ) : $datetime->format('Y');
54 $month = ( !empty( $month ) && $month >= 1 && $month <= 12 ) ? sprintf( '%02d', $month ) : $datetime->format('m');
55 $day = ( !empty( $day ) && $day >= 1 && $day <= 31 ) ? sprintf( '%02d', $day ) : $datetime->format('d');
56 $hour = ( ( !empty( $hour ) || $hour == 0 ) && $hour >= 0 && $hour <= 23 ) ? sprintf( '%02d', $hour ) : '00';
57 $minute = ( ( !empty( $minute ) || $minute == 0 ) && $minute >= 0 && $minute <= 59 ) ? sprintf( '%02d', $minute ) : '00';
58 $second = '00';
59 // display .= $year . ' ' . $month . ' ' . $day . ' ' . $hour . ' ' . $minute;
60
61 // Set times
62 $currenttime = current_time('timestamp');
63 $deadline = strtotime( "{$day}-{$month}-{$year} {$hour}:{$minute}:{$second}" );
64 $timedifference = $deadline - $currenttime;
65 // GMT : $display .= '<br />' . ( time() - strtotime('2020-06-29 4:45:00') );
66 // Server Time : $display .= '<br />' . ( current_time('timestamp') - strtotime('2020-06-29 10:15:00') );
67
68 $display .= '<span class="hootkit-timer" ' .
69 'data-diff="' . esc_attr( $timedifference ) . '" ' .
70 // 'data-yearlabel = "' . esc_attr( $yearlabel ) . '" ' .
71 // 'data-yearslabel = "' . esc_attr( $yearslabel ) . '" ' .
72 // 'data-monthlabel = "' . esc_attr( $monthlabel ) . '" ' .
73 // 'data-monthslabel = "' . esc_attr( $monthslabel ) . '" ' .
74 'data-daylabel = "' . esc_attr( $daylabel ) . '" ' .
75 'data-dayslabel = "' . esc_attr( $dayslabel ) . '" ' .
76 'data-expiredlabel = "' . esc_attr( $expiredlabel ) . '" ' .
77 '></span>';
78
79 return $display;
80 }