diff --git a/wp-shopping-cart.php b/wp-shopping-cart.php index 268925f5a6..d1b53321ed 100644 --- a/wp-shopping-cart.php +++ b/wp-shopping-cart.php @@ -69,6 +69,12 @@ public function _register_core_components( $components ) { WPSC_FILE_PATH . '/wpsc-components/merchant-core-v2/merchant-core-v2.php' ); + $components['theme-engine']['core-v1'] = array( + 'title' => __( 'WP e-Commerce Theme Engine v1', 'wpsc' ), + 'includes' => + WPSC_FILE_PATH . '/wpsc-components/theme-engine-v1/theme-engine-v1.php' + ); + return $components; } @@ -195,9 +201,6 @@ function load() { // Setup the core WPEC cart wpsc_core_setup_cart(); - // Load the thumbnail sizes - wpsc_core_load_thumbnail_sizes(); - // Load the purchase log statuses wpsc_core_load_purchase_log_statuses(); @@ -210,9 +213,6 @@ function load() { // Load the shipping modules wpsc_core_load_shipping_modules(); - // Set page title array for important WPSC pages - wpsc_core_load_page_titles(); - // WPEC is fully loaded do_action( 'wpsc_loaded' ); } diff --git a/wpsc-admin/css/admin.css b/wpsc-admin/css/admin.css index 17b3748890..442b7a9d27 100644 --- a/wpsc-admin/css/admin.css +++ b/wpsc-admin/css/admin.css @@ -1906,24 +1906,38 @@ table.purchase-logs tr:hover .column-id .delete { .wpsc-product-variations-tabs { background: #F1F1F1; - border-bottom: 1px solid #ccc; - padding: 10px 10px 0; + border-bottom: 1px solid #dfdfdf; + padding: 5px 4px 0; margin: 0; + width: 100%; +} + +.wpsc-product-variations-tabs:before, +.wpsc-product-variations-tabs:after { + display: table; + content: ""; +} + +.wpsc-product-variations-tabs:after { + clear: both; } .wpsc-product-variations-tabs li { - display: inline-block; - margin: 0 4px 2px 0; + float: left; + margin: 0 4px 0 0; } .wpsc-product-variations-tabs a { - background-color: #fff; - border-color: #ccc #ccc #fff; + display: block; + background-color: #f1f1f1; + border-color: #dfdfdf #dfdfdf #fff; border-style: solid; border-width: 1px 1px 0; + line-height: 1em; color: #aaa; padding: 5px 7px 3px; text-decoration: none; + vertical-align: middle; border-top-left-radius: 3px; border-top-right-radius: 3px; @@ -1938,12 +1952,14 @@ table.purchase-logs tr:hover .column-id .delete { } .wpsc-product-variations-tabs .active a { + background: #fff; border-bottom-width: 1px; color: #333; - margin-bottom: 2px; + margin-bottom: -1px; } .wpsc-product-variations-tab-content { + clear: both; padding: 0 10px; } diff --git a/wpsc-admin/includes/product-variations-page.class.php b/wpsc-admin/includes/product-variations-page.class.php index 64c5b34f27..1a5f5176b2 100644 --- a/wpsc-admin/includes/product-variations-page.class.php +++ b/wpsc-admin/includes/product-variations-page.class.php @@ -60,7 +60,7 @@ private function save_variation_meta( $id, $data ) { if ( isset( $data['sku'] ) ) update_product_meta( $id, 'sku', $data['sku'] ); - if ( isset( $data['stock'] ) && $data['stock'] !== '' ) { + if ( isset( $data['stock'] ) ) { if ( is_numeric( $data['stock'] ) ) update_product_meta( $id, 'stock', absint( $data['stock'] ) ); else diff --git a/wpsc-admin/init.php b/wpsc-admin/init.php index c8d111aa2f..5bf2fa0a4b 100644 --- a/wpsc-admin/init.php +++ b/wpsc-admin/init.php @@ -679,19 +679,6 @@ function wpsc_delete_variation_set() { if ( isset( $_REQUEST['wpsc_admin_action'] ) && ( 'wpsc-delete-variation-set' == $_REQUEST['wpsc_admin_action'] ) ) add_action( 'admin_init', 'wpsc_delete_variation_set' ); -function wpsc_force_flush_theme_transients() { - // Flush transients - wpsc_flush_theme_transients( true ); - - // Bounce back - $sendback = wp_get_referer(); - wp_redirect( $sendback ); - - exit(); -} -if ( isset( $_REQUEST['wpsc_flush_theme_transients'] ) && ( $_REQUEST['wpsc_flush_theme_transients'] == 'true' ) ) - add_action( 'admin_init', 'wpsc_force_flush_theme_transients' ); - function wpsc_backup_theme() { $wp_theme_path = get_stylesheet_directory(); wpsc_recursive_copy( $wp_theme_path, WPSC_THEME_BACKUP_DIR ); diff --git a/wpsc-admin/settings-page.php b/wpsc-admin/settings-page.php index 2575386a59..73ef05599f 100644 --- a/wpsc-admin/settings-page.php +++ b/wpsc-admin/settings-page.php @@ -203,7 +203,6 @@ final class WPSC_Settings_Page { public static function init() { self::$default_tabs = array( 'general' => _x( 'General' , 'General settings tab in Settings->Store page' , 'wpsc' ), - 'presentation' => _x( 'Presentation', 'Presentation settings tab in Settings->Store page', 'wpsc' ), 'admin' => _x( 'Admin' , 'Admin settings tab in Settings->Store page' , 'wpsc' ), 'taxes' => _x( 'Taxes' , 'Taxes settings tab in Settings->Store page' , 'wpsc' ), 'shipping' => _x( 'Shipping' , 'Shipping settings tab in Settings->Store page' , 'wpsc' ), @@ -378,10 +377,10 @@ public function set_current_tab( $tab_id = null ) { if ( isset( $_REQUEST['wpsc_admin_action'] ) && ( $_REQUEST['wpsc_admin_action'] == 'submit_options' ) ) { check_admin_referer( 'update-options', 'wpsc-update-options' ); - + $this->save_options(); do_action( 'wpsc_save_' . $this->current_tab_id . '_settings', $this->current_tab ); - + $query_args = array(); if ( is_callable( array( $this->current_tab, 'callback_submit_options' ) ) ) { $additional_query_args = $this->current_tab->callback_submit_options(); @@ -445,6 +444,7 @@ private function tab_class( $id ) { */ private function submit_url() { $location = add_query_arg( 'tab', $this->current_tab_id ); + $location = apply_filters( 'wpsc_settings_page_submit_url', $location, $this, $this->current_tab ); return $location; } @@ -476,14 +476,14 @@ public function display_current_tab() {
current_tab, 'display' ) ) ) { + do_action( 'wpsc_before_settings_tab', $this, $this->current_tab ); $this->current_tab->display(); + do_action( 'wpsc_after_settings_tab', $this, $this->current_tab ); } ?> current_tab_id . '_settings_page' ); ?>
- - current_tab->is_submit_button_displayed() ): ?> @@ -706,3 +706,12 @@ private function save_options( $selected = '' ) { } WPSC_Settings_Page::init(); + +add_action( 'wpsc_after_settings_tab', '_wpsc_action_after_settings_tab' ); + +function _wpsc_action_after_settings_tab() { + ?> + + +} \ No newline at end of file diff --git a/wpsc-components/theme-engine-v1/classes/hide-subcatsprods-in-cat.php b/wpsc-components/theme-engine-v1/classes/hide-subcatsprods-in-cat.php new file mode 100644 index 0000000000..ff10a2d020 --- /dev/null +++ b/wpsc-components/theme-engine-v1/classes/hide-subcatsprods-in-cat.php @@ -0,0 +1,61 @@ +q =& $q; + if ( ( !isset($q->query_vars['taxonomy']) || ( "wpsc_product_category" != $q->query_vars['taxonomy'] )) ) + return false; + + add_action( 'posts_where', array( &$this, 'where' ) ); + add_action( 'posts_join', array( &$this, 'join' ) ); + } + + function where( $where ) { + global $wpdb; + + remove_action( 'posts_where', array( &$this, 'where' ) ); + + $term_id=$wpdb->get_var($wpdb->prepare('SELECT term_id FROM '.$wpdb->terms.' WHERE slug = %s ', $this->q->query_vars['term'])); + + if ( !is_numeric( $term_id ) || $term_id < 1 ) + return $where; + + $term_taxonomy_id = $wpdb->get_var($wpdb->prepare('SELECT term_taxonomy_id FROM '.$wpdb->term_taxonomy.' WHERE term_id = %d and taxonomy = %s', $term_id, $this->q->query_vars['taxonomy'])); + + if ( !is_numeric($term_taxonomy_id) || $term_taxonomy_id < 1) + return $where; + + $field = preg_quote( "$wpdb->term_relationships.term_taxonomy_id", '#' ); + + $just_one = $wpdb->prepare( " AND $wpdb->term_relationships.term_taxonomy_id = %d ", $term_taxonomy_id ); + if ( preg_match( "#AND\s+$field\s+IN\s*\(\s*(?:['\"]?\d+['\"]?\s*,\s*)*['\"]?\d+['\"]?\s*\)#", $where, $matches ) ) + $where = str_replace( $matches[0], $just_one, $where ); + else + $where .= $just_one; + + return $where; + } + + function join($join){ + global $wpdb; + remove_action( 'posts_where', array( &$this, 'where' ) ); + remove_action( 'posts_join', array( &$this, 'join' ) ); + if( strpos($join, "JOIN $wpdb->term_relationships ON ($wpdb->posts.ID = $wpdb->term_relationships.object_id)" ) ){ + return $join; + } + $join .= " JOIN $wpdb->term_relationships ON ($wpdb->posts.ID = $wpdb->term_relationships.object_id)"; + return $join; + } +} + diff --git a/wpsc-admin/includes/settings-tabs/presentation.php b/wpsc-components/theme-engine-v1/classes/settings-tab-presentation.php similarity index 100% rename from wpsc-admin/includes/settings-tabs/presentation.php rename to wpsc-components/theme-engine-v1/classes/settings-tab-presentation.php diff --git a/wpsc-components/theme-engine-v1/classes/wpsc-products-by-category.php b/wpsc-components/theme-engine-v1/classes/wpsc-products-by-category.php new file mode 100644 index 0000000000..2780e8efa0 --- /dev/null +++ b/wpsc-components/theme-engine-v1/classes/wpsc-products-by-category.php @@ -0,0 +1,130 @@ +query_vars; + + + // Category stuff for nice URLs + if ( !empty( $q['wpsc_product_category'] ) && !$query->is_singular ) { + $q['taxonomy'] = 'wpsc_product_category'; + $q['term'] = $q['wpsc_product_category']; + $in_cats = ''; + $join = " INNER JOIN $wpdb->term_relationships + ON ($wpdb->posts.ID = $wpdb->term_relationships.object_id) + INNER JOIN $wpdb->term_taxonomy + ON ($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id) + "; + if(isset($q['meta_key'])) + $join .= " INNER JOIN $wpdb->postmeta ON ($wpdb->posts.ID = $wpdb->postmeta.post_id) "; + + $whichcat = " AND $wpdb->term_taxonomy.taxonomy = '{$q['taxonomy']}' "; + + $term_data = get_term_by( 'slug', $q['term'], $q['taxonomy'] ); + + if( is_object( $term_data ) ) + $in_cats = array( $term_data->term_id ); + + if('0' != get_option('show_subcatsprods_in_cat') && is_object($term_data)){ + $term_children_data = get_term_children( $term_data->term_id, $q['taxonomy'] ); + $in_cats = array_reverse( array_merge( $in_cats, $term_children_data ) ); + } + if( is_array( $in_cats ) ){ + $in_cats = "'" . implode( "', '", $in_cats ) . "'"; + $whichcat .= "AND $wpdb->term_taxonomy.term_id IN ($in_cats)"; + } + + $post_type_object = get_post_type_object( 'wpsc-product' ); + $permitted_post_statuses = current_user_can( $post_type_object->cap->edit_posts ) ? "'private', 'draft', 'pending', 'publish'" : "'publish'"; + + + $whichcat .= " AND $wpdb->posts.post_status IN ($permitted_post_statuses) "; + $groupby = "{$wpdb->posts}.ID"; + + $this->sql_components['join'] = $join; + $this->sql_components['fields'] = "{$wpdb->posts}.*, {$wpdb->term_taxonomy}.term_id"; + $this->sql_components['group_by'] = $groupby; + + //what about ordering by price + if(isset($q['meta_key']) && '_wpsc_price' == $q['meta_key']){ + $whichcat .= " AND $wpdb->postmeta.meta_key = '_wpsc_price'"; + }else{ + + $this->sql_components['order_by'] = "{$wpdb->term_taxonomy}.term_id"; + } + $this->sql_components['where'] = $whichcat; + add_filter( 'posts_join', array( &$this, 'join_sql' ) ); + add_filter( 'posts_where', array( &$this, 'where_sql' ) ); + add_filter( 'posts_fields', array( &$this, 'fields_sql' ) ); + add_filter( 'posts_orderby', array( &$this, 'order_by_sql' ) ); + add_filter( 'posts_groupby', array( &$this, 'group_by_sql' ) ); + } + } + + function join_sql( $sql ) { + if ( isset( $this->sql_components['join'] ) ) + $sql = $this->sql_components['join']; + + remove_filter( 'posts_join', array( &$this, 'join_sql' ) ); + return $sql; + } + + function where_sql( $sql ) { + if ( isset( $this->sql_components['where'] ) ) + $sql = $this->sql_components['where']; + + remove_filter( 'posts_where', array( &$this, 'where_sql' ) ); + return $sql; + } + + function order_by_sql( $sql ) { + $order_by_parts = array( ); + $order_by_parts[] = $sql; + + if ( isset( $this->sql_components['order_by'] ) ) + $order_by_parts[] = $this->sql_components['order_by']; + + $order_by_parts = array_reverse( $order_by_parts ); + $sql = implode( ',', $order_by_parts ); + + remove_filter( 'posts_orderby', array( &$this, 'order_by_sql' ) ); + return $sql; + } + + function fields_sql( $sql ) { + if ( isset( $this->sql_components['fields'] ) ) + $sql = $this->sql_components['fields']; + + remove_filter( 'posts_fields', array( &$this, 'fields_sql' ) ); + return $sql; + } + + function group_by_sql( $sql ) { + if ( isset( $this->sql_components['group_by'] ) ) + $sql = $this->sql_components['group_by']; + + remove_filter( 'posts_groupby', array( &$this, 'group_by_sql' ) ); + return $sql; + } + + function request_sql( $sql ) { + echo $sql . "
"; + remove_filter( 'posts_request', array( &$this, 'request_sql' ) ); + return $sql; + } +} + diff --git a/wpsc-components/theme-engine-v1/helpers/admin.php b/wpsc-components/theme-engine-v1/helpers/admin.php new file mode 100644 index 0000000000..77df036423 --- /dev/null +++ b/wpsc-components/theme-engine-v1/helpers/admin.php @@ -0,0 +1,14 @@ +register_tab( 'presentation', _x( 'Presentation', 'Presentation settings tab in Settings->Store page', 'wpsc' ) ); +} + +function _wpsc_te_v1_load_settings_tab_class( $page_instance ) { + $current_tab_id = $page_instance->get_current_tab_id(); + if ( in_array( $current_tab_id, array( 'presentation' ) ) ) + require_once( WPSC_TE_V1_PATH . '/classes/settings-tab-presentation.php' ); +} diff --git a/wpsc-components/theme-engine-v1/helpers/ajax.php b/wpsc-components/theme-engine-v1/helpers/ajax.php new file mode 100644 index 0000000000..bd9226aff2 --- /dev/null +++ b/wpsc-components/theme-engine-v1/helpers/ajax.php @@ -0,0 +1,1094 @@ + 0))) ) + add_action( 'init', 'wpsc_empty_cart' ); + +if ( isset( $_POST['coupon_num'] ) ) + add_action( 'init', 'wpsc_coupon_price' ); + +if ( isset( $_REQUEST['wpsc_update_quantity'] ) && ($_REQUEST['wpsc_update_quantity'] == 'true') ) + add_action( 'init', 'wpsc_update_item_quantity' ); + +if ( isset( $_REQUEST['wpsc_ajax_action'] ) && ($_REQUEST['wpsc_ajax_action'] == 'rate_product') ) + add_action( 'init', 'wpsc_update_product_rating' ); + +add_action( 'wp_ajax_add_to_cart' , 'wpsc_add_to_cart' ); +add_action( 'wp_ajax_nopriv_add_to_cart', 'wpsc_add_to_cart' ); +add_action( 'wp_ajax_get_cart' , 'wpsc_get_cart' ); +add_action( 'wp_ajax_nopriv_get_cart', 'wpsc_get_cart' ); +add_action( 'wp_ajax_update_shipping_price' , 'wpsc_update_shipping_price' ); +add_action( 'wp_ajax_nopriv_update_shipping_price', 'wpsc_update_shipping_price' ); +add_action( 'wp_ajax_update_product_price' , 'wpsc_update_product_price' ); +add_action( 'wp_ajax_nopriv_update_product_price', 'wpsc_update_product_price' ); +add_action( 'wp_ajax_update_location' , 'wpsc_update_location' ); +add_action( 'wp_ajax_nopriv_update_location', 'wpsc_update_location' ); +add_action( 'wp_ajax_change_tax' , 'wpsc_change_tax' ); +add_action( 'wp_ajax_nopriv_change_tax', 'wpsc_change_tax' ); +add_action( 'wp_ajax_change_profile_country' , '_wpsc_change_profile_country' ); +add_action( 'wp_ajax_nopriv_change_profile_country', '_wpsc_change_profile_country' ); + + +/** + * WP eCommerce AJAX and Init functions + * + * These are the WPSC AJAX and Init functions + * + * @package wp-e-commerce + * @since 3.7 + */ +function wpsc_special_widget() { + wpsc_add_to_cart(); +} + +/** + * add_to_cart function, used through ajax and in normal page loading. + * No parameters, returns nothing + */ +function wpsc_add_to_cart() { + global $wpsc_cart; + + /// default values + $default_parameters['variation_values'] = null; + $default_parameters['quantity'] = 1; + $default_parameters['provided_price'] = null; + $default_parameters['comment'] = null; + $default_parameters['time_requested'] = null; + $default_parameters['custom_message'] = null; + $default_parameters['file_data'] = null; + $default_parameters['is_customisable'] = false; + $default_parameters['meta'] = null; + + $provided_parameters = array(); + $post_type_object = get_post_type_object( 'wpsc-product' ); + $permitted_post_statuses = current_user_can( $post_type_object->cap->edit_posts ) ? array( 'private', 'draft', 'pending', 'publish' ) : array( 'publish' ); + + /// sanitise submitted values + $product_id = apply_filters( 'wpsc_add_to_cart_product_id' , (int) $_POST['product_id'] ); + $product = apply_filters( 'wpsc_add_to_cart_product_object', get_post( $product_id, OBJECT, 'display' ) ); + + if ( ! in_array( $product->post_status, $permitted_post_statuses ) || 'wpsc-product' != $product->post_type ) + return false; + + // compatibility with older themes + if ( isset( $_POST['wpsc_quantity_update'] ) && is_array( $_POST['wpsc_quantity_update'] ) ) { + $_POST['wpsc_quantity_update'] = $_POST['wpsc_quantity_update'][$product_id]; + } + + if(isset($_POST['variation'])){ + foreach ( (array) $_POST['variation'] as $key => $variation ) { + $provided_parameters['variation_values'][ (int) $key ] = (int) $variation; + } + + if ( count( $provided_parameters['variation_values'] ) > 0 ) { + $variation_product_id = wpsc_get_child_object_in_terms( $product_id, $provided_parameters['variation_values'], 'wpsc-variation' ); + if ( $variation_product_id > 0 ) { + $product_id = $variation_product_id; + } + } + + } + + if ( (isset( $_POST['quantity'] ) && $_POST['quantity'] > 0) && (!isset( $_POST['wpsc_quantity_update'] )) ) { + $provided_parameters['quantity'] = (int) $_POST['quantity']; + } else if ( isset( $_POST['wpsc_quantity_update'] ) ) { + $wpsc_cart->remove_item( $_POST['key'] ); + $provided_parameters['quantity'] = (int) $_POST['wpsc_quantity_update']; + } + + if ( isset( $_POST['is_customisable'] ) && + 'true' == $_POST['is_customisable'] ) { + $provided_parameters['is_customisable'] = true; + + if ( isset( $_POST['custom_text'] ) ) { + $provided_parameters['custom_message'] = stripslashes( $_POST['custom_text'] ); + } + if ( isset( $_FILES['custom_file'] ) ) { + $provided_parameters['file_data'] = $_FILES['custom_file']; + } + } + + if ( isset( $_POST['donation_price'] ) && ( (float) $_POST['donation_price'] > 0 ) ) { + $provided_parameters['provided_price'] = (float) $_POST['donation_price']; + } + + $parameters = array_merge( $default_parameters, (array) $provided_parameters ); + + $cart_item = $wpsc_cart->set_item( $product_id, $parameters ); + + if ( is_object( $cart_item ) ) { + do_action( 'wpsc_add_to_cart', $product, $cart_item ); + $cart_messages[] = str_replace( "[product_name]", $cart_item->get_title(), __( 'You just added "[product_name]" to your cart.', 'wpsc' ) ); + } else { + if ( $parameters['quantity'] <= 0 ) { + $cart_messages[] = __( 'Sorry, but you cannot add zero items to your cart', 'wpsc' ); + } else if ( $wpsc_cart->get_remaining_quantity( $product_id, $parameters['variation_values'], $parameters['quantity'] ) > 0 ) { + $quantity = $wpsc_cart->get_remaining_quantity( $product_id, $parameters['variation_values'], $parameters['quantity'] ); + $cart_messages[] = sprintf( _n( 'Sorry, but there is only %s of this item in stock.', 'Sorry, but there are only %s of this item in stock.', $quantity, 'wpsc' ), $quantity ); + } else { + $cart_messages[] = sprintf( __( 'Sorry, but the item "%s" is out of stock.', 'wpsc' ), $product->post_title ); + } + } + + + if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) { + + $json_response = array( 'cart_messages' => $cart_messages, 'product_id' => $product_id, 'cart_total' => wpsc_cart_total() ); + + $output = _wpsc_ajax_get_cart( false, $cart_messages ); + + $json_response = $json_response + $output; + + if ( is_numeric( $product_id ) && 1 == get_option( 'fancy_notifications' ) ) + $json_response['fancy_notification'] = str_replace( array( "\n", "\r" ), array( '\n', '\r' ), fancy_notification_content( $cart_messages ) ); + + die( json_encode( $json_response ) ); + } +} + +function wpsc_get_cart() { + _wpsc_ajax_get_cart(); +} + +/* 19-02-09 + * add cart button function used for php template tags and shortcodes + */ + +function wpsc_add_to_cart_button( $product_id, $return = false ) { + global $wpdb,$wpsc_variations; + $output = ''; + if ( $product_id > 0 ) { + // grab the variation form fields here + $wpsc_variations = new wpsc_variations( $product_id ); + if ( $return ) + ob_start(); + ?> +
+
+ +
+ +

+ + +

+ +
+ + + ' /> + +
+
+ $product_id ) { + $original_string = $matches[0][$key]; + $output = wpsc_add_to_cart_button( $product_id, true ); + $content = str_replace( $original_string, $output, $content ); + } + + if ( ! $fancy_notification_output ) { + $content .= wpsc_fancy_notifications( true ); + $fancy_notification_output = true; + } + } + return $content; +} + +/** + * empty cart function, used through ajax and in normal page loading. + * No parameters, returns nothing + */ +function wpsc_empty_cart() { + global $wpsc_cart; + $wpsc_cart->empty_cart( false ); + + if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) { + $output = _wpsc_ajax_get_cart( false ); + die( json_encode( $output ) ); + } +} + +/** + * coupons price, used through ajax and in normal page loading. + * No parameters, returns nothing + */ +function wpsc_coupon_price( $currCoupon = '' ) { + global $wpsc_cart, $wpsc_coupons; + if ( isset( $_POST['coupon_num'] ) && $_POST['coupon_num'] != '' ) { + $coupon = esc_sql( $_POST['coupon_num'] ); + wpsc_update_customer_meta( 'coupon', $coupon ); + $wpsc_coupons = new wpsc_coupons( $coupon ); + + if ( $wpsc_coupons->validate_coupon() ) { + $discountAmount = $wpsc_coupons->calculate_discount(); + $wpsc_cart->apply_coupons( $discountAmount, $coupon ); + $wpsc_coupons->errormsg = false; + } else { + $wpsc_coupons->errormsg = true; + $wpsc_cart->coupons_amount = 0; + $wpsc_cart->coupons_name = ''; + wpsc_delete_customer_meta( 'coupon' ); + } + } else if ( (!isset( $_POST['coupon_num'] ) || $_POST['coupon_num'] == '') && $currCoupon == '' ) { + $wpsc_cart->coupons_amount = 0; + $wpsc_cart->coupons_name = ''; + } else if ( $currCoupon != '' ) { + $coupon = esc_sql( $currCoupon ); + wpsc_update_customer_meta( 'coupon', $coupon ); + $wpsc_coupons = new wpsc_coupons( $coupon ); + + if ( $wpsc_coupons->validate_coupon() ) { + $discountAmount = $wpsc_coupons->calculate_discount(); + $wpsc_cart->apply_coupons( $discountAmount, $coupon ); + $wpsc_coupons->errormsg = false; + } + } +} + +/** + * update quantity function, used through ajax and in normal page loading. + * No parameters, returns nothing + */ +function wpsc_update_item_quantity() { + global $wpsc_cart; + + if ( is_numeric( $_POST['key'] ) ) { + $key = (int)$_POST['key']; + if ( $_POST['quantity'] > 0 ) { + // if the quantity is greater than 0, update the item; + $parameters['quantity'] = (int)$_POST['quantity']; + $wpsc_cart->edit_item( $key, $parameters ); + } else { + // if the quantity is 0, remove the item. + $wpsc_cart->remove_item( $key ); + } + $coupon = wpsc_get_customer_meta( 'coupon' ); + if ( $coupon ) { + wpsc_coupon_price( $coupon ); + } + } + $die = ! ( ( isset( $_REQUEST['wpsc_ajax_action'] ) && 'true' == $_REQUEST['wpsc_ajax_action'] ) || ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX ) ); + + _wpsc_ajax_get_cart( $die ); +} + + +function wpsc_update_product_rating() { + global $wpdb; + $nowtime = time(); + $product_id = absint( $_POST['product_id'] ); + $ip_number = $_SERVER['REMOTE_ADDR']; + $rating = absint( $_POST['product_rating'] ); + + $cookie_data = explode( ",", $_COOKIE['voting_cookie'][$product_id] ); + + if ( is_numeric( $cookie_data[0] ) && ($cookie_data[0] > 0) ) { + $vote_id = absint( $cookie_data[0] ); + $wpdb->update( WPSC_TABLE_PRODUCT_RATING, array( + 'rated' => $rating + ), array( 'id' => $vote_id ) ); + } else { + $wpdb->insert( WPSC_TABLE_PRODUCT_RATING, array( + 'ipnum' => $ip_number, + 'productid' => $product_id, + 'rated' => $rating, + 'time' => $nowtime + ) ); + $data = $wpdb->get_results( "SELECT `id`,`rated` FROM `" . WPSC_TABLE_PRODUCT_RATING . "` WHERE `ipnum`='" . $ip_number . "' AND `productid` = '" . $product_id . "' AND `rated` = '" . $rating . "' AND `time` = '" . $nowtime . "' ORDER BY `id` DESC LIMIT 1", ARRAY_A ); + $vote_id = $data[0]['id']; + setcookie( "voting_cookie[$prodid]", ($vote_id . "," . $rating ), time() + (60 * 60 * 24 * 360) ); + } + if ( $_POST['ajax'] == 'true' ) { + + exit(); + } +} + +/** + * update_shipping_price function, used through ajax and in normal page loading. + * No parameters, returns nothing + */ +function wpsc_update_shipping_price() { + global $wpsc_cart; + $quote_shipping_method = $_POST['method']; + $quote_shipping_option = $_POST['option']; + + if(!empty($quote_shipping_option) && !empty($quote_shipping_method)){ + $wpsc_cart->update_shipping( $quote_shipping_method, $quote_shipping_option ); + + echo " + if(jQuery('.pricedisplay.checkout-shipping .pricedisplay')){ + jQuery('.pricedisplay.checkout-shipping > .pricedisplay:first').html(\"" . wpsc_cart_shipping() . "\"); + jQuery('.shoppingcart .pricedisplay.checkout-shipping > .pricedisplay:first').html(\"" . wpsc_cart_shipping() . "\"); + } else { + jQuery('.pricedisplay.checkout-shipping').html(\"" . wpsc_cart_shipping() . "\");}"; + echo " + if (jQuery('#coupons_amount .pricedisplay').size() > 0) { + jQuery('#coupons_amount .pricedisplay').html(\"" . wpsc_coupon_amount() . "\"); + } else { + jQuery('#coupons_amount').html(\"" . wpsc_coupon_amount() . "\"); + } + "; + echo "jQuery('.pricedisplay.checkout-total').html(\"" . wpsc_cart_total() . "\");\n\r"; + } + exit(); +} + +/** + * update_shipping_price function, used through ajax and in normal page loading. + * No parameters, returns nothing + */ +function wpsc_get_rating_count() { + global $wpdb, $wpsc_cart; + $prodid = $_POST['product_id']; + $count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) AS `count` FROM `" . WPSC_TABLE_PRODUCT_RATING . "` WHERE `productid` = %d", $prodid ) ); + echo $count . "," . absint( $prodid ); + exit(); +} + +/** + * update_product_page_price function, used through ajax with variations + * No parameters, returns nothing + */ +function wpsc_update_product_price() { + if ( empty( $_POST['product_id'] ) || ! is_numeric( $_POST['product_id'] ) ) + return; + + $from = ''; + $change_price = true; + $product_id = (int) $_POST['product_id']; + $variations = array(); + $response = array( + 'product_id' => $product_id, + 'variation_found' => false, + ); + if ( ! empty( $_POST['variation'] ) ) { + foreach ( $_POST['variation'] as $variation ) { + if ( is_numeric( $variation ) ) { + $variations[] = (int)$variation; + } + } + + do_action( 'wpsc_update_variation_product', $product_id, $variations ); + + $stock = wpsc_check_variation_stock_availability( $product_id, $variations ); + + if ( $stock !== false ) { + $response['variation_found'] = true; + if ( $stock === 0 ) { + $response += array( + 'product_msg' => __( 'Sorry, but this variation is out of stock.', 'wpsc' ), + 'variation_msg' => __( 'Variation not in stock', 'wpsc' ), + 'stock_available' => false, + ); + } else { + $response += array( + 'variation_msg' => __( 'Product in stock', 'wpsc' ), + 'stock_available' => true, + ); + } + + if ( $change_price ) { + $old_price = wpsc_calculate_price( $product_id, $variations, false ); + $you_save_amount = wpsc_you_save( array( 'product_id' => $product_id, 'type' => 'amount', 'variations' => $variations ) ); + $you_save_percentage = wpsc_you_save( array( 'product_id' => $product_id, 'variations' => $variations ) ); + $price = wpsc_calculate_price( $product_id, $variations, true ); + $response += array( + 'old_price' => wpsc_currency_display( $old_price, array( 'display_as_html' => false ) ), + 'numeric_old_price' => (float) $old_price, + 'you_save' => wpsc_currency_display( $you_save_amount, array( 'display_as_html' => false ) ) . "! (" . $you_save_percentage . "%)", + 'price' => $from . wpsc_currency_display( $price, array( 'display_as_html' => false ) ), + 'numeric_price' => (float) $price, + ); + } + } + } + + echo json_encode( $response ); + exit(); +} + +/** + * update location function, used through ajax and in normal page loading. + * No parameters, returns nothing + */ +function wpsc_update_location() { + global $wpdb, $wpsc_cart; + + $delivery_country = ''; + $billing_country = ''; + if ( ! empty( $_POST['country'] ) ) { + $delivery_country = $_POST['country']; + $billing_country = wpsc_get_customer_meta( 'billing_country' ); + $delivery_region = wpsc_get_customer_meta( 'shipping_region' ); + $billing_region = wpsc_get_customer_meta( 'billing_region' ); + $shipping_zipcode = wpsc_get_customer_meta( 'shipping_zipcode' ); + + if ( ! $billing_country ) + wpsc_update_customer_meta( 'billing_country', $_POST['country'] ); + + if ( ! empty( $_POST['region'] ) ) { + $delivery_region = $_POST['region']; + if ( ! $billing_region ) + $billing_region = $_POST['region']; + } else if ( ! $billing_region ) { + $billing_region = $delivery_region = get_option( 'base_region' ); + } + + if ( ! $delivery_region ) + $delivery_region = $billing_region; + } + + if ( ! empty( $_POST['zipcode'] ) ) + $shipping_zipcode = $_POST['zipcode']; + + $delivery_region_count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(`regions`.`id`) 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')", $delivery_country ) ); + if ( $delivery_region_count < 1 ) + $delivery_region = ''; + + $selected_region_count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(`regions`.`id`) 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')", $billing_country ) ); + if ( $selected_region_count < 1 ) + $billing_region = ''; + + wpsc_update_customer_meta( 'shipping_country' , $delivery_country ); + wpsc_update_customer_meta( 'shipping_region' , $delivery_region ); + wpsc_update_customer_meta( 'billing_country' , $billing_country ); + wpsc_update_customer_meta( 'billing_region' , $billing_region ); + wpsc_update_customer_meta( 'shipping_zip' , $shipping_zipcode ); + + $wpsc_cart->update_location(); + $wpsc_cart->get_shipping_method(); + $wpsc_cart->get_shipping_option(); + if ( $wpsc_cart->selected_shipping_method != '' ) { + $wpsc_cart->update_shipping( $wpsc_cart->selected_shipping_method, $wpsc_cart->selected_shipping_option ); + } + + if ( wpsc_get_customer_meta( 'shipping_same_as_billing' ) && ( $delivery_country != $billing_country || $delivery_region != $billing_region ) ) + wpsc_update_customer_meta( 'shipping_same_as_billing', false ); + + if ( defined( 'DOING_AJAX' ) && DOING_AJAX && isset( $_REQUEST['action'] ) && 'update_location' == $_REQUEST['action'] ) + exit; +} + +function wpsc_cart_html_page() { + require_once(WPSC_FILE_PATH . "/wpsc-includes/shopping_cart_container.php"); + exit(); +} + +/** + * Populate Also Bought List + * Runs on checking out and populates the also bought list. + */ +function wpsc_populate_also_bought_list() { + global $wpdb, $wpsc_cart, $wpsc_coupons; + + $new_also_bought_data = array(); + foreach ( $wpsc_cart->cart_items as $outer_cart_item ) { + $new_also_bought_data[$outer_cart_item->product_id] = array(); + foreach ( $wpsc_cart->cart_items as $inner_cart_item ) { + if ( $outer_cart_item->product_id != $inner_cart_item->product_id ) { + $new_also_bought_data[$outer_cart_item->product_id][$inner_cart_item->product_id] = $inner_cart_item->quantity; + } else { + continue; + } + } + } + + $insert_statement_parts = array(); + foreach ( $new_also_bought_data as $new_also_bought_id => $new_also_bought_row ) { + $new_other_ids = array_keys( $new_also_bought_row ); + $also_bought_data = $wpdb->get_results( $wpdb->prepare( "SELECT `id`, `associated_product`, `quantity` FROM `" . WPSC_TABLE_ALSO_BOUGHT . "` WHERE `selected_product` IN(%d) AND `associated_product` IN('" . implode( "','", $new_other_ids ) . "')", $new_also_bought_id ), ARRAY_A ); + $altered_new_also_bought_row = $new_also_bought_row; + + foreach ( (array)$also_bought_data as $also_bought_row ) { + $quantity = $new_also_bought_row[$also_bought_row['associated_product']] + $also_bought_row['quantity']; + + unset( $altered_new_also_bought_row[$also_bought_row['associated_product']] ); + $wpdb->update( + WPSC_TABLE_ALSO_BOUGHT, + array( + 'quantity' => $quantity + ), + array( + 'id' => $also_bought_row['id'] + ), + '%d', + '%d' + ); + } + + if ( count( $altered_new_also_bought_row ) > 0 ) { + foreach ( $altered_new_also_bought_row as $associated_product => $quantity ) { + $insert_statement_parts[] = "(" . absint( esc_sql( $new_also_bought_id ) ) . "," . absint( esc_sql( $associated_product ) ) . "," . absint( esc_sql( $quantity ) ) . ")"; + } + } + } + + if ( count( $insert_statement_parts ) > 0 ) { + $insert_statement = "INSERT INTO `" . WPSC_TABLE_ALSO_BOUGHT . "` (`selected_product`, `associated_product`, `quantity`) VALUES " . implode( ",\n ", $insert_statement_parts ); + $wpdb->query( $insert_statement ); + } +} + +/** + * submit checkout function, used through ajax and in normal page loading. + * No parameters, returns nothing + */ +function wpsc_submit_checkout( $collected_data = true ) { + global $wpdb, $wpsc_cart, $user_ID, $nzshpcrt_gateways, $wpsc_shipping_modules, $wpsc_gateways; + + $num_items = 0; + $use_shipping = 0; + $disregard_shipping = 0; + + do_action( 'wpsc_before_submit_checkout' ); + + $error_messages = wpsc_get_customer_meta( 'checkout_misc_error_messages' ); + if ( ! is_array( $error_messages ) ) + $error_messages = array(); + $wpsc_checkout = new wpsc_checkout(); + $selected_gateways = get_option( 'custom_gateway_options' ); + $submitted_gateway = isset( $_POST['custom_gateway'] ) ? $_POST['custom_gateway'] : ''; + $options = get_option( 'custom_shipping_options' ); + if ( $collected_data ) { + $form_validity = $wpsc_checkout->validate_forms(); + extract( $form_validity ); // extracts $is_valid and $error_messages + + if ( wpsc_has_tnc() && ( ! isset( $_POST['agree'] ) || $_POST['agree'] != 'yes' ) ) { + $error_messages[] = __( 'Please agree to the terms and conditions, otherwise we cannot process your order.', 'wpsc' ); + $is_valid = false; + } + } else { + $is_valid = true; + $error_messages = array(); + } + + $selectedCountry = $wpdb->get_results( $wpdb->prepare( "SELECT id, country FROM `" . WPSC_TABLE_CURRENCY_LIST . "` WHERE isocode = '%s' ", wpsc_get_customer_meta( 'shipping_country' ) ), ARRAY_A ); + foreach ( $wpsc_cart->cart_items as $cartitem ) { + if( ! empty( $cartitem->meta[0]['no_shipping'] ) ) continue; + $categoriesIDs = $cartitem->category_id_list; + foreach ( (array)$categoriesIDs as $catid ) { + if ( is_array( $catid ) ) + $countries = wpsc_get_meta( $catid[0], 'target_market', 'wpsc_category' ); + else + $countries = wpsc_get_meta( $catid, 'target_market', 'wpsc_category' ); + + if ( !empty($countries) && !in_array( $selectedCountry[0]['id'], (array)$countries ) ) { + $errormessage = sprintf( __( '%s cannot be shipped to %s. To continue with your transaction please remove this product from the list below.', 'wpsc' ), $cartitem->get_title(), $selectedCountry[0]['country'] ); + wpsc_update_customer_meta( 'category_shipping_conflict', $errormessage ); + $is_valid = false; + } + } + //count number of items, and number of items using shipping + $num_items++; + if ( $cartitem->uses_shipping != 1 ) + $disregard_shipping++; + else + $use_shipping++; + + } + if ( array_search( $submitted_gateway, $selected_gateways ) !== false ) + wpsc_update_customer_meta( 'selected_gateway', $submitted_gateway ); + else + $is_valid = false; + + if ( $collected_data ) { + if ( get_option( 'do_not_use_shipping' ) == 0 && ($wpsc_cart->selected_shipping_method == null || $wpsc_cart->selected_shipping_option == null) && ( $num_items != $disregard_shipping ) ) { + $error_messages[] = __( 'You must select a shipping method, otherwise we cannot process your order.', 'wpsc' ); + $is_valid = false; + } + if ( (get_option( 'do_not_use_shipping' ) != 1) && (in_array( 'ups', (array)$options )) && ! wpsc_get_customer_meta( 'shipping_zip' ) && ( $num_items != $disregard_shipping ) ) { + wpsc_update_customer_meta( 'category_shipping_conflict', __( 'Please enter a Zipcode and click calculate to proceed', 'wpsc' ) ); + $is_valid = false; + } + } + + wpsc_update_customer_meta( 'checkout_misc_error_messages', $error_messages ); + + if ( $is_valid == true ) { + wpsc_delete_customer_meta( 'category_shipping_conflict' ); + // check that the submitted gateway is in the list of selected ones + $sessionid = (mt_rand( 100, 999 ) . time()); + wpsc_update_customer_meta( 'checkout_session_id', $sessionid ); + $subtotal = $wpsc_cart->calculate_subtotal(); + if ( $wpsc_cart->has_total_shipping_discount() == false ) + $base_shipping = $wpsc_cart->calculate_base_shipping(); + else + $base_shipping = 0; + + $delivery_country = $wpsc_cart->delivery_country; + $delivery_region = $wpsc_cart->delivery_region; + + if ( wpsc_uses_shipping ( ) ) { + $shipping_method = $wpsc_cart->selected_shipping_method; + $shipping_option = $wpsc_cart->selected_shipping_option; + } else { + $shipping_method = ''; + $shipping_option = ''; + } + if ( isset( $_POST['how_find_us'] ) ) + $find_us = $_POST['how_find_us']; + else + $find_us = ''; + + //keep track of tax if taxes are exclusive + $wpec_taxes_controller = new wpec_taxes_controller(); + if ( !$wpec_taxes_controller->wpec_taxes_isincluded() ) { + $tax = $wpsc_cart->calculate_total_tax(); + $tax_percentage = $wpsc_cart->tax_percentage; + } else { + $tax = 0.00; + $tax_percentage = 0.00; + } + $total = $wpsc_cart->calculate_total_price(); + $args = array( + 'totalprice' => $total, + 'statusno' => '0', + 'sessionid' => $sessionid, + 'user_ID' => (int) $user_ID, + 'date' => time(), + 'gateway' => $submitted_gateway, + 'billing_country' => $wpsc_cart->selected_country, + 'shipping_country' => $delivery_country, + 'billing_region' => $wpsc_cart->selected_region, + 'shipping_region' => $delivery_region, + 'base_shipping' => $base_shipping, + 'shipping_method' => $shipping_method, + 'shipping_option' => $shipping_option, + 'plugin_version' => WPSC_VERSION, + 'discount_value' => $wpsc_cart->coupons_amount, + 'discount_data' => $wpsc_cart->coupons_name, + 'find_us' => $find_us, + 'wpec_taxes_total' => $tax, + 'wpec_taxes_rate' => $tax_percentage, + ); + $purchase_log = new WPSC_Purchase_Log( $args ); + $purchase_log->save(); + $purchase_log_id = $purchase_log->get( 'id' ); + if ( $collected_data ) + $wpsc_checkout->save_forms_to_db( $purchase_log_id ); + $wpsc_cart->save_to_db( $purchase_log_id ); + $wpsc_cart->submit_stock_claims( $purchase_log_id ); + if( !isset( $our_user_id ) && isset( $user_ID )) + $our_user_id = $user_ID; + $wpsc_cart->log_id = $purchase_log_id; + do_action( 'wpsc_submit_checkout', array( "purchase_log_id" => $purchase_log_id, "our_user_id" => $our_user_id ) ); + do_action( 'wpsc_submit_checkout_gateway', $submitted_gateway, $purchase_log ); + } +} + +function wpsc_show_terms_and_conditions() { + echo wpautop( wp_kses_post( get_option( 'terms_and_conditions' ) ) ); + die(); +} + +/** + * wpsc_change_tax function, used through ajax and in normal page loading. + * No parameters, returns nothing + */ +function wpsc_change_tax() { + global $wpdb, $wpsc_cart; + + $form_id = absint( $_POST['form_id'] ); + + $wpsc_selected_country = $wpsc_cart->selected_country; + $wpsc_selected_region = $wpsc_cart->selected_region; + + $wpsc_delivery_country = $wpsc_cart->delivery_country; + $wpsc_delivery_region = $wpsc_cart->delivery_region; + + + $previous_country = wpsc_get_customer_meta( 'billing_country' ); + if ( isset( $_POST['billing_country'] ) ) { + $wpsc_selected_country = $_POST['billing_country']; + wpsc_update_customer_meta( 'billing_country', $wpsc_selected_country ); + } + + if ( isset( $_POST['billing_region'] ) ) { + $wpsc_selected_region = absint( $_POST['billing_region'] ); + wpsc_update_customer_meta( 'billing_region', $wpsc_selected_region ); + } + + $check_country_code = $wpdb->get_var( $wpdb->prepare( "SELECT `country`.`isocode` FROM `" . WPSC_TABLE_REGION_TAX . "` AS `region` INNER JOIN `" . WPSC_TABLE_CURRENCY_LIST . "` AS `country` ON `region`.`country_id` = `country`.`id` WHERE `region`.`id` = %d LIMIT 1", wpsc_get_customer_meta( 'billing_region' ) ) ); + + if ( wpsc_get_customer_meta( 'billing_country' ) != $check_country_code ) { + $wpsc_selected_region = null; + } + + if ( isset( $_POST['shipping_country'] ) ) { + $wpsc_delivery_country = $_POST['shipping_country']; + wpsc_update_customer_meta( 'shipping_country', $wpsc_delivery_country ); + } + if ( isset( $_POST['shipping_region'] ) ) { + $wpsc_delivery_region = absint( $_POST['shipping_region'] ); + wpsc_update_customer_meta( 'shipping_region', $wpsc_delivery_region ); + } + + $check_country_code = $wpdb->get_var( $wpdb->prepare( "SELECT `country`.`isocode` FROM `" . WPSC_TABLE_REGION_TAX . "` AS `region` INNER JOIN `" . WPSC_TABLE_CURRENCY_LIST . "` AS `country` ON `region`.`country_id` = `country`.`id` WHERE `region`.`id` = %d LIMIT 1", $wpsc_delivery_region ) ); + + if ( $wpsc_delivery_country != $check_country_code ) { + $wpsc_delivery_region = null; + } + + + $wpsc_cart->update_location(); + $wpsc_cart->get_shipping_method(); + $wpsc_cart->get_shipping_option(); + if ( $wpsc_cart->selected_shipping_method != '' ) { + $wpsc_cart->update_shipping( $wpsc_cart->selected_shipping_method, $wpsc_cart->selected_shipping_option ); + } + + $tax = $wpsc_cart->calculate_total_tax(); + $total = wpsc_cart_total(); + $total_input = wpsc_cart_total(false); + if($wpsc_cart->coupons_amount >= wpsc_cart_total(false) && !empty($wpsc_cart->coupons_amount)){ + $total = 0; + } + if ( $wpsc_cart->total_price < 0 ) { + $wpsc_cart->coupons_amount += $wpsc_cart->total_price; + $wpsc_cart->total_price = null; + $wpsc_cart->calculate_total_price(); + } + ob_start(); + + include_once( wpsc_get_template_file_path( 'wpsc-cart_widget.php' ) ); + $output = ob_get_contents(); + + ob_end_clean(); + $delivery_country = wpsc_get_customer_meta( 'shipping_country' ); + $output = str_replace( Array( "\n", "\r" ), Array( "\\n", "\\r" ), addslashes( $output ) ); + if ( get_option( 'lock_tax' ) == 1 ) { + echo "jQuery('#current_country').val('" . esc_js( $delivery_country ) . "'); \n"; + if ( $delivery_country == 'US' && get_option( 'lock_tax' ) == 1 ) { + $output = wpsc_shipping_region_list( $delivery_country, wpsc_get_customer_meta( 'shipping_region' ) ); + $output = str_replace( Array( "\n", "\r" ), Array( "\\n", "\\r" ), addslashes( $output ) ); + echo "jQuery('#region').remove();\n\r"; + echo "jQuery('#change_country').append(\"" . $output . "\");\n\r"; + } + } + + + foreach ( $wpsc_cart->cart_items as $key => $cart_item ) { + echo "jQuery('#shipping_$key').html(\"" . wpsc_currency_display( $cart_item->shipping ) . "\");\n\r"; + } + + echo "jQuery('#checkout_shipping').html(\"" . wpsc_cart_shipping() . "\");\n\r"; + + echo "jQuery('div.shopping-cart-wrapper').html('$output');\n"; + if ( get_option( 'lock_tax' ) == 1 ) { + echo "jQuery('.shipping_country').val('" . esc_js( $delivery_country ) . "') \n"; + $sql = $wpdb->prepare( "SELECT `country` FROM `" . WPSC_TABLE_CURRENCY_LIST . "` WHERE `isocode`= '%s'", $delivery_country ); + $country_name = $wpdb->get_var( $sql ); + echo "jQuery('.shipping_country_name').html('" . $country_name . "') \n"; + } + + + $form_selected_country = null; + $form_selected_region = null; + $onchange_function = null; + + if ( ! empty( $_POST['billing_country'] ) && $_POST['billing_country'] != 'undefined' && !isset( $_POST['shipping_country'] ) ) { + $form_selected_country = $wpsc_selected_country; + $form_selected_region = $wpsc_selected_region; + $onchange_function = 'set_billing_country'; + } else if ( ! empty( $_POST['shipping_country'] ) && $_POST['shipping_country'] != 'undefined' && !isset( $_POST['billing_country'] ) ) { + $form_selected_country = $wpsc_delivery_country; + $form_selected_region = $wpsc_delivery_region; + $onchange_function = 'set_shipping_country'; + } + + if ( ($form_selected_country != null) && ($onchange_function != null) ) { + $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`", $form_selected_country ), ARRAY_A ); + if ( $region_list != null ) { + $title = (empty($_POST['billing_country']))?'shippingstate':'billingstate'; + $output = "\n\r"; + + $output = str_replace( Array( "\n", "\r" ), Array( "\\n", "\\r" ), addslashes( $output ) ); + echo "jQuery('#region_select_$form_id').html(\"" . $output . "\");\n\r"; + echo " + var wpsc_checkout_table_selector = jQuery('#region_select_$form_id').parents('.wpsc_checkout_table').attr('class'); + wpsc_checkout_table_selector = wpsc_checkout_table_selector.replace(' ','.'); + wpsc_checkout_table_selector = '.'+wpsc_checkout_table_selector; + jQuery(wpsc_checkout_table_selector + ' input.billing_region').attr('disabled', 'disabled'); + jQuery(wpsc_checkout_table_selector + ' input.shipping_region').attr('disabled', 'disabled'); + jQuery(wpsc_checkout_table_selector + ' .billing_region').parent().parent().hide(); + jQuery(wpsc_checkout_table_selector + ' .shipping_region').parent().parent().hide(); + "; + } else { + if ( get_option( 'lock_tax' ) == 1 ) { + echo "jQuery('#region').hide();"; + } + echo "jQuery('#region_select_$form_id').html('');\n\r"; + echo " + var wpsc_checkout_table_selector = jQuery('#region_select_$form_id').parents('.wpsc_checkout_table').attr('class'); + wpsc_checkout_table_selector = wpsc_checkout_table_selector.replace(' ','.'); + wpsc_checkout_table_selector = '.'+wpsc_checkout_table_selector; + jQuery(wpsc_checkout_table_selector + ' input.billing_region').removeAttr('disabled'); + jQuery(wpsc_checkout_table_selector + ' input.shipping_region').removeAttr('disabled'); + jQuery(wpsc_checkout_table_selector + ' .billing_region').parent().parent().show(); + jQuery(wpsc_checkout_table_selector + ' .shipping_region').parent().parent().show(); + "; + } + } + + if ( $tax > 0 ) { + echo "jQuery(\"tr.total_tax\").show();\n\r"; + } else { + echo "jQuery(\"tr.total_tax\").hide();\n\r"; + } + echo "jQuery('#checkout_tax').html(\"" . wpsc_cart_tax() . "\");\n\r"; + echo "jQuery('#checkout_total').html(\"{$total}\");\n\r"; + exit(); +} + +function _wpsc_change_profile_country() { + global $wpdb; + + $country_field_id = absint( $_REQUEST['form_id'] ); + $country = $_REQUEST['country']; + + $sql = $wpdb->prepare( 'SELECT unique_name FROM `'.WPSC_TABLE_CHECKOUT_FORMS.'` WHERE `id`= %d', $country_field_id ); + $country_field_unique_name = $wpdb->get_var( $sql ); + + $has_regions = wpsc_has_regions( $country ); + $response = array( 'has_regions' => $has_regions ); + + $region_unique_name = 'shippingstate'; + if ( $country_field_unique_name == 'billingcountry' ) + $region_unique_name = 'billingstate'; + + $sql = $wpdb->prepare( 'SELECT id FROM ' . WPSC_TABLE_CHECKOUT_FORMS . ' WHERE unique_name=%s AND active="1"', $region_unique_name ); + $response['region_field_id'] = $wpdb->get_var( $sql ); + + if ( $has_regions ) + $response['html'] = ""; + + echo json_encode( $response ); + exit; +} + +function wpsc_shipping_same_as_billing(){ + wpsc_update_customer_meta( 'shipping_same_as_billing', $_POST['wpsc_shipping_same_as_billing'] ); +} + +function wpsc_update_shipping_quotes_on_shipping_same_as_billing() { + global $wpsc_cart; + + wpsc_update_location(); + + if ( get_option( 'do_not_use_shipping' ) ) + die( '-1' ); + + if ( ! wpsc_have_shipping_quote() ) { + die( '0' ); + } + else { + ?> + + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + + + + + + + + + + + + + + + + onclick='switchmethod("", "")' value='' name='shipping_method' /> + + disabled='disabled' type='radio' id='' value='' name='shipping_method' /> + + + + + + + + + + + '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( "/(

)*\[shoppingcart\](<\/p>)*/", $output, $content ); + } else { + return $content; + } +} + +function wpsc_transaction_results( $content = '' ) { + if ( ! in_the_loop() ) + return $content; + + if ( preg_match( "/\[transactionresults\]/", $content ) ) { + define( 'DONOTCACHEPAGE', true ); + ob_start(); + include( wpsc_get_template_file_path( 'wpsc-transaction_results.php' ) ); + $output = ob_get_contents(); + ob_end_clean(); + $output = preg_replace( '#(?)*\[transactionresults\](<\/p>)*/", $output, $content ); + } else { + return $content; + } +} + +function wpsc_user_log( $content = '' ) { + if ( ! in_the_loop() ) + return $content; + if ( preg_match( "/\[userlog\]/", $content ) ) { + define( 'DONOTCACHEPAGE', true ); + + ob_start(); + + include( wpsc_get_template_file_path('wpsc-user-log.php') ); + $output = ob_get_clean(); + $content = preg_replace( "/(

)*\[userlog\](<\/p>)*/", '[userlog]', $content ); + return str_replace( '[userlog]', $output, $content ); + } else { + return $content; + } +} + +function wpsc_get_the_post_id_by_shortcode( $shortcode ) { + + $shortcode_options = array( + '[productspage]' => 'product_list_url', + '[shoppingcart]' => 'shopping_cart_url', + '[checkout]' => 'shopping_cart_url', + '[transactionresults]' => 'transact_url', + '[userlog]' => 'user_account_url' + ); + + if ( ! isset( $shortcode_options[$shortcode] ) ) + return 0; + + $page_ids = get_option( 'wpsc_shortcode_page_ids', false ); + + if ( $page_ids === false ) { + wpsc_update_permalink_slugs(); + $page_ids = get_option( 'wpsc_shortcode_page_ids', false ); + } + + $post_id = isset( $page_ids[$shortcode] ) ? $page_ids[$shortcode] : null; + + // For back compat + $post_id = apply_filters( 'wpec_get_the_post_id_by_shortcode', $post_id ); + + return apply_filters( 'wpsc_get_the_post_id_by_shortcode', $post_id, $shortcode ); + +} + +function wpec_remap_shop_subpages( $vars ) { + if( empty( $vars ) ) + return $vars; + $reserved_names = array('[shoppingcart]','[userlog]','[transactionresults]'); + foreach($reserved_names as $reserved_name){ + if ( isset( $vars['taxonomy'] ) && $vars['taxonomy'] == 'wpsc_product_category' && $isset( $vars['term'] ) && $vars['term'] == $page->post_name ) { + $page_id = wpsc_get_the_post_id_by_shortcode( $reserved_name ); + $page = get_post( $page_id ); + return array( 'page_id' => $page->ID ); + } + } + return $vars; +} + +function wpsc_remove_page_from_query_string($query_string) +{ + + if ( isset($query_string['name']) && $query_string['name'] == 'page' && isset($query_string['page']) ) { + unset($query_string['name']); + list($delim, $page_index) = explode( '/', $query_string['page'] ); + + $query_string['paged'] = $page_index; + } + + if ( isset($query_string['wpsc-product']) && 'page' == $query_string['wpsc-product'] ) + $query_string['wpsc-product'] = ''; + + if ( isset($query_string['name']) && is_numeric($query_string['name']) ) { + $query_string['paged'] = $query_string['name']; + $query_string['page'] = '/'.$query_string['name']; + + $query_string['posts_per_page'] = get_option('wpsc_products_per_page'); + } + if ( isset($query_string['wpsc-product']) && is_numeric($query_string['wpsc-product']) ) + unset( $query_string['wpsc-product'] ); + + if ( isset($query_string['wpsc_product_category']) && 'page' == $query_string['wpsc_product_category'] ) + unset( $query_string['wpsc_product_category'] ); + if ( isset($query_string['name']) && is_numeric($query_string['name']) ) + unset( $query_string['name'] ); + if ( isset($query_string['term']) && 'page' == $query_string['term'] ) { + unset( $query_string['term'] ); + unset( $query_string['taxonomy'] ); + } + return $query_string; +} + +function is_products_page(){ + global $post; + + $product_page_id = wpsc_get_the_post_id_by_shortcode( '[productspage]' ); + + return $post->ID == $product_page_id; + +} + +/** + * wpsc_display_products_page function. + * + * @access public + * @param mixed $query + * @return void + */ +function wpsc_display_featured_products_page() { + global $wp_query; + $sticky_array = get_option( 'sticky_products' ); + if ( (is_front_page() || is_home() || is_products_page() ) && !empty( $sticky_array ) && $wp_query->post_count > 1) { + $query = get_posts( array( + 'post__in' => $sticky_array, + 'post_type' => 'wpsc-product', + 'orderby' => 'rand', + 'numberposts' => 1, + 'posts_per_page' => 1 + ) ); + + if ( count( $query ) > 0 ) { + + $GLOBALS['nzshpcrt_activateshpcrt'] = true; + $image_width = get_option( 'product_image_width' ); + $image_height = get_option( 'product_image_height' ); + $featured_product_theme_path = wpsc_get_template_file_path( 'wpsc-featured_product.php' ); + ob_start(); + include_once($featured_product_theme_path); + $is_single = false; + $output .= ob_get_contents(); + ob_end_clean(); + + //Begin outputting featured product. We can worry about templating later, or folks can just CSS it up. + echo $output; + //End output + } + } +} + +function wpsc_hidesubcatprods_init() { + $hide_subcatsprods = new WPSC_Hide_subcatsprods_in_cat; + add_action( 'pre_get_posts', array( &$hide_subcatsprods, 'get_posts' ) ); +} + +function wpsc_the_featured_image_fix($stuff){ + global $wp_query; + remove_action('post_thumbnail_html','wpsc_the_featured_image_fix'); + if(isset($wp_query->query_vars['wpsc-product'])){ + $stuff =''; ?> + is_static_front_page() ) { + $aiosp_home_title = $aiosp->internationalize( $aioseop_options['aiosp_home_title'] ); + $new_title = wpsc_obtain_the_title(); + if ( $new_title != '' ) { + $title = str_replace( $aiosp_home_title, $new_title, $title ); + } + } + return $title; + } + + add_filter( 'aioseop_home_page_title', 'wpsc_change_aioseop_home_title' ); +} + +/** + * wpsc_obtain_the_title function, for replaacing the page title with the category or product + * @return string - the new page title + */ +function wpsc_obtain_the_title() { + global $wpdb, $wp_query, $wpsc_title_data; + $output = null; + $category_id = null; + if( !isset( $wp_query->query_vars['wpsc_product_category']) && !isset( $wp_query->query_vars['wpsc-product'])) + return; + + if ( !isset( $wp_query->query_vars['wpsc_product_category'] ) && isset($wp_query->query_vars['wpsc-product']) ) + $wp_query->query_vars['wpsc_product_category'] = 0; + + + if ( isset( $wp_query->query_vars['taxonomy'] ) && 'wpsc_product_category' == $wp_query->query_vars['taxonomy'] || isset($wp_query->query_vars['wpsc_product_category'])) + $category_id = wpsc_get_the_category_id($wp_query->query_vars['wpsc_product_category'],'slug'); + + if ( $category_id > 0 ) { + + if ( isset( $wpsc_title_data['category'][$category_id] ) ) { + $output = $wpsc_title_data['category'][$category_id]; + } else { + $term = get_term($category_id, 'wpsc_product_category'); + $output = $term->name; + $wpsc_title_data['category'][$category_id] = $output; + } + } + + if ( !isset( $_GET['wpsc-product'] ) ) + $_GET['wpsc-product'] = 0; + + if ( !isset( $wp_query->query_vars['wpsc-product'] ) ) + $wp_query->query_vars['wpsc-product'] = ''; + + if ( isset( $wp_query->query_vars['wpsc-product'] ) || is_string( $_GET['wpsc-product'] ) ) { + $product_name = $wp_query->query_vars['wpsc-product']; + if ( isset( $wpsc_title_data['product'][$product_name] ) ) { + $product_list = array( ); + $full_product_name = $wpsc_title_data['product'][$product_name]; + } else if ( $product_name != '' ) { + $product_id = $wp_query->post->ID; + $full_product_name = $wpdb->get_var( $wpdb->prepare( "SELECT `post_title` FROM `$wpdb->posts` WHERE `ID`= %d LIMIT 1", $product_id ) ); + $wpsc_title_data['product'][$product_name] = $full_product_name; + } else { + if(isset($_REQUEST['product_id'])){ + $product_id = absint( $_REQUEST['product_id'] ); + $product_name = $wpdb->get_var( $wpdb->prepare( "SELECT `post_title` FROM `$wpdb->posts` WHERE `ID`= %d LIMIT 1", $product_id ) ); + $full_product_name = $wpdb->get_var( $wpdb->prepare( "SELECT `post_title` FROM `$wpdb->posts` WHERE `ID`= %d LIMIT 1", $product_id ) ); + $wpsc_title_data['product'][$product_name] = $full_product_name; + }else{ + //This has to exist, otherwise we would have bailed earlier. + $category = $wp_query->query_vars['wpsc_product_category']; + $cat_term = get_term_by('slug',$wp_query->query_vars['wpsc_product_category'], 'wpsc_product_category'); + $full_product_name = $cat_term->name; + } + } + $output = $full_product_name; + } + + if ( isset( $full_product_name ) && ($full_product_name != null) ) + $output = esc_html( $full_product_name ); + $seperator = ' | '; + $seperator = apply_filters('wpsc_the_wp_title_seperator' , $seperator); + return $output.$seperator; +} + +/** + * Return category or product description depending on queried item + */ +function wpsc_obtain_the_description() { + + $output = null; + + // Return Category Description + if ( is_numeric( get_query_var('category_id') ) ) { + $output = wpsc_get_categorymeta( get_query_var('category_id'), 'description' ); + } else if ( ! empty($_GET['category']) ) { + $output = wpsc_get_categorymeta( absint( $_GET['category'] ), 'description' ); + } + + // Return product content as description if product page + if ( !empty($_GET['product_id'] ) && is_numeric( $_GET['product_id'] ) ) { + $product = get_post(absint( $_GET['product_id'] )); + $output = $product->post_content; + } + + return $output; +} + +function wpsc_set_aioseop_description( $data ) { + $replacement_data = wpsc_obtain_the_description(); + if ( $replacement_data != '' ) { + $data = $replacement_data; + } + return $data; +} + +/** + * this page url function, returns the URL of this page + * @return string - the URL of the current page + */ +function wpsc_this_page_url() { + global $wpsc_query, $wp_query; + if ( $wpsc_query->is_single === true ) { + $output = get_permalink( $wp_query->post->ID ); + } else if ( isset( $wpsc_query->category ) && $wpsc_query->category != null ) { + $output = wpsc_category_url( $wpsc_query->category ); + if ( $wpsc_query->query_vars['page'] > 1 ) { + if ( get_option( 'permalink_structure' ) ) { + $output .= "page/{$wpsc_query->query_vars['page']}/"; + } else { + $output = add_query_arg( 'page_number', $wpsc_query->query_vars['page'], $output ); + } + } + } elseif ( isset( $id ) ) { + $output = get_permalink( $id ); + } else { + $output = get_permalink( get_the_ID() ); + } + return $output; +} + diff --git a/wpsc-components/theme-engine-v1/helpers/product.php b/wpsc-components/theme-engine-v1/helpers/product.php new file mode 100644 index 0000000000..3df8e16bb2 --- /dev/null +++ b/wpsc-components/theme-engine-v1/helpers/product.php @@ -0,0 +1,868 @@ +ID; + } else { + // In wordpress 3.0 we get a post ID + $post_id = $post; + $post = get_post( $post_id ); + } + + // Only applies to WPSC products, don't stop on permalinks of other CPTs + // Fixes http://code.google.com/p/wp-e-commerce/issues/detail?id=271 + if ($post->post_type != 'wpsc-product') + return $permalink; + + $permalink_structure = get_option( 'permalink_structure' ); + + // This may become customiseable later + $our_permalink_structure = str_replace( basename( home_url() ), '', $wpsc_page_titles['products'] ) . "/%wpsc_product_category%/%postname%/"; + // Mostly the same conditions used for posts, but restricted to items with a post type of "wpsc-product " + + if ( '' != $permalink_structure && !in_array( $post->post_status, array( 'draft', 'pending' ) ) ) { + $product_categories = wpsc_get_product_terms( $post_id, 'wpsc_product_category' ); + $product_category_slugs = array( ); + foreach ( $product_categories as $product_category ) { + $product_category_slugs[] = $product_category->slug; + } + // If the product is associated with multiple categories, determine which one to pick + if ( count( $product_categories ) == 0 ) { + $category_slug = 'uncategorized'; + } elseif ( count( $product_categories ) > 1 ) { + if ( (isset( $wp_query->query_vars['products'] ) && $wp_query->query_vars['products'] != null) && in_array( $wp_query->query_vars['products'], $product_category_slugs ) ) { + $product_category = $wp_query->query_vars['products']; + } else { + $link = $product_categories[0]->slug; + if ( ! in_array( 'wp_head', $wp_current_filter) && isset( $wpsc_query->query_vars['wpsc_product_category'] ) ) { + $current_cat = $wpsc_query->query_vars['wpsc_product_category']; + if ( in_array( $current_cat, $product_category_slugs ) ) + $link = $current_cat; + } + + $product_category = $link; + } + $category_slug = $product_category; + } else { + // If the product is associated with only one category, we only have one choice + if ( !isset( $product_categories[0] ) ) + $product_categories[0] = ''; + + $product_category = $product_categories[0]; + + if ( !is_object( $product_category ) ) + $product_category = new stdClass(); + + if ( !isset( $product_category->slug ) ) + $product_category->slug = null; + + $category_slug = $product_category->slug; + } + + $post_name = $post->post_name; + + if ( get_option( 'product_category_hierarchical_url', 0 ) ) { + $selected_term = get_term_by( 'slug', $category_slug, 'wpsc_product_category' ); + if ( is_object( $selected_term ) ) { + $term_chain = array( $selected_term->slug ); + while ( $selected_term->parent ) { + $selected_term = get_term( $selected_term->parent, 'wpsc_product_category' ); + array_unshift( $term_chain, $selected_term->slug ); + } + $category_slug = implode( '/', $term_chain ); + } + } + + if( isset( $category_slug ) && empty( $category_slug ) ) + $category_slug = 'product'; + + $category_slug = apply_filters( 'wpsc_product_permalink_cat_slug', $category_slug, $post_id ); + + $rewritereplace = array( + $category_slug, + $post_name + ); + + $permalink = str_replace( $rewritecode, $rewritereplace, $our_permalink_structure ); + $permalink = user_trailingslashit( $permalink, 'single' ); + + $permalink = home_url( $permalink ); + } + return apply_filters( 'wpsc_product_permalink', $permalink, $post->ID ); +} + +/** + * wpsc_list_categories function. + * + * @access public + * @param string $callback_function - The function name you want to use for displaying the data + * @param mixed $parameters (default: null) - the additional parameters to the callback function + * @param int $category_id. (default: 0) - The category id defaults to zero, for displaying all categories + * @param int $level. (default: 0) + */ +function wpsc_list_categories($callback_function, $parameters = null, $category_id = 0, $level = 0) { + global $wpdb,$category_data; + $output = ''; + $category_list = get_terms('wpsc_product_category','hide_empty=0&parent='.$category_id); + if($category_list != null) { + foreach((array)$category_list as $category) { + $callback_output = $callback_function($category, $level, $parameters); + if(is_array($callback_output)) { + $output .= array_shift($callback_output); + } else { + $output .= $callback_output; + } + $output .= wpsc_list_categories($callback_function, $parameters , $category->term_id, ($level+1)); + if(is_array($callback_output) && (isset($callback_output[1]))) { + $output .= $callback_output[1]; + } + } + } + return $output; +} + +/** +* Gets the Function Parent Image link and checks whether Image should be displayed or not +* +*/ +function wpsc_parent_category_image($show_thumbnails , $category_image , $width, $height, $grid=false, $show_name){ + + if(!$show_thumbnails) return; + + if($category_image == WPSC_CATEGORY_URL){ + if(!$show_name) return; + ?> + + + + + + $start_element, 'end_element' => $end_element); + echo "[wpsc_category_description]"; +} + +/** +* wpsc print category url function +* places the shortcode for the category URL +*/ +function wpsc_print_category_url() { + echo "[wpsc_category_url]"; +} + +/** +* wpsc print category id function +* places the shortcode for the category URL +*/ +function wpsc_print_category_id() { + echo "[wpsc_category_id]"; +} + +/** +* wpsc print category classes function +* places classes for the category including selected state +* +* please note that "current category" means the category that we are in now, +* and not the category that we are printing for +* +* @param $category_to_print - the category for which we should print classes +* @param $echo - whether to echo the result (true) or return (false) +*/ +function wpsc_print_category_classes($category_to_print = false, $echo = true) { + global $wp_query, $wpdb; + + //if we are in wpsc category page then get the current category + $curr_cat = false; + $term = get_query_var( 'wpsc_product_category' ); + if ( ! $term && get_query_var( 'taxonomy' ) == 'wpsc_product_category' ) + $term = get_query_var( 'term' ); + if ( $term ) + $curr_cat = get_term_by( 'slug', $term, 'wpsc_product_category' ); + + //check if we are in wpsc category page and that we have a term_id of the category to print + //this is done here because none of the following matters if we don't have one of those and we can + //safely return + if(isset($category_to_print['term_id']) && $curr_cat){ + + //we will need a list of current category parents for the following if statement + $curr_cat_parents = wpsc_get_term_parents($curr_cat->term_id, 'wpsc_product_category'); + + //if current category is the same as the one we are printing - then add wpsc-current-cat class + if( $category_to_print['term_id'] == $curr_cat->term_id ) + $result = ' wpsc-current-cat '; + //else check if the category that we are printing is parent of current category + elseif ( in_array($category_to_print['term_id'], $curr_cat_parents) ) + $result = ' wpsc-cat-ancestor '; + } + if( isset($result) ) + if($echo) + echo $result; + else + return $result; +} + +/** +* wpsc print subcategory function +* places the shortcode for the subcategories, accepts parameters for the subcategories container, have this as

if using a list +* @param string starting HTML element +* @param string ending HTML element +*/ +function wpsc_print_subcategory($start_element = '', $end_element = '') { + global $wpsc_category_query; + $wpsc_category_query['subcategory_container'] = array('start_element' => $start_element, 'end_element' => $end_element); + echo "[wpsc_subcategory]"; +} +function wpsc_print_category_classes_section(){ + echo "[wpsc_category_classes]"; +} + +/** +* wpsc print category image function +* places the shortcode for the category image, accepts parameters for width and height +* @param integer width +* @param integer height +*/ +function wpsc_print_category_image($width = null, $height = null) { + global $wpsc_category_query; + $wpsc_category_query['image_size'] = array('width' => $width, 'height' => $height); + echo "[wpsc_category_image]"; +} + +/** +* wpsc print category products count function +* places the shortcode for the category product count, accepts parameters for the container element +* @param string starting HTML element +* @param string ending HTML element +*/ +function wpsc_print_category_products_count($start_element = '', $end_element = '') { + global $wpsc_category_query; + $wpsc_category_query['products_count'] = array('start_element' => $start_element, 'end_element' => $end_element); + echo "[wpsc_category_products_count]"; +} + +/** +* wpsc end category query function +*/ +function wpsc_end_category_query() { + global $wpdb, $wpsc_category_query; + $category_html = ob_get_clean(); + echo wpsc_display_category_loop($wpsc_category_query, $category_html); + unset($GLOBALS['wpsc_category_query']); +} + +/** +* wpsc category loop function +* This function recursively loops through the categories to display the category tree. +* This function also generates a tree of categories at the same time +* WARNING: as this function is recursive, be careful what you do with it. +* @param array the category query +* @param string the category html +* @param array the category array branch, is an internal value, leave it alone. +* @return string - the finished category html +*/ +function wpsc_display_category_loop($query, $category_html, &$category_branch = null){ + static $category_count_data = array(); // the array tree is stored in this + + if( isset($query['parent_category_id']) ) + $category_id = absint($query['parent_category_id']); + else + $category_id = 0; + $category_data = get_terms('wpsc_product_category','hide_empty=0&parent='.$category_id, OBJECT, 'display'); + $output =''; + + // if the category branch is identical to null, make it a reference to $category_count_data + if($category_branch === null) { + $category_branch =& $category_count_data; + } + $allowed_tags = array('a' => array('href' => array(),'title' => array()),'abbr' => array('title' => array()),'acronym' => array('title' => array()),'code' => array(),'em' => array(),'strong' => array(), 'b'=> array()); + + $allowedtags = apply_filters('wpsc_category_description_allowed_tags' , $allowed_tags); + + foreach((array)$category_data as $category_row) { + + // modifys the query for the next round + $modified_query = $query; + $modified_query['parent_category_id'] = $category_row->term_id; + + // gets the count of products associated with this category + $category_count = $category_row->count; + + + // Sticks the category description in + $category_description = ''; + if($category_row->description != '' && ! empty( $query['description_container'] ) ) { + $start_element = $query['description_container']['start_element']; + $end_element = $query['description_container']['end_element']; + $category_description = $start_element.wpautop(wptexturize( wp_kses( $category_row->description, $allowedtags ))).$end_element; + } + + + // Creates the list of classes on the category item + $category_classes = wpsc_print_category_classes((array)$category_row, false); + + // Set the variables for this category + $category_branch[$category_row->term_id]['children'] = array(); + $category_branch[$category_row->term_id]['count'] = (int)$category_count; + + + // Recurse into the next level of categories + $sub_categories = wpsc_display_category_loop($modified_query, $category_html, $category_branch[$category_row->term_id]['children']); + + // grab the product count from the subcategories + foreach((array)$category_branch[$category_row->term_id]['children'] as $child_category) { + $category_branch[$category_row->term_id]['count'] += (int)$child_category['count']; + } + + // stick the category count array together here + // this must run after the subcategories and the count of products belonging to them has been obtained + + $category_count = $category_branch[$category_row->term_id]['count']; + + $start_element = ''; + $end_element = ''; + + if (isset($query['products_count']['start_element'])) { + $start_element = $query['products_count']['start_element']; + } + + if (isset($query['products_count']['end_element'])) { + $end_element = $query['products_count']['end_element']; + } + + $category_count_html = $start_element.$category_count.$end_element; + + + if ( isset( $query['subcategory_container'] ) && ! empty( $sub_categories ) ) { + $start_element = $query['subcategory_container']['start_element']; + $end_element = $query['subcategory_container']['end_element']; + $sub_categories = $start_element.$sub_categories.$end_element; + } + + // get the category images + $category_image = wpsc_place_category_image($category_row->term_id, $modified_query); + + if ( empty( $query['image_size']['width'] ) ) { + if ( ! wpsc_category_grid_view() ) + $width = wpsc_get_categorymeta( $category_row->term_id, 'image_width' ); + if ( empty( $width ) ) + $width = get_option( 'category_image_width' ); + } else { + $width = $query['image_size']['width']; + } + + if ( empty( $query['image_size']['height'] ) ) { + if ( ! wpsc_category_grid_view() ) + $height = wpsc_get_categorymeta( $category_row->term_id, 'image_height' ); + if ( empty( $height ) ) + $height = get_option( 'category_image_height' ); + } else { + $height = $query['image_size']['height']; + } + + $category_image = wpsc_get_categorymeta($category_row->term_id, 'image'); + $category_image_html = ''; + if(($query['show_thumbnails'] == 1)) { + if((!empty($category_image)) && is_file(WPSC_CATEGORY_DIR.$category_image)) { + $category_image_html = "{$category_row->name}"; + } elseif( isset( $query['show_name'] ) && 1 == $query['show_name']) { + $category_image_html .= "\n\r"; + $category_image_html .= " \n\r"; + $category_image_html .= " ".__('N/A','wpsc')."\n\r"; + $category_image_html .= " \n\r"; + $category_image_html .= "\n\r"; + } + + } + + + // get the list of products associated with this category. + $tags_to_replace = array('[wpsc_category_name]', + '[wpsc_category_description]', + '[wpsc_category_url]', + '[wpsc_category_id]', + '[wpsc_category_classes]', + '[wpsc_category_image]', + '[wpsc_subcategory]', + '[wpsc_category_products_count]'); + + $content_to_place = array( + esc_html($category_row->name), + $category_description, + esc_url( get_term_link( $category_row->slug, 'wpsc_product_category' ) ), + $category_row->term_id, + $category_classes, + $category_image_html, + $sub_categories, + $category_count_html); + + // Stick all the category html together and concatenate it to the previously generated HTML + $output .= str_replace($tags_to_replace, $content_to_place ,$category_html); + } + return $output; +} + +/** +* wpsc category image function +* if no parameters are passed, the category is not resized, otherwise it is resized to the specified dimensions +* @param integer category id +* @param array category query array +* @return string - the category image URL, or the URL of the resized version +*/ +function wpsc_place_category_image($category_id, $query) { + // show the full sized image for the product, if supplied with dimensions, will resize image to those. + $width = (isset($query['image_size']['width'])) ? ($query['image_size']['width']) : get_option('category_image_width'); + $height = (isset($query['image_size']['height'])) ? ($query['image_size']['height']) : get_option('category_image_height'); + $image_url = "index.php?wpsc_request_image=true&category_id=".$category_id."&width=".$width."&height=".$height; + return htmlspecialchars($image_url); +} + +/// category template tags end here + +/** +* wpsc_category_url function, makes permalink to the category or +* @param integer category ID, can be 0 +* @param boolean permalink compatibility, adds a prefix to prevent permalink namespace conflicts +*/ +function wpsc_category_url($category_id, $permalink_compatibility = false) { + return get_term_link( $category_id, 'wpsc_product_category'); +} + + +function wpsc_is_in_category() { + global $wpdb, $wp_query; + $is_in_category = false; + if(isset($wp_query->query_vars['wpsc_product_category'] ) && !empty($wp_query->query_vars['wpsc_product_category'])) { + $is_in_category = true; + } else if(isset($_GET['wpsc_product_category']) && !empty($_GET['wpsc_product_category'])) { + $is_in_category = true; + } + + return $is_in_category; +} + + +/** + * Uses a category's, (in the wpsc_product_category taxonomy), slug to find its + * ID, then returns it. + * + * @param string $category_slug The slug of the category who's ID we want. + * @return (int | bool) Returns the integer ID of the category if found, or a + * boolean false if the category is not found. + * + * @todo Cache the results of this somewhere. It could save quite a few trips + * to the MySQL server. + * + * @author John Beales ( johnbeales.com ) + */ +function wpsc_category_id($category_slug = '') { + if(empty($category_slug)) + $category_slug = get_query_var( 'wpsc_product_category' ); + elseif(array_key_exists('wpsc_product_category', $_GET)) + $category_slug = $_GET['wpsc_product_category']; + + if(!empty($category_slug)) { + $category = get_term_by('slug', $category_slug, 'wpsc_product_category'); + if(!empty($category->term_id)){ + return $category->term_id; + } else { + return false; + } + } else { + return false; + } +} + + +/** +* wpsc_category_image function, Gets the category image or returns false +* @param integer category ID, can be 0 +* @return string url to the category image +*/ +function wpsc_category_image($category_id = null) { + if($category_id < 1) + $category_id = wpsc_category_id(); + $category_image = wpsc_get_categorymeta($category_id, 'image'); + $category_path = WPSC_CATEGORY_DIR.basename($category_image); + $category_url = WPSC_CATEGORY_URL.basename($category_image); + if(file_exists($category_path) && is_file($category_path)) + return $category_url; + return false; +} + + +/** +* wpsc_category_description function, Gets the category description +* @param integer category ID, can be 0 +* @return string category description +*/ +function wpsc_category_description($category_id = null) { + if($category_id < 1) + $category_id = wpsc_category_id(); + $category = get_term_by('id', $category_id, 'wpsc_product_category'); + return $category->description; +} + +function wpsc_category_name($category_id = null) { + if($category_id < 1) + $category_id = wpsc_category_id(); + $category = get_term_by('id', $category_id, 'wpsc_product_category'); + return $category->name; +} + +function nzshpcrt_display_categories_groups() { + global $wpdb; + + return $output; + } + +/** wpsc list subcategories function + used to get an array of all the subcategories of a category. +*/ +function wpsc_list_subcategories($category_id = null) { + global $wpdb,$category_data; + + $category_list = $wpdb->get_col( $wpdb->prepare( "SELECT `id` FROM `".WPSC_TABLE_PRODUCT_CATEGORIES."` WHERE `category_parent` = %d", $category_id ) ); + + if($category_list != null) { + foreach($category_list as $subcategory_id) { + $category_list = array_merge((array)$category_list, (array)wpsc_list_subcategories($subcategory_id)); + } + } + return $category_list; +} + +/** + * wpsc_show_category_thumbnails function + * @return bool - whether to show category thumbnails or not + */ +function wpsc_show_category_thumbnails(){ + if(get_option('show_category_thumbnails') && wpsc_category_image()) + return true; + else + return false; +} + +/** + * wpsc_show_category_description function + * @return bool - whether to show category description or not + */ +function wpsc_show_category_description(){ + return get_option('wpsc_category_description'); +} + +/** + * wpsc buy now button code products function + * Sorry about the ugly code, this is just to get the functionality back, buy now will soon be overhauled, and this function will then be completely different + * @return string - html displaying one or more products + */ +function wpsc_buy_now_button( $product_id, $replaced_shortcode = false ) { + + $product_id = absint($product_id); + + $product = get_post( $product_id ); + $supported_gateways = array( 'wpsc_merchant_paypal_standard', 'paypal_multiple' ); + $selected_gateways = get_option( 'custom_gateway_options' ); + + if ( $replaced_shortcode ) + ob_start(); + + if ( in_array( 'wpsc_merchant_paypal_standard', (array) $selected_gateways ) ) { + if ( $product_id > 0 ) { + + $post_meta = get_post_meta( $product_id, '_wpsc_product_metadata', true ); + $shipping = isset( $post_meta['shipping'] ) ? $post_meta['shipping']['local'] : ''; + $price = get_post_meta( $product_id, '_wpsc_price', true ); + $special_price = get_post_meta( $product_id, '_wpsc_special_price', true ); + + if ( $special_price ) + $price = $special_price; + + if ( wpsc_uses_shipping ( ) ) { + $handling = get_option( 'base_local_shipping' ); + } else { + $handling = $shipping; + } + + $has_variants = wpsc_product_has_variations( $product_id ); + + $src = apply_filters( 'wpsc_buy_now_button_src', _x( 'https://www.paypal.com/en_US/i/btn/btn_buynow_LG.gif', 'PayPal Buy Now Button', 'wpsc' ) ); + $classes = apply_filters( 'wpsc_buy_now_button_class', "wpsc-buy-now-form wpsc-buy-now-form-{$product_id}" ); + + $button_html = sprintf( '', + disabled( $has_variants, true, false ), + esc_attr( $product_id ), + esc_url( $src ), + esc_attr__( 'PayPal - The safer, easier way to pay online', 'wpsc' ) + ); + + $button_html = apply_filters( 'wpsc_buy_now_button_html', $button_html, $product_id ); +?> +
+ + +', wpsc_vargrp_id(), wpsc_vargrp_form_id() ); + endwhile; + endif; /* END wpsc_product_has_variations */ +?> + + +
+ + + + + ' /> +
+ get_results( $wpdb->prepare( "SELECT `" . $wpdb->posts . "`.* FROM `" . WPSC_TABLE_ALSO_BOUGHT . "`, `" . $wpdb->posts . "` WHERE `selected_product`= %d AND `" . WPSC_TABLE_ALSO_BOUGHT . "`.`associated_product` = `" . $wpdb->posts . "`.`id` AND `" . $wpdb->posts . "`.`post_status` IN('publish','protected') ORDER BY `" . WPSC_TABLE_ALSO_BOUGHT . "`.`quantity` DESC LIMIT $also_bought_limit", $product_id ), ARRAY_A ); + if ( is_array( $also_bought ) && count( $also_bought ) > 0 ) { + $output .= '

' . __( 'People who bought this item also bought', 'wpsc' ) . '

'; + $output .= '
'; + foreach ( $also_bought as $also_bought_data ) { + $output .= '
'; + if ( get_option( 'show_thumbnails' ) == 1 ) { + $image_path = wpsc_the_product_thumbnail( $image_display_width, $image_display_height, $also_bought_data['ID'] ); + if ( $image_path ) { + $output .= ''; + $output .= ''; + $output .= ''; + } else { + if ( get_option( 'product_image_width' ) != '' ) { + $width_and_height = 'width="' . $image_display_height . '" height="' . $image_display_height . '" '; + } else { + $width_and_height = ''; + } + $output .= '' . esc_attr( get_the_title( $also_bought_data['ID'] ) ) . ''; + } + } + + $output .= '' . get_the_title( $also_bought_data['ID'] ) . ''; + if ( ! wpsc_product_is_donation( $also_bought_data['ID'] ) ) { + // Ideally use the wpsc_the_product_price_display() function here but needs some tweaking + $price = get_product_meta( $also_bought_data['ID'], 'price', true ); + $special_price = get_product_meta( $also_bought_data['ID'], 'special_price', true ); + if ( ! empty( $special_price ) ) { + $output .= '' . wpsc_currency_display( $price ) . ''; + $output .= wpsc_currency_display( $special_price ); + } else { + $output .= wpsc_currency_display( $price ); + } + } + $output .= '
'; + } + $output .= '
'; + $output .= '
'; + } + return $output; +} + +/** + * Get the URL of the loading animation image. + * Can be filtered using the wpsc_loading_animation_url filter. + */ +function wpsc_loading_animation_url() { + return apply_filters( 'wpsc_loading_animation_url', WPSC_CORE_THEME_URL . 'wpsc-images/indicator.gif' ); +} + +function fancy_notifications() { + return wpsc_fancy_notifications( true ); +} +function wpsc_fancy_notifications( $return = false ) { + static $already_output = false; + + if ( $already_output ) + return ''; + + $output = ""; + if ( get_option( 'fancy_notifications' ) == 1 ) { + $output = ""; + $output .= "
\n\r"; + $output .= "
\n\r"; + $output .= '' . esc_attr__( 'Loading', 'wpsc' ) . '' . __( 'Updating', 'wpsc' ) . "...\n\r"; + $output .= "
\n\r"; + $output .= "
\n\r"; + $output .= "
\n\r"; + $output .= "
\n\r"; + } + + $already_output = true; + + if ( $return ) + return $output; + else + echo $output; +} + +function fancy_notification_content( $cart_messages ) { + $siteurl = get_option( 'siteurl' ); + $output = ''; + foreach ( (array)$cart_messages as $cart_message ) { + $output .= "" . $cart_message . "
"; + } + $output .= "" . __( 'Go to Checkout', 'wpsc' ) . ""; + $output .= "" . __( 'Continue Shopping', 'wpsc' ) . ""; + return $output; +} + +/* + * wpsc product url function, gets the URL of a product, + * Deprecated, all parameters past the first unused. use get_permalink + */ + +function wpsc_product_url( $product_id, $category_id = null, $escape = true ) { + $post = get_post($product_id); + if ( isset($post->post_parent) && $post->post_parent > 0) { + return get_permalink($post->post_parent); + } else { + return get_permalink($product_id); + } +} + +function external_link( $product_id ) { + $link = get_product_meta( $product_id, 'external_link', true ); + if ( !stristr( $link, 'http://' ) ) { + $link = 'http://' . $link; + } + $target = wpsc_product_external_link_target( $product_id ); + $output .= ""; + return $output; +} + +/** + * wpsc_refresh_page_urls + * + * Refresh page urls when pages are updated + * + * @param int $post_id + * @param object $post + * @uses wpsc_update_permalink_slugs() + * @return int $post_id + */ +function wpsc_refresh_page_urls( $post_id, $post ) { + + if ( ! current_user_can( 'manage_options' ) ) + return; + + if ( 'page' != $post->post_type ) + return; + + if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) + return; + + if ( ! in_array( $post->post_status, array( 'publish', 'private' ) ) ) + return; + + wpsc_update_permalink_slugs(); + + return $post_id; +} + +function wpsc_replace_wp_title( $input ) { + global $wpdb, $wp_query; + $output = wpsc_obtain_the_title(); + if ( $output != null ) { + return $output; + } + return $input; +} + +function wpsc_replace_bloginfo_title( $input, $show ) { + global $wpdb, $wp_query; + if ( $show == 'description' ) { + $output = wpsc_obtain_the_title(); + if ( $output != null ) { + return $output; + } + } + return $input; +} + diff --git a/wpsc-components/theme-engine-v1/helpers/query.php b/wpsc-components/theme-engine-v1/helpers/query.php new file mode 100644 index 0000000000..8b45f7c2b5 --- /dev/null +++ b/wpsc-components/theme-engine-v1/helpers/query.php @@ -0,0 +1,612 @@ +menu ); + + // Get the nav menu based on the theme_location + if ( ! $menu && $args->theme_location && ( $locations = get_nav_menu_locations() ) && isset( $locations[ $args->theme_location ] ) ) + $menu = wp_get_nav_menu_object( $locations[ $args->theme_location ] ); + + // get the first menu that has items if we still can't find a menu + if ( ! $menu && ! $args->theme_location ) { + $menus = wp_get_nav_menus(); + foreach ( $menus as $menu_maybe ) { + if ( $menu_items = wp_get_nav_menu_items( $menu_maybe->term_id ) ) { + $menu = $menu_maybe; + break; + } + } + } + + // If the menu exists, get its items. + if ( $menu && ! is_wp_error( $menu ) && ! isset( $menu_items ) ) + $menu_items = wp_get_nav_menu_items( $menu->term_id ); + + // If no menu was found or if the menu has no items and no location was requested, call the fallback_cb if it exists + if ( ( ! $menu || is_wp_error( $menu ) || ( isset( $menu_items ) && empty( $menu_items ) && ! $args->theme_location ) ) ) + return false; + + // If no fallback function was specified and the menu doesn't exists, bail. + if ( ! $menu || is_wp_error( $menu ) || empty( $menu_items ) ) + return false; + + return (bool) $menu; +} + +function _wpsc_switch_the_query( $stuff = '' ) { + global $wp_query, $wpsc_query; + list( $wp_query, $wpsc_query ) = array( $wpsc_query, $wp_query ); + return $stuff; +} + +/** + * Switch $wp_query and $wpsc_query when outputting the navigation menu, but only if we're on a product + * category page. + * + * We need to do this because the function _wp_menu_item_classes_by_context(), which generates classes + * for menu items, depends on $wp_query. As a result, without this fix, when viewing a product category + * page, the corresponding product category menu item will not be highlighted. + * + * Because there are no action hooks in wp_nav_menu(), we have to use two filters that are applied at + * the beginning and the end of the function. + * + * @param mixed $stuff + * @return mixed + */ +function wpsc_switch_the_query( $args ) { + global $wp_query, $wpsc_query; + $qv = $wpsc_query->query_vars; + if ( ! empty( $qv['wpsc_product_category'] ) && ! empty( $qv['taxonomy'] ) && ! empty( $qv['term'] ) && ! is_single() && _wpsc_menu_exists( $args ) ) { + _wpsc_switch_the_query(); + add_filter( 'wp_nav_menu', '_wpsc_switch_the_query', 99 ); + } + return $args; +} + +function _wpsc_pre_get_posts_reset_taxonomy_globals( $query ) { + global $wp_the_query; + + if ( is_admin() || $query !== $wp_the_query ) + return; + + if ( ! $query->get( 'page' ) && ! $query->get( 'paged' ) ) + return; + + if ( ! get_option( 'use_pagination' ) ) + return; + + if ( ! is_page( wpsc_get_the_post_id_by_shortcode( '[productspage]' ) ) && ! $query->get( 'wpsc_product_category' ) ) + return; + + $query->set( 'posts_per_page', get_option( 'wpsc_products_per_page' ) ); + + $post_type_object = get_post_type_object( 'wpsc-product' ); + + if ( current_user_can( $post_type_object->cap->edit_posts ) ) + $query->set( 'post_status', 'private,draft,pending,publish' ); + else + $query->set( 'post_status', 'publish' ); +} + +/** + * wpsc_start_the_query + */ +function wpsc_start_the_query() { + global $wpsc_page_titles, $wp_query, $wpsc_query, $wpsc_query_vars; + + $is_404 = false; + if ( null == $wpsc_query ) { + if( ( $wp_query->is_404 && !empty($wp_query->query_vars['paged']) ) || (isset( $wp_query->query['pagename']) && strpos( $wp_query->query['pagename'] , $wpsc_page_titles['products'] ) !== false ) && !isset($wp_query->post)){ + global $post; + $is_404 = true; + if( !isset( $wp_query->query_vars['wpsc_product_category'] ) && ! isset( $wp_query->query_vars['product_tag'] ) ) + $wp_query = new WP_Query('post_type=wpsc-product&name='.$wp_query->query_vars['name']); + + if(isset($wp_query->post->ID)) + $post = $wp_query->post; + else + $wpsc_query_vars['wpsc_product_category'] = $wp_query->query_vars['name']; + } + if ( count( $wpsc_query_vars ) <= 1 ) { + $post_type_object = get_post_type_object( 'wpsc-product' ); + $wpsc_query_vars = array( + 'post_status' => apply_filters( 'wpsc_product_display_status', array( 'publish' ) ), + 'post_parent' => 0, + 'order' => apply_filters( 'wpsc_product_order', get_option( 'wpsc_product_order', 'ASC' ) ) + ); + if($wp_query->query_vars['preview']) + $wpsc_query_vars['post_status'] = 'any'; + + if( isset( $_GET['product_order'] ) ) + $wpsc_query_vars['order'] = $_GET['product_order']; + + if(isset($wp_query->query_vars['product_tag'])){ + $wpsc_query_vars['product_tag'] = $wp_query->query_vars['product_tag']; + $wpsc_query_vars['taxonomy'] = get_query_var( 'taxonomy' ); + $wpsc_query_vars['term'] = get_query_var( 'term' ); + }elseif( isset($wp_query->query_vars['wpsc_product_category']) ){ + $wpsc_query_vars['wpsc_product_category'] = $wp_query->query_vars['wpsc_product_category']; + $wpsc_query_vars['taxonomy'] = get_query_var( 'taxonomy' ); + $wpsc_query_vars['term'] = get_query_var( 'term' ); + }else{ + $wpsc_query_vars['post_type'] = 'wpsc-product'; + $wpsc_query_vars['pagename'] = wpsc_get_page_slug( '[productspage]' ); + } + if(1 == get_option('use_pagination')){ + $wpsc_query_vars['nopaging'] = false; + + $wpsc_query_vars['posts_per_page'] = get_option('wpsc_products_per_page'); + + $wpsc_query_vars['paged'] = get_query_var('paged'); + if(isset($wpsc_query_vars['paged']) && empty($wpsc_query_vars['paged'])){ + $wpsc_query_vars['paged'] = get_query_var('page'); + + } + + } + + $orderby = ( isset( $_GET['product_order'] ) ) ? 'title' : null; + $wpsc_query_vars = array_merge( $wpsc_query_vars, wpsc_product_sort_order_query_vars($orderby) ); + + add_filter( 'pre_get_posts', 'wpsc_generate_product_query', 11 ); + + $wpsc_query = new WP_Query( $wpsc_query_vars ); + + //for 3.1 :| + if(empty($wpsc_query->posts) && isset($wpsc_query->tax_query) && isset($wp_query->query_vars['wpsc_product_category'])){ + $wpsc_query_vars = array(); + $wpsc_query_vars['wpsc_product_category'] = $wp_query->query_vars['wpsc_product_category']; + if(1 == get_option('use_pagination')){ + $wpsc_query_vars['posts_per_page'] = get_option('wpsc_products_per_page'); + $wpsc_query_vars['paged'] = get_query_var('paged'); + if(empty($wpsc_query_vars['paged'])) + $wpsc_query_vars['paged'] = get_query_var('page'); + } + $wpsc_query = new WP_Query( $wpsc_query_vars ); + + } + } + } + + if( $is_404 || ( ( isset($wpsc_query->post_count) && $wpsc_query->post_count == 0 ) && isset($wpsc_query_vars['wpsc_product_category'] ) )){ + + $args = array_merge($wp_query->query, array('posts_per_page' => get_option('wpsc_products_per_page'))); + $wp_query = new WP_Query($args); + + if( empty( $wp_query->posts ) ){ + $product_page_id = wpsc_get_the_post_id_by_shortcode('[productspage]'); + $wp_query = new WP_Query( 'page_id='.$product_page_id); + } + } + if ( isset( $wp_query->post->ID ) ) + $post_id = $wp_query->post->ID; + else + $post_id = 0; + + if ( get_permalink( $post_id ) == get_option( 'shopping_cart_url' ) ) + $_SESSION['wpsc_has_been_to_checkout'] = true; +} + +/** +* Returns page slug that corresponds to a given WPEC-specific shortcode. +* +* @since 3.8.10 +* +* @uses wpsc_get_the_post_id_by_shortcode() Gets page ID of shortcode. +* @uses get_post_field() Returns post name of page ID. +* +* @param string $shortcode Shortcode of WPEC-specific page, e.g. '[productspage]'' +* @return string Post slug +*/ +function wpsc_get_page_slug( $shortcode ) { + $id = wpsc_get_the_post_id_by_shortcode( $shortcode ); + return get_post_field( 'post_name', $id ); +} + +/** + * Obtain the necessary product sort order query variables based on the specified product sort order. + * If no sort order is specified, the sort order configured in Dashboard -> Settings -> Store -> Presentation -> 'Sort Product By' is used. + * + * @param string $orderby optional product sort order + * @return array Array of query variables + */ +function wpsc_product_sort_order_query_vars( $orderby = null ) { + if ( is_null($orderby) ) + $orderby = get_option( 'wpsc_sort_by' ); + + $query_vars = array(); + + switch ( $orderby ) { + + case "dragndrop": + $query_vars["orderby"] = 'menu_order'; + break; + + case "name": + $query_vars["orderby"] = 'title'; + break; + + //This only works in WP 3.0. + case "price": + add_filter( 'posts_join', 'wpsc_add_meta_table' ); + add_filter( 'posts_where', 'wpsc_add_meta_table_where' ); + $query_vars["meta_key"] = '_wpsc_price'; + $query_vars["orderby"] = 'meta_value_num'; + break; + + case "id": + $query_vars["orderby"] = 'ID'; + break; + default: + // Allow other WordPress 'ordery' values as defined in http://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters + $query_vars["orderby"] = $orderby; + break; + } + return $query_vars; +} + +/** + * wpsc_query_vars function. + * adds in the post_type and wpsc_item query vars + * + * @since 3.8 + * @access public + * @param mixed $vars + * @return void + */ +function wpsc_query_vars( $vars ) { + // post_type is used to specify that we are looking for products + $vars[] = "post_type"; + // wpsc_item is used to find items that could be either a product or a product category, it defaults to category, then tries products + $vars[] = "wpsc_item"; + return $vars; +} + +/** + * wpsc_query_modifier function. + * + * @since 3.8 + * @access public + * @param object - reference to $wp_query + * @return $query + */ +function wpsc_split_the_query( $query ) { + global $wpsc_page_titles, $wpsc_query, $wpsc_query_vars; + // These values are to be dynamically defined + $products_page = $wpsc_page_titles['products']; + $checkout_page = $wpsc_page_titles['checkout']; + $userlog_page = $wpsc_page_titles['userlog']; + $transaction_results_page = $wpsc_page_titles['transaction_results']; + + // otherwise, check if we are looking at a product, if so, duplicate the query and swap the old one out for a products page request + // JS - 6.4.1020 - Added is_admin condition, as the products condition broke categories in backend + if ( !empty($query->query_vars['pagename']) && ($query->query_vars['pagename'] == $products_page) || isset( $query->query_vars['products'] ) && !is_admin() ) { + // store a copy of the wordpress query + $wpsc_query_data = $query->query; + + // wipe and replace the query vars + $query->query = array(); + $query->query['pagename'] = "$products_page"; + $query->query_vars['pagename'] = "$products_page"; + $query->query_vars['name'] = ''; + $query->query_vars['post_type'] = ''; + + $query->queried_object = & get_page_by_path( $query->query['pagename'] ); + + if ( !empty( $query->queried_object ) ) + $query->queried_object_id = (int)$query->queried_object->ID; + else + unset( $query->queried_object ); + + unset( $query->query_vars['products'] ); + unset( $query->query_vars['name'] ); + unset( $query->query_vars['taxonomy'] ); + unset( $query->query_vars['term'] ); + unset( $query->query_vars['wpsc_item'] ); + + $query->is_singular = true; + $query->is_page = true; + $query->is_tax = false; + $query->is_archive = false; + $query->is_single = false; + + if ( ($wpsc_query_vars == null ) ) { + unset( $wpsc_query_data['pagename'] ); + $wpsc_query_vars = $wpsc_query_data; + } + } + + add_filter( 'redirect_canonical', 'wpsc_break_canonical_redirects', 10, 2 ); + remove_filter( 'pre_get_posts', 'wpsc_split_the_query', 8 ); +} + +/** + * wpsc_generate_product_query function. + * + * @access public + * @param mixed $query + * @return void + */ +function wpsc_generate_product_query( $query ) { + global $wp_query; + $prod_page = wpsc_get_the_post_id_by_shortcode('[productspage]'); + $prod_page = get_post($prod_page); + remove_filter( 'pre_get_posts', 'wpsc_generate_product_query', 11 ); + $query->query_vars['taxonomy'] = null; + $query->query_vars['term'] = null; + + // default product selection + if ( $query->query_vars['pagename'] != '' ) { + $query->query_vars['post_type'] = 'wpsc-product'; + $query->query_vars['pagename'] = ''; + $query->is_page = false; + $query->is_tax = false; + $query->is_archive = true; + $query->is_singular = false; + $query->is_single = false; + } + + // If wpsc_item is not null, we are looking for a product or a product category, check for category + if ( isset( $query->query_vars['wpsc_item'] ) && ($query->query_vars['wpsc_item'] != '') ) { + $test_term = get_term_by( 'slug', $query->query_vars['wpsc_item'], 'wpsc_product_category' ); + if ( $test_term->slug == $query->query_vars['wpsc_item'] ) { + // if category exists (slug matches slug), set products to value of wpsc_item + $query->query_vars['products'] = $query->query_vars['wpsc_item']; + } else { + // otherwise set name to value of wpsc_item + $query->query_vars['name'] = $query->query_vars['wpsc_item']; + } + } + + if ( isset( $query->query_vars['products'] ) && ($query->query_vars['products'] != null) && ($query->query_vars['name'] != null) ) { + unset( $query->query_vars['taxonomy'] ); + unset( $query->query_vars['term'] ); + $query->query_vars['post_type'] = 'wpsc-product'; + $query->is_tax = false; + $query->is_archive = true; + $query->is_singular = false; + $query->is_single = false; + } + if( isset($wp_query->query_vars['wpsc_product_category']) && !isset($wp_query->query_vars['wpsc-product'])){ + $query->query_vars['wpsc_product_category'] = $wp_query->query_vars['wpsc_product_category']; + $query->query_vars['taxonomy'] = $wp_query->query_vars['taxonomy']; + $query->query_vars['term'] = $wp_query->query_vars['term']; + }elseif( '' != ($default_category = get_option('wpsc_default_category')) && !isset($wp_query->query_vars['wpsc-product'])){ + $default_term = get_term($default_category,'wpsc_product_category'); + if(!empty($default_term) && empty($wp_query->query_vars['category_name'])){ + $query->query_vars['taxonomy'] = 'wpsc_product_category'; + $query->query_vars['term'] = $default_term->slug; + $query->is_tax = true; + }elseif(isset($wp_query->query_vars['name']) && $wp_query->is_404 && $wp_query->query_vars['category_name'] != $prod_page->post_name){ + unset( $query->query_vars['taxonomy'] ); + unset( $query->query_vars['term'] ); + $query->query_vars['wpsc-product'] = $wp_query->query_vars['name']; + $query->query_vars['name'] = $wp_query->query_vars['name']; + + }else{ + $query->is_tax = true; + $term = get_term_by('slug',$wp_query->query_vars['name'], 'wpsc_product_category' ); + if(!empty($term)){ + $query->query_vars['taxonomy'] = 'wpsc_product_category'; + $query->query_vars['wpsc_product_category__in'] = array($term->term_taxonomy_id); + $query->query_vars['wpsc_product_category'] = $wp_query->query_vars['name']; + $query->query_vars['term'] = $wp_query->query_vars['name']; + }elseif(is_numeric($default_category)){ + $query->query_vars['taxonomy'] = 'wpsc_product_category'; + }else{ + $query->is_tax = false; + } + } + } + //If Product Tag Taxonomy + if (isset($wp_query->query_vars['product_tag']) && $wp_query->query_vars['product_tag']){ + $query->query_vars['product_tag'] = $wp_query->query_vars['product_tag']; + $query->query_vars['term'] = $wp_query->query_vars['term']; + $query->query_vars['taxonomy'] = 'product_tag'; + $query->is_tax = true; + } + if(1 == get_option('use_pagination')){ + $query->query_vars['posts_per_page'] = get_option('wpsc_products_per_page'); + if( isset( $_GET['items_per_page'] ) ) { + if ( is_numeric( $_GET['items_per_page'] ) ) { + $query->query_vars['posts_per_page'] = (int) $_GET['items_per_page']; + } elseif ( $_GET['items_per_page'] == 'all' ) { + $query->query_vars['posts_per_page'] = -1; + $query->query_vars['nopaging'] = 1; + } + } + } else { + $query->query_vars['posts_per_page'] = -1; + $query->query_vars['nopaging'] = 1; + } + if ( $query->is_tax == true ) + new wpsc_products_by_category( $query ); + return $query; +} + +function wpsc_mark_product_query( $query ) { + + if ( isset( $query->query_vars['post_type'] ) && ($query->query_vars['post_type'] == 'wpsc-product') ) + $query->is_product = true; + + return $query; +} + +/** + * add meta table where section for ordering by price + * + */ +function wpsc_add_meta_table_where($where){ + global $wpdb; + + remove_filter( 'posts_where', 'wpsc_add_meta_table_where' ); + + return $where . ' AND ' . $wpdb->postmeta . '.meta_key = "_wpsc_price"'; +} + +/** + * add meta table join section for ordering by price + * + */ +function wpsc_add_meta_table($join){ + global $wpdb; + remove_filter( 'posts_join', 'wpsc_add_meta_table' ); + if(strpos($join, "INNER JOIN ON (".$wpdb->posts.".ID = ".$wpdb->postmeta.".post_id)") !== false){ + return ' JOIN ' . $wpdb->postmeta . ' ON ' . $wpdb->posts. '.ID = ' . $wpdb->postmeta . '.post_id'; + }else{ + return $join; + } +} + +function wpsc_break_canonical_redirects( $redirect_url, $requested_url ) { + global $wp_query; + + if ( ( isset( $wp_query->query_vars['products'] ) && ($wp_query->query_vars['products'] != '') ) || ( isset( $wp_query->query_vars['products'] ) && $wp_query->query_vars['products'] != 'wpsc_item') ) + return false; + + if ( stristr( $requested_url, $redirect_url ) ) + return false; + + return $redirect_url; +} + +function wpsc_filter_request( $q ) { + if ( empty( $q['wpsc-product'] ) ) + return $q; + + $components = explode( '/', $q['wpsc-product'] ); + $end_node = array_pop( $components ); + $parent_node = array_pop( $components ); + + $posts = get_posts( array( + 'post_type' => 'wpsc-product', + 'name' => $end_node, + ) ); + + if ( ! empty( $posts ) ) { + $q['wpsc-product'] = $q['name'] = $end_node; + if ( !empty( $parent_node ) ) + $q['wpsc_product_category'] = $parent_node; + } else { + $q['wpsc_product_category'] = $end_node; + unset( $q['name'] ); + unset( $q['wpsc-product'] ); + } + return $q; +} + +/** + * if the user is on a checkout page, force SSL if that option is so set + */ +function wpsc_force_ssl() { + global $wp_query; + if ( '1' == get_option( 'wpsc_force_ssl' ) && + ! is_ssl() && + ! empty ( $wp_query->post->post_content ) && + false !== strpos( $wp_query->post->post_content, '[shoppingcart]' ) ) { + $sslurl = 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; + wp_redirect( $sslurl ); + exit; + } +} + +/** + * wpsc_add_https_to_page_url_options( $url ) + * + * Forces SSL onto option URLs + * + * @param string $url + * @return string + */ +function wpsc_add_https_to_page_url_options( $url ) { + return str_replace( 'http://', 'https://', $url ); +} + +/** + * Checks if current page is shopping cart, and it should be SSL, but is not. + * Used primarily for str_replacing links or content for https + * + * @since 3.8.8.1 + * @deprecated 3.8.8.2 + * @return boolean true if we're on the shopping cart page and should be ssl, false if not + */ +function wpsc_is_ssl() { + global $wp_query; + + return '1' == get_option( 'wpsc_force_ssl' ) && ! is_ssl() && false !== strpos( $wp_query->post->post_content, '[shoppingcart]' ); +} + diff --git a/wpsc-components/theme-engine-v1/helpers/rewrite.php b/wpsc-components/theme-engine-v1/helpers/rewrite.php new file mode 100644 index 0000000000..14aacdf15d --- /dev/null +++ b/wpsc-components/theme-engine-v1/helpers/rewrite.php @@ -0,0 +1,71 @@ + $rewrite_query ) { + if ( stristr( $rewrite_query, "index.php?product" ) ) { + $rewrite_rules[$rewrite_key] = str_replace( $target_string, $replacement_string, $rewrite_query ); + } + if ( stristr( $rewrite_query, "$target_rule_set_query_var=" ) ) { + $target_rule_set[] = $rewrite_key; + } + } + + $new_rewrite_rules[$products_page . '/(.+?)/product/([^/]+)/comment-page-([0-9]{1,})/?$'] = 'index.php?post_type=wpsc-product&products=$matches[1]&name=$matches[2]&cpage=$matches[3]'; + $new_rewrite_rules[$products_page . '/(.+?)/product/([^/]+)/?$'] = 'index.php?post_type=wpsc-product&products=$matches[1]&name=$matches[2]'; + $new_rewrite_rules[$products_page . '/(.+?)/([^/]+)/comment-page-([0-9]{1,})/?$'] = 'index.php?post_type=wpsc-product&products=$matches[1]&wpsc_item=$matches[2]&cpage=$matches[3]'; + $new_rewrite_rules[$products_page . '/(.+?)/([^/]+)?$'] = 'index.php?post_type=wpsc-product&products=$matches[1]&wpsc_item=$matches[2]'; + + $last_target_rule = array_pop( $target_rule_set ); + + $rebuilt_rewrite_rules = array( ); + foreach ( $rewrite_rules as $rewrite_key => $rewrite_query ) { + if ( $rewrite_key == $last_target_rule ) { + $rebuilt_rewrite_rules = array_merge( $rebuilt_rewrite_rules, $new_rewrite_rules ); + } + $rebuilt_rewrite_rules[$rewrite_key] = $rewrite_query; + } + + // fix pagination issue with product category hirarchical URL + if ( get_option( 'product_category_hierarchical_url', false ) ) { + $rule = $rebuilt_rewrite_rules[$products_page . '/(.+?)/page/?([0-9]{1,})/?$']; + unset( $rebuilt_rewrite_rules[$products_page . '/(.+?)/page/?([0-9]{1,})/?$'] ); + $rebuilt_rewrite_rules = array_merge( + array( + '(' . $products_page . ')/page/([0-9]+)/?' => 'index.php?pagename=$matches[1]&page=$matches[2]', + $products_page . '/(.+?)(/.+?)?/page/?([0-9]{1,})/?$' => 'index.php?wpsc_product_category=$matches[1]&wpsc-product=$matches[2]&page=$matches[3]', + ), + $rebuilt_rewrite_rules + ); + } + + // fix pagination in WordPress 3.4 + if ( version_compare( get_bloginfo( 'version' ), '3.4', '>=' ) ) { + $rebuilt_rewrite_rules = array_merge( + array( + '(' . $products_page . ')/([0-9]+)/?$' => 'index.php?pagename=$matches[1]&page=$matches[2]', + ), + $rebuilt_rewrite_rules + ); + } + return $rebuilt_rewrite_rules; +} + diff --git a/wpsc-components/theme-engine-v1/helpers/rss.php b/wpsc-components/theme-engine-v1/helpers/rss.php new file mode 100644 index 0000000000..450a4ae9ae --- /dev/null +++ b/wpsc-components/theme-engine-v1/helpers/rss.php @@ -0,0 +1,28 @@ +"; +} diff --git a/wpsc-components/theme-engine-v1/helpers/shipping.php b/wpsc-components/theme-engine-v1/helpers/shipping.php new file mode 100644 index 0000000000..c5cecb14c2 --- /dev/null +++ b/wpsc-components/theme-engine-v1/helpers/shipping.php @@ -0,0 +1,150 @@ +have_shipping_methods(); +} +/** +* the shipping method function, no parameters +* @return boolean +*/ +function wpsc_the_shipping_method() { + global $wpsc_cart; + return $wpsc_cart->the_shipping_method(); +} +/** +* the shipping method name function, no parameters +* @return string shipping method name +*/ +function wpsc_shipping_method_name() { + global $wpsc_cart, $wpsc_shipping_modules; + $name = ''; + if ( ! empty( $wpsc_cart->shipping_method ) && isset( $wpsc_shipping_modules[$wpsc_cart->shipping_method] ) ) + $name = $wpsc_shipping_modules[$wpsc_cart->shipping_method]->name; + + return apply_filters( 'wpsc_shipping_method_name', $name ); +} + + +/** +* the shipping method internal name function, no parameters +* @return string shipping method internal name +*/ +function wpsc_shipping_method_internal_name() { + global $wpsc_cart, $wpsc_shipping_modules; + return $wpsc_cart->shipping_method; +} + + +/** +* have shipping quotes function, no parameters +* @return string the cart item url +*/ +function wpsc_have_shipping_quotes() { + global $wpsc_cart; + return $wpsc_cart->have_shipping_quotes(); +} + +/** +* the shipping quote function, no parameters +* @return string the cart item url +*/ +function wpsc_the_shipping_quote() { + global $wpsc_cart; + return $wpsc_cart->the_shipping_quote(); +} + +/** +* the shipping quote name function, no parameters +* @return string shipping quote name +*/ +function wpsc_shipping_quote_name() { + global $wpsc_cart; + return apply_filters( 'wpsc_shipping_quote_name', $wpsc_cart->shipping_quote['name'] ); +} + +/** +* the shipping quote value function, no parameters +* @return string shipping quote value +*/ +function wpsc_shipping_quote_value( $numeric = false ) { + global $wpsc_cart; + + $value = apply_filters( 'wpsc_shipping_quote_value', $wpsc_cart->shipping_quote['value'] ); + + return ( $numeric ) ? $value : wpsc_currency_display( $value ); + +} + +/** +* the shipping quote html ID function, no parameters +* @return string shipping quote html ID +*/ +function wpsc_shipping_quote_html_id() { + global $wpsc_cart; + return $wpsc_cart->shipping_method."_".$wpsc_cart->current_shipping_quote; +} + +/** +* the shipping quote selected state function, no parameters +* @return string true or false +*/ +function wpsc_shipping_quote_selected_state() { + global $wpsc_cart; + if(($wpsc_cart->selected_shipping_method == $wpsc_cart->shipping_method) && ($wpsc_cart->selected_shipping_option == $wpsc_cart->shipping_quote['name']) ) { + $wpsc_cart->selected_shipping_amount = $wpsc_cart->base_shipping; + return "checked='checked'"; + } else { + return ""; + } +} +function wpsc_have_morethanone_shipping_quote(){ + global $wpsc_cart, $wpsc_shipping_modules; + + // if it's fixed rate shipping, and all the prices are the same, then there aren't really options. + if ( count($wpsc_cart->shipping_methods) == 1 && $wpsc_cart->shipping_methods[0] == 'flatrate' ) { + $last_price = false; + $first_quote_name = false; + + $quotes = $wpsc_shipping_modules['flatrate']->getQuote(); + if ( empty( $quotes ) ) + return false; + + foreach ((array)$quotes as $name => $quote) { + if (!$first_quote_name) $first_quote_name = $name; + if ($last_price !== false && $quote != $last_price) return true; + $last_price = $quote; + } + $wpsc_cart->rewind_shipping_methods(); + + $wpsc_cart->update_shipping('flatrate', $name); + return false; + } + return true; +} + +function wpsc_have_morethanone_shipping_methods_and_quotes(){ + global $wpsc_cart; + + if(count($wpsc_cart->shipping_quotes) > 1 || count($wpsc_cart->shipping_methods) > 1 || count($wpsc_cart->shipping_quotes) == $wpsc_cart->shipping_quote_count){ + return true; + }else{ + return false; + } +} +/** + * Whether or not there is a valid shipping quote/option available to the customer when checking out + * + * @return bool + */ +function wpsc_have_shipping_quote(){ + global $wpsc_cart; + if ($wpsc_cart->shipping_quote_count > 0 || count($wpsc_cart->shipping_quotes) > 0) { + return true; + } + return false; +} \ No newline at end of file diff --git a/wpsc-includes/shortcode.functions.php b/wpsc-components/theme-engine-v1/helpers/shortcodes.php old mode 100755 new mode 100644 similarity index 86% rename from wpsc-includes/shortcode.functions.php rename to wpsc-components/theme-engine-v1/helpers/shortcodes.php index 0d2c496a5e..5e004583ba --- a/wpsc-includes/shortcode.functions.php +++ b/wpsc-components/theme-engine-v1/helpers/shortcodes.php @@ -1,4 +1,8 @@ ID ) ) { + if ( get_option( 'wpsc_default_category' ) == 'list' && $post->ID == $product_page_id ) + $output = false; + + if ( isset( $_GET['range'] ) || isset( $_GET['category'] ) ) + $output = true; + } + return $output; +} + +/** + * is single product function, determines if we are viewing a single product + * @return boolean - true, or false... + */ +function wpsc_is_single_product() { + return is_single() && get_post_type() == 'wpsc-product'; +} + +/** + * category class function, categories can have a specific class, this gets that + * @return string - the class of the selected category + */ +function wpsc_category_class() { + global $wpdb, $wp_query; + + $category_nice_name = ''; + if ( 'wpsc_product_category' == $wp_query->query_vars['taxonomy'] ) { + $catid = wpsc_get_the_category_id($wp_query->query_vars['term'],'slug'); + } else { + $catid = get_option( 'wpsc_default_category' ); + if ( $catid == 'all+list' ) { + $catid = 'all'; + } + } + + if ( (int)$catid > 0 ){ + $term = get_term($catid, 'wpsc_product_category'); + $category_nice_name = $term->slug; + }else if ( $catid == 'all' ){ + $category_nice_name = 'all-categories'; +} + return $category_nice_name; +} + +/** + * category transition function, finds the transition between categories + * @return string - the class of the selected category + */ +function wpsc_current_category_name() { + global $wp_query; + $term_data = get_term( $wp_query->post->term_id, 'wpsc_product_category' ); + + return $term_data->name; +} + +/** + * category transition function, finds the transition between categories + * @return string - the class of the selected category + */ +function wpsc_category_transition() { + //removed because it was not working in 3.8 RC2 see first changest after + //http://plugins.trac.wordpress.org/changeset/357529/wp-e-commerce/ + return false; + +} +/** + * wpsc show fb like function, check whether to show facebook like + * @return boolean true if option is on, otherwise, false + */ + +function wpsc_show_fb_like(){ + if('on' == get_option('wpsc_facebook_like')) + return true; + else + return false; +} +/** + * wpsc have products function, the product loop + * @return boolean true while we have products, otherwise, false + */ +function wpsc_have_products() { + return have_posts(); +} + +/** + * wpsc the product function, gets the next product, + * @return nothing + */ +function wpsc_the_product() { + global $wpsc_custom_meta, $wpsc_variations; + the_post(); + $wpsc_custom_meta = new wpsc_custom_meta( get_the_ID() ); + $wpsc_variations = new wpsc_variations( get_the_ID() ); +} + +/** + * wpsc the product id function, + * @return integer - the product ID + */ +function wpsc_the_product_id() { + return get_the_ID(); +} + +/** + * wpsc edit the product link function + * @return string - a link to edit this product + */ +function wpsc_edit_the_product_link( $link = null, $before = '', $after = '', $id = 0 ) { + global $wpsc_query, $current_user, $table_prefix, $wp_query; + if ( $link == null ) + $link = __( 'Edit', 'wpsc' ); + + $product_id = $wp_query->post->ID; + if ( $id > 0 ) + $product_id = $id; + + $output = ''; + if(is_user_logged_in()){ + get_currentuserinfo(); + if ( $current_user->{$table_prefix . 'capabilities'}['administrator'] == 1 ) + $output = $before . '' . $link . '' . $after; + + } + return $output; +} + +/** + * wpsc the product title function + * @return string - the product title + */ +function wpsc_the_product_title( $post = 0 ) { + return get_the_title( $post ); +} + +/** + * wpsc product description function + * @return string - the product description + */ +function wpsc_the_product_description() { + $content = get_the_content( __( 'Read the rest of this entry »', 'wpsc' ) ); + return do_shortcode( wpautop( $content,1 ) ); +} + +/** + * wpsc additional product description function + * TODO make this work with the tabbed multiple product descriptions, may require another loop + * @return string - the additional description + */ +function wpsc_the_product_additional_description() { + global $post; + + if ( !empty( $post->post_excerpt ) ) + return $post->post_excerpt; + else + return false; +} + +/** + * wpsc product permalink function + * @return string - the URL to the single product page for this product + */ +function wpsc_the_product_permalink() { + global $wp_query; + return get_permalink(); +} + +/** + * wpsc external link function + * @return string - the product price + */ +function wpsc_product_external_link( $id = null ) { + if ( is_numeric( $id ) && ( $id > 0 ) ) + $id = absint( $id ); + else + $id = get_the_ID(); + + $product_meta = get_post_meta( $id, '_wpsc_product_metadata', true ); + if ( isset( $product_meta['external_link'] ) ) { + $external_link = $product_meta['external_link']; + return esc_url( $external_link ); + } +} + +/** + * wpsc external link text function + * @return string - the product external link text + */ +function wpsc_product_external_link_text( $id = null, $default = null ) { + if ( is_numeric( $id ) && ( $id > 0 ) ) + $id = absint( $id ); + else + $id = get_the_ID(); + + $external_link_text = __( 'Buy Now', 'wpsc' ); + if ( $default != null ) { + $external_link_text = $default; + } + + $product_meta = get_post_meta( $id, '_wpsc_product_metadata', true ); + if ( isset( $product_meta['external_link_text'] ) && !empty( $product_meta['external_link_text'] ) ) { + $external_link_text = $product_meta['external_link_text']; + } + return esc_html( $external_link_text ); +} + +/** + * wpsc external link target function + * @return string - the product external link target + */ +function wpsc_product_external_link_target( $id = null, $external_link_target = '' ) { + if ( is_numeric( $id ) && ( $id > 0 ) ) + $id = absint( $id ); + else + $id = get_the_ID(); + + $product_meta = get_post_meta( $id, '_wpsc_product_metadata', true ); + if ( isset( $product_meta['external_link_target'] ) && !empty( $product_meta['external_link_target'] ) ) { + $external_link_target = $product_meta['external_link_target']; + } + return esc_attr( $external_link_target ); +} + +/** + * wpsc product sku function + * @return string - the product price + */ +function wpsc_product_sku( $id = null ) { + if ( is_numeric( $id ) && ( $id > 0 ) ) + $id = absint( $id ); + else + $id = get_the_ID(); + + $product_sku = get_post_meta( $id, '_wpsc_sku', true ); + + return esc_attr( $product_sku ); +} + +function wpsc_has_pages_top(){if(wpsc_has_pages() && ((get_option('wpsc_page_number_position') == 1) || (get_option('wpsc_page_number_position') == 3))) + return true; + else + return false; +} + + +function wpsc_has_pages_bottom(){ + if(wpsc_has_pages() && ((get_option('wpsc_page_number_position') == 2) || (get_option('wpsc_page_number_position') == 3))) + return true; + else + return false; +} + +/** + * Used in wpsc_pagination to generate the links in pagination + * @access public + * + * @since 3.8 + * @param $page int + * @return $output string, url + */ +function wpsc_a_page_url($page=null) { + global $wp_query; + $output = ''; + $curpage = $wp_query->query_vars['paged']; + if($page != '') + $wp_query->query_vars['paged'] = $page; + if($wp_query->is_single === true) { + $wp_query->query_vars['paged'] = $curpage; + return get_permalink($wp_query->post->ID); + } else { + if( 1 < $wp_query->query_vars['paged']) { + if(get_option('permalink_structure')) + $output .= "paged/{$wp_query->query_vars['paged']}/"; + else + $output = add_query_arg('paged', '', $output); + + } + return $output; + } +} +/** + * wpsc_pagination generates and returns the urls for pagination + * @access public + * + * @since 3.8 + * @param $totalpages (INT) Number of pages, + * @param $per_page (INT) Number of products per page + * @param $current_page (INT) Current Product page number + * @param $page_link (STRING) URL of Page + * + * @return + */ +function wpsc_pagination( $totalpages = '', $per_page = '', $current_page = '', $page_link = '' ) { + global $wp_query, $wpsc_query, $wp_the_query; + + $num_paged_links = 4; //amount of links to show on either side of current page + + $additional_links = ''; + + //additional links, items per page and products order + if( get_option('permalink_structure') != '' ){ + $additional_links_separator = '?'; + }else{ + $additional_links_separator = '&'; + } + if( !empty( $_GET['items_per_page'] ) ){ + $additional_links = $additional_links_separator . 'items_per_page=' . $_GET['items_per_page']; + $additional_links_separator = '&'; + } + if( !empty( $_GET['product_order'] ) ) + $additional_links .= $additional_links_separator . 'product_order=' . $_GET['product_order']; + + if ( ! empty( $_GET['range'] ) ) + $additional_links .= $additional_links_separator . 'range=' . $_GET['range']; + + $additional_links = apply_filters('wpsc_pagination_additional_links', $additional_links); + //end of additional links + + if(empty($totalpages)){ + $totalpages = $wp_query->max_num_pages; + } + if(empty($per_page)) + $per_page = (int)get_option('wpsc_products_per_page'); + + $current_page = absint( get_query_var('paged') ); + if($current_page == 0) + $current_page = 1; + + if(empty($page_link)) + $page_link = wpsc_a_page_url(); + + //if there is no pagination + if(!get_option('permalink_structure')) { + $category = '?'; + + if( ! empty( $wp_query->query_vars['wpsc_product_category'] ) ) + $category = '?wpsc_product_category='.$wp_query->query_vars['wpsc_product_category']; + if(isset($wp_query->query_vars['wpsc_product_category']) && is_string($wp_query->query_vars['wpsc_product_category'])){ + $page_link = get_option('blogurl').$category.'&paged'; + }else{ + $page_link = get_option('product_list_url').$category.'&paged'; + } + + $separator = '='; + }else{ + global $wpsc_query; + + $separator = 'page/'; + + if ( isset( $wp_query->query_vars['wpsc_product_category'] ) ) { + $category_id = get_term_by( 'slug', $wp_query->query_vars['wpsc_product_category'], 'wpsc_product_category' ); + $page_link = trailingslashit( get_term_link( $category_id, 'wpsc_product_category' ) ); + // in case we're displaying a category using shortcode, need to use the page's URL instead of the taxonomy URL + if ( $wp_the_query->is_page() ) { + $page = $wp_the_query->get_queried_object(); + if ( preg_match( '/\[wpsc\_products[^\]]*category_id=/', $page->post_content ) ) { + $page_link = trailingslashit( get_permalink( $page->ID ) ); + $separator = ''; + } + } + } elseif ( is_tax( 'product_tag' ) ) { + $tag = get_queried_object(); + $page_link = trailingslashit( get_term_link( (int) $tag->term_id, 'product_tag' ) ); + } elseif ( $wpsc_query->is_front_page() ) { + $page_link = trailingslashit( home_url() ); + } else { + $page_link = trailingslashit( get_option( 'product_list_url' ) ); + $separator = ''; + } + + if ( version_compare( get_bloginfo( 'version' ), '3.4', '<' ) ) + $separator = 'page/'; + } + + // If there's only one page, return now and don't bother + if($totalpages == 1) + return; + // Pagination Prefix + $output = __('Pages: ','wpsc'); + if(get_option('permalink_structure')){ + // Should we show the FIRST PAGE link? + if($current_page > 1) + $output .= "" . __('« First', 'wpsc') . ""; + + // Should we show the PREVIOUS PAGE link? + if($current_page > 1) { + $previous_page = $current_page - 1; + if( $previous_page == 1 ) + $output .= " " . __('< Previous', 'wpsc') . ""; + else + $output .= " " . __('< Previous', 'wpsc') . ""; + } + $i =$current_page - $num_paged_links; + $count = 1; + if($i <= 0) $i =1; + while($i < $current_page){ + if($count <= $num_paged_links){ + if($count == 1) + $output .= " ".$i.""; + else + $output .= " ".$i.""; + } + $i++; + $count++; + } + // Current Page Number + if($current_page > 0) + $output .= "$current_page"; + + //Links after Current Page + $i = $current_page + $num_paged_links; + $count = 1; + + if($current_page < $totalpages){ + while(($i) > $current_page){ + + if($count < $num_paged_links && ($count+$current_page) <= $totalpages){ + $output .= " ".($count+$current_page).""; + $i++; + }else{ + break; + } + $count ++; + } + } + + if($current_page < $totalpages) { + $next_page = $current_page + 1; + $output .= "" . __('Next >', 'wpsc') . ""; + } + // Should we show the LAST PAGE link? + if($current_page < $totalpages) { + $output .= "" . __('Last »', 'wpsc') . ""; + } + } else { + // Should we show the FIRST PAGE link? + if($current_page > 1) + $output .= "" . __('« First', 'wpsc') . ""; + + // Should we show the PREVIOUS PAGE link? + if($current_page > 1) { + $previous_page = $current_page - 1; + if( $previous_page == 1 ) + $output .= " " . __('< Previous', 'wpsc') . ""; + else + $output .= " " . __('< Previous', 'wpsc') . ""; + } + $i =$current_page - $num_paged_links; + $count = 1; + if($i <= 0) $i =1; + while($i < $current_page){ + if($count <= $num_paged_links){ + if($i == 1) + $output .= " ".$i.""; + else + $output .= " ".$i.""; + } + $i++; + $count++; + } + // Current Page Number + if($current_page > 0) + $output .= "$current_page"; + + //Links after Current Page + $i = $current_page + $num_paged_links; + $count = 1; + + if($current_page < $totalpages){ + while(($i) > $current_page){ + + if($count < $num_paged_links && ($count+$current_page) <= $totalpages){ + $output .= " ".($count+$current_page).""; + $i++; + }else{ + break; + } + $count ++; + } + } + + if($current_page < $totalpages) { + $next_page = $current_page + 1; + $output .= "" . __('Next >', 'wpsc') . ""; + } + // Should we show the LAST PAGE link? + if($current_page < $totalpages) { + $output .= "" . __('Last »', 'wpsc') . ""; + } + } + // Return the output. + echo apply_filters( 'wpsc_pagination', $output, $totalpages, $per_page, $current_page, $page_link ); +} + +/** + * wpsc_show_stock_availability + * + * Checks to see whether stock symbols need to be shown + * @return boolean - true is the option has been checked false otherwise + */ +function wpsc_show_stock_availability(){ + if( get_option('list_view_quantity') == 1 ) + return true; + else + return false; +} + +/** + * wpsc product image function + * + * if no parameters are passed, the image is not resized, otherwise it is resized to the specified dimensions + * + * @param integer attachment_ID + * @param integer width + * @param integer height + * @return string - the product image URL, or the URL of the resized version + */ +function wpsc_product_image( $attachment_id = 0, $width = null, $height = null ) { + // Do some dancing around the image size + if ( ( ( $width >= 10 ) && ( $height >= 10 ) ) && ( ( $width <= 1024 ) && ( $height <= 1024 ) ) ) + $intermediate_size = "wpsc-{$width}x{$height}"; + + // Get image url if we have enough info + if ( ( $attachment_id > 0 ) && ( !empty( $intermediate_size ) ) ) { + + // Get all the required information about the attachment + $uploads = wp_upload_dir(); + $image_meta = get_post_meta( $attachment_id, '' ); + $file_path = get_attached_file( $attachment_id ); + + // Clean up the meta array + foreach ( $image_meta as $meta_name => $meta_value ) + $image_meta[$meta_name] = maybe_unserialize( array_pop( $meta_value ) ); + + + $attachment_metadata = $image_meta['_wp_attachment_metadata']; + // Determine if we already have an image of this size + if ( isset( $attachment_metadata['sizes'] ) && (count( $attachment_metadata['sizes'] ) > 0) && ( isset( $attachment_metadata['sizes'][$intermediate_size] ) ) ) { + $intermediate_image_data = image_get_intermediate_size( $attachment_id, $intermediate_size ); + $image_url = $intermediate_image_data['url']; + } else { + $image_url = home_url( "index.php?wpsc_action=scale_image&attachment_id={$attachment_id}&width=$width&height=$height" ); + } + // Not enough info so attempt to fallback + } else { + + if ( !empty( $attachment_id ) ) { + $image_url = home_url( "index.php?wpsc_action=scale_image&attachment_id={$attachment_id}&width=$width&height=$height" ); + } else { + $image_url = false; + } + + } + if(empty($image_url) && !empty($file_path)){ + $image_meta = get_post_meta( $attachment_id, '_wp_attached_file' ); + if ( ! empty( $image_meta ) ) + $image_url = $uploads['baseurl'].'/'.$image_meta[0]; + } + if( is_ssl() ) str_replace('http://', 'https://', $image_url); + + return apply_filters( 'wpsc_product_image', $image_url ); +} + +function wpsc_product_no_image_fallback( $image_url = '' ) { + if ( !empty( $image_url ) ) + return $image_url; + else + return apply_filters( 'wpsc_product_noimage', WPSC_CORE_THEME_URL . 'wpsc-images/noimage.png' ); +} +add_filter( 'wpsc_product_image', 'wpsc_product_no_image_fallback' ); + + +/** + * wpsc show pnp function + * @return boolean - true if display_pnp is 1 false otherwise + */ +function wpsc_show_pnp(){ + global $post; + if(1 == get_option('display_pnp')) + return true; + return false; +} + +/** + * wpsc product price function + * @return string - the product price + */ +function wpsc_the_product_price( $no_decimals = false, $only_normal_price = false, $product_id = 0 ) { + global $wpsc_query, $wpsc_variations, $wpdb; + + if ( ! $product_id ) + $product_id = get_the_ID(); + + if ( wpsc_product_has_variations( $product_id ) ) { + $from_text = __( ' from %s', 'wpsc' ); + $from_text = apply_filters( 'wpsc_product_variation_text', $from_text ); + $output = wpsc_product_variation_price_available( $product_id, $from_text, $only_normal_price ); + } else { + $price = $full_price = get_post_meta( $product_id, '_wpsc_price', true ); + + if ( ! $only_normal_price ) { + $special_price = get_post_meta( $product_id, '_wpsc_special_price', true ); + + if ( ( $full_price > $special_price ) && ( $special_price > 0 ) ) + $price = $special_price; + } + + if ( $no_decimals == true ) + $price = array_shift( explode( ".", $price ) ); + + $price = apply_filters( 'wpsc_do_convert_price', $price, $product_id ); + $args = array( + 'display_as_html' => false, + 'display_decimal_point' => ! $no_decimals + ); + $output = wpsc_currency_display( $price, $args ); + } + return $output; +} + +/** + * wpsc display categories function + * Used to determine whether to display products on the page + * @return boolean - true for yes, false for no + */ +function wpsc_display_categories() { + global $wp_query; + $output = false; + if ( !is_numeric( get_option( 'wpsc_default_category' ) ) && ! get_query_var( 'product_tag' ) ) { + + if ( isset( $wp_query->query_vars['products'] ) ) + $category_id = $wp_query->query_vars['products']; + else if ( isset( $_GET['products'] ) ) + $category_id = $_GET['products']; + + // if we have no categories, and no search, show the group list + if ( is_numeric( get_option( 'wpsc_default_category' ) ) || (isset( $product_id ) && is_numeric( $product_id )) ) + $output = true; + if ( (get_option( 'wpsc_default_category' ) == 'all+list')) + $output = true; + + if (get_option( 'wpsc_default_category' ) == 'list' && (!isset($wp_query->query_vars['wpsc_product_category']) || !isset($wp_query->query_vars['product_tag']) && get_option('wpsc_display_categories'))) + $output = true; + + } + + if ( isset( $category_id ) && $category_id > 0 ) + $output = false; + if ( get_option( 'wpsc_display_categories' )) + $output = true; + + return $output; +} + +/** + * wpsc product creation time function + * @return string - the product price + */ +function wpsc_product_creation_time( $format = null ) { + global $wpsc_query; + + if ( $format == null ) + $format = "Y-m-d H:i:s"; + + return mysql2date( $format, $wpsc_query->product['date_added'] ); +} + +/** + * wpsc check variation stock availability function + * @return string - the product price + */ +function wpsc_check_variation_stock_availability( $product_id, $variations ) { + global $wpdb; + $selected_post = get_posts( array( + 'post_parent' => $product_id, + 'post_type' => "wpsc-product", + 'post_status' => 'any', + 'suppress_filters' => true, + 'numberposts' => -1, + ) ); + + $selected_variation = false; + + foreach ( $selected_post as $variation ) { + $matches = 0; + $terms = wpsc_get_product_terms( $variation->ID, 'wpsc-variation' ); + foreach ( $terms as $term ) { + if ( in_array( $term->term_id, $variations ) ) + $matches++; + } + + if ( $matches == count( $variations ) ) { + $selected_variation = $variation->ID; + } + } + + if ( ! $selected_variation ) + return false; + + if ( wpsc_product_has_stock( $selected_variation ) ) { + $stock = get_product_meta( $selected_variation, 'stock', true ); + if ( $stock === '' ) + return true; + + return (int) $stock; + } + + return 0; +} + +/** + * wpsc product has stock function + * @return boolean - true if the product has stock or does not use stock, false if it does not + */ +function wpsc_product_has_stock( $id = null ) { + global $wpdb; + // maybe do wpsc_clear_stock_claims first? + if ( is_numeric( $id ) && ( $id > 0 ) ) + $id = absint( $id ); + else + $id = get_the_ID(); + + $stock = get_post_meta( $id, '_wpsc_stock', true ); + if ( $stock === '' ) + return true; + + $variations = get_children( array( "post_type" => "wpsc-product", "post_parent" => $id ) ); + $filter_name = empty( $variations ) ? 'wpsc_product_stock' : 'wpsc_product_variation_stock'; + $stock = apply_filters( $filter_name, (int) $stock, $id ); + + if ( ! empty( $variations ) ) { + foreach ( $variations as $variation ) { + if ( wpsc_product_has_stock( $variation->ID ) ) + return true; + } + } elseif ( $stock > 0 ) { + $claimed_stock = $wpdb->get_var("SELECT SUM(`stock_claimed`) FROM `".WPSC_TABLE_CLAIMED_STOCK."` WHERE `product_id` IN($id)"); + if( $stock - $claimed_stock > 0 ) + return true; + } + + return false; +} + +/** + * wpsc_is_product_external( $product_id = 0 ) + * + * Checks if current product is external. + * + * @param int $product_id + */ +function wpsc_is_product_external( $product_id = 0 ) { + + // Get product ID if incorrect value was passed + if ( empty( $product_id ) || !is_numeric( $product_id ) ) + $product_id = wpsc_the_product_id(); + + // Get external link + $external_link = wpsc_product_external_link( $product_id ); + + // Use external if set + if ( !empty( $external_link ) ) + return true; + else + return false; +} + +/** + * wpsc product remaining stock function + * @return integer - the amount of remaining stock, or null if product is stockless + */ +function wpsc_product_remaining_stock( $id = null ) { + if ( is_numeric( $id ) && ($id > 0) ) + $id = absint( $id ); + else + $id = get_the_ID(); + + $is_limited_stock = get_post_meta( $id, '_wpsc_stock', true ); + + if ( is_numeric( $is_limited_stock ) ) { + $product_stock = get_post_meta( $id, '_wpsc_stock', true ); + return absint( $product_stock ); + } else { + return null; + } +} + +/** + * wpsc is donation function + * @return boolean - true if it is a donation, otherwise false + */ +function wpsc_product_is_donation( $id = null ) { + if ( is_numeric( $id ) && ($id > 0) ) + $id = absint( $id ); + else + $id = get_the_ID(); + + $is_donation = get_post_meta( $id, '_wpsc_is_donation', true ); + if ( $is_donation == 1 ) + return true; + else + return false; + +} + +/** + * wpsc product on special function + * @return boolean - true if the product is on special, otherwise false + */ +function wpsc_product_on_special( $id = 0 ) { + static $on_special = array(); + + global $wpsc_query, $wpdb; + + if ( ! $id ) + $id = get_the_ID(); + + if ( ! isset( $on_special[$id] ) ) { + // don't rely on product sales price if it has variations + if ( wpsc_product_has_variations( $id ) ) { + $sql = $wpdb->prepare(" + SELECT p.id, CAST(pm.meta_value AS DECIMAL(10, 2)) AS sale_price + FROM {$wpdb->posts} AS p + INNER JOIN {$wpdb->postmeta} AS pm ON pm.post_id = p.id AND pm.meta_key = '_wpsc_special_price' AND pm.meta_value != '0' AND pm.meta_value != '' + INNER JOIN {$wpdb->postmeta} AS pm2 ON pm2.post_id = p.id AND pm2.meta_key = '_wpsc_stock' AND pm2.meta_value != '0' + INNER JOIN {$wpdb->postmeta} AS pm3 ON pm3.post_id = p.id AND pm3.meta_key = '_wpsc_price' AND CAST(pm3.meta_value AS DECIMAL(10,2)) > CAST(pm.meta_value AS DECIMAL(10,2)) + WHERE + p.post_type = 'wpsc-product' + AND + p.post_parent = %d + ORDER BY sale_price ASC + ", $id ); + + $results = $wpdb->get_results( $sql ); + + $on_special[$id] = ! empty( $results ); + } else { + $price = get_product_meta( $id, 'price', true ); + $special_price = get_product_meta( $id, 'special_price', true ); + $on_special[$id] = $special_price > 0 && $price > $special_price; + } + } + + return $on_special[$id]; +} + +/** + * wpsc product is modifiable function + * @return boolean - true if the product has a file + */ +function wpsc_product_is_customisable() { + global $wpsc_query, $wpdb; + $id = get_the_ID(); + $product_meta = get_post_meta( $id, '_wpsc_product_metadata', true ); + if ( (isset($product_meta['engraved']) && $product_meta['engraved'] == true) || (isset($product_meta['can_have_uploaded_image']) && $product_meta['can_have_uploaded_image'] == true) ) + return true; + + return false; +} + +/** + * wpsc product has personal text function + * @return boolean - true if the product has a file + */ +function wpsc_product_has_personal_text() { + global $wpsc_query, $wpdb; + $id = get_the_ID(); + $product_meta = get_post_meta( $id, '_wpsc_product_metadata', true ); + if ( isset($product_meta['engraved']) && $product_meta['engraved'] == true ) + return true; + + return false; +} + +/** + * wpsc product has personal file function + * @return boolean - true if the product has a file + */ +function wpsc_product_has_supplied_file() { + global $wpsc_query, $wpdb; + $id = get_the_ID(); + $product_meta = get_post_meta( $id, '_wpsc_product_metadata', true ); + if ( isset($product_meta['can_have_uploaded_image']) && $product_meta['can_have_uploaded_image'] == true ) + return true; + + return false; +} + +/** + * wpsc product postage and packaging function + * @return string - currently only valid for flat rate + */ +function wpsc_product_postage_and_packaging() { + if ( isset( $id ) && is_numeric( $id ) && ($id > 0) ) + $id = absint( $id ); + else + $id = get_the_ID(); + + $product_meta = get_post_meta( $id, '_wpsc_product_metadata', true ); + if ( isset( $product_meta['shipping'] ) && is_array( $product_meta['shipping'] ) && 1 != $product_meta['no_shipping']) + return wpsc_currency_display( apply_filters( 'wpsc_product_postage_and_packaging', $product_meta['shipping']['local'] ) ); + else + return wpsc_currency_display( 0 ); + + +} + +/** + * WPSC Product Image + * + * Gets the product image URL. Uses the post thumbnail if set. + * + * @param int $width Image width + * @param int $height Image height + * @param int $product_id Product ID + * @return string The URL to the thumbnail image + * + * @uses wpsc_the_product_thumbnail_id() Get the product thumbnail ID + */ +function wpsc_the_product_image( $width = '', $height = '', $product_id = '' ) { + if ( empty( $product_id ) ) + $product_id = get_the_ID(); + + // If variation, get parent product + $product = get_post( $product_id ); + if ( $product->post_parent > 0 ) + $product_id = $product->post_parent; + + $src = false; + + $product_thumbnail_id = wpsc_the_product_thumbnail_id( $product_id ); + $src = wp_get_attachment_image_src( $product_thumbnail_id, 'large' ); + $src = is_array( $src ) ? $src[0] : $src; + + if ( is_ssl() && ! empty( $src ) ) + $src = str_replace( 'http://', 'https://', $src ); + + // 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 + $src = str_replace( ' ', '%20', $src ); + + return apply_filters( 'wpsc_product_image', $src ); +} + +/** + * wpsc check display type + * + * Check the display view for the selected category + * + * @return string - display type + */ +function wpsc_check_display_type(){ + global $wpsc_query, $post; + if(isset($wpsc_query->query_vars['taxonomy']) && 'wpsc_product_category' == $wpsc_query->query_vars['taxonomy'] && is_string($wpsc_query->query_vars['term']) && 1 < $wpsc_query->post_count) + $display_type = wpsc_get_the_category_display($wpsc_query->query_vars['term']); + else + $display_type = get_option('product_view'); + return $display_type; +} + +/** + * 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 it's parent image (props. TJM) + if ( ! $thumbnail_id && $product->post_parent ) + $thumbnail_id = wpsc_the_product_thumbnail_id( $product->post_parent ); + + if ( ! $page ) { + if ( is_single() ) + $page = 'single'; + else + $page = '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'; + $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', 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 ); + + // 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 $thumbnail; +} + +/** + * Return the class(es) that should be applied to a product image's tag. + * + * If the thickbox effect is enabled for product images (presentation setting), the thickbox class name is included + * + * This function is called from theme files when outputting product img tags + * + * @since 3.8 + * @return string space-separated list of class names (for use in a class="") attribute + */ +function wpsc_the_product_image_link_classes() { + $classes = array( ); + if ( get_option( 'show_thumbnails_thickbox' ) ) + $classes[] = 'thickbox'; + + $classes[] = 'preview_link'; + + $classes = apply_filters( 'wpsc_the_product_image_link_classes', $classes ); + return implode( ' ', $classes ); +} + +/** + * wpsc product comment link function + * @return string - javascript required to make the intense debate link work + */ +function wpsc_product_comment_link() { + // add the product comment link + global $wpsc_query; + + if ( get_option( 'wpsc_enable_comments' ) == 1 ) { + $enable_for_product = get_product_meta( get_the_ID(), 'enable_comments' ); + + if ( (get_option( 'wpsc_comments_which_products' ) == 1 && $enable_for_product == '') || $enable_for_product == 'yes' ) { + $original = array( "&", "'", ":", "/", "@", "?", "=" ); + $entities = array( "%26", "%27", "%3A", "%2F", "%40", "%3F", "%3D" ); + + $output = "
+ +
"; + } + } + return $output; +} + +/** + * wpsc product comments function + * @return string - javascript for the intensedebate comments + */ +function wpsc_product_comments() { + global $wpsc_query; + $output = ''; + // add the product comments + if ( get_option( 'wpsc_enable_comments' ) == 1 ) { + $enable_for_product = get_product_meta( $wpsc_query->product['id'], 'enable_comments' ); + + if ( (get_option( 'wpsc_comments_which_products' ) == 1 && $enable_for_product == '') || $enable_for_product == 'yes' ) { + $output = " + + + "; + } + } + return $output; +} + +/** + * wpsc have custom meta function + * @return boolean - true while we have custom meta to display + */ +function wpsc_have_custom_meta() { + global $wpsc_custom_meta; + return esc_html( $wpsc_custom_meta->have_custom_meta() ); +} + +/** + * wpsc the custom meta function + * @return nothing - iterate through the custom meta vallues + */ +function wpsc_the_custom_meta() { + global $wpsc_custom_meta; + return esc_html( $wpsc_custom_meta->the_custom_meta() ); +} + +/** + * wpsc custom meta name function + * @return string - the custom metal name + */ +function wpsc_custom_meta_name() { + global $wpsc_custom_meta; + return esc_html( $wpsc_custom_meta->custom_meta_values['meta_key'] ); +} + +/** + * wpsc custom meta value function + * @return string - the custom meta value + */ +function wpsc_custom_meta_value() { + global $wpsc_custom_meta; + return esc_html( $wpsc_custom_meta->custom_meta_values['meta_value'] ); +} + +/** + * wpsc have variation groups function + * @return boolean - true while we have variation groups + */ +function wpsc_have_variation_groups() { + global $wpsc_variations; + return $wpsc_variations->have_variation_groups(); +} + +/** + * wpsc the variation group function + * @return nothing - iterate through the variation groups + */ +function wpsc_the_variation_group() { + global $wpsc_variations; + $wpsc_variations->the_variation_group(); +} + +/** + * wpsc have variations function + * @return boolean - true while we have variations + */ +function wpsc_have_variations() { + global $wpsc_variations; + return $wpsc_variations->have_variations(); +} + +/** + * wpsc the variation function + * @return nothing - iterate through the variations + */ +function wpsc_the_variation() { + global $wpsc_variations; + $wpsc_variations->the_variation(); +} + + +function wpsc_product_has_multicurrency() { + global $wpdb, $wpsc_query; + + $currency = get_product_meta(get_the_ID(),'currency',true); + if ( ! empty( $currency ) ) + return true; + else + return false; +} + +function wpsc_display_product_multicurrency() { + global $wpdb, $wpsc_query; + + $results = get_product_meta(get_the_ID(),'currency',true); + if ( count( $results ) > 0 ) { + foreach ( (array)$results as $isocode => $curr ) { + echo apply_filters( 'wpsc_display_product_multicurrency', '' . $isocode . ': ' . wpsc_currency_display( $curr, array( 'isocode' => $isocode ) ) . '
', $isocode, $curr ); + } + } + + return false; +} + +/** + * wpsc variation group name function + * @return string - the variation group name + */ +function wpsc_the_vargrp_name() { + global $wpsc_variations; + return apply_filters( 'wpsc_vargrp_name', $wpsc_variations->variation_group->name, $wpsc_variations->variation_group ); +} + +/** + * wpsc variation group form ID function + * @return string - the variation group form id, for labels and the like + */ +function wpsc_vargrp_form_id() { + // generate the variation group form ID; + global $wpsc_variations, $wpsc_variations; + $product_id = get_the_ID(); + $form_id = "variation_select_{$product_id}_{$wpsc_variations->variation_group->term_id}"; + return $form_id; +} + +/** + * wpsc variation group ID function + * @return integer - the variation group ID + */ +function wpsc_vargrp_id() { + global $wpsc_variations; + return $wpsc_variations->variation_group->term_id; +} + +/** + * wpsc the variation name function + * @return string - the variation name + */ +function wpsc_the_variation_name() { + global $wpsc_variations; + return esc_html( apply_filters( 'wpsc_variation_name', $wpsc_variations->variation->name ) ); +} + +/** + * wpsc the variation ID function + * @return integer - the variation ID + */ +function wpsc_the_variation_id() { + global $wpsc_variations; + return $wpsc_variations->variation->term_id; +} + +/** + * wpsc the variation out_of_stock function + * @return string - HTML attribute to disable select options and radio buttons + */ +function wpsc_the_variation_out_of_stock() { + global $wpsc_query, $wpdb, $wpsc_variations; + $out_of_stock = false; + + // If there is more than one variation group we cannot determine a stock status for individual variations + // Also, if the item is not stock limited, there is no need to check variation stock status + $product_id = get_the_ID(); + + $stock = get_product_meta( $product_id, 'stock', true ); + if ( ($wpsc_variations->variation_group_count == 1) && is_numeric( $stock ) && isset( $wpsc_variations->variation->slug ) ) { + + $product_id = get_the_ID(); + $variation_group_id = $wpsc_variations->variation_group->term_id; + $variation_id = $wpsc_variations->variation->term_id; + + $wpq = array( 'variations' => $wpsc_variations->variation->slug, + 'post_status' => 'inherit', + 'post_type' => 'wpsc-product', + 'post_parent' => $product_id ); + $query = new WP_Query( $wpq ); + + if ( $query->post_count != 1 ) { + // Should never happen + return FALSE; + } + + $variation_product_id = $query->posts[0]->ID; + + $stock = get_product_meta( $variation_product_id, "stock" ); + $stock = $stock[0]; + if ( $stock < 1 ) { + $out_of_stock = true; + } + } + + if ( $out_of_stock == true ) + return "disabled='disabled'"; + else + return ''; + +} + +/** + * wpsc product rater function + * @return string - HTML to display the product rater + */ +function wpsc_product_rater() { + global $wpsc_query; + $product_id = get_the_ID(); + $output = ''; + if ( get_option( 'product_ratings' ) == 1 ) { + $output .= ""; + } + return $output; +} + +function wpsc_product_existing_rating( $product_id ) { + global $wpdb; + $get_average = $wpdb->get_results( $wpdb->prepare( "SELECT AVG(`rated`) AS `average`, COUNT(*) AS `count` FROM `" . WPSC_TABLE_PRODUCT_RATING . "` WHERE `productid`= %d ", $product_id ), ARRAY_A ); + $average = floor( $get_average[0]['average'] ); + $count = $get_average[0]['count']; + $output = " "; + for ( $l = 1; $l <= $average; ++$l ) { + $output .= "$l"; + } + $remainder = 5 - $average; + for ( $l = 1; $l <= $remainder; ++$l ) { + $output .= "$l"; + } + $output .= " (" . $count . ") \r\n"; + $output .= " \r\n"; + return $output; +} + +function wpsc_product_new_rating( $product_id ) { + global $wpdb; + + $cookie_data = ''; + if (isset($_COOKIE['voting_cookie'][$product_id])) { + $cookie_data = explode( ",", $_COOKIE['voting_cookie'][$product_id] ); + } + + $vote_id = 0; + + if ( isset($cookie_data[0]) && is_numeric( $cookie_data[0] ) ) + $vote_id = absint( $cookie_data[0] ); + + $previous_vote = 1; + if ( $vote_id > 0 ) + $previous_vote = $wpdb->get_var( "SELECT `rated` FROM `" . WPSC_TABLE_PRODUCT_RATING . "` WHERE `id`='" . $vote_id . "' LIMIT 1" ); + + $output = "
\n"; + $output .= " \n"; + $output .= " \n"; + $output .= " \n"; + $output .= " "; + $output .= "
"; + return $output; +} + +/** + * wpsc has pages function + * @return boolean - true if we have pages + */ +function wpsc_has_pages() { + if(1 == get_option('use_pagination')) + return true; + else + return false; + +} + +/** + * this is for the multi adding property, it checks to see whether multi adding is enabled; + * + */ +function wpsc_has_multi_adding() { + if ( get_option( 'multi_add' ) == 1 && (get_option( 'addtocart_or_buynow' ) != 1) ) { + return true; + } else { + return false; + } +} + +/** + * wpsc product count function + * @return string - the page URL + */ +function wpsc_product_count() { + global $wp_query; + return count($wp_query->posts); +} + +//The following code was removed from WP 3.8, present in 3.7 - Not sure why it was removed and not refactored. (JS) + +/** + * wpsc the variation price function + * @return string - the variation price + */ +function wpsc_the_variation_price( $return_as_numeric = false ) { + global $wpdb, $wpsc_variations; + if ( $wpsc_variations->variation_count > 0 ) { + + $product_id = get_the_ID(); + $wpq = array( + 'variations' => $wpsc_variations->variation->slug, + 'post_status' => array( 'inherit', 'publish' ), + 'post_type' => 'wpsc-product', + 'post_parent' => $product_id + ); + + $query = new WP_Query( $wpq ); + // Should never happen + if ( $query->post_count != 1 ) + return false; + + $variation_product_id = $query->posts[0]->ID; + + $price = get_product_meta( $variation_product_id, 'price',true ); + $special_price = get_product_meta( $variation_product_id, 'special_price', true ); + + if ( $special_price < $price && $special_price > 0 ) + $price = $special_price; + + $price = apply_filters( 'wpsc_do_convert_price', $price, $product_id, $variation_product_id ); + $output = $return_as_numeric ? $price : wpsc_currency_display( $price, array( 'display_as_html' => false ) ); + } else { + $output = false; + } + + return $output; +} + +/** + * wpsc the variation stock function + * @return mixed - Stock level for the variation or FALSE if it can't be calculated + */ +function wpsc_the_variation_stock() { + global $wpdb, $wpsc_variations; + + if ( $wpsc_variations->variation_count > 0 ) { + + $product_id = get_the_ID(); + + $wpq = array( 'variations' => $wpsc_variations->variation->slug, + 'post_status' => 'inherit', + 'post_type' => 'wpsc-product', + 'post_parent' => $product_id ); + + $query = new WP_Query( $wpq ); + + // Should never happen + if ( $query->post_count != 1 ) + return false; + + // Get the stock count + $vp_id = $query->posts[0]->ID; + $stock = get_product_meta( $vp_id, "stock" ); + $stock[0] = apply_filters( 'wpsc_product_variation_stock', $stock[0], $id ); + $output = $stock[0]; + } else { + return false; + } + + return $output; +} + +/** + * wpsc_category_grid_view function + * @return bool - whether the category is in grid view or not + */ +function wpsc_category_grid_view(){ + if(get_option('wpsc_category_grid_view') == 1) + return true; + else + return false; +} + +/** + * wpsc_show_thumbnails function + * @return bool - whether to show thumbnails or not + */ +function wpsc_show_thumbnails(){ + return get_option('show_thumbnails'); +} + +/** + * gold_cart_display_gallery function + * @return bool - whether to show gold cart gallery or not + */ +function gold_cart_display_gallery(){ + return function_exists('gold_shpcrt_display_gallery'); +} + +function wpsc_remove_currency_code( $args ) { + + $args['display_currency_symbol'] = false; + $args['display_currency_code'] = false; + + return $args; +} + +function wpsc_you_save( $args = null ){ + + $defaults = array( + 'product_id' => false, + 'type' => 'percentage', + 'variations' => false + ); + + $args = wp_parse_args( $args, $defaults ); + extract( $args, EXTR_SKIP ); + + global $wpdb; + + if ( ! $product_id ) + if(function_exists('wpsc_the_product_id')){ + //select the variation ID with lowest price + $product_id = $wpdb->get_var('SELECT `posts`.`id` FROM ' . $wpdb->posts . ' `posts` JOIN ' . $wpdb->postmeta . ' `postmeta` ON `posts`.`id` = `postmeta`.`post_id` WHERE `posts`.`post_parent` = ' . wpsc_the_product_id() . ' AND `posts`.`post_type` = "wpsc-product" AND `posts`.`post_status` = "inherit" AND `postmeta`.`meta_key`="_wpsc_price" ORDER BY (`postmeta`.`meta_value`)+0 ASC LIMIT 1'); + if(!$product_id) + $product_id=wpsc_the_product_id(); + } + + if ( ! $product_id ) + return 0; + + $regular_price = wpsc_calculate_price( $product_id, $variations, false ); + $sale_price = wpsc_calculate_price( $product_id, $variations, true ); + + switch( $type ){ + case "amount": + return $regular_price - $sale_price; + break; + + default: + if ( $regular_price == 0 ) + return 0; + else + return number_format( ( $regular_price - $sale_price ) / $regular_price * 100, 2 ); + } +} + +function wpsc_the_product_price_display( $args = array() ) { + if ( empty( $args['id'] ) ) + $id = get_the_ID(); + else + $id = (int) $args['id']; + + $defaults = array( + 'id' => $id, + 'old_price_text' => __( 'Old Price: %s', 'wpsc' ), + 'price_text' => __( 'Price: %s', 'wpsc' ), + /* translators : %1$s is the saved amount text, %2$s is the saved percentage text, %% is the percentage sign */ + 'you_save_text' => __( 'You save: %s', 'wpsc' ), + 'old_price_class' => 'pricedisplay wpsc-product-old-price ' . $id, + 'old_price_before' => '

', + 'old_price_after' => '

', + 'old_price_amount_id' => 'old_product_price_' . $id, + 'old_price_amount_class' => 'oldprice', + 'old_price_amount_before' => '', + 'old_price_amount_after' => '', + 'price_amount_id' => 'product_price_' . $id, + 'price_class' => 'pricedisplay wpsc-product-price ' . $id, + 'price_before' => '

', + 'price_after' => '

', + 'price_amount_class' => 'currentprice pricedisplay ' . $id, + 'price_amount_before' => '', + 'price_amount_after' => '', + 'you_save_class' => 'pricedisplay wpsc-product-you-save product_' . $id, + 'you_save_before' => '

', + 'you_save_after' => '

', + 'you_save_amount_id' => 'yousave_' . $id, + 'you_save_amount_class' => 'yousave', + 'you_save_amount_before' => '', + 'you_save_amount_after' => '', + 'output_price' => true, + 'output_old_price' => true, + 'output_you_save' => true, + ); + + $r = wp_parse_args( $args, $defaults ); + extract( $r ); + + // if the product has no variations, these amounts are straight forward... + $old_price = wpsc_product_normal_price( $id ); + $current_price = wpsc_the_product_price( false, false, $id ); + $you_save = wpsc_you_save( 'type=amount' ) . '! (' . wpsc_you_save() . '%)'; + $you_save_percentage = wpsc_you_save(); + + $show_old_price = $show_you_save = wpsc_product_on_special( $id ); + + // but if the product has variations and at least one of the variations is on special, we have + // a few edge cases... + if ( wpsc_product_has_variations( $id ) && wpsc_product_on_special( $id ) ) { + // generally it doesn't make sense to display "you save" amount unless the user has selected + // a specific variation + $show_you_save = false; + + $old_price_number = wpsc_product_variation_price_available( $id, false, true ); + $current_price_number = wpsc_product_variation_price_available( $id, false, false ); + + // if coincidentally, one of the variations are not on special, but its price is equal to + // or lower than the lowest variation sale price, old price should be hidden, and current + // price should reflect the "normal" price, not the sales price, to avoid confusion + if ( $old_price_number == $current_price_number ) { + $show_old_price = false; + $current_price = wpsc_product_normal_price( $id ); + } + } + + // replace placeholders in arguments with correct values + $old_price_class = apply_filters( 'wpsc_the_product_price_display_old_price_class', $old_price_class, $id ); + $old_price_amount_class = apply_filters( 'wpsc_the_product_price_display_old_price_amount_class', $old_price_amount_class, $id ); + $attributes = 'class="' . esc_attr( $old_price_class ) . '"'; + if ( ! $show_old_price ) + $attributes .= ' style="display:none;"'; + $old_price_before = sprintf( $old_price_before, $attributes ); + $old_price_amount_before = sprintf( $old_price_amount_before, esc_attr( $old_price_amount_class ), esc_attr( $old_price_amount_id ) ); + + $price_class = 'class="' . esc_attr( apply_filters( 'wpsc_the_product_price_display_price_class', esc_attr( $price_class ), $id ) ) . '"'; + $price_amount_class = apply_filters( 'wpsc_the_product_price_display_price_amount_class', esc_attr( $price_amount_class ), $id ); + $price_before = sprintf( $price_before, $price_class ); + $price_amount_before = sprintf( $price_amount_before, esc_attr( $price_amount_class ), esc_attr( $price_amount_id ) ); + + $you_save_class = apply_filters( 'wpsc_the_product_price_display_you_save_class', $you_save_class, $id ); + $you_save_amount_class = apply_filters( 'wpsc_the_product_price_display_you_save_amount_class', $you_save_amount_class, $id ); + $attributes = 'class="' . esc_attr( $you_save_class ) . '"'; + if ( ! $show_you_save ) + $attributes .= ' style="display:none;"'; + $you_save_before = sprintf( $you_save_before, $attributes ); + $you_save_amount_before = sprintf( $you_save_amount_before, esc_attr( $you_save_amount_class ), esc_attr( $you_save_amount_id ) ); + $you_save = wpsc_currency_display ( $you_save ); + + $old_price = $old_price_amount_before . $old_price . $old_price_amount_after; + $current_price = $price_amount_before . $current_price . $price_amount_after; + $you_save = $you_save_amount_before . $you_save . $you_save_amount_after; + + $old_price_text = sprintf( $old_price_text, $old_price ); + $price_text = sprintf( $price_text, $current_price ); + $you_save_text = sprintf( $you_save_text, $you_save ); + + if ( $output_old_price ) + echo $old_price_before . $old_price_text . $old_price_after . "\n"; + + if ( $output_price ) + echo $price_before . $price_text . $price_after . "\n"; + + if ( $output_you_save ) + echo $you_save_before . $you_save_text . $you_save_after . "\n"; +} + +/** + * 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; + } + diff --git a/wpsc-components/theme-engine-v1/helpers/template.php b/wpsc-components/theme-engine-v1/helpers/template.php new file mode 100644 index 0000000000..9e50a388c8 --- /dev/null +++ b/wpsc-components/theme-engine-v1/helpers/template.php @@ -0,0 +1,283 @@ +is_product ) ) + $tmp = $wp_query->is_product; + + return $tmp; +} + +/** + * wpsc_is_product function. + * + * @since 3.8 + * @access public + * @return boolean + */ +function wpsc_is_checkout() { + global $wp_query, $rewrite_rules; + $tmp = false; + + if ( isset( $wp_query->is_checkout ) ) + $tmp = $wp_query->is_checkout; + + return $tmp; +} + +/** + * wpsc_get_product_template function. + * + * @since 3.8 + * @access public + * @return void + */ +function wpsc_get_template( $template ) { + return get_query_template( $template ); +} + +/** + * wpsc_product_template_fallback function. + * + * @since 3.8 + * @access public + * @param mixed $template_path + * @return string - the corrected template path + */ +function wpsc_template_fallback( $template_path ) { + + $prospective_file_name = basename( "{$template_path}.php" ); + $prospective_file_path = trailingslashit( WPSC_CORE_THEME_PATH ) . $prospective_file_name; + + if ( !file_exists( $prospective_file_path ) ) + exit( $prospective_file_path ); + + return $prospective_file_path; +} + +function wpsc_products_template_fallback() { + return wpsc_template_fallback( 'products' ); +} + +function wpsc_checkout_template_fallback() { + return wpsc_template_fallback( 'checkout' ); +} + +/** + * wpsc_template_loader function. + * + * @since 3.8 + * @access public + * @return void + */ +function wpsc_template_loader() { + global $wp_query; + + if ( wpsc_is_product() && $template = wpsc_get_template( 'products' ) ) { + include( $template ); + exit(); + } + + if ( wpsc_is_checkout() && $template = wpsc_get_template( 'checkout' ) ) { + include( $template ); + exit(); + } +} + +/** + * select_wpsc_theme_functions function, provides a place to override the e-commece theme path + * add to switch "theme's functions file + * © with xiligroup dev + */ +function wpsc_select_theme_functions() { + $selected_theme = get_option( 'wpsc_selected_theme' ); + if ( !empty( $selected_theme ) && file_exists( WPSC_CORE_THEME_PATH . '/' . WPSC_THEME_DIR . '.php' ) ) + include_once( WPSC_CORE_THEME_PATH . '/' . WPSC_THEME_DIR . '.php' ); +} + +/** + * Body Class Filter + * @modified: 2009-10-14 by Ben + * @description: Adds additional wpsc classes to the body tag. + * @param: $classes = Array of body classes + * @return: (Array) of classes + */ +function wpsc_body_class( $classes ) { + global $wp_query, $wpsc_query; + $post_id = 0; + if ( isset( $wp_query->post->ID ) ) + $post_id = $wp_query->post->ID; + $page_url = get_permalink( $post_id ); + + // If on a product or category page... + if ( get_option( 'product_list_url' ) == $page_url ) { + + $classes[] = 'wpsc'; + + if ( !is_array( $wpsc_query->query ) ) + $classes[] = 'wpsc-home'; + + if ( wpsc_is_single_product ( ) ) { + $classes[] = 'wpsc-single-product'; + if ( absint( $wpsc_query->products[0]['id'] ) > 0 ) { + $classes[] = 'wpsc-single-product-' . $wpsc_query->products[0]['id']; + } + } + + if ( wpsc_is_in_category() && !wpsc_is_single_product() ) + $classes[] = 'wpsc-category'; + + if ( isset( $wpsc_query->query_vars['category_id'] ) && absint( $wpsc_query->query_vars['category_id'] ) > 0 ) + $classes[] = 'wpsc-category-' . $wpsc_query->query_vars['category_id']; + + } + + // If viewing the shopping cart... + if ( get_option( 'shopping_cart_url' ) == $page_url ) { + $classes[] = 'wpsc'; + $classes[] = 'wpsc-shopping-cart'; + } + + // If viewing the transaction... + if ( get_option( 'transact_url' ) == $page_url ) { + $classes[] = 'wpsc'; + $classes[] = 'wpsc-transaction-details'; + } + + // If viewing your account... + if ( get_option( 'user_account_url' ) == $page_url ) { + $classes[] = 'wpsc'; + $classes[] = 'wpsc-user-account'; + } + + return $classes; +} + +/** + * Checks the active theme folder for the particular file, if it exists then return the active theme directory otherwise + * return the global wpsc_theme_path + * @access public + * + * @since 3.8 + * @param $file string filename + * @return PATH to the file + */ +function wpsc_get_template_file_path( $file = '' ){ + + // If we're not looking for a file, do not proceed + if ( empty( $file ) ) + return; + + // No cache, so find one and set it + if ( false === ( $file_path = get_transient( WPEC_TRANSIENT_THEME_PATH_PREFIX . $file ) ) ) { + // Look for file in stylesheet + if ( file_exists( get_stylesheet_directory() . '/' . $file ) ) { + $file_path = get_stylesheet_directory() . '/' . $file; + + // Look for file in template + } elseif ( file_exists( get_template_directory() . '/' . $file ) ) { + $file_path = get_template_directory() . '/' . $file; + + // Backwards compatibility + } else { + // Look in old theme path + $selected_theme_check = WPSC_OLD_THEMES_PATH . get_option( 'wpsc_selected_theme' ) . '/' . str_ireplace( 'wpsc-', '', $file ); + + // Check the selected theme + if ( file_exists( $selected_theme_check ) ) { + $file_path = $selected_theme_check; + + // Use the bundled file + } else { + $file_path = path_join( WPSC_CORE_THEME_PATH, $file ); + } + } + // Save the transient and update it every 12 hours + if ( !empty( $file_path ) ) + set_transient( WPEC_TRANSIENT_THEME_PATH_PREFIX . $file, $file_path, 60 * 60 * 12 ); + + }elseif(!file_exists($file_path)){ + delete_transient(WPEC_TRANSIENT_THEME_PATH_PREFIX . $file); + wpsc_get_template_file_path($file); + } + + // Return filtered result + return apply_filters( WPEC_TRANSIENT_THEME_PATH_PREFIX . $file, $file_path ); +} + +/** + * Featured Product + * + * Refactoring Featured Product Plugin to utilize Sticky Post Status, available since WP 2.7 + * also utilizes Featured Image functionality, available as post_thumbnail since 2.9, Featured Image since 3.0 + * Main differences - Removed 3.8 conditions, removed meta box from admin, changed meta_values + * Removes shortcode, as it automatically ties in to top_of_page hook if sticky AND featured product exists. + * + * @package wp-e-commerce + * @since 3.8 + */ +function wpsc_the_sticky_image( $product_id ) { + $attached_images = (array)get_posts( array( + 'post_type' => 'attachment', + 'numberposts' => 1, + 'post_status' => null, + 'post_parent' => $product_id, + 'orderby' => 'menu_order', + 'order' => 'ASC' + ) ); + if ( has_post_thumbnail( $product_id ) ) { + add_image_size( 'featured-product-thumbnails', 540, 260, TRUE ); + $image = get_the_post_thumbnail( $product_id, 'featured-product-thumbnails' ); + return $image; + } elseif ( !empty( $attached_images ) ) { + $attached_image = $attached_images[0]; + $image_link = wpsc_product_image( $attached_image->ID, 540, 260 ); + return ''; + } else { + return false; + } +} + +/** + * WPSC canonical URL function + * Needs a recent version + * @since 3.7 + * @param int product id + * @return bool true or false + */ +function wpsc_change_canonical_url( $url = '' ) { + global $wpdb, $wp_query, $wpsc_page_titles; + + if ( $wp_query->is_single == true && 'wpsc-product' == $wp_query->query_vars['post_type']) { + $url = get_permalink( $wp_query->get_queried_object()->ID ); + } + return apply_filters( 'wpsc_change_canonical_url', $url ); +} + +add_filter( 'aioseop_canonical_url', 'wpsc_change_canonical_url' ); + +function wpsc_insert_canonical_url() { + $wpsc_url = wpsc_change_canonical_url( null ); + echo "\n"; +} + +function wpsc_canonical_url() { + $wpsc_url = wpsc_change_canonical_url( null ); + if ( $wpsc_url != null ) { + remove_action( 'wp_head', 'rel_canonical' ); + add_action( 'wp_head', 'wpsc_insert_canonical_url' ); + } +} +add_action( 'template_redirect', 'wpsc_canonical_url' ); + diff --git a/wpsc-components/theme-engine-v1/helpers/thumbnails.php b/wpsc-components/theme-engine-v1/helpers/thumbnails.php new file mode 100644 index 0000000000..dfda2b753d --- /dev/null +++ b/wpsc-components/theme-engine-v1/helpers/thumbnails.php @@ -0,0 +1,68 @@ + get_option( 'product_image_width' ), + "height" => get_option( 'product_image_height' ), + "crop" => get_option( 'wpsc_crop_thumbnails', false ) + ); + $sizes['medium-single-product']=array( + "width" => get_option( 'single_view_image_width' ), + "height" => get_option( 'single_view_image_height' ), + "crop" => get_option( 'wpsc_crop_thumbnails', false ) + ); + $sizes['featured-product-thumbnails']=array( + "width" => 425, + "height" => 215, + "crop" => get_option( 'wpsc_crop_thumbnails', true ) + ); + $sizes['admin-product-thumbnails']=array( + "width" => 38, + "height" => 38, + "crop" => get_option( 'wpsc_crop_thumbnails', true ) + ); + $sizes['product-thumbnails']=array( + "width" => get_option( 'product_image_width' ), + "height" => get_option( 'product_image_height' ), + "crop" => get_option( 'wpsc_crop_thumbnails', false ) + ); + $sizes['gold-thumbnails']=array( + "width" => get_option( 'wpsc_gallery_image_width' ), + "height" => get_option( 'wpsc_gallery_image_height' ), + "crop" => get_option( 'wpsc_crop_thumbnails', false ) + ); + return $sizes; +} + +/** + * + * wpsc_core_load_thumbnail_sizes() + * + * Load up the WPEC core thumbnail sizes + * @todo Remove hardcoded sizes + */ +function wpsc_core_load_thumbnail_sizes() { + // Add image sizes for products + add_image_size( 'product-thumbnails', get_option( 'product_image_width' ), get_option( 'product_image_height' ), get_option( 'wpsc_crop_thumbnails', false ) ); + add_image_size( 'gold-thumbnails', get_option( 'wpsc_gallery_image_width' ), get_option( 'wpsc_gallery_image_height' ), get_option( 'wpsc_crop_thumbnails', false ) ); + add_image_size( 'admin-product-thumbnails', 38, 38, get_option( 'wpsc_crop_thumbnails', true ) ); + add_image_size( 'featured-product-thumbnails', 425, 215, get_option( 'wpsc_crop_thumbnails', true ) ); + add_image_size( 'small-product-thumbnail', get_option( 'product_image_width' ), get_option( 'product_image_height' ), get_option( 'wpsc_crop_thumbnails', false ) ); + add_image_size( 'medium-single-product', get_option( 'single_view_image_width' ), get_option( 'single_view_image_height' ), get_option( 'wpsc_crop_thumbnails', false) ); +} diff --git a/wpsc-includes/rss_template.php b/wpsc-components/theme-engine-v1/rss/rss.php old mode 100755 new mode 100644 similarity index 97% rename from wpsc-includes/rss_template.php rename to wpsc-components/theme-engine-v1/rss/rss.php index f147edacdf..e7cd35a4c6 --- a/wpsc-includes/rss_template.php +++ b/wpsc-components/theme-engine-v1/rss/rss.php @@ -15,7 +15,7 @@ ]]> ]]> ]]> - + diff --git a/wpsc-theme/compatibility.css b/wpsc-components/theme-engine-v1/templates/compatibility.css similarity index 100% rename from wpsc-theme/compatibility.css rename to wpsc-components/theme-engine-v1/templates/compatibility.css diff --git a/wpsc-theme/functions/wpsc-transaction_results_functions.php b/wpsc-components/theme-engine-v1/templates/functions/wpsc-transaction_results_functions.php similarity index 100% rename from wpsc-theme/functions/wpsc-transaction_results_functions.php rename to wpsc-components/theme-engine-v1/templates/functions/wpsc-transaction_results_functions.php diff --git a/wpsc-theme/functions/wpsc-user_log_functions.php b/wpsc-components/theme-engine-v1/templates/functions/wpsc-user_log_functions.php similarity index 100% rename from wpsc-theme/functions/wpsc-user_log_functions.php rename to wpsc-components/theme-engine-v1/templates/functions/wpsc-user_log_functions.php diff --git a/wpsc-theme/wpsc-account-downloads.php b/wpsc-components/theme-engine-v1/templates/wpsc-account-downloads.php similarity index 100% rename from wpsc-theme/wpsc-account-downloads.php rename to wpsc-components/theme-engine-v1/templates/wpsc-account-downloads.php diff --git a/wpsc-theme/wpsc-account-edit-profile.php b/wpsc-components/theme-engine-v1/templates/wpsc-account-edit-profile.php similarity index 100% rename from wpsc-theme/wpsc-account-edit-profile.php rename to wpsc-components/theme-engine-v1/templates/wpsc-account-edit-profile.php diff --git a/wpsc-theme/wpsc-account-purchase-history.php b/wpsc-components/theme-engine-v1/templates/wpsc-account-purchase-history.php similarity index 100% rename from wpsc-theme/wpsc-account-purchase-history.php rename to wpsc-components/theme-engine-v1/templates/wpsc-account-purchase-history.php diff --git a/wpsc-theme/wpsc-cart_widget.php b/wpsc-components/theme-engine-v1/templates/wpsc-cart_widget.php similarity index 100% rename from wpsc-theme/wpsc-cart_widget.php rename to wpsc-components/theme-engine-v1/templates/wpsc-cart_widget.php diff --git a/wpsc-theme/wpsc-category-list.php b/wpsc-components/theme-engine-v1/templates/wpsc-category-list.php similarity index 100% rename from wpsc-theme/wpsc-category-list.php rename to wpsc-components/theme-engine-v1/templates/wpsc-category-list.php diff --git a/wpsc-theme/wpsc-category_widget.php b/wpsc-components/theme-engine-v1/templates/wpsc-category_widget.php similarity index 100% rename from wpsc-theme/wpsc-category_widget.php rename to wpsc-components/theme-engine-v1/templates/wpsc-category_widget.php diff --git a/wpsc-theme/wpsc-default.css b/wpsc-components/theme-engine-v1/templates/wpsc-default.css similarity index 100% rename from wpsc-theme/wpsc-default.css rename to wpsc-components/theme-engine-v1/templates/wpsc-default.css diff --git a/wpsc-theme/wpsc-featured_product.php b/wpsc-components/theme-engine-v1/templates/wpsc-featured_product.php similarity index 100% rename from wpsc-theme/wpsc-featured_product.php rename to wpsc-components/theme-engine-v1/templates/wpsc-featured_product.php diff --git a/wpsc-theme/wpsc-grid_view.php b/wpsc-components/theme-engine-v1/templates/wpsc-grid_view.php similarity index 100% rename from wpsc-theme/wpsc-grid_view.php rename to wpsc-components/theme-engine-v1/templates/wpsc-grid_view.php diff --git a/wpsc-theme/wpsc-images/bulletpoint.gif b/wpsc-components/theme-engine-v1/templates/wpsc-images/bulletpoint.gif similarity index 100% rename from wpsc-theme/wpsc-images/bulletpoint.gif rename to wpsc-components/theme-engine-v1/templates/wpsc-images/bulletpoint.gif diff --git a/wpsc-theme/wpsc-images/cart.png b/wpsc-components/theme-engine-v1/templates/wpsc-images/cart.png similarity index 100% rename from wpsc-theme/wpsc-images/cart.png rename to wpsc-components/theme-engine-v1/templates/wpsc-images/cart.png diff --git a/wpsc-theme/wpsc-images/delete.png b/wpsc-components/theme-engine-v1/templates/wpsc-images/delete.png similarity index 100% rename from wpsc-theme/wpsc-images/delete.png rename to wpsc-components/theme-engine-v1/templates/wpsc-images/delete.png diff --git a/wpsc-theme/wpsc-images/gold-star.gif b/wpsc-components/theme-engine-v1/templates/wpsc-images/gold-star.gif similarity index 100% rename from wpsc-theme/wpsc-images/gold-star.gif rename to wpsc-components/theme-engine-v1/templates/wpsc-images/gold-star.gif diff --git a/wpsc-theme/wpsc-images/grey-star.gif b/wpsc-components/theme-engine-v1/templates/wpsc-images/grey-star.gif similarity index 100% rename from wpsc-theme/wpsc-images/grey-star.gif rename to wpsc-components/theme-engine-v1/templates/wpsc-images/grey-star.gif diff --git a/wpsc-theme/wpsc-images/icon_window_collapse.gif b/wpsc-components/theme-engine-v1/templates/wpsc-images/icon_window_collapse.gif similarity index 100% rename from wpsc-theme/wpsc-images/icon_window_collapse.gif rename to wpsc-components/theme-engine-v1/templates/wpsc-images/icon_window_collapse.gif diff --git a/wpsc-theme/wpsc-images/icon_window_expand.gif b/wpsc-components/theme-engine-v1/templates/wpsc-images/icon_window_expand.gif similarity index 100% rename from wpsc-theme/wpsc-images/icon_window_expand.gif rename to wpsc-components/theme-engine-v1/templates/wpsc-images/icon_window_expand.gif diff --git a/wpsc-theme/wpsc-images/indicator.gif b/wpsc-components/theme-engine-v1/templates/wpsc-images/indicator.gif similarity index 100% rename from wpsc-theme/wpsc-images/indicator.gif rename to wpsc-components/theme-engine-v1/templates/wpsc-images/indicator.gif diff --git a/wpsc-theme/wpsc-images/no_stock.gif b/wpsc-components/theme-engine-v1/templates/wpsc-images/no_stock.gif similarity index 100% rename from wpsc-theme/wpsc-images/no_stock.gif rename to wpsc-components/theme-engine-v1/templates/wpsc-images/no_stock.gif diff --git a/wpsc-theme/wpsc-images/noimage.png b/wpsc-components/theme-engine-v1/templates/wpsc-images/noimage.png similarity index 100% rename from wpsc-theme/wpsc-images/noimage.png rename to wpsc-components/theme-engine-v1/templates/wpsc-images/noimage.png diff --git a/wpsc-theme/wpsc-images/outofstock.png b/wpsc-components/theme-engine-v1/templates/wpsc-images/outofstock.png similarity index 100% rename from wpsc-theme/wpsc-images/outofstock.png rename to wpsc-components/theme-engine-v1/templates/wpsc-images/outofstock.png diff --git a/wpsc-theme/wpsc-images/sale.png b/wpsc-components/theme-engine-v1/templates/wpsc-images/sale.png similarity index 100% rename from wpsc-theme/wpsc-images/sale.png rename to wpsc-components/theme-engine-v1/templates/wpsc-images/sale.png diff --git a/wpsc-theme/wpsc-images/yes_stock.gif b/wpsc-components/theme-engine-v1/templates/wpsc-images/yes_stock.gif similarity index 100% rename from wpsc-theme/wpsc-images/yes_stock.gif rename to wpsc-components/theme-engine-v1/templates/wpsc-images/yes_stock.gif diff --git a/wpsc-theme/wpsc-images/yes_stock.png b/wpsc-components/theme-engine-v1/templates/wpsc-images/yes_stock.png similarity index 100% rename from wpsc-theme/wpsc-images/yes_stock.png rename to wpsc-components/theme-engine-v1/templates/wpsc-images/yes_stock.png diff --git a/wpsc-theme/wpsc-list_view.php b/wpsc-components/theme-engine-v1/templates/wpsc-list_view.php similarity index 100% rename from wpsc-theme/wpsc-list_view.php rename to wpsc-components/theme-engine-v1/templates/wpsc-list_view.php diff --git a/wpsc-theme/wpsc-products_page.php b/wpsc-components/theme-engine-v1/templates/wpsc-products_page.php similarity index 100% rename from wpsc-theme/wpsc-products_page.php rename to wpsc-components/theme-engine-v1/templates/wpsc-products_page.php diff --git a/wpsc-theme/wpsc-shopping_cart_page.php b/wpsc-components/theme-engine-v1/templates/wpsc-shopping_cart_page.php similarity index 100% rename from wpsc-theme/wpsc-shopping_cart_page.php rename to wpsc-components/theme-engine-v1/templates/wpsc-shopping_cart_page.php diff --git a/wpsc-theme/wpsc-single_product.php b/wpsc-components/theme-engine-v1/templates/wpsc-single_product.php similarity index 100% rename from wpsc-theme/wpsc-single_product.php rename to wpsc-components/theme-engine-v1/templates/wpsc-single_product.php diff --git a/wpsc-theme/wpsc-transaction_results.php b/wpsc-components/theme-engine-v1/templates/wpsc-transaction_results.php similarity index 100% rename from wpsc-theme/wpsc-transaction_results.php rename to wpsc-components/theme-engine-v1/templates/wpsc-transaction_results.php diff --git a/wpsc-theme/wpsc-user-log.php b/wpsc-components/theme-engine-v1/templates/wpsc-user-log.php similarity index 100% rename from wpsc-theme/wpsc-user-log.php rename to wpsc-components/theme-engine-v1/templates/wpsc-user-log.php diff --git a/wpsc-components/theme-engine-v1/theme-engine-v1.php b/wpsc-components/theme-engine-v1/theme-engine-v1.php new file mode 100644 index 0000000000..25d0ae11ee --- /dev/null +++ b/wpsc-components/theme-engine-v1/theme-engine-v1.php @@ -0,0 +1,93 @@ +calculate_subtotal(); + + if ( $shipping ) { + $total += $wpsc_cart->calculate_total_shipping(); + } + if ( $tax && wpsc_tax_isincluded() == false ) { + $total += $wpsc_cart->calculate_total_tax(); + } + if ( $coupons ) { + $total -= $wpsc_cart->coupons_amount; + } + + if ( get_option( 'add_plustax' ) == 1 ) { + return wpsc_currency_display( $wpsc_cart->calculate_subtotal() ); + } else { + return wpsc_currency_display( $total ); + } + +} diff --git a/wpsc-widgets/category_widget.php b/wpsc-components/theme-engine-v1/widgets/category_widget.php similarity index 97% rename from wpsc-widgets/category_widget.php rename to wpsc-components/theme-engine-v1/widgets/category_widget.php index efe80283f7..8ad099696e 100755 --- a/wpsc-widgets/category_widget.php +++ b/wpsc-components/theme-engine-v1/widgets/category_widget.php @@ -57,11 +57,11 @@ function widget( $args, $instance ) { $instance['categories'][$categories->term_id] = 'on'; } } - + } foreach ( array_keys( (array)$instance['categories'] ) as $category_id ) { - if (!get_term($category_id, "wpsc_product_category")) + if (!get_term($category_id, "wpsc_product_category")) continue; if ( file_exists( wpsc_get_template_file_path( 'wpsc-category_widget.php' ) ) ) { @@ -94,7 +94,7 @@ function update( $new_instance, $old_instance ) { $instance['grid'] = $new_instance['grid'] ? 1 : 0; $instance['height'] = (int)$new_instance['height']; $instance['width'] = (int)$new_instance['width']; - $instance['show_name'] = (bool)$new_instance['show_name']; + $instance['show_name'] = (bool)$new_instance['show_name']; return $instance; } @@ -124,7 +124,7 @@ function form( $instance ) { $width = (int) $instance['width']; $height = (int) $instance['height']; $grid = (bool) $instance['grid']; - $show_name= (bool) $instance['show_name']; + $show_name= (bool) $instance['show_name']; ?>

@@ -147,7 +147,7 @@ function form( $instance ) {