From 46a78e6936989fa296419bd1e29bb6a12a86a477 Mon Sep 17 00:00:00 2001 From: Gerhard Date: Wed, 26 Feb 2014 13:54:16 +0200 Subject: [PATCH] Coding standards, mostly braces --- includes/class-wc-download-handler.php | 62 +++++++++++++++++--------- 1 file changed, 40 insertions(+), 22 deletions(-) diff --git a/includes/class-wc-download-handler.php b/includes/class-wc-download-handler.php index 53e64571d2d..01eca5da6f7 100644 --- a/includes/class-wc-download-handler.php +++ b/includes/class-wc-download-handler.php @@ -33,8 +33,9 @@ class WC_Download_Handler { $download_id = isset( $_GET['key'] ) ? preg_replace( '/\s+/', ' ', $_GET['key'] ) : ''; $_product = get_product( $product_id ); - if ( ! is_email( $email) ) + if ( ! is_email( $email) ) { wp_die( __( 'Invalid email address.', 'woocommerce' ) . ' ' . __( 'Go to homepage', 'woocommerce' ) . '' ); + } $query = " SELECT order_id,downloads_remaining,user_id,download_count,access_expires,download_id @@ -57,8 +58,9 @@ class WC_Download_Handler { $download_result = $wpdb->get_row( $wpdb->prepare( $query, $args ) ); - if ( ! $download_result ) + if ( ! $download_result ) { wp_die( __( 'Invalid download.', 'woocommerce' ) . ' ' . __( 'Go to homepage', 'woocommerce' ) . '' ); + } $download_id = $download_result->download_id; $order_id = $download_result->order_id; @@ -69,29 +71,33 @@ class WC_Download_Handler { if ( $user_id && get_option( 'woocommerce_downloads_require_login' ) == 'yes' ) { - if ( ! is_user_logged_in() ) + if ( ! is_user_logged_in() ) { wp_die( __( 'You must be logged in to download files.', 'woocommerce' ) . ' ' . __( 'Login', 'woocommerce' ) . '', __( 'Log in to Download Files', 'woocommerce' ) ); - - elseif ( !current_user_can( 'download_file', $download_result ) ) + } elseif ( ! current_user_can( 'download_file', $download_result ) ) { wp_die( __( 'This is not your download link.', 'woocommerce' ) ); + } } - if ( ! get_post( $product_id ) ) + if ( ! get_post( $product_id ) ) { wp_die( __( 'Product no longer exists.', 'woocommerce' ) . ' ' . __( 'Go to homepage', 'woocommerce' ) . '' ); + } if ( $order_id ) { $order = new WC_Order( $order_id ); - if ( ! $order->is_download_permitted() || $order->post_status != 'publish' ) + if ( ! $order->is_download_permitted() || $order->post_status != 'publish' ) { wp_die( __( 'Invalid order.', 'woocommerce' ) . ' ' . __( 'Go to homepage', 'woocommerce' ) . '' ); + } } - if ( $downloads_remaining == '0' ) + if ( $downloads_remaining == '0' ) { wp_die( __( 'Sorry, you have reached your download limit for this file', 'woocommerce' ) . ' ' . __( 'Go to homepage', 'woocommerce' ) . '' ); + } - if ( $access_expires > 0 && strtotime( $access_expires) < current_time( 'timestamp' ) ) + if ( $access_expires > 0 && strtotime( $access_expires) < current_time( 'timestamp' ) ) { wp_die( __( 'Sorry, this download has expired', 'woocommerce' ) . ' ' . __( 'Go to homepage', 'woocommerce' ) . '' ); + } if ( $downloads_remaining > 0 ) { $wpdb->update( $wpdb->prefix . "woocommerce_downloadable_product_permissions", array( @@ -133,8 +139,9 @@ class WC_Download_Handler { $file_download_method = apply_filters( 'woocommerce_file_download_method', get_option( 'woocommerce_file_download_method' ), $product_id ); - if ( ! $file_path ) + if ( ! $file_path ) { wp_die( __( 'No file defined', 'woocommerce' ) . ' ' . __( 'Go to homepage', 'woocommerce' ) . '' ); + } // Redirect to the file... if ( $file_download_method == "redirect" ) { @@ -181,8 +188,9 @@ class WC_Download_Handler { $remote_file = false; // Remove Query String - if ( strstr( $file_path, '?' ) ) + if ( strstr( $file_path, '?' ) ) { $file_path = current( explode( '?', $file_path ) ); + } $file_path = realpath( $file_path ); } @@ -199,14 +207,17 @@ class WC_Download_Handler { } // Start setting headers - if ( ! ini_get('safe_mode') ) + if ( ! ini_get('safe_mode') ) { @set_time_limit(0); + } - if ( function_exists( 'get_magic_quotes_runtime' ) && get_magic_quotes_runtime() ) + if ( function_exists( 'get_magic_quotes_runtime' ) && get_magic_quotes_runtime() ) { @set_magic_quotes_runtime(0); + } - if( function_exists( 'apache_setenv' ) ) + if ( function_exists( 'apache_setenv' ) ) { @apache_setenv( 'no-gzip', 1 ); + } @session_write_close(); @ini_set( 'zlib.output_compression', 'Off' ); @@ -236,8 +247,9 @@ class WC_Download_Handler { $file_name = basename( $file_path ); - if ( strstr( $file_name, '?' ) ) + if ( strstr( $file_name, '?' ) ) { $file_name = current( explode( '?', $file_name ) ); + } header( "X-Robots-Tag: noindex, nofollow", true ); header( "Content-Type: " . $ctype ); @@ -245,14 +257,16 @@ class WC_Download_Handler { header( "Content-Disposition: attachment; filename=\"" . $file_name . "\";" ); header( "Content-Transfer-Encoding: binary" ); - if ( $size = @filesize( $file_path ) ) + if ( $size = @filesize( $file_path ) ) { header( "Content-Length: " . $size ); + } if ( $file_download_method == 'xsendfile' ) { // Path fix - kudos to Jason Judge - if ( getcwd() ) + if ( getcwd() ) { $file_path = trim( preg_replace( '`^' . str_replace( '\\', '/', getcwd() ) . '`' , '', $file_path ), '/' ); + } header( "Content-Disposition: attachment; filename=\"" . $file_name . "\";" ); @@ -274,10 +288,11 @@ class WC_Download_Handler { } } - if ( $remote_file ) + if ( $remote_file ) { $this->readfile_chunked( $file_path ) or header( 'Location: ' . $file_path ); - else + } else { $this->readfile_chunked( $file_path ) or wp_die( __( 'File not found', 'woocommerce' ) . ' ' . __( 'Go to homepage', 'woocommerce' ) . '' ); + } exit; } @@ -297,8 +312,9 @@ class WC_Download_Handler { $cnt = 0; $handle = @fopen( $file, 'r' ); - if ( $handle === FALSE ) + if ( $handle === FALSE ) { return FALSE; + } while ( ! feof( $handle ) ) { $buffer = fread( $handle, $chunksize ); @@ -306,14 +322,16 @@ class WC_Download_Handler { ob_flush(); flush(); - if ( $retbytes ) + if ( $retbytes ) { $cnt += strlen( $buffer ); + } } $status = fclose( $handle ); - if ( $retbytes && $status ) + if ( $retbytes && $status ) { return $cnt; + } return $status; }