/** * wpsc product thumbnail function * * Show the thumbnail image for the product * * @return string - the URL to the thumbnail image */ function wpsc_the_product_thumbnail($width = null, $height = null, $product_id = 0, $page = false) { $thumbnail = false; $display = wpsc_check_display_type(); // Get the product ID if none was passed if (empty($product_id)) { $product_id = get_the_ID(); } // Load the product $product = get_post($product_id); $thumbnail_id = wpsc_the_product_thumbnail_id($product_id); // If no thumbnail found for item, get its parent image if (!$thumbnail_id && (is_a($product, 'WP_Post') && $product->post_parent)) { $thumbnail_id = wpsc_the_product_thumbnail_id($product->post_parent); } // if still no thumbnail ID is found, return our fallback function if (!$thumbnail_id) { return wpsc_product_image(); } if (!$page) { $page = is_single() ? 'single' : 'products-page'; } if (!$width && !$height) { $width = get_option('product_image_width'); $height = get_option('product_image_height'); // Overwrite height & width if custom dimensions exist for thumbnail_id if ('grid' != $display && 'products-page' == $page && isset($thumbnail_id)) { $custom_width = get_post_meta($thumbnail_id, '_wpsc_custom_thumb_w', true); $custom_height = get_post_meta($thumbnail_id, '_wpsc_custom_thumb_h', true); if (!empty($custom_width) && !empty($custom_height)) { $width = $custom_width; $height = $custom_height; } } elseif ($page == 'single' && isset($thumbnail_id)) { $custom_thumbnail = get_post_meta($thumbnail_id, '_wpsc_selected_image_size', true); if (!$custom_thumbnail) { $custom_thumbnail = 'medium-single-product'; } $src = wp_get_attachment_image_src($thumbnail_id, $custom_thumbnail); if (!$src) { $custom_thumbnail = 'medium-single-product'; $current_size = image_get_intermediate_size($thumbnail_id, $custom_thumbnail); $settings_width = get_option('single_view_image_width'); $settings_height = get_option('single_view_image_height'); if (!$current_size || $current_size['width'] != $settings_width && $current_size['height'] != $settings_height) { _wpsc_regenerate_thumbnail_size($thumbnail_id, $custom_thumbnail); } $src = wp_get_attachment_image_src($thumbnail_id, $custom_thumbnail); } if (!empty($src) && is_string($src[0])) { $thumbnail = $src[0]; } } elseif ($page == 'manage-products' && isset($thumbnail_id)) { $current_size = image_get_intermediate_size($thumbnail_id, 'admin-product-thumbnails'); if (!$current_size) { _wpsc_regenerate_thumbnail_size($thumbnail_id, 'admin-product-thumbnails'); } $src = wp_get_attachment_image_src($thumbnail_id, 'admin-product-thumbnails'); if (!empty($src) && is_string($src[0])) { $thumbnail = $src[0]; } } } // Calculate the height based on the ratio of the original dimensions. if ($height == 0 || $width == 0) { $attachment_meta = get_post_meta($thumbnail_id, '_wp_attachment_metadata', true); $original_width = isset($attachment_meta['width']) ? absint($attachment_meta['width']) : 0; $original_height = isset($attachment_meta['height']) ? absint($attachment_meta['height']) : 0; // bail if either original value is zero. can't divide by zero. if ($original_width == 0 || $original_height == 0) { return; } if ($width != 0) { $height = $original_height / $original_width * $width; $height = round($height, 0); } elseif ($height != 0) { $width = $original_width / $original_height * $height; $width = round($width, 0); } } if (!$thumbnail && isset($thumbnail_id)) { $thumbnail = wpsc_product_image($thumbnail_id, $width, $height); } // WordPress's esc_url() function strips out spaces, so encode them here to ensure they don't get stripped out // Ref: http://core.trac.wordpress.org/ticket/23605 $thumbnail = str_replace(' ', '%20', $thumbnail); return apply_filters('wpsc_the_product_thumbnail', set_url_scheme($thumbnail), $product_id, $product); }
/** * wpsc product thumbnail function * * Show the thumbnail image for the product * * @return string - the URL to the thumbnail image */ function wpsc_the_product_thumbnail($width = null, $height = null, $product_id = 0, $page = 'products-page') { $thumbnail = false; $display = wpsc_check_display_type(); // Get the product ID if none was passed if (empty($product_id)) { $product_id = get_the_ID(); } // Load the product $product = get_post($product_id); // Get ID of parent product if one exists if (!empty($product->post_parent)) { $product_id = $product->post_parent; } // Load image proportions if none were passed if ($width < 10 || $height < 10) { $width = get_option('product_image_width'); $height = get_option('product_image_height'); } // Use product thumbnail if (has_post_thumbnail($product_id)) { $thumbnail_id = get_post_thumbnail_id($product_id); // Use first product image } else { // Get all attached images to this product $attached_images = (array) get_posts(array('post_type' => 'attachment', 'numberposts' => 1, 'post_status' => null, 'post_parent' => $product_id, 'orderby' => 'menu_order', 'order' => 'ASC')); if (!empty($attached_images)) { $thumbnail_id = $attached_images[0]->ID; } } //Overwrite height & width if custom dimensions exist for thumbnail_id if ('grid' != $display && 'products-page' == $page && isset($thumbnail_id)) { $custom_width = get_post_meta($thumbnail_id, '_wpsc_custom_thumb_w', true); $custom_height = get_post_meta($thumbnail_id, '_wpsc_custom_thumb_h', true); if (!empty($custom_width) && !empty($custom_height)) { $width = $custom_width; $height = $custom_height; } } elseif ($page == 'single' && isset($thumbnail_id)) { $custom_thumbnail = get_post_meta($thumbnail_id, '_wpsc_selected_image_size', true); if (!$custom_thumbnail) { $custom_thumbnail = 'medium-single-product'; $current_size = image_get_intermediate_size($thumbnail_id, $custom_thumbnail); $settings_width = get_option('single_view_image_width'); $settings_height = get_option('single_view_image_height'); // regenerate size metadata in case it's missing if (!$current_size || $current_size['width'] != $settings_width || $current_size['height'] != $settings_height) { require_once ABSPATH . 'wp-admin/includes/image.php'; if (!($metadata = wp_get_attachment_metadata($thumbnail_id))) { $metadata = array(); } if (empty($metadata['sizes'])) { $metadata['sizes'] = array(); } $file = get_attached_file($thumbnail_id); $generated = wp_generate_attachment_metadata($thumbnail_id, $file); $metadata['sizes'] = array_merge($metadata['sizes'], $generated['sizes']); wp_update_attachment_metadata($thumbnail_id, $metadata); } } $src = wp_get_attachment_image_src($thumbnail_id, $custom_thumbnail); if (!empty($src) && is_string($src[0])) { $thumbnail = $src[0]; } } // calculate the height based on the ratio of the original demensions // blame Cameron if this is buggy :P if ($height == 0 || $width == 0) { $attachment_meta = get_post_meta($thumbnail_id, '_wp_attachment_metadata', false); $original_width = $attachment_meta[0]['width']; $original_height = $attachment_meta[0]['height']; if ($width != 0) { $height = $original_height / $original_width * $width; $height = round($height, 0); } elseif ($height != 0) { $width = $original_width / $original_height * $height; $width = round($width, 0); } } if (!$thumbnail && isset($thumbnail_id)) { $thumbnail = wpsc_product_image($thumbnail_id, $width, $height); } if (!empty($thumbnail) && is_ssl()) { $thumbnail = str_replace('http://', 'https://', $thumbnail); } return $thumbnail; }
function wpsc_products_page($content = '') { global $wpdb, $wp_query, $wpsc_query, $wpsc_query_vars, $_wpsc_is_in_custom_loop; $output = ''; if (!in_the_loop()) { return $content; } if (preg_match("/\\[productspage\\]/", $content)) { global $more; $more = 0; remove_filter('the_content', 'wpautop'); list($wp_query, $wpsc_query) = array($wpsc_query, $wp_query); // swap the wpsc_query object $_wpsc_is_in_custom_loop = true; $GLOBALS['nzshpcrt_activateshpcrt'] = true; // get the display type for the productspage $saved_display = wpsc_get_customer_meta('display_type'); $display_type = !empty($saved_display) ? $saved_display : wpsc_check_display_type(); ob_start(); do_action('wpsc_display_products_page', $display_type); wpsc_include_products_page_template($display_type); $is_single = false; $output .= ob_get_contents(); ob_end_clean(); $output = str_replace('$', '\\$', $output); if ($wp_query->post_count > 0) { $product_id = $wp_query->post->ID; $product_meta = get_post_meta($product_id, '_wpsc_product_metadata', true); list($wp_query, $wpsc_query) = array($wpsc_query, $wp_query); // swap the wpsc_query objects back $_wpsc_is_in_custom_loop = false; if ($is_single == false || $product_meta['enable_comments'] == '0') { wp_reset_postdata(); } } $wp_query->current_post = $wp_query->post_count; return preg_replace("/(<p>)*\\[productspage\\](<\\/p>)*/", $output, $content); } elseif (is_archive() && wpsc_is_viewable_taxonomy()) { remove_filter('the_content', 'wpautop'); return wpsc_products_page('[productspage]'); } else { return $content; } }
/** * wpsc product thumbnail function * * Show the thumbnail image for the product * * @return string - the URL to the thumbnail image */ function wpsc_the_product_thumbnail($width = null, $height = null, $product_id = 0, $page = 'products-page') { $display = wpsc_check_display_type(); // Get the product ID if none was passed if (empty($product_id)) { $product_id = get_the_ID(); } // Load the product $product = get_post($product_id); // Get ID of parent product if one exists if (!empty($product->post_parent)) { $product_id = $product->post_parent; } // Load image proportions if none were passed if ($width < 10 || $height < 10) { $width = get_option('product_image_width'); $height = get_option('product_image_height'); } // Use product thumbnail if (has_post_thumbnail($product_id) && 'single' != $page) { $thumbnail_id = get_post_thumbnail_id($product_id); // Use first product image } else { // Get all attached images to this product $attached_images = (array) get_posts(array('post_type' => 'attachment', 'numberposts' => 1, 'post_status' => null, 'post_parent' => $product_id, 'orderby' => 'menu_order', 'order' => 'ASC')); if (!empty($attached_images)) { $thumbnail_id = $attached_images[0]->ID; } } //Overwrite height & width if custom dimensions exist for thumbnail_id if ('grid' != $display && 'products-page' == $page && isset($thumbnail_id)) { $custom_width = get_post_meta($thumbnail_id, '_wpsc_custom_thumb_w', true); $custom_height = get_post_meta($thumbnail_id, '_wpsc_custom_thumb_h', true); if (!empty($custom_width) && !empty($custom_height)) { $width = $custom_width; $height = $custom_height; } } elseif ($page == 'single' && isset($thumbnail_id)) { $custom_thumbnail = get_post_meta($thumbnail_id, '_wpsc_selected_image_size', true); if (!$custom_thumbnail) { $custom_thumbnail = array($width, $height); } $src = wp_get_attachment_image_src($thumbnail_id, $custom_thumbnail); if (!empty($src) && is_string($src[0])) { return $src[0]; } } // Return image link... if (isset($thumbnail_id) && ($image_link = wpsc_product_image($thumbnail_id, $width, $height))) { return $image_link; } else { return false; } }
/** * wpsc product thumbnail function * * Show the thumbnail image for the product * * @return string - the URL to the thumbnail image */ function wpsc_the_product_thumbnail($width = null, $height = null, $product_id = 0, $page = 'products-page') { $thumbnail = false; $display = wpsc_check_display_type(); // Get the product ID if none was passed if (empty($product_id)) { $product_id = get_the_ID(); } // Load the product $product = get_post($product_id); // Load image proportions if none were passed if ($width < 10 || $height < 10) { $width = get_option('product_image_width'); $height = get_option('product_image_height'); } $thumbnail_id = wpsc_the_product_thumbnail_id($product_id); // If no thumbnail found for item, get it's parent image (props. TJM) if (!$thumbnail_id && $product->post_parent) { $thumbnail_id = wpsc_the_product_thumbnail_id($product->post_parent); } if (!$width && !$height) { //Overwrite height & width if custom dimensions exist for thumbnail_id if ('grid' != $display && 'products-page' == $page && isset($thumbnail_id)) { $custom_width = get_post_meta($thumbnail_id, '_wpsc_custom_thumb_w', true); $custom_height = get_post_meta($thumbnail_id, '_wpsc_custom_thumb_h', true); if (!empty($custom_width) && !empty($custom_height)) { $width = $custom_width; $height = $custom_height; } } elseif ($page == 'single' && isset($thumbnail_id)) { $custom_thumbnail = get_post_meta($thumbnail_id, '_wpsc_selected_image_size', true); if (!$custom_thumbnail) { $custom_thumbnail = 'medium-single-product'; $current_size = image_get_intermediate_size($thumbnail_id, $custom_thumbnail); $settings_width = get_option('single_view_image_width'); $settings_height = get_option('single_view_image_height'); if (!$current_size || $current_size['width'] != $settings_width && $current_size['height'] != $settings_height) { _wpsc_regenerate_thumbnail_size($thumbnail_id, $custom_thumbnail); } } $src = wp_get_attachment_image_src($thumbnail_id, $custom_thumbnail); if (!empty($src) && is_string($src[0])) { $thumbnail = $src[0]; } } elseif ($page == 'manage-products' && isset($thumbnail_id)) { $current_size = image_get_intermediate_size($thumbnail_id, 'admin-product-thumbnails'); if (!$current_size) { _wpsc_regenerate_thumbnail_size($thumbnail_id, 'admin-product-thumbnails'); } $src = wp_get_attachment_image_src($thumbnail_id, 'admin-product-thumbnails'); if (!empty($src) && is_string($src[0])) { $thumbnail = $src[0]; } } } // calculate the height based on the ratio of the original demensions // blame Cameron if this is buggy :P if ($height == 0 || $width == 0) { $attachment_meta = get_post_meta($thumbnail_id, '_wp_attachment_metadata', false); $original_width = $attachment_meta[0]['width']; $original_height = $attachment_meta[0]['height']; if ($width != 0) { $height = $original_height / $original_width * $width; $height = round($height, 0); } elseif ($height != 0) { $width = $original_width / $original_height * $height; $width = round($width, 0); } } if (!$thumbnail && isset($thumbnail_id)) { $thumbnail = wpsc_product_image($thumbnail_id, $width, $height); } if (!empty($thumbnail) && is_ssl()) { $thumbnail = str_replace('http://', 'https://', $thumbnail); } return $thumbnail; }
/** * View mode. */ function wpsc_gc_view_mode() { global $wpsc_gc_view_mode; $wpsc_gc_view_mode = wpsc_check_display_type(); if (get_option('show_search') && get_option('show_advanced_search')) { $meta = wpsc_get_customer_meta('display_type'); if (!empty($meta)) { $wpsc_gc_view_mode = $meta; } if (!empty($_REQUEST['view_type']) && in_array($_REQUEST['view_type'], array('list', 'grid', 'default'))) { $wpsc_gc_view_mode = $_REQUEST['view_type']; wpsc_update_customer_meta('display_type', $wpsc_gc_view_mode); } elseif (empty($wpsc_gc_view_mode)) { $wpsc_gc_view_mode = get_option('product_view', 'default'); } } if ($wpsc_gc_view_mode == 'grid') { add_action('wp_head', 'wpsc_grid_custom_styles', 9); } }