Completed
Branch BUG-9042-ics-organizer-email (215e38)
by
unknown
59:28 queued 47:35
created
modules/ical/EED_Ical.module.php 1 patch
Spacing   +66 added lines, -66 removed lines patch added patch discarded remove patch
@@ -19,7 +19,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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="&#xf145;" 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
 block discarded – undo
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
 block discarded – undo
152 152
 
153 153
 				// Create array of ics details, escape strings, convert timestamps to ics format, etc
154 154
 				$ics_data = array(
155
-					'ORGANIZER_NAME' => 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
-					'ORGANIZER' => 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;VALUE=URI' => EED_Ical::_escape_ICal_data( get_permalink( $event->ID() )),
165
-					'DTSTART' => EED_Ical::_escape_ICal_data( date( EED_Ical::iCal_datetime_format, $datetime->start() )),
166
-					'DTEND' => EED_Ical::_escape_ICal_data( date( EED_Ical::iCal_datetime_format, $datetime->end() )),
155
+					'ORGANIZER_NAME' => 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
+					'ORGANIZER' => 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;VALUE=URI' => EED_Ical::_escape_ICal_data(get_permalink($event->ID())),
165
+					'DTSTART' => EED_Ical::_escape_ICal_data(date(EED_Ical::iCal_datetime_format, $datetime->start())),
166
+					'DTEND' => EED_Ical::_escape_ICal_data(date(EED_Ical::iCal_datetime_format, $datetime->end())),
167 167
 				);
168 168
 
169 169
 				//Filter the values used within the ics output.
170
-				$ics_data = apply_filters( 'FHEE__EED_Ical__download_ics_file_ics_data', $ics_data, $datetime );
170
+				$ics_data = apply_filters('FHEE__EED_Ical__download_ics_file_ics_data', $ics_data, $datetime);
171 171
 
172 172
 				//Pull the organizer name from ics_data and remove it from the array.
173
-				$organizer_name = isset( $ics_data['ORGANIZER_NAME'] ) ? $ics_data['ORGANIZER_NAME'] : '';
174
-				unset( $ics_data['ORGANIZER_NAME'] );
173
+				$organizer_name = isset($ics_data['ORGANIZER_NAME']) ? $ics_data['ORGANIZER_NAME'] : '';
174
+				unset($ics_data['ORGANIZER_NAME']);
175 175
 
176 176
 				// set headers
177
-				header( 'Content-type: text/calendar; charset=utf-8' );
178
-				header( 'Content-Disposition: attachment; filename="' . $filename . '"' );
179
-				header( 'Cache-Control: private, max-age=0, must-revalidate' );
180
-				header( 'Pragma: public' );
181
-				header( 'Content-Type: application/octet-stream' );
182
-				header( 'Content-Type: application/force-download' );
183
-				header( 'Cache-Control: no-cache, must-revalidate' );
184
-				header( 'Content-Transfer-Encoding: binary' );
185
-				header( 'Expires: Sat, 26 Jul 1997 05:00:00 GMT' ); // past date
186
-				ini_set( 'zlib.output_compression', '0' );
177
+				header('Content-type: text/calendar; charset=utf-8');
178
+				header('Content-Disposition: attachment; filename="'.$filename.'"');
179
+				header('Cache-Control: private, max-age=0, must-revalidate');
180
+				header('Pragma: public');
181
+				header('Content-Type: application/octet-stream');
182
+				header('Content-Type: application/force-download');
183
+				header('Cache-Control: no-cache, must-revalidate');
184
+				header('Content-Transfer-Encoding: binary');
185
+				header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // past date
186
+				ini_set('zlib.output_compression', '0');
187 187
 				// echo the output
188
-				echo "BEGIN:VCALENDAR" . PHP_EOL;
189
-				echo "VERSION:2.0" . PHP_EOL;
190
-				echo "PRODID:-//{$organizer_name}//NONSGML PDA Calendar Version 1.0//EN" . PHP_EOL;
191
-				echo "CALSCALE:GREGORIAN" . PHP_EOL;
192
-				echo "BEGIN:VEVENT" . PHP_EOL;
188
+				echo "BEGIN:VCALENDAR".PHP_EOL;
189
+				echo "VERSION:2.0".PHP_EOL;
190
+				echo "PRODID:-//{$organizer_name}//NONSGML PDA Calendar Version 1.0//EN".PHP_EOL;
191
+				echo "CALSCALE:GREGORIAN".PHP_EOL;
192
+				echo "BEGIN:VEVENT".PHP_EOL;
193 193
 				
194 194
 				//Output all remaining values from ics_data.
195
-				foreach( $ics_data as $key => $value) {
196
-					echo strtoupper( $key ) . ':' . $value . PHP_EOL;
195
+				foreach ($ics_data as $key => $value) {
196
+					echo strtoupper($key).':'.$value.PHP_EOL;
197 197
 				}
198 198
 
199
-				echo "END:VEVENT" . PHP_EOL;
200
-				echo "END:VCALENDAR" . 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
 block discarded – undo
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
 block discarded – undo
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
 	}
Please login to merge, or discard this patch.