Completed
Push — test/fusion-bk ( 6474d6...2b2ed1 )
by
unknown
87:38 queued 80:14
created

Milestone_Widget::__construct()   A

Complexity

Conditions 4
Paths 2

Size

Total Lines 24

Duplication

Lines 3
Ratio 12.5 %

Importance

Changes 0
Metric Value
cc 4
nc 2
nop 0
dl 3
loc 24
rs 9.536
c 0
b 0
f 0
1
<?php
2
/*
3
Plugin Name: Milestone
4
Description: Countdown to a specific date.
5
Version: 1.0
6
Author: Automattic Inc.
7
Author URI: https://automattic.com/
8
License: GPLv2 or later
9
*/
10
11
use Automattic\Jetpack\Assets;
12
13
function jetpack_register_widget_milestone() {
14
	register_widget( 'Milestone_Widget' );
15
}
16
add_action( 'widgets_init', 'jetpack_register_widget_milestone' );
17
18
class Milestone_Widget extends WP_Widget {
19
	private static $dir       = null;
20
	private static $url       = null;
21
	private static $defaults  = null;
22
	private static $config_js = null;
23
24
	/**
25
	 * Available time units sorted in descending order.
26
	 *
27
	 * @var Array
28
	 */
29
	protected $available_units = array(
30
		'years',
31
		'months',
32
		'days',
33
		'hours',
34
		'minutes',
35
		'seconds',
36
	);
37
38
	function __construct() {
39
		$widget = array(
40
			'classname'   => 'milestone-widget',
41
			'description' => __( 'Display a countdown to a certain date.', 'jetpack' ),
42
		);
43
44
		parent::__construct(
45
			'Milestone_Widget',
46
			/** This filter is documented in modules/widgets/facebook-likebox.php */
47
			apply_filters( 'jetpack_widget_name', __( 'Milestone', 'jetpack' ) ),
48
			$widget
49
		);
50
51
		self::$dir = trailingslashit( dirname( __FILE__ ) );
52
		self::$url = plugin_dir_url( __FILE__ );
53
54
		add_action( 'wp_enqueue_scripts', array( __class__, 'enqueue_template' ) );
55
		add_action( 'admin_enqueue_scripts', array( __class__, 'enqueue_admin' ) );
56
		add_action( 'wp_footer', array( $this, 'localize_script' ) );
57
58 View Code Duplication
		if ( is_active_widget( false, false, $this->id_base, true ) || is_active_widget( false, false, 'monster', true ) || is_customize_preview() ) {
59
			add_action( 'wp_head', array( __class__, 'styles_template' ) );
60
		}
61
	}
62
63
	public static function enqueue_admin( $hook_suffix ) {
64
		if ( 'widgets.php' == $hook_suffix ) {
65
			wp_enqueue_style( 'milestone-admin', self::$url . 'style-admin.css', array(), '20161215' );
66
			wp_enqueue_script(
67
				'milestone-admin-js',
68
				Assets::get_file_url_for_environment(
69
					'_inc/build/widgets/milestone/admin.min.js',
70
					'modules/widgets/milestone/admin.js'
71
				),
72
				array( 'jquery' ),
73
				'20170915',
74
				true
75
			);
76
		}
77
	}
78
79
	public static function enqueue_template() {
80
		if ( Jetpack_AMP_Support::is_amp_request() ) {
81
			return;
82
		}
83
84
		wp_enqueue_script(
85
			'milestone',
86
			Assets::get_file_url_for_environment(
87
				'_inc/build/widgets/milestone/milestone.min.js',
88
				'modules/widgets/milestone/milestone.js'
89
			),
90
			array(),
91
			'20160520',
92
			true
93
		);
94
	}
95
96
	public static function styles_template() {
97
		global $themecolors;
98
		$colors = wp_parse_args(
99
			$themecolors,
100
			array(
0 ignored issues
show
Documentation introduced by
array('bg' => 'ffffff', ...c', 'text' => '333333') is of type array<string,string,{"bg...ring","text":"string"}>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
101
				'bg'     => 'ffffff',
102
				'border' => 'cccccc',
103
				'text'   => '333333',
104
			)
105
		);
106
		?>
107
<style>
108
.milestone-widget {
109
	margin-bottom: 1em;
110
}
111
.milestone-content {
112
	line-height: 2;
113
	margin-top: 5px;
114
	max-width: 100%;
115
	padding: 0;
116
	text-align: center;
117
}
118
.milestone-header {
119
	background-color: <?php echo self::sanitize_color_hex( $colors['text'] ); ?>;
120
	color: <?php echo self::sanitize_color_hex( $colors['bg'] ); ?>;
121
	line-height: 1.3;
122
	margin: 0;
123
	padding: .8em;
124
}
125
.milestone-header .event,
126
.milestone-header .date {
127
	display: block;
128
}
129
.milestone-header .event {
130
	font-size: 120%;
131
}
132
.milestone-countdown .difference {
133
	display: block;
134
	font-size: 500%;
135
	font-weight: bold;
136
	line-height: 1.2;
137
}
138
.milestone-countdown,
139
.milestone-message {
140
	background-color: <?php echo self::sanitize_color_hex( $colors['bg'] ); ?>;
141
	border: 1px solid <?php echo self::sanitize_color_hex( $colors['border'] ); ?>;
142
	border-top: 0;
143
	color: <?php echo self::sanitize_color_hex( $colors['text'] ); ?>;
144
	padding-bottom: 1em;
145
}
146
.milestone-message {
147
	padding-top: 1em
148
}
149
</style>
150
		<?php
151
	}
152
153
	/**
154
	 * Ensure that a string representing a color in hexadecimal
155
	 * notation is safe for use in css and database saves.
156
	 *
157
	 * @param string Color in hexadecimal notation. "#" may or may not be prepended to the string.
158
	 * @return string Color in hexadecimal notation on success - the string "transparent" otherwise.
159
	 */
160
	public static function sanitize_color_hex( $hex, $prefix = '#' ) {
161
		$hex = trim( $hex );
162
163
		/* Strip recognized prefixes. */
164
		if ( 0 === strpos( $hex, '#' ) ) {
165
			$hex = substr( $hex, 1 );
166
		} elseif ( 0 === strpos( $hex, '%23' ) ) {
167
			$hex = substr( $hex, 3 );
168
		}
169
170
		if ( 0 !== preg_match( '/^[0-9a-fA-F]{6}$/', $hex ) ) {
171
			return $prefix . $hex;
172
		}
173
174
		return 'transparent';
175
	}
176
177
	/**
178
	 * Localize Front-end Script.
179
	 *
180
	 * Print the javascript configuration array only if the
181
	 * current template has an instance of the widget that
182
	 * is still counting down. In all other cases, this
183
	 * function will dequeue milestone.js.
184
	 *
185
	 * Hooks into the "wp_footer" action.
186
	 */
187
	function localize_script() {
188
		if ( Jetpack_AMP_Support::is_amp_request() ) {
189
			return;
190
		}
191
192
		if ( empty( self::$config_js['instances'] ) ) {
193
			wp_dequeue_script( 'milestone' );
194
			return;
195
		}
196
		self::$config_js['api_root'] = esc_url_raw( rest_url() );
197
		wp_localize_script( 'milestone', 'MilestoneConfig', self::$config_js );
198
	}
199
200
	/**
201
	 * Widget
202
	 */
203
	function widget( $args, $instance ) {
204
		echo $args['before_widget'];
205
206
		/** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */
207
		$title = apply_filters( 'widget_title', $instance['title'] );
208
		if ( ! empty( $title ) ) {
209
			echo $args['before_title'] . $title . $args['after_title'];
210
		}
211
212
		$data   = $this->get_widget_data( $instance );
213
		$config = array(
214
			'id'      => $args['widget_id'],
215
			'message' => $data['message'],
216
			'refresh' => $data['refresh'],
217
		);
218
219
		/*
220
		 * Sidebars may be configured to not expose the `widget_id`. Example: `twentytwenty` footer areas.
221
		 *
222
		 * We need our own unique identifier.
223
		 */
224
		$config['content_id'] = $args['widget_id'] . '-content';
225
226
		self::$config_js['instances'][] = $config;
227
228
		echo sprintf( '<div id="%s" class="milestone-content">', esc_html( $config['content_id'] ) );
229
230
		echo '<div class="milestone-header">';
231
		echo '<strong class="event">' . esc_html( $instance['event'] ) . '</strong>';
232
		echo '<span class="date">' . esc_html( date_i18n( get_option( 'date_format' ), $data['milestone'] ) ) . '</span>';
233
		echo '</div>';
234
235
		echo $data['message'];
236
237
		echo '</div><!--milestone-content-->';
238
239
		echo $args['after_widget'];
240
241
		/** This action is documented in modules/widgets/gravatar-profile.php */
242
		do_action( 'jetpack_stats_extra', 'widget_view', 'milestone' );
243
	}
244
245
	function get_widget_data( $instance ) {
246
		$data = array();
247
248
		$instance = $this->sanitize_instance( $instance );
249
250
		$milestone = mktime( $instance['hour'], $instance['min'], 0, $instance['month'], $instance['day'], $instance['year'] );
251
		$now       = (int) current_time( 'timestamp' );
252
		$type      = $instance['type'];
253
254
		if ( 'since' === $type ) {
255
			$diff = (int) floor( $now - $milestone );
256
		} else {
257
			$diff = (int) floor( $milestone - $now );
258
		}
259
260
		$data['diff'] = $diff;
261
		$data['unit'] = $this->get_unit( $diff, $instance['unit'] );
262
263
		// Setting the refresh counter to equal the number of seconds it takes to flip a unit
264
		$refresh_intervals = array(
265
			0, // should be YEAR_IN_SECONDS, but doing setTimeout for a year doesn't seem to be logical
266
			0, // same goes for MONTH_IN_SECONDS,
267
			DAY_IN_SECONDS,
268
			HOUR_IN_SECONDS,
269
			MINUTE_IN_SECONDS,
270
			1,
271
		);
272
273
		$data['refresh']   = $refresh_intervals[ array_search( $data['unit'], $this->available_units ) ];
274
		$data['milestone'] = $milestone;
275
276
		if ( ( 1 > $diff ) && ( 'until' === $type ) ) {
277
			$data['message'] = '<div class="milestone-message">' . $instance['message'] . '</div>';
278
			$data['refresh'] = 0; // No need to refresh, the milestone has been reached
279
		} else {
280
			$interval_text = $this->get_interval_in_units( $diff, $data['unit'] );
281
			$interval      = intval( $interval_text );
282
283
			if ( 'since' === $type ) {
284
285 View Code Duplication
				switch ( $data['unit'] ) {
286
					case 'years':
287
						$data['message'] = sprintf(
288
							_n(
289
								'<span class="difference">%s</span> <span class="label">year ago.</span>',
290
								'<span class="difference">%s</span> <span class="label">years ago.</span>',
291
								$interval,
292
								'jetpack'
293
							),
294
							$interval_text
295
						);
296
						break;
297
					case 'months':
298
						$data['message'] = sprintf(
299
							_n(
300
								'<span class="difference">%s</span> <span class="label">month ago.</span>',
301
								'<span class="difference">%s</span> <span class="label">months ago.</span>',
302
								$interval,
303
								'jetpack'
304
							),
305
							$interval_text
306
						);
307
						break;
308
					case 'days':
309
						$data['message'] = sprintf(
310
							_n(
311
								'<span class="difference">%s</span> <span class="label">day ago.</span>',
312
								'<span class="difference">%s</span> <span class="label">days ago.</span>',
313
								$interval,
314
								'jetpack'
315
							),
316
							$interval_text
317
						);
318
						break;
319
					case 'hours':
320
						$data['message'] = sprintf(
321
							_n(
322
								'<span class="difference">%s</span> <span class="label">hour ago.</span>',
323
								'<span class="difference">%s</span> <span class="label">hours ago.</span>',
324
								$interval,
325
								'jetpack'
326
							),
327
							$interval_text
328
						);
329
						break;
330
					case 'minutes':
331
						$data['message'] = sprintf(
332
							_n(
333
								'<span class="difference">%s</span> <span class="label">minute ago.</span>',
334
								'<span class="difference">%s</span> <span class="label">minutes ago.</span>',
335
								$interval,
336
								'jetpack'
337
							),
338
							$interval_text
339
						);
340
						break;
341
					case 'seconds':
342
						$data['message'] = sprintf(
343
							_n(
344
								'<span class="difference">%s</span> <span class="label">second ago.</span>',
345
								'<span class="difference">%s</span> <span class="label">seconds ago.</span>',
346
								$interval,
347
								'jetpack'
348
							),
349
							$interval_text
350
						);
351
						break;
352
				}
353
			} else {
354 View Code Duplication
				switch ( $this->get_unit( $diff, $instance['unit'] ) ) {
355
					case 'years':
356
						$data['message'] = sprintf(
357
							_n(
358
								'<span class="difference">%s</span> <span class="label">year to go.</span>',
359
								'<span class="difference">%s</span> <span class="label">years to go.</span>',
360
								$interval,
361
								'jetpack'
362
							),
363
							$interval_text
364
						);
365
						break;
366
					case 'months':
367
						$data['message'] = sprintf(
368
							_n(
369
								'<span class="difference">%s</span> <span class="label">month to go.</span>',
370
								'<span class="difference">%s</span> <span class="label">months to go.</span>',
371
								$interval,
372
								'jetpack'
373
							),
374
							$interval_text
375
						);
376
						break;
377
					case 'days':
378
						$data['message'] = sprintf(
379
							_n(
380
								'<span class="difference">%s</span> <span class="label">day to go.</span>',
381
								'<span class="difference">%s</span> <span class="label">days to go.</span>',
382
								$interval,
383
								'jetpack'
384
							),
385
							$interval_text
386
						);
387
						break;
388
					case 'hours':
389
						$data['message'] = sprintf(
390
							_n(
391
								'<span class="difference">%s</span> <span class="label">hour to go.</span>',
392
								'<span class="difference">%s</span> <span class="label">hours to go.</span>',
393
								$interval,
394
								'jetpack'
395
							),
396
							$interval_text
397
						);
398
						break;
399
					case 'minutes':
400
						$data['message'] = sprintf(
401
							_n(
402
								'<span class="difference">%s</span> <span class="label">minute to go.</span>',
403
								'<span class="difference">%s</span> <span class="label">minutes to go.</span>',
404
								$interval,
405
								'jetpack'
406
							),
407
							$interval_text
408
						);
409
						break;
410
					case 'seconds':
411
						$data['message'] = sprintf(
412
							_n(
413
								'<span class="difference">%s</span> <span class="label">second to go.</span>',
414
								'<span class="difference">%s</span> <span class="label">seconds to go.</span>',
415
								$interval,
416
								'jetpack'
417
							),
418
							$interval_text
419
						);
420
						break;
421
				}
422
			}
423
			$data['message'] = '<div class="milestone-countdown">' . $data['message'] . '</div>';
424
		}
425
426
		return $data;
427
	}
428
429
	/**
430
	 * Return the largest possible time unit that the difference will be displayed in.
431
	 *
432
	 * @param Integer $seconds the interval in seconds
433
	 * @param String  $maximum_unit the maximum unit that will be used. Optional.
434
	 * @return String $calculated_unit
435
	 */
436
	protected function get_unit( $seconds, $maximum_unit = 'automatic' ) {
437
		$unit = '';
0 ignored issues
show
Unused Code introduced by
$unit is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
438
439
		if ( $seconds >= YEAR_IN_SECONDS * 2 ) {
440
			// more than 2 years - show in years, one decimal point
441
			$unit = 'years';
442
443
		} elseif ( $seconds >= YEAR_IN_SECONDS ) {
444
			if ( 'years' === $maximum_unit ) {
445
				$unit = 'years';
446
			} else {
447
				// automatic mode - showing months even if it's between one and two years
448
				$unit = 'months';
449
			}
450
		} elseif ( $seconds >= MONTH_IN_SECONDS * 3 ) {
451
			// fewer than 2 years - show in months
452
			$unit = 'months';
453
454
		} elseif ( $seconds >= MONTH_IN_SECONDS ) {
455
			if ( 'months' === $maximum_unit ) {
456
				$unit = 'months';
457
			} else {
458
				// automatic mode - showing days even if it's between one and three months
459
				$unit = 'days';
460
			}
461
		} elseif ( $seconds >= DAY_IN_SECONDS - 1 ) {
462
			// fewer than a month - show in days
463
			$unit = 'days';
464
465
		} elseif ( $seconds >= HOUR_IN_SECONDS - 1 ) {
466
			// less than 1 day - show in hours
467
			$unit = 'hours';
468
469
		} elseif ( $seconds >= MINUTE_IN_SECONDS - 1 ) {
470
			// less than 1 hour - show in minutes
471
			$unit = 'minutes';
472
473
		} else {
474
			// less than 1 minute - show in seconds
475
			$unit = 'seconds';
476
		}
477
478
		$maximum_unit_index = array_search( $maximum_unit, $this->available_units );
479
		$unit_index         = array_search( $unit, $this->available_units );
480
481
		if (
482
			false === $maximum_unit_index // the maximum unit parameter is automatic
483
			|| $unit_index > $maximum_unit_index // there is not enough seconds for even one maximum time unit
484
		) {
485
			return $unit;
486
		}
487
		return $maximum_unit;
488
	}
489
490
	/**
491
	 * Returns a time difference value in specified units.
492
	 *
493
	 * @param Integer $seconds
494
	 * @param String  $units
495
	 * @return Integer|String $time_in_units
496
	 */
497
	protected function get_interval_in_units( $seconds, $units ) {
498
		switch ( $units ) {
499
			case 'years':
500
				$years    = $seconds / YEAR_IN_SECONDS;
501
				$decimals = abs( round( $years, 1 ) - round( $years ) ) > 0 ? 1 : 0;
502
				return number_format_i18n( $years, $decimals );
503
			case 'months':
504
				return (int) ( $seconds / 60 / 60 / 24 / 30 );
505
			case 'days':
506
				return (int) ( $seconds / 60 / 60 / 24 + 1 );
507
			case 'hours':
508
				return (int) ( $seconds / 60 / 60 );
509
			case 'minutes':
510
				return (int) ( $seconds / 60 + 1 );
511
			default:
512
				return $seconds;
513
		}
514
	}
515
516
	/**
517
	 * Update
518
	 */
519
	function update( $new_instance, $old_instance ) {
520
		return $this->sanitize_instance( $new_instance );
521
	}
522
523
	/*
524
	 * Make sure that a number is within a certain range.
525
	 * If the number is too small it will become the possible lowest value.
526
	 * If the number is too large it will become the possible highest value.
527
	 *
528
	 * @param int $n The number to check.
529
	 * @param int $floor The lowest possible value.
530
	 * @param int $ceil The highest possible value.
531
	 */
532
	function sanitize_range( $n, $floor, $ceil ) {
533
		$n = (int) $n;
534
		if ( $n < $floor ) {
535
			$n = $floor;
536
		} elseif ( $n > $ceil ) {
537
			$n = $ceil;
538
		}
539
		return $n;
540
	}
541
542
	/*
543
	 * Sanitize an instance of this widget.
544
	 *
545
	 * Date ranges match the documentation for mktime in the php manual.
546
	 * @see https://php.net/manual/en/function.mktime.php#refsect1-function.mktime-parameters
547
	 *
548
	 * @uses Milestone_Widget::sanitize_range().
549
	 */
550
	function sanitize_instance( $dirty ) {
551
		$now = (int) current_time( 'timestamp' );
552
553
		$dirty = wp_parse_args(
554
			$dirty,
555
			array(
0 ignored issues
show
Documentation introduced by
array('title' => '', 'ev...hour' => 0, 'min' => 0) is of type array<string,?,{"title":...eger","min":"integer"}>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
556
				'title'   => '',
557
				'event'   => __( 'The Big Day', 'jetpack' ),
558
				'unit'    => 'automatic',
559
				'type'    => 'until',
560
				'message' => __( 'The big day is here.', 'jetpack' ),
561
				'day'     => date( 'd', $now ),
562
				'month'   => date( 'm', $now ),
563
				'year'    => date( 'Y', $now ),
564
				'hour'    => 0,
565
				'min'     => 0,
566
			)
567
		);
568
569
		$allowed_tags = array(
570
			'a'      => array(
571
				'title'  => array(),
572
				'href'   => array(),
573
				'target' => array(),
574
			),
575
			'em'     => array( 'title' => array() ),
576
			'strong' => array( 'title' => array() ),
577
		);
578
579
		$clean = array(
580
			'title'   => trim( strip_tags( stripslashes( $dirty['title'] ) ) ),
581
			'event'   => trim( strip_tags( stripslashes( $dirty['event'] ) ) ),
582
			'unit'    => $dirty['unit'],
583
			'type'    => $dirty['type'],
584
			'message' => wp_kses( $dirty['message'], $allowed_tags ),
585
			'year'    => $this->sanitize_range( $dirty['year'], 1901, 2037 ),
586
			'month'   => $this->sanitize_range( $dirty['month'], 1, 12 ),
587
			'hour'    => $this->sanitize_range( $dirty['hour'], 0, 23 ),
588
			'min'     => zeroise( $this->sanitize_range( $dirty['min'], 0, 59 ), 2 ),
589
		);
590
591
		$clean['day'] = $this->sanitize_range( $dirty['day'], 1, date( 't', mktime( 0, 0, 0, $clean['month'], 1, $clean['year'] ) ) );
592
593
		return $clean;
594
	}
595
596
	/**
597
	 * Form
598
	 */
599
	function form( $instance ) {
600
		$instance = $this->sanitize_instance( $instance );
601
602
		$units = array(
603
			'automatic' => _x( 'Automatic', 'Milestone widget: mode in which the date unit is determined automatically', 'jetpack' ),
604
			'years'     => _x( 'Years', 'Milestone widget: mode in which the date unit is set to years', 'jetpack' ),
605
			'months'    => _x( 'Months', 'Milestone widget: mode in which the date unit is set to months', 'jetpack' ),
606
			'days'      => _x( 'Days', 'Milestone widget: mode in which the date unit is set to days', 'jetpack' ),
607
			'hours'     => _x( 'Hours', 'Milestone widget: mode in which the date unit is set to hours', 'jetpack' ),
608
		);
609
		?>
610
611
	<div class="milestone-widget">
612
		<p>
613
			<label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title', 'jetpack' ); ?></label>
614
			<input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $instance['title'] ); ?>" />
615
		</p>
616
617
		<p>
618
			<label for="<?php echo $this->get_field_id( 'event' ); ?>"><?php _e( 'Description', 'jetpack' ); ?></label>
619
			<input class="widefat" id="<?php echo $this->get_field_id( 'event' ); ?>" name="<?php echo $this->get_field_name( 'event' ); ?>" type="text" value="<?php echo esc_attr( $instance['event'] ); ?>" />
620
		</p>
621
622
		<fieldset class="jp-ms-data-time">
623
			<legend><?php esc_html_e( 'Date', 'jetpack' ); ?></legend>
624
625
			<label for="<?php echo $this->get_field_id( 'month' ); ?>" class="assistive-text"><?php _e( 'Month', 'jetpack' ); ?></label>
626
			<select id="<?php echo $this->get_field_id( 'month' ); ?>" class="month" name="<?php echo $this->get_field_name( 'month' ); ?>">
627
								   <?php
628
									global $wp_locale;
629
									for ( $i = 1; $i < 13; $i++ ) {
630
										$monthnum = zeroise( $i, 2 );
631
										echo '<option value="' . esc_attr( $monthnum ) . '"' . selected( $i, $instance['month'], false ) . '>' . $monthnum . '-' . $wp_locale->get_month_abbrev( $wp_locale->get_month( $i ) ) . '</option>';
632
									}
633
									?>
634
			</select>
635
636
			<label for="<?php echo $this->get_field_id( 'day' ); ?>" class="assistive-text"><?php _e( 'Day', 'jetpack' ); ?></label>
637
			<input id="<?php echo $this->get_field_id( 'day' ); ?>" class="day" name="<?php echo $this->get_field_name( 'day' ); ?>" type="text" value="<?php echo esc_attr( $instance['day'] ); ?>">,
638
639
			<label for="<?php echo $this->get_field_id( 'year' ); ?>" class="assistive-text"><?php _e( 'Year', 'jetpack' ); ?></label>
640
			<input id="<?php echo $this->get_field_id( 'year' ); ?>" class="year" name="<?php echo $this->get_field_name( 'year' ); ?>" type="text" value="<?php echo esc_attr( $instance['year'] ); ?>">
641
		</fieldset>
642
643
		<fieldset class="jp-ms-data-time">
644
			<legend><?php esc_html_e( 'Time', 'jetpack' ); ?></legend>
645
646
			<label for="<?php echo $this->get_field_id( 'hour' ); ?>" class="assistive-text"><?php _e( 'Hour', 'jetpack' ); ?></label>
647
			<input id="<?php echo $this->get_field_id( 'hour' ); ?>" class="hour" name="<?php echo $this->get_field_name( 'hour' ); ?>" type="text" value="<?php echo esc_attr( $instance['hour'] ); ?>">
648
649
			<label for="<?php echo $this->get_field_id( 'min' ); ?>" class="assistive-text"><?php _e( 'Minutes', 'jetpack' ); ?></label>
650
651
			<span class="time-separator">:</span>
652
653
			<input id="<?php echo $this->get_field_id( 'min' ); ?>" class="minutes" name="<?php echo $this->get_field_name( 'min' ); ?>" type="text" value="<?php echo esc_attr( $instance['min'] ); ?>">
654
		</fieldset>
655
656
		<fieldset class="jp-ms-data-unit">
657
			<legend><?php esc_html_e( 'Time Unit', 'jetpack' ); ?></legend>
658
659
			<label for="<?php echo $this->get_field_id( 'unit' ); ?>" class="assistive-text">
660
				<?php _e( 'Time Unit', 'jetpack' ); ?>
661
			</label>
662
			<select id="<?php echo $this->get_field_id( 'unit' ); ?>" class="unit" name="<?php echo $this->get_field_name( 'unit' ); ?>">
663
			<?php
664
			foreach ( $units as $key => $unit ) {
665
				echo '<option value="' . esc_attr( $key ) . '"' . selected( $key, $instance['unit'], false ) . '>' . $unit . '</option>';
666
			}
667
			?>
668
			</select>
669
		</fieldset>
670
671
		<ul class="milestone-type">
672
			<li>
673
				<label>
674
					<input
675
						<?php checked( $instance['type'], 'until' ); ?>
676
						name="<?php echo esc_attr( $this->get_field_name( 'type' ) ); ?>"
677
						type="radio"
678
						value="until"
679
					/>
680
					<?php esc_html_e( 'Until your milestone', 'jetpack' ); ?>
681
				</label>
682
			</li>
683
684
			<li>
685
				<label>
686
					<input
687
						<?php checked( $instance['type'], 'since' ); ?>
688
						name="<?php echo esc_attr( $this->get_field_name( 'type' ) ); ?>"
689
						type="radio"
690
						value="since"
691
					/>
692
					<?php esc_html_e( 'Since your milestone', 'jetpack' ); ?>
693
				</label>
694
			</li>
695
		</ul>
696
697
		<p class="milestone-message-wrapper">
698
			<label for="<?php echo $this->get_field_id( 'message' ); ?>"><?php _e( 'Milestone Reached Message', 'jetpack' ); ?></label>
699
			<textarea id="<?php echo $this->get_field_id( 'message' ); ?>" name="<?php echo $this->get_field_name( 'message' ); ?>" class="widefat" rows="3"><?php echo esc_textarea( $instance['message'] ); ?></textarea>
700
		</p>
701
	</div>
702
703
		<?php
704
	}
705
}
706