| 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 |
echo $args['before_widget']; |
| 56 |
if(!empty($instance['title'])){ |
| 57 |
echo $args['before_title']; |
| 58 |
echo $instance['title']; |
| 59 |
echo $args['after_title']; |
| 60 |
} |
| 61 |
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>'; |
| 62 |
echo $args['after_widget']; |
| 63 |
} |
| 64 |
|
| 65 |
function update($new_instance, $old_instance) { |
| 66 |
return $new_instance; |
| 67 |
} |
| 68 |
|
| 69 |
function form($local_instance) { |
| 70 |
global $EventPost; |
| 71 |
$instance = wp_parse_args( (array) $local_instance, $this->defaults ); |
| 72 |
|
| 73 |
$cats = get_categories(); |
| 74 |
$thumbnail_sizes = $EventPost->get_thumbnail_sizes(); |
| 75 |
?> |
| 76 |
<input type="hidden" id="<?php echo $this->get_field_id('title'); ?>-title" value="<?php echo $instance['title']; ?>"> |
| 77 |
<p> |
| 78 |
<label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title','event-post'); ?> |
| 79 |
<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']; ?>" /> |
| 80 |
</label> |
| 81 |
</p> |
| 82 |
|
| 83 |
<p> |
| 84 |
<label for="<?php echo $this->get_field_id('cat'); ?>"><?php _e('Only in:','event-post'); ?> |
| 85 |
<select id="<?php echo $this->get_field_id('cat'); ?>" name="<?php echo $this->get_field_name('cat'); ?>"> |
| 86 |
<option value=''><?php _e('All','event-post') ?></option> |
| 87 |
<?php foreach($cats as $cat){ ?> |
| 88 |
<option value="<?php echo $cat->slug; ?>" <?php selected($cat->slug, $instance['cat'], true); ?>><?php echo $cat->cat_name; ?></option> |
| 89 |
<?php } ?> |
| 90 |
</select> |
| 91 |
</label> |
| 92 |
</p> |
| 93 |
|
| 94 |
<p> |
| 95 |
<label for="<?php echo $this->get_field_id('date'); ?>"><?php _e('Date','event-post'); ?> |
| 96 |
<select id="<?php echo $this->get_field_id('date'); ?>" name="<?php echo $this->get_field_name('date'); ?>"> |
| 97 |
<option value='' <?php selected($instance['date'], '', true); ?>><?php _e('Current','event-post'); ?></option> |
| 98 |
<option value='-1 Month' <?php selected($instance['date'], '-1 Month', true); ?>><?php _e('-1 Month','event-post'); ?></option> |
| 99 |
<option value='-2 Months' <?php selected($instance['date'], '-2 Months', true); ?>><?php _e('-2 Months','event-post'); ?></option> |
| 100 |
<option value='+1 Month' <?php selected($instance['date'],'+1 Month', true); ?>><?php _e('+1 Month','event-post'); ?></option> |
| 101 |
<option value='+2 Months' <?php selected($instance['date'], '+2 Months', true); ?>><?php _e('+2 Months','event-post'); ?></option> |
| 102 |
</select> |
| 103 |
</label> |
| 104 |
</p> |
| 105 |
|
| 106 |
<p> |
| 107 |
<label for="<?php echo $this->get_field_id('mf'); ?>"><?php _e('Weeks start on','event-post'); ?> |
| 108 |
<select id="<?php echo $this->get_field_id('mf'); ?>" name="<?php echo $this->get_field_name('mf'); ?>"> |
| 109 |
<option value="0" <?php selected($instance['mf'], 0, true); ?>><?php _e('Sunday','event-post'); ?></option> |
| 110 |
<option value="1" <?php selected($instance['mf'], 1, true); ?>><?php _e('Monday','event-post'); ?></option> |
| 111 |
</select> |
| 112 |
</label> |
| 113 |
</p> |
| 114 |
|
| 115 |
<p> |
| 116 |
<label for="<?php echo $this->get_field_id('choose'); ?>"><?php _e('Date picker','event-post'); ?> |
| 117 |
<select id="<?php echo $this->get_field_id('choose'); ?>" name="<?php echo $this->get_field_name('choose'); ?>"> |
| 118 |
<option value="0" <?php selected($instance['choose'], 0, true); ?>><?php _e('No','event-post'); ?></option> |
| 119 |
<option value="1" <?php selected($instance['choose'], 1, true); ?>><?php _e('Yes','event-post'); ?></option> |
| 120 |
</select> |
| 121 |
</label> |
| 122 |
</p> |
| 123 |
|
| 124 |
<p> |
| 125 |
<label for="<?php echo $this->get_field_id('colored'); ?>"><?php _e('Colored days','event-post'); ?> |
| 126 |
<select id="<?php echo $this->get_field_id('colored'); ?>" name="<?php echo $this->get_field_name('colored'); ?>"> |
| 127 |
<option value="0" <?php selected($instance['colored'], 0, true); ?>><?php _e('No','event-post'); ?></option> |
| 128 |
<option value="1" <?php selected($instance['colored'], 1, true); ?>><?php _e('Yes','event-post'); ?></option> |
| 129 |
</select> |
| 130 |
</label> |
| 131 |
</p> |
| 132 |
|
| 133 |
<p style="margin-top:10px;"> |
| 134 |
<label for="<?php echo $this->get_field_id('display_title'); ?>"> |
| 135 |
<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); ?>/> |
| 136 |
<?php _e('Display title','event-post'); ?> |
| 137 |
</label> |
| 138 |
</p> |
| 139 |
|
| 140 |
<p style="margin-top:10px;"> |
| 141 |
<label for="<?php echo $this->get_field_id('thumbnail'); ?>"> |
| 142 |
<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); ?>/> |
| 143 |
<?php _e('Show thumbnails','event-post'); ?> |
| 144 |
</label> |
| 145 |
</p> |
| 146 |
<p> |
| 147 |
<label for="<?php echo $this->get_field_id('thumbnail_size'); ?>"> |
| 148 |
<?php _e('Thumbnail size:','event-post'); ?> |
| 149 |
<select class="widefat" id="<?php echo $this->get_field_id('thumbnail_size'); ?>" name="<?php echo $this->get_field_name('thumbnail_size'); ?>"> |
| 150 |
<option value=''></option> |
| 151 |
<?php foreach($thumbnail_sizes as $size){?> |
| 152 |
<option value="<?php echo $size; ?>" <?php selected($size, $instance['thumbnail_size'], true); ?>><?php echo $size; ?></option> |
| 153 |
<?php } ?> |
| 154 |
</select> |
| 155 |
</label> |
| 156 |
</p> |
| 157 |
<?php |
| 158 |
} |
| 159 |
|
| 160 |
} |
| 161 |
|