function __construct () { parent::__construct(); global $Ecart; $this->urls['schema'] = 'http://checkout.google.com/schema/2'; $this->urls['checkout'] = array( 'live' => 'https://%s:%s@checkout.google.com/api/checkout/v2/merchantCheckout/Merchant/%s', 'test' => 'https://%s:%s@sandbox.google.com/checkout/api/checkout/v2/merchantCheckout/Merchant/%s' ); $this->urls['order'] = array( 'live' => 'https://%s:%s@checkout.google.com/api/checkout/v2/request/Merchant/%s', 'test' => 'https://%s:%s@sandbox.google.com/checkout/api/checkout/v2/request/Merchant/%s' ); $this->urls['button'] = array( 'live' => (is_ecart_secure()?'https':'http').'://checkout.google.com/buttons/checkout.gif', 'test' => (is_ecart_secure()?'https':'http').'://sandbox.google.com/checkout/buttons/checkout.gif' ); $this->merchant_calc_url = esc_url(add_query_string('_txnupdate=gc',ecarturl(false,'catalog',true))); $this->setup('id','key','apiurl'); $this->settings['merchant_email'] = $Ecart->Settings->get('merchant_email'); $this->settings['location'] = "en_US"; $base = $Ecart->Settings->get('base_operations'); if ($base['country'] == "GB") $this->settings['location'] = "en_UK"; $this->settings['base_operations'] = $Ecart->Settings->get('base_operations'); $this->settings['currency'] = $this->settings['base_operations']['currency']['code']; if (empty($this->settings['currency'])) $this->settings['currency'] = "USD"; $this->settings['taxes'] = $Ecart->Settings->get('taxrates'); if (isset($_GET['gctest'])) $this->order(''); add_action('ecart_txn_update',array(&$this,'notifications')); add_filter('ecart_checkout_submit_button',array(&$this,'submit'),10,3); add_action('get_header',array(&$this,'analytics')); add_filter('ecart_tag_cart_google',array($this,'cartcheckout')); add_action('parse_request',array(&$this,'intercept_cartcheckout')); }
/** * Checkout form processing * * Handles taking user input from the checkout form and * processing the information into useable order data * * @since 1.1 * * @return void **/ function checkout () { global $Ecart; if (!isset($_POST['checkout'])) return; if ($_POST['checkout'] != "process") return; $_POST = stripslashes_deep($_POST); $cc = $this->ccpayment(); if ($cc) { $_POST['billing']['cardexpires'] = sprintf("%02d%02d",$_POST['billing']['cardexpires-mm'],$_POST['billing']['cardexpires-yy']); // If the card number is provided over a secure connection // Change the cart to operate in secure mode if (!empty($_POST['billing']['card']) && is_ecart_secure()) $Ecart->Shopping->secured(true); // Sanitize the card number to ensure it only contains numbers if (!empty($_POST['billing']['card'])) $_POST['billing']['card'] = preg_replace('/[^\d]/','',$_POST['billing']['card']); } // Remove invlalid characters from the phone number $_POST['phone'] = preg_replace('/[^\d\(\)\-+\. (ext|x)]/','',$_POST['phone']); if (isset($_POST['data'])) $this->data = $_POST['data']; if (isset($_POST['info'])) $this->Customer->info = $_POST['info']; if (empty($this->Customer)) $this->Customer = new Customer(); $this->Customer->updates($_POST); // Keep confirm-password field value when showing checkout validation errors if (isset($_POST['confirm-password'])) $this->Customer->_confirm_password = $_POST['confirm-password']; if (empty($this->Billing)) $this->Billing = new Billing(); // Default the cardtype to the payment method label selected $this->Billing->cardtype = $this->payoptions[$this->paymethod]->label; $this->Billing->updates($_POST['billing']); // Special case for updating/tracking billing locale if (!empty($_POST['billing']['locale'])) $this->Billing->locale = $_POST['billing']['locale']; if ($cc) { if (!empty($_POST['billing']['cardexpires-mm']) && !empty($_POST['billing']['cardexpires-yy'])) { $exmm = preg_replace('/[^\d]/','',$_POST['billing']['cardexpires-mm']); $exyy = preg_replace('/[^\d]/','',$_POST['billing']['cardexpires-yy']); $this->Billing->cardexpires = mktime(0,0,0,$exmm,1,($exyy)+2000); } else $this->Billing->cardexpires = 0; $this->Billing->cvv = preg_replace('/[^\d]/','',$_POST['billing']['cvv']); if (!empty($_POST['billing']['xcsc'])) { foreach ($_POST['billing']['xcsc'] as $field => $value) $this->Billing->{$field} = $value; } } if (!empty($this->Cart->shipped)) { if (empty($this->Shipping)) $this->Shipping = new Shipping(); if (isset($_POST['shipping'])) $this->Shipping->updates($_POST['shipping']); if (!empty($_POST['shipmethod'])) $this->Shipping->method = $_POST['shipmethod']; else $this->Shipping->method = key($this->Cart->shipping); // Override posted shipping updates with billing address if (isset($_POST['sameshipaddress']) && $_POST['sameshipaddress'] == "on") $this->Shipping->updates($this->Billing, array("_datatypes","_table","_key","_lists","id","created","modified")); } else $this->Shipping = new Shipping(); // Use blank shipping for non-Shipped orders $freebie = $this->Cart->orderisfree(); $estimated = $this->Cart->Totals->total; $this->Cart->changed(true); $this->Cart->totals(); if ($this->validform() !== true) return; else $this->Customer->updates($_POST); // Catch changes from validation do_action('ecart_checkout_processed'); if (apply_filters('ecart_process_free_order',$this->Cart->orderisfree())) return; // Catch originally free orders that get extra (shipping) costs added to them if ($freebie && $this->Cart->Totals->total > 0) { if ( ! (count($this->payoptions) == 1 // One paymethod && ( isset($this->payoptions[$this->paymethod]->cards) // Remote checkout && empty( $this->payoptions[$this->paymethod]->cards ) ) ) ) { new EcartError(__('Payment information for this order is missing.','Ecart'),'checkout_no_paymethod',ECART_ERR); ecart_redirect( ecarturl(false,'checkout',$this->security()) ); } } // If the cart's total changes at all, confirm the order if ($estimated != $this->Cart->Totals->total || $this->confirm) ecart_redirect( ecarturl(false,'confirm-order',$this->security()) ); else do_action('ecart_process_order'); }
/** * Generate the session security key * * @since 1.1 * * @return string **/ function securekey () { if (!is_ecart_secure()) return false; $expiration = time()+ECART_SESSION_TIMEOUT; if (defined('SECRET_AUTH_KEY') && SECRET_AUTH_KEY != '') $key = SECRET_AUTH_KEY; else $key = md5(serialize($this->data).time()); $content = hash_hmac('sha256', $this->session . '|' . $expiration, $key); $success = false; if ( version_compare(phpversion(), '5.2.0', 'ge') ) $success = setcookie(ECART_SECURE_KEY,$content,0,'/','',true,true); else $success = setcookie(ECART_SECURE_KEY,$content,0,'/','',true); if ($success) return $content; else return false; }
/** * Queues Ecart storefront javascript and styles as needed * * @since 1.1 * * @return void **/ function behaviors () { global $Ecart; global $wp_query; $object = $wp_query->get_queried_object(); if(is_ecart_secure()) { add_filter('option_siteurl', 'force_ssl'); add_filter('option_home', 'force_ssl'); add_filter('option_url', 'force_ssl'); add_filter('option_wpurl', 'force_ssl'); add_filter('option_stylesheet_url', 'force_ssl'); add_filter('option_template_url', 'force_ssl'); add_filter('script_loader_src', 'force_ssl'); } // Determine which tag is getting used in the current post/page $tag = false; $tagregexp = join( '|', array_keys($this->shortcodes) ); foreach ($wp_query->posts as $post) { if (preg_match('/\[('.$tagregexp.')\b(.*?)(?:(\/))?\](?:(.+?)\[\/\1\])?/',$post->post_content,$matches)) $tag = $matches[1]; } // Include stylesheets and javascript based on whether ecart shortcodes are used add_action('wp_print_styles',array(&$this, 'catalogcss')); // Replace the WordPress canonical link remove_action('wp_head','rel_canonical'); add_action('wp_head', array(&$this, 'header')); add_action('wp_footer', array(&$this, 'footer')); wp_enqueue_style('ecart.catalog',ECART_ADMIN_URI.'/styles/catalog.css',array(),ECART_VERSION,'screen'); wp_enqueue_style('ecart',ECART_TEMPLATES_URI.'/ecart.css',array(),ECART_VERSION,'screen'); wp_enqueue_style('ecart.colorbox',ECART_ADMIN_URI.'/styles/colorbox.css',array(),ECART_VERSION,'screen'); if (is_ecart_page('account') || (isset($wp->query_vars['ecart_proc']) && $wp->query_vars['ecart_proc'] == "sold")) wp_enqueue_style('ecart.printable',ECART_ADMIN_URI.'/styles/printable.css',array(),ECART_VERSION,'print'); $loading = $this->Settings->get('script_loading'); if (!$loading || $loading == "global" || $tag !== false) { ecart_enqueue_script("colorbox"); ecart_enqueue_script("ecart"); ecart_enqueue_script("catalog"); ecart_enqueue_script("cart"); if (is_ecart_page('catalog')) ecart_custom_script('catalog',"var pricetags = {};\n"); add_action('wp_head', array(&$Ecart, 'settingsjs')); } if ($tag == "checkout") ecart_enqueue_script('checkout'); }
/** * Generates canonical storefront URLs that respects the WordPress permalink settings * * @since 1.1 * * @param mixed $request Additional URI requests * @param string $page The gateway page * @param boolean $secure (optional) True for secure URLs, false to force unsecure URLs * @return string The final URL **/ function ecarturl ($request=false,$page='catalog',$secure=null) { $dynamic = array("thanks","receipt","confirm-order"); $Settings =& EcartSettings(); if (!$Settings->available) return; // Get the currently indexed Ecart gateway pages $pages = $Settings->get('pages'); if (empty($pages)) { // Hrm, no pages, attempt to rescan for them // No WordPress actions, #epicfail if (!function_exists('do_action')) return false; do_action('ecart_reindex_pages'); $pages = $Settings->get('pages'); // Still no pages? WTH? #epicfailalso if (empty($pages)) return false; } // Start with the site url $siteurl = trailingslashit(get_bloginfo('url')); // Rewrite as an HTTPS connection if necessary if ($secure === false) $siteurl = str_replace('https://','http://',$siteurl); elseif (($secure || is_ecart_secure()) && !ECART_NOSSL) $siteurl = str_replace('http://','https://',$siteurl); // Determine WordPress gateway page URI path fragment if (isset($pages[$page])) { $path = $pages[$page]['uri']; $pageid = $pages[$page]['id']; } else { if (in_array($page,$dynamic)) { $target = $pages['checkout']; if (ECART_PRETTYURLS) { $catalog = empty($pages['catalog']['uri'])?$pages['catalog']['name']:$pages['catalog']['uri']; $path = trailingslashit($catalog).$page; } else $pageid = $target['id']."&ecart_proc=$page"; } elseif ('images' == $page) { $target = $pages['catalog']; $path = trailingslashit($target['uri']).'images'; if (!ECART_PRETTYURLS) $request = array('siid'=>$request); } else { $path = $pages['catalog']['uri']; $pageid = $pages['catalog']['id']; } } if (ECART_PRETTYURLS) $url = user_trailingslashit($siteurl.$path); else $url = isset($pageid)?add_query_arg('page_id',$pageid,$siteurl):$siteurl; // No extra request, return the complete URL if (!$request) return $url; // Filter URI request $uri = false; if (!is_array($request)) $uri = urldecode($request); if (is_array($request && isset($request[0]))) $uri = array_shift($request); if (!empty($uri)) $uri = join('/',array_map('urlencode',explode('/',$uri))); // sanitize $url = user_trailingslashit(trailingslashit($url).$uri); if (!empty($request) && is_array($request)) { $request = array_map('urldecode',$request); $request = array_map('urlencode',$request); $url = add_query_arg($request,$url); } return $url; }
function Ecart () { if (WP_DEBUG) { $this->_debug = new StdClass(); if (function_exists('memory_get_peak_usage')) $this->_debug->memory = memory_get_peak_usage(true); if (function_exists('memory_get_usage')) $this->_debug->memory = memory_get_usage(true); } // Determine system and URI paths $this->path = sanitize_path(dirname(__FILE__)); $this->file = basename(__FILE__); $this->directory = basename($this->path); $languages_path = array($this->directory,'lang'); load_plugin_textdomain('Ecart',false,sanitize_path(join('/',$languages_path))); $this->uri = get_template_directory_uri()."/core/".$this->directory; $this->siteurl = get_bloginfo('url'); $this->wpadminurl = admin_url(); if ($this->secure = is_ecart_secure()) { $this->uri = str_replace('http://','https://',$this->uri); $this->siteurl = str_replace('http://','https://',$this->siteurl); $this->wpadminurl = str_replace('http://','https://',$this->wpadminurl); } // Initialize settings & macros $this->Settings = new Settings(); if (!defined('BR')) define('BR','<br />'); // Overrideable macros if (!defined('ECART_NOSSL')) define('ECART_NOSSL',false); if (!defined('ECART_PREPAYMENT_DOWNLOADS')) define('ECART_PREPAYMENT_DOWNLOADS',false); if (!defined('ECART_SESSION_TIMEOUT')) define('ECART_SESSION_TIMEOUT',7200); if (!defined('ECART_QUERY_DEBUG')) define('ECART_QUERY_DEBUG',false); if (!defined('ECART_GATEWAY_TIMEOUT')) define('ECART_GATEWAY_TIMEOUT',10); if (!defined('ECART_SHIPPING_TIMEOUT')) define('ECART_SHIPPING_TIMEOUT',10); if (!defined('ECART_TEMP_PATH')) define('ECART_TEMP_PATH',sys_get_temp_dir()); // Settings & Paths define("ECART_DEBUG",($this->Settings->get('error_logging') == 2048)); define("ECART_PATH",$this->path); define("ECART_PLUGINURI",$this->uri); define("ECART_PLUGINFILE",$this->directory."/".$this->file); define("ECART_ADMIN_DIR","/core/ui"); define("ECART_ADMIN_PATH",ECART_PATH.ECART_ADMIN_DIR); define("ECART_ADMIN_URI",ECART_PLUGINURI.ECART_ADMIN_DIR); define("ECART_FLOW_PATH",ECART_PATH."/core/flow"); define("ECART_MODEL_PATH",ECART_PATH."/core/model"); define("ECART_GATEWAYS",ECART_PATH."/gateways"); define("ECART_SHIPPING",ECART_PATH."/shipping"); define("ECART_STORAGE",ECART_PATH."/storage"); define("ECART_DBSCHEMA",ECART_MODEL_PATH."/schema.sql"); define("ECART_TEMPLATES",($this->Settings->get('theme_templates') != "off" && is_dir(sanitize_path(get_stylesheet_directory().'/ecart')))? sanitize_path(get_stylesheet_directory().'/ecart'): ECART_PATH.'/'."templates"); define("ECART_TEMPLATES_URI",($this->Settings->get('theme_templates') != "off" && is_dir(sanitize_path(get_stylesheet_directory().'/ecart')))? sanitize_path(get_bloginfo('stylesheet_directory')."/ecart"): ECART_PLUGINURI."/templates"); define("ECART_PRETTYURLS",(get_option('permalink_structure') == "")?false:true); define("ECART_PERMALINKS",ECART_PRETTYURLS); // Deprecated // Initialize application control processing $this->Flow = new Flow(); $this->Shopping = new Shopping(); add_action('init', array(&$this,'init')); // Plugin management add_action('after_plugin_row_'.ECART_PLUGINFILE, array(&$this, 'status'),10,2); add_action('install_plugins_pre_plugin-information', array(&$this, 'changelog')); add_action('ecart_check_updates', array(&$this, 'updates')); add_action('ecart_init',array(&$this, 'loaded')); // Theme integration add_action('widgets_init', array(&$this, 'widgets')); add_filter('wp_list_pages',array(&$this,'secure_links')); add_filter('rewrite_rules_array',array(&$this,'rewrites')); add_action('admin_head-options-reading.php',array(&$this,'pages_index')); add_action('generate_rewrite_rules',array(&$this,'pages_index')); add_action('save_post', array(&$this, 'pages_index'),10,2); add_action('ecart_reindex_pages', array(&$this, 'pages_index')); add_filter('query_vars', array(&$this,'queryvars')); if (!wp_next_scheduled('ecart_check_updates')) wp_schedule_event(time(),'twicedaily','ecart_check_updates'); }