From 8da42654c57573e7d241efadb0292b2ff6326537 Mon Sep 17 00:00:00 2001 From: danix Date: Wed, 4 Jul 2018 17:57:25 +0200 Subject: initial commit --- danixland-countdown.php | 194 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 194 insertions(+) create mode 100644 danixland-countdown.php (limited to 'danixland-countdown.php') diff --git a/danixland-countdown.php b/danixland-countdown.php new file mode 100644 index 0000000..c10f7a2 --- /dev/null +++ b/danixland-countdown.php @@ -0,0 +1,194 @@ + 400, 'height' => 350); + parent::__construct( + 'dnx-countdown', // id_base + __('danixland CountDown', 'dnxcd' ), // Name + array( 'description' => __('Use this widget to add a simple Count Down to your Sidebar', 'dnxcd') ), + $control_ops + ); + } + + /** + * How to display the widget on the public side of the site. + */ + public function widget( $args, $instance ) { + extract( $args ); + + /* Our variables from the widget settings. */ + $title = apply_filters('widget_title', $instance['title'] ); + + /* Before widget (defined by themes). */ + echo $before_widget; + + /* Display the widget title if one was input (before and after defined by themes). */ + if ( $title ) { + echo $before_title . $title . $after_title; + } + + if ( '' != get_option('dnxcd_future_date') ) { + echo '
'; + $date = gmdate('U', strtotime( get_option('dnxcd_future_date') )); + $diff = $date - gmdate('U'); + if ( '' != get_option('dnxcd_widget_link') ) { + echo ''; + echo '-' . floor($diff / (24 * 60 * 60)); + echo ''; + } else { + echo '-' . floor($diff / (24 * 60 * 60)); + } + echo '
'; + echo '
' . __('days to go', 'dnxcd') . '
'; + } else { + echo "
" . __('the date is missing
configure widget', 'dnxcd') . "
"; + } + + /* After widget (defined by themes). */ + echo $after_widget; + } + + //Update the widget + + public function update( $new_instance, $old_instance ) { + $instance = $old_instance; + + //Strip tags from title and name to remove HTML + $instance['title'] = sanitize_text_field( $new_instance['title'] ); + $instance['date'] = strip_tags( $new_instance['date'] ); + $instance['link'] = esc_url( $new_instance['link'], array('http', 'https') ); + $instance['style'] = (bool) $new_instance['style']; + + update_option( 'dnxcd_future_date', $instance['date'] ); + update_option( 'dnxcd_widget_link', $instance['link'] ); + update_option( 'dnxcd_use_style', $instance['style'] ); + + return $instance; + } + + /** + * Displays just a quick notice with a link to the Settings page + */ + public function form( $instance ) { + $defaults = array( + 'title' => __( 'Count Down', 'dnxcd' ), + 'date' => get_option( 'dnxcd_future_date' ), + 'link' => get_option( 'dnxcd_widget_link' ), + 'style' => get_option( 'dnxcd_use_style' ) + ); + $instance = wp_parse_args( (array) $instance, $defaults ); + extract( $instance, EXTR_SKIP ); + ?> + +

+ + +

+

+ + + + +

+

+ id="get_field_id( 'style' ); ?>" name="get_field_name( 'style' ); ?>" /> + +

+ -- cgit v1.2.3