Fixes #2897: Long query string displayed as part of download file name

This commit is contained in:
Brad Touesnard 2013-04-07 15:13:47 -03:00
parent fa91ef80d4
commit f6892a676c
3 changed files with 19 additions and 2 deletions

View File

@ -41,12 +41,14 @@ foreach ($items as $item) :
foreach ( $download_file_urls as $file_url => $download_file_url ) {
echo '<br/><small>';
$filename = woocommerce_get_filename_from_url( $file_url );
if ( count( $download_file_urls ) > 1 ) {
echo sprintf( __('Download %d:', 'woocommerce' ), $i + 1 );
} elseif ( $i == 0 )
echo __( 'Download:', 'woocommerce' );
echo ' <a href="' . $download_file_url . '" target="_blank">' . current( explode( '?', basename( $file_url ) ) ) . '</a></small>';
echo ' <a href="' . $download_file_url . '" target="_blank">' . $filename . '</a></small>';
$i++;
}

View File

@ -59,7 +59,9 @@ $order = new WC_Order( $order_id );
foreach ( $download_file_urls as $file_url => $download_file_url ) {
$links[] = '<small><a href="' . $download_file_url . '">' . sprintf( __( 'Download file%s', 'woocommerce' ), ( count( $download_file_urls ) > 1 ? ' ' . ( $i + 1 ) . ': ' : ': ' ) ) . basename( $file_url ) . '</a></small>';
$filename = woocommerce_get_filename_from_url( $file_url );
$links[] = '<small><a href="' . $download_file_url . '">' . sprintf( __( 'Download file%s', 'woocommerce' ), ( count( $download_file_urls ) > 1 ? ' ' . ( $i + 1 ) . ': ' : ': ' ) ) . $filename . '</a></small>';
$i++;
}

View File

@ -1717,3 +1717,16 @@ function woocommerce_save_address() {
}
add_action( 'template_redirect', 'woocommerce_save_address' );
/**
* Gets the filename part of a download URL
*
* @access public
* @param string $file_url
* @return string
*/
function woocommerce_get_filename_from_url( $file_url ) {
$parts = parse_url( $file_url );
return basename( $parts['path'] );
}