@@ -11,241 +11,241 @@ |
||
| 11 | 11 | class EED_Ical extends EED_Module |
| 12 | 12 | { |
| 13 | 13 | |
| 14 | - const iCal_datetime_format = 'Ymd\THis\Z'; |
|
| 15 | - |
|
| 16 | - |
|
| 17 | - /** |
|
| 18 | - * @return EED_Ical|EED_Module |
|
| 19 | - */ |
|
| 20 | - public static function instance() |
|
| 21 | - { |
|
| 22 | - return parent::get_instance(__CLASS__); |
|
| 23 | - } |
|
| 24 | - |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * set_hooks - for hooking into EE Core, other modules, etc |
|
| 28 | - * |
|
| 29 | - * @access public |
|
| 30 | - * @return void |
|
| 31 | - */ |
|
| 32 | - public static function set_hooks() |
|
| 33 | - { |
|
| 34 | - // create download buttons |
|
| 35 | - add_filter( |
|
| 36 | - 'FHEE__espresso_list_of_event_dates__datetime_html', |
|
| 37 | - array('EED_Ical', 'generate_add_to_iCal_button'), |
|
| 38 | - 10, |
|
| 39 | - 2 |
|
| 40 | - ); |
|
| 41 | - // process ics download request |
|
| 42 | - EE_Config::register_route('download_ics_file', 'EED_Ical', 'download_ics_file'); |
|
| 43 | - } |
|
| 44 | - |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
| 48 | - * |
|
| 49 | - * @access public |
|
| 50 | - * @return void |
|
| 51 | - */ |
|
| 52 | - public static function set_hooks_admin() |
|
| 53 | - { |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * run - initial module setup |
|
| 59 | - * |
|
| 60 | - * @access public |
|
| 61 | - * @param WP $WP |
|
| 62 | - * @return void |
|
| 63 | - */ |
|
| 64 | - public function run($WP) |
|
| 65 | - { |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * generate_add_to_iCal_button |
|
| 71 | - * |
|
| 72 | - * @access public |
|
| 73 | - * @param $html |
|
| 74 | - * @param $datetime |
|
| 75 | - * @return string |
|
| 76 | - * @throws \EE_Error |
|
| 77 | - */ |
|
| 78 | - public static function generate_add_to_iCal_button($html, $datetime) |
|
| 79 | - { |
|
| 80 | - // first verify a proper datetime object has been received |
|
| 81 | - if ($datetime instanceof EE_Datetime) { |
|
| 82 | - // set whether a link or submit button is shown |
|
| 83 | - $iCal_type = apply_filters('FHEE__EED_Ical__generate_add_to_iCal_button__iCal_type', 'submit'); |
|
| 84 | - // generate a link to the route we registered in set_hooks() |
|
| 85 | - $URL = add_query_arg(array('ee' => 'download_ics_file', 'ics_id' => $datetime->ID()), site_url()); |
|
| 86 | - // what type ? |
|
| 87 | - switch ($iCal_type) { |
|
| 88 | - // submit buttons appear as buttons and are very compatible with a theme's style |
|
| 89 | - case 'submit': |
|
| 90 | - $html .= '<form id="download-iCal-frm-' . $datetime->ID(); |
|
| 91 | - $html .= '" class="download-iCal-frm" action="' . $URL . '" method="post" >'; |
|
| 92 | - $html .= '<input type="submit" class="ee-ical-sbmt" value="" title="'; |
|
| 93 | - $html .= esc_html__('Add to iCal Calendar', 'event_espresso') . '"/>'; |
|
| 94 | - $html .= '</form>'; |
|
| 95 | - break; |
|
| 96 | - // buttons are just links that have been styled to appear as buttons, |
|
| 97 | - // but may not be blend with a theme as well as submit buttons |
|
| 98 | - case 'button': |
|
| 99 | - $html .= '<a class="ee-ical-btn small ee-button ee-roundish" href="' . $URL; |
|
| 100 | - $html .= '" title="' . esc_html__('Add to iCal Calendar', 'event_espresso') . '">'; |
|
| 101 | - $html .= ' <span class="dashicons dashicons-calendar"></span>'; |
|
| 102 | - $html .= '</a>'; |
|
| 103 | - break; |
|
| 104 | - // links are just links that use the calendar dashicon |
|
| 105 | - case 'icon': |
|
| 106 | - $html .= '<a class="ee-ical-lnk" href="' . $URL . '" title="'; |
|
| 107 | - $html .= esc_html__('Add to iCal Calendar', 'event_espresso') . '">'; |
|
| 108 | - $html .= ' <span class="dashicons dashicons-calendar"></span>'; |
|
| 109 | - $html .= '</a>'; |
|
| 110 | - break; |
|
| 111 | - } |
|
| 112 | - } |
|
| 113 | - return $html; |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - |
|
| 117 | - /** |
|
| 118 | - * download_ics_file |
|
| 119 | - * |
|
| 120 | - * @access public |
|
| 121 | - * @return void |
|
| 122 | - * @throws \EE_Error |
|
| 123 | - */ |
|
| 124 | - public static function download_ics_file() |
|
| 125 | - { |
|
| 126 | - if (EE_Registry::instance()->REQ->is_set('ics_id')) { |
|
| 127 | - $DTT_ID = absint(EE_Registry::instance()->REQ->get('ics_id')); |
|
| 128 | - $datetime = EE_Registry::instance()->load_model('Datetime')->get_one_by_ID($DTT_ID); |
|
| 129 | - if ($datetime instanceof EE_Datetime) { |
|
| 130 | - // get related event, venues, and event categories |
|
| 131 | - $event = $datetime->event(); |
|
| 132 | - if ($event instanceof EE_Event) { |
|
| 133 | - // get related category Term object and it's name |
|
| 134 | - $category = $event->first_event_category(); |
|
| 135 | - if ($category instanceof EE_Term) { |
|
| 136 | - $category = $category->name(); |
|
| 137 | - } |
|
| 138 | - $location = ''; |
|
| 139 | - // get first related venue and convert to CSV string |
|
| 140 | - $venue = $event->venues(array('limit' => 1)); |
|
| 141 | - if (is_array($venue) && ! empty($venue)) { |
|
| 142 | - $venue = array_shift($venue); |
|
| 143 | - if ($venue instanceof EE_Venue) { |
|
| 144 | - $location = espresso_venue_raw_address('inline', $venue->ID(), false); |
|
| 145 | - } |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - // Generate filename |
|
| 149 | - $filename = $event->slug() . '-' . $datetime->start_date('Y-m-d') . '.ics'; |
|
| 150 | - |
|
| 151 | - // Check the datetime status has not been cancelled and set the ics value accordingly |
|
| 152 | - $status = $datetime->get_active_status(); |
|
| 153 | - $status = $status === EE_Datetime::cancelled ? 'CANCELLED' : 'CONFIRMED'; |
|
| 154 | - |
|
| 155 | - // Create array of ics details, escape strings, convert timestamps to ics format, etc |
|
| 156 | - $ics_data = array( |
|
| 157 | - 'ORGANIZER_NAME' => EE_Registry::instance()->CFG->organization->name, |
|
| 158 | - 'UID' => md5($event->name() . $event->ID() . $datetime->ID()), |
|
| 159 | - 'ORGANIZER' => EE_Registry::instance()->CFG->organization->email, |
|
| 160 | - 'DTSTAMP' => date(EED_Ical::iCal_datetime_format), |
|
| 161 | - 'LOCATION' => $location, |
|
| 162 | - 'SUMMARY' => $event->name(), |
|
| 163 | - 'DESCRIPTION' => wp_strip_all_tags($event->description()), |
|
| 164 | - 'STATUS' => $status, |
|
| 165 | - 'CATEGORIES' => $category, |
|
| 166 | - 'URL;VALUE=URI' => get_permalink($event->ID()), |
|
| 167 | - 'DTSTART' => date(EED_Ical::iCal_datetime_format, $datetime->start()), |
|
| 168 | - 'DTEND' => date(EED_Ical::iCal_datetime_format, $datetime->end()), |
|
| 169 | - ); |
|
| 170 | - |
|
| 171 | - // Filter the values used within the ics output. |
|
| 172 | - // NOTE - all values within ics_data will be escaped automatically. |
|
| 173 | - $ics_data = apply_filters('FHEE__EED_Ical__download_ics_file_ics_data', $ics_data, $datetime); |
|
| 174 | - |
|
| 175 | - // Escape all ics data |
|
| 176 | - foreach ($ics_data as $key => $value) { |
|
| 177 | - // Description is escaped differently from all all values |
|
| 178 | - if ($key === 'DESCRIPTION') { |
|
| 179 | - $ics_data[ $key ] = EED_Ical::_escape_ICal_description(wp_strip_all_tags($value)); |
|
| 180 | - } else { |
|
| 181 | - $ics_data[ $key ] = EED_Ical::_escape_ICal_data($value); |
|
| 182 | - } |
|
| 183 | - } |
|
| 184 | - |
|
| 185 | - // Pull the organizer name from ics_data and remove it from the array. |
|
| 186 | - $organizer_name = isset($ics_data['ORGANIZER_NAME']) ? $ics_data['ORGANIZER_NAME'] : ''; |
|
| 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 | - * @access private |
|
| 225 | - * @param string $string |
|
| 226 | - * @return string |
|
| 227 | - */ |
|
| 228 | - private static function _escape_ICal_data($string = '') |
|
| 229 | - { |
|
| 230 | - return preg_replace('/([\,;])/', '\\\$1', $string); |
|
| 231 | - } |
|
| 232 | - |
|
| 233 | - /** |
|
| 234 | - * _escape_ICal_description |
|
| 235 | - * |
|
| 236 | - * @access private |
|
| 237 | - * @param string $description |
|
| 238 | - * @return string |
|
| 239 | - */ |
|
| 240 | - private static function _escape_ICal_description($description = '') |
|
| 241 | - { |
|
| 242 | - |
|
| 243 | - // Escape special chars within the description |
|
| 244 | - $description = EED_Ical::_escape_ICal_data($description); |
|
| 245 | - |
|
| 246 | - // Remove line breaks and output in iCal format |
|
| 247 | - $description = str_replace(array("\r\n", "\n"), '\n', $description); |
|
| 248 | - |
|
| 249 | - return $description; |
|
| 250 | - } |
|
| 14 | + const iCal_datetime_format = 'Ymd\THis\Z'; |
|
| 15 | + |
|
| 16 | + |
|
| 17 | + /** |
|
| 18 | + * @return EED_Ical|EED_Module |
|
| 19 | + */ |
|
| 20 | + public static function instance() |
|
| 21 | + { |
|
| 22 | + return parent::get_instance(__CLASS__); |
|
| 23 | + } |
|
| 24 | + |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * set_hooks - for hooking into EE Core, other modules, etc |
|
| 28 | + * |
|
| 29 | + * @access public |
|
| 30 | + * @return void |
|
| 31 | + */ |
|
| 32 | + public static function set_hooks() |
|
| 33 | + { |
|
| 34 | + // create download buttons |
|
| 35 | + add_filter( |
|
| 36 | + 'FHEE__espresso_list_of_event_dates__datetime_html', |
|
| 37 | + array('EED_Ical', 'generate_add_to_iCal_button'), |
|
| 38 | + 10, |
|
| 39 | + 2 |
|
| 40 | + ); |
|
| 41 | + // process ics download request |
|
| 42 | + EE_Config::register_route('download_ics_file', 'EED_Ical', 'download_ics_file'); |
|
| 43 | + } |
|
| 44 | + |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
| 48 | + * |
|
| 49 | + * @access public |
|
| 50 | + * @return void |
|
| 51 | + */ |
|
| 52 | + public static function set_hooks_admin() |
|
| 53 | + { |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * run - initial module setup |
|
| 59 | + * |
|
| 60 | + * @access public |
|
| 61 | + * @param WP $WP |
|
| 62 | + * @return void |
|
| 63 | + */ |
|
| 64 | + public function run($WP) |
|
| 65 | + { |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * generate_add_to_iCal_button |
|
| 71 | + * |
|
| 72 | + * @access public |
|
| 73 | + * @param $html |
|
| 74 | + * @param $datetime |
|
| 75 | + * @return string |
|
| 76 | + * @throws \EE_Error |
|
| 77 | + */ |
|
| 78 | + public static function generate_add_to_iCal_button($html, $datetime) |
|
| 79 | + { |
|
| 80 | + // first verify a proper datetime object has been received |
|
| 81 | + if ($datetime instanceof EE_Datetime) { |
|
| 82 | + // set whether a link or submit button is shown |
|
| 83 | + $iCal_type = apply_filters('FHEE__EED_Ical__generate_add_to_iCal_button__iCal_type', 'submit'); |
|
| 84 | + // generate a link to the route we registered in set_hooks() |
|
| 85 | + $URL = add_query_arg(array('ee' => 'download_ics_file', 'ics_id' => $datetime->ID()), site_url()); |
|
| 86 | + // what type ? |
|
| 87 | + switch ($iCal_type) { |
|
| 88 | + // submit buttons appear as buttons and are very compatible with a theme's style |
|
| 89 | + case 'submit': |
|
| 90 | + $html .= '<form id="download-iCal-frm-' . $datetime->ID(); |
|
| 91 | + $html .= '" class="download-iCal-frm" action="' . $URL . '" method="post" >'; |
|
| 92 | + $html .= '<input type="submit" class="ee-ical-sbmt" value="" title="'; |
|
| 93 | + $html .= esc_html__('Add to iCal Calendar', 'event_espresso') . '"/>'; |
|
| 94 | + $html .= '</form>'; |
|
| 95 | + break; |
|
| 96 | + // buttons are just links that have been styled to appear as buttons, |
|
| 97 | + // but may not be blend with a theme as well as submit buttons |
|
| 98 | + case 'button': |
|
| 99 | + $html .= '<a class="ee-ical-btn small ee-button ee-roundish" href="' . $URL; |
|
| 100 | + $html .= '" title="' . esc_html__('Add to iCal Calendar', 'event_espresso') . '">'; |
|
| 101 | + $html .= ' <span class="dashicons dashicons-calendar"></span>'; |
|
| 102 | + $html .= '</a>'; |
|
| 103 | + break; |
|
| 104 | + // links are just links that use the calendar dashicon |
|
| 105 | + case 'icon': |
|
| 106 | + $html .= '<a class="ee-ical-lnk" href="' . $URL . '" title="'; |
|
| 107 | + $html .= esc_html__('Add to iCal Calendar', 'event_espresso') . '">'; |
|
| 108 | + $html .= ' <span class="dashicons dashicons-calendar"></span>'; |
|
| 109 | + $html .= '</a>'; |
|
| 110 | + break; |
|
| 111 | + } |
|
| 112 | + } |
|
| 113 | + return $html; |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + |
|
| 117 | + /** |
|
| 118 | + * download_ics_file |
|
| 119 | + * |
|
| 120 | + * @access public |
|
| 121 | + * @return void |
|
| 122 | + * @throws \EE_Error |
|
| 123 | + */ |
|
| 124 | + public static function download_ics_file() |
|
| 125 | + { |
|
| 126 | + if (EE_Registry::instance()->REQ->is_set('ics_id')) { |
|
| 127 | + $DTT_ID = absint(EE_Registry::instance()->REQ->get('ics_id')); |
|
| 128 | + $datetime = EE_Registry::instance()->load_model('Datetime')->get_one_by_ID($DTT_ID); |
|
| 129 | + if ($datetime instanceof EE_Datetime) { |
|
| 130 | + // get related event, venues, and event categories |
|
| 131 | + $event = $datetime->event(); |
|
| 132 | + if ($event instanceof EE_Event) { |
|
| 133 | + // get related category Term object and it's name |
|
| 134 | + $category = $event->first_event_category(); |
|
| 135 | + if ($category instanceof EE_Term) { |
|
| 136 | + $category = $category->name(); |
|
| 137 | + } |
|
| 138 | + $location = ''; |
|
| 139 | + // get first related venue and convert to CSV string |
|
| 140 | + $venue = $event->venues(array('limit' => 1)); |
|
| 141 | + if (is_array($venue) && ! empty($venue)) { |
|
| 142 | + $venue = array_shift($venue); |
|
| 143 | + if ($venue instanceof EE_Venue) { |
|
| 144 | + $location = espresso_venue_raw_address('inline', $venue->ID(), false); |
|
| 145 | + } |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + // Generate filename |
|
| 149 | + $filename = $event->slug() . '-' . $datetime->start_date('Y-m-d') . '.ics'; |
|
| 150 | + |
|
| 151 | + // Check the datetime status has not been cancelled and set the ics value accordingly |
|
| 152 | + $status = $datetime->get_active_status(); |
|
| 153 | + $status = $status === EE_Datetime::cancelled ? 'CANCELLED' : 'CONFIRMED'; |
|
| 154 | + |
|
| 155 | + // Create array of ics details, escape strings, convert timestamps to ics format, etc |
|
| 156 | + $ics_data = array( |
|
| 157 | + 'ORGANIZER_NAME' => EE_Registry::instance()->CFG->organization->name, |
|
| 158 | + 'UID' => md5($event->name() . $event->ID() . $datetime->ID()), |
|
| 159 | + 'ORGANIZER' => EE_Registry::instance()->CFG->organization->email, |
|
| 160 | + 'DTSTAMP' => date(EED_Ical::iCal_datetime_format), |
|
| 161 | + 'LOCATION' => $location, |
|
| 162 | + 'SUMMARY' => $event->name(), |
|
| 163 | + 'DESCRIPTION' => wp_strip_all_tags($event->description()), |
|
| 164 | + 'STATUS' => $status, |
|
| 165 | + 'CATEGORIES' => $category, |
|
| 166 | + 'URL;VALUE=URI' => get_permalink($event->ID()), |
|
| 167 | + 'DTSTART' => date(EED_Ical::iCal_datetime_format, $datetime->start()), |
|
| 168 | + 'DTEND' => date(EED_Ical::iCal_datetime_format, $datetime->end()), |
|
| 169 | + ); |
|
| 170 | + |
|
| 171 | + // Filter the values used within the ics output. |
|
| 172 | + // NOTE - all values within ics_data will be escaped automatically. |
|
| 173 | + $ics_data = apply_filters('FHEE__EED_Ical__download_ics_file_ics_data', $ics_data, $datetime); |
|
| 174 | + |
|
| 175 | + // Escape all ics data |
|
| 176 | + foreach ($ics_data as $key => $value) { |
|
| 177 | + // Description is escaped differently from all all values |
|
| 178 | + if ($key === 'DESCRIPTION') { |
|
| 179 | + $ics_data[ $key ] = EED_Ical::_escape_ICal_description(wp_strip_all_tags($value)); |
|
| 180 | + } else { |
|
| 181 | + $ics_data[ $key ] = EED_Ical::_escape_ICal_data($value); |
|
| 182 | + } |
|
| 183 | + } |
|
| 184 | + |
|
| 185 | + // Pull the organizer name from ics_data and remove it from the array. |
|
| 186 | + $organizer_name = isset($ics_data['ORGANIZER_NAME']) ? $ics_data['ORGANIZER_NAME'] : ''; |
|
| 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 | + * @access private |
|
| 225 | + * @param string $string |
|
| 226 | + * @return string |
|
| 227 | + */ |
|
| 228 | + private static function _escape_ICal_data($string = '') |
|
| 229 | + { |
|
| 230 | + return preg_replace('/([\,;])/', '\\\$1', $string); |
|
| 231 | + } |
|
| 232 | + |
|
| 233 | + /** |
|
| 234 | + * _escape_ICal_description |
|
| 235 | + * |
|
| 236 | + * @access private |
|
| 237 | + * @param string $description |
|
| 238 | + * @return string |
|
| 239 | + */ |
|
| 240 | + private static function _escape_ICal_description($description = '') |
|
| 241 | + { |
|
| 242 | + |
|
| 243 | + // Escape special chars within the description |
|
| 244 | + $description = EED_Ical::_escape_ICal_data($description); |
|
| 245 | + |
|
| 246 | + // Remove line breaks and output in iCal format |
|
| 247 | + $description = str_replace(array("\r\n", "\n"), '\n', $description); |
|
| 248 | + |
|
| 249 | + return $description; |
|
| 250 | + } |
|
| 251 | 251 | } |
@@ -87,24 +87,24 @@ discard block |
||
| 87 | 87 | switch ($iCal_type) { |
| 88 | 88 | // submit buttons appear as buttons and are very compatible with a theme's style |
| 89 | 89 | case 'submit': |
| 90 | - $html .= '<form id="download-iCal-frm-' . $datetime->ID(); |
|
| 91 | - $html .= '" class="download-iCal-frm" action="' . $URL . '" method="post" >'; |
|
| 90 | + $html .= '<form id="download-iCal-frm-'.$datetime->ID(); |
|
| 91 | + $html .= '" class="download-iCal-frm" action="'.$URL.'" method="post" >'; |
|
| 92 | 92 | $html .= '<input type="submit" class="ee-ical-sbmt" value="" title="'; |
| 93 | - $html .= esc_html__('Add to iCal Calendar', 'event_espresso') . '"/>'; |
|
| 93 | + $html .= esc_html__('Add to iCal Calendar', 'event_espresso').'"/>'; |
|
| 94 | 94 | $html .= '</form>'; |
| 95 | 95 | break; |
| 96 | 96 | // buttons are just links that have been styled to appear as buttons, |
| 97 | 97 | // but may not be blend with a theme as well as submit buttons |
| 98 | 98 | case 'button': |
| 99 | - $html .= '<a class="ee-ical-btn small ee-button ee-roundish" href="' . $URL; |
|
| 100 | - $html .= '" title="' . esc_html__('Add to iCal Calendar', 'event_espresso') . '">'; |
|
| 99 | + $html .= '<a class="ee-ical-btn small ee-button ee-roundish" href="'.$URL; |
|
| 100 | + $html .= '" title="'.esc_html__('Add to iCal Calendar', 'event_espresso').'">'; |
|
| 101 | 101 | $html .= ' <span class="dashicons dashicons-calendar"></span>'; |
| 102 | 102 | $html .= '</a>'; |
| 103 | 103 | break; |
| 104 | 104 | // links are just links that use the calendar dashicon |
| 105 | 105 | case 'icon': |
| 106 | - $html .= '<a class="ee-ical-lnk" href="' . $URL . '" title="'; |
|
| 107 | - $html .= esc_html__('Add to iCal Calendar', 'event_espresso') . '">'; |
|
| 106 | + $html .= '<a class="ee-ical-lnk" href="'.$URL.'" title="'; |
|
| 107 | + $html .= esc_html__('Add to iCal Calendar', 'event_espresso').'">'; |
|
| 108 | 108 | $html .= ' <span class="dashicons dashicons-calendar"></span>'; |
| 109 | 109 | $html .= '</a>'; |
| 110 | 110 | break; |
@@ -146,7 +146,7 @@ discard block |
||
| 146 | 146 | } |
| 147 | 147 | |
| 148 | 148 | // Generate filename |
| 149 | - $filename = $event->slug() . '-' . $datetime->start_date('Y-m-d') . '.ics'; |
|
| 149 | + $filename = $event->slug().'-'.$datetime->start_date('Y-m-d').'.ics'; |
|
| 150 | 150 | |
| 151 | 151 | // Check the datetime status has not been cancelled and set the ics value accordingly |
| 152 | 152 | $status = $datetime->get_active_status(); |
@@ -155,7 +155,7 @@ discard block |
||
| 155 | 155 | // Create array of ics details, escape strings, convert timestamps to ics format, etc |
| 156 | 156 | $ics_data = array( |
| 157 | 157 | 'ORGANIZER_NAME' => EE_Registry::instance()->CFG->organization->name, |
| 158 | - 'UID' => md5($event->name() . $event->ID() . $datetime->ID()), |
|
| 158 | + 'UID' => md5($event->name().$event->ID().$datetime->ID()), |
|
| 159 | 159 | 'ORGANIZER' => EE_Registry::instance()->CFG->organization->email, |
| 160 | 160 | 'DTSTAMP' => date(EED_Ical::iCal_datetime_format), |
| 161 | 161 | 'LOCATION' => $location, |
@@ -176,9 +176,9 @@ discard block |
||
| 176 | 176 | foreach ($ics_data as $key => $value) { |
| 177 | 177 | // Description is escaped differently from all all values |
| 178 | 178 | if ($key === 'DESCRIPTION') { |
| 179 | - $ics_data[ $key ] = EED_Ical::_escape_ICal_description(wp_strip_all_tags($value)); |
|
| 179 | + $ics_data[$key] = EED_Ical::_escape_ICal_description(wp_strip_all_tags($value)); |
|
| 180 | 180 | } else { |
| 181 | - $ics_data[ $key ] = EED_Ical::_escape_ICal_data($value); |
|
| 181 | + $ics_data[$key] = EED_Ical::_escape_ICal_data($value); |
|
| 182 | 182 | } |
| 183 | 183 | } |
| 184 | 184 | |
@@ -188,7 +188,7 @@ discard block |
||
| 188 | 188 | |
| 189 | 189 | // set headers |
| 190 | 190 | header('Content-type: text/calendar; charset=utf-8'); |
| 191 | - header('Content-Disposition: attachment; filename="' . $filename . '"'); |
|
| 191 | + header('Content-Disposition: attachment; filename="'.$filename.'"'); |
|
| 192 | 192 | header('Cache-Control: private, max-age=0, must-revalidate'); |
| 193 | 193 | header('Pragma: public'); |
| 194 | 194 | header('Content-Type: application/octet-stream'); |
@@ -206,7 +206,7 @@ discard block |
||
| 206 | 206 | |
| 207 | 207 | // Output all remaining values from ics_data. |
| 208 | 208 | foreach ($ics_data as $key => $value) { |
| 209 | - echo $key . ':' . $value . "\r\n"; |
|
| 209 | + echo $key.':'.$value."\r\n"; |
|
| 210 | 210 | } |
| 211 | 211 | |
| 212 | 212 | echo "END:VEVENT\r\n"; |
@@ -38,103 +38,103 @@ |
||
| 38 | 38 | * @since 4.0 |
| 39 | 39 | */ |
| 40 | 40 | if (function_exists('espresso_version')) { |
| 41 | - if (! function_exists('espresso_duplicate_plugin_error')) { |
|
| 42 | - /** |
|
| 43 | - * espresso_duplicate_plugin_error |
|
| 44 | - * displays if more than one version of EE is activated at the same time |
|
| 45 | - */ |
|
| 46 | - function espresso_duplicate_plugin_error() |
|
| 47 | - { |
|
| 48 | - ?> |
|
| 41 | + if (! function_exists('espresso_duplicate_plugin_error')) { |
|
| 42 | + /** |
|
| 43 | + * espresso_duplicate_plugin_error |
|
| 44 | + * displays if more than one version of EE is activated at the same time |
|
| 45 | + */ |
|
| 46 | + function espresso_duplicate_plugin_error() |
|
| 47 | + { |
|
| 48 | + ?> |
|
| 49 | 49 | <div class="error"> |
| 50 | 50 | <p> |
| 51 | 51 | <?php |
| 52 | - echo esc_html__( |
|
| 53 | - 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
| 54 | - 'event_espresso' |
|
| 55 | - ); ?> |
|
| 52 | + echo esc_html__( |
|
| 53 | + 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
| 54 | + 'event_espresso' |
|
| 55 | + ); ?> |
|
| 56 | 56 | </p> |
| 57 | 57 | </div> |
| 58 | 58 | <?php |
| 59 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
| 60 | - } |
|
| 61 | - } |
|
| 62 | - add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
| 59 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
| 60 | + } |
|
| 61 | + } |
|
| 62 | + add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
| 63 | 63 | } else { |
| 64 | - define('EE_MIN_PHP_VER_REQUIRED', '5.4.0'); |
|
| 65 | - if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
| 66 | - /** |
|
| 67 | - * espresso_minimum_php_version_error |
|
| 68 | - * |
|
| 69 | - * @return void |
|
| 70 | - */ |
|
| 71 | - function espresso_minimum_php_version_error() |
|
| 72 | - { |
|
| 73 | - ?> |
|
| 64 | + define('EE_MIN_PHP_VER_REQUIRED', '5.4.0'); |
|
| 65 | + if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
| 66 | + /** |
|
| 67 | + * espresso_minimum_php_version_error |
|
| 68 | + * |
|
| 69 | + * @return void |
|
| 70 | + */ |
|
| 71 | + function espresso_minimum_php_version_error() |
|
| 72 | + { |
|
| 73 | + ?> |
|
| 74 | 74 | <div class="error"> |
| 75 | 75 | <p> |
| 76 | 76 | <?php |
| 77 | - printf( |
|
| 78 | - esc_html__( |
|
| 79 | - 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
| 80 | - 'event_espresso' |
|
| 81 | - ), |
|
| 82 | - EE_MIN_PHP_VER_REQUIRED, |
|
| 83 | - PHP_VERSION, |
|
| 84 | - '<br/>', |
|
| 85 | - '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
| 86 | - ); |
|
| 87 | - ?> |
|
| 77 | + printf( |
|
| 78 | + esc_html__( |
|
| 79 | + 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
| 80 | + 'event_espresso' |
|
| 81 | + ), |
|
| 82 | + EE_MIN_PHP_VER_REQUIRED, |
|
| 83 | + PHP_VERSION, |
|
| 84 | + '<br/>', |
|
| 85 | + '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
| 86 | + ); |
|
| 87 | + ?> |
|
| 88 | 88 | </p> |
| 89 | 89 | </div> |
| 90 | 90 | <?php |
| 91 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
| 92 | - } |
|
| 91 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
| 92 | + } |
|
| 93 | 93 | |
| 94 | - add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
| 95 | - } else { |
|
| 96 | - define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
| 97 | - /** |
|
| 98 | - * espresso_version |
|
| 99 | - * Returns the plugin version |
|
| 100 | - * |
|
| 101 | - * @return string |
|
| 102 | - */ |
|
| 103 | - function espresso_version() |
|
| 104 | - { |
|
| 105 | - return apply_filters('FHEE__espresso__espresso_version', '4.10.4.rc.023'); |
|
| 106 | - } |
|
| 94 | + add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
| 95 | + } else { |
|
| 96 | + define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
| 97 | + /** |
|
| 98 | + * espresso_version |
|
| 99 | + * Returns the plugin version |
|
| 100 | + * |
|
| 101 | + * @return string |
|
| 102 | + */ |
|
| 103 | + function espresso_version() |
|
| 104 | + { |
|
| 105 | + return apply_filters('FHEE__espresso__espresso_version', '4.10.4.rc.023'); |
|
| 106 | + } |
|
| 107 | 107 | |
| 108 | - /** |
|
| 109 | - * espresso_plugin_activation |
|
| 110 | - * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
| 111 | - */ |
|
| 112 | - function espresso_plugin_activation() |
|
| 113 | - { |
|
| 114 | - update_option('ee_espresso_activation', true); |
|
| 115 | - } |
|
| 108 | + /** |
|
| 109 | + * espresso_plugin_activation |
|
| 110 | + * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
| 111 | + */ |
|
| 112 | + function espresso_plugin_activation() |
|
| 113 | + { |
|
| 114 | + update_option('ee_espresso_activation', true); |
|
| 115 | + } |
|
| 116 | 116 | |
| 117 | - register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
| 117 | + register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
| 118 | 118 | |
| 119 | - require_once __DIR__ . '/core/bootstrap_espresso.php'; |
|
| 120 | - bootstrap_espresso(); |
|
| 121 | - } |
|
| 119 | + require_once __DIR__ . '/core/bootstrap_espresso.php'; |
|
| 120 | + bootstrap_espresso(); |
|
| 121 | + } |
|
| 122 | 122 | } |
| 123 | 123 | if (! function_exists('espresso_deactivate_plugin')) { |
| 124 | - /** |
|
| 125 | - * deactivate_plugin |
|
| 126 | - * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
| 127 | - * |
|
| 128 | - * @access public |
|
| 129 | - * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
| 130 | - * @return void |
|
| 131 | - */ |
|
| 132 | - function espresso_deactivate_plugin($plugin_basename = '') |
|
| 133 | - { |
|
| 134 | - if (! function_exists('deactivate_plugins')) { |
|
| 135 | - require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
| 136 | - } |
|
| 137 | - unset($_GET['activate'], $_REQUEST['activate']); |
|
| 138 | - deactivate_plugins($plugin_basename); |
|
| 139 | - } |
|
| 124 | + /** |
|
| 125 | + * deactivate_plugin |
|
| 126 | + * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
| 127 | + * |
|
| 128 | + * @access public |
|
| 129 | + * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
| 130 | + * @return void |
|
| 131 | + */ |
|
| 132 | + function espresso_deactivate_plugin($plugin_basename = '') |
|
| 133 | + { |
|
| 134 | + if (! function_exists('deactivate_plugins')) { |
|
| 135 | + require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
| 136 | + } |
|
| 137 | + unset($_GET['activate'], $_REQUEST['activate']); |
|
| 138 | + deactivate_plugins($plugin_basename); |
|
| 139 | + } |
|
| 140 | 140 | } |