PluginProbe
Event Post / trunk
Event Post vtrunk
6.1.1 6.1.0 6.0.1 6.0.0 5.12.0 trunk 3.9 4.0 4.2 4.3 4.4 4.5 5.0 5.1 5.10.0 5.10.1 5.10.2 5.10.3 5.10.4 5.11.0 5.11.1 5.2 5.5 5.6 5.6.1 All 46 releases
event-post / inc / shortcodes.php

shortcodes.php in Event Post trunk, at inc/shortcodes.php

306 lines 11.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Implements all shortcodes features
4 *
5 * @package event-post
6 */
7 class EventPost_Shortcodes{
8 public $EP;
9
10 function __construct() {
11 //Shortcodes
12 add_action('init', array(&$this,'init'));
13 add_shortcode(apply_filters('eventpost_shortcode_slug', 'events_list'), array(&$this, 'shortcode_list'));
14 add_shortcode(apply_filters('eventpost_shortcode_slug', 'events_timeline'), array(&$this, 'shortcode_timeline'));
15 add_shortcode(apply_filters('eventpost_shortcode_slug', 'events_map'), array(&$this, 'shortcode_map'));
16 add_shortcode(apply_filters('eventpost_shortcode_slug', 'events_cal'), array(&$this, 'shortcode_cal'));
17 add_shortcode(apply_filters('eventpost_shortcode_slug', 'event_details'), array(&$this, 'shortcode_single'));
18 add_shortcode(apply_filters('eventpost_shortcode_slug', 'event_term'), array(&$this, 'shortcode_term'));
19 add_shortcode(apply_filters('eventpost_shortcode_slug', 'event_cat'), array(&$this, 'shortcode_cat'));
20 add_shortcode(apply_filters('eventpost_shortcode_slug', 'event_search'), array(&$this, 'shortcode_search'));
21 }
22
23 /**
24 * Call functions when WP is ready
25 */
26 public function init(){
27 global $EventPost;
28 $this->EP = $EventPost;
29 }
30
31 /**
32 * shortcode_single
33 * @param array $atts
34 * @filter : eventpost_params
35 * @return string
36 */
37 public function shortcode_single($atts){
38 extract(shortcode_atts(apply_filters('eventpost_params', array(
39 'attribute' => '',
40 ), 'shortcode_single'), $atts));
41 $event = $this->EP->retreive();
42 switch($attribute){
43 case 'start':
44 return $this->EP->human_date($event->time_start);
45 case 'end':
46 return $this->EP->human_date($event->time_end);
47 case 'address':
48 return $event->address;
49 case 'location':
50 return $this->EP->get_singleloc($event, '', 'single');
51 case 'date':
52 return $this->EP->get_singledate($event, '', 'single');
53 default:
54 return $this->EP->get_single($event, '', 'single');
55 }
56 }
57
58 /**
59 *
60 * @param array $atts
61 * @return string
62 */
63 public function shortcode_term($atts){
64 extract(shortcode_atts(apply_filters('eventpost_params', array(
65 'tax' => null,
66 'term' => null,
67 'post_type' => null,
68 ), 'shortcode_term'), $atts));
69 if(false !== $the_term = $this->EP->retreive_term($term, $tax, $post_type)){
70 return $this->EP->delta_date($the_term->time_start, $the_term->time_end);
71 }
72 }
73 public function shortcode_cat($_atts){
74 $atts = shortcode_atts(array(
75 'cat' => null,
76 ), $_atts);
77 $atts['tax']='category';
78 $atts['post_type']='post';
79 $atts['term']=$atts['cat'];
80 unset($atts['cat']);
81 return $this->shortcode_term($atts);
82 }
83
84 /**
85 * Shortcode to display a list of events
86 *
87 ### Query parameters
88
89 - **nb=5** *(number of post, -1 is all, default: 5)*
90 - **future=1** *(boolean, retreive, or not, events in the future, default = 1)*
91 - **past=0** *(boolean, retreive, or not, events in the past, default = 0)*
92 - **cat=''** *(string, select posts only from the selected category, default=null, for all categories)*
93 - **tag=''** *(string, select posts only from the selected tag, default=null, for all tags)*
94 - **geo=0** *(boolean, retreives or not, only events which have geolocation informations, default=0)*
95 - **order="ASC"** *(string (can be "ASC" or "DESC")*
96 - **orderby="meta_value"** *(string (if set to "meta_value" events are sorted by event date, possible values are native posts fileds : "post_title","post_date" etc...)*
97
98 ### Display parameters
99
100 - **thumbnail=""** * (Bool, default:false, used to display posts thumbnails)*
101 - **thumbnail_size=""** * (String, default:"thmbnail", can be set to any existing size : "medium","large","full" etc...)*
102 - **excerpt=""** * (Bool, default:false, used to display posts excerpts)*
103 - **style=""** * (String, add some inline CSS to the list wrapper)*
104 - **type=div** *(string, possible values are : div, ul, ol default=div)*
105 - **title=''** *(string, hidden if no events is found)*
106 - **before_title="&lt;h3&gt;"** *(string (default &lt;h3&gt;)*
107 - **after_title="&lt;/h3&gt;"** *(string (default &lt;/h3&gt;)*
108 - **container_schema=""** *(string html schema to display list)*
109 - **item_schema=""** *(string html schema to display item)*
110 *
111 * @param array $_atts
112 * @filter eventpost_params
113 * @return string
114 */
115 public function shortcode_list($_atts) {
116 $atts = shortcode_atts(apply_filters('eventpost_params', array(
117 // Filters
118 'nb' => 0,
119 'future' => true,
120 'past' => false,
121 'geo' => 0,
122 'cat' => '',
123 'tag' => '',
124 'tax_name' => '',
125 'tax_term' => '',
126 'orderby' => 'meta_value',
127 'order' => 'ASC',
128 'title' => '',
129 // Display
130 'type' => 'div',
131 'before_title' => '<h3>',
132 'after_title' => '</h3>',
133 'thumbnail' => '',
134 'thumbnail_size' => '',
135 'excerpt' => '',
136 'width' => '',
137 'height' => 'auto',
138 'style' => '',
139 'pages' => false,
140 'container_schema' => $this->EP->list_shema['container'],
141 'item_schema' => $this->EP->list_shema['item'],
142 'className' => '',
143 ), 'shortcode_list'), $_atts);
144
145 if ($atts['container_schema'] != $this->EP->list_shema['container'])
146 $atts['container_schema'] = html_entity_decode($atts['container_schema']);
147 if ($atts['item_schema'] != $this->EP->list_shema['item'])
148 $atts['item_schema'] = html_entity_decode($atts['item_schema']);
149 return $this->EP->list_events($atts, 'event_list', 'shortcode');
150 }
151
152 /**
153 * Shortcode to display a list of events
154 *
155 ### Query parameters
156
157 - **nb=5** *(number of post, -1 is all, default: 5)*
158 - **future=1** *(boolean, retreive, or not, events in the future, default = 1)*
159 - **past=0** *(boolean, retreive, or not, events in the past, default = 0)*
160 - **cat=''** *(string, select posts only from the selected category, default=null, for all categories)*
161 - **tag=''** *(string, select posts only from the selected tag, default=null, for all tags)*
162 - **geo=0** *(boolean, retreives or not, only events which have geolocation informations, default=0)*
163
164 ### Display parameters
165
166 - **excerpt=""** * (Bool, default:false, used to display posts excerpts)*
167 - **style=""** * (String, add some inline CSS to the list wrapper)*
168 - **type=div** *(string, possible values are : div, ul, ol default=div)*
169 - **title=''** *(string, hidden if no events is found)*
170 - **before_title="&lt;h3&gt;"** *(string (default &lt;h3&gt;)*
171 - **after_title="&lt;/h3&gt;"** *(string (default &lt;/h3&gt;)*
172 - **container_schema=""** *(string html schema to display list)*
173 - **item_schema=""** *(string html schema to display item)*
174 *
175 * @param array $_atts
176 * @filter eventpost_params
177 * @return string
178 */
179 public function shortcode_timeline($_atts) {
180 $atts = shortcode_atts(apply_filters('eventpost_params', array(
181 // Filters
182 'nb' => 0,
183 'future' => true,
184 'past' => false,
185 'geo' => 0,
186 'cat' => '',
187 'tag' => '',
188 'tax_name' => '',
189 'tax_term' => '',
190 'title' => '',
191 // Display
192 'type' => 'div',
193 'before_title' => '<h3>',
194 'after_title' => '</h3>',
195 'excerpt' => '',
196 'width' => '',
197 'height' => 'auto',
198 'style' => '',
199 'container_schema' => $this->EP->timeline_shema['container'],
200 'item_schema' => $this->EP->timeline_shema['item'],
201 'className' => '',
202 ), 'shortcode_list'), $_atts);
203
204 if ($atts['container_schema'] != $this->EP->timeline_shema['container'])
205 $atts['container_schema'] = html_entity_decode($atts['container_schema']);
206 if ($atts['item_schema'] != $this->EP->timeline_shema['item'])
207 $atts['item_schema'] = html_entity_decode($atts['item_schema']);
208 return $this->EP->list_events($atts, 'event_timeline', 'shortcode');
209 }
210
211 /**
212 * Shortcode to display a map of events
213 * @param array $_atts
214 * @filter eventpost_params
215 * @return string
216 */
217 public function shortcode_map($_atts) {
218
219 $ep_settings = $this->EP->settings;
220 $defaults = array(
221 // Display
222 'width' => '',
223 'height' => '',
224 'tile' => $ep_settings['tile'],
225 'pop_element_schema' => '',
226 'htmlPop_element_schema' => '',
227 'title' => '',
228 'before_title' => '<h3>',
229 'after_title' => '</h3>',
230 'style' => '',
231 'thumbnail' => '',
232 'thumbnail_size' => '',
233 'excerpt' => '',
234 'zoom' => '',
235 'map_position' => '',
236 'latitude' => '',
237 'longitude' => '',
238 'list' => '0',
239 // Filters
240 'nb' => 0,
241 'future' => true,
242 'past' => false,
243 'cat' => '',
244 'tag' => '',
245 'tax_name' => '',
246 'tax_term' => '',
247 'orderby' => 'meta_value',
248 'order' => 'ASC',
249 'className' => '',
250 );
251 // UI options
252 foreach($this->EP->map_interactions as $int_key=>$int_name){
253 $defaults[$int_key]=true;
254 }
255 // - UI options
256 foreach($this->EP->map_interactions as $int_key=>$int_name){
257 $defaults['disable_'.strtolower($int_key)]=false;
258 }
259
260 $atts = shortcode_atts(apply_filters('eventpost_params', $defaults, 'shortcode_map'), $_atts);
261 // UI options
262 foreach($this->EP->map_interactions as $int_key=>$int_name){
263 if($atts['disable_'.strtolower($int_key)]==true){
264 $atts[$int_key]=false;
265 }
266 unset($atts['disable_'.strtolower($int_key)]);
267 }
268 $atts['geo'] = 1;
269 $atts['type'] = 'div';
270 return $this->EP->list_events($atts, 'event_geolist', 'shortcode'); //$nb,'div',$future,$past,1,'event_geolist');
271 }
272
273 /**
274 * Shortcode to display a calendar of events
275 * @param array $_atts
276 * @filter eventpost_params
277 * @return string
278 */
279 public function shortcode_cal($_atts) {
280 $this->EP->load_scripts();
281 $atts = shortcode_atts(apply_filters('eventpost_params', array(
282 'date' => date('Y-n'),
283 'cat' => '',
284 'mondayfirst' => 0, //1 : weeks starts on monday
285 'display_title' => 0,
286 'datepicker' => 1,
287 'tax_name' => '',
288 'tax_term' => '',
289 'thumbnail' => '',
290 'className' => '',
291 ), 'shortcode_cal'), $_atts);
292 extract($atts);
293 return '<div class="eventpost_calendar '.$className.'" data-tax_name="' . $tax_name . '" data-tax_term="' . $tax_term . '" data-cat="' . $cat . '" data-date="' . $date . '" data-mf="' . $mondayfirst . '" data-dp="' . $datepicker . '" data-title="'. $display_title .'">' . $this->EP->calendar($atts) . '</div>';
294 }
295
296 /**
297 *
298 * @param type $_atts
299 * @return type
300 */
301 public function shortcode_search($_atts){
302 return $this->EP->search($_atts);
303 }
304
305 }
306