'.print_r($_POST, true).'');
if(($_POST['wpsc_live_search']==true) && (get_option('show_live_search') == 1) && !empty($_POST['keyword'])){
$keyword=$_POST['keyword'];
$search_sql = gold_shpcrt_search_sql($keyword);
$product_list = $wpdb->get_results("SELECT DISTINCT `".WPSC_TABLE_PRODUCT_LIST."`.* FROM `".WPSC_TABLE_PRODUCT_LIST."` WHERE `".WPSC_TABLE_PRODUCT_LIST."`.`active`='1' $search_sql ORDER BY `".WPSC_TABLE_PRODUCT_LIST."`.`name` ASC",ARRAY_A) ;
//exit("SELECT DISTINCT `".WPSC_TABLE_PRODUCT_LIST."`.* FROM `".WPSC_TABLE_PRODUCT_LIST."` WHERE `".WPSC_TABLE_PRODUCT_LIST."`.`active`='1' $search_sql ORDER BY `".WPSC_TABLE_PRODUCT_LIST."`.`name` ASC");
$output = "
";
$_SESSION['live_search_results'] = $product_list;
exit($output);
}
if ($_POST['affiliate']==true) {
if(!function_exists('affiliate_text')) {
function affiliate_text($id, $user) {
$output = "";
return $output;
}
}
$id = $_POST['prodid'];
$product = $wpdb->get_row("SELECT * FROM `".WPSC_TABLE_PRODUCT_LIST."` WHERE id='$id' LIMIT 1",ARRAY_A);
$product = $product[0];
$link = affiliate_text($id,$_POST['uid']);
echo "";
exit();
}
if ($_POST['log_affiliate']==true) {
$uid = $_POST['uid'];
$amount = $_POST['amount'];
$product = $wpdb->query("UPDATE {$wpdb->prefix}wpsc_affiliates SET paid=paid+$amount WHERE user_id='$uid'");
echo "uid=".$uid;
exit();
}
}
function edit_submit_extra_images($id) {
global $wpdb;
foreach($_FILES['extra_image']['name'] as $key => $name) {
if(($name != '') && ($_FILES['extra_image']['size'][$key] >= 0)) {
$time_data = explode(" ",microtime());
$microtime = str_replace("0.", ".", $time_data[0]);
$fulltime = $time_data[1].$microtime;
$name = basename($name);
// test to see if the image already exists
if(file_exists(WPSC_IMAGE_DIR.$name)) {
$name_parts = explode('.',basename($name));
$extension = array_pop($name_parts);
$name_base = implode('.',$name_parts);
$dir = glob(WPSC_IMAGE_DIR."$name_base*");
foreach($dir as $file) {
$matching_files[] = basename($file);
}
$name = null;
$num = 2;
// loop till we find a free file name, first time I get to do a do loop in yonks
do {
$test_name = "{$name_base}-{$num}.{$extension}";
if(!file_exists(WPSC_IMAGE_DIR.$test_name)) {
$name = $test_name;
}
$num++;
} while ($name == null);
}
//echo("".print_r($name,true)."
");
//exit("".print_r($matching_files,true)."
");
$new_image_path = (WPSC_IMAGE_DIR.$name);
$type = $_FILES['extra_image']['type'][$key];
$tmp_name = $_FILES['extra_image']['tmp_name'][$key];
$resize_state = $_POST['extra_image_resize'][$key];
$extra_height = $_POST['extra_height'][$key];
$extra_width = $_POST['extra_width'][$key];
move_uploaded_file($tmp_name, $new_image_path);
if(function_exists("getimagesize")) {
//image_processing($tmp_name,$new_image_path);
$imagetype = @getimagesize($new_image_path);
}
$stat = stat( dirname( $new_image_path ));
$perms = $stat['mode'] & 0000666;
@ chmod( $new_image_path, $perms );
$insert_query = "INSERT INTO `".WPSC_TABLE_PRODUCT_IMAGES."` ( `product_id` , `image` , `width` , `height` ) VALUES ( '$id', '$name', '".(int)$imagetype['width']."', '".(int)$imagetype['height']."');";
$wpdb->query($insert_query);
}
}
return $output;
}
function edit_extra_images($id) {
global $wpdb;
//exit("".print_r($_POST,true)."
");
if($_POST['extra_image_id'] != null) {
foreach($_POST['extra_image_id'] as $num => $value) {
if($_POST['extra_deleteimage'][$num] == 1) {
$wpdb->query("DELETE FROM `".WPSC_TABLE_PRODUCT_IMAGES."` WHERE `id` = '".$value."' LIMIT 1");
}
}
}
return $output;
}
function edit_multiple_image_form($id) {
global $wpdb;
$siteurl = get_option('siteurl');
$values = $wpdb->get_results("SELECT * FROM `".WPSC_TABLE_PRODUCT_IMAGES."` WHERE `product_id` = '$id'",ARRAY_A);
$num = 0;
if($values != null) {
foreach($values as $image) {
if(function_exists("getimagesize")) {
if($image['image'] != '') {
$num++;
$imagepath = WPSC_IMAGE_DIR . $image['image'];
include('getimagesize.php');
$output .= " \n\r";
$output .= " \n\r";
$output .= " ";
$output .= " | \n\r";
$output .= "
\n\r";
$output .= " \n\r";
$output .= " \n\r";
$output .= TXT_WPSC_ADDITIONAL_IMAGE.": ";
if(is_file(WPSC_IMAGE_DIR.$image['image'])) {
$image_size = @getimagesize(WPSC_IMAGE_DIR.$image['image']);
}
if(($image_size[0] != '') && ($image_size[1] != '')) {
$output .= "".$image_size[0]."x".$image_size[1]."";
}
$output .= " | \n\r";
$output .= " \n\r";
$output .= "\n\r";
$output .= " \n\r";
$output .= " \n\r";
$output .= "\n\r";
$output .= " | \n\r";
$output .= " ";
$output .= "";
$output .= " | ";
$output .= " ";
$output .= " \n\r";
$output .= " | \n\r";
$output .= "
\n\r";
}
}
}
}
$output .= " \n\r";
$output .= " \n\r";
$output .= " \n\r";
$output .= " | \n\r";
$output .= "
\n\r";
$output .= " \n\r";
$output .= " \n\r";
$output .= " | \n\r";
$output .= " \n\r";
$output .= "".TXT_WPSC_ADD_ADDITIONAL_IMAGE."";
$output .= " | \n\r";
$output .= "
\n\r";
$output .= " \n\r";
$output .= " \n\r";
$output .= " ";
$output .= " | \n\r";
$output .= "
\n\r";
return $output;
}
function add_multiple_image_form($state = '') {
$output .= " \n\r";
$output .= " \n\r";
$output .= " \n\r";
$output .= " | \n\r";
$output .= "
\n\r";
$output .= " \n\r";
$output .= " \n\r";
$output .= " | \n\r";
$output .= " \n\r";
$output .= "".TXT_WPSC_ADD_ADDITIONAL_IMAGE."\n\r";
$output .= " | \n\r";
$output .= "
\n\r";
return $output;
}
function gold_shpcrt_preview_image() {
global $wpdb;
if(($_GET['view_preview'] == 'true') && is_numeric($_GET['imageid'])) {
if(function_exists("getimagesize")) {
$imagesql = "SELECT `image` FROM `".WPSC_TABLE_PRODUCT_IMAGES."` WHERE `id`='".$_GET['imageid']."' LIMIT 1";
$imagedata = $wpdb->get_results($imagesql,ARRAY_A);
$imagepath = WPSC_IMAGE_DIR . $imagedata[0]['image'];
if(is_numeric($_GET['height']) && is_numeric($_GET['width'])) {
$height = $_GET['height'];
$width = $_GET['width'];
} else {
$image_size = @getimagesize($imagepath);
$width .= $image_size[0];
$height .= $image_size[1];
}
if(($height > 0) && ($height <= 1024) && ($width > 0) && ($width <= 1024)) {
include("image_preview.php");
}
}
}
}
function gold_shpcrt_display_extra_images($product_id,$product_name, $display = false) {
global $wpdb;
$siteurl = get_option('siteurl');
$images = $wpdb->get_results("SELECT * FROM `".WPSC_TABLE_PRODUCT_IMAGES."` WHERE `product_id` = '$product_id' ORDER BY `id` DESC",ARRAY_A);
$output = "";
if($images != null) {
foreach($images as $image) {
$image_link = WPSC_IMAGE_URL.$image['image']."";
$display_style = '';
if($display == false) {
$display_style = "style='display: none;'";
}
$output .= "";
}
}
return $output;
}
function gold_shpcrt_display_gallery($product_id, $invisible = false) {
global $wpdb;
$siteurl = get_option('siteurl');
if(get_option('show_gallery') == 1 && !isset($_GET['range'])) {
/* No GD? No gallery. */
if(function_exists("getimagesize")) {
/* get data about the base product image */
$product = $wpdb->get_row("SELECT * FROM `".WPSC_TABLE_PRODUCT_LIST."` WHERE `id`='".$product_id."' LIMIT 1",ARRAY_A);
$image_link = WPSC_IMAGE_URL.$product['image']."";
$image_file_name = $product['image'];
$imagepath = WPSC_THUMBNAIL_DIR.$image_file_name;
$base_image_size = @getimagesize($imagepath);
/* get data about the extra product images */
$images = $wpdb->get_results("SELECT * FROM `".WPSC_TABLE_PRODUCT_IMAGES."` WHERE `product_id` = '$product_id' AND `id` NOT IN('$image_file_name') ORDER BY `image_order` ASC",ARRAY_A);
$output = "";
//echo "SELECT * FROM `".WPSC_TABLE_PRODUCT_IMAGES."` WHERE `product_id` = '$product_id' AND `id` NOT IN('$image_file_name') ORDER BY `image_order` ASC";
$new_height = get_option('wpsc_gallery_image_height');
$new_width = get_option('wpsc_gallery_image_width');
if(count($images) > 0) {
/* display gallery */
if($invisible == true) {
foreach($images as $image) {
$extra_imagepath = WPSC_IMAGE_DIR.$image['image']."";
$extra_image_size = @getimagesize($extra_imagepath);
$thickbox_link = WPSC_IMAGE_URL.$image['image']."";
$image_link = "index.php?image_id=".$image['id']."&width=".$new_width."&height=".$new_height."";
$output .= " ";
}
} else {
$output .= "".__("Gallery")."
";
$output .= "";
if($images != null) {
foreach($images as $image) {
$extra_imagepath = WPSC_IMAGE_DIR.$image['image']."";
$extra_image_size = @getimagesize($extra_imagepath);
$thickbox_link = WPSC_IMAGE_URL.$image['image']."";
$image_link = "index.php?image_id=".$image['id']."&width=".$new_width."&height=".$new_height."";
$output .= "
";
}
}
$output .= "
";
}
}
}
}
return $output;
}
function gold_shpcrt_search_sql($search_string = '') {
global $wpdb;
$output = "";
if($search_string == '') {
$search_string = $_GET['product_search'];
}
if($search_string != '') {
$brand_sql = '';
$category_sql = '';
$search_string_title = "%".$wpdb->escape(stripslashes($search_string))."%";
$search_string_description = "%".$wpdb->escape(stripslashes($search_string))."%";
$category_list = $wpdb->get_col("SELECT `id` FROM `".WPSC_TABLE_PRODUCT_CATEGORIES."` WHERE `name` LIKE '".$search_string_title."'");
$meta_list = $wpdb->get_col("SELECT DISTINCT `product_id` FROM `".WPSC_TABLE_PRODUCTMETA."` WHERE `meta_value` REGEXP '".$wpdb->escape(stripslashes($search_string))."' AND `custom` IN ('1')");
//echo "SELECT `product_id` FROM `".$wpdb->prefix."wpsc_productmeta` WHERE `meta_value` LIKE '".$wpdb->escape(stripslashes($_GET['product_search']))."' AND `custom` IN ('1')";
if($category_list != null) {
$category_assoc_list = $wpdb->get_col("SELECT DISTINCT `product_id` FROM `".WPSC_TABLE_ITEM_CATEGORY_ASSOC."` WHERE `category_id` IN ('".implode("', '", $category_list)."')");
$category_sql = "OR `".WPSC_TABLE_PRODUCT_LIST."`.`id` IN ('".implode("', '", $category_assoc_list)."')";
}
// this cannot currently list products that are associated with no categories
$output = "AND (`".WPSC_TABLE_PRODUCT_LIST."`.`name` LIKE '".$search_string_title."' OR `".WPSC_TABLE_PRODUCT_LIST."`.`description` LIKE '".$search_string_description."' OR `".WPSC_TABLE_PRODUCT_LIST."`.`id` IN ('".implode("','",$meta_list)."') OR `".WPSC_TABLE_PRODUCT_LIST."`.`additional_description` LIKE '".$search_string_description."' $category_sql )";
//echo $output;
}
return $output;
}
function gold_shpcrt_search_form(){
$siteurl = get_option('siteurl');
$output = '';
if(get_option('permalink_structure') != '') {
$seperator ="?";
} else {
$seperator ="&";
}
$output .= "";
if($seperator == "&") {
$output .= "
\n\r";
$output .="
"; //This div is for live searching, Please don't remove this line.
$output .= "
";
echo $output;
}
function product_display_list($product_list, $group_type, $group_sql = '', $search_sql = '')
{
global $wpdb;
$siteurl = get_option('siteurl');
if(get_option('permalink_structure') != '') {
$seperator ="?";
} else {
$seperator ="&";
}
$product_listing_data = wpsc_get_product_listing($product_list, $group_type, $group_sql, $search_sql);
$product_list = $product_listing_data['product_list'];
$output .= $product_listing_data['page_listing'];
if($product_listing_data['category_id']) {
$category_nice_name = $wpdb->get_var("SELECT `nice-name` FROM `".WPSC_TABLE_PRODUCT_CATEGORIES."` WHERE `id` ='".(int)$product_listing_data['category_id']."' LIMIT 1");
} else {
$category_nice_name = '';
}
if($product_list != null) {
$output .= "";
} else {
$output .= "".TXT_WPSC_NOITEMSINTHIS." ".$group_type.".
";
}
return $output;
}
//written by allen
function gold_shpcrt_xmlmaker(){
$keyword = $_POST['value'];
header("Content-type: text/xml");
$siteurl = get_option('siteurl');
global $wpdb;
$sql = "SELECT DISTINCT `".WPSC_TABLE_PRODUCT_LIST."`.* FROM `".WPSC_TABLE_PRODUCT_LIST."` WHERE `".WPSC_TABLE_PRODUCT_LIST."`.`active`='1' AND ".$wpdb->prefix."product_list.name LIKE '$keyword%'";
$product_list = $wpdb->get_results($sql,ARRAY_A) ;
echo "\n\r";
//you can choose any name for the starting tag
echo "\n\r";
if ($product_list != null) {
foreach($product_list as $product) {
echo $product['image'];
echo "- \n\r";
echo "\n\r";
echo "<a href='#' onClick='window.location=\"".$siteurl."/?page_id=3&product_id=".$product['id']."\"'>\n\r";
echo "<table cellspacing='2' border='0' class='products'>\n\r";
echo "<tr>\n\r";
echo "<td class='product_img' rowspan='2'>\n\r";
if($product['image']!=""){
echo "<img src='".WPSC_IMAGE_URL.$product['image']."' width='35' height='35' />\n\r";
} else {
echo "<img src='./wp-content/plugins/".WPSC_DIR_NAME."/no-image-uploaded.gif' width='35' height='35'/>\n\r";
}
echo "</td>\n\r";
echo "<td width='5px' rowspan='2'>\n\r";
echo "</td>\n\r";
echo "<td align='left'>\n\r";
echo "<strong>".$product['name']."</strong>\n\r";
echo "</td>\n\r";
echo "<tr>\n\r";
echo "<td>\n\r";
if (strlen($product['description'])>34){
$product['description'] = substr($product['description'],0,33)."...";
}
echo $product['description'];
echo "</td>\n\r";
echo "</tr>\n\r";
echo "</table>\n\r";
echo "</a>";
echo "\n\r";
echo "\n\r";
echo $product['name'];
echo "\n\r";
echo "
";
}
}
echo "";
exit();
}
//end of written by allen
$gold_gateway_directory = dirname(__FILE__).'/merchants/';
$gold_nzshpcrt_merchant_list = nzshpcrt_listdir($gold_gateway_directory);
foreach($gold_nzshpcrt_merchant_list as $gold_nzshpcrt_merchant) {
if(!is_dir($gold_gateway_directory.$gold_nzshpcrt_merchant)) {
include_once($gold_gateway_directory.$gold_nzshpcrt_merchant);
}
$num++;
}
if(count((array)get_option('custom_gateway_options')) == 1) {
// if there is only one active gateway, and it has form fields, append them to the end of the checkout form.
$active_gateway = implode('',(array)get_option('custom_gateway_options'));
if((count((array)$gateway_checkout_form_fields) == 1) && ($gateway_checkout_form_fields[$active_gateway] != '')) {
$gateway_checkout_form_field = $gateway_checkout_form_fields[$active_gateway];
}
}
//exit("".print_r($gateway_checkout_form_field,true)."
");
if(file_exists(dirname(__FILE__).'/mp3_functions/mp3_functions.php')) {
require_once(dirname(__FILE__).'/mp3_functions/mp3_functions.php');
}
if(file_exists(dirname(__FILE__).'/dropshop/drag_and_drop_cart.php')) {
require_once(dirname(__FILE__).'/dropshop/drag_and_drop_cart.php');
}
if(file_exists(dirname(__FILE__).'/grid_display_functions.php')) {
require_once(dirname(__FILE__).'/grid_display_functions.php');
}
if(file_exists(dirname(__FILE__).'/members/members.php')) {
require_once(dirname(__FILE__).'/members/members.php');
}
if(file_exists(dirname(__FILE__).'/product_slider/product_slider.php')) {
require_once(dirname(__FILE__).'/product_slider/product_slider.php');
}
if(file_exists(dirname(__FILE__).'/api_key_generator/api_key_generator.php')) {
require_once(dirname(__FILE__).'/api_key_generator/api_key_generator.php');
}
/* re-added by dev.xiligroup 090701 */
if(file_exists(dirname(__FILE__).'/touchShop/touchShopCore.php')) {
require_once(dirname(__FILE__).'/touchShop/touchShopCore.php');
}
if(isset($_GET['activate']) && $_GET['activate'] == 'true') {
add_action('init', 'gold_shpcrt_install');
}
if(get_option('show_search') == 1) {
add_action('wpsc_top_of_products_page', 'gold_shpcrt_search_form');
}
add_action('admin_head', 'gold_shpcrt_javascript');
add_action('wp_head', 'gold_shpcrt_javascript');
add_action('init', 'wpsc_gold_shpcrt_ajax');
//exit(get_option('show_live_search'));
add_action('init', 'gold_shpcrt_preview_image');
}
?>