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: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210: 211: 212: 213: 214: 215: 216: 217: 218: 219: 220: 221: 222: 223: 224: 225: 226: 227: 228: 229: 230: 231: 232: 233: 234: 235: 236: 237: 238: 239: 240: 241: 242: 243: 244: 245: 246: 247: 248:
<?php
class EventPost_Map extends WP_Widget {
var $defaults;
function __construct() {
global $EventPost;
parent::__construct(false, __( 'Events Map', 'event-post' ),array('description'=>__( 'Map of events posts', 'event-post' )));
$this->defaults = array(
'numberposts' => '',
'widgettitle' => '',
'cat' => '',
'tag' => '',
'height' => '',
'width' => '',
'future' => 0,
'past' => 0,
'thumbnail' => 0,
'thumbnail_size' => '',
'excerpt' => 0,
'tile' => $EventPost->settings['tile'],
'zoom' => '',
);
foreach($EventPost->map_interactions as $int_key=>$int_name){
$this->defaults[$int_key]=true;
}
}
public function EventPost_Map(){
$this->__construct();
}
function widget($args, $local_instance) {
if(!defined('ALLOW_DEPRECATED') || !ALLOW_DEPRECATED) {
_deprecated_function(__FUNCTION__, '5.9.0', __('Legacy widgets have been deprecated. Consider using blocks instead.', 'event-post'));
}
global $EventPost;
extract( $args );
$instance = wp_parse_args((array) $local_instance, $this->defaults);
$numberposts = intval($instance['numberposts']);
$future = intval($instance['future']);
$past = intval($instance['past']);
$cat = sanitize_text_field($instance['cat']);
$tag = sanitize_text_field($instance['tag']);
$events = $EventPost->get_events(
array(
'nb' => $numberposts,
'future' => $future,
'past' => $past,
'geo' => 1,
'cat' => $cat,
'tag' => $tag
)
);
if (sizeof($events) > 0) {
echo $args['before_widget'];
if (!empty($instance['widgettitle'])) {
echo $args['before_title'];
echo $instance['widgettitle'];
echo $args['after_title'];
}
$atts = array(
'events' => $events,
'width' => esc_attr($instance['width']),
'height' => esc_attr($instance['height']),
'zoom' => esc_attr($instance['zoom']),
'geo' => 1,
'class' => 'eventpost_widget',
'thumbnail' => esc_attr($instance['thumbnail']),
'thumbnail_size' => esc_attr($instance['thumbnail_size']),
'excerpt' => esc_attr($instance['excerpt']),
'tile' => esc_attr($instance['tile'])
);
foreach($EventPost->map_interactions as $int_key=>$int_name){
$atts[$int_key] = isset($instance[$int_key]) ? esc_attr($instance[$int_key]) : '';
}
echo $EventPost->list_events($atts, 'event_geolist', 'widget');
echo $args['after_widget'];
}
}
function update($new_instance, $old_instance) {
global $EventPost;
foreach($EventPost->map_interactions as $int_key=>$int_name){
if(!isset($new_instance[$int_key])){
$new_instance[$int_key]=false;
}
}
return $new_instance;
}
function form($local_instance) {
global $EventPost;
$instance = wp_parse_args( (array) $local_instance, $this->defaults );
$cats = get_categories();
$tags = get_tags();
$thumbnail_sizes = $EventPost->get_thumbnail_sizes();
?>
<input type="hidden" id="<?php echo $this->get_field_id('widgettitle'); ?>-title" value="<?php echo $instance['widgettitle']; ?>">
<p>
<label for="<?php echo $this->get_field_id('widgettitle'); ?>"><?php _e('Title','event-post'); ?>
<input class="widefat" id="<?php echo $this->get_field_id('widgettitle'); ?>" name="<?php echo $this->get_field_name('widgettitle'); ?>" type="text" value="<?php echo $instance['widgettitle']; ?>" />
</label>
</p>
<p style="margin-top:10px;">
<label for="<?php echo $this->get_field_id('numberposts'); ?>"><?php _e('Number of posts','event-post'); ?>
<input id="<?php echo $this->get_field_id('numberposts'); ?>" name="<?php echo $this->get_field_name('numberposts'); ?>" type="number" value="<?php echo $instance['numberposts']; ?>" />
</label> <?php _e('(-1 is no limit)','event-post'); ?>
</p>
<p style="margin-top:10px;">
<label for="<?php echo $this->get_field_id('future'); ?>">
<input id="<?php echo $this->get_field_id('future'); ?>" name="<?php echo $this->get_field_name('future'); ?>" type="checkbox" value="1" <?php checked($instance['future'], true , true); ?> />
<?php _e('Display future events','event-post'); ?>
</label>
</p>
<p style="margin-top:10px;">
<label for="<?php echo $this->get_field_id('past'); ?>">
<input id="<?php echo $this->get_field_id('past'); ?>" name="<?php echo $this->get_field_name('past'); ?>" type="checkbox" value="1" <?php checked($instance['past'], true , true); ?> />
<?php _e('Display past events','event-post'); ?>
</label>
</p>
<p>
<label for="<?php echo $this->get_field_id('cat'); ?>">
<span class="dashicons dashicons-category"></span>
<?php _e('Only in:','event-post'); ?>
<select class="widefat" id="<?php echo $this->get_field_id('cat'); ?>" name="<?php echo $this->get_field_name('cat'); ?>">
<option value=''><?php _e('All categories','event-post') ?></option>
<?php
$cats = get_categories();
foreach($cats as $_cat){ ?>
<option value="<?=$_cat->slug?>" <?php selected($instance['cat'], $_cat->slug , true); ?>><?=$_cat->cat_name?></option>
<?php } ?>
</select>
</label>
</p>
<p>
<label for="<?php echo $this->get_field_id('tag'); ?>">
<span class="dashicons dashicons-tag"></span>
<?php _e('Only in:','event-post'); ?>
<select class="widefat" id="<?php echo $this->get_field_id('tag'); ?>" name="<?php echo $this->get_field_name('tag'); ?>">
<option value=''><?php _e('All tags','event-post') ?></option>
<?php
$tags = get_tags();
foreach($tags as $_tag){?>
<option value="<?=$_tag->slug?>" <?php selected($instance['tag'], $_tag->slug , true); ?>><?=$_tag->name?></option>
<?php } ?>
</select>
</label>
</p>
<hr>
<p style="margin-top:10px;">
<label for="<?php echo $this->get_field_id('width'); ?>"><?php _e('Width','event-post'); ?>
<input id="<?php echo $this->get_field_id('width'); ?>" name="<?php echo $this->get_field_name('width'); ?>" value="<?php echo $instance['width']; ?>" />
</label> (px, %)
</p>
<p style="margin-top:10px;">
<label for="<?php echo $this->get_field_id('height'); ?>"><?php _e('Height','event-post'); ?>
<input id="<?php echo $this->get_field_id('height'); ?>" name="<?php echo $this->get_field_name('height'); ?>" value="<?php echo $instance['height']; ?>" />
</label> (px, %)
</p>
<p style="margin-top:10px;">
<label for="<?php echo $this->get_field_id('zoom'); ?>"><?php _e('Force zoom','event-post'); ?>
<input id="<?php echo $this->get_field_id('zoom'); ?>" name="<?php echo $this->get_field_name('zoom'); ?>" value="<?php echo $instance['zoom']; ?>" type="number" min="3" max="20" size="2"/>
</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>
<p style="margin-top:10px;">
<label for="<?php echo $this->get_field_id('excerpt'); ?>">
<input id="<?php echo $this->get_field_id('excerpt'); ?>" name="<?php echo $this->get_field_name('excerpt'); ?>" type="checkbox" value="1" <?php checked($instance['excerpt'], true , true); ?> />
<?php _e('Show excerpt','event-post'); ?>
</label>
</p>
<p style="margin-top:10px;">
<label for="<?php echo $this->get_field_id('tile'); ?>">
<?php _e('Map background', 'event-post'); ?>
<select id="<?php echo $this->get_field_id('tile'); ?>" name="<?php echo $this->get_field_name('tile'); ?>">
<?php
foreach ($EventPost->maps as $id => $map):
?>
<option value="<?php
if ($EventPost->settings['tile'] != $map['id']) {
echo $map['id'];
}
?>" <?php selected($instance['tile'], $id, true);?>>
<?php echo $map['name']; ?><?php
if ($EventPost->settings['tile'] == $map['id']) {
echo' (default)';
}
?>
</option>
<?php endforeach; ?>
</select>
</label>
</p>
<hr>
<?php foreach($EventPost->map_interactions as $int_key=>$int_name): ?>
<p>
<label for="<?php echo $this->get_field_id($int_key); ?>">
<input id="<?php echo $this->get_field_id($int_key); ?>" name="<?php echo $this->get_field_name($int_key); ?>" type="checkbox" value="1" <?php checked($instance[$int_key], true , true); ?>/>
<?php printf(__('Activate %s interaction','event-post'), $int_name); ?>
</label>
</p>
<?php endforeach; ?>
<?php
}
}