$product_id)); list($wpsc_query, $temp_wpsc_query) = array($temp_wpsc_query, $wpsc_query); // swap the wpsc_query objects // exit('
'.print_r($temp_wpsc_query, true).''); $selected_gateways = get_option('custom_gateway_options'); if (in_array('google', (array)$selected_gateways)) { $output .= google_buynow($product['id']); } else if (in_array('paypal_multiple', (array)$selected_gateways)) { if ($product_id > 0){ //$output .= "
".print_r($wpsc_query,true).""; while (wpsc_have_products()) : wpsc_the_product(); $price = calculate_product_price($wpsc_query->product['id'], $wpsc_query->first_variations); $shipping = $wpsc_query->product['pnp']; $output .= " \n\r"; endwhile; } } list($temp_wpsc_query, $wpsc_query) = array($wpsc_query, $temp_wpsc_query); // swap the wpsc_query objects back if($replaced_shortcode == true) { return $output; } else { echo $output; } } function wpsc_also_bought($product_id) { /* * Displays products that were bought aling with the product defined by $product_id * most of it scarcely needs describing */ global $wpdb; $siteurl = get_option('siteurl'); if(get_option('wpsc_also_bought') == 0) { //returns nothing if this is off return ''; } // to be made customiseable in a future release $also_bought_limit = 3; $element_widths = 96; $image_display_height = 96; $image_display_width = 96; $also_bought = $wpdb->get_results("SELECT `".WPSC_TABLE_PRODUCT_LIST."`.* FROM `".WPSC_TABLE_ALSO_BOUGHT."`, `".WPSC_TABLE_PRODUCT_LIST."` WHERE `selected_product`='".$product_id."' AND `".WPSC_TABLE_ALSO_BOUGHT."`.`associated_product` = `".WPSC_TABLE_PRODUCT_LIST."`.`id` AND `".WPSC_TABLE_PRODUCT_LIST."`.`active` IN('1') AND `".WPSC_TABLE_PRODUCT_LIST."`.`publish` IN ('1')ORDER BY `".WPSC_TABLE_ALSO_BOUGHT."`.`quantity` DESC LIMIT $also_bought_limit",ARRAY_A); if(count($also_bought) > 0) { $output = "
".TXT_WPSC_USING_EXAMPLE_CATEGORY."
"; } else { $output = "".TXT_WPSC_ADMIN_EMPTY_CATEGORY."
"; } } return $output; } function wpsc_product_image_html($image_name, $product_id) { global $wpdb, $wp_query; if(is_numeric($wp_query->query_vars['product_category'])) { $category_id = (int)$wp_query->query_vars['product_category']; } else if (is_numeric($_GET['category'])) { $category_id = (int)$_GET['category']; } else { $category_id = (int)get_option('wpsc_default_category'); } $product['height'] = get_product_meta($id, 'thumbnail_height'); $product['width'] = get_product_meta($id, 'thumbnail_width'); $use_thumbnail_image = 'false'; if(($product['height'] > $category['height']) || ($product['width'] > $category['width'])) { $use_thumbnail_image = 'true'; } //list($category['height'], $category['width']) = if($category_id > 0) { $category = $wpdb->get_row("SELECT `image_height` AS `height`, `image_width` AS `width` FROM `".WPSC_TABLE_PRODUCT_CATEGORIES."` WHERE `id` IN ('{$category_id}') LIMIT 1", ARRAY_A); } // if there is a height, width, and imagePNG function if(($category['height'] != null) && ($category['width'] != null) && (function_exists('ImagePNG'))) { $image_path = "index.php?productid=".$product_id."&thumbnail=".$use_thumbnail_image."&width=".$category['width']."&height=".$category['height'].""; } else { $image_path = WPSC_THUMBNAIL_URL.$image_name; if(is_ssl()) { $image_path = str_replace("http://", "https://", $image_path); } } return $image_path; } /* 19-02-09 * add cart button function used for php template tags and shortcodes */ function wpsc_add_to_cart_button($product_id, $replaced_shortcode = false) { global $wpdb; if ($product_id > 0){ if(function_exists('wpsc_theme_html')) { $product = $wpdb->get_row("SELECT * FROM ".WPSC_TABLE_PRODUCT_LIST." WHERE id = ".$product_id." LIMIT 1", ARRAY_A); //this needs the results from the product_list table passed to it, does not take just an ID $wpsc_theme = wpsc_theme_html($product); } // grab the variation form fields here $variations_processor = new nzshpcrt_variations; $variations_output = $variations_processor->display_product_variations($product_id,false, false, false); $output .= "'; if($replaced_shortcode == true) { return $output; } else { echo $output; } } } function wpsc_refresh_page_urls($content) { global $wpdb; $wpsc_pageurl_option['product_list_url'] = '[productspage]'; $wpsc_pageurl_option['shopping_cart_url'] = '[shoppingcart]'; $check_chekout = $wpdb->get_var("SELECT `guid` FROM `{$wpdb->posts}` WHERE `post_content` LIKE '%[checkout]%' AND `post_type` NOT IN('revision') LIMIT 1"); if($check_chekout != null) { $wpsc_pageurl_option['checkout_url'] = '[checkout]'; } else { $wpsc_pageurl_option['checkout_url'] = '[checkout]'; } $wpsc_pageurl_option['transact_url'] = '[transactionresults]'; $wpsc_pageurl_option['user_account_url'] = '[userlog]'; $changes_made = false; foreach($wpsc_pageurl_option as $option_key => $page_string) { $post_id = $wpdb->get_var("SELECT `ID` FROM `{$wpdb->posts}` WHERE `post_type` IN('page','post') AND `post_content` LIKE '%$page_string%' AND `post_type` NOT IN('revision') LIMIT 1"); $the_new_link = get_permalink($post_id); if(stristr(get_option($option_key), "https://")) { $the_new_link = str_replace('http://', "https://",$the_new_link); } update_option($option_key, $the_new_link); } return $content; } function wpsc_product_permalinks($rewrite_rules) { global $wpdb, $wp_rewrite; $page_details = $wpdb->get_row("SELECT * FROM `".$wpdb->posts."` WHERE `post_content` LIKE '%[productspage]%' AND `post_type` NOT IN('revision') LIMIT 1", ARRAY_A); $is_index = false; if((get_option('page_on_front') == $page_details['ID']) && (get_option('show_on_front') == 'page')) { $is_index = true; } $first_post_name = $page_details['post_name']; $page_name_array[] = $page_details['post_name']; if($page_details['post_parent'] > 0) { $count = 0; while(($page_details['post_parent'] > 0) && ($count <= 20)) { $page_details = $wpdb->get_row("SELECT * FROM `".$wpdb->posts."` WHERE `ID` IN('{$page_details['post_parent']}') AND `post_type` NOT IN('revision') LIMIT 1", ARRAY_A); $page_name_array[] = $page_details['post_name']; $count ++; } } $page_name_array = array_reverse($page_name_array); $page_name = implode("/",$page_name_array); if(!function_exists('wpsc_rewrite_categories')) { // to stop this function from being declared multiple times /* * This is the function for making the e-commerce rewrite rules, it is recursive */ function wpsc_rewrite_categories($page_name, $id = null, $level = 0, $parent_categories = array(), $is_index = false) { global $wpdb,$category_data; if($is_index == true) { $rewrite_page_name = ''; } else { $rewrite_page_name = $page_name.'/'; } if(is_numeric($id)) { $category_sql = "SELECT * FROM `".WPSC_TABLE_PRODUCT_CATEGORIES."` WHERE `active`='1' AND `category_parent` = '".$id."' ORDER BY `id`"; $category_list = $wpdb->get_results($category_sql,ARRAY_A); } else { $category_sql = "SELECT * FROM `".WPSC_TABLE_PRODUCT_CATEGORIES."` WHERE `active`='1' AND `category_parent` = '0' ORDER BY `id`"; $category_list = $wpdb->get_results($category_sql,ARRAY_A); } if($category_list != null) { foreach($category_list as $category) { if($level === 0) { $parent_categories = array(); } $parent_categories[] = $category['nice-name']; $new_rules[($rewrite_page_name.implode($parent_categories,"/").'/?$')] = 'index.php?pagename='.$page_name.'&category_id='.$category['id']; $new_rules[($rewrite_page_name.implode($parent_categories,"/").'/(.+?)/?$')] = 'index.php?pagename='.$page_name.'&category_id='.$category['id'].'&product_url_name=$matches[1]'; $new_rules[($rewrite_page_name.implode($parent_categories,"/").'/page/([0-9]+)/?$')] = 'index.php?pagename='.$page_name.'&category_id='.$category['id'].'&wpsc_page=$matches[1]'; // recurses here $sub_rules = wpsc_rewrite_categories($page_name, $category['id'], ($level+1), $parent_categories, $is_index); array_pop($parent_categories); $new_rules = array_merge((array)$new_rules, (array)$sub_rules); } } return $new_rules; } } $new_rules = wpsc_rewrite_categories($page_name, null, 0, null, $is_index); $new_rules = array_reverse((array)$new_rules); $new_rules[($first_post_name.'/page/([0-9]+)/?$')] = 'index.php?pagename='.$page_name.'&wpsc_page=$matches[1]'; $new_rules[$page_name.'/tag/([A-Za-z0-9\-]+)?$'] = 'index.php?pagename='.$page_name.'&ptag=$matches[1]'; $new_rewrite_rules = array_merge((array)$new_rules,(array)$rewrite_rules); return $new_rewrite_rules; } function wpsc_query_vars($vars) { // $vars[] = "product_category"; // $vars[] = "product_name"; $vars[] = "category_id"; $vars[] = "product_url_name"; $vars[] = "wpsc_page"; return $vars; } add_filter('query_vars', 'wpsc_query_vars'); // using page_rewrite_rules makes it so that odd permalink structures like /%category%/%postname%.htm do not override the plugin permalinks. add_filter('page_rewrite_rules', 'wpsc_product_permalinks'); /** * 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; if(is_numeric($wp_query->query_vars['category_id'])) { $category_id = $wp_query->query_vars['category_id']; } else if($_GET['category']) { $category_id = absint($_GET['category']); } if($category_id > 0) { if(isset($wpsc_title_data['category'][$category_id])) { $output = $wpsc_title_data['category'][$category_id]; } else { $output = $wpdb->get_var("SELECT `name` FROM `".WPSC_TABLE_PRODUCT_CATEGORIES."` WHERE `id`='{$category_id}' LIMIT 1"); $wpsc_title_data['category'][$category_id] = $output; } } if(isset($wp_query->query_vars['product_url_name']) || is_numeric($_GET['product_id'])) { $product_name = $wp_query->query_vars['product_url_name']; 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 = $wpdb->get_var("SELECT `product_id` FROM `".WPSC_TABLE_PRODUCTMETA."` WHERE `meta_key` IN ( 'url_name' ) AND `meta_value` IN ( '{$wp_query->query_vars['product_url_name']}' ) ORDER BY `id` DESC LIMIT 1"); $full_product_name = $wpdb->get_var("SELECT `name` FROM `".WPSC_TABLE_PRODUCT_LIST."` WHERE `id`='{$product_id}' LIMIT 1"); $wpsc_title_data['product'][$product_name] = $full_product_name; } else { $product_id = absint($_GET['product_id']); $product_name = $wpdb->get_var("SELECT `meta_value` FROM `".WPSC_TABLE_PRODUCTMETA."` WHERE `meta_key` IN ( 'url_name' ) AND `product_id` IN ( '{$product_id}' ) LIMIT 1"); $full_product_name = $wpdb->get_var("SELECT `name` FROM `".WPSC_TABLE_PRODUCT_LIST."` WHERE `id`='{$product_id}' LIMIT 1"); $wpsc_title_data['product'][$product_name] = $full_product_name; } } //exit("".print_r($wp_query,true).""); if(isset($full_product_name ) && ($full_product_name != null)) { $output = htmlentities(stripslashes($full_product_name), ENT_QUOTES, 'UTF-8'); } return $output; } function wpsc_obtain_the_description() { global $wpdb, $wp_query, $wpsc_title_data; $output = null; //exit("
".print_r($wp_query,true).""); if(is_numeric($wp_query->query_vars['category_id'])) { $category_id = $wp_query->query_vars['category_id']; } else if($_GET['category']) { $category_id = absint($_GET['category']); } if(is_numeric($category_id)) { $output = $wpdb->get_var("SELECT `description` FROM `".WPSC_TABLE_PRODUCT_CATEGORIES."` WHERE `id`='{$category_id}' LIMIT 1"); } if(isset($wp_query->query_vars['product_url_name'])) { $product_name = $wp_query->query_vars['product_url_name']; $product_id = $wpdb->get_var("SELECT `product_id` FROM `".WPSC_TABLE_PRODUCTMETA."` WHERE `meta_key` IN ( 'url_name' ) AND `meta_value` IN ( '{$wp_query->query_vars['product_url_name']}' ) ORDER BY `id` DESC LIMIT 1"); $output = $wpdb->get_var("SELECT `description` FROM `".WPSC_TABLE_PRODUCT_LIST."` WHERE `id`='{$product_id}' LIMIT 1"); } else if(is_numeric($_GET['product_id'])) { $product_id = absint($_GET['product_id']); $output = $wpdb->get_var("SELECT `description` FROM `".WPSC_TABLE_PRODUCT_LIST."` WHERE `id`='{$product_id}' LIMIT 1"); } return $output; } function wpsc_replace_the_title($input) { global $wpdb, $wp_query; $output = wpsc_obtain_the_title(); if($output != null) { $backtrace = debug_backtrace(); if($backtrace[3]['function'] == 'get_the_title') { return $output; } } return $input; } 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; } if(get_option('wpsc_replace_page_title') == 1) { add_filter('the_title', 'wpsc_replace_the_title', 10, 2); add_filter('wp_title', 'wpsc_replace_wp_title', 10, 2); //add_filter('bloginfo', 'wpsc_replace_bloginfo_title', 10, 2); } ?>