@@ -12,7 +12,7 @@ discard block |
||
| 12 | 12 | * @ version 4.0 |
| 13 | 13 | * |
| 14 | 14 | */ |
| 15 | -require_once( EE_HELPERS . 'EEH_Base.helper.php' ); |
|
| 15 | +require_once(EE_HELPERS.'EEH_Base.helper.php'); |
|
| 16 | 16 | /** |
| 17 | 17 | * |
| 18 | 18 | * Class EEH_File |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | private static function _get_wp_filesystem() { |
| 42 | 42 | global $wp_filesystem; |
| 43 | 43 | // no filesystem setup ??? |
| 44 | - if ( ! $wp_filesystem instanceof WP_Filesystem_Base ) { |
|
| 44 | + if ( ! $wp_filesystem instanceof WP_Filesystem_Base) { |
|
| 45 | 45 | // if some eager beaver's just trying to get in there too early... |
| 46 | 46 | // let them do it, because we are one of those eager beavers! :P |
| 47 | 47 | /** |
@@ -54,29 +54,29 @@ discard block |
||
| 54 | 54 | * and there may be troubles if the WP files are owned by a different user |
| 55 | 55 | * than the server user. But both of these issues should exist in 4.4 and earlier too |
| 56 | 56 | */ |
| 57 | - if ( FALSE && ! did_action( 'wp_loaded' )) { |
|
| 57 | + if (FALSE && ! did_action('wp_loaded')) { |
|
| 58 | 58 | $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'); |
| 59 | - if ( WP_DEBUG ) { |
|
| 60 | - $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'); |
|
| 59 | + if (WP_DEBUG) { |
|
| 60 | + $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'); |
|
| 61 | 61 | } |
| 62 | - throw new EE_Error( $msg ); |
|
| 62 | + throw new EE_Error($msg); |
|
| 63 | 63 | } else { |
| 64 | 64 | // should be loaded if we are past the wp_loaded hook... |
| 65 | - if ( ! function_exists( 'WP_Filesystem' )) { |
|
| 66 | - require_once( ABSPATH . 'wp-admin/includes/file.php' ); |
|
| 67 | - require_once( ABSPATH . 'wp-admin/includes/template.php' ); |
|
| 65 | + if ( ! function_exists('WP_Filesystem')) { |
|
| 66 | + require_once(ABSPATH.'wp-admin/includes/file.php'); |
|
| 67 | + require_once(ABSPATH.'wp-admin/includes/template.php'); |
|
| 68 | 68 | } |
| 69 | 69 | // basically check for direct or previously configured access |
| 70 | - if ( ! WP_Filesystem() ) { |
|
| 70 | + if ( ! WP_Filesystem()) { |
|
| 71 | 71 | // turn on output buffering so that we can capture the credentials form |
| 72 | 72 | ob_start(); |
| 73 | - $credentials = request_filesystem_credentials( '' ); |
|
| 73 | + $credentials = request_filesystem_credentials(''); |
|
| 74 | 74 | // store credentials form for the time being |
| 75 | 75 | EEH_File::$_credentials_form = ob_get_clean(); |
| 76 | 76 | // if credentials do NOT exist |
| 77 | - if ( $credentials === FALSE ) { |
|
| 78 | - add_action( 'admin_notices', array( 'EEH_File', 'display_request_filesystem_credentials_form' ), 999 ); |
|
| 79 | - 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')); |
|
| 77 | + if ($credentials === FALSE) { |
|
| 78 | + add_action('admin_notices', array('EEH_File', 'display_request_filesystem_credentials_form'), 999); |
|
| 79 | + 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')); |
|
| 80 | 80 | } |
| 81 | 81 | } |
| 82 | 82 | } |
@@ -89,8 +89,8 @@ discard block |
||
| 89 | 89 | * display_request_filesystem_credentials_form |
| 90 | 90 | */ |
| 91 | 91 | public static function display_request_filesystem_credentials_form() { |
| 92 | - if ( ! empty( EEH_File::$_credentials_form )) { |
|
| 93 | - echo '<div class="updated espresso-notices-attention"><p>' . EEH_File::$_credentials_form . '</p></div>'; |
|
| 92 | + if ( ! empty(EEH_File::$_credentials_form)) { |
|
| 93 | + echo '<div class="updated espresso-notices-attention"><p>'.EEH_File::$_credentials_form.'</p></div>'; |
|
| 94 | 94 | } |
| 95 | 95 | } |
| 96 | 96 | |
@@ -108,29 +108,29 @@ discard block |
||
| 108 | 108 | * @throws EE_Error |
| 109 | 109 | * @return bool |
| 110 | 110 | */ |
| 111 | - public static function verify_filepath_and_permissions( $full_file_path = '', $file_name = '', $file_ext = '', $type_of_file = '' ) { |
|
| 111 | + public static function verify_filepath_and_permissions($full_file_path = '', $file_name = '', $file_ext = '', $type_of_file = '') { |
|
| 112 | 112 | // load WP_Filesystem and set file permissions |
| 113 | 113 | $wp_filesystem = EEH_File::_get_wp_filesystem(); |
| 114 | - $full_file_path = EEH_File::standardise_directory_separators( $full_file_path ); |
|
| 115 | - if ( ! $wp_filesystem->is_readable( $full_file_path )) { |
|
| 116 | - $file_name = ! empty( $type_of_file ) ? $file_name . ' ' . $type_of_file : $file_name; |
|
| 117 | - $file_name .= ! empty( $file_ext ) ? ' file' : ' folder'; |
|
| 114 | + $full_file_path = EEH_File::standardise_directory_separators($full_file_path); |
|
| 115 | + if ( ! $wp_filesystem->is_readable($full_file_path)) { |
|
| 116 | + $file_name = ! empty($type_of_file) ? $file_name.' '.$type_of_file : $file_name; |
|
| 117 | + $file_name .= ! empty($file_ext) ? ' file' : ' folder'; |
|
| 118 | 118 | $msg = sprintf( |
| 119 | - __( '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' ), |
|
| 119 | + __('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'), |
|
| 120 | 120 | $file_name, |
| 121 | 121 | '<br />' |
| 122 | 122 | ); |
| 123 | - if ( EEH_File::exists( $full_file_path )) { |
|
| 124 | - $msg .= EEH_File::_permissions_error_for_unreadable_filepath( $full_file_path, $type_of_file ); |
|
| 123 | + if (EEH_File::exists($full_file_path)) { |
|
| 124 | + $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_file_path, $type_of_file); |
|
| 125 | 125 | } else { |
| 126 | 126 | // no file permissions means the file was not found |
| 127 | 127 | $msg .= sprintf( |
| 128 | - __( 'Please ensure the following path is correct: "%s".', 'event_espresso' ), |
|
| 128 | + __('Please ensure the following path is correct: "%s".', 'event_espresso'), |
|
| 129 | 129 | $full_file_path |
| 130 | 130 | ); |
| 131 | 131 | } |
| 132 | - if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { |
|
| 133 | - throw new EE_Error( $msg . '||' . $msg ); |
|
| 132 | + if (defined('WP_DEBUG') && WP_DEBUG) { |
|
| 133 | + throw new EE_Error($msg.'||'.$msg); |
|
| 134 | 134 | } |
| 135 | 135 | return FALSE; |
| 136 | 136 | } |
@@ -147,24 +147,24 @@ discard block |
||
| 147 | 147 | * @param string $type_of_file - general type of file (ie: "module"), this is only used to improve error messages |
| 148 | 148 | * @return string |
| 149 | 149 | */ |
| 150 | - private static function _permissions_error_for_unreadable_filepath( $full_file_path = '', $type_of_file = '' ){ |
|
| 150 | + private static function _permissions_error_for_unreadable_filepath($full_file_path = '', $type_of_file = '') { |
|
| 151 | 151 | // load WP_Filesystem and set file permissions |
| 152 | 152 | $wp_filesystem = EEH_File::_get_wp_filesystem(); |
| 153 | 153 | // check file permissions |
| 154 | - $perms = $wp_filesystem->getchmod( $full_file_path ); |
|
| 155 | - if ( $perms ) { |
|
| 154 | + $perms = $wp_filesystem->getchmod($full_file_path); |
|
| 155 | + if ($perms) { |
|
| 156 | 156 | // file permissions exist, but way be set incorrectly |
| 157 | - $type_of_file = ! empty( $type_of_file ) ? $type_of_file . ' ' : ''; |
|
| 158 | - $type_of_file .= ! empty( $type_of_file ) ? 'file' : 'folder'; |
|
| 157 | + $type_of_file = ! empty($type_of_file) ? $type_of_file.' ' : ''; |
|
| 158 | + $type_of_file .= ! empty($type_of_file) ? 'file' : 'folder'; |
|
| 159 | 159 | return sprintf( |
| 160 | - __( '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' ), |
|
| 160 | + __('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'), |
|
| 161 | 161 | $type_of_file, |
| 162 | 162 | $perms |
| 163 | 163 | ); |
| 164 | 164 | } else { |
| 165 | 165 | // file exists but file permissions could not be read ?!?! |
| 166 | 166 | return sprintf( |
| 167 | - __( 'Please ensure that the server and/or PHP configuration allows the current process to access the following file: "%s".', 'event_espresso' ), |
|
| 167 | + __('Please ensure that the server and/or PHP configuration allows the current process to access the following file: "%s".', 'event_espresso'), |
|
| 168 | 168 | $full_file_path |
| 169 | 169 | ); |
| 170 | 170 | } |
@@ -179,33 +179,33 @@ discard block |
||
| 179 | 179 | * @throws EE_Error |
| 180 | 180 | * @return bool |
| 181 | 181 | */ |
| 182 | - public static function ensure_folder_exists_and_is_writable( $folder = '' ){ |
|
| 183 | - if ( empty( $folder )) { |
|
| 182 | + public static function ensure_folder_exists_and_is_writable($folder = '') { |
|
| 183 | + if (empty($folder)) { |
|
| 184 | 184 | return FALSE; |
| 185 | 185 | } |
| 186 | 186 | // remove ending DS |
| 187 | - $folder = EEH_File::standardise_directory_separators( rtrim( $folder, '/\\' )); |
|
| 187 | + $folder = EEH_File::standardise_directory_separators(rtrim($folder, '/\\')); |
|
| 188 | 188 | // determine parent folder |
| 189 | - $folder_segments = explode( DS, $folder ); |
|
| 190 | - array_pop( $folder_segments ); |
|
| 191 | - $parent_folder = implode( DS, $folder_segments ) . DS; |
|
| 189 | + $folder_segments = explode(DS, $folder); |
|
| 190 | + array_pop($folder_segments); |
|
| 191 | + $parent_folder = implode(DS, $folder_segments).DS; |
|
| 192 | 192 | // add DS to folder |
| 193 | - $folder = EEH_File::end_with_directory_separator( $folder ); |
|
| 193 | + $folder = EEH_File::end_with_directory_separator($folder); |
|
| 194 | 194 | $wp_filesystem = EEH_File::_get_wp_filesystem(); |
| 195 | - if ( ! $wp_filesystem->is_dir( $folder )) { |
|
| 196 | - if ( ! EEH_File::verify_is_writable( $parent_folder, 'folder' )) { |
|
| 195 | + if ( ! $wp_filesystem->is_dir($folder)) { |
|
| 196 | + if ( ! EEH_File::verify_is_writable($parent_folder, 'folder')) { |
|
| 197 | 197 | return FALSE; |
| 198 | 198 | } else { |
| 199 | - if ( ! $wp_filesystem->mkdir( $folder )) { |
|
| 200 | - if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { |
|
| 201 | - $msg = sprintf( __( '"%s" could not be created.', 'event_espresso' ), $folder ); |
|
| 202 | - $msg .= EEH_File::_permissions_error_for_unreadable_filepath( $folder ); |
|
| 203 | - throw new EE_Error( $msg ); |
|
| 199 | + if ( ! $wp_filesystem->mkdir($folder)) { |
|
| 200 | + if (defined('WP_DEBUG') && WP_DEBUG) { |
|
| 201 | + $msg = sprintf(__('"%s" could not be created.', 'event_espresso'), $folder); |
|
| 202 | + $msg .= EEH_File::_permissions_error_for_unreadable_filepath($folder); |
|
| 203 | + throw new EE_Error($msg); |
|
| 204 | 204 | } |
| 205 | 205 | return FALSE; |
| 206 | 206 | } |
| 207 | 207 | } |
| 208 | - } elseif ( ! EEH_File::verify_is_writable( $folder, 'folder' )) { |
|
| 208 | + } elseif ( ! EEH_File::verify_is_writable($folder, 'folder')) { |
|
| 209 | 209 | return FALSE; |
| 210 | 210 | } |
| 211 | 211 | return TRUE; |
@@ -220,15 +220,15 @@ discard block |
||
| 220 | 220 | * @throws EE_Error |
| 221 | 221 | * @return bool |
| 222 | 222 | */ |
| 223 | - public static function verify_is_writable( $full_path = '', $file_or_folder = 'folder' ){ |
|
| 223 | + public static function verify_is_writable($full_path = '', $file_or_folder = 'folder') { |
|
| 224 | 224 | // load WP_Filesystem and set file permissions |
| 225 | 225 | $wp_filesystem = EEH_File::_get_wp_filesystem(); |
| 226 | - $full_path = EEH_File::standardise_directory_separators( $full_path ); |
|
| 227 | - if ( ! $wp_filesystem->is_writable( $full_path )) { |
|
| 228 | - if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { |
|
| 229 | - $msg = sprintf( __( 'The "%1$s" %2$s is not writable.', 'event_espresso' ), $full_path, $file_or_folder ); |
|
| 230 | - $msg .= EEH_File::_permissions_error_for_unreadable_filepath( $full_path ); |
|
| 231 | - throw new EE_Error( $msg ); |
|
| 226 | + $full_path = EEH_File::standardise_directory_separators($full_path); |
|
| 227 | + if ( ! $wp_filesystem->is_writable($full_path)) { |
|
| 228 | + if (defined('WP_DEBUG') && WP_DEBUG) { |
|
| 229 | + $msg = sprintf(__('The "%1$s" %2$s is not writable.', 'event_espresso'), $full_path, $file_or_folder); |
|
| 230 | + $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_path); |
|
| 231 | + throw new EE_Error($msg); |
|
| 232 | 232 | } |
| 233 | 233 | return FALSE; |
| 234 | 234 | } |
@@ -244,21 +244,21 @@ discard block |
||
| 244 | 244 | * @throws EE_Error |
| 245 | 245 | * @return bool |
| 246 | 246 | */ |
| 247 | - public static function ensure_file_exists_and_is_writable( $full_file_path = '' ) { |
|
| 247 | + public static function ensure_file_exists_and_is_writable($full_file_path = '') { |
|
| 248 | 248 | // load WP_Filesystem and set file permissions |
| 249 | 249 | $wp_filesystem = EEH_File::_get_wp_filesystem(); |
| 250 | - $full_file_path = EEH_File::standardise_directory_separators( $full_file_path ); |
|
| 251 | - if ( ! EEH_File::exists( $full_file_path )) { |
|
| 252 | - if ( ! $wp_filesystem->touch( $full_file_path )) { |
|
| 253 | - if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { |
|
| 254 | - $msg = sprintf( __( 'The "%s" file could not be created.', 'event_espresso' ), $full_file_path ); |
|
| 255 | - $msg .= EEH_File::_permissions_error_for_unreadable_filepath( $full_file_path ); |
|
| 256 | - throw new EE_Error( $msg ); |
|
| 250 | + $full_file_path = EEH_File::standardise_directory_separators($full_file_path); |
|
| 251 | + if ( ! EEH_File::exists($full_file_path)) { |
|
| 252 | + if ( ! $wp_filesystem->touch($full_file_path)) { |
|
| 253 | + if (defined('WP_DEBUG') && WP_DEBUG) { |
|
| 254 | + $msg = sprintf(__('The "%s" file could not be created.', 'event_espresso'), $full_file_path); |
|
| 255 | + $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_file_path); |
|
| 256 | + throw new EE_Error($msg); |
|
| 257 | 257 | } |
| 258 | 258 | return FALSE; |
| 259 | 259 | } |
| 260 | 260 | } |
| 261 | - if ( ! EEH_File::verify_is_writable( $full_file_path, 'file' )) { |
|
| 261 | + if ( ! EEH_File::verify_is_writable($full_file_path, 'file')) { |
|
| 262 | 262 | return FALSE; |
| 263 | 263 | } |
| 264 | 264 | return TRUE; |
@@ -271,12 +271,12 @@ discard block |
||
| 271 | 271 | * @param string $full_file_path |
| 272 | 272 | * @return string |
| 273 | 273 | */ |
| 274 | - public static function get_file_contents( $full_file_path = '' ){ |
|
| 275 | - $full_file_path = EEH_File::standardise_directory_separators( $full_file_path ); |
|
| 276 | - 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 ))) { |
|
| 274 | + public static function get_file_contents($full_file_path = '') { |
|
| 275 | + $full_file_path = EEH_File::standardise_directory_separators($full_file_path); |
|
| 276 | + 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))) { |
|
| 277 | 277 | // load WP_Filesystem and set file permissions |
| 278 | 278 | $wp_filesystem = EEH_File::_get_wp_filesystem(); |
| 279 | - return $wp_filesystem->get_contents( $full_file_path ); |
|
| 279 | + return $wp_filesystem->get_contents($full_file_path); |
|
| 280 | 280 | } |
| 281 | 281 | return ''; |
| 282 | 282 | } |
@@ -291,26 +291,26 @@ discard block |
||
| 291 | 291 | * @throws EE_Error |
| 292 | 292 | * @return bool |
| 293 | 293 | */ |
| 294 | - public static function write_to_file( $full_file_path = '', $file_contents = '', $file_type = '' ){ |
|
| 295 | - $full_file_path = EEH_File::standardise_directory_separators( $full_file_path ); |
|
| 296 | - $file_type = ! empty( $file_type ) ? rtrim( $file_type, ' ' ) . ' ' : ''; |
|
| 297 | - $folder = EEH_File::remove_filename_from_filepath( $full_file_path ); |
|
| 298 | - if ( ! EEH_File::verify_is_writable( $folder, 'folder' )) { |
|
| 299 | - if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { |
|
| 300 | - $msg = sprintf( __( 'The %1$sfile located at "%2$s" is not writable.', 'event_espresso' ), $file_type, $full_file_path ); |
|
| 301 | - $msg .= EEH_File::_permissions_error_for_unreadable_filepath( $full_file_path ); |
|
| 302 | - throw new EE_Error( $msg ); |
|
| 294 | + public static function write_to_file($full_file_path = '', $file_contents = '', $file_type = '') { |
|
| 295 | + $full_file_path = EEH_File::standardise_directory_separators($full_file_path); |
|
| 296 | + $file_type = ! empty($file_type) ? rtrim($file_type, ' ').' ' : ''; |
|
| 297 | + $folder = EEH_File::remove_filename_from_filepath($full_file_path); |
|
| 298 | + if ( ! EEH_File::verify_is_writable($folder, 'folder')) { |
|
| 299 | + if (defined('WP_DEBUG') && WP_DEBUG) { |
|
| 300 | + $msg = sprintf(__('The %1$sfile located at "%2$s" is not writable.', 'event_espresso'), $file_type, $full_file_path); |
|
| 301 | + $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_file_path); |
|
| 302 | + throw new EE_Error($msg); |
|
| 303 | 303 | } |
| 304 | 304 | return FALSE; |
| 305 | 305 | } |
| 306 | 306 | // load WP_Filesystem and set file permissions |
| 307 | 307 | $wp_filesystem = EEH_File::_get_wp_filesystem(); |
| 308 | 308 | // write the file |
| 309 | - if ( ! $wp_filesystem->put_contents( $full_file_path, $file_contents )) { |
|
| 310 | - if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { |
|
| 311 | - $msg = sprintf( __( 'The %1$sfile located at "%2$s" could not be written to.', 'event_espresso' ), $file_type, $full_file_path ); |
|
| 312 | - $msg .= EEH_File::_permissions_error_for_unreadable_filepath( $full_file_path, 'f' ); |
|
| 313 | - throw new EE_Error( $msg ); |
|
| 309 | + if ( ! $wp_filesystem->put_contents($full_file_path, $file_contents)) { |
|
| 310 | + if (defined('WP_DEBUG') && WP_DEBUG) { |
|
| 311 | + $msg = sprintf(__('The %1$sfile located at "%2$s" could not be written to.', 'event_espresso'), $file_type, $full_file_path); |
|
| 312 | + $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_file_path, 'f'); |
|
| 313 | + throw new EE_Error($msg); |
|
| 314 | 314 | } |
| 315 | 315 | return FALSE; |
| 316 | 316 | } |
@@ -326,9 +326,9 @@ discard block |
||
| 326 | 326 | * @param string $full_file_path |
| 327 | 327 | * @return bool |
| 328 | 328 | */ |
| 329 | - public static function exists( $full_file_path = '' ) { |
|
| 329 | + public static function exists($full_file_path = '') { |
|
| 330 | 330 | $wp_filesystem = EEH_File::_get_wp_filesystem(); |
| 331 | - return $wp_filesystem->exists( $full_file_path ) ? TRUE : FALSE; |
|
| 331 | + return $wp_filesystem->exists($full_file_path) ? TRUE : FALSE; |
|
| 332 | 332 | } |
| 333 | 333 | |
| 334 | 334 | |
@@ -340,9 +340,9 @@ discard block |
||
| 340 | 340 | * @param string $full_file_path |
| 341 | 341 | * @return bool |
| 342 | 342 | */ |
| 343 | - public static function is_readable( $full_file_path = '' ) { |
|
| 343 | + public static function is_readable($full_file_path = '') { |
|
| 344 | 344 | $wp_filesystem = EEH_File::_get_wp_filesystem(); |
| 345 | - return $wp_filesystem->is_readable( $full_file_path ) ? TRUE : FALSE; |
|
| 345 | + return $wp_filesystem->is_readable($full_file_path) ? TRUE : FALSE; |
|
| 346 | 346 | } |
| 347 | 347 | |
| 348 | 348 | |
@@ -354,8 +354,8 @@ discard block |
||
| 354 | 354 | * @param string $full_file_path |
| 355 | 355 | * @return string |
| 356 | 356 | */ |
| 357 | - public static function remove_filename_from_filepath( $full_file_path = '' ) { |
|
| 358 | - return pathinfo( $full_file_path, PATHINFO_DIRNAME ); |
|
| 357 | + public static function remove_filename_from_filepath($full_file_path = '') { |
|
| 358 | + return pathinfo($full_file_path, PATHINFO_DIRNAME); |
|
| 359 | 359 | } |
| 360 | 360 | |
| 361 | 361 | |
@@ -365,8 +365,8 @@ discard block |
||
| 365 | 365 | * @param string $full_file_path |
| 366 | 366 | * @return string |
| 367 | 367 | */ |
| 368 | - public static function get_filename_from_filepath( $full_file_path = '' ) { |
|
| 369 | - return pathinfo( $full_file_path, PATHINFO_BASENAME ); |
|
| 368 | + public static function get_filename_from_filepath($full_file_path = '') { |
|
| 369 | + return pathinfo($full_file_path, PATHINFO_BASENAME); |
|
| 370 | 370 | } |
| 371 | 371 | |
| 372 | 372 | |
@@ -376,8 +376,8 @@ discard block |
||
| 376 | 376 | * @param string $full_file_path |
| 377 | 377 | * @return string |
| 378 | 378 | */ |
| 379 | - public static function get_file_extension( $full_file_path = '' ) { |
|
| 380 | - return pathinfo( $full_file_path, PATHINFO_EXTENSION ); |
|
| 379 | + public static function get_file_extension($full_file_path = '') { |
|
| 380 | + return pathinfo($full_file_path, PATHINFO_EXTENSION); |
|
| 381 | 381 | } |
| 382 | 382 | |
| 383 | 383 | |
@@ -387,10 +387,10 @@ discard block |
||
| 387 | 387 | * @param string $folder |
| 388 | 388 | * @return bool |
| 389 | 389 | */ |
| 390 | - public static function add_htaccess_deny_from_all( $folder = '' ) { |
|
| 391 | - $folder = EEH_File::standardise_and_end_with_directory_separator( $folder ); |
|
| 392 | - if ( ! EEH_File::exists( $folder . '.htaccess' ) ) { |
|
| 393 | - if ( ! EEH_File::write_to_file( $folder . '.htaccess', 'deny from all', '.htaccess' )) { |
|
| 390 | + public static function add_htaccess_deny_from_all($folder = '') { |
|
| 391 | + $folder = EEH_File::standardise_and_end_with_directory_separator($folder); |
|
| 392 | + if ( ! EEH_File::exists($folder.'.htaccess')) { |
|
| 393 | + if ( ! EEH_File::write_to_file($folder.'.htaccess', 'deny from all', '.htaccess')) { |
|
| 394 | 394 | return FALSE; |
| 395 | 395 | } |
| 396 | 396 | } |
@@ -405,11 +405,11 @@ discard block |
||
| 405 | 405 | * @param string $file_path |
| 406 | 406 | * @return string |
| 407 | 407 | */ |
| 408 | - public static function get_classname_from_filepath_with_standard_filename( $file_path ){ |
|
| 408 | + public static function get_classname_from_filepath_with_standard_filename($file_path) { |
|
| 409 | 409 | //extract file from path |
| 410 | - $filename = basename( $file_path ); |
|
| 410 | + $filename = basename($file_path); |
|
| 411 | 411 | //now remove the first period and everything after |
| 412 | - $pos_of_first_period = strpos( $filename,'.' ); |
|
| 412 | + $pos_of_first_period = strpos($filename, '.'); |
|
| 413 | 413 | return substr($filename, 0, $pos_of_first_period); |
| 414 | 414 | } |
| 415 | 415 | |
@@ -421,8 +421,8 @@ discard block |
||
| 421 | 421 | * @param string $file_path |
| 422 | 422 | * @return string |
| 423 | 423 | */ |
| 424 | - public static function standardise_directory_separators( $file_path ){ |
|
| 425 | - return str_replace( array( '\\', '/' ), DS, $file_path ); |
|
| 424 | + public static function standardise_directory_separators($file_path) { |
|
| 425 | + return str_replace(array('\\', '/'), DS, $file_path); |
|
| 426 | 426 | } |
| 427 | 427 | |
| 428 | 428 | |
@@ -433,8 +433,8 @@ discard block |
||
| 433 | 433 | * @param string $file_path |
| 434 | 434 | * @return string |
| 435 | 435 | */ |
| 436 | - public static function end_with_directory_separator( $file_path ){ |
|
| 437 | - return rtrim( $file_path, '/\\' ) . DS; |
|
| 436 | + public static function end_with_directory_separator($file_path) { |
|
| 437 | + return rtrim($file_path, '/\\').DS; |
|
| 438 | 438 | } |
| 439 | 439 | |
| 440 | 440 | |
@@ -444,8 +444,8 @@ discard block |
||
| 444 | 444 | * @param $file_path |
| 445 | 445 | * @return string |
| 446 | 446 | */ |
| 447 | - public static function standardise_and_end_with_directory_separator( $file_path ){ |
|
| 448 | - return self::end_with_directory_separator( self::standardise_directory_separators( $file_path )); |
|
| 447 | + public static function standardise_and_end_with_directory_separator($file_path) { |
|
| 448 | + return self::end_with_directory_separator(self::standardise_directory_separators($file_path)); |
|
| 449 | 449 | } |
| 450 | 450 | |
| 451 | 451 | |
@@ -462,21 +462,21 @@ discard block |
||
| 462 | 462 | * if $index_numerically == FALSE (Default) keys are what the class names SHOULD be; |
| 463 | 463 | * and values are their filepaths |
| 464 | 464 | */ |
| 465 | - public static function get_contents_of_folders( $folder_paths = array(), $index_numerically = FALSE ){ |
|
| 465 | + public static function get_contents_of_folders($folder_paths = array(), $index_numerically = FALSE) { |
|
| 466 | 466 | $class_to_folder_path = array(); |
| 467 | - foreach( $folder_paths as $folder_path ){ |
|
| 468 | - $folder_path = self::standardise_and_end_with_directory_separator( $folder_path ); |
|
| 467 | + foreach ($folder_paths as $folder_path) { |
|
| 468 | + $folder_path = self::standardise_and_end_with_directory_separator($folder_path); |
|
| 469 | 469 | // load WP_Filesystem and set file permissions |
| 470 | - $files_in_folder = glob( $folder_path . '*' ); |
|
| 470 | + $files_in_folder = glob($folder_path.'*'); |
|
| 471 | 471 | $class_to_folder_path = array(); |
| 472 | - if ( $files_in_folder ) { |
|
| 473 | - foreach( $files_in_folder as $file_path ){ |
|
| 472 | + if ($files_in_folder) { |
|
| 473 | + foreach ($files_in_folder as $file_path) { |
|
| 474 | 474 | //only add files, not folders |
| 475 | - if ( ! is_dir( $file_path )) { |
|
| 476 | - if ( $index_numerically ) { |
|
| 475 | + if ( ! is_dir($file_path)) { |
|
| 476 | + if ($index_numerically) { |
|
| 477 | 477 | $class_to_folder_path[] = $file_path; |
| 478 | 478 | } else { |
| 479 | - $classname = self::get_classname_from_filepath_with_standard_filename( $file_path ); |
|
| 479 | + $classname = self::get_classname_from_filepath_with_standard_filename($file_path); |
|
| 480 | 480 | $class_to_folder_path[$classname] = $file_path; |
| 481 | 481 | } |
| 482 | 482 | } |
@@ -496,24 +496,24 @@ discard block |
||
| 496 | 496 | * @return boolean success |
| 497 | 497 | * @throws EE_Error |
| 498 | 498 | */ |
| 499 | - public static function copy( $source_file, $destination_file, $overwrite = FALSE ){ |
|
| 500 | - $full_source_path = EEH_File::standardise_directory_separators( $source_file ); |
|
| 501 | - if( ! EEH_File::exists( $full_source_path ) ){ |
|
| 502 | - if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { |
|
| 503 | - $msg = sprintf( __( 'The file located at "%2$s" is not readable or doesn\'t exist.', 'event_espresso' ), $full_source_path ); |
|
| 504 | - $msg .= EEH_File::_permissions_error_for_unreadable_filepath( $full_source_path ); |
|
| 505 | - throw new EE_Error( $msg ); |
|
| 499 | + public static function copy($source_file, $destination_file, $overwrite = FALSE) { |
|
| 500 | + $full_source_path = EEH_File::standardise_directory_separators($source_file); |
|
| 501 | + if ( ! EEH_File::exists($full_source_path)) { |
|
| 502 | + if (defined('WP_DEBUG') && WP_DEBUG) { |
|
| 503 | + $msg = sprintf(__('The file located at "%2$s" is not readable or doesn\'t exist.', 'event_espresso'), $full_source_path); |
|
| 504 | + $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_source_path); |
|
| 505 | + throw new EE_Error($msg); |
|
| 506 | 506 | } |
| 507 | 507 | return FALSE; |
| 508 | 508 | } |
| 509 | 509 | |
| 510 | - $full_dest_path = EEH_File::standardise_directory_separators( $destination_file ); |
|
| 511 | - $folder = EEH_File::remove_filename_from_filepath( $full_dest_path ); |
|
| 512 | - if ( ! EEH_File::verify_is_writable( $folder, 'folder' )) { |
|
| 513 | - if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { |
|
| 514 | - $msg = sprintf( __( 'The file located at "%2$s" is not writable.', 'event_espresso' ), $full_dest_path ); |
|
| 515 | - $msg .= EEH_File::_permissions_error_for_unreadable_filepath( $full_dest_path ); |
|
| 516 | - throw new EE_Error( $msg ); |
|
| 510 | + $full_dest_path = EEH_File::standardise_directory_separators($destination_file); |
|
| 511 | + $folder = EEH_File::remove_filename_from_filepath($full_dest_path); |
|
| 512 | + if ( ! EEH_File::verify_is_writable($folder, 'folder')) { |
|
| 513 | + if (defined('WP_DEBUG') && WP_DEBUG) { |
|
| 514 | + $msg = sprintf(__('The file located at "%2$s" is not writable.', 'event_espresso'), $full_dest_path); |
|
| 515 | + $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_dest_path); |
|
| 516 | + throw new EE_Error($msg); |
|
| 517 | 517 | } |
| 518 | 518 | return FALSE; |
| 519 | 519 | } |
@@ -521,11 +521,11 @@ discard block |
||
| 521 | 521 | // load WP_Filesystem and set file permissions |
| 522 | 522 | $wp_filesystem = EEH_File::_get_wp_filesystem(); |
| 523 | 523 | // write the file |
| 524 | - if ( ! $wp_filesystem->copy( $full_source_path, $full_dest_path, $overwrite )) { |
|
| 525 | - if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { |
|
| 526 | - $msg = sprintf( __( 'Attempted writing to file %1$s, but could not, probably because of permissions issues', 'event_espresso' ), $full_source_path ); |
|
| 527 | - $msg .= EEH_File::_permissions_error_for_unreadable_filepath( $full_source_path, 'f' ); |
|
| 528 | - throw new EE_Error( $msg ); |
|
| 524 | + if ( ! $wp_filesystem->copy($full_source_path, $full_dest_path, $overwrite)) { |
|
| 525 | + if (defined('WP_DEBUG') && WP_DEBUG) { |
|
| 526 | + $msg = sprintf(__('Attempted writing to file %1$s, but could not, probably because of permissions issues', 'event_espresso'), $full_source_path); |
|
| 527 | + $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_source_path, 'f'); |
|
| 528 | + throw new EE_Error($msg); |
|
| 529 | 529 | } |
| 530 | 530 | return FALSE; |
| 531 | 531 | } |
@@ -1,4 +1,6 @@ |
||
| 1 | -<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed'); |
|
| 1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 2 | + exit('No direct script access allowed'); |
|
| 3 | +} |
|
| 2 | 4 | /** |
| 3 | 5 | * Event Espresso |
| 4 | 6 | * |
@@ -1,21 +1,21 @@ |
||
| 1 | 1 | <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { exit('No direct script access allowed'); } |
| 2 | 2 | /** |
| 3 | - * |
|
| 4 | - * Class EEH_HTML |
|
| 5 | - * |
|
| 3 | + * |
|
| 4 | + * Class EEH_HTML |
|
| 5 | + * |
|
| 6 | 6 | * Sometimes when writing PHP you need to generate some standard HTML, |
| 7 | 7 | * but either not enough to warrant creating a template file, |
| 8 | 8 | * or the amount of PHP conditionals and/or loops peppered throughout the HTML |
| 9 | 9 | * just make it really ugly and difficult to read. |
| 10 | 10 | * This class simply adds a bunch of methods for generating basic HTML tags. |
| 11 | 11 | * Most of the methods have the same name as the HTML tag they generate, and most have the same set of parameters. |
| 12 | - * |
|
| 13 | - * @package Event Espresso |
|
| 14 | - * @subpackage core |
|
| 15 | - * @author Brent Christensen |
|
| 16 | - * @since $VID:$ |
|
| 17 | - * |
|
| 18 | - */ |
|
| 12 | + * |
|
| 13 | + * @package Event Espresso |
|
| 14 | + * @subpackage core |
|
| 15 | + * @author Brent Christensen |
|
| 16 | + * @since $VID:$ |
|
| 17 | + * |
|
| 18 | + */ |
|
| 19 | 19 | |
| 20 | 20 | class EEH_HTML { |
| 21 | 21 | |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | */ |
| 42 | 42 | public static function instance() { |
| 43 | 43 | // check if class object is instantiated, and instantiated properly |
| 44 | - if ( ! self::$_instance instanceof EEH_HTML ) { |
|
| 44 | + if ( ! self::$_instance instanceof EEH_HTML) { |
|
| 45 | 45 | self::$_instance = new EEH_HTML(); |
| 46 | 46 | } |
| 47 | 47 | return self::$_instance; |
@@ -93,15 +93,15 @@ discard block |
||
| 93 | 93 | * @param bool $force_close |
| 94 | 94 | * @return string |
| 95 | 95 | */ |
| 96 | - protected static function _open_tag( $tag = 'div', $content = '', $id = '', $class = '', $style = '', $other_attributes = '', $force_close = FALSE ) { |
|
| 97 | - $attributes = ! empty( $id ) ? ' id="' . EEH_HTML::sanitize_id( $id ) . '"' : ''; |
|
| 98 | - $attributes .= ! empty( $class ) ? ' class="' . $class . '"' : ''; |
|
| 99 | - $attributes .= ! empty( $style ) ? ' style="' . $style . '"' : ''; |
|
| 100 | - $attributes .= ! empty( $other_attributes ) ? ' ' . $other_attributes : ''; |
|
| 101 | - $html = EEH_HTML::nl( 0, $tag ) . '<' . $tag . $attributes . '>'; |
|
| 102 | - $html .= ! empty( $content ) ? EEH_HTML::nl( 1, $tag ) . $content : ''; |
|
| 103 | - $indent = ! empty( $content ) || $force_close ? TRUE : FALSE; |
|
| 104 | - $html .= ! empty( $content ) || $force_close ? EEH_HTML::_close_tag( $tag, $id, $class, $indent ) : ''; |
|
| 96 | + protected static function _open_tag($tag = 'div', $content = '', $id = '', $class = '', $style = '', $other_attributes = '', $force_close = FALSE) { |
|
| 97 | + $attributes = ! empty($id) ? ' id="'.EEH_HTML::sanitize_id($id).'"' : ''; |
|
| 98 | + $attributes .= ! empty($class) ? ' class="'.$class.'"' : ''; |
|
| 99 | + $attributes .= ! empty($style) ? ' style="'.$style.'"' : ''; |
|
| 100 | + $attributes .= ! empty($other_attributes) ? ' '.$other_attributes : ''; |
|
| 101 | + $html = EEH_HTML::nl(0, $tag).'<'.$tag.$attributes.'>'; |
|
| 102 | + $html .= ! empty($content) ? EEH_HTML::nl(1, $tag).$content : ''; |
|
| 103 | + $indent = ! empty($content) || $force_close ? TRUE : FALSE; |
|
| 104 | + $html .= ! empty($content) || $force_close ? EEH_HTML::_close_tag($tag, $id, $class, $indent) : ''; |
|
| 105 | 105 | return $html; |
| 106 | 106 | } |
| 107 | 107 | |
@@ -117,16 +117,16 @@ discard block |
||
| 117 | 117 | * @param bool $indent |
| 118 | 118 | * @return string |
| 119 | 119 | */ |
| 120 | - protected static function _close_tag( $tag = 'div', $id = '', $class = '', $indent = TRUE ) { |
|
| 121 | - if ( $id ) { |
|
| 122 | - $comment = EEH_HTML::comment( 'close ' . $id ) . EEH_HTML::nl( 0, $tag ); |
|
| 123 | - } else if ( $class ) { |
|
| 124 | - $comment = EEH_HTML::comment( 'close ' . $class ) . EEH_HTML::nl( 0, $tag ); |
|
| 120 | + protected static function _close_tag($tag = 'div', $id = '', $class = '', $indent = TRUE) { |
|
| 121 | + if ($id) { |
|
| 122 | + $comment = EEH_HTML::comment('close '.$id).EEH_HTML::nl(0, $tag); |
|
| 123 | + } else if ($class) { |
|
| 124 | + $comment = EEH_HTML::comment('close '.$class).EEH_HTML::nl(0, $tag); |
|
| 125 | 125 | } else { |
| 126 | 126 | $comment = ''; |
| 127 | 127 | } |
| 128 | 128 | $html = $indent ? EEH_HTML::nl( -1, $tag ) : ''; |
| 129 | - $html .= '</' . $tag . '>' . $comment; |
|
| 129 | + $html .= '</'.$tag.'>'.$comment; |
|
| 130 | 130 | return $html; |
| 131 | 131 | } |
| 132 | 132 | |
@@ -145,8 +145,8 @@ discard block |
||
| 145 | 145 | * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
| 146 | 146 | * @return string |
| 147 | 147 | */ |
| 148 | - public static function div( $content = '', $id = '', $class = '', $style = '', $other_attributes = '' ) { |
|
| 149 | - return EEH_HTML::_open_tag( 'div', $content, $id, $class, $style, $other_attributes ); |
|
| 148 | + public static function div($content = '', $id = '', $class = '', $style = '', $other_attributes = '') { |
|
| 149 | + return EEH_HTML::_open_tag('div', $content, $id, $class, $style, $other_attributes); |
|
| 150 | 150 | } |
| 151 | 151 | |
| 152 | 152 | |
@@ -159,8 +159,8 @@ discard block |
||
| 159 | 159 | * @param string $class - html class attribute |
| 160 | 160 | * @return string |
| 161 | 161 | */ |
| 162 | - public static function divx( $id = '', $class = '' ) { |
|
| 163 | - return EEH_HTML::_close_tag( 'div', $id, $class ); |
|
| 162 | + public static function divx($id = '', $class = '') { |
|
| 163 | + return EEH_HTML::_close_tag('div', $id, $class); |
|
| 164 | 164 | } |
| 165 | 165 | |
| 166 | 166 | |
@@ -176,23 +176,23 @@ discard block |
||
| 176 | 176 | * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
| 177 | 177 | * @return string |
| 178 | 178 | */ |
| 179 | - public static function h1( $content = '', $id = '', $class = '', $style = '', $other_attributes = '' ) { |
|
| 180 | - return EEH_HTML::_open_tag( 'h1', $content, $id, $class, $style, $other_attributes, TRUE ); |
|
| 179 | + public static function h1($content = '', $id = '', $class = '', $style = '', $other_attributes = '') { |
|
| 180 | + return EEH_HTML::_open_tag('h1', $content, $id, $class, $style, $other_attributes, TRUE); |
|
| 181 | 181 | } |
| 182 | - public static function h2( $content = '', $id = '', $class = '', $style = '', $other_attributes = '' ) { |
|
| 183 | - return EEH_HTML::_open_tag( 'h2', $content, $id, $class, $style, $other_attributes, TRUE ); |
|
| 182 | + public static function h2($content = '', $id = '', $class = '', $style = '', $other_attributes = '') { |
|
| 183 | + return EEH_HTML::_open_tag('h2', $content, $id, $class, $style, $other_attributes, TRUE); |
|
| 184 | 184 | } |
| 185 | - public static function h3( $content = '', $id = '', $class = '', $style = '', $other_attributes = '' ) { |
|
| 186 | - return EEH_HTML::_open_tag( 'h3', $content, $id, $class, $style, $other_attributes, TRUE ); |
|
| 185 | + public static function h3($content = '', $id = '', $class = '', $style = '', $other_attributes = '') { |
|
| 186 | + return EEH_HTML::_open_tag('h3', $content, $id, $class, $style, $other_attributes, TRUE); |
|
| 187 | 187 | } |
| 188 | - public static function h4( $content = '', $id = '', $class = '', $style = '', $other_attributes = '' ) { |
|
| 189 | - return EEH_HTML::_open_tag( 'h4', $content, $id, $class, $style, $other_attributes, TRUE ); |
|
| 188 | + public static function h4($content = '', $id = '', $class = '', $style = '', $other_attributes = '') { |
|
| 189 | + return EEH_HTML::_open_tag('h4', $content, $id, $class, $style, $other_attributes, TRUE); |
|
| 190 | 190 | } |
| 191 | - public static function h5( $content = '', $id = '', $class = '', $style = '', $other_attributes = '' ) { |
|
| 192 | - return EEH_HTML::_open_tag( 'h5', $content, $id, $class, $style, $other_attributes, TRUE ); |
|
| 191 | + public static function h5($content = '', $id = '', $class = '', $style = '', $other_attributes = '') { |
|
| 192 | + return EEH_HTML::_open_tag('h5', $content, $id, $class, $style, $other_attributes, TRUE); |
|
| 193 | 193 | } |
| 194 | - public static function h6( $content = '', $id = '', $class = '', $style = '', $other_attributes = '' ) { |
|
| 195 | - return EEH_HTML::_open_tag( 'h6', $content, $id, $class, $style, $other_attributes, TRUE ); |
|
| 194 | + public static function h6($content = '', $id = '', $class = '', $style = '', $other_attributes = '') { |
|
| 195 | + return EEH_HTML::_open_tag('h6', $content, $id, $class, $style, $other_attributes, TRUE); |
|
| 196 | 196 | } |
| 197 | 197 | |
| 198 | 198 | |
@@ -208,8 +208,8 @@ discard block |
||
| 208 | 208 | * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
| 209 | 209 | * @return string |
| 210 | 210 | */ |
| 211 | - public static function p( $content = '', $id = '', $class = '', $style = '', $other_attributes = '' ) { |
|
| 212 | - return EEH_HTML::_open_tag( 'p', $content, $id, $class, $style, $other_attributes, TRUE ); |
|
| 211 | + public static function p($content = '', $id = '', $class = '', $style = '', $other_attributes = '') { |
|
| 212 | + return EEH_HTML::_open_tag('p', $content, $id, $class, $style, $other_attributes, TRUE); |
|
| 213 | 213 | } |
| 214 | 214 | |
| 215 | 215 | |
@@ -224,8 +224,8 @@ discard block |
||
| 224 | 224 | * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
| 225 | 225 | * @return string |
| 226 | 226 | */ |
| 227 | - public static function ul( $id = '', $class = '', $style = '', $other_attributes = '' ) { |
|
| 228 | - return EEH_HTML::_open_tag( 'ul', '', $id, $class, $style, $other_attributes ); |
|
| 227 | + public static function ul($id = '', $class = '', $style = '', $other_attributes = '') { |
|
| 228 | + return EEH_HTML::_open_tag('ul', '', $id, $class, $style, $other_attributes); |
|
| 229 | 229 | } |
| 230 | 230 | |
| 231 | 231 | |
@@ -238,8 +238,8 @@ discard block |
||
| 238 | 238 | * @param string $class - html class attribute |
| 239 | 239 | * @return string |
| 240 | 240 | */ |
| 241 | - public static function ulx( $id = '', $class = '' ) { |
|
| 242 | - return EEH_HTML::_close_tag( 'ul', $id, $class ); |
|
| 241 | + public static function ulx($id = '', $class = '') { |
|
| 242 | + return EEH_HTML::_close_tag('ul', $id, $class); |
|
| 243 | 243 | } |
| 244 | 244 | |
| 245 | 245 | |
@@ -256,8 +256,8 @@ discard block |
||
| 256 | 256 | * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
| 257 | 257 | * @return string |
| 258 | 258 | */ |
| 259 | - public static function li( $content = '', $id = '', $class = '', $style = '', $other_attributes = '' ) { |
|
| 260 | - return EEH_HTML::_open_tag( 'li', $content, $id, $class, $style, $other_attributes ); |
|
| 259 | + public static function li($content = '', $id = '', $class = '', $style = '', $other_attributes = '') { |
|
| 260 | + return EEH_HTML::_open_tag('li', $content, $id, $class, $style, $other_attributes); |
|
| 261 | 261 | } |
| 262 | 262 | |
| 263 | 263 | |
@@ -270,8 +270,8 @@ discard block |
||
| 270 | 270 | * @param string $class - html class attribute |
| 271 | 271 | * @return string |
| 272 | 272 | */ |
| 273 | - public static function lix( $id = '', $class = '' ) { |
|
| 274 | - return EEH_HTML::_close_tag( 'li', $id, $class ); |
|
| 273 | + public static function lix($id = '', $class = '') { |
|
| 274 | + return EEH_HTML::_close_tag('li', $id, $class); |
|
| 275 | 275 | } |
| 276 | 276 | |
| 277 | 277 | |
@@ -287,8 +287,8 @@ discard block |
||
| 287 | 287 | * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
| 288 | 288 | * @return string |
| 289 | 289 | */ |
| 290 | - public static function table( $content = '', $id = '', $class = '', $style = '', $other_attributes = '' ) { |
|
| 291 | - return EEH_HTML::_open_tag( 'table', $content, $id, $class, $style, $other_attributes ); |
|
| 290 | + public static function table($content = '', $id = '', $class = '', $style = '', $other_attributes = '') { |
|
| 291 | + return EEH_HTML::_open_tag('table', $content, $id, $class, $style, $other_attributes); |
|
| 292 | 292 | } |
| 293 | 293 | |
| 294 | 294 | |
@@ -300,8 +300,8 @@ discard block |
||
| 300 | 300 | * @param string $class - html class attribute |
| 301 | 301 | * @return string |
| 302 | 302 | */ |
| 303 | - public static function tablex( $id = '', $class = '' ) { |
|
| 304 | - return EEH_HTML::_close_tag( 'table', $id, $class ); |
|
| 303 | + public static function tablex($id = '', $class = '') { |
|
| 304 | + return EEH_HTML::_close_tag('table', $id, $class); |
|
| 305 | 305 | } |
| 306 | 306 | |
| 307 | 307 | |
@@ -317,8 +317,8 @@ discard block |
||
| 317 | 317 | * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
| 318 | 318 | * @return string |
| 319 | 319 | */ |
| 320 | - public static function thead( $content = '', $id = '', $class = '', $style = '', $other_attributes = '' ) { |
|
| 321 | - return EEH_HTML::_open_tag( 'thead', $content, $id, $class, $style, $other_attributes ); |
|
| 320 | + public static function thead($content = '', $id = '', $class = '', $style = '', $other_attributes = '') { |
|
| 321 | + return EEH_HTML::_open_tag('thead', $content, $id, $class, $style, $other_attributes); |
|
| 322 | 322 | } |
| 323 | 323 | |
| 324 | 324 | |
@@ -330,8 +330,8 @@ discard block |
||
| 330 | 330 | * @param string $class - html class attribute |
| 331 | 331 | * @return string |
| 332 | 332 | */ |
| 333 | - public static function theadx( $id = '', $class = '' ) { |
|
| 334 | - return EEH_HTML::_close_tag( 'thead', $id, $class ); |
|
| 333 | + public static function theadx($id = '', $class = '') { |
|
| 334 | + return EEH_HTML::_close_tag('thead', $id, $class); |
|
| 335 | 335 | } |
| 336 | 336 | |
| 337 | 337 | |
@@ -347,8 +347,8 @@ discard block |
||
| 347 | 347 | * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
| 348 | 348 | * @return string |
| 349 | 349 | */ |
| 350 | - public static function tbody( $content = '', $id = '', $class = '', $style = '', $other_attributes = '' ) { |
|
| 351 | - return EEH_HTML::_open_tag( 'tbody', $content, $id, $class, $style, $other_attributes ); |
|
| 350 | + public static function tbody($content = '', $id = '', $class = '', $style = '', $other_attributes = '') { |
|
| 351 | + return EEH_HTML::_open_tag('tbody', $content, $id, $class, $style, $other_attributes); |
|
| 352 | 352 | } |
| 353 | 353 | |
| 354 | 354 | |
@@ -360,8 +360,8 @@ discard block |
||
| 360 | 360 | * @param string $class - html class attribute |
| 361 | 361 | * @return string |
| 362 | 362 | */ |
| 363 | - public static function tbodyx( $id = '', $class = '' ) { |
|
| 364 | - return EEH_HTML::_close_tag( 'tbody', $id, $class ); |
|
| 363 | + public static function tbodyx($id = '', $class = '') { |
|
| 364 | + return EEH_HTML::_close_tag('tbody', $id, $class); |
|
| 365 | 365 | } |
| 366 | 366 | |
| 367 | 367 | |
@@ -377,8 +377,8 @@ discard block |
||
| 377 | 377 | * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
| 378 | 378 | * @return string |
| 379 | 379 | */ |
| 380 | - public static function tr( $content = '', $id = '', $class = '', $style = '', $other_attributes = '' ) { |
|
| 381 | - return EEH_HTML::_open_tag( 'tr', $content, $id, $class, $style, $other_attributes ); |
|
| 380 | + public static function tr($content = '', $id = '', $class = '', $style = '', $other_attributes = '') { |
|
| 381 | + return EEH_HTML::_open_tag('tr', $content, $id, $class, $style, $other_attributes); |
|
| 382 | 382 | } |
| 383 | 383 | |
| 384 | 384 | |
@@ -390,8 +390,8 @@ discard block |
||
| 390 | 390 | * @param string $class - html class attribute |
| 391 | 391 | * @return string |
| 392 | 392 | */ |
| 393 | - public static function trx( $id = '', $class = '' ) { |
|
| 394 | - return EEH_HTML::_close_tag( 'tr', $id, $class ); |
|
| 393 | + public static function trx($id = '', $class = '') { |
|
| 394 | + return EEH_HTML::_close_tag('tr', $id, $class); |
|
| 395 | 395 | } |
| 396 | 396 | |
| 397 | 397 | |
@@ -407,8 +407,8 @@ discard block |
||
| 407 | 407 | * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
| 408 | 408 | * @return string |
| 409 | 409 | */ |
| 410 | - public static function th( $content = '', $id = '', $class = '', $style = '', $other_attributes = '' ) { |
|
| 411 | - return EEH_HTML::_open_tag( 'th', $content, $id, $class, $style, $other_attributes ); |
|
| 410 | + public static function th($content = '', $id = '', $class = '', $style = '', $other_attributes = '') { |
|
| 411 | + return EEH_HTML::_open_tag('th', $content, $id, $class, $style, $other_attributes); |
|
| 412 | 412 | } |
| 413 | 413 | |
| 414 | 414 | |
@@ -420,8 +420,8 @@ discard block |
||
| 420 | 420 | * @param string $class - html class attribute |
| 421 | 421 | * @return string |
| 422 | 422 | */ |
| 423 | - public static function thx( $id = '', $class = '' ) { |
|
| 424 | - return EEH_HTML::_close_tag( 'th', $id, $class ); |
|
| 423 | + public static function thx($id = '', $class = '') { |
|
| 424 | + return EEH_HTML::_close_tag('th', $id, $class); |
|
| 425 | 425 | } |
| 426 | 426 | |
| 427 | 427 | |
@@ -437,8 +437,8 @@ discard block |
||
| 437 | 437 | * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
| 438 | 438 | * @return string |
| 439 | 439 | */ |
| 440 | - public static function td( $content = '', $id = '', $class = '', $style = '', $other_attributes = '' ) { |
|
| 441 | - return EEH_HTML::_open_tag( 'td', $content, $id, $class, $style, $other_attributes ); |
|
| 440 | + public static function td($content = '', $id = '', $class = '', $style = '', $other_attributes = '') { |
|
| 441 | + return EEH_HTML::_open_tag('td', $content, $id, $class, $style, $other_attributes); |
|
| 442 | 442 | } |
| 443 | 443 | |
| 444 | 444 | |
@@ -450,8 +450,8 @@ discard block |
||
| 450 | 450 | * @param string $class - html class attribute |
| 451 | 451 | * @return string |
| 452 | 452 | */ |
| 453 | - public static function tdx( $id = '', $class = '' ) { |
|
| 454 | - return EEH_HTML::_close_tag( 'td', $id, $class ); |
|
| 453 | + public static function tdx($id = '', $class = '') { |
|
| 454 | + return EEH_HTML::_close_tag('td', $id, $class); |
|
| 455 | 455 | } |
| 456 | 456 | |
| 457 | 457 | |
@@ -465,10 +465,10 @@ discard block |
||
| 465 | 465 | * @param int $colspan |
| 466 | 466 | * @return string |
| 467 | 467 | */ |
| 468 | - public static function no_row( $content = '', $colspan = 2 ) { |
|
| 468 | + public static function no_row($content = '', $colspan = 2) { |
|
| 469 | 469 | return EEH_HTML::tr( |
| 470 | - EEH_HTML::td( $content, '', '', 'padding:0; border:none;', 'colspan="' . $colspan . '"' ), |
|
| 471 | - '', '', 'padding:0; border:none;' |
|
| 470 | + EEH_HTML::td($content, '', '', 'padding:0; border:none;', 'colspan="'.$colspan.'"'), |
|
| 471 | + '', '', 'padding:0; border:none;' |
|
| 472 | 472 | ); |
| 473 | 473 | } |
| 474 | 474 | |
@@ -488,14 +488,14 @@ discard block |
||
| 488 | 488 | * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
| 489 | 489 | * @return string |
| 490 | 490 | */ |
| 491 | - public static function link( $href = '', $link_text = '', $title = '', $id = '', $class = '', $style = '', $other_attributes = '' ) { |
|
| 492 | - $link_text = ! empty( $link_text ) ? $link_text : $href; |
|
| 493 | - $attributes = ! empty( $id ) ? ' id="' . EEH_HTML::sanitize_id( $id ) . '"' : ''; |
|
| 494 | - $attributes .= ! empty( $class ) ? ' class="' . $class . '"' : ''; |
|
| 495 | - $attributes .= ! empty( $style ) ? ' style="' . $style . '"' : ''; |
|
| 496 | - $attributes .= ! empty( $title ) ? ' title="' . esc_attr( $title ) . '"' : ''; |
|
| 497 | - $attributes .= ! empty( $other_attributes ) ? ' ' . $other_attributes : ''; |
|
| 498 | - return '<a href="' . $href . '" ' . $attributes . '>' . $link_text . '</a>'; |
|
| 491 | + public static function link($href = '', $link_text = '', $title = '', $id = '', $class = '', $style = '', $other_attributes = '') { |
|
| 492 | + $link_text = ! empty($link_text) ? $link_text : $href; |
|
| 493 | + $attributes = ! empty($id) ? ' id="'.EEH_HTML::sanitize_id($id).'"' : ''; |
|
| 494 | + $attributes .= ! empty($class) ? ' class="'.$class.'"' : ''; |
|
| 495 | + $attributes .= ! empty($style) ? ' style="'.$style.'"' : ''; |
|
| 496 | + $attributes .= ! empty($title) ? ' title="'.esc_attr($title).'"' : ''; |
|
| 497 | + $attributes .= ! empty($other_attributes) ? ' '.$other_attributes : ''; |
|
| 498 | + return '<a href="'.$href.'" '.$attributes.'>'.$link_text.'</a>'; |
|
| 499 | 499 | } |
| 500 | 500 | |
| 501 | 501 | |
@@ -512,14 +512,14 @@ discard block |
||
| 512 | 512 | * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
| 513 | 513 | * @return string |
| 514 | 514 | */ |
| 515 | - public static function img( $src = '', $alt = '', $id = '', $class = '', $style = '', $other_attributes = '' ) { |
|
| 516 | - $attributes = ! empty( $src ) ? ' src="' . esc_url_raw( $src ) . '"' : ''; |
|
| 517 | - $attributes .= ! empty( $alt ) ? ' alt="' . esc_attr( $alt ) . '"' : ''; |
|
| 518 | - $attributes .= ! empty( $id ) ? ' id="' . EEH_HTML::sanitize_id( $id ) . '"' : ''; |
|
| 519 | - $attributes .= ! empty( $class ) ? ' class="' . $class . '"' : ''; |
|
| 520 | - $attributes .= ! empty( $style ) ? ' style="' . $style . '"' : ''; |
|
| 521 | - $attributes .= ! empty( $other_attributes ) ? ' ' . $other_attributes : ''; |
|
| 522 | - return '<img' . $attributes . '/>'; |
|
| 515 | + public static function img($src = '', $alt = '', $id = '', $class = '', $style = '', $other_attributes = '') { |
|
| 516 | + $attributes = ! empty($src) ? ' src="'.esc_url_raw($src).'"' : ''; |
|
| 517 | + $attributes .= ! empty($alt) ? ' alt="'.esc_attr($alt).'"' : ''; |
|
| 518 | + $attributes .= ! empty($id) ? ' id="'.EEH_HTML::sanitize_id($id).'"' : ''; |
|
| 519 | + $attributes .= ! empty($class) ? ' class="'.$class.'"' : ''; |
|
| 520 | + $attributes .= ! empty($style) ? ' style="'.$style.'"' : ''; |
|
| 521 | + $attributes .= ! empty($other_attributes) ? ' '.$other_attributes : ''; |
|
| 522 | + return '<img'.$attributes.'/>'; |
|
| 523 | 523 | } |
| 524 | 524 | |
| 525 | 525 | |
@@ -537,12 +537,12 @@ discard block |
||
| 537 | 537 | * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
| 538 | 538 | * @return string |
| 539 | 539 | */ |
| 540 | - protected static function _inline_tag( $tag = 'span', $content = '', $id = '', $class = '', $style = '', $other_attributes = '' ) { |
|
| 541 | - $attributes = ! empty( $id ) ? ' id="' . EEH_HTML::sanitize_id( $id ) . '"' : ''; |
|
| 542 | - $attributes .= ! empty( $class ) ? ' class="' . $class . '"' : ''; |
|
| 543 | - $attributes .= ! empty( $style ) ? ' style="' . $style . '"' : ''; |
|
| 544 | - $attributes .= ! empty( $other_attributes ) ? ' ' . $other_attributes : ''; |
|
| 545 | - return '<' . $tag . ' ' . $attributes . '>' . $content . '</' . $tag . '>'; |
|
| 540 | + protected static function _inline_tag($tag = 'span', $content = '', $id = '', $class = '', $style = '', $other_attributes = '') { |
|
| 541 | + $attributes = ! empty($id) ? ' id="'.EEH_HTML::sanitize_id($id).'"' : ''; |
|
| 542 | + $attributes .= ! empty($class) ? ' class="'.$class.'"' : ''; |
|
| 543 | + $attributes .= ! empty($style) ? ' style="'.$style.'"' : ''; |
|
| 544 | + $attributes .= ! empty($other_attributes) ? ' '.$other_attributes : ''; |
|
| 545 | + return '<'.$tag.' '.$attributes.'>'.$content.'</'.$tag.'>'; |
|
| 546 | 546 | } |
| 547 | 547 | |
| 548 | 548 | |
@@ -558,8 +558,8 @@ discard block |
||
| 558 | 558 | * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
| 559 | 559 | * @return string |
| 560 | 560 | */ |
| 561 | - public static function label( $content = '', $id = '', $class = '', $style = '', $other_attributes = '' ) { |
|
| 562 | - return EEH_HTML::_inline_tag( 'label', $content, $id, $class, $style, $other_attributes ); |
|
| 561 | + public static function label($content = '', $id = '', $class = '', $style = '', $other_attributes = '') { |
|
| 562 | + return EEH_HTML::_inline_tag('label', $content, $id, $class, $style, $other_attributes); |
|
| 563 | 563 | } |
| 564 | 564 | |
| 565 | 565 | |
@@ -575,8 +575,8 @@ discard block |
||
| 575 | 575 | * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
| 576 | 576 | * @return string |
| 577 | 577 | */ |
| 578 | - public static function span( $content = '', $id = '', $class = '', $style = '', $other_attributes = '' ) { |
|
| 579 | - return EEH_HTML::_inline_tag( 'span', $content, $id, $class, $style, $other_attributes ); |
|
| 578 | + public static function span($content = '', $id = '', $class = '', $style = '', $other_attributes = '') { |
|
| 579 | + return EEH_HTML::_inline_tag('span', $content, $id, $class, $style, $other_attributes); |
|
| 580 | 580 | } |
| 581 | 581 | |
| 582 | 582 | |
@@ -592,8 +592,8 @@ discard block |
||
| 592 | 592 | * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc |
| 593 | 593 | * @return string |
| 594 | 594 | */ |
| 595 | - public static function strong( $content = '', $id = '', $class = '', $style = '', $other_attributes = '' ) { |
|
| 596 | - return EEH_HTML::_inline_tag( 'strong', $content, $id, $class, $style, $other_attributes ); |
|
| 595 | + public static function strong($content = '', $id = '', $class = '', $style = '', $other_attributes = '') { |
|
| 596 | + return EEH_HTML::_inline_tag('strong', $content, $id, $class, $style, $other_attributes); |
|
| 597 | 597 | } |
| 598 | 598 | |
| 599 | 599 | |
@@ -605,8 +605,8 @@ discard block |
||
| 605 | 605 | * @param string $comment |
| 606 | 606 | * @return string |
| 607 | 607 | */ |
| 608 | - public static function comment( $comment = '' ) { |
|
| 609 | - return ! empty( $comment ) ? EEH_HTML::nl() . '<!-- ' . $comment . ' -->' : ''; |
|
| 608 | + public static function comment($comment = '') { |
|
| 609 | + return ! empty($comment) ? EEH_HTML::nl().'<!-- '.$comment.' -->' : ''; |
|
| 610 | 610 | } |
| 611 | 611 | |
| 612 | 612 | |
@@ -617,8 +617,8 @@ discard block |
||
| 617 | 617 | * @param int $nmbr - the number of line breaks to return |
| 618 | 618 | * @return string |
| 619 | 619 | */ |
| 620 | - public static function br( $nmbr = 1 ) { |
|
| 621 | - return str_repeat( '<br />', $nmbr ); |
|
| 620 | + public static function br($nmbr = 1) { |
|
| 621 | + return str_repeat('<br />', $nmbr); |
|
| 622 | 622 | } |
| 623 | 623 | |
| 624 | 624 | |
@@ -629,8 +629,8 @@ discard block |
||
| 629 | 629 | * @param int $nmbr - the number of non-breaking spaces to return |
| 630 | 630 | * @return string |
| 631 | 631 | */ |
| 632 | - public static function nbsp( $nmbr = 1 ) { |
|
| 633 | - return str_repeat( ' ', $nmbr ); |
|
| 632 | + public static function nbsp($nmbr = 1) { |
|
| 633 | + return str_repeat(' ', $nmbr); |
|
| 634 | 634 | } |
| 635 | 635 | |
| 636 | 636 | |
@@ -644,9 +644,9 @@ discard block |
||
| 644 | 644 | * @param string $id |
| 645 | 645 | * @return string |
| 646 | 646 | */ |
| 647 | - public static function sanitize_id( $id = '' ) { |
|
| 648 | - $key = str_replace( ' ', '-', trim( $id ) ); |
|
| 649 | - return preg_replace( '/[^a-zA-Z0-9_\-]/', '', $key ); |
|
| 647 | + public static function sanitize_id($id = '') { |
|
| 648 | + $key = str_replace(' ', '-', trim($id)); |
|
| 649 | + return preg_replace('/[^a-zA-Z0-9_\-]/', '', $key); |
|
| 650 | 650 | } |
| 651 | 651 | |
| 652 | 652 | |
@@ -658,10 +658,10 @@ discard block |
||
| 658 | 658 | * @param string $tag |
| 659 | 659 | * @return string - newline character plus # of indents passed (can be + or -) |
| 660 | 660 | */ |
| 661 | - public static function nl( $indent = 0, $tag = 'none' ) { |
|
| 661 | + public static function nl($indent = 0, $tag = 'none') { |
|
| 662 | 662 | $html = "\n"; |
| 663 | - EEH_HTML::indent( $indent, $tag ); |
|
| 664 | - for ( $x = 0; $x < EEH_HTML::$_indent[ $tag ]; $x++ ) { |
|
| 663 | + EEH_HTML::indent($indent, $tag); |
|
| 664 | + for ($x = 0; $x < EEH_HTML::$_indent[$tag]; $x++) { |
|
| 665 | 665 | $html .= "\t"; |
| 666 | 666 | } |
| 667 | 667 | return $html; |
@@ -676,17 +676,17 @@ discard block |
||
| 676 | 676 | * @param int $indent can be negative to decrease the indentation level |
| 677 | 677 | * @param string $tag |
| 678 | 678 | */ |
| 679 | - public static function indent( $indent, $tag = 'none' ){ |
|
| 679 | + public static function indent($indent, $tag = 'none') { |
|
| 680 | 680 | static $default_indentation = FALSE; |
| 681 | - if ( ! $default_indentation ) { |
|
| 681 | + if ( ! $default_indentation) { |
|
| 682 | 682 | EEH_HTML::_set_default_indentation(); |
| 683 | 683 | $default_indentation = TRUE; |
| 684 | 684 | } |
| 685 | - if ( ! isset( EEH_HTML::$_indent[ $tag ] )) { |
|
| 686 | - EEH_HTML::$_indent[ $tag ] = 0; |
|
| 685 | + if ( ! isset(EEH_HTML::$_indent[$tag])) { |
|
| 686 | + EEH_HTML::$_indent[$tag] = 0; |
|
| 687 | 687 | } |
| 688 | - EEH_HTML::$_indent[ $tag ] += intval( $indent ); |
|
| 689 | - EEH_HTML::$_indent[ $tag ] = EEH_HTML::$_indent[ $tag ] >= 0 ? EEH_HTML::$_indent[ $tag ] : 0; |
|
| 688 | + EEH_HTML::$_indent[$tag] += intval($indent); |
|
| 689 | + EEH_HTML::$_indent[$tag] = EEH_HTML::$_indent[$tag] >= 0 ? EEH_HTML::$_indent[$tag] : 0; |
|
| 690 | 690 | } |
| 691 | 691 | |
| 692 | 692 | |
@@ -35,9 +35,9 @@ discard block |
||
| 35 | 35 | * @version $Revision 0.1 $ |
| 36 | 36 | */ |
| 37 | 37 | class EEH_Inflector{ |
| 38 | - // ------ CLASS METHODS ------ // |
|
| 39 | - // ---- Public methods ---- // |
|
| 40 | - // {{{ pluralize() |
|
| 38 | + // ------ CLASS METHODS ------ // |
|
| 39 | + // ---- Public methods ---- // |
|
| 40 | + // {{{ pluralize() |
|
| 41 | 41 | |
| 42 | 42 | /** |
| 43 | 43 | * Just calls self::pluralize and strtolower on $word and returns it |
@@ -51,319 +51,319 @@ discard block |
||
| 51 | 51 | static function singularize_and_upper( $word ) { |
| 52 | 52 | return str_replace( ' ', '_', self::humanize( self::singularize( $word ), 'all' ) ); |
| 53 | 53 | } |
| 54 | - /** |
|
| 55 | - * Pluralizes English nouns. |
|
| 56 | - * |
|
| 57 | - * @access public |
|
| 58 | - * @static |
|
| 59 | - * @param string $word English noun to pluralize |
|
| 60 | - * @return string Plural noun |
|
| 61 | - */ |
|
| 62 | - static function pluralize($word){ |
|
| 63 | - $plural = array( |
|
| 64 | - '/(quiz)$/i' => '\1zes', |
|
| 65 | - '/^(ox)$/i' => '\1en', |
|
| 66 | - '/([m|l])ouse$/i' => '\1ice', |
|
| 67 | - '/(matr|vert|ind)ix|ex$/i' => '\1ices', |
|
| 68 | - '/(x|ch|ss|sh)$/i' => '\1es', |
|
| 69 | - '/([^aeiouy]|qu)ies$/i' => '\1y', |
|
| 70 | - '/([^aeiouy]|qu)y$/i' => '\1ies', |
|
| 71 | - '/(hive)$/i' => '\1s', |
|
| 72 | - '/(?:([^f])fe|([lr])f)$/i' => '\1\2ves', |
|
| 73 | - '/sis$/i' => 'ses', |
|
| 74 | - '/([ti])um$/i' => '\1a', |
|
| 75 | - '/(buffal|tomat)o$/i' => '\1oes', |
|
| 76 | - '/(bu)s$/i' => '\1ses', |
|
| 77 | - '/(alias|status)/i' => '\1es', |
|
| 78 | - '/(octop|vir)us$/i' => '\1i', |
|
| 79 | - '/(ax|test)is$/i' => '\1es', |
|
| 80 | - '/s$/i' => 's', |
|
| 81 | - '/$/' => 's'); |
|
| 82 | - |
|
| 83 | - $uncountable = array('equipment', 'information', 'rice', 'money', 'species', 'series', 'fish', 'sheep'); |
|
| 84 | - |
|
| 85 | - $irregular = array( |
|
| 86 | - 'person' => 'people', |
|
| 87 | - 'man' => 'men', |
|
| 88 | - 'child' => 'children', |
|
| 89 | - 'sex' => 'sexes', |
|
| 90 | - 'move' => 'moves'); |
|
| 91 | - |
|
| 92 | - $lowercased_word = strtolower($word); |
|
| 93 | - |
|
| 94 | - foreach($uncountable as $_uncountable){ |
|
| 95 | - if(substr($lowercased_word, (-1 * strlen($_uncountable))) == $_uncountable && //even though the word "price" ends in "rice", it can be pluralized, so check the previous character isnt a letter |
|
| 54 | + /** |
|
| 55 | + * Pluralizes English nouns. |
|
| 56 | + * |
|
| 57 | + * @access public |
|
| 58 | + * @static |
|
| 59 | + * @param string $word English noun to pluralize |
|
| 60 | + * @return string Plural noun |
|
| 61 | + */ |
|
| 62 | + static function pluralize($word){ |
|
| 63 | + $plural = array( |
|
| 64 | + '/(quiz)$/i' => '\1zes', |
|
| 65 | + '/^(ox)$/i' => '\1en', |
|
| 66 | + '/([m|l])ouse$/i' => '\1ice', |
|
| 67 | + '/(matr|vert|ind)ix|ex$/i' => '\1ices', |
|
| 68 | + '/(x|ch|ss|sh)$/i' => '\1es', |
|
| 69 | + '/([^aeiouy]|qu)ies$/i' => '\1y', |
|
| 70 | + '/([^aeiouy]|qu)y$/i' => '\1ies', |
|
| 71 | + '/(hive)$/i' => '\1s', |
|
| 72 | + '/(?:([^f])fe|([lr])f)$/i' => '\1\2ves', |
|
| 73 | + '/sis$/i' => 'ses', |
|
| 74 | + '/([ti])um$/i' => '\1a', |
|
| 75 | + '/(buffal|tomat)o$/i' => '\1oes', |
|
| 76 | + '/(bu)s$/i' => '\1ses', |
|
| 77 | + '/(alias|status)/i' => '\1es', |
|
| 78 | + '/(octop|vir)us$/i' => '\1i', |
|
| 79 | + '/(ax|test)is$/i' => '\1es', |
|
| 80 | + '/s$/i' => 's', |
|
| 81 | + '/$/' => 's'); |
|
| 82 | + |
|
| 83 | + $uncountable = array('equipment', 'information', 'rice', 'money', 'species', 'series', 'fish', 'sheep'); |
|
| 84 | + |
|
| 85 | + $irregular = array( |
|
| 86 | + 'person' => 'people', |
|
| 87 | + 'man' => 'men', |
|
| 88 | + 'child' => 'children', |
|
| 89 | + 'sex' => 'sexes', |
|
| 90 | + 'move' => 'moves'); |
|
| 91 | + |
|
| 92 | + $lowercased_word = strtolower($word); |
|
| 93 | + |
|
| 94 | + foreach($uncountable as $_uncountable){ |
|
| 95 | + if(substr($lowercased_word, (-1 * strlen($_uncountable))) == $_uncountable && //even though the word "price" ends in "rice", it can be pluralized, so check the previous character isnt a letter |
|
| 96 | 96 | ! ctype_alpha( $lowercased_word[ strlen( $lowercased_word ) - strlen($_uncountable) ] ) ){ |
| 97 | - return $word; |
|
| 98 | - } |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - foreach($irregular as $_plural => $_singular){ |
|
| 102 | - if(preg_match('/(' . $_plural . ')$/i', $word, $arr)){ |
|
| 103 | - return preg_replace('/(' . $_plural . ')$/i', substr($arr[0], 0, 1) . substr($_singular, 1), $word); |
|
| 104 | - } |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - foreach($plural as $rule => $replacement){ |
|
| 108 | - if(preg_match($rule, $word)){ |
|
| 109 | - return preg_replace($rule, $replacement, $word); |
|
| 110 | - } |
|
| 111 | - } |
|
| 112 | - return false; |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - // }}} |
|
| 116 | - // {{{ singularize() |
|
| 117 | - |
|
| 118 | - /** |
|
| 119 | - * Singularizes English nouns. |
|
| 120 | - * |
|
| 121 | - * @access public |
|
| 122 | - * @static |
|
| 123 | - * @param string $word English noun to singularize |
|
| 124 | - * @return string Singular noun. |
|
| 125 | - */ |
|
| 126 | - static function singularize($word){ |
|
| 127 | - $singular = array( |
|
| 128 | - '/(quiz)zes$/i' => '\1', |
|
| 129 | - '/(matr)ices$/i' => '\1ix', |
|
| 130 | - '/(vert|ind)ices$/i' => '\1ex', |
|
| 131 | - '/^(ox)en/i' => '\1', |
|
| 132 | - '/(alias|status)es$/i' => '\1', |
|
| 133 | - '/([octop|vir])i$/i' => '\1us', |
|
| 134 | - '/(cris|ax|test)es$/i' => '\1is', |
|
| 135 | - '/(shoe)s$/i' => '\1', |
|
| 136 | - '/(o)es$/i' => '\1', |
|
| 137 | - '/(bus)es$/i' => '\1', |
|
| 138 | - '/([m|l])ice$/i' => '\1ouse', |
|
| 139 | - '/(x|ch|ss|sh)es$/i' => '\1', |
|
| 140 | - '/(m)ovies$/i' => '\1ovie', |
|
| 141 | - '/(s)eries$/i' => '\1eries', |
|
| 142 | - '/([^aeiouy]|qu)ies$/i' => '\1y', |
|
| 143 | - '/([lr])ves$/i' => '\1f', |
|
| 144 | - '/(tive)s$/i' => '\1', |
|
| 145 | - '/(hive)s$/i' => '\1', |
|
| 146 | - '/([^f])ves$/i' => '\1fe', |
|
| 147 | - '/(^analy)ses$/i' => '\1sis', |
|
| 148 | - '/((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)ses$/i' => '\1\2sis', |
|
| 149 | - '/([ti])a$/i' => '\1um', |
|
| 150 | - '/(n)ews$/i' => '\1ews', |
|
| 151 | - '/s$/i' => '', |
|
| 152 | - ); |
|
| 153 | - |
|
| 154 | - $uncountable = array('equipment', 'information', 'rice', 'money', 'species', 'series', 'fish', 'sheep'); |
|
| 155 | - |
|
| 156 | - $irregular = array( |
|
| 157 | - 'person' => 'people', |
|
| 158 | - 'man' => 'men', |
|
| 159 | - 'child' => 'children', |
|
| 160 | - 'sex' => 'sexes', |
|
| 161 | - 'move' => 'moves'); |
|
| 162 | - |
|
| 163 | - $lowercased_word = strtolower($word); |
|
| 164 | - foreach($uncountable as $_uncountable){ |
|
| 165 | - if(substr($lowercased_word, (-1 * strlen($_uncountable))) == $_uncountable){ |
|
| 166 | - return $word; |
|
| 167 | - } |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - foreach($irregular as $_plural => $_singular){ |
|
| 171 | - if(preg_match('/(' . $_singular . ')$/i', $word, $arr)){ |
|
| 172 | - return preg_replace('/(' . $_singular . ')$/i', substr($arr[0], 0, 1) . substr($_plural, 1), $word); |
|
| 173 | - } |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - foreach($singular as $rule => $replacement){ |
|
| 177 | - if(preg_match($rule, $word)){ |
|
| 178 | - return preg_replace($rule, $replacement, $word); |
|
| 179 | - } |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - return $word; |
|
| 183 | - } |
|
| 184 | - |
|
| 185 | - // }}} |
|
| 186 | - // {{{ titleize() |
|
| 187 | - |
|
| 188 | - /** |
|
| 189 | - * Converts an underscored or CamelCase word into a English |
|
| 190 | - * sentence. |
|
| 191 | - * |
|
| 192 | - * The titleize static function converts text like "WelcomePage", |
|
| 193 | - * "welcome_page" or "welcome page" to this "Welcome |
|
| 194 | - * Page". |
|
| 195 | - * If second parameter is set to 'first' it will only |
|
| 196 | - * capitalize the first character of the title. |
|
| 197 | - * |
|
| 198 | - * @access public |
|
| 199 | - * @static |
|
| 200 | - * @param string $word Word to format as tile |
|
| 201 | - * @param string $uppercase If set to 'first' it will only uppercase the |
|
| 202 | - * first character. Otherwise it will uppercase all |
|
| 203 | - * the words in the title. |
|
| 204 | - * @return string Text formatted as title |
|
| 205 | - */ |
|
| 206 | - static function titleize($word, $uppercase = ''){ |
|
| 207 | - $uppercase = $uppercase == 'first' ? 'ucfirst' : 'ucwords'; |
|
| 208 | - return $uppercase(EEH_Inflector::humanize(EEH_Inflector::underscore($word))); |
|
| 209 | - } |
|
| 210 | - |
|
| 211 | - // }}} |
|
| 212 | - // {{{ camelize() |
|
| 213 | - |
|
| 214 | - /** |
|
| 215 | - * Returns given word as CamelCased |
|
| 216 | - * |
|
| 217 | - * Converts a word like "send_email" to "SendEmail". It |
|
| 218 | - * will remove non alphanumeric character from the word, so |
|
| 219 | - * "who's online" will be converted to "WhoSOnline" |
|
| 220 | - * |
|
| 221 | - * @access public |
|
| 222 | - * @static |
|
| 223 | - * @see variablize |
|
| 224 | - * @param string $word Word to convert to camel case |
|
| 225 | - * @return string UpperCamelCasedWord |
|
| 226 | - */ |
|
| 227 | - static function camelize($word){ |
|
| 228 | - return str_replace(' ', '', ucwords(preg_replace('/[^A-Z^a-z^0-9]+/', ' ', $word))); |
|
| 229 | - } |
|
| 230 | - |
|
| 231 | - // }}} |
|
| 232 | - // {{{ underscore() |
|
| 233 | - |
|
| 234 | - /** |
|
| 235 | - * Converts a word "into_it_s_underscored_version" |
|
| 236 | - * |
|
| 237 | - * Convert any "CamelCased" or "ordinary Word" into an |
|
| 238 | - * "underscored_word". |
|
| 239 | - * |
|
| 240 | - * This can be really useful for creating friendly URLs. |
|
| 241 | - * |
|
| 242 | - * @access public |
|
| 243 | - * @static |
|
| 244 | - * @param string $word Word to underscore |
|
| 245 | - * @return string Underscored word |
|
| 246 | - */ |
|
| 247 | - static function underscore($word){ |
|
| 248 | - return strtolower(preg_replace('/[^A-Z^a-z^0-9]+/', '_', preg_replace('/([a-zd])([A-Z])/', '1_2', preg_replace('/([A-Z]+)([A-Z][a-z])/', '1_2', $word)))); |
|
| 249 | - } |
|
| 250 | - |
|
| 251 | - // }}} |
|
| 252 | - // {{{ humanize() |
|
| 253 | - |
|
| 254 | - /** |
|
| 255 | - * Returns a human-readable string from $word |
|
| 256 | - * |
|
| 257 | - * Returns a human-readable string from $word, by replacing |
|
| 258 | - * underscores with a space, and by upper-casing the initial |
|
| 259 | - * character by default. |
|
| 260 | - * |
|
| 261 | - * If you need to uppercase all the words you just have to |
|
| 262 | - * pass 'all' as a second parameter. |
|
| 263 | - * |
|
| 264 | - * @access public |
|
| 265 | - * @static |
|
| 266 | - * @param string $word String to "humanize" |
|
| 267 | - * @param string $uppercase If set to 'all' it will uppercase all the words |
|
| 268 | - * instead of just the first one. |
|
| 269 | - * @return string Human-readable word |
|
| 270 | - */ |
|
| 271 | - static function humanize($word, $uppercase = ''){ |
|
| 97 | + return $word; |
|
| 98 | + } |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + foreach($irregular as $_plural => $_singular){ |
|
| 102 | + if(preg_match('/(' . $_plural . ')$/i', $word, $arr)){ |
|
| 103 | + return preg_replace('/(' . $_plural . ')$/i', substr($arr[0], 0, 1) . substr($_singular, 1), $word); |
|
| 104 | + } |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + foreach($plural as $rule => $replacement){ |
|
| 108 | + if(preg_match($rule, $word)){ |
|
| 109 | + return preg_replace($rule, $replacement, $word); |
|
| 110 | + } |
|
| 111 | + } |
|
| 112 | + return false; |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + // }}} |
|
| 116 | + // {{{ singularize() |
|
| 117 | + |
|
| 118 | + /** |
|
| 119 | + * Singularizes English nouns. |
|
| 120 | + * |
|
| 121 | + * @access public |
|
| 122 | + * @static |
|
| 123 | + * @param string $word English noun to singularize |
|
| 124 | + * @return string Singular noun. |
|
| 125 | + */ |
|
| 126 | + static function singularize($word){ |
|
| 127 | + $singular = array( |
|
| 128 | + '/(quiz)zes$/i' => '\1', |
|
| 129 | + '/(matr)ices$/i' => '\1ix', |
|
| 130 | + '/(vert|ind)ices$/i' => '\1ex', |
|
| 131 | + '/^(ox)en/i' => '\1', |
|
| 132 | + '/(alias|status)es$/i' => '\1', |
|
| 133 | + '/([octop|vir])i$/i' => '\1us', |
|
| 134 | + '/(cris|ax|test)es$/i' => '\1is', |
|
| 135 | + '/(shoe)s$/i' => '\1', |
|
| 136 | + '/(o)es$/i' => '\1', |
|
| 137 | + '/(bus)es$/i' => '\1', |
|
| 138 | + '/([m|l])ice$/i' => '\1ouse', |
|
| 139 | + '/(x|ch|ss|sh)es$/i' => '\1', |
|
| 140 | + '/(m)ovies$/i' => '\1ovie', |
|
| 141 | + '/(s)eries$/i' => '\1eries', |
|
| 142 | + '/([^aeiouy]|qu)ies$/i' => '\1y', |
|
| 143 | + '/([lr])ves$/i' => '\1f', |
|
| 144 | + '/(tive)s$/i' => '\1', |
|
| 145 | + '/(hive)s$/i' => '\1', |
|
| 146 | + '/([^f])ves$/i' => '\1fe', |
|
| 147 | + '/(^analy)ses$/i' => '\1sis', |
|
| 148 | + '/((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)ses$/i' => '\1\2sis', |
|
| 149 | + '/([ti])a$/i' => '\1um', |
|
| 150 | + '/(n)ews$/i' => '\1ews', |
|
| 151 | + '/s$/i' => '', |
|
| 152 | + ); |
|
| 153 | + |
|
| 154 | + $uncountable = array('equipment', 'information', 'rice', 'money', 'species', 'series', 'fish', 'sheep'); |
|
| 155 | + |
|
| 156 | + $irregular = array( |
|
| 157 | + 'person' => 'people', |
|
| 158 | + 'man' => 'men', |
|
| 159 | + 'child' => 'children', |
|
| 160 | + 'sex' => 'sexes', |
|
| 161 | + 'move' => 'moves'); |
|
| 162 | + |
|
| 163 | + $lowercased_word = strtolower($word); |
|
| 164 | + foreach($uncountable as $_uncountable){ |
|
| 165 | + if(substr($lowercased_word, (-1 * strlen($_uncountable))) == $_uncountable){ |
|
| 166 | + return $word; |
|
| 167 | + } |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + foreach($irregular as $_plural => $_singular){ |
|
| 171 | + if(preg_match('/(' . $_singular . ')$/i', $word, $arr)){ |
|
| 172 | + return preg_replace('/(' . $_singular . ')$/i', substr($arr[0], 0, 1) . substr($_plural, 1), $word); |
|
| 173 | + } |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + foreach($singular as $rule => $replacement){ |
|
| 177 | + if(preg_match($rule, $word)){ |
|
| 178 | + return preg_replace($rule, $replacement, $word); |
|
| 179 | + } |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + return $word; |
|
| 183 | + } |
|
| 184 | + |
|
| 185 | + // }}} |
|
| 186 | + // {{{ titleize() |
|
| 187 | + |
|
| 188 | + /** |
|
| 189 | + * Converts an underscored or CamelCase word into a English |
|
| 190 | + * sentence. |
|
| 191 | + * |
|
| 192 | + * The titleize static function converts text like "WelcomePage", |
|
| 193 | + * "welcome_page" or "welcome page" to this "Welcome |
|
| 194 | + * Page". |
|
| 195 | + * If second parameter is set to 'first' it will only |
|
| 196 | + * capitalize the first character of the title. |
|
| 197 | + * |
|
| 198 | + * @access public |
|
| 199 | + * @static |
|
| 200 | + * @param string $word Word to format as tile |
|
| 201 | + * @param string $uppercase If set to 'first' it will only uppercase the |
|
| 202 | + * first character. Otherwise it will uppercase all |
|
| 203 | + * the words in the title. |
|
| 204 | + * @return string Text formatted as title |
|
| 205 | + */ |
|
| 206 | + static function titleize($word, $uppercase = ''){ |
|
| 207 | + $uppercase = $uppercase == 'first' ? 'ucfirst' : 'ucwords'; |
|
| 208 | + return $uppercase(EEH_Inflector::humanize(EEH_Inflector::underscore($word))); |
|
| 209 | + } |
|
| 210 | + |
|
| 211 | + // }}} |
|
| 212 | + // {{{ camelize() |
|
| 213 | + |
|
| 214 | + /** |
|
| 215 | + * Returns given word as CamelCased |
|
| 216 | + * |
|
| 217 | + * Converts a word like "send_email" to "SendEmail". It |
|
| 218 | + * will remove non alphanumeric character from the word, so |
|
| 219 | + * "who's online" will be converted to "WhoSOnline" |
|
| 220 | + * |
|
| 221 | + * @access public |
|
| 222 | + * @static |
|
| 223 | + * @see variablize |
|
| 224 | + * @param string $word Word to convert to camel case |
|
| 225 | + * @return string UpperCamelCasedWord |
|
| 226 | + */ |
|
| 227 | + static function camelize($word){ |
|
| 228 | + return str_replace(' ', '', ucwords(preg_replace('/[^A-Z^a-z^0-9]+/', ' ', $word))); |
|
| 229 | + } |
|
| 230 | + |
|
| 231 | + // }}} |
|
| 232 | + // {{{ underscore() |
|
| 233 | + |
|
| 234 | + /** |
|
| 235 | + * Converts a word "into_it_s_underscored_version" |
|
| 236 | + * |
|
| 237 | + * Convert any "CamelCased" or "ordinary Word" into an |
|
| 238 | + * "underscored_word". |
|
| 239 | + * |
|
| 240 | + * This can be really useful for creating friendly URLs. |
|
| 241 | + * |
|
| 242 | + * @access public |
|
| 243 | + * @static |
|
| 244 | + * @param string $word Word to underscore |
|
| 245 | + * @return string Underscored word |
|
| 246 | + */ |
|
| 247 | + static function underscore($word){ |
|
| 248 | + return strtolower(preg_replace('/[^A-Z^a-z^0-9]+/', '_', preg_replace('/([a-zd])([A-Z])/', '1_2', preg_replace('/([A-Z]+)([A-Z][a-z])/', '1_2', $word)))); |
|
| 249 | + } |
|
| 250 | + |
|
| 251 | + // }}} |
|
| 252 | + // {{{ humanize() |
|
| 253 | + |
|
| 254 | + /** |
|
| 255 | + * Returns a human-readable string from $word |
|
| 256 | + * |
|
| 257 | + * Returns a human-readable string from $word, by replacing |
|
| 258 | + * underscores with a space, and by upper-casing the initial |
|
| 259 | + * character by default. |
|
| 260 | + * |
|
| 261 | + * If you need to uppercase all the words you just have to |
|
| 262 | + * pass 'all' as a second parameter. |
|
| 263 | + * |
|
| 264 | + * @access public |
|
| 265 | + * @static |
|
| 266 | + * @param string $word String to "humanize" |
|
| 267 | + * @param string $uppercase If set to 'all' it will uppercase all the words |
|
| 268 | + * instead of just the first one. |
|
| 269 | + * @return string Human-readable word |
|
| 270 | + */ |
|
| 271 | + static function humanize($word, $uppercase = ''){ |
|
| 272 | 272 | //make special exceptions for acronyms |
| 273 | 273 | $word = str_replace('wp_', 'WP_', $word ); |
| 274 | - $uppercase = $uppercase == 'all' ? 'ucwords' : 'ucfirst'; |
|
| 275 | - return $uppercase(str_replace('_', ' ', preg_replace('/_id$/', '', $word))); |
|
| 276 | - } |
|
| 277 | - |
|
| 278 | - // }}} |
|
| 279 | - // {{{ variablize() |
|
| 280 | - |
|
| 281 | - /** |
|
| 282 | - * Same as camelize but first char is underscored |
|
| 283 | - * |
|
| 284 | - * Converts a word like "send_email" to "sendEmail". It |
|
| 285 | - * will remove non alphanumeric character from the word, so |
|
| 286 | - * "who's online" will be converted to "whoSOnline" |
|
| 287 | - * |
|
| 288 | - * @access public |
|
| 289 | - * @static |
|
| 290 | - * @see camelize |
|
| 291 | - * @param string $word Word to lowerCamelCase |
|
| 292 | - * @return string Returns a lowerCamelCasedWord |
|
| 293 | - */ |
|
| 294 | - static function variablize($word){ |
|
| 295 | - $word = EEH_Inflector::camelize($word); |
|
| 296 | - return strtolower($word[0]) . substr($word, 1); |
|
| 297 | - } |
|
| 298 | - |
|
| 299 | - // }}} |
|
| 300 | - // {{{ tableize() |
|
| 301 | - |
|
| 302 | - /** |
|
| 303 | - * Converts a class name to its table name according to rails |
|
| 304 | - * naming conventions. |
|
| 305 | - * |
|
| 306 | - * Converts "Person" to "people" |
|
| 307 | - * |
|
| 308 | - * @access public |
|
| 309 | - * @static |
|
| 310 | - * @see classify |
|
| 311 | - * @param string $class_name Class name for getting related table_name. |
|
| 312 | - * @return string plural_table_name |
|
| 313 | - */ |
|
| 314 | - static function tableize($class_name){ |
|
| 315 | - return EEH_Inflector::pluralize(EEH_Inflector::underscore($class_name)); |
|
| 316 | - } |
|
| 317 | - |
|
| 318 | - // }}} |
|
| 319 | - // {{{ classify() |
|
| 320 | - |
|
| 321 | - /** |
|
| 322 | - * Converts a table name to its class name according to rails |
|
| 323 | - * naming conventions. |
|
| 324 | - * |
|
| 325 | - * Converts "people" to "Person" |
|
| 326 | - * |
|
| 327 | - * @access public |
|
| 328 | - * @static |
|
| 329 | - * @see tableize |
|
| 330 | - * @param string $table_name Table name for getting related ClassName. |
|
| 331 | - * @return string SingularClassName |
|
| 332 | - */ |
|
| 333 | - static function classify($table_name){ |
|
| 334 | - return EEH_Inflector::camelize(EEH_Inflector::singularize($table_name)); |
|
| 335 | - } |
|
| 336 | - |
|
| 337 | - // }}} |
|
| 338 | - // {{{ ordinalize() |
|
| 339 | - |
|
| 340 | - /** |
|
| 341 | - * Converts number to its ordinal English form. |
|
| 342 | - * |
|
| 343 | - * This method converts 13 to 13th, 2 to 2nd ... |
|
| 344 | - * |
|
| 345 | - * @access public |
|
| 346 | - * @static |
|
| 347 | - * @param integer $number Number to get its ordinal value |
|
| 348 | - * @return string Ordinal representation of given string. |
|
| 349 | - */ |
|
| 350 | - static function ordinalize($number){ |
|
| 351 | - if(in_array(($number % 100), range(11, 13))){ |
|
| 352 | - return $number . 'th'; |
|
| 353 | - }else{ |
|
| 354 | - switch(($number % 10)){ |
|
| 355 | - case 1: |
|
| 356 | - return $number . 'st'; |
|
| 357 | - break; |
|
| 358 | - case 2: |
|
| 359 | - return $number . 'nd'; |
|
| 360 | - break; |
|
| 361 | - case 3: |
|
| 362 | - return $number . 'rd'; |
|
| 363 | - default: |
|
| 364 | - return $number . 'th'; |
|
| 365 | - break; |
|
| 366 | - } |
|
| 367 | - } |
|
| 368 | - } |
|
| 274 | + $uppercase = $uppercase == 'all' ? 'ucwords' : 'ucfirst'; |
|
| 275 | + return $uppercase(str_replace('_', ' ', preg_replace('/_id$/', '', $word))); |
|
| 276 | + } |
|
| 277 | + |
|
| 278 | + // }}} |
|
| 279 | + // {{{ variablize() |
|
| 280 | + |
|
| 281 | + /** |
|
| 282 | + * Same as camelize but first char is underscored |
|
| 283 | + * |
|
| 284 | + * Converts a word like "send_email" to "sendEmail". It |
|
| 285 | + * will remove non alphanumeric character from the word, so |
|
| 286 | + * "who's online" will be converted to "whoSOnline" |
|
| 287 | + * |
|
| 288 | + * @access public |
|
| 289 | + * @static |
|
| 290 | + * @see camelize |
|
| 291 | + * @param string $word Word to lowerCamelCase |
|
| 292 | + * @return string Returns a lowerCamelCasedWord |
|
| 293 | + */ |
|
| 294 | + static function variablize($word){ |
|
| 295 | + $word = EEH_Inflector::camelize($word); |
|
| 296 | + return strtolower($word[0]) . substr($word, 1); |
|
| 297 | + } |
|
| 298 | + |
|
| 299 | + // }}} |
|
| 300 | + // {{{ tableize() |
|
| 301 | + |
|
| 302 | + /** |
|
| 303 | + * Converts a class name to its table name according to rails |
|
| 304 | + * naming conventions. |
|
| 305 | + * |
|
| 306 | + * Converts "Person" to "people" |
|
| 307 | + * |
|
| 308 | + * @access public |
|
| 309 | + * @static |
|
| 310 | + * @see classify |
|
| 311 | + * @param string $class_name Class name for getting related table_name. |
|
| 312 | + * @return string plural_table_name |
|
| 313 | + */ |
|
| 314 | + static function tableize($class_name){ |
|
| 315 | + return EEH_Inflector::pluralize(EEH_Inflector::underscore($class_name)); |
|
| 316 | + } |
|
| 317 | + |
|
| 318 | + // }}} |
|
| 319 | + // {{{ classify() |
|
| 320 | + |
|
| 321 | + /** |
|
| 322 | + * Converts a table name to its class name according to rails |
|
| 323 | + * naming conventions. |
|
| 324 | + * |
|
| 325 | + * Converts "people" to "Person" |
|
| 326 | + * |
|
| 327 | + * @access public |
|
| 328 | + * @static |
|
| 329 | + * @see tableize |
|
| 330 | + * @param string $table_name Table name for getting related ClassName. |
|
| 331 | + * @return string SingularClassName |
|
| 332 | + */ |
|
| 333 | + static function classify($table_name){ |
|
| 334 | + return EEH_Inflector::camelize(EEH_Inflector::singularize($table_name)); |
|
| 335 | + } |
|
| 336 | + |
|
| 337 | + // }}} |
|
| 338 | + // {{{ ordinalize() |
|
| 339 | + |
|
| 340 | + /** |
|
| 341 | + * Converts number to its ordinal English form. |
|
| 342 | + * |
|
| 343 | + * This method converts 13 to 13th, 2 to 2nd ... |
|
| 344 | + * |
|
| 345 | + * @access public |
|
| 346 | + * @static |
|
| 347 | + * @param integer $number Number to get its ordinal value |
|
| 348 | + * @return string Ordinal representation of given string. |
|
| 349 | + */ |
|
| 350 | + static function ordinalize($number){ |
|
| 351 | + if(in_array(($number % 100), range(11, 13))){ |
|
| 352 | + return $number . 'th'; |
|
| 353 | + }else{ |
|
| 354 | + switch(($number % 10)){ |
|
| 355 | + case 1: |
|
| 356 | + return $number . 'st'; |
|
| 357 | + break; |
|
| 358 | + case 2: |
|
| 359 | + return $number . 'nd'; |
|
| 360 | + break; |
|
| 361 | + case 3: |
|
| 362 | + return $number . 'rd'; |
|
| 363 | + default: |
|
| 364 | + return $number . 'th'; |
|
| 365 | + break; |
|
| 366 | + } |
|
| 367 | + } |
|
| 368 | + } |
|
| 369 | 369 | } |
| 370 | 370 | \ No newline at end of file |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( !defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
| 3 | - exit( 'No direct script access allowed' ); |
|
| 2 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 3 | + exit('No direct script access allowed'); |
|
| 4 | 4 | } |
| 5 | 5 | |
| 6 | 6 | // +----------------------------------------------------------------------+ |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | * @since 0.1 |
| 35 | 35 | * @version $Revision 0.1 $ |
| 36 | 36 | */ |
| 37 | -class EEH_Inflector{ |
|
| 37 | +class EEH_Inflector { |
|
| 38 | 38 | // ------ CLASS METHODS ------ // |
| 39 | 39 | // ---- Public methods ---- // |
| 40 | 40 | // {{{ pluralize() |
@@ -44,12 +44,12 @@ discard block |
||
| 44 | 44 | * @param string $word |
| 45 | 45 | * @return string |
| 46 | 46 | */ |
| 47 | - static function pluralize_and_lower( $word ){ |
|
| 48 | - return strtolower( self::pluralize( $word ) ); |
|
| 47 | + static function pluralize_and_lower($word) { |
|
| 48 | + return strtolower(self::pluralize($word)); |
|
| 49 | 49 | } |
| 50 | 50 | |
| 51 | - static function singularize_and_upper( $word ) { |
|
| 52 | - return str_replace( ' ', '_', self::humanize( self::singularize( $word ), 'all' ) ); |
|
| 51 | + static function singularize_and_upper($word) { |
|
| 52 | + return str_replace(' ', '_', self::humanize(self::singularize($word), 'all')); |
|
| 53 | 53 | } |
| 54 | 54 | /** |
| 55 | 55 | * Pluralizes English nouns. |
@@ -59,7 +59,7 @@ discard block |
||
| 59 | 59 | * @param string $word English noun to pluralize |
| 60 | 60 | * @return string Plural noun |
| 61 | 61 | */ |
| 62 | - static function pluralize($word){ |
|
| 62 | + static function pluralize($word) { |
|
| 63 | 63 | $plural = array( |
| 64 | 64 | '/(quiz)$/i' => '\1zes', |
| 65 | 65 | '/^(ox)$/i' => '\1en', |
@@ -91,21 +91,21 @@ discard block |
||
| 91 | 91 | |
| 92 | 92 | $lowercased_word = strtolower($word); |
| 93 | 93 | |
| 94 | - foreach($uncountable as $_uncountable){ |
|
| 95 | - if(substr($lowercased_word, (-1 * strlen($_uncountable))) == $_uncountable && //even though the word "price" ends in "rice", it can be pluralized, so check the previous character isnt a letter |
|
| 96 | - ! ctype_alpha( $lowercased_word[ strlen( $lowercased_word ) - strlen($_uncountable) ] ) ){ |
|
| 94 | + foreach ($uncountable as $_uncountable) { |
|
| 95 | + if (substr($lowercased_word, (-1 * strlen($_uncountable))) == $_uncountable && //even though the word "price" ends in "rice", it can be pluralized, so check the previous character isnt a letter |
|
| 96 | + ! ctype_alpha($lowercased_word[strlen($lowercased_word) - strlen($_uncountable)])) { |
|
| 97 | 97 | return $word; |
| 98 | 98 | } |
| 99 | 99 | } |
| 100 | 100 | |
| 101 | - foreach($irregular as $_plural => $_singular){ |
|
| 102 | - if(preg_match('/(' . $_plural . ')$/i', $word, $arr)){ |
|
| 103 | - return preg_replace('/(' . $_plural . ')$/i', substr($arr[0], 0, 1) . substr($_singular, 1), $word); |
|
| 101 | + foreach ($irregular as $_plural => $_singular) { |
|
| 102 | + if (preg_match('/('.$_plural.')$/i', $word, $arr)) { |
|
| 103 | + return preg_replace('/('.$_plural.')$/i', substr($arr[0], 0, 1).substr($_singular, 1), $word); |
|
| 104 | 104 | } |
| 105 | 105 | } |
| 106 | 106 | |
| 107 | - foreach($plural as $rule => $replacement){ |
|
| 108 | - if(preg_match($rule, $word)){ |
|
| 107 | + foreach ($plural as $rule => $replacement) { |
|
| 108 | + if (preg_match($rule, $word)) { |
|
| 109 | 109 | return preg_replace($rule, $replacement, $word); |
| 110 | 110 | } |
| 111 | 111 | } |
@@ -123,7 +123,7 @@ discard block |
||
| 123 | 123 | * @param string $word English noun to singularize |
| 124 | 124 | * @return string Singular noun. |
| 125 | 125 | */ |
| 126 | - static function singularize($word){ |
|
| 126 | + static function singularize($word) { |
|
| 127 | 127 | $singular = array( |
| 128 | 128 | '/(quiz)zes$/i' => '\1', |
| 129 | 129 | '/(matr)ices$/i' => '\1ix', |
@@ -161,20 +161,20 @@ discard block |
||
| 161 | 161 | 'move' => 'moves'); |
| 162 | 162 | |
| 163 | 163 | $lowercased_word = strtolower($word); |
| 164 | - foreach($uncountable as $_uncountable){ |
|
| 165 | - if(substr($lowercased_word, (-1 * strlen($_uncountable))) == $_uncountable){ |
|
| 164 | + foreach ($uncountable as $_uncountable) { |
|
| 165 | + if (substr($lowercased_word, (-1 * strlen($_uncountable))) == $_uncountable) { |
|
| 166 | 166 | return $word; |
| 167 | 167 | } |
| 168 | 168 | } |
| 169 | 169 | |
| 170 | - foreach($irregular as $_plural => $_singular){ |
|
| 171 | - if(preg_match('/(' . $_singular . ')$/i', $word, $arr)){ |
|
| 172 | - return preg_replace('/(' . $_singular . ')$/i', substr($arr[0], 0, 1) . substr($_plural, 1), $word); |
|
| 170 | + foreach ($irregular as $_plural => $_singular) { |
|
| 171 | + if (preg_match('/('.$_singular.')$/i', $word, $arr)) { |
|
| 172 | + return preg_replace('/('.$_singular.')$/i', substr($arr[0], 0, 1).substr($_plural, 1), $word); |
|
| 173 | 173 | } |
| 174 | 174 | } |
| 175 | 175 | |
| 176 | - foreach($singular as $rule => $replacement){ |
|
| 177 | - if(preg_match($rule, $word)){ |
|
| 176 | + foreach ($singular as $rule => $replacement) { |
|
| 177 | + if (preg_match($rule, $word)) { |
|
| 178 | 178 | return preg_replace($rule, $replacement, $word); |
| 179 | 179 | } |
| 180 | 180 | } |
@@ -203,7 +203,7 @@ discard block |
||
| 203 | 203 | * the words in the title. |
| 204 | 204 | * @return string Text formatted as title |
| 205 | 205 | */ |
| 206 | - static function titleize($word, $uppercase = ''){ |
|
| 206 | + static function titleize($word, $uppercase = '') { |
|
| 207 | 207 | $uppercase = $uppercase == 'first' ? 'ucfirst' : 'ucwords'; |
| 208 | 208 | return $uppercase(EEH_Inflector::humanize(EEH_Inflector::underscore($word))); |
| 209 | 209 | } |
@@ -224,7 +224,7 @@ discard block |
||
| 224 | 224 | * @param string $word Word to convert to camel case |
| 225 | 225 | * @return string UpperCamelCasedWord |
| 226 | 226 | */ |
| 227 | - static function camelize($word){ |
|
| 227 | + static function camelize($word) { |
|
| 228 | 228 | return str_replace(' ', '', ucwords(preg_replace('/[^A-Z^a-z^0-9]+/', ' ', $word))); |
| 229 | 229 | } |
| 230 | 230 | |
@@ -244,7 +244,7 @@ discard block |
||
| 244 | 244 | * @param string $word Word to underscore |
| 245 | 245 | * @return string Underscored word |
| 246 | 246 | */ |
| 247 | - static function underscore($word){ |
|
| 247 | + static function underscore($word) { |
|
| 248 | 248 | return strtolower(preg_replace('/[^A-Z^a-z^0-9]+/', '_', preg_replace('/([a-zd])([A-Z])/', '1_2', preg_replace('/([A-Z]+)([A-Z][a-z])/', '1_2', $word)))); |
| 249 | 249 | } |
| 250 | 250 | |
@@ -268,9 +268,9 @@ discard block |
||
| 268 | 268 | * instead of just the first one. |
| 269 | 269 | * @return string Human-readable word |
| 270 | 270 | */ |
| 271 | - static function humanize($word, $uppercase = ''){ |
|
| 271 | + static function humanize($word, $uppercase = '') { |
|
| 272 | 272 | //make special exceptions for acronyms |
| 273 | - $word = str_replace('wp_', 'WP_', $word ); |
|
| 273 | + $word = str_replace('wp_', 'WP_', $word); |
|
| 274 | 274 | $uppercase = $uppercase == 'all' ? 'ucwords' : 'ucfirst'; |
| 275 | 275 | return $uppercase(str_replace('_', ' ', preg_replace('/_id$/', '', $word))); |
| 276 | 276 | } |
@@ -291,9 +291,9 @@ discard block |
||
| 291 | 291 | * @param string $word Word to lowerCamelCase |
| 292 | 292 | * @return string Returns a lowerCamelCasedWord |
| 293 | 293 | */ |
| 294 | - static function variablize($word){ |
|
| 294 | + static function variablize($word) { |
|
| 295 | 295 | $word = EEH_Inflector::camelize($word); |
| 296 | - return strtolower($word[0]) . substr($word, 1); |
|
| 296 | + return strtolower($word[0]).substr($word, 1); |
|
| 297 | 297 | } |
| 298 | 298 | |
| 299 | 299 | // }}} |
@@ -311,7 +311,7 @@ discard block |
||
| 311 | 311 | * @param string $class_name Class name for getting related table_name. |
| 312 | 312 | * @return string plural_table_name |
| 313 | 313 | */ |
| 314 | - static function tableize($class_name){ |
|
| 314 | + static function tableize($class_name) { |
|
| 315 | 315 | return EEH_Inflector::pluralize(EEH_Inflector::underscore($class_name)); |
| 316 | 316 | } |
| 317 | 317 | |
@@ -330,7 +330,7 @@ discard block |
||
| 330 | 330 | * @param string $table_name Table name for getting related ClassName. |
| 331 | 331 | * @return string SingularClassName |
| 332 | 332 | */ |
| 333 | - static function classify($table_name){ |
|
| 333 | + static function classify($table_name) { |
|
| 334 | 334 | return EEH_Inflector::camelize(EEH_Inflector::singularize($table_name)); |
| 335 | 335 | } |
| 336 | 336 | |
@@ -347,21 +347,21 @@ discard block |
||
| 347 | 347 | * @param integer $number Number to get its ordinal value |
| 348 | 348 | * @return string Ordinal representation of given string. |
| 349 | 349 | */ |
| 350 | - static function ordinalize($number){ |
|
| 351 | - if(in_array(($number % 100), range(11, 13))){ |
|
| 352 | - return $number . 'th'; |
|
| 353 | - }else{ |
|
| 354 | - switch(($number % 10)){ |
|
| 350 | + static function ordinalize($number) { |
|
| 351 | + if (in_array(($number % 100), range(11, 13))) { |
|
| 352 | + return $number.'th'; |
|
| 353 | + } else { |
|
| 354 | + switch (($number % 10)) { |
|
| 355 | 355 | case 1: |
| 356 | - return $number . 'st'; |
|
| 356 | + return $number.'st'; |
|
| 357 | 357 | break; |
| 358 | 358 | case 2: |
| 359 | - return $number . 'nd'; |
|
| 359 | + return $number.'nd'; |
|
| 360 | 360 | break; |
| 361 | 361 | case 3: |
| 362 | - return $number . 'rd'; |
|
| 362 | + return $number.'rd'; |
|
| 363 | 363 | default: |
| 364 | - return $number . 'th'; |
|
| 364 | + return $number.'th'; |
|
| 365 | 365 | break; |
| 366 | 366 | } |
| 367 | 367 | } |
@@ -350,7 +350,7 @@ |
||
| 350 | 350 | static function ordinalize($number){ |
| 351 | 351 | if(in_array(($number % 100), range(11, 13))){ |
| 352 | 352 | return $number . 'th'; |
| 353 | - }else{ |
|
| 353 | + } else{ |
|
| 354 | 354 | switch(($number % 10)){ |
| 355 | 355 | case 1: |
| 356 | 356 | return $number . 'st'; |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -if (!defined('EVENT_ESPRESSO_VERSION') ) |
|
| 3 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) |
|
| 4 | 4 | exit('NO direct script access allowed'); |
| 5 | 5 | |
| 6 | 6 | /** |
@@ -46,20 +46,20 @@ discard block |
||
| 46 | 46 | * @throws \EE_Error |
| 47 | 47 | * @return array|bool array of data required for the redirect to the correct edit page or FALSE if encountering problems. |
| 48 | 48 | */ |
| 49 | - public static function generate_new_templates($messenger, $message_types, $GRP_ID = 0, $global = FALSE) { |
|
| 49 | + public static function generate_new_templates($messenger, $message_types, $GRP_ID = 0, $global = FALSE) { |
|
| 50 | 50 | |
| 51 | 51 | //make sure message_type is an array. |
| 52 | 52 | $message_types = (array) $message_types; |
| 53 | 53 | $templates = array(); |
| 54 | 54 | $success = TRUE; |
| 55 | 55 | |
| 56 | - if ( empty($messenger) ) { |
|
| 57 | - throw new EE_Error( __('We need a messenger to generate templates!', 'event_espresso') ); |
|
| 56 | + if (empty($messenger)) { |
|
| 57 | + throw new EE_Error(__('We need a messenger to generate templates!', 'event_espresso')); |
|
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | //if we STILL have empty $message_types then we need to generate an error message b/c we NEED message types to do the template files. |
| 61 | - if ( empty($message_types) ) { |
|
| 62 | - throw new EE_Error( __('We need at least one message type to generate templates!', 'event_espresso') ); |
|
| 61 | + if (empty($message_types)) { |
|
| 62 | + throw new EE_Error(__('We need at least one message type to generate templates!', 'event_espresso')); |
|
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | self::_set_autoloader(); |
@@ -67,25 +67,25 @@ discard block |
||
| 67 | 67 | |
| 68 | 68 | $MSG = new EE_messages(); |
| 69 | 69 | |
| 70 | - foreach ( $message_types as $message_type ) { |
|
| 70 | + foreach ($message_types as $message_type) { |
|
| 71 | 71 | //if global then let's attempt to get the GRP_ID for this combo IF GRP_ID is empty. |
| 72 | - if ( $global && empty( $GRP_ID ) ) { |
|
| 73 | - $GRP_ID = EEM_Message_Template_Group::instance()->get_one( array( array( 'MTP_messenger' => $messenger, 'MTP_message_type' => $message_type, 'MTP_is_global' => TRUE ) ) ); |
|
| 72 | + if ($global && empty($GRP_ID)) { |
|
| 73 | + $GRP_ID = EEM_Message_Template_Group::instance()->get_one(array(array('MTP_messenger' => $messenger, 'MTP_message_type' => $message_type, 'MTP_is_global' => TRUE))); |
|
| 74 | 74 | $GRP_ID = $GRP_ID instanceof EE_Message_Template_Group ? $GRP_ID->ID() : 0; |
| 75 | 75 | } |
| 76 | 76 | //if this is global template generation. First let's determine if we already HAVE global templates for this messenger and message_type combination. If we do then NO generation!! |
| 77 | - if ( $global && self::already_generated($messenger, $message_type, $GRP_ID ) ) { |
|
| 77 | + if ($global && self::already_generated($messenger, $message_type, $GRP_ID)) { |
|
| 78 | 78 | $templates = TRUE; |
| 79 | 79 | continue; //get out we've already got generated templates for this. |
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | $new_message_template_group = $MSG->create_new_templates($messenger, $message_type, $GRP_ID, $global); |
| 83 | 83 | |
| 84 | - if ( !$new_message_template_group ) { |
|
| 84 | + if ( ! $new_message_template_group) { |
|
| 85 | 85 | $success = FALSE; |
| 86 | 86 | continue; |
| 87 | 87 | } |
| 88 | - if ( $templates === TRUE ) $templates = array(); |
|
| 88 | + if ($templates === TRUE) $templates = array(); |
|
| 89 | 89 | $templates[] = $new_message_template_group; |
| 90 | 90 | } |
| 91 | 91 | |
@@ -101,18 +101,18 @@ discard block |
||
| 101 | 101 | * @param bool $update_to_active if true then we also toggle the template to active. |
| 102 | 102 | * @return bool true = generated, false = hasn't been generated. |
| 103 | 103 | */ |
| 104 | - public static function already_generated( $messenger, $message_type, $GRP_ID = 0, $update_to_active = TRUE ) { |
|
| 104 | + public static function already_generated($messenger, $message_type, $GRP_ID = 0, $update_to_active = TRUE) { |
|
| 105 | 105 | self::_set_autoloader(); |
| 106 | 106 | $MTP = EEM_Message_Template::instance(); |
| 107 | 107 | |
| 108 | 108 | //what method we use depends on whether we have an GRP_ID or not |
| 109 | - $count = empty( $GRP_ID ) ? EEM_Message_Template::instance()->count( array( array( 'Message_Template_Group.MTP_messenger' => $messenger, 'Message_Template_Group.MTP_message_type' => $message_type, 'Message_Template_Group.MTP_is_global' => TRUE ) ) ) : $MTP->count( array( array( 'GRP_ID' => $GRP_ID ) ) ); |
|
| 109 | + $count = empty($GRP_ID) ? EEM_Message_Template::instance()->count(array(array('Message_Template_Group.MTP_messenger' => $messenger, 'Message_Template_Group.MTP_message_type' => $message_type, 'Message_Template_Group.MTP_is_global' => TRUE))) : $MTP->count(array(array('GRP_ID' => $GRP_ID))); |
|
| 110 | 110 | |
| 111 | - if ( $update_to_active ) { |
|
| 112 | - self::update_to_active( $messenger, $message_type ); |
|
| 111 | + if ($update_to_active) { |
|
| 112 | + self::update_to_active($messenger, $message_type); |
|
| 113 | 113 | } |
| 114 | 114 | |
| 115 | - return ( $count > 0 ) ? TRUE : FALSE; |
|
| 115 | + return ($count > 0) ? TRUE : FALSE; |
|
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | |
@@ -126,8 +126,8 @@ discard block |
||
| 126 | 126 | * @static |
| 127 | 127 | * @return int count of updated records. |
| 128 | 128 | */ |
| 129 | - public static function update_to_active( $messenger, $message_type ) { |
|
| 130 | - return EEM_Message_Template_Group::instance()->update( array('MTP_is_active' => 1), array(array('MTP_messenger' => $messenger, 'MTP_message_type' => $message_type )) ); |
|
| 129 | + public static function update_to_active($messenger, $message_type) { |
|
| 130 | + return EEM_Message_Template_Group::instance()->update(array('MTP_is_active' => 1), array(array('MTP_messenger' => $messenger, 'MTP_message_type' => $message_type))); |
|
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | |
@@ -140,18 +140,18 @@ discard block |
||
| 140 | 140 | * |
| 141 | 141 | * @return int count of updated records. |
| 142 | 142 | */ |
| 143 | - public static function update_to_inactive( $messenger = '', $message_type = '' ) { |
|
| 143 | + public static function update_to_inactive($messenger = '', $message_type = '') { |
|
| 144 | 144 | $query_args = array(); |
| 145 | - if ( empty( $messenger ) && empty( $message_type ) ) |
|
| 145 | + if (empty($messenger) && empty($message_type)) |
|
| 146 | 146 | return 0; |
| 147 | - if ( ! empty( $messenger ) ) { |
|
| 147 | + if ( ! empty($messenger)) { |
|
| 148 | 148 | $query_args[0]['MTP_messenger'] = $messenger; |
| 149 | 149 | } |
| 150 | 150 | |
| 151 | - if ( ! empty( $message_type ) ) { |
|
| 151 | + if ( ! empty($message_type)) { |
|
| 152 | 152 | $query_args[0]['MTP_message_type'] = $message_type; |
| 153 | 153 | } |
| 154 | - return EEM_Message_Template_Group::instance()->update( array( 'MTP_is_active' => FALSE ), $query_args ); |
|
| 154 | + return EEM_Message_Template_Group::instance()->update(array('MTP_is_active' => FALSE), $query_args); |
|
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | |
@@ -189,39 +189,39 @@ discard block |
||
| 189 | 189 | * OR |
| 190 | 190 | * FALSE if no shortcodes found. |
| 191 | 191 | */ |
| 192 | - public static function get_shortcodes( $message_type, $messenger, $fields = array(), $context = 'admin', $merged = FALSE ) { |
|
| 192 | + public static function get_shortcodes($message_type, $messenger, $fields = array(), $context = 'admin', $merged = FALSE) { |
|
| 193 | 193 | |
| 194 | - $messenger_name = str_replace( ' ', '_', ucwords( str_replace( '_', ' ', $messenger ) ) ); |
|
| 195 | - $mt_name = str_replace( ' ', '_', ucwords( str_replace( '_', ' ', $message_type ) ) ); |
|
| 194 | + $messenger_name = str_replace(' ', '_', ucwords(str_replace('_', ' ', $messenger))); |
|
| 195 | + $mt_name = str_replace(' ', '_', ucwords(str_replace('_', ' ', $message_type))); |
|
| 196 | 196 | |
| 197 | 197 | //convert slug to object |
| 198 | - $messenger = self::messenger_obj( $messenger ); |
|
| 198 | + $messenger = self::messenger_obj($messenger); |
|
| 199 | 199 | |
| 200 | 200 | //validate class for getting our list of shortcodes |
| 201 | - $classname = 'EE_Messages_' . $messenger_name . '_' . $mt_name . '_Validator'; |
|
| 202 | - if ( !class_exists( $classname ) ) { |
|
| 203 | - $msg[] = __( 'The Validator class was unable to load', 'event_espresso'); |
|
| 204 | - $msg[] = sprintf( __('The class name compiled was %s. Please check and make sure the spelling and case is correct for the class name and that there is an autoloader in place for this class', 'event_espresso'), $classname ); |
|
| 205 | - throw new EE_Error( implode( '||', $msg ) ); |
|
| 201 | + $classname = 'EE_Messages_'.$messenger_name.'_'.$mt_name.'_Validator'; |
|
| 202 | + if ( ! class_exists($classname)) { |
|
| 203 | + $msg[] = __('The Validator class was unable to load', 'event_espresso'); |
|
| 204 | + $msg[] = sprintf(__('The class name compiled was %s. Please check and make sure the spelling and case is correct for the class name and that there is an autoloader in place for this class', 'event_espresso'), $classname); |
|
| 205 | + throw new EE_Error(implode('||', $msg)); |
|
| 206 | 206 | } |
| 207 | 207 | |
| 208 | - $a = new ReflectionClass( $classname ); |
|
| 209 | - $_VLD = $a->newInstance( array(), $context ); |
|
| 208 | + $a = new ReflectionClass($classname); |
|
| 209 | + $_VLD = $a->newInstance(array(), $context); |
|
| 210 | 210 | $valid_shortcodes = $_VLD->get_validators(); |
| 211 | 211 | |
| 212 | 212 | //let's make sure we're only getting the shortcode part of the validators |
| 213 | 213 | $shortcodes = array(); |
| 214 | - foreach( $valid_shortcodes as $field => $validators ) { |
|
| 214 | + foreach ($valid_shortcodes as $field => $validators) { |
|
| 215 | 215 | $shortcodes[$field] = $validators['shortcodes']; |
| 216 | 216 | $fields[] = $field; |
| 217 | 217 | } |
| 218 | 218 | $valid_shortcodes = $shortcodes; |
| 219 | 219 | |
| 220 | 220 | //if not all fields let's make sure we ONLY include the shortcodes for the specified fields. |
| 221 | - if ( ! empty( $fields ) ) { |
|
| 221 | + if ( ! empty($fields)) { |
|
| 222 | 222 | $specified_shortcodes = array(); |
| 223 | - foreach ( $fields as $field ) { |
|
| 224 | - if ( isset( $valid_shortcodes[$field] ) ) |
|
| 223 | + foreach ($fields as $field) { |
|
| 224 | + if (isset($valid_shortcodes[$field])) |
|
| 225 | 225 | $specified_shortcodes[$field] = $valid_shortcodes[$field]; |
| 226 | 226 | } |
| 227 | 227 | $valid_shortcodes = $specified_shortcodes; |
@@ -229,16 +229,16 @@ discard block |
||
| 229 | 229 | |
| 230 | 230 | |
| 231 | 231 | //if not merged then let's replace the fields with the localized fields |
| 232 | - if ( ! $merged ) { |
|
| 232 | + if ( ! $merged) { |
|
| 233 | 233 | //let's get all the fields for the set messenger so that we can get the localized label and use that in the returned array. |
| 234 | 234 | $field_settings = $messenger->get_template_fields(); |
| 235 | 235 | $localized = array(); |
| 236 | - foreach ( $valid_shortcodes as $field => $shortcodes ) { |
|
| 236 | + foreach ($valid_shortcodes as $field => $shortcodes) { |
|
| 237 | 237 | //get localized field label |
| 238 | - if ( isset( $field_settings[$field] ) ) { |
|
| 238 | + if (isset($field_settings[$field])) { |
|
| 239 | 239 | //possible that this is used as a main field. |
| 240 | - if ( empty( $field_settings[$field] ) ) { |
|
| 241 | - if ( isset( $field_settings['extra'][$field] ) ) { |
|
| 240 | + if (empty($field_settings[$field])) { |
|
| 241 | + if (isset($field_settings['extra'][$field])) { |
|
| 242 | 242 | $_field = $field_settings['extra'][$field]['main']['label']; |
| 243 | 243 | } else { |
| 244 | 244 | $_field = $field; |
@@ -246,10 +246,10 @@ discard block |
||
| 246 | 246 | } else { |
| 247 | 247 | $_field = $field_settings[$field]['label']; |
| 248 | 248 | } |
| 249 | - } else if ( isset( $field_settings['extra'] ) ) { |
|
| 249 | + } else if (isset($field_settings['extra'])) { |
|
| 250 | 250 | //loop through extra "main fields" and see if any of their children have our field |
| 251 | - foreach ( $field_settings['extra'] as $main_field => $fields ) { |
|
| 252 | - if ( isset( $fields[$field] ) ) |
|
| 251 | + foreach ($field_settings['extra'] as $main_field => $fields) { |
|
| 252 | + if (isset($fields[$field])) |
|
| 253 | 253 | $_field = $fields[$field]['label']; |
| 254 | 254 | else |
| 255 | 255 | $_field = $field; |
@@ -257,8 +257,8 @@ discard block |
||
| 257 | 257 | } else { |
| 258 | 258 | $_field = $field; |
| 259 | 259 | } |
| 260 | - if ( isset( $_field )) { |
|
| 261 | - $localized[ $_field ] = $shortcodes; |
|
| 260 | + if (isset($_field)) { |
|
| 261 | + $localized[$_field] = $shortcodes; |
|
| 262 | 262 | } |
| 263 | 263 | } |
| 264 | 264 | $valid_shortcodes = $localized; |
@@ -266,11 +266,11 @@ discard block |
||
| 266 | 266 | |
| 267 | 267 | |
| 268 | 268 | //if $merged then let's merge all the shortcodes into one list NOT indexed by field. |
| 269 | - if ( $merged ) { |
|
| 269 | + if ($merged) { |
|
| 270 | 270 | $merged_codes = array(); |
| 271 | - foreach ( $valid_shortcodes as $field => $shortcode ) { |
|
| 272 | - foreach ( $shortcode as $code => $label ) { |
|
| 273 | - if ( isset( $merged_codes[$code] ) ) |
|
| 271 | + foreach ($valid_shortcodes as $field => $shortcode) { |
|
| 272 | + foreach ($shortcode as $code => $label) { |
|
| 273 | + if (isset($merged_codes[$code])) |
|
| 274 | 274 | continue; |
| 275 | 275 | else |
| 276 | 276 | $merged_codes[$code] = $label; |
@@ -292,15 +292,15 @@ discard block |
||
| 292 | 292 | * @throws \EE_Error |
| 293 | 293 | * @return EE_messenger |
| 294 | 294 | */ |
| 295 | - public static function messenger_obj( $messenger ) { |
|
| 296 | - $ref = ucwords( str_replace( '_', ' ', $messenger ) ); |
|
| 297 | - $ref = str_replace( ' ', '_', $ref ); |
|
| 298 | - $classname = 'EE_' . $ref . '_messenger'; |
|
| 295 | + public static function messenger_obj($messenger) { |
|
| 296 | + $ref = ucwords(str_replace('_', ' ', $messenger)); |
|
| 297 | + $ref = str_replace(' ', '_', $ref); |
|
| 298 | + $classname = 'EE_'.$ref.'_messenger'; |
|
| 299 | 299 | |
| 300 | - if ( !class_exists($classname) ) { |
|
| 300 | + if ( ! class_exists($classname)) { |
|
| 301 | 301 | $msg[] = __('Messenger class loading fail.', 'event_espresso'); |
| 302 | - $msg[] = sprintf( __('The class name checked was "%s". Please check the spelling and case of this reference and make sure it matches the appropriate messenger file name (minus the extension) in the "/core/messages/messenger/" directory', 'event_espresso'), $classname ); |
|
| 303 | - throw new EE_Error( implode( '||', $msg ) ); |
|
| 302 | + $msg[] = sprintf(__('The class name checked was "%s". Please check the spelling and case of this reference and make sure it matches the appropriate messenger file name (minus the extension) in the "/core/messages/messenger/" directory', 'event_espresso'), $classname); |
|
| 303 | + throw new EE_Error(implode('||', $msg)); |
|
| 304 | 304 | } |
| 305 | 305 | |
| 306 | 306 | //made it here so let's instantiate the object and return it. |
@@ -318,15 +318,15 @@ discard block |
||
| 318 | 318 | * @throws \EE_Error |
| 319 | 319 | * @return EE_message_type |
| 320 | 320 | */ |
| 321 | - public static function message_type_obj( $message_type ) { |
|
| 322 | - $ref = ucwords( str_replace( '_', ' ', $message_type ) ); |
|
| 323 | - $ref = str_replace( ' ', '_', $ref ); |
|
| 324 | - $classname = 'EE_' . $ref . '_message_type'; |
|
| 321 | + public static function message_type_obj($message_type) { |
|
| 322 | + $ref = ucwords(str_replace('_', ' ', $message_type)); |
|
| 323 | + $ref = str_replace(' ', '_', $ref); |
|
| 324 | + $classname = 'EE_'.$ref.'_message_type'; |
|
| 325 | 325 | |
| 326 | - if ( !class_exists($classname) ) { |
|
| 326 | + if ( ! class_exists($classname)) { |
|
| 327 | 327 | $msg[] = __('Message Type class loading fail.', 'event_espresso'); |
| 328 | - $msg[] = sprintf( __('The class name checked was "%s". Please check the spelling and case of this reference and make sure it matches the appropriate message type file name (minus the extension) in the "/core/messages/message_type/" directory', 'event_espresso'), $classname ); |
|
| 329 | - throw new EE_Error( implode( '||', $msg ) ); |
|
| 328 | + $msg[] = sprintf(__('The class name checked was "%s". Please check the spelling and case of this reference and make sure it matches the appropriate message type file name (minus the extension) in the "/core/messages/message_type/" directory', 'event_espresso'), $classname); |
|
| 329 | + throw new EE_Error(implode('||', $msg)); |
|
| 330 | 330 | } |
| 331 | 331 | |
| 332 | 332 | //made it here so let's instantiate the object and return it. |
@@ -345,10 +345,10 @@ discard block |
||
| 345 | 345 | * @param string $message_type message type to check for. |
| 346 | 346 | * @return boolean |
| 347 | 347 | */ |
| 348 | - public static function is_mt_active( $message_type ) { |
|
| 348 | + public static function is_mt_active($message_type) { |
|
| 349 | 349 | self::_set_autoloader(); |
| 350 | - $active_mts = EE_Registry::instance()->load_lib( 'messages' )->get_active_message_types(); |
|
| 351 | - return in_array( $message_type, $active_mts ); |
|
| 350 | + $active_mts = EE_Registry::instance()->load_lib('messages')->get_active_message_types(); |
|
| 351 | + return in_array($message_type, $active_mts); |
|
| 352 | 352 | } |
| 353 | 353 | |
| 354 | 354 | |
@@ -361,10 +361,10 @@ discard block |
||
| 361 | 361 | * @param string $messenger slug for messenger to check. |
| 362 | 362 | * @return boolean |
| 363 | 363 | */ |
| 364 | - public static function is_messenger_active( $messenger ) { |
|
| 364 | + public static function is_messenger_active($messenger) { |
|
| 365 | 365 | self::_set_autoloader(); |
| 366 | 366 | $active_messengers = EE_Registry::instance()->load_lib('messages')->get_active_messengers(); |
| 367 | - return isset( $active_messengers[ $messenger ] ); |
|
| 367 | + return isset($active_messengers[$messenger]); |
|
| 368 | 368 | } |
| 369 | 369 | |
| 370 | 370 | |
@@ -378,7 +378,7 @@ discard block |
||
| 378 | 378 | * @return array |
| 379 | 379 | */ |
| 380 | 380 | public static function get_active_messengers_in_db() { |
| 381 | - return apply_filters( 'FHEE__EEH_MSG_Template__get_active_messengers_in_db', get_option( 'ee_active_messengers', array() ) ); |
|
| 381 | + return apply_filters('FHEE__EEH_MSG_Template__get_active_messengers_in_db', get_option('ee_active_messengers', array())); |
|
| 382 | 382 | } |
| 383 | 383 | |
| 384 | 384 | |
@@ -393,8 +393,8 @@ discard block |
||
| 393 | 393 | * |
| 394 | 394 | * @return bool FALSE if not updated, TRUE if updated. |
| 395 | 395 | */ |
| 396 | - public static function update_active_messengers_in_db( $data_to_save ) { |
|
| 397 | - return update_option( 'ee_active_messengers', $data_to_save ); |
|
| 396 | + public static function update_active_messengers_in_db($data_to_save) { |
|
| 397 | + return update_option('ee_active_messengers', $data_to_save); |
|
| 398 | 398 | } |
| 399 | 399 | |
| 400 | 400 | |
@@ -413,7 +413,7 @@ discard block |
||
| 413 | 413 | * |
| 414 | 414 | * @return string The generated url. |
| 415 | 415 | */ |
| 416 | - public static function generate_url_trigger( $sending_messenger, $generating_messenger, $context, $message_type, EE_Registration $registration, $message_template_group, $data_id ) { |
|
| 416 | + public static function generate_url_trigger($sending_messenger, $generating_messenger, $context, $message_type, EE_Registration $registration, $message_template_group, $data_id) { |
|
| 417 | 417 | $query_args = array( |
| 418 | 418 | 'ee' => 'msg_url_trigger', |
| 419 | 419 | 'snd_msgr' => $sending_messenger, |
@@ -424,10 +424,10 @@ discard block |
||
| 424 | 424 | 'GRP_ID' => $message_template_group, |
| 425 | 425 | 'id' => $data_id |
| 426 | 426 | ); |
| 427 | - $url = add_query_arg( $query_args, get_site_url() ); |
|
| 427 | + $url = add_query_arg($query_args, get_site_url()); |
|
| 428 | 428 | |
| 429 | 429 | //made it here so now we can just get the url and filter it. Filtered globally and by message type. |
| 430 | - $url = apply_filters( 'FHEE__EEH_MSG_Template__generate_url_trigger', $url, $sending_messenger, $generating_messenger, $context, $message_type, $registration, $message_template_group, $data_id ); |
|
| 430 | + $url = apply_filters('FHEE__EEH_MSG_Template__generate_url_trigger', $url, $sending_messenger, $generating_messenger, $context, $message_type, $registration, $message_template_group, $data_id); |
|
| 431 | 431 | |
| 432 | 432 | return $url; |
| 433 | 433 | } |
@@ -1,7 +1,8 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -if (!defined('EVENT_ESPRESSO_VERSION') ) |
|
| 3 | +if (!defined('EVENT_ESPRESSO_VERSION') ) { |
|
| 4 | 4 | exit('NO direct script access allowed'); |
| 5 | +} |
|
| 5 | 6 | |
| 6 | 7 | /** |
| 7 | 8 | * Event Espresso |
@@ -85,7 +86,9 @@ discard block |
||
| 85 | 86 | $success = FALSE; |
| 86 | 87 | continue; |
| 87 | 88 | } |
| 88 | - if ( $templates === TRUE ) $templates = array(); |
|
| 89 | + if ( $templates === TRUE ) { |
|
| 90 | + $templates = array(); |
|
| 91 | + } |
|
| 89 | 92 | $templates[] = $new_message_template_group; |
| 90 | 93 | } |
| 91 | 94 | |
@@ -142,8 +145,9 @@ discard block |
||
| 142 | 145 | */ |
| 143 | 146 | public static function update_to_inactive( $messenger = '', $message_type = '' ) { |
| 144 | 147 | $query_args = array(); |
| 145 | - if ( empty( $messenger ) && empty( $message_type ) ) |
|
| 146 | - return 0; |
|
| 148 | + if ( empty( $messenger ) && empty( $message_type ) ) { |
|
| 149 | + return 0; |
|
| 150 | + } |
|
| 147 | 151 | if ( ! empty( $messenger ) ) { |
| 148 | 152 | $query_args[0]['MTP_messenger'] = $messenger; |
| 149 | 153 | } |
@@ -221,8 +225,9 @@ discard block |
||
| 221 | 225 | if ( ! empty( $fields ) ) { |
| 222 | 226 | $specified_shortcodes = array(); |
| 223 | 227 | foreach ( $fields as $field ) { |
| 224 | - if ( isset( $valid_shortcodes[$field] ) ) |
|
| 225 | - $specified_shortcodes[$field] = $valid_shortcodes[$field]; |
|
| 228 | + if ( isset( $valid_shortcodes[$field] ) ) { |
|
| 229 | + $specified_shortcodes[$field] = $valid_shortcodes[$field]; |
|
| 230 | + } |
|
| 226 | 231 | } |
| 227 | 232 | $valid_shortcodes = $specified_shortcodes; |
| 228 | 233 | } |
@@ -249,10 +254,11 @@ discard block |
||
| 249 | 254 | } else if ( isset( $field_settings['extra'] ) ) { |
| 250 | 255 | //loop through extra "main fields" and see if any of their children have our field |
| 251 | 256 | foreach ( $field_settings['extra'] as $main_field => $fields ) { |
| 252 | - if ( isset( $fields[$field] ) ) |
|
| 253 | - $_field = $fields[$field]['label']; |
|
| 254 | - else |
|
| 255 | - $_field = $field; |
|
| 257 | + if ( isset( $fields[$field] ) ) { |
|
| 258 | + $_field = $fields[$field]['label']; |
|
| 259 | + } else { |
|
| 260 | + $_field = $field; |
|
| 261 | + } |
|
| 256 | 262 | } |
| 257 | 263 | } else { |
| 258 | 264 | $_field = $field; |
@@ -270,10 +276,11 @@ discard block |
||
| 270 | 276 | $merged_codes = array(); |
| 271 | 277 | foreach ( $valid_shortcodes as $field => $shortcode ) { |
| 272 | 278 | foreach ( $shortcode as $code => $label ) { |
| 273 | - if ( isset( $merged_codes[$code] ) ) |
|
| 274 | - continue; |
|
| 275 | - else |
|
| 276 | - $merged_codes[$code] = $label; |
|
| 279 | + if ( isset( $merged_codes[$code] ) ) { |
|
| 280 | + continue; |
|
| 281 | + } else { |
|
| 282 | + $merged_codes[$code] = $label; |
|
| 283 | + } |
|
| 277 | 284 | } |
| 278 | 285 | } |
| 279 | 286 | $valid_shortcodes = $merged_codes; |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | * |
| 21 | 21 | * ------------------------------------------------------------------------ |
| 22 | 22 | */ |
| 23 | -class EEH_Money extends EEH_Base { |
|
| 23 | +class EEH_Money extends EEH_Base { |
|
| 24 | 24 | |
| 25 | 25 | |
| 26 | 26 | /** |
@@ -29,15 +29,15 @@ discard block |
||
| 29 | 29 | * @param int|string $incoming_value |
| 30 | 30 | * @return float |
| 31 | 31 | */ |
| 32 | - public static function convert_to_float_from_localized_money( $incoming_value ) { |
|
| 32 | + public static function convert_to_float_from_localized_money($incoming_value) { |
|
| 33 | 33 | //remove thousands separator |
| 34 | - $money_value = str_replace( EE_Registry::instance()->CFG->currency->thsnds, '', $incoming_value ); |
|
| 34 | + $money_value = str_replace(EE_Registry::instance()->CFG->currency->thsnds, '', $incoming_value); |
|
| 35 | 35 | |
| 36 | 36 | //replace decimal place with standard decimal. |
| 37 | - $money_value = str_replace( EE_Registry::instance()->CFG->currency->dec_mrk, '.', $money_value ); |
|
| 37 | + $money_value = str_replace(EE_Registry::instance()->CFG->currency->dec_mrk, '.', $money_value); |
|
| 38 | 38 | |
| 39 | 39 | //float it! and round to three decimal places |
| 40 | - $money_value = round ( (float) $money_value, 3 ); |
|
| 40 | + $money_value = round((float) $money_value, 3); |
|
| 41 | 41 | return $money_value; |
| 42 | 42 | } |
| 43 | 43 | |
@@ -57,12 +57,12 @@ discard block |
||
| 57 | 57 | * @throws \EE_Error |
| 58 | 58 | */ |
| 59 | 59 | |
| 60 | - public static function compare_floats( $float1, $float2, $operator='=' ) { |
|
| 60 | + public static function compare_floats($float1, $float2, $operator = '=') { |
|
| 61 | 61 | // Check numbers to 5 digits of precision |
| 62 | 62 | $epsilon = 0.00001; |
| 63 | 63 | |
| 64 | - $float1 = (float)$float1; |
|
| 65 | - $float2 = (float)$float2; |
|
| 64 | + $float1 = (float) $float1; |
|
| 65 | + $float2 = (float) $float2; |
|
| 66 | 66 | |
| 67 | 67 | switch ($operator) { |
| 68 | 68 | // equal |
@@ -116,7 +116,7 @@ discard block |
||
| 116 | 116 | } |
| 117 | 117 | break; |
| 118 | 118 | default: |
| 119 | - throw new EE_Error(__( "Unknown operator '" . $operator . "' in EEH_Money::compare_floats()", 'event_espresso' ) ); |
|
| 119 | + throw new EE_Error(__("Unknown operator '".$operator."' in EEH_Money::compare_floats()", 'event_espresso')); |
|
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | return false; |
@@ -5,7 +5,9 @@ |
||
| 5 | 5 | * @subpackage plugin api, messages |
| 6 | 6 | * @since 4.5.0 |
| 7 | 7 | */ |
| 8 | -if ( ! defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed'); |
|
| 8 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 9 | + exit('No direct script access allowed'); |
|
| 10 | +} |
|
| 9 | 11 | |
| 10 | 12 | /** |
| 11 | 13 | * Use this to register or deregister a new message template pack variation for the EE messages system. |
@@ -1,25 +1,25 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * This file contains a helper class for money type actions. |
|
| 4 | - * |
|
| 5 | - * @since %VER% |
|
| 6 | - * @package Event Espresso |
|
| 7 | - * @subpackage helper |
|
| 8 | - */ |
|
| 3 | + * This file contains a helper class for money type actions. |
|
| 4 | + * |
|
| 5 | + * @since %VER% |
|
| 6 | + * @package Event Espresso |
|
| 7 | + * @subpackage helper |
|
| 8 | + */ |
|
| 9 | 9 | if ( ! defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed'); |
| 10 | 10 | /** |
| 11 | - * |
|
| 12 | - * Money helper class. |
|
| 13 | - * This class has helper methods that help with money related conversions and calculations. |
|
| 14 | - * |
|
| 15 | - * @since %VER% |
|
| 16 | - * |
|
| 17 | - * @package Event Espresso |
|
| 18 | - * @subpackage helpers |
|
| 19 | - * @author Darren Ethier |
|
| 20 | - * |
|
| 21 | - * ------------------------------------------------------------------------ |
|
| 22 | - */ |
|
| 11 | + * |
|
| 12 | + * Money helper class. |
|
| 13 | + * This class has helper methods that help with money related conversions and calculations. |
|
| 14 | + * |
|
| 15 | + * @since %VER% |
|
| 16 | + * |
|
| 17 | + * @package Event Espresso |
|
| 18 | + * @subpackage helpers |
|
| 19 | + * @author Darren Ethier |
|
| 20 | + * |
|
| 21 | + * ------------------------------------------------------------------------ |
|
| 22 | + */ |
|
| 23 | 23 | class EEH_Money extends EEH_Base { |
| 24 | 24 | |
| 25 | 25 | |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -if (!defined('EVENT_ESPRESSO_VERSION') ) |
|
| 3 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) |
|
| 4 | 4 | exit('NO direct script access allowed'); |
| 5 | 5 | |
| 6 | 6 | /** |
@@ -83,7 +83,7 @@ discard block |
||
| 83 | 83 | * @param INT $GRP_ID The message template grp_id for the specific template being parsed. |
| 84 | 84 | * @return string The parsed template string |
| 85 | 85 | */ |
| 86 | - public function parse_message_template( $template, EE_Messages_Addressee $data, $valid_shortcodes, EE_message_type $message_type, EE_messenger $messenger, $context, $GRP_ID ) { |
|
| 86 | + public function parse_message_template($template, EE_Messages_Addressee $data, $valid_shortcodes, EE_message_type $message_type, EE_messenger $messenger, $context, $GRP_ID) { |
|
| 87 | 87 | $extra_data = array( |
| 88 | 88 | 'messenger' => $messenger, |
| 89 | 89 | 'message_type' => $message_type, |
@@ -91,7 +91,7 @@ discard block |
||
| 91 | 91 | 'GRP_ID' => $GRP_ID |
| 92 | 92 | ); |
| 93 | 93 | |
| 94 | - $this->_init_data( $template, $data, $valid_shortcodes, $extra_data ); |
|
| 94 | + $this->_init_data($template, $data, $valid_shortcodes, $extra_data); |
|
| 95 | 95 | |
| 96 | 96 | |
| 97 | 97 | $this->_template = is_array($template) ? $template['main'] : $template; |
@@ -102,9 +102,9 @@ discard block |
||
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | |
| 105 | - public function parse_attendee_list_template( $template, EE_Registration $registration, $valid_shortcodes, $extra_data = array() ) { |
|
| 105 | + public function parse_attendee_list_template($template, EE_Registration $registration, $valid_shortcodes, $extra_data = array()) { |
|
| 106 | 106 | |
| 107 | - $this->_init_data( $template, $registration, $valid_shortcodes, $extra_data ); |
|
| 107 | + $this->_init_data($template, $registration, $valid_shortcodes, $extra_data); |
|
| 108 | 108 | |
| 109 | 109 | $this->_template = is_array($template) ? $template['attendee_list'] : $template; |
| 110 | 110 | |
@@ -112,8 +112,8 @@ discard block |
||
| 112 | 112 | return $parsed; |
| 113 | 113 | } |
| 114 | 114 | |
| 115 | - public function parse_event_list_template( $template, EE_Event $event, $valid_shortcodes, $extra_data = array() ) { |
|
| 116 | - $this->_init_data( $template, $event, $valid_shortcodes, $extra_data ); |
|
| 115 | + public function parse_event_list_template($template, EE_Event $event, $valid_shortcodes, $extra_data = array()) { |
|
| 116 | + $this->_init_data($template, $event, $valid_shortcodes, $extra_data); |
|
| 117 | 117 | |
| 118 | 118 | $this->_template = is_array($template) ? $template['event_list'] : $template; |
| 119 | 119 | |
@@ -122,8 +122,8 @@ discard block |
||
| 122 | 122 | } |
| 123 | 123 | |
| 124 | 124 | |
| 125 | - public function parse_ticket_list_template( $template, EE_Ticket $ticket, $valid_shortcodes, $extra_data = array() ) { |
|
| 126 | - $this->_init_data( $template, $ticket, $valid_shortcodes, $extra_data ); |
|
| 125 | + public function parse_ticket_list_template($template, EE_Ticket $ticket, $valid_shortcodes, $extra_data = array()) { |
|
| 126 | + $this->_init_data($template, $ticket, $valid_shortcodes, $extra_data); |
|
| 127 | 127 | |
| 128 | 128 | $this->_template = is_array($template) ? $template['ticket_list'] : $template; |
| 129 | 129 | |
@@ -133,26 +133,26 @@ discard block |
||
| 133 | 133 | |
| 134 | 134 | |
| 135 | 135 | |
| 136 | - public function parse_line_item_list_template( $template, EE_Line_Item $line_item, $valid_shortcodes, $extra_data = array() ) { |
|
| 137 | - $this->_init_data( $template, $line_item, $valid_shortcodes, $extra_data ); |
|
| 138 | - $this->_template = is_array( $template ) ? $template['ticket_line_item_no_pms'] : $template; |
|
| 136 | + public function parse_line_item_list_template($template, EE_Line_Item $line_item, $valid_shortcodes, $extra_data = array()) { |
|
| 137 | + $this->_init_data($template, $line_item, $valid_shortcodes, $extra_data); |
|
| 138 | + $this->_template = is_array($template) ? $template['ticket_line_item_no_pms'] : $template; |
|
| 139 | 139 | |
| 140 | 140 | $parsed = $this->_parse_message_template(); |
| 141 | 141 | return $parsed; |
| 142 | 142 | } |
| 143 | 143 | |
| 144 | 144 | |
| 145 | - public function parse_payment_list_template( $template, EE_Payment $payment_item, $valid_shortcodes, $extra_data = array() ) { |
|
| 146 | - $this->_init_data( $template, $payment_item, $valid_shortcodes, $extra_data ); |
|
| 147 | - $this->_template = is_array( $template ) ? $template['payment_list'] : $template; |
|
| 145 | + public function parse_payment_list_template($template, EE_Payment $payment_item, $valid_shortcodes, $extra_data = array()) { |
|
| 146 | + $this->_init_data($template, $payment_item, $valid_shortcodes, $extra_data); |
|
| 147 | + $this->_template = is_array($template) ? $template['payment_list'] : $template; |
|
| 148 | 148 | |
| 149 | 149 | $parsed = $this->_parse_message_template(); |
| 150 | 150 | return $parsed; |
| 151 | 151 | } |
| 152 | 152 | |
| 153 | 153 | |
| 154 | - public function parse_datetime_list_template( $template, EE_Datetime $datetime, $valid_shortcodes, $extra_data = array() ) { |
|
| 155 | - $this->_init_data( $template, $datetime, $valid_shortcodes, $extra_data ); |
|
| 154 | + public function parse_datetime_list_template($template, EE_Datetime $datetime, $valid_shortcodes, $extra_data = array()) { |
|
| 155 | + $this->_init_data($template, $datetime, $valid_shortcodes, $extra_data); |
|
| 156 | 156 | |
| 157 | 157 | $this->_template = is_array($template) ? $template['datetime_list'] : $template; |
| 158 | 158 | |
@@ -161,8 +161,8 @@ discard block |
||
| 161 | 161 | } |
| 162 | 162 | |
| 163 | 163 | |
| 164 | - public function parse_question_list_template( $template, EE_Answer $answer, $valid_shortcodes, $extra_data = array() ) { |
|
| 165 | - $this->_init_data( $template, $answer, $valid_shortcodes, $extra_data ); |
|
| 164 | + public function parse_question_list_template($template, EE_Answer $answer, $valid_shortcodes, $extra_data = array()) { |
|
| 165 | + $this->_init_data($template, $answer, $valid_shortcodes, $extra_data); |
|
| 166 | 166 | |
| 167 | 167 | $this->_template = is_array($template) ? $template['question_list'] : $template; |
| 168 | 168 | |
@@ -171,13 +171,13 @@ discard block |
||
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | |
| 174 | - private function _init_data( $template, $data, $valid_shortcodes, $extra_data = array() ) { |
|
| 174 | + private function _init_data($template, $data, $valid_shortcodes, $extra_data = array()) { |
|
| 175 | 175 | $this->_reset_props(); |
| 176 | 176 | $this->_data['template'] = $template; |
| 177 | 177 | $this->_data['data'] = $data; |
| 178 | 178 | $this->_data['extra_data'] = $extra_data; |
| 179 | 179 | |
| 180 | - $this->_set_shortcodes( $valid_shortcodes ); |
|
| 180 | + $this->_set_shortcodes($valid_shortcodes); |
|
| 181 | 181 | } |
| 182 | 182 | |
| 183 | 183 | |
@@ -196,7 +196,7 @@ discard block |
||
| 196 | 196 | |
| 197 | 197 | |
| 198 | 198 | //now let's get a list of shortcodes that are found in the given template |
| 199 | - $possible_shortcodes = preg_match_all( '/(\[.+?\])/', $this->_template, $matches ); |
|
| 199 | + $possible_shortcodes = preg_match_all('/(\[.+?\])/', $this->_template, $matches); |
|
| 200 | 200 | $shortcodes = (array) $matches[0]; //this should be an array of shortcodes in the template string. |
| 201 | 201 | |
| 202 | 202 | $matched_code = array(); |
@@ -221,31 +221,31 @@ discard block |
||
| 221 | 221 | '[PAYMENT_LIST_*]' |
| 222 | 222 | ); |
| 223 | 223 | |
| 224 | - $list_type_shortcodes = apply_filters( 'FHEE__EEH_Parse_Shortcodes___parse_message_template__list_type_shortcodes', $list_type_shortcodes ); |
|
| 224 | + $list_type_shortcodes = apply_filters('FHEE__EEH_Parse_Shortcodes___parse_message_template__list_type_shortcodes', $list_type_shortcodes); |
|
| 225 | 225 | |
| 226 | 226 | //now lets go ahead and loop through our parsers for each shortcode and setup the values |
| 227 | - foreach ( $shortcodes as $shortcode ) { |
|
| 227 | + foreach ($shortcodes as $shortcode) { |
|
| 228 | 228 | |
| 229 | - foreach ( $this->_shortcode_objs as $sc_obj ) { |
|
| 229 | + foreach ($this->_shortcode_objs as $sc_obj) { |
|
| 230 | 230 | $data_send = ''; |
| 231 | 231 | |
| 232 | 232 | //we need to setup any dynamic shortcodes so that they work with the array_key_exists |
| 233 | - $sc = preg_match_all( '/(\[[A-Za-z0-9\_]+_\*)/', $shortcode, $matches ); |
|
| 234 | - $sc_to_verify = !empty($matches[0] ) ? $matches[0][0] . ']' : $shortcode; |
|
| 233 | + $sc = preg_match_all('/(\[[A-Za-z0-9\_]+_\*)/', $shortcode, $matches); |
|
| 234 | + $sc_to_verify = ! empty($matches[0]) ? $matches[0][0].']' : $shortcode; |
|
| 235 | 235 | |
| 236 | - if ( !array_key_exists( $sc_to_verify, $sc_obj->get_shortcodes() ) ) { |
|
| 236 | + if ( ! array_key_exists($sc_to_verify, $sc_obj->get_shortcodes())) { |
|
| 237 | 237 | continue; //the given shortcode isn't in this object |
| 238 | 238 | } |
| 239 | 239 | |
| 240 | 240 | //if this isn't a "list" type shortcode then we'll send along the data vanilla instead of in an array. |
| 241 | - if ( ! in_array( $sc_to_verify, $list_type_shortcodes ) ) { |
|
| 242 | - $data_send = !is_object($this->_data) && isset($this->_data['data']) ? $this->_data['data'] : $this->_data; |
|
| 241 | + if ( ! in_array($sc_to_verify, $list_type_shortcodes)) { |
|
| 242 | + $data_send = ! is_object($this->_data) && isset($this->_data['data']) ? $this->_data['data'] : $this->_data; |
|
| 243 | 243 | } else { |
| 244 | 244 | $data_send = $this->_data; |
| 245 | 245 | } |
| 246 | 246 | |
| 247 | 247 | |
| 248 | - $parsed = $sc_obj->parser( $shortcode, $data_send, $this->_data['extra_data'] ); |
|
| 248 | + $parsed = $sc_obj->parser($shortcode, $data_send, $this->_data['extra_data']); |
|
| 249 | 249 | |
| 250 | 250 | $matched_code[] = $shortcode; |
| 251 | 251 | $sc_values[] = $parsed; |
@@ -267,13 +267,13 @@ discard block |
||
| 267 | 267 | * @param array $valid_shortcodes an array of strings corresponding to EE_Shortcode Library objects |
| 268 | 268 | * @return void |
| 269 | 269 | */ |
| 270 | - private function _set_shortcodes( $valid_shortcodes ) { |
|
| 271 | - foreach ( $valid_shortcodes as $shortcode_ref ) { |
|
| 272 | - $ref = ucwords( str_replace('_', ' ', $shortcode_ref ) ); |
|
| 273 | - $ref = str_replace( ' ', '_', $ref ); |
|
| 274 | - $classname = 'EE_' . $ref . '_Shortcodes'; |
|
| 275 | - if ( class_exists( $classname ) ) { |
|
| 276 | - $a = new ReflectionClass( $classname ); |
|
| 270 | + private function _set_shortcodes($valid_shortcodes) { |
|
| 271 | + foreach ($valid_shortcodes as $shortcode_ref) { |
|
| 272 | + $ref = ucwords(str_replace('_', ' ', $shortcode_ref)); |
|
| 273 | + $ref = str_replace(' ', '_', $ref); |
|
| 274 | + $classname = 'EE_'.$ref.'_Shortcodes'; |
|
| 275 | + if (class_exists($classname)) { |
|
| 276 | + $a = new ReflectionClass($classname); |
|
| 277 | 277 | $this->_shortcode_objs[] = $a->newInstance(); |
| 278 | 278 | } |
| 279 | 279 | } |
@@ -6,8 +6,9 @@ |
||
| 6 | 6 | * @package Event Espresso |
| 7 | 7 | * @subpackage messages |
| 8 | 8 | */ |
| 9 | -if (!defined('EVENT_ESPRESSO_VERSION') ) |
|
| 9 | +if (!defined('EVENT_ESPRESSO_VERSION') ) { |
|
| 10 | 10 | exit('NO direct script access allowed'); |
| 11 | +} |
|
| 11 | 12 | |
| 12 | 13 | /** |
| 13 | 14 | * |
@@ -28,7 +28,7 @@ discard block |
||
| 28 | 28 | |
| 29 | 29 | |
| 30 | 30 | |
| 31 | -require_once( EE_HELPERS . 'EEH_Base.helper.php' ); |
|
| 31 | +require_once(EE_HELPERS.'EEH_Base.helper.php'); |
|
| 32 | 32 | class EEH_Sideloader extends EEH_Base { |
| 33 | 33 | |
| 34 | 34 | private $_upload_to; |
@@ -43,8 +43,8 @@ discard block |
||
| 43 | 43 | * @access public |
| 44 | 44 | * @param array $init array fo initializing the sideloader if keys match the properties. |
| 45 | 45 | */ |
| 46 | - public function __construct( $init = array() ) { |
|
| 47 | - $this->_init( $init ); |
|
| 46 | + public function __construct($init = array()) { |
|
| 47 | + $this->_init($init); |
|
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | |
@@ -55,24 +55,24 @@ discard block |
||
| 55 | 55 | * @param array $init array on init (keys match properties others ignored) |
| 56 | 56 | * @return void |
| 57 | 57 | */ |
| 58 | - private function _init( $init ) { |
|
| 58 | + private function _init($init) { |
|
| 59 | 59 | $defaults = array( |
| 60 | 60 | '_upload_to' => $this->_get_wp_uploads_dir(), |
| 61 | 61 | '_upload_from' => '', |
| 62 | 62 | '_permissions' => 0644, |
| 63 | - '_new_file_name' => 'EE_Sideloader_' . uniqid() . '.default' |
|
| 63 | + '_new_file_name' => 'EE_Sideloader_'.uniqid().'.default' |
|
| 64 | 64 | ); |
| 65 | 65 | |
| 66 | - $props = array_merge( $defaults, $init ); |
|
| 66 | + $props = array_merge($defaults, $init); |
|
| 67 | 67 | |
| 68 | - foreach ( $props as $key => $val ) { |
|
| 69 | - if ( EEH_Class_Tools::has_property( $this, $key ) ) { |
|
| 68 | + foreach ($props as $key => $val) { |
|
| 69 | + if (EEH_Class_Tools::has_property($this, $key)) { |
|
| 70 | 70 | $this->$key = $val; |
| 71 | 71 | } |
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | //make sure we include the required wp file for needed functions |
| 75 | - require_once( ABSPATH . 'wp-admin/includes/file.php' ); |
|
| 75 | + require_once(ABSPATH.'wp-admin/includes/file.php'); |
|
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | |
@@ -80,16 +80,16 @@ discard block |
||
| 80 | 80 | private function _get_wp_uploads_dir() {} |
| 81 | 81 | |
| 82 | 82 | //setters |
| 83 | - public function set_upload_to( $upload_to_folder ) { |
|
| 83 | + public function set_upload_to($upload_to_folder) { |
|
| 84 | 84 | $this->_upload_to = $upload_to_folder; |
| 85 | 85 | } |
| 86 | - public function set_upload_from( $upload_from_folder ) { |
|
| 86 | + public function set_upload_from($upload_from_folder) { |
|
| 87 | 87 | $this->_upload_from_folder = $upload_from_folder; |
| 88 | 88 | } |
| 89 | - public function set_permissions( $permissions ) { |
|
| 89 | + public function set_permissions($permissions) { |
|
| 90 | 90 | $this->_permissions = $permissions; |
| 91 | 91 | } |
| 92 | - public function set_new_file_name( $new_file_name ) { |
|
| 92 | + public function set_new_file_name($new_file_name) { |
|
| 93 | 93 | $this->_new_file_name = $new_file_name; |
| 94 | 94 | } |
| 95 | 95 | |
@@ -111,34 +111,34 @@ discard block |
||
| 111 | 111 | //upload methods |
| 112 | 112 | public function sideload() { |
| 113 | 113 | //setup temp dir |
| 114 | - $temp_file = wp_tempnam( $this->_upload_from ); |
|
| 114 | + $temp_file = wp_tempnam($this->_upload_from); |
|
| 115 | 115 | |
| 116 | - if ( !$temp_file ) { |
|
| 117 | - EE_Error::add_error( __('Something went wrong with the upload. Unable to create a tmp file for the uploaded file on the server', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__ ); |
|
| 116 | + if ( ! $temp_file) { |
|
| 117 | + EE_Error::add_error(__('Something went wrong with the upload. Unable to create a tmp file for the uploaded file on the server', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
| 118 | 118 | return false; |
| 119 | 119 | } |
| 120 | 120 | |
| 121 | - do_action( 'AHEE__EEH_Sideloader__sideload__before', $this, $temp_file ); |
|
| 121 | + do_action('AHEE__EEH_Sideloader__sideload__before', $this, $temp_file); |
|
| 122 | 122 | |
| 123 | - $wp_remote_args = apply_filters( 'FHEE__EEH_Sideloader__sideload__wp_remote_args', array( 'timeout' => 500, 'stream' => true, 'filename' => $temp_file ), $this, $temp_file ); |
|
| 123 | + $wp_remote_args = apply_filters('FHEE__EEH_Sideloader__sideload__wp_remote_args', array('timeout' => 500, 'stream' => true, 'filename' => $temp_file), $this, $temp_file); |
|
| 124 | 124 | |
| 125 | - $response = wp_safe_remote_get( $this->_upload_from, $wp_remote_args ); |
|
| 125 | + $response = wp_safe_remote_get($this->_upload_from, $wp_remote_args); |
|
| 126 | 126 | |
| 127 | - if ( is_wp_error( $response ) || 200 != wp_remote_retrieve_response_code( $response ) ) { |
|
| 128 | - unlink( $temp_file ); |
|
| 129 | - if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { |
|
| 130 | - EE_Error::add_error( sprintf( __('Unable to upload the file. Either the path given to upload from is incorrect, or something else happened. Here is the response returned:<br />%s<br />Here is the path given: %s', 'event_espresso'), var_export( $response, true ), $this->_upload_from ), __FILE__, __FUNCTION__, __LINE__ ); |
|
| 127 | + if (is_wp_error($response) || 200 != wp_remote_retrieve_response_code($response)) { |
|
| 128 | + unlink($temp_file); |
|
| 129 | + if (defined('WP_DEBUG') && WP_DEBUG) { |
|
| 130 | + EE_Error::add_error(sprintf(__('Unable to upload the file. Either the path given to upload from is incorrect, or something else happened. Here is the response returned:<br />%s<br />Here is the path given: %s', 'event_espresso'), var_export($response, true), $this->_upload_from), __FILE__, __FUNCTION__, __LINE__); |
|
| 131 | 131 | } |
| 132 | 132 | return false; |
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | //possible md5 check |
| 136 | - $content_md5 = wp_remote_retrieve_header( $response, 'content-md5' ); |
|
| 137 | - if ( $content_md5 ) { |
|
| 138 | - $md5_check = verify_file_md5( $temp_file, $content_md5 ); |
|
| 139 | - if ( is_wp_error( $md5_check ) ) { |
|
| 140 | - unlink( $temp_file ); |
|
| 141 | - EE_Error::add_error( $md5_check->get_error_message(), __FILE__, __FUNCTION__, __LINE__ ); |
|
| 136 | + $content_md5 = wp_remote_retrieve_header($response, 'content-md5'); |
|
| 137 | + if ($content_md5) { |
|
| 138 | + $md5_check = verify_file_md5($temp_file, $content_md5); |
|
| 139 | + if (is_wp_error($md5_check)) { |
|
| 140 | + unlink($temp_file); |
|
| 141 | + EE_Error::add_error($md5_check->get_error_message(), __FILE__, __FUNCTION__, __LINE__); |
|
| 142 | 142 | return false; |
| 143 | 143 | } |
| 144 | 144 | } |
@@ -146,24 +146,24 @@ discard block |
||
| 146 | 146 | $file = $temp_file; |
| 147 | 147 | |
| 148 | 148 | //now we have the file, let's get it in the right directory with the right name. |
| 149 | - $path = apply_filters( 'FHEE__EEH_Sideloader__sideload__new_path', $this->_upload_to . $this->_new_file_name, $this ); |
|
| 149 | + $path = apply_filters('FHEE__EEH_Sideloader__sideload__new_path', $this->_upload_to.$this->_new_file_name, $this); |
|
| 150 | 150 | |
| 151 | 151 | //move file in |
| 152 | - if ( false === @ rename( $file, $path ) ) { |
|
| 153 | - unlink( $temp_file ); |
|
| 154 | - EE_Error::add_error( sprintf( __('Unable to move the file to new location (possible permissions errors). This is the path the class attempted to move the file to: %s', 'event_espresso' ), $path ), __FILE__, __FUNCTION__, __LINE__ ); |
|
| 152 | + if (false === @ rename($file, $path)) { |
|
| 153 | + unlink($temp_file); |
|
| 154 | + EE_Error::add_error(sprintf(__('Unable to move the file to new location (possible permissions errors). This is the path the class attempted to move the file to: %s', 'event_espresso'), $path), __FILE__, __FUNCTION__, __LINE__); |
|
| 155 | 155 | return false; |
| 156 | 156 | } |
| 157 | 157 | |
| 158 | 158 | //set permissions |
| 159 | - $permissions = apply_filters( 'FHEE__EEH_Sideloader__sideload__permissions_applied', $this->_permissions, $this ); |
|
| 160 | - chmod( $path, $permissions ); |
|
| 159 | + $permissions = apply_filters('FHEE__EEH_Sideloader__sideload__permissions_applied', $this->_permissions, $this); |
|
| 160 | + chmod($path, $permissions); |
|
| 161 | 161 | |
| 162 | 162 | //that's it. let's allow for actions after file uploaded. |
| 163 | - do_action( 'AHEE__EE_Sideloader__sideload_after', $this, $path ); |
|
| 163 | + do_action('AHEE__EE_Sideloader__sideload_after', $this, $path); |
|
| 164 | 164 | |
| 165 | 165 | //unlink tempfile |
| 166 | - @unlink( $temp_file ); |
|
| 166 | + @unlink($temp_file); |
|
| 167 | 167 | return true; |
| 168 | 168 | } |
| 169 | 169 | |
@@ -44,16 +44,16 @@ discard block |
||
| 44 | 44 | * regardless of access. |
| 45 | 45 | * @return EE_Venue | null |
| 46 | 46 | */ |
| 47 | - public static function get_venue( $VNU_ID = 0, $look_in_event = TRUE, $privacy_check = true ) { |
|
| 48 | - $VNU_ID = absint( $VNU_ID ); |
|
| 47 | + public static function get_venue($VNU_ID = 0, $look_in_event = TRUE, $privacy_check = true) { |
|
| 48 | + $VNU_ID = absint($VNU_ID); |
|
| 49 | 49 | // do we already have the Venue you are looking for? |
| 50 | - if ( EEH_Venue_View::$_venue instanceof EE_Venue && EEH_Venue_View::$_venue->ID() == $VNU_ID ) { |
|
| 51 | - return EEH_Venue_View::_get_venue( $privacy_check ); |
|
| 50 | + if (EEH_Venue_View::$_venue instanceof EE_Venue && EEH_Venue_View::$_venue->ID() == $VNU_ID) { |
|
| 51 | + return EEH_Venue_View::_get_venue($privacy_check); |
|
| 52 | 52 | } |
| 53 | 53 | // international newspaper? |
| 54 | 54 | global $post; |
| 55 | - if ( $post instanceof WP_Post ) { |
|
| 56 | - switch ( $post->post_type ) { |
|
| 55 | + if ($post instanceof WP_Post) { |
|
| 56 | + switch ($post->post_type) { |
|
| 57 | 57 | // if this is being called from an EE_Venue post, |
| 58 | 58 | // and the EE_Venue post corresponds to the EE_Venue that is being asked for, |
| 59 | 59 | // then we can try to just grab the attached EE_Venue object |
@@ -61,31 +61,31 @@ discard block |
||
| 61 | 61 | // the post already contains the related EE_Venue object AND one of the following is TRUE: |
| 62 | 62 | // the requested Venue ID matches the post ID OR... |
| 63 | 63 | // there was no specific Venue ID requested |
| 64 | - if ( isset( $post->EE_Venue ) && ( $VNU_ID == $post->ID || ! $VNU_ID )) { |
|
| 64 | + if (isset($post->EE_Venue) && ($VNU_ID == $post->ID || ! $VNU_ID)) { |
|
| 65 | 65 | // use existing related EE_Venue object |
| 66 | - EEH_Venue_View::$_venue = $post->EE_Venue; |
|
| 67 | - } else if ( $VNU_ID ) { |
|
| 66 | + EEH_Venue_View::$_venue = $post->EE_Venue; |
|
| 67 | + } else if ($VNU_ID) { |
|
| 68 | 68 | // there WAS a specific Venue ID requested, but it's NOT the current post object |
| 69 | - EEH_Venue_View::$_venue = EEM_Venue::instance()->get_one_by_ID( $VNU_ID ); |
|
| 69 | + EEH_Venue_View::$_venue = EEM_Venue::instance()->get_one_by_ID($VNU_ID); |
|
| 70 | 70 | } else { |
| 71 | 71 | // no specific Venue ID requested, so use post ID to generate EE_Venue object |
| 72 | - EEH_Venue_View::$_venue = EEM_Venue::instance()->get_one_by_ID( $post->ID ); |
|
| 72 | + EEH_Venue_View::$_venue = EEM_Venue::instance()->get_one_by_ID($post->ID); |
|
| 73 | 73 | } |
| 74 | 74 | break; |
| 75 | 75 | |
| 76 | 76 | case 'espresso_events': |
| 77 | - if ( $look_in_event ) { |
|
| 77 | + if ($look_in_event) { |
|
| 78 | 78 | // grab the events related venues |
| 79 | 79 | $venues = EEH_Venue_View::get_event_venues(); |
| 80 | 80 | // make sure the result is an array |
| 81 | - $venues = is_array( $venues ) ? $venues : array(); |
|
| 81 | + $venues = is_array($venues) ? $venues : array(); |
|
| 82 | 82 | // do we have an ID for a specific venue? |
| 83 | - if ( $VNU_ID ) { |
|
| 83 | + if ($VNU_ID) { |
|
| 84 | 84 | // loop thru the related venues |
| 85 | - foreach( $venues as $venue ) { |
|
| 86 | - if ( $venue instanceof EE_Venue ) { |
|
| 85 | + foreach ($venues as $venue) { |
|
| 86 | + if ($venue instanceof EE_Venue) { |
|
| 87 | 87 | // until we find the venue we're looking for |
| 88 | - if ( $venue->ID() == $VNU_ID ) { |
|
| 88 | + if ($venue->ID() == $VNU_ID) { |
|
| 89 | 89 | EEH_Venue_View::$_venue = $venue; |
| 90 | 90 | break; |
| 91 | 91 | } |
@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | // then the global post is an events post and this function was called with no argument |
| 98 | 98 | } else { |
| 99 | 99 | // just grab the first related event venue |
| 100 | - EEH_Venue_View::$_venue = reset( $venues ); |
|
| 100 | + EEH_Venue_View::$_venue = reset($venues); |
|
| 101 | 101 | } |
| 102 | 102 | } |
| 103 | 103 | break; |
@@ -105,11 +105,11 @@ discard block |
||
| 105 | 105 | } |
| 106 | 106 | } |
| 107 | 107 | // now if we STILL do NOT have an EE_Venue model object, BUT we have a Venue ID... |
| 108 | - if ( ! EEH_Venue_View::$_venue instanceof EE_Venue && $VNU_ID ) { |
|
| 108 | + if ( ! EEH_Venue_View::$_venue instanceof EE_Venue && $VNU_ID) { |
|
| 109 | 109 | // sigh... pull it from the db |
| 110 | - EEH_Venue_View::$_venue = EEM_Venue::instance()->get_one_by_ID( $VNU_ID ); |
|
| 110 | + EEH_Venue_View::$_venue = EEM_Venue::instance()->get_one_by_ID($VNU_ID); |
|
| 111 | 111 | } |
| 112 | - return EEH_Venue_View::_get_venue( $privacy_check ); |
|
| 112 | + return EEH_Venue_View::_get_venue($privacy_check); |
|
| 113 | 113 | } |
| 114 | 114 | |
| 115 | 115 | |
@@ -121,9 +121,9 @@ discard block |
||
| 121 | 121 | * regardless of access. |
| 122 | 122 | * @return EE_Venue |
| 123 | 123 | */ |
| 124 | - protected static function _get_venue( $privacy_check = true ) { |
|
| 124 | + protected static function _get_venue($privacy_check = true) { |
|
| 125 | 125 | // check for private venues. |
| 126 | - if ( EEH_Venue_View::$_venue instanceof EE_Venue && EEH_Venue_View::$_venue->status() == 'private' && $privacy_check && ! EE_Registry::instance()->CAP->current_user_can( 'ee_read_private_venues', 'get_venues' ) ) { |
|
| 126 | + if (EEH_Venue_View::$_venue instanceof EE_Venue && EEH_Venue_View::$_venue->status() == 'private' && $privacy_check && ! EE_Registry::instance()->CAP->current_user_can('ee_read_private_venues', 'get_venues')) { |
|
| 127 | 127 | return null; |
| 128 | 128 | } |
| 129 | 129 | return EEH_Venue_View::$_venue instanceof EE_Venue ? EEH_Venue_View::$_venue : null; |
@@ -139,8 +139,8 @@ discard block |
||
| 139 | 139 | */ |
| 140 | 140 | public static function get_event_venues() { |
| 141 | 141 | global $post; |
| 142 | - if ( $post->post_type == 'espresso_events' ) { |
|
| 143 | - if ( isset( $post->EE_Event ) && $post->EE_Event instanceof EE_Event ) { |
|
| 142 | + if ($post->post_type == 'espresso_events') { |
|
| 143 | + if (isset($post->EE_Event) && $post->EE_Event instanceof EE_Event) { |
|
| 144 | 144 | return $post->EE_Event->venues(); |
| 145 | 145 | } |
| 146 | 146 | } |
@@ -160,9 +160,9 @@ discard block |
||
| 160 | 160 | * |
| 161 | 161 | * @return bool|null |
| 162 | 162 | */ |
| 163 | - public static function is_venue_private( $VNU_ID = false ) { |
|
| 164 | - $venue = EEH_Venue_View::get_venue( $VNU_ID, true, true ); |
|
| 165 | - if ( ! $venue instanceof EE_Venue ) { |
|
| 163 | + public static function is_venue_private($VNU_ID = false) { |
|
| 164 | + $venue = EEH_Venue_View::get_venue($VNU_ID, true, true); |
|
| 165 | + if ( ! $venue instanceof EE_Venue) { |
|
| 166 | 166 | return null; |
| 167 | 167 | } |
| 168 | 168 | |
@@ -178,9 +178,9 @@ discard block |
||
| 178 | 178 | * @param int $VNU_ID |
| 179 | 179 | * @return string |
| 180 | 180 | */ |
| 181 | - public static function venue_description( $VNU_ID = 0 ) { |
|
| 182 | - $venue = EEH_Venue_View::get_venue( $VNU_ID ); |
|
| 183 | - if ( $venue instanceof EE_Venue ) { |
|
| 181 | + public static function venue_description($VNU_ID = 0) { |
|
| 182 | + $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
| 183 | + if ($venue instanceof EE_Venue) { |
|
| 184 | 184 | return$venue->description(); |
| 185 | 185 | } |
| 186 | 186 | return ''; |
@@ -195,12 +195,12 @@ discard block |
||
| 195 | 195 | * @param int $VNU_ID |
| 196 | 196 | * @return string |
| 197 | 197 | */ |
| 198 | - public static function venue_excerpt( $VNU_ID = 0 ) { |
|
| 199 | - $venue = EEH_Venue_View::get_venue( $VNU_ID ); |
|
| 200 | - if ( $venue instanceof EE_Venue ) { |
|
| 198 | + public static function venue_excerpt($VNU_ID = 0) { |
|
| 199 | + $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
| 200 | + if ($venue instanceof EE_Venue) { |
|
| 201 | 201 | $excerpt = $venue->excerpt() != NULL && $venue->excerpt() ? $venue->excerpt() : $venue->description(); |
| 202 | - $venue_link = ' ' . EEH_Venue_View::venue_details_link( $venue->ID(), __( 'more', 'event_espresso' ) . '…' ); |
|
| 203 | - return ! empty( $excerpt ) ? wp_trim_words( $excerpt, 25, '' ) . $venue_link : ''; |
|
| 202 | + $venue_link = ' '.EEH_Venue_View::venue_details_link($venue->ID(), __('more', 'event_espresso').'…'); |
|
| 203 | + return ! empty($excerpt) ? wp_trim_words($excerpt, 25, '').$venue_link : ''; |
|
| 204 | 204 | } |
| 205 | 205 | return ''; |
| 206 | 206 | } |
@@ -215,22 +215,22 @@ discard block |
||
| 215 | 215 | * @param bool $hide_uncategorized |
| 216 | 216 | * @return string |
| 217 | 217 | */ |
| 218 | - public static function venue_categories( $VNU_ID = 0, $hide_uncategorized = TRUE ) { |
|
| 218 | + public static function venue_categories($VNU_ID = 0, $hide_uncategorized = TRUE) { |
|
| 219 | 219 | $category_links = array(); |
| 220 | - $venue = EEH_Venue_View::get_venue( $VNU_ID ); |
|
| 221 | - if ( $venue instanceof EE_Venue ) { |
|
| 220 | + $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
| 221 | + if ($venue instanceof EE_Venue) { |
|
| 222 | 222 | // get category terms |
| 223 | - if ( $venue_categories = get_the_terms( $venue->ID(), 'espresso_venue_categories' )) { |
|
| 223 | + if ($venue_categories = get_the_terms($venue->ID(), 'espresso_venue_categories')) { |
|
| 224 | 224 | // loop thru terms and create links |
| 225 | - foreach ( $venue_categories as $term ) { |
|
| 226 | - $url = get_term_link( $term, 'espresso_venue_categories' ); |
|
| 227 | - if ( ! is_wp_error( $url ) && (( $hide_uncategorized && strtolower( $term->name ) != __( 'uncategorized', 'event_espresso' )) || ! $hide_uncategorized )) { |
|
| 228 | - $category_links[] = '<a href="' . esc_url( $url ) . '" rel="tag">' . $term->name . '</a> '; |
|
| 225 | + foreach ($venue_categories as $term) { |
|
| 226 | + $url = get_term_link($term, 'espresso_venue_categories'); |
|
| 227 | + if ( ! is_wp_error($url) && (($hide_uncategorized && strtolower($term->name) != __('uncategorized', 'event_espresso')) || ! $hide_uncategorized)) { |
|
| 228 | + $category_links[] = '<a href="'.esc_url($url).'" rel="tag">'.$term->name.'</a> '; |
|
| 229 | 229 | } |
| 230 | 230 | } |
| 231 | 231 | } |
| 232 | 232 | } |
| 233 | - return implode( ', ', $category_links ); |
|
| 233 | + return implode(', ', $category_links); |
|
| 234 | 234 | } |
| 235 | 235 | |
| 236 | 236 | |
@@ -245,11 +245,11 @@ discard block |
||
| 245 | 245 | * @param bool $add_wrapper |
| 246 | 246 | * @return string |
| 247 | 247 | */ |
| 248 | - public static function venue_address( $type = 'multiline', $VNU_ID = 0, $use_schema = true, $add_wrapper = true ) { |
|
| 249 | - $venue = EEH_Venue_View::get_venue( $VNU_ID ); |
|
| 250 | - if ( $venue instanceof EE_Venue ) { |
|
| 251 | - EE_Registry::instance()->load_helper( 'Formatter' ); |
|
| 252 | - return EEH_Address::format( $venue, $type, $use_schema, $add_wrapper ); |
|
| 248 | + public static function venue_address($type = 'multiline', $VNU_ID = 0, $use_schema = true, $add_wrapper = true) { |
|
| 249 | + $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
| 250 | + if ($venue instanceof EE_Venue) { |
|
| 251 | + EE_Registry::instance()->load_helper('Formatter'); |
|
| 252 | + return EEH_Address::format($venue, $type, $use_schema, $add_wrapper); |
|
| 253 | 253 | } |
| 254 | 254 | return ''; |
| 255 | 255 | } |
@@ -263,11 +263,11 @@ discard block |
||
| 263 | 263 | * @param int $VNU_ID |
| 264 | 264 | * @return bool|string |
| 265 | 265 | */ |
| 266 | - public static function venue_has_address( $VNU_ID = 0 ) { |
|
| 267 | - $venue = EEH_Venue_View::get_venue( $VNU_ID ); |
|
| 268 | - if ( $venue instanceof EE_Venue ) { |
|
| 269 | - EE_Registry::instance()->load_helper( 'Formatter' ); |
|
| 270 | - return EEH_Address::format( $venue, 'inline', FALSE, FALSE ); |
|
| 266 | + public static function venue_has_address($VNU_ID = 0) { |
|
| 267 | + $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
| 268 | + if ($venue instanceof EE_Venue) { |
|
| 269 | + EE_Registry::instance()->load_helper('Formatter'); |
|
| 270 | + return EEH_Address::format($venue, 'inline', FALSE, FALSE); |
|
| 271 | 271 | } |
| 272 | 272 | return false; |
| 273 | 273 | } |
@@ -282,31 +282,31 @@ discard block |
||
| 282 | 282 | * @param int $VNU_ID |
| 283 | 283 | * @return string |
| 284 | 284 | */ |
| 285 | - public static function venue_name( $link_to = 'details', $VNU_ID = 0 ) { |
|
| 286 | - $venue = EEH_Venue_View::get_venue( $VNU_ID ); |
|
| 287 | - if ( $venue instanceof EE_Venue ) { |
|
| 288 | - EE_Registry::instance()->load_helper( 'Formatter' ); |
|
| 285 | + public static function venue_name($link_to = 'details', $VNU_ID = 0) { |
|
| 286 | + $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
| 287 | + if ($venue instanceof EE_Venue) { |
|
| 288 | + EE_Registry::instance()->load_helper('Formatter'); |
|
| 289 | 289 | $venue_name = apply_filters( |
| 290 | 290 | 'FHEE__EEH_Venue__venue_name__append_private_venue_name', |
| 291 | 291 | EEH_Venue_View::is_venue_private() |
| 292 | - ? EEH_Venue_View::$_venue->name() . " " . __( '(Private)', 'event_espresso' ) |
|
| 292 | + ? EEH_Venue_View::$_venue->name()." ".__('(Private)', 'event_espresso') |
|
| 293 | 293 | : EEH_Venue_View::$_venue->name(), |
| 294 | 294 | EEH_Venue_View::$_venue |
| 295 | 295 | ); |
| 296 | - $venue_name = EEH_Schema::name( $venue_name ); |
|
| 296 | + $venue_name = EEH_Schema::name($venue_name); |
|
| 297 | 297 | |
| 298 | 298 | //if venue is trashed then ignore the "link to" setting because the venue is trashed. |
| 299 | - if ( $venue->get('status') == 'trash' ) { |
|
| 299 | + if ($venue->get('status') == 'trash') { |
|
| 300 | 300 | $link_to = ''; |
| 301 | 301 | } |
| 302 | - switch( $link_to ) { |
|
| 302 | + switch ($link_to) { |
|
| 303 | 303 | |
| 304 | 304 | case 'details' : |
| 305 | - return EEH_Venue_View::venue_details_link( $venue->ID(), $venue_name ); |
|
| 305 | + return EEH_Venue_View::venue_details_link($venue->ID(), $venue_name); |
|
| 306 | 306 | break; |
| 307 | 307 | |
| 308 | 308 | case 'website' : |
| 309 | - return EEH_Venue_View::venue_website_link( $venue->ID(), $venue_name ); |
|
| 309 | + return EEH_Venue_View::venue_website_link($venue->ID(), $venue_name); |
|
| 310 | 310 | break; |
| 311 | 311 | |
| 312 | 312 | default : |
@@ -326,10 +326,10 @@ discard block |
||
| 326 | 326 | * @param string $text |
| 327 | 327 | * @return string |
| 328 | 328 | */ |
| 329 | - public static function venue_details_link( $VNU_ID = 0, $text = '' ) { |
|
| 330 | - $venue = EEH_Venue_View::get_venue( $VNU_ID ); |
|
| 331 | - if ( $venue instanceof EE_Venue ) { |
|
| 332 | - return EEH_Schema::url( get_permalink( $venue->ID() ), $text ); |
|
| 329 | + public static function venue_details_link($VNU_ID = 0, $text = '') { |
|
| 330 | + $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
| 331 | + if ($venue instanceof EE_Venue) { |
|
| 332 | + return EEH_Schema::url(get_permalink($venue->ID()), $text); |
|
| 333 | 333 | } |
| 334 | 334 | return ''; |
| 335 | 335 | } |
@@ -344,13 +344,13 @@ discard block |
||
| 344 | 344 | * @param string $text |
| 345 | 345 | * @return string |
| 346 | 346 | */ |
| 347 | - public static function venue_website_link( $VNU_ID = 0, $text = '' ) { |
|
| 348 | - $venue = EEH_Venue_View::get_venue( $VNU_ID ); |
|
| 349 | - if ( $venue instanceof EE_Venue ) { |
|
| 350 | - EE_Registry::instance()->load_helper( 'Formatter' ); |
|
| 347 | + public static function venue_website_link($VNU_ID = 0, $text = '') { |
|
| 348 | + $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
| 349 | + if ($venue instanceof EE_Venue) { |
|
| 350 | + EE_Registry::instance()->load_helper('Formatter'); |
|
| 351 | 351 | $url = $venue->venue_url(); |
| 352 | - $text = ! empty( $text ) ? $text : $url; |
|
| 353 | - return ! empty( $url ) ? EEH_Schema::url( $url, $text ) : ''; |
|
| 352 | + $text = ! empty($text) ? $text : $url; |
|
| 353 | + return ! empty($url) ? EEH_Schema::url($url, $text) : ''; |
|
| 354 | 354 | } |
| 355 | 355 | return ''; |
| 356 | 356 | } |
@@ -364,11 +364,11 @@ discard block |
||
| 364 | 364 | * @param int $VNU_ID |
| 365 | 365 | * @return string |
| 366 | 366 | */ |
| 367 | - public static function venue_phone( $VNU_ID = 0) { |
|
| 368 | - $venue = EEH_Venue_View::get_venue( $VNU_ID ); |
|
| 369 | - if ( $venue instanceof EE_Venue ) { |
|
| 370 | - EE_Registry::instance()->load_helper( 'Formatter' ); |
|
| 371 | - return EEH_Schema::telephone( $venue->phone() ); |
|
| 367 | + public static function venue_phone($VNU_ID = 0) { |
|
| 368 | + $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
| 369 | + if ($venue instanceof EE_Venue) { |
|
| 370 | + EE_Registry::instance()->load_helper('Formatter'); |
|
| 371 | + return EEH_Schema::telephone($venue->phone()); |
|
| 372 | 372 | } |
| 373 | 373 | return ''; |
| 374 | 374 | } |
@@ -384,51 +384,51 @@ discard block |
||
| 384 | 384 | * @param array $gmap map options |
| 385 | 385 | * @return string |
| 386 | 386 | */ |
| 387 | - public static function venue_gmap( $VNU_ID = 0, $map_ID = FALSE, $gmap = array() ) { |
|
| 387 | + public static function venue_gmap($VNU_ID = 0, $map_ID = FALSE, $gmap = array()) { |
|
| 388 | 388 | |
| 389 | - $venue = EEH_Venue_View::get_venue( $VNU_ID ); |
|
| 390 | - if ( $venue instanceof EE_Venue ) { |
|
| 389 | + $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
| 390 | + if ($venue instanceof EE_Venue) { |
|
| 391 | 391 | // check for global espresso_events post and use it's ID if no map_ID is set |
| 392 | 392 | global $post; |
| 393 | - $map_ID = empty( $map_ID ) && $post->post_type == 'espresso_events' ? $post->ID : $map_ID; |
|
| 393 | + $map_ID = empty($map_ID) && $post->post_type == 'espresso_events' ? $post->ID : $map_ID; |
|
| 394 | 394 | // grab map settings |
| 395 | 395 | $map_cfg = EE_Registry::instance()->CFG->map_settings; |
| 396 | 396 | // are maps enabled ? |
| 397 | - if ( $map_cfg->use_google_maps && $venue->enable_for_gmap() ) { |
|
| 397 | + if ($map_cfg->use_google_maps && $venue->enable_for_gmap()) { |
|
| 398 | 398 | |
| 399 | - EE_Registry::instance()->load_helper( 'Maps' ); |
|
| 400 | - EE_Registry::instance()->load_helper( 'Formatter' ); |
|
| 399 | + EE_Registry::instance()->load_helper('Maps'); |
|
| 400 | + EE_Registry::instance()->load_helper('Formatter'); |
|
| 401 | 401 | |
| 402 | 402 | $details_page = is_single(); |
| 403 | 403 | $options = array(); |
| 404 | - $options['map_ID'] = $map_ID && $map_ID != $venue->ID() ? $map_ID . '-' . $venue->ID()/* . '-' . $static_map_id*/ : $venue->ID()/* . '-' . $static_map_id*/; |
|
| 404 | + $options['map_ID'] = $map_ID && $map_ID != $venue->ID() ? $map_ID.'-'.$venue->ID()/* . '-' . $static_map_id*/ : $venue->ID()/* . '-' . $static_map_id*/; |
|
| 405 | 405 | |
| 406 | - $options['location'] = EEH_Address::format( $venue, 'inline', FALSE, FALSE ); |
|
| 406 | + $options['location'] = EEH_Address::format($venue, 'inline', FALSE, FALSE); |
|
| 407 | 407 | |
| 408 | 408 | $options['ee_map_width'] = $details_page ? $map_cfg->event_details_map_width : $map_cfg->event_list_map_width; |
| 409 | - $options['ee_map_width'] = isset( $gmap['ee_map_width'] ) && ! empty( $gmap['ee_map_width'] ) ? $gmap['ee_map_width'] : $options['ee_map_width']; |
|
| 409 | + $options['ee_map_width'] = isset($gmap['ee_map_width']) && ! empty($gmap['ee_map_width']) ? $gmap['ee_map_width'] : $options['ee_map_width']; |
|
| 410 | 410 | |
| 411 | 411 | $options['ee_map_height'] = $details_page ? $map_cfg->event_details_map_height : $map_cfg->event_list_map_height; |
| 412 | - $options['ee_map_height'] = isset( $gmap['ee_map_height'] ) && ! empty( $gmap['ee_map_height'] ) ? $gmap['ee_map_height'] : $options['ee_map_height']; |
|
| 412 | + $options['ee_map_height'] = isset($gmap['ee_map_height']) && ! empty($gmap['ee_map_height']) ? $gmap['ee_map_height'] : $options['ee_map_height']; |
|
| 413 | 413 | |
| 414 | 414 | $options['ee_map_zoom'] = $details_page ? $map_cfg->event_details_map_zoom : $map_cfg->event_list_map_zoom; |
| 415 | - $options['ee_map_zoom'] = isset( $gmap['ee_map_zoom'] ) && ! empty( $gmap['ee_map_zoom'] ) ? $gmap['ee_map_zoom'] : $options['ee_map_zoom']; |
|
| 415 | + $options['ee_map_zoom'] = isset($gmap['ee_map_zoom']) && ! empty($gmap['ee_map_zoom']) ? $gmap['ee_map_zoom'] : $options['ee_map_zoom']; |
|
| 416 | 416 | |
| 417 | 417 | $options['ee_map_nav_display'] = $details_page ? $map_cfg->event_details_display_nav : $map_cfg->event_list_display_nav; |
| 418 | - $options['ee_map_nav_display'] = isset( $gmap['ee_map_nav_display'] ) && ! empty( $gmap['ee_map_nav_display'] ) ? 'true' : $options['ee_map_nav_display'];; |
|
| 418 | + $options['ee_map_nav_display'] = isset($gmap['ee_map_nav_display']) && ! empty($gmap['ee_map_nav_display']) ? 'true' : $options['ee_map_nav_display']; ; |
|
| 419 | 419 | |
| 420 | 420 | $options['ee_map_nav_size'] = $details_page ? $map_cfg->event_details_nav_size : $map_cfg->event_list_nav_size; |
| 421 | - $options['ee_map_nav_size'] = isset( $gmap['ee_map_nav_size'] ) && ! empty( $gmap['ee_map_nav_size'] )? $gmap['ee_map_nav_size'] : $options['ee_map_nav_size']; |
|
| 421 | + $options['ee_map_nav_size'] = isset($gmap['ee_map_nav_size']) && ! empty($gmap['ee_map_nav_size']) ? $gmap['ee_map_nav_size'] : $options['ee_map_nav_size']; |
|
| 422 | 422 | |
| 423 | 423 | $options['ee_map_type_control'] = $details_page ? $map_cfg->event_details_control_type : $map_cfg->event_list_control_type; |
| 424 | - $options['ee_map_type_control'] = isset( $gmap['ee_map_type_control'] ) && ! empty( $gmap['ee_map_type_control'] )? $gmap['ee_map_type_control'] : $options['ee_map_type_control']; |
|
| 424 | + $options['ee_map_type_control'] = isset($gmap['ee_map_type_control']) && ! empty($gmap['ee_map_type_control']) ? $gmap['ee_map_type_control'] : $options['ee_map_type_control']; |
|
| 425 | 425 | |
| 426 | 426 | $options['ee_map_align'] = $details_page ? $map_cfg->event_details_map_align : $map_cfg->event_list_map_align; |
| 427 | - $options['ee_map_align'] = isset( $gmap['ee_map_align'] ) && ! empty( $gmap['ee_map_align'] )? $gmap['ee_map_align'] : $options['ee_map_align']; |
|
| 427 | + $options['ee_map_align'] = isset($gmap['ee_map_align']) && ! empty($gmap['ee_map_align']) ? $gmap['ee_map_align'] : $options['ee_map_align']; |
|
| 428 | 428 | |
| 429 | - $options['ee_static_url'] = isset( $gmap['ee_static_url'] ) && ! empty( $gmap['ee_static_url'] ) ? (bool)absint( $gmap['ee_static_url'] ) : $venue->google_map_link(); |
|
| 429 | + $options['ee_static_url'] = isset($gmap['ee_static_url']) && ! empty($gmap['ee_static_url']) ? (bool) absint($gmap['ee_static_url']) : $venue->google_map_link(); |
|
| 430 | 430 | |
| 431 | - return EEH_Maps::google_map( $options ); |
|
| 431 | + return EEH_Maps::google_map($options); |
|
| 432 | 432 | |
| 433 | 433 | } |
| 434 | 434 | } |
@@ -443,7 +443,7 @@ discard block |
||
| 443 | 443 | * @param array $atts like EEH_Maps::google_map_link |
| 444 | 444 | * @return string |
| 445 | 445 | */ |
| 446 | - public static function espresso_google_static_map( EE_Venue $venue, $atts = array() ){ |
|
| 446 | + public static function espresso_google_static_map(EE_Venue $venue, $atts = array()) { |
|
| 447 | 447 | EE_Registry::instance()->load_helper('Maps'); |
| 448 | 448 | $state = $venue->state_obj(); |
| 449 | 449 | $country = $venue->country_obj(); |
@@ -475,23 +475,23 @@ discard block |
||
| 475 | 475 | * @param string $after |
| 476 | 476 | * @return string |
| 477 | 477 | */ |
| 478 | - public static function edit_venue_link( $VNU_ID = 0, $link = '', $before = '<p class="edit-venue-lnk small-txt">', $after = '</p>' ) { |
|
| 479 | - $venue = EEH_Venue_View::get_venue( $VNU_ID ); |
|
| 480 | - if ( $venue instanceof EE_Venue ) { |
|
| 478 | + public static function edit_venue_link($VNU_ID = 0, $link = '', $before = '<p class="edit-venue-lnk small-txt">', $after = '</p>') { |
|
| 479 | + $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
| 480 | + if ($venue instanceof EE_Venue) { |
|
| 481 | 481 | // can the user edit this post ? |
| 482 | - if ( current_user_can( 'edit_post', $venue->ID() )) { |
|
| 482 | + if (current_user_can('edit_post', $venue->ID())) { |
|
| 483 | 483 | // set link text |
| 484 | - $link = ! empty( $link ) ? $link : __('edit this venue'); |
|
| 484 | + $link = ! empty($link) ? $link : __('edit this venue'); |
|
| 485 | 485 | // generate nonce |
| 486 | - $nonce = wp_create_nonce( 'edit_nonce' ); |
|
| 486 | + $nonce = wp_create_nonce('edit_nonce'); |
|
| 487 | 487 | // generate url to venue editor for this venue |
| 488 | - $url = add_query_arg( array( 'page' => 'espresso_venues', 'action' => 'edit', 'post' => $venue->ID(), 'edit_nonce' => $nonce ), admin_url( 'admin.php' ) ); |
|
| 488 | + $url = add_query_arg(array('page' => 'espresso_venues', 'action' => 'edit', 'post' => $venue->ID(), 'edit_nonce' => $nonce), admin_url('admin.php')); |
|
| 489 | 489 | // get edit CPT text |
| 490 | - $post_type_obj = get_post_type_object( 'espresso_venues' ); |
|
| 490 | + $post_type_obj = get_post_type_object('espresso_venues'); |
|
| 491 | 491 | // build final link html |
| 492 | - $link = '<a class="post-edit-link" href="' . $url . '" title="' . esc_attr( $post_type_obj->labels->edit_item ) . '">' . $link . '</a>'; |
|
| 492 | + $link = '<a class="post-edit-link" href="'.$url.'" title="'.esc_attr($post_type_obj->labels->edit_item).'">'.$link.'</a>'; |
|
| 493 | 493 | // put it all together |
| 494 | - return $before . apply_filters( 'edit_post_link', $link, $venue->ID() ) . $after; |
|
| 494 | + return $before.apply_filters('edit_post_link', $link, $venue->ID()).$after; |
|
| 495 | 495 | } |
| 496 | 496 | } |
| 497 | 497 | return ''; |
@@ -1,4 +1,6 @@ |
||
| 1 | -<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed'); |
|
| 1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 2 | + exit('No direct script access allowed'); |
|
| 3 | +} |
|
| 2 | 4 | /** |
| 3 | 5 | * Event Espresso |
| 4 | 6 | * |
@@ -1,20 +1,20 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -class EE_Sample_Form extends EE_Form_Section_Proper{ |
|
| 3 | - function __construct(){ |
|
| 2 | +class EE_Sample_Form extends EE_Form_Section_Proper { |
|
| 3 | + function __construct() { |
|
| 4 | 4 | $this->_subsections = array( |
| 5 | 5 | 'h1'=>new EE_Form_Section_HTML('hello wordl'), |
| 6 | - 'name'=>new EE_Text_Input(array('required'=>true,'default'=>'your name here')), |
|
| 6 | + 'name'=>new EE_Text_Input(array('required'=>true, 'default'=>'your name here')), |
|
| 7 | 7 | 'email'=>new EE_Email_Input(array('required'=>false)), |
| 8 | - 'shirt_size'=>new EE_Select_Input(array(''=>'Please select...', 's'=> __("Small", "event_espresso"),'m'=> __("Medium", "event_espresso"),'l'=> __("Large", "event_espresso")),array('required'=>true,'default'=>'s')), |
|
| 8 | + 'shirt_size'=>new EE_Select_Input(array(''=>'Please select...', 's'=> __("Small", "event_espresso"), 'm'=> __("Medium", "event_espresso"), 'l'=> __("Large", "event_espresso")), array('required'=>true, 'default'=>'s')), |
|
| 9 | 9 | 'month_normal'=>new EE_Month_Input(), |
| 10 | 10 | 'month_leading_zero'=>new EE_Month_Input(true), |
| 11 | 11 | 'year_2'=>new EE_Year_Input(false, 1, 1), |
| 12 | - 'year_4'=>new EE_Year_Input(true, 0,10,array('default'=>'2017')), |
|
| 12 | + 'year_4'=>new EE_Year_Input(true, 0, 10, array('default'=>'2017')), |
|
| 13 | 13 | 'yes_no'=>new EE_Yes_No_Input(array('html_label_text'=> __("Yes or No", "event_espresso"))), |
| 14 | 14 | 'credit_card'=>new EE_Credit_Card_Input(), |
| 15 | 15 | 'image_1'=>new EE_Admin_File_Uploader_Input(), |
| 16 | 16 | 'image_2'=>new EE_Admin_File_Uploader_Input(), |
| 17 | - 'skillz'=>new EE_Checkbox_Multi_Input(array('php'=>'PHP','mysql'=>'MYSQL'),array('default'=>array('php'))), |
|
| 17 | + 'skillz'=>new EE_Checkbox_Multi_Input(array('php'=>'PHP', 'mysql'=>'MYSQL'), array('default'=>array('php'))), |
|
| 18 | 18 | 'float'=>new EE_Float_Input(), |
| 19 | 19 | 'essay'=>new EE_Text_Area_Input(), |
| 20 | 20 | 'amenities'=>new EE_Select_Multiple_Input( |
@@ -40,16 +40,16 @@ discard block |
||
| 40 | 40 | * Extra validation for the 'name' input. |
| 41 | 41 | * @param EE_Text_Input $form_input |
| 42 | 42 | */ |
| 43 | - function _validate_name($form_input){ |
|
| 44 | - if($form_input->raw_value() != 'Mike'){ |
|
| 43 | + function _validate_name($form_input) { |
|
| 44 | + if ($form_input->raw_value() != 'Mike') { |
|
| 45 | 45 | $form_input->add_validation_error(__("You are not mike. You must be brent or darren. Thats ok, I guess", 'event_espresso'), 'not-mike'); |
| 46 | 46 | } |
| 47 | 47 | } |
| 48 | 48 | |
| 49 | - function _validate(){ |
|
| 49 | + function _validate() { |
|
| 50 | 50 | parent::_validate(); |
| 51 | - if($this->_subsections['shirt_size']->normalized_value() =='s' |
|
| 52 | - && $this->_subsections['year_4']->normalized_value() < 2010){ |
|
| 51 | + if ($this->_subsections['shirt_size']->normalized_value() == 's' |
|
| 52 | + && $this->_subsections['year_4']->normalized_value() < 2010) { |
|
| 53 | 53 | $this->add_validation_error(__("If you want a small shirt, you should be born after 2010. Otherwise theyre just too big", 'event_espresso'), 'too-old'); |
| 54 | 54 | } |
| 55 | 55 | } |