Completed
Branch FET-9113-extra-joins-table (84c293)
by
unknown
567:52 queued 554:01
created
core/helpers/EEH_File.helper.php 1 patch
Spacing   +179 added lines, -179 removed lines patch added patch discarded remove patch
@@ -12,8 +12,8 @@  discard block
 block discarded – undo
12 12
  * @ version		 	4.0
13 13
  *
14 14
  */
15
-require_once( EE_HELPERS . 'EEH_Base.helper.php' );
16
-require_once( EE_INTERFACES . 'EEI_Interfaces.php' );
15
+require_once(EE_HELPERS.'EEH_Base.helper.php');
16
+require_once(EE_INTERFACES.'EEI_Interfaces.php');
17 17
 /**
18 18
  *
19 19
  * Class EEH_File
@@ -42,30 +42,30 @@  discard block
 block discarded – undo
42 42
 	 * @throws EE_Error
43 43
 	 * @return WP_Filesystem_Base
44 44
 	 */
45
-	private static function _get_wp_filesystem( $filepath = null) {
46
-		if( apply_filters( 
45
+	private static function _get_wp_filesystem($filepath = null) {
46
+		if (apply_filters( 
47 47
 				'FHEE__EEH_File___get_wp_filesystem__allow_using_filesystem_direct', 
48
-				$filepath && EEH_File::is_in_uploads_folder( $filepath ), 
49
-				$filepath ) ) {
50
-			if( ! EEH_File::$_wp_filesystem_direct instanceof WP_Filesystem_Direct ) {
51
-				require_once(ABSPATH . 'wp-admin/includes/class-wp-filesystem-base.php');
48
+				$filepath && EEH_File::is_in_uploads_folder($filepath), 
49
+				$filepath )) {
50
+			if ( ! EEH_File::$_wp_filesystem_direct instanceof WP_Filesystem_Direct) {
51
+				require_once(ABSPATH.'wp-admin/includes/class-wp-filesystem-base.php');
52 52
 				$method = 'direct';
53
-				$wp_filesystem_direct_file = apply_filters( 'filesystem_method_file', ABSPATH . 'wp-admin/includes/class-wp-filesystem-' . $method . '.php', $method );
53
+				$wp_filesystem_direct_file = apply_filters('filesystem_method_file', ABSPATH.'wp-admin/includes/class-wp-filesystem-'.$method.'.php', $method);
54 54
 				//check constants defined, just like in wp-admin/includes/file.php's WP_Filesystem()
55
-				if ( ! defined('FS_CHMOD_DIR') ) {
56
-					define('FS_CHMOD_DIR', ( fileperms( ABSPATH ) & 0777 | 0755 ) );
55
+				if ( ! defined('FS_CHMOD_DIR')) {
56
+					define('FS_CHMOD_DIR', (fileperms(ABSPATH) & 0777 | 0755));
57 57
 				}
58
-				if ( ! defined('FS_CHMOD_FILE') ) {
59
-					define('FS_CHMOD_FILE', ( fileperms( ABSPATH . 'index.php' ) & 0777 | 0644 ) );
58
+				if ( ! defined('FS_CHMOD_FILE')) {
59
+					define('FS_CHMOD_FILE', (fileperms(ABSPATH.'index.php') & 0777 | 0644));
60 60
 				}
61
-				require_once( $wp_filesystem_direct_file );
62
-				EEH_File::$_wp_filesystem_direct = new WP_Filesystem_Direct( array() );
61
+				require_once($wp_filesystem_direct_file);
62
+				EEH_File::$_wp_filesystem_direct = new WP_Filesystem_Direct(array());
63 63
 			}
64 64
 			return EEH_File::$_wp_filesystem_direct;
65 65
 		}
66 66
 		global $wp_filesystem;
67 67
 		// no filesystem setup ???
68
-		if ( ! $wp_filesystem instanceof WP_Filesystem_Base ) {
68
+		if ( ! $wp_filesystem instanceof WP_Filesystem_Base) {
69 69
 			// if some eager beaver's just trying to get in there too early...
70 70
 			// let them do it, because we are one of those eager beavers! :P
71 71
 			/**
@@ -78,34 +78,34 @@  discard block
 block discarded – undo
78 78
 			 * and there may be troubles if the WP files are owned by a different user
79 79
 			 * than the server user. But both of these issues should exist in 4.4 and earlier too
80 80
 			 */
81
-			if ( FALSE && ! did_action( 'wp_loaded' )) {
81
+			if (FALSE && ! did_action('wp_loaded')) {
82 82
 				$msg = __('An attempt to access and/or write to a file on the server could not be completed due to a lack of sufficient credentials.', 'event_espresso');
83
-				if ( WP_DEBUG ) {
84
-					$msg .= '<br />' .  __('The WP Filesystem can not be accessed until after the "wp_loaded" hook has run, so it\'s best not to attempt access until the "admin_init" hookpoint.', 'event_espresso');
83
+				if (WP_DEBUG) {
84
+					$msg .= '<br />'.__('The WP Filesystem can not be accessed until after the "wp_loaded" hook has run, so it\'s best not to attempt access until the "admin_init" hookpoint.', 'event_espresso');
85 85
 				}
86
-				throw new EE_Error( $msg );
86
+				throw new EE_Error($msg);
87 87
 			} else {
88 88
 				// should be loaded if we are past the wp_loaded hook...
89
-				if ( ! function_exists( 'WP_Filesystem' )) {
90
-					require_once( ABSPATH . 'wp-admin/includes/file.php' );
91
-					require_once( ABSPATH . 'wp-admin/includes/template.php' );
89
+				if ( ! function_exists('WP_Filesystem')) {
90
+					require_once(ABSPATH.'wp-admin/includes/file.php');
91
+					require_once(ABSPATH.'wp-admin/includes/template.php');
92 92
 				}
93 93
 				// turn on output buffering so that we can capture the credentials form
94 94
 				ob_start();
95
-				$credentials = request_filesystem_credentials( '' );
95
+				$credentials = request_filesystem_credentials('');
96 96
 				// store credentials form for the time being
97 97
 				EEH_File::$_credentials_form = ob_get_clean();
98 98
 				// basically check for direct or previously configured access
99
-				if ( ! WP_Filesystem( $credentials ) ) {
99
+				if ( ! WP_Filesystem($credentials)) {
100 100
 					// if credentials do NOT exist
101
-					if ( $credentials === FALSE ) {
102
-						add_action( 'admin_notices', array( 'EEH_File', 'display_request_filesystem_credentials_form' ), 999 );
103
-						throw new EE_Error( __('An attempt to access and/or write to a file on the server could not be completed due to a lack of sufficient credentials.', 'event_espresso'));
104
-					} elseif( is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->get_error_code() ) {
105
-						add_action( 'admin_notices', array( 'EEH_File', 'display_request_filesystem_credentials_form' ), 999 );
101
+					if ($credentials === FALSE) {
102
+						add_action('admin_notices', array('EEH_File', 'display_request_filesystem_credentials_form'), 999);
103
+						throw new EE_Error(__('An attempt to access and/or write to a file on the server could not be completed due to a lack of sufficient credentials.', 'event_espresso'));
104
+					} elseif (is_wp_error($wp_filesystem->errors) && $wp_filesystem->errors->get_error_code()) {
105
+						add_action('admin_notices', array('EEH_File', 'display_request_filesystem_credentials_form'), 999);
106 106
 						throw new EE_Error(
107 107
 								sprintf(
108
-										__( 'WP Filesystem Error: $1%s', 'event_espresso' ),
108
+										__('WP Filesystem Error: $1%s', 'event_espresso'),
109 109
 										$wp_filesystem->errors->get_error_message() ) );
110 110
 					}
111 111
 				}
@@ -118,8 +118,8 @@  discard block
 block discarded – undo
118 118
 	 * display_request_filesystem_credentials_form
119 119
 	 */
120 120
 	public static function display_request_filesystem_credentials_form() {
121
-		if ( ! empty( EEH_File::$_credentials_form )) {
122
-			echo '<div class="updated espresso-notices-attention"><p>' . EEH_File::$_credentials_form . '</p></div>';
121
+		if ( ! empty(EEH_File::$_credentials_form)) {
122
+			echo '<div class="updated espresso-notices-attention"><p>'.EEH_File::$_credentials_form.'</p></div>';
123 123
 		}
124 124
 	}
125 125
 
@@ -137,29 +137,29 @@  discard block
 block discarded – undo
137 137
 	 * @throws EE_Error
138 138
 	 * @return bool
139 139
 	 */
140
-	public static function verify_filepath_and_permissions( $full_file_path = '', $file_name = '', $file_ext = '', $type_of_file = '' ) {
140
+	public static function verify_filepath_and_permissions($full_file_path = '', $file_name = '', $file_ext = '', $type_of_file = '') {
141 141
 		// load WP_Filesystem and set file permissions
142
-		$wp_filesystem = EEH_File::_get_wp_filesystem( $full_file_path );
143
-		$full_file_path = EEH_File::standardise_directory_separators( $full_file_path );
144
-		if ( ! $wp_filesystem->is_readable( EEH_File::convert_local_filepath_to_remote_filepath( $full_file_path ) )) {
145
-			$file_name = ! empty( $type_of_file ) ? $file_name . ' ' . $type_of_file : $file_name;
146
-			$file_name .= ! empty( $file_ext ) ? ' file' : ' folder';
142
+		$wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path);
143
+		$full_file_path = EEH_File::standardise_directory_separators($full_file_path);
144
+		if ( ! $wp_filesystem->is_readable(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path))) {
145
+			$file_name = ! empty($type_of_file) ? $file_name.' '.$type_of_file : $file_name;
146
+			$file_name .= ! empty($file_ext) ? ' file' : ' folder';
147 147
 			$msg = sprintf(
148
-				__( 'The requested %1$s could not be found or is not readable, possibly due to an incorrect filepath, or incorrect file permissions.%2$s', 'event_espresso' ),
148
+				__('The requested %1$s could not be found or is not readable, possibly due to an incorrect filepath, or incorrect file permissions.%2$s', 'event_espresso'),
149 149
 				$file_name,
150 150
 				'<br />'
151 151
 			);
152
-			if ( EEH_File::exists( $full_file_path )) {
153
-				$msg .= EEH_File::_permissions_error_for_unreadable_filepath( $full_file_path, $type_of_file );
152
+			if (EEH_File::exists($full_file_path)) {
153
+				$msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_file_path, $type_of_file);
154 154
 			} else {
155 155
 				// no file permissions means the file was not found
156 156
 				$msg .= sprintf(
157
-					__( 'Please ensure the following path is correct: "%s".', 'event_espresso' ),
157
+					__('Please ensure the following path is correct: "%s".', 'event_espresso'),
158 158
 					$full_file_path
159 159
 				);
160 160
 			}
161
-			if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
162
-				throw new EE_Error( $msg . '||' . $msg );
161
+			if (defined('WP_DEBUG') && WP_DEBUG) {
162
+				throw new EE_Error($msg.'||'.$msg);
163 163
 			}
164 164
 			return FALSE;
165 165
 		}
@@ -176,24 +176,24 @@  discard block
 block discarded – undo
176 176
 	 * @param string $type_of_file - general type of file (ie: "module"), this is only used to improve error messages
177 177
 	 * @return string
178 178
 	 */
179
-	private static function _permissions_error_for_unreadable_filepath( $full_file_path = '', $type_of_file = '' ){
179
+	private static function _permissions_error_for_unreadable_filepath($full_file_path = '', $type_of_file = '') {
180 180
 		// load WP_Filesystem and set file permissions
181
-		$wp_filesystem = EEH_File::_get_wp_filesystem( $full_file_path );
181
+		$wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path);
182 182
 		// check file permissions
183
-		$perms = $wp_filesystem->getchmod( EEH_File::convert_local_filepath_to_remote_filepath( $full_file_path ) );
184
-		if ( $perms ) {
183
+		$perms = $wp_filesystem->getchmod(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path));
184
+		if ($perms) {
185 185
 			// file permissions exist, but way be set incorrectly
186
-			$type_of_file = ! empty( $type_of_file ) ? $type_of_file . ' ' : '';
187
-			$type_of_file .= ! empty( $type_of_file ) ? 'file' : 'folder';
186
+			$type_of_file = ! empty($type_of_file) ? $type_of_file.' ' : '';
187
+			$type_of_file .= ! empty($type_of_file) ? 'file' : 'folder';
188 188
 			return sprintf(
189
-				__( 'File permissions for the requested %1$s are currently set at "%2$s". The recommended permissions are 644 for files and 755 for folders.', 'event_espresso' ),
189
+				__('File permissions for the requested %1$s are currently set at "%2$s". The recommended permissions are 644 for files and 755 for folders.', 'event_espresso'),
190 190
 				$type_of_file,
191 191
 				$perms
192 192
 			);
193 193
 		} else {
194 194
 			// file exists but file permissions could not be read ?!?!
195 195
 			return sprintf(
196
-				__( 'Please ensure that the server and/or PHP configuration allows the current process to access the following file: "%s".', 'event_espresso' ),
196
+				__('Please ensure that the server and/or PHP configuration allows the current process to access the following file: "%s".', 'event_espresso'),
197 197
 				$full_file_path
198 198
 			);
199 199
 		}
@@ -211,35 +211,35 @@  discard block
 block discarded – undo
211 211
 	 * can't write to it
212 212
 	 * @return bool false if folder isn't writable; true if it exists and is writeable,
213 213
 	 */
214
-	public static function ensure_folder_exists_and_is_writable( $folder = '' ){
215
-		if ( empty( $folder )) {
214
+	public static function ensure_folder_exists_and_is_writable($folder = '') {
215
+		if (empty($folder)) {
216 216
 			return false;
217 217
 		}
218 218
 		// remove ending DS
219
-		$folder = EEH_File::standardise_directory_separators( rtrim( $folder, '/\\' ));
220
-		$parent_folder = EEH_File::get_parent_folder( $folder );
219
+		$folder = EEH_File::standardise_directory_separators(rtrim($folder, '/\\'));
220
+		$parent_folder = EEH_File::get_parent_folder($folder);
221 221
 		// add DS to folder
222
-		$folder = EEH_File::end_with_directory_separator( $folder );
223
-		$wp_filesystem = EEH_File::_get_wp_filesystem( $folder );
224
-		if ( ! $wp_filesystem->is_dir( EEH_File::convert_local_filepath_to_remote_filepath( $folder ) ) ) {
222
+		$folder = EEH_File::end_with_directory_separator($folder);
223
+		$wp_filesystem = EEH_File::_get_wp_filesystem($folder);
224
+		if ( ! $wp_filesystem->is_dir(EEH_File::convert_local_filepath_to_remote_filepath($folder))) {
225 225
 			//ok so it doesn't exist. Does its parent? Can we write to it?
226
-			if(	! EEH_File::ensure_folder_exists_and_is_writable( $parent_folder ) ) {
226
+			if ( ! EEH_File::ensure_folder_exists_and_is_writable($parent_folder)) {
227 227
 				return false;
228 228
 			}
229
-			if ( ! EEH_File::verify_is_writable( $parent_folder, 'folder' )) {
229
+			if ( ! EEH_File::verify_is_writable($parent_folder, 'folder')) {
230 230
 				return false;
231 231
 			} else {
232
-				if ( ! $wp_filesystem->mkdir( EEH_File::convert_local_filepath_to_remote_filepath(  $folder ) ) ) {
233
-					if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
234
-						$msg = sprintf( __( '"%s" could not be created.', 'event_espresso' ), $folder );
235
-						$msg .= EEH_File::_permissions_error_for_unreadable_filepath( $folder );
236
-						throw new EE_Error( $msg );
232
+				if ( ! $wp_filesystem->mkdir(EEH_File::convert_local_filepath_to_remote_filepath($folder))) {
233
+					if (defined('WP_DEBUG') && WP_DEBUG) {
234
+						$msg = sprintf(__('"%s" could not be created.', 'event_espresso'), $folder);
235
+						$msg .= EEH_File::_permissions_error_for_unreadable_filepath($folder);
236
+						throw new EE_Error($msg);
237 237
 					}
238 238
 					return false;
239 239
 				}
240
-				EEH_File::add_index_file( $folder );
240
+				EEH_File::add_index_file($folder);
241 241
 			}
242
-		} elseif ( ! EEH_File::verify_is_writable( $folder, 'folder' )) {
242
+		} elseif ( ! EEH_File::verify_is_writable($folder, 'folder')) {
243 243
 			return false;
244 244
 		}
245 245
 		return true;
@@ -254,15 +254,15 @@  discard block
 block discarded – undo
254 254
 	 * @throws EE_Error
255 255
 	 * @return bool
256 256
 	 */
257
-	public static function verify_is_writable( $full_path = '', $file_or_folder = 'folder' ){
257
+	public static function verify_is_writable($full_path = '', $file_or_folder = 'folder') {
258 258
 		// load WP_Filesystem and set file permissions
259
-		$wp_filesystem = EEH_File::_get_wp_filesystem( $full_path );
260
-		$full_path = EEH_File::standardise_directory_separators( $full_path );
261
-		if ( ! $wp_filesystem->is_writable( EEH_File::convert_local_filepath_to_remote_filepath( $full_path ) ) ) {
262
-			if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
263
-				$msg = sprintf( __( 'The "%1$s" %2$s is not writable.', 'event_espresso' ), $full_path, $file_or_folder );
264
-				$msg .= EEH_File::_permissions_error_for_unreadable_filepath( $full_path );
265
-				throw new EE_Error( $msg );
259
+		$wp_filesystem = EEH_File::_get_wp_filesystem($full_path);
260
+		$full_path = EEH_File::standardise_directory_separators($full_path);
261
+		if ( ! $wp_filesystem->is_writable(EEH_File::convert_local_filepath_to_remote_filepath($full_path))) {
262
+			if (defined('WP_DEBUG') && WP_DEBUG) {
263
+				$msg = sprintf(__('The "%1$s" %2$s is not writable.', 'event_espresso'), $full_path, $file_or_folder);
264
+				$msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_path);
265
+				throw new EE_Error($msg);
266 266
 			}
267 267
 			return FALSE;
268 268
 		}
@@ -279,25 +279,25 @@  discard block
 block discarded – undo
279 279
 	 * @throws EE_Error
280 280
 	 * @return bool
281 281
 	 */
282
-	public static function ensure_file_exists_and_is_writable( $full_file_path = '' ) {
282
+	public static function ensure_file_exists_and_is_writable($full_file_path = '') {
283 283
 		// load WP_Filesystem and set file permissions
284
-		$wp_filesystem = EEH_File::_get_wp_filesystem( $full_file_path );
285
-		$full_file_path = EEH_File::standardise_directory_separators( $full_file_path );
286
-		$parent_folder = EEH_File::get_parent_folder( $full_file_path );
287
-		if ( ! EEH_File::exists( $full_file_path )) {
288
-			if( ! EEH_File::ensure_folder_exists_and_is_writable( $parent_folder ) ) {
284
+		$wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path);
285
+		$full_file_path = EEH_File::standardise_directory_separators($full_file_path);
286
+		$parent_folder = EEH_File::get_parent_folder($full_file_path);
287
+		if ( ! EEH_File::exists($full_file_path)) {
288
+			if ( ! EEH_File::ensure_folder_exists_and_is_writable($parent_folder)) {
289 289
 				return false;
290 290
 			}
291
-			if ( ! $wp_filesystem->touch( EEH_File::convert_local_filepath_to_remote_filepath( $full_file_path ) ) ) {
292
-				if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
293
-					$msg = sprintf( __( 'The "%s" file could not be created.', 'event_espresso' ), $full_file_path );
294
-					$msg .= EEH_File::_permissions_error_for_unreadable_filepath( $full_file_path );
295
-					throw new EE_Error( $msg );
291
+			if ( ! $wp_filesystem->touch(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path))) {
292
+				if (defined('WP_DEBUG') && WP_DEBUG) {
293
+					$msg = sprintf(__('The "%s" file could not be created.', 'event_espresso'), $full_file_path);
294
+					$msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_file_path);
295
+					throw new EE_Error($msg);
296 296
 				}
297 297
 				return false;
298 298
 			}
299 299
 		}
300
-		if ( ! EEH_File::verify_is_writable( $full_file_path, 'file' )) {
300
+		if ( ! EEH_File::verify_is_writable($full_file_path, 'file')) {
301 301
 			return false;
302 302
 		}
303 303
 		return true;
@@ -309,15 +309,15 @@  discard block
 block discarded – undo
309 309
 	 * @param string $file_or_folder_path
310 310
 	 * @return string parent folder, ENDING with a directory separator
311 311
 	 */
312
-	public static function get_parent_folder( $file_or_folder_path ) {
312
+	public static function get_parent_folder($file_or_folder_path) {
313 313
 		//find the last DS, ignoring a DS on the very end
314 314
 		//eg if given "/var/something/somewhere/", we want to get "somewhere"'s
315 315
 		//parent folder, "/var/something/"
316
-		$ds = strrpos( $file_or_folder_path, DS, -2 );
317
-		return substr( $file_or_folder_path, 0, $ds + 1 );
316
+		$ds = strrpos($file_or_folder_path, DS, -2);
317
+		return substr($file_or_folder_path, 0, $ds + 1);
318 318
 	}
319 319
 	
320
-	public static function ensure_folder_exists_recursively( $folder ) {
320
+	public static function ensure_folder_exists_recursively($folder) {
321 321
 		
322 322
 	}
323 323
 
@@ -328,12 +328,12 @@  discard block
 block discarded – undo
328 328
 	 * @param string $full_file_path
329 329
 	 * @return string
330 330
 	 */
331
-	public static function get_file_contents( $full_file_path = '' ){
332
-		$full_file_path = EEH_File::standardise_directory_separators( $full_file_path );
333
-		if ( EEH_File::verify_filepath_and_permissions( $full_file_path, EEH_File::get_filename_from_filepath( $full_file_path ) , EEH_File::get_file_extension( $full_file_path ))) {
331
+	public static function get_file_contents($full_file_path = '') {
332
+		$full_file_path = EEH_File::standardise_directory_separators($full_file_path);
333
+		if (EEH_File::verify_filepath_and_permissions($full_file_path, EEH_File::get_filename_from_filepath($full_file_path), EEH_File::get_file_extension($full_file_path))) {
334 334
 			// load WP_Filesystem and set file permissions
335
-			$wp_filesystem = EEH_File::_get_wp_filesystem( $full_file_path );
336
-			return $wp_filesystem->get_contents(EEH_File::convert_local_filepath_to_remote_filepath( $full_file_path ) );
335
+			$wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path);
336
+			return $wp_filesystem->get_contents(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path));
337 337
 		}
338 338
 		return '';
339 339
 	}
@@ -348,26 +348,26 @@  discard block
 block discarded – undo
348 348
 	 * @throws EE_Error
349 349
 	 * @return bool
350 350
 	 */
351
-	public static function write_to_file( $full_file_path = '', $file_contents = '', $file_type = '' ){
352
-		$full_file_path = EEH_File::standardise_directory_separators( $full_file_path );
353
-		$file_type = ! empty( $file_type ) ? rtrim( $file_type, ' ' ) . ' ' : '';
354
-		$folder = EEH_File::remove_filename_from_filepath( $full_file_path );
355
-		if ( ! EEH_File::verify_is_writable( $folder, 'folder' )) {
356
-			if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
357
-				$msg = sprintf( __( 'The %1$sfile located at "%2$s" is not writable.', 'event_espresso' ), $file_type, $full_file_path );
358
-				$msg .= EEH_File::_permissions_error_for_unreadable_filepath( $full_file_path );
359
-				throw new EE_Error( $msg );
351
+	public static function write_to_file($full_file_path = '', $file_contents = '', $file_type = '') {
352
+		$full_file_path = EEH_File::standardise_directory_separators($full_file_path);
353
+		$file_type = ! empty($file_type) ? rtrim($file_type, ' ').' ' : '';
354
+		$folder = EEH_File::remove_filename_from_filepath($full_file_path);
355
+		if ( ! EEH_File::verify_is_writable($folder, 'folder')) {
356
+			if (defined('WP_DEBUG') && WP_DEBUG) {
357
+				$msg = sprintf(__('The %1$sfile located at "%2$s" is not writable.', 'event_espresso'), $file_type, $full_file_path);
358
+				$msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_file_path);
359
+				throw new EE_Error($msg);
360 360
 			}
361 361
 			return FALSE;
362 362
 		}
363 363
 		// load WP_Filesystem and set file permissions
364
-		$wp_filesystem = EEH_File::_get_wp_filesystem( $full_file_path );
364
+		$wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path);
365 365
 		// write the file
366
-		if ( ! $wp_filesystem->put_contents(EEH_File::convert_local_filepath_to_remote_filepath( $full_file_path ), $file_contents )) {
367
-			if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
368
-				$msg = sprintf( __( 'The %1$sfile located at "%2$s" could not be written to.', 'event_espresso' ), $file_type, $full_file_path );
369
-				$msg .= EEH_File::_permissions_error_for_unreadable_filepath( $full_file_path, 'f' );
370
-				throw new EE_Error( $msg );
366
+		if ( ! $wp_filesystem->put_contents(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path), $file_contents)) {
367
+			if (defined('WP_DEBUG') && WP_DEBUG) {
368
+				$msg = sprintf(__('The %1$sfile located at "%2$s" could not be written to.', 'event_espresso'), $file_type, $full_file_path);
369
+				$msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_file_path, 'f');
370
+				throw new EE_Error($msg);
371 371
 			}
372 372
 			return FALSE;
373 373
 		}
@@ -382,9 +382,9 @@  discard block
 block discarded – undo
382 382
 	 * @param boolean|string $type 'd' for directory, 'f' for file
383 383
 	 * @return boolean
384 384
 	 */
385
-	public static function delete( $filepath, $recursive = false, $type = false ) {
385
+	public static function delete($filepath, $recursive = false, $type = false) {
386 386
 		$wp_filesystem = EEH_File::_get_wp_filesystem();
387
-		return $wp_filesystem->delete( $filepath, $recursive, $type ) ? TRUE : FALSE;
387
+		return $wp_filesystem->delete($filepath, $recursive, $type) ? TRUE : FALSE;
388 388
 	}
389 389
 
390 390
 
@@ -396,9 +396,9 @@  discard block
 block discarded – undo
396 396
 	 * @param string $full_file_path
397 397
 	 * @return bool
398 398
 	 */
399
-	public static function exists( $full_file_path = '' ) {
400
-		$wp_filesystem = EEH_File::_get_wp_filesystem( $full_file_path );
401
-		return $wp_filesystem->exists( EEH_File::convert_local_filepath_to_remote_filepath( $full_file_path ) ) ? TRUE : FALSE;
399
+	public static function exists($full_file_path = '') {
400
+		$wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path);
401
+		return $wp_filesystem->exists(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path)) ? TRUE : FALSE;
402 402
 	}
403 403
 
404 404
 
@@ -410,9 +410,9 @@  discard block
 block discarded – undo
410 410
 	 * @param string $full_file_path
411 411
 	 * @return bool
412 412
 	 */
413
-	public static function is_readable( $full_file_path = '' ) {
414
-		$wp_filesystem = EEH_File::_get_wp_filesystem( $full_file_path );
415
-		if( $wp_filesystem->is_readable( EEH_File::convert_local_filepath_to_remote_filepath(  $full_file_path ) ) ) {
413
+	public static function is_readable($full_file_path = '') {
414
+		$wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path);
415
+		if ($wp_filesystem->is_readable(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path))) {
416 416
 			return true;
417 417
 		} else {
418 418
 			return false;
@@ -428,8 +428,8 @@  discard block
 block discarded – undo
428 428
 	 * @param string $full_file_path
429 429
 	 * @return string
430 430
 	 */
431
-	public static function remove_filename_from_filepath( $full_file_path = '' ) {
432
-		return pathinfo( $full_file_path, PATHINFO_DIRNAME );
431
+	public static function remove_filename_from_filepath($full_file_path = '') {
432
+		return pathinfo($full_file_path, PATHINFO_DIRNAME);
433 433
 	}
434 434
 
435 435
 
@@ -439,8 +439,8 @@  discard block
 block discarded – undo
439 439
 	 * @param string $full_file_path
440 440
 	 * @return string
441 441
 	 */
442
-	public static function get_filename_from_filepath( $full_file_path = '' ) {
443
-		return pathinfo( $full_file_path, PATHINFO_BASENAME );
442
+	public static function get_filename_from_filepath($full_file_path = '') {
443
+		return pathinfo($full_file_path, PATHINFO_BASENAME);
444 444
 	}
445 445
 
446 446
 
@@ -450,8 +450,8 @@  discard block
 block discarded – undo
450 450
 	 * @param string $full_file_path
451 451
 	 * @return string
452 452
 	 */
453
-	public static function get_file_extension( $full_file_path = '' ) {
454
-		return pathinfo( $full_file_path, PATHINFO_EXTENSION );
453
+	public static function get_file_extension($full_file_path = '') {
454
+		return pathinfo($full_file_path, PATHINFO_EXTENSION);
455 455
 	}
456 456
 
457 457
 
@@ -461,10 +461,10 @@  discard block
 block discarded – undo
461 461
 	 * @param string $folder
462 462
 	 * @return bool
463 463
 	 */
464
-	public static function add_htaccess_deny_from_all( $folder = '' ) {
465
-		$folder = EEH_File::standardise_and_end_with_directory_separator( $folder );
466
-		if ( ! EEH_File::exists( $folder . '.htaccess' ) ) {
467
-			if ( ! EEH_File::write_to_file( $folder . '.htaccess', 'deny from all', '.htaccess' )) {
464
+	public static function add_htaccess_deny_from_all($folder = '') {
465
+		$folder = EEH_File::standardise_and_end_with_directory_separator($folder);
466
+		if ( ! EEH_File::exists($folder.'.htaccess')) {
467
+			if ( ! EEH_File::write_to_file($folder.'.htaccess', 'deny from all', '.htaccess')) {
468 468
 				return FALSE;
469 469
 			}
470 470
 		}
@@ -477,10 +477,10 @@  discard block
 block discarded – undo
477 477
 	 * @param string $folder
478 478
 	 * @return boolean
479 479
 	 */
480
-	public static function add_index_file( $folder ) {
481
-		$folder = EEH_File::standardise_and_end_with_directory_separator( $folder );
482
-		if ( ! EEH_File::exists( $folder . 'index.php' ) ) {
483
-			if ( ! EEH_File::write_to_file( $folder . 'index.php', 'You are not permitted to read from this folder', '.php' )) {
480
+	public static function add_index_file($folder) {
481
+		$folder = EEH_File::standardise_and_end_with_directory_separator($folder);
482
+		if ( ! EEH_File::exists($folder.'index.php')) {
483
+			if ( ! EEH_File::write_to_file($folder.'index.php', 'You are not permitted to read from this folder', '.php')) {
484 484
 				return false;
485 485
 			}
486 486
 		}
@@ -495,11 +495,11 @@  discard block
 block discarded – undo
495 495
 	 * @param string $file_path
496 496
 	 * @return string
497 497
 	 */
498
-	public static function get_classname_from_filepath_with_standard_filename( $file_path ){
498
+	public static function get_classname_from_filepath_with_standard_filename($file_path) {
499 499
 		//extract file from path
500
-		$filename = basename( $file_path );
500
+		$filename = basename($file_path);
501 501
 		//now remove the first period and everything after
502
-		$pos_of_first_period = strpos( $filename,'.' );
502
+		$pos_of_first_period = strpos($filename, '.');
503 503
 		return substr($filename, 0, $pos_of_first_period);
504 504
 	}
505 505
 
@@ -511,8 +511,8 @@  discard block
 block discarded – undo
511 511
 	 * @param string $file_path
512 512
 	 * @return string
513 513
 	 */
514
-	public static function standardise_directory_separators( $file_path ){
515
-		return str_replace( array( '\\', '/' ), DS, $file_path );
514
+	public static function standardise_directory_separators($file_path) {
515
+		return str_replace(array('\\', '/'), DS, $file_path);
516 516
 	}
517 517
 
518 518
 
@@ -523,8 +523,8 @@  discard block
 block discarded – undo
523 523
 	 * @param string $file_path
524 524
 	 * @return string
525 525
 	 */
526
-	public static function end_with_directory_separator( $file_path ){
527
-		return rtrim( $file_path, '/\\' ) . DS;
526
+	public static function end_with_directory_separator($file_path) {
527
+		return rtrim($file_path, '/\\').DS;
528 528
 	}
529 529
 
530 530
 
@@ -534,8 +534,8 @@  discard block
 block discarded – undo
534 534
 	 * @param $file_path
535 535
 	 * @return string
536 536
 	 */
537
-	public static function standardise_and_end_with_directory_separator( $file_path ){
538
-		return self::end_with_directory_separator( self::standardise_directory_separators( $file_path ));
537
+	public static function standardise_and_end_with_directory_separator($file_path) {
538
+		return self::end_with_directory_separator(self::standardise_directory_separators($file_path));
539 539
 	}
540 540
 
541 541
 
@@ -552,21 +552,21 @@  discard block
 block discarded – undo
552 552
 	 *		if $index_numerically == FALSE (Default) keys are what the class names SHOULD be;
553 553
 	 *		 and values are their filepaths
554 554
 	 */
555
-	public static function get_contents_of_folders( $folder_paths = array(), $index_numerically = FALSE ){
555
+	public static function get_contents_of_folders($folder_paths = array(), $index_numerically = FALSE) {
556 556
 		$class_to_folder_path = array();
557
-		foreach( $folder_paths as $folder_path ){
558
-			$folder_path = self::standardise_and_end_with_directory_separator( $folder_path );
557
+		foreach ($folder_paths as $folder_path) {
558
+			$folder_path = self::standardise_and_end_with_directory_separator($folder_path);
559 559
 			// load WP_Filesystem and set file permissions
560
-			$files_in_folder = glob( $folder_path . '*' );
560
+			$files_in_folder = glob($folder_path.'*');
561 561
 			$class_to_folder_path = array();
562
-			if ( $files_in_folder ) {
563
-				foreach( $files_in_folder as $file_path ){
562
+			if ($files_in_folder) {
563
+				foreach ($files_in_folder as $file_path) {
564 564
 					//only add files, not folders
565
-					if ( ! is_dir( $file_path )) {
566
-						if ( $index_numerically ) {
565
+					if ( ! is_dir($file_path)) {
566
+						if ($index_numerically) {
567 567
 							$class_to_folder_path[] = $file_path;
568 568
 						} else {
569
-							$classname = self::get_classname_from_filepath_with_standard_filename( $file_path );
569
+							$classname = self::get_classname_from_filepath_with_standard_filename($file_path);
570 570
 							$class_to_folder_path[$classname] = $file_path;
571 571
 						}
572 572
 					}
@@ -586,39 +586,39 @@  discard block
 block discarded – undo
586 586
 	 * @return boolean success
587 587
 	 * @throws EE_Error
588 588
 	 */
589
-	public static function copy( $source_file, $destination_file, $overwrite = FALSE ){
590
-		$full_source_path = EEH_File::standardise_directory_separators( $source_file );
591
-		if( ! EEH_File::exists( $full_source_path ) ){
592
-			if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
593
-				$msg = sprintf( __( 'The file located at "%2$s" is not readable or doesn\'t exist.', 'event_espresso' ), $full_source_path );
594
-				$msg .= EEH_File::_permissions_error_for_unreadable_filepath( $full_source_path );
595
-				throw new EE_Error( $msg );
589
+	public static function copy($source_file, $destination_file, $overwrite = FALSE) {
590
+		$full_source_path = EEH_File::standardise_directory_separators($source_file);
591
+		if ( ! EEH_File::exists($full_source_path)) {
592
+			if (defined('WP_DEBUG') && WP_DEBUG) {
593
+				$msg = sprintf(__('The file located at "%2$s" is not readable or doesn\'t exist.', 'event_espresso'), $full_source_path);
594
+				$msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_source_path);
595
+				throw new EE_Error($msg);
596 596
 			}
597 597
 			return FALSE;
598 598
 		}
599 599
 
600
-		$full_dest_path = EEH_File::standardise_directory_separators( $destination_file );
601
-		$folder = EEH_File::remove_filename_from_filepath( $full_dest_path );
602
-		if ( ! EEH_File::verify_is_writable( $folder, 'folder' )) {
603
-			if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
604
-				$msg = sprintf( __( 'The file located at "%2$s" is not writable.', 'event_espresso' ), $full_dest_path );
605
-				$msg .= EEH_File::_permissions_error_for_unreadable_filepath( $full_dest_path );
606
-				throw new EE_Error( $msg );
600
+		$full_dest_path = EEH_File::standardise_directory_separators($destination_file);
601
+		$folder = EEH_File::remove_filename_from_filepath($full_dest_path);
602
+		if ( ! EEH_File::verify_is_writable($folder, 'folder')) {
603
+			if (defined('WP_DEBUG') && WP_DEBUG) {
604
+				$msg = sprintf(__('The file located at "%2$s" is not writable.', 'event_espresso'), $full_dest_path);
605
+				$msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_dest_path);
606
+				throw new EE_Error($msg);
607 607
 			}
608 608
 			return FALSE;
609 609
 		}
610 610
 
611 611
 		// load WP_Filesystem and set file permissions
612
-		$wp_filesystem = EEH_File::_get_wp_filesystem( $destination_file );
612
+		$wp_filesystem = EEH_File::_get_wp_filesystem($destination_file);
613 613
 		// write the file
614 614
 		if ( ! $wp_filesystem->copy( 
615
-						EEH_File::convert_local_filepath_to_remote_filepath( $full_source_path ), 
616
-						EEH_File::convert_local_filepath_to_remote_filepath( $full_dest_path ), 
615
+						EEH_File::convert_local_filepath_to_remote_filepath($full_source_path), 
616
+						EEH_File::convert_local_filepath_to_remote_filepath($full_dest_path), 
617 617
 						$overwrite )) {
618
-			if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
619
-				$msg = sprintf( __( 'Attempted writing to file %1$s, but could not, probably because of permissions issues', 'event_espresso' ), $full_source_path );
620
-				$msg .= EEH_File::_permissions_error_for_unreadable_filepath( $full_source_path, 'f' );
621
-				throw new EE_Error( $msg );
618
+			if (defined('WP_DEBUG') && WP_DEBUG) {
619
+				$msg = sprintf(__('Attempted writing to file %1$s, but could not, probably because of permissions issues', 'event_espresso'), $full_source_path);
620
+				$msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_source_path, 'f');
621
+				throw new EE_Error($msg);
622 622
 			}
623 623
 			return FALSE;
624 624
 		}
@@ -630,9 +630,9 @@  discard block
 block discarded – undo
630 630
 	 * @param string $filepath
631 631
 	 * @return boolean
632 632
 	 */
633
-	public static function is_in_uploads_folder( $filepath ) {
633
+	public static function is_in_uploads_folder($filepath) {
634 634
 		$uploads = wp_upload_dir();
635
-		return strpos( $filepath, $uploads[ 'basedir' ] ) === 0 ? true : false;
635
+		return strpos($filepath, $uploads['basedir']) === 0 ? true : false;
636 636
 	}
637 637
 	
638 638
 	/**
@@ -646,9 +646,9 @@  discard block
 block discarded – undo
646 646
 	 * @return string the remote filepath (eg the filepath the filesystem method, eg 
647 647
 	 * ftp or ssh, will use to access the folder
648 648
 	 */
649
-	public static function convert_local_filepath_to_remote_filepath( $local_filepath ) {
650
-		$wp_filesystem = EEH_File::_get_wp_filesystem( $local_filepath );
651
-		return str_replace( WP_CONTENT_DIR . DS, $wp_filesystem->wp_content_dir(), $local_filepath );
649
+	public static function convert_local_filepath_to_remote_filepath($local_filepath) {
650
+		$wp_filesystem = EEH_File::_get_wp_filesystem($local_filepath);
651
+		return str_replace(WP_CONTENT_DIR.DS, $wp_filesystem->wp_content_dir(), $local_filepath);
652 652
 	}
653 653
 }
654 654
 // End of file EEH_File.helper.php
Please login to merge, or discard this patch.