@@ -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,43 +152,43 @@ 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 | - 'UID' => EED_Ical::_escape_ICal_data( md5( $event->name() . $event->ID() . $datetime->ID() )), |
|
156 | - 'ORGANIZER' => EED_Ical::_escape_ICal_data( EE_Registry::instance()->CFG->organization->email ), |
|
157 | - 'TIMESTAMP' => date( EED_Ical::iCal_datetime_format ), |
|
158 | - 'LOCATION' => EED_Ical::_escape_ICal_data( $location ), |
|
159 | - 'SUMMARY' => EED_Ical::_escape_ICal_data( $event->name() ), |
|
160 | - 'DESCRIPTION' => EED_Ical::_escape_ICal_description( wp_strip_all_tags( $event->description() )), |
|
161 | - 'STATUS' => EED_Ical::_escape_ICal_data( $status ), |
|
162 | - 'CATEGORIES' => EED_Ical::_escape_ICal_data( $category ), |
|
163 | - 'URL;VALUE=URI' => EED_Ical::_escape_ICal_data( get_permalink( $event->ID() )), |
|
164 | - 'DTSTART' => EED_Ical::_escape_ICal_data( date( EED_Ical::iCal_datetime_format, $datetime->start() )), |
|
165 | - 'DTEND' => EED_Ical::_escape_ICal_data( date( EED_Ical::iCal_datetime_format, $datetime->end() )), |
|
155 | + 'UID' => EED_Ical::_escape_ICal_data(md5($event->name().$event->ID().$datetime->ID())), |
|
156 | + 'ORGANIZER' => EED_Ical::_escape_ICal_data(EE_Registry::instance()->CFG->organization->email), |
|
157 | + 'TIMESTAMP' => date(EED_Ical::iCal_datetime_format), |
|
158 | + 'LOCATION' => EED_Ical::_escape_ICal_data($location), |
|
159 | + 'SUMMARY' => EED_Ical::_escape_ICal_data($event->name()), |
|
160 | + 'DESCRIPTION' => EED_Ical::_escape_ICal_description(wp_strip_all_tags($event->description())), |
|
161 | + 'STATUS' => EED_Ical::_escape_ICal_data($status), |
|
162 | + 'CATEGORIES' => EED_Ical::_escape_ICal_data($category), |
|
163 | + 'URL;VALUE=URI' => EED_Ical::_escape_ICal_data(get_permalink($event->ID())), |
|
164 | + 'DTSTART' => EED_Ical::_escape_ICal_data(date(EED_Ical::iCal_datetime_format, $datetime->start())), |
|
165 | + 'DTEND' => EED_Ical::_escape_ICal_data(date(EED_Ical::iCal_datetime_format, $datetime->end())), |
|
166 | 166 | ); |
167 | 167 | |
168 | - $ics_data = apply_filters( 'FHEE__EED_Ical__download_ics_file_ics_data', $ics_data, $datetime ); |
|
168 | + $ics_data = apply_filters('FHEE__EED_Ical__download_ics_file_ics_data', $ics_data, $datetime); |
|
169 | 169 | |
170 | 170 | // set headers |
171 | - header( 'Content-type: text/calendar; charset=utf-8' ); |
|
172 | - header( 'Content-Disposition: attachment; filename="' . $filename . '"' ); |
|
173 | - header( 'Cache-Control: private, max-age=0, must-revalidate' ); |
|
174 | - header( 'Pragma: public' ); |
|
175 | - header( 'Content-Type: application/octet-stream' ); |
|
176 | - header( 'Content-Type: application/force-download' ); |
|
177 | - header( 'Cache-Control: no-cache, must-revalidate' ); |
|
178 | - header( 'Content-Transfer-Encoding: binary' ); |
|
179 | - header( 'Expires: Sat, 26 Jul 1997 05:00:00 GMT' ); // past date |
|
180 | - ini_set( 'zlib.output_compression', '0' ); |
|
171 | + header('Content-type: text/calendar; charset=utf-8'); |
|
172 | + header('Content-Disposition: attachment; filename="'.$filename.'"'); |
|
173 | + header('Cache-Control: private, max-age=0, must-revalidate'); |
|
174 | + header('Pragma: public'); |
|
175 | + header('Content-Type: application/octet-stream'); |
|
176 | + header('Content-Type: application/force-download'); |
|
177 | + header('Cache-Control: no-cache, must-revalidate'); |
|
178 | + header('Content-Transfer-Encoding: binary'); |
|
179 | + header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // past date |
|
180 | + ini_set('zlib.output_compression', '0'); |
|
181 | 181 | // echo the output |
182 | - echo "BEGIN:VCALENDAR" . PHP_EOL; |
|
183 | - echo "VERSION:2.0" . PHP_EOL; |
|
184 | - echo "PRODID:-//{$organizer_name}//NONSGML PDA Calendar Version 1.0//EN" . PHP_EOL; |
|
185 | - echo "CALSCALE:GREGORIAN" . PHP_EOL; |
|
186 | - echo "BEGIN:VEVENT" . PHP_EOL; |
|
187 | - foreach( $ics_data as $key => $value) { |
|
188 | - echo strtoupper( $key ) . ':' . $value . PHP_EOL; |
|
182 | + echo "BEGIN:VCALENDAR".PHP_EOL; |
|
183 | + echo "VERSION:2.0".PHP_EOL; |
|
184 | + echo "PRODID:-//{$organizer_name}//NONSGML PDA Calendar Version 1.0//EN".PHP_EOL; |
|
185 | + echo "CALSCALE:GREGORIAN".PHP_EOL; |
|
186 | + echo "BEGIN:VEVENT".PHP_EOL; |
|
187 | + foreach ($ics_data as $key => $value) { |
|
188 | + echo strtoupper($key).':'.$value.PHP_EOL; |
|
189 | 189 | } |
190 | - echo "END:VEVENT" . PHP_EOL; |
|
191 | - echo "END:VCALENDAR" . PHP_EOL; |
|
190 | + echo "END:VEVENT".PHP_EOL; |
|
191 | + echo "END:VCALENDAR".PHP_EOL; |
|
192 | 192 | } |
193 | 193 | } |
194 | 194 | die(); |
@@ -203,8 +203,8 @@ discard block |
||
203 | 203 | * @param string $string |
204 | 204 | * @return string |
205 | 205 | */ |
206 | - private static function _escape_ICal_data( $string = '' ) { |
|
207 | - return preg_replace( '/([\,;])/', '\\\$1', $string ); |
|
206 | + private static function _escape_ICal_data($string = '') { |
|
207 | + return preg_replace('/([\,;])/', '\\\$1', $string); |
|
208 | 208 | } |
209 | 209 | |
210 | 210 | /** |
@@ -214,13 +214,13 @@ discard block |
||
214 | 214 | * @param string $description |
215 | 215 | * @return string |
216 | 216 | */ |
217 | - private static function _escape_ICal_description( $description = '' ) { |
|
217 | + private static function _escape_ICal_description($description = '') { |
|
218 | 218 | |
219 | 219 | //Escape special chars within the description |
220 | - $description = EED_Ical::_escape_ICal_data( $description ); |
|
220 | + $description = EED_Ical::_escape_ICal_data($description); |
|
221 | 221 | |
222 | 222 | //Remove line breaks and output in iCal format |
223 | - $description = str_replace( array( "\r\n", "\n"), '\n', $description ); |
|
223 | + $description = str_replace(array("\r\n", "\n"), '\n', $description); |
|
224 | 224 | |
225 | 225 | return $description; |
226 | 226 | } |