1 | <?php |
---|
2 | /** |
---|
3 | * The calendar widget |
---|
4 | * @deprecated |
---|
5 | * @package event-post |
---|
6 | */ |
---|
7 | class EventPost_Cal extends WP_Widget { |
---|
8 | var $defaults; |
---|
9 | function __construct() { |
---|
10 | parent::__construct(false, __( 'Events Calendar', 'event-post' ),array('description'=>__( 'Calendar presentation of events posts', 'event-post' ))); |
---|
11 | $this->defaults = array( |
---|
12 | 'title' => '', |
---|
13 | 'cat' => '', |
---|
14 | 'date' => date('Y-n'), |
---|
15 | 'mf' => 0, |
---|
16 | 'choose' => 1, |
---|
17 | 'colored' => 1, |
---|
18 | 'display_title' => 0, |
---|
19 | 'thumbnail' => 0, |
---|
20 | 'thumbnail_size' => '', |
---|
21 | ); |
---|
22 | } |
---|
23 | public function eventpostcal_widget(){ |
---|
24 | $this->__construct(); |
---|
25 | } |
---|
26 | function widget($args, $local_instance) { |
---|
27 | if(!defined('ALLOW_DEPRECATED') || !ALLOW_DEPRECATED) { |
---|
28 | _deprecated_function(__FUNCTION__, '5.9.0', __('Legacy widgets have been deprecated. Consider using blocks instead.', 'event-post')); |
---|
29 | } |
---|
30 | extract( $args ); |
---|
31 | $instance = wp_parse_args((array) $local_instance, $this->defaults); |
---|
32 | |
---|
33 | $date = !empty($instance['date'])?date('Y-n',strtotime(esc_attr($instance['date']))):date('Y-n'); |
---|
34 | $cat = sanitize_text_field($instance['cat']); |
---|
35 | $mf = intval($instance['mf']); |
---|
36 | $choose = intval($instance['choose']); |
---|
37 | $colored = intval($instance['colored']); |
---|
38 | $display_title = intval($instance['display_title']); |
---|
39 | $thumbnail = sanitize_text_field($instance['thumbnail']); |
---|
40 | $thumbnail_size = $thumbnail ? sanitize_text_field($instance['thumbnail_size']) : ''; |
---|
41 | |
---|
42 | global $EventPost; |
---|
43 | $events = $EventPost->get_events( |
---|
44 | array( |
---|
45 | 'nb'=>-1, |
---|
46 | 'future'=>1, |
---|
47 | 'past'=>1, |
---|
48 | 'geo'=>0, |
---|
49 | 'cat'=>$cat |
---|
50 | ) |
---|
51 | ); |
---|
52 | if(count($events)==0){ |
---|
53 | return; |
---|
54 | } |
---|
55 | $EventPost->load_scripts(); |
---|
56 | echo $args['before_widget']; |
---|
57 | if(!empty($instance['title'])){ |
---|
58 | echo $args['before_title']; |
---|
59 | echo $instance['title']; |
---|
60 | echo $args['after_title']; |
---|
61 | } |
---|
62 | echo '<div class="eventpost_calendar" data-cat="'.$cat.'" data-date="'.$date.'" data-mf="'.$mf.'" data-dp="'.$choose.'" data-color="'.$colored.'" data-title="'.$display_title.'" data-thumbnail="'.($thumbnail?$thumbnail_size:'').'"></div>'; |
---|
63 | echo $args['after_widget']; |
---|
64 | } |
---|
65 | |
---|
66 | function update($new_instance, $old_instance) { |
---|
67 | return $new_instance; |
---|
68 | } |
---|
69 | |
---|
70 | function form($local_instance) { |
---|
71 | global $EventPost; |
---|
72 | $instance = wp_parse_args( (array) $local_instance, $this->defaults ); |
---|
73 | |
---|
74 | $cats = get_categories(); |
---|
75 | $thumbnail_sizes = $EventPost->get_thumbnail_sizes(); |
---|
76 | ?> |
---|
77 | <input type="hidden" id="<?php echo $this->get_field_id('title'); ?>-title" value="<?php echo $instance['title']; ?>"> |
---|
78 | <p> |
---|
79 | <label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title','event-post'); ?> |
---|
80 | <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $instance['title']; ?>" /> |
---|
81 | </label> |
---|
82 | </p> |
---|
83 | |
---|
84 | <p> |
---|
85 | <label for="<?php echo $this->get_field_id('cat'); ?>"><?php _e('Only in:','event-post'); ?> |
---|
86 | <select id="<?php echo $this->get_field_id('cat'); ?>" name="<?php echo $this->get_field_name('cat'); ?>"> |
---|
87 | <option value=''><?php _e('All','event-post') ?></option> |
---|
88 | <?php foreach($cats as $cat){ ?> |
---|
89 | <option value="<?php echo $cat->slug; ?>" <?php selected($cat->slug, $instance['cat'], true); ?>><?php echo $cat->cat_name; ?></option> |
---|
90 | <?php } ?> |
---|
91 | </select> |
---|
92 | </label> |
---|
93 | </p> |
---|
94 | |
---|
95 | <p> |
---|
96 | <label for="<?php echo $this->get_field_id('date'); ?>"><?php _e('Date','event-post'); ?> |
---|
97 | <select id="<?php echo $this->get_field_id('date'); ?>" name="<?php echo $this->get_field_name('date'); ?>"> |
---|
98 | <option value='' <?php selected($instance['date'], '', true); ?>><?php _e('Current','event-post'); ?></option> |
---|
99 | <option value='-1 Month' <?php selected($instance['date'], '-1 Month', true); ?>><?php _e('-1 Month','event-post'); ?></option> |
---|
100 | <option value='-2 Months' <?php selected($instance['date'], '-2 Months', true); ?>><?php _e('-2 Months','event-post'); ?></option> |
---|
101 | <option value='+1 Month' <?php selected($instance['date'],'+1 Month', true); ?>><?php _e('+1 Month','event-post'); ?></option> |
---|
102 | <option value='+2 Months' <?php selected($instance['date'], '+2 Months', true); ?>><?php _e('+2 Months','event-post'); ?></option> |
---|
103 | </select> |
---|
104 | </label> |
---|
105 | </p> |
---|
106 | |
---|
107 | <p> |
---|
108 | <label for="<?php echo $this->get_field_id('mf'); ?>"><?php _e('Weeks start on','event-post'); ?> |
---|
109 | <select id="<?php echo $this->get_field_id('mf'); ?>" name="<?php echo $this->get_field_name('mf'); ?>"> |
---|
110 | <option value="0" <?php selected($instance['mf'], 0, true); ?>><?php _e('Sunday','event-post'); ?></option> |
---|
111 | <option value="1" <?php selected($instance['mf'], 1, true); ?>><?php _e('Monday','event-post'); ?></option> |
---|
112 | </select> |
---|
113 | </label> |
---|
114 | </p> |
---|
115 | |
---|
116 | <p> |
---|
117 | <label for="<?php echo $this->get_field_id('choose'); ?>"><?php _e('Date picker','event-post'); ?> |
---|
118 | <select id="<?php echo $this->get_field_id('choose'); ?>" name="<?php echo $this->get_field_name('choose'); ?>"> |
---|
119 | <option value="0" <?php selected($instance['choose'], 0, true); ?>><?php _e('No','event-post'); ?></option> |
---|
120 | <option value="1" <?php selected($instance['choose'], 1, true); ?>><?php _e('Yes','event-post'); ?></option> |
---|
121 | </select> |
---|
122 | </label> |
---|
123 | </p> |
---|
124 | |
---|
125 | <p> |
---|
126 | <label for="<?php echo $this->get_field_id('colored'); ?>"><?php _e('Colored days','event-post'); ?> |
---|
127 | <select id="<?php echo $this->get_field_id('colored'); ?>" name="<?php echo $this->get_field_name('colored'); ?>"> |
---|
128 | <option value="0" <?php selected($instance['colored'], 0, true); ?>><?php _e('No','event-post'); ?></option> |
---|
129 | <option value="1" <?php selected($instance['colored'], 1, true); ?>><?php _e('Yes','event-post'); ?></option> |
---|
130 | </select> |
---|
131 | </label> |
---|
132 | </p> |
---|
133 | |
---|
134 | <p style="margin-top:10px;"> |
---|
135 | <label for="<?php echo $this->get_field_id('display_title'); ?>"> |
---|
136 | <input id="<?php echo $this->get_field_id('display_title'); ?>" name="<?php echo $this->get_field_name('display_title'); ?>" type="checkbox" value="1" <?php checked($instance['display_title'], true , true); ?>/> |
---|
137 | <?php _e('Display title','event-post'); ?> |
---|
138 | </label> |
---|
139 | </p> |
---|
140 | |
---|
141 | <p style="margin-top:10px;"> |
---|
142 | <label for="<?php echo $this->get_field_id('thumbnail'); ?>"> |
---|
143 | <input id="<?php echo $this->get_field_id('thumbnail'); ?>" name="<?php echo $this->get_field_name('thumbnail'); ?>" type="checkbox" value="1" <?php checked($instance['thumbnail'], true , true); ?>/> |
---|
144 | <?php _e('Show thumbnails','event-post'); ?> |
---|
145 | </label> |
---|
146 | </p> |
---|
147 | <p> |
---|
148 | <label for="<?php echo $this->get_field_id('thumbnail_size'); ?>"> |
---|
149 | <?php _e('Thumbnail size:','event-post'); ?> |
---|
150 | <select class="widefat" id="<?php echo $this->get_field_id('thumbnail_size'); ?>" name="<?php echo $this->get_field_name('thumbnail_size'); ?>"> |
---|
151 | <option value=''></option> |
---|
152 | <?php foreach($thumbnail_sizes as $size){?> |
---|
153 | <option value="<?php echo $size; ?>" <?php selected($size, $instance['thumbnail_size'], true); ?>><?php echo $size; ?></option> |
---|
154 | <?php } ?> |
---|
155 | </select> |
---|
156 | </label> |
---|
157 | </p> |
---|
158 | <?php |
---|
159 | } |
---|
160 | |
---|
161 | } |
---|