@@ -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(); |
@@ -153,48 +153,48 @@ discard block |
||
| 153 | 153 | // Create array of ics details, escape strings, convert timestamps to ics format, etc |
| 154 | 154 | $ics_data = array( |
| 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 | - 'DTSTAMP' => date( EED_Ical::iCal_datetime_format ), |
|
| 158 | + 'DTSTAMP' => date(EED_Ical::iCal_datetime_format), |
|
| 159 | 159 | 'LOCATION' => $location, |
| 160 | 160 | 'SUMMARY' => $event->name(), |
| 161 | - 'DESCRIPTION' => wp_strip_all_tags( $event->description() ), |
|
| 161 | + 'DESCRIPTION' => wp_strip_all_tags($event->description()), |
|
| 162 | 162 | 'STATUS' => $status, |
| 163 | 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() ), |
|
| 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 | 167 | ); |
| 168 | 168 | |
| 169 | 169 | //Filter the values used within the ics output. |
| 170 | 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 ); |
|
| 171 | + $ics_data = apply_filters('FHEE__EED_Ical__download_ics_file_ics_data', $ics_data, $datetime); |
|
| 172 | 172 | |
| 173 | 173 | //Escape all ics data |
| 174 | - foreach( $ics_data as $key => $value ) { |
|
| 174 | + foreach ($ics_data as $key => $value) { |
|
| 175 | 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 ) ); |
|
| 176 | + if ($key === 'DESCRIPTION') { |
|
| 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 | |
| 183 | 183 | //Pull the organizer name from ics_data and remove it from the array. |
| 184 | - $organizer_name = isset( $ics_data['ORGANIZER_NAME'] ) ? $ics_data['ORGANIZER_NAME'] : ''; |
|
| 185 | - unset( $ics_data['ORGANIZER_NAME'] ); |
|
| 184 | + $organizer_name = isset($ics_data['ORGANIZER_NAME']) ? $ics_data['ORGANIZER_NAME'] : ''; |
|
| 185 | + unset($ics_data['ORGANIZER_NAME']); |
|
| 186 | 186 | |
| 187 | 187 | // set headers |
| 188 | - header( 'Content-type: text/calendar; charset=utf-8' ); |
|
| 189 | - header( 'Content-Disposition: attachment; filename="' . $filename . '"' ); |
|
| 190 | - header( 'Cache-Control: private, max-age=0, must-revalidate' ); |
|
| 191 | - header( 'Pragma: public' ); |
|
| 192 | - header( 'Content-Type: application/octet-stream' ); |
|
| 193 | - header( 'Content-Type: application/force-download' ); |
|
| 194 | - header( 'Cache-Control: no-cache, must-revalidate' ); |
|
| 195 | - header( 'Content-Transfer-Encoding: binary' ); |
|
| 196 | - header( 'Expires: Sat, 26 Jul 1997 05:00:00 GMT' ); // past date |
|
| 197 | - ini_set( 'zlib.output_compression', '0' ); |
|
| 188 | + header('Content-type: text/calendar; charset=utf-8'); |
|
| 189 | + header('Content-Disposition: attachment; filename="'.$filename.'"'); |
|
| 190 | + header('Cache-Control: private, max-age=0, must-revalidate'); |
|
| 191 | + header('Pragma: public'); |
|
| 192 | + header('Content-Type: application/octet-stream'); |
|
| 193 | + header('Content-Type: application/force-download'); |
|
| 194 | + header('Cache-Control: no-cache, must-revalidate'); |
|
| 195 | + header('Content-Transfer-Encoding: binary'); |
|
| 196 | + header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // past date |
|
| 197 | + ini_set('zlib.output_compression', '0'); |
|
| 198 | 198 | // echo the output |
| 199 | 199 | echo "BEGIN:VCALENDAR\r\n"; |
| 200 | 200 | echo "VERSION:2.0\r\n"; |
@@ -203,8 +203,8 @@ discard block |
||
| 203 | 203 | echo "BEGIN:VEVENT\r\n"; |
| 204 | 204 | |
| 205 | 205 | //Output all remaining values from ics_data. |
| 206 | - foreach( $ics_data as $key => $value ) { |
|
| 207 | - echo $key . ':' . $value . "\r\n"; |
|
| 206 | + foreach ($ics_data as $key => $value) { |
|
| 207 | + echo $key.':'.$value."\r\n"; |
|
| 208 | 208 | } |
| 209 | 209 | |
| 210 | 210 | echo "END:VEVENT\r\n"; |
@@ -223,8 +223,8 @@ discard block |
||
| 223 | 223 | * @param string $string |
| 224 | 224 | * @return string |
| 225 | 225 | */ |
| 226 | - private static function _escape_ICal_data( $string = '' ) { |
|
| 227 | - return preg_replace( '/([\,;])/', '\\\$1', $string ); |
|
| 226 | + private static function _escape_ICal_data($string = '') { |
|
| 227 | + return preg_replace('/([\,;])/', '\\\$1', $string); |
|
| 228 | 228 | } |
| 229 | 229 | |
| 230 | 230 | /** |
@@ -234,13 +234,13 @@ discard block |
||
| 234 | 234 | * @param string $description |
| 235 | 235 | * @return string |
| 236 | 236 | */ |
| 237 | - private static function _escape_ICal_description( $description = '' ) { |
|
| 237 | + private static function _escape_ICal_description($description = '') { |
|
| 238 | 238 | |
| 239 | 239 | //Escape special chars within the description |
| 240 | - $description = EED_Ical::_escape_ICal_data( $description ); |
|
| 240 | + $description = EED_Ical::_escape_ICal_data($description); |
|
| 241 | 241 | |
| 242 | 242 | //Remove line breaks and output in iCal format |
| 243 | - $description = str_replace( array( "\r\n", "\n"), '\n', $description ); |
|
| 243 | + $description = str_replace(array("\r\n", "\n"), '\n', $description); |
|
| 244 | 244 | |
| 245 | 245 | return $description; |
| 246 | 246 | } |