1: <?php
2: /**
3: * The Map widget
4: * Displays a map of geolocalized posts
5: * @deprecated
6: * @package event-post
7: */
8:
9: if ( ! defined( 'ABSPATH' ) ) exit;
10:
11: class EventPost_Map extends WP_Widget {
12: var $defaults;
13: function __construct() {
14: global $EventPost;
15: parent::__construct(false, __( 'Events Map', 'event-post' ),array('description'=>__( 'Map of events posts', 'event-post' )));
16: $this->defaults = array(
17: 'numberposts' => '',
18: 'widgettitle' => '',
19: 'cat' => '',
20: 'tag' => '',
21: 'height' => '',
22: 'width' => '',
23: 'future' => 0,
24: 'past' => 0,
25: 'thumbnail' => 0,
26: 'thumbnail_size' => '',
27: 'excerpt' => 0,
28: 'tile' => $EventPost->settings['tile'],
29: 'zoom' => '',
30: );
31: // UI options
32: foreach($EventPost->map_interactions as $int_key=>$int_name){
33: $this->defaults[$int_key]=true;
34: }
35: }
36: public function EventPost_Map(){
37: $this->__construct();
38: }
39: function widget($args, $local_instance) {
40: if(!defined('ALLOW_DEPRECATED') || !ALLOW_DEPRECATED) {
41: _deprecated_function(__FUNCTION__, '5.9.0', __('Legacy widgets have been deprecated. Consider using blocks instead.', 'event-post'));
42: }
43: global $EventPost;
44: extract( $args );
45: $instance = wp_parse_args((array) $local_instance, $this->defaults);
46:
47: $numberposts = intval($instance['numberposts']);
48: $future = intval($instance['future']);
49: $past = intval($instance['past']);
50: $cat = sanitize_text_field($instance['cat']);
51: $tag = sanitize_text_field($instance['tag']);
52:
53: $events = $EventPost->get_events(
54: array(
55: 'nb' => $numberposts,
56: 'future' => $future,
57: 'past' => $past,
58: 'geo' => 1,
59: 'cat' => $cat,
60: 'tag' => $tag
61: )
62: );
63: if (sizeof($events) > 0) {
64: echo $args['before_widget'];
65: if (!empty($instance['widgettitle'])) {
66: echo $args['before_title'];
67: echo $instance['widgettitle'];
68: echo $args['after_title'];
69: }
70: $atts = array(
71: 'events' => $events,
72: 'width' => esc_attr($instance['width']),
73: 'height' => esc_attr($instance['height']),
74: 'zoom' => esc_attr($instance['zoom']),
75: 'geo' => 1,
76: 'class' => 'eventpost_widget',
77: 'thumbnail' => esc_attr($instance['thumbnail']),
78: 'thumbnail_size' => esc_attr($instance['thumbnail_size']),
79: 'excerpt' => esc_attr($instance['excerpt']),
80: 'tile' => esc_attr($instance['tile'])
81: );
82: foreach($EventPost->map_interactions as $int_key=>$int_name){
83: $atts[$int_key] = isset($instance[$int_key]) ? esc_attr($instance[$int_key]) : '';
84: }
85: echo $EventPost->list_events($atts, 'event_geolist', 'widget');
86: echo $args['after_widget'];
87: }
88: }
89: /**
90: *
91: * @global object $EventPost
92: * @param array $new_instance
93: * @param array $old_instance
94: * @return array
95: */
96: function update($new_instance, $old_instance) {
97: global $EventPost;
98: foreach($EventPost->map_interactions as $int_key=>$int_name){
99: if(!isset($new_instance[$int_key])){
100: $new_instance[$int_key]=false;
101: }
102: }
103: return $new_instance;
104: }
105: /**
106: *
107: * @global object $EventPost
108: * @param array $instance
109: */
110: function form($local_instance) {
111: global $EventPost;
112: $instance = wp_parse_args( (array) $local_instance, $this->defaults );
113:
114: $cats = get_categories();
115: $tags = get_tags();
116: $thumbnail_sizes = $EventPost->get_thumbnail_sizes();
117: ?>
118: <input type="hidden" id="<?php echo $this->get_field_id('widgettitle'); ?>-title" value="<?php echo $instance['widgettitle']; ?>">
119: <p>
120: <label for="<?php echo $this->get_field_id('widgettitle'); ?>"><?php _e('Title','event-post'); ?>
121: <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']; ?>" />
122: </label>
123: </p>
124:
125: <p style="margin-top:10px;">
126: <label for="<?php echo $this->get_field_id('numberposts'); ?>"><?php _e('Number of posts','event-post'); ?>
127: <input id="<?php echo $this->get_field_id('numberposts'); ?>" name="<?php echo $this->get_field_name('numberposts'); ?>" type="number" value="<?php echo $instance['numberposts']; ?>" />
128: </label> <?php _e('(-1 is no limit)','event-post'); ?>
129: </p>
130:
131:
132: <p style="margin-top:10px;">
133: <label for="<?php echo $this->get_field_id('future'); ?>">
134: <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); ?> />
135: <?php _e('Display future events','event-post'); ?>
136: </label>
137: </p>
138: <p style="margin-top:10px;">
139: <label for="<?php echo $this->get_field_id('past'); ?>">
140: <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); ?> />
141: <?php _e('Display past events','event-post'); ?>
142: </label>
143: </p>
144:
145: <p>
146: <label for="<?php echo $this->get_field_id('cat'); ?>">
147: <span class="dashicons dashicons-category"></span>
148: <?php _e('Only in:','event-post'); ?>
149: <select class="widefat" id="<?php echo $this->get_field_id('cat'); ?>" name="<?php echo $this->get_field_name('cat'); ?>">
150: <option value=''><?php _e('All categories','event-post') ?></option>
151: <?php
152: $cats = get_categories();
153: foreach($cats as $_cat){ ?>
154: <option value="<?=$_cat->slug?>" <?php selected($instance['cat'], $_cat->slug , true); ?>><?=$_cat->cat_name?></option>
155: <?php } ?>
156: </select>
157: </label>
158: </p>
159:
160: <p>
161: <label for="<?php echo $this->get_field_id('tag'); ?>">
162: <span class="dashicons dashicons-tag"></span>
163: <?php _e('Only in:','event-post'); ?>
164: <select class="widefat" id="<?php echo $this->get_field_id('tag'); ?>" name="<?php echo $this->get_field_name('tag'); ?>">
165: <option value=''><?php _e('All tags','event-post') ?></option>
166: <?php
167: $tags = get_tags();
168: foreach($tags as $_tag){?>
169: <option value="<?=$_tag->slug?>" <?php selected($instance['tag'], $_tag->slug , true); ?>><?=$_tag->name?></option>
170: <?php } ?>
171: </select>
172: </label>
173: </p>
174:
175: <hr>
176: <p style="margin-top:10px;">
177: <label for="<?php echo $this->get_field_id('width'); ?>"><?php _e('Width','event-post'); ?>
178: <input id="<?php echo $this->get_field_id('width'); ?>" name="<?php echo $this->get_field_name('width'); ?>" value="<?php echo $instance['width']; ?>" />
179: </label> (px, %)
180: </p>
181: <p style="margin-top:10px;">
182: <label for="<?php echo $this->get_field_id('height'); ?>"><?php _e('Height','event-post'); ?>
183: <input id="<?php echo $this->get_field_id('height'); ?>" name="<?php echo $this->get_field_name('height'); ?>" value="<?php echo $instance['height']; ?>" />
184: </label> (px, %)
185: </p>
186: <p style="margin-top:10px;">
187: <label for="<?php echo $this->get_field_id('zoom'); ?>"><?php _e('Force zoom','event-post'); ?>
188: <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"/>
189: </label>
190: </p>
191:
192: <p style="margin-top:10px;">
193: <label for="<?php echo $this->get_field_id('thumbnail'); ?>">
194: <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); ?>/>
195: <?php _e('Show thumbnails','event-post'); ?>
196: </label>
197: </p>
198: <p>
199: <label for="<?php echo $this->get_field_id('thumbnail_size'); ?>">
200: <?php _e('Thumbnail size:','event-post'); ?>
201: <select class="widefat" id="<?php echo $this->get_field_id('thumbnail_size'); ?>" name="<?php echo $this->get_field_name('thumbnail_size'); ?>">
202: <option value=''></option>
203: <?php foreach($thumbnail_sizes as $size){?>
204: <option value="<?php echo $size; ?>" <?php selected($size, $instance['thumbnail_size'], true); ?>><?php echo $size; ?></option>
205: <?php } ?>
206: </select>
207: </label>
208: </p>
209: <p style="margin-top:10px;">
210: <label for="<?php echo $this->get_field_id('excerpt'); ?>">
211: <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); ?> />
212: <?php _e('Show excerpt','event-post'); ?>
213: </label>
214: </p>
215:
216: <p style="margin-top:10px;">
217: <label for="<?php echo $this->get_field_id('tile'); ?>">
218: <?php _e('Map background', 'event-post'); ?>
219: <select id="<?php echo $this->get_field_id('tile'); ?>" name="<?php echo $this->get_field_name('tile'); ?>">
220: <?php
221: foreach ($EventPost->maps as $id => $map):
222: ?>
223: <option value="<?php
224: if ($EventPost->settings['tile'] != $map['id']) {
225: echo $map['id'];
226: }
227: ?>" <?php selected($instance['tile'], $id, true);?>>
228: <?php echo $map['name']; ?><?php
229: if ($EventPost->settings['tile'] == $map['id']) {
230: echo' (default)';
231: }
232: ?>
233: </option>
234: <?php endforeach; ?>
235: </select>
236: </label>
237: </p>
238: <hr>
239: <?php foreach($EventPost->map_interactions as $int_key=>$int_name): ?>
240: <p>
241: <label for="<?php echo $this->get_field_id($int_key); ?>">
242: <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); ?>/>
243: <?php
244: // Translators: %s is the interaction name
245: printf(__('Activate %s interaction','event-post'), $int_name); ?>
246: </label>
247: </p>
248: <?php endforeach; ?>
249: <?php
250: }
251:
252: }
253: