@@ -12,276 +12,276 @@ |
||
12 | 12 | { |
13 | 13 | |
14 | 14 | |
15 | - /** |
|
16 | - * generates JSON-based linked data for an event |
|
17 | - * |
|
18 | - * @param EE_Event $event |
|
19 | - * @throws EE_Error |
|
20 | - */ |
|
21 | - public static function add_json_linked_data_for_event(EE_Event $event) |
|
22 | - { |
|
23 | - // Check we have a valid datetime for the event |
|
24 | - if (! $event->primary_datetime() instanceof EE_Datetime) { |
|
25 | - return; |
|
26 | - } |
|
27 | - |
|
28 | - $template_args = array( |
|
29 | - 'event_permalink' => '', |
|
30 | - 'event_name' => '', |
|
31 | - 'event_description' => '', |
|
32 | - 'event_start' => '', |
|
33 | - 'event_end' => '', |
|
34 | - 'currency' => '', |
|
35 | - 'event_tickets' => array(), |
|
36 | - 'venue_name' => '', |
|
37 | - 'venue_url' => '', |
|
38 | - 'venue_locality' => '', |
|
39 | - 'venue_region' => '', |
|
40 | - 'venue_address' => '', |
|
41 | - 'event_image' => '', |
|
42 | - ); |
|
43 | - $template_args['event_permalink'] = $event->get_permalink(); |
|
44 | - $template_args['event_name'] = $event->name(); |
|
45 | - $template_args['event_description'] = wp_strip_all_tags($event->short_description(200)); |
|
46 | - // clone datetime so that date formats don't override those for the original datetime |
|
47 | - $primary_datetime = clone $event->primary_datetime(); |
|
48 | - $template_args['event_start'] = $primary_datetime->start_date(DateTime::ATOM); |
|
49 | - $template_args['event_end'] = $primary_datetime->end_date(DateTime::ATOM); |
|
50 | - unset($primary_datetime); |
|
51 | - $template_args['currency'] = EE_Registry::instance()->CFG->currency->code; |
|
52 | - foreach ($event->tickets() as $original_ticket) { |
|
53 | - // clone tickets so that date formats don't override those for the original ticket |
|
54 | - $ticket= clone $original_ticket; |
|
55 | - $ID = $ticket->ID(); |
|
56 | - $template_args['event_tickets'][ $ID ]['start_date'] = $ticket->start_date(DateTime::ATOM, null); |
|
57 | - $template_args['event_tickets'][ $ID ]['end_date'] = $ticket->end_date(DateTime::ATOM, null); |
|
58 | - $template_args['event_tickets'][ $ID ]['price'] = number_format( |
|
59 | - $ticket->price(), |
|
60 | - EE_Registry::instance()->CFG->currency->dec_plc, |
|
61 | - EE_Registry::instance()->CFG->currency->dec_mrk, |
|
62 | - '' |
|
63 | - ); |
|
64 | - switch ($ticket->ticket_status()) { |
|
65 | - case 'TKO': |
|
66 | - $availability = 'InStock'; |
|
67 | - break; |
|
68 | - case 'TKS': |
|
69 | - $availability = 'SoldOut'; |
|
70 | - break; |
|
71 | - default: |
|
72 | - $availability = null; |
|
73 | - break; |
|
74 | - } |
|
75 | - $template_args['event_tickets'][ $ID ]['availability'] = $availability; |
|
76 | - unset($ticket); |
|
77 | - } |
|
78 | - $VNU_ID = espresso_venue_id(); |
|
79 | - if (! empty($VNU_ID) && ! espresso_is_venue_private($VNU_ID)) { |
|
80 | - $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
81 | - $template_args['venue_name'] = get_the_title($VNU_ID); |
|
82 | - $template_args['venue_url'] = get_permalink($VNU_ID); |
|
83 | - $template_args['venue_locality'] = $venue->city(); |
|
84 | - $template_args['venue_region'] = $venue->state_name(); |
|
85 | - $template_args['venue_address'] = $venue->address(); |
|
86 | - } |
|
87 | - $template_args['event_image'] = $event->feature_image_url(); |
|
88 | - $template_args = apply_filters( |
|
89 | - 'FHEE__EEH_Schema__add_json_linked_data_for_event__template_args', |
|
90 | - $template_args, |
|
91 | - $event, |
|
92 | - $VNU_ID |
|
93 | - ); |
|
94 | - extract($template_args, EXTR_OVERWRITE); |
|
95 | - include EE_TEMPLATES . 'json_linked_data_for_event.template.php'; |
|
96 | - } |
|
97 | - |
|
98 | - |
|
99 | - /** |
|
100 | - * location |
|
101 | - * The location of the event, organization or action. |
|
102 | - * Should include the Venue name AND schema formatted address info |
|
103 | - * |
|
104 | - * @access public |
|
105 | - * @param string $location |
|
106 | - * @return string |
|
107 | - */ |
|
108 | - public static function location($location = null) |
|
109 | - { |
|
110 | - return ! empty($location) ? '<div itemprop="location" itemscope itemtype="http://schema.org/Place">' |
|
111 | - . $location |
|
112 | - . '</div>' : ''; |
|
113 | - } |
|
114 | - |
|
115 | - |
|
116 | - |
|
117 | - /** |
|
118 | - * name |
|
119 | - * The name of the Event or Venue. |
|
120 | - * |
|
121 | - * @access public |
|
122 | - * @param string $name |
|
123 | - * @return string |
|
124 | - */ |
|
125 | - public static function name($name = null) |
|
126 | - { |
|
127 | - return ! empty($name) ? '<span itemprop="name">' . $name . '</span>' : ''; |
|
128 | - } |
|
129 | - |
|
130 | - |
|
131 | - |
|
132 | - /** |
|
133 | - * streetAddress |
|
134 | - * The street address. For example, 1600 Amphitheatre Pkwy. |
|
135 | - * |
|
136 | - * @access public |
|
137 | - * @param EEI_Address $obj_with_address |
|
138 | - * @return string |
|
139 | - */ |
|
140 | - public static function streetAddress(EEI_Address $obj_with_address = null) |
|
141 | - { |
|
142 | - return $obj_with_address->address() !== null && $obj_with_address->address() !== '' |
|
143 | - ? '<span itemprop="streetAddress">' . $obj_with_address->address() . '</span>' : ''; |
|
144 | - } |
|
145 | - |
|
146 | - |
|
147 | - |
|
148 | - /** |
|
149 | - * postOfficeBoxNumber |
|
150 | - * The post office box number for PO box addresses. |
|
151 | - * |
|
152 | - * @access public |
|
153 | - * @param EEI_Address $obj_with_address |
|
154 | - * @return string |
|
155 | - */ |
|
156 | - public static function postOfficeBoxNumber(EEI_Address $obj_with_address = null) |
|
157 | - { |
|
158 | - // regex check for some form of PO Box or P.O. Box, etc, etc, etc |
|
159 | - if (preg_match( |
|
160 | - "/^\s*((P(OST)?.?\s*(O(FF(ICE)?)?)?.?\s+(B(IN|OX))?)|B(IN|OX))/i", |
|
161 | - $obj_with_address->address2() |
|
162 | - ) ) { |
|
163 | - return $obj_with_address->address2() !== null && $obj_with_address->address2() !== '' |
|
164 | - ? '<span itemprop="postOfficeBoxNumber">' . $obj_with_address->address2() . '</span>' : ''; |
|
165 | - } else { |
|
166 | - return $obj_with_address->address2(); |
|
167 | - } |
|
168 | - } |
|
169 | - |
|
170 | - |
|
171 | - |
|
172 | - /** |
|
173 | - * addressLocality |
|
174 | - * The locality (city, town, etc). For example, Mountain View. |
|
175 | - * |
|
176 | - * @access public |
|
177 | - * @param EEI_Address $obj_with_address |
|
178 | - * @return string |
|
179 | - */ |
|
180 | - public static function addressLocality(EEI_Address $obj_with_address = null) |
|
181 | - { |
|
182 | - return $obj_with_address->city() !== null && $obj_with_address->city() !== '' |
|
183 | - ? '<span itemprop="addressLocality">' . $obj_with_address->city() . '</span>' : ''; |
|
184 | - } |
|
185 | - |
|
186 | - |
|
187 | - |
|
188 | - /** |
|
189 | - * addressRegion |
|
190 | - * The region (state, province, etc). For example, CA. |
|
191 | - * |
|
192 | - * @access public |
|
193 | - * @param EEI_Address $obj_with_address |
|
194 | - * @return string |
|
195 | - */ |
|
196 | - public static function addressRegion(EEI_Address $obj_with_address = null) |
|
197 | - { |
|
198 | - $state = $obj_with_address->state_name(); |
|
199 | - if (! empty($state)) { |
|
200 | - return '<span itemprop="addressRegion">' . $state . '</span>'; |
|
201 | - } else { |
|
202 | - return ''; |
|
203 | - } |
|
204 | - } |
|
205 | - |
|
206 | - |
|
207 | - |
|
208 | - /** |
|
209 | - * addressCountry |
|
210 | - * The country. For example, USA. You can also provide the two-letter ISO 3166-1 alpha-2 country code. |
|
211 | - * |
|
212 | - * @access public |
|
213 | - * @param EEI_Address $obj_with_address |
|
214 | - * @return string |
|
215 | - */ |
|
216 | - public static function addressCountry(EEI_Address $obj_with_address = null) |
|
217 | - { |
|
218 | - $country = $obj_with_address->country_name(); |
|
219 | - if (! empty($country)) { |
|
220 | - return '<span itemprop="addressCountry">' . $country . '</span>'; |
|
221 | - } else { |
|
222 | - return ''; |
|
223 | - } |
|
224 | - } |
|
225 | - |
|
226 | - |
|
227 | - |
|
228 | - /** |
|
229 | - * postalCode |
|
230 | - * The postal code. For example, 94043. |
|
231 | - * |
|
232 | - * @access public |
|
233 | - * @param EEI_Address $obj_with_address |
|
234 | - * @return string |
|
235 | - */ |
|
236 | - public static function postalCode(EEI_Address $obj_with_address = null) |
|
237 | - { |
|
238 | - return $obj_with_address->zip() !== null && $obj_with_address->zip() !== '' ? '<span itemprop="postalCode">' |
|
239 | - . $obj_with_address->zip() |
|
240 | - . '</span>' : ''; |
|
241 | - } |
|
242 | - |
|
243 | - |
|
244 | - |
|
245 | - /** |
|
246 | - * telephone |
|
247 | - * The telephone number. |
|
248 | - * |
|
249 | - * @access public |
|
250 | - * @param string $phone_nmbr |
|
251 | - * @return string |
|
252 | - */ |
|
253 | - public static function telephone($phone_nmbr = null) |
|
254 | - { |
|
255 | - return $phone_nmbr !== null && $phone_nmbr !== '' ? '<span itemprop="telephone">' . $phone_nmbr . '</span>' |
|
256 | - : ''; |
|
257 | - } |
|
258 | - |
|
259 | - |
|
260 | - |
|
261 | - /** |
|
262 | - * URL |
|
263 | - * URL of the item as a clickable link |
|
264 | - * |
|
265 | - * @access public |
|
266 | - * @param string $url - the URL that the link will resolve to |
|
267 | - * @param string $text - the text that will be used for the visible link |
|
268 | - * @param array $attributes - array of additional link attributes in attribute_name => value pairs. ie: array( 'title' => 'click here', 'class' => 'link-class' ) |
|
269 | - * @return string (link) |
|
270 | - */ |
|
271 | - public static function url($url = null, $text = null, $attributes = array()) |
|
272 | - { |
|
273 | - // Check the URL includes a scheme |
|
274 | - $parsed_url = parse_url($url); |
|
275 | - if (empty($parsed_url['scheme'])) { |
|
276 | - $url = 'http://' . ltrim($url, '/'); |
|
277 | - } |
|
278 | - |
|
279 | - $atts = ''; |
|
280 | - foreach ($attributes as $attribute => $value) { |
|
281 | - $atts .= ' ' . $attribute . '="' . $value . '"'; |
|
282 | - } |
|
283 | - $text = $text !== null && $text !== '' ? $text : $url; |
|
284 | - return $url !== null && $url !== '' ? '<a itemprop="url" href="' . $url . '"' . $atts . '>' . $text . '</a>' |
|
285 | - : ''; |
|
286 | - } |
|
15 | + /** |
|
16 | + * generates JSON-based linked data for an event |
|
17 | + * |
|
18 | + * @param EE_Event $event |
|
19 | + * @throws EE_Error |
|
20 | + */ |
|
21 | + public static function add_json_linked_data_for_event(EE_Event $event) |
|
22 | + { |
|
23 | + // Check we have a valid datetime for the event |
|
24 | + if (! $event->primary_datetime() instanceof EE_Datetime) { |
|
25 | + return; |
|
26 | + } |
|
27 | + |
|
28 | + $template_args = array( |
|
29 | + 'event_permalink' => '', |
|
30 | + 'event_name' => '', |
|
31 | + 'event_description' => '', |
|
32 | + 'event_start' => '', |
|
33 | + 'event_end' => '', |
|
34 | + 'currency' => '', |
|
35 | + 'event_tickets' => array(), |
|
36 | + 'venue_name' => '', |
|
37 | + 'venue_url' => '', |
|
38 | + 'venue_locality' => '', |
|
39 | + 'venue_region' => '', |
|
40 | + 'venue_address' => '', |
|
41 | + 'event_image' => '', |
|
42 | + ); |
|
43 | + $template_args['event_permalink'] = $event->get_permalink(); |
|
44 | + $template_args['event_name'] = $event->name(); |
|
45 | + $template_args['event_description'] = wp_strip_all_tags($event->short_description(200)); |
|
46 | + // clone datetime so that date formats don't override those for the original datetime |
|
47 | + $primary_datetime = clone $event->primary_datetime(); |
|
48 | + $template_args['event_start'] = $primary_datetime->start_date(DateTime::ATOM); |
|
49 | + $template_args['event_end'] = $primary_datetime->end_date(DateTime::ATOM); |
|
50 | + unset($primary_datetime); |
|
51 | + $template_args['currency'] = EE_Registry::instance()->CFG->currency->code; |
|
52 | + foreach ($event->tickets() as $original_ticket) { |
|
53 | + // clone tickets so that date formats don't override those for the original ticket |
|
54 | + $ticket= clone $original_ticket; |
|
55 | + $ID = $ticket->ID(); |
|
56 | + $template_args['event_tickets'][ $ID ]['start_date'] = $ticket->start_date(DateTime::ATOM, null); |
|
57 | + $template_args['event_tickets'][ $ID ]['end_date'] = $ticket->end_date(DateTime::ATOM, null); |
|
58 | + $template_args['event_tickets'][ $ID ]['price'] = number_format( |
|
59 | + $ticket->price(), |
|
60 | + EE_Registry::instance()->CFG->currency->dec_plc, |
|
61 | + EE_Registry::instance()->CFG->currency->dec_mrk, |
|
62 | + '' |
|
63 | + ); |
|
64 | + switch ($ticket->ticket_status()) { |
|
65 | + case 'TKO': |
|
66 | + $availability = 'InStock'; |
|
67 | + break; |
|
68 | + case 'TKS': |
|
69 | + $availability = 'SoldOut'; |
|
70 | + break; |
|
71 | + default: |
|
72 | + $availability = null; |
|
73 | + break; |
|
74 | + } |
|
75 | + $template_args['event_tickets'][ $ID ]['availability'] = $availability; |
|
76 | + unset($ticket); |
|
77 | + } |
|
78 | + $VNU_ID = espresso_venue_id(); |
|
79 | + if (! empty($VNU_ID) && ! espresso_is_venue_private($VNU_ID)) { |
|
80 | + $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
81 | + $template_args['venue_name'] = get_the_title($VNU_ID); |
|
82 | + $template_args['venue_url'] = get_permalink($VNU_ID); |
|
83 | + $template_args['venue_locality'] = $venue->city(); |
|
84 | + $template_args['venue_region'] = $venue->state_name(); |
|
85 | + $template_args['venue_address'] = $venue->address(); |
|
86 | + } |
|
87 | + $template_args['event_image'] = $event->feature_image_url(); |
|
88 | + $template_args = apply_filters( |
|
89 | + 'FHEE__EEH_Schema__add_json_linked_data_for_event__template_args', |
|
90 | + $template_args, |
|
91 | + $event, |
|
92 | + $VNU_ID |
|
93 | + ); |
|
94 | + extract($template_args, EXTR_OVERWRITE); |
|
95 | + include EE_TEMPLATES . 'json_linked_data_for_event.template.php'; |
|
96 | + } |
|
97 | + |
|
98 | + |
|
99 | + /** |
|
100 | + * location |
|
101 | + * The location of the event, organization or action. |
|
102 | + * Should include the Venue name AND schema formatted address info |
|
103 | + * |
|
104 | + * @access public |
|
105 | + * @param string $location |
|
106 | + * @return string |
|
107 | + */ |
|
108 | + public static function location($location = null) |
|
109 | + { |
|
110 | + return ! empty($location) ? '<div itemprop="location" itemscope itemtype="http://schema.org/Place">' |
|
111 | + . $location |
|
112 | + . '</div>' : ''; |
|
113 | + } |
|
114 | + |
|
115 | + |
|
116 | + |
|
117 | + /** |
|
118 | + * name |
|
119 | + * The name of the Event or Venue. |
|
120 | + * |
|
121 | + * @access public |
|
122 | + * @param string $name |
|
123 | + * @return string |
|
124 | + */ |
|
125 | + public static function name($name = null) |
|
126 | + { |
|
127 | + return ! empty($name) ? '<span itemprop="name">' . $name . '</span>' : ''; |
|
128 | + } |
|
129 | + |
|
130 | + |
|
131 | + |
|
132 | + /** |
|
133 | + * streetAddress |
|
134 | + * The street address. For example, 1600 Amphitheatre Pkwy. |
|
135 | + * |
|
136 | + * @access public |
|
137 | + * @param EEI_Address $obj_with_address |
|
138 | + * @return string |
|
139 | + */ |
|
140 | + public static function streetAddress(EEI_Address $obj_with_address = null) |
|
141 | + { |
|
142 | + return $obj_with_address->address() !== null && $obj_with_address->address() !== '' |
|
143 | + ? '<span itemprop="streetAddress">' . $obj_with_address->address() . '</span>' : ''; |
|
144 | + } |
|
145 | + |
|
146 | + |
|
147 | + |
|
148 | + /** |
|
149 | + * postOfficeBoxNumber |
|
150 | + * The post office box number for PO box addresses. |
|
151 | + * |
|
152 | + * @access public |
|
153 | + * @param EEI_Address $obj_with_address |
|
154 | + * @return string |
|
155 | + */ |
|
156 | + public static function postOfficeBoxNumber(EEI_Address $obj_with_address = null) |
|
157 | + { |
|
158 | + // regex check for some form of PO Box or P.O. Box, etc, etc, etc |
|
159 | + if (preg_match( |
|
160 | + "/^\s*((P(OST)?.?\s*(O(FF(ICE)?)?)?.?\s+(B(IN|OX))?)|B(IN|OX))/i", |
|
161 | + $obj_with_address->address2() |
|
162 | + ) ) { |
|
163 | + return $obj_with_address->address2() !== null && $obj_with_address->address2() !== '' |
|
164 | + ? '<span itemprop="postOfficeBoxNumber">' . $obj_with_address->address2() . '</span>' : ''; |
|
165 | + } else { |
|
166 | + return $obj_with_address->address2(); |
|
167 | + } |
|
168 | + } |
|
169 | + |
|
170 | + |
|
171 | + |
|
172 | + /** |
|
173 | + * addressLocality |
|
174 | + * The locality (city, town, etc). For example, Mountain View. |
|
175 | + * |
|
176 | + * @access public |
|
177 | + * @param EEI_Address $obj_with_address |
|
178 | + * @return string |
|
179 | + */ |
|
180 | + public static function addressLocality(EEI_Address $obj_with_address = null) |
|
181 | + { |
|
182 | + return $obj_with_address->city() !== null && $obj_with_address->city() !== '' |
|
183 | + ? '<span itemprop="addressLocality">' . $obj_with_address->city() . '</span>' : ''; |
|
184 | + } |
|
185 | + |
|
186 | + |
|
187 | + |
|
188 | + /** |
|
189 | + * addressRegion |
|
190 | + * The region (state, province, etc). For example, CA. |
|
191 | + * |
|
192 | + * @access public |
|
193 | + * @param EEI_Address $obj_with_address |
|
194 | + * @return string |
|
195 | + */ |
|
196 | + public static function addressRegion(EEI_Address $obj_with_address = null) |
|
197 | + { |
|
198 | + $state = $obj_with_address->state_name(); |
|
199 | + if (! empty($state)) { |
|
200 | + return '<span itemprop="addressRegion">' . $state . '</span>'; |
|
201 | + } else { |
|
202 | + return ''; |
|
203 | + } |
|
204 | + } |
|
205 | + |
|
206 | + |
|
207 | + |
|
208 | + /** |
|
209 | + * addressCountry |
|
210 | + * The country. For example, USA. You can also provide the two-letter ISO 3166-1 alpha-2 country code. |
|
211 | + * |
|
212 | + * @access public |
|
213 | + * @param EEI_Address $obj_with_address |
|
214 | + * @return string |
|
215 | + */ |
|
216 | + public static function addressCountry(EEI_Address $obj_with_address = null) |
|
217 | + { |
|
218 | + $country = $obj_with_address->country_name(); |
|
219 | + if (! empty($country)) { |
|
220 | + return '<span itemprop="addressCountry">' . $country . '</span>'; |
|
221 | + } else { |
|
222 | + return ''; |
|
223 | + } |
|
224 | + } |
|
225 | + |
|
226 | + |
|
227 | + |
|
228 | + /** |
|
229 | + * postalCode |
|
230 | + * The postal code. For example, 94043. |
|
231 | + * |
|
232 | + * @access public |
|
233 | + * @param EEI_Address $obj_with_address |
|
234 | + * @return string |
|
235 | + */ |
|
236 | + public static function postalCode(EEI_Address $obj_with_address = null) |
|
237 | + { |
|
238 | + return $obj_with_address->zip() !== null && $obj_with_address->zip() !== '' ? '<span itemprop="postalCode">' |
|
239 | + . $obj_with_address->zip() |
|
240 | + . '</span>' : ''; |
|
241 | + } |
|
242 | + |
|
243 | + |
|
244 | + |
|
245 | + /** |
|
246 | + * telephone |
|
247 | + * The telephone number. |
|
248 | + * |
|
249 | + * @access public |
|
250 | + * @param string $phone_nmbr |
|
251 | + * @return string |
|
252 | + */ |
|
253 | + public static function telephone($phone_nmbr = null) |
|
254 | + { |
|
255 | + return $phone_nmbr !== null && $phone_nmbr !== '' ? '<span itemprop="telephone">' . $phone_nmbr . '</span>' |
|
256 | + : ''; |
|
257 | + } |
|
258 | + |
|
259 | + |
|
260 | + |
|
261 | + /** |
|
262 | + * URL |
|
263 | + * URL of the item as a clickable link |
|
264 | + * |
|
265 | + * @access public |
|
266 | + * @param string $url - the URL that the link will resolve to |
|
267 | + * @param string $text - the text that will be used for the visible link |
|
268 | + * @param array $attributes - array of additional link attributes in attribute_name => value pairs. ie: array( 'title' => 'click here', 'class' => 'link-class' ) |
|
269 | + * @return string (link) |
|
270 | + */ |
|
271 | + public static function url($url = null, $text = null, $attributes = array()) |
|
272 | + { |
|
273 | + // Check the URL includes a scheme |
|
274 | + $parsed_url = parse_url($url); |
|
275 | + if (empty($parsed_url['scheme'])) { |
|
276 | + $url = 'http://' . ltrim($url, '/'); |
|
277 | + } |
|
278 | + |
|
279 | + $atts = ''; |
|
280 | + foreach ($attributes as $attribute => $value) { |
|
281 | + $atts .= ' ' . $attribute . '="' . $value . '"'; |
|
282 | + } |
|
283 | + $text = $text !== null && $text !== '' ? $text : $url; |
|
284 | + return $url !== null && $url !== '' ? '<a itemprop="url" href="' . $url . '"' . $atts . '>' . $text . '</a>' |
|
285 | + : ''; |
|
286 | + } |
|
287 | 287 | } |