+
+
+
+
+
+
+ 'true', 'wpsc_action' => 'wpsc_get_alternate_html', 'ajax' => 'true', 'wpsc_ajax_action' => 'add_to_cart' ), home_url() ),
+ array( 'body' =>
+ array(
+ 'cart_messages' => $cart_messages, 'ajax' => 'true', 'wpsc_ajax_action' => 'add_to_cart', 'product_id' => $_REQUEST['product_id']
+ )
+ )
+ )
+ );
+ return $javascript;
+}
+
+/**
+ * Returns the jQuery that is likely included in calls to this action. For back compat only, will be deprecated soon.
+ * Couldn't think up a better way to return this output, which most often will end in die(), without die()ing early ourselves.
+ *
+ * @param array $cart_messages [description]
+ */
+function _wpsc_ajax_return_alternate_html() {
+ $cart_messages = is_array( $_POST['cart_messages'] ) ? $_POST['cart_messages'] : array();
+
+ do_action( 'wpsc_alternate_cart_html', $cart_messages );
+ die;
+}
+
+if ( isset( $_REQUEST['wpsc_action'] ) && 'wpsc_get_alternate_html' == $_REQUEST['wpsc_action'] )
+ add_action( 'init', '_wpsc_ajax_return_alternate_html' );
+
+/**
+ * Returns the Cart Widget
+ *
+ * @param boolean $die Whether or not to return the output (for new JSON requests) or to die() on the old $output / action.
+ * @param array $cart_message An array of cart messages to be optionally passed. Primarily passed via wpsc_add_to_cart().
+ *
+ * @since 3.8.11
+ * @return mixed Returns an array of output data, alternatively
+ */
+function _wpsc_ajax_get_cart( $die = true, $cart_messages = array() ) {
+ $return = array();
+
+ if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
+
+ ob_start();
+ include_once( wpsc_get_template_file_path( 'wpsc-cart_widget.php' ) );
+
+ $output = ob_get_contents();
+ ob_end_clean();
+ $output = str_replace( array( '\n', '\r' ), '', $output );
+
+ $return['widget_output'] = $output;
+ $return['core_images_url'] = WPSC_CORE_IMAGES_URL;
+
+ if ( 1 == get_option( 'show_sliding_cart' ) || empty( $cart_messages ) ) {
+ if ( wpsc_cart_item_count() ) {
+ $_SESSION['slider_state'] = 1;
+ $return['sliding_cart_state'] = 'show';
+ } else {
+ $_SESSION['slider_state'] = 0;
+ $return['sliding_cart_state'] = 'hide';
+ }
+ }
+
+ $action_output = '';
+ if ( has_action( 'wpsc_alternate_cart_html' ) ) {
+ //Deprecated action. Do not use. We now have a custom JS event called 'wpsc_fancy_notification'. There is access to the complete $json_response object.
+ ob_start();
+
+ echo _wpsc_get_alternate_html();
+ $action_output = ob_get_contents();
+
+ ob_end_clean();
+ }
+
+ if ( ! empty( $action_output ) ) {
+ _wpsc_doing_it_wrong( 'wpsc_alternate_cart_html', __( 'As of WPeC 3.8.11, it is improper to hook into "wpsc_alternate_cart_html" to output javascript. We now have a custom javascript event called "wpsc_fancy_notification" you can hook into.', 'wpsc' ), '3.8.11' );
+ $return['wpsc_alternate_cart_html'] = $action_output;
+ }
+ }
+
+ if ( $die )
+ die( $output . $action_output );
+ else
+ return $return;
+}
\ No newline at end of file
diff --git a/wpsc-components/theme-engine-v1/helpers/cart.php b/wpsc-components/theme-engine-v1/helpers/cart.php
new file mode 100644
index 0000000000..97292d80e2
--- /dev/null
+++ b/wpsc-components/theme-engine-v1/helpers/cart.php
@@ -0,0 +1,122 @@
+have_cart_items();
+}
+
+function wpsc_the_cart_item() {
+ global $wpsc_cart;
+ return $wpsc_cart->the_cart_item();
+}
+
+/**
+* cart item key function, no parameters
+* @return integer - the cart item key from the array in the cart object
+*/
+function wpsc_the_cart_item_key() {
+ global $wpsc_cart;
+ return $wpsc_cart->current_cart_item;
+}
+
+ /**
+* cart item name function, no parameters
+* @return string the cart item name
+*/
+function wpsc_cart_item_name( $context = 'display' ) {
+ global $wpsc_cart;
+ $product_name = apply_filters( 'wpsc_cart_item_name', $wpsc_cart->cart_item->get_title(), $wpsc_cart->cart_item->product_id );
+ return $product_name;
+}
+ /**
+* cart item quantity function, no parameters
+* @return string the selected quantity of items
+*/
+function wpsc_cart_item_product_id() {
+ global $wpsc_cart;
+ return $wpsc_cart->cart_item->product_id;
+}
+ /**
+* cart item quantity function, no parameters
+* @return string the selected quantity of items
+*/
+function wpsc_cart_item_quantity() {
+ global $wpsc_cart;
+ return $wpsc_cart->cart_item->quantity;
+}
+
+function wpsc_cart_item_quantity_single_prod($id) {
+ global $wpsc_cart;
+ return $wpsc_cart;
+}
+
+/**
+* cart item price function, no parameters
+* @return string the cart item price multiplied by the quantity, with a currency sign
+*/
+function wpsc_cart_item_price($forDisplay = true) {
+ global $wpsc_cart;
+ if($forDisplay){
+ return wpsc_currency_display($wpsc_cart->cart_item->total_price);
+ }else{
+ return $wpsc_cart->cart_item->total_price;
+ }
+}
+
+/**
+* cart item individual single price function, no parameters
+* @return string the cart individual single item price (1 quantity)
+*/
+function wpsc_cart_single_item_price($forDisplay = true) {
+ global $wpsc_cart;
+ if($forDisplay){
+ return wpsc_currency_display(($wpsc_cart->cart_item->total_price) / ($wpsc_cart->cart_item->quantity));
+ }else{
+ return ($wpsc_cart->cart_item->total_price / $wpsc_cart->cart_item->quantity);
+ }
+}
+
+/**
+* cart item shipping function, no parameters
+* @return string the cart item price multiplied by the quantity, with a currency sign
+*/
+function wpsc_cart_item_shipping($forDisplay = true) {
+ global $wpsc_cart;
+ if($forDisplay){
+ return wpsc_currency_display($wpsc_cart->cart_item->shipping);
+ }else{
+ return $wpsc_cart->cart_item->shipping;
+ }
+}
+
+/**
+* cart item url function, no parameters
+* @return string the cart item url
+*/
+function wpsc_cart_item_url() {
+ global $wpsc_cart;
+ return apply_filters( 'wpsc_cart_item_url', $wpsc_cart->cart_item->product_url, $wpsc_cart->cart_item->product_id );
+}
+
+/**
+* cart item image function
+* returns the url to the to the cart item thumbnail image, if a width and height is specified, it resizes the thumbnail image to that size using the preview code (which caches the thumbnail also)
+* @param integer width
+* @param integer height
+* @return string url to the to the cart item thumbnail image
+*/
+function wpsc_cart_item_image( $width = 31, $height = 31 ) {
+ global $wpsc_cart;
+
+ $cart_image = wpsc_the_product_thumbnail( $width, $height, $wpsc_cart->cart_item->product_id, "shopping_cart");
+
+ if( is_ssl() )
+ $cart_image = str_replace( 'http://', 'https://', $cart_image );
+
+ return apply_filters( 'wpsc_cart_item_image', $cart_image, $wpsc_cart->cart_item->product_id );
+}
+
diff --git a/wpsc-components/theme-engine-v1/helpers/checkout.php b/wpsc-components/theme-engine-v1/helpers/checkout.php
new file mode 100644
index 0000000000..a348c1adbc
--- /dev/null
+++ b/wpsc-components/theme-engine-v1/helpers/checkout.php
@@ -0,0 +1,416 @@
+have_checkout_items();
+}
+
+/**
+ * The checkout item sets the checkout item to the next one in the loop
+ * @access public
+ *
+ * @since 3.7
+ * @return the checkout item array
+ */
+function wpsc_the_checkout_item() {
+ global $wpsc_checkout;
+ return $wpsc_checkout->the_checkout_item();
+}
+
+/**
+ * Checks shipping details
+ * @access public
+ *
+ * @since 3.7
+ * @return (boolean)
+ */
+function wpsc_is_shipping_details() {
+ global $wpsc_checkout;
+ if ( $wpsc_checkout->checkout_item->unique_name == 'delivertoafriend' && get_option( 'shippingsameasbilling' ) == '1' ) {
+ return true;
+ } else {
+ return false;
+ }
+}
+
+/**
+ * returns the class for shipping and billing forms
+ * @access public
+ *
+ * @since 3.8
+ * @param $additional_classes (string) additional classes to be
+ * @return
+ */
+function wpsc_the_checkout_details_class($additional_classes = ''){
+ if(wpsc_is_shipping_details())
+ echo "class='wpsc_shipping_forms ".$additional_classes."'";
+ else
+ echo "class='wpsc_billing_forms ".$additional_classes."'";
+
+}
+
+/**
+ * Checks to see is user login form needs to be displayed
+ * @access public
+ *
+ * @since 3.8
+ * @return (boolean) true or false
+ */
+function wpsc_show_user_login_form(){
+ if(!is_user_logged_in() && get_option('users_can_register') && get_option('require_register'))
+ return true;
+ else
+ return false;
+}
+
+/**
+ * checks to see whether the country and categories selected have conflicts
+ * i.e products of this category cannot be shipped to selected country
+ * @access public
+ *
+ * @since 3.8
+ * @return (boolean) true or false
+ */
+function wpsc_has_category_and_country_conflict(){
+ $conflict = wpsc_get_customer_meta( 'category_shipping_conflict' );
+ return ( ! empty( $conflict ) );
+}
+
+/**
+ * Have valid shipping zipcode
+ * Logic was modified in 3.8.9 to check if the Calculate button was ever actually hit
+ * @see http://code.google.com/p/wp-e-commerce/issues/detail?id=1014
+ *
+ * @access public
+ *
+ * @since 3.8
+ * @return (boolean) true or false
+ */
+function wpsc_have_valid_shipping_zipcode(){
+ $zip = wpsc_get_customer_meta( 'shipping_zip' );
+
+ if( ! $zip || ( __( 'Your Zipcode', 'wpsc' ) == $zip ) && ( wpsc_get_customer_meta( 'update_location' ) ) )
+ return false;
+ else
+ return true;
+
+}
+
+/**
+ * Checks to see whether terms and conditions are empty
+ * @access public
+ *
+ * @since 3.8
+ * @return (boolean) true or false
+ */
+function wpsc_has_tnc(){
+ if('' == get_option('terms_and_conditions'))
+ return false;
+ else
+ return true;
+}
+
+/**
+ * show find us checks whether the 'how you found us' drop down should be displayed
+ * @access public
+ *
+ * @since 3.8
+ * @return (boolean) true or false
+ */
+function wpsc_show_find_us(){
+ if(get_option('display_find_us') == '1')
+ return true;
+ else
+ return false;
+}
+
+/**
+ * disregard state fields - checks to see whether selected country has regions or not,
+ * depending on the scenario will return wither a true or false
+ * @access public
+ *
+ * @since 3.8
+ * @return (boolean) true or false
+ */
+function wpsc_disregard_shipping_state_fields(){
+ global $wpsc_checkout;
+ if ( ! wpsc_uses_shipping() ):
+ $delivery_country = wpsc_get_customer_meta( 'shipping_country' );
+ if ( 'shippingstate' == $wpsc_checkout->checkout_item->unique_name && wpsc_has_regions( $delivery_country ) )
+ return true;
+ else
+ return false;
+ elseif ( 'billingstate' == $wpsc_checkout->checkout_item->unique_name && wpsc_has_regions( wpsc_get_customer_meta( 'billing_country' ) ) ):
+ return true;
+ endif;
+}
+
+function wpsc_disregard_billing_state_fields(){
+ global $wpsc_checkout;
+ if ( 'billingstate' == $wpsc_checkout->checkout_item->unique_name && wpsc_has_regions( wpsc_get_customer_meta( 'billing_country' ) ) )
+ return true;
+ return false;
+}
+
+
+function wpsc_shipping_details() {
+ global $wpsc_checkout;
+ if ( stristr( $wpsc_checkout->checkout_item->unique_name, 'shipping' ) != false ) {
+
+ return ' wpsc_shipping_forms';
+ } else {
+ return "";
+ }
+}
+
+function wpsc_the_checkout_item_error_class( $as_attribute = true ) {
+ global $wpsc_checkout, $wpsc_checkout_error_messages;
+
+ $class_name = '';
+
+ if ( ! empty( $wpsc_checkout_error_messages ) && isset( $wpsc_checkout_error_messages[$wpsc_checkout->checkout_item->id] ) && $wpsc_checkout_error_messages[$wpsc_checkout->checkout_item->id] != '' ) {
+ $class_name = 'validation-error';
+ }
+ if ( ($as_attribute == true ) ) {
+ $output = "class='" . $class_name . wpsc_shipping_details() . "'";
+ } else {
+ $output = $class_name;
+ }
+ return $output;
+}
+
+function wpsc_the_checkout_item_error() {
+ global $wpsc_checkout, $wpsc_checkout_error_messages;
+ $output = false;
+ if ( ! empty( $wpsc_checkout_error_messages ) && isset( $wpsc_checkout_error_messages[$wpsc_checkout->checkout_item->id] ) && $wpsc_checkout_error_messages[$wpsc_checkout->checkout_item->id] != '' ) {
+ $output = $wpsc_checkout_error_messages[$wpsc_checkout->checkout_item->id];
+ }
+
+ return $output;
+}
+
+function wpsc_the_checkout_CC_validation() {
+ global $wpsc_gateway_error_messages;
+
+ $output = '';
+ if ( ! empty( $wpsc_gateway_error_messages ) && ! empty( $wpsc_gateway_error_messages['card_number'] ) )
+ $output = $wpsc_gateway_error_messages['card_number'];
+
+ return $output;
+}
+
+function wpsc_the_checkout_CC_validation_class() {
+ global $wpsc_gateway_error_messages;
+ if ( empty( $wpsc_gateway_error_messages ) )
+ return '';
+
+ return empty( $wpsc_gateway_error_messages['card_number'] ) ? '' : 'class="validation-error"';
+}
+
+function wpsc_the_checkout_CCexpiry_validation_class() {
+ global $wpsc_gateway_error_messages;
+
+ if ( empty( $wpsc_gateway_error_messages ) )
+ return '';
+
+ return empty( $wpsc_gateway_error_messages['expdate'] ) ? '' : 'class="validation-error"';
+}
+
+function wpsc_the_checkout_CCexpiry_validation() {
+ global $wpsc_gateway_error_messages;
+
+ if ( empty( $wpsc_gateway_error_messages ) )
+ return '';
+
+ return empty( $wpsc_gateway_error_messages['expdate'] ) ? '' : $wpsc_gateway_error_messages['expdate'];
+}
+
+function wpsc_the_checkout_CCcvv_validation_class() {
+ global $wpsc_gateway_error_messages;
+
+ if ( empty( $wpsc_gateway_error_messages ) )
+ return '';
+
+ return empty( $wpsc_gateway_error_messages['card_code'] ) ? '' : 'class="validation-error"';
+}
+
+function wpsc_the_checkout_CCcvv_validation() {
+ global $wpsc_gateway_error_messages;
+
+ if ( empty( $wpsc_gateway_error_messages ) )
+ return '';
+
+ return empty( $wpsc_gateway_error_messages['card_code'] ) ? '' : $wpsc_gateway_error_messages['card_code'];
+}
+
+function wpsc_the_checkout_CCtype_validation_class() {
+ global $wpsc_gateway_error_messages;
+
+ if ( empty( $wpsc_gateway_error_messages ) )
+ return '';
+
+ return empty( $wpsc_gateway_error_messages['cctype'] ) ? '' : 'class="validation-error"';
+}
+
+function wpsc_the_checkout_CCtype_validation() {
+ global $wpsc_gateway_error_messages;
+
+ if ( empty( $wpsc_gateway_error_messages ) )
+ return '';
+
+ return empty( $wpsc_gateway_error_messages['cctype'] ) ? '' : $wpsc_gateway_error_messages['cctype'];
+}
+
+function wpsc_checkout_form_is_header() {
+ global $wpsc_checkout;
+ if ( $wpsc_checkout->checkout_item->type == 'heading' ) {
+ $output = true;
+ } else {
+ $output = false;
+ }
+ return $output;
+}
+
+function wpsc_checkout_form_name() {
+ global $wpsc_checkout;
+ return $wpsc_checkout->form_name();
+}
+
+function wpsc_checkout_form_element_id() {
+ global $wpsc_checkout;
+ return $wpsc_checkout->form_element_id();
+}
+
+function wpsc_checkout_form_field() {
+ global $wpsc_checkout;
+ return $wpsc_checkout->form_field();
+}
+
+function wpsc_shipping_region_list( $selected_country, $selected_region, $shippingdetails = false ) {
+ global $wpdb;
+ $output = '';
+ $region_data = $wpdb->get_results( $wpdb->prepare( "SELECT `regions`.* FROM `" . WPSC_TABLE_REGION_TAX . "` AS `regions` INNER JOIN `" . WPSC_TABLE_CURRENCY_LIST . "` AS `country` ON `country`.`id` = `regions`.`country_id` WHERE `country`.`isocode` IN(%s) ORDER BY name ASC", $selected_country ), ARRAY_A );
+ $js = '';
+ if ( !$shippingdetails ) {
+ $js = "onchange='submit_change_country();'";
+ }
+ if ( count( $region_data ) > 0 ) {
+ $output .= "";
+ } else {
+ $output .= " ";
+ }
+ return $output;
+}
+
+function wpsc_shipping_country_list( $shippingdetails = false ) {
+ global $wpdb, $wpsc_shipping_modules, $wpsc_country_data;
+ $js = '';
+ $output = '';
+ if ( !$shippingdetails ) {
+ $output = "";
+ $js = " onchange='submit_change_country();'";
+ }
+ $selected_country = (string) wpsc_get_customer_meta( 'shipping_country' );
+ $selected_region = (string) wpsc_get_customer_meta( 'shipping_region' );
+
+ if ( empty( $selected_country ) )
+ $selected_country = esc_attr( get_option( 'base_country' ) );
+
+ if ( empty( $selected_region ) )
+ $selected_region = esc_attr( get_option( 'base_region' ) );
+
+ if ( empty( $wpsc_country_data ) )
+ $country_data = $wpdb->get_results( "SELECT * FROM `" . WPSC_TABLE_CURRENCY_LIST . "` WHERE `visible`= '1' ORDER BY `country` ASC", ARRAY_A );
+ else
+ $country_data = $wpsc_country_data;
+
+ $acceptable_countries = wpsc_get_acceptable_countries();
+
+ $output .= wpsc_get_country_dropdown( array(
+ 'name' => 'country',
+ 'id' => 'current_country',
+ 'additional_attributes' => $js,
+ 'acceptable_ids' => $acceptable_countries,
+ 'selected' => $selected_country,
+ 'placeholder' => '',
+ ) );
+
+ $output .= wpsc_shipping_region_list( $selected_country, $selected_region, $shippingdetails );
+
+ if ( isset( $_POST['wpsc_update_location'] ) && $_POST['wpsc_update_location'] == 'true' ) {
+ wpsc_update_customer_meta( 'update_location', true );
+ } else {
+ wpsc_delete_customer_meta( 'update_location' );
+ }
+
+ $zipvalue = (string) wpsc_get_customer_meta( 'shipping_zip' );
+ if ( ! empty( $_POST['zipcode'] ) )
+ $zipvalue = $_POST['zipcode'];
+
+ $zip_code_text = __( 'Your Zipcode', 'wpsc' );
+
+ if ( ( $zipvalue != '' ) && ( $zipvalue != $zip_code_text ) ) {
+ $color = '#000';
+ wpsc_update_customer_meta( 'shipping_zip', $zipvalue );
+ } else {
+ $zipvalue = $zip_code_text;
+ $color = '#999';
+ }
+
+ $uses_zipcode = false;
+ $custom_shipping = get_option( 'custom_shipping_options' );
+ foreach ( (array)$custom_shipping as $shipping ) {
+ if ( isset( $wpsc_shipping_modules[$shipping]->needs_zipcode ) && $wpsc_shipping_modules[$shipping]->needs_zipcode == true ) {
+ $uses_zipcode = true;
+ }
+ }
+
+ if ( $uses_zipcode ) {
+ $output .= " ";
+ }
+ return $output;
+}
+
+function wpsc_get_gateway_list() {
+ return apply_filters( 'wpsc_get_gateway_list', '' );
+}
+
+function wpsc_gateway_list() {
+ echo wpsc_get_gateway_list();
+}
+
+function wpsc_gateway_count() {
+ return apply_filters( 'wpsc_gateway_count', 0 );
+}
+
+function wpsc_get_gateway_hidden_field() {
+ $output = sprintf(
+ '',
+ apply_filters( 'wpsc_gateway_hidden_field_value', '' )
+ );
+
+ return $output;
+}
+
+function wpsc_gateway_hidden_field() {
+ do_action( 'wpsc_before_gateway_hidden_field' );
+ echo wpsc_get_gateway_hidden_field();
+ do_action( 'wpsc_after_gateway_hidden_field' );
+}
\ No newline at end of file
diff --git a/wpsc-components/theme-engine-v1/helpers/form.php b/wpsc-components/theme-engine-v1/helpers/form.php
new file mode 100644
index 0000000000..6511589162
--- /dev/null
+++ b/wpsc-components/theme-engine-v1/helpers/form.php
@@ -0,0 +1,87 @@
+ $selected_country,
+ ) );
+}
+
+function nzshpcrt_region_list( $selected_country = null, $selected_region = null ) {
+ global $wpdb;
+
+ if ( $selected_region == null )
+ $selected_region = get_option( 'base_region' );
+
+ $output = "";
+ $region_list = $wpdb->get_results( $wpdb->prepare( "SELECT `" . WPSC_TABLE_REGION_TAX . "`.* FROM `" . WPSC_TABLE_REGION_TAX . "`, `" . WPSC_TABLE_CURRENCY_LIST . "` WHERE `" . WPSC_TABLE_CURRENCY_LIST . "`.`isocode` IN(%s) AND `" . WPSC_TABLE_CURRENCY_LIST . "`.`id` = `" . WPSC_TABLE_REGION_TAX . "`.`country_id`", $selected_country ), ARRAY_A );
+
+ if ( $region_list != null ) {
+ foreach ( $region_list as $region ) {
+ if ( $selected_region == $region['id'] ) {
+ $selected = "selected='selected'";
+ } else {
+ $selected = "";
+ }
+
+ $output .= "\r\n";
+ }
+ } else {
+ $output .= "\r\n";
+ }
+
+ return $output;
+}
+
+function nzshpcrt_form_field_list( $selected_field = null ) {
+ global $wpdb;
+ $output = "";
+ $form_sql = "SELECT * FROM `" . WPSC_TABLE_CHECKOUT_FORMS . "` WHERE `active` = '1';";
+ $form_data = $wpdb->get_results( $form_sql, ARRAY_A );
+
+ foreach ( (array)$form_data as $form ) {
+ $selected = '';
+ if ( $selected_field == $form['id'] ) {
+ $selected = "selected='selected'";
+ }
+ $output .= "";
+ }
+
+ return $output;
+}
+
+function wpsc_parent_category_list( $taxonomies, $args, $parent, $current_term_id ) {
+ $myterms = get_terms( $taxonomies, $args );
+ $output = "";
+
+ return $output;
+}
+
+/*
+ * Displays the category forms for adding and editing products
+ * Recurses to generate the branched view for subcategories
+ */
+function wpsc_category_options( $group_id, $this_category = null, $category_id = null, $iteration = 0, $selected_id = null ) {
+ global $wpdb;
+ $selected_term = get_term($selected_id,'wpsc_product_category');
+ $values = get_terms( 'wpsc_product_category', 'hide_empty=0&parent=' . $group_id );
+ $selected = "";
+ $output = "";
+
+ foreach ( (array)$values as $option ) {
+ if ( $option->term_id != $this_category ) {
+ if ( isset($selected_term->parent) && $selected_term->parent == $option->term_id ) {
+ $selected = "selected='selected'";
+ }
+
+ $output .= "\r\n";
+ $output .= wpsc_category_options( $option->term_id, $this_category, $option->term_id, $iteration + 1, $selected_id );
+ $selected = "";
+ }
+ }
+
+ return $output;
+}
+
diff --git a/wpsc-components/theme-engine-v1/helpers/page.php b/wpsc-components/theme-engine-v1/helpers/page.php
new file mode 100644
index 0000000000..50e64b54d5
--- /dev/null
+++ b/wpsc-components/theme-engine-v1/helpers/page.php
@@ -0,0 +1,1380 @@
+ 0 )
+ return $results;
+
+ // No differences so return false
+ else
+ return false;
+}
+
+/**
+ * wpsc_list_product_templates( $path = '' )
+ *
+ * Lists the files within the WPSC_CORE_THEME_PATH directory
+ *
+ * @access public
+ * @since 3.8
+ * @param $path - you can provide a path to find the files within it
+ * @return $templates (Array) List of files
+ */
+function wpsc_list_product_templates( $path = '' ) {
+
+ $selected_theme = get_option( 'wpsc_selected_theme' );
+
+ // If no path, then try to make some assuptions
+ if ( empty( $path ) ) {
+ if ( file_exists( WPSC_OLD_THEMES_PATH . $selected_theme . '/' . $selected_theme . '.css' ) ) {
+ $path = WPSC_OLD_THEMES_PATH . $selected_theme . '/';
+ } else {
+ $path = WPSC_CORE_THEME_PATH;
+ }
+ }
+
+ // Open the path and get the file names
+ $dh = opendir( $path );
+ while ( ( $file = readdir( $dh ) ) !== false ) {
+ if ( $file != "." && $file != ".." && !strstr( $file, ".svn" ) && !strstr( $file, "images" ) && is_file( $path . $file ) ) {
+ $templates[] = $file;
+ }
+ }
+
+ // Return template names
+ return $templates;
+}
+
+/**
+ * Displays the theme upgrade notice
+ * @access public
+ *
+ * @since 3.8
+ * @param null
+ * @return null
+ */
+function wpsc_theme_upgrade_notice() { ?>
+
+
+
WP e-Commerce is ready. If you plan on editing the look of your site, you should update your active theme to include the additional WP e-Commerce files. Click here to ignore and remove this box.', 'wpsc' ), admin_url( 'admin.php?page=wpsc-settings&tab=presentation' ), admin_url( 'admin.php?page=wpsc-settings&tab=presentation&wpsc_notices=theme_ignore' ) ) ?>
+
+
+
+
+
+
Your WP e-Commerce data needs to be updated. You\'ve upgraded from a previous version of the WP e-Commerce plugin, and your store needs updating. You should update your database for your store to continue working.', 'wpsc' ), admin_url( 'index.php?page=wpsc-update' ) ) ?>
+
+
+
+
+
+
Store Settings: You have set \'users must register before checkout\', for this to work you need to check \'Anyone can register\' in your WordPress General Settings.', 'wpsc' ), admin_url( 'options-general.php' ) ) ?>
+
+
+ admin_url( 'admin-ajax.php', 'relative' ),
+ 'spinner' => esc_url( admin_url( 'images/wpspin_light.gif' ) ),
+ 'no_quotes' => __( 'It appears that there are no shipping quotes for the shipping information provided. Please check the information and try again.', 'wpsc' )
+ )
+ );
+
+ wp_enqueue_script( 'livequery', WPSC_URL . '/wpsc-admin/js/jquery.livequery.js', array( 'jquery' ), '1.0.3' );
+ if( get_option( 'product_ratings' ) == 1 )
+ wp_enqueue_script( 'jquery-rating', WPSC_CORE_JS_URL . '/jquery.rating.js', array( 'jquery' ), $version_identifier );
+ wp_enqueue_script( 'wp-e-commerce-legacy', WPSC_CORE_JS_URL . '/user.js', array( 'jquery' ), WPSC_VERSION . WPSC_MINOR_VERSION );
+ if ( get_option( 'show_thumbnails_thickbox' ) == 1 ){
+ $lightbox = get_option('wpsc_lightbox', 'thickbox');
+ if( $lightbox == 'thickbox' ) {
+ wp_enqueue_script( 'wpsc-thickbox', WPSC_CORE_JS_URL . '/thickbox.js', array( 'jquery' ), 'Instinct_e-commerce' );
+ wp_enqueue_style( 'wpsc-thickbox', WPSC_CORE_JS_URL . '/thickbox.css', false, $version_identifier, 'all' );
+ } elseif( $lightbox == 'colorbox' ) {
+ wp_enqueue_script( 'colorbox-min', WPSC_CORE_JS_URL . '/jquery.colorbox-min.js', array( 'jquery' ), 'Instinct_e-commerce' );
+ wp_enqueue_script( 'wpsc_colorbox', WPSC_CORE_JS_URL . '/wpsc_colorbox.js', array( 'jquery', 'colorbox-min' ), 'Instinct_e-commerce' );
+ wp_enqueue_style( 'wpsc-colorbox-css', WPSC_CORE_JS_URL . '/wpsc_colorbox.css', false, $version_identifier, 'all' );
+ }
+ }
+ wp_enqueue_style( 'wpsc-theme-css', wpsc_get_template_file_url( 'wpsc-' . get_option( 'wpsc_selected_theme' ) . '.css' ), false, $version_identifier, 'all' );
+ wp_enqueue_style( 'wpsc-theme-css-compatibility', wpsc_get_template_file_url( 'compatibility.css' ), array( 'wpsc-theme-css' ), $version_identifier, 'all' );
+
+ if ( function_exists( 'wp_add_inline_style' ) )
+ wp_add_inline_style( 'wpsc-theme-css', wpsc_get_user_dynamic_css() );
+ else
+ wp_enqueue_style( 'wp-e-commerce-dynamic', wpsc_get_dynamic_user_css_url(), array( 'wpsc-theme-css' ), $version_identifier );
+
+ if( get_option( 'product_ratings' ) == 1 )
+ wp_enqueue_style( 'wpsc-product-rater', WPSC_CORE_JS_URL . '/product_rater.css', false, $version_identifier, 'all' );
+
+ }
+
+
+ if ( !defined( 'WPSC_MP3_MODULE_USES_HOOKS' ) && function_exists( 'listen_button' ) ) {
+
+ function wpsc_legacy_add_mp3_preview( $product_id, &$product_data ) {
+ global $wpdb;
+ if ( function_exists( 'listen_button' ) ) {
+ $file_data = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM `" . WPSC_TABLE_PRODUCT_FILES . "` WHERE `id` = %d LIMIT 1", $product_data['file'] ), ARRAY_A );
+ if ( $file_data != null ) {
+ echo listen_button( $file_data['idhash'], $file_data['id'] );
+ }
+ }
+ }
+
+ add_action( 'wpsc_product_before_description', 'wpsc_legacy_add_mp3_preview', 10, 2 );
+ }
+}
+
+/**
+ * Checks the category slug for a display type, if none set returns default
+ * << May need reworking to be more specific to the taxonomy type >>
+ * @access public
+ *
+ * @since 3.8
+ * @param $slug(string)
+ * @return $slug either from db or 'default' if none set
+ */
+
+function wpsc_get_the_category_display($slug){
+ global $wpdb;
+ $default_display_type = get_option('product_view');
+ if ( !empty($slug) && is_string($slug) ) {
+ $category_id = wpsc_get_the_category_id($slug , 'slug');
+ $display_type = wpsc_get_categorymeta( $category_id, 'display_type' );
+ }
+ if(!empty($display_type))
+ return $display_type;
+ else
+ return $default_display_type;
+}
+
+/**
+ * wpsc display products function
+ * @return string - html displaying one or more products
+ */
+function wpsc_display_products_page( $query ) {global $wpdb, $wpsc_query,$wp_query, $wp_the_query;
+
+ remove_filter('the_title','wpsc_the_category_title');
+
+ // If the data is coming from a shortcode parse the values into the args variable,
+ // I did it this was to preserve backwards compatibility
+ if(!empty($query)){
+ $args = array();
+
+ $args['post_type'] = 'wpsc-product';
+ if(!empty($query['product_id']) && is_array($query['product_id'])){
+ $args['post__in'] = $query['product_id'];
+ }elseif(is_string($query['product_id'])){
+ $args['post__in'] = (array)$query['product_id'];
+ }
+ if(!empty($query['old_product_id'])){
+ $post_id = wpsc_get_the_new_id($query['old_product_id']);
+ $args['post__in'] = (array)$post_id;
+ }
+ if(!empty($query['price']) && 'sale' != $query['price']){
+ $args['meta_key'] = '_wpsc_price';
+ $args['meta_value'] = $query['price'];
+ }elseif(!empty($query['price']) && 'sale' == $query['price']){
+ $args['meta_key'] = '_wpsc_special_price';
+ $args['meta_compare'] = '>=';
+ $args['meta_value'] = '1';
+ }
+ if(!empty($query['product_name'])){
+ $args['pagename'] = $query['product_name'];
+ }
+ if(!empty($query['category_id'])){
+ $term = get_term($query['category_id'],'wpsc_product_category');
+ $id = wpsc_get_meta($query['category_id'], 'category_id','wpsc_old_category');
+ if( !empty($id)){
+ $term = get_term($id,'wpsc_product_category');
+ $args['wpsc_product_category'] = $term->slug;
+ $args['wpsc_product_category__in'] = $term->term_id;
+ }else{
+ $args['wpsc_product_category'] = $term->slug;
+ $args['wpsc_product_category__in'] = $term->term_id;
+ }
+ }
+ if(!empty($query['category_url_name'])){
+ $args['wpsc_product_category'] = $query['category_url_name'];
+ }
+ $orderby = ( !empty($query['sort_order']) ) ? $query['sort_order'] : null;
+
+ $args = array_merge( $args, wpsc_product_sort_order_query_vars($orderby) );
+
+ if(!empty($query['order'])){
+ $args['order'] = $query['order'];
+ }
+ if(!empty($query['limit_of_items']) && '1' == get_option('use_pagination')){
+ $args['posts_per_page'] = $query['limit_of_items'];
+ }
+ if(!empty($query['number_per_page']) && '1' == get_option('use_pagination')){
+ $args['posts_per_page'] = $query['number_per_page'];
+ $args['paged'] = $query['page'];
+ }
+ if( '0' == get_option('use_pagination') ){
+ $args['nopaging'] = true;
+ $args['posts_per_page'] = '-1';
+ }
+ if(!empty($query['tag'])){
+ $args['product_tag'] = $query['tag'];
+ }
+ query_posts( $args );
+ }
+ // swap the wpsc_query objects
+
+ $GLOBALS['nzshpcrt_activateshpcrt'] = true;
+
+ // Pretty sure this single_product code is legacy...but fixing it up just in case.
+ // get the display type for the selected category
+ if(!empty($temp_wpsc_query->query_vars['term']))
+ $display_type = wpsc_get_the_category_display($temp_wpsc_query->query_vars['term']);
+ elseif( !empty( $args['wpsc_product_category'] ) )
+ $display_type = wpsc_get_the_category_display($args['wpsc_product_category']);
+ else
+ $display_type = 'default';
+
+ $saved_display = wpsc_get_customer_meta( 'display_type' );
+ $display_type = ! empty( $saved_display ) ? $saved_display : wpsc_check_display_type();
+
+ ob_start();
+ if( 'wpsc-product' == $wp_query->post->post_type && !is_archive() && $wp_query->post_count <= 1 )
+ include( wpsc_get_template_file_path( 'wpsc-single_product.php' ) );
+ else
+ wpsc_include_products_page_template($display_type);
+
+ $output = ob_get_contents();
+ ob_end_clean();
+ $output = str_replace('\$','$', $output);
+
+ if ( ! empty( $query ) ) {
+ wp_reset_query();
+ wp_reset_postdata();
+ }
+ return $output;
+}
+
+/**
+ * Checks if wpsc-single_product.php has been moved to the active theme, if it has then include the
+ * template from the active theme.
+ * @access public
+ *
+ * @since 3.8
+ * @param $content content of the page
+ * @return $content with wpsc-single_product content if its a single product
+ */
+function wpsc_single_template( $content ) {
+ global $wpdb, $post, $wp_query, $wpsc_query, $_wpsc_is_in_custom_loop;
+ if ( ! in_the_loop() )
+ return $content;
+
+ //if we dont belong here exit out straight away
+ if((!isset($wp_query->is_product)) && !isset($wp_query->query_vars['wpsc_product_category']))return $content;
+
+ // If we are a single products page
+ if ( !is_archive() && $wp_query->post_count > 0 && 'wpsc-product' == $wp_query->post->post_type && $wp_query->post_count <= 1 ) {
+ remove_filter( "the_content", "wpsc_single_template", 12 );
+ $single_theme_path = wpsc_get_template_file_path( 'wpsc-single_product.php' );
+ if( isset( $wp_query->query_vars['preview'] ) && $wp_query->query_vars['preview'])
+ $is_preview = 'true';
+ else
+ $is_preview = 'false';
+ $wpsc_temp_query = new WP_Query( array( 'p' => $wp_query->post->ID , 'post_type' => 'wpsc-product','posts_per_page'=>1, 'preview' => $is_preview ) );
+
+ list( $wp_query, $wpsc_temp_query ) = array( $wpsc_temp_query, $wp_query ); // swap the wpsc_query object
+ $_wpsc_is_in_custom_loop = true;
+ ob_start();
+ include( $single_theme_path );
+ $content = ob_get_contents();
+ ob_end_clean();
+ list( $wp_query, $wpsc_temp_query ) = array( $wpsc_temp_query, $wp_query ); // swap the wpsc_query objects back
+ $_wpsc_is_in_custom_loop = false;
+ }
+
+ return $content;
+}
+
+function wpsc_is_viewable_taxonomy(){
+ global $wp_query;
+ if(isset($wp_query->query_vars['taxonomy']) && ('wpsc_product_category' == $wp_query->query_vars['taxonomy'] || 'product_tag' == $wp_query->query_vars['taxonomy'] ) || isset($wp_query->query_vars['wpsc_product_category']))
+ return true;
+ else
+ return false;
+}
+
+function _wpsc_is_in_custom_loop() {
+ global $_wpsc_is_in_custom_loop;
+ return (bool) $_wpsc_is_in_custom_loop;
+}
+
+/**
+ * Checks and replaces the Page title with the category title if on a category page
+ *
+ * @since 3.8
+ * @access public
+ *
+ * @param string $title The Page Title
+ * @param int $id The Page ID
+ * @return string $title The new title
+ *
+ * @uses in_the_loop() Returns true if you are in the loop
+ * @uses _wpsc_is_in_custom_loop() Returns true if in the WPSC custom loop
+ * @uses is_tax() Returns true if you are on the supplied registered taxonomy
+ * @uses get_term_by() Gets term object by defined item, and what you pass
+ * @uses get_query_var() Gets query var from wp_query
+ */
+function wpsc_the_category_title( $title='', $id='' ){
+
+ if ( ! empty( $id ) )
+ _wpsc_deprecated_argument( __FUNCTION__, '3.8.10', 'The $id param is not used. If you are trying to get the title of the category use get_term' );
+
+ if ( ! in_the_loop() || _wpsc_is_in_custom_loop() )
+ return $title;
+
+ $term = null;
+ if ( is_tax( 'wpsc_product_category' ) ){
+ $term = get_term_by( 'slug', get_query_var( 'wpsc_product_category' ),'wpsc_product_category' );
+ } elseif ( is_tax( 'product_tag' ) ){
+ $term = get_term_by( 'slug', get_query_var( 'term' ),'product_tag' );
+ } // is_tax
+
+ if ( $term )
+ return $term->name;
+
+ return $title;
+
+}
+
+//handles replacing the tags in the pages
+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
+ $display_type = wpsc_check_display_type();
+ if ( get_option( 'show_search' ) && get_option( 'show_advanced_search' ) ) {
+ $saved_display = wpsc_get_customer_meta( 'display_type' );
+ if ( ! empty( $saved_display ) )
+ $display_type = $saved_display;
+ }
+
+ ob_start();
+ 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( "/(
)*\[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_the_category_template swaps the template used for product categories with pageif archive template is being used use
+ * @access public
+ *
+ * @since 3.8
+ * @param $template (string) template path
+ * @return $template (string)
+ */
+function wpsc_the_category_template($template){
+ global $wp_query;
+ //this bit of code makes sure we use a nice standard page template for our products
+ if(wpsc_is_viewable_taxonomy() && false !== strpos($template,'archive'))
+ return str_ireplace('archive', 'page',$template);
+ else
+ return $template;
+
+}
+
+/**
+ * Returns current product category ID or default category ID if one is set. If one is not set and there is no current category, returns empty string
+ * @return mixed
+ */
+function wpsc_get_current_category_id() {
+ global $wp_query;
+
+ $category_id = '';
+
+ if ( isset( $wp_query ) && isset( $wp_query->query_vars['taxonomy'] ) && ('wpsc_product_category' == $wp_query->query_vars['taxonomy'] ) || is_numeric( get_option( 'wpsc_default_category' ) ) )
+ $category_id = isset( $wp_query->query_vars['term'] ) && is_string( $wp_query->query_vars['term'] ) ? wpsc_get_category_id( $wp_query->query_vars['term'], 'slug' ) : get_option( 'wpsc_default_category' );
+
+ return $category_id;
+}
+
+/**
+ * Returns Dynamic User CSS URL
+ *
+ * This produces the cached CSS file if it exists and the uploads folder is writeable.
+ * If the folder is not writeable, we return the dynamic URL
+ * If the folder is writeable, but for some reason a cached copy of the CSS doesn't exist, we attempt to create it and return that URL.
+ *
+ * @since 3.8.9
+ * @return string
+ */
+
+function wpsc_get_dynamic_user_css_url() {
+
+ $uploads_dir = wp_upload_dir();
+ $upload_folder = $uploads_dir['path'];
+
+ if ( is_writable( $upload_folder ) && file_exists( $upload_folder . '/wpsc_cached_styles.css' ) )
+ return add_query_arg( 'timestamp', get_option( 'wpsc_dynamic_css_hash', time() ), $uploads_dir['url'] . '/wpsc_cached_styles.css' );
+
+ if ( ! is_writable( $upload_folder ) )
+ return add_query_arg( 'wpsc_user_dynamic_css', 'true', home_url( 'index.php' ) );
+
+ if ( is_writable( $upload_folder ) && ! file_exists( $upload_folder . '/wpsc_cached_styles.css' ) )
+ return wpsc_cache_to_upload();
+}
+
+/**
+ * Moves dynamically generated input into a file in the uploads folder.
+ * Also updates CSS hash timestamp. Timestamp is appended to URL
+ *
+ * @since 3.8.9
+ * @return mixed File URL on successful move, false on failure
+ */
+function wpsc_cache_to_upload() {
+
+ $uploads_dir = wp_upload_dir();
+ $upload_folder = $uploads_dir['path'];
+ $path = $upload_folder . '/wpsc_cached_styles.css';
+
+ if ( ! is_writable( $upload_folder ) )
+ return false;
+
+ if ( false === file_put_contents( $path, wpsc_get_user_dynamic_css() ) )
+ return false;
+
+ $timestamp = time();
+
+ update_option( 'wpsc_dynamic_css_hash', $timestamp );
+
+ return add_query_arg( 'timestamp', $timestamp, $uploads_dir['url'] . '/wpsc_cached_styles.css' );
+
+}
+
+/**
+ * Prints dynamic CSS. This function is run either when the dynamic URL is hit, or when we need to grab new CSS to cache.
+ *
+ * @since 3.8.9
+ * @return CSS
+ */
+function wpsc_user_dynamic_css() {
+
+ header( 'Content-Type: text/css' );
+ header( 'Expires: ' . gmdate( 'r', mktime( 0, 0, 0, date( 'm' ), ( date( 'd' ) + 12 ), date( 'Y' ) ) ) );
+ header( 'Cache-Control: public, must-revalidate, max-age=86400' );
+ header( 'Pragma: public' );
+
+ echo wpsc_get_user_dynamic_css();
+ exit;
+}
+
+/**
+ * Returns dynamic CSS as string. This function is run either when the dynamic URL is hit, or when we need to grab new CSS to cache.
+ *
+ * @since 3.8.9
+ * @return string
+ */
+function wpsc_get_user_dynamic_css() {
+ global $wpdb;
+
+ ob_start();
+
+ if ( ! defined( 'WPSC_DISABLE_IMAGE_SIZE_FIXES' ) || (constant( 'WPSC_DISABLE_IMAGE_SIZE_FIXES' ) != true ) ) {
+
+ $thumbnail_width = get_option( 'product_image_width' );
+
+ if ( $thumbnail_width <= 0 )
+ $thumbnail_width = 96;
+
+ $thumbnail_height = get_option( 'product_image_height' );
+
+ if ( $thumbnail_height <= 0 )
+ $thumbnail_height = 96;
+
+ $single_thumbnail_width = get_option( 'single_view_image_width' );
+ $single_thumbnail_height = get_option( 'single_view_image_height' );
+
+ if ( $single_thumbnail_width <= 0 )
+ $single_thumbnail_width = 128;
+
+ $category_height = get_option( 'category_image_height' );
+ $category_width = get_option( 'category_image_width' );
+?>
+
+ /*
+ * Default View Styling
+ */
+ div.default_product_display div.textcol{
+ margin-left: px !important;
+ min-height: px;
+ _height: px;
+ }
+
+ div.default_product_display div.textcol div.imagecol{
+ position:absolute;
+ top:0px;
+ left: 0px;
+ margin-left: -px !important;
+ }
+
+ div.default_product_display div.textcol div.imagecol a img {
+ width: px;
+ height: px;
+ }
+
+ .wpsc_category_grid_item {
+ display:block;
+ float:left;
+ width: px;
+ height: px;
+ }
+ .wpsc_category_grid_item span{
+ position:relative;
+ top:px;
+ }
+ div.default_product_display div.item_no_image a {
+ width: px;
+ }
+
+ div.default_product_display .imagecol img.no-image, #content div.default_product_display .imagecol img.no-image {
+ width: px;
+ height: px;
+ }
+
+
+
+ /*
+ * Single View Styling
+ */
+
+ div.single_product_display div.item_no_image {
+ width: px;
+ height: px;
+ }
+ div.single_product_display div.item_no_image a {
+ width: px;
+ }
+
+ div.single_product_display div.textcol{
+ margin-left: px !important;
+ min-height: px;
+ _height: px;
+ }
+
+
+ div.single_product_display div.textcol div.imagecol{
+ position:absolute;
+
+ margin-left: -px !important;
+ }
+
+ div.single_product_display div.textcol div.imagecol a img {
+ width: px;
+ height: px;
+ }
+
+
+ div#categorydisplay{
+ display: ;
+ }
+
+ div#branddisplay{
+ display: ;
+ }
+get_var($wpdb->prepare( "SELECT `post_id` FROM `{$wpdb->postmeta}` WHERE meta_key = %s AND `meta_value` = %d LIMIT 1", '_wpsc_original_id', $prod_id ));
+ return $post_id;
+
+}
+
+/**
+ * This switched between the 3 view types on category and products pages and includes the necessary tempalte part
+ * @access public
+ *
+ * @since 3.8
+ * @param $display_type
+ * @return NULL
+ */
+function wpsc_include_products_page_template($display_type = 'default'){
+ if ( isset( $_GET['view_type'] ) && get_option( 'show_search' ) && get_option( 'show_advanced_search' ) ) {
+ switch ( $_GET['view_type'] ) {
+ case 'grid':
+ $display_type = 'grid';
+ wpsc_update_customer_meta( 'display_type', $display_type );
+ break;
+
+ case 'list':
+ $display_type = 'list';
+ wpsc_update_customer_meta( 'display_type', $display_type );
+ break;
+
+ case 'default':
+ $display_type = 'default';
+ wpsc_update_customer_meta( 'display_type', $display_type );
+ break;
+
+ default:
+ break;
+ }
+ }
+ // switch the display type, based on the display type variable...
+ switch ( $display_type ) {
+ case "grid":
+ include( wpsc_get_template_file_path( 'wpsc-grid_view.php' ) );
+ break; // only break if we have the function;
+
+ case "list":
+ include( wpsc_get_template_file_path( 'wpsc-list_view.php' ) );
+ break; // only break if we have the file;
+ default:
+ include( wpsc_get_template_file_path( 'wpsc-products_page.php' ) );
+ break;
+ }
+
+}
+
+function wpsc_thesis_compat( $loop ) {
+ $loop[1] = 'page';
+ return $loop;
+}
+
+// Template tags
+function wpsc_all_products_on_page(){
+ global $wp_query,$wpsc_query;
+ do_action('wpsc_swap_the_template');
+ $products_page_id = wpsc_get_the_post_id_by_shortcode('[productspage]');
+ $term = get_query_var( 'wpsc_product_category' );
+ $tax_term = get_query_var ('product_tag' );
+ $obj = $wp_query->get_queried_object();
+
+ $id = isset( $obj->ID ) ? $obj->ID : null;
+
+ if( get_query_var( 'post_type' ) == 'wpsc-product' || $term || $tax_term || ( $id == $products_page_id )){
+
+ $templates = array();
+
+ if ( $term && ! is_single() ) {
+ array_push( $templates, "taxonomy-wpsc_product_category-{$term}.php", 'taxonomy-wpsc_product_category.php' );
+ }
+
+ if ( $tax_term && ! is_single() ) {
+ array_push( $templates, "taxonomy-product_tag-{$tax_term}.php", 'taxonomy-product_tag.php' );
+ }
+
+
+ // Attempt to use the [productspage]'s custom page template as a higher priority than the normal page.php template
+ if ( false !== $productspage_page_template = get_post_meta($products_page_id, '_wp_page_template', true) )
+ array_push( $templates, $productspage_page_template );
+
+ array_push( $templates, 'page.php', 'single.php' );
+
+ if ( is_single() )
+ array_unshift( $templates, 'single-wpsc-product.php' );
+
+ // have to pass 'page' as the template type. This is lame, btw, and needs a rewrite in 4.0
+ if ( ! $template = get_query_template( 'page', $templates ) )
+ $template = get_index_template();
+
+ add_filter( 'thesis_custom_loop', 'wpsc_thesis_compat' );
+
+ include( $template );
+ exit;
+ }
+}
+
+/**
+ * wpsc_count_themes_in_uploads_directory, does exactly what the name says
+ */
+function wpsc_count_themes_in_uploads_directory() {
+ $uploads_dir = false;
+ if ( is_dir( WPSC_OLD_THEMES_PATH.get_option('wpsc_selected_theme').'/' ) )
+ $uploads_dir = @opendir( WPSC_OLD_THEMES_PATH.get_option('wpsc_selected_theme').'/' ); // might cause problems if dir doesnt exist
+
+ if ( !$uploads_dir )
+ return false;
+
+ $file_names = array( );
+ while ( ($file = @readdir( $uploads_dir )) !== false ) {
+ if ( is_dir( WPSC_OLD_THEMES_PATH . get_option('wpsc_selected_theme') . '/' . $file ) && ($file != "..") && ($file != ".") && ($file != ".svn") )
+ $file_names[] = $file;
+
+ }
+ @closedir( $uploads_dir );
+ return count( $file_names );
+}
+
+function wpsc_place_shopping_cart( $content = '' ) {
+ if ( ! in_the_loop() )
+ return $content;
+
+ if ( preg_match( "/\[shoppingcart\]/", $content ) ) {
+ // BEGIN: compatibility fix for outdated theme files still relying on sessions
+ $_SESSION['coupon_numbers' ] = wpsc_get_customer_meta( 'coupon' );
+ $_SESSION['wpsc_checkout_misc_error_messages' ] = wpsc_get_customer_meta( 'checkout_misc_error_messages' );
+ $_SESSION['categoryAndShippingCountryConflict'] = wpsc_get_customer_meta( 'category_shipping_conflict' );
+ $_SESSION['shippingSameBilling' ] = wpsc_get_customer_meta( 'shipping_same_as_billing' );
+ $_SESSION['wpsc_checkout_user_error_messages' ] = wpsc_get_customer_meta( 'registration_error_messages' );
+ // END: compatibility fix
+ $GLOBALS['nzshpcrt_activateshpcrt'] = true;
+ if ( ! defined( 'DONOTCACHEPAGE' ) )
+ define( 'DONOTCACHEPAGE', true );
+
+ // call this function to detect conflicts when the cart page is first loaded, otherwise
+ // any conflict messages will only be displayed on the next page load
+ wpsc_get_acceptable_countries();
+ ob_start();
+ do_action( 'wpsc_before_shopping_cart_page' );
+ include( wpsc_get_template_file_path( 'wpsc-shopping_cart_page.php' ) );
+ do_action( 'wpsc_after_shopping_cart_page' );
+ $output = ob_get_contents();
+ ob_end_clean();
+ $output = str_replace( '$', '\$', $output );
+ wpsc_delete_customer_meta( 'checkout_misc_error_messages' );
+ wpsc_delete_customer_meta( 'category_shipping_conflict' );
+ wpsc_delete_customer_meta( 'registration_error_messages' );
+ wpsc_delete_customer_meta( 'checkout_error_messages' );
+ wpsc_delete_customer_meta( 'gateway_error_messages' );
+ return preg_replace( "/(
Your WP e-Commerce data needs to be updated. You\'ve upgraded from a previous version of the WP e-Commerce plugin, and your store needs updating. You should update your database for your store to continue working.', 'wpsc' ), admin_url( 'index.php?page=wpsc-update' ) ) ?>
-
-
-
-
-
-
Store Settings: You have set \'users must register before checkout\', for this to work you need to check \'Anyone can register\' in your WordPress General Settings.', 'wpsc' ), admin_url( 'options-general.php' ) ) ?>
-
-
-term_id;
}
-/**
- * Checks the category slug for a display type, if none set returns default
- * << May need reworking to be more specific to the taxonomy type >>
- * @access public
- *
- * @since 3.8
- * @param $slug(string)
- * @return $slug either from db or 'default' if none set
- */
-
-function wpsc_get_the_category_display($slug){
- global $wpdb;
- $default_display_type = get_option('product_view');
- if ( !empty($slug) && is_string($slug) ) {
- $category_id = wpsc_get_the_category_id($slug , 'slug');
- $display_type = wpsc_get_categorymeta( $category_id, 'display_type' );
- }
- if(!empty($display_type))
- return $display_type;
- else
- return $default_display_type;
-}
-
-/**
- * Checks if wpsc-single_product.php has been moved to the active theme, if it has then include the
- * template from the active theme.
- * @access public
- *
- * @since 3.8
- * @param $content content of the page
- * @return $content with wpsc-single_product content if its a single product
- */
-function wpsc_single_template( $content ) {
- global $wpdb, $post, $wp_query, $wpsc_query, $_wpsc_is_in_custom_loop;
- if ( ! in_the_loop() )
- return $content;
-
- //if we dont belong here exit out straight away
- if((!isset($wp_query->is_product)) && !isset($wp_query->query_vars['wpsc_product_category']))return $content;
-
- // If we are a single products page
- if ( !is_archive() && $wp_query->post_count > 0 && 'wpsc-product' == $wp_query->post->post_type && $wp_query->post_count <= 1 ) {
- remove_filter( "the_content", "wpsc_single_template", 12 );
- $single_theme_path = wpsc_get_template_file_path( 'wpsc-single_product.php' );
- if( isset( $wp_query->query_vars['preview'] ) && $wp_query->query_vars['preview'])
- $is_preview = 'true';
- else
- $is_preview = 'false';
- $wpsc_temp_query = new WP_Query( array( 'p' => $wp_query->post->ID , 'post_type' => 'wpsc-product','posts_per_page'=>1, 'preview' => $is_preview ) );
-
- list( $wp_query, $wpsc_temp_query ) = array( $wpsc_temp_query, $wp_query ); // swap the wpsc_query object
- $_wpsc_is_in_custom_loop = true;
- ob_start();
- include( $single_theme_path );
- $content = ob_get_contents();
- ob_end_clean();
- list( $wp_query, $wpsc_temp_query ) = array( $wpsc_temp_query, $wp_query ); // swap the wpsc_query objects back
- $_wpsc_is_in_custom_loop = false;
- }
-
- return $content;
-}
-
-
-
-function wpsc_is_viewable_taxonomy(){
- global $wp_query;
- if(isset($wp_query->query_vars['taxonomy']) && ('wpsc_product_category' == $wp_query->query_vars['taxonomy'] || 'product_tag' == $wp_query->query_vars['taxonomy'] ) || isset($wp_query->query_vars['wpsc_product_category']))
- return true;
- else
- return false;
-}
-
-function _wpsc_is_in_custom_loop() {
- global $_wpsc_is_in_custom_loop;
- return (bool) $_wpsc_is_in_custom_loop;
-}
-
-/**
- * Checks and replaces the Page title with the category title if on a category page
- *
- * @since 3.8
- * @access public
- *
- * @param string $title The Page Title
- * @param int $id The Page ID
- * @return string $title The new title
- *
- * @uses in_the_loop() Returns true if you are in the loop
- * @uses _wpsc_is_in_custom_loop() Returns true if in the WPSC custom loop
- * @uses is_tax() Returns true if you are on the supplied registered taxonomy
- * @uses get_term_by() Gets term object by defined item, and what you pass
- * @uses get_query_var() Gets query var from wp_query
- */
-function wpsc_the_category_title( $title='', $id='' ){
-
- if ( ! empty( $id ) )
- _wpsc_deprecated_argument( __FUNCTION__, '3.8.10', 'The $id param is not used. If you are trying to get the title of the category use get_term' );
-
- if ( ! in_the_loop() || _wpsc_is_in_custom_loop() )
- return $title;
-
- $term = null;
- if ( is_tax( 'wpsc_product_category' ) ){
- $term = get_term_by( 'slug', get_query_var( 'wpsc_product_category' ),'wpsc_product_category' );
- } elseif ( is_tax( 'product_tag' ) ){
- $term = get_term_by( 'slug', get_query_var( 'term' ),'product_tag' );
- } // is_tax
-
- if ( $term )
- return $term->name;
-
- return $title;
-
-}
-
-/**
- * wpsc_the_category_template swaps the template used for product categories with pageif archive template is being used use
- * @access public
- *
- * @since 3.8
- * @param $template (string) template path
- * @return $template (string)
- */
-function wpsc_the_category_template($template){
- global $wp_query;
- //this bit of code makes sure we use a nice standard page template for our products
- if(wpsc_is_viewable_taxonomy() && false !== strpos($template,'archive'))
- return str_ireplace('archive', 'page',$template);
- else
- return $template;
-
-}
-
-/**
- * wpsc_form_action
- *
- * Echo the form action for use in the template files
- *
- * @global $wpec_form_action
- * @return
- */
-function wpsc_form_action() {
- echo wpsc_get_form_action();
-}
- /**
- * wpsc_get_form_action
- *
- * Return the form action for use in the template files
- *
- * @global $wpec_form_action
- * @return
- */
- function wpsc_get_form_action() {
- global $wpec_form_action;
-
- $product_id = wpsc_the_product_id();
-
- // Function has already ran in this page load
- if ( isset( $wpec_form_action ) ) {
- $action = $wpec_form_action;
-
- // No global so figure it out
- } else {
-
- // Use external if set
- if ( wpsc_is_product_external() ) {
- $action = wpsc_product_external_link( $product_id );
-
- // Otherwise use this page
- } else {
- $action = wpsc_this_page_url();
- }
- }
-
- // Return form action
- return $action;
- }
-
-/**
- * wpsc_user_enqueues products function,
- * enqueue all javascript and CSS for wp ecommerce
- */
-function wpsc_enqueue_user_script_and_css() {
- global $wp_styles, $wpsc_theme_url, $wp_query;
- /**
- * added by xiligroup.dev to be compatible with touchshop
- */
- if ( has_filter( 'wpsc_enqueue_user_script_and_css' ) && apply_filters( 'wpsc_mobile_scripts_css_filters', false ) ) {
- do_action( 'wpsc_enqueue_user_script_and_css' );
- } else {
- /**
- * end of added by xiligroup.dev to be compatible with touchshop
- */
- $scheme = is_ssl() ? 'https' : 'http';
- $version_identifier = WPSC_VERSION . "." . WPSC_MINOR_VERSION;
-
- $category_id = wpsc_get_current_category_id();
-
- if ( get_option( 'wpsc_share_this' ) == 1 ) {
- $remote_protocol = is_ssl() ? 'https://ws' : 'http://w';
- wp_enqueue_script( 'sharethis', $remote_protocol . '.sharethis.com/button/buttons.js', array(), false, true );
- wp_enqueue_script( 'wpsc-sharethis', WPSC_CORE_JS_URL . '/sharethis.js', array( 'jquery', 'sharethis' ), $version_identifier );
- wp_enqueue_style( 'wpsc-sharethis-css', WPSC_CORE_JS_URL . '/sharethis.css', false, $version_identifier, 'all' );
- }
-
- wp_enqueue_script( 'jQuery' );
- wp_enqueue_script( 'wp-e-commerce', WPSC_CORE_JS_URL . '/wp-e-commerce.js', array( 'jquery' ), $version_identifier );
- wp_enqueue_script( 'wp-e-commerce-dynamic', home_url( '/index.php?wpsc_user_dynamic_js=true', $scheme ), false, $version_identifier );
-
- wp_localize_script( 'wp-e-commerce-dynamic', 'wpsc_ajax', array(
- 'ajaxurl' => admin_url( 'admin-ajax.php', 'relative' ),
- 'spinner' => esc_url( admin_url( 'images/wpspin_light.gif' ) ),
- 'no_quotes' => __( 'It appears that there are no shipping quotes for the shipping information provided. Please check the information and try again.', 'wpsc' )
- )
- );
-
- wp_enqueue_script( 'livequery', WPSC_URL . '/wpsc-admin/js/jquery.livequery.js', array( 'jquery' ), '1.0.3' );
- if( get_option( 'product_ratings' ) == 1 )
- wp_enqueue_script( 'jquery-rating', WPSC_CORE_JS_URL . '/jquery.rating.js', array( 'jquery' ), $version_identifier );
- wp_enqueue_script( 'wp-e-commerce-legacy', WPSC_CORE_JS_URL . '/user.js', array( 'jquery' ), WPSC_VERSION . WPSC_MINOR_VERSION );
- if ( get_option( 'show_thumbnails_thickbox' ) == 1 ){
- $lightbox = get_option('wpsc_lightbox', 'thickbox');
- if( $lightbox == 'thickbox' ) {
- wp_enqueue_script( 'wpsc-thickbox', WPSC_CORE_JS_URL . '/thickbox.js', array( 'jquery' ), 'Instinct_e-commerce' );
- wp_enqueue_style( 'wpsc-thickbox', WPSC_CORE_JS_URL . '/thickbox.css', false, $version_identifier, 'all' );
- } elseif( $lightbox == 'colorbox' ) {
- wp_enqueue_script( 'colorbox-min', WPSC_CORE_JS_URL . '/jquery.colorbox-min.js', array( 'jquery' ), 'Instinct_e-commerce' );
- wp_enqueue_script( 'wpsc_colorbox', WPSC_CORE_JS_URL . '/wpsc_colorbox.js', array( 'jquery', 'colorbox-min' ), 'Instinct_e-commerce' );
- wp_enqueue_style( 'wpsc-colorbox-css', WPSC_CORE_JS_URL . '/wpsc_colorbox.css', false, $version_identifier, 'all' );
- }
- }
- wp_enqueue_style( 'wpsc-theme-css', wpsc_get_template_file_url( 'wpsc-' . get_option( 'wpsc_selected_theme' ) . '.css' ), false, $version_identifier, 'all' );
- wp_enqueue_style( 'wpsc-theme-css-compatibility', wpsc_get_template_file_url( 'compatibility.css' ), array( 'wpsc-theme-css' ), $version_identifier, 'all' );
-
- if ( function_exists( 'wp_add_inline_style' ) )
- wp_add_inline_style( 'wpsc-theme-css', wpsc_get_user_dynamic_css() );
- else
- wp_enqueue_style( 'wp-e-commerce-dynamic', wpsc_get_dynamic_user_css_url(), array( 'wpsc-theme-css' ), $version_identifier );
-
- if( get_option( 'product_ratings' ) == 1 )
- wp_enqueue_style( 'wpsc-product-rater', WPSC_CORE_JS_URL . '/product_rater.css', false, $version_identifier, 'all' );
-
- }
-
-
- if ( !defined( 'WPSC_MP3_MODULE_USES_HOOKS' ) && function_exists( 'listen_button' ) ) {
-
- function wpsc_legacy_add_mp3_preview( $product_id, &$product_data ) {
- global $wpdb;
- if ( function_exists( 'listen_button' ) ) {
- $file_data = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM `" . WPSC_TABLE_PRODUCT_FILES . "` WHERE `id` = %d LIMIT 1", $product_data['file'] ), ARRAY_A );
- if ( $file_data != null ) {
- echo listen_button( $file_data['idhash'], $file_data['id'] );
- }
- }
- }
-
- add_action( 'wpsc_product_before_description', 'wpsc_legacy_add_mp3_preview', 10, 2 );
- }
-}
-if ( ! is_admin() )
- add_action( 'init', 'wpsc_enqueue_user_script_and_css' );
-
-/**
- * Returns current product category ID or default category ID if one is set. If one is not set and there is no current category, returns empty string
- * @return mixed
- */
-function wpsc_get_current_category_id() {
- global $wp_query;
-
- $category_id = '';
-
- if ( isset( $wp_query ) && isset( $wp_query->query_vars['taxonomy'] ) && ('wpsc_product_category' == $wp_query->query_vars['taxonomy'] ) || is_numeric( get_option( 'wpsc_default_category' ) ) )
- $category_id = isset( $wp_query->query_vars['term'] ) && is_string( $wp_query->query_vars['term'] ) ? wpsc_get_category_id( $wp_query->query_vars['term'], 'slug' ) : get_option( 'wpsc_default_category' );
-
- return $category_id;
-}
-
-
-function wpsc_product_list_rss_feed() {
- $rss_url = add_query_arg( 'wpsc_action', 'rss', home_url( '/' ) );
- $rss_url = str_replace('&', '&', $rss_url);
- $rss_url = esc_url( $rss_url ); // URL santization - IMPORTANT!
-
- echo "";
-}
-add_action( 'wp_head', 'wpsc_product_list_rss_feed' );
-
function wpsc_user_dynamic_js() {
header( 'Content-Type: text/javascript' );
header( 'Expires: ' . gmdate( 'r', mktime( 0, 0, 0, date( 'm' ), (date( 'd' ) + 12 ), date( 'Y' ) ) ) . '' );
@@ -672,927 +60,3 @@ function wpsc_user_dynamic_js() {
}
if ( isset( $_GET['wpsc_user_dynamic_js'] ) && ($_GET['wpsc_user_dynamic_js'] == 'true') )
add_action( "init", 'wpsc_user_dynamic_js' );
-
-
-/**
- * Returns Dynamic User CSS URL
- *
- * This produces the cached CSS file if it exists and the uploads folder is writeable.
- * If the folder is not writeable, we return the dynamic URL
- * If the folder is writeable, but for some reason a cached copy of the CSS doesn't exist, we attempt to create it and return that URL.
- *
- * @since 3.8.9
- * @return string
- */
-
-function wpsc_get_dynamic_user_css_url() {
-
- $uploads_dir = wp_upload_dir();
- $upload_folder = $uploads_dir['path'];
-
- if ( is_writable( $upload_folder ) && file_exists( $upload_folder . '/wpsc_cached_styles.css' ) )
- return add_query_arg( 'timestamp', get_option( 'wpsc_dynamic_css_hash', time() ), $uploads_dir['url'] . '/wpsc_cached_styles.css' );
-
- if ( ! is_writable( $upload_folder ) )
- return add_query_arg( 'wpsc_user_dynamic_css', 'true', home_url( 'index.php' ) );
-
- if ( is_writable( $upload_folder ) && ! file_exists( $upload_folder . '/wpsc_cached_styles.css' ) )
- return wpsc_cache_to_upload();
-}
-
-/**
- * Moves dynamically generated input into a file in the uploads folder.
- * Also updates CSS hash timestamp. Timestamp is appended to URL
- *
- * @since 3.8.9
- * @return mixed File URL on successful move, false on failure
- */
-function wpsc_cache_to_upload() {
-
- $uploads_dir = wp_upload_dir();
- $upload_folder = $uploads_dir['path'];
- $path = $upload_folder . '/wpsc_cached_styles.css';
-
- if ( ! is_writable( $upload_folder ) )
- return false;
-
- if ( false === file_put_contents( $path, wpsc_get_user_dynamic_css() ) )
- return false;
-
- $timestamp = time();
-
- update_option( 'wpsc_dynamic_css_hash', $timestamp );
-
- return add_query_arg( 'timestamp', $timestamp, $uploads_dir['url'] . '/wpsc_cached_styles.css' );
-
-}
-
-/**
- * Prints dynamic CSS. This function is run either when the dynamic URL is hit, or when we need to grab new CSS to cache.
- *
- * @since 3.8.9
- * @return CSS
- */
-function wpsc_user_dynamic_css() {
-
- header( 'Content-Type: text/css' );
- header( 'Expires: ' . gmdate( 'r', mktime( 0, 0, 0, date( 'm' ), ( date( 'd' ) + 12 ), date( 'Y' ) ) ) );
- header( 'Cache-Control: public, must-revalidate, max-age=86400' );
- header( 'Pragma: public' );
-
- echo wpsc_get_user_dynamic_css();
- exit;
-}
-
-/**
- * Returns dynamic CSS as string. This function is run either when the dynamic URL is hit, or when we need to grab new CSS to cache.
- *
- * @since 3.8.9
- * @return string
- */
-function wpsc_get_user_dynamic_css() {
- global $wpdb;
-
- ob_start();
-
- if ( ! defined( 'WPSC_DISABLE_IMAGE_SIZE_FIXES' ) || (constant( 'WPSC_DISABLE_IMAGE_SIZE_FIXES' ) != true ) ) {
-
- $thumbnail_width = get_option( 'product_image_width' );
-
- if ( $thumbnail_width <= 0 )
- $thumbnail_width = 96;
-
- $thumbnail_height = get_option( 'product_image_height' );
-
- if ( $thumbnail_height <= 0 )
- $thumbnail_height = 96;
-
- $single_thumbnail_width = get_option( 'single_view_image_width' );
- $single_thumbnail_height = get_option( 'single_view_image_height' );
-
- if ( $single_thumbnail_width <= 0 )
- $single_thumbnail_width = 128;
-
- $category_height = get_option( 'category_image_height' );
- $category_width = get_option( 'category_image_width' );
-?>
-
- /*
- * Default View Styling
- */
- div.default_product_display div.textcol{
- margin-left: px !important;
- min-height: px;
- _height: px;
- }
-
- div.default_product_display div.textcol div.imagecol{
- position:absolute;
- top:0px;
- left: 0px;
- margin-left: -px !important;
- }
-
- div.default_product_display div.textcol div.imagecol a img {
- width: px;
- height: px;
- }
-
- .wpsc_category_grid_item {
- display:block;
- float:left;
- width: px;
- height: px;
- }
- .wpsc_category_grid_item span{
- position:relative;
- top:px;
- }
- div.default_product_display div.item_no_image a {
- width: px;
- }
-
- div.default_product_display .imagecol img.no-image, #content div.default_product_display .imagecol img.no-image {
- width: px;
- height: px;
- }
-
-
-
- /*
- * Single View Styling
- */
-
- div.single_product_display div.item_no_image {
- width: px;
- height: px;
- }
- div.single_product_display div.item_no_image a {
- width: px;
- }
-
- div.single_product_display div.textcol{
- margin-left: px !important;
- min-height: px;
- _height: px;
- }
-
-
- div.single_product_display div.textcol div.imagecol{
- position:absolute;
-
- margin-left: -px !important;
- }
-
- div.single_product_display div.textcol div.imagecol a img {
- width: px;
- height: px;
- }
-
-
- div#categorydisplay{
- display: ;
- }
-
- div#branddisplay{
- display: ;
- }
-get_var($wpdb->prepare( "SELECT `post_id` FROM `{$wpdb->postmeta}` WHERE meta_key = %s AND `meta_value` = %d LIMIT 1", '_wpsc_original_id', $prod_id ));
- return $post_id;
-
-}
-// Template tags
-/**
- * wpsc display products function
- * @return string - html displaying one or more products
- */
-function wpsc_display_products_page( $query ) {
- global $wpdb, $wpsc_query,$wp_query, $wp_the_query;
-
- remove_filter('the_title','wpsc_the_category_title');
-
- // If the data is coming from a shortcode parse the values into the args variable,
- // I did it this was to preserve backwards compatibility
- if(!empty($query)){
- $args = array();
-
- $args['post_type'] = 'wpsc-product';
- if(!empty($query['product_id']) && is_array($query['product_id'])){
- $args['post__in'] = $query['product_id'];
- }elseif(is_string($query['product_id'])){
- $args['post__in'] = (array)$query['product_id'];
- }
- if(!empty($query['old_product_id'])){
- $post_id = wpsc_get_the_new_id($query['old_product_id']);
- $args['post__in'] = (array)$post_id;
- }
- if(!empty($query['price']) && 'sale' != $query['price']){
- $args['meta_key'] = '_wpsc_price';
- $args['meta_value'] = $query['price'];
- }elseif(!empty($query['price']) && 'sale' == $query['price']){
- $args['meta_key'] = '_wpsc_special_price';
- $args['meta_compare'] = '>=';
- $args['meta_value'] = '1';
- }
- if(!empty($query['product_name'])){
- $args['pagename'] = $query['product_name'];
- }
- if(!empty($query['category_id'])){
- $term = get_term($query['category_id'],'wpsc_product_category');
- $id = wpsc_get_meta($query['category_id'], 'category_id','wpsc_old_category');
- if( !empty($id)){
- $term = get_term($id,'wpsc_product_category');
- $args['wpsc_product_category'] = $term->slug;
- $args['wpsc_product_category__in'] = $term->term_id;
- }else{
- $args['wpsc_product_category'] = $term->slug;
- $args['wpsc_product_category__in'] = $term->term_id;
- }
- }
- if(!empty($query['category_url_name'])){
- $args['wpsc_product_category'] = $query['category_url_name'];
- }
- $orderby = ( !empty($query['sort_order']) ) ? $query['sort_order'] : null;
-
- $args = array_merge( $args, wpsc_product_sort_order_query_vars($orderby) );
-
- if(!empty($query['order'])){
- $args['order'] = $query['order'];
- }
- if(!empty($query['limit_of_items']) && '1' == get_option('use_pagination')){
- $args['posts_per_page'] = $query['limit_of_items'];
- }
- if(!empty($query['number_per_page']) && '1' == get_option('use_pagination')){
- $args['posts_per_page'] = $query['number_per_page'];
- $args['paged'] = $query['page'];
- }
- if( '0' == get_option('use_pagination') ){
- $args['nopaging'] = true;
- $args['posts_per_page'] = '-1';
- }
- if(!empty($query['tag'])){
- $args['product_tag'] = $query['tag'];
- }
- query_posts( $args );
- }
- // swap the wpsc_query objects
-
- $GLOBALS['nzshpcrt_activateshpcrt'] = true;
-
- // Pretty sure this single_product code is legacy...but fixing it up just in case.
- // get the display type for the selected category
- if(!empty($temp_wpsc_query->query_vars['term']))
- $display_type = wpsc_get_the_category_display($temp_wpsc_query->query_vars['term']);
- elseif( !empty( $args['wpsc_product_category'] ) )
- $display_type = wpsc_get_the_category_display($args['wpsc_product_category']);
- else
- $display_type = 'default';
-
- $saved_display = wpsc_get_customer_meta( 'display_type' );
- $display_type = ! empty( $saved_display ) ? $saved_display : wpsc_check_display_type();
-
- ob_start();
- if( 'wpsc-product' == $wp_query->post->post_type && !is_archive() && $wp_query->post_count <= 1 )
- include( wpsc_get_template_file_path( 'wpsc-single_product.php' ) );
- else
- wpsc_include_products_page_template($display_type);
-
- $output = ob_get_contents();
- ob_end_clean();
- $output = str_replace('\$','$', $output);
-
- if ( ! empty( $query ) ) {
- wp_reset_query();
- wp_reset_postdata();
- }
- return $output;
-}
-
-/**
- * This switched between the 3 view types on category and products pages and includes the necessary tempalte part
- * @access public
- *
- * @since 3.8
- * @param $display_type
- * @return NULL
- */
-function wpsc_include_products_page_template($display_type = 'default'){
- if ( isset( $_GET['view_type'] ) && get_option( 'show_search' ) && get_option( 'show_advanced_search' ) ) {
- switch ( $_GET['view_type'] ) {
- case 'grid':
- $display_type = 'grid';
- wpsc_update_customer_meta( 'display_type', $display_type );
- break;
-
- case 'list':
- $display_type = 'list';
- wpsc_update_customer_meta( 'display_type', $display_type );
- break;
-
- case 'default':
- $display_type = 'default';
- wpsc_update_customer_meta( 'display_type', $display_type );
- break;
-
- default:
- break;
- }
- }
- // switch the display type, based on the display type variable...
- switch ( $display_type ) {
- case "grid":
- include( wpsc_get_template_file_path( 'wpsc-grid_view.php' ) );
- break; // only break if we have the function;
-
- case "list":
- include( wpsc_get_template_file_path( 'wpsc-list_view.php' ) );
- break; // only break if we have the file;
- default:
- include( wpsc_get_template_file_path( 'wpsc-products_page.php' ) );
- break;
- }
-
-}
-
-//handles replacing the tags in the pages
-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();
- 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( "/(