PageRenderTime 75ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 1ms

/wpeasycart.php

https://github.com/EmranAhmed/wp-easycart
PHP | 1891 lines | 1404 code | 322 blank | 165 comment | 368 complexity | d65cb55320a8f1d8494ee688f16157f8 MD5 | raw file
  1. <?php
  2. /**
  3. * Plugin Name: WP EasyCart
  4. * Plugin URI: http://www.wpeasycart.com
  5. * Description: The WordPress Shopping Cart by WP EasyCart is a simple install into new or existing WordPress blogs. Customers purchase directly from your store! Get a full eCommerce platform in WordPress! Sell products, downloadable goods, gift cards, clothing and more! Now with WordPress, the powerful features are still very easy to administrate! If you have any questions, please view our website at <a href="http://www.wpeasycart.com" target="_blank">WP EasyCart</a>. <br /><br /><strong>*** UPGRADING? Please be sure to backup your plugin, or follow our upgrade instructions at <a href="http://www.wpeasycart.com/docs/2.0.0/index/upgrading.php" target="_blank">WP EasyCart Upgrading</a> ***</strong>
  6. * Version: 2.1.21
  7. * Author: Level Four Development, llc
  8. * Author URI: http://www.wpeasycart.com
  9. *
  10. * This program is free to download and install, but requires the purchase of our shopping cart plugin to use live payment gateways, coupons, promotions, and more.
  11. * Each site requires a license for live use and must be purchased through the WP EasyCart website.
  12. *
  13. * @package wpeasycart
  14. * @version 2.1.21
  15. * @author WP EasyCart <sales@wpeasycart.com>
  16. * @copyright Copyright (c) 2012, WP EasyCart
  17. * @link http://www.wpeasycart.com
  18. */
  19. define( 'EC_PUGIN_NAME', 'WP EasyCart');
  20. define( 'EC_PLUGIN_DIRECTORY', 'wp-easycart');
  21. define( 'EC_CURRENT_VERSION', '2_1_21' );
  22. define( 'EC_CURRENT_DB', '1_19' );
  23. if( !defined( "EC_QB_PLUGIN_DIRECTORY" ) )
  24. define( 'EC_QB_PLUGIN_DIRECTORY', 'wp-easycart-quickbooks' );
  25. require_once( WP_PLUGIN_DIR . "/" . EC_PLUGIN_DIRECTORY . '/inc/ec_config.php' );
  26. // Setup Hook Structure
  27. ec_setup_hooks( );
  28. // Check and add hooks
  29. if( file_exists( WP_PLUGIN_DIR . "/wp-easycart-data/ec_hooks.php" ) )
  30. include( WP_PLUGIN_DIR . "/wp-easycart-data/ec_hooks.php" );
  31. function ec_activate(){
  32. // ADD WORDPRESS OPTIONS
  33. $wpoptions = new ec_wpoptionset();
  34. $wpoptions->add_options();
  35. //INITIALIZE DATABASE
  36. $mysqli = new ec_db();
  37. // FIRST ATTEMPT TO INSTALL THE INITIAL VERSION.
  38. $install_sql_url = WP_PLUGIN_DIR . "/" . EC_PLUGIN_DIRECTORY . '/inc/admin/sql/install_' . EC_CURRENT_DB . '.sql';
  39. $f = fopen( $install_sql_url, "r" ) or die( "Could not open the install sql script. Likely the permissions on the file when copied from WordPress are preventing our activation script from accessing the install script. To fix this issue, look in your default wordpress plugins folder, then change the permissions on the following file to 775: wp-easycart/inc/admin/sql/install_x_x.sql (look for the highest version). Please submit a support ticket at www.wpeasycart.com with FTP access if you wish to have the WP EasyCart staff help you get up and running." );
  40. $install_sql = fread( $f, filesize( $install_sql_url ) );
  41. $install_sql_array = explode(';', $install_sql);
  42. $mysqli->install( $install_sql_array );
  43. // END SQL INSTALLER
  44. // START SQL UPGRADER
  45. if( get_option( 'ec_option_db_version' ) && EC_CURRENT_DB != get_option( 'ec_option_db_version' ) ){
  46. $update_sql_url = WP_PLUGIN_DIR . "/" . EC_PLUGIN_DIRECTORY . '/inc/admin/sql/upgrade_' . get_option( 'ec_option_db_version') . '_to_' . EC_CURRENT_DB . '.sql';
  47. $f = fopen( $update_sql_url, "r") or die("The Wp EasyCart plugin was unable to access the database upgrade script. Upgrade halted. To fix this problem, change the permissions on the following files to 775 and try again: wp-easycart/inc/admin/sql/upgrade_x_x_to_x_x (change all upgrade files unless you know what plugin DB version you have and which you are upgrading to). Contact WP EasyCart support by submitting a support ticket at www.wpeasycart.com with FTP access for assistance.");
  48. $upgrade_sql = fread( $f, filesize( $update_sql_url ) );
  49. $upgrade_sql_array = explode(';', $upgrade_sql);
  50. $db = new ec_db();
  51. $db->upgrade( $upgrade_sql_array );
  52. update_option( 'ec_option_db_version', EC_CURRENT_DB );
  53. }
  54. // END SQL UPGRADER
  55. // UPDATE SITE URL
  56. $site = explode( "://", ec_get_url( ) );
  57. $site = $site[1];
  58. $mysqli->update_url( $site );
  59. // END UPDATE SITE URL
  60. //SETUP BASIC LANGUAGE SETTINGS
  61. $language = new ec_language( );
  62. //WE BLOCK THIS FROM THE ec_config.php TO PREVENT OUTPUT ON ACTIVATION, INCLUDE HERE...
  63. update_option( 'ec_option_is_installed', '1' );
  64. $GLOBALS['setting'] = new ec_setting( );
  65. //WRITE OUR EC_CONN FILE FOR AMFPHP
  66. global $wpdb;
  67. $ec_conn_php = "<?php
  68. define ('HOSTNAME','" . DB_HOST . "');
  69. define ('DATABASE','" . DB_NAME . "');
  70. define ('USERNAME','" . DB_USER . "');
  71. define ('PASSWORD','" . DB_PASSWORD . "');
  72. define ('WP_PREFIX','" . $wpdb->base_prefix . "');
  73. ?>";
  74. $ec_conn_filename = WP_PLUGIN_DIR . "/" . EC_PLUGIN_DIRECTORY . "/connection/ec_conn.php";
  75. if( is_writable( WP_PLUGIN_DIR . "/" . EC_PLUGIN_DIRECTORY . "/connection/" ) ){
  76. $ec_conn_filehandler = fopen($ec_conn_filename, 'w');
  77. fwrite($ec_conn_filehandler, $ec_conn_php);
  78. fclose($ec_conn_filehandler);
  79. }
  80. //END WRITE FOR EC_CONN FILE FOR AMFPHP
  81. // FIX FOR CURRENCY ISSUES
  82. if( get_option( 'ec_option_currency' ) == '&#36;' ){
  83. update_option( 'ec_option_currency', '$' );
  84. }
  85. // END FIX FOR CURRENCY ISSUES
  86. // IF NO wp-easycart-data FOLDER
  87. // SHOULD ONLY RUN ON FIRST INSTALL
  88. if( !is_dir( WP_PLUGIN_DIR . "/wp-easycart-data/" ) ){
  89. $to = WP_PLUGIN_DIR . "/wp-easycart-data/";
  90. $from = WP_PLUGIN_DIR . "/" . EC_PLUGIN_DIRECTORY . "/";
  91. // CHECK IF WRITABLE
  92. if( !is_writable( WP_PLUGIN_DIR ) ){
  93. // We really can't do anything now about the data folder. Lets try and get people to do this in the install page.
  94. }else{
  95. // For a first time install, use the old linking style
  96. update_option( 'ec_option_use_old_linking_style', '1' );
  97. mkdir( $to, 0755 );
  98. // COPY FROM wp-easycart to wp-easycart-data
  99. wpeasycart_copyr( $from . "products", $to . "products" );
  100. wpeasycart_copyr( $from . "design", $to . "design" );
  101. wpeasycart_copyr( $from . "connection", $to . "connection" );
  102. }
  103. }
  104. // Create Uploads folder if it doesn't exist
  105. if( !is_dir( WP_PLUGIN_DIR . "/wp-easycart/products/uploads/" ) ){
  106. mkdir( WP_PLUGIN_DIR . "/wp-easycart/products/uploads/" );
  107. }
  108. if( !is_dir( WP_PLUGIN_DIR . "/wp-easycart-data/products/uploads/" ) ){
  109. mkdir( WP_PLUGIN_DIR . "/wp-easycart-data/products/uploads/" );
  110. }
  111. // Fix for new installs, make sure the smart states is set to true. This is because old installs would be messed up without this.
  112. $fixrow = $wpdb->get_row( "SELECT ec_state.id_sta FROM ec_state WHERE ec_state.name_sta = 'FIXFORFRESHINSTALLS'" );
  113. if( $fixrow ){
  114. update_option( 'ec_option_use_smart_states', '1' );
  115. update_option( 'ec_option_display_country_top', '1' );
  116. update_option( 'ec_option_use_address2', '1' );
  117. $wpdb->query( "DELETE FROM ec_state WHERE ec_state.name_sta = 'FIXFORFRESHINSTALLS'" );
  118. }
  119. }
  120. function ec_uninstall(){
  121. $mysqli = new ec_db();
  122. $uninstall_sql_url = WP_PLUGIN_DIR . "/" . EC_PLUGIN_DIRECTORY . '/inc/admin/sql/uninstall_' . get_option( 'ec_option_db_version' ) . '.sql';
  123. if( file_exists( $uninstall_sql_url ) ){
  124. $f = fopen( $uninstall_sql_url, "r" );
  125. $uninstall_sql = fread( $f, filesize( $uninstall_sql_url ) );
  126. $uninstall_sql_array = explode(';', $uninstall_sql);
  127. $mysqli->uninstall( $uninstall_sql_array );
  128. }
  129. //delete options
  130. $wpoptions = new ec_wpoptionset();
  131. $wpoptions->delete_options();
  132. $data_dir = WP_PLUGIN_DIR . "/wp-easycart-data/";
  133. if( !is_writable( $data_dir ) ){
  134. // Could not open the file, lets write it via ftp!
  135. $ftp_server = $_POST['hostname'];
  136. $ftp_user_name = $_POST['username'];
  137. $ftp_user_pass = $_POST['password'];
  138. // set up basic connection
  139. $conn_id = ftp_connect( $ftp_server ) or die("Couldn't connect to $ftp_server");
  140. // login with username and password
  141. $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
  142. if( !$login_result ){
  143. die( "Could not connect to your server via FTP to uninstall your wp-easycart. Please remove the files manually." );
  144. }else{
  145. ec_delete_directory_ftp( $conn_id, $data_dir );
  146. }
  147. }else{
  148. ec_recursive_remove_directory( $data_dir );
  149. }
  150. // Clean up linking structure
  151. $store_posts = get_posts( array( 'post_type' => 'ec_store', 'posts_per_page' => 10000 ) );
  152. foreach( $store_posts as $store_post ) {
  153. wp_delete_post( $store_post->ID, true);
  154. }
  155. }
  156. register_activation_hook( __FILE__, 'ec_activate' );
  157. register_uninstall_hook( __FILE__, 'ec_uninstall' );
  158. function load_ec_pre(){
  159. // UPGRADE THE DB IF NEEDED
  160. if( get_option( 'ec_option_db_version' ) && EC_CURRENT_DB != get_option( 'ec_option_db_version' ) ){
  161. $update_sql_url = WP_PLUGIN_DIR . "/" . EC_PLUGIN_DIRECTORY . '/inc/admin/sql/upgrade_' . get_option( 'ec_option_db_version') . '_to_' . EC_CURRENT_DB . '.sql';
  162. $f = fopen( $update_sql_url, "r") or die("The Wp EasyCart plugin was unable to access the database upgrade script. Upgrade halted. To fix this problem, change the permissions on the following files to 775 and try again: wp-easycart/inc/admin/sql/upgrade_x_x_to_x_x (change all upgrade files unless you know what plugin DB version you have and which you are upgrading to). Contact WP EasyCart support by submitting a support ticket at www.wpeasycart.com with FTP access for assistance.");
  163. $upgrade_sql = fread( $f, filesize( $update_sql_url ) );
  164. $upgrade_sql_array = explode(';', $upgrade_sql);
  165. $db = new ec_db();
  166. $db->upgrade( $upgrade_sql_array );
  167. update_option( 'ec_option_db_version', EC_CURRENT_DB );
  168. }
  169. // END UPGRADE THE DB IF NEEDED
  170. // CREATE DATA FOLDER IF IT DOESN'T EXIST
  171. if( !is_dir( WP_PLUGIN_DIR . "/wp-easycart-data/" ) ){
  172. $to = WP_PLUGIN_DIR . "/wp-easycart-data/";
  173. $from = WP_PLUGIN_DIR . "/" . EC_PLUGIN_DIRECTORY . "/";
  174. if( !is_writable( WP_PLUGIN_DIR ) ){
  175. // We really can't do anything now about the data folder. Lets try and get people to do this in the install page.
  176. }else{
  177. mkdir( $to, 0755 );
  178. // Now backup
  179. wpeasycart_copyr( $from . "products", $to . "products" );
  180. wpeasycart_copyr( $from . "design", $to . "design" );
  181. wpeasycart_copyr( $from . "connection", $to . "connection" );
  182. }
  183. }
  184. // END CREATE DATA FOLDER IF IT DOESN'T EXIST
  185. // CHECK FOR PRODUCTS FOLDER STRUCTURE IN MAIN FOLDER, ADD IF NEEDED
  186. $products_folder = WP_PLUGIN_DIR . "/" . EC_PLUGIN_DIRECTORY . "/products/";
  187. $banners = WP_PLUGIN_DIR . "/" . EC_PLUGIN_DIRECTORY . "/products/banners/";
  188. $downloads = WP_PLUGIN_DIR . "/" . EC_PLUGIN_DIRECTORY . "/products/downloads/";
  189. $pics1 = WP_PLUGIN_DIR . "/" . EC_PLUGIN_DIRECTORY . "/products/pics1/";
  190. $pics2 = WP_PLUGIN_DIR . "/" . EC_PLUGIN_DIRECTORY . "/products/pics2/";
  191. $pics3 = WP_PLUGIN_DIR . "/" . EC_PLUGIN_DIRECTORY . "/products/pics3/";
  192. $pics4 = WP_PLUGIN_DIR . "/" . EC_PLUGIN_DIRECTORY . "/products/pics4/";
  193. $pics5 = WP_PLUGIN_DIR . "/" . EC_PLUGIN_DIRECTORY . "/products/pics5/";
  194. $swatches = WP_PLUGIN_DIR . "/" . EC_PLUGIN_DIRECTORY . "/products/swatches/";
  195. $uploads = WP_PLUGIN_DIR . "/" . EC_PLUGIN_DIRECTORY . "/products/uploads/";
  196. if( !is_dir( $products_folder ) )
  197. mkdir( $products_folder, 0755 );
  198. if( !is_dir( $banners ) )
  199. mkdir( $banners, 0755 );
  200. if( !is_dir( $downloads ) )
  201. mkdir( $downloads, 0751 );
  202. if( !is_dir( $pics1 ) )
  203. mkdir( $pics1, 0755 );
  204. if( !is_dir( $pics2 ) )
  205. mkdir( $pics2, 0755 );
  206. if( !is_dir( $pics3 ) )
  207. mkdir( $pics3, 0755 );
  208. if( !is_dir( $pics4 ) )
  209. mkdir( $pics4, 0755 );
  210. if( !is_dir( $pics5 ) )
  211. mkdir( $pics5, 0755 );
  212. if( !is_dir( $swatches ) )
  213. mkdir( $swatches, 0755 );
  214. if( !is_dir( $uploads ) )
  215. mkdir( $uploads, 0751 );
  216. // END CHECK FOR PRODUCTS FOLDER
  217. // CHECK FOR PRODUCTS FOLDER STRUCTURE IN DATA FOLDER, ADD IF NEEDED
  218. $products_folder = WP_PLUGIN_DIR . "/wp-easycart-data/products/";
  219. $banners = WP_PLUGIN_DIR . "/wp-easycart-data/products/banners/";
  220. $downloads = WP_PLUGIN_DIR . "/wp-easycart-data/products/downloads/";
  221. $pics1 = WP_PLUGIN_DIR . "/wp-easycart-data/products/pics1/";
  222. $pics2 = WP_PLUGIN_DIR . "/wp-easycart-data/products/pics2/";
  223. $pics3 = WP_PLUGIN_DIR . "/wp-easycart-data/products/pics3/";
  224. $pics4 = WP_PLUGIN_DIR . "/wp-easycart-data/products/pics4/";
  225. $pics5 = WP_PLUGIN_DIR . "/wp-easycart-data/products/pics5/";
  226. $swatches = WP_PLUGIN_DIR . "/wp-easycart-data/products/swatches/";
  227. $uploads = WP_PLUGIN_DIR . "/wp-easycart-data/products/uploads/";
  228. if( !is_dir( $products_folder ) )
  229. mkdir( $products_folder, 0755 );
  230. if( !is_dir( $banners ) )
  231. mkdir( $banners, 0755 );
  232. if( !is_dir( $downloads ) )
  233. mkdir( $downloads, 0751 );
  234. if( !is_dir( $pics1 ) )
  235. mkdir( $pics1, 0755 );
  236. if( !is_dir( $pics2 ) )
  237. mkdir( $pics2, 0755 );
  238. if( !is_dir( $pics3 ) )
  239. mkdir( $pics3, 0755 );
  240. if( !is_dir( $pics4 ) )
  241. mkdir( $pics4, 0755 );
  242. if( !is_dir( $pics5 ) )
  243. mkdir( $pics5, 0755 );
  244. if( !is_dir( $swatches ) )
  245. mkdir( $swatches, 0755 );
  246. if( !is_dir( $uploads ) )
  247. mkdir( $uploads, 0751 );
  248. // END CHECK FOR PRODUCTS FOLDER
  249. ///////////////////////////////////////////////////////////////////////////////////
  250. // This is a check to ensure old users are upgraded to the new linking format
  251. ///////////////////////////////////////////////////////////////////////////////////
  252. if( !get_option( 'ec_option_new_linking_setup' ) ){
  253. $db = new ec_db();
  254. $menulevel1_items = $db->get_menulevel1_items( );
  255. $menulevel2_items = $db->get_menulevel2_items( );
  256. $menulevel3_items = $db->get_menulevel3_items( );
  257. $product_list = $db->get_product_list( "", "", "", "" );
  258. $category_list = $db->get_category_list( );
  259. $manufacturer_list = $db->get_manufacturer_list( );
  260. foreach( $menulevel1_items as $menu_item ){
  261. if( $menu_item->menulevel1_post_id == 0 ){
  262. // Add a post id
  263. $post = array( 'post_content' => "[ec_store menuid=\"" . $menu_item->menulevel1_id . "\"]",
  264. 'post_status' => "publish",
  265. 'post_title' => $menu_item->menu1_name,
  266. 'post_type' => "ec_store"
  267. );
  268. $post_id = wp_insert_post( $post );
  269. $db->update_menu_post_id( $menu_item->menulevel1_id, $post_id );
  270. }
  271. }
  272. foreach( $menulevel2_items as $menu_item ){
  273. if( $menu_item->menulevel2_post_id == 0 ){
  274. // Add a post id
  275. $post = array( 'post_content' => "[ec_store submenuid=\"" . $menu_item->menulevel2_id . "\"]",
  276. 'post_status' => "publish",
  277. 'post_title' => $menu_item->menu2_name,
  278. 'post_type' => "ec_store"
  279. );
  280. $post_id = wp_insert_post( $post );
  281. $db->update_submenu_post_id( $menu_item->menulevel2_id, $post_id );
  282. }
  283. }
  284. foreach( $menulevel3_items as $menu_item ){
  285. if( $menu_item->menulevel3_post_id == 0 ){
  286. // Add a post id
  287. $post = array( 'post_content' => "[ec_store subsubmenuid=\"" . $menu_item->menulevel3_id . "\"]",
  288. 'post_status' => "publish",
  289. 'post_title' => $menu_item->menu3_name,
  290. 'post_type' => "ec_store"
  291. );
  292. $post_id = wp_insert_post( $post );
  293. $db->update_subsubmenu_post_id( $menu_item->menulevel3_id, $post_id );
  294. }
  295. }
  296. foreach( $product_list as $product_single ){
  297. if( $product_single->post_id == 0 ){
  298. // Add a post id
  299. $post = array( 'post_content' => "[ec_store modelnumber=\"" . $product_single['model_number'] . "\"]",
  300. 'post_status' => "publish",
  301. 'post_title' => $product_single['title'],
  302. 'post_type' => "ec_store"
  303. );
  304. $post_id = wp_insert_post( $post );
  305. $db->update_product_post_id( $product_single['product_id'], $post_id );
  306. }
  307. }
  308. foreach( $manufacturer_list as $manufacturer_single ){
  309. if( $manufacturer_single->post_id == 0 ){
  310. // Add a post id
  311. $post = array( 'post_content' => "[ec_store manufacturerid=\"" . $manufacturer_single->manufacturer_id . "\"]",
  312. 'post_status' => "publish",
  313. 'post_title' => $manufacturer_single->name,
  314. 'post_type' => "ec_store"
  315. );
  316. $post_id = wp_insert_post( $post );
  317. $db->update_manufacturer_post_id( $manufacturer_single->manufacturer_id, $post_id );
  318. }
  319. }
  320. foreach( $category_list as $category_single ){
  321. if( $category_single->post_id == 0 ){
  322. // Add a post id
  323. $post = array( 'post_content' => "[ec_store groupid=\"" . $category_single->category_id . "\"]",
  324. 'post_status' => "publish",
  325. 'post_title' => $category_single->category_name,
  326. 'post_type' => "ec_store"
  327. );
  328. $post_id = wp_insert_post( $post );
  329. $db->update_product_post_id( $category_single->category_id, $post_id );
  330. }
  331. }
  332. update_option( 'ec_option_new_linking_setup', 1 );
  333. }
  334. ///////////////////////////////////////////////////////////////////////////////////
  335. // END - linkage check
  336. ///////////////////////////////////////////////////////////////////////////////////
  337. // START STATS AND FORM PROCESSING
  338. $storepageid = get_option('ec_option_storepage');
  339. $cartpageid = get_option('ec_option_cartpage');
  340. $accountpageid = get_option('ec_option_accountpage');
  341. $storepage = get_permalink( $storepageid );
  342. $cartpage = get_permalink( $cartpageid );
  343. $accountpage = get_permalink( $accountpageid );
  344. if( class_exists( "WordPressHTTPS" ) && isset( $_SERVER['HTTPS'] ) ){
  345. $https_class = new WordPressHTTPS( );
  346. $storepage = $https_class->makeUrlHttps( $storepage );
  347. $cartpage = $https_class->makeUrlHttps( $cartpage );
  348. $accountpage = $https_class->makeUrlHttps( $accountpage );
  349. }
  350. if(substr_count($storepage, '?')) $permalinkdivider = "&";
  351. else $permalinkdivider = "?";
  352. if( isset( $_SERVER['HTTPS'] ) ) $currentpageid = url_to_postid( "https://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'] );
  353. else $currentpageid = url_to_postid( "http://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'] );
  354. if( isset( $_GET['ec_page'] ) && $_GET['ec_page'] == "checkout_success" && isset( $_GET['error_description'] ) && get_option( 'ec_option_payment_third_party' ) == "dwolla_thirdparty" ){
  355. $db = new ec_db( );
  356. $db->insert_response( $_GET['order_id'], 1, "Dwolla Third Party", print_r( $_GET, true ) );
  357. header( "location: " . $accountpage . $permalinkdivider . "ec_page=order_details&order_id=" . $_GET['order_id'] . "&ec_error=dwolla_error" );
  358. }else if( isset( $_GET['ec_page'] ) && $_GET['ec_page'] == "checkout_success" && get_option( 'ec_option_payment_third_party' ) == "dwolla_thirdparty" && isset( $_GET['signature'] ) && isset( $_GET['checkoutId'] ) && isset( $_GET['amount'] ) ){
  359. $dwolla_verification = ec_dwolla_verify_signature( $_GET['signature'], $_GET['checkoutId'], $_GET['amount'] );
  360. if( $dwolla_verification ){
  361. $db = new ec_db( );
  362. $db->update_order_status( $_GET['order_id'], "10" );
  363. // send email
  364. $order_row = $db->get_order_row( $_GET['order_id'], "guest", "guest" );
  365. $order_display = new ec_orderdisplay( $order_row, true );
  366. $order_display->send_email_receipt( );
  367. // Quickbooks Hook
  368. if( file_exists( WP_PLUGIN_DIR . "/" . EC_QB_PLUGIN_DIRECTORY . "/ec_quickbooks.php" ) ){
  369. $quickbooks = new ec_quickbooks( );
  370. $quickbooks->add_order( $order_id );
  371. }
  372. header( "location: " . $cartpage . $permalinkdivider . "ec_page=checkout_success&order_id=" . $_GET['order_id'] );
  373. }else{
  374. $db = new ec_db( );
  375. $db->insert_response( $_GET['order_id'], 1, "Dwolla Third Party", print_r( $_GET, true ) );
  376. header( "location: " . $accountpage . $permalinkdivider . "ec_page=order_details&order_id=" . $_GET['order_id'] . "&ec_error=dwolla_error" );
  377. }
  378. }
  379. /* Update the Menu and Product Statistics */
  380. if( isset( $_GET['model_number'] ) ){
  381. $db = new ec_db( );
  382. $db->update_product_views( $_GET['model_number'] );
  383. }else if( isset( $_GET['menuid'] ) ){
  384. $db = new ec_db( );
  385. $db->update_menu_views( $_GET['menuid'] );
  386. }else if( isset( $_GET['submenuid'] ) ){
  387. $db = new ec_db( );
  388. $db->update_submenu_views( $_GET['submenuid'] );
  389. }else if( isset( $_GET['subsubmenuid'] ) ){
  390. $db = new ec_db( );
  391. $db->update_subsubmenu_views( $_GET['subsubmenuid'] );
  392. }
  393. /* Cart Form Actions, Process Prior to WP Loading */
  394. if( isset( $_POST['ec_cart_form_action'] ) ){
  395. $ec_cartpage = new ec_cartpage();
  396. $ec_cartpage->process_form_action( $_POST['ec_cart_form_action'] );
  397. }else if( isset( $_GET['ec_cart_action'] ) ){
  398. $ec_cartpage = new ec_cartpage();
  399. $ec_cartpage->process_form_action( $_GET['ec_cart_action'] );
  400. }else if( isset( $_GET['ec_page'] ) && $_GET['ec_page'] == "3dsecure" ){
  401. $ec_cartpage = new ec_cartpage();
  402. $ec_cartpage->process_form_action( "3dsecure" );
  403. }else if( isset( $_GET['ec_page'] ) && $_GET['ec_page'] == "third_party" ){
  404. $ec_cartpage = new ec_cartpage();
  405. $ec_cartpage->process_form_action( "third_party_forward" );
  406. }else if( isset( $_GET['ec_page'] ) && $_GET['ec_page'] == "realex_redirect" ){
  407. $ec_cartpage = new ec_cartpage();
  408. $ec_cartpage->process_form_action( "realex_redirect" );
  409. }else if( isset( $_GET['ec_page'] ) && $_GET['ec_page'] == "realex_response" ){
  410. $ec_cartpage = new ec_cartpage();
  411. $ec_cartpage->process_form_action( "realex_response" );
  412. }else if( isset( $_GET['ec_page'] ) && $_GET['ec_page'] == "checkout_success" && isset( $_GET['ec_action'] ) && $_GET['ec_action'] == "paymentexpress" ){
  413. $ec_cartpage = new ec_cartpage();
  414. $ec_cartpage->process_form_action( "paymentexpress_thirdparty_response" );
  415. }else if( isset( $_GET['ec_page'] ) && $_GET['ec_page'] == "nets_return" && isset( $_GET['transactionId'] ) ){
  416. global $wpdb;
  417. $order_id = $wpdb->get_var( $wpdb->prepare( "SELECT ec_order.order_id FROM ec_order WHERE ec_order.nets_transaction_id = %s", $_GET['transactionId'] ) );
  418. $nets = new ec_nets( );
  419. $nets->process_payment_final( $order_id, $_GET['transactionId'], $_GET['responseCode'] );
  420. }
  421. /* Account Form Actions, Process Prior to WP Loading */
  422. if( isset( $_POST['ec_account_form_action'] ) ){
  423. $ec_accountpage = new ec_accountpage();
  424. $ec_accountpage->process_form_action( $_POST['ec_account_form_action'] );
  425. }else if( isset( $_GET['ec_page'] ) && $_GET['ec_page'] == "logout" ){
  426. $ec_accountpage = new ec_accountpage();
  427. $ec_accountpage->process_form_action( "logout" );
  428. }else if( isset( $_GET['ec_page'] ) && $_GET['ec_page'] == "print_receipt" ){
  429. include( WP_PLUGIN_DIR . "/" . EC_PLUGIN_DIRECTORY . "/inc/scripts/print_receipt.php" );
  430. die( );
  431. }else if( isset( $_GET['ec_page'] ) && $_GET['ec_page'] == "activate_account" && isset( $_GET['email'] ) && isset( $_GET['key'] ) ){
  432. $db = new ec_db( );
  433. $is_activated = $db->activate_user( $_GET['email'], $_GET['key'] );
  434. if( $is_activated ){
  435. header( "location: " . $account_page . $permalinkdivider . "ec_page=login&account_success=activation_success" );
  436. }else{
  437. header( "location: " . $account_page . $permalinkdivider . "ec_page=login&account_error=activation_error" );
  438. }
  439. }
  440. /* Newsletter Form Actions */
  441. if( isset( $_POST['ec_newsletter_email'] ) ){
  442. $ec_db = new ec_db();
  443. $ec_db->insert_subscriber( $_POST['ec_newsletter_email'], "", "" );
  444. }
  445. // END STATS AND FORM PROCESSING
  446. // FIX FOR PRODUCT LIST DROP DOWN
  447. if( !get_option( 'ec_option_product_filter_1' ) && !get_option( 'ec_option_product_filter_2' ) && !get_option( 'ec_option_product_filter_3' ) && !get_option( 'ec_option_product_filter_4' ) && !get_option( 'ec_option_product_filter_5') && !get_option( 'ec_option_product_filter_6') && !get_option( 'ec_option_product_filter_7' ) ){
  448. update_option( 'ec_option_product_filter_1', '1' );
  449. update_option( 'ec_option_product_filter_2', '1' );
  450. update_option( 'ec_option_product_filter_3', '1' );
  451. update_option( 'ec_option_product_filter_4', '1' );
  452. update_option( 'ec_option_product_filter_5', '1' );
  453. update_option( 'ec_option_product_filter_6', '1' );
  454. update_option( 'ec_option_product_filter_7', '1' );
  455. }
  456. // END FIX FOR PRODUCT LIST DROP DOWN
  457. }
  458. function ec_custom_headers( ){
  459. if( isset( $_GET['order_id'] ) && isset( $_GET['orderdetail_id'] ) && isset( $_GET['download_id'] ) && isset( $_SESSION['ec_email'] ) && isset( $_SESSION['ec_password'] ) ){
  460. $mysqli = new ec_db( );
  461. $orderdetail_row = $mysqli->get_orderdetail_row( $_GET['order_id'], $_GET['orderdetail_id'], $_SESSION['ec_email'], $_SESSION['ec_password'] );
  462. $ec_orderdetail = new ec_orderdetail( $orderdetail_row, 1 );
  463. }
  464. if( isset( $_GET['ec_page'] ) && ( $_GET['ec_page'] == "checkout_payment" || $_GET['ec_page'] == "checkout_shipping" || $_GET['ec_page'] == "checkout_info" ) ){
  465. header('Cache-Control: no-cache, no-store, must-revalidate'); // HTTP 1.1.
  466. header('Pragma: no-cache'); // HTTP 1.0.
  467. header('Expires: 0'); // Proxies.
  468. }
  469. }
  470. function ec_cache_management( ){
  471. if( get_option( 'ec_option_caching_on' ) ){
  472. // File does not exist at all
  473. if( !file_exists( ABSPATH . "wp-content/plugins/wp-easycart-data/design/theme/" . get_option( 'ec_option_base_theme' ) . "/ec-store-css.css" ) ){
  474. ec_regenerate_css( );
  475. ec_regenerate_js( );
  476. update_option( 'ec_option_cached_date', time( ) );
  477. }
  478. // Use cache management system
  479. else if( get_option( 'ec_option_cache_update_period' ) ){
  480. $update_time = true;
  481. $new_time = time( );
  482. // Use a automatic cache builder and the last update has not been set
  483. if( get_option( 'ec_option_cache_update_period' ) && !get_option( 'ec_option_cached_date' ) ){
  484. ec_regenerate_css( );
  485. ec_regenerate_js( );
  486. }
  487. // Cache update daily
  488. else if( get_option( 'ec_option_cache_update_period' ) == '1' && get_option( 'ec_option_cached_date' ) < strtotime("-1 day") ){
  489. ec_regenerate_css( );
  490. ec_regenerate_js( );
  491. }
  492. // Cache update weekly
  493. else if( get_option( 'ec_option_cache_update_period' ) == '1' && get_option( 'ec_option_cached_date' ) < strtotime("-1 week") ){
  494. ec_regenerate_css( );
  495. ec_regenerate_js( );
  496. }
  497. // Cache update monthly
  498. else if( get_option( 'ec_option_cache_update_period' ) == '1' && get_option( 'ec_option_cached_date' ) < strtotime("-1 month") ){
  499. ec_regenerate_css( );
  500. ec_regenerate_js( );
  501. }
  502. // Cache update yearly
  503. else if( get_option( 'ec_option_cache_update_period' ) == '1' && get_option( 'ec_option_cached_date' ) < strtotime("-1 year") ){
  504. ec_regenerate_css( );
  505. ec_regenerate_js( );
  506. }
  507. // Do not update
  508. else{
  509. $update_time = false;
  510. }
  511. if( $update_time ){
  512. update_option( 'ec_option_cached_date', $new_time );
  513. }
  514. }
  515. }else{
  516. ec_regenerate_css( );
  517. ec_regenerate_js( );
  518. update_option( 'ec_option_cached_date', time( ) );
  519. }
  520. }
  521. function ec_regenerate_css( ){
  522. ob_start( "ec_save_css_file" );
  523. include( ABSPATH . "wp-content/plugins/" . EC_PLUGIN_DIRECTORY . '/inc/scripts/ec_css_generator.php' );
  524. ob_end_flush();
  525. }
  526. function ec_save_css_file( $buffer ){
  527. file_put_contents( ABSPATH . "wp-content/plugins/wp-easycart-data/design/theme/" . get_option( 'ec_option_base_theme' ) . "/ec-store-css.css", $buffer );
  528. }
  529. function ec_regenerate_js( ){
  530. if( file_exists( ABSPATH . "wp-content/plugins/wp-easycart-data/design/theme/" . get_option( 'ec_option_base_theme' ) . "/ec_account_billing_information/" ) ){ //check to see if any of the old folders exist
  531. ob_start( "ec_save_js_file" );
  532. include( ABSPATH . "wp-content/plugins/" . EC_PLUGIN_DIRECTORY . '/inc/scripts/ec_js_generator.php' );
  533. ob_end_flush();
  534. }
  535. }
  536. function ec_save_js_file( $buffer ){
  537. file_put_contents( ABSPATH . "wp-content/plugins/wp-easycart-data/design/theme/" . get_option( 'ec_option_base_theme' ) . "/ec-store-js.js", $buffer );
  538. }
  539. function ec_load_css( ){
  540. ec_cache_management( );
  541. if( file_exists( ABSPATH . "wp-content/plugins/wp-easycart-data/design/theme/" . get_option( 'ec_option_base_theme' ) . "/ec-store-css.css" ) && filesize( ABSPATH . "wp-content/plugins/wp-easycart-data/design/theme/" . get_option( 'ec_option_base_theme' ) . "/ec-store-css.css" ) ){
  542. // Load the cached file because it exists
  543. wp_register_style( 'wpeasycart_css', plugins_url( 'wp-easycart-data/design/theme/' . get_option( 'ec_option_base_theme' ) . '/ec-store-css.css' ) );
  544. wp_enqueue_style( 'wpeasycart_css' );
  545. }else{
  546. // File did not exist, revert back to the development mode loader
  547. wp_register_style( 'wpeasycart_css', plugins_url( EC_PLUGIN_DIRECTORY . '/inc/scripts/ec_css_loader.php' ) );
  548. wp_enqueue_style( 'wpeasycart_css' );
  549. }
  550. $gfont_list = "";
  551. $font_list = explode( ":::", get_option( 'ec_option_font_replacements' ) );
  552. $fonts_added = 0;
  553. for( $i=0; $i<count( $font_list ); $i++ ){
  554. $temp = explode( "=", $font_list[$i] );
  555. if( $temp[1] != "Verdana, Geneva, sans-serif" &&
  556. $temp[1] != "Georgia, Times New Roman, Times, serif" &&
  557. $temp[1] != "Courier New, Courier, monospace" &&
  558. $temp[1] != "Arial, Helvetica, sans-serif" &&
  559. $temp[1] != "Tahoma, Geneva, sans-serif" &&
  560. $temp[1] != "Trebuchet MS, Arial, Helvetica, sans-serif" &&
  561. $temp[1] != "Arial Black, Gadget, sans-serif" &&
  562. $temp[1] != "Times New Roman, Times, serif" &&
  563. $temp[1] != "Palatino Linotype, Book Antiqua, Palatino, serif" &&
  564. $temp[1] != "Lucida Sans Unicode, Lucida Grande, sans-serif" &&
  565. $temp[1] != "MS Serif, New York, serif" &&
  566. $temp[1] != "Lucida Console, Monaco, monospace" &&
  567. $temp[1] != "Comic Sans MS, cursive" &&
  568. $temp[1] != ""
  569. ){
  570. if( $fonts_added > 0 )
  571. $gfont_list .= "|";
  572. $gfont_list .= $temp[1];
  573. $fonts_added++;
  574. }
  575. }
  576. if( $fonts_added > 0 ){
  577. $pageURL = 'http';
  578. if( isset( $_SERVER["HTTPS"] ) )
  579. $pageURL .= "s";
  580. wp_register_style( "wpeasycart_gfont", $pageURL . "://fonts.googleapis.com/css?family=" . $gfont_list );
  581. wp_enqueue_style( 'wpeasycart_gfont' );
  582. }
  583. }
  584. function ec_load_js( ){
  585. if( file_exists( ABSPATH . "wp-content/plugins/wp-easycart-data/design/theme/" . get_option( 'ec_option_base_theme' ) . "/ec-store-js.js" ) && filesize( ABSPATH . "wp-content/plugins/wp-easycart-data/design/theme/" . get_option( 'ec_option_base_theme' ) . "/ec-store-js.js" ) ){
  586. // Load the cached file because it exists
  587. wp_register_script( 'wpeasycart_js', plugins_url( 'wp-easycart-data/design/theme/' . get_option( 'ec_option_base_theme' ) . '/ec-store-js.js' ), array( 'jquery' ) );
  588. wp_enqueue_script( 'wpeasycart_js' );
  589. }else{
  590. // File did not exist, revert back to the development mode loader
  591. wp_register_script( 'wpeasycart_js', plugins_url( EC_PLUGIN_DIRECTORY . '/inc/scripts/ec_js_loader.php' ), array( 'jquery' ) );
  592. wp_enqueue_script( 'wpeasycart_js' );
  593. }
  594. $ajax_subfolder = "";
  595. if( file_exists( plugins_url( 'wp-easycart-data/ajax-subfolder.txt' ) ) ){
  596. $ajax_subfolder = file_get_contents( plugins_url( 'wp-easycart-data/ajax-subfolder.txt' ) );
  597. }
  598. $https_link = "";
  599. if( class_exists( "WordPressHTTPS" ) ){
  600. $https_class = new WordPressHTTPS( );
  601. if( $ajax_subfolder != "" ){
  602. $https_link = $https_class->getHttpsUrl() . $ajax_subfolder . '/wp-admin/admin-ajax.php';
  603. }else{
  604. $https_link = $https_class->makeUrlHttps( admin_url( 'admin-ajax.php' ) );
  605. }
  606. }else{
  607. $https_link = str_replace( "http://", "https://", str_replace( "/wp-admin", $ajax_subfolder . "/wp-admin", admin_url( 'admin-ajax.php' ) ) );
  608. }
  609. if( isset( $_SERVER['HTTPS'] ) && $_SERVER["HTTPS"] == "on" )
  610. wp_localize_script( 'wpeasycart_js', 'ajax_object', array( 'ajax_url' => $https_link ) );
  611. else
  612. wp_localize_script( 'wpeasycart_js', 'ajax_object', array( 'ajax_url' => admin_url( 'admin-ajax.php' ) ) );
  613. }
  614. function ec_facebook_metadata() {
  615. global $wp_query;
  616. $post_obj = $wp_query->get_queried_object();
  617. if( isset( $post_obj ) && isset( $post_obj->ID ) ){
  618. $post_id = $post_obj->ID;
  619. }else{
  620. $post_id = 0;
  621. }
  622. $db = new ec_db( );
  623. $product = $db->get_product_from_post_id( $post_id );
  624. if( isset( $product ) || isset( $_GET['model_number'] ) ){
  625. if( isset( $product ) ){
  626. $product_id = $product->product_id;
  627. $prod_title = $product->title;
  628. $prod_model_number = $product->model_number;
  629. $prod_description = $product->description;
  630. $prod_use_optionitem_images = $product->use_optionitem_images;
  631. $prod_image = $product->image1;
  632. }else{
  633. $query_productRS = sprintf("SELECT ec_product.* FROM ec_product WHERE ec_product.model_number = '%s'", mysql_real_escape_string($_GET['model_number']));
  634. $productRS = mysql_query($query_productRS);
  635. $product = mysql_fetch_assoc($productRS);
  636. $product_id = $product['product_id'];
  637. $prod_title = $product['title'];
  638. $prod_model_number = $product['model_number'];
  639. $prod_description = $product['description'];
  640. $prod_use_optionitem_images = $product['use_optionitem_images'];
  641. $prod_image = $product['image1'];
  642. }
  643. if( $prod_use_optionitem_images ){
  644. $optimg_sql = sprintf("SELECT ec_optionitemimage.image1 FROM ec_optionitemimage WHERE ec_optionitemimage.product_id = '%s' ", $product_id );
  645. $optimgs = mysql_query($optimg_sql);
  646. $optimg = mysql_fetch_assoc($optimgs);
  647. $prod_image = $optimg['image1'];
  648. }
  649. remove_action('wp_head', 'rel_canonical');
  650. //this method places to early, before html tags open
  651. echo "<meta property=\"og:title\" content=\"" . $prod_title . "\" />\n";
  652. echo "<meta property=\"og:type\" content=\"product\" />\n";
  653. echo "<meta property=\"og:description\" content=\"" . ec_short_string($prod_description, 300) . "\" />\n";
  654. $test_src1 = ABSPATH . "wp-content/plugins/wp-easycart-data/products/pics1/" . $prod_image;
  655. $test_src2 = ABSPATH . "wp-content/plugins/" . EC_PLUGIN_DIRECTORY . "/products/pics1/" . $prod_image;
  656. if( file_exists( $test_src1 ) )
  657. echo "<meta property=\"og:image\" content=\"" . plugin_dir_url(__DIR__) . "wp-easycart-data/products/pics1/" . $prod_image . "\" />\n";
  658. else if( file_exists( $test_src2 ) )
  659. echo "<meta property=\"og:image\" content=\"" . plugin_dir_url(__DIR__) . EC_PLUGIN_DIRECTORY . "/products/pics1/" . $prod_image . "\" />\n";
  660. else
  661. echo "<meta property=\"og:image\" content=\"" . plugin_dir_url(__DIR__) . EC_PLUGIN_DIRECTORY . "/design/theme/" . get_option( 'ec_option_base_theme' ) . "/ec_image_not_found.jpg" . "\" />\n";
  662. echo "<meta property=\"og:url\" content=\"" . ec_curPageURL() . "\" /> \n";
  663. }
  664. }
  665. function ec_curPageURL() {
  666. $pageURL = 'http';
  667. if( isset( $_SERVER["HTTPS"] ) )
  668. $pageURL .= "s";
  669. $pageURL .= "://";
  670. if( $_SERVER["SERVER_PORT"] != "80" )
  671. $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
  672. else
  673. $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
  674. return $pageURL;
  675. }
  676. function ec_short_string($text, $length){
  677. if( strlen( $text ) > $length )
  678. $text = substr($text, 0, strpos($text, ' ', $length));
  679. return $text;
  680. }
  681. //[ecstore]
  682. function load_ec_store( $atts ){
  683. define( "DONOTCACHEPAGE", true );
  684. define('DONOTCDN', true);
  685. extract( shortcode_atts( array(
  686. 'menuid' => 'NOMENU',
  687. 'submenuid' => 'NOSUBMENU',
  688. 'subsubmenuid' => 'NOSUBSUBMENU',
  689. 'manufacturerid' => 'NOMANUFACTURER',
  690. 'groupid' => 'NOGROUP',
  691. 'modelnumber' => 'NOMODELNUMBER'
  692. ), $atts ) );
  693. ob_start();
  694. $store_page = new ec_storepage( $menuid, $submenuid, $subsubmenuid, $manufacturerid, $groupid, $modelnumber );
  695. $store_page->display_store_page();
  696. return ob_get_clean();
  697. }
  698. //[eccart]
  699. function load_ec_cart( $atts ){
  700. define( "DONOTCACHEPAGE", true );
  701. define('DONOTCDN', true);
  702. ob_start( );
  703. $cart_page = new ec_cartpage( );
  704. $cart_page->display_cart_page( );
  705. return ob_get_clean( );
  706. }
  707. //[ecaccount]
  708. function load_ec_account( $atts ){
  709. define( "DONOTCACHEPAGE", true );
  710. define('DONOTCDN', true);
  711. ob_start( );
  712. $account_page = new ec_accountpage( );
  713. if( isset( $_POST['ec_form_action'] ) )
  714. $account_page->process_form_action( $_POST['ec_form_action'] );
  715. else
  716. $account_page->display_account_page( );
  717. return ob_get_clean();
  718. }
  719. //[ec_product]
  720. function load_ec_product( $atts ){
  721. extract( shortcode_atts( array(
  722. 'model_number' => 'NOPRODUCT',
  723. 'productid' => 'NOPRODUCTID',
  724. 'columns' => '3',
  725. 'margin' => '45px',
  726. 'width' => '175px',
  727. 'minheight' => '375px',
  728. 'imagew' => '140px',
  729. 'imageh' => '140px',
  730. 'style' => '1'
  731. ), $atts ) );
  732. $simp_product_id = $model_number;
  733. ob_start( );
  734. $mysqli = new ec_db( );
  735. if( $model_number != "NOPRODUCT" ){
  736. $products = $mysqli->get_product_list( " WHERE product.model_number = '" . $model_number . "'", "", "", "" );
  737. }else{
  738. $product_ids = explode( ',', $productid );
  739. $product_where = " WHERE ";
  740. $ids = 0;
  741. foreach( $product_ids as $product_id ){
  742. if( $ids > 0 ){
  743. $product_where .= " OR ";
  744. }
  745. $product_where .= "product.product_id = " . $product_id;
  746. $ids++;
  747. }
  748. $products = $mysqli->get_product_list( $product_where, "", "", "" );
  749. }
  750. if( count( $products ) > 0 ){
  751. echo "<div style=\"float:left; width:100%;\"><ul class=\"ec_productlist_ul\" style=\"list-style:none; margin: 0px; float:left; width:100%; min-height:" . $minheight . ";\">";
  752. for( $i=0; $i<count( $products ); $i++ ){
  753. $product = new ec_product( $products[$i], 0, 0, 1 );
  754. if( $i%$columns == $columns-1 ){
  755. echo "<li style=\"float:right;\">";
  756. }else{
  757. echo "<li style=\"float:left; margin-right:" . $margin . ";\">";
  758. }
  759. if( $style == '1' ){
  760. if( file_exists( WP_PLUGIN_DIR . '/wp-easycart-data/design/layout/' . get_option( 'ec_option_base_layout' ) . '/ec_product.php' ) )
  761. include( WP_PLUGIN_DIR . "/" . '/wp-easycart-data/design/layout/' . get_option( 'ec_option_base_layout' ) . '/ec_product.php' );
  762. else
  763. include( WP_PLUGIN_DIR . "/" . EC_PLUGIN_DIRECTORY . '/design/layout/' . get_option( 'ec_option_base_layout' ) . '/ec_product.php' );
  764. }else if( $style == '2' ){
  765. if( file_exists( WP_PLUGIN_DIR . '/wp-easycart-data/design/layout/' . get_option( 'ec_option_base_layout' ) . '/ec_product_widget.php' ) )
  766. include( WP_PLUGIN_DIR . "/" . '/wp-easycart-data/design/layout/' . get_option( 'ec_option_base_layout' ) . '/ec_product_widget.php' );
  767. else
  768. include( WP_PLUGIN_DIR . "/" . EC_PLUGIN_DIRECTORY . '/design/layout/' . get_option( 'ec_option_base_layout' ) . '/ec_product_widget.php' );
  769. }else{
  770. echo "<a href=\"" . $product->get_product_link( ) . "\">";
  771. echo "<img src=\"" . $product->get_product_single_image( ) . "\" alt=\"" . $product->title . "\" width=\"" . $imagew . "\" height=\"" . $imageh . "\">";
  772. echo "</a>";
  773. echo "<h3><a href=\"" . $product->get_product_link( ) . "\">" . $product->title . "</a></h3>";
  774. echo "<span class=\"ec_price_button\" style=\"width:" . $width . "\">";
  775. if( $product->has_sale_price( ) ){
  776. echo "<span class=\"ec_price_before\"><del>" . $product->get_formatted_before_price( ) . "</del></span>";
  777. echo "<span class=\"ec_price_sale\">" . $product->get_formatted_price( ) . "</span>";
  778. }else{
  779. echo "<span class=\"ec_price\">" . $product->get_formatted_price( ) . "</span>";
  780. }
  781. echo "</span>";
  782. }
  783. echo "</li>";
  784. }
  785. echo "</ul><div style=\"clear:both;\"></div></div>";
  786. }
  787. return ob_get_clean( );
  788. }
  789. //[ec_addtocart]
  790. function load_ec_addtocart( $atts ){
  791. extract( shortcode_atts( array(
  792. 'productid' => 'NOPRODUCTID'
  793. ), $atts ) );
  794. ob_start( );
  795. $mysqli = new ec_db( );
  796. $products = $mysqli->get_product_list( " WHERE product.product_id = " . $productid, "", "", "" );
  797. if( count( $products ) > 0 ){
  798. $product = new ec_product( $products[0], 0, 0, 1 );
  799. if( $product->stock_quantity > 0 ){
  800. echo "<div style=\"display:none;\">";
  801. $product->display_product_details_image_set( "large", "ec_image_", "ec_image_click" );
  802. $product->display_product_image_thumbnails("xsmall", "ec_thumb_", "ec_thumb_click" );
  803. echo "</div>";
  804. $product->display_product_details_form_start( );
  805. if( $product->use_advanced_optionset ){
  806. echo "<div class=\"ec_product_details_option_holder\">";
  807. $product->display_all_advanced_optionsets( );
  808. echo "</div>";
  809. }else{
  810. if( $product->product_has_swatches( $product->options->optionset1 ) ){
  811. echo "<div class=\"ec_product_details_option1_swatches\">";
  812. $product->display_product_option( $product->options->optionset1, "large", 1, "ec_swatch_", "ec_swatch_click" );
  813. echo "</div>";
  814. }else if( $product->product_has_combo( $product->options->optionset1 ) ){
  815. echo "<div class=\"ec_product_details_option1_combo\">";
  816. $product->display_product_option( $product->options->optionset1, "large", 1, "ec_combo_", "" );
  817. echo "</div>";
  818. }
  819. if( $product->product_has_swatches( $product->options->optionset2 ) ){
  820. echo "<div class=\"ec_product_details_option2_swatches\">";
  821. $product->display_product_option( $product->options->optionset2, "large", 2, "ec_swatch_", "ec_swatch_click" );
  822. echo "</div>";
  823. }else if( $product->product_has_combo( $product->options->optionset2 ) ){
  824. echo "<div class=\"ec_product_details_option2_combo\">";
  825. $product->display_product_option( $product->options->optionset2, "large", 2, "ec_combo_", "" );
  826. echo "</div>";
  827. }
  828. if( $product->product_has_swatches( $product->options->optionset3 ) ){
  829. echo "<div class=\"ec_product_details_option3_swatches\">";
  830. $product->display_product_option( $product->options->optionset3, "large", 3, "ec_swatch_", "ec_swatch_click" );
  831. echo "</div>";
  832. }else if( $product->product_has_combo( $product->options->optionset3 ) ){
  833. echo "<div class=\"ec_product_details_option3_combo\">";
  834. $product->display_product_option( $product->options->optionset3, "large", 3, "ec_combo_", "" );
  835. echo "</div>";
  836. }
  837. if( $product->product_has_swatches( $product->options->optionset4 ) ){
  838. echo "<div class=\"ec_product_details_option4_swatches\">";
  839. $product->display_product_option( $product->options->optionset4, "large", 4, "ec_swatch_", "ec_swatch_click" );
  840. echo "</div>";
  841. }else if( $product->product_has_combo( $product->options->optionset4 ) ){
  842. echo "<div class=\"ec_product_details_option4_combo\">";
  843. $product->display_product_option( $product->options->optionset4, "large", 4, "ec_combo_", "" );
  844. echo "</div>";
  845. }
  846. if( $product->product_has_swatches( $product->options->optionset5 ) ){
  847. echo "<div class=\"ec_product_details_option5_swatches\">";
  848. $product->display_product_option( $product->options->optionset5, "large", 5, "ec_swatch_", "ec_swatch_click" );
  849. echo "</div>";
  850. }else if( $product->product_has_combo( $product->options->optionset5 ) ){
  851. echo "<div class=\"ec_product_details_option5_combo\">";
  852. $product->display_product_option( $product->options->optionset5, "large", 5, "ec_combo_", "" );
  853. echo "</div>";
  854. }
  855. }
  856. if( $product->is_giftcard ){
  857. echo "<div class=\"ec_product_details_gift_card\">"; $product->display_gift_card_input(); echo "</div>";
  858. }
  859. if( !$product->has_grid_optionset ){
  860. echo "<div class=\"";
  861. if( $product->is_donation ){
  862. echo "ec_product_details_quantity_donation";
  863. }else{
  864. echo "ec_product_details_quantity";
  865. }
  866. echo "\" id=\"ec_product_details_quantity_" . $product->model_number . "\">" . $GLOBALS['language']->get_text( 'product_details', 'product_details_quantity' );
  867. $product->display_product_quantity_input("1");
  868. echo "</div>";
  869. }
  870. echo "<input type=\"hidden\" id=\"product_quantity_" . $product->model_number . "\" value=\"1\">";
  871. echo "<div class=\"ec_product_details_add_to_cart\">";
  872. $product->display_product_add_to_cart_button_no_validation( $GLOBALS['language']->get_text( 'product_details', 'product_details_add_to_cart' ), "ec_quick_view_error" );
  873. echo "</div>";
  874. $product->display_product_details_form_end( );
  875. }else{
  876. echo "<div class=\"ec_product_details_quantity\">" . $GLOBALS['language']->get_text( 'product_details', 'product_details_out_of_stock' ) . "</div>";
  877. }
  878. }
  879. return ob_get_clean( );
  880. }
  881. //[ec_cartdisplay]
  882. function load_ec_cartdisplay( $atts ){
  883. extract( shortcode_atts( array(
  884. 'style' => '1'
  885. ), $atts ) );
  886. ob_start( );
  887. $cartpage = new ec_cartpage( );
  888. if( $cartpage->cart->total_items > 0 ){
  889. echo "<div class=\"ec_cart_title_bar\">";
  890. echo "<div class=\"ec_cart_title_bar_column_1\">" . $GLOBALS['language']->get_text( 'cart', 'cart_header_column1' ) . "</div>";
  891. echo "<div class=\"ec_cart_title_bar_column_2\">" . $GLOBALS['language']->get_text( 'cart', 'cart_header_column2' ) . "</div>";
  892. echo "<div class=\"ec_cart_title_bar_column_3\">" . $GLOBALS['language']->get_text( 'cart', 'cart_header_column3' ) . "</div>";
  893. echo "<div class=\"ec_cart_title_bar_column_4\">" . $GLOBALS['language']->get_text( 'cart', 'cart_header_column4' ) . "</div>";
  894. echo "<div class=\"ec_cart_title_bar_column_5\">" . $GLOBALS['language']->get_text( 'cart', 'cart_header_column5' ) . "</div>";
  895. echo "</div>";
  896. echo "<div class=\"ec_cart_item_holder\">";
  897. $cartpage->display_cart_items();
  898. echo "</div>";
  899. echo "<input type=\"hidden\" name=\"ec_cart_session_id\" id=\"ec_cart_session_id\" value=\"" . session_id() . "\" />";
  900. }
  901. return ob_get_clean( );
  902. }
  903. //[ec_membership productid=''][/ec_membership]
  904. function load_ec_membership( $atts, $content = NULL ){
  905. extract( shortcode_atts( array(
  906. 'productid' => '',
  907. 'userroles' => ''
  908. ), $atts ) );
  909. if( is_user_logged_in( ) ){
  910. return "<h3>ADMIN ONLY - MEMBER CONTENT</h3><hr />" . do_shortcode( $content ) . "<hr />";
  911. }else{
  912. $db = new ec_db( );
  913. $is_member = false;
  914. if( $productid != '' ){
  915. $is_member = $db->has_membership_product_ids( $productid );
  916. }
  917. if( $userroles != '' ){
  918. $user_role_array = explode( ',', $userroles );
  919. $user = new ec_user( $_SESSION['ec_email'] );
  920. if( in_array( $user->user_level, $user_role_array ) )
  921. $is_member = true;
  922. }
  923. if( $is_member )
  924. return do_shortcode( $content );
  925. else
  926. return "";
  927. }
  928. }
  929. //[ec_membership_alt productid=''][/ec_membership_alt]
  930. function load_ec_membership_alt( $atts, $content = NULL ){
  931. extract( shortcode_atts( array(
  932. 'productid' => '',
  933. 'userroles' => ''
  934. ), $atts ) );
  935. if( is_user_logged_in( ) ){
  936. return "<h3>ADMIN ONLY - ALTERNATE CONTENT</h3><hr />" . do_shortcode( $content ) . "<hr />";
  937. }else{
  938. $db = new ec_db( );
  939. $is_member = false;
  940. if( $productid != '' ){
  941. $is_member = $db->has_membership_product_ids( $productid );
  942. }
  943. if( $userroles != '' ){
  944. $user_role_array = explode( ',', $userroles );
  945. $user = new ec_user( $_SESSION['ec_email'] );
  946. if( in_array( $user->user_level, $user_role_array ) )
  947. $is_member = true;
  948. }
  949. if( !$is_member )
  950. return do_shortcode( $content );
  951. else
  952. return "";
  953. }
  954. }
  955. function ec_wp_myplugin_property_title($data){
  956. global $post;
  957. if( isset($_GET['model_number']) && $post->ID == $storepageid ){
  958. $query_productRS = sprintf("SELECT products.Title FROM products WHERE model_number = '%s'", mysql_real_escape_string($_GET['model_number']));
  959. $productRS = mysql_query($query_productRS);
  960. $row_productRS = mysql_fetch_assoc($productRS);
  961. $seotitle = $row_productRS['Title'];
  962. return $seotitle . " ";
  963. }else{
  964. return $data;
  965. }
  966. }
  967. function wpeasycart_register_widgets( ) {
  968. register_widget( 'ec_categorywidget' );
  969. register_widget( 'ec_cartwidget' );
  970. register_widget( 'ec_currencywidget' );
  971. register_widget( 'ec_donationwidget' );
  972. register_widget( 'ec_groupwidget' );
  973. register_widget( 'ec_languagewidget' );
  974. register_widget( 'ec_manufacturerwidget' );
  975. register_widget( 'ec_menuwidget' );
  976. register_widget( 'ec_newsletterwidget' );
  977. register_widget( 'ec_pricepointwidget' );
  978. register_widget( 'ec_productwidget' );
  979. register_widget( 'ec_searchwidget' );
  980. register_widget( 'ec_specialswidget' );
  981. }
  982. add_action( 'wp', 'load_ec_pre' );
  983. add_action( 'wp_enqueue_scripts', 'ec_load_css' );
  984. add_action( 'wp_enqueue_scripts', 'ec_load_js' );
  985. add_action( 'widgets_init', 'wpeasycart_register_widgets' );
  986. add_action( 'send_headers', 'ec_custom_headers' );
  987. add_shortcode( 'ec_store', 'load_ec_store' );
  988. add_shortcode( 'ec_cart', 'load_ec_cart' );
  989. add_shortcode( 'ec_account', 'load_ec_account' );
  990. add_shortcode( 'ec_product', 'load_ec_product' );
  991. add_shortcode( 'ec_addtocart', 'load_ec_addtocart' );
  992. add_shortcode( 'ec_cartdisplay', 'load_ec_cartdisplay' );
  993. add_shortcode( 'ec_membership', 'load_ec_membership' );
  994. add_shortcode( 'ec_membership_alt', 'load_ec_membership_alt' );
  995. add_filter( 'widget_text', 'do_shortcode');
  996. add_action('wp_head', 'ec_facebook_metadata');
  997. add_action( 'wp_enqueue_scripts', 'ec_load_dashicons' );
  998. function ec_load_dashicons() {
  999. wp_enqueue_style( 'dashicons' );
  1000. }
  1001. //////////////////////////////////////////////
  1002. //UPDATE FUNCTIONS
  1003. //////////////////////////////////////////////
  1004. function wpeasycart_copyr( $source, $dest ){
  1005. // Check for symlinks
  1006. if( is_link( $source ) ){
  1007. return symlink( readlink( $source ), $dest );
  1008. }
  1009. // Simple copy for a file
  1010. if( is_file( $source ) ){
  1011. $success = copy( $source, $dest );
  1012. if( $success ){
  1013. return true;
  1014. }else{
  1015. $err_message = "wpeasycart - error backing up " . $source . ". Updated halted.";
  1016. error_log( $err_message );
  1017. exit( $err_message );
  1018. }
  1019. }
  1020. // Make destination directory
  1021. if ( !is_dir( $dest ) ){
  1022. $success = mkdir( $dest, 0755 );
  1023. if( !$success ){
  1024. $err_message = "wpeasycart - error creating backup directory: " . $dest . ". Updated halted.";
  1025. error_log( $err_message );
  1026. exit( $err_message );
  1027. }
  1028. }
  1029. // Loop through the folder
  1030. $dir = dir( $source );
  1031. while( false !== $entry = $dir->read( ) ){
  1032. // Skip pointers
  1033. if ($entry == '.' || $entry == '..') {
  1034. continue;
  1035. }
  1036. // Deep copy directories
  1037. wpeasycart_copyr( "$source/$entry", "$dest/$entry" ); // <------- defines wpeasycart copy action
  1038. }
  1039. // Clean up
  1040. $dir->close( );
  1041. return true;
  1042. }
  1043. function wpeasycart_backup( ){
  1044. // Test for data folder
  1045. if( !file_exists( WP_PLUGIN_DIR . "/wp-easycart-data/" ) ){
  1046. echo "YOU DO NOT HAVE A WP EASYCART DATA FOLDER, PLEASE <a href=\"http://www.wpeasycart.com/plugin-update-help/\" target=\"_blank\">CLICK HERE TO READ HOW TO PREVENT DATA LOSS DURING THE UPDATE</a>";
  1047. die( );
  1048. }
  1049. }
  1050. function ec_recursive_remove_directory( $directory, $empty=FALSE ) {
  1051. // if the path has a slash at the end we remove it here
  1052. if( substr( $directory, -1 ) == '/' )
  1053. $directory = substr( $directory, 0, -1);
  1054. // if the path is not valid or is not a directory ...
  1055. if( !file_exists( $directory ) || !is_dir( $directory ) )
  1056. return FALSE;
  1057. // ... if the path is not readable
  1058. elseif(!is_readable($directory))
  1059. return FALSE;
  1060. // ... else if the path is readable
  1061. else{
  1062. // we open the directory
  1063. $handle = opendir( $directory );
  1064. // and scan through the items inside
  1065. while( FALSE !== ( $item = readdir( $handle ) ) ){
  1066. // if the filepointer is not the current directory
  1067. // or the parent directory
  1068. if( $item != '.' && $item != '..' ){
  1069. // we build the new path to delete
  1070. $path = $directory . '/' . $item;
  1071. // if the new path is a directory
  1072. if( is_dir( $path ) ){
  1073. // we call this function with the new path
  1074. ec_recursive_remove_directory( $path );
  1075. // if the new path is a file
  1076. }else{
  1077. // we remove the file
  1078. unlink( $path );
  1079. }
  1080. }
  1081. }
  1082. // close the directory
  1083. closedir( $handle );
  1084. // if the option to empty is not set to true
  1085. if( $empty == FALSE ){
  1086. // try to delete the now empty directory
  1087. if( !rmdir( $directory ) ){
  1088. // return false if not possible
  1089. return FALSE;
  1090. }
  1091. }
  1092. // return success
  1093. return TRUE;
  1094. }
  1095. }
  1096. function ec_delete_directory_ftp( $resource, $path ) {
  1097. $result_message = "";
  1098. $list = ftp_nlist( $resource, $path );
  1099. if ( empty($list) ) {
  1100. $list = ec_ran_list_n( ftp_rawlist($resource, $path), $path . ( substr($path, strlen($path) - 1, 1) == "/" ? "" : "/" ) );
  1101. }
  1102. if ($list[0] != $path) {
  1103. $path .= ( substr($path, strlen($path)-1, 1) == "/" ? "" : "/" );
  1104. foreach ($list as $item) {
  1105. if ($item != $path.".." && $item != $path.".") {
  1106. $result_message .= ec_delete_directory_ftp($resource, $item);
  1107. }
  1108. }
  1109. if (ftp_rmdir ($resource, $path)) {
  1110. $result_message .= "Successfully deleted $path <br />\n";
  1111. } else {
  1112. $result_message .= "There was a problem while deleting $path <br />\n";
  1113. }
  1114. }
  1115. else {
  1116. $res = ftp_site( $resource, 'CHMOD 0777 ' . $path );
  1117. if (ftp_delete ($resource, $path)) {
  1118. $result_message .= "Successfully deleted $path <br />\n";
  1119. } else {
  1120. $result_message .= "There was a problem while deleting $path <br />\n";
  1121. }
  1122. }
  1123. return $result_message;
  1124. }
  1125. function ec_ran_list_n($rawlist, $path) {
  1126. $array = array();
  1127. foreach ($rawlist as $item) {
  1128. $filename = trim(substr($item, 55, strlen($item) - 55));
  1129. if ($filename != "." || $filename != "..") {
  1130. $array[] = $path . $filename;
  1131. }
  1132. }
  1133. return $array;
  1134. }
  1135. add_filter( 'upgrader_pre_install', 'wpeasycart_backup', 10, 2 );
  1136. //////////////////////////////////////////////
  1137. //END UPDATE FUNCTIONS
  1138. //////////////////////////////////////////////
  1139. /////////////////////////////////////////////////////////////////////
  1140. //AJAX SETUP FUNCTIONS
  1141. /////////////////////////////////////////////////////////////////////
  1142. add_action( 'wp_ajax_ec_ajax_cartitem_update', 'ec_ajax_cartitem_update' );
  1143. add_action( 'wp_ajax_nopriv_ec_ajax_cartitem_update', 'ec_ajax_cartitem_update' );
  1144. function ec_ajax_cartitem_update( ){
  1145. // UPDATE CART ITEM
  1146. $tempcart_id = $_POST['cartitem_id'];
  1147. $session_id = $_POST['session_id'];
  1148. $quantity = $_POST['quantity'];
  1149. if( is_numeric( $quantity ) ){
  1150. $db = new ec_db();
  1151. $db->update_cartitem( $tempcart_id, $session_id, $quantity );
  1152. }
  1153. // UPDATE CART ITEM
  1154. // GET NEW CART ITEM INFO
  1155. $cart = new ec_cart( session_id() );
  1156. $unit_price = 0;
  1157. $total_price = 0;
  1158. $new_quantity = 0;
  1159. for( $i=0; $i<count( $cart->cart ); $i++ ){
  1160. if( $cart->cart[$i]->cartitem_id == $tempcart_id ){
  1161. $unit_price = $cart->cart[$i]->unit_price;
  1162. $total_price = $cart->cart[$i]->total_price;
  1163. $new_quantity = $cart->cart[$i]->quantity;
  1164. }
  1165. }
  1166. // GET NEW CART ITEM INFO
  1167. $order_totals = ec_get_order_totals( );
  1168. echo $GLOBALS['currency']->get_currency_display( $unit_price ) . "***" .
  1169. $GLOBALS['currency']->get_currency_display( $total_price ) . "***" .
  1170. $new_quantity . "***" .
  1171. $GLOBALS['currency']->get_currency_display( $order_totals->sub_total ) . "***" .
  1172. $GLOBALS['currency']->get_currency_display( $order_totals->tax_total ) . "***" .
  1173. $GLOBALS['currency']->get_currency_display( $order_totals->shipping_total ) . "***" .
  1174. $GLOBALS['currency']->get_currency_display( $order_totals->duty_total ) . "***" .
  1175. $GLOBALS['currency']->get_currency_display( $order_totals->vat_total ) . "***" .
  1176. $GLOBALS['currency']->get_currency_display( $order_totals->discount_total ) . "***" .
  1177. $GLOBALS['currency']->get_currency_display( $order_totals->grand_total );
  1178. die(); // this is required to return a proper result
  1179. }
  1180. add_action( 'wp_ajax_ec_ajax_cartitem_delete', 'ec_ajax_cartitem_delete' );
  1181. add_action( 'wp_ajax_nopriv_ec_ajax_cartitem_delete', 'ec_ajax_cartitem_delete' );
  1182. function ec_ajax_cartitem_delete( ){
  1183. //Get the variables from the AJAX call
  1184. $tempcart_id = $_POST['cartitem_id'];
  1185. $session_id = $_POST['session_id'];
  1186. // DELTE CART ITEM
  1187. $db = new ec_db();
  1188. $ret_data = $db->delete_cartitem( $tempcart_id, $session_id );
  1189. // DELETE CART ITEM
  1190. $cart = new ec_cart( session_id() );
  1191. $order_totals = ec_get_order_totals( );
  1192. echo $cart->total_items . "***" .
  1193. $GLOBALS['currency']->get_currency_display( $order_totals->sub_total ) . "***" .
  1194. $GLOBALS['currency']->get_currency_display( $order_totals->tax_total ) . "***" .
  1195. $GLOBALS['currency']->get_currency_display( $order_totals->shipping_total ) . "***" .
  1196. $GLOBALS['currency']->get_currency_display( $order_totals->duty_total ) . "***" .
  1197. $GLOBALS['currency']->get_currency_display( $order_totals->vat_total ) . "***" .
  1198. $GLOBALS['currency']->get_currency_display( $order_totals->discount_total ) . "***" .
  1199. $GLOBALS['currency']->get_currency_display( $order_totals->grand_total );
  1200. die(); // this is required to return a proper result
  1201. }
  1202. add_action( 'wp_ajax_ec_ajax_redeem_coupon_code', 'ec_ajax_redeem_coupon_code' );
  1203. add_action( 'wp_ajax_nopriv_ec_ajax_redeem_coupon_code', 'ec_ajax_redeem_coupon_code' );
  1204. function ec_ajax_redeem_coupon_code( ){
  1205. //UPDATE COUPON CODE
  1206. $coupon_code = "";
  1207. if( isset( $_POST['couponcode'] ) )
  1208. $coupon_code = $_POST['couponcode'];
  1209. $_SESSION['ec_couponcode'] = $coupon_code;
  1210. $db = new ec_db();
  1211. $coupon = $db->redeem_coupon_code( $coupon_code );
  1212. // UPDATE COUPON CODE
  1213. $cart = new ec_cart( session_id() );
  1214. $order_totals = ec_get_order_totals( );
  1215. echo $cart->total_items . "***" .
  1216. $GLOBALS['currency']->get_currency_display( $order_totals->sub_total ) . "***" .
  1217. $GLOBALS['currency']->get_currency_display( $order_totals->tax_total ) . "***" .
  1218. $GLOBALS['currency']->get_currency_display( $order_totals->shipping_total ) . "***" .
  1219. $GLOBALS['currency']->get_currency_display( $order_totals->discount_total ) . "***" .
  1220. $GLOBALS['currency']->get_currency_display( $order_totals->duty_total ) . "***" .
  1221. $GLOBALS['currency']->get_currency_display( $order_totals->vat_total ) . "***" .
  1222. $GLOBALS['currency']->get_currency_display( $order_totals->grand_total );
  1223. if( $coupon )
  1224. echo "***" . $coupon->message;
  1225. else
  1226. echo "***" . $GLOBALS['language']->get_text( 'cart_coupons', 'cart_invalid_coupon' );
  1227. die(); // this is required to return a proper result
  1228. }
  1229. add_action( 'wp_ajax_ec_ajax_redeem_gift_card', 'ec_ajax_redeem_gift_card' );
  1230. add_action( 'wp_ajax_nopriv_ec_ajax_redeem_gift_card', 'ec_ajax_redeem_gift_card' );
  1231. function ec_ajax_redeem_gift_card( ){
  1232. // UPDATE GIFT CARD
  1233. $gift_card = "";
  1234. if( isset( $_POST['giftcard'] ) )
  1235. $gift_card = $_POST['giftcard'];
  1236. $_SESSION['ec_giftcard'] = $gift_card;
  1237. $db = new ec_db();
  1238. $giftcard = $db->redeem_gift_card( $gift_card );
  1239. // UPDATE GIFT CARD
  1240. $cart = new ec_cart( session_id() );
  1241. $order_totals = ec_get_order_totals( );
  1242. echo $cart->total_items . "***" .
  1243. $GLOBALS['currency']->get_currency_display( $order_totals->sub_total ) . "***" .
  1244. $GLOBALS['currency']->get_currency_display( $order_totals->tax_total ) . "***" .
  1245. $GLOBALS['currency']->get_currency_display( $order_totals->shipping_total ) . "***" .
  1246. $GLOBALS['currency']->get_currency_display( $order_totals->discount_total ) . "***" .
  1247. $GLOBALS['currency']->get_currency_display( $order_totals->duty_total ) . "***" .
  1248. $GLOBALS['currency']->get_currency_display( $order_totals->vat_total ) . "***" .
  1249. $GLOBALS['currency']->get_currency_display( $order_totals->grand_total );
  1250. if( $giftcard )
  1251. echo "***" . $giftcard->message;
  1252. else
  1253. echo "***" . $GLOBALS['language']->get_text( 'cart_coupons', 'cart_invalid_giftcard' );
  1254. die(); // this is required to return a proper result
  1255. }
  1256. add_action( 'wp_ajax_ec_ajax_estimate_shipping', 'ec_ajax_estimate_shipping' );
  1257. add_action( 'wp_ajax_nopriv_ec_ajax_estimate_shipping', 'ec_ajax_estimate_shipping' );
  1258. function ec_ajax_estimate_shipping( ){
  1259. //Get the variables from the AJAX call
  1260. if( isset( $_POST['zipcode'] ) ){
  1261. $_SESSION['ec_temp_zipcode'] = $_POST['zipcode'];
  1262. $_SESSION['ec_shipping_zip'] = $_POST['zipcode'];
  1263. }
  1264. if( isset( $_POST['country'] ) && $_POST['country'] != "0" ){
  1265. $_SESSION['ec_temp_country'] = $_POST['country'];
  1266. $_SESSION['ec_shipping_country'] = $_POST['country'];
  1267. }
  1268. $cart = new ec_cart( session_id() );
  1269. $order_totals = ec_get_order_totals( );
  1270. $setting = new ec_setting( );
  1271. $cart = new ec_cart( session_id() );
  1272. $shipping = new ec_shipping( $cart->subtotal, $cart->weight, $cart->shippable_total_items );
  1273. $shipping_options = $shipping->get_shipping_options( $GLOBALS['language']->get_text( 'cart_estimate_shipping', 'cart_estimate_shipping_standard' ),$GLOBALS['language']->get_text( 'cart_estimate_shipping', 'cart_estimate_shipping_express' ), "RADIO" );
  1274. if( $setting->get_shipping_method() == "live" && $shipping_options )
  1275. echo $GLOBALS['currency']->get_currency_display( $order_totals->shipping_total ) . "***" . $GLOBALS['currency']->get_currency_display( $order_totals->grand_total ) . "***" . $shipping_options . "***" . $GLOBALS['currency']->get_currency_display( $order_totals->vat_total );
  1276. else if( $setting->get_shipping_method() == "live" )
  1277. echo $GLOBALS['currency']->get_currency_display( $order_totals->shipping_total ) . "***" . $GLOBALS['currency']->get_currency_display( $order_totals->grand_total ) . "***" . "<div class=\"ec_cart_shipping_method_row\">" . $GLOBALS['language']->get_text( 'cart_estimate_shipping', 'cart_estimate_shipping_error' ) . "</div>";
  1278. else
  1279. echo $GLOBALS['currency']->get_currency_display( $order_totals->shipping_total ) . "***" . $GLOBALS['currency']->get_currency_display( $order_totals->grand_total ) . "***" . $shipping_options;
  1280. die(); // this is required to return a proper result
  1281. }
  1282. add_action( 'wp_ajax_ec_ajax_update_shipping_method', 'ec_ajax_update_shipping_method' );
  1283. add_action( 'wp_ajax_nopriv_ec_ajax_update_shipping_method', 'ec_ajax_update_shipping_method' );
  1284. function ec_ajax_update_shipping_method( ){
  1285. //Get the variables from the AJAX call
  1286. $shipping_method = $_POST['shipping_method'];
  1287. //Create a new db and submit review
  1288. $_SESSION['ec_shipping_method'] = $shipping_method;
  1289. $cart = new ec_cart( session_id() );
  1290. $order_totals = ec_get_order_totals( );
  1291. $setting = new ec_setting( );
  1292. $cart = new ec_cart( session_id() );
  1293. $shipping = new ec_shipping( $cart->subtotal, $cart->weight, $cart->shippable_total_items );
  1294. $shipping_options = $shipping->get_shipping_options( "", "" );
  1295. if( $setting->get_shipping_method() == "live" && $shipping_options )
  1296. echo $GLOBALS['currency']->get_currency_display( $order_totals->shipping_total ) . "***" . $GLOBALS['currency']->get_currency_display( $order_totals->grand_total ) . "***" . $shipping_options . "***" . $GLOBALS['currency']->get_currency_display( $order_totals->vat_total );
  1297. else if( $setting->get_shipping_method() == "live" )
  1298. echo $GLOBALS['currency']->get_currency_display( $order_totals->shipping_total ) . "***" . $GLOBALS['currency']->get_currency_display( $order_totals->grand_total ) . "***" . "<div class=\"ec_cart_shipping_method_row\">" . $GLOBALS['language']->get_text( 'cart_estimate_shipping', 'cart_estimate_shipping_error' ) . "</div>";
  1299. else
  1300. echo $GLOBALS['currency']->get_currency_display( $order_totals->shipping_total ) . "***" . $GLOBALS['currency']->get_currency_display( $order_totals->grand_total );
  1301. die(); // this is required to return a proper result
  1302. }
  1303. add_action( 'wp_ajax_ec_ajax_insert_customer_review', 'ec_ajax_insert_customer_review' );
  1304. add_action( 'wp_ajax_nopriv_ec_ajax_insert_customer_review', 'ec_ajax_insert_customer_review' );
  1305. function ec_ajax_insert_customer_review( ){
  1306. //Get the variables from the AJAX call
  1307. $product_id = $_POST['product_id'];
  1308. $rating = $_POST['rating'];
  1309. $title = $_POST['title'];
  1310. $description = $_POST['description'];
  1311. //Create a new db and submit review
  1312. $db = new ec_db();
  1313. echo $db->submit_customer_review( $product_id, $rating, $title, $description );
  1314. die(); // this is required to return a proper result
  1315. }
  1316. // Helper function for AJAX calls in cart.
  1317. function ec_get_order_totals( ){
  1318. $user_email = "";
  1319. if( isset( $_SESSION['ec_email'] ) )
  1320. $user_email = $_SESSION['ec_email'];
  1321. $coupon_code = "";
  1322. if( isset( $_SESSION['ec_couponcode'] ) )
  1323. $coupon_code = $_SESSION['ec_couponcode'];
  1324. $gift_card = "";
  1325. if( isset( $_SESSION['ec_giftcard'] ) )
  1326. $gift_card = $_SESSION['ec_giftcard'];
  1327. $cart = new ec_cart( session_id() );
  1328. $user = new ec_user( $user_email );
  1329. $shipping = new ec_shipping( $cart->shipping_subtotal, $cart->weight, $cart->shippable_total_items );
  1330. $sales_tax_discount = new ec_discount( $cart, $cart->subtotal, 0.00, $coupon_code, "", 0 );
  1331. $tax = new ec_tax( $cart->subtotal, $cart->taxable_subtotal - $sales_tax_discount->coupon_discount, 0, $user->shipping->state, $user->shipping->country );
  1332. $grand_total = ( $cart->subtotal + $tax->tax_total + $shipping->get_shipping_price( ) + $tax->duty_total );
  1333. $discount = new ec_discount( $cart, $cart->subtotal, $shipping->get_shipping_price( ), $coupon_code, $gift_card, $grand_total );
  1334. $vatable_subtotal = $grand_total - $discount->coupon_discount;
  1335. $tax = new ec_tax( $cart->subtotal, $cart->taxable_subtotal - $sales_tax_discount->coupon_discount, $vatable_subtotal, $user->shipping->state, $user->shipping->country );
  1336. $discount = new ec_discount( $cart, $cart->subtotal, $shipping->get_shipping_price( ), $coupon_code, $gift_card, $GLOBALS['currency']->get_number_only( $grand_total ) + $GLOBALS['currency']->get_number_only( $tax->vat_total ) );
  1337. $order_totals = new ec_order_totals( $cart, $user, $shipping, $tax, $discount );
  1338. return $order_totals;
  1339. }
  1340. add_action( 'wp_ajax_ec_ajax_get_cart', 'ec_ajax_get_cart' );
  1341. add_action( 'wp_ajax_nopriv_ec_ajax_get_cart', 'ec_ajax_get_cart' );
  1342. function ec_ajax_get_cart( ){
  1343. //Get the variables from the AJAX call
  1344. $cart = new ec_cart( session_id() );
  1345. $retarray = array( );
  1346. foreach( $cart->cart as $cartitem ){
  1347. $retarray[] = array( "cartitem_id" => $cartitem->cartitem_id,
  1348. "title" => $cartitem->title,
  1349. "quantity" => $cartitem->quantity,
  1350. "unit_price" => $GLOBALS['currency']->get_currency_display( $cartitem->unit_price ) );
  1351. }
  1352. echo json_encode( $retarray );
  1353. die(); // this is required to return a proper result
  1354. }
  1355. add_action( 'wp_ajax_ec_ajax_get_cart_totals', 'ec_ajax_get_cart_totals' );
  1356. add_action( 'wp_ajax_nopriv_ec_ajax_get_cart_totals', 'ec_ajax_get_cart_totals' );
  1357. function ec_ajax_get_cart_totals( ){
  1358. //Get the variables from the AJAX call
  1359. $cartpage = new ec_cartpage( );
  1360. $retarray = array( "sub_total" => $GLOBALS['currency']->get_currency_display( $cartpage->order_totals->sub_total ),
  1361. "tax_total" => $GLOBALS['currency']->get_currency_display( $cartpage->order_totals->tax_total ),
  1362. "shipping_total" => $GLOBALS['currency']->get_currency_display( $cartpage->order_totals->shipping_total ),
  1363. "duty_total" => $GLOBALS['currency']->get_currency_display( $cartpage->order_totals->duty_total ),
  1364. "vat_total" => $GLOBALS['currency']->get_currency_display( $cartpage->order_totals->vat_total ),
  1365. "discount_total" => $GLOBALS['currency']->get_currency_display( $cartpage->order_totals->discount_total ),
  1366. "grand_total" => $GLOBALS['currency']->get_currency_display( $cartpage->order_totals->grand_total ) );
  1367. echo json_encode( $retarray );
  1368. die(); // this is required to return a proper result
  1369. }
  1370. // End AJAX helper function for cart.
  1371. add_filter( 'wp_title', 'ec_custom_title', 20 );
  1372. function ec_custom_title( $title ) {
  1373. $page_id = get_the_ID();
  1374. $store_id = get_option( 'ec_option_storepage' );
  1375. if( $page_id == $store_id && isset( $_GET['model_number'] ) ){
  1376. $db = new ec_db( );
  1377. $products = $db->get_product_list( " WHERE product.model_number = '" . $_GET['model_number'] . "'", "", "", "" );
  1378. if( count( $products ) > 0 ){
  1379. $custom_title = $products[0]['title'] . " |" . $title;
  1380. return $custom_title;
  1381. }else{
  1382. return $title;
  1383. }
  1384. }else if( $page_id == $store_id ){
  1385. $additional_title = "";
  1386. if( isset( $_GET['manufacturer'] ) ){
  1387. $db = new ec_db( );
  1388. $manufacturer = $db->get_manufacturer_row( $_GET['manufacturer'] );
  1389. $additional_title .= $manufacturer->name . " |";
  1390. }
  1391. if( isset( $_GET['menu'] ) ){
  1392. $custom_title = $_GET['menu'] . " |" . $additional_title . $title;
  1393. return $custom_title;
  1394. }else if( isset( $_GET['submenu'] ) ){
  1395. $custom_title = $_GET['submenu'] . " |" . $additional_title . $title;
  1396. return $custom_title;
  1397. }else if( isset( $_GET['subsubmenu'] ) ){
  1398. $custom_title = $_GET['subsubmenu'] . " |" . $additional_title . $title;
  1399. return $custom_title;
  1400. }else{
  1401. return $additional_title . $title;
  1402. }
  1403. }else{
  1404. return $title;
  1405. }
  1406. }
  1407. add_action('wp_head', 'ec_store_meta', 0);
  1408. function ec_store_meta( ){
  1409. $page_id = get_the_ID();
  1410. $store_id = get_option( 'ec_option_storepage' );
  1411. if( $page_id == $store_id && isset( $_GET['model_number'] ) ){
  1412. $db = new ec_db( );
  1413. $products = $db->get_product_list( " WHERE product.model_number = '" . $_GET['model_number'] . "'", "", "", "" );
  1414. if( count( $products ) > 0){
  1415. echo "<meta name=\"description\" content=\"" . $products[0]['seo_description'] . "\"/>";
  1416. echo "<meta name=\"keywords\" content=\"" . $products[0]['seo_keywords'] . "\" />";
  1417. }
  1418. }else if( $page_id == $store_id ){
  1419. if( isset( $_GET['menuid'] ) ){
  1420. $db = new ec_db( );
  1421. $menu_row = $db->get_menu_row( $_GET['menuid'], 1 );
  1422. echo "<meta name=\"description\" content=\"" . $menu_row->seo_description . "\"/>\n";
  1423. echo "<meta name=\"keywords\" content=\"" . $menu_row->seo_keywords . "\" />\n";
  1424. }else if( isset( $_GET['submenuid'] ) ){
  1425. $db = new ec_db( );
  1426. $menu_row = $db->get_menu_row( $_GET['submenuid'], 2 );
  1427. echo "<meta name=\"description\" content=\"" . $menu_row->seo_description . "\"/>\n";
  1428. echo "<meta name=\"keywords\" content=\"" . $menu_row->seo_keywords . "\" />\n";
  1429. }else if( isset( $_GET['subsubmenuid'] ) ){
  1430. $db = new ec_db( );
  1431. $menu_row = $db->get_menu_row( $_GET['subsubmenuid'], 3 );
  1432. echo "<meta name=\"description\" content=\"" . $menu_row->seo_description . "\"/>\n";
  1433. echo "<meta name=\"keywords\" content=\"" . $menu_row->seo_keywords . "\" />\n";
  1434. }
  1435. }
  1436. }
  1437. function ec_theme_options_page_callback( ){
  1438. if( is_dir( WP_PLUGIN_DIR . "/wp-easycart-data/design/theme/" . get_option('ec_option_base_theme') . "/" ) )
  1439. include( WP_PLUGIN_DIR . "/wp-easycart-data/design/theme/" . get_option('ec_option_base_theme') . "/admin_panel.php");
  1440. else
  1441. include( WP_PLUGIN_DIR . "/" . EC_PLUGIN_DIRECTORY . "/design/theme/" . get_option('ec_option_base_theme') . "/admin_panel.php");
  1442. }
  1443. /////////////////////////////////////////////////////////////////////
  1444. //CUSTOM POST TYPES
  1445. /////////////////////////////////////////////////////////////////////
  1446. add_action( 'init', 'ec_create_post_type_menu' );
  1447. function ec_create_post_type_menu() {
  1448. $store_id = get_option( 'ec_option_storepage' );
  1449. if( $store_id ){
  1450. $store_slug = ec_get_the_slug( $store_id );
  1451. $labels = array(
  1452. 'name' => _x( 'Store Items', 'post type general name' ),
  1453. 'singular_name' => _x( 'Store Item', 'post type singular name' ),
  1454. 'add_new' => _x( 'Add New', 'ec_store' ),
  1455. 'add_new_item' => __( 'Add New Store Item' ),
  1456. 'edit_item' => __( 'Edit Store Item' ),
  1457. 'new_item' => __( 'New Store Item' ),
  1458. 'all_items' => __( 'All Store Items' ),
  1459. 'view_item' => __( 'View Store Item' ),
  1460. 'search_items' => __( 'Search Store Items' ),
  1461. 'not_found' => __( 'No store items found' ),
  1462. 'not_found_in_trash' => __( 'No store items found in the Trash' ),
  1463. 'parent_item_colon' => '',
  1464. 'menu_name' => 'Store Items'
  1465. );
  1466. $args = array(
  1467. 'labels' => $labels,
  1468. 'description' => 'Used for the EasyCart Store',
  1469. 'public' => true,
  1470. 'has_archive' => false,
  1471. 'show_ui' => false,
  1472. 'show_in_nav_menus' => true,
  1473. 'supports' => array( 'title', 'page-attributes', 'author', 'editor', 'post-formats' ),
  1474. 'rewrite' => array( 'slug' => $store_slug, 'with_front' => false, 'page' => false ),
  1475. );
  1476. register_post_type( 'ec_store', $args );
  1477. global $wp_rewrite;
  1478. $wp_rewrite->add_permastruct( 'ec_store', $store_slug . '/%ec_store%/', true, 1 );
  1479. add_rewrite_rule( $store_slug . '/([^/]*)/([^/]*)/?$', 'index.php?ec_store=$matches[2]', 'top');
  1480. // Only Flush Once!
  1481. if( get_option( 'ec_option_added_custom_post_type' ) < 2 ){
  1482. $wp_rewrite->flush_rules();
  1483. update_option( 'ec_option_added_custom_post_type', 2 );
  1484. }
  1485. }
  1486. }
  1487. function ec_get_the_slug( $id=null ){
  1488. if( empty($id) ) :
  1489. global $post;
  1490. if( empty($post) )
  1491. return '';
  1492. $id = $post->ID;
  1493. endif;
  1494. $slug = basename( get_permalink($id) );
  1495. return $slug;
  1496. }
  1497. add_action( 'wp', 'ec_force_page_type' );
  1498. function ec_force_page_type() {
  1499. global $wp_query, $post_type;
  1500. if ($post_type == 'ec_store') {
  1501. $wp_query->is_page = true;
  1502. $wp_query->is_single = false;
  1503. $wp_query->query_vars['post_type'] = "page";
  1504. $wp_query->post->post_type = "page";
  1505. }
  1506. }
  1507. add_filter( 'template_redirect', 'ec_fix_store_template', 1 );
  1508. function ec_fix_store_template( ){
  1509. global $wp;
  1510. $custom_post_types = array("ec_store");
  1511. if( isset( $wp->query_vars["post_type"] ) && in_array( $wp->query_vars["post_type"], $custom_post_types ) ){
  1512. $store_template = get_post_meta( get_option( 'ec_option_storepage' ), "_wp_page_template", true );
  1513. if( isset( $store_template ) && $store_template != "" && $store_template != "default" ){
  1514. if( file_exists( get_template_directory( ) . "/" . $store_template ) ){
  1515. include( get_template_directory( ) . "/" . $store_template );
  1516. exit( );
  1517. }
  1518. }
  1519. }
  1520. }
  1521. /////////////////////////////////////////////////////////////////////
  1522. //HELPER FUNCTIONS
  1523. /////////////////////////////////////////////////////////////////////
  1524. //Helper Function, Get URL
  1525. function ec_get_url(){
  1526. if( isset( $_SERVER['HTTPS'] ) )
  1527. $protocol = "https";
  1528. else
  1529. $protocol = "http";
  1530. $baseurl = "://" . $_SERVER['HTTP_HOST'];
  1531. $strip = explode("/wp-admin", $_SERVER['REQUEST_URI']);
  1532. $folder = $strip[0];
  1533. return $protocol . $baseurl . $folder;
  1534. }
  1535. function ec_setup_hooks( ){
  1536. $GLOBALS['ec_hooks'] = array( );
  1537. }
  1538. function ec_add_hook( $call_location, $function_name, $args = array(), $priority = 1 ){
  1539. if( !isset( $GLOBALS['ec_hooks'][$call_location] ) )
  1540. $GLOBALS['ec_hooks'][$call_location] = array( );
  1541. $GLOBALS['ec_hooks'][$call_location][] = array( $function_name, $args, $priority );
  1542. }
  1543. function ec_call_hook( $hook_array, $class_args ){
  1544. $hook_array[0]( $hook_array[1], $class_args );
  1545. }
  1546. function ec_dwolla_verify_signature( $proposedSignature, $checkoutId, $amount ){
  1547. $apiSecret = get_option( 'ec_option_dwolla_thirdparty_secret' );
  1548. $amount = number_format( $amount, 2 );
  1549. $signature = hash_hmac("sha1", "{$checkoutId}&{$amount}", $apiSecret);
  1550. return $signature == $proposedSignature;
  1551. }
  1552. ///////////////////HAVING ISSUES WITH OUT DURING ACTIVATION?? PRINT ERRORS!//////////////////
  1553. /*
  1554. add_action( 'activated_plugin','ec_save_error' );
  1555. function ec_save_error(){
  1556. file_put_contents( WP_PLUGIN_DIR . "/" . EC_PLUGIN_DIRECTORY. '/error_activation.html', ob_get_contents( ) );
  1557. }
  1558. */
  1559. ?>