PageRenderTime 70ms CodeModel.GetById 22ms 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

Large files files are truncated, but you can click here to view the full 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( );

Large files files are truncated, but you can click here to view the full file