@@ -86,24 +86,24 @@ discard block |
||
86 | 86 | switch ($iCal_type) { |
87 | 87 | // submit buttons appear as buttons and are very compatible with a theme's style |
88 | 88 | case 'submit': |
89 | - $html .= '<form id="download-iCal-frm-' . $datetime->ID(); |
|
90 | - $html .= '" class="download-iCal-frm" action="' . $URL . '" method="post" >'; |
|
89 | + $html .= '<form id="download-iCal-frm-'.$datetime->ID(); |
|
90 | + $html .= '" class="download-iCal-frm" action="'.$URL.'" method="post" >'; |
|
91 | 91 | $html .= '<input type="submit" class="ee-ical-sbmt" value="" title="'; |
92 | - $html .= esc_html__('Add to iCal Calendar', 'event_espresso') . '"/>'; |
|
92 | + $html .= esc_html__('Add to iCal Calendar', 'event_espresso').'"/>'; |
|
93 | 93 | $html .= '</form>'; |
94 | 94 | break; |
95 | 95 | // buttons are just links that have been styled to appear as buttons, |
96 | 96 | // but may not be blend with a theme as well as submit buttons |
97 | 97 | case 'button': |
98 | - $html .= '<a class="ee-ical-btn small ee-button ee-roundish" href="' . $URL; |
|
99 | - $html .= '" title="' . esc_html__('Add to iCal Calendar', 'event_espresso') . '">'; |
|
98 | + $html .= '<a class="ee-ical-btn small ee-button ee-roundish" href="'.$URL; |
|
99 | + $html .= '" title="'.esc_html__('Add to iCal Calendar', 'event_espresso').'">'; |
|
100 | 100 | $html .= ' <span class="dashicons dashicons-calendar"></span>'; |
101 | 101 | $html .= '</a>'; |
102 | 102 | break; |
103 | 103 | // links are just links that use the calendar dashicon |
104 | 104 | case 'icon': |
105 | - $html .= '<a class="ee-ical-lnk" href="' . $URL . '" title="'; |
|
106 | - $html .= esc_html__('Add to iCal Calendar', 'event_espresso') . '">'; |
|
105 | + $html .= '<a class="ee-ical-lnk" href="'.$URL.'" title="'; |
|
106 | + $html .= esc_html__('Add to iCal Calendar', 'event_espresso').'">'; |
|
107 | 107 | $html .= ' <span class="dashicons dashicons-calendar"></span>'; |
108 | 108 | $html .= '</a>'; |
109 | 109 | break; |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | } |
145 | 145 | |
146 | 146 | // Generate filename |
147 | - $filename = $event->slug() . '-' . $datetime->start_date('Y-m-d') . '.ics'; |
|
147 | + $filename = $event->slug().'-'.$datetime->start_date('Y-m-d').'.ics'; |
|
148 | 148 | |
149 | 149 | // Check the datetime status has not been cancelled and set the ics value accordingly |
150 | 150 | $status = $datetime->get_active_status(); |
@@ -153,7 +153,7 @@ discard block |
||
153 | 153 | // Create array of ics details, escape strings, convert timestamps to ics format, etc |
154 | 154 | $ics_data = [ |
155 | 155 | 'ORGANIZER_NAME' => EE_Registry::instance()->CFG->organization->name, |
156 | - 'UID' => md5($event->name() . $event->ID() . $datetime->ID()), |
|
156 | + 'UID' => md5($event->name().$event->ID().$datetime->ID()), |
|
157 | 157 | 'ORGANIZER' => EE_Registry::instance()->CFG->organization->email, |
158 | 158 | 'DTSTAMP' => date(EED_Ical::iCal_datetime_format), |
159 | 159 | 'LOCATION' => $location, |
@@ -174,9 +174,9 @@ discard block |
||
174 | 174 | foreach ($ics_data as $key => $value) { |
175 | 175 | // Description is escaped differently from all all values |
176 | 176 | if ($key === 'DESCRIPTION') { |
177 | - $ics_data[ $key ] = EED_Ical::_escape_ICal_description(wp_strip_all_tags($value)); |
|
177 | + $ics_data[$key] = EED_Ical::_escape_ICal_description(wp_strip_all_tags($value)); |
|
178 | 178 | } else { |
179 | - $ics_data[ $key ] = EED_Ical::_escape_ICal_data($value); |
|
179 | + $ics_data[$key] = EED_Ical::_escape_ICal_data($value); |
|
180 | 180 | } |
181 | 181 | } |
182 | 182 | |
@@ -186,7 +186,7 @@ discard block |
||
186 | 186 | |
187 | 187 | // set headers |
188 | 188 | header('Content-type: text/calendar; charset=utf-8'); |
189 | - header('Content-Disposition: attachment; filename="' . $filename . '"'); |
|
189 | + header('Content-Disposition: attachment; filename="'.$filename.'"'); |
|
190 | 190 | header('Cache-Control: private, max-age=0, must-revalidate'); |
191 | 191 | header('Pragma: public'); |
192 | 192 | header('Content-Type: application/octet-stream'); |
@@ -204,7 +204,7 @@ discard block |
||
204 | 204 | |
205 | 205 | // Output all remaining values from ics_data. |
206 | 206 | foreach ($ics_data as $key => $value) { |
207 | - echo $key . ':' . $value . "\r\n"; |
|
207 | + echo $key.':'.$value."\r\n"; |
|
208 | 208 | } |
209 | 209 | |
210 | 210 | echo "END:VEVENT\r\n"; |
@@ -12,235 +12,235 @@ |
||
12 | 12 | */ |
13 | 13 | class EED_Ical extends EED_Module |
14 | 14 | { |
15 | - const iCal_datetime_format = 'Ymd\THis\Z'; |
|
16 | - |
|
17 | - |
|
18 | - /** |
|
19 | - * @return EED_Ical|EED_Module |
|
20 | - * @throws EE_Error |
|
21 | - * @throws ReflectionException |
|
22 | - */ |
|
23 | - public static function instance() |
|
24 | - { |
|
25 | - return parent::get_instance(__CLASS__); |
|
26 | - } |
|
27 | - |
|
28 | - |
|
29 | - /** |
|
30 | - * set_hooks - for hooking into EE Core, other modules, etc |
|
31 | - * |
|
32 | - * @return void |
|
33 | - */ |
|
34 | - public static function set_hooks() |
|
35 | - { |
|
36 | - // create download buttons |
|
37 | - add_filter( |
|
38 | - 'FHEE__espresso_list_of_event_dates__datetime_html', |
|
39 | - ['EED_Ical', 'generate_add_to_iCal_button'], |
|
40 | - 10, |
|
41 | - 2 |
|
42 | - ); |
|
43 | - // process ics download request |
|
44 | - EE_Config::register_route('download_ics_file', 'EED_Ical', 'download_ics_file'); |
|
45 | - } |
|
46 | - |
|
47 | - |
|
48 | - /** |
|
49 | - * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
50 | - * |
|
51 | - * @return void |
|
52 | - */ |
|
53 | - public static function set_hooks_admin() |
|
54 | - { |
|
55 | - } |
|
56 | - |
|
57 | - |
|
58 | - /** |
|
59 | - * run - initial module setup |
|
60 | - * |
|
61 | - * @param WP $WP |
|
62 | - * @return void |
|
63 | - */ |
|
64 | - public function run($WP) |
|
65 | - { |
|
66 | - } |
|
67 | - |
|
68 | - |
|
69 | - /** |
|
70 | - * @param $html |
|
71 | - * @param $datetime |
|
72 | - * @return string |
|
73 | - * @throws EE_Error |
|
74 | - * @throws ReflectionException |
|
75 | - */ |
|
76 | - public static function generate_add_to_iCal_button($html, $datetime) |
|
77 | - { |
|
78 | - // first verify a proper datetime object has been received |
|
79 | - if ($datetime instanceof EE_Datetime) { |
|
80 | - // set whether a link or submit button is shown |
|
81 | - $iCal_type = apply_filters('FHEE__EED_Ical__generate_add_to_iCal_button__iCal_type', 'submit'); |
|
82 | - // generate a link to the route we registered in set_hooks() |
|
83 | - $URL = add_query_arg(['ee' => 'download_ics_file', 'ics_id' => $datetime->ID()], site_url()); |
|
84 | - $URL = esc_url_Raw($URL); |
|
85 | - // what type ? |
|
86 | - switch ($iCal_type) { |
|
87 | - // submit buttons appear as buttons and are very compatible with a theme's style |
|
88 | - case 'submit': |
|
89 | - $html .= '<form id="download-iCal-frm-' . $datetime->ID(); |
|
90 | - $html .= '" class="download-iCal-frm" action="' . $URL . '" method="post" >'; |
|
91 | - $html .= '<input type="submit" class="ee-ical-sbmt" value="" title="'; |
|
92 | - $html .= esc_html__('Add to iCal Calendar', 'event_espresso') . '"/>'; |
|
93 | - $html .= '</form>'; |
|
94 | - break; |
|
95 | - // buttons are just links that have been styled to appear as buttons, |
|
96 | - // but may not be blend with a theme as well as submit buttons |
|
97 | - case 'button': |
|
98 | - $html .= '<a class="ee-ical-btn small ee-button ee-roundish" href="' . $URL; |
|
99 | - $html .= '" title="' . esc_html__('Add to iCal Calendar', 'event_espresso') . '">'; |
|
100 | - $html .= ' <span class="dashicons dashicons-calendar"></span>'; |
|
101 | - $html .= '</a>'; |
|
102 | - break; |
|
103 | - // links are just links that use the calendar dashicon |
|
104 | - case 'icon': |
|
105 | - $html .= '<a class="ee-ical-lnk" href="' . $URL . '" title="'; |
|
106 | - $html .= esc_html__('Add to iCal Calendar', 'event_espresso') . '">'; |
|
107 | - $html .= ' <span class="dashicons dashicons-calendar"></span>'; |
|
108 | - $html .= '</a>'; |
|
109 | - break; |
|
110 | - } |
|
111 | - } |
|
112 | - return $html; |
|
113 | - } |
|
114 | - |
|
115 | - |
|
116 | - /** |
|
117 | - * @return void |
|
118 | - * @throws EE_Error |
|
119 | - * @throws ReflectionException |
|
120 | - */ |
|
121 | - public static function download_ics_file() |
|
122 | - { |
|
123 | - $request = self::getRequest(); |
|
124 | - if ($request->requestParamIsSet('ics_id')) { |
|
125 | - $DTT_ID = $request->getRequestParam('ics_id', 0, 'int'); |
|
126 | - $datetime = EEM_Datetime::instance()->get_one_by_ID($DTT_ID); |
|
127 | - if ($datetime instanceof EE_Datetime) { |
|
128 | - // get related event, venues, and event categories |
|
129 | - $event = $datetime->event(); |
|
130 | - if ($event instanceof EE_Event) { |
|
131 | - // get related category Term object and it's name |
|
132 | - $category = $event->first_event_category(); |
|
133 | - if ($category instanceof EE_Term) { |
|
134 | - $category = $category->name(); |
|
135 | - } |
|
136 | - $location = ''; |
|
137 | - // get first related venue and convert to CSV string |
|
138 | - $venue = $event->venues(['limit' => 1]); |
|
139 | - if (is_array($venue) && ! empty($venue)) { |
|
140 | - $venue = array_shift($venue); |
|
141 | - if ($venue instanceof EE_Venue) { |
|
142 | - $location = espresso_venue_raw_address('inline', $venue->ID(), false); |
|
143 | - } |
|
144 | - } |
|
145 | - |
|
146 | - // Generate filename |
|
147 | - $filename = $event->slug() . '-' . $datetime->start_date('Y-m-d') . '.ics'; |
|
148 | - |
|
149 | - // Check the datetime status has not been cancelled and set the ics value accordingly |
|
150 | - $status = $datetime->get_active_status(); |
|
151 | - $status = $status === EE_Datetime::cancelled ? 'CANCELLED' : 'CONFIRMED'; |
|
152 | - |
|
153 | - // Create array of ics details, escape strings, convert timestamps to ics format, etc |
|
154 | - $ics_data = [ |
|
155 | - 'ORGANIZER_NAME' => EE_Registry::instance()->CFG->organization->name, |
|
156 | - 'UID' => md5($event->name() . $event->ID() . $datetime->ID()), |
|
157 | - 'ORGANIZER' => EE_Registry::instance()->CFG->organization->email, |
|
158 | - 'DTSTAMP' => date(EED_Ical::iCal_datetime_format), |
|
159 | - 'LOCATION' => $location, |
|
160 | - 'SUMMARY' => $event->name(), |
|
161 | - 'DESCRIPTION' => wp_strip_all_tags($event->description()), |
|
162 | - 'STATUS' => $status, |
|
163 | - 'CATEGORIES' => $category, |
|
164 | - 'URL;VALUE=URI' => get_permalink($event->ID()), |
|
165 | - 'DTSTART' => date(EED_Ical::iCal_datetime_format, $datetime->start()), |
|
166 | - 'DTEND' => date(EED_Ical::iCal_datetime_format, $datetime->end()), |
|
167 | - ]; |
|
168 | - |
|
169 | - // Filter the values used within the ics output. |
|
170 | - // NOTE - all values within ics_data will be escaped automatically. |
|
171 | - $ics_data = apply_filters('FHEE__EED_Ical__download_ics_file_ics_data', $ics_data, $datetime); |
|
172 | - |
|
173 | - // Escape all ics data |
|
174 | - foreach ($ics_data as $key => $value) { |
|
175 | - // Description is escaped differently from all all values |
|
176 | - if ($key === 'DESCRIPTION') { |
|
177 | - $ics_data[ $key ] = EED_Ical::_escape_ICal_description(wp_strip_all_tags($value)); |
|
178 | - } else { |
|
179 | - $ics_data[ $key ] = EED_Ical::_escape_ICal_data($value); |
|
180 | - } |
|
181 | - } |
|
182 | - |
|
183 | - // Pull the organizer name from ics_data and remove it from the array. |
|
184 | - $organizer_name = isset($ics_data['ORGANIZER_NAME']) |
|
185 | - ? $ics_data['ORGANIZER_NAME'] |
|
186 | - : ''; |
|
187 | - unset($ics_data['ORGANIZER_NAME']); |
|
188 | - |
|
189 | - // set headers |
|
190 | - header('Content-type: text/calendar; charset=utf-8'); |
|
191 | - header('Content-Disposition: attachment; filename="' . $filename . '"'); |
|
192 | - header('Cache-Control: private, max-age=0, must-revalidate'); |
|
193 | - header('Pragma: public'); |
|
194 | - header('Content-Type: application/octet-stream'); |
|
195 | - header('Content-Type: application/force-download'); |
|
196 | - header('Cache-Control: no-cache, must-revalidate'); |
|
197 | - header('Content-Transfer-Encoding: binary'); |
|
198 | - header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // past date |
|
199 | - ini_set('zlib.output_compression', '0'); |
|
200 | - // echo the output |
|
201 | - echo "BEGIN:VCALENDAR\r\n"; |
|
202 | - echo "VERSION:2.0\r\n"; |
|
203 | - echo "PRODID:-//{$organizer_name}//NONSGML PDA Calendar Version 1.0//EN\r\n"; |
|
204 | - echo "CALSCALE:GREGORIAN\r\n"; |
|
205 | - echo "BEGIN:VEVENT\r\n"; |
|
206 | - |
|
207 | - // Output all remaining values from ics_data. |
|
208 | - foreach ($ics_data as $key => $value) { |
|
209 | - echo $key . ':' . $value . "\r\n"; |
|
210 | - } |
|
211 | - |
|
212 | - echo "END:VEVENT\r\n"; |
|
213 | - echo "END:VCALENDAR\r\n"; |
|
214 | - } |
|
215 | - } |
|
216 | - } |
|
217 | - die(); |
|
218 | - } |
|
219 | - |
|
220 | - |
|
221 | - /** |
|
222 | - * _escape_ICal_data |
|
223 | - * |
|
224 | - * @param string $string |
|
225 | - * @return string |
|
226 | - */ |
|
227 | - private static function _escape_ICal_data($string = '') |
|
228 | - { |
|
229 | - return preg_replace('/([\,;])/', '\\\$1', $string); |
|
230 | - } |
|
231 | - |
|
232 | - |
|
233 | - /** |
|
234 | - * _escape_ICal_description |
|
235 | - * |
|
236 | - * @param string $description |
|
237 | - * @return string |
|
238 | - */ |
|
239 | - private static function _escape_ICal_description($description = '') |
|
240 | - { |
|
241 | - // Escape special chars within the description |
|
242 | - $description = EED_Ical::_escape_ICal_data($description); |
|
243 | - // Remove line breaks and output in iCal format |
|
244 | - return str_replace(["\r\n", "\n"], '\n', $description); |
|
245 | - } |
|
15 | + const iCal_datetime_format = 'Ymd\THis\Z'; |
|
16 | + |
|
17 | + |
|
18 | + /** |
|
19 | + * @return EED_Ical|EED_Module |
|
20 | + * @throws EE_Error |
|
21 | + * @throws ReflectionException |
|
22 | + */ |
|
23 | + public static function instance() |
|
24 | + { |
|
25 | + return parent::get_instance(__CLASS__); |
|
26 | + } |
|
27 | + |
|
28 | + |
|
29 | + /** |
|
30 | + * set_hooks - for hooking into EE Core, other modules, etc |
|
31 | + * |
|
32 | + * @return void |
|
33 | + */ |
|
34 | + public static function set_hooks() |
|
35 | + { |
|
36 | + // create download buttons |
|
37 | + add_filter( |
|
38 | + 'FHEE__espresso_list_of_event_dates__datetime_html', |
|
39 | + ['EED_Ical', 'generate_add_to_iCal_button'], |
|
40 | + 10, |
|
41 | + 2 |
|
42 | + ); |
|
43 | + // process ics download request |
|
44 | + EE_Config::register_route('download_ics_file', 'EED_Ical', 'download_ics_file'); |
|
45 | + } |
|
46 | + |
|
47 | + |
|
48 | + /** |
|
49 | + * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
50 | + * |
|
51 | + * @return void |
|
52 | + */ |
|
53 | + public static function set_hooks_admin() |
|
54 | + { |
|
55 | + } |
|
56 | + |
|
57 | + |
|
58 | + /** |
|
59 | + * run - initial module setup |
|
60 | + * |
|
61 | + * @param WP $WP |
|
62 | + * @return void |
|
63 | + */ |
|
64 | + public function run($WP) |
|
65 | + { |
|
66 | + } |
|
67 | + |
|
68 | + |
|
69 | + /** |
|
70 | + * @param $html |
|
71 | + * @param $datetime |
|
72 | + * @return string |
|
73 | + * @throws EE_Error |
|
74 | + * @throws ReflectionException |
|
75 | + */ |
|
76 | + public static function generate_add_to_iCal_button($html, $datetime) |
|
77 | + { |
|
78 | + // first verify a proper datetime object has been received |
|
79 | + if ($datetime instanceof EE_Datetime) { |
|
80 | + // set whether a link or submit button is shown |
|
81 | + $iCal_type = apply_filters('FHEE__EED_Ical__generate_add_to_iCal_button__iCal_type', 'submit'); |
|
82 | + // generate a link to the route we registered in set_hooks() |
|
83 | + $URL = add_query_arg(['ee' => 'download_ics_file', 'ics_id' => $datetime->ID()], site_url()); |
|
84 | + $URL = esc_url_Raw($URL); |
|
85 | + // what type ? |
|
86 | + switch ($iCal_type) { |
|
87 | + // submit buttons appear as buttons and are very compatible with a theme's style |
|
88 | + case 'submit': |
|
89 | + $html .= '<form id="download-iCal-frm-' . $datetime->ID(); |
|
90 | + $html .= '" class="download-iCal-frm" action="' . $URL . '" method="post" >'; |
|
91 | + $html .= '<input type="submit" class="ee-ical-sbmt" value="" title="'; |
|
92 | + $html .= esc_html__('Add to iCal Calendar', 'event_espresso') . '"/>'; |
|
93 | + $html .= '</form>'; |
|
94 | + break; |
|
95 | + // buttons are just links that have been styled to appear as buttons, |
|
96 | + // but may not be blend with a theme as well as submit buttons |
|
97 | + case 'button': |
|
98 | + $html .= '<a class="ee-ical-btn small ee-button ee-roundish" href="' . $URL; |
|
99 | + $html .= '" title="' . esc_html__('Add to iCal Calendar', 'event_espresso') . '">'; |
|
100 | + $html .= ' <span class="dashicons dashicons-calendar"></span>'; |
|
101 | + $html .= '</a>'; |
|
102 | + break; |
|
103 | + // links are just links that use the calendar dashicon |
|
104 | + case 'icon': |
|
105 | + $html .= '<a class="ee-ical-lnk" href="' . $URL . '" title="'; |
|
106 | + $html .= esc_html__('Add to iCal Calendar', 'event_espresso') . '">'; |
|
107 | + $html .= ' <span class="dashicons dashicons-calendar"></span>'; |
|
108 | + $html .= '</a>'; |
|
109 | + break; |
|
110 | + } |
|
111 | + } |
|
112 | + return $html; |
|
113 | + } |
|
114 | + |
|
115 | + |
|
116 | + /** |
|
117 | + * @return void |
|
118 | + * @throws EE_Error |
|
119 | + * @throws ReflectionException |
|
120 | + */ |
|
121 | + public static function download_ics_file() |
|
122 | + { |
|
123 | + $request = self::getRequest(); |
|
124 | + if ($request->requestParamIsSet('ics_id')) { |
|
125 | + $DTT_ID = $request->getRequestParam('ics_id', 0, 'int'); |
|
126 | + $datetime = EEM_Datetime::instance()->get_one_by_ID($DTT_ID); |
|
127 | + if ($datetime instanceof EE_Datetime) { |
|
128 | + // get related event, venues, and event categories |
|
129 | + $event = $datetime->event(); |
|
130 | + if ($event instanceof EE_Event) { |
|
131 | + // get related category Term object and it's name |
|
132 | + $category = $event->first_event_category(); |
|
133 | + if ($category instanceof EE_Term) { |
|
134 | + $category = $category->name(); |
|
135 | + } |
|
136 | + $location = ''; |
|
137 | + // get first related venue and convert to CSV string |
|
138 | + $venue = $event->venues(['limit' => 1]); |
|
139 | + if (is_array($venue) && ! empty($venue)) { |
|
140 | + $venue = array_shift($venue); |
|
141 | + if ($venue instanceof EE_Venue) { |
|
142 | + $location = espresso_venue_raw_address('inline', $venue->ID(), false); |
|
143 | + } |
|
144 | + } |
|
145 | + |
|
146 | + // Generate filename |
|
147 | + $filename = $event->slug() . '-' . $datetime->start_date('Y-m-d') . '.ics'; |
|
148 | + |
|
149 | + // Check the datetime status has not been cancelled and set the ics value accordingly |
|
150 | + $status = $datetime->get_active_status(); |
|
151 | + $status = $status === EE_Datetime::cancelled ? 'CANCELLED' : 'CONFIRMED'; |
|
152 | + |
|
153 | + // Create array of ics details, escape strings, convert timestamps to ics format, etc |
|
154 | + $ics_data = [ |
|
155 | + 'ORGANIZER_NAME' => EE_Registry::instance()->CFG->organization->name, |
|
156 | + 'UID' => md5($event->name() . $event->ID() . $datetime->ID()), |
|
157 | + 'ORGANIZER' => EE_Registry::instance()->CFG->organization->email, |
|
158 | + 'DTSTAMP' => date(EED_Ical::iCal_datetime_format), |
|
159 | + 'LOCATION' => $location, |
|
160 | + 'SUMMARY' => $event->name(), |
|
161 | + 'DESCRIPTION' => wp_strip_all_tags($event->description()), |
|
162 | + 'STATUS' => $status, |
|
163 | + 'CATEGORIES' => $category, |
|
164 | + 'URL;VALUE=URI' => get_permalink($event->ID()), |
|
165 | + 'DTSTART' => date(EED_Ical::iCal_datetime_format, $datetime->start()), |
|
166 | + 'DTEND' => date(EED_Ical::iCal_datetime_format, $datetime->end()), |
|
167 | + ]; |
|
168 | + |
|
169 | + // Filter the values used within the ics output. |
|
170 | + // NOTE - all values within ics_data will be escaped automatically. |
|
171 | + $ics_data = apply_filters('FHEE__EED_Ical__download_ics_file_ics_data', $ics_data, $datetime); |
|
172 | + |
|
173 | + // Escape all ics data |
|
174 | + foreach ($ics_data as $key => $value) { |
|
175 | + // Description is escaped differently from all all values |
|
176 | + if ($key === 'DESCRIPTION') { |
|
177 | + $ics_data[ $key ] = EED_Ical::_escape_ICal_description(wp_strip_all_tags($value)); |
|
178 | + } else { |
|
179 | + $ics_data[ $key ] = EED_Ical::_escape_ICal_data($value); |
|
180 | + } |
|
181 | + } |
|
182 | + |
|
183 | + // Pull the organizer name from ics_data and remove it from the array. |
|
184 | + $organizer_name = isset($ics_data['ORGANIZER_NAME']) |
|
185 | + ? $ics_data['ORGANIZER_NAME'] |
|
186 | + : ''; |
|
187 | + unset($ics_data['ORGANIZER_NAME']); |
|
188 | + |
|
189 | + // set headers |
|
190 | + header('Content-type: text/calendar; charset=utf-8'); |
|
191 | + header('Content-Disposition: attachment; filename="' . $filename . '"'); |
|
192 | + header('Cache-Control: private, max-age=0, must-revalidate'); |
|
193 | + header('Pragma: public'); |
|
194 | + header('Content-Type: application/octet-stream'); |
|
195 | + header('Content-Type: application/force-download'); |
|
196 | + header('Cache-Control: no-cache, must-revalidate'); |
|
197 | + header('Content-Transfer-Encoding: binary'); |
|
198 | + header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // past date |
|
199 | + ini_set('zlib.output_compression', '0'); |
|
200 | + // echo the output |
|
201 | + echo "BEGIN:VCALENDAR\r\n"; |
|
202 | + echo "VERSION:2.0\r\n"; |
|
203 | + echo "PRODID:-//{$organizer_name}//NONSGML PDA Calendar Version 1.0//EN\r\n"; |
|
204 | + echo "CALSCALE:GREGORIAN\r\n"; |
|
205 | + echo "BEGIN:VEVENT\r\n"; |
|
206 | + |
|
207 | + // Output all remaining values from ics_data. |
|
208 | + foreach ($ics_data as $key => $value) { |
|
209 | + echo $key . ':' . $value . "\r\n"; |
|
210 | + } |
|
211 | + |
|
212 | + echo "END:VEVENT\r\n"; |
|
213 | + echo "END:VCALENDAR\r\n"; |
|
214 | + } |
|
215 | + } |
|
216 | + } |
|
217 | + die(); |
|
218 | + } |
|
219 | + |
|
220 | + |
|
221 | + /** |
|
222 | + * _escape_ICal_data |
|
223 | + * |
|
224 | + * @param string $string |
|
225 | + * @return string |
|
226 | + */ |
|
227 | + private static function _escape_ICal_data($string = '') |
|
228 | + { |
|
229 | + return preg_replace('/([\,;])/', '\\\$1', $string); |
|
230 | + } |
|
231 | + |
|
232 | + |
|
233 | + /** |
|
234 | + * _escape_ICal_description |
|
235 | + * |
|
236 | + * @param string $description |
|
237 | + * @return string |
|
238 | + */ |
|
239 | + private static function _escape_ICal_description($description = '') |
|
240 | + { |
|
241 | + // Escape special chars within the description |
|
242 | + $description = EED_Ical::_escape_ICal_data($description); |
|
243 | + // Remove line breaks and output in iCal format |
|
244 | + return str_replace(["\r\n", "\n"], '\n', $description); |
|
245 | + } |
|
246 | 246 | } |
@@ -4,7 +4,7 @@ |
||
4 | 4 | use EventEspresso\core\services\request\sanitizers\AllowedTags; |
5 | 5 | |
6 | 6 | assert($question_group instanceof EE_Question_Group); |
7 | -assert(isset($all_questions) && (empty($all_questions) || is_array($all_questions)));// list of unused questions |
|
7 | +assert(isset($all_questions) && (empty($all_questions) || is_array($all_questions))); // list of unused questions |
|
8 | 8 | foreach ($all_questions as $question_option) { |
9 | 9 | assert($question_option); |
10 | 10 | assert($question_option instanceof EE_Question); |
@@ -10,30 +10,30 @@ discard block |
||
10 | 10 | */ |
11 | 11 | function ee_show_billing_info_cleaned(EE_Form_Section_Proper $form_section, $found_cc_data = false) |
12 | 12 | { |
13 | - foreach ($form_section->subsections() as $subsection) { |
|
14 | - if ($subsection instanceof EE_Form_Input_Base) { |
|
15 | - if ( |
|
16 | - $subsection->get_sensitive_data_removal_strategy() instanceof EE_All_Sensitive_Data_Removal |
|
17 | - || $subsection->get_sensitive_data_removal_strategy() instanceof EE_CCV_Sensitive_Data_Removal |
|
18 | - || $subsection->get_display_strategy() instanceof EE_Hidden_Display_Strategy |
|
19 | - ) { |
|
20 | - continue; |
|
21 | - } |
|
22 | - if ($subsection->get_sensitive_data_removal_strategy() instanceof EE_Credit_Card_Sensitive_Data_Removal) { |
|
23 | - $found_cc_data = true; |
|
24 | - } |
|
25 | - ?> |
|
13 | + foreach ($form_section->subsections() as $subsection) { |
|
14 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
15 | + if ( |
|
16 | + $subsection->get_sensitive_data_removal_strategy() instanceof EE_All_Sensitive_Data_Removal |
|
17 | + || $subsection->get_sensitive_data_removal_strategy() instanceof EE_CCV_Sensitive_Data_Removal |
|
18 | + || $subsection->get_display_strategy() instanceof EE_Hidden_Display_Strategy |
|
19 | + ) { |
|
20 | + continue; |
|
21 | + } |
|
22 | + if ($subsection->get_sensitive_data_removal_strategy() instanceof EE_Credit_Card_Sensitive_Data_Removal) { |
|
23 | + $found_cc_data = true; |
|
24 | + } |
|
25 | + ?> |
|
26 | 26 | <div class="clearfix"> |
27 | 27 | <span class="admin-side-mbox-label-spn lt-grey-txt float-left"> |
28 | 28 | <?php echo wp_kses($subsection->get_html_for_label(), AllowedTags::getWithFormTags()); ?> |
29 | 29 | </span> |
30 | 30 | <?php echo wp_kses($subsection->pretty_value(), AllowedTags::getWithFormTags()); ?> |
31 | 31 | </div><?php |
32 | - } elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
33 | - $found_cc_data = ee_show_billing_info_cleaned($subsection, $found_cc_data); |
|
34 | - } |
|
35 | - } |
|
36 | - return $found_cc_data; |
|
32 | + } elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
33 | + $found_cc_data = ee_show_billing_info_cleaned($subsection, $found_cc_data); |
|
34 | + } |
|
35 | + } |
|
36 | + return $found_cc_data; |
|
37 | 37 | } |
38 | 38 | ?> |
39 | 39 | |
@@ -43,24 +43,24 @@ discard block |
||
43 | 43 | <?php esc_html_e('There is no billing info for this transaction.', 'event_espresso'); ?><br/> |
44 | 44 | </div> |
45 | 45 | <?php else : |
46 | - $found_cc_data = ee_show_billing_info_cleaned($billing_form); |
|
47 | - if ( |
|
48 | - apply_filters( |
|
49 | - 'FHEE__txn_admin_details_side_meta_box_billing_info__show_default_note', |
|
50 | - $found_cc_data, |
|
51 | - $billing_form |
|
52 | - ) |
|
53 | - ) { ?> |
|
46 | + $found_cc_data = ee_show_billing_info_cleaned($billing_form); |
|
47 | + if ( |
|
48 | + apply_filters( |
|
49 | + 'FHEE__txn_admin_details_side_meta_box_billing_info__show_default_note', |
|
50 | + $found_cc_data, |
|
51 | + $billing_form |
|
52 | + ) |
|
53 | + ) { ?> |
|
54 | 54 | <p class="help"> |
55 | 55 | <?php esc_html_e( |
56 | - 'Note: Card expiry dates and CCV are not stored. Only the last 4 digits of card numbers are stored.', |
|
57 | - 'event_espresso' |
|
58 | - ); ?> |
|
56 | + 'Note: Card expiry dates and CCV are not stored. Only the last 4 digits of card numbers are stored.', |
|
57 | + 'event_espresso' |
|
58 | + ); ?> |
|
59 | 59 | </p> |
60 | 60 | <?php |
61 | - } |
|
62 | - do_action('AHEE__txn_admin_details_side_meta_box_billing_info__billing_form_footer', $billing_form); |
|
63 | - endif; ?> |
|
61 | + } |
|
62 | + do_action('AHEE__txn_admin_details_side_meta_box_billing_info__billing_form_footer', $billing_form); |
|
63 | + endif; ?> |
|
64 | 64 | |
65 | 65 | </div> |
66 | 66 |
@@ -131,7 +131,7 @@ discard block |
||
131 | 131 | */ |
132 | 132 | public static function get_timezone_string_from_abbreviations_list($gmt_offset = 0, $coerce = true) |
133 | 133 | { |
134 | - $gmt_offset = (int) $gmt_offset; |
|
134 | + $gmt_offset = (int) $gmt_offset; |
|
135 | 135 | /** @var array[] $abbreviations */ |
136 | 136 | $abbreviations = DateTimeZone::listAbbreviations(); |
137 | 137 | foreach ($abbreviations as $abbreviation) { |
@@ -326,7 +326,7 @@ discard block |
||
326 | 326 | */ |
327 | 327 | protected static function _modify_datetime_object(DateTime $DateTime, $period = 'years', $value = 1, $operand = '+') |
328 | 328 | { |
329 | - if (! $DateTime instanceof DateTime) { |
|
329 | + if ( ! $DateTime instanceof DateTime) { |
|
330 | 330 | throw new EE_Error( |
331 | 331 | sprintf( |
332 | 332 | esc_html__('Expected a PHP DateTime object, but instead received %1$s', 'event_espresso'), |
@@ -336,25 +336,25 @@ discard block |
||
336 | 336 | } |
337 | 337 | switch ($period) { |
338 | 338 | case 'years': |
339 | - $value = 'P' . $value . 'Y'; |
|
339 | + $value = 'P'.$value.'Y'; |
|
340 | 340 | break; |
341 | 341 | case 'months': |
342 | - $value = 'P' . $value . 'M'; |
|
342 | + $value = 'P'.$value.'M'; |
|
343 | 343 | break; |
344 | 344 | case 'weeks': |
345 | - $value = 'P' . $value . 'W'; |
|
345 | + $value = 'P'.$value.'W'; |
|
346 | 346 | break; |
347 | 347 | case 'days': |
348 | - $value = 'P' . $value . 'D'; |
|
348 | + $value = 'P'.$value.'D'; |
|
349 | 349 | break; |
350 | 350 | case 'hours': |
351 | - $value = 'PT' . $value . 'H'; |
|
351 | + $value = 'PT'.$value.'H'; |
|
352 | 352 | break; |
353 | 353 | case 'minutes': |
354 | - $value = 'PT' . $value . 'M'; |
|
354 | + $value = 'PT'.$value.'M'; |
|
355 | 355 | break; |
356 | 356 | case 'seconds': |
357 | - $value = 'PT' . $value . 'S'; |
|
357 | + $value = 'PT'.$value.'S'; |
|
358 | 358 | break; |
359 | 359 | } |
360 | 360 | switch ($operand) { |
@@ -382,7 +382,7 @@ discard block |
||
382 | 382 | */ |
383 | 383 | protected static function _modify_timestamp($timestamp, $period = 'years', $value = 1, $operand = '+') |
384 | 384 | { |
385 | - if (! preg_match(EE_Datetime_Field::unix_timestamp_regex, $timestamp)) { |
|
385 | + if ( ! preg_match(EE_Datetime_Field::unix_timestamp_regex, $timestamp)) { |
|
386 | 386 | throw new EE_Error( |
387 | 387 | sprintf( |
388 | 388 | esc_html__('Expected a Unix timestamp, but instead received %1$s', 'event_espresso'), |
@@ -495,7 +495,7 @@ discard block |
||
495 | 495 | 'date' => $date_format['js'], |
496 | 496 | 'time' => $time_format['js'], |
497 | 497 | ), |
498 | - 'moment' => $date_format['moment'] . ' ' . $time_format['moment'], |
|
498 | + 'moment' => $date_format['moment'].' '.$time_format['moment'], |
|
499 | 499 | 'moment_split' => array( |
500 | 500 | 'date' => $date_format['moment'], |
501 | 501 | 'time' => $time_format['moment'] |
@@ -518,7 +518,7 @@ discard block |
||
518 | 518 | * |
519 | 519 | * @var array |
520 | 520 | */ |
521 | - $symbols_map = array( |
|
521 | + $symbols_map = array( |
|
522 | 522 | // Day |
523 | 523 | // 01 |
524 | 524 | 'd' => array( |
@@ -670,26 +670,26 @@ discard block |
||
670 | 670 | $escaping = false; |
671 | 671 | $format_string_length = strlen($format_string); |
672 | 672 | for ($i = 0; $i < $format_string_length; $i++) { |
673 | - $char = $format_string[ $i ]; |
|
673 | + $char = $format_string[$i]; |
|
674 | 674 | if ($char === '\\') { // PHP date format escaping character |
675 | 675 | $i++; |
676 | 676 | if ($escaping) { |
677 | - $jquery_ui_format .= $format_string[ $i ]; |
|
678 | - $moment_format .= $format_string[ $i ]; |
|
677 | + $jquery_ui_format .= $format_string[$i]; |
|
678 | + $moment_format .= $format_string[$i]; |
|
679 | 679 | } else { |
680 | - $jquery_ui_format .= '\'' . $format_string[ $i ]; |
|
681 | - $moment_format .= $format_string[ $i ]; |
|
680 | + $jquery_ui_format .= '\''.$format_string[$i]; |
|
681 | + $moment_format .= $format_string[$i]; |
|
682 | 682 | } |
683 | 683 | $escaping = true; |
684 | 684 | } else { |
685 | 685 | if ($escaping) { |
686 | 686 | $jquery_ui_format .= "'"; |
687 | 687 | $moment_format .= "'"; |
688 | - $escaping = false; |
|
688 | + $escaping = false; |
|
689 | 689 | } |
690 | - if (isset($symbols_map[ $char ])) { |
|
691 | - $jquery_ui_format .= $symbols_map[ $char ]['js']; |
|
692 | - $moment_format .= $symbols_map[ $char ]['moment']; |
|
690 | + if (isset($symbols_map[$char])) { |
|
691 | + $jquery_ui_format .= $symbols_map[$char]['js']; |
|
692 | + $moment_format .= $symbols_map[$char]['moment']; |
|
693 | 693 | } else { |
694 | 694 | $jquery_ui_format .= $char; |
695 | 695 | $moment_format .= $char; |
@@ -747,7 +747,7 @@ discard block |
||
747 | 747 | { |
748 | 748 | |
749 | 749 | if ( |
750 | - (! $date_1 instanceof DateTime || ! $date_2 instanceof DateTime) |
|
750 | + ( ! $date_1 instanceof DateTime || ! $date_2 instanceof DateTime) |
|
751 | 751 | || ($date_1->format(EE_Datetime_Field::mysql_time_format) !== '00:00:00' |
752 | 752 | || $date_2->format( |
753 | 753 | EE_Datetime_Field::mysql_time_format |
@@ -783,8 +783,8 @@ discard block |
||
783 | 783 | ? $DateTimeZone->getOffset(new DateTime('now')) / HOUR_IN_SECONDS |
784 | 784 | : (float) get_option('gmt_offset'); |
785 | 785 | $query_interval = $offset < 0 |
786 | - ? 'DATE_SUB(' . $field_for_interval . ', INTERVAL ' . $offset * -1 . ' HOUR)' |
|
787 | - : 'DATE_ADD(' . $field_for_interval . ', INTERVAL ' . $offset . ' HOUR)'; |
|
786 | + ? 'DATE_SUB('.$field_for_interval.', INTERVAL '.$offset * -1.' HOUR)' |
|
787 | + : 'DATE_ADD('.$field_for_interval.', INTERVAL '.$offset.' HOUR)'; |
|
788 | 788 | return $query_interval; |
789 | 789 | } |
790 | 790 | |
@@ -801,16 +801,16 @@ discard block |
||
801 | 801 | public static function get_timezone_string_for_display() |
802 | 802 | { |
803 | 803 | $pretty_timezone = apply_filters('FHEE__EEH_DTT_Helper__get_timezone_string_for_display', ''); |
804 | - if (! empty($pretty_timezone)) { |
|
804 | + if ( ! empty($pretty_timezone)) { |
|
805 | 805 | return esc_html($pretty_timezone); |
806 | 806 | } |
807 | 807 | $timezone_string = get_option('timezone_string'); |
808 | 808 | if ($timezone_string) { |
809 | 809 | static $mo_loaded = false; |
810 | 810 | // Load translations for continents and cities just like wp_timezone_choice does |
811 | - if (! $mo_loaded) { |
|
811 | + if ( ! $mo_loaded) { |
|
812 | 812 | $locale = get_locale(); |
813 | - $mofile = WP_LANG_DIR . '/continents-cities-' . $locale . '.mo'; |
|
813 | + $mofile = WP_LANG_DIR.'/continents-cities-'.$locale.'.mo'; |
|
814 | 814 | load_textdomain('continents-cities', $mofile); |
815 | 815 | $mo_loaded = true; |
816 | 816 | } |
@@ -837,10 +837,10 @@ discard block |
||
837 | 837 | } else { |
838 | 838 | // convert the part after the decimal, eg "5" (from x.5) or "25" (from x.25) |
839 | 839 | // to minutes, eg 30 or 15, respectively |
840 | - $hour_fraction = (float) ('0.' . $parts[1]); |
|
840 | + $hour_fraction = (float) ('0.'.$parts[1]); |
|
841 | 841 | $parts[1] = (string) $hour_fraction * 60; |
842 | 842 | } |
843 | - return sprintf(esc_html__('UTC%1$s', 'event_espresso'), $prefix . implode(':', $parts)); |
|
843 | + return sprintf(esc_html__('UTC%1$s', 'event_espresso'), $prefix.implode(':', $parts)); |
|
844 | 844 | } |
845 | 845 | |
846 | 846 | |
@@ -923,9 +923,9 @@ discard block |
||
923 | 923 | 'Pacific', |
924 | 924 | ); |
925 | 925 | // Load translations for continents and cities. |
926 | - if (! $mo_loaded || $locale !== $locale_loaded) { |
|
926 | + if ( ! $mo_loaded || $locale !== $locale_loaded) { |
|
927 | 927 | $locale_loaded = $locale ? $locale : get_locale(); |
928 | - $mofile = WP_LANG_DIR . '/continents-cities-' . $locale_loaded . '.mo'; |
|
928 | + $mofile = WP_LANG_DIR.'/continents-cities-'.$locale_loaded.'.mo'; |
|
929 | 929 | unload_textdomain('continents-cities'); |
930 | 930 | load_textdomain('continents-cities', $mofile); |
931 | 931 | $mo_loaded = true; |
@@ -933,11 +933,11 @@ discard block |
||
933 | 933 | $zone_data = array(); |
934 | 934 | foreach (timezone_identifiers_list() as $zone) { |
935 | 935 | $zone = explode('/', $zone); |
936 | - if (! in_array($zone[0], $continents, true)) { |
|
936 | + if ( ! in_array($zone[0], $continents, true)) { |
|
937 | 937 | continue; |
938 | 938 | } |
939 | 939 | // This determines what gets set and translated - we don't translate Etc/* strings here, they are done later |
940 | - $exists = array( |
|
940 | + $exists = array( |
|
941 | 941 | 0 => isset($zone[0]) && $zone[0], |
942 | 942 | 1 => isset($zone[1]) && $zone[1], |
943 | 943 | 2 => isset($zone[2]) && $zone[2], |
@@ -967,7 +967,7 @@ discard block |
||
967 | 967 | usort($zone_data, '_wp_timezone_choice_usort_callback'); |
968 | 968 | $structure = array(); |
969 | 969 | if (empty($selected_zone)) { |
970 | - $structure[] = '<option selected value="">' . esc_html__('Select a city', 'event_espresso') . '</option>'; |
|
970 | + $structure[] = '<option selected value="">'.esc_html__('Select a city', 'event_espresso').'</option>'; |
|
971 | 971 | } |
972 | 972 | foreach ($zone_data as $key => $zone) { |
973 | 973 | // Build value in an array to join later |
@@ -978,31 +978,31 @@ discard block |
||
978 | 978 | } else { |
979 | 979 | // It's inside a continent group |
980 | 980 | // Continent optgroup |
981 | - if (! isset($zone_data[ $key - 1 ]) || $zone_data[ $key - 1 ]['continent'] !== $zone['continent']) { |
|
981 | + if ( ! isset($zone_data[$key - 1]) || $zone_data[$key - 1]['continent'] !== $zone['continent']) { |
|
982 | 982 | $label = $zone['t_continent']; |
983 | - $structure[] = '<optgroup label="' . esc_attr($label) . '">'; |
|
983 | + $structure[] = '<optgroup label="'.esc_attr($label).'">'; |
|
984 | 984 | } |
985 | 985 | // Add the city to the value |
986 | 986 | $value[] = $zone['city']; |
987 | 987 | $display = $zone['t_city']; |
988 | - if (! empty($zone['subcity'])) { |
|
988 | + if ( ! empty($zone['subcity'])) { |
|
989 | 989 | // Add the subcity to the value |
990 | 990 | $value[] = $zone['subcity']; |
991 | - $display .= ' - ' . $zone['t_subcity']; |
|
991 | + $display .= ' - '.$zone['t_subcity']; |
|
992 | 992 | } |
993 | 993 | } |
994 | 994 | // Build the value |
995 | 995 | $value = implode('/', $value); |
996 | 996 | $selected = $value === $selected_zone ? ' selected' : ''; |
997 | - $structure[] = '<option value="' . esc_attr($value) . '"' . $selected . '>' |
|
997 | + $structure[] = '<option value="'.esc_attr($value).'"'.$selected.'>' |
|
998 | 998 | . esc_html($display) |
999 | 999 | . '</option>'; |
1000 | 1000 | // Close continent optgroup |
1001 | 1001 | if ( |
1002 | 1002 | ! empty($zone['city']) |
1003 | 1003 | && ( |
1004 | - ! isset($zone_data[ $key + 1 ]) |
|
1005 | - || (isset($zone_data[ $key + 1 ]) && $zone_data[ $key + 1 ]['continent'] !== $zone['continent']) |
|
1004 | + ! isset($zone_data[$key + 1]) |
|
1005 | + || (isset($zone_data[$key + 1]) && $zone_data[$key + 1]['continent'] !== $zone['continent']) |
|
1006 | 1006 | ) |
1007 | 1007 | ) { |
1008 | 1008 | $structure[] = '</optgroup>'; |
@@ -15,1045 +15,1045 @@ |
||
15 | 15 | */ |
16 | 16 | class EEH_DTT_Helper |
17 | 17 | { |
18 | - /** |
|
19 | - * return the timezone set for the WP install |
|
20 | - * |
|
21 | - * @return string valid timezone string for PHP DateTimeZone() class |
|
22 | - * @throws InvalidArgumentException |
|
23 | - * @throws InvalidDataTypeException |
|
24 | - * @throws InvalidInterfaceException |
|
25 | - */ |
|
26 | - public static function get_timezone() |
|
27 | - { |
|
28 | - return EEH_DTT_Helper::get_valid_timezone_string(); |
|
29 | - } |
|
18 | + /** |
|
19 | + * return the timezone set for the WP install |
|
20 | + * |
|
21 | + * @return string valid timezone string for PHP DateTimeZone() class |
|
22 | + * @throws InvalidArgumentException |
|
23 | + * @throws InvalidDataTypeException |
|
24 | + * @throws InvalidInterfaceException |
|
25 | + */ |
|
26 | + public static function get_timezone() |
|
27 | + { |
|
28 | + return EEH_DTT_Helper::get_valid_timezone_string(); |
|
29 | + } |
|
30 | 30 | |
31 | 31 | |
32 | - /** |
|
33 | - * get_valid_timezone_string |
|
34 | - * ensures that a valid timezone string is returned |
|
35 | - * |
|
36 | - * @param string $timezone_string |
|
37 | - * @return string |
|
38 | - * @throws InvalidArgumentException |
|
39 | - * @throws InvalidDataTypeException |
|
40 | - * @throws InvalidInterfaceException |
|
41 | - */ |
|
42 | - public static function get_valid_timezone_string($timezone_string = '') |
|
43 | - { |
|
44 | - return self::getHelperAdapter()->getValidTimezoneString($timezone_string); |
|
45 | - } |
|
32 | + /** |
|
33 | + * get_valid_timezone_string |
|
34 | + * ensures that a valid timezone string is returned |
|
35 | + * |
|
36 | + * @param string $timezone_string |
|
37 | + * @return string |
|
38 | + * @throws InvalidArgumentException |
|
39 | + * @throws InvalidDataTypeException |
|
40 | + * @throws InvalidInterfaceException |
|
41 | + */ |
|
42 | + public static function get_valid_timezone_string($timezone_string = '') |
|
43 | + { |
|
44 | + return self::getHelperAdapter()->getValidTimezoneString($timezone_string); |
|
45 | + } |
|
46 | 46 | |
47 | 47 | |
48 | - /** |
|
49 | - * This only purpose for this static method is to validate that the incoming timezone is a valid php timezone. |
|
50 | - * |
|
51 | - * @static |
|
52 | - * @param string $timezone_string Timezone string to check |
|
53 | - * @param bool $throw_error |
|
54 | - * @return bool |
|
55 | - * @throws InvalidArgumentException |
|
56 | - * @throws InvalidDataTypeException |
|
57 | - * @throws InvalidInterfaceException |
|
58 | - */ |
|
59 | - public static function validate_timezone($timezone_string, $throw_error = true) |
|
60 | - { |
|
61 | - return self::getHelperAdapter()->validateTimezone($timezone_string, $throw_error); |
|
62 | - } |
|
48 | + /** |
|
49 | + * This only purpose for this static method is to validate that the incoming timezone is a valid php timezone. |
|
50 | + * |
|
51 | + * @static |
|
52 | + * @param string $timezone_string Timezone string to check |
|
53 | + * @param bool $throw_error |
|
54 | + * @return bool |
|
55 | + * @throws InvalidArgumentException |
|
56 | + * @throws InvalidDataTypeException |
|
57 | + * @throws InvalidInterfaceException |
|
58 | + */ |
|
59 | + public static function validate_timezone($timezone_string, $throw_error = true) |
|
60 | + { |
|
61 | + return self::getHelperAdapter()->validateTimezone($timezone_string, $throw_error); |
|
62 | + } |
|
63 | 63 | |
64 | 64 | |
65 | - /** |
|
66 | - * This returns a string that can represent the provided gmt offset in format that can be passed into |
|
67 | - * DateTimeZone. This is NOT a string that can be passed as a value on the WordPress timezone_string option. |
|
68 | - * |
|
69 | - * @param float|string $gmt_offset |
|
70 | - * @return string |
|
71 | - * @throws InvalidArgumentException |
|
72 | - * @throws InvalidDataTypeException |
|
73 | - * @throws InvalidInterfaceException |
|
74 | - */ |
|
75 | - public static function get_timezone_string_from_gmt_offset($gmt_offset = '') |
|
76 | - { |
|
77 | - return self::getHelperAdapter()->getTimezoneStringFromGmtOffset($gmt_offset); |
|
78 | - } |
|
65 | + /** |
|
66 | + * This returns a string that can represent the provided gmt offset in format that can be passed into |
|
67 | + * DateTimeZone. This is NOT a string that can be passed as a value on the WordPress timezone_string option. |
|
68 | + * |
|
69 | + * @param float|string $gmt_offset |
|
70 | + * @return string |
|
71 | + * @throws InvalidArgumentException |
|
72 | + * @throws InvalidDataTypeException |
|
73 | + * @throws InvalidInterfaceException |
|
74 | + */ |
|
75 | + public static function get_timezone_string_from_gmt_offset($gmt_offset = '') |
|
76 | + { |
|
77 | + return self::getHelperAdapter()->getTimezoneStringFromGmtOffset($gmt_offset); |
|
78 | + } |
|
79 | 79 | |
80 | 80 | |
81 | - /** |
|
82 | - * Gets the site's GMT offset based on either the timezone string |
|
83 | - * (in which case teh gmt offset will vary depending on the location's |
|
84 | - * observance of daylight savings time) or the gmt_offset wp option |
|
85 | - * |
|
86 | - * @return int seconds offset |
|
87 | - * @throws InvalidArgumentException |
|
88 | - * @throws InvalidDataTypeException |
|
89 | - * @throws InvalidInterfaceException |
|
90 | - */ |
|
91 | - public static function get_site_timezone_gmt_offset() |
|
92 | - { |
|
93 | - return self::getHelperAdapter()->getSiteTimezoneGmtOffset(); |
|
94 | - } |
|
81 | + /** |
|
82 | + * Gets the site's GMT offset based on either the timezone string |
|
83 | + * (in which case teh gmt offset will vary depending on the location's |
|
84 | + * observance of daylight savings time) or the gmt_offset wp option |
|
85 | + * |
|
86 | + * @return int seconds offset |
|
87 | + * @throws InvalidArgumentException |
|
88 | + * @throws InvalidDataTypeException |
|
89 | + * @throws InvalidInterfaceException |
|
90 | + */ |
|
91 | + public static function get_site_timezone_gmt_offset() |
|
92 | + { |
|
93 | + return self::getHelperAdapter()->getSiteTimezoneGmtOffset(); |
|
94 | + } |
|
95 | 95 | |
96 | 96 | |
97 | - /** |
|
98 | - * Depending on PHP version, |
|
99 | - * there might not be valid current timezone strings to match these gmt_offsets in its timezone tables. |
|
100 | - * To get around that, for these fringe timezones we bump them to a known valid offset. |
|
101 | - * This method should ONLY be called after first verifying an timezone_string cannot be retrieved for the offset. |
|
102 | - * |
|
103 | - * @deprecated 4.9.54.rc Developers this was always meant to only be an internally used method. This will be |
|
104 | - * removed in a future version of EE. |
|
105 | - * @param int $gmt_offset |
|
106 | - * @return int |
|
107 | - * @throws InvalidArgumentException |
|
108 | - * @throws InvalidDataTypeException |
|
109 | - * @throws InvalidInterfaceException |
|
110 | - */ |
|
111 | - public static function adjust_invalid_gmt_offsets($gmt_offset = 0) |
|
112 | - { |
|
113 | - return self::getHelperAdapter()->adjustInvalidGmtOffsets($gmt_offset); |
|
114 | - } |
|
97 | + /** |
|
98 | + * Depending on PHP version, |
|
99 | + * there might not be valid current timezone strings to match these gmt_offsets in its timezone tables. |
|
100 | + * To get around that, for these fringe timezones we bump them to a known valid offset. |
|
101 | + * This method should ONLY be called after first verifying an timezone_string cannot be retrieved for the offset. |
|
102 | + * |
|
103 | + * @deprecated 4.9.54.rc Developers this was always meant to only be an internally used method. This will be |
|
104 | + * removed in a future version of EE. |
|
105 | + * @param int $gmt_offset |
|
106 | + * @return int |
|
107 | + * @throws InvalidArgumentException |
|
108 | + * @throws InvalidDataTypeException |
|
109 | + * @throws InvalidInterfaceException |
|
110 | + */ |
|
111 | + public static function adjust_invalid_gmt_offsets($gmt_offset = 0) |
|
112 | + { |
|
113 | + return self::getHelperAdapter()->adjustInvalidGmtOffsets($gmt_offset); |
|
114 | + } |
|
115 | 115 | |
116 | 116 | |
117 | - /** |
|
118 | - * get_timezone_string_from_abbreviations_list |
|
119 | - * |
|
120 | - * @deprecated 4.9.54.rc Developers, this was never intended to be public. This is a soft deprecation for now. |
|
121 | - * If you are using this, you'll want to work out an alternate way of getting the value. |
|
122 | - * @param int $gmt_offset |
|
123 | - * @param bool $coerce If true, we attempt to coerce with our adjustment table @see self::adjust_invalid_gmt_offset. |
|
124 | - * @return string |
|
125 | - * @throws EE_Error |
|
126 | - * @throws InvalidArgumentException |
|
127 | - * @throws InvalidDataTypeException |
|
128 | - * @throws InvalidInterfaceException |
|
129 | - */ |
|
130 | - public static function get_timezone_string_from_abbreviations_list($gmt_offset = 0, $coerce = true) |
|
131 | - { |
|
132 | - $gmt_offset = (int) $gmt_offset; |
|
133 | - /** @var array[] $abbreviations */ |
|
134 | - $abbreviations = DateTimeZone::listAbbreviations(); |
|
135 | - foreach ($abbreviations as $abbreviation) { |
|
136 | - foreach ($abbreviation as $timezone) { |
|
137 | - if ((int) $timezone['offset'] === $gmt_offset && (bool) $timezone['dst'] === false) { |
|
138 | - try { |
|
139 | - $offset = self::get_timezone_offset(new DateTimeZone($timezone['timezone_id'])); |
|
140 | - if ($offset !== $gmt_offset) { |
|
141 | - continue; |
|
142 | - } |
|
143 | - return $timezone['timezone_id']; |
|
144 | - } catch (Exception $e) { |
|
145 | - continue; |
|
146 | - } |
|
147 | - } |
|
148 | - } |
|
149 | - } |
|
150 | - // if $coerce is true, let's see if we can get a timezone string after the offset is adjusted |
|
151 | - if ($coerce === true) { |
|
152 | - $timezone_string = self::get_timezone_string_from_abbreviations_list( |
|
153 | - self::adjust_invalid_gmt_offsets($gmt_offset), |
|
154 | - false |
|
155 | - ); |
|
156 | - if ($timezone_string) { |
|
157 | - return $timezone_string; |
|
158 | - } |
|
159 | - } |
|
160 | - throw new EE_Error( |
|
161 | - sprintf( |
|
162 | - esc_html__( |
|
163 | - 'The provided GMT offset (%1$s), is invalid, please check with %2$sthis list%3$s for what valid timezones can be used', |
|
164 | - 'event_espresso' |
|
165 | - ), |
|
166 | - $gmt_offset / HOUR_IN_SECONDS, |
|
167 | - '<a href="http://www.php.net/manual/en/timezones.php">', |
|
168 | - '</a>' |
|
169 | - ) |
|
170 | - ); |
|
171 | - } |
|
117 | + /** |
|
118 | + * get_timezone_string_from_abbreviations_list |
|
119 | + * |
|
120 | + * @deprecated 4.9.54.rc Developers, this was never intended to be public. This is a soft deprecation for now. |
|
121 | + * If you are using this, you'll want to work out an alternate way of getting the value. |
|
122 | + * @param int $gmt_offset |
|
123 | + * @param bool $coerce If true, we attempt to coerce with our adjustment table @see self::adjust_invalid_gmt_offset. |
|
124 | + * @return string |
|
125 | + * @throws EE_Error |
|
126 | + * @throws InvalidArgumentException |
|
127 | + * @throws InvalidDataTypeException |
|
128 | + * @throws InvalidInterfaceException |
|
129 | + */ |
|
130 | + public static function get_timezone_string_from_abbreviations_list($gmt_offset = 0, $coerce = true) |
|
131 | + { |
|
132 | + $gmt_offset = (int) $gmt_offset; |
|
133 | + /** @var array[] $abbreviations */ |
|
134 | + $abbreviations = DateTimeZone::listAbbreviations(); |
|
135 | + foreach ($abbreviations as $abbreviation) { |
|
136 | + foreach ($abbreviation as $timezone) { |
|
137 | + if ((int) $timezone['offset'] === $gmt_offset && (bool) $timezone['dst'] === false) { |
|
138 | + try { |
|
139 | + $offset = self::get_timezone_offset(new DateTimeZone($timezone['timezone_id'])); |
|
140 | + if ($offset !== $gmt_offset) { |
|
141 | + continue; |
|
142 | + } |
|
143 | + return $timezone['timezone_id']; |
|
144 | + } catch (Exception $e) { |
|
145 | + continue; |
|
146 | + } |
|
147 | + } |
|
148 | + } |
|
149 | + } |
|
150 | + // if $coerce is true, let's see if we can get a timezone string after the offset is adjusted |
|
151 | + if ($coerce === true) { |
|
152 | + $timezone_string = self::get_timezone_string_from_abbreviations_list( |
|
153 | + self::adjust_invalid_gmt_offsets($gmt_offset), |
|
154 | + false |
|
155 | + ); |
|
156 | + if ($timezone_string) { |
|
157 | + return $timezone_string; |
|
158 | + } |
|
159 | + } |
|
160 | + throw new EE_Error( |
|
161 | + sprintf( |
|
162 | + esc_html__( |
|
163 | + 'The provided GMT offset (%1$s), is invalid, please check with %2$sthis list%3$s for what valid timezones can be used', |
|
164 | + 'event_espresso' |
|
165 | + ), |
|
166 | + $gmt_offset / HOUR_IN_SECONDS, |
|
167 | + '<a href="http://www.php.net/manual/en/timezones.php">', |
|
168 | + '</a>' |
|
169 | + ) |
|
170 | + ); |
|
171 | + } |
|
172 | 172 | |
173 | 173 | |
174 | - /** |
|
175 | - * Get Timezone Transitions |
|
176 | - * |
|
177 | - * @param DateTimeZone $date_time_zone |
|
178 | - * @param int|null $time |
|
179 | - * @param bool $first_only |
|
180 | - * @return array |
|
181 | - * @throws InvalidArgumentException |
|
182 | - * @throws InvalidDataTypeException |
|
183 | - * @throws InvalidInterfaceException |
|
184 | - */ |
|
185 | - public static function get_timezone_transitions(DateTimeZone $date_time_zone, $time = null, $first_only = true) |
|
186 | - { |
|
187 | - return self::getHelperAdapter()->getTimezoneTransitions($date_time_zone, $time, $first_only); |
|
188 | - } |
|
174 | + /** |
|
175 | + * Get Timezone Transitions |
|
176 | + * |
|
177 | + * @param DateTimeZone $date_time_zone |
|
178 | + * @param int|null $time |
|
179 | + * @param bool $first_only |
|
180 | + * @return array |
|
181 | + * @throws InvalidArgumentException |
|
182 | + * @throws InvalidDataTypeException |
|
183 | + * @throws InvalidInterfaceException |
|
184 | + */ |
|
185 | + public static function get_timezone_transitions(DateTimeZone $date_time_zone, $time = null, $first_only = true) |
|
186 | + { |
|
187 | + return self::getHelperAdapter()->getTimezoneTransitions($date_time_zone, $time, $first_only); |
|
188 | + } |
|
189 | 189 | |
190 | 190 | |
191 | - /** |
|
192 | - * Get Timezone Offset for given timezone object. |
|
193 | - * |
|
194 | - * @param DateTimeZone $date_time_zone |
|
195 | - * @param null $time |
|
196 | - * @return mixed |
|
197 | - * @throws InvalidArgumentException |
|
198 | - * @throws InvalidDataTypeException |
|
199 | - * @throws InvalidInterfaceException |
|
200 | - */ |
|
201 | - public static function get_timezone_offset(DateTimeZone $date_time_zone, $time = null) |
|
202 | - { |
|
203 | - return self::getHelperAdapter()->getTimezoneOffset($date_time_zone, $time); |
|
204 | - } |
|
191 | + /** |
|
192 | + * Get Timezone Offset for given timezone object. |
|
193 | + * |
|
194 | + * @param DateTimeZone $date_time_zone |
|
195 | + * @param null $time |
|
196 | + * @return mixed |
|
197 | + * @throws InvalidArgumentException |
|
198 | + * @throws InvalidDataTypeException |
|
199 | + * @throws InvalidInterfaceException |
|
200 | + */ |
|
201 | + public static function get_timezone_offset(DateTimeZone $date_time_zone, $time = null) |
|
202 | + { |
|
203 | + return self::getHelperAdapter()->getTimezoneOffset($date_time_zone, $time); |
|
204 | + } |
|
205 | 205 | |
206 | 206 | |
207 | - /** |
|
208 | - * Prints a select input for the given timezone string. |
|
209 | - * @param string $timezone_string |
|
210 | - * @deprecatd 4.9.54.rc Soft deprecation. Consider using \EEH_DTT_Helper::wp_timezone_choice instead. |
|
211 | - * @throws InvalidArgumentException |
|
212 | - * @throws InvalidDataTypeException |
|
213 | - * @throws InvalidInterfaceException |
|
214 | - */ |
|
215 | - public static function timezone_select_input($timezone_string = '') |
|
216 | - { |
|
217 | - self::getHelperAdapter()->timezoneSelectInput($timezone_string); |
|
218 | - } |
|
207 | + /** |
|
208 | + * Prints a select input for the given timezone string. |
|
209 | + * @param string $timezone_string |
|
210 | + * @deprecatd 4.9.54.rc Soft deprecation. Consider using \EEH_DTT_Helper::wp_timezone_choice instead. |
|
211 | + * @throws InvalidArgumentException |
|
212 | + * @throws InvalidDataTypeException |
|
213 | + * @throws InvalidInterfaceException |
|
214 | + */ |
|
215 | + public static function timezone_select_input($timezone_string = '') |
|
216 | + { |
|
217 | + self::getHelperAdapter()->timezoneSelectInput($timezone_string); |
|
218 | + } |
|
219 | 219 | |
220 | 220 | |
221 | - /** |
|
222 | - * This method will take an incoming unix timestamp and add the offset to it for the given timezone_string. |
|
223 | - * If no unix timestamp is given then time() is used. If no timezone is given then the set timezone string for |
|
224 | - * the site is used. |
|
225 | - * This is used typically when using a Unix timestamp any core WP functions that expect their specially |
|
226 | - * computed timestamp (i.e. date_i18n() ) |
|
227 | - * |
|
228 | - * @param int $unix_timestamp if 0, then time() will be used. |
|
229 | - * @param string $timezone_string timezone_string. If empty, then the current set timezone for the |
|
230 | - * site will be used. |
|
231 | - * @return int $unix_timestamp with the offset applied for the given timezone. |
|
232 | - * @throws InvalidArgumentException |
|
233 | - * @throws InvalidDataTypeException |
|
234 | - * @throws InvalidInterfaceException |
|
235 | - */ |
|
236 | - public static function get_timestamp_with_offset($unix_timestamp = 0, $timezone_string = '') |
|
237 | - { |
|
238 | - return self::getHelperAdapter()->getTimestampWithOffset($unix_timestamp, $timezone_string); |
|
239 | - } |
|
221 | + /** |
|
222 | + * This method will take an incoming unix timestamp and add the offset to it for the given timezone_string. |
|
223 | + * If no unix timestamp is given then time() is used. If no timezone is given then the set timezone string for |
|
224 | + * the site is used. |
|
225 | + * This is used typically when using a Unix timestamp any core WP functions that expect their specially |
|
226 | + * computed timestamp (i.e. date_i18n() ) |
|
227 | + * |
|
228 | + * @param int $unix_timestamp if 0, then time() will be used. |
|
229 | + * @param string $timezone_string timezone_string. If empty, then the current set timezone for the |
|
230 | + * site will be used. |
|
231 | + * @return int $unix_timestamp with the offset applied for the given timezone. |
|
232 | + * @throws InvalidArgumentException |
|
233 | + * @throws InvalidDataTypeException |
|
234 | + * @throws InvalidInterfaceException |
|
235 | + */ |
|
236 | + public static function get_timestamp_with_offset($unix_timestamp = 0, $timezone_string = '') |
|
237 | + { |
|
238 | + return self::getHelperAdapter()->getTimestampWithOffset($unix_timestamp, $timezone_string); |
|
239 | + } |
|
240 | 240 | |
241 | 241 | |
242 | - /** |
|
243 | - * _set_date_time_field |
|
244 | - * modifies EE_Base_Class EE_Datetime_Field objects |
|
245 | - * |
|
246 | - * @param EE_Base_Class $obj EE_Base_Class object |
|
247 | - * @param DateTime $DateTime PHP DateTime object |
|
248 | - * @param string $datetime_field_name the datetime fieldname to be manipulated |
|
249 | - * @return EE_Base_Class |
|
250 | - * @throws EE_Error |
|
251 | - */ |
|
252 | - protected static function _set_date_time_field(EE_Base_Class $obj, DateTime $DateTime, $datetime_field_name) |
|
253 | - { |
|
254 | - // grab current datetime format |
|
255 | - $current_format = $obj->get_format(); |
|
256 | - // set new full timestamp format |
|
257 | - $obj->set_date_format(EE_Datetime_Field::mysql_date_format); |
|
258 | - $obj->set_time_format(EE_Datetime_Field::mysql_time_format); |
|
259 | - // set the new date value using a full timestamp format so that no data is lost |
|
260 | - $obj->set($datetime_field_name, $DateTime->format(EE_Datetime_Field::mysql_timestamp_format)); |
|
261 | - // reset datetime formats |
|
262 | - $obj->set_date_format($current_format[0]); |
|
263 | - $obj->set_time_format($current_format[1]); |
|
264 | - return $obj; |
|
265 | - } |
|
242 | + /** |
|
243 | + * _set_date_time_field |
|
244 | + * modifies EE_Base_Class EE_Datetime_Field objects |
|
245 | + * |
|
246 | + * @param EE_Base_Class $obj EE_Base_Class object |
|
247 | + * @param DateTime $DateTime PHP DateTime object |
|
248 | + * @param string $datetime_field_name the datetime fieldname to be manipulated |
|
249 | + * @return EE_Base_Class |
|
250 | + * @throws EE_Error |
|
251 | + */ |
|
252 | + protected static function _set_date_time_field(EE_Base_Class $obj, DateTime $DateTime, $datetime_field_name) |
|
253 | + { |
|
254 | + // grab current datetime format |
|
255 | + $current_format = $obj->get_format(); |
|
256 | + // set new full timestamp format |
|
257 | + $obj->set_date_format(EE_Datetime_Field::mysql_date_format); |
|
258 | + $obj->set_time_format(EE_Datetime_Field::mysql_time_format); |
|
259 | + // set the new date value using a full timestamp format so that no data is lost |
|
260 | + $obj->set($datetime_field_name, $DateTime->format(EE_Datetime_Field::mysql_timestamp_format)); |
|
261 | + // reset datetime formats |
|
262 | + $obj->set_date_format($current_format[0]); |
|
263 | + $obj->set_time_format($current_format[1]); |
|
264 | + return $obj; |
|
265 | + } |
|
266 | 266 | |
267 | 267 | |
268 | - /** |
|
269 | - * date_time_add |
|
270 | - * helper for doing simple datetime calculations on a given datetime from EE_Base_Class |
|
271 | - * and modifying it IN the EE_Base_Class so you don't have to do anything else. |
|
272 | - * |
|
273 | - * @param EE_Base_Class $obj EE_Base_Class object |
|
274 | - * @param string $datetime_field_name name of the EE_Datetime_Filed datatype db column to be manipulated |
|
275 | - * @param string $period what you are adding. The options are (years, months, days, hours, |
|
276 | - * minutes, seconds) defaults to years |
|
277 | - * @param integer $value what you want to increment the time by |
|
278 | - * @return EE_Base_Class return the EE_Base_Class object so right away you can do something with it |
|
279 | - * (chaining) |
|
280 | - * @throws EE_Error |
|
281 | - * @throws Exception |
|
282 | - */ |
|
283 | - public static function date_time_add(EE_Base_Class $obj, $datetime_field_name, $period = 'years', $value = 1) |
|
284 | - { |
|
285 | - // get the raw UTC date. |
|
286 | - $DateTime = $obj->get_DateTime_object($datetime_field_name); |
|
287 | - $DateTime = EEH_DTT_Helper::calc_date($DateTime, $period, $value); |
|
288 | - return EEH_DTT_Helper::_set_date_time_field($obj, $DateTime, $datetime_field_name); |
|
289 | - } |
|
268 | + /** |
|
269 | + * date_time_add |
|
270 | + * helper for doing simple datetime calculations on a given datetime from EE_Base_Class |
|
271 | + * and modifying it IN the EE_Base_Class so you don't have to do anything else. |
|
272 | + * |
|
273 | + * @param EE_Base_Class $obj EE_Base_Class object |
|
274 | + * @param string $datetime_field_name name of the EE_Datetime_Filed datatype db column to be manipulated |
|
275 | + * @param string $period what you are adding. The options are (years, months, days, hours, |
|
276 | + * minutes, seconds) defaults to years |
|
277 | + * @param integer $value what you want to increment the time by |
|
278 | + * @return EE_Base_Class return the EE_Base_Class object so right away you can do something with it |
|
279 | + * (chaining) |
|
280 | + * @throws EE_Error |
|
281 | + * @throws Exception |
|
282 | + */ |
|
283 | + public static function date_time_add(EE_Base_Class $obj, $datetime_field_name, $period = 'years', $value = 1) |
|
284 | + { |
|
285 | + // get the raw UTC date. |
|
286 | + $DateTime = $obj->get_DateTime_object($datetime_field_name); |
|
287 | + $DateTime = EEH_DTT_Helper::calc_date($DateTime, $period, $value); |
|
288 | + return EEH_DTT_Helper::_set_date_time_field($obj, $DateTime, $datetime_field_name); |
|
289 | + } |
|
290 | 290 | |
291 | 291 | |
292 | - /** |
|
293 | - * date_time_subtract |
|
294 | - * same as date_time_add except subtracting value instead of adding. |
|
295 | - * |
|
296 | - * @param EE_Base_Class $obj |
|
297 | - * @param string $datetime_field_name name of the EE_Datetime_Filed datatype db column to be manipulated |
|
298 | - * @param string $period |
|
299 | - * @param int $value |
|
300 | - * @return EE_Base_Class |
|
301 | - * @throws EE_Error |
|
302 | - * @throws Exception |
|
303 | - */ |
|
304 | - public static function date_time_subtract(EE_Base_Class $obj, $datetime_field_name, $period = 'years', $value = 1) |
|
305 | - { |
|
306 | - // get the raw UTC date |
|
307 | - $DateTime = $obj->get_DateTime_object($datetime_field_name); |
|
308 | - $DateTime = EEH_DTT_Helper::calc_date($DateTime, $period, $value, '-'); |
|
309 | - return EEH_DTT_Helper::_set_date_time_field($obj, $DateTime, $datetime_field_name); |
|
310 | - } |
|
292 | + /** |
|
293 | + * date_time_subtract |
|
294 | + * same as date_time_add except subtracting value instead of adding. |
|
295 | + * |
|
296 | + * @param EE_Base_Class $obj |
|
297 | + * @param string $datetime_field_name name of the EE_Datetime_Filed datatype db column to be manipulated |
|
298 | + * @param string $period |
|
299 | + * @param int $value |
|
300 | + * @return EE_Base_Class |
|
301 | + * @throws EE_Error |
|
302 | + * @throws Exception |
|
303 | + */ |
|
304 | + public static function date_time_subtract(EE_Base_Class $obj, $datetime_field_name, $period = 'years', $value = 1) |
|
305 | + { |
|
306 | + // get the raw UTC date |
|
307 | + $DateTime = $obj->get_DateTime_object($datetime_field_name); |
|
308 | + $DateTime = EEH_DTT_Helper::calc_date($DateTime, $period, $value, '-'); |
|
309 | + return EEH_DTT_Helper::_set_date_time_field($obj, $DateTime, $datetime_field_name); |
|
310 | + } |
|
311 | 311 | |
312 | 312 | |
313 | - /** |
|
314 | - * Simply takes an incoming DateTime object and does calculations on it based on the incoming parameters |
|
315 | - * |
|
316 | - * @param DateTime $DateTime DateTime object |
|
317 | - * @param string $period a value to indicate what interval is being used in the calculation. The options are |
|
318 | - * 'years', 'months', 'days', 'hours', 'minutes', 'seconds'. Defaults to years. |
|
319 | - * @param int|string $value What you want to increment the date by |
|
320 | - * @param string $operand What operand you wish to use for the calculation |
|
321 | - * @return DateTime return whatever type came in. |
|
322 | - * @throws Exception |
|
323 | - * @throws EE_Error |
|
324 | - */ |
|
325 | - protected static function _modify_datetime_object(DateTime $DateTime, $period = 'years', $value = 1, $operand = '+') |
|
326 | - { |
|
327 | - if (! $DateTime instanceof DateTime) { |
|
328 | - throw new EE_Error( |
|
329 | - sprintf( |
|
330 | - esc_html__('Expected a PHP DateTime object, but instead received %1$s', 'event_espresso'), |
|
331 | - print_r($DateTime, true) |
|
332 | - ) |
|
333 | - ); |
|
334 | - } |
|
335 | - switch ($period) { |
|
336 | - case 'years': |
|
337 | - $value = 'P' . $value . 'Y'; |
|
338 | - break; |
|
339 | - case 'months': |
|
340 | - $value = 'P' . $value . 'M'; |
|
341 | - break; |
|
342 | - case 'weeks': |
|
343 | - $value = 'P' . $value . 'W'; |
|
344 | - break; |
|
345 | - case 'days': |
|
346 | - $value = 'P' . $value . 'D'; |
|
347 | - break; |
|
348 | - case 'hours': |
|
349 | - $value = 'PT' . $value . 'H'; |
|
350 | - break; |
|
351 | - case 'minutes': |
|
352 | - $value = 'PT' . $value . 'M'; |
|
353 | - break; |
|
354 | - case 'seconds': |
|
355 | - $value = 'PT' . $value . 'S'; |
|
356 | - break; |
|
357 | - } |
|
358 | - switch ($operand) { |
|
359 | - case '+': |
|
360 | - $DateTime->add(new DateInterval($value)); |
|
361 | - break; |
|
362 | - case '-': |
|
363 | - $DateTime->sub(new DateInterval($value)); |
|
364 | - break; |
|
365 | - } |
|
366 | - return $DateTime; |
|
367 | - } |
|
313 | + /** |
|
314 | + * Simply takes an incoming DateTime object and does calculations on it based on the incoming parameters |
|
315 | + * |
|
316 | + * @param DateTime $DateTime DateTime object |
|
317 | + * @param string $period a value to indicate what interval is being used in the calculation. The options are |
|
318 | + * 'years', 'months', 'days', 'hours', 'minutes', 'seconds'. Defaults to years. |
|
319 | + * @param int|string $value What you want to increment the date by |
|
320 | + * @param string $operand What operand you wish to use for the calculation |
|
321 | + * @return DateTime return whatever type came in. |
|
322 | + * @throws Exception |
|
323 | + * @throws EE_Error |
|
324 | + */ |
|
325 | + protected static function _modify_datetime_object(DateTime $DateTime, $period = 'years', $value = 1, $operand = '+') |
|
326 | + { |
|
327 | + if (! $DateTime instanceof DateTime) { |
|
328 | + throw new EE_Error( |
|
329 | + sprintf( |
|
330 | + esc_html__('Expected a PHP DateTime object, but instead received %1$s', 'event_espresso'), |
|
331 | + print_r($DateTime, true) |
|
332 | + ) |
|
333 | + ); |
|
334 | + } |
|
335 | + switch ($period) { |
|
336 | + case 'years': |
|
337 | + $value = 'P' . $value . 'Y'; |
|
338 | + break; |
|
339 | + case 'months': |
|
340 | + $value = 'P' . $value . 'M'; |
|
341 | + break; |
|
342 | + case 'weeks': |
|
343 | + $value = 'P' . $value . 'W'; |
|
344 | + break; |
|
345 | + case 'days': |
|
346 | + $value = 'P' . $value . 'D'; |
|
347 | + break; |
|
348 | + case 'hours': |
|
349 | + $value = 'PT' . $value . 'H'; |
|
350 | + break; |
|
351 | + case 'minutes': |
|
352 | + $value = 'PT' . $value . 'M'; |
|
353 | + break; |
|
354 | + case 'seconds': |
|
355 | + $value = 'PT' . $value . 'S'; |
|
356 | + break; |
|
357 | + } |
|
358 | + switch ($operand) { |
|
359 | + case '+': |
|
360 | + $DateTime->add(new DateInterval($value)); |
|
361 | + break; |
|
362 | + case '-': |
|
363 | + $DateTime->sub(new DateInterval($value)); |
|
364 | + break; |
|
365 | + } |
|
366 | + return $DateTime; |
|
367 | + } |
|
368 | 368 | |
369 | 369 | |
370 | - /** |
|
371 | - * Simply takes an incoming Unix timestamp and does calculations on it based on the incoming parameters |
|
372 | - * |
|
373 | - * @param int $timestamp Unix timestamp |
|
374 | - * @param string $period a value to indicate what interval is being used in the calculation. The options are |
|
375 | - * 'years', 'months', 'days', 'hours', 'minutes', 'seconds'. Defaults to years. |
|
376 | - * @param integer $value What you want to increment the date by |
|
377 | - * @param string $operand What operand you wish to use for the calculation |
|
378 | - * @return int |
|
379 | - * @throws EE_Error |
|
380 | - */ |
|
381 | - protected static function _modify_timestamp($timestamp, $period = 'years', $value = 1, $operand = '+') |
|
382 | - { |
|
383 | - if (! preg_match(EE_Datetime_Field::unix_timestamp_regex, $timestamp)) { |
|
384 | - throw new EE_Error( |
|
385 | - sprintf( |
|
386 | - esc_html__('Expected a Unix timestamp, but instead received %1$s', 'event_espresso'), |
|
387 | - print_r($timestamp, true) |
|
388 | - ) |
|
389 | - ); |
|
390 | - } |
|
391 | - switch ($period) { |
|
392 | - case 'years': |
|
393 | - $value = YEAR_IN_SECONDS * $value; |
|
394 | - break; |
|
395 | - case 'months': |
|
396 | - $value = YEAR_IN_SECONDS / 12 * $value; |
|
397 | - break; |
|
398 | - case 'weeks': |
|
399 | - $value = WEEK_IN_SECONDS * $value; |
|
400 | - break; |
|
401 | - case 'days': |
|
402 | - $value = DAY_IN_SECONDS * $value; |
|
403 | - break; |
|
404 | - case 'hours': |
|
405 | - $value = HOUR_IN_SECONDS * $value; |
|
406 | - break; |
|
407 | - case 'minutes': |
|
408 | - $value = MINUTE_IN_SECONDS * $value; |
|
409 | - break; |
|
410 | - } |
|
411 | - switch ($operand) { |
|
412 | - case '+': |
|
413 | - $timestamp += $value; |
|
414 | - break; |
|
415 | - case '-': |
|
416 | - $timestamp -= $value; |
|
417 | - break; |
|
418 | - } |
|
419 | - return $timestamp; |
|
420 | - } |
|
370 | + /** |
|
371 | + * Simply takes an incoming Unix timestamp and does calculations on it based on the incoming parameters |
|
372 | + * |
|
373 | + * @param int $timestamp Unix timestamp |
|
374 | + * @param string $period a value to indicate what interval is being used in the calculation. The options are |
|
375 | + * 'years', 'months', 'days', 'hours', 'minutes', 'seconds'. Defaults to years. |
|
376 | + * @param integer $value What you want to increment the date by |
|
377 | + * @param string $operand What operand you wish to use for the calculation |
|
378 | + * @return int |
|
379 | + * @throws EE_Error |
|
380 | + */ |
|
381 | + protected static function _modify_timestamp($timestamp, $period = 'years', $value = 1, $operand = '+') |
|
382 | + { |
|
383 | + if (! preg_match(EE_Datetime_Field::unix_timestamp_regex, $timestamp)) { |
|
384 | + throw new EE_Error( |
|
385 | + sprintf( |
|
386 | + esc_html__('Expected a Unix timestamp, but instead received %1$s', 'event_espresso'), |
|
387 | + print_r($timestamp, true) |
|
388 | + ) |
|
389 | + ); |
|
390 | + } |
|
391 | + switch ($period) { |
|
392 | + case 'years': |
|
393 | + $value = YEAR_IN_SECONDS * $value; |
|
394 | + break; |
|
395 | + case 'months': |
|
396 | + $value = YEAR_IN_SECONDS / 12 * $value; |
|
397 | + break; |
|
398 | + case 'weeks': |
|
399 | + $value = WEEK_IN_SECONDS * $value; |
|
400 | + break; |
|
401 | + case 'days': |
|
402 | + $value = DAY_IN_SECONDS * $value; |
|
403 | + break; |
|
404 | + case 'hours': |
|
405 | + $value = HOUR_IN_SECONDS * $value; |
|
406 | + break; |
|
407 | + case 'minutes': |
|
408 | + $value = MINUTE_IN_SECONDS * $value; |
|
409 | + break; |
|
410 | + } |
|
411 | + switch ($operand) { |
|
412 | + case '+': |
|
413 | + $timestamp += $value; |
|
414 | + break; |
|
415 | + case '-': |
|
416 | + $timestamp -= $value; |
|
417 | + break; |
|
418 | + } |
|
419 | + return $timestamp; |
|
420 | + } |
|
421 | 421 | |
422 | 422 | |
423 | - /** |
|
424 | - * Simply takes an incoming UTC timestamp or DateTime object and does calculations on it based on the incoming |
|
425 | - * parameters and returns the new timestamp or DateTime. |
|
426 | - * |
|
427 | - * @param int | DateTime $DateTime_or_timestamp DateTime object or Unix timestamp |
|
428 | - * @param string $period a value to indicate what interval is being used in the |
|
429 | - * calculation. The options are 'years', 'months', 'days', 'hours', |
|
430 | - * 'minutes', 'seconds'. Defaults to years. |
|
431 | - * @param integer $value What you want to increment the date by |
|
432 | - * @param string $operand What operand you wish to use for the calculation |
|
433 | - * @return mixed string|DateTime return whatever type came in. |
|
434 | - * @throws Exception |
|
435 | - * @throws EE_Error |
|
436 | - */ |
|
437 | - public static function calc_date($DateTime_or_timestamp, $period = 'years', $value = 1, $operand = '+') |
|
438 | - { |
|
439 | - if ($DateTime_or_timestamp instanceof DateTime) { |
|
440 | - return EEH_DTT_Helper::_modify_datetime_object( |
|
441 | - $DateTime_or_timestamp, |
|
442 | - $period, |
|
443 | - $value, |
|
444 | - $operand |
|
445 | - ); |
|
446 | - } |
|
447 | - if (preg_match(EE_Datetime_Field::unix_timestamp_regex, $DateTime_or_timestamp)) { |
|
448 | - return EEH_DTT_Helper::_modify_timestamp( |
|
449 | - $DateTime_or_timestamp, |
|
450 | - $period, |
|
451 | - $value, |
|
452 | - $operand |
|
453 | - ); |
|
454 | - } |
|
455 | - // error |
|
456 | - return $DateTime_or_timestamp; |
|
457 | - } |
|
423 | + /** |
|
424 | + * Simply takes an incoming UTC timestamp or DateTime object and does calculations on it based on the incoming |
|
425 | + * parameters and returns the new timestamp or DateTime. |
|
426 | + * |
|
427 | + * @param int | DateTime $DateTime_or_timestamp DateTime object or Unix timestamp |
|
428 | + * @param string $period a value to indicate what interval is being used in the |
|
429 | + * calculation. The options are 'years', 'months', 'days', 'hours', |
|
430 | + * 'minutes', 'seconds'. Defaults to years. |
|
431 | + * @param integer $value What you want to increment the date by |
|
432 | + * @param string $operand What operand you wish to use for the calculation |
|
433 | + * @return mixed string|DateTime return whatever type came in. |
|
434 | + * @throws Exception |
|
435 | + * @throws EE_Error |
|
436 | + */ |
|
437 | + public static function calc_date($DateTime_or_timestamp, $period = 'years', $value = 1, $operand = '+') |
|
438 | + { |
|
439 | + if ($DateTime_or_timestamp instanceof DateTime) { |
|
440 | + return EEH_DTT_Helper::_modify_datetime_object( |
|
441 | + $DateTime_or_timestamp, |
|
442 | + $period, |
|
443 | + $value, |
|
444 | + $operand |
|
445 | + ); |
|
446 | + } |
|
447 | + if (preg_match(EE_Datetime_Field::unix_timestamp_regex, $DateTime_or_timestamp)) { |
|
448 | + return EEH_DTT_Helper::_modify_timestamp( |
|
449 | + $DateTime_or_timestamp, |
|
450 | + $period, |
|
451 | + $value, |
|
452 | + $operand |
|
453 | + ); |
|
454 | + } |
|
455 | + // error |
|
456 | + return $DateTime_or_timestamp; |
|
457 | + } |
|
458 | 458 | |
459 | 459 | |
460 | - /** |
|
461 | - * The purpose of this helper method is to receive an incoming format string in php date/time format |
|
462 | - * and spit out the js and moment.js equivalent formats. |
|
463 | - * Note, if no format string is given, then it is assumed the user wants what is set for WP. |
|
464 | - * Note, js date and time formats are those used by the jquery-ui datepicker and the jquery-ui date- |
|
465 | - * time picker. |
|
466 | - * |
|
467 | - * @see http://stackoverflow.com/posts/16725290/ for the code inspiration. |
|
468 | - * @param string $date_format_string |
|
469 | - * @param string $time_format_string |
|
470 | - * @return array |
|
471 | - * array( |
|
472 | - * 'js' => array ( |
|
473 | - * 'date' => //date format |
|
474 | - * 'time' => //time format |
|
475 | - * ), |
|
476 | - * 'moment' => //date and time format. |
|
477 | - * ) |
|
478 | - */ |
|
479 | - public static function convert_php_to_js_and_moment_date_formats( |
|
480 | - $date_format_string = null, |
|
481 | - $time_format_string = null |
|
482 | - ) { |
|
483 | - if ($date_format_string === null) { |
|
484 | - $date_format_string = (string) get_option('date_format'); |
|
485 | - } |
|
486 | - if ($time_format_string === null) { |
|
487 | - $time_format_string = (string) get_option('time_format'); |
|
488 | - } |
|
489 | - $date_format = self::_php_to_js_moment_converter($date_format_string); |
|
490 | - $time_format = self::_php_to_js_moment_converter($time_format_string); |
|
491 | - return array( |
|
492 | - 'js' => array( |
|
493 | - 'date' => $date_format['js'], |
|
494 | - 'time' => $time_format['js'], |
|
495 | - ), |
|
496 | - 'moment' => $date_format['moment'] . ' ' . $time_format['moment'], |
|
497 | - 'moment_split' => array( |
|
498 | - 'date' => $date_format['moment'], |
|
499 | - 'time' => $time_format['moment'] |
|
500 | - ) |
|
501 | - ); |
|
502 | - } |
|
460 | + /** |
|
461 | + * The purpose of this helper method is to receive an incoming format string in php date/time format |
|
462 | + * and spit out the js and moment.js equivalent formats. |
|
463 | + * Note, if no format string is given, then it is assumed the user wants what is set for WP. |
|
464 | + * Note, js date and time formats are those used by the jquery-ui datepicker and the jquery-ui date- |
|
465 | + * time picker. |
|
466 | + * |
|
467 | + * @see http://stackoverflow.com/posts/16725290/ for the code inspiration. |
|
468 | + * @param string $date_format_string |
|
469 | + * @param string $time_format_string |
|
470 | + * @return array |
|
471 | + * array( |
|
472 | + * 'js' => array ( |
|
473 | + * 'date' => //date format |
|
474 | + * 'time' => //time format |
|
475 | + * ), |
|
476 | + * 'moment' => //date and time format. |
|
477 | + * ) |
|
478 | + */ |
|
479 | + public static function convert_php_to_js_and_moment_date_formats( |
|
480 | + $date_format_string = null, |
|
481 | + $time_format_string = null |
|
482 | + ) { |
|
483 | + if ($date_format_string === null) { |
|
484 | + $date_format_string = (string) get_option('date_format'); |
|
485 | + } |
|
486 | + if ($time_format_string === null) { |
|
487 | + $time_format_string = (string) get_option('time_format'); |
|
488 | + } |
|
489 | + $date_format = self::_php_to_js_moment_converter($date_format_string); |
|
490 | + $time_format = self::_php_to_js_moment_converter($time_format_string); |
|
491 | + return array( |
|
492 | + 'js' => array( |
|
493 | + 'date' => $date_format['js'], |
|
494 | + 'time' => $time_format['js'], |
|
495 | + ), |
|
496 | + 'moment' => $date_format['moment'] . ' ' . $time_format['moment'], |
|
497 | + 'moment_split' => array( |
|
498 | + 'date' => $date_format['moment'], |
|
499 | + 'time' => $time_format['moment'] |
|
500 | + ) |
|
501 | + ); |
|
502 | + } |
|
503 | 503 | |
504 | 504 | |
505 | - /** |
|
506 | - * This converts incoming format string into js and moment variations. |
|
507 | - * |
|
508 | - * @param string $format_string incoming php format string |
|
509 | - * @return array js and moment formats. |
|
510 | - */ |
|
511 | - protected static function _php_to_js_moment_converter($format_string) |
|
512 | - { |
|
513 | - /** |
|
514 | - * This is a map of symbols for formats. |
|
515 | - * The index is the php symbol, the equivalent values are in the array. |
|
516 | - * |
|
517 | - * @var array |
|
518 | - */ |
|
519 | - $symbols_map = array( |
|
520 | - // Day |
|
521 | - // 01 |
|
522 | - 'd' => array( |
|
523 | - 'js' => 'dd', |
|
524 | - 'moment' => 'DD', |
|
525 | - ), |
|
526 | - // Mon |
|
527 | - 'D' => array( |
|
528 | - 'js' => 'D', |
|
529 | - 'moment' => 'ddd', |
|
530 | - ), |
|
531 | - // 1,2,...31 |
|
532 | - 'j' => array( |
|
533 | - 'js' => 'd', |
|
534 | - 'moment' => 'D', |
|
535 | - ), |
|
536 | - // Monday |
|
537 | - 'l' => array( |
|
538 | - 'js' => 'DD', |
|
539 | - 'moment' => 'dddd', |
|
540 | - ), |
|
541 | - // ISO numeric representation of the day of the week (1-6) |
|
542 | - 'N' => array( |
|
543 | - 'js' => '', |
|
544 | - 'moment' => 'E', |
|
545 | - ), |
|
546 | - // st,nd.rd |
|
547 | - 'S' => array( |
|
548 | - 'js' => '', |
|
549 | - 'moment' => 'o', |
|
550 | - ), |
|
551 | - // numeric representation of day of week (0-6) |
|
552 | - 'w' => array( |
|
553 | - 'js' => '', |
|
554 | - 'moment' => 'd', |
|
555 | - ), |
|
556 | - // day of year starting from 0 (0-365) |
|
557 | - 'z' => array( |
|
558 | - 'js' => 'o', |
|
559 | - 'moment' => 'DDD' // note moment does not start with 0 so will need to modify by subtracting 1 |
|
560 | - ), |
|
561 | - // Week |
|
562 | - // ISO-8601 week number of year (weeks starting on monday) |
|
563 | - 'W' => array( |
|
564 | - 'js' => '', |
|
565 | - 'moment' => 'w', |
|
566 | - ), |
|
567 | - // Month |
|
568 | - // January...December |
|
569 | - 'F' => array( |
|
570 | - 'js' => 'MM', |
|
571 | - 'moment' => 'MMMM', |
|
572 | - ), |
|
573 | - // 01...12 |
|
574 | - 'm' => array( |
|
575 | - 'js' => 'mm', |
|
576 | - 'moment' => 'MM', |
|
577 | - ), |
|
578 | - // Jan...Dec |
|
579 | - 'M' => array( |
|
580 | - 'js' => 'M', |
|
581 | - 'moment' => 'MMM', |
|
582 | - ), |
|
583 | - // 1-12 |
|
584 | - 'n' => array( |
|
585 | - 'js' => 'm', |
|
586 | - 'moment' => 'M', |
|
587 | - ), |
|
588 | - // number of days in given month |
|
589 | - 't' => array( |
|
590 | - 'js' => '', |
|
591 | - 'moment' => '', |
|
592 | - ), |
|
593 | - // Year |
|
594 | - // whether leap year or not 1/0 |
|
595 | - 'L' => array( |
|
596 | - 'js' => '', |
|
597 | - 'moment' => '', |
|
598 | - ), |
|
599 | - // ISO-8601 year number |
|
600 | - 'o' => array( |
|
601 | - 'js' => '', |
|
602 | - 'moment' => 'GGGG', |
|
603 | - ), |
|
604 | - // 1999...2003 |
|
605 | - 'Y' => array( |
|
606 | - 'js' => 'yy', |
|
607 | - 'moment' => 'YYYY', |
|
608 | - ), |
|
609 | - // 99...03 |
|
610 | - 'y' => array( |
|
611 | - 'js' => 'y', |
|
612 | - 'moment' => 'YY', |
|
613 | - ), |
|
614 | - // Time |
|
615 | - // am/pm |
|
616 | - 'a' => array( |
|
617 | - 'js' => 'tt', |
|
618 | - 'moment' => 'a', |
|
619 | - ), |
|
620 | - // AM/PM |
|
621 | - 'A' => array( |
|
622 | - 'js' => 'TT', |
|
623 | - 'moment' => 'A', |
|
624 | - ), |
|
625 | - // Swatch Internet Time?!? |
|
626 | - 'B' => array( |
|
627 | - 'js' => '', |
|
628 | - 'moment' => '', |
|
629 | - ), |
|
630 | - // 1...12 |
|
631 | - 'g' => array( |
|
632 | - 'js' => 'h', |
|
633 | - 'moment' => 'h', |
|
634 | - ), |
|
635 | - // 0...23 |
|
636 | - 'G' => array( |
|
637 | - 'js' => 'H', |
|
638 | - 'moment' => 'H', |
|
639 | - ), |
|
640 | - // 01...12 |
|
641 | - 'h' => array( |
|
642 | - 'js' => 'hh', |
|
643 | - 'moment' => 'hh', |
|
644 | - ), |
|
645 | - // 00...23 |
|
646 | - 'H' => array( |
|
647 | - 'js' => 'HH', |
|
648 | - 'moment' => 'HH', |
|
649 | - ), |
|
650 | - // 00..59 |
|
651 | - 'i' => array( |
|
652 | - 'js' => 'mm', |
|
653 | - 'moment' => 'mm', |
|
654 | - ), |
|
655 | - // seconds... 00...59 |
|
656 | - 's' => array( |
|
657 | - 'js' => 'ss', |
|
658 | - 'moment' => 'ss', |
|
659 | - ), |
|
660 | - // microseconds |
|
661 | - 'u' => array( |
|
662 | - 'js' => '', |
|
663 | - 'moment' => '', |
|
664 | - ), |
|
665 | - ); |
|
666 | - $jquery_ui_format = ''; |
|
667 | - $moment_format = ''; |
|
668 | - $escaping = false; |
|
669 | - $format_string_length = strlen($format_string); |
|
670 | - for ($i = 0; $i < $format_string_length; $i++) { |
|
671 | - $char = $format_string[ $i ]; |
|
672 | - if ($char === '\\') { // PHP date format escaping character |
|
673 | - $i++; |
|
674 | - if ($escaping) { |
|
675 | - $jquery_ui_format .= $format_string[ $i ]; |
|
676 | - $moment_format .= $format_string[ $i ]; |
|
677 | - } else { |
|
678 | - $jquery_ui_format .= '\'' . $format_string[ $i ]; |
|
679 | - $moment_format .= $format_string[ $i ]; |
|
680 | - } |
|
681 | - $escaping = true; |
|
682 | - } else { |
|
683 | - if ($escaping) { |
|
684 | - $jquery_ui_format .= "'"; |
|
685 | - $moment_format .= "'"; |
|
686 | - $escaping = false; |
|
687 | - } |
|
688 | - if (isset($symbols_map[ $char ])) { |
|
689 | - $jquery_ui_format .= $symbols_map[ $char ]['js']; |
|
690 | - $moment_format .= $symbols_map[ $char ]['moment']; |
|
691 | - } else { |
|
692 | - $jquery_ui_format .= $char; |
|
693 | - $moment_format .= $char; |
|
694 | - } |
|
695 | - } |
|
696 | - } |
|
697 | - return array('js' => $jquery_ui_format, 'moment' => $moment_format); |
|
698 | - } |
|
505 | + /** |
|
506 | + * This converts incoming format string into js and moment variations. |
|
507 | + * |
|
508 | + * @param string $format_string incoming php format string |
|
509 | + * @return array js and moment formats. |
|
510 | + */ |
|
511 | + protected static function _php_to_js_moment_converter($format_string) |
|
512 | + { |
|
513 | + /** |
|
514 | + * This is a map of symbols for formats. |
|
515 | + * The index is the php symbol, the equivalent values are in the array. |
|
516 | + * |
|
517 | + * @var array |
|
518 | + */ |
|
519 | + $symbols_map = array( |
|
520 | + // Day |
|
521 | + // 01 |
|
522 | + 'd' => array( |
|
523 | + 'js' => 'dd', |
|
524 | + 'moment' => 'DD', |
|
525 | + ), |
|
526 | + // Mon |
|
527 | + 'D' => array( |
|
528 | + 'js' => 'D', |
|
529 | + 'moment' => 'ddd', |
|
530 | + ), |
|
531 | + // 1,2,...31 |
|
532 | + 'j' => array( |
|
533 | + 'js' => 'd', |
|
534 | + 'moment' => 'D', |
|
535 | + ), |
|
536 | + // Monday |
|
537 | + 'l' => array( |
|
538 | + 'js' => 'DD', |
|
539 | + 'moment' => 'dddd', |
|
540 | + ), |
|
541 | + // ISO numeric representation of the day of the week (1-6) |
|
542 | + 'N' => array( |
|
543 | + 'js' => '', |
|
544 | + 'moment' => 'E', |
|
545 | + ), |
|
546 | + // st,nd.rd |
|
547 | + 'S' => array( |
|
548 | + 'js' => '', |
|
549 | + 'moment' => 'o', |
|
550 | + ), |
|
551 | + // numeric representation of day of week (0-6) |
|
552 | + 'w' => array( |
|
553 | + 'js' => '', |
|
554 | + 'moment' => 'd', |
|
555 | + ), |
|
556 | + // day of year starting from 0 (0-365) |
|
557 | + 'z' => array( |
|
558 | + 'js' => 'o', |
|
559 | + 'moment' => 'DDD' // note moment does not start with 0 so will need to modify by subtracting 1 |
|
560 | + ), |
|
561 | + // Week |
|
562 | + // ISO-8601 week number of year (weeks starting on monday) |
|
563 | + 'W' => array( |
|
564 | + 'js' => '', |
|
565 | + 'moment' => 'w', |
|
566 | + ), |
|
567 | + // Month |
|
568 | + // January...December |
|
569 | + 'F' => array( |
|
570 | + 'js' => 'MM', |
|
571 | + 'moment' => 'MMMM', |
|
572 | + ), |
|
573 | + // 01...12 |
|
574 | + 'm' => array( |
|
575 | + 'js' => 'mm', |
|
576 | + 'moment' => 'MM', |
|
577 | + ), |
|
578 | + // Jan...Dec |
|
579 | + 'M' => array( |
|
580 | + 'js' => 'M', |
|
581 | + 'moment' => 'MMM', |
|
582 | + ), |
|
583 | + // 1-12 |
|
584 | + 'n' => array( |
|
585 | + 'js' => 'm', |
|
586 | + 'moment' => 'M', |
|
587 | + ), |
|
588 | + // number of days in given month |
|
589 | + 't' => array( |
|
590 | + 'js' => '', |
|
591 | + 'moment' => '', |
|
592 | + ), |
|
593 | + // Year |
|
594 | + // whether leap year or not 1/0 |
|
595 | + 'L' => array( |
|
596 | + 'js' => '', |
|
597 | + 'moment' => '', |
|
598 | + ), |
|
599 | + // ISO-8601 year number |
|
600 | + 'o' => array( |
|
601 | + 'js' => '', |
|
602 | + 'moment' => 'GGGG', |
|
603 | + ), |
|
604 | + // 1999...2003 |
|
605 | + 'Y' => array( |
|
606 | + 'js' => 'yy', |
|
607 | + 'moment' => 'YYYY', |
|
608 | + ), |
|
609 | + // 99...03 |
|
610 | + 'y' => array( |
|
611 | + 'js' => 'y', |
|
612 | + 'moment' => 'YY', |
|
613 | + ), |
|
614 | + // Time |
|
615 | + // am/pm |
|
616 | + 'a' => array( |
|
617 | + 'js' => 'tt', |
|
618 | + 'moment' => 'a', |
|
619 | + ), |
|
620 | + // AM/PM |
|
621 | + 'A' => array( |
|
622 | + 'js' => 'TT', |
|
623 | + 'moment' => 'A', |
|
624 | + ), |
|
625 | + // Swatch Internet Time?!? |
|
626 | + 'B' => array( |
|
627 | + 'js' => '', |
|
628 | + 'moment' => '', |
|
629 | + ), |
|
630 | + // 1...12 |
|
631 | + 'g' => array( |
|
632 | + 'js' => 'h', |
|
633 | + 'moment' => 'h', |
|
634 | + ), |
|
635 | + // 0...23 |
|
636 | + 'G' => array( |
|
637 | + 'js' => 'H', |
|
638 | + 'moment' => 'H', |
|
639 | + ), |
|
640 | + // 01...12 |
|
641 | + 'h' => array( |
|
642 | + 'js' => 'hh', |
|
643 | + 'moment' => 'hh', |
|
644 | + ), |
|
645 | + // 00...23 |
|
646 | + 'H' => array( |
|
647 | + 'js' => 'HH', |
|
648 | + 'moment' => 'HH', |
|
649 | + ), |
|
650 | + // 00..59 |
|
651 | + 'i' => array( |
|
652 | + 'js' => 'mm', |
|
653 | + 'moment' => 'mm', |
|
654 | + ), |
|
655 | + // seconds... 00...59 |
|
656 | + 's' => array( |
|
657 | + 'js' => 'ss', |
|
658 | + 'moment' => 'ss', |
|
659 | + ), |
|
660 | + // microseconds |
|
661 | + 'u' => array( |
|
662 | + 'js' => '', |
|
663 | + 'moment' => '', |
|
664 | + ), |
|
665 | + ); |
|
666 | + $jquery_ui_format = ''; |
|
667 | + $moment_format = ''; |
|
668 | + $escaping = false; |
|
669 | + $format_string_length = strlen($format_string); |
|
670 | + for ($i = 0; $i < $format_string_length; $i++) { |
|
671 | + $char = $format_string[ $i ]; |
|
672 | + if ($char === '\\') { // PHP date format escaping character |
|
673 | + $i++; |
|
674 | + if ($escaping) { |
|
675 | + $jquery_ui_format .= $format_string[ $i ]; |
|
676 | + $moment_format .= $format_string[ $i ]; |
|
677 | + } else { |
|
678 | + $jquery_ui_format .= '\'' . $format_string[ $i ]; |
|
679 | + $moment_format .= $format_string[ $i ]; |
|
680 | + } |
|
681 | + $escaping = true; |
|
682 | + } else { |
|
683 | + if ($escaping) { |
|
684 | + $jquery_ui_format .= "'"; |
|
685 | + $moment_format .= "'"; |
|
686 | + $escaping = false; |
|
687 | + } |
|
688 | + if (isset($symbols_map[ $char ])) { |
|
689 | + $jquery_ui_format .= $symbols_map[ $char ]['js']; |
|
690 | + $moment_format .= $symbols_map[ $char ]['moment']; |
|
691 | + } else { |
|
692 | + $jquery_ui_format .= $char; |
|
693 | + $moment_format .= $char; |
|
694 | + } |
|
695 | + } |
|
696 | + } |
|
697 | + return array('js' => $jquery_ui_format, 'moment' => $moment_format); |
|
698 | + } |
|
699 | 699 | |
700 | 700 | |
701 | - /** |
|
702 | - * This takes an incoming format string and validates it to ensure it will work fine with PHP. |
|
703 | - * |
|
704 | - * @param string $format_string Incoming format string for php date(). |
|
705 | - * @return mixed bool|array If all is okay then TRUE is returned. Otherwise an array of validation |
|
706 | - * errors is returned. So for client code calling, check for is_array() to |
|
707 | - * indicate failed validations. |
|
708 | - */ |
|
709 | - public static function validate_format_string($format_string) |
|
710 | - { |
|
711 | - $error_msg = array(); |
|
712 | - // time format checks |
|
713 | - switch (true) { |
|
714 | - case strpos($format_string, 'h') !== false: |
|
715 | - case strpos($format_string, 'g') !== false: |
|
716 | - /** |
|
717 | - * if the time string has a lowercase 'h' which == 12 hour time format and there |
|
718 | - * is not any ante meridiem format ('a' or 'A'). Then throw an error because its |
|
719 | - * too ambiguous and PHP won't be able to figure out whether 1 = 1pm or 1am. |
|
720 | - */ |
|
721 | - if (stripos($format_string, 'A') === false) { |
|
722 | - $error_msg[] = esc_html__( |
|
723 | - 'There is a time format for 12 hour time but no "a" or "A" to indicate am/pm. Without this distinction, PHP is unable to determine if a "1" for the hour value equals "1pm" or "1am".', |
|
724 | - 'event_espresso' |
|
725 | - ); |
|
726 | - } |
|
727 | - break; |
|
728 | - } |
|
729 | - return empty($error_msg) ? true : $error_msg; |
|
730 | - } |
|
701 | + /** |
|
702 | + * This takes an incoming format string and validates it to ensure it will work fine with PHP. |
|
703 | + * |
|
704 | + * @param string $format_string Incoming format string for php date(). |
|
705 | + * @return mixed bool|array If all is okay then TRUE is returned. Otherwise an array of validation |
|
706 | + * errors is returned. So for client code calling, check for is_array() to |
|
707 | + * indicate failed validations. |
|
708 | + */ |
|
709 | + public static function validate_format_string($format_string) |
|
710 | + { |
|
711 | + $error_msg = array(); |
|
712 | + // time format checks |
|
713 | + switch (true) { |
|
714 | + case strpos($format_string, 'h') !== false: |
|
715 | + case strpos($format_string, 'g') !== false: |
|
716 | + /** |
|
717 | + * if the time string has a lowercase 'h' which == 12 hour time format and there |
|
718 | + * is not any ante meridiem format ('a' or 'A'). Then throw an error because its |
|
719 | + * too ambiguous and PHP won't be able to figure out whether 1 = 1pm or 1am. |
|
720 | + */ |
|
721 | + if (stripos($format_string, 'A') === false) { |
|
722 | + $error_msg[] = esc_html__( |
|
723 | + 'There is a time format for 12 hour time but no "a" or "A" to indicate am/pm. Without this distinction, PHP is unable to determine if a "1" for the hour value equals "1pm" or "1am".', |
|
724 | + 'event_espresso' |
|
725 | + ); |
|
726 | + } |
|
727 | + break; |
|
728 | + } |
|
729 | + return empty($error_msg) ? true : $error_msg; |
|
730 | + } |
|
731 | 731 | |
732 | 732 | |
733 | - /** |
|
734 | - * If the the first date starts at midnight on one day, and the next date ends at midnight on the |
|
735 | - * very next day then this method will return true. |
|
736 | - * If $date_1 = 2015-12-15 00:00:00 and $date_2 = 2015-12-16 00:00:00 then this function will return true. |
|
737 | - * If $date_1 = 2015-12-15 03:00:00 and $date_2 = 2015-12_16 03:00:00 then this function will return false. |
|
738 | - * If $date_1 = 2015-12-15 00:00:00 and $date_2 = 2015-12-15 00:00:00 then this function will return true. |
|
739 | - * |
|
740 | - * @param mixed $date_1 |
|
741 | - * @param mixed $date_2 |
|
742 | - * @return bool |
|
743 | - */ |
|
744 | - public static function dates_represent_one_24_hour_date($date_1, $date_2) |
|
745 | - { |
|
733 | + /** |
|
734 | + * If the the first date starts at midnight on one day, and the next date ends at midnight on the |
|
735 | + * very next day then this method will return true. |
|
736 | + * If $date_1 = 2015-12-15 00:00:00 and $date_2 = 2015-12-16 00:00:00 then this function will return true. |
|
737 | + * If $date_1 = 2015-12-15 03:00:00 and $date_2 = 2015-12_16 03:00:00 then this function will return false. |
|
738 | + * If $date_1 = 2015-12-15 00:00:00 and $date_2 = 2015-12-15 00:00:00 then this function will return true. |
|
739 | + * |
|
740 | + * @param mixed $date_1 |
|
741 | + * @param mixed $date_2 |
|
742 | + * @return bool |
|
743 | + */ |
|
744 | + public static function dates_represent_one_24_hour_date($date_1, $date_2) |
|
745 | + { |
|
746 | 746 | |
747 | - if ( |
|
748 | - (! $date_1 instanceof DateTime || ! $date_2 instanceof DateTime) |
|
749 | - || ($date_1->format(EE_Datetime_Field::mysql_time_format) !== '00:00:00' |
|
750 | - || $date_2->format( |
|
751 | - EE_Datetime_Field::mysql_time_format |
|
752 | - ) !== '00:00:00') |
|
753 | - ) { |
|
754 | - return false; |
|
755 | - } |
|
756 | - return $date_2->format('U') - $date_1->format('U') === 86400; |
|
757 | - } |
|
747 | + if ( |
|
748 | + (! $date_1 instanceof DateTime || ! $date_2 instanceof DateTime) |
|
749 | + || ($date_1->format(EE_Datetime_Field::mysql_time_format) !== '00:00:00' |
|
750 | + || $date_2->format( |
|
751 | + EE_Datetime_Field::mysql_time_format |
|
752 | + ) !== '00:00:00') |
|
753 | + ) { |
|
754 | + return false; |
|
755 | + } |
|
756 | + return $date_2->format('U') - $date_1->format('U') === 86400; |
|
757 | + } |
|
758 | 758 | |
759 | 759 | |
760 | - /** |
|
761 | - * This returns the appropriate query interval string that can be used in sql queries involving mysql Date |
|
762 | - * Functions. |
|
763 | - * |
|
764 | - * @param string $timezone_string A timezone string in a valid format to instantiate a DateTimeZone object. |
|
765 | - * @param string $field_for_interval The Database field that is the interval is applied to in the query. |
|
766 | - * @return string |
|
767 | - */ |
|
768 | - public static function get_sql_query_interval_for_offset($timezone_string, $field_for_interval) |
|
769 | - { |
|
770 | - try { |
|
771 | - /** need to account for timezone offset on the selects */ |
|
772 | - $DateTimeZone = new DateTimeZone($timezone_string); |
|
773 | - } catch (Exception $e) { |
|
774 | - $DateTimeZone = null; |
|
775 | - } |
|
776 | - /** |
|
777 | - * Note get_option( 'gmt_offset') returns a value in hours, whereas DateTimeZone::getOffset returns values in seconds. |
|
778 | - * Hence we do the calc for DateTimeZone::getOffset. |
|
779 | - */ |
|
780 | - $offset = $DateTimeZone instanceof DateTimeZone |
|
781 | - ? $DateTimeZone->getOffset(new DateTime('now')) / HOUR_IN_SECONDS |
|
782 | - : (float) get_option('gmt_offset'); |
|
783 | - $query_interval = $offset < 0 |
|
784 | - ? 'DATE_SUB(' . $field_for_interval . ', INTERVAL ' . $offset * -1 . ' HOUR)' |
|
785 | - : 'DATE_ADD(' . $field_for_interval . ', INTERVAL ' . $offset . ' HOUR)'; |
|
786 | - return $query_interval; |
|
787 | - } |
|
760 | + /** |
|
761 | + * This returns the appropriate query interval string that can be used in sql queries involving mysql Date |
|
762 | + * Functions. |
|
763 | + * |
|
764 | + * @param string $timezone_string A timezone string in a valid format to instantiate a DateTimeZone object. |
|
765 | + * @param string $field_for_interval The Database field that is the interval is applied to in the query. |
|
766 | + * @return string |
|
767 | + */ |
|
768 | + public static function get_sql_query_interval_for_offset($timezone_string, $field_for_interval) |
|
769 | + { |
|
770 | + try { |
|
771 | + /** need to account for timezone offset on the selects */ |
|
772 | + $DateTimeZone = new DateTimeZone($timezone_string); |
|
773 | + } catch (Exception $e) { |
|
774 | + $DateTimeZone = null; |
|
775 | + } |
|
776 | + /** |
|
777 | + * Note get_option( 'gmt_offset') returns a value in hours, whereas DateTimeZone::getOffset returns values in seconds. |
|
778 | + * Hence we do the calc for DateTimeZone::getOffset. |
|
779 | + */ |
|
780 | + $offset = $DateTimeZone instanceof DateTimeZone |
|
781 | + ? $DateTimeZone->getOffset(new DateTime('now')) / HOUR_IN_SECONDS |
|
782 | + : (float) get_option('gmt_offset'); |
|
783 | + $query_interval = $offset < 0 |
|
784 | + ? 'DATE_SUB(' . $field_for_interval . ', INTERVAL ' . $offset * -1 . ' HOUR)' |
|
785 | + : 'DATE_ADD(' . $field_for_interval . ', INTERVAL ' . $offset . ' HOUR)'; |
|
786 | + return $query_interval; |
|
787 | + } |
|
788 | 788 | |
789 | 789 | |
790 | - /** |
|
791 | - * Retrieves the site's default timezone and returns it formatted so it's ready for display |
|
792 | - * to users. If you want to customize how its displayed feel free to fetch the 'timezone_string' |
|
793 | - * and 'gmt_offset' WordPress options directly; or use the filter |
|
794 | - * FHEE__EEH_DTT_Helper__get_timezone_string_for_display |
|
795 | - * (although note that we remove any HTML that may be added) |
|
796 | - * |
|
797 | - * @return string |
|
798 | - */ |
|
799 | - public static function get_timezone_string_for_display() |
|
800 | - { |
|
801 | - $pretty_timezone = apply_filters('FHEE__EEH_DTT_Helper__get_timezone_string_for_display', ''); |
|
802 | - if (! empty($pretty_timezone)) { |
|
803 | - return esc_html($pretty_timezone); |
|
804 | - } |
|
805 | - $timezone_string = get_option('timezone_string'); |
|
806 | - if ($timezone_string) { |
|
807 | - static $mo_loaded = false; |
|
808 | - // Load translations for continents and cities just like wp_timezone_choice does |
|
809 | - if (! $mo_loaded) { |
|
810 | - $locale = get_locale(); |
|
811 | - $mofile = WP_LANG_DIR . '/continents-cities-' . $locale . '.mo'; |
|
812 | - load_textdomain('continents-cities', $mofile); |
|
813 | - $mo_loaded = true; |
|
814 | - } |
|
815 | - // well that was easy. |
|
816 | - $parts = explode('/', $timezone_string); |
|
817 | - // remove the continent |
|
818 | - unset($parts[0]); |
|
819 | - $t_parts = array(); |
|
820 | - // phpcs:disable WordPress.WP.I18n.NonSingularStringLiteralText |
|
821 | - // phpcs:disable WordPress.WP.I18n.TextDomainMismatch |
|
822 | - // disabled because this code is copied from WordPress and is a WordPress domain |
|
823 | - foreach ($parts as $part) { |
|
824 | - $t_parts[] = translate(str_replace('_', ' ', $part), 'continents-cities'); |
|
825 | - } |
|
826 | - return implode(' - ', $t_parts); |
|
827 | - // phpcs:enable |
|
828 | - } |
|
829 | - // they haven't set the timezone string, so let's return a string like "UTC+1" |
|
830 | - $gmt_offset = get_option('gmt_offset'); |
|
831 | - $prefix = (int) $gmt_offset >= 0 ? '+' : ''; |
|
832 | - $parts = explode('.', (string) $gmt_offset); |
|
833 | - if (count($parts) === 1) { |
|
834 | - $parts[1] = '00'; |
|
835 | - } else { |
|
836 | - // convert the part after the decimal, eg "5" (from x.5) or "25" (from x.25) |
|
837 | - // to minutes, eg 30 or 15, respectively |
|
838 | - $hour_fraction = (float) ('0.' . $parts[1]); |
|
839 | - $parts[1] = (string) $hour_fraction * 60; |
|
840 | - } |
|
841 | - return sprintf(esc_html__('UTC%1$s', 'event_espresso'), $prefix . implode(':', $parts)); |
|
842 | - } |
|
790 | + /** |
|
791 | + * Retrieves the site's default timezone and returns it formatted so it's ready for display |
|
792 | + * to users. If you want to customize how its displayed feel free to fetch the 'timezone_string' |
|
793 | + * and 'gmt_offset' WordPress options directly; or use the filter |
|
794 | + * FHEE__EEH_DTT_Helper__get_timezone_string_for_display |
|
795 | + * (although note that we remove any HTML that may be added) |
|
796 | + * |
|
797 | + * @return string |
|
798 | + */ |
|
799 | + public static function get_timezone_string_for_display() |
|
800 | + { |
|
801 | + $pretty_timezone = apply_filters('FHEE__EEH_DTT_Helper__get_timezone_string_for_display', ''); |
|
802 | + if (! empty($pretty_timezone)) { |
|
803 | + return esc_html($pretty_timezone); |
|
804 | + } |
|
805 | + $timezone_string = get_option('timezone_string'); |
|
806 | + if ($timezone_string) { |
|
807 | + static $mo_loaded = false; |
|
808 | + // Load translations for continents and cities just like wp_timezone_choice does |
|
809 | + if (! $mo_loaded) { |
|
810 | + $locale = get_locale(); |
|
811 | + $mofile = WP_LANG_DIR . '/continents-cities-' . $locale . '.mo'; |
|
812 | + load_textdomain('continents-cities', $mofile); |
|
813 | + $mo_loaded = true; |
|
814 | + } |
|
815 | + // well that was easy. |
|
816 | + $parts = explode('/', $timezone_string); |
|
817 | + // remove the continent |
|
818 | + unset($parts[0]); |
|
819 | + $t_parts = array(); |
|
820 | + // phpcs:disable WordPress.WP.I18n.NonSingularStringLiteralText |
|
821 | + // phpcs:disable WordPress.WP.I18n.TextDomainMismatch |
|
822 | + // disabled because this code is copied from WordPress and is a WordPress domain |
|
823 | + foreach ($parts as $part) { |
|
824 | + $t_parts[] = translate(str_replace('_', ' ', $part), 'continents-cities'); |
|
825 | + } |
|
826 | + return implode(' - ', $t_parts); |
|
827 | + // phpcs:enable |
|
828 | + } |
|
829 | + // they haven't set the timezone string, so let's return a string like "UTC+1" |
|
830 | + $gmt_offset = get_option('gmt_offset'); |
|
831 | + $prefix = (int) $gmt_offset >= 0 ? '+' : ''; |
|
832 | + $parts = explode('.', (string) $gmt_offset); |
|
833 | + if (count($parts) === 1) { |
|
834 | + $parts[1] = '00'; |
|
835 | + } else { |
|
836 | + // convert the part after the decimal, eg "5" (from x.5) or "25" (from x.25) |
|
837 | + // to minutes, eg 30 or 15, respectively |
|
838 | + $hour_fraction = (float) ('0.' . $parts[1]); |
|
839 | + $parts[1] = (string) $hour_fraction * 60; |
|
840 | + } |
|
841 | + return sprintf(esc_html__('UTC%1$s', 'event_espresso'), $prefix . implode(':', $parts)); |
|
842 | + } |
|
843 | 843 | |
844 | 844 | |
845 | 845 | |
846 | - /** |
|
847 | - * So PHP does this awesome thing where if you are trying to get a timestamp |
|
848 | - * for a month using a string like "February" or "February 2017", |
|
849 | - * and you don't specify a day as part of your string, |
|
850 | - * then PHP will use whatever the current day of the month is. |
|
851 | - * IF the current day of the month happens to be the 30th or 31st, |
|
852 | - * then PHP gets really confused by a date like February 30, |
|
853 | - * so instead of saying |
|
854 | - * "Hey February only has 28 days (this year)... |
|
855 | - * ...you must have meant the last day of the month!" |
|
856 | - * PHP does the next most logical thing, and bumps the date up to March 2nd, |
|
857 | - * because someone requesting February 30th obviously meant March 1st! |
|
858 | - * The way around this is to always set the day to the first, |
|
859 | - * so that the month will stay on the month you wanted. |
|
860 | - * this method will add that "1" into your date regardless of the format. |
|
861 | - * |
|
862 | - * @param string $month |
|
863 | - * @return string |
|
864 | - */ |
|
865 | - public static function first_of_month_timestamp($month = '') |
|
866 | - { |
|
867 | - $month = (string) $month; |
|
868 | - $year = ''; |
|
869 | - // check if the incoming string has a year in it or not |
|
870 | - if (preg_match('/\b\d{4}\b/', $month, $matches)) { |
|
871 | - $year = $matches[0]; |
|
872 | - // ten remove that from the month string as well as any spaces |
|
873 | - $month = trim(str_replace($year, '', $month)); |
|
874 | - // add a space before the year |
|
875 | - $year = " {$year}"; |
|
876 | - } |
|
877 | - // return timestamp for something like "February 1 2017" |
|
878 | - return strtotime("{$month} 1{$year}"); |
|
879 | - } |
|
846 | + /** |
|
847 | + * So PHP does this awesome thing where if you are trying to get a timestamp |
|
848 | + * for a month using a string like "February" or "February 2017", |
|
849 | + * and you don't specify a day as part of your string, |
|
850 | + * then PHP will use whatever the current day of the month is. |
|
851 | + * IF the current day of the month happens to be the 30th or 31st, |
|
852 | + * then PHP gets really confused by a date like February 30, |
|
853 | + * so instead of saying |
|
854 | + * "Hey February only has 28 days (this year)... |
|
855 | + * ...you must have meant the last day of the month!" |
|
856 | + * PHP does the next most logical thing, and bumps the date up to March 2nd, |
|
857 | + * because someone requesting February 30th obviously meant March 1st! |
|
858 | + * The way around this is to always set the day to the first, |
|
859 | + * so that the month will stay on the month you wanted. |
|
860 | + * this method will add that "1" into your date regardless of the format. |
|
861 | + * |
|
862 | + * @param string $month |
|
863 | + * @return string |
|
864 | + */ |
|
865 | + public static function first_of_month_timestamp($month = '') |
|
866 | + { |
|
867 | + $month = (string) $month; |
|
868 | + $year = ''; |
|
869 | + // check if the incoming string has a year in it or not |
|
870 | + if (preg_match('/\b\d{4}\b/', $month, $matches)) { |
|
871 | + $year = $matches[0]; |
|
872 | + // ten remove that from the month string as well as any spaces |
|
873 | + $month = trim(str_replace($year, '', $month)); |
|
874 | + // add a space before the year |
|
875 | + $year = " {$year}"; |
|
876 | + } |
|
877 | + // return timestamp for something like "February 1 2017" |
|
878 | + return strtotime("{$month} 1{$year}"); |
|
879 | + } |
|
880 | 880 | |
881 | 881 | |
882 | - /** |
|
883 | - * This simply returns the timestamp for tomorrow (midnight next day) in this sites timezone. So it may be midnight |
|
884 | - * for this sites timezone, but the timestamp could be some other time GMT. |
|
885 | - */ |
|
886 | - public static function tomorrow() |
|
887 | - { |
|
888 | - // The multiplication of -1 ensures that we switch positive offsets to negative and negative offsets to positive |
|
889 | - // before adding to the timestamp. Why? Because we want tomorrow to be for midnight the next day in THIS timezone |
|
890 | - // not an offset from midnight in UTC. So if we're starting with UTC 00:00:00, then we want to make sure the |
|
891 | - // final timestamp is equivalent to midnight in this timezone as represented in GMT. |
|
892 | - return strtotime('tomorrow') + (self::get_site_timezone_gmt_offset() * -1); |
|
893 | - } |
|
882 | + /** |
|
883 | + * This simply returns the timestamp for tomorrow (midnight next day) in this sites timezone. So it may be midnight |
|
884 | + * for this sites timezone, but the timestamp could be some other time GMT. |
|
885 | + */ |
|
886 | + public static function tomorrow() |
|
887 | + { |
|
888 | + // The multiplication of -1 ensures that we switch positive offsets to negative and negative offsets to positive |
|
889 | + // before adding to the timestamp. Why? Because we want tomorrow to be for midnight the next day in THIS timezone |
|
890 | + // not an offset from midnight in UTC. So if we're starting with UTC 00:00:00, then we want to make sure the |
|
891 | + // final timestamp is equivalent to midnight in this timezone as represented in GMT. |
|
892 | + return strtotime('tomorrow') + (self::get_site_timezone_gmt_offset() * -1); |
|
893 | + } |
|
894 | 894 | |
895 | 895 | |
896 | - /** |
|
897 | - * ** |
|
898 | - * Gives a nicely-formatted list of timezone strings. |
|
899 | - * Copied from the core wp function by the same name so we could customize to remove UTC offsets. |
|
900 | - * |
|
901 | - * @since 4.9.40.rc.008 |
|
902 | - * @staticvar bool $mo_loaded |
|
903 | - * @staticvar string $locale_loaded |
|
904 | - * @param string $selected_zone Selected timezone. |
|
905 | - * @param string $locale Optional. Locale to load the timezones in. Default current site locale. |
|
906 | - * @return string |
|
907 | - */ |
|
908 | - public static function wp_timezone_choice($selected_zone, $locale = null) |
|
909 | - { |
|
910 | - static $mo_loaded = false, $locale_loaded = null; |
|
911 | - $continents = array( |
|
912 | - 'Africa', |
|
913 | - 'America', |
|
914 | - 'Antarctica', |
|
915 | - 'Arctic', |
|
916 | - 'Asia', |
|
917 | - 'Atlantic', |
|
918 | - 'Australia', |
|
919 | - 'Europe', |
|
920 | - 'Indian', |
|
921 | - 'Pacific', |
|
922 | - ); |
|
923 | - // Load translations for continents and cities. |
|
924 | - if (! $mo_loaded || $locale !== $locale_loaded) { |
|
925 | - $locale_loaded = $locale ? $locale : get_locale(); |
|
926 | - $mofile = WP_LANG_DIR . '/continents-cities-' . $locale_loaded . '.mo'; |
|
927 | - unload_textdomain('continents-cities'); |
|
928 | - load_textdomain('continents-cities', $mofile); |
|
929 | - $mo_loaded = true; |
|
930 | - } |
|
931 | - $zone_data = array(); |
|
932 | - foreach (timezone_identifiers_list() as $zone) { |
|
933 | - $zone = explode('/', $zone); |
|
934 | - if (! in_array($zone[0], $continents, true)) { |
|
935 | - continue; |
|
936 | - } |
|
937 | - // This determines what gets set and translated - we don't translate Etc/* strings here, they are done later |
|
938 | - $exists = array( |
|
939 | - 0 => isset($zone[0]) && $zone[0], |
|
940 | - 1 => isset($zone[1]) && $zone[1], |
|
941 | - 2 => isset($zone[2]) && $zone[2], |
|
942 | - ); |
|
943 | - $exists[3] = $exists[0] && $zone[0] !== 'Etc'; |
|
944 | - $exists[4] = $exists[1] && $exists[3]; |
|
945 | - $exists[5] = $exists[2] && $exists[3]; |
|
946 | - // phpcs:disable WordPress.WP.I18n.NonSingularStringLiteralText |
|
947 | - // phpcs:disable WordPress.WP.I18n.TextDomainMismatch |
|
948 | - // disabled because this code is copied from WordPress and is a WordPress domain |
|
949 | - $zone_data[] = array( |
|
950 | - 'continent' => $exists[0] ? $zone[0] : '', |
|
951 | - 'city' => $exists[1] ? $zone[1] : '', |
|
952 | - 'subcity' => $exists[2] ? $zone[2] : '', |
|
953 | - 't_continent' => $exists[3] |
|
954 | - ? translate(str_replace('_', ' ', $zone[0]), 'continents-cities') |
|
955 | - : '', |
|
956 | - 't_city' => $exists[4] |
|
957 | - ? translate(str_replace('_', ' ', $zone[1]), 'continents-cities') |
|
958 | - : '', |
|
959 | - 't_subcity' => $exists[5] |
|
960 | - ? translate(str_replace('_', ' ', $zone[2]), 'continents-cities') |
|
961 | - : '', |
|
962 | - ); |
|
963 | - // phpcs:enable |
|
964 | - } |
|
965 | - usort($zone_data, '_wp_timezone_choice_usort_callback'); |
|
966 | - $structure = array(); |
|
967 | - if (empty($selected_zone)) { |
|
968 | - $structure[] = '<option selected value="">' . esc_html__('Select a city', 'event_espresso') . '</option>'; |
|
969 | - } |
|
970 | - foreach ($zone_data as $key => $zone) { |
|
971 | - // Build value in an array to join later |
|
972 | - $value = array($zone['continent']); |
|
973 | - if (empty($zone['city'])) { |
|
974 | - // It's at the continent level (generally won't happen) |
|
975 | - $display = $zone['t_continent']; |
|
976 | - } else { |
|
977 | - // It's inside a continent group |
|
978 | - // Continent optgroup |
|
979 | - if (! isset($zone_data[ $key - 1 ]) || $zone_data[ $key - 1 ]['continent'] !== $zone['continent']) { |
|
980 | - $label = $zone['t_continent']; |
|
981 | - $structure[] = '<optgroup label="' . esc_attr($label) . '">'; |
|
982 | - } |
|
983 | - // Add the city to the value |
|
984 | - $value[] = $zone['city']; |
|
985 | - $display = $zone['t_city']; |
|
986 | - if (! empty($zone['subcity'])) { |
|
987 | - // Add the subcity to the value |
|
988 | - $value[] = $zone['subcity']; |
|
989 | - $display .= ' - ' . $zone['t_subcity']; |
|
990 | - } |
|
991 | - } |
|
992 | - // Build the value |
|
993 | - $value = implode('/', $value); |
|
994 | - $selected = $value === $selected_zone ? ' selected' : ''; |
|
995 | - $structure[] = '<option value="' . esc_attr($value) . '"' . $selected . '>' |
|
996 | - . esc_html($display) |
|
997 | - . '</option>'; |
|
998 | - // Close continent optgroup |
|
999 | - if ( |
|
1000 | - ! empty($zone['city']) |
|
1001 | - && ( |
|
1002 | - ! isset($zone_data[ $key + 1 ]) |
|
1003 | - || (isset($zone_data[ $key + 1 ]) && $zone_data[ $key + 1 ]['continent'] !== $zone['continent']) |
|
1004 | - ) |
|
1005 | - ) { |
|
1006 | - $structure[] = '</optgroup>'; |
|
1007 | - } |
|
1008 | - } |
|
1009 | - return implode("\n", $structure); |
|
1010 | - } |
|
896 | + /** |
|
897 | + * ** |
|
898 | + * Gives a nicely-formatted list of timezone strings. |
|
899 | + * Copied from the core wp function by the same name so we could customize to remove UTC offsets. |
|
900 | + * |
|
901 | + * @since 4.9.40.rc.008 |
|
902 | + * @staticvar bool $mo_loaded |
|
903 | + * @staticvar string $locale_loaded |
|
904 | + * @param string $selected_zone Selected timezone. |
|
905 | + * @param string $locale Optional. Locale to load the timezones in. Default current site locale. |
|
906 | + * @return string |
|
907 | + */ |
|
908 | + public static function wp_timezone_choice($selected_zone, $locale = null) |
|
909 | + { |
|
910 | + static $mo_loaded = false, $locale_loaded = null; |
|
911 | + $continents = array( |
|
912 | + 'Africa', |
|
913 | + 'America', |
|
914 | + 'Antarctica', |
|
915 | + 'Arctic', |
|
916 | + 'Asia', |
|
917 | + 'Atlantic', |
|
918 | + 'Australia', |
|
919 | + 'Europe', |
|
920 | + 'Indian', |
|
921 | + 'Pacific', |
|
922 | + ); |
|
923 | + // Load translations for continents and cities. |
|
924 | + if (! $mo_loaded || $locale !== $locale_loaded) { |
|
925 | + $locale_loaded = $locale ? $locale : get_locale(); |
|
926 | + $mofile = WP_LANG_DIR . '/continents-cities-' . $locale_loaded . '.mo'; |
|
927 | + unload_textdomain('continents-cities'); |
|
928 | + load_textdomain('continents-cities', $mofile); |
|
929 | + $mo_loaded = true; |
|
930 | + } |
|
931 | + $zone_data = array(); |
|
932 | + foreach (timezone_identifiers_list() as $zone) { |
|
933 | + $zone = explode('/', $zone); |
|
934 | + if (! in_array($zone[0], $continents, true)) { |
|
935 | + continue; |
|
936 | + } |
|
937 | + // This determines what gets set and translated - we don't translate Etc/* strings here, they are done later |
|
938 | + $exists = array( |
|
939 | + 0 => isset($zone[0]) && $zone[0], |
|
940 | + 1 => isset($zone[1]) && $zone[1], |
|
941 | + 2 => isset($zone[2]) && $zone[2], |
|
942 | + ); |
|
943 | + $exists[3] = $exists[0] && $zone[0] !== 'Etc'; |
|
944 | + $exists[4] = $exists[1] && $exists[3]; |
|
945 | + $exists[5] = $exists[2] && $exists[3]; |
|
946 | + // phpcs:disable WordPress.WP.I18n.NonSingularStringLiteralText |
|
947 | + // phpcs:disable WordPress.WP.I18n.TextDomainMismatch |
|
948 | + // disabled because this code is copied from WordPress and is a WordPress domain |
|
949 | + $zone_data[] = array( |
|
950 | + 'continent' => $exists[0] ? $zone[0] : '', |
|
951 | + 'city' => $exists[1] ? $zone[1] : '', |
|
952 | + 'subcity' => $exists[2] ? $zone[2] : '', |
|
953 | + 't_continent' => $exists[3] |
|
954 | + ? translate(str_replace('_', ' ', $zone[0]), 'continents-cities') |
|
955 | + : '', |
|
956 | + 't_city' => $exists[4] |
|
957 | + ? translate(str_replace('_', ' ', $zone[1]), 'continents-cities') |
|
958 | + : '', |
|
959 | + 't_subcity' => $exists[5] |
|
960 | + ? translate(str_replace('_', ' ', $zone[2]), 'continents-cities') |
|
961 | + : '', |
|
962 | + ); |
|
963 | + // phpcs:enable |
|
964 | + } |
|
965 | + usort($zone_data, '_wp_timezone_choice_usort_callback'); |
|
966 | + $structure = array(); |
|
967 | + if (empty($selected_zone)) { |
|
968 | + $structure[] = '<option selected value="">' . esc_html__('Select a city', 'event_espresso') . '</option>'; |
|
969 | + } |
|
970 | + foreach ($zone_data as $key => $zone) { |
|
971 | + // Build value in an array to join later |
|
972 | + $value = array($zone['continent']); |
|
973 | + if (empty($zone['city'])) { |
|
974 | + // It's at the continent level (generally won't happen) |
|
975 | + $display = $zone['t_continent']; |
|
976 | + } else { |
|
977 | + // It's inside a continent group |
|
978 | + // Continent optgroup |
|
979 | + if (! isset($zone_data[ $key - 1 ]) || $zone_data[ $key - 1 ]['continent'] !== $zone['continent']) { |
|
980 | + $label = $zone['t_continent']; |
|
981 | + $structure[] = '<optgroup label="' . esc_attr($label) . '">'; |
|
982 | + } |
|
983 | + // Add the city to the value |
|
984 | + $value[] = $zone['city']; |
|
985 | + $display = $zone['t_city']; |
|
986 | + if (! empty($zone['subcity'])) { |
|
987 | + // Add the subcity to the value |
|
988 | + $value[] = $zone['subcity']; |
|
989 | + $display .= ' - ' . $zone['t_subcity']; |
|
990 | + } |
|
991 | + } |
|
992 | + // Build the value |
|
993 | + $value = implode('/', $value); |
|
994 | + $selected = $value === $selected_zone ? ' selected' : ''; |
|
995 | + $structure[] = '<option value="' . esc_attr($value) . '"' . $selected . '>' |
|
996 | + . esc_html($display) |
|
997 | + . '</option>'; |
|
998 | + // Close continent optgroup |
|
999 | + if ( |
|
1000 | + ! empty($zone['city']) |
|
1001 | + && ( |
|
1002 | + ! isset($zone_data[ $key + 1 ]) |
|
1003 | + || (isset($zone_data[ $key + 1 ]) && $zone_data[ $key + 1 ]['continent'] !== $zone['continent']) |
|
1004 | + ) |
|
1005 | + ) { |
|
1006 | + $structure[] = '</optgroup>'; |
|
1007 | + } |
|
1008 | + } |
|
1009 | + return implode("\n", $structure); |
|
1010 | + } |
|
1011 | 1011 | |
1012 | 1012 | |
1013 | - /** |
|
1014 | - * Shim for the WP function `get_user_locale` that was added in WordPress 4.7.0 |
|
1015 | - * |
|
1016 | - * @param int|WP_User $user_id |
|
1017 | - * @return string |
|
1018 | - */ |
|
1019 | - public static function get_user_locale($user_id = 0) |
|
1020 | - { |
|
1021 | - if (function_exists('get_user_locale')) { |
|
1022 | - return get_user_locale($user_id); |
|
1023 | - } |
|
1024 | - return get_locale(); |
|
1025 | - } |
|
1013 | + /** |
|
1014 | + * Shim for the WP function `get_user_locale` that was added in WordPress 4.7.0 |
|
1015 | + * |
|
1016 | + * @param int|WP_User $user_id |
|
1017 | + * @return string |
|
1018 | + */ |
|
1019 | + public static function get_user_locale($user_id = 0) |
|
1020 | + { |
|
1021 | + if (function_exists('get_user_locale')) { |
|
1022 | + return get_user_locale($user_id); |
|
1023 | + } |
|
1024 | + return get_locale(); |
|
1025 | + } |
|
1026 | 1026 | |
1027 | 1027 | |
1028 | - /** |
|
1029 | - * Return the appropriate helper adapter for DTT related things. |
|
1030 | - * |
|
1031 | - * @return HelperInterface |
|
1032 | - * @throws InvalidArgumentException |
|
1033 | - * @throws InvalidDataTypeException |
|
1034 | - * @throws InvalidInterfaceException |
|
1035 | - */ |
|
1036 | - private static function getHelperAdapter() |
|
1037 | - { |
|
1038 | - $dtt_helper_fqcn = PHP_VERSION_ID < 50600 |
|
1039 | - ? 'EventEspresso\core\services\helpers\datetime\PhpCompatLessFiveSixHelper' |
|
1040 | - : 'EventEspresso\core\services\helpers\datetime\PhpCompatGreaterFiveSixHelper'; |
|
1041 | - return LoaderFactory::getLoader()->getShared($dtt_helper_fqcn); |
|
1042 | - } |
|
1028 | + /** |
|
1029 | + * Return the appropriate helper adapter for DTT related things. |
|
1030 | + * |
|
1031 | + * @return HelperInterface |
|
1032 | + * @throws InvalidArgumentException |
|
1033 | + * @throws InvalidDataTypeException |
|
1034 | + * @throws InvalidInterfaceException |
|
1035 | + */ |
|
1036 | + private static function getHelperAdapter() |
|
1037 | + { |
|
1038 | + $dtt_helper_fqcn = PHP_VERSION_ID < 50600 |
|
1039 | + ? 'EventEspresso\core\services\helpers\datetime\PhpCompatLessFiveSixHelper' |
|
1040 | + : 'EventEspresso\core\services\helpers\datetime\PhpCompatGreaterFiveSixHelper'; |
|
1041 | + return LoaderFactory::getLoader()->getShared($dtt_helper_fqcn); |
|
1042 | + } |
|
1043 | 1043 | |
1044 | 1044 | |
1045 | - /** |
|
1046 | - * Helper function for setting the timezone on a DateTime object. |
|
1047 | - * This is implemented to standardize a workaround for a PHP bug outlined in |
|
1048 | - * https://events.codebasehq.com/projects/event-espresso/tickets/11407 and |
|
1049 | - * https://events.codebasehq.com/projects/event-espresso/tickets/11233 |
|
1050 | - * |
|
1051 | - * @param DateTime $datetime |
|
1052 | - * @param DateTimeZone $timezone |
|
1053 | - */ |
|
1054 | - public static function setTimezone(DateTime $datetime, DateTimeZone $timezone) |
|
1055 | - { |
|
1056 | - $datetime->setTimezone($timezone); |
|
1057 | - $datetime->getTimestamp(); |
|
1058 | - } |
|
1045 | + /** |
|
1046 | + * Helper function for setting the timezone on a DateTime object. |
|
1047 | + * This is implemented to standardize a workaround for a PHP bug outlined in |
|
1048 | + * https://events.codebasehq.com/projects/event-espresso/tickets/11407 and |
|
1049 | + * https://events.codebasehq.com/projects/event-espresso/tickets/11233 |
|
1050 | + * |
|
1051 | + * @param DateTime $datetime |
|
1052 | + * @param DateTimeZone $timezone |
|
1053 | + */ |
|
1054 | + public static function setTimezone(DateTime $datetime, DateTimeZone $timezone) |
|
1055 | + { |
|
1056 | + $datetime->setTimezone($timezone); |
|
1057 | + $datetime->getTimestamp(); |
|
1058 | + } |
|
1059 | 1059 | } |
@@ -29,8 +29,8 @@ discard block |
||
29 | 29 | "eventStatus": [ "<?php echo esc_url_raw($event_status); ?>" ], |
30 | 30 | "offers": [ |
31 | 31 | <?php |
32 | - $i = 0; |
|
33 | - foreach ($event_tickets as $ticket) {?> |
|
32 | + $i = 0; |
|
33 | + foreach ($event_tickets as $ticket) {?> |
|
34 | 34 | { |
35 | 35 | "@type": "Offer", |
36 | 36 | "url": "<?php echo esc_url_raw($event_permalink); ?>", |
@@ -39,18 +39,18 @@ discard block |
||
39 | 39 | "price": "<?php echo esc_html($ticket['price']); ?>", |
40 | 40 | "priceCurrency": "<?php echo esc_html($currency); ?>" |
41 | 41 | <?php if (isset($ticket['availability'])) { |
42 | - ?>,"availability": "<?php echo esc_url_raw('https://schema.org/' . $ticket['availability']); ?>" |
|
42 | + ?>,"availability": "<?php echo esc_url_raw('https://schema.org/' . $ticket['availability']); ?>" |
|
43 | 43 | <?php } ?> |
44 | 44 | }<?php |
45 | - $i++; |
|
46 | - if ($i < count($event_tickets)) { |
|
47 | - echo ','; |
|
48 | - } |
|
49 | - } |
|
50 | - ?> |
|
45 | + $i++; |
|
46 | + if ($i < count($event_tickets)) { |
|
47 | + echo ','; |
|
48 | + } |
|
49 | + } |
|
50 | + ?> |
|
51 | 51 | ]<?php |
52 | - if ($venue_name) { |
|
53 | - ?>, |
|
52 | + if ($venue_name) { |
|
53 | + ?>, |
|
54 | 54 | "location": { |
55 | 55 | "@type": "Place", |
56 | 56 | "name": <?php echo wp_json_encode($venue_name); ?>, |
@@ -63,13 +63,13 @@ discard block |
||
63 | 63 | } |
64 | 64 | } |
65 | 65 | <?php |
66 | - } ?> |
|
66 | + } ?> |
|
67 | 67 | <?php |
68 | - if ($event_image) { |
|
69 | - ?>, |
|
68 | + if ($event_image) { |
|
69 | + ?>, |
|
70 | 70 | "image": "<?php echo esc_url_raw($event_image); ?>" |
71 | 71 | <?php |
72 | - } ?> |
|
72 | + } ?> |
|
73 | 73 | <?php do_action('AHEE__json_linked_data_for_event__template'); ?> |
74 | 74 | } |
75 | 75 |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | $input->set_label_sizes(); |
23 | 23 | $label_size_class = $input->get_label_size_class(); |
24 | 24 | $html = ''; |
25 | - if (! is_array($input->raw_value()) && $input->raw_value() !== null) { |
|
25 | + if ( ! is_array($input->raw_value()) && $input->raw_value() !== null) { |
|
26 | 26 | EE_Error::doing_it_wrong( |
27 | 27 | 'EE_Checkbox_Display_Strategy::display()', |
28 | 28 | sprintf( |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | ), |
34 | 34 | $input->html_id(), |
35 | 35 | var_export($input->raw_value(), true), |
36 | - $input->html_name() . '[]' |
|
36 | + $input->html_name().'[]' |
|
37 | 37 | ), |
38 | 38 | '4.8.1' |
39 | 39 | ); |
@@ -52,19 +52,19 @@ discard block |
||
52 | 52 | . '">'; |
53 | 53 | $html .= EEH_HTML::nl(1, 'checkbox'); |
54 | 54 | $html .= '<input type="checkbox"'; |
55 | - $html .= ' name="' . $input->html_name() . '[]"'; |
|
56 | - $html .= ' id="' . $html_id . '"'; |
|
57 | - $html .= ' class="' . $input->html_class() . '"'; |
|
58 | - $html .= ' style="' . $input->html_style() . '"'; |
|
59 | - $html .= ' value="' . esc_attr($value) . '"'; |
|
55 | + $html .= ' name="'.$input->html_name().'[]"'; |
|
56 | + $html .= ' id="'.$html_id.'"'; |
|
57 | + $html .= ' class="'.$input->html_class().'"'; |
|
58 | + $html .= ' style="'.$input->html_style().'"'; |
|
59 | + $html .= ' value="'.esc_attr($value).'"'; |
|
60 | 60 | $html .= ! empty($input_raw_value) && in_array($value, $input_raw_value, true) |
61 | 61 | ? ' checked' |
62 | 62 | : ''; |
63 | - $html .= ' ' . $this->_input->other_html_attributes(); |
|
64 | - $html .= ' data-question_label="' . $input->html_label_id() . '"'; |
|
63 | + $html .= ' '.$this->_input->other_html_attributes(); |
|
64 | + $html .= ' data-question_label="'.$input->html_label_id().'"'; |
|
65 | 65 | $html .= '> '; |
66 | 66 | $html .= $display_text; |
67 | - $html .= EEH_HTML::nl(-1, 'checkbox') . '</label>'; |
|
67 | + $html .= EEH_HTML::nl(-1, 'checkbox').'</label>'; |
|
68 | 68 | } |
69 | 69 | return $html; |
70 | 70 | } |
@@ -11,60 +11,60 @@ |
||
11 | 11 | */ |
12 | 12 | class EE_Checkbox_Display_Strategy extends EE_Compound_Input_Display_Strategy |
13 | 13 | { |
14 | - /** |
|
15 | - * @throws EE_Error |
|
16 | - * @return string of html to display the field |
|
17 | - */ |
|
18 | - public function display() |
|
19 | - { |
|
20 | - $input = $this->get_input(); |
|
21 | - $input->set_label_sizes(); |
|
22 | - $label_size_class = $input->get_label_size_class(); |
|
23 | - $html = ''; |
|
24 | - if (! is_array($input->raw_value()) && $input->raw_value() !== null) { |
|
25 | - EE_Error::doing_it_wrong( |
|
26 | - 'EE_Checkbox_Display_Strategy::display()', |
|
27 | - sprintf( |
|
28 | - esc_html_x( |
|
29 | - 'Input values for checkboxes should be an array of values, but the value for input "%1$s" is "%2$s". Please verify that the input name is exactly "%3$s"', |
|
30 | - 'Input values for checkboxes should be an array of values, but the value for input "form-input-id" is "form-input-value". Please verify that the input name is exactly "form_input_name[]"', |
|
31 | - 'event_espresso' |
|
32 | - ), |
|
33 | - $input->html_id(), |
|
34 | - var_export($input->raw_value(), true), |
|
35 | - $input->html_name() . '[]' |
|
36 | - ), |
|
37 | - '4.8.1' |
|
38 | - ); |
|
39 | - } |
|
40 | - $input_raw_value = (array) $input->raw_value(); |
|
41 | - foreach ($input->options() as $value => $display_text) { |
|
42 | - $value = $input->get_normalization_strategy()->unnormalize_one($value); |
|
43 | - $html_id = $this->get_sub_input_id($value); |
|
44 | - $html .= EEH_HTML::nl(0, 'checkbox'); |
|
45 | - $html .= '<label for="' |
|
46 | - . $html_id |
|
47 | - . '" id="' |
|
48 | - . $html_id |
|
49 | - . '-lbl" class="ee-checkbox-label-after' |
|
50 | - . $label_size_class |
|
51 | - . '">'; |
|
52 | - $html .= EEH_HTML::nl(1, 'checkbox'); |
|
53 | - $html .= '<input type="checkbox"'; |
|
54 | - $html .= ' name="' . $input->html_name() . '[]"'; |
|
55 | - $html .= ' id="' . $html_id . '"'; |
|
56 | - $html .= ' class="' . $input->html_class() . '"'; |
|
57 | - $html .= ' style="' . $input->html_style() . '"'; |
|
58 | - $html .= ' value="' . esc_attr($value) . '"'; |
|
59 | - $html .= ! empty($input_raw_value) && in_array($value, $input_raw_value, true) |
|
60 | - ? ' checked' |
|
61 | - : ''; |
|
62 | - $html .= ' ' . $this->_input->other_html_attributes(); |
|
63 | - $html .= ' data-question_label="' . $input->html_label_id() . '"'; |
|
64 | - $html .= '> '; |
|
65 | - $html .= $display_text; |
|
66 | - $html .= EEH_HTML::nl(-1, 'checkbox') . '</label>'; |
|
67 | - } |
|
68 | - return $html; |
|
69 | - } |
|
14 | + /** |
|
15 | + * @throws EE_Error |
|
16 | + * @return string of html to display the field |
|
17 | + */ |
|
18 | + public function display() |
|
19 | + { |
|
20 | + $input = $this->get_input(); |
|
21 | + $input->set_label_sizes(); |
|
22 | + $label_size_class = $input->get_label_size_class(); |
|
23 | + $html = ''; |
|
24 | + if (! is_array($input->raw_value()) && $input->raw_value() !== null) { |
|
25 | + EE_Error::doing_it_wrong( |
|
26 | + 'EE_Checkbox_Display_Strategy::display()', |
|
27 | + sprintf( |
|
28 | + esc_html_x( |
|
29 | + 'Input values for checkboxes should be an array of values, but the value for input "%1$s" is "%2$s". Please verify that the input name is exactly "%3$s"', |
|
30 | + 'Input values for checkboxes should be an array of values, but the value for input "form-input-id" is "form-input-value". Please verify that the input name is exactly "form_input_name[]"', |
|
31 | + 'event_espresso' |
|
32 | + ), |
|
33 | + $input->html_id(), |
|
34 | + var_export($input->raw_value(), true), |
|
35 | + $input->html_name() . '[]' |
|
36 | + ), |
|
37 | + '4.8.1' |
|
38 | + ); |
|
39 | + } |
|
40 | + $input_raw_value = (array) $input->raw_value(); |
|
41 | + foreach ($input->options() as $value => $display_text) { |
|
42 | + $value = $input->get_normalization_strategy()->unnormalize_one($value); |
|
43 | + $html_id = $this->get_sub_input_id($value); |
|
44 | + $html .= EEH_HTML::nl(0, 'checkbox'); |
|
45 | + $html .= '<label for="' |
|
46 | + . $html_id |
|
47 | + . '" id="' |
|
48 | + . $html_id |
|
49 | + . '-lbl" class="ee-checkbox-label-after' |
|
50 | + . $label_size_class |
|
51 | + . '">'; |
|
52 | + $html .= EEH_HTML::nl(1, 'checkbox'); |
|
53 | + $html .= '<input type="checkbox"'; |
|
54 | + $html .= ' name="' . $input->html_name() . '[]"'; |
|
55 | + $html .= ' id="' . $html_id . '"'; |
|
56 | + $html .= ' class="' . $input->html_class() . '"'; |
|
57 | + $html .= ' style="' . $input->html_style() . '"'; |
|
58 | + $html .= ' value="' . esc_attr($value) . '"'; |
|
59 | + $html .= ! empty($input_raw_value) && in_array($value, $input_raw_value, true) |
|
60 | + ? ' checked' |
|
61 | + : ''; |
|
62 | + $html .= ' ' . $this->_input->other_html_attributes(); |
|
63 | + $html .= ' data-question_label="' . $input->html_label_id() . '"'; |
|
64 | + $html .= '> '; |
|
65 | + $html .= $display_text; |
|
66 | + $html .= EEH_HTML::nl(-1, 'checkbox') . '</label>'; |
|
67 | + } |
|
68 | + return $html; |
|
69 | + } |
|
70 | 70 | } |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | */ |
23 | 23 | public function display() |
24 | 24 | { |
25 | - if (! $this->_input instanceof EE_Form_Input_With_Options_Base) { |
|
25 | + if ( ! $this->_input instanceof EE_Form_Input_With_Options_Base) { |
|
26 | 26 | throw new EE_Error(sprintf(esc_html__('Cannot use Select Display Strategy with an input that doesn\'t have options', 'event_espresso'))); |
27 | 27 | } |
28 | 28 | |
@@ -36,14 +36,14 @@ discard block |
||
36 | 36 | if (EEH_Array::is_multi_dimensional_array($this->_input->options())) { |
37 | 37 | EEH_HTML::indent(1, 'optgroup'); |
38 | 38 | foreach ($this->_input->options() as $opt_group_label => $opt_group) { |
39 | - if (! empty($opt_group_label)) { |
|
40 | - $html .= EEH_HTML::nl(0, 'optgroup') . '<optgroup label="' . esc_attr($opt_group_label) . '">'; |
|
39 | + if ( ! empty($opt_group_label)) { |
|
40 | + $html .= EEH_HTML::nl(0, 'optgroup').'<optgroup label="'.esc_attr($opt_group_label).'">'; |
|
41 | 41 | } |
42 | 42 | EEH_HTML::indent(1, 'option'); |
43 | 43 | $html .= $this->_display_options($opt_group); |
44 | 44 | EEH_HTML::indent(-1, 'option'); |
45 | - if (! empty($opt_group_label)) { |
|
46 | - $html .= EEH_HTML::nl(0, 'optgroup') . '</optgroup>'; |
|
45 | + if ( ! empty($opt_group_label)) { |
|
46 | + $html .= EEH_HTML::nl(0, 'optgroup').'</optgroup>'; |
|
47 | 47 | } |
48 | 48 | } |
49 | 49 | EEH_HTML::indent(-1, 'optgroup'); |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | $html .= $this->_display_options($this->_input->options()); |
52 | 52 | } |
53 | 53 | |
54 | - $html .= EEH_HTML::nl(0, 'select') . '</select>'; |
|
54 | + $html .= EEH_HTML::nl(0, 'select').'</select>'; |
|
55 | 55 | return $html; |
56 | 56 | } |
57 | 57 | |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | // PHP will have converted it to a PHP integer (eg 123). So we need to make sure it's a string |
72 | 72 | $unnormalized_value = $this->_input->get_normalization_strategy()->unnormalize_one($value); |
73 | 73 | $selected = $this->_check_if_option_selected($unnormalized_value) ? ' selected' : ''; |
74 | - $html .= EEH_HTML::nl(0, 'option') . '<option value="' . esc_attr($unnormalized_value) . '"' . $selected . '>' . $display_text . '</option>'; |
|
74 | + $html .= EEH_HTML::nl(0, 'option').'<option value="'.esc_attr($unnormalized_value).'"'.$selected.'>'.$display_text.'</option>'; |
|
75 | 75 | } |
76 | 76 | EEH_HTML::indent(-1, 'option'); |
77 | 77 | return $html; |
@@ -14,78 +14,78 @@ |
||
14 | 14 | */ |
15 | 15 | class EE_Select_Display_Strategy extends EE_Display_Strategy_Base |
16 | 16 | { |
17 | - /** |
|
18 | - * |
|
19 | - * @throws EE_Error |
|
20 | - * @return string of html to display the field |
|
21 | - */ |
|
22 | - public function display() |
|
23 | - { |
|
24 | - if (! $this->_input instanceof EE_Form_Input_With_Options_Base) { |
|
25 | - throw new EE_Error(sprintf(esc_html__('Cannot use Select Display Strategy with an input that doesn\'t have options', 'event_espresso'))); |
|
26 | - } |
|
17 | + /** |
|
18 | + * |
|
19 | + * @throws EE_Error |
|
20 | + * @return string of html to display the field |
|
21 | + */ |
|
22 | + public function display() |
|
23 | + { |
|
24 | + if (! $this->_input instanceof EE_Form_Input_With_Options_Base) { |
|
25 | + throw new EE_Error(sprintf(esc_html__('Cannot use Select Display Strategy with an input that doesn\'t have options', 'event_espresso'))); |
|
26 | + } |
|
27 | 27 | |
28 | - $html = EEH_HTML::nl(0, 'select'); |
|
29 | - $html .= '<select'; |
|
30 | - $html .= $this->_attributes_string( |
|
31 | - $this->_standard_attributes_array() |
|
32 | - ); |
|
33 | - $html .= '>'; |
|
28 | + $html = EEH_HTML::nl(0, 'select'); |
|
29 | + $html .= '<select'; |
|
30 | + $html .= $this->_attributes_string( |
|
31 | + $this->_standard_attributes_array() |
|
32 | + ); |
|
33 | + $html .= '>'; |
|
34 | 34 | |
35 | - if (EEH_Array::is_multi_dimensional_array($this->_input->options())) { |
|
36 | - EEH_HTML::indent(1, 'optgroup'); |
|
37 | - foreach ($this->_input->options() as $opt_group_label => $opt_group) { |
|
38 | - if (! empty($opt_group_label)) { |
|
39 | - $html .= EEH_HTML::nl(0, 'optgroup') . '<optgroup label="' . esc_attr($opt_group_label) . '">'; |
|
40 | - } |
|
41 | - EEH_HTML::indent(1, 'option'); |
|
42 | - $html .= $this->_display_options($opt_group); |
|
43 | - EEH_HTML::indent(-1, 'option'); |
|
44 | - if (! empty($opt_group_label)) { |
|
45 | - $html .= EEH_HTML::nl(0, 'optgroup') . '</optgroup>'; |
|
46 | - } |
|
47 | - } |
|
48 | - EEH_HTML::indent(-1, 'optgroup'); |
|
49 | - } else { |
|
50 | - $html .= $this->_display_options($this->_input->options()); |
|
51 | - } |
|
35 | + if (EEH_Array::is_multi_dimensional_array($this->_input->options())) { |
|
36 | + EEH_HTML::indent(1, 'optgroup'); |
|
37 | + foreach ($this->_input->options() as $opt_group_label => $opt_group) { |
|
38 | + if (! empty($opt_group_label)) { |
|
39 | + $html .= EEH_HTML::nl(0, 'optgroup') . '<optgroup label="' . esc_attr($opt_group_label) . '">'; |
|
40 | + } |
|
41 | + EEH_HTML::indent(1, 'option'); |
|
42 | + $html .= $this->_display_options($opt_group); |
|
43 | + EEH_HTML::indent(-1, 'option'); |
|
44 | + if (! empty($opt_group_label)) { |
|
45 | + $html .= EEH_HTML::nl(0, 'optgroup') . '</optgroup>'; |
|
46 | + } |
|
47 | + } |
|
48 | + EEH_HTML::indent(-1, 'optgroup'); |
|
49 | + } else { |
|
50 | + $html .= $this->_display_options($this->_input->options()); |
|
51 | + } |
|
52 | 52 | |
53 | - $html .= EEH_HTML::nl(0, 'select') . '</select>'; |
|
54 | - return $html; |
|
55 | - } |
|
53 | + $html .= EEH_HTML::nl(0, 'select') . '</select>'; |
|
54 | + return $html; |
|
55 | + } |
|
56 | 56 | |
57 | 57 | |
58 | 58 | |
59 | - /** |
|
60 | - * Displays a flat list of options as option tags |
|
61 | - * @param array $options |
|
62 | - * @return string |
|
63 | - */ |
|
64 | - protected function _display_options($options) |
|
65 | - { |
|
66 | - $html = ''; |
|
67 | - EEH_HTML::indent(1, 'option'); |
|
68 | - foreach ($options as $value => $display_text) { |
|
69 | - // even if this input uses EE_Text_Normalization if one of the array keys is a numeric string, like "123", |
|
70 | - // PHP will have converted it to a PHP integer (eg 123). So we need to make sure it's a string |
|
71 | - $unnormalized_value = $this->_input->get_normalization_strategy()->unnormalize_one($value); |
|
72 | - $selected = $this->_check_if_option_selected($unnormalized_value) ? ' selected' : ''; |
|
73 | - $html .= EEH_HTML::nl(0, 'option') . '<option value="' . esc_attr($unnormalized_value) . '"' . $selected . '>' . $display_text . '</option>'; |
|
74 | - } |
|
75 | - EEH_HTML::indent(-1, 'option'); |
|
76 | - return $html; |
|
77 | - } |
|
59 | + /** |
|
60 | + * Displays a flat list of options as option tags |
|
61 | + * @param array $options |
|
62 | + * @return string |
|
63 | + */ |
|
64 | + protected function _display_options($options) |
|
65 | + { |
|
66 | + $html = ''; |
|
67 | + EEH_HTML::indent(1, 'option'); |
|
68 | + foreach ($options as $value => $display_text) { |
|
69 | + // even if this input uses EE_Text_Normalization if one of the array keys is a numeric string, like "123", |
|
70 | + // PHP will have converted it to a PHP integer (eg 123). So we need to make sure it's a string |
|
71 | + $unnormalized_value = $this->_input->get_normalization_strategy()->unnormalize_one($value); |
|
72 | + $selected = $this->_check_if_option_selected($unnormalized_value) ? ' selected' : ''; |
|
73 | + $html .= EEH_HTML::nl(0, 'option') . '<option value="' . esc_attr($unnormalized_value) . '"' . $selected . '>' . $display_text . '</option>'; |
|
74 | + } |
|
75 | + EEH_HTML::indent(-1, 'option'); |
|
76 | + return $html; |
|
77 | + } |
|
78 | 78 | |
79 | 79 | |
80 | 80 | |
81 | - /** |
|
82 | - * Checks if that value is the one selected |
|
83 | - * |
|
84 | - * @param string|int $option_value unnormalized value option (string). How it will appear in the HTML. |
|
85 | - * @return string |
|
86 | - */ |
|
87 | - protected function _check_if_option_selected($option_value) |
|
88 | - { |
|
89 | - return $option_value === $this->_input->raw_value(); |
|
90 | - } |
|
81 | + /** |
|
82 | + * Checks if that value is the one selected |
|
83 | + * |
|
84 | + * @param string|int $option_value unnormalized value option (string). How it will appear in the HTML. |
|
85 | + * @return string |
|
86 | + */ |
|
87 | + protected function _check_if_option_selected($option_value) |
|
88 | + { |
|
89 | + return $option_value === $this->_input->raw_value(); |
|
90 | + } |
|
91 | 91 | } |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | maxlength='245' |
82 | 82 | name="<?php echo esc_attr($edit_tickets_name); ?>[<?php echo esc_attr($tkt_row); ?>][TKT_name]" |
83 | 83 | placeholder="<?php |
84 | - esc_html_e('Ticket Title', 'event_espresso') ?>" |
|
84 | + esc_html_e('Ticket Title', 'event_espresso') ?>" |
|
85 | 85 | value="<?php echo esc_attr($TKT_name); ?>" |
86 | 86 | /> |
87 | 87 | </td> |
@@ -327,7 +327,7 @@ discard block |
||
327 | 327 | for='edit-ticket-TKT_uses-<?php echo esc_attr($tkt_row); ?>' |
328 | 328 | > |
329 | 329 | <?php |
330 | - esc_html_e('Ticket Uses', 'event_espresso') ?> |
|
330 | + esc_html_e('Ticket Uses', 'event_espresso') ?> |
|
331 | 331 | </label> |
332 | 332 | <input type="text" |
333 | 333 | class="edit-ticket-TKT_uses ee-small-text-inp ee-numeric" |
@@ -346,7 +346,7 @@ discard block |
||
346 | 346 | /> |
347 | 347 | <label class='screen-reader-text' for='disabled-ticket-TKT_min-<?php echo esc_attr($tkt_row);?>'> |
348 | 348 | <?php |
349 | - esc_html_e('Minimum Quantity', 'event_espresso') ?> |
|
349 | + esc_html_e('Minimum Quantity', 'event_espresso') ?> |
|
350 | 350 | </label> |
351 | 351 | <input type="text" disabled |
352 | 352 | class="edit-ticket-TKT_min ee-small-text-inp ee-numeric" |
@@ -408,14 +408,14 @@ discard block |
||
408 | 408 | id="edit-ticket-TKT_required-<?php echo esc_attr($tkt_row); ?>" |
409 | 409 | value="1" |
410 | 410 | <?php |
411 | - echo ($TKT_required ? ' checked' : ''); |
|
412 | - echo ($disabled ? ' disabled' : ''); |
|
413 | - ?> |
|
411 | + echo ($TKT_required ? ' checked' : ''); |
|
412 | + echo ($disabled ? ' disabled' : ''); |
|
413 | + ?> |
|
414 | 414 | /> |
415 | 415 | <?php esc_html_e( |
416 | - 'This ticket is required (will appear first in frontend ticket lists).', |
|
417 | - 'event_espresso' |
|
418 | - ); ?> |
|
416 | + 'This ticket is required (will appear first in frontend ticket lists).', |
|
417 | + 'event_espresso' |
|
418 | + ); ?> |
|
419 | 419 | </label> |
420 | 420 | </div> |
421 | 421 | <div class="ticket-is-taxable-container"> |
@@ -517,32 +517,32 @@ discard block |
||
517 | 517 | <h4 class="tickets-heading"><?php esc_html_e('Event Datetimes', 'event_espresso'); ?></h4> |
518 | 518 | <p> |
519 | 519 | <?php esc_html_e( |
520 | - 'This ticket will be usable (allow entrance) for the following selected event datetimes (click to select). The "# Datetimes" amount (above) indicates how many of the assigned datetimes the ticket holder can gain access to:', |
|
521 | - 'event_espresso' |
|
522 | - ); ?> |
|
520 | + 'This ticket will be usable (allow entrance) for the following selected event datetimes (click to select). The "# Datetimes" amount (above) indicates how many of the assigned datetimes the ticket holder can gain access to:', |
|
521 | + 'event_espresso' |
|
522 | + ); ?> |
|
523 | 523 | </p> |
524 | 524 | <ul class="datetime-tickets-list"> |
525 | 525 | <?php echo wp_kses($ticket_datetimes_list, AllowedTags::getWithFormTags()); ?> |
526 | 526 | </ul> |
527 | 527 | |
528 | 528 | <?php do_action( |
529 | - 'AHEE__event_tickets_datetime_ticket_row_template__advanced_details_end', |
|
530 | - $tkt_row, |
|
531 | - $TKT_ID |
|
532 | - ); ?> |
|
529 | + 'AHEE__event_tickets_datetime_ticket_row_template__advanced_details_end', |
|
530 | + $tkt_row, |
|
531 | + $TKT_ID |
|
532 | + ); ?> |
|
533 | 533 | <div class="ee-editor-footer-container"> |
534 | 534 | <div class="ee-editor-id-container"> |
535 | 535 | <span class="ee-item-id"><?php |
536 | - echo ($TKT_ID |
|
537 | - ? sprintf(esc_html__('Ticket ID: %d', 'event_espresso'), $TKT_ID) |
|
538 | - : ''); ?></span> |
|
536 | + echo ($TKT_ID |
|
537 | + ? sprintf(esc_html__('Ticket ID: %d', 'event_espresso'), $TKT_ID) |
|
538 | + : ''); ?></span> |
|
539 | 539 | </div> |
540 | 540 | <div class="save-cancel-button-container"> |
541 | 541 | <label for="edit-ticket-TKT_is_default_selector-<?php echo esc_attr($tkt_row); ?>"> |
542 | 542 | <?php esc_html_e( |
543 | - 'use this new ticket as a default ticket for any new events', |
|
544 | - 'event_espresso' |
|
545 | - ); ?> |
|
543 | + 'use this new ticket as a default ticket for any new events', |
|
544 | + 'event_espresso' |
|
545 | + ); ?> |
|
546 | 546 | <input type="checkbox" |
547 | 547 | name="<?php echo esc_attr($edit_tickets_name); ?>[<?php echo esc_attr($tkt_row); ?>][TKT_is_default_selector]" |
548 | 548 | class="edit-ticket-TKT_is_default_selector" |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | |
60 | 60 | $ticket_archive_class .= WP_DEBUG ? ' ee-wp-debug' : ''; |
61 | 61 | ?> |
62 | -<tr class="ee-ticket-sortable ticket-row <?php echo sanitize_html_class($ticket_archive_class);?>" |
|
62 | +<tr class="ee-ticket-sortable ticket-row <?php echo sanitize_html_class($ticket_archive_class); ?>" |
|
63 | 63 | id="display-ticketrow-<?php echo esc_attr($tkt_row); ?>"> |
64 | 64 | <!-- TKT_order --> |
65 | 65 | <td class="ee-tkt-order-field"> |
@@ -344,23 +344,23 @@ discard block |
||
344 | 344 | name="<?php echo esc_attr($edit_tickets_name); ?>[<?php echo esc_attr($tkt_row); ?>][TKT_min]" |
345 | 345 | value="<?php echo esc_attr($TKT_min); ?>" |
346 | 346 | /> |
347 | - <label class='screen-reader-text' for='disabled-ticket-TKT_min-<?php echo esc_attr($tkt_row);?>'> |
|
347 | + <label class='screen-reader-text' for='disabled-ticket-TKT_min-<?php echo esc_attr($tkt_row); ?>'> |
|
348 | 348 | <?php |
349 | 349 | esc_html_e('Minimum Quantity', 'event_espresso') ?> |
350 | 350 | </label> |
351 | 351 | <input type="text" disabled |
352 | 352 | class="edit-ticket-TKT_min ee-small-text-inp ee-numeric" |
353 | - id='disabled-ticket-TKT_min-<?php echo esc_attr($tkt_row);?>' |
|
353 | + id='disabled-ticket-TKT_min-<?php echo esc_attr($tkt_row); ?>' |
|
354 | 354 | name="archived_ticket[<?php echo esc_attr($tkt_row); ?>][TKT_min]" |
355 | 355 | value="<?php echo esc_attr($TKT_min); ?>" |
356 | 356 | /> |
357 | 357 | <?php else : ?> |
358 | - <label class='screen-reader-text' for='edit-ticket-TKT_min-<?php echo esc_attr($tkt_row);?>'> |
|
358 | + <label class='screen-reader-text' for='edit-ticket-TKT_min-<?php echo esc_attr($tkt_row); ?>'> |
|
359 | 359 | <?php esc_html_e('Minimum Quantity', 'event_espresso') ?> |
360 | 360 | </label> |
361 | 361 | <input type="text" |
362 | 362 | class="edit-ticket-TKT_min ee-small-text-inp ee-numeric" |
363 | - id='edit-ticket-TKT_min-<?php echo esc_attr($tkt_row);?>' |
|
363 | + id='edit-ticket-TKT_min-<?php echo esc_attr($tkt_row); ?>' |
|
364 | 364 | name="<?php echo esc_attr($edit_tickets_name); ?>[<?php echo esc_attr($tkt_row); ?>][TKT_min]" |
365 | 365 | value="<?php echo esc_attr($TKT_min); ?>" |
366 | 366 | /> |
@@ -372,22 +372,22 @@ discard block |
||
372 | 372 | name="<?php echo esc_attr($edit_tickets_name); ?>[<?php echo esc_attr($tkt_row); ?>][TKT_max]" |
373 | 373 | value="<?php echo esc_attr($TKT_max); ?>" |
374 | 374 | /> |
375 | - <label class='screen-reader-text' for='disabled-ticket-TKT_max-<?php echo esc_attr($tkt_row);?>'> |
|
375 | + <label class='screen-reader-text' for='disabled-ticket-TKT_max-<?php echo esc_attr($tkt_row); ?>'> |
|
376 | 376 | <?php esc_html_e('Maximum Quantity', 'event_espresso') ?> |
377 | 377 | </label> |
378 | 378 | <input type="text" disabled |
379 | 379 | class="edit-ticket-TKT_max ee-small-text-inp ee-numeric" |
380 | - id='disabled-ticket-TKT_max-<?php echo esc_attr($tkt_row);?>' |
|
380 | + id='disabled-ticket-TKT_max-<?php echo esc_attr($tkt_row); ?>' |
|
381 | 381 | name="<?php echo esc_attr($edit_tickets_name); ?>[<?php echo esc_attr($tkt_row); ?>][TKT_max]" |
382 | 382 | value="<?php echo esc_attr($TKT_max); ?>" |
383 | 383 | /> |
384 | 384 | <?php else : ?> |
385 | - <label class='screen-reader-text' for='edit-ticket-TKT_max-<?php echo esc_attr($tkt_row);?>'> |
|
385 | + <label class='screen-reader-text' for='edit-ticket-TKT_max-<?php echo esc_attr($tkt_row); ?>'> |
|
386 | 386 | <?php esc_html_e('Maximum Quantity', 'event_espresso') ?> |
387 | 387 | </label> |
388 | 388 | <input type="text" |
389 | 389 | class="edit-ticket-TKT_max ee-small-text-inp ee-numeric" |
390 | - id='edit-ticket-TKT_max-<?php echo esc_attr($tkt_row);?>' |
|
390 | + id='edit-ticket-TKT_max-<?php echo esc_attr($tkt_row); ?>' |
|
391 | 391 | name="<?php echo esc_attr($edit_tickets_name); ?>[<?php echo esc_attr($tkt_row); ?>][TKT_max]" |
392 | 392 | value="<?php echo esc_attr($TKT_max); ?>" |
393 | 393 | /> |
@@ -419,7 +419,7 @@ discard block |
||
419 | 419 | </label> |
420 | 420 | </div> |
421 | 421 | <div class="ticket-is-taxable-container"> |
422 | - <?php if (! empty($tax_rows)) { ?> |
|
422 | + <?php if ( ! empty($tax_rows)) { ?> |
|
423 | 423 | <label for="edit-ticket-TKT_taxable-<?php echo esc_attr($tkt_row); ?>"> |
424 | 424 | <?php if ($disabled) : ?> |
425 | 425 | <?php $tax_value = ! empty($TKT_taxable) ? 1 : 0; ?> |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | : []; |
136 | 136 | $EQGids = array_keys($EQGs); |
137 | 137 | |
138 | - if (! empty($QSGs)) { |
|
138 | + if ( ! empty($QSGs)) { |
|
139 | 139 | $html = count($QSGs) > 10 ? '<div style="height:250px;overflow:auto;">' : ''; |
140 | 140 | foreach ($QSGs as $QSG) { |
141 | 141 | $checked = in_array($QSG->ID(), $EQGids, true) ? ' checked ' : ''; |
@@ -148,15 +148,15 @@ discard block |
||
148 | 148 | ); |
149 | 149 | |
150 | 150 | $html .= ' |
151 | - <p id="event-question-group-' . $QSG->ID() . '"> |
|
152 | - <input value="' . $QSG->ID() . '"' |
|
153 | - . ' type="checkbox" name="add_attendee_question_groups[' . $QSG->ID() . ']"' . $checked . ' /> |
|
154 | - <a href="' . $edit_link . '" title="' |
|
151 | + <p id="event-question-group-' . $QSG->ID().'"> |
|
152 | + <input value="' . $QSG->ID().'"' |
|
153 | + . ' type="checkbox" name="add_attendee_question_groups['.$QSG->ID().']"'.$checked.' /> |
|
154 | + <a href="' . $edit_link.'" title="' |
|
155 | 155 | . sprintf( |
156 | 156 | esc_attr__('Edit %s Group', 'event_espresso'), |
157 | 157 | $QSG->get('QSG_name') |
158 | 158 | ) |
159 | - . '" target="_blank">' . $QSG->get('QSG_name') . '</a> |
|
159 | + . '" target="_blank">'.$QSG->get('QSG_name').'</a> |
|
160 | 160 | </p>'; |
161 | 161 | if ($QSG->ID() === 2) { |
162 | 162 | $html .= ' |
@@ -200,7 +200,7 @@ discard block |
||
200 | 200 | $current_qgs = array_keys($current_qgs); // we just want the ids |
201 | 201 | |
202 | 202 | // now let's get the groups selected in the editor and update (IF we have data) |
203 | - if (! empty($question_groups)) { |
|
203 | + if ( ! empty($question_groups)) { |
|
204 | 204 | foreach ($question_groups as $qgid) { |
205 | 205 | // add to event |
206 | 206 | if ($qgid) { |
@@ -16,214 +16,214 @@ |
||
16 | 16 | */ |
17 | 17 | class espresso_events_Registration_Form_Hooks_Extend extends espresso_events_Registration_Form_Hooks |
18 | 18 | { |
19 | - /** |
|
20 | - * extending the properties set in espresso_events_Registration_From_Hooks |
|
21 | - * |
|
22 | - * @access protected |
|
23 | - * @return void |
|
24 | - */ |
|
25 | - protected function _extend_properties() |
|
26 | - { |
|
27 | - if ( |
|
28 | - $this->_adminpage_obj->adminConfig()->useAdvancedEditor() |
|
29 | - && $this->_adminpage_obj->feature()->allowed('use_reg_form_builder') |
|
30 | - ) { |
|
31 | - return; |
|
32 | - } |
|
33 | - $this->_metaboxes = array_merge( |
|
34 | - $this->_metaboxes, |
|
35 | - array( |
|
36 | - 1 => array( |
|
37 | - 'page_route' => array('create_new', 'edit'), |
|
38 | - 'func' => 'additional_questions', |
|
39 | - 'label' => esc_html__('Questions for Additional Registrants', 'event_espresso'), |
|
40 | - 'priority' => 'default', |
|
41 | - 'context' => 'side', |
|
42 | - ), |
|
43 | - ) |
|
44 | - ); |
|
45 | - $this->_scripts_styles = array( |
|
46 | - 'registers' => array( |
|
47 | - 'extended-event-editor' => array( |
|
48 | - 'url' => EE_CORE_CAF_ADMIN_EXTEND_URL |
|
49 | - . 'registration_form/assets/event-editor-question-groups.js', |
|
50 | - 'depends' => array('jquery'), |
|
51 | - ), |
|
52 | - ), |
|
53 | - 'enqueues' => array( |
|
54 | - 'extended-event-editor' => array('edit', 'create_new'), |
|
55 | - ), |
|
56 | - ); |
|
57 | - } |
|
58 | - |
|
59 | - |
|
60 | - /** |
|
61 | - * @param Callable[] $callbacks |
|
62 | - * @return array |
|
63 | - */ |
|
64 | - public function modify_callbacks($callbacks) |
|
65 | - { |
|
66 | - $callbacks = parent::modify_callbacks($callbacks); |
|
67 | - $callbacks[] = array($this, 'additional_question_group_update'); |
|
68 | - return $callbacks; |
|
69 | - } |
|
70 | - |
|
71 | - |
|
72 | - /** |
|
73 | - * Call back hooked into revision restores. |
|
74 | - * |
|
75 | - * @param $post_id |
|
76 | - * @param $revision_id |
|
77 | - * @return EE_Base_Class|void |
|
78 | - * @throws EE_Error |
|
79 | - * @throws InvalidArgumentException |
|
80 | - * @throws InvalidDataTypeException |
|
81 | - * @throws InvalidInterfaceException |
|
82 | - * @throws ReflectionException |
|
83 | - */ |
|
84 | - public function restore_revision($post_id, $revision_id) |
|
85 | - { |
|
86 | - $post_evt = parent::restore_revision($post_id, $revision_id); |
|
87 | - |
|
88 | - // restore revision for additional questions |
|
89 | - $post_evt->restore_revision( |
|
90 | - $revision_id, |
|
91 | - ['Question_Group'], |
|
92 | - [ |
|
93 | - 'Question_Group' => ['Event_Question_Group.EQG_additional' => true], |
|
94 | - ] |
|
95 | - ); |
|
96 | - } |
|
97 | - |
|
98 | - |
|
99 | - /** |
|
100 | - * @param $post_id |
|
101 | - * @param $post |
|
102 | - * @throws EE_Error |
|
103 | - * @throws InvalidArgumentException |
|
104 | - * @throws InvalidDataTypeException |
|
105 | - * @throws InvalidInterfaceException |
|
106 | - */ |
|
107 | - public function additional_questions($post_id, $post) |
|
108 | - { |
|
109 | - $this->_event = $this->_adminpage_obj->get_event_object(); |
|
110 | - $event_id = $this->_event->ID(); |
|
111 | - ?> |
|
19 | + /** |
|
20 | + * extending the properties set in espresso_events_Registration_From_Hooks |
|
21 | + * |
|
22 | + * @access protected |
|
23 | + * @return void |
|
24 | + */ |
|
25 | + protected function _extend_properties() |
|
26 | + { |
|
27 | + if ( |
|
28 | + $this->_adminpage_obj->adminConfig()->useAdvancedEditor() |
|
29 | + && $this->_adminpage_obj->feature()->allowed('use_reg_form_builder') |
|
30 | + ) { |
|
31 | + return; |
|
32 | + } |
|
33 | + $this->_metaboxes = array_merge( |
|
34 | + $this->_metaboxes, |
|
35 | + array( |
|
36 | + 1 => array( |
|
37 | + 'page_route' => array('create_new', 'edit'), |
|
38 | + 'func' => 'additional_questions', |
|
39 | + 'label' => esc_html__('Questions for Additional Registrants', 'event_espresso'), |
|
40 | + 'priority' => 'default', |
|
41 | + 'context' => 'side', |
|
42 | + ), |
|
43 | + ) |
|
44 | + ); |
|
45 | + $this->_scripts_styles = array( |
|
46 | + 'registers' => array( |
|
47 | + 'extended-event-editor' => array( |
|
48 | + 'url' => EE_CORE_CAF_ADMIN_EXTEND_URL |
|
49 | + . 'registration_form/assets/event-editor-question-groups.js', |
|
50 | + 'depends' => array('jquery'), |
|
51 | + ), |
|
52 | + ), |
|
53 | + 'enqueues' => array( |
|
54 | + 'extended-event-editor' => array('edit', 'create_new'), |
|
55 | + ), |
|
56 | + ); |
|
57 | + } |
|
58 | + |
|
59 | + |
|
60 | + /** |
|
61 | + * @param Callable[] $callbacks |
|
62 | + * @return array |
|
63 | + */ |
|
64 | + public function modify_callbacks($callbacks) |
|
65 | + { |
|
66 | + $callbacks = parent::modify_callbacks($callbacks); |
|
67 | + $callbacks[] = array($this, 'additional_question_group_update'); |
|
68 | + return $callbacks; |
|
69 | + } |
|
70 | + |
|
71 | + |
|
72 | + /** |
|
73 | + * Call back hooked into revision restores. |
|
74 | + * |
|
75 | + * @param $post_id |
|
76 | + * @param $revision_id |
|
77 | + * @return EE_Base_Class|void |
|
78 | + * @throws EE_Error |
|
79 | + * @throws InvalidArgumentException |
|
80 | + * @throws InvalidDataTypeException |
|
81 | + * @throws InvalidInterfaceException |
|
82 | + * @throws ReflectionException |
|
83 | + */ |
|
84 | + public function restore_revision($post_id, $revision_id) |
|
85 | + { |
|
86 | + $post_evt = parent::restore_revision($post_id, $revision_id); |
|
87 | + |
|
88 | + // restore revision for additional questions |
|
89 | + $post_evt->restore_revision( |
|
90 | + $revision_id, |
|
91 | + ['Question_Group'], |
|
92 | + [ |
|
93 | + 'Question_Group' => ['Event_Question_Group.EQG_additional' => true], |
|
94 | + ] |
|
95 | + ); |
|
96 | + } |
|
97 | + |
|
98 | + |
|
99 | + /** |
|
100 | + * @param $post_id |
|
101 | + * @param $post |
|
102 | + * @throws EE_Error |
|
103 | + * @throws InvalidArgumentException |
|
104 | + * @throws InvalidDataTypeException |
|
105 | + * @throws InvalidInterfaceException |
|
106 | + */ |
|
107 | + public function additional_questions($post_id, $post) |
|
108 | + { |
|
109 | + $this->_event = $this->_adminpage_obj->get_event_object(); |
|
110 | + $event_id = $this->_event->ID(); |
|
111 | + ?> |
|
112 | 112 | <div class="inside"> |
113 | 113 | <p><strong> |
114 | 114 | <?php esc_html_e('Question Groups', 'event_espresso'); ?> |
115 | 115 | </strong><br/> |
116 | 116 | <?php |
117 | - printf( |
|
118 | - esc_html__( |
|
119 | - 'Add a pre-populated %1$sgroup of questions%2$s to your event.', |
|
120 | - 'event_espresso' |
|
121 | - ), |
|
122 | - '<a href="admin.php?page=espresso_registration_form" target="_blank">', |
|
123 | - '</a>' |
|
124 | - ); |
|
125 | - ?> |
|
117 | + printf( |
|
118 | + esc_html__( |
|
119 | + 'Add a pre-populated %1$sgroup of questions%2$s to your event.', |
|
120 | + 'event_espresso' |
|
121 | + ), |
|
122 | + '<a href="admin.php?page=espresso_registration_form" target="_blank">', |
|
123 | + '</a>' |
|
124 | + ); |
|
125 | + ?> |
|
126 | 126 | </p> |
127 | 127 | <?php |
128 | 128 | |
129 | - $qsg_where['QSG_deleted'] = false; |
|
130 | - $query_params = apply_filters( |
|
131 | - 'FHEE__espresso_events_Registration_Form_Hooks_Extend__additional_questions__question_group_query_parameters', |
|
132 | - array($qsg_where, 'order_by' => array('QSG_order' => 'ASC')) |
|
133 | - ); |
|
134 | - $QSGs = EEM_Question_Group::instance()->get_all($query_params); |
|
135 | - $EQGs = ! empty($event_id) |
|
136 | - ? $this->_event->get_many_related( |
|
137 | - 'Question_Group', |
|
138 | - [['Event_Question_Group.EQG_additional' => true]] |
|
139 | - ) |
|
140 | - : []; |
|
141 | - $EQGids = array_keys($EQGs); |
|
142 | - |
|
143 | - if (! empty($QSGs)) { |
|
144 | - $html = count($QSGs) > 10 ? '<div style="height:250px;overflow:auto;">' : ''; |
|
145 | - foreach ($QSGs as $QSG) { |
|
146 | - $checked = in_array($QSG->ID(), $EQGids, true) ? ' checked ' : ''; |
|
147 | - $edit_link = EE_Admin_Page::add_query_args_and_nonce( |
|
148 | - array( |
|
149 | - 'action' => 'edit_question_group', |
|
150 | - 'QSG_ID' => $QSG->ID(), |
|
151 | - ), |
|
152 | - EE_FORMS_ADMIN_URL |
|
153 | - ); |
|
154 | - |
|
155 | - $html .= ' |
|
129 | + $qsg_where['QSG_deleted'] = false; |
|
130 | + $query_params = apply_filters( |
|
131 | + 'FHEE__espresso_events_Registration_Form_Hooks_Extend__additional_questions__question_group_query_parameters', |
|
132 | + array($qsg_where, 'order_by' => array('QSG_order' => 'ASC')) |
|
133 | + ); |
|
134 | + $QSGs = EEM_Question_Group::instance()->get_all($query_params); |
|
135 | + $EQGs = ! empty($event_id) |
|
136 | + ? $this->_event->get_many_related( |
|
137 | + 'Question_Group', |
|
138 | + [['Event_Question_Group.EQG_additional' => true]] |
|
139 | + ) |
|
140 | + : []; |
|
141 | + $EQGids = array_keys($EQGs); |
|
142 | + |
|
143 | + if (! empty($QSGs)) { |
|
144 | + $html = count($QSGs) > 10 ? '<div style="height:250px;overflow:auto;">' : ''; |
|
145 | + foreach ($QSGs as $QSG) { |
|
146 | + $checked = in_array($QSG->ID(), $EQGids, true) ? ' checked ' : ''; |
|
147 | + $edit_link = EE_Admin_Page::add_query_args_and_nonce( |
|
148 | + array( |
|
149 | + 'action' => 'edit_question_group', |
|
150 | + 'QSG_ID' => $QSG->ID(), |
|
151 | + ), |
|
152 | + EE_FORMS_ADMIN_URL |
|
153 | + ); |
|
154 | + |
|
155 | + $html .= ' |
|
156 | 156 | <p id="event-question-group-' . $QSG->ID() . '"> |
157 | 157 | <input value="' . $QSG->ID() . '"' |
158 | - . ' type="checkbox" name="add_attendee_question_groups[' . $QSG->ID() . ']"' . $checked . ' /> |
|
158 | + . ' type="checkbox" name="add_attendee_question_groups[' . $QSG->ID() . ']"' . $checked . ' /> |
|
159 | 159 | <a href="' . $edit_link . '" title="' |
160 | - . sprintf( |
|
161 | - esc_attr__('Edit %s Group', 'event_espresso'), |
|
162 | - $QSG->get('QSG_name') |
|
163 | - ) |
|
164 | - . '" target="_blank">' . $QSG->get('QSG_name') . '</a> |
|
160 | + . sprintf( |
|
161 | + esc_attr__('Edit %s Group', 'event_espresso'), |
|
162 | + $QSG->get('QSG_name') |
|
163 | + ) |
|
164 | + . '" target="_blank">' . $QSG->get('QSG_name') . '</a> |
|
165 | 165 | </p>'; |
166 | - if ($QSG->ID() === 2) { |
|
167 | - $html .= ' |
|
166 | + if ($QSG->ID() === 2) { |
|
167 | + $html .= ' |
|
168 | 168 | <p id="question-group-requirements-notice-pg" class="important-notice small-text" style="display: none;">' |
169 | - . esc_html__( |
|
170 | - 'The Personal Information question group is required whenever the Address Information question group is activated.', |
|
171 | - 'event_espresso' |
|
172 | - ) |
|
173 | - . '</p>'; |
|
174 | - } |
|
175 | - } |
|
176 | - $html .= count($QSGs) > 10 ? '</div>' : ''; |
|
177 | - |
|
178 | - echo wp_kses($html, AllowedTags::getWithFormTags()); |
|
179 | - } else { |
|
180 | - esc_html_e( |
|
181 | - 'There seems to be a problem with your questions. Please contact [email protected]', |
|
182 | - 'event_espresso' |
|
183 | - ); |
|
184 | - } |
|
185 | - do_action('AHEE__espresso_events_Registration_Form_Hooks__additional_questions__after_content'); |
|
186 | - ?> |
|
169 | + . esc_html__( |
|
170 | + 'The Personal Information question group is required whenever the Address Information question group is activated.', |
|
171 | + 'event_espresso' |
|
172 | + ) |
|
173 | + . '</p>'; |
|
174 | + } |
|
175 | + } |
|
176 | + $html .= count($QSGs) > 10 ? '</div>' : ''; |
|
177 | + |
|
178 | + echo wp_kses($html, AllowedTags::getWithFormTags()); |
|
179 | + } else { |
|
180 | + esc_html_e( |
|
181 | + 'There seems to be a problem with your questions. Please contact [email protected]', |
|
182 | + 'event_espresso' |
|
183 | + ); |
|
184 | + } |
|
185 | + do_action('AHEE__espresso_events_Registration_Form_Hooks__additional_questions__after_content'); |
|
186 | + ?> |
|
187 | 187 | </div> |
188 | 188 | <?php |
189 | - } |
|
190 | - |
|
191 | - |
|
192 | - public function additional_question_group_update($evtobj, $data) |
|
193 | - { |
|
194 | - $question_groups = ! empty($data['add_attendee_question_groups']) |
|
195 | - ? (array) $data['add_attendee_question_groups'] |
|
196 | - : []; |
|
197 | - $added_qgs = array_keys($question_groups); |
|
198 | - $success = []; |
|
199 | - |
|
200 | - // let's get all current question groups associated with this event. |
|
201 | - $current_qgs = $evtobj->get_many_related( |
|
202 | - 'Question_Group', |
|
203 | - [['Event_Question_Group.EQG_additional' => true]] |
|
204 | - ); |
|
205 | - $current_qgs = array_keys($current_qgs); // we just want the ids |
|
206 | - |
|
207 | - // now let's get the groups selected in the editor and update (IF we have data) |
|
208 | - if (! empty($question_groups)) { |
|
209 | - foreach ($question_groups as $qgid) { |
|
210 | - // add to event |
|
211 | - if ($qgid) { |
|
212 | - $qg = $evtobj->add_question_group($qgid, false); |
|
213 | - } |
|
214 | - $success[] = ! empty($qg) ? 1 : 0; |
|
215 | - } |
|
216 | - } |
|
217 | - |
|
218 | - // wait a minute... are there question groups missing in the saved groups that ARE with the current event? |
|
219 | - $removed_qgs = array_diff($current_qgs, $added_qgs); |
|
220 | - |
|
221 | - foreach ($removed_qgs as $qgid) { |
|
222 | - $qg = $evtobj->remove_question_group($qgid, false); |
|
223 | - $success[] = ! empty($qg) ? 1 : 0; |
|
224 | - } |
|
225 | - |
|
226 | - |
|
227 | - return in_array(0, $success, true) ? false : true; |
|
228 | - } |
|
189 | + } |
|
190 | + |
|
191 | + |
|
192 | + public function additional_question_group_update($evtobj, $data) |
|
193 | + { |
|
194 | + $question_groups = ! empty($data['add_attendee_question_groups']) |
|
195 | + ? (array) $data['add_attendee_question_groups'] |
|
196 | + : []; |
|
197 | + $added_qgs = array_keys($question_groups); |
|
198 | + $success = []; |
|
199 | + |
|
200 | + // let's get all current question groups associated with this event. |
|
201 | + $current_qgs = $evtobj->get_many_related( |
|
202 | + 'Question_Group', |
|
203 | + [['Event_Question_Group.EQG_additional' => true]] |
|
204 | + ); |
|
205 | + $current_qgs = array_keys($current_qgs); // we just want the ids |
|
206 | + |
|
207 | + // now let's get the groups selected in the editor and update (IF we have data) |
|
208 | + if (! empty($question_groups)) { |
|
209 | + foreach ($question_groups as $qgid) { |
|
210 | + // add to event |
|
211 | + if ($qgid) { |
|
212 | + $qg = $evtobj->add_question_group($qgid, false); |
|
213 | + } |
|
214 | + $success[] = ! empty($qg) ? 1 : 0; |
|
215 | + } |
|
216 | + } |
|
217 | + |
|
218 | + // wait a minute... are there question groups missing in the saved groups that ARE with the current event? |
|
219 | + $removed_qgs = array_diff($current_qgs, $added_qgs); |
|
220 | + |
|
221 | + foreach ($removed_qgs as $qgid) { |
|
222 | + $qg = $evtobj->remove_question_group($qgid, false); |
|
223 | + $success[] = ! empty($qg) ? 1 : 0; |
|
224 | + } |
|
225 | + |
|
226 | + |
|
227 | + return in_array(0, $success, true) ? false : true; |
|
228 | + } |
|
229 | 229 | } |