PageRenderTime 24ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/tags/3.7.5 Beta 2/wp-shopping-cart.php

https://github.com/evadne/wp-e-commerce
PHP | 358 lines | 248 code | 58 blank | 52 comment | 50 complexity | 73c3a0873a4a1a9ad84da6c5e3c4e97d 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.
  6. Version: 3.7.5 Beta 2
  7. Author: Instinct Entertainment
  8. Author URI: http://www.instinct.co.nz/e-commerce/
  9. */
  10. /**
  11. * WP eCommerce Main Plugin File
  12. * @package wp-e-commerce
  13. */
  14. // this is to make sure it sets up the table name constants correctly on activation
  15. global $wpdb;
  16. define('WPSC_VERSION', '3.7');
  17. define('WPSC_MINOR_VERSION', '35');
  18. define('WPSC_PRESENTABLE_VERSION', '3.7.5 Beta 2');
  19. define('WPSC_DEBUG', false);
  20. define('WPSC_GATEWAY_DEBUG', false);
  21. $v1 = str_replace(array('_','-','+'), '.', strtolower($wp_version));
  22. $v1 = str_replace(array('alpha','beta','gamma'), array('a','b','g'), $v1);
  23. $v1 = preg_split("/([a-z]+)/i",$v1,-1, PREG_SPLIT_DELIM_CAPTURE);
  24. array_walk($v1, create_function('&$v', '$v = trim($v,". ");'));
  25. define('IS_WP25', version_compare($v1[0], '2.5', '>='));
  26. define('IS_WP27', version_compare($v1[0], '2.7', '>='));
  27. // // we need to know where we are, rather than assuming where we are
  28. //Define the path to the plugin folder
  29. define('WPSC_FILE_PATH', dirname(__FILE__));
  30. define('WPSC_DIR_NAME', basename(WPSC_FILE_PATH));
  31. $siteurl = get_option('siteurl');
  32. //Define the URL to the plugin folder
  33. define('WPSC_FOLDER', dirname(plugin_basename(__FILE__)));
  34. define('WPSC_URL', get_option('siteurl').'/wp-content/plugins/' . WPSC_FOLDER);
  35. if(isset($wpdb->blogid)) {
  36. define('IS_WPMU', 1);
  37. } else {
  38. define('IS_WPMU', 0);
  39. }
  40. // include the selected language file
  41. if(get_option('language_setting') != '') {
  42. require(WPSC_FILE_PATH.'/languages/'.get_option('language_setting'));
  43. } else {
  44. require(WPSC_FILE_PATH.'/languages/EN_en.php');
  45. }
  46. if(!empty($wpdb->prefix)) {
  47. $wp_table_prefix = $wpdb->prefix;
  48. } else if(!empty($table_prefix)) {
  49. $wp_table_prefix = $table_prefix;
  50. }
  51. // Define the database table names
  52. define('WPSC_TABLE_CATEGORY_TM', "{$wp_table_prefix}wpsc_category_tm");
  53. define('WPSC_TABLE_ALSO_BOUGHT', "{$wp_table_prefix}wpsc_also_bought");
  54. define('WPSC_TABLE_CART_CONTENTS', "{$wp_table_prefix}wpsc_cart_contents");
  55. define('WPSC_TABLE_CART_ITEM_EXTRAS', "{$wp_table_prefix}wpsc_cart_item_extras");
  56. define('WPSC_TABLE_CART_ITEM_VARIATIONS', "{$wp_table_prefix}wpsc_cart_item_variations");
  57. define('WPSC_TABLE_CHECKOUT_FORMS', "{$wp_table_prefix}wpsc_checkout_forms");
  58. define('WPSC_TABLE_CURRENCY_LIST', "{$wp_table_prefix}wpsc_currency_list");
  59. define('WPSC_TABLE_DOWNLOAD_STATUS', "{$wp_table_prefix}wpsc_download_status");
  60. define('WPSC_TABLE_ITEM_CATEGORY_ASSOC', "{$wp_table_prefix}wpsc_item_category_assoc");
  61. define('WPSC_TABLE_PRODUCT_CATEGORIES', "{$wp_table_prefix}wpsc_product_categories");
  62. define('WPSC_TABLE_PRODUCT_FILES', "{$wp_table_prefix}wpsc_product_files");
  63. define('WPSC_TABLE_PRODUCT_IMAGES', "{$wp_table_prefix}wpsc_product_images");
  64. define('WPSC_TABLE_PRODUCT_LIST', "{$wp_table_prefix}wpsc_product_list");
  65. define('WPSC_TABLE_PRODUCT_ORDER', "{$wp_table_prefix}wpsc_product_order");
  66. define('WPSC_TABLE_PRODUCT_RATING', "{$wp_table_prefix}wpsc_product_rating");
  67. define('WPSC_TABLE_PRODUCT_VARIATIONS', "{$wp_table_prefix}wpsc_product_variations");
  68. define('WPSC_TABLE_PURCHASE_LOGS', "{$wp_table_prefix}wpsc_purchase_logs");
  69. define('WPSC_TABLE_PURCHASE_STATUSES', "{$wp_table_prefix}wpsc_purchase_statuses");
  70. define('WPSC_TABLE_REGION_TAX', "{$wp_table_prefix}wpsc_region_tax");
  71. define('WPSC_TABLE_SUBMITED_FORM_DATA', "{$wp_table_prefix}wpsc_submited_form_data");
  72. define('WPSC_TABLE_VARIATION_ASSOC', "{$wp_table_prefix}wpsc_variation_assoc");
  73. define('WPSC_TABLE_VARIATION_PROPERTIES', "{$wp_table_prefix}wpsc_variation_properties");
  74. define('WPSC_TABLE_VARIATION_VALUES', "{$wp_table_prefix}wpsc_variation_values");
  75. define('WPSC_TABLE_VARIATION_VALUES_ASSOC', "{$wp_table_prefix}wpsc_variation_values_assoc");
  76. define('WPSC_TABLE_COUPON_CODES', "{$wp_table_prefix}wpsc_coupon_codes");
  77. define('WPSC_TABLE_LOGGED_SUBSCRIPTIONS', "{$wp_table_prefix}wpsc_logged_subscriptions");
  78. define('WPSC_TABLE_PRODUCTMETA', "{$wp_table_prefix}wpsc_productmeta");
  79. define('WPSC_TABLE_CATEGORISATION_GROUPS', "{$wp_table_prefix}wpsc_categorisation_groups");
  80. define('WPSC_TABLE_VARIATION_COMBINATIONS', "{$wp_table_prefix}wpsc_variation_combinations");
  81. define('WPSC_TABLE_CLAIMED_STOCK', "{$wp_table_prefix}wpsc_claimed_stock");
  82. // start including the rest of the plugin here
  83. require_once(WPSC_FILE_PATH.'/wpsc-includes/wpsc_query.php');
  84. require_once(WPSC_FILE_PATH.'/wpsc-includes/variations.class.php');
  85. require_once(WPSC_FILE_PATH.'/wpsc-includes/ajax.functions.php');
  86. require_once(WPSC_FILE_PATH.'/wpsc-includes/misc.functions.php');
  87. require_once(WPSC_FILE_PATH.'/wpsc-includes/mimetype.php');
  88. require_once(WPSC_FILE_PATH.'/wpsc-includes/cart.class.php');
  89. require_once(WPSC_FILE_PATH.'/wpsc-includes/checkout.class.php');
  90. require_once(WPSC_FILE_PATH.'/wpsc-includes/display.functions.php');
  91. require_once(WPSC_FILE_PATH.'/wpsc-includes/theme.functions.php');
  92. require_once(WPSC_FILE_PATH.'/wpsc-includes/shortcode.functions.php');
  93. require_once(WPSC_FILE_PATH.'/wpsc-includes/coupons.class.php');
  94. require_once(WPSC_FILE_PATH.'/wpsc-includes/purchaselogs.class.php');
  95. include_once(WPSC_FILE_PATH."/wpsc-includes/category.functions.php");
  96. include_once(WPSC_FILE_PATH."/wpsc-includes/processing.functions.php");
  97. require_once(WPSC_FILE_PATH."/wpsc-includes/form-display.functions.php");
  98. //exit(print_r($v1,true));
  99. if($v1[0] >= 2.8){
  100. require_once(WPSC_FILE_PATH."/wpsc-includes/upgrades.php");
  101. }
  102. if (!IS_WP25) {
  103. require_once(WPSC_FILE_PATH.'/editor.php');
  104. } else {
  105. require_once(WPSC_FILE_PATH.'/js/tinymce3/tinymce.php');
  106. }
  107. /// OLD CODE INCLUDED HERE
  108. include_once('wp-shopping-cart.old.php');
  109. require_once(WPSC_FILE_PATH."/currency_converter.inc.php");
  110. require_once(WPSC_FILE_PATH."/shopping_cart_functions.php");
  111. require_once(WPSC_FILE_PATH."/homepage_products_functions.php");
  112. require_once(WPSC_FILE_PATH."/transaction_result_functions.php");
  113. // include_once(WPSC_FILE_PATH.'/submit_checkout_function.php');
  114. require_once(WPSC_FILE_PATH."/admin-form-functions.php");
  115. require_once(WPSC_FILE_PATH."/shipwire_functions.php");
  116. /* widget_section */
  117. include_once(WPSC_FILE_PATH.'/widgets/product_tag_widget.php');
  118. include_once(WPSC_FILE_PATH.'/widgets/shopping_cart_widget.php');
  119. include_once(WPSC_FILE_PATH.'/widgets/donations_widget.php');
  120. include_once(WPSC_FILE_PATH.'/widgets/specials_widget.php');
  121. include_once(WPSC_FILE_PATH.'/widgets/latest_product_widget.php');
  122. include_once(WPSC_FILE_PATH.'/widgets/price_range_widget.php');
  123. include_once(WPSC_FILE_PATH.'/widgets/admin_menu_widget.php');
  124. //include_once(WPSC_FILE_PATH.'/widgets/api_key_widget.php');
  125. if (class_exists('WP_Widget')) {
  126. include_once(WPSC_FILE_PATH.'/widgets/category_widget.28.php');
  127. } else {
  128. include_once(WPSC_FILE_PATH.'/widgets/category_widget.27.php');
  129. }
  130. include_once(WPSC_FILE_PATH.'/image_processing.php');
  131. // if we are in the admin section, include the admin code
  132. if(WP_ADMIN == true) {
  133. require_once(WPSC_FILE_PATH."/wpsc-admin/admin.php");
  134. }
  135. /**
  136. * Code to define where the uploaded files are stored starts here
  137. */
  138. if(IS_WPMU == 1) {
  139. $upload_url = get_option('siteurl').'/files';
  140. $upload_path = ABSPATH.get_option('upload_path');
  141. } else {
  142. if ( !defined('WP_CONTENT_URL') ) {
  143. define( 'WP_CONTENT_URL', get_option('siteurl') . '/wp-content');
  144. }
  145. if ( !defined('WP_CONTENT_DIR') ) {
  146. define( 'WP_CONTENT_DIR', ABSPATH . 'wp-content');
  147. }
  148. $upload_path = WP_CONTENT_DIR."/uploads";
  149. $upload_url = WP_CONTENT_URL."/uploads";
  150. }
  151. $wpsc_upload_dir = "{$upload_path}/wpsc/";
  152. $wpsc_file_dir = "{$wpsc_upload_dir}downloadables/";
  153. $wpsc_preview_dir = "{$wpsc_upload_dir}previews/";
  154. $wpsc_image_dir = "{$wpsc_upload_dir}product_images/";
  155. $wpsc_thumbnail_dir = "{$wpsc_upload_dir}product_images/thumbnails/";
  156. $wpsc_category_dir = "{$wpsc_upload_dir}category_images/";
  157. $wpsc_user_uploads_dir = "{$wpsc_upload_dir}user_uploads/";
  158. $wpsc_cache_dir = "{$wpsc_upload_dir}cache/";
  159. $wpsc_upgrades_dir = "{$wpsc_upload_dir}upgrades/";
  160. $wpsc_themes_dir = "{$wpsc_upload_dir}themes/";
  161. define('WPSC_UPLOAD_DIR', $wpsc_upload_dir);
  162. define('WPSC_FILE_DIR', $wpsc_file_dir);
  163. define('WPSC_PREVIEW_DIR', $wpsc_preview_dir);
  164. define('WPSC_IMAGE_DIR', $wpsc_image_dir);
  165. define('WPSC_THUMBNAIL_DIR', $wpsc_thumbnail_dir);
  166. define('WPSC_CATEGORY_DIR', $wpsc_category_dir);
  167. define('WPSC_USER_UPLOADS_DIR', $wpsc_user_uploads_dir);
  168. define('WPSC_CACHE_DIR', $wpsc_cache_dir);
  169. define('WPSC_UPGRADES_DIR', $wpsc_upgrades_dir);
  170. define('WPSC_THEMES_PATH', $wpsc_themes_dir);
  171. /**
  172. * files that are uploaded as part of digital products are not directly downloaded, therefore there is no need for a URL constant for them
  173. */
  174. $wpsc_upload_url = "{$upload_url}/wpsc/";
  175. $wpsc_preview_url = "{$wpsc_upload_url}previews/";
  176. $wpsc_image_url = "{$wpsc_upload_url}product_images/";
  177. $wpsc_thumbnail_url = "{$wpsc_upload_url}product_images/thumbnails/";
  178. $wpsc_category_url = "{$wpsc_upload_url}category_images/";
  179. $wpsc_user_uploads_url = "{$wpsc_upload_url}user_uploads/";
  180. $wpsc_cache_url = "{$wpsc_upload_url}cache/";
  181. $wpsc_upgrades_url = "{$wpsc_upload_url}upgrades/";
  182. $wpsc_themes_url = "{$wpsc_upload_url}themes/";
  183. define('WPSC_UPLOAD_URL', $wpsc_upload_url);
  184. define('WPSC_PREVIEW_URL', $wpsc_preview_url);
  185. define('WPSC_IMAGE_URL', $wpsc_image_url);
  186. define('WPSC_THUMBNAIL_URL', $wpsc_thumbnail_url);
  187. define('WPSC_CATEGORY_URL', $wpsc_category_url);
  188. define('WPSC_USER_UPLOADS_URL', $wpsc_user_uploads_url);
  189. define('WPSC_CACHE_URL', $wpsc_cache_url);
  190. define('WPSC_UPGRADES_URL', $wpsc_upgrades_url);
  191. define('WPSC_THEMES_URL', $wpsc_themes_url);
  192. // if the gold cart file is present, include it, this must be done before the admin file is included
  193. if(is_file(WPSC_UPGRADES_DIR . "gold_cart_files/gold_shopping_cart.php")) {
  194. require_once(WPSC_UPGRADES_DIR . "gold_cart_files/gold_shopping_cart.php");
  195. }
  196. //if there are any upgrades present, include them., thanks to nielo.info and lsdev.biz
  197. if($v1[0] >= 2.8){
  198. $upgrades = get_upgrades();
  199. foreach ($upgrades as $path=>$upgrade) {
  200. $upgrade_file = WPSC_UPGRADES_DIR . '/' . $path;
  201. require_once($upgrade_file);
  202. }
  203. }
  204. include_once("install_and_update.php");
  205. register_activation_hook(__FILE__, 'wpsc_install');
  206. /**
  207. * Code to define where the uploaded files are stored ends here
  208. */
  209. if(!function_exists('wpsc_start_the_query')) {
  210. function wpsc_start_the_query() {
  211. global $wp_query, $wpsc_query;
  212. $wpsc_query = new WPSC_query();
  213. $post_id = $wp_query->post->ID;
  214. $page_url = get_permalink($post_id);
  215. if(get_option('shopping_cart_url') == $page_url) {
  216. $_SESSION['wpsc_has_been_to_checkout'] = true;
  217. //echo $_SESSION['wpsc_has_been_to_checkout'];
  218. }
  219. }
  220. }
  221. // after init and after when the wp query string is parsed but before anything is displayed
  222. add_action('template_redirect', 'wpsc_start_the_query', 0);
  223. /**
  224. * Check to see if the session exists, if not, start it
  225. */
  226. if((!is_array($_SESSION)) xor (!isset($_SESSION['nzshpcrt_cart'])) xor (!$_SESSION)) {
  227. session_start();
  228. }
  229. if(!function_exists('wpsc_initialisation')){
  230. function wpsc_initialisation() {
  231. global $wpsc_cart, $wpsc_theme_path, $wpsc_theme_url, $wpsc_category_url_cache;
  232. // set the theme directory constant
  233. $uploads_dir = @opendir(WPSC_THEMES_PATH);
  234. $file_names = array();
  235. while(($file = @readdir($uploads_dir)) !== false) {
  236. //echo "<br />test".WPSC_THEMES_PATH.$file;
  237. if(is_dir(WPSC_THEMES_PATH.$file) && ($file != "..") && ($file != ".") && ($file != ".svn")){
  238. $file_names[] = $file;
  239. }
  240. }
  241. if(count($file_names) > 0) {
  242. $wpsc_theme_path = WPSC_THEMES_PATH;
  243. $wpsc_theme_url = WPSC_THEMES_URL;
  244. } else {
  245. $wpsc_theme_path = WPSC_FILE_PATH . "/themes/";
  246. $wpsc_theme_url = WPSC_URL. '/themes/';
  247. }
  248. //$theme_path = WPSC_FILE_PATH . "/themes/";
  249. //exit(print_r($file_names,true));
  250. if((get_option('wpsc_selected_theme') == null) || (!file_exists($wpsc_theme_path.get_option('wpsc_selected_theme')))) {
  251. $theme_dir = 'default';
  252. } else {
  253. $theme_dir = get_option('wpsc_selected_theme');
  254. }
  255. define('WPSC_THEME_DIR', $theme_dir);
  256. // initialise the cart session, if it exist, unserialize it, otherwise make it
  257. if(isset($_SESSION['wpsc_cart'])) {
  258. if(is_object($_SESSION['wpsc_cart'])) {
  259. $GLOBALS['wpsc_cart'] = $_SESSION['wpsc_cart'];
  260. } else {
  261. $GLOBALS['wpsc_cart'] = unserialize($_SESSION['wpsc_cart']);
  262. }
  263. if(get_class($GLOBALS['wpsc_cart']) != "wpsc_cart") {
  264. $GLOBALS['wpsc_cart'] = new wpsc_cart;
  265. }
  266. } else {
  267. $GLOBALS['wpsc_cart'] = new wpsc_cart;
  268. }
  269. }
  270. $GLOBALS['wpsc_category_url_cache'] = get_option('wpsc_category_url_cache');
  271. register_taxonomy('product_tag', 'product');
  272. }
  273. // first plugin hook in wordpress
  274. add_action('plugins_loaded','wpsc_initialisation', 0);
  275. /**
  276. * This serializes the shopping cart variable as a backup in case the unserialized one gets butchered by various things
  277. */
  278. if(!function_exists('wpsc_serialize_shopping_cart')){
  279. function wpsc_serialize_shopping_cart() {
  280. global $wpdb, $wpsc_start_time, $wpsc_cart, $wpsc_category_url_cache;
  281. if(is_object($wpsc_cart)) {
  282. $wpsc_cart->errors = array();
  283. }
  284. $_SESSION['wpsc_cart'] = serialize($wpsc_cart);
  285. $previous_category_url_cache = get_option('wpsc_category_url_cache');
  286. if($wpsc_category_url_cache != $previous_category_url_cache) {
  287. update_option('wpsc_category_url_cache', $wpsc_category_url_cache);
  288. }
  289. /// Delete the old claims on stock
  290. $session_timeout = 60*60; // 180 * 60 = three hours in seconds
  291. $old_claimed_stock_timestamp = time() - $session_timeout;
  292. $old_claimed_stock_timestamp = mktime((date('H') - 3), date('i'), date('s'), date('m'), date('d'), date('Y'));
  293. $old_claimed_stock_datetime = date("Y-m-d H:i:s", $old_claimed_stock_timestamp);
  294. //echo "$old_claimed_stock_timestamp <br /> DELETE FROM `".WPSC_TABLE_CLAIMED_STOCK."` WHERE `last_activity` < '{$old_claimed_stock_datetime}' AND `cart_submitted` IN ('0')";
  295. $wpdb->query("DELETE FROM `".WPSC_TABLE_CLAIMED_STOCK."` WHERE `last_activity` < '{$old_claimed_stock_datetime}' AND `cart_submitted` IN ('0')");
  296. return true;
  297. }
  298. }
  299. add_action('shutdown','wpsc_serialize_shopping_cart');
  300. ?>