PageRenderTime 65ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 1ms

/wp-content/plugins/wp-shopping-cart/wp-shopping-cart.php

https://github.com/alx/barceloneta
PHP | 2608 lines | 2076 code | 343 blank | 189 comment | 544 complexity | 8aea27015246860d47a4e369a46af1d9 MD5 | raw file
  1. <?php
  2. /*
  3. Plugin Name:WP Shopping Cart
  4. Plugin URI: http://www.instinct.co.nz
  5. Description: A plugin that provides a WordPress Shopping Cart. Contact <a href='http://www.instinct.co.nz/?p=16#support'>Instinct Entertainment</a> for support. <br />Click here to to <a href='?wpsc_uninstall=ask'>Uninstall</a>.
  6. Version: 3.6.8 RC1
  7. Author: Thomas Howard of Instinct Entertainment
  8. Author URI: http://www.instinct.co.nz/e-commerce/
  9. /* Major version for "major" releases */
  10. define('WPSC_VERSION', '3.6');
  11. define('WPSC_MINOR_VERSION', '80');
  12. define('WPSC_PRESENTABLE_VERSION', '3.6.8 RC1');
  13. define('WPSC_DEBUG', false);
  14. /*
  15. * {Notes} Language Files
  16. * {Required} Yes
  17. * {WP-Set} Yes (Admin Panel)
  18. */
  19. define('IS_WP25', version_compare($wp_version, '2.4', '>=') );
  20. // // we need to know where we are, rather than assuming where we are
  21. define('WPSC_FILE_PATH', dirname(__FILE__));
  22. define('WPSC_DIR_NAME', basename(WPSC_FILE_PATH));
  23. $siteurl = get_option('siteurl');
  24. // thanks to ikool for this fix
  25. define('WPSC_FOLDER', dirname(plugin_basename(__FILE__)));
  26. define('WPSC_URL', get_option('siteurl').'/wp-content/plugins/' . WPSC_FOLDER);
  27. //exit("");
  28. if(WPSC_DEBUG === true) {
  29. function microtime_float() {
  30. list($usec, $sec) = explode(" ", microtime());
  31. return ((float)$usec + (float)$sec);
  32. }
  33. function wpsc_debug_start_subtimer($name, $action, $loop = false) {
  34. global $wpsc_debug_sections,$loop_debug_increment;
  35. if($loop === true) {
  36. if ($action == 'start') {
  37. $loop_debug_increment[$name]++;
  38. $wpsc_debug_sections[$name.$loop_debug_increment[$name]][$action] = microtime_float();
  39. } else if($action == 'stop') {
  40. $wpsc_debug_sections[$name.$loop_debug_increment[$name]][$action] = microtime_float();
  41. }
  42. } else {
  43. $wpsc_debug_sections[$name][$action] = microtime_float();
  44. }
  45. }
  46. $wpsc_start_time = microtime_float();
  47. } else {
  48. function wpsc_debug_start_subtimer($name) {
  49. return null;
  50. }
  51. }
  52. if(get_option('language_setting') != '') {
  53. require(WPSC_FILE_PATH.'/languages/'.get_option('language_setting'));
  54. } else {
  55. require(WPSC_FILE_PATH.'/languages/EN_en.php');
  56. }
  57. require(WPSC_FILE_PATH.'/classes/variations.class.php');
  58. require(WPSC_FILE_PATH.'/classes/extra.class.php');
  59. // require(WPSC_FILE_PATH.'/classes/http_client.php');
  60. require(WPSC_FILE_PATH.'/classes/mimetype.php');
  61. require(WPSC_FILE_PATH.'/classes/cart.class.php');
  62. require(WPSC_FILE_PATH.'/classes/xmlparser.php');
  63. if (!IS_WP25) {
  64. require(WPSC_FILE_PATH.'/editor.php');
  65. } else {
  66. require(WPSC_FILE_PATH.'/js/tinymce3/tinymce.php');
  67. }
  68. if(IS_WPMU == 1) {
  69. $upload_url = get_option('siteurl').'/files';
  70. $upload_path = ABSPATH.get_option('upload_path');
  71. } else {
  72. if ( !defined('WP_CONTENT_URL') ) {
  73. define( 'WP_CONTENT_URL', get_option('siteurl') . '/wp-content');
  74. }
  75. if ( !defined('WP_CONTENT_DIR') ) {
  76. define( 'WP_CONTENT_DIR', ABSPATH . 'wp-content' );
  77. }
  78. $upload_path = WP_CONTENT_DIR."/uploads";
  79. $upload_url = WP_CONTENT_URL."/uploads";
  80. }
  81. $wpsc_file_dir = "{$upload_path}/wpsc/downloadables/";
  82. $wpsc_preview_dir = "{$upload_path}/wpsc/previews/";
  83. $wpsc_image_dir = "{$upload_path}/wpsc/product_images/";
  84. $wpsc_thumbnail_dir = "{$upload_path}/wpsc/product_images/thumbnails/";
  85. $wpsc_category_dir = "{$upload_path}/wpsc/category_images/";
  86. $wpsc_user_uploads_dir = "{$upload_path}/wpsc/user_uploads/";
  87. // $wpsc_file_dir = ABSPATH."{$upload_path}/files/";
  88. // $wpsc_preview_dir = ABSPATH."{$upload_path}/preview_clips/";
  89. // $wpsc_image_dir = ABSPATH."{$upload_path}/product_images/";
  90. // $wpsc_thumbnail_dir = ABSPATH."{$upload_path}/product_images/thumbnails/";
  91. // $wpsc_category_dir = ABSPATH."{$upload_path}/category_images/";
  92. define('WPSC_FILE_DIR', $wpsc_file_dir);
  93. define('WPSC_PREVIEW_DIR', $wpsc_preview_dir);
  94. define('WPSC_IMAGE_DIR', $wpsc_image_dir);
  95. define('WPSC_THUMBNAIL_DIR', $wpsc_thumbnail_dir);
  96. define('WPSC_CATEGORY_DIR', $wpsc_category_dir);
  97. define('WPSC_USER_UPLOADS_DIR', $wpsc_user_uploads_dir);
  98. /**
  99. * files that are uploaded as part of digital products are not directly downloaded, therefore there is no need for a URL constant for them
  100. */
  101. $wpsc_preview_url = "{$upload_url}/wpsc/previews/";
  102. $wpsc_image_url = "{$upload_url}/wpsc/product_images/";
  103. $wpsc_thumbnail_url = "{$upload_url}/wpsc/product_images/thumbnails/";
  104. $wpsc_category_url = "{$upload_url}/wpsc/category_images/";
  105. $wpsc_user_uploads_url = "{$upload_url}/wpsc/user_uploads/";
  106. // $wpsc_preview_url = "{$siteurl}/{$upload_path}/preview_clips/";
  107. // $wpsc_image_url = "{$siteurl}/{$upload_path}/product_images/";
  108. // $wpsc_thumbnail_url = "{$siteurl}/{$upload_path}/product_images/thumbnails/";
  109. // $wpsc_category_url = "{$siteurl}/{$upload_path}/category_images/";
  110. define('WPSC_PREVIEW_URL', $wpsc_preview_url);
  111. define('WPSC_IMAGE_URL', $wpsc_image_url);
  112. define('WPSC_THUMBNAIL_URL', $wpsc_thumbnail_url);
  113. define('WPSC_CATEGORY_URL', $wpsc_category_url);
  114. define('WPSC_USER_UPLOADS_URL', $wpsc_user_uploads_url);
  115. /*
  116. * {Notes} Session will sometimes always exist dependent on server
  117. * {Notes} Controls user Session
  118. */
  119. if((!is_array($_SESSION)) xor (!isset($_SESSION['nzshpcrt_cart'])) xor (!$_SESSION)) {
  120. session_start();
  121. }
  122. if(isset($_SESSION['nzshpcrt_cart'])) {
  123. foreach((array)$_SESSION['nzshpcrt_cart'] as $key => $item) {
  124. if(get_class($item) == "__PHP_Incomplete_Class") {
  125. $_SESSION['nzshpcrt_cart'] = unserialize($_SESSION['nzshpcrt_serialized_cart']);
  126. }
  127. }
  128. } else {
  129. if(isset($_SESSION['nzshpcrt_cart'])) {
  130. $_SESSION['nzshpcrt_cart'] = unserialize($_SESSION['nzshpcrt_serialized_cart']);
  131. }
  132. }
  133. if(is_numeric($_GET['sessionid'])) {
  134. $sessionid = $_GET['sessionid'];
  135. $cart_log_id = $wpdb->get_var("SELECT `id` FROM `".$wpdb->prefix."purchase_logs` WHERE `sessionid`= ".$sessionid." LIMIT 1");
  136. if(is_numeric($cart_log_id)) {
  137. $_SESSION['nzshpcrt_cart'] = null;
  138. $_SESSION['nzshpcrt_serialized_cart'] = null;
  139. }
  140. }
  141. $GLOBALS['nzshpcrt_imagesize_info'] = TXT_WPSC_IMAGESIZEINFO;
  142. $nzshpcrt_log_states[0]['name'] = TXT_WPSC_RECEIVED;
  143. $nzshpcrt_log_states[1]['name'] = TXT_WPSC_PROCESSING;
  144. $nzshpcrt_log_states[2]['name'] = TXT_WPSC_PROCESSED;
  145. class wp_shopping_cart {
  146. function wp_shopping_cart() {
  147. return;
  148. }
  149. function displaypages()
  150. {
  151. /*
  152. * Fairly standard wordpress plugin API stuff for adding the admin pages, rearrange the order to rearrange the pages
  153. * The bits to display the options page first on first use may be buggy, but tend not to stick around long enough to be identified and fixed
  154. * if you find bugs, feel free to fix them.
  155. *
  156. * If the permissions are changed here, they will likewise need to be changed for the other secions of the admin that either use ajax
  157. * or bypass the normal download system.
  158. * its in an object because nobody has moved it out of the object yet.
  159. */
  160. if(function_exists('add_options_page')) {
  161. // if(get_option('nzshpcrt_first_load') == 0) {
  162. // $base_page = WPSC_DIR_NAME.'/options.php';
  163. // add_menu_page(TXT_WPSC_ECOMMERCE, TXT_WPSC_ECOMMERCE, 7, $base_page);
  164. // add_submenu_page($base_page,TXT_WPSC_OPTIONS, TXT_WPSC_OPTIONS, 7, WPSC_DIR_NAME.'/options.php');
  165. // } else {
  166. $base_page = WPSC_DIR_NAME.'/display-log.php';
  167. add_menu_page(TXT_WPSC_ECOMMERCE, TXT_WPSC_ECOMMERCE, 7, $base_page);
  168. add_submenu_page(WPSC_DIR_NAME.'/display-log.php',TXT_WPSC_PURCHASELOG, TXT_WPSC_PURCHASELOG, 7, WPSC_DIR_NAME.'/display-log.php');
  169. // }
  170. //written by allen
  171. add_submenu_page('users.php',TXT_WPSC_ECOMMERCE_SUBSCRIBERS, TXT_WPSC_ECOMMERCE_SUBSCRIBERS, 7, WPSC_DIR_NAME.'/display-ecommerce-subs.php');
  172. //exit(ABSPATH.'wp-admin/users.php');
  173. //end of written by allen
  174. add_submenu_page($base_page,TXT_WPSC_PRODUCTS, TXT_WPSC_PRODUCTS, 7, WPSC_DIR_NAME.'/display-items.php');
  175. add_submenu_page($base_page,TXT_WPSC_CATEGORISATION, TXT_WPSC_CATEGORISATION, 7, WPSC_DIR_NAME.'/display-category.php');
  176. add_submenu_page($base_page,TXT_WPSC_VARIATIONS, TXT_WPSC_VARIATIONS, 7, WPSC_DIR_NAME.'/display_variations.php');
  177. add_submenu_page($base_page,TXT_WPSC_MARKETING, TXT_WPSC_MARKETING, 7, WPSC_DIR_NAME.'/display-coupons.php');
  178. add_submenu_page($base_page,TXT_WPSC_PAYMENTGATEWAYOPTIONS, TXT_WPSC_PAYMENTGATEWAYOPTIONS, 7, WPSC_DIR_NAME.'/gatewayoptions.php');
  179. add_submenu_page($base_page,TXT_WPSC_FORM_FIELDS, TXT_WPSC_FORM_FIELDS, 7, WPSC_DIR_NAME.'/form_fields.php');
  180. add_submenu_page($base_page,TXT_WPSC_OPTIONS, TXT_WPSC_OPTIONS, 7, WPSC_DIR_NAME.'/options.php');
  181. if(function_exists('gold_shpcrt_options')) {
  182. gold_shpcrt_options($base_page);
  183. }
  184. // add_submenu_page($base_page,TXT_WPSC_HELPINSTALLATION, TXT_WPSC_HELPINSTALLATION, 7, WPSC_DIR_NAME.'/instructions.php');
  185. }
  186. return;
  187. }
  188. }
  189. function nzshpcrt_style() {
  190. ?>
  191. <style type="text/css" media="screen">
  192. <?php
  193. if((get_option('product_view') == 'default') || (get_option('product_view') == '')) {
  194. $thumbnail_width = get_option('product_image_width');
  195. if($thumbnail_width <= 0) {
  196. $thumbnail_width = 96;
  197. }
  198. ?>
  199. div.default_product_display div.textcol{
  200. margin-left: <?php echo $thumbnail_width + 10; ?>px !important;
  201. _margin-left: <?php echo ($thumbnail_width/2) + 5; ?>px !important;
  202. }
  203. div.default_product_display div.textcol div.imagecol{
  204. position:absolute;
  205. top:0px;
  206. left: 0px;
  207. margin-left: -<?php echo $thumbnail_width + 10; ?>px !important;
  208. }
  209. <?php
  210. }
  211. $single_thumbnail_width = get_option('single_view_image_width');
  212. $single_thumbnail_height = get_option('single_view_image_height');
  213. if($single_thumbnail_width <= 0) {
  214. $single_thumbnail_width = 128;
  215. }
  216. ?>
  217. div.single_product_display div.textcol{
  218. margin-left: <?php echo $single_thumbnail_width + 10; ?>px !important;
  219. _margin-left: <?php echo ($single_thumbnail_width/2) + 5; ?>px !important;
  220. min-height: <?php echo $single_thumbnail_height + 10;?>px;
  221. _height: <?php echo $single_thumbnail_height + 10;?>px;
  222. }
  223. div.single_product_display div.textcol div.imagecol{
  224. position:absolute;
  225. top:0px;
  226. left: 0px;
  227. margin-left: -<?php echo $single_thumbnail_width + 10; ?>px !important;
  228. }
  229. <?php
  230. if(is_numeric($_GET['brand']) || (get_option('show_categorybrands') == 3)) {
  231. $brandstate = 'block';
  232. $categorystate = 'none';
  233. } else {
  234. $brandstate = 'none';
  235. $categorystate = 'block';
  236. }
  237. ?>
  238. div#categorydisplay{
  239. display: <?php echo $categorystate; ?>;
  240. }
  241. div#branddisplay{
  242. display: <?php echo $brandstate; ?>;
  243. }
  244. </style>
  245. <?php
  246. }
  247. function nzshpcrt_javascript()
  248. {
  249. $siteurl = get_option('siteurl');
  250. echo "";
  251. if(($_SESSION['nzshpcrt_cart'] == null) && (get_option('show_sliding_cart') == 1)) {
  252. ?>
  253. <style type="text/css" media="screen">
  254. div#sliding_cart{
  255. display: none;
  256. }
  257. </style>
  258. <?php
  259. } else {
  260. ?>
  261. <style type="text/css" media="screen">
  262. div#sliding_cart{
  263. display: block;
  264. }
  265. </style>
  266. <?php
  267. }
  268. ?>
  269. <?php if (get_option('product_ratings') == 1){ ?>
  270. <link href='<?php echo WPSC_URL; ?>/product_rater.css' rel="stylesheet" type="text/css" />
  271. <?php } ?>
  272. <link href='<?php echo WPSC_URL; ?>/thickbox.css' rel="stylesheet" type="text/css" />
  273. <?php if (get_option('catsprods_display_type') == 1){ ?>
  274. <script language="JavaScript" type="text/javascript" src="<?php echo WPSC_URL; ?>/js/slideMenu.js"></script>
  275. <?php } ?>
  276. <script language='JavaScript' type='text/javascript'>
  277. jQuery.noConflict();
  278. /* base url */
  279. var base_url = "<?php echo $siteurl; ?>";
  280. var WPSC_URL = "<?php echo WPSC_URL; ?>";
  281. /* LightBox Configuration start*/
  282. var fileLoadingImage = "<?php echo WPSC_URL; ?>/images/loading.gif";
  283. var fileBottomNavCloseImage = "<?php echo WPSC_URL; ?>/images/closelabel.gif";
  284. var fileThickboxLoadingImage = "<?php echo WPSC_URL; ?>/images/loadingAnimation.gif";
  285. var resizeSpeed = 9; // controls the speed of the image resizing (1=slowest and 10=fastest)
  286. var borderSize = 10; //if you adjust the padding in the CSS, you will need to update this variable
  287. jQuery(document).ready( function() {
  288. <?php
  289. if(get_option('show_sliding_cart') == 1) {
  290. if(is_numeric($_SESSION['slider_state'])) {
  291. if($_SESSION['slider_state'] == 0) {
  292. ?>
  293. jQuery("#sliding_cart").css({ display: "none"});
  294. <?php
  295. } else {
  296. ?>
  297. jQuery("#sliding_cart").css({ display: "block"});
  298. <?php
  299. }
  300. } else {
  301. if($_SESSION['nzshpcrt_cart'] == null) {
  302. ?>
  303. jQuery("#sliding_cart").css({ display: "none"});
  304. <?php
  305. } else {
  306. ?>
  307. jQuery("#sliding_cart").css({ display: "block"});
  308. <?php
  309. }
  310. }
  311. }
  312. ?>
  313. });
  314. </script>
  315. <script src="<?php echo WPSC_URL; ?>/ajax.js" language='JavaScript' type="text/javascript"></script>
  316. <script src="<?php echo WPSC_URL; ?>/user.js" language='JavaScript' type="text/javascript">
  317. </script>
  318. <?php
  319. $theme_path = WPSC_FILE_PATH. '/themes/';
  320. if((get_option('wpsc_selected_theme') != '') && (file_exists($theme_path.get_option('wpsc_selected_theme')."/".get_option('wpsc_selected_theme').".css") )) {
  321. ?>
  322. <link href='<?php echo WPSC_URL; ?>/themes/<?php echo get_option('wpsc_selected_theme')."/".get_option('wpsc_selected_theme').".css"; ?>' rel="stylesheet" type="text/css" />
  323. <?php
  324. } else {
  325. ?>
  326. <link href='<?php echo WPSC_URL; ?>/themes/default/default.css' rel="stylesheet" type="text/css" />
  327. <?php
  328. }
  329. ?>
  330. <link href='<?php echo WPSC_URL; ?>/themes/compatibility.css' rel="stylesheet" type="text/css" />
  331. <?php
  332. }
  333. function wpsc_admin_css() {
  334. $siteurl = get_option('siteurl');
  335. if(strpos($_SERVER['REQUEST_URI'], WPSC_DIR_NAME.'') !== false) {
  336. ?>
  337. <link href='<?php echo WPSC_URL; ?>/admin.css' rel="stylesheet" type="text/css" />
  338. <link href='<?php echo WPSC_URL; ?>/js/jquery.ui.tabs.css' rel="stylesheet" type="text/css" />
  339. <?php
  340. if($_GET['page'] == 'wp-shopping-cart/display-log.php') {
  341. ?>
  342. <link href='<?php echo $siteurl; ?>/wp-admin/css/dashboard.css?ver=2.6' rel="stylesheet" type="text/css" />
  343. <?php
  344. }
  345. ?>
  346. <link href='<?php echo WPSC_URL; ?>/thickbox.css' rel="stylesheet" type="text/css" />
  347. <script src="<?php echo WPSC_URL; ?>/ajax.js" language='JavaScript' type="text/javascript"></script>
  348. <script language="JavaScript" type="text/javascript" src="<?php echo WPSC_URL; ?>/js/jquery.tooltip.js"></script>
  349. <script language='JavaScript' type='text/javascript'>
  350. /* base url */
  351. var base_url = "<?php echo $siteurl; ?>";
  352. var WPSC_URL = "<?php echo WPSC_URL; ?>";
  353. /* LightBox Configuration start*/
  354. var fileLoadingImage = "<?php echo WPSC_URL; ?>/images/loading.gif";
  355. var fileBottomNavCloseImage = "<?php echo WPSC_URL; ?>/images/closelabel.gif";
  356. var fileThickboxLoadingImage = "<?php echo WPSC_URL; ?>/images/loadingAnimation.gif";
  357. var resizeSpeed = 9;
  358. var borderSize = 10;
  359. /* LightBox Configuration end*/
  360. /* custom admin functions start*/
  361. <?php
  362. echo "var TXT_WPSC_DELETE = '".TXT_WPSC_DELETE."';\n\r";
  363. echo "var TXT_WPSC_TEXT = '".TXT_WPSC_TEXT."';\n\r";
  364. echo "var TXT_WPSC_EMAIL = '".TXT_WPSC_EMAIL."';\n\r";
  365. echo "var TXT_WPSC_COUNTRY = '".TXT_WPSC_COUNTRY."';\n\r";
  366. echo "var TXT_WPSC_TEXTAREA = '".TXT_WPSC_TEXTAREA."';\n\r";
  367. echo "var TXT_WPSC_HEADING = '".TXT_WPSC_HEADING."';\n\r";
  368. echo "var TXT_WPSC_COUPON = '".TXT_WPSC_COUPON."';\n\r";
  369. echo "var HTML_FORM_FIELD_TYPES =\"<option value='text' >".TXT_WPSC_TEXT."</option>";
  370. echo "<option value='email' >".TXT_WPSC_EMAIL."</option>";
  371. echo "<option value='address' >".TXT_WPSC_ADDRESS."</option>";
  372. echo "<option value='city' >".TXT_WPSC_CITY."</option>";
  373. echo "<option value='country'>".TXT_WPSC_COUNTRY."</option>";
  374. echo "<option value='delivery_address' >".TXT_WPSC_DELIVERY_ADDRESS."</option>";
  375. echo "<option value='delivery_city' >".TXT_WPSC_DELIVERY_CITY."</option>";
  376. echo "<option value='delivery_country'>".TXT_WPSC_DELIVERY_COUNTRY."</option>";
  377. echo "<option value='textarea' >".TXT_WPSC_TEXTAREA."</option>";
  378. echo "<option value='heading' >".TXT_WPSC_HEADING."</option>";
  379. echo "<option value='coupon' >".TXT_WPSC_COUPON."</option>\";\n\r";
  380. ?>
  381. /* custom admin functions end*/
  382. </script>
  383. <script language="JavaScript" type="text/javascript" src="<?php echo WPSC_URL; ?>/js/thickbox.js"></script>
  384. <script language="JavaScript" type="text/javascript" src="<?php echo WPSC_URL; ?>/js/jquery.tooltip.js"></script>
  385. <script language="JavaScript" type="text/javascript" src="<?php echo WPSC_URL; ?>/js/dimensions.js"></script>
  386. <script language="JavaScript" type="text/javascript" src="<?php echo WPSC_URL; ?>/admin.js"></script>
  387. <?php
  388. }
  389. }
  390. function nzshpcrt_displaypages()
  391. {
  392. $nzshpcrt = new wp_shopping_cart;
  393. $nzshpcrt->displaypages();
  394. }
  395. function nzshpcrt_adminpage()
  396. {
  397. $nzshpcrt = new wp_shopping_cart;
  398. $nzshpcrt->adminpage();
  399. }
  400. function nzshpcrt_additem()
  401. {
  402. $nzshpcrt = new wp_shopping_cart;
  403. $nzshpcrt->additem();
  404. }
  405. function nzshpcrt_displayitems()
  406. {
  407. $nzshpcrt = new wp_shopping_cart;
  408. $nzshpcrt->displayitems();
  409. }
  410. function nzshpcrt_instructions()
  411. {
  412. $nzshpcrt = new wp_shopping_cart;
  413. $nzshpcrt->instructions();
  414. }
  415. function nzshpcrt_options()
  416. {
  417. $nzshpcrt = new wp_shopping_cart;
  418. $nzshpcrt->options();
  419. }
  420. function nzshpcrt_gatewayoptions()
  421. {
  422. $nzshpcrt = new wp_shopping_cart;
  423. $nzshpcrt->gatewayoptions();
  424. }
  425. function nzshpcrt_addcategory()
  426. {
  427. $nzshpcrt = new wp_shopping_cart;
  428. $nzshpcrt->addcategory();
  429. //$GLOBALS['nzshpcrt_activateshpcrt'] = true;
  430. }
  431. function nzshpcrt_editcategory()
  432. {
  433. $nzshpcrt = new wp_shopping_cart;
  434. $nzshpcrt->editcategory();
  435. //$GLOBALS['nzshpcrt_activateshpcrt'] = true;
  436. }
  437. function nzshpcrt_editvariations()
  438. {
  439. $nzshpcrt = new wp_shopping_cart;
  440. $nzshpcrt->editvariations();
  441. //$GLOBALS['nzshpcrt_activateshpcrt'] = true;
  442. }
  443. function nzshpcrt_submit_ajax()
  444. {
  445. global $wpdb,$user_level,$wp_rewrite;
  446. get_currentuserinfo();
  447. if(get_option('permalink_structure') != '') {
  448. $seperator ="?";
  449. } else {
  450. $seperator ="&amp;";
  451. }
  452. $cartt = $_SESSION['nzshpcrt_cart'];
  453. $cartt1=$cartt[0]->product_id;
  454. // if is an AJAX request, cruddy code, could be done better but getting approval would be impossible
  455. if(($_POST['ajax'] == "true") || ($_GET['ajax'] == "true"))
  456. {
  457. if ($_POST['changetax'] == "true") {
  458. if (isset($_POST['billing_region'])){
  459. $billing_region=$_POST['billing_region'];
  460. } else {
  461. $billing_region=$_SESSION['selected_region'];
  462. }
  463. $billing_country=$_POST['billing_country'];
  464. foreach($cartt as $cart_item) {
  465. $product_id = $cart_item->product_id;
  466. $quantity = $cart_item->quantity;
  467. //echo("<pre>".print_r($cart_item->product_variations,true)."</pre>");
  468. $product = $wpdb->get_row("SELECT * FROM `".$wpdb->prefix."product_list` WHERE `id` = '$product_id' LIMIT 1",ARRAY_A);
  469. if($product['donation'] == 1) {
  470. $price = $quantity * $cart_item->donation_price;
  471. } else {
  472. $price = $quantity * calculate_product_price($product_id, $cart_item->product_variations);
  473. if($product['notax'] != 1) {
  474. $tax += nzshpcrt_calculate_tax($price, $billing_country, $billing_region) - $price;
  475. }
  476. $all_donations = false;
  477. }
  478. if($_SESSION['delivery_country'] != null) {
  479. $total_shipping += nzshpcrt_determine_item_shipping($product['id'], $quantity, $_SESSION['delivery_country']);
  480. }
  481. }
  482. echo $tax.":".$price.":".$total_shipping;
  483. exit();
  484. }
  485. if ($_POST['submittogoogle']) {
  486. $newvalue=$_POST['value'];
  487. $amount=$_POST['amount'];
  488. $reason=$_POST['reason'];
  489. $comment=$_POST['comment'];
  490. $message=$_POST['message'];
  491. $amount=number_format($amount, 2, '.', '');
  492. $log_data = $wpdb->get_row("SELECT * FROM `".$wpdb->prefix."purchase_logs` WHERE `id` = '".$_POST['id']."' LIMIT 1",ARRAY_A);
  493. if (($newvalue==2) && function_exists('wpsc_member_activate_subscriptions')){
  494. wpsc_member_activate_subscriptions($_POST['id']);
  495. }
  496. $google_status = unserialize($log_data['google_status']);
  497. switch($newvalue) {
  498. case "Charge":
  499. if ($google_status[0]!='CANCELLED_BY_GOOGLE') {
  500. if ($amount=='') {
  501. $google_status['0']='Partially Charged';
  502. } else {
  503. $google_status['0']='CHARGED';
  504. $google_status['partial_charge_amount']=$amount;
  505. }
  506. }
  507. break;
  508. case "Cancel":
  509. if ($google_status[0]!='CANCELLED_BY_GOOGLE')
  510. $google_status[0]='CANCELLED';
  511. if ($google_status[1]!='DELIVERED')
  512. $google_status[1]='WILL_NOT_DELIVER';
  513. break;
  514. case "Refund":
  515. if ($amount=='') {
  516. $google_status['0']='Partially Refund';
  517. } else {
  518. $google_status['0']='REFUND';
  519. $google_status['partial_refund_amount']=$amount;
  520. }
  521. break;
  522. case "Ship":
  523. if ($google_status[1]!='WILL_NOT_DELIVER')
  524. $google_status[1]='DELIVERED';
  525. break;
  526. case "Archive":
  527. $google_status[1]='ARCHIVED';
  528. break;
  529. }
  530. $google_status_sql="UPDATE `".$wpdb->prefix."purchase_logs` SET google_status='".serialize($google_status)."' WHERE `id` = '".$_POST['id']."' LIMIT 1";
  531. $wpdb->query($google_status_sql);
  532. $merchant_id = get_option('google_id');
  533. $merchant_key = get_option('google_key');
  534. $server_type = get_option('google_server_type');
  535. $currency = get_option('google_cur');
  536. $Grequest = new GoogleRequest($merchant_id, $merchant_key, $server_type,$currency);
  537. $google_order_number=$wpdb->get_var("SELECT google_order_number FROM `".$wpdb->prefix."purchase_logs` WHERE `id` = '".$_POST['id']."' LIMIT 1");
  538. switch ($newvalue) {
  539. case 'Charge':
  540. $Grequest->SendChargeOrder($google_order_number,$amount);
  541. break;
  542. case 'Ship':
  543. $Grequest->SendDeliverOrder($google_order_number);
  544. break;
  545. case 'Archive':
  546. $Grequest->SendArchiveOrder($google_order_number);
  547. break;
  548. case 'Refund':
  549. $Grequest->SendRefundOrder($google_order_number,$amount,$reason);
  550. break;
  551. case 'Cancel':
  552. $Grequest->SendCancelOrder($google_order_number,$reason,$comment);
  553. break;
  554. case 'Send Message':
  555. $Grequest->SendBuyerMessage($google_order_number,$message);
  556. break;
  557. }
  558. $newvalue++;
  559. $update_sql = "UPDATE `".$wpdb->prefix."purchase_logs` SET `processed` = '".$newvalue."' WHERE `id` = '".$_POST['id']."' LIMIT 1";
  560. //$wpdb->query($update_sql);
  561. exit();
  562. }
  563. ////changes for usps
  564. if ($_POST['uspsswitch']) {
  565. foreach ($_SESSION['uspsQuote'] as $quotes) {
  566. $total=$_POST['total'];
  567. if ($quotes[$_POST['key']]!='') {
  568. echo nzshpcrt_currency_display($total+$quotes[$_POST['key']],1);
  569. echo "<input type='hidden' value='".$total."' id='shopping_cart_total_price'>";
  570. $_SESSION['usps_shipping']= $quotes[$_POST['key']];
  571. }
  572. }
  573. exit();
  574. }
  575. //changes for usps ends
  576. if(($_GET['user'] == "true") && is_numeric($_POST['prodid']))
  577. {
  578. $memberstatus = get_product_meta($_POST['prodid'],'is_membership',true);
  579. if(($memberstatus[0]=='1') && ($_SESSION['nzshopcrt_cart']!=NULL)){
  580. } else{
  581. $sql = "SELECT * FROM `".$wpdb->prefix."product_list` WHERE `id`='".$_POST['prodid']."' LIMIT 1";
  582. $item_data = $wpdb->get_results($sql,ARRAY_A);
  583. $item_quantity = 0;
  584. if($_SESSION['nzshpcrt_cart'] != null)
  585. {
  586. foreach($_SESSION['nzshpcrt_cart'] as $cart_key => $cart_item)
  587. {
  588. if (($memberstatus[0]!='1')&&($_SESSION['nzshpcrt_cart']!=NULL)){
  589. if($cart_item->product_id == $_POST['prodid']) {
  590. if(($_SESSION['nzshpcrt_cart'][$cart_key]->product_variations === $_POST['variation'])&&($_SESSION['nzshpcrt_cart'][$cart_key]->extras === $_POST['extras'])) {
  591. $item_quantity += $_SESSION['nzshpcrt_cart'][$cart_key]->quantity;
  592. $item_variations = $_SESSION['nzshpcrt_cart'][$cart_key]->product_variations;
  593. }
  594. }
  595. }
  596. }
  597. }
  598. $item_stock = null;
  599. $variation_count = count($_POST['variation']);
  600. if(($variation_count >= 1) && ($variation_count <= 2)) {
  601. foreach($_POST['variation'] as $variation_id) {
  602. if(is_numeric($variation_id)) {
  603. $variation_ids[] = (int)$variation_id;
  604. }
  605. }
  606. if(count($variation_ids) == 2) {
  607. $variation_stock_data = $wpdb->get_row("SELECT * FROM `".$wpdb->prefix."variation_priceandstock` WHERE `product_id` = '".$_POST['prodid']."' AND (`variation_id_1` = '".$variation_ids[0]."' AND `variation_id_2` = '".$variation_ids[1]."') OR (`variation_id_1` = '".$variation_ids[1]."' AND `variation_id_2` = '".$variation_ids[0]."') LIMIT 1",ARRAY_A);
  608. $item_stock = $variation_stock_data['stock'];
  609. } else if(count($variation_ids) == 1) {
  610. $variation_stock_data = $wpdb->get_row("SELECT * FROM `".$wpdb->prefix."variation_priceandstock` WHERE `product_id` = '".$_POST['prodid']."' AND (`variation_id_1` = '".$variation_ids[0]."' AND `variation_id_2` = '0') LIMIT 1",ARRAY_A);
  611. $item_stock = $variation_stock_data['stock'];
  612. }
  613. }
  614. if($item_stock === null) {
  615. $item_stock = $item_data[0]['quantity'];
  616. }
  617. if((($item_data[0]['quantity_limited'] == 1) && ($item_stock > 0) && ($item_stock > $item_quantity)) || ($item_data[0]['quantity_limited'] == 0)) {
  618. $cartcount = count($_SESSION['nzshpcrt_cart']);
  619. if(is_array($_POST['variation'])) { $variations = $_POST['variation']; } else { $variations = null; }
  620. if(is_array($_POST['extras'])) { $extras = $_POST['extras']; } else { $extras = null; }
  621. $updated_quantity = false;
  622. if($_SESSION['nzshpcrt_cart'] != null) {
  623. foreach($_SESSION['nzshpcrt_cart'] as $cart_key => $cart_item) {
  624. if ((!($memberstatus[0]=='1')&&(count($_SESSION['nzshpcrt_cart'])>0))) {
  625. if((int)$cart_item->product_id === (int)$_POST['prodid']) { // force both to integer before testing for identicality
  626. if(($_SESSION['nzshpcrt_cart'][$cart_key]->extras === $extras)&&($_SESSION['nzshpcrt_cart'][$cart_key]->product_variations === $variations) && ((int)$_SESSION['nzshpcrt_cart'][$cart_key]->donation_price == (int)$_POST['donation_price'])) {
  627. if(is_numeric($_POST['quantity'])) {
  628. $_SESSION['nzshpcrt_cart'][$cart_key]->quantity += (int)$_POST['quantity'];
  629. } else {
  630. $_SESSION['nzshpcrt_cart'][$cart_key]->quantity++;
  631. }
  632. $updated_quantity = true;
  633. }
  634. }
  635. }
  636. }
  637. }
  638. if($item_data[0]['donation'] == 1) {
  639. $donation = $_POST['donation_price'];
  640. } else {
  641. $donation = false;
  642. }
  643. if(!(($memberstatus[0]=='1')&&(count($_SESSION['nzshpcrt_cart'])>0))){
  644. $status = get_product_meta($cartt1, 'is_membership', true);
  645. if ($status[0]=='1'){
  646. exit();
  647. }
  648. if($updated_quantity === false) {
  649. if(is_numeric($_POST['quantity'])) {
  650. if($_POST['quantity'] > 0) {
  651. $new_cart_item = new cart_item($_POST['prodid'],$variations,$_POST['quantity'], $donation,$extras);
  652. }
  653. } else {
  654. //echo "correct";
  655. $new_cart_item = new cart_item($_POST['prodid'],$variations, 1, $donation,$extras);
  656. }
  657. $_SESSION['nzshpcrt_cart'][] = $new_cart_item;
  658. }
  659. }
  660. } else {
  661. $quantity_limit = true;
  662. }
  663. $cart = $_SESSION['nzshpcrt_cart'];
  664. if (($memberstatus[0]=='1')&&(count($cart)>1)) {
  665. } else {
  666. $status = get_product_meta($cartt1, 'is_membership', true);
  667. if ($status[0]=='1'){
  668. exit('st');
  669. }
  670. echo "if(document.getElementById('shoppingcartcontents') != null)
  671. {
  672. document.getElementById('shoppingcartcontents').innerHTML = \"".str_replace(Array("\n","\r") , "",addslashes(nzshpcrt_shopping_basket_internals($cart,$quantity_limit))). "\";
  673. }
  674. ";
  675. if(($_POST['prodid'] != null) &&(get_option('fancy_notifications') == 1)) {
  676. echo "if(document.getElementById('fancy_notification_content') != null)
  677. {
  678. document.getElementById('fancy_notification_content').innerHTML = \"".str_replace(Array("\n","\r") , "",addslashes(fancy_notification_content($_POST['prodid'], $quantity_limit))). "\";
  679. jQuery('#loading_animation').css('display', 'none');
  680. jQuery('#fancy_notification_content').css('display', 'block');
  681. }
  682. ";
  683. }
  684. if($_SESSION['slider_state'] == 0) {
  685. echo 'jQuery("#sliding_cart").css({ display: "none"});'."\n\r";
  686. } else {
  687. echo 'jQuery("#sliding_cart").css({ display: "block"});'."\n\r";
  688. }
  689. }
  690. }
  691. exit();
  692. } else if(($_POST['user'] == "true") && ($_POST['emptycart'] == "true")) {
  693. //exit("/* \n\r ".get_option('shopping_cart_url')." \n\r ".print_r($_POST,true)." \n\r */");
  694. $_SESSION['nzshpcrt_cart'] = '';
  695. $_SESSION['nzshpcrt_cart'] = Array();
  696. echo "if(document.getElementById('shoppingcartcontents') != null) {
  697. document.getElementById('shoppingcartcontents').innerHTML = \"".str_replace(Array("\n","\r") , "", addslashes(nzshpcrt_shopping_basket_internals($cart))). "\";
  698. }\n\r";
  699. if($_POST['current_page'] == get_option('shopping_cart_url')) {
  700. echo "window.location = '".get_option('shopping_cart_url')."';\n\r"; // if we are on the checkout page, redirect back to it to clear the non-ajax cart too
  701. }
  702. exit();
  703. }
  704. if ($_POST['store_list']=="true") {
  705. $map_data['address'] = $_POST['addr'];
  706. $map_data['city'] = $_POST['city'];
  707. $map_data['country'] = 'US';
  708. $map_data['zipcode']='';
  709. $map_data['radius'] = '50000';
  710. $map_data['state'] = '';
  711. $map_data['submit'] = 'Find Store';
  712. $stores = getdistance($map_data);
  713. $i=0;
  714. while($rows = mysql_fetch_array($stores)) {
  715. //echo "<pre>".print_r($rows,1)."</pre>";
  716. if ($i==0) {
  717. $closest_store = $rows[5];
  718. }
  719. $i++;
  720. $store_list[$i] = $rows[5];
  721. }
  722. foreach ($store_list as $store){
  723. $output.="<option value='$store'>$store</option>";
  724. }
  725. echo $output;
  726. exit();
  727. }
  728. if($_POST['admin'] == "true") {
  729. if(is_numeric($_POST['prodid'])) {
  730. /* fill product form */
  731. echo nzshpcrt_getproductform($_POST['prodid']);
  732. exit();
  733. } else if(is_numeric($_POST['catid'])) {
  734. /* fill category form */
  735. echo nzshpcrt_getcategoryform($_POST['catid']);
  736. exit();
  737. } else if(is_numeric($_POST['brandid'])) {
  738. /* fill brand form */
  739. echo nzshpcrt_getbrandsform($_POST['brandid']);
  740. exit();
  741. } else if(is_numeric($_POST['variation_id'])) {
  742. echo nzshpcrt_getvariationform($_POST['variation_id']);
  743. exit();
  744. }
  745. if($_POST['hide_ecom_dashboard'] == 'true') {
  746. require_once (ABSPATH . WPINC . '/rss.php');
  747. $rss = fetch_rss('http://www.instinct.co.nz/feed/');
  748. $rss->items = array_slice($rss->items, 0, 5);
  749. $rss_hash = sha1(serialize($rss->items));
  750. update_option('wpsc_ecom_news_hash', $rss_hash);
  751. exit(1);
  752. }
  753. if(($_POST['remove_meta'] == 'true') && is_numeric($_POST['meta_id'])) {
  754. $meta_id = (int)$_POST['meta_id'];
  755. $selected_meta = $wpdb->get_row("SELECT * FROM `{$wpdb->prefix}wpsc_productmeta` WHERE `id` IN('{$meta_id}') ",ARRAY_A);
  756. if($selected_meta != null) {
  757. if($wpdb->query("DELETE FROM `{$wpdb->prefix}wpsc_productmeta` WHERE `id` IN('{$meta_id}') LIMIT 1")) {
  758. echo $meta_id;
  759. exit();
  760. }
  761. }
  762. echo 0;
  763. exit();
  764. }
  765. exit();
  766. }
  767. if(is_numeric($_POST['currencyid'])){
  768. $currency_data = $wpdb->get_results("SELECT `symbol`,`symbol_html`,`code` FROM `".$wpdb->prefix."currency_list` WHERE `id`='".$_POST['currencyid']."' LIMIT 1",ARRAY_A) ;
  769. $price_out = null;
  770. if($currency_data[0]['symbol'] != '') {
  771. $currency_sign = $currency_data[0]['symbol_html'];
  772. } else {
  773. $currency_sign = $currency_data[0]['code'];
  774. }
  775. echo $currency_sign;
  776. exit();
  777. }
  778. //echo "--==->";
  779. if($_POST['buynow'] == "true") {
  780. $id = $_REQUEST['product_id'];
  781. $price = $_REQUEST['price'];
  782. $downloads = get_option('max_downloads');
  783. $product_sql = "SELECT * FROM ".$wpdb->prefix."product_list WHERE id = ".$id." LIMIT 1";
  784. $product_info = $wpdb->get_results($product_sql, ARRAY_A);
  785. $product_info = $product_info[0];
  786. $sessionid = (mt_rand(100,999).time());
  787. $sql = "INSERT INTO `".$wpdb->prefix."purchase_logs` ( `totalprice` , `sessionid` , `date`, `billing_country`, `shipping_country`,`shipping_region`, `user_ID`, `discount_value` ) VALUES ( '".$price."', '".$sessionid."', '".time()."', 'BuyNow', 'BuyNow', 'BuyNow' , NULL , 0)";
  788. $wpdb->query($sql) ;
  789. $log_id = $wpdb->get_var("SELECT `id` FROM `".$wpdb->prefix."purchase_logs` WHERE `sessionid` IN('".$sessionid."') LIMIT 1") ;
  790. $cartsql = "INSERT INTO `".$wpdb->prefix."cart_contents` ( `prodid` , `purchaseid`, `price`, `pnp`, `gst`, `quantity`, `donation`, `no_shipping` ) VALUES ('".$id."', '".$log_id."','".$price."','0', '0','1', '".$donation."', '1')";
  791. $wpdb->query($cartsql);
  792. $wpdb->query("INSERT INTO `".$wpdb->prefix."download_status` ( `fileid` , `purchid` , `downloads` , `active` , `datetime` ) VALUES ( '".$product_info['file']."', '".$log_id."', '$downloads', '0', NOW( ));");
  793. exit();
  794. }
  795. if(($_POST['changeorder'] == "true") && is_numeric($_POST['category_id'])) {
  796. $category_id = (int)$_POST['category_id'];
  797. $hash=$_POST['sort1'];
  798. $order=1;
  799. foreach($hash as $id) {
  800. $wpdb->query("UPDATE `".$wpdb->prefix."product_order` SET `order`=$order WHERE `product_id`=".(int)$id." AND `category_id`=".(int)$category_id." LIMIT 1");
  801. $order++;
  802. }
  803. exit(" ");
  804. }
  805. /* rate item */
  806. if(($_POST['rate_item'] == "true") && is_numeric($_POST['product_id']) && is_numeric($_POST['rating']))
  807. {
  808. $nowtime = time();
  809. $prodid = $_POST['product_id'];
  810. $ip_number = $_SERVER['REMOTE_ADDR'];
  811. $rating = $_POST['rating'];
  812. $cookie_data = explode(",",$_COOKIE['voting_cookie'][$prodid]);
  813. if(is_numeric($cookie_data[0]) && ($cookie_data[0] > 0))
  814. {
  815. $vote_id = $cookie_data[0];
  816. $wpdb->query("UPDATE `".$wpdb->prefix."product_rating` SET `rated` = '".$rating."' WHERE `id` ='".$vote_id."' LIMIT 1 ;");
  817. }
  818. else
  819. {
  820. $insert_sql = "INSERT INTO `".$wpdb->prefix."product_rating` ( `ipnum` , `productid` , `rated`, `time`) VALUES ( '".$ip_number."', '".$prodid."', '".$rating."', '".$nowtime."');";
  821. $wpdb->query($insert_sql);
  822. $data = $wpdb->get_results("SELECT `id`,`rated` FROM `".$wpdb->prefix."product_rating` WHERE `ipnum`='".$ip_number."' AND `productid` = '".$prodid."' AND `rated` = '".$rating."' AND `time` = '".$nowtime."' ORDER BY `id` DESC LIMIT 1",ARRAY_A) ;
  823. $vote_id = $data[0]['id'];
  824. setcookie("voting_cookie[$prodid]", ($vote_id.",".$rating),time()+(60*60*24*360));
  825. }
  826. $output[1]= $prodid;
  827. $output[2]= $rating;
  828. echo $output[1].",".$output[2];
  829. exit();
  830. }
  831. //written by allen
  832. if ($_REQUEST['save_tracking_id'] == "true"){
  833. $id = $_POST['id'];
  834. $value = $_POST['value'];
  835. $update_sql = "UPDATE ".$wpdb->prefix."purchase_logs SET track_id = '".$value."' WHERE id=$id";
  836. $wpdb->query($update_sql);
  837. exit();
  838. }
  839. if(($_POST['get_rating_count'] == "true") && is_numeric($_POST['product_id']))
  840. {
  841. $prodid = $_POST['product_id'];
  842. $data = $wpdb->get_results("SELECT COUNT(*) AS `count` FROM `".$wpdb->prefix."product_rating` WHERE `productid` = '".$prodid."'",ARRAY_A) ;
  843. echo $data[0]['count'].",".$prodid;
  844. exit();
  845. }
  846. /// Pointless AJAX call is pointless
  847. // if(isset($_POST['changeperpage'])) {
  848. // $item_per_page = $_POST['changeperpage'];
  849. // echo $item_per_page;
  850. // exit();
  851. // }
  852. if(($_POST['remove_variation_value'] == "true") && is_numeric($_POST['variation_value_id']))
  853. {
  854. $wpdb->query("DELETE FROM `".$wpdb->prefix."variation_values_associations` WHERE `value_id` = '".$_POST['variation_value_id']."'");
  855. $wpdb->query("DELETE FROM `".$wpdb->prefix."variation_values` WHERE `id` = '".$_POST['variation_value_id']."' LIMIT 1");
  856. exit();
  857. }
  858. if(($_POST['get_updated_price'] == "true") && is_numeric($_POST['product_id']))
  859. {
  860. $notax = $wpdb->get_var("SELECT `notax` FROM `".$wpdb->prefix."product_list` WHERE `id` IN('".$_POST['product_id']."') LIMIT 1");
  861. foreach((array)$_POST['variation'] as $variation)
  862. {
  863. if(is_numeric($variation))
  864. {
  865. $variations[] = $variation;
  866. }
  867. }
  868. foreach((array)$_POST['extra'] as $extra)
  869. {
  870. if(is_numeric($extra))
  871. {
  872. $extras[] = $extra;
  873. }
  874. }
  875. $pm=$_POST['pm'];
  876. echo "product_id=".$_POST['product_id'].";\n";
  877. echo "price=\"".nzshpcrt_currency_display(calculate_product_price($_POST['product_id'], $variations,'stay',$extras), $notax)."\";\n";
  878. //exit(print_r($extras,1));
  879. exit();
  880. }
  881. if(($_REQUEST['log_state'] == "true") && is_numeric($_POST['id']) && is_numeric($_POST['value'])) {
  882. $newvalue = $_POST['value'];
  883. if ($_REQUEST['suspend']=='true'){
  884. if ($_REQUEST['value']==1){
  885. wpsc_member_dedeactivate_subscriptions($_POST['id']);
  886. } else {
  887. wpsc_member_deactivate_subscriptions($_POST['id']);
  888. }
  889. exit();
  890. } else {
  891. $log_data = $wpdb->get_row("SELECT * FROM `".$wpdb->prefix."purchase_logs` WHERE `id` = '".$_POST['id']."' LIMIT 1",ARRAY_A);
  892. if (($newvalue==2) && function_exists('wpsc_member_activate_subscriptions')){
  893. wpsc_member_activate_subscriptions($_POST['id']);
  894. }
  895. $update_sql = "UPDATE `".$wpdb->prefix."purchase_logs` SET `processed` = '".$newvalue."' WHERE `id` = '".$_POST['id']."' LIMIT 1";
  896. $wpdb->query($update_sql);
  897. //echo("/*");
  898. if(($newvalue > $log_data['processed']) && ($log_data['processed'] < 2)) {
  899. transaction_results($log_data['sessionid'],false);
  900. }
  901. //echo("*/");
  902. $stage_sql = "SELECT * FROM `".$wpdb->prefix."purchase_statuses` WHERE `id`='".$newvalue."' AND `active`='1' LIMIT 1";
  903. $stage_data = $wpdb->get_row($stage_sql,ARRAY_A);
  904. echo "document.getElementById(\"form_group_".$_POST['id']."_text\").innerHTML = '".$stage_data['name']."';\n";
  905. echo "document.getElementById(\"form_group_".$_POST['id']."_text\").style.color = '#".$stage_data['colour']."';\n";
  906. $year = date("Y");
  907. $month = date("m");
  908. $start_timestamp = mktime(0, 0, 0, $month, 1, $year);
  909. $end_timestamp = mktime(0, 0, 0, ($month+1), 0, $year);
  910. echo "document.getElementById(\"log_total_month\").innerHTML = '".addslashes(nzshpcrt_currency_display(admin_display_total_price($start_timestamp, $end_timestamp),1))."';\n";
  911. echo "document.getElementById(\"log_total_absolute\").innerHTML = '".addslashes(nzshpcrt_currency_display(admin_display_total_price(),1))."';\n";
  912. exit();
  913. }
  914. }
  915. if(($_POST['list_variation_values'] == "true") && is_numeric($_POST['new_variation_id'])) {
  916. $variation_processor = new nzshpcrt_variations();
  917. echo "variation_value_id = \"".$_POST['new_variation_id']."\";\n";
  918. echo "variation_value_html = \"".$variation_processor->display_variation_values($_POST['prefix'],$_POST['new_variation_id'])."\";\n";
  919. $variations_selected = array_values(array_unique(array_merge((array)$_POST['new_variation_id'], (array)$_POST['variation_id'])));
  920. echo "variation_subvalue_html = \"".str_replace("\n\r", '\n\r', $variation_processor->variations_add_grid_view((array)$variations_selected))."\";\n";
  921. //echo "/*\n\r".print_r(array_values(array_unique(array_merge((array)$_POST['new_variation_id'], $_POST['variation_id']))),true)."\n\r*/";
  922. exit();
  923. }
  924. if(($_POST['redisplay_variation_values'] == "true")) {
  925. $variation_processor = new nzshpcrt_variations();
  926. $variations_selected = array_values(array_unique(array_merge((array)$_POST['new_variation_id'], (array)$_POST['variation_id'])));
  927. foreach($variations_selected as $variation_id) {
  928. // cast everything to integer to make sure nothing nasty gets in.
  929. $variation_list[] = (int)$variation_id;
  930. }
  931. echo $variation_processor->variations_add_grid_view((array)$variation_list);
  932. //echo "/*\n\r".print_r(array_values(array_unique($_POST['variation_id'])),true)."\n\r*/";
  933. exit();
  934. }
  935. if(($_POST['edit_variation_value_list'] == 'true') && is_numeric($_POST['variation_id']) && is_numeric($_POST['product_id'])) {
  936. $variation_id = (int)$_POST['variation_id'];
  937. $product_id = (int)$_POST['product_id'];
  938. $variations_processor = new nzshpcrt_variations();
  939. $variation_values = $variations_processor->falsepost_variation_values($variation_id);
  940. if(is_array($variation_values)) {
  941. //echo(print_r($variation_values,true));
  942. $check_variation_added = $wpdb->get_var("SELECT `id` FROM `".$wpdb->prefix."variation_associations` WHERE `type` IN ('product') AND `associated_id` IN ('{$product_id}') AND `variation_id` IN ('{$variation_id}') LIMIT 1");
  943. if($check_variation_added == null) {
  944. $variations_processor->add_to_existing_product($product_id,$variation_values);
  945. }
  946. echo $variations_processor->display_attached_variations($product_id);
  947. echo $variations_processor->variations_grid_view($product_id);
  948. } else {
  949. echo "false";
  950. }
  951. exit();
  952. }
  953. if(($_POST['remove_form_field'] == "true") && is_numeric($_POST['form_id'])) {
  954. //exit(print_r($user,true));
  955. if(current_user_can('level_7')) {
  956. $wpdb->query("UPDATE `".$wpdb->prefix."collect_data_forms` SET `active` = '0' WHERE `id` ='".$_POST['form_id']."' LIMIT 1 ;");
  957. exit(' ');
  958. }
  959. }
  960. /*
  961. * function for handling the checkout billing address
  962. */
  963. if(preg_match("/[a-zA-Z]{2,4}/", $_POST['billing_country']))
  964. {
  965. if($_SESSION['selected_country'] == $_POST['billing_country'])
  966. {
  967. $do_not_refresh_regions = true;
  968. }
  969. else
  970. {
  971. $do_not_refresh_regions = false;
  972. $_SESSION['selected_country'] = $_POST['billing_country'];
  973. }
  974. if(is_numeric($_POST['form_id']))
  975. {
  976. $form_id = $_POST['form_id'];
  977. $html_form_id = "region_country_form_$form_id";
  978. }
  979. else
  980. {
  981. $html_form_id = 'region_country_form';
  982. }
  983. if(is_numeric($_POST['billing_region']))
  984. {
  985. $_SESSION['selected_region'] = $_POST['billing_region'];
  986. }
  987. $cart =& $_SESSION['nzshpcrt_cart'];
  988. if (($memberstatus[0]=='1')&&(count($cart)>0)){
  989. echo "
  990. ";
  991. }else{
  992. if ($status[0]=='1'){
  993. exit();
  994. }
  995. echo "if(document.getElementById('shoppingcartcontents') != null)
  996. {
  997. document.getElementById('shoppingcartcontents').innerHTML = \"".str_replace(Array("\n","\r") , "",addslashes(nzshpcrt_shopping_basket_internals($cart,$quantity_limit))). "\";
  998. }
  999. ";
  1000. if($do_not_refresh_regions == false)
  1001. {
  1002. $region_list = $wpdb->get_results("SELECT `".$wpdb->prefix."region_tax`.* FROM `".$wpdb->prefix."region_tax`, `".$wpdb->prefix."currency_list` WHERE `".$wpdb->prefix."currency_list`.`isocode` IN('".$_POST['billing_country']."') AND `".$wpdb->prefix."currency_list`.`id` = `".$wpdb->prefix."region_tax`.`country_id`",ARRAY_A) ;
  1003. if($region_list != null)
  1004. {
  1005. $output .= "<select name='collected_data[".$form_id."][1]' class='current_region' onchange='set_billing_country(\\\"$html_form_id\\\", \\\"$form_id\\\");'>";
  1006. //$output .= "<option value=''>None</option>";
  1007. foreach($region_list as $region)
  1008. {
  1009. if($_SESSION['selected_region'] == $region['id'])
  1010. {
  1011. $selected = "selected='true'";
  1012. }
  1013. else
  1014. {
  1015. $selected = "";
  1016. }
  1017. $output .= "<option value='".$region['id']."' $selected>".$region['name']."</option>";
  1018. }
  1019. $output .= "</select>";
  1020. echo "if(document.getElementById('region_select_$form_id') != null)
  1021. {
  1022. document.getElementById('region_select_$form_id').innerHTML = \"".$output."\";
  1023. }
  1024. ";
  1025. }
  1026. else
  1027. {
  1028. echo "if(document.getElementById('region_select_$form_id') != null)
  1029. {
  1030. document.getElementById('region_select_$form_id').innerHTML = \"\";
  1031. }
  1032. ";
  1033. }
  1034. }
  1035. }
  1036. exit();
  1037. }
  1038. if(($_POST['get_country_tax'] == "true") && preg_match("/[a-zA-Z]{2,4}/",$_POST['country_id']))
  1039. {
  1040. $country_id = $_POST['country_id'];
  1041. $region_list = $wpdb->get_results("SELECT `".$wpdb->prefix."region_tax`.* FROM `".$wpdb->prefix."region_tax`, `".$wpdb->prefix."currency_list` WHERE `".$wpdb->prefix."currency_list`.`isocode` IN('".$country_id."') AND `".$wpdb->prefix."currency_list`.`id` = `".$wpdb->prefix."region_tax`.`country_id`",ARRAY_A) ;
  1042. if($region_list != null)
  1043. {
  1044. echo "<select name='base_region'>\n\r";
  1045. foreach($region_list as $region)
  1046. {
  1047. if(get_option('base_region') == $region['id'])
  1048. {
  1049. $selected = "selected='true'";
  1050. }
  1051. else
  1052. {
  1053. $selected = "";
  1054. }
  1055. echo "<option value='".$region['id']."' $selected>".$region['name']."</option>\n\r";
  1056. }
  1057. echo "</select>\n\r";
  1058. }
  1059. else { echo "&nbsp;"; }
  1060. exit();
  1061. }
  1062. /* fill product form */
  1063. if(($_POST['set_slider'] == "true") && is_numeric($_POST['state']))
  1064. {
  1065. $_SESSION['slider_state'] = $_POST['state'];
  1066. exit();
  1067. } /* fill category form */
  1068. if($_GET['action'] == "register")
  1069. {
  1070. $siteurl = get_option('siteurl');
  1071. require_once( ABSPATH . WPINC . '/registration-functions.php');
  1072. if(($_POST['action']=='register') && get_settings('users_can_register'))
  1073. {
  1074. //exit("fail for testing purposes");
  1075. $user_login = sanitize_user( $_POST['user_login'] );
  1076. $user_email = $_POST['user_email'];
  1077. $errors = array();
  1078. if ( $user_login == '' )
  1079. exit($errors['user_login'] = __('<strong>ERROR</strong>: Please enter a username.'));
  1080. /* checking e-mail address */
  1081. if ($user_email == '') {
  1082. exit(__('<strong>ERROR</strong>: Please type your e-mail address.'));
  1083. } else if (!is_email($user_email)) {
  1084. exit( __('<strong>ERROR</strong>: The email address isn&#8217;t correct.'));
  1085. $user_email = '';
  1086. }
  1087. if ( ! validate_username($user_login) ) {
  1088. $errors['user_login'] = __('<strong>ERROR</strong>: This username is invalid. Please enter a valid username.');
  1089. $user_login = '';
  1090. }
  1091. if ( username_exists( $user_login ) )
  1092. exit( __('<strong>ERROR</strong>: This username is already registered, please choose another one.'));
  1093. /* checking the email isn't already used by another user */
  1094. $email_exists = $wpdb->get_row("SELECT user_email FROM $wpdb->users WHERE user_email = '$user_email'");
  1095. if ( $email_exists)
  1096. die (__('<strong>ERROR</strong>: This email address is already registered, please supply another.'));
  1097. if ( 0 == count($errors) ) {
  1098. $password = substr( md5( uniqid( microtime() ) ), 0, 7);
  1099. //xit('there?');
  1100. $user_id = wp_create_user( $user_login, $password, $user_email );
  1101. if ( !$user_id )
  1102. {
  1103. exit(sprintf(__('<strong>ERROR</strong>: Couldn&#8217;t register you... please contact the <a href="mailto:%s">webmaster</a> !'), get_settings('admin_email')));
  1104. }
  1105. else
  1106. {
  1107. wp_new_user_notification($user_id, $password);
  1108. ?>
  1109. <div id="login">
  1110. <h2><?php _e('Registration Complete') ?></h2>
  1111. <p><?php printf(__('Username: %s'), "<strong>" . wp_specialchars($user_login) . "</strong>") ?><br />
  1112. <?php printf(__('Password: %s'), '<strong>' . __('emailed to you') . '</strong>') ?> <br />
  1113. <?php printf(__('E-mail: %s'), "<strong>" . wp_specialchars($user_email) . "</strong>") ?></p>
  1114. </div>
  1115. <?php
  1116. }
  1117. }
  1118. }
  1119. else
  1120. {
  1121. // onsubmit='submit_register_form(this);return false;'
  1122. echo "<div id='login'>
  1123. <h2>Register for this blog</h2>
  1124. <form id='registerform' action='index.php?ajax=true&amp;action=register' onsubmit='submit_register_form(this);return false;' method='post'>
  1125. <p><input type='hidden' value='register' name='action'/>
  1126. <label for='user_login'>Username:</label><br/> <input type='text' value='' maxlength='20' size='20' id='user_login' name='user_login'/><br/></p>
  1127. <p><label for='user_email'>E-mail:</label><br/> <input type='text' value='' maxlength='100' size='25' id='user_email' name='user_email'/></p>
  1128. <p>A password will be emailed to you.</p>
  1129. <p class='submit'><input type='submit' name='submit_form' id='submit' value='Register »'/><img id='register_loading_img' src='".WPSC_URL."/images/loading.gif' alt='' title=''></p>
  1130. </form>
  1131. </div>";
  1132. }
  1133. exit();
  1134. }
  1135. }
  1136. /*
  1137. * AJAX stuff stops here, I would put an exit here, but it may screw up other plugins
  1138. //exit();
  1139. */
  1140. }
  1141. if(isset($_POST['language_setting']) && ($_GET['page'] = WPSC_DIR_NAME.'/options.php'))
  1142. {
  1143. if($user_level >= 7)
  1144. {
  1145. update_option('language_setting', $_POST['language_setting']);
  1146. }
  1147. }
  1148. if(isset($_POST['language_setting']) && ($_GET['page'] = WPSC_DIR_NAME.'/options.php'))
  1149. {
  1150. if($user_level >= 7)
  1151. {
  1152. update_option('language_setting', $_POST['language_setting']);
  1153. }
  1154. }
  1155. if(($_GET['rss'] == "true") && ($_GET['rss_key'] == 'key') && ($_GET['action'] == "purchase_log"))
  1156. {
  1157. $sql = "SELECT * FROM `".$wpdb->prefix."purchase_logs` WHERE `date`!='' ORDER BY `date` DESC";
  1158. $purchase_log = $wpdb->get_results($sql,ARRAY_A);
  1159. header("Content-Type: application/xml; charset=UTF-8");
  1160. header('Content-Disposition: inline; filename="WP_E-Commerce_Purchase_Log.rss"');
  1161. $output = '';
  1162. $output .= "<?xml version='1.0'?>\n\r";
  1163. $output .= "<rss version='2.0'>\n\r";
  1164. $output .= " <channel>\n\r";
  1165. $output .= " <title>WP E-Commerce Product Log</title>\n\r";
  1166. $output .= " <link>".get_option('siteurl')."/wp-admin/admin.php?page=".WPSC_DIR_NAME."/display-log.php</link>\n\r";
  1167. $output .= " <description>This is the WP E-Commerce Product Log RSS feed</description>\n\r";
  1168. $output .= " <generator>WP E-Commerce Plugin</generator>\n\r";
  1169. foreach((array)$purchase_log as $purchase)
  1170. {
  1171. $purchase_link = get_option('siteurl')."/wp-admin/admin.php?page=".WPSC_DIR_NAME."/display-log.php&amp;purchaseid=".$purchase['id'];
  1172. $output .= " <item>\n\r";
  1173. $output .= " <title>Purchase No. ".$purchase['id']."</title>\n\r";
  1174. $output .= " <link>$purchase_link</link>\n\r";
  1175. $output .= " <description>This is an entry in the purchase log.</description>\n\r";
  1176. $output .= " <pubDate>".date("r",$purchase['date'])."</pubDate>\n\r";
  1177. $output .= " <guid>$purchase_link</guid>\n\r";
  1178. $output .= " </item>\n\r";
  1179. }
  1180. $output .= " </channel>\n\r";
  1181. $output .= "</rss>";
  1182. echo $output;
  1183. exit();
  1184. }
  1185. if(($_GET['rss'] == "true") && ($_GET['action'] == "product_list")) {
  1186. $siteurl = get_option('siteurl');
  1187. if(is_numeric($_GET['limit'])) {
  1188. $limit = "LIMIT ".$_GET['limit']."";
  1189. } else {
  1190. $limit = '';
  1191. }
  1192. // LIMIT $startnum
  1193. if(is_numeric($_GET['product_id'])) {
  1194. $sql = "SELECT * FROM `".$wpdb->prefix."product_list` WHERE `active` IN('1') AND `id` IN('".$_GET['product_id']."') LIMIT 1";
  1195. } else if($_GET['random'] == 'true') {
  1196. $sql = "SELECT * FROM `".$wpdb->prefix."product_list` WHERE `active` IN('1') ORDER BY RAND() $limit";
  1197. } else if(is_numeric($_GET['category_id'])) {
  1198. /* man, this is a hard to read SQL statement */
  1199. $sql = "SELECT DISTINCT `".$wpdb->prefix."product_list`.*, `".$wpdb->prefix."item_category_associations`.`category_id`,`".$wpdb->prefix."product_order`.`order`, IF(ISNULL(`".$wpdb->prefix."product_order`.`order`), 0, 1) AS `order_state` FROM `".$wpdb->prefix."product_list` LEFT JOIN `".$wpdb->prefix."item_category_associations` ON `".$wpdb->prefix."product_list`.`id` = `".$wpdb->prefix."item_category_associations`.`product_id` LEFT JOIN `".$wpdb->prefix."product_order` ON ( ( `".$wpdb->prefix."product_list`.`id` = `".$wpdb->prefix."product_order`.`product_id` ) AND ( `".$wpdb->prefix."item_category_associations`.`category_id` = `".$wpdb->prefix."product_order`.`category_id` ) ) WHERE `".$wpdb->prefix."product_list`.`active` = '1' AND `".$wpdb->prefix."item_category_associations`.`category_id` IN ('".$_GET['category_id']."') ORDER BY `order_state` DESC,`".$wpdb->prefix."product_order`.`order` ASC $limit";
  1200. } else {
  1201. $sql = "SELECT DISTINCT * FROM `".$wpdb->prefix."product_list` WHERE `active` IN('1') ORDER BY `id` DESC $limit";
  1202. }
  1203. include_once(WPSC_FILE_PATH."/product_display_functions.php");
  1204. include_once(WPSC_FILE_PATH."/show_cats_brands.php");
  1205. if(isset($_GET['category_id']) and is_numeric($_GET['category_id'])){
  1206. $selected_category = "&amp;category_id=".$_GET['category']."";
  1207. }
  1208. $self = get_option('siteurl')."/index.php?rss=true&amp;action=product_list$selected_category";
  1209. $product_list = $wpdb->get_results($sql,ARRAY_A);
  1210. header("Content-Type: application/xml; charset=UTF-8");
  1211. header('Content-Disposition: inline; filename="E-Commerce_Product_List.rss"');
  1212. $output = "<?xml version='1.0'?>\n\r";
  1213. $output .= "<rss version='2.0' xmlns:atom='http://www.w3.org/2005/Atom' xmlns:product='http://www.buy.com/rss/module/productV2/'>\n\r";
  1214. $output .= " <channel>\n\r";
  1215. $output .= " <title>".get_option('blogname')." Products</title>\n\r";
  1216. $output .= " <link>".get_option('siteurl')."/wp-admin/admin.php?page=".WPSC_DIR_NAME."/display-log.php</link>\n\r";
  1217. $output .= " <description>This is the WP E-Commerce Product List RSS feed</description>\n\r";
  1218. $output .= " <generator>WP E-Commerce Plugin</generator>\n\r";
  1219. $output .= " <atom:link href='$self' rel='self' type='application/rss+xml' />";
  1220. foreach($product_list as $product) {
  1221. $purchase_link = wpsc_product_url($product['id']);
  1222. $output .= " <item>\n\r";
  1223. $output .= " <title>".htmlentities(stripslashes($product['name']), ENT_NOQUOTES, 'UTF-8')."</title>\n\r";
  1224. $output .= " <link>$purchase_link</link>\n\r";
  1225. $output .= " <description>".htmlentities(stripslashes($product['description']), ENT_NOQUOTES, 'UTF-8')."</description>\n\r";
  1226. $output .= " <pubDate>".date("r")."</pubDate>\n\r";
  1227. $output .= " <guid>$purchase_link</guid>\n\r";
  1228. if($product['thumbnail_image'] != null) {
  1229. $image_file_name = $product['thumbnail_image'];
  1230. } else {
  1231. $image_file_name = $product['image'];
  1232. }
  1233. $image_path = WPSC_THUMBNAIL_DIR.$image_file_name;
  1234. if(is_file($image_path) && (filesize($image_path) > 0)) {
  1235. $image_data = @getimagesize($image_path);
  1236. $image_link = WPSC_THUMBNAIL_URL.$product['image'];
  1237. $output .= " <enclosure url='$image_link' length='".filesize($image_path)."' type='".$image_data['mime']."' width='".$image_data[0]."' height='".$image_data[1]."' />\n\r";
  1238. }
  1239. $output .= " <product:price>".$product['price']."</product:price>\n\r";
  1240. $output .= " </item>\n\r";
  1241. }
  1242. $output .= " </channel>\n\r";
  1243. $output .= "</rss>";
  1244. echo $output;
  1245. exit();
  1246. }
  1247. if($_GET['termsandconds'] === 'true')
  1248. {
  1249. echo stripslashes(get_option('terms_and_conditions'));
  1250. exit();
  1251. }
  1252. require_once(WPSC_FILE_PATH . '/processing_functions.php');
  1253. /*
  1254. * This plugin gets the merchants from the merchants directory and
  1255. * needs to search the merchants directory for merchants, the code to do this starts here
  1256. */
  1257. $gateway_directory = WPSC_FILE_PATH.'/merchants';
  1258. $nzshpcrt_merchant_list = nzshpcrt_listdir($gateway_directory);
  1259. //exit("<pre>".print_r($nzshpcrt_merchant_list,true)."</pre>");
  1260. $num=0;
  1261. foreach($nzshpcrt_merchant_list as $nzshpcrt_merchant) {
  1262. if(stristr( $nzshpcrt_merchant , '.php' )) {
  1263. //echo $nzshpcrt_merchant;
  1264. require(WPSC_FILE_PATH."/merchants/".$nzshpcrt_merchant);
  1265. }
  1266. $num++;
  1267. }
  1268. /*
  1269. * and ends here
  1270. */
  1271. if(($_GET['purchase_log_csv'] == "true") && ($_GET['rss_key'] == 'key') && is_numeric($_GET['start_timestamp']) && is_numeric($_GET['end_timestamp']))
  1272. {
  1273. $form_sql = "SELECT * FROM `".$wpdb->prefix."collect_data_forms` WHERE `active` = '1' AND `display_log` = '1';";
  1274. $form_data = $wpdb->get_results($form_sql,ARRAY_A);
  1275. $start_timestamp = $_GET['start_timestamp'];
  1276. $end_timestamp = $_GET['end_timestamp'];
  1277. $data = $wpdb->get_results("SELECT * FROM `".$wpdb->prefix."purchase_logs` WHERE `date` BETWEEN '$start_timestamp' AND '$end_timestamp' ORDER BY `date` DESC",ARRAY_A);
  1278. header('Content-Type: text/csv');
  1279. header('Content-Disposition: inline; filename="Purchase Log '.date("M-d-Y", $start_timestamp).' to '.date("M-d-Y", $end_timestamp).'.csv"');
  1280. foreach($data as $purchase)
  1281. {
  1282. $country_sql = "SELECT * FROM `".$wpdb->prefix."submited_form_data` WHERE `log_id` = '".$purchase['id']."' AND `form_id` = '".get_option('country_form_field')."' LIMIT 1";
  1283. $country_data = $wpdb->get_results($country_sql,ARRAY_A);
  1284. $country = $country_data[0]['value'];
  1285. $output .= "\"".nzshpcrt_find_total_price($purchase['id'],$country) ."\",";
  1286. foreach($form_data as $form_field)
  1287. {
  1288. $collected_data_sql = "SELECT * FROM `".$wpdb->prefix."submited_form_data` WHERE `log_id` = '".$purchase['id']."' AND `form_id` = '".$form_field['id']."' LIMIT 1";
  1289. $collected_data = $wpdb->get_results($collected_data_sql,ARRAY_A);
  1290. $collected_data = $collected_data[0];
  1291. $output .= "\"".$collected_data['value']."\",";
  1292. }
  1293. if(get_option('payment_method') == 2)
  1294. {
  1295. $gateway_name = '';
  1296. foreach($GLOBALS['nzshpcrt_gateways'] as $gateway)
  1297. {
  1298. if($purchase['gateway'] != 'testmode')
  1299. {
  1300. if($gateway['internalname'] == $purchase['gateway'] )
  1301. {
  1302. $gateway_name = $gateway['name'];
  1303. }
  1304. }
  1305. else
  1306. {
  1307. $gateway_name = "Manual Payment";
  1308. }
  1309. }
  1310. $output .= "\"". $gateway_name ."\",";
  1311. }
  1312. if($purchase['processed'] < 1)
  1313. {
  1314. $purchase['processed'] = 1;
  1315. }
  1316. $stage_sql = "SELECT * FROM `".$wpdb->prefix."purchase_statuses` WHERE `id`='".$purchase['processed']."' AND `active`='1' LIMIT 1";
  1317. $stage_data = $wpdb->get_results($stage_sql,ARRAY_A);
  1318. $output .= "\"". $stage_data[0]['name'] ."\",";
  1319. $output .= "\"". date("jS M Y",$purchase['date']) ."\"";
  1320. $cartsql = "SELECT * FROM `".$wpdb->prefix."cart_contents` WHERE `purchaseid`=".$purchase['id']."";
  1321. $cart = $wpdb->get_results($cartsql,ARRAY_A) ;
  1322. //exit(nl2br(print_r($cart,true)));
  1323. foreach($cart as $item)
  1324. {
  1325. $output .= ",";
  1326. $product = $wpdb->get_row("SELECT * FROM `".$wpdb->prefix."product_list` WHERE `id`=".$item['prodid']." LIMIT 1",ARRAY_A);
  1327. $variation_sql = "SELECT * FROM `".$wpdb->prefix."cart_item_variations` WHERE `cart_id`='".$item['id']."'";
  1328. $variation_data = $wpdb->get_results($variation_sql,ARRAY_A);
  1329. $variation_count = count($variation_data);
  1330. if($variation_count >= 1)
  1331. {
  1332. $variation_list = " (";
  1333. $i = 0;
  1334. foreach($variation_data as $variation)
  1335. {
  1336. if($i > 0)
  1337. {
  1338. $variation_list .= ", ";
  1339. }
  1340. $value_id = $variation['value_id'];
  1341. $value_data = $wpdb->get_results("SELECT * FROM `".$wpdb->prefix."variation_values` WHERE `id`='".$value_id."' LIMIT 1",ARRAY_A);
  1342. $variation_list .= $value_data[0]['name'];
  1343. $i++;
  1344. }
  1345. $variation_list .= ")";
  1346. }
  1347. $output .= "\"".$item['quantity']." ".$product['name'].$variation_list."\"";
  1348. }
  1349. $output .= "\n"; // terminates the row/line in the CSV file
  1350. }
  1351. echo $output;
  1352. exit();
  1353. }
  1354. if(is_numeric($_GET['remove']) && ($_SESSION['nzshpcrt_cart'] != null)) {
  1355. $key = $_GET['remove'];
  1356. if(is_object($_SESSION['nzshpcrt_cart'][$key])){
  1357. $_SESSION['nzshpcrt_cart'][$key]->empty_item();
  1358. }
  1359. unset($_SESSION['nzshpcrt_cart'][$key]);
  1360. }
  1361. if($_GET['cart']== 'empty') {
  1362. $_SESSION['nzshpcrt_cart'] = '';
  1363. $_SESSION['nzshpcrt_cart'] = Array();
  1364. }
  1365. if(is_numeric($_POST['quantity']) && is_numeric($_POST['key'])) {
  1366. $quantity = (int)$_POST['quantity'];
  1367. $key = (int)$_POST['key'];
  1368. $product_id = $_SESSION['nzshpcrt_cart'][$key]->product_id;
  1369. $item_data = $wpdb->get_row("SELECT * FROM `{$wpdb->prefix}product_list` WHERE `id`='$product_id' LIMIT 1",ARRAY_A);
  1370. $check_stock = false;
  1371. if((bool)(int)$item_data['quantity_limited'] == true) {
  1372. $item_variations = array_values((array)$_SESSION['nzshpcrt_cart'][$key]->product_variations); // reset the keys to start from 0
  1373. if(count($item_variations) == 2) {
  1374. $variation_stock_data = $wpdb->get_row("SELECT * FROM `{$wpdb->prefix}variation_priceandstock` WHERE `product_id` = '{$product_id}' AND (`variation_id_1` = '{$item_variations[0]}' AND `variation_id_2` = '{$item_variations[1]}') OR (`variation_id_1` = '{$item_variations[1]}' AND `variation_id_2` = '{$item_variations[0]}') LIMIT 1",ARRAY_A);
  1375. $item_stock = $variation_stock_data['stock'];
  1376. } else if(count($item_variations) == 1) {
  1377. $variation_stock_data = $wpdb->get_row("SELECT * FROM `{$wpdb->prefix}variation_priceandstock` WHERE `product_id` = '{$product_id}' AND (`variation_id_1` = '{$item_variations[0]}' AND `variation_id_2` = '0') LIMIT 1",ARRAY_A);
  1378. $item_stock = $variation_stock_data['stock'];
  1379. } else {
  1380. $item_stock = $item_data['quantity'];
  1381. }
  1382. $check_stock = true;
  1383. }
  1384. $_SESSION['out_of_stock'] = false;
  1385. if(is_object($_SESSION['nzshpcrt_cart'][$key])) {
  1386. if($quantity > 0) {
  1387. // if stock is not limited or stock is limited and requested quantity is equal to or less than current stock.
  1388. if(($check_stock == false) || (($check_stock == true) && ($quantity <= $item_stock))) {
  1389. $_SESSION['nzshpcrt_cart'][$key]->quantity = $quantity;
  1390. } else {
  1391. $_SESSION['out_of_stock'] = true;
  1392. }
  1393. } else {
  1394. $_SESSION['nzshpcrt_cart'][$key]->empty_item();
  1395. unset($_SESSION['nzshpcrt_cart'][$key]);
  1396. }
  1397. }
  1398. }
  1399. function nzshpcrt_download_file() {
  1400. global $wpdb,$user_level,$wp_rewrite;
  1401. get_currentuserinfo();
  1402. function readfile_chunked($filename, $retbytes = true) {
  1403. $chunksize = 1 * (1024 * 1024); // how many bytes per chunk
  1404. $buffer = '';
  1405. $cnt = 0;
  1406. $handle = fopen($filename, 'rb');
  1407. if($handle === false) {
  1408. return false;
  1409. }
  1410. while (!feof($handle)) {
  1411. $buffer = fread($handle, $chunksize);
  1412. echo $buffer;
  1413. ob_flush();
  1414. flush();
  1415. if($retbytes) {
  1416. $cnt += strlen($buffer);
  1417. }
  1418. }
  1419. $status = fclose($handle);
  1420. if($retbytes && $status) {
  1421. return $cnt; // return num. bytes delivered like readfile() does.
  1422. }
  1423. return $status;
  1424. }
  1425. if(isset($_GET['downloadid'])) {
  1426. // strip out anything that isnt 'a' to 'z' or '0' to '9'
  1427. $downloadid = preg_replace("/[^a-z0-9]+/i",'',strtolower($_GET['downloadid']));
  1428. $download_data = $wpdb->get_row("SELECT * FROM `".$wpdb->prefix."download_status` WHERE `uniqueid` = '".$downloadid."' AND `downloads` > '0' AND `active`='1' LIMIT 1",ARRAY_A);
  1429. if(($download_data == null) && is_numeric($downloadid)) {
  1430. $download_data = $wpdb->get_row("SELECT * FROM `".$wpdb->prefix."download_status` WHERE `id` = '".$downloadid."' AND `downloads` > '0' AND `active`='1' AND `uniqueid` IS NULL LIMIT 1",ARRAY_A);
  1431. }
  1432. if((get_option('wpsc_ip_lock_downloads') == 1) && ($_SERVER['REMOTE_ADDR'] != null)) {
  1433. $ip_number = $_SERVER['REMOTE_ADDR'];
  1434. if($download_data['ip_number'] == '') {
  1435. // if the IP number is not set, set it
  1436. $wpdb->query("UPDATE `".$wpdb->prefix."download_status` SET `ip_number` = '{$ip_number}' WHERE `id` = '{$download_data['id']}' LIMIT 1");
  1437. } else if($ip_number != $download_data['ip_number']) {
  1438. // if the IP number is set but does not match, fail here.
  1439. // return false;
  1440. exit(WPSC_DOWNLOAD_INVALID);
  1441. }
  1442. }
  1443. //exit("<pre>".print_r($download_data,true)."</pre>");
  1444. if($download_data != null) {
  1445. $file_data = $wpdb->get_results("SELECT * FROM `".$wpdb->prefix."product_files` WHERE `id`='".$download_data['fileid']."' LIMIT 1",ARRAY_A) ;
  1446. $file_data = $file_data[0];
  1447. if((int)$download_data['downloads'] >= 1) {
  1448. $download_count = (int)$download_data['downloads'] - 1;
  1449. } else {
  1450. $download_count = 0;
  1451. }
  1452. $wpdb->query("UPDATE `".$wpdb->prefix."download_status` SET `downloads` = '{$download_count}' WHERE `id` = '{$download_data['id']}' LIMIT 1");
  1453. $wpdb->query("UPDATE `".$wpdb->prefix."purchase_logs` SET `processed` = '4' WHERE `id` = '".$download_data['purchid']."' LIMIT 1");
  1454. if(is_file(WPSC_FILE_DIR.$file_data['idhash'])) {
  1455. header('Content-Type: '.$file_data['mimetype']);
  1456. header('Content-Length: '.filesize(WPSC_FILE_DIR.$file_data['idhash']));
  1457. header('Content-Transfer-Encoding: binary');
  1458. header('Content-Disposition: attachment; filename="'.stripslashes($file_data['filename']).'"');
  1459. if(isset($_SERVER["HTTPS"]) && ($_SERVER["HTTPS"] != '')) {
  1460. /*
  1461. There is a bug in how IE handles downloads from servers using HTTPS, this is part of the fix, you may also need:
  1462. session_cache_limiter('public');
  1463. session_cache_expire(30);
  1464. At the start of your index.php file or before the session is started
  1465. */
  1466. header("Pragma: public");
  1467. header("Expires: 0");
  1468. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  1469. header("Cache-Control: public");
  1470. } else {
  1471. header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
  1472. }
  1473. $filename = WPSC_FILE_DIR.$file_data['idhash'];
  1474. readfile_chunked($filename);
  1475. exit();
  1476. }
  1477. }
  1478. } else {
  1479. if(($_GET['admin_preview'] == "true") && is_numeric($_GET['product_id']) && current_user_can('edit_plugins')) {
  1480. $product_id = $_GET['product_id'];
  1481. $product_data = $wpdb->get_results("SELECT * FROM `".$wpdb->prefix."product_list` WHERE `id` = '$product_id' LIMIT 1",ARRAY_A);
  1482. if(is_numeric($product_data[0]['file']) && ($product_data[0]['file'] > 0)) {
  1483. $file_data = $wpdb->get_results("SELECT * FROM `".$wpdb->prefix."product_files` WHERE `id`='".$product_data[0]['file']."' LIMIT 1",ARRAY_A) ;
  1484. $file_data = $file_data[0];
  1485. if(is_file(WPSC_FILE_DIR.$file_data['idhash'])) {
  1486. header('Content-Type: '.$file_data['mimetype']);
  1487. header('Content-Length: '.filesize(WPSC_FILE_DIR.$file_data['idhash']));
  1488. header('Content-Transfer-Encoding: binary');
  1489. if($_GET['preview_track'] != 'true') {
  1490. header('Content-Disposition: attachment; filename="'.$file_data['filename'].'"');
  1491. } else {
  1492. header('Content-Disposition: inline; filename="'.$file_data['filename'].'"');
  1493. }
  1494. if(isset($_SERVER["HTTPS"]) && ($_SERVER["HTTPS"] != '')) {
  1495. header("Pragma: public");
  1496. header("Expires: 0");
  1497. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  1498. header("Cache-Control: public");
  1499. } else {
  1500. header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
  1501. }
  1502. $filename = WPSC_FILE_DIR.$file_data['idhash'];
  1503. readfile_chunked($filename);
  1504. exit();
  1505. }
  1506. }
  1507. }
  1508. }
  1509. }
  1510. function nzshpcrt_display_preview_image()
  1511. {
  1512. global $wpdb;
  1513. if(is_numeric($_GET['productid']) || is_numeric($_GET['image_id']))
  1514. {
  1515. if(function_exists("getimagesize"))
  1516. {
  1517. if(is_numeric($_GET['productid']))
  1518. {
  1519. $imagesql = "SELECT `image`,`thumbnail_image` FROM `".$wpdb->prefix."product_list` WHERE `id`='".$_GET['productid']."' LIMIT 1";
  1520. $imagedata = $wpdb->get_row($imagesql,ARRAY_A);
  1521. if($_GET['thumbnail'] == 'true')
  1522. {
  1523. if($imagedata['thumbnail_image'] != '')
  1524. {
  1525. $image_name = $imagedata['thumbnail_image'];
  1526. }
  1527. else
  1528. {
  1529. $image_name = $imagedata['image'];
  1530. }
  1531. $imagepath = WPSC_THUMBNAIL_DIR . $image_name;
  1532. }
  1533. else
  1534. {
  1535. $imagepath = WPSC_IMAGE_DIR . $imagedata['image'];
  1536. }
  1537. }
  1538. else if($_GET['image_id'])
  1539. {
  1540. $image_id = $_GET['image_id'];
  1541. $image = $wpdb->get_var("SELECT `image` FROM `".$wpdb->prefix."product_images` WHERE `id` = '$image_id' LIMIT 1");
  1542. $imagepath = WPSC_IMAGE_DIR . $image;
  1543. }
  1544. $image_size = @getimagesize($imagepath);
  1545. if(is_numeric($_GET['height']) && is_numeric($_GET['width']))
  1546. {
  1547. $height = $_GET['height'];
  1548. $width = $_GET['width'];
  1549. }
  1550. else
  1551. {
  1552. $width = $image_size[0];
  1553. $height = $image_size[1];
  1554. }
  1555. if(($height > 0) && ($height <= 1024) && ($width > 0) && ($width <= 1024))
  1556. {
  1557. include("image_preview.php");
  1558. }
  1559. else
  1560. {
  1561. $width = $image_size[0];
  1562. $height = $image_size[1];
  1563. include("image_preview.php");
  1564. }
  1565. }
  1566. }
  1567. }
  1568. function nzshpcrt_listdir($dirname)
  1569. {
  1570. /*
  1571. lists the merchant directory
  1572. */
  1573. $dir = @opendir($dirname);
  1574. $num = 0;
  1575. while(($file = @readdir($dir)) !== false)
  1576. {
  1577. //filter out the dots and any backup files, dont be tempted to correct the "spelling mistake", its to filter out a previous spelling mistake.
  1578. if(($file != "..") && ($file != ".") && !stristr($file, "~") && !stristr($file, "Chekcout") && !( strpos($file, ".") === 0 ))
  1579. {
  1580. $dirlist[$num] = $file;
  1581. $num++;
  1582. }
  1583. }
  1584. if($dirlist == null)
  1585. {
  1586. $dirlist[0] = "paypal.php";
  1587. $dirlist[1] = "testmode.php";
  1588. }
  1589. return $dirlist;
  1590. }
  1591. function nzshpcrt_product_rating($prodid)
  1592. {
  1593. global $wpdb;
  1594. $get_average = $wpdb->get_results("SELECT AVG(`rated`) AS `average`, COUNT(*) AS `count` FROM `".$wpdb->prefix."product_rating` WHERE `productid`='".$prodid."'",ARRAY_A);
  1595. $average = floor($get_average[0]['average']);
  1596. $count = $get_average[0]['count'];
  1597. $output .= " <span class='votetext'>";
  1598. for($l=1; $l<=$average; ++$l)
  1599. {
  1600. $output .= "<img class='goldstar' src='". WPSC_URL."/images/gold-star.gif' alt='$l' title='$l' />";
  1601. }
  1602. $remainder = 5 - $average;
  1603. for($l=1; $l<=$remainder; ++$l)
  1604. {
  1605. $output .= "<img class='goldstar' src='". WPSC_URL."/images/grey-star.gif' alt='$l' title='$l' />";
  1606. }
  1607. $output .= "<span class='vote_total'>&nbsp;(<span id='vote_total_$prodid'>".$count."</span>)</span> \r\n";
  1608. $output .= "</span> \r\n";
  1609. return $output;
  1610. }
  1611. // this appears to have some star rating code in it
  1612. function nzshpcrt_product_vote($prodid, $starcontainer_attributes = '')
  1613. {
  1614. global $wpdb;
  1615. $output = null;
  1616. $useragent = $_SERVER['HTTP_USER_AGENT'];
  1617. $visibility = "style='display: none;'";
  1618. preg_match("/(?<=Mozilla\/)[\d]*\.[\d]*/", $useragent,$rawmozversion );
  1619. $mozversion = $rawmozversion[0];
  1620. if(stristr($useragent,"opera"))
  1621. {
  1622. $firstregexp = "Opera[\s\/]{1}\d\.[\d]+";
  1623. }
  1624. else
  1625. {
  1626. $firstregexp = "MSIE\s\d\.\d";
  1627. }
  1628. preg_match("/$firstregexp|Firefox\/\d\.\d\.\d|Netscape\/\d\.\d\.\d|Safari\/[\d\.]+/", $useragent,$rawbrowserinfo);
  1629. $browserinfo = preg_split("/[\/\s]{1}/",$rawbrowserinfo[0]);
  1630. $browsername = $browserinfo[0];
  1631. $browserversion = $browserinfo[1];
  1632. //exit($browsername . " " . $browserversion);
  1633. if(($browsername == 'MSIE') && ($browserversion < 7.0))
  1634. {
  1635. $starimg = ''. get_option('siteurl').'/wp-content/plugins/wp-shopping-cart/images/star.gif';
  1636. $ie_javascript_hack = "onmouseover='ie_rating_rollover(this.id,1)' onmouseout='ie_rating_rollover(this.id,0)'";
  1637. }
  1638. else
  1639. {
  1640. $starimg = ''. get_option('siteurl').'/wp-content/plugins/wp-shopping-cart/images/24bit-star.png';
  1641. $ie_javascript_hack = '';
  1642. }
  1643. $cookie_data = explode(",",$_COOKIE['voting_cookie'][$prodid]);
  1644. if(is_numeric($cookie_data[0]))
  1645. {
  1646. $vote_id = $cookie_data[0];
  1647. }
  1648. $chkrate = $wpdb->get_results("SELECT * FROM `".$wpdb->prefix."product_rating` WHERE `id`='".$vote_id."' LIMIT 1",ARRAY_A);
  1649. //$output .= "<pre>".print_r($chkrate,true)."</pre>";
  1650. if($chkrate[0]['rated'] > 0)
  1651. {
  1652. $rating = $chkrate[0]['rated'];
  1653. $type = 'voted';
  1654. }
  1655. else
  1656. {
  1657. $rating = 0;
  1658. $type = 'voting';
  1659. }
  1660. //$output .= "<pre>".print_r($rating,true)."</pre>";
  1661. $output .= "<div class='starcontainer' $starcontainer_attributes >\r\n";
  1662. for($k=1; $k<=5; ++$k)
  1663. {
  1664. $style = '';
  1665. if($k <= $rating)
  1666. {
  1667. $style = "style='background: url(". WPSC_URL."/images/gold-star.gif)'";
  1668. }
  1669. $output .= " <a id='star".$prodid."and".$k."_link' onclick='rate_item(".$prodid.",".$k.")' class='star$k' $style $ie_javascript_hack ><img id='star".$prodid."and".$k."' class='starimage' src='$starimg' alt='$k' title='$k' /></a>\r\n";
  1670. }
  1671. $output .= " </div>\r\n";
  1672. $output .= "";
  1673. $voted = TXT_WPSC_CLICKSTARSTORATE;
  1674. switch($ratecount[0]['count'])
  1675. {
  1676. case 0:
  1677. $votestr = TXT_WPSC_NOVOTES;
  1678. break;
  1679. case 1:
  1680. $votestr = TXT_WPSC_1VOTE;
  1681. break;
  1682. default:
  1683. $votestr = $ratecount[0]['count']." ".TXT_WPSC_VOTES2;
  1684. break;
  1685. }
  1686. for($i= 5; $i>= 1; --$i)
  1687. {
  1688. //$tmpcount = $this->db->GetAll("SELECT COUNT(*) AS 'count' FROM `pxtrated` WHERE `pxtid`=".$dbdat['rID']." AND `rated`=$i");
  1689. switch($tmpcount[0]['count'])
  1690. {
  1691. case 0:
  1692. $othervotes .= "";
  1693. break;
  1694. case 1:
  1695. $othervotes .= "<br />". $tmpcount[0]['count'] . " ".TXT_WPSC_PERSONGIVEN." $i ".TXT_WPSC_PERSONGIVEN2;
  1696. break;
  1697. default:
  1698. $othervotes .= "<br />". $tmpcount[0]['count'] . " ".TXT_WPSC_PEOPLEGIVEN." $i ".TXT_WPSC_PEOPLEGIVEN2;
  1699. break;
  1700. }
  1701. } /*
  1702. $output .= "</td><td class='centerer2'>&nbsp;</td></tr>\r\n";
  1703. $output .= "<tr><td colspan='3' class='votes' >\r\n";//id='startxtmove'
  1704. $output .= " <p class='votes'> ".$votestr."<br />$voted <br />
  1705. $othervotes</p>";*/
  1706. return Array($output,$type);
  1707. } //*/
  1708. function get_country($country_code)
  1709. {
  1710. global $wpdb;
  1711. $country = $wpdb->get_var("SELECT `country` FROM `".$wpdb->prefix."currency_list` WHERE `isocode` IN ('".$country_code."') LIMIT 1");
  1712. return $country;
  1713. }
  1714. function get_region($region_code)
  1715. {
  1716. global $wpdb;
  1717. $region = $wpdb->get_var("SELECT `name` FROM `".$wpdb->prefix."region_tax` WHERE `id` IN('$region_code')");
  1718. return $region;
  1719. }
  1720. function get_brand($brand_id)
  1721. {
  1722. global $wpdb;
  1723. $brand_data = $wpdb->get_results("SELECT `name` FROM `".$wpdb->prefix."product_brands` WHERE `id` IN ('".$brand_id."') LIMIT 1",ARRAY_A);
  1724. return $brand_data[0]['name'];
  1725. }
  1726. function filter_input_wp($input) {
  1727. // if the input is numeric, then its probably safe
  1728. if(is_numeric($input)) {
  1729. $output = $input;
  1730. } else {
  1731. // if its not numeric, then make it safe
  1732. if(!get_magic_quotes_gpc()) {
  1733. $output = mysql_real_escape_string($input);
  1734. } else {
  1735. $output = mysql_real_escape_string(stripslashes($input));
  1736. }
  1737. }
  1738. return $output;
  1739. }
  1740. function make_csv($array)
  1741. {
  1742. $count = count($array);
  1743. $num = 1;
  1744. foreach($array as $value)
  1745. {
  1746. $output .= "'$value'";
  1747. if($num < $count)
  1748. {
  1749. $output .= ",";
  1750. }
  1751. $num++;
  1752. }
  1753. return $output;
  1754. }
  1755. function nzshpcrt_product_log_rss_feed() {
  1756. echo "<link type='application/rss+xml' href='".get_option('siteurl')."/index.php?rss=true&amp;rss_key=key&amp;action=purchase_log&amp;type=rss' title='WP E-Commerce Purchase Log RSS' rel='alternate'/>";
  1757. }
  1758. function nzshpcrt_product_list_rss_feed() {
  1759. if(isset($_GET['category']) and is_numeric($_GET['category'])){
  1760. $selected_category = "&amp;category_id=".$_GET['category']."";
  1761. }
  1762. echo "<link rel='alternate' type='application/rss+xml' title='".get_option('blogname')." Product List RSS' href='".get_option('siteurl')."/index.php?rss=true&amp;action=product_list$selected_category'/>";
  1763. }
  1764. //handles replacing the tags in the pages
  1765. function nzshpcrt_products_page($content = '') {
  1766. //if(WPSC_DEBUG === true) {wpsc_debug_start_subtimer('nzshpcrt_products_page','start');}
  1767. //exit(htmlentities($content));
  1768. if(preg_match("/\[productspage\]/",$content)) {
  1769. $GLOBALS['nzshpcrt_activateshpcrt'] = true;
  1770. ob_start();
  1771. include_once(WPSC_FILE_PATH . "/products_page.php");
  1772. $output = ob_get_contents();
  1773. ob_end_clean();
  1774. //if(WPSC_DEBUG === true) {wpsc_debug_start_subtimer('nzshpcrt_products_page','stop');}
  1775. //return preg_replace("/\[productspage\]/",$output, $content);
  1776. return preg_replace("/(<p>)*\[productspage\](<\/p>)*/",$output, $content);
  1777. } else {
  1778. return $content;
  1779. }
  1780. }
  1781. function nzshpcrt_shopping_cart($content = '')
  1782. {
  1783. if(preg_match("/\[shoppingcart\]/",$content))
  1784. {
  1785. ob_start();
  1786. include_once(WPSC_FILE_PATH . "/shopping_cart.php");
  1787. $output = ob_get_contents();
  1788. ob_end_clean();
  1789. return preg_replace("/(<p>)*\[shoppingcart\](<\/p>)*/",$output, $content);
  1790. }
  1791. else
  1792. {
  1793. return $content;
  1794. }
  1795. }
  1796. function nzshpcrt_checkout($content = '')
  1797. {
  1798. if(preg_match("/\[checkout\]/",$content))
  1799. {
  1800. ob_start();
  1801. include_once(WPSC_FILE_PATH . "/checkout.php");
  1802. $output = ob_get_contents();
  1803. ob_end_clean();
  1804. return preg_replace("/(<p>)*\[checkout\](<\/p>)*/",$output, $content);
  1805. }
  1806. else
  1807. {
  1808. return $content;
  1809. }
  1810. }
  1811. function nzshpcrt_transaction_results($content = '')
  1812. {
  1813. if(preg_match("/\[transactionresults\]/",$content))
  1814. {
  1815. ob_start();
  1816. include_once(WPSC_FILE_PATH . "/transaction_results.php");
  1817. $output = ob_get_contents();
  1818. ob_end_clean();
  1819. return preg_replace("/(<p>)*\[transactionresults\](<\/p>)*/",$output, $content);
  1820. }
  1821. else
  1822. {
  1823. return $content;
  1824. }
  1825. }
  1826. function nzshpcrt_user_log($content = '') {
  1827. if(preg_match("/\[userlog\]/",$content)) {
  1828. ob_start();
  1829. include_once(WPSC_FILE_PATH . '/user-log.php');
  1830. $output = ob_get_contents();
  1831. ob_end_clean();
  1832. return preg_replace("/(<p>)*\[userlog\](<\/p>)*/",$output, $content);
  1833. } else {
  1834. return $content;
  1835. }
  1836. }
  1837. //displays a list of categories when the code [showcategories] is present in a post or page.
  1838. function nzshpcrt_show_categories($content = '') {
  1839. if(preg_match("/\[showcategories\]/",$content)) {
  1840. $GLOBALS['nzshpcrt_activateshpcrt'] = true;
  1841. $output = nzshpcrt_display_categories_groups();
  1842. return preg_replace("/(<p>)*\[showcategories\](<\/p>)*/",$output, $content);
  1843. } else {
  1844. return $content;
  1845. }
  1846. }
  1847. // substitutes in the buy now buttons where the shortcode is in a post.
  1848. function nzshpcrt_substitute_buy_now_button($content = '') {
  1849. if(preg_match_all("/\[buy_now_button=([\d]+)\]/", $content, $matches)) {
  1850. foreach($matches[1] as $key => $product_id) {
  1851. $original_string = $matches[0][$key];
  1852. //print_r($matches);
  1853. $output = wpsc_buy_now_button($product_id, true);
  1854. $content = str_replace($original_string, $output, $content);
  1855. }
  1856. }
  1857. return $content;
  1858. }
  1859. // This function displays the category gropus, it is used by the above function
  1860. function nzshpcrt_display_categories_groups() {
  1861. global $wpdb;
  1862. if(get_option('permalink_structure') != '') {
  1863. $seperator ="?";
  1864. } else {
  1865. $seperator ="&amp;";
  1866. }
  1867. if(function_exists('gold_shpcrt_search_form') && get_option('show_search') == 1) {
  1868. echo gold_shpcrt_search_form();
  1869. }
  1870. //include("show_cats_brands.php");
  1871. if (get_option('cat_brand_loc') == 0) {
  1872. show_cats_brands();
  1873. }
  1874. }
  1875. function add_product_meta($product_id, $key, $value, $unique = false, $custom = false) {
  1876. global $wpdb, $post_meta_cache, $blog_id;
  1877. $product_id = (int)$product_id;
  1878. if($product_id > 0) {
  1879. if(($unique == true) && $wpdb->get_var("SELECT meta_key FROM `".$wpdb->prefix."wpsc_productmeta` WHERE meta_key = '$key' AND product_id = '$product_id'")) {
  1880. return false;
  1881. }
  1882. $value = $wpdb->escape(maybe_serialize($value));
  1883. if(!$wpdb->get_var("SELECT meta_key FROM `".$wpdb->prefix."wpsc_productmeta` WHERE meta_key = '$key' AND product_id = '$product_id'")) {
  1884. $custom = (int)$custom;
  1885. $wpdb->query("INSERT INTO `".$wpdb->prefix."wpsc_productmeta` (product_id,meta_key,meta_value, custom) VALUES ('$product_id','$key','$value', '$custom')");
  1886. } else {
  1887. $wpdb->query("UPDATE `".$wpdb->prefix."wpsc_productmeta` SET meta_value = '$value' WHERE meta_key = '$key' AND product_id = '$product_id'");
  1888. }
  1889. return true;
  1890. }
  1891. return false;
  1892. }
  1893. function delete_product_meta($product_id, $key, $value = '') {
  1894. global $wpdb, $post_meta_cache, $blog_id;
  1895. $product_id = (int)$product_id;
  1896. if($product_id > 0) {
  1897. if ( empty($value) ) {
  1898. $meta_id = $wpdb->get_var("SELECT id FROM `".$wpdb->prefix."wpsc_productmeta` WHERE product_id = '$product_id' AND meta_key = '$key'");
  1899. if(is_numeric($meta_id) && ($meta_id > 0)) {
  1900. $wpdb->query("DELETE FROM `".$wpdb->prefix."wpsc_productmeta` WHERE product_id = '$product_id' AND meta_key = '$key'");
  1901. }
  1902. } else {
  1903. $meta_id = $wpdb->get_var("SELECT id FROM `".$wpdb->prefix."wpsc_productmeta` WHERE product_id = '$product_id' AND meta_key = '$key' AND meta_value = '$value'");
  1904. if(is_numeric($meta_id) && ($meta_id > 0)) {
  1905. $wpdb->query("DELETE FROM `".$wpdb->prefix."wpsc_productmeta` WHERE product_id = '$product_id' AND meta_key = '$key' AND meta_value = '$value'");
  1906. }
  1907. }
  1908. }
  1909. return true;
  1910. }
  1911. function get_product_meta($product_id, $key, $single = false) {
  1912. global $wpdb, $post_meta_cache, $blog_id;
  1913. $product_id = (int)$product_id;
  1914. if($product_id > 0) {
  1915. $meta_id = $wpdb->get_var("SELECT `id` FROM `".$wpdb->prefix."wpsc_productmeta` WHERE `meta_key` IN('$key') AND `product_id` = '$product_id' LIMIT 1");
  1916. if(is_numeric($meta_id) && ($meta_id > 0)) {
  1917. if($single != false) {
  1918. $meta_values[0] = maybe_unserialize($wpdb->get_var("SELECT `meta_value` FROM `".$wpdb->prefix."wpsc_productmeta` WHERE `meta_key` IN('$key') AND `product_id` = '$product_id' LIMIT 1"));
  1919. } else {
  1920. $temp_meta_values = $wpdb->get_results("SELECT `meta_value` FROM `".$wpdb->prefix."wpsc_productmeta` WHERE `meta_key` IN('$key') AND `product_id` = '$product_id'", ARRAY_A);
  1921. foreach($temp_meta_values as $value) {
  1922. $meta_values[] = maybe_unserialize($value['meta_value']);
  1923. }
  1924. }
  1925. }
  1926. } else {
  1927. $meta_values = false;
  1928. }
  1929. return $meta_values;
  1930. }
  1931. function update_product_meta($product_id, $key, $value, $prev_value = '') {
  1932. global $wpdb, $blog_id;
  1933. $product_id = (int)$product_id;
  1934. if($product_id > 0) {
  1935. $value = $wpdb->escape(maybe_serialize($value));
  1936. if(!empty($prev_value)) {
  1937. $prev_value = $wpdb->escape(maybe_serialize($prev_value));
  1938. }
  1939. if($wpdb->get_var("SELECT meta_key FROM `".$wpdb->prefix."wpsc_productmeta` WHERE `meta_key` IN('$key') AND product_id = '$product_id'")) {
  1940. if (empty($prev_value)) {
  1941. $wpdb->query("UPDATE `".$wpdb->prefix."wpsc_productmeta` SET `meta_value` = '$value' WHERE `meta_key` IN('$key') AND product_id = '$product_id'");
  1942. } else {
  1943. $wpdb->query("UPDATE `".$wpdb->prefix."wpsc_productmeta` SET `meta_value` = '$value' WHERE `meta_key` IN('$key') AND product_id = '$product_id' AND meta_value = '$prev_value'");
  1944. }
  1945. } else {
  1946. $wpdb->query("INSERT INTO `".$wpdb->prefix."wpsc_productmeta` (product_id,meta_key,meta_value) VALUES ('$product_id','$key','$value')");
  1947. }
  1948. return true;
  1949. }
  1950. }
  1951. function wpsc_refresh_page_urls($content) {
  1952. global $wpdb;
  1953. $wpsc_pageurl_option['product_list_url'] = '[productspage]';
  1954. $wpsc_pageurl_option['shopping_cart_url'] = '[shoppingcart]';
  1955. $check_chekout = $wpdb->get_var("SELECT `guid` FROM `".$wpdb->prefix."posts` WHERE `post_content` LIKE '%[checkout]%' LIMIT 1");
  1956. if($check_chekout != null) {
  1957. $wpsc_pageurl_option['checkout_url'] = '[checkout]';
  1958. } else {
  1959. $wpsc_pageurl_option['checkout_url'] = '[checkout]';
  1960. }
  1961. $wpsc_pageurl_option['transact_url'] = '[transactionresults]';
  1962. $wpsc_pageurl_option['user_account_url'] = '[userlog]';
  1963. $changes_made = false;
  1964. foreach($wpsc_pageurl_option as $option_key => $page_string) {
  1965. $post_id = $wpdb->get_var("SELECT `ID` FROM `".$wpdb->prefix."posts` WHERE `post_content` LIKE '%$page_string%' LIMIT 1");
  1966. $the_new_link = get_permalink($post_id);
  1967. if(stristr(get_option($option_key), "https://")) {
  1968. $the_new_link = str_replace('http://', "https://",$the_new_link);
  1969. }
  1970. update_option($option_key, $the_new_link);
  1971. }
  1972. return $content;
  1973. }
  1974. function wpsc_product_permalinks($rewrite_rules) {
  1975. global $wpdb, $wp_rewrite;
  1976. $page_details = $wpdb->get_row("SELECT * FROM `".$wpdb->posts."` WHERE `post_content` LIKE '%[productspage]%' LIMIT 1", ARRAY_A);
  1977. $is_index = false;
  1978. if((get_option('page_on_front') == $page_details['ID']) && (get_option('show_on_front') == 'page')) {
  1979. $is_index = true;
  1980. }
  1981. $page_name = $page_details['post_name'];
  1982. if(!function_exists('wpsc_rewrite_categories')) { // to stop this function from being declared multiple times, which causes wordpress to fail.
  1983. function wpsc_rewrite_categories($page_name, $id = null, $level = 0, $parent_categories = array(), $is_index = false) {
  1984. global $wpdb,$category_data;
  1985. if($is_index == true) {
  1986. $rewrite_page_name = '';
  1987. } else {
  1988. $rewrite_page_name = $page_name.'/';
  1989. }
  1990. if(is_numeric($id)) {
  1991. $category_sql = "SELECT * FROM `".$wpdb->prefix."product_categories` WHERE `active`='1' AND `category_parent` = '".$id."' ORDER BY `id`";
  1992. $category_list = $wpdb->get_results($category_sql,ARRAY_A);
  1993. } else {
  1994. $category_sql = "SELECT * FROM `".$wpdb->prefix."product_categories` WHERE `active`='1' AND `category_parent` = '0' ORDER BY `id`";
  1995. $category_list = $wpdb->get_results($category_sql,ARRAY_A);
  1996. }
  1997. if($category_list != null) {
  1998. foreach($category_list as $category) {
  1999. if($level === 0) {
  2000. $parent_categories = array();
  2001. }
  2002. $parent_categories[] = $category['nice-name'];
  2003. $new_rules[($rewrite_page_name.implode($parent_categories,"/").'/?$')] = 'index.php?pagename='.$page_name.'&product_category='.$category['id'];
  2004. $new_rules[($rewrite_page_name.implode($parent_categories,"/").'/([A-Za-z0-9\-]+)/?$')] = 'index.php?pagename='.$page_name.'&product_category='.$category['id'].'&product_name=$matches[1]';
  2005. $sub_rules = wpsc_rewrite_categories($page_name, $category['id'], ($level+1), $parent_categories, $is_index);
  2006. array_pop($parent_categories);
  2007. $new_rules = array_merge((array)$new_rules, (array)$sub_rules);
  2008. }
  2009. }
  2010. return $new_rules;
  2011. }
  2012. }
  2013. $new_rules = wpsc_rewrite_categories($page_name, null, 0, null, $is_index);
  2014. $new_rules = array_reverse((array)$new_rules);
  2015. //$new_rules[$page_name.'/product-tag/(.+?)/page/?([0-9]{1,})/?$'] = 'index.php?pagename='.$page_name.'&ptag=$matches[1]&paged=$matches[2]';
  2016. $new_rules[$page_name.'/tag/([A-Za-z0-9\-]+)?$'] = 'index.php?pagename='.$page_name.'&ptag=$matches[1]';
  2017. $new_rewrite_rules = array_merge((array)$new_rules,(array)$rewrite_rules);
  2018. return $new_rewrite_rules;
  2019. }
  2020. function wpsc_query_vars($vars) {
  2021. $vars[] = "product_category";
  2022. $vars[] = "product_name";
  2023. return $vars;
  2024. }
  2025. add_filter('query_vars', 'wpsc_query_vars');
  2026. // using page_rewrite_rules makes it so that odd permalink structures like /%category%/%postname%.htm do not override the plugin permalinks.
  2027. add_filter('page_rewrite_rules', 'wpsc_product_permalinks');
  2028. function wpsc_replace_the_title($input) {
  2029. global $wpdb, $wp_query;
  2030. if(is_numeric($wp_query->query_vars['product_category'])) {
  2031. // using debug_backtrace here is not a good way of doing this, but wordpress provides no way to differentiate between the various uses of this plugin hook.
  2032. $backtrace = debug_backtrace();
  2033. if($backtrace[3]['function'] == 'get_the_title') {
  2034. return $wpdb->get_var("SELECT `name` FROM `".$wpdb->prefix."product_categories` WHERE `id`='{$wp_query->query_vars['product_category']}' LIMIT 1");
  2035. }
  2036. }
  2037. return $input;
  2038. }
  2039. add_filter('the_title', 'wpsc_replace_the_title', 10, 2);
  2040. require_once(WPSC_FILE_PATH . '/product_display_functions.php');
  2041. if(is_file(WPSC_FILE_PATH.'/gold_shopping_cart.php')) {
  2042. require_once(WPSC_FILE_PATH.'/gold_shopping_cart.php');
  2043. }
  2044. require_once(WPSC_FILE_PATH."/currency_converter.inc.php");
  2045. require_once(WPSC_FILE_PATH."/form_display_functions.php");
  2046. require_once(WPSC_FILE_PATH."/shopping_cart_functions.php");
  2047. require_once(WPSC_FILE_PATH."/homepage_products_functions.php");
  2048. require_once(WPSC_FILE_PATH."/transaction_result_functions.php");
  2049. include_once(WPSC_FILE_PATH.'/submit_checkout_function.php');
  2050. require_once(WPSC_FILE_PATH."/admin-form-functions.php");
  2051. require_once(WPSC_FILE_PATH."/shipwire_functions.php");
  2052. /* widget_section */
  2053. include_once(WPSC_FILE_PATH.'/widgets/product_tag_widget.php');
  2054. include_once(WPSC_FILE_PATH.'/widgets/shopping_cart_widget.php');
  2055. include_once(WPSC_FILE_PATH.'/widgets/category_widget.php');
  2056. include_once(WPSC_FILE_PATH.'/widgets/donations_widget.php');
  2057. include_once(WPSC_FILE_PATH.'/widgets/specials_widget.php');
  2058. include_once(WPSC_FILE_PATH.'/widgets/latest_product_widget.php');
  2059. include_once(WPSC_FILE_PATH.'/widgets/price_range_widget.php');
  2060. include_once(WPSC_FILE_PATH.'/widgets/admin_menu_widget.php');
  2061. include_once(WPSC_FILE_PATH.'/image_processing.php');
  2062. include_once(WPSC_FILE_PATH."/show_cats_brands.php");
  2063. $theme_path = WPSC_FILE_PATH . '/themes/';
  2064. if((get_option('wpsc_selected_theme') != '') && (file_exists($theme_path.get_option('wpsc_selected_theme')."/".get_option('wpsc_selected_theme').".php") )) {
  2065. include_once(WPSC_FILE_PATH.'/themes/'.get_option('wpsc_selected_theme').'/'.get_option('wpsc_selected_theme').'.php');
  2066. }
  2067. $current_version_number = get_option('wpsc_version');
  2068. if(count(explode(".",$current_version_number)) > 2) {
  2069. // in a previous version, I accidentally had the major version number have two dots, and three numbers
  2070. // this code rectifies that mistake
  2071. $current_version_number_array = explode(".",$current_version_number);
  2072. array_pop($current_version_number_array);
  2073. $current_version_number = (float)implode(".", $current_version_number_array );
  2074. } else if(!is_numeric(get_option('wpsc_version'))) {
  2075. $current_version_number = 0;
  2076. }
  2077. if(isset($_GET['activate']) && ($_GET['activate'] == 'true')) {
  2078. include_once("install_and_update.php");
  2079. add_action('init', 'nzshpcrt_install');
  2080. } else if(($current_version_number < WPSC_VERSION ) || (($current_version_number == WPSC_VERSION ) && (get_option('wpsc_minor_version') <= WPSC_MINOR_VERSION))) {
  2081. include_once("install_and_update.php");
  2082. add_action('init', 'wpsc_auto_update');
  2083. }
  2084. add_filter('single_post_title','wpsc_post_title_seo');
  2085. function nzshpcrt_enable_page_filters($excerpt = ''){
  2086. global $wp_query;
  2087. add_filter('the_content', 'nzshpcrt_products_page', 12);
  2088. add_filter('the_content', 'nzshpcrt_shopping_cart', 12);
  2089. add_filter('the_content', 'nzshpcrt_transaction_results', 12);
  2090. add_filter('the_content', 'nzshpcrt_checkout', 12);
  2091. add_filter('the_content', 'nszhpcrt_homepage_products', 12);
  2092. add_filter('the_content', 'nzshpcrt_user_log', 12);
  2093. add_filter('the_content', 'nszhpcrt_category_tag', 12);
  2094. add_filter('the_content', 'nzshpcrt_show_categories', 12);
  2095. add_filter('the_content', 'nzshpcrt_substitute_buy_now_button', 12);
  2096. return $excerpt;
  2097. }
  2098. function nzshpcrt_disable_page_filters($excerpt = '') {
  2099. remove_filter('the_content', 'nzshpcrt_products_page');
  2100. remove_filter('the_content', 'nzshpcrt_shopping_cart');
  2101. remove_filter('the_content', 'nzshpcrt_transaction_results');
  2102. remove_filter('the_content', 'nzshpcrt_checkout');
  2103. remove_filter('the_content', 'nszhpcrt_homepage_products');
  2104. remove_filter('the_content', 'nzshpcrt_user_log');
  2105. remove_filter('the_content', 'nszhpcrt_category_tag');
  2106. remove_filter('the_content', 'nzshpcrt_show_categories');
  2107. remove_filter('the_content', 'nzshpcrt_substitute_buy_now_button');
  2108. return $excerpt;
  2109. }
  2110. nzshpcrt_enable_page_filters();
  2111. add_filter('get_the_excerpt', 'nzshpcrt_disable_page_filters', -1000000);
  2112. add_filter('get_the_excerpt', 'nzshpcrt_enable_page_filters', 1000000);
  2113. add_action('wp_head', 'nzshpcrt_style');
  2114. add_action('admin_head', 'wpsc_admin_css');
  2115. if($_GET['page'] == WPSC_DIR_NAME."/display-log.php") {
  2116. add_action('admin_head', 'nzshpcrt_product_log_rss_feed');
  2117. }
  2118. add_action('wp_head', 'nzshpcrt_javascript');
  2119. add_action('wp_head', 'nzshpcrt_product_list_rss_feed');
  2120. if(($_POST['submitwpcheckout'] == 'true')) {
  2121. add_action('init', 'nzshpcrt_submit_checkout');
  2122. }
  2123. add_action('init', 'nzshpcrt_submit_ajax');
  2124. add_action('init', 'nzshpcrt_download_file');
  2125. add_action('init', 'nzshpcrt_display_preview_image');
  2126. if(stristr($_GET['page'], WPSC_DIR_NAME)) {
  2127. add_action('admin_notices', 'wpsc_admin_notices');
  2128. }
  2129. function wpsc_admin_notices() {
  2130. global $wpdb;
  2131. if(get_option('wpsc_default_category') != 'all') {
  2132. if((get_option('wpsc_default_category') < 1) || $wpdb->get_var("SELECT `id` FROM `{$wpdb->prefix}product_categories` WHERE `id` IN ('".get_option('wpsc_default_category')."') AND `active` NOT IN ('1');")) { // if there is no default category or it is deleted
  2133. if(!$_POST['wpsc_default_category']) { // if we are not changing the default category
  2134. echo "<div id='message' class='updated fade' style='background-color: rgb(255, 251, 204);'>";
  2135. echo "<p>".TXT_WPSC_NO_DEFAULT_PRODUCTS."</p>";
  2136. echo "</div>\n\r";
  2137. }
  2138. }
  2139. }
  2140. }
  2141. function wpsc_admin_latest_activity() {
  2142. $user = wp_get_current_user();
  2143. if($user->user_level>9){
  2144. echo "<div>";
  2145. echo "<h3>".TXT_WPSC_E_COMMERCE."</h3>";
  2146. echo "<p>";
  2147. echo "<strong>".TXT_WPSC_TOTAL_THIS_MONTH."</strong><br />";
  2148. $year = date("Y");
  2149. $month = date("m");
  2150. $start_timestamp = mktime(0, 0, 0, $month, 1, $year);
  2151. $end_timestamp = mktime(0, 0, 0, ($month+1), 0, $year);
  2152. echo nzshpcrt_currency_display(admin_display_total_price($start_timestamp, $end_timestamp),1);
  2153. echo "</p>";
  2154. echo "<p>";
  2155. echo "<strong>".TXT_WPSC_TOTAL_INCOME."</strong><br />";
  2156. echo nzshpcrt_currency_display(admin_display_total_price(),1);
  2157. echo "</p>";
  2158. echo "</div>";
  2159. }
  2160. }
  2161. add_action('activity_box_end', 'wpsc_admin_latest_activity');
  2162. //this adds all the admin pages, before the code was a mess, now it is slightly less so.
  2163. add_action('admin_menu', 'nzshpcrt_displaypages');
  2164. // pe.{
  2165. if(get_option('wpsc_share_this') == 1) {
  2166. if(stristr(("http://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']), get_option('product_list_url'))){
  2167. include_once(WPSC_FILE_PATH."/share-this.php");
  2168. }
  2169. }
  2170. add_filter('option_update_plugins', 'wpsc_plugin_no_upgrade');
  2171. function wpsc_plugin_no_upgrade($option) {
  2172. $this_plugin = plugin_basename(__FILE__);
  2173. //echo "<pre>".print_r($option->response[ $this_plugin ],true)."</pre>";
  2174. if( isset($option->response[ $this_plugin ]) ) {
  2175. $option->response[ $this_plugin ]->package = '';
  2176. }
  2177. return $option;
  2178. }
  2179. // if(get_option('cat_brand_loc') != 0) {
  2180. // add_action('wp_list_pages', 'show_cats_brands');
  2181. // }
  2182. // }.pe
  2183. add_action('plugins_loaded', 'widget_wp_shopping_cart_init');
  2184. // refresh page urls when permalinks are turned on or altered
  2185. add_filter('mod_rewrite_rules', 'wpsc_refresh_page_urls');
  2186. // refresh the page URL's when permalinks are turned off
  2187. // the plugin hook used just above doesnt run when they are turned off
  2188. // if(stristr($_POST['_wp_http_referer'], 'options-permalink.php')) {
  2189. // add_filter('admin_head', 'wpsc_refresh_page_urls');
  2190. // }
  2191. if(strpos($_SERVER['SCRIPT_NAME'], "wp-admin") === false) {
  2192. wp_enqueue_script( 'jQuery', WPSC_URL.'/js/jquery.js', false, '1.2.3');
  2193. // wp_enqueue_script('instinct_thickbox',WPSC_URL.'/js/thickbox.js', 'jQuery', 'Instinct_e-commerce');
  2194. wp_enqueue_script('ngg-thickbox',WPSC_URL.'/js/thickbox.js', 'jQuery', 'Instinct_e-commerce');
  2195. } else {
  2196. wp_enqueue_script('thickbox');
  2197. wp_enqueue_script('ui-tabs',WPSC_URL.'/js/jquery.tabs.pack.js?ver=2.7.4', array('jquery'), '2.7.4');
  2198. }
  2199. if(strpos($_SERVER['REQUEST_URI'], WPSC_DIR_NAME.'') !== false) {
  2200. wp_enqueue_script('interface',WPSC_URL.'/js/interface.js', 'Interface');
  2201. }
  2202. switch(get_option('cart_location')) {
  2203. case 1:
  2204. add_action('wp_list_pages','nzshpcrt_shopping_basket');
  2205. break;
  2206. case 2:
  2207. add_action('the_content', 'nzshpcrt_shopping_basket' , 14);
  2208. break;
  2209. case 4:
  2210. break;
  2211. case 5:
  2212. //exit("<pre>".print_r($_SERVER,true)."</pre>");
  2213. if(function_exists('drag_and_drop_cart')) {
  2214. $shop_pages_only = 1;
  2215. add_action('init', 'drag_and_drop_cart_ajax');
  2216. if (get_option('dropshop_display')=='product'){
  2217. $url_prefix_array = explode("://", get_option('product_list_url'));
  2218. $url_prefix = $url_prefix_array[0]."://";
  2219. if(stristr(($url_prefix.$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']), get_option('product_list_url'))){
  2220. wp_enqueue_script('interface',WPSC_URL.'/js/interface.js', 'Interface');
  2221. add_action('wp_head', 'drag_and_drop_js');
  2222. add_action('wp_footer', 'drag_and_drop_cart');
  2223. }
  2224. } else {
  2225. wp_enqueue_script('interface',WPSC_URL.'/js/interface.js', 'Interface');
  2226. add_action('wp_head', 'drag_and_drop_js');
  2227. add_action('wp_footer', 'drag_and_drop_cart');
  2228. }
  2229. }
  2230. break;
  2231. case 3:
  2232. //add_action('the_content', 'nzshpcrt_shopping_basket');
  2233. //<?php nzshpcrt_shopping_basket(); ?/>
  2234. break;
  2235. default:
  2236. add_action('the_content', 'nzshpcrt_shopping_basket', 14);
  2237. break;
  2238. }
  2239. /*
  2240. * This serializes the shopping cart variable as a backup in case the unserialized one gets butchered by various things
  2241. */
  2242. function serialize_shopping_cart() {
  2243. global $wpsc_start_time, $wpsc_debug_sections;
  2244. @$_SESSION['nzshpcrt_serialized_cart'] = serialize($_SESSION['nzshpcrt_cart']);
  2245. if(WPSC_DEBUG === true) {
  2246. $wpsc_end_time = microtime_float() - $wpsc_start_time;
  2247. $memory_usage = (@memory_get_usage() / 1000);
  2248. $debug_message = "/*\n\r<div style='position: absolute; top: 4px; left: 4px; background: #ffffff; padding: 3px; outline: 1px solid black; text-align: left;'>\n\r";
  2249. $debug_message .= "<div>Total Seconds: $wpsc_end_time</div>\n\r";
  2250. $debug_message .= "<div>Total Memory: $memory_usage kb</div>\n\r";
  2251. //$sections
  2252. foreach((array)$wpsc_debug_sections as $debug_section_name => $debug_section_values) {
  2253. $execution_time = ($debug_section_values['stop'] - $debug_section_values['start']);
  2254. $debug_message .= "<div>{$debug_section_name} Seconds: {$execution_time}</div>\n\r";
  2255. }
  2256. $debug_message .= "</div>\n\r*/";
  2257. //mail(get_option('purch_log_email'), "debug_report", $debug_email);
  2258. exit($debug_message);
  2259. }
  2260. return true;
  2261. }
  2262. register_shutdown_function("serialize_shopping_cart");
  2263. ?>