PluginProbe
Event Post / 5.5
Event Post v5.5
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 5.5, at inc/shortcodes.php

245 lines 9.0 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_map'), array(&$this, 'shortcode_map'));
15 add_shortcode(apply_filters('eventpost_shortcode_slug', 'events_cal'), array(&$this, 'shortcode_cal'));
16 add_shortcode(apply_filters('eventpost_shortcode_slug', 'event_details'), array(&$this, 'shortcode_single'));
17 add_shortcode(apply_filters('eventpost_shortcode_slug', 'event_term'), array(&$this, 'shortcode_term'));
18 add_shortcode(apply_filters('eventpost_shortcode_slug', 'event_cat'), array(&$this, 'shortcode_cat'));
19 add_shortcode(apply_filters('eventpost_shortcode_slug', 'event_search'), array(&$this, 'shortcode_search'));
20 }
21
22 /**
23 * Call functions when WP is ready
24 */
25 public function init(){
26 global $EventPost;
27 $this->EP = $EventPost;
28 }
29
30 /**
31 * shortcode_single
32 * @param array $atts
33 * @filter : eventpost_params
34 * @return string
35 */
36 public function shortcode_single($atts){
37 extract(shortcode_atts(apply_filters('eventpost_params', array(
38 'attribute' => '',
39 ), 'shortcode_single'), $atts));
40 $event = $this->EP->retreive();
41 switch($attribute){
42 case 'start':
43 return $this->EP->human_date($event->time_start);
44 case 'end':
45 return $this->EP->human_date($event->time_end);
46 case 'address':
47 return $event->address;
48 case 'location':
49 return $this->EP->get_singleloc($event, '', 'single');
50 case 'date':
51 return $this->EP->get_singledate($event, '', 'single');
52 default:
53 return $this->EP->get_single($event, '', 'single');
54 }
55 }
56
57 /**
58 *
59 * @param array $atts
60 * @return string
61 */
62 public function shortcode_term($atts){
63 extract(shortcode_atts(apply_filters('eventpost_params', array(
64 'tax' => null,
65 'term' => null,
66 'post_type' => null,
67 ), 'shortcode_term'), $atts));
68 if(false !== $the_term = $this->EP->retreive_term($term, $tax, $post_type)){
69 return $this->EP->delta_date($the_term->time_start, $the_term->time_end);
70 }
71 }
72 public function shortcode_cat($_atts){
73 $atts = shortcode_atts(array(
74 'cat' => null,
75 ), $_atts);
76 $atts['tax']='category';
77 $atts['post_type']='post';
78 $atts['term']=$atts['cat'];
79 unset($atts['cat']);
80 return $this->shortcode_term($atts);
81 }
82
83 /**
84 * Shortcode to display a list of events
85 *
86 ### Query parameters
87
88 - **nb=5** *(number of post, -1 is all, default: 5)*
89 - **future=1** *(boolean, retreive, or not, events in the future, default = 1)*
90 - **past=0** *(boolean, retreive, or not, events in the past, default = 0)*
91 - **cat=''** *(string, select posts only from the selected category, default=null, for all categories)*
92 - **tag=''** *(string, select posts only from the selected tag, default=null, for all tags)*
93 - **geo=0** *(boolean, retreives or not, only events wich have geolocation informations, default=0)*
94 - **order="ASC"** *(string (can be "ASC" or "DESC")*
95 - **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...)*
96
97 ### Display parameters
98
99 - **thumbnail=""** * (Bool, default:false, used to display posts thumbnails)*
100 - **thumbnail_size=""** * (String, default:"thmbnail", can be set to any existing size : "medium","large","full" etc...)*
101 - **excerpt=""** * (Bool, default:false, used to display posts excerpts)*
102 - **style=""** * (String, add some inline CSS to the list wrapper)*
103 - **type=div** *(string, possible values are : div, ul, ol default=div)*
104 - **title=''** *(string, hidden if no events is found)*
105 - **before_title="&lt;h3&gt;"** *(string (default &lt;h3&gt;)*
106 - **after_title="&lt;/h3&gt;"** *(string (default &lt;/h3&gt;)*
107 - **container_schema=""** *(string html schema to display list)*
108 - **item_schema=""** *(string html schema to display item)*
109 *
110 * @param array $_atts
111 * @filter eventpost_params
112 * @return string
113 */
114 public function shortcode_list($_atts) {
115 $atts = shortcode_atts(apply_filters('eventpost_params', array(
116 // Filters
117 'nb' => 0,
118 'future' => true,
119 'past' => false,
120 'geo' => 0,
121 'cat' => '',
122 'tag' => '',
123 'tax_name' => '',
124 'tax_term' => '',
125 'orderby' => 'meta_value',
126 'order' => 'ASC',
127 'title' => '',
128 // Display
129 'type' => 'div',
130 'before_title' => '<h3>',
131 'after_title' => '</h3>',
132 'thumbnail' => '',
133 'thumbnail_size' => '',
134 'excerpt' => '',
135 'width' => '',
136 'height' => 'auto',
137 'style' => '',
138 'pages' => false,
139 'container_schema' => $this->EP->list_shema['container'],
140 'item_schema' => $this->EP->list_shema['item'],
141 'className' => '',
142 ), 'shortcode_list'), $_atts);
143
144 if ($atts['container_schema'] != $this->EP->list_shema['container'])
145 $atts['container_schema'] = html_entity_decode($atts['container_schema']);
146 if ($atts['item_schema'] != $this->EP->list_shema['item'])
147 $atts['item_schema'] = html_entity_decode($atts['item_schema']);
148 return $this->EP->list_events($atts, 'event_list', 'shortcode');
149 }
150
151 /**
152 * Shortcode to display a map of events
153 * @param array $_atts
154 * @filter eventpost_params
155 * @return string
156 */
157 public function shortcode_map($_atts) {
158 $ep_settings = $this->EP->settings;
159 $defaults = array(
160 // Display
161 'width' => '',
162 'height' => '',
163 'tile' => $ep_settings['tile'],
164 'pop_element_schema' => '',
165 'htmlPop_element_schema' => '',
166 'title' => '',
167 'before_title' => '<h3>',
168 'after_title' => '</h3>',
169 'style' => '',
170 'thumbnail' => '',
171 'thumbnail_size' => '',
172 'excerpt' => '',
173 'zoom' => '',
174 'map_position' => '',
175 'latitude' => '',
176 'longitude' => '',
177 'list' => '0',
178 // Filters
179 'nb' => 0,
180 'future' => true,
181 'past' => false,
182 'cat' => '',
183 'tag' => '',
184 'tax_name' => '',
185 'tax_term' => '',
186 'orderby' => 'meta_value',
187 'order' => 'ASC',
188 'className' => '',
189 );
190 // UI options
191 foreach($this->EP->map_interactions as $int_key=>$int_name){
192 $defaults[$int_key]=true;
193 }
194 // - UI options
195 foreach($this->EP->map_interactions as $int_key=>$int_name){
196 $defaults['disable_'.strtolower($int_key)]=false;
197 }
198
199 $atts = shortcode_atts(apply_filters('eventpost_params', $defaults, 'shortcode_map'), $_atts);
200 // UI options
201 foreach($this->EP->map_interactions as $int_key=>$int_name){
202 if($atts['disable_'.strtolower($int_key)]==true){
203 $atts[$int_key]=false;
204 }
205 unset($atts['disable_'.strtolower($int_key)]);
206 }
207 $atts['geo'] = 1;
208 $atts['type'] = 'div';
209 return $this->EP->list_events($atts, 'event_geolist', 'shortcode'); //$nb,'div',$future,$past,1,'event_geolist');
210 }
211
212 /**
213 * Shortcode to display a calendar of events
214 * @param array $_atts
215 * @filter eventpost_params
216 * @return string
217 */
218 public function shortcode_cal($_atts) {
219 $this->EP->load_scripts();
220 $atts = shortcode_atts(apply_filters('eventpost_params', array(
221 'date' => date('Y-n'),
222 'cat' => '',
223 'mondayfirst' => 0, //1 : weeks starts on monday
224 'display_title' => 0,
225 'datepicker' => 1,
226 'tax_name' => '',
227 'tax_term' => '',
228 'thumbnail' => '',
229 'className' => '',
230 ), 'shortcode_cal'), $_atts);
231 extract($atts);
232 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>';
233 }
234
235 /**
236 *
237 * @param type $_atts
238 * @return type
239 */
240 public function shortcode_search($_atts){
241 return $this->EP->search($_atts);
242 }
243
244 }
245