This repository has been archived by the owner on Mar 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwidget.cal.php
146 lines (131 loc) · 6.5 KB
/
widget.cal.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
<?php
/** Articles de catgorie **/
class eventpostcal_widget extends WP_Widget {
var $defaults;
function __construct() {
parent::__construct(false, __( 'Events calendar', 'event-post' ),array('description'=>__( 'Calendar presentation of events posts', 'event-post' )));
$this->defaults = array(
'title' => '',
'cat' => '',
'date' => date('Y-n'),
'mf' => 0,
'choose' => 1,
'colored' => 1,
'thumbnail' => 0,
'thumbnail_size' => '',
);
}
public function eventpostcal_widget(){
$this->__construct();
}
function widget($args, $local_instance) {
extract( $args );
$instance = wp_parse_args((array) $local_instance, $this->defaults);
$date = !empty($instance['date'])?date('Y-n',strtotime(esc_attr($instance['date']))):date('Y-n');
global $EventPost;
$events = $EventPost->get_events(
array(
'nb'=>-1,
'future'=>1,
'past'=>1,
'geo'=>0,
'cat'=>$instance['cat']
)
);
if(count($events)==0){
return;
}
$EventPost->load_scripts();
echo $args['before_widget'];
if(!empty($title)){
echo $args['before_title'];
echo $instance['title'];
echo $args['after_title'];
}
echo '<div class="eventpost_calendar" data-cat="'.$instance['cat'].'" data-date="'.$date.'" data-mf="'.$instance['mf'].'" data-dp="'.$instance['choose'].'" data-color="'.$instance['colored'].'" data-thumbnail="'.($instance['thumbnail']?$instance['thumbnail_size']:'').'"></div>';
echo $args['after_widget'];
}
function update($new_instance, $old_instance) {
return $new_instance;
}
function form($local_instance) {
global $EventPost;
$instance = wp_parse_args( (array) $local_instance, $this->defaults );
$cats = get_categories();
$thumbnail_sizes = $EventPost->get_thumbnail_sizes();
?>
<input type="hidden" id="<?php echo $this->get_field_id('title'); ?>-title" value="<?php echo $instance['title']; ?>">
<p>
<label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title','event-post'); ?>
<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']; ?>" />
</label>
</p>
<p>
<label for="<?php echo $this->get_field_id('cat'); ?>"><?php _e('Only in :','event-post'); ?>
<select id="<?php echo $this->get_field_id('cat'); ?>" name="<?php echo $this->get_field_name('cat'); ?>">
<option value=''><?php _e('All','event-post') ?></option>
<?php foreach($cats as $cat){ ?>
<option value="<?php echo $cat->slug; ?>" <?php selected($cat->slug, $instance['cat'], true); ?>><?php echo $cat->cat_name; ?></option>
<?php } ?>
</select>
</label>
</p>
<p>
<label for="<?php echo $this->get_field_id('date'); ?>"><?php _e('Date','event-post'); ?>
<select id="<?php echo $this->get_field_id('date'); ?>" name="<?php echo $this->get_field_name('date'); ?>">
<option value='' <?php selected($instance['date'], '', true); ?>><?php _e('Current','event-post'); ?></option>
<option value='-1 Month' <?php selected($instance['date'], '-1 Month', true); ?>><?php _e('-1 Month','event-post'); ?></option>
<option value='-2 Months' <?php selected($instance['date'], '-2 Months', true); ?>><?php _e('-2 Months','event-post'); ?></option>
<option value='+1 Month' <?php selected($instance['date'],'+1 Month', true); ?>><?php _e('+1 Month','event-post'); ?></option>
<option value='+2 Months' <?php selected($instance['date'], '+2 Months', true); ?>><?php _e('+2 Months','event-post'); ?></option>
</select>
</label>
</p>
<p>
<label for="<?php echo $this->get_field_id('mf'); ?>"><?php _e('Weeks start on','event-post'); ?>
<select id="<?php echo $this->get_field_id('mf'); ?>" name="<?php echo $this->get_field_name('mf'); ?>">
<option value="0" <?php selected($instance['mf'], 0, true); ?>><?php _e('Sunday','event-post'); ?></option>
<option value="1" <?php selected($instance['mf'], 1, true); ?>><?php _e('Monday','event-post'); ?></option>
</select>
</label>
</p>
<p>
<label for="<?php echo $this->get_field_id('choose'); ?>"><?php _e('Date picker','event-post'); ?>
<select id="<?php echo $this->get_field_id('choose'); ?>" name="<?php echo $this->get_field_name('choose'); ?>">
<option value="0" <?php selected($instance['choose'], 0, true); ?>><?php _e('No','event-post'); ?></option>
<option value="1" <?php selected($instance['choose'], 1, true); ?>><?php _e('Yes','event-post'); ?></option>
</select>
</label>
</p>
<p>
<label for="<?php echo $this->get_field_id('colored'); ?>"><?php _e('Colored days','event-post'); ?>
<select id="<?php echo $this->get_field_id('colored'); ?>" name="<?php echo $this->get_field_name('colored'); ?>">
<option value="0" <?php selected($instance['colored'], 0, true); ?>><?php _e('No','event-post'); ?></option>
<option value="1" <?php selected($instance['colored'], 1, true); ?>><?php _e('Yes','event-post'); ?></option>
</select>
</label>
</p>
<p style="margin-top:10px;">
<label for="<?php echo $this->get_field_id('thumbnail'); ?>">
<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); ?>/>
<?php _e('Show thumbnails','event-post'); ?>
</label>
</p>
<p>
<label for="<?php echo $this->get_field_id('thumbnail_size'); ?>">
<?php _e('Thumbnail size:','event-post'); ?>
<select class="widefat" id="<?php echo $this->get_field_id('thumbnail_size'); ?>" name="<?php echo $this->get_field_name('thumbnail_size'); ?>">
<option value=''></option>
<?php foreach($thumbnail_sizes as $size){?>
<option value="<?php echo $size; ?>" <?php selected($size, $instance['thumbnail_size'], true); ?>><?php echo $size; ?></option>
<?php } ?>
</select>
</label>
</p>
<?php
}
}
function register_eventpostcal_widget(){
register_widget('eventpostcal_widget');
}
add_action('widgets_init', 'register_eventpostcal_widget');