@@ -33,11 +33,11 @@ discard block |
||
| 33 | 33 | public static function set_hooks() { |
| 34 | 34 | // create download buttons |
| 35 | 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 | - ); |
|
| 36 | + 'FHEE__espresso_list_of_event_dates__datetime_html', |
|
| 37 | + array( 'EED_Ical', 'generate_add_to_iCal_button' ), |
|
| 38 | + 10, |
|
| 39 | + 2 |
|
| 40 | + ); |
|
| 41 | 41 | // process ics download request |
| 42 | 42 | EE_Config::register_route( 'download_ics_file', 'EED_Ical', 'download_ics_file' ); |
| 43 | 43 | } |
@@ -66,15 +66,15 @@ discard block |
||
| 66 | 66 | |
| 67 | 67 | |
| 68 | 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 | - */ |
|
| 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 | 78 | public static function generate_add_to_iCal_button( $html, $datetime ) { |
| 79 | 79 | // first verify a proper datetime object has been received |
| 80 | 80 | if ( $datetime instanceof EE_Datetime ) { |
@@ -93,7 +93,7 @@ discard block |
||
| 93 | 93 | $html .= '</form>'; |
| 94 | 94 | break; |
| 95 | 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 |
|
| 96 | + // but may not be blend with a theme as well as submit buttons |
|
| 97 | 97 | case 'button' : |
| 98 | 98 | $html .= '<a class="ee-ical-btn small ee-button ee-roundish" href="' . $URL; |
| 99 | 99 | $html .= '" title="' . __( 'Add to iCal Calendar', 'event_espresso' ) . '">'; |
@@ -114,13 +114,13 @@ discard block |
||
| 114 | 114 | |
| 115 | 115 | |
| 116 | 116 | |
| 117 | - /** |
|
| 118 | - * download_ics_file |
|
| 119 | - * |
|
| 120 | - * @access public |
|
| 121 | - * @return void |
|
| 122 | - * @throws \EE_Error |
|
| 123 | - */ |
|
| 117 | + /** |
|
| 118 | + * download_ics_file |
|
| 119 | + * |
|
| 120 | + * @access public |
|
| 121 | + * @return void |
|
| 122 | + * @throws \EE_Error |
|
| 123 | + */ |
|
| 124 | 124 | public static function download_ics_file() { |
| 125 | 125 | if ( EE_Registry::instance()->REQ->is_set( 'ics_id' )) { |
| 126 | 126 | $DTT_ID = absint( EE_Registry::instance()->REQ->get( 'ics_id' )); |
@@ -228,8 +228,8 @@ discard block |
||
| 228 | 228 | //Escape special chars within the description |
| 229 | 229 | $description = EED_Ical::_escape_ICal_data( $description ); |
| 230 | 230 | |
| 231 | - //Remove line breaks and output in iCal format |
|
| 232 | - $description = str_replace( array( "\r\n", "\n"), '\n', $description ); |
|
| 231 | + //Remove line breaks and output in iCal format |
|
| 232 | + $description = str_replace( array( "\r\n", "\n"), '\n', $description ); |
|
| 233 | 233 | |
| 234 | 234 | return $description; |
| 235 | 235 | } |
@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | * @return EED_Ical|EED_Module |
| 20 | 20 | */ |
| 21 | 21 | public static function instance() { |
| 22 | - return parent::get_instance( __CLASS__ ); |
|
| 22 | + return parent::get_instance(__CLASS__); |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | |
@@ -34,12 +34,12 @@ discard block |
||
| 34 | 34 | // create download buttons |
| 35 | 35 | add_filter( |
| 36 | 36 | 'FHEE__espresso_list_of_event_dates__datetime_html', |
| 37 | - array( 'EED_Ical', 'generate_add_to_iCal_button' ), |
|
| 37 | + array('EED_Ical', 'generate_add_to_iCal_button'), |
|
| 38 | 38 | 10, |
| 39 | 39 | 2 |
| 40 | 40 | ); |
| 41 | 41 | // process ics download request |
| 42 | - EE_Config::register_route( 'download_ics_file', 'EED_Ical', 'download_ics_file' ); |
|
| 42 | + EE_Config::register_route('download_ics_file', 'EED_Ical', 'download_ics_file'); |
|
| 43 | 43 | } |
| 44 | 44 | |
| 45 | 45 | |
@@ -62,7 +62,7 @@ discard block |
||
| 62 | 62 | * @param WP $WP |
| 63 | 63 | * @return void |
| 64 | 64 | */ |
| 65 | - public function run( $WP ) {} |
|
| 65 | + public function run($WP) {} |
|
| 66 | 66 | |
| 67 | 67 | |
| 68 | 68 | |
@@ -75,35 +75,35 @@ discard block |
||
| 75 | 75 | * @return string |
| 76 | 76 | * @throws \EE_Error |
| 77 | 77 | */ |
| 78 | - public static function generate_add_to_iCal_button( $html, $datetime ) { |
|
| 78 | + public static function generate_add_to_iCal_button($html, $datetime) { |
|
| 79 | 79 | // first verify a proper datetime object has been received |
| 80 | - if ( $datetime instanceof EE_Datetime ) { |
|
| 80 | + if ($datetime instanceof EE_Datetime) { |
|
| 81 | 81 | // set whether a link or submit button is shown |
| 82 | - $iCal_type = apply_filters( 'FHEE__EED_Ical__generate_add_to_iCal_button__iCal_type', 'submit' ); |
|
| 82 | + $iCal_type = apply_filters('FHEE__EED_Ical__generate_add_to_iCal_button__iCal_type', 'submit'); |
|
| 83 | 83 | // generate a link to the route we registered in set_hooks() |
| 84 | - $URL = add_query_arg( array( 'ee' => 'download_ics_file', 'ics_id' => $datetime->ID() ), site_url() ); |
|
| 84 | + $URL = add_query_arg(array('ee' => 'download_ics_file', 'ics_id' => $datetime->ID()), site_url()); |
|
| 85 | 85 | // what type ? |
| 86 | - switch ( $iCal_type ) { |
|
| 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 .= __( 'Add to iCal Calendar', 'event_espresso' ) . '"/>'; |
|
| 92 | + $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="' . __( 'Add to iCal Calendar', 'event_espresso' ) . '">'; |
|
| 98 | + $html .= '<a class="ee-ical-btn small ee-button ee-roundish" href="'.$URL; |
|
| 99 | + $html .= '" title="'.__('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 .= __( 'Add to iCal Calendar', 'event_espresso' ) . '">'; |
|
| 105 | + $html .= '<a class="ee-ical-lnk" href="'.$URL.'" title="'; |
|
| 106 | + $html .= __('Add to iCal Calendar', 'event_espresso').'">'; |
|
| 107 | 107 | $html .= ' <span class="dashicons dashicons-calendar"></span>'; |
| 108 | 108 | $html .= '</a>'; |
| 109 | 109 | break; |
@@ -122,29 +122,29 @@ discard block |
||
| 122 | 122 | * @throws \EE_Error |
| 123 | 123 | */ |
| 124 | 124 | public static function download_ics_file() { |
| 125 | - if ( EE_Registry::instance()->REQ->is_set( 'ics_id' )) { |
|
| 126 | - $DTT_ID = absint( EE_Registry::instance()->REQ->get( 'ics_id' )); |
|
| 127 | - $datetime = EE_Registry::instance()->load_model( 'Datetime' )->get_one_by_ID( $DTT_ID ); |
|
| 128 | - if ( $datetime instanceof EE_Datetime ) { |
|
| 125 | + if (EE_Registry::instance()->REQ->is_set('ics_id')) { |
|
| 126 | + $DTT_ID = absint(EE_Registry::instance()->REQ->get('ics_id')); |
|
| 127 | + $datetime = EE_Registry::instance()->load_model('Datetime')->get_one_by_ID($DTT_ID); |
|
| 128 | + if ($datetime instanceof EE_Datetime) { |
|
| 129 | 129 | // get related event, venues, and event categories |
| 130 | 130 | $event = $datetime->event(); |
| 131 | 131 | // get related category Term object and it's name |
| 132 | 132 | $category = $event->first_event_category(); |
| 133 | - if ( $category instanceof EE_Term ) { |
|
| 133 | + if ($category instanceof EE_Term) { |
|
| 134 | 134 | $category = $category->name(); |
| 135 | 135 | } |
| 136 | 136 | $location = ''; |
| 137 | 137 | // get first related venue and convert to CSV string |
| 138 | - $venue = $event->venues(array( '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 ); |
|
| 138 | + $venue = $event->venues(array('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 | 143 | } |
| 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(); |
@@ -152,52 +152,52 @@ discard block |
||
| 152 | 152 | |
| 153 | 153 | // Create array of ics details, escape strings, convert timestamps to ics format, etc |
| 154 | 154 | $ics_data = array( |
| 155 | - 'organizer' => EED_Ical::_escape_ICal_data( EE_Registry::instance()->CFG->organization->name ), |
|
| 156 | - 'UID' => EED_Ical::_escape_ICal_data( md5( $event->name() . $event->ID() . $datetime->ID() )), |
|
| 157 | - 'org_email' => EED_Ical::_escape_ICal_data( EE_Registry::instance()->CFG->organization->email ), |
|
| 158 | - 'timestamp' => date( EED_Ical::iCal_datetime_format ), |
|
| 159 | - 'location' => EED_Ical::_escape_ICal_data( $location ), |
|
| 160 | - 'summary' => EED_Ical::_escape_ICal_data( $event->name() ), |
|
| 161 | - 'description' => EED_Ical::_escape_ICal_description( wp_strip_all_tags( $event->description() )), |
|
| 162 | - 'status' => EED_Ical::_escape_ICal_data( $status ), |
|
| 163 | - 'categories' => EED_Ical::_escape_ICal_data( $category ), |
|
| 164 | - 'url' => EED_Ical::_escape_ICal_data( get_permalink( $event->ID() )), |
|
| 165 | - 'dtt_start' => EED_Ical::_escape_ICal_data( date( EED_Ical::iCal_datetime_format, $datetime->start() )), |
|
| 166 | - 'dtt_end' => EED_Ical::_escape_ICal_data( date( EED_Ical::iCal_datetime_format, $datetime->end() )), |
|
| 155 | + 'organizer' => EED_Ical::_escape_ICal_data(EE_Registry::instance()->CFG->organization->name), |
|
| 156 | + 'UID' => EED_Ical::_escape_ICal_data(md5($event->name().$event->ID().$datetime->ID())), |
|
| 157 | + 'org_email' => EED_Ical::_escape_ICal_data(EE_Registry::instance()->CFG->organization->email), |
|
| 158 | + 'timestamp' => date(EED_Ical::iCal_datetime_format), |
|
| 159 | + 'location' => EED_Ical::_escape_ICal_data($location), |
|
| 160 | + 'summary' => EED_Ical::_escape_ICal_data($event->name()), |
|
| 161 | + 'description' => EED_Ical::_escape_ICal_description(wp_strip_all_tags($event->description())), |
|
| 162 | + 'status' => EED_Ical::_escape_ICal_data($status), |
|
| 163 | + 'categories' => EED_Ical::_escape_ICal_data($category), |
|
| 164 | + 'url' => EED_Ical::_escape_ICal_data(get_permalink($event->ID())), |
|
| 165 | + 'dtt_start' => EED_Ical::_escape_ICal_data(date(EED_Ical::iCal_datetime_format, $datetime->start())), |
|
| 166 | + 'dtt_end' => EED_Ical::_escape_ICal_data(date(EED_Ical::iCal_datetime_format, $datetime->end())), |
|
| 167 | 167 | ); |
| 168 | 168 | |
| 169 | - $ics_data = apply_filters( 'FHEE__EED_Ical__download_ics_file_ics_data', $ics_data, $datetime ); |
|
| 169 | + $ics_data = apply_filters('FHEE__EED_Ical__download_ics_file_ics_data', $ics_data, $datetime); |
|
| 170 | 170 | |
| 171 | 171 | // set headers |
| 172 | - header( 'Content-type: text/calendar; charset=utf-8' ); |
|
| 173 | - header( 'Content-Disposition: attachment; filename="' . $filename . '"' ); |
|
| 174 | - header( 'Cache-Control: private, max-age=0, must-revalidate' ); |
|
| 175 | - header( 'Pragma: public' ); |
|
| 176 | - header( 'Content-Type: application/octet-stream' ); |
|
| 177 | - header( 'Content-Type: application/force-download' ); |
|
| 178 | - header( 'Cache-Control: no-cache, must-revalidate' ); |
|
| 179 | - header( 'Content-Transfer-Encoding: binary' ); |
|
| 180 | - header( 'Expires: Sat, 26 Jul 1997 05:00:00 GMT' ); // past date |
|
| 181 | - ini_set( 'zlib.output_compression', '0' ); |
|
| 172 | + header('Content-type: text/calendar; charset=utf-8'); |
|
| 173 | + header('Content-Disposition: attachment; filename="'.$filename.'"'); |
|
| 174 | + header('Cache-Control: private, max-age=0, must-revalidate'); |
|
| 175 | + header('Pragma: public'); |
|
| 176 | + header('Content-Type: application/octet-stream'); |
|
| 177 | + header('Content-Type: application/force-download'); |
|
| 178 | + header('Cache-Control: no-cache, must-revalidate'); |
|
| 179 | + header('Content-Transfer-Encoding: binary'); |
|
| 180 | + header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // past date |
|
| 181 | + ini_set('zlib.output_compression', '0'); |
|
| 182 | 182 | // echo the output |
| 183 | - echo "BEGIN:VCALENDAR" . PHP_EOL; |
|
| 184 | - echo "VERSION:2.0" . PHP_EOL; |
|
| 185 | - echo "PRODID:-//{$ics_data['organizer']}//NONSGML PDA Calendar Version 1.0//EN" . PHP_EOL; |
|
| 186 | - echo "CALSCALE:GREGORIAN" . PHP_EOL; |
|
| 187 | - echo "BEGIN:VEVENT" . PHP_EOL; |
|
| 188 | - echo "UID:{$ics_data['UID']}" . PHP_EOL; |
|
| 189 | - if ( isset( $ics_data['org_email'] ) ) { echo "ORGANIZER:MAILTO:{$ics_data['org_email']}" . PHP_EOL; } |
|
| 190 | - echo "DTSTAMP:{$ics_data['timestamp']}" . PHP_EOL; |
|
| 191 | - echo "LOCATION:{$ics_data['location']}" . PHP_EOL; |
|
| 192 | - echo "SUMMARY:{$ics_data['summary']}" . PHP_EOL; |
|
| 193 | - echo "DESCRIPTION:{$ics_data['description']}" . PHP_EOL; |
|
| 194 | - echo "STATUS:{$ics_data['status']}" . PHP_EOL; |
|
| 195 | - echo "CATEGORIES:{$ics_data['categories']}" . PHP_EOL; |
|
| 196 | - echo "URL;VALUE=URI:{$ics_data['url']}" . PHP_EOL; |
|
| 197 | - echo "DTSTART:{$ics_data['dtt_start']}" . PHP_EOL; |
|
| 198 | - echo "DTEND:{$ics_data['dtt_end']}" . PHP_EOL; |
|
| 199 | - echo "END:VEVENT" . PHP_EOL; |
|
| 200 | - echo "END:VCALENDAR" . PHP_EOL; |
|
| 183 | + echo "BEGIN:VCALENDAR".PHP_EOL; |
|
| 184 | + echo "VERSION:2.0".PHP_EOL; |
|
| 185 | + echo "PRODID:-//{$ics_data['organizer']}//NONSGML PDA Calendar Version 1.0//EN".PHP_EOL; |
|
| 186 | + echo "CALSCALE:GREGORIAN".PHP_EOL; |
|
| 187 | + echo "BEGIN:VEVENT".PHP_EOL; |
|
| 188 | + echo "UID:{$ics_data['UID']}".PHP_EOL; |
|
| 189 | + if (isset($ics_data['org_email'])) { echo "ORGANIZER:MAILTO:{$ics_data['org_email']}".PHP_EOL; } |
|
| 190 | + echo "DTSTAMP:{$ics_data['timestamp']}".PHP_EOL; |
|
| 191 | + echo "LOCATION:{$ics_data['location']}".PHP_EOL; |
|
| 192 | + echo "SUMMARY:{$ics_data['summary']}".PHP_EOL; |
|
| 193 | + echo "DESCRIPTION:{$ics_data['description']}".PHP_EOL; |
|
| 194 | + echo "STATUS:{$ics_data['status']}".PHP_EOL; |
|
| 195 | + echo "CATEGORIES:{$ics_data['categories']}".PHP_EOL; |
|
| 196 | + echo "URL;VALUE=URI:{$ics_data['url']}".PHP_EOL; |
|
| 197 | + echo "DTSTART:{$ics_data['dtt_start']}".PHP_EOL; |
|
| 198 | + echo "DTEND:{$ics_data['dtt_end']}".PHP_EOL; |
|
| 199 | + echo "END:VEVENT".PHP_EOL; |
|
| 200 | + echo "END:VCALENDAR".PHP_EOL; |
|
| 201 | 201 | } |
| 202 | 202 | } |
| 203 | 203 | die(); |
@@ -212,8 +212,8 @@ discard block |
||
| 212 | 212 | * @param string $string |
| 213 | 213 | * @return string |
| 214 | 214 | */ |
| 215 | - private static function _escape_ICal_data( $string = '' ) { |
|
| 216 | - return preg_replace( '/([\,;])/', '\\\$1', $string ); |
|
| 215 | + private static function _escape_ICal_data($string = '') { |
|
| 216 | + return preg_replace('/([\,;])/', '\\\$1', $string); |
|
| 217 | 217 | } |
| 218 | 218 | |
| 219 | 219 | /** |
@@ -223,13 +223,13 @@ discard block |
||
| 223 | 223 | * @param string $description |
| 224 | 224 | * @return string |
| 225 | 225 | */ |
| 226 | - private static function _escape_ICal_description( $description = '' ) { |
|
| 226 | + private static function _escape_ICal_description($description = '') { |
|
| 227 | 227 | |
| 228 | 228 | //Escape special chars within the description |
| 229 | - $description = EED_Ical::_escape_ICal_data( $description ); |
|
| 229 | + $description = EED_Ical::_escape_ICal_data($description); |
|
| 230 | 230 | |
| 231 | 231 | //Remove line breaks and output in iCal format |
| 232 | - $description = str_replace( array( "\r\n", "\n"), '\n', $description ); |
|
| 232 | + $description = str_replace(array("\r\n", "\n"), '\n', $description); |
|
| 233 | 233 | |
| 234 | 234 | return $description; |
| 235 | 235 | } |