'milestone-widget', 'description' => __( 'Display a countdown to a certain date.', 'jetpack' ), ); parent::__construct( 'Milestone_Widget', /** This filter is documented in modules/widgets/facebook-likebox.php */ apply_filters( 'jetpack_widget_name', __( 'Milestone', 'jetpack' ) ), $widget ); self::$dir = trailingslashit( dirname( __FILE__ ) ); self::$url = plugin_dir_url( __FILE__ ); self::$labels = array( 'year' => __( 'year', 'jetpack' ), 'years' => __( 'years', 'jetpack' ), 'month' => __( 'month', 'jetpack' ), 'months' => __( 'months', 'jetpack' ), 'day' => __( 'day', 'jetpack' ), 'days' => __( 'days', 'jetpack' ), 'hour' => __( 'hour', 'jetpack' ), 'hours' => __( 'hours', 'jetpack' ), 'minute' => __( 'minute', 'jetpack' ), 'minutes' => __( 'minutes', 'jetpack' ), 'second' => __( 'second', 'jetpack' ), 'seconds' => __( 'seconds', 'jetpack' ), ); add_action( 'wp_enqueue_scripts', array( __class__, 'enqueue_template' ) ); add_action( 'admin_enqueue_scripts', array( __class__, 'enqueue_admin' ) ); add_action( 'wp_footer', array( $this, 'localize_script' ) ); if ( is_active_widget( false, false, $this->id_base, true ) || is_active_widget( false, false, 'monster', true ) || is_customize_preview() ) { add_action( 'wp_head', array( __class__, 'styles_template' ) ); } } public static function enqueue_admin( $hook_suffix ) { if ( 'widgets.php' == $hook_suffix ) { wp_enqueue_style( 'milestone-admin', self::$url . 'style-admin.css', array(), '20161215' ); } } public static function enqueue_template() { wp_enqueue_script( 'milestone', self::$url . 'milestone.js', array( 'jquery' ), '20160520', true ); } public static function styles_template() { global $themecolors; $colors = wp_parse_args( $themecolors, array( 'bg' => 'ffffff', 'border' => 'cccccc', 'text' => '333333', ) ); ?> sanitize_instance( $instance ); $milestone = mktime( $instance['hour'], $instance['min'], 0, $instance['month'], $instance['day'], $instance['year'] ); $now = (int) current_time( 'timestamp' ); $diff = (int) floor( $milestone - $now ); $number = 0; $label = ''; if ( 63113852 < $diff ) { // more than 2 years - show in years, one decimal point $number = round( $diff / 60 / 60 / 24 / 365, 1 ); $label = self::$labels['years']; } else if ( 7775999 < $diff ) { // fewer than 2 years - show in months $number = floor( $diff / 60 / 60 / 24 / 30 ); $label = ( 1 == $number ) ? self::$labels['month'] : self::$labels['months']; } else if ( 86399 < $diff ) { // fewer than 3 months - show in days $number = floor( $diff / 60 / 60 / 24 ) + 1; $label = ( 1 == $number ) ? self::$labels['day'] : self::$labels['days']; } else if ( 3599 < $diff ) { // less than 1 day - show in hours $number = floor( $diff / 60 / 60 ); $label = ( 1 == $number ) ? self::$labels['hour'] : self::$labels['hours']; } else if ( 59 < $diff ) { // less than 1 hour - show in minutes $number = floor( $diff / 60 ) + 1; $label = ( 1 == $number ) ? self::$labels['minute'] : self::$labels['minutes']; } else { // less than 1 minute - show in seconds $number = $diff; $label = ( 1 == $number ) ? self::$labels['second'] : self::$labels['seconds'] ; } echo $args['before_widget']; $title = apply_filters( 'widget_title', $instance['title'] ); if ( ! empty( $title ) ) { echo $args['before_title'] . $title . $args['after_title']; } echo '