Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix product image caching system littering the monthly upload tree #4

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ Author: Marko Miljus (Incsub), Aaron Edwards (Incsub), Hoang Ngo (Incsub), Jonat
Change Log:
----------------------------------------------------------------------

3.4.0
----------------------------------------------------------------------
- Fix: Product image caching system littering the monthly upload tree


3.3.0
----------------------------------------------------------------------
- Added: Added new filter mp_media_buttons to disable/enable shortcode buttons in visual editor.
Expand Down Expand Up @@ -230,11 +235,11 @@ Change Log:
3.0.0.7
----------------------------------------------------------------------
- Fixed: Issue with PDF Invoice add-on after complete order
- Fixed: Issues with ProSites add-on on multisite/network
- Fixed: Issues with ProSites add-on on multisite/network
- Fixed: Adding related product to cart
- Fixed: Compatibilities issues with Select2 and themes
- Fixed: Products not showing on main/sub-sites on multisite/network
- Fixed: Various issues with Global widgets
- Fixed: Products not showing on main/sub-sites on multisite/network
- Fixed: Various issues with Global widgets
- Fixed: Missing company information on orders
- Fixed: Issue with 2Checkout finishing the order
- Fixed: Issues with PayPal chained payments
Expand All @@ -258,7 +263,7 @@ Change Log:
- Tweaked: Added new option for Digital Products, collect full or basic customer details
- Tweaked: Hide shipping details if collect basic customer details is selected for Digital Products
- Tweaked: Added a notice when quick-setup is not completed
- Tweaked: Quick-setup now runs on new subsites on multisite/network
- Tweaked: Quick-setup now runs on new subsites on multisite/network
- Tweaked: More order detailed values on order page (admin)
- Tweaked: Added option to hide/show products filter on products archives pages
- Tweaked: Removed unused CSS files
Expand Down Expand Up @@ -384,7 +389,7 @@ Adding notice for deprecated gateways Cubepoints, Bitpay, iDEAL, Skrill, Google

2.9.6.2
----------------------------------------------------------------------
- Fixed issue with collecting billing address for digital products (when "Collect Address on Downloadable Only Cart" is checked and shipping method is not set)
- Fixed issue with collecting billing address for digital products (when "Collect Address on Downloadable Only Cart" is checked and shipping method is not set)

2.9.6.1
----------------------------------------------------------------------
Expand Down Expand Up @@ -469,7 +474,7 @@ Adding notice for deprecated gateways Cubepoints, Bitpay, iDEAL, Skrill, Google
----------------------------------------------------------------------
- Fixed: File download issue that some users were reporting
- Fixed: Conflicts with Ultimatum theme http://wp.mu/9tt
- Fixed: Global Product Widget is showing a description under each product even when "content to show" is set to none http://wp.mu/9u8
- Fixed: Global Product Widget is showing a description under each product even when "content to show" is set to none http://wp.mu/9u8
- Fixed: Shipping not being calculated correctly when using global cart and multiple shipping methods http://wp.mu/a0a
- Fixed: Issue with shipping/billing fields displaying incorrect values in admin http://wp.mu/a0b
- Fixed: Double escaping in global product list widget title http://wp.mu/a0e
Expand All @@ -479,7 +484,7 @@ Adding notice for deprecated gateways Cubepoints, Bitpay, iDEAL, Skrill, Google
- Added Coupons for individual categories/products
- Added compatibility with Google Universal Analytics
- Added Stripe embedded form button
- Added Pinterest "Rich Pins" w/advanced oembed endpoint
- Added Pinterest "Rich Pins" w/advanced oembed endpoint
- Added show related products option
- Added Pickup in-store shipping option
- Added ability to assign a custom per-order limit to a product
Expand Down
9 changes: 4 additions & 5 deletions includes/common/class-mp-product.php
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ public function attribute_input_fields( $is_variation = false, $qty = false, $pr
$disabled = '';
$error = '';

$max_max = $this->max_product_quantity( $product_id, false, false );
$max_max = $this->max_product_quantity( $product_id, false, false );
extract($this->max_product_quantity( $product_id, false, true ), EXTR_PREFIX_ALL, "max");

$max = 'max="' . esc_attr( $max_qty ) . '" ';
Expand Down Expand Up @@ -654,7 +654,7 @@ public function attribute_input_fields( $is_variation = false, $qty = false, $pr
if( (! mp_doing_ajax() && ! $product->in_stock( 1, true ) ) || $max_qty == 0 ){
$error = '<label class="mp_form_label mp_product_options_att_input_label" for="' . $input_id . '"><span id="mp_product_options_att_quantity-error" class="mp_form_input_error">' . $max_msg . $max_msg_2 . '</span></label>';
}


return $error . '<input id="' . $input_id . '" class="mp_form_input mp_form_input-qty required digits" min="' . esc_attr( $min_value ) . '" ' . $max . ' type="number" name="product_quantity" value="' . $product_quantity . '" ' . $disabled . '>';
}
Expand Down Expand Up @@ -1473,7 +1473,7 @@ public function download_url( $order_id, $echo = true ) {
}

}

}

/**
Expand Down Expand Up @@ -2075,8 +2075,7 @@ public function image( $echo = true, $context = 'list', $size = null, $align = n
if ( ( $context == 'single' || $context == 'list' ) && ! empty( $image ) ) {
//if single case, we will get the better graphic
$image_id = get_post_thumbnail_id( $image_post_id );
$image_orignal_url = wp_get_attachment_image_src( $image_id, 'full' );
$image_url = mp_resize_image( $image_id, $image_orignal_url[0], $size );
$image_url = wp_get_attachment_image_src( $image_id, $size );
if ( $image_url ) {
$atts = '';
foreach (
Expand Down
85 changes: 11 additions & 74 deletions includes/common/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,14 @@ function mp_filter_email( $order, $text, $escape = false ) {
//show download link if set
$download_link = false;
if ( $order->post_status != 'order_received' && ( $download_url = $item->download_url( $order->get_id(), false ) ) ) {

//Handle multiple files
if( is_array( $download_url ) ){
//If we have more than one product file, we loop and add each to a new line
foreach ( $download_url as $key => $value ){
$download_link .= '<a target="_blank" href="' . $value . '">' . sprintf( __( 'Download %1$s', 'mp' ),( $key+1 ) ) . '</a><br/>';
}

} else {
$download_link = '<a href="' . $download_url . '">' . __( 'Download', 'mp' ) . '</a>';
}
Expand Down Expand Up @@ -175,7 +175,7 @@ function mp_filter_email( $order, $text, $escape = false ) {
$zip = $order->get_meta( "mp_{$type}_info->zip" );

if( $type != "shipping" || !$cart->is_download_only() ) {

$shipping_billing_info .= '<td><strong>' . $label . '</strong><br /><br />' . "\n";
$shipping_billing_info .= $order->get_name( $type ) . "<br />\n";
$shipping_billing_info .= $order->get_meta( "mp_{$type}_info->company_name" ) . "<br />\n";
Expand All @@ -191,12 +191,12 @@ function mp_filter_email( $order, $text, $escape = false ) {

if( ( ( $country = $order->get_meta( "mp_{$type}_info->country", '' ) ) && is_array( $all_countries ) && isset( $all_countries[$country] ) ) ){
$country = $all_countries[$country];
}
}

if( ! empty( $city ) && ! empty( $state ) && ! empty( $zip ) && ! empty( $country ) ) {
$shipping_billing_info .= $order->get_meta( "mp_{$type}_info->city" ) . ', ' . $state . ' ' . $order->get_meta( "mp_{$type}_info->zip" ) . ' ' . $country . "<br /><br />\n";
}

$shipping_billing_info .= $order->get_meta( "mp_{$type}_info->email" ) . "<br />\n";

if ( $order->get_meta( "mp_{$type}_info->phone" ) ) {
Expand All @@ -208,10 +208,10 @@ function mp_filter_email( $order, $text, $escape = false ) {
}

$shipping_billing_info .= '</tr></table><br /><br />';

$custom_carriers = mp_get_setting( 'shipping->custom_method', array() );
$method = $order->get_meta( 'mp_shipping_info->method' );

if( isset( $custom_carriers[ $method ] ) && !empty( $custom_carriers[ $method ] ) ) {
$carrier = $custom_carriers[ $method ];
} else {
Expand Down Expand Up @@ -437,7 +437,7 @@ function mp_countries() {
*
* @param array $countries The default countries.
*/
return apply_filters( 'mp_countries', $countries );
return apply_filters( 'mp_countries', $countries );
}

endif;
Expand Down Expand Up @@ -1376,7 +1376,7 @@ function mp_get_store_caps() {
if( $cap == "read" ) {
continue;
}

$store_caps[ $cap ] = $cap;
}
}
Expand All @@ -1402,72 +1402,9 @@ function mp_get_single_site_cart() {
}
}

if ( ! function_exists( 'mp_resize_image' ) ) {
/**
* @param $image_id
* @param $image_url
* @param string $size
*
* @return mixed|void
*/
function mp_resize_image( $image_id, $image_url, $size = 'thumbnail' ) {
$img_path = get_attached_file($image_id);

$image = wp_get_image_editor( $img_path );

if ( ! is_wp_error( $image ) ) {
if ( is_array( $size ) ) {
$size_data = $size;
} else {
// Get the image sizes from options
$size_data = array(
get_option( $size . '_size_w' ),
get_option( $size . '_size_h' ),
);
}
//build the path name, and try to check if
$filename_data = pathinfo( $image_url );
$upload_dir = wp_upload_dir();
$image_path = $upload_dir['path'] . '/' . $filename_data['filename'] . '-' . $size_data[0] . 'x' . $size_data[1] . '.' . $filename_data['extension'];
$image_url = str_replace( $upload_dir['path'], $upload_dir['url'], $image_path );
if ( file_exists( $image_path ) ) {
//we will check the time of this image
$cache_time = apply_filters( 'mp_image_resize_cache_duration', 3 );
if ( strtotime( '+' . $cache_time . ' days', filemtime( $image_path ) ) <= time() ) {
unlink( $image_path );
}
}

if ( ! file_exists( $image_path ) ) {
$is_crop = false;
if ( $size == 'thumbnail' ) {
$is_crop = array( 'left', 'top' );
}
$is_crop = apply_filters( 'mp_image_crop_position', $is_crop, $image, $image_path, $image_url, $size );
$image->resize( $size_data[0], $size_data[1], $is_crop );
$image->save( $image_path );
}

$image = apply_filters( 'image_downsize', array(
$image_url,
$size_data[0],
$size_data[1]
), $image_id, array( $size_data[0], $size_data[1] ) );

return apply_filters( 'mp_image_after_resize', $image );
}

return false;
}
}

if ( ! function_exists( 'mp_get_the_thumbnail' ) ) {

}

if (! function_exists( 'mp_array_column' ) ) {
function mp_array_column( array $input, $columnKey, $indexKey = null ) {

if( function_exists( 'array_column' ) ){
return array_column( $input, $columnKey, $indexKey );
}
Expand Down
Loading