diff --git a/wpsc-admin/init.php b/wpsc-admin/init.php index 779634aec9..99e8c603d5 100644 --- a/wpsc-admin/init.php +++ b/wpsc-admin/init.php @@ -44,8 +44,39 @@ function wpsc_delete_file() { } -if ( isset( $_REQUEST['wpsc_admin_action'] ) && ($_REQUEST['wpsc_admin_action'] == 'delete_file') ) +if ( isset( $_REQUEST['wpsc_admin_action'] ) && ($_REQUEST['wpsc_admin_action'] == 'delete_file') ) { add_action( 'admin_init', 'wpsc_delete_file' ); +} + +if ( isset( $_REQUEST['wpsc_admin_action'] ) && ($_REQUEST['wpsc_admin_action'] == 'release_file') ) { + add_action( 'admin_init', 'wpsc_release_file' ); +} + +function wpsc_release_file() { + $product_id = absint( $_REQUEST['product_id'] ); + $file_id = basename( $_REQUEST['file_id'] ); + $file_name = basename( $_REQUEST['file_name'] ); + + check_admin_referer( 'release_file_' . $file_name ); + + update_post_meta( $product_id, '_wpsc_product_current_file', $file_id ); + + $sendback = wp_get_referer(); + wp_redirect( $sendback ); + exit; +} + +function _wpec_ajax_update_file() { + if ( ! wp_verify_nonce( $_POST['_ajax_nonce'], 'wpec_update_file_' . $_POST['id'] ) ) + _wpec_ajax_error( 'Invalid nonce.' ); + + + update_post_meta( $_POST['id'], '_wpsc_product_file_version', $_POST['version'] ); + + _wpec_ajax_response( array( 'message' => 'Successfully updated file.' ) ); +} + +add_action( 'wp_ajax_wpec-update-file', '_wpec_ajax_update_file' ); /** * Function and action for publishing or unpublishing single products diff --git a/wpsc-includes/form-display.functions.php b/wpsc-includes/form-display.functions.php index 9f98621407..ba25e21dd8 100755 --- a/wpsc-includes/form-display.functions.php +++ b/wpsc-includes/form-display.functions.php @@ -76,6 +76,7 @@ function wpsc_select_product_file( $product_id = null ) { $output .= ''; $output .= ''; $output .= '' . _x( 'Title', 'Digital download UI', 'wpsc' ) . ''; + $output .= '' . _x( 'Version', 'Digital download UI', 'wpsc' ) . ''; $output .= '' . _x( 'Size', 'Digital download UI', 'wpsc' ) . ''; $output .= '' . _x( 'File Type', 'Digital download UI', 'wpsc' ) . ''; $output .= '' . _x( 'Actions', 'Digital download UI', 'wpsc' ) . ''; @@ -84,6 +85,7 @@ function wpsc_select_product_file( $product_id = null ) { $output .= ''; $output .= ''; $output .= '' . _x( 'Title', 'Digital download UI', 'wpsc' ) . ''; + $output .= '' . _x( 'Version', 'Digital download UI', 'wpsc' ) . ''; $output .= '' . _x( 'Size', 'Digital download UI', 'wpsc' ) . ''; $output .= '' . _x( 'File Type', 'Digital download UI', 'wpsc' ) . ''; $output .= '' . _x( 'Actions', 'Digital download UI', 'wpsc' ) . ''; @@ -94,6 +96,7 @@ function wpsc_select_product_file( $product_id = null ) { $output .= ''; $delete_nonce = _wpsc_create_ajax_nonce( 'delete_file' ); + $release_nonce = _wpsc_create_ajax_nonce( 'release_file' ); foreach ( (array)$attached_files as $file ) { $file_dir = WPSC_FILE_DIR . $file->post_title; @@ -107,17 +110,24 @@ function wpsc_select_product_file( $product_id = null ) { admin_url() ); $deletion_url = wp_nonce_url( "admin.php?wpsc_admin_action=delete_file&file_name={$file->post_title}&product_id={$product_id}&row_number={$num}", 'delete_file_' . $file->post_title ); - + $release_url = wp_nonce_url( "admin.php?wpsc_admin_action=release_file&file_name={$file->post_title}&file_id={$file->ID}&product_id={$product_id}&row_number={$num}", 'release_file_' . $file->post_title ); + $class = ( ! wpsc_is_odd( $num ) ) ? 'alternate' : ''; $file_type = get_post_mime_type($file->ID); $icon_url = wp_mime_type_icon($file_type); + $file_version = get_product_meta( $file->ID, '_wpsc_product_file_version', true ); + $released = get_post_meta( $product_id, '_wpsc_product_current_file', true ) == $file->ID ? ' [current]' : ''; $output .= ''; - $output .= '' . $file->post_title . ''; + $output .= '' . $file->post_title . ' '.$released.' '; + $output .= '' . $file_version .'
'; $output .= '' . $file_size .''; $output .= '' . $file_type . ''; - $output .= '' . _x( 'Download', 'Digital download row UI', 'wpsc' ) . '' . _x( "Delete", "Digital download row UI", "wpsc" ) . ''; + $output .= '' . _x( 'Download', 'Digital download row UI', 'wpsc' ) . ' + ' . _x( "Delete", "Digital download row UI", "wpsc" ) . ' + ' . _x( "Release", "Digital download row UI", "wpsc" ) . ' + '; $output .= '';