diff --git a/classes/integrations/shareyourcart/class-shareyourcart-woocommerce-extended.php b/classes/integrations/shareyourcart/class-shareyourcart-woocommerce-extended.php
new file mode 100644
index 00000000000..df5c6ec6aa6
--- /dev/null
+++ b/classes/integrations/shareyourcart/class-shareyourcart-woocommerce-extended.php
@@ -0,0 +1,78 @@
+settings = $settings;
+ $this->SDK_ANALYTICS = false; //disable analytics for the woocommerce integration
+
+ parent::__construct();
+ }
+
+ public function isCartActive() {
+ return true; //since this class has loaded, the WooCommerce plugin is active
+ }
+
+ public function getSecretKey() {
+ return '2cfd496d-7812-44ba-91ce-e43c59f6c680';
+ }
+
+ public function showAdminMenu() {
+ //since we have allready integrated this in our own settings page,
+ //leave this function empty
+ }
+
+ /**
+ *
+ * Set the field value
+ *
+ */
+ protected function setConfigValue($field, $value) {
+
+ $this->settings[$field] = $value;
+
+ //make sure to update the enabled field as well, based on the account_status
+ switch($field){
+ case 'account_status':
+ $this->settings['enabled'] = ( $value == 'active' ? 'yes' : 'no' );
+ break;
+ case "plugin_current_version":
+ //this setting needs to be set globaly as well, in order to be recognized by other ShareYourCart integrations,
+ //and to not interfear with one-another
+ parent::setConfigValue($field, $value);
+ break;
+ }
+
+ //save the config in the DB
+ update_option( 'woocommerce_shareyourcart_settings', $this->settings );
+ }
+
+ /**
+ *
+ * Get the field value
+ *
+ */
+ protected function getConfigValue( $field ) {
+
+ $value = ( isset( $this->settings[$field] ) ) ? $this->settings[$field] : '';
+
+ //search for the global value of this field
+ //as it might have been changed by an external ShareYourCart integration
+ if($field == "plugin_current_version"){
+ $val = parent::getConfigValue($field);
+
+ if(!empty($val)) $value = $val;
+ }
+
+ return $value;
+ }
+}
\ No newline at end of file
diff --git a/classes/integrations/shareyourcart/class-shareyourcart-woocommerce.php b/classes/integrations/shareyourcart/class-shareyourcart-woocommerce.php
deleted file mode 100755
index a7739d3463b..00000000000
--- a/classes/integrations/shareyourcart/class-shareyourcart-woocommerce.php
+++ /dev/null
@@ -1,386 +0,0 @@
-settings = $settings;
-
- parent::__construct();
-
- //if there is installed another plugin with a never version
- //do not load this one further
- if (!$this->canLoad()) return;
-
- // Shortcodes
- add_shortcode( 'shareyourcart', array(&$this, 'getButton') );
- add_shortcode( 'shareyourcart_button', array(&$this, 'getButton') );
-
- // Actions
- add_action( 'init', array(&$this, 'init') );
- add_action( 'wp', array(&$this, 'hook_buttons') );
- add_action( 'wp_head', array(&$this, 'wp_head') );
- }
-
- function admin_settings_page() {
- $this->checkSDKStatus(true);
- }
-
- /**
- * processInit function.
- *
- * @access public
- */
- public function init() {
- if (isset($_REQUEST['action'])) {
- switch ($_REQUEST['action']) {
- case $this->_plugin_name:
- $this->buttonCallback();
- break;
-
- case $this->_plugin_name . '_coupon':
- $this->couponCallback();
- break;
- }
- }
- }
-
- /**
- * hook_buttons function.
- *
- * @access public
- */
- public function hook_buttons() {
- if ( $this->isSingleProduct() )
- add_filter('woocommerce_product_description_heading', array(&$this, '_getProductButton'));
-
- add_action('woocommerce_cart_coupon', array(&$this, '_getCartButton'));
- }
-
- public function wp_head() {
- echo '';
- }
-
- public function _getProductButton( $title ) {
- $title .= $this->getProductButton();
- return $title;
- }
-
- public function _getCartButton() {
- echo '
' . $this->getCartButton() . '
';
- }
-
- public function getSecretKey() {
- return '2cfd496d-7812-44ba-91ce-e43c59f6c680';
- }
-
- public function isSingleProduct() {
- return is_singular('product');
- }
-
- public function saveCoupon( $token, $coupon_code, $coupon_value, $coupon_type ) {
-
- // Create coupon
- $post_id = $this->_saveCouponPost($coupon_code);
-
- // Set coupon meta
- switch ($coupon_type) {
- case 'amount':
- $discount_type = 'fixed_product';
- $free_shipping = 'no';
- break;
- case 'percent':
- $discount_type = 'percent_product';
- $free_shipping = 'no';
- break;
- case 'free_shipping':
- $discount_type = 'fixed_product';
- $coupon_value = 0;
- $free_shipping = 'yes';
- break;
- default :
- $discount_type = 'fixed_cart';
- $free_shipping = 'no';
- }
-
- update_post_meta( $post_id, 'customer_email', array() );
- update_post_meta( $post_id, 'minimum_amount', '' );
- update_post_meta( $post_id, 'exclude_product_categories', array() );
- update_post_meta( $post_id, 'product_categories', array() );
- update_post_meta( $post_id, 'free_shipping', $free_shipping );
- update_post_meta( $post_id, 'apply_before_tax', 'yes' );
- update_post_meta( $post_id, 'expiry_date', '' );
- update_post_meta( $post_id, 'usage_limit', 1 );
- update_post_meta( $post_id, 'exclude_product_ids', '' );
- update_post_meta( $post_id, 'product_ids', '' );
- update_post_meta( $post_id, 'individual_use', 'yes' );
- update_post_meta( $post_id, 'coupon_amount', $coupon_value );
- update_post_meta( $post_id, 'discount_type', $discount_type );
-
- // parent
- parent::saveCoupon( $token, $coupon_code, $coupon_value, $coupon_type );
- }
-
- public function applyCoupon( $coupon_code ) {}
-
- private function _saveCouponPost($coupon_code) {
- $new_post = array(
- 'post_title' => $coupon_code,
- 'post_name' => sanitize_title( $coupon_code ),
- 'post_content' => '',
- 'post_status' => 'publish',
- 'comment_status'=> 'closed',
- 'ping_status' => 'closed',
- 'post_author' => $this->_post_user_id,
- 'post_type' => 'shop_coupon'
- );
-
- $post_id = wp_insert_post($new_post);
-
- return $post_id;
- }
-
- public function getButtonCallbackURL() {
- global $wp_query;
-
- $callback_url = add_query_arg( 'action', $this->_plugin_name, trailingslashit( home_url() ) );
-
- if ($this->isSingleProduct()) {
- $callback_url .= '&p='. $wp_query->post->ID;
- }
-
- return $callback_url;
- }
-
- public function buttonCallback() {
- global $woocommerce;
-
- //specify the parameters
- $params = array(
- 'callback_url' => get_bloginfo('wpurl').'/?action='.$this->_plugin_name.'_coupon'.(isset($_REQUEST['p']) ? '&p='.$_REQUEST['p'] : '' ),
- 'success_url' => get_option('shopping_cart_url'),
- 'cancel_url' => get_option('shopping_cart_url'),
- );
-
- //there is no product set, thus send the products from the shopping cart
- if (!isset($_REQUEST['p'])) {
- if ( sizeof( $woocommerce->cart->get_cart() ) == 0 )
- exit("Cart is empty");
-
- foreach ($woocommerce->cart->get_cart() as $cart_details) {
- $params['cart'][] = $this->_getProductDetails($cart_details['product_id']);
- }
- }
- else {
- $params['cart'][] = $this->_getProductDetails($_GET['p']);
- }
-
- try
- {
- $this->startSession($params);
- }
- catch(Exception $e) {
- //display the error to the user
- echo $e->getMessage();
- }
- exit;
- }
-
- private function _getProductDetails($product_id) {
- $product = new WC_Product($product_id);
-
- ob_start();
-
- echo $product->get_image();
-
- $image = ob_get_clean();
-
- return array(
- "item_name" => $product->get_title(),
- "item_description" => $product->post->post_content,
- "item_url" => $product->post->guid,
- "item_price" => $product->price,
- "item_picture_url" => $image,
- );
- }
-
- public function loadSessionData() {
- return;
- }
-
- /**
- *
- * Get the plugin version.
- * @return an integer
- *
- */
- protected function getPluginVersion() {
-
- return self::$_VERSION;
- }
-
- /**
- *
- * Return the project's URL
- *
- */
- protected function getDomain() {
-
- return get_bloginfo('url');
- }
-
- /**
- *
- * Return the admin's email
- *
- */
- protected function getAdminEmail() {
-
- return get_settings('admin_email');
- }
-
- /**
- *
- * Set the field value
- *
- */
- public function setConfigValue($field, $value) {
- $this->settings[$field] = $value;
- update_option( 'woocommerce_shareyourcart_settings', $this->settings );
- }
-
- /**
- *
- * Get the field value
- *
- */
- protected function getConfigValue( $field ) {
-
- switch ( $field ) {
- case "clientId" :
- return $this->settings['client_id'];
- case "hide_on_checkout" :
- return ( $this->settings['show_on_cart'] == 'yes' ) ? false : true;
- case "hide_on_product" :
- return ( $this->settings['show_on_product'] == 'yes' ) ? false : true;
- case "appKey" :
- return $this->settings['app_key'];
- case "account_status" :
- return 'active';
- case "button_type" :
-
- if ( $this->settings['button_style'] == 'image_button' ) return 2;
- if ( $this->settings['button_style'] == 'custom_html' ) return 3;
-
- return 1; // Standard
-
- break;
- default :
- return ( isset( $this->settings[$field] ) ) ? $this->settings[$field] : '';
- }
-
- }
-
- /**
- *
- * Execute the SQL statement
- *
- */
- protected function executeNonQuery($sql) {
-
- if (substr($sql, 0, 12) == "CREATE TABLE") {
-
- require_once ABSPATH . 'wp-admin/includes/upgrade.php';
-
- //if this is a create table command, use the special function which compares tables
- dbDelta($sql);
-
- } else {
-
- global $wpdb;
-
- //use the normal query
- $wpdb->query($sql);
- }
- }
-
- /**
- *
- * Get the row returned from the SQL
- *
- * @return an associative array containing the data of the row OR NULL
- * if there is none
- */
- protected function getRow($sql) {
-
- global $wpdb;
-
- //get the row as an associative array
- return $wpdb->get_row($sql, ARRAY_A);
- }
-
- /**
- *
- * Get the table name based on the key
- *
- */
- protected function getTableName($key) {
- global $wpdb;
-
- return $wpdb->base_prefix . $key;
- }
-
- /**
- *
- * Insert the row into the specified table
- *
- */
- protected function insertRow($tableName, $data) {
- global $wpdb;
-
- $wpdb->insert($tableName, $data);
- }
-
- /**
- *
- * Create url for the specified file. The file must be specified in relative path
- * to the base of the plugin
- */
- protected function createUrl($file) {
- //get the real file path
- $file = realpath($file);
-
- //calculate the relative path from this file
- $file = SyC::relativepath(dirname(__FILE__), $file);
-
- //append the relative path to the current file's URL
- return WP_PLUGIN_URL.'/'.str_replace(basename( __FILE__), "", plugin_basename(__FILE__)).$file;
- }
-
- /*
- *
- * Called when a new coupon is generated
- *
- */
- public function couponCallback() {
-
- parent::couponCallback();
-
- //since this is actually an API, exit
- exit;
- }
-
-}
\ No newline at end of file
diff --git a/classes/integrations/shareyourcart/class-wc-shareyourcart.php b/classes/integrations/shareyourcart/class-wc-shareyourcart.php
index aecb313a1ed..a4eaf32cc90 100644
--- a/classes/integrations/shareyourcart/class-wc-shareyourcart.php
+++ b/classes/integrations/shareyourcart/class-wc-shareyourcart.php
@@ -1,177 +1,85 @@
id = 'shareyourcart';
$this->method_title = __( 'ShareYourCart', 'woocommerce' );
- $this->method_description = sprintf( __( 'Increase your social media exposure by 10 percent! ShareYourCart helps you get more customers by motivating satisfied customers to talk with their friends about your products. For help with ShareYourCart view the documentation.', 'woocommerce' ), 'http://www.woothemes.com/woocommerce-docs/user-guide/shareyourcart/' );
-
- // Load the form fields.
- $this->init_form_fields();
-
+ $this->method_description = sprintf( __( 'Increase your social media exposure by 10 percent! ShareYourCart helps you get more customers by motivating satisfied customers to talk with their friends about your products. For help with ShareYourCart view the documentation.', 'woocommerce' ), 'http://www.woothemes.com/woocommerce-docs/user-guide/shareyourcart/' );
+
// Load the settings.
- $this->init_settings();
-
- // Define user set variables
- $this->enabled = $this->settings['enabled'];
- $this->client_id = $this->settings['client_id'];
- $this->app_key = $this->settings['app_key'];
- $this->email = $this->settings['email'];
-
- // Actions
- add_action( 'woocommerce_update_options_integration_shareyourcart', array( &$this, 'process_admin_options') );
+ $this->settings = ( array ) get_option( $this->plugin_id . $this->id . '_settings' ); //do not rely on the base implementation of init_settings
+
+ //the classes need to be initialized
+ $this->init_share_your_cart();
+
+ //hook to the admin settings page
add_action( 'woocommerce_update_options_integration_shareyourcart', array( &$this, 'process_forms') );
-
- // Actions if enabled
- if ( $this->enabled == 'yes' ) {
- add_action( 'wp_enqueue_scripts', array(&$this, 'styles') );
-
- $this->init_share_your_cart();
- }
- }
+ }
/**
* styles function.
- *
+ *
* @access public
* @return void
*/
public function styles() {
wp_enqueue_style( 'shareyourcart', plugins_url( 'css/style.css', __FILE__ ) );
}
-
+
/**
* init_share_your_cart function.
- *
+ *
* @access public
* @return void
*/
function init_share_your_cart() {
-
+
if ( empty( $this->shareYourCartWooCommerce ) ) {
// Share your cart api class
- include_once('class-shareyourcart-woocommerce.php');
-
+ include_once('class-shareyourcart-woocommerce-extended.php');
+
// Init the class
- $this->shareYourCartWooCommerce = new ShareYourCartWooCommerce( $this->settings );
+ $this->shareYourCartWooCommerce = new ShareYourCartWooCommerceEx( $this->settings );
+
+ //by the time we get here, the plugins_loaded hook has allready been called
+ //so call the method manually
+ $this->shareYourCartWooCommerce->pluginsLoadedHook();
}
-
+
}
-
+
/**
- * process_forms function.
- *
+ * process_forms function.
+ *
* @access public
*/
function process_forms() {
-
- if ( ! empty( $_REQUEST['syc-account'] ) && $_REQUEST['syc-account'] == 'create' ) {
-
- $this->init_share_your_cart();
-
- $error = $message = '';
-
- $redirect = remove_query_arg( 'saved' );
- $redirect = remove_query_arg( 'wc_error', $redirect );
- $redirect = remove_query_arg( 'wc_message', $redirect );
-
- if ( ! empty( $_POST['domain'] ) && ! empty( $_POST['email'] ) && ! empty( $_POST['syc-terms-agreement'] ) ) {
- if ( ! ( ( $register = $this->shareYourCartWooCommerce->register( $this->shareYourCartWooCommerce->getSecretKey(), $_POST['domain'], $_POST['email'], $message ) ) === false) ) {
-
- $this->shareYourCartWooCommerce->setConfigValue('app_key', $register['app_key']);
- $this->shareYourCartWooCommerce->setConfigValue('client_id', $register['client_id']);
-
- $redirect = remove_query_arg( 'syc-account', $redirect );
- } else {
-
- $error = $message;
-
- if ( json_decode($error) ) {
- $error = json_decode($error);
- $error = $error->message;
- }
-
- $message = '';
-
- }
-
- } else {
-
- $error = __( 'Please complete all fields.', 'woocommerce' );
-
- }
-
- if ( $error ) $redirect = add_query_arg( 'wc_error', urlencode( esc_attr( $error ) ), $redirect );
- if ( $message ) $redirect = add_query_arg( 'wc_message', urlencode( esc_attr( $message ) ), $redirect );
-
- wp_safe_redirect( $redirect );
- exit;
-
- } elseif ( ! empty( $_REQUEST['syc-account'] ) && $_REQUEST['syc-account'] == 'recover' ) {
-
- $this->init_share_your_cart();
-
- $error = $message = '';
-
- $redirect = remove_query_arg( 'saved' );
- $redirect = remove_query_arg( 'wc_error', $redirect );
- $redirect = remove_query_arg( 'wc_message', $redirect );
-
- if ( ! empty( $_POST['domain'] ) && ! empty( $_POST['email'] ) ) {
-
- if ( ! $this->shareYourCartWooCommerce->recover( $this->shareYourCartWooCommerce->getSecretKey(), $_POST['domain'], $_POST['email'], $message ) ) {
-
- $error = $message;
-
- if ( json_decode($error) ) {
- $error = json_decode($error);
- $error = $error->message;
- }
-
- $message = '';
-
- } else {
- $redirect = remove_query_arg( 'syc-account', $redirect );
- }
-
- } else {
-
- $error = __( 'Please complete all fields.', 'woocommerce' );
-
- }
-
- if ( $error ) $redirect = add_query_arg( 'wc_error', urlencode( esc_attr( $error ) ), $redirect );
- if ( $message ) $redirect = add_query_arg( 'wc_message', urlencode( esc_attr( $message ) ), $redirect );
-
- wp_safe_redirect( $redirect );
- exit;
-
- }
-
+
+ //after this function completes, WooCommerce will refresh the page, so we need to save the data here
+
+ //stripslashes from button_html
+ if(isset($_POST['button_html']))
+ $_POST['button_html'] = stripslashes($_POST['button_html']);
+
+ //TODO: investigate why the files are not being uploaded
+
+ $this->shareYourCartWooCommerce->getAdminPage($this); //get the admin page ( so that the data is processed, but do not show it )
+ $this->shareYourCartWooCommerce->getButtonCustomizationPage(); //get the customization page ( so that the data is processed, but do not show it )
}
-
+
/**
* Admin Options
*
@@ -181,226 +89,25 @@ class WC_ShareYourCart extends WC_Integration {
* @since 1.0.0
*/
function admin_options() {
-
- if ( $this->enabled == 'yes' ) {
- // Installation
+
+ if ( $this->shareYourCartWooCommerce->isActive() ) {
+
+ // call this manually ( to determine if there needs to be a table update, or not )
$this->shareYourCartWooCommerce->install();
-
- // Check status
- $this->shareYourCartWooCommerce->admin_settings_page();
}
- ?>
-
- client_id && ! $this->app_key ) {
-
- if ( ! empty( $_REQUEST['syc-account'] ) && $_REQUEST['syc-account'] == 'create' ) {
-
- ?>
-
-
-
-
-
-
- form_fields = array(
- 'enabled' => array(
- 'title' => __( 'Enable/Disable', 'woocommerce' ),
- 'label' => __( 'Enable ShareYourCart integration', 'woocommerce' ),
- 'type' => 'checkbox',
- 'default' => 'no',
- ),
- 'client_id' => array(
- 'title' => __( 'Client ID', 'woocommerce' ),
- 'description' => __( 'Get your client ID by creating a ShareYourCart account.', 'woocommerce' ),
- 'type' => 'text',
- 'default' => '',
- 'css' => 'width: 300px'
- ),
- 'app_key' => array(
- 'title' => __( 'App Key', 'woocommerce' ),
- 'description' => __( 'Get your app key by creating a ShareYourCart account.', 'woocommerce' ),
- 'type' => 'text',
- 'default' => '',
- 'css' => 'width: 300px'
- ),
- 'email' => array(
- 'title' => __( 'Email address', 'woocommerce' ),
- 'description' => __( 'The email address you used to sign up for ShareYourCart.', 'woocommerce' ),
- 'type' => 'text',
- 'default' => get_option('admin_email'),
- 'css' => 'width: 300px'
- ),
- 'show_on_product' => array(
- 'title' => __( 'Show button by default on:', 'woocommerce' ),
- 'label' => __( 'Product page', 'woocommerce' ),
- 'type' => 'checkbox',
- 'default' => 'yes',
- ),
- 'show_on_cart' => array(
- 'label' => __( 'Cart page', 'woocommerce' ),
- 'type' => 'checkbox',
- 'default' => 'yes',
- ),
- 'button_style' => array(
- 'title' => __( 'Button style', 'woocommerce' ),
- 'description' => __( 'Select a style for your share buttons', 'woocommerce' ),
- 'default' => 'standard_button',
- 'type' => 'select',
- 'options' => array(
- 'standard_button' => __( 'Standard Button', 'woocommerce' ),
- 'custom_html' => __( 'Custom HTML', 'woocommerce' )
- )
- ),
- 'button_skin' => array(
- 'title' => __( 'Button skin', 'woocommerce' ),
- 'description' => __( 'Select a skin for your share buttons', 'woocommerce' ),
- 'default' => 'orange',
- 'type' => 'select',
- 'options' => array(
- 'orange' => __( 'Orange', 'woocommerce' ),
- 'blue' => __( 'Blue', 'woocommerce' ),
- 'light' => __( 'Light', 'woocommerce' ),
- 'dark' => __( 'Dark', 'woocommerce' )
- ),
- 'class' => 'standard_button'
- ),
- 'button_position' => array(
- 'title' => __( 'Button position', 'woocommerce' ),
- 'description' => __( 'Where should the button be positioned?', 'woocommerce' ),
- 'default' => 'normal',
- 'type' => 'select',
- 'options' => array(
- 'normal' => __( 'Normal', 'woocommerce' ),
- 'floating' => __( 'Floating', 'woocommerce' )
- ),
- 'class' => 'standard_button'
- ),
- 'button_html' => array(
- 'title' => __( 'HTML for the button', 'woocommerce' ),
- 'description' => __( 'Enter the HTML code for your custom button.', 'woocommerce' ),
- 'default' => '',
- 'type' => 'textarea',
- 'class' => 'custom_html'
- )
- );
-
- } // End init_form_fields()
-
+
+ $this->shareYourCartWooCommerce->showAdminHeader();
+ $this->shareYourCartWooCommerce->showAdminPage($this,true,false); //send this obj to the view, but do not show the footer
+ $this->shareYourCartWooCommerce->showButtonCustomizationPage(null,false,false); //do not show neither the header, nor the footer of this page
+ }
}
-
/**
* Add the integration to WooCommerce
- *
- * @package WooCommerce/Classes/Integrations
- * @access public
- * @param mixed $integrations
- * @return void
- */
+ **/
function add_shareyourcart_integration( $integrations ) {
if ( ! class_exists('ShareYourCartAPI') ) // Only allow this integration if we're not already using shareyourcart via another plugin
- $integrations[] = 'WC_ShareYourCart';
+ $integrations[] = 'WC_ShareYourCart';
return $integrations;
}
add_filter('woocommerce_integrations', 'add_shareyourcart_integration' );
diff --git a/classes/integrations/shareyourcart/class.shareyourcart-wp-woocommerce.php b/classes/integrations/shareyourcart/class.shareyourcart-wp-woocommerce.php
new file mode 100644
index 00000000000..d9b3ae4b1a6
--- /dev/null
+++ b/classes/integrations/shareyourcart/class.shareyourcart-wp-woocommerce.php
@@ -0,0 +1,245 @@
+_plugin_name:
+ $this->buttonCallback();
+ break;
+
+ case $this->_plugin_name.'_coupon':
+ $this->couponCallback();
+ break;
+ }
+ }
+ }
+
+ public function isCartActive() {
+ return in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) );
+ }
+
+ /*
+ *
+ * Extend the base class implementation
+ *
+ */
+ public function pluginsLoadedHook() {
+ parent::pluginsLoadedHook();
+
+ if(!$this->isCartActive()) return;
+
+ add_action('init', array(&$this, 'processInit'));
+
+ add_action('woocommerce_before_single_product', array(&$this,'showProductButton'));
+ add_action('woocommerce_cart_contents', array(&$this,'showCartButton'));
+ }
+
+ /**
+ *
+ * Return the jQuery sibling selector for the product button
+ *
+ */
+ protected function getProductButtonPosition(){
+ $selector = parent::getProductButtonPosition();
+ return (!empty($selector) ? $selector : ".summary .price .amount");
+ }
+
+ /**
+ *
+ * Return the jQuery sibling selector for the cart button
+ *
+ */
+ protected function getCartButtonPosition(){
+ $selector = parent::getCartButtonPosition();
+ return (!empty($selector) ? $selector : ".cart-subtotal .amount");
+ }
+
+ public function getSecretKey() {
+ return 'd3ce6c18-7e45-495d-aa4c-8f63edee03a5';
+ }
+
+ public function isSingleProduct() {
+ return is_singular('product');
+ }
+
+ protected function saveCoupon($token, $coupon_code, $coupon_value, $coupon_type, $product_unique_ids = array()) {
+
+ // Create coupon
+ $post_id = $this->_saveCouponPost($coupon_code);
+
+ // Set coupon meta
+ switch ($coupon_type) {
+ case 'amount':
+ $discount_type = 'fixed_product';
+ $free_shipping = 'no';
+ break;
+ case 'percent':
+ $discount_type = 'percent_product';
+ $free_shipping = 'no';
+ break;
+ case 'free_shipping':
+ $discount_type = 'fixed_product';
+ $coupon_value = 0;
+ $free_shipping = 'yes';
+ break;
+ default :
+ $discount_type = 'fixed_cart';
+ $free_shipping = 'no';
+ }
+
+ update_post_meta( $post_id, 'customer_email', array() );
+ update_post_meta( $post_id, 'minimum_amount', '' );
+ update_post_meta( $post_id, 'exclude_product_categories', array() );
+ update_post_meta( $post_id, 'product_categories', array() );
+ update_post_meta( $post_id, 'free_shipping', $free_shipping );
+ update_post_meta( $post_id, 'apply_before_tax', 'yes' );
+ update_post_meta( $post_id, 'expiry_date', '' );
+ update_post_meta( $post_id, 'usage_limit', 1 );
+ update_post_meta( $post_id, 'exclude_product_ids', '' );
+ update_post_meta( $post_id, 'product_ids', '' );
+ update_post_meta( $post_id, 'individual_use', 'yes' );
+ update_post_meta( $post_id, 'coupon_amount', $coupon_value );
+ update_post_meta( $post_id, 'discount_type', $discount_type );
+
+ // parent
+ parent::saveCoupon( $token, $coupon_code, $coupon_value, $coupon_type );
+ }
+
+ public function applyCoupon($coupon_code) {
+ //$this->_loadWooCommerce();
+
+ //global $woocommerce;
+ //$woocommerce->cart->add_discount($coupon_code);
+
+ return;
+ }
+
+ private function _saveCouponPost($coupon_code){
+ $new_post = array(
+ 'post_title' => $coupon_code,
+ 'post_name' => ereg_replace("[^A-Za-z0-9]", "", $coupon_code),
+ 'post_content' => '',
+ 'post_status' => 'publish',
+ 'comment_status'=> 'closed',
+ 'ping_status' => 'closed',
+ 'post_author' => $this->_post_user_id,
+ 'post_type' => 'shop_coupon'
+ );
+
+ $post_id = wp_insert_post($new_post);
+
+ return $post_id;
+ }
+
+ public function getButtonCallbackURL() {
+ global $wp_query;
+
+ $callback_url = add_query_arg( 'action', $this->_plugin_name, trailingslashit( home_url() ) );
+
+ if ($this->isSingleProduct()) {
+ $callback_url .= '&p='. $wp_query->post->ID;
+ }
+
+ return $callback_url;
+ }
+
+ public function buttonCallback(){
+ if(!$this->isCartActive()) return;
+
+ $this->_loadWooCommerce();
+
+ //specify the parameters
+ $params = array(
+ 'callback_url' => get_bloginfo('wpurl').'/?action='.$this->_plugin_name.'_coupon'.(isset($_REQUEST['p']) ? '&p='.$_REQUEST['p'] : '' ),
+ 'success_url' => get_option('shopping_cart_url'),
+ 'cancel_url' => get_option('shopping_cart_url'),
+ );
+
+ //there is no product set, thus send the products from the shopping cart
+ if(!isset($_REQUEST['p']))
+ {
+ if(empty($_SESSION['cart']))
+ exit("Cart is empty");
+
+ foreach($_SESSION['cart'] as $cart_details){
+ $params['cart'][] = $this->_getProductDetails($cart_details['product_id']);
+ }
+ }
+ else
+ {
+ $params['cart'][] = $this->_getProductDetails($_REQUEST['p']);
+ }
+
+ try
+ {
+ $this->startSession($params);
+ }
+ catch(Exception $e)
+ {
+ //display the error to the user
+ echo $e->getMessage();
+ }
+ exit;
+ }
+
+ private function _getProductDetails($product_id){
+ $product = new WC_Product($product_id);
+
+ //WooCommerce actually echoes the image
+ ob_start();
+ echo $product->get_image(); //older WooCommerce versions might allready echo, but newer versions don't, so force it anyway
+ $image = ob_get_clean();
+
+ //check is image actually a HTML img entity
+ if(($doc = @DomDocument::loadHTML($image)) !== FALSE)
+ {
+ $imageTags = $doc->getElementsByTagName('img');
+ if($imageTags->length >0 )
+ $src = $imageTags->item(0)->getAttribute('src');
+
+ //replace image only if src has been set
+ if (!empty($src))
+ $image = $src;
+ }
+
+ return array(
+ "item_name" => $product->get_title(),
+ "item_description" => $product->post->post_excerpt,
+ "item_url" => get_permalink($product_id),
+ "item_price" => $product->price,
+ "item_picture_url" => $image,
+ );
+ }
+
+ public function loadSessionData() {
+ return;
+ }
+
+ private function _loadWooCommerce(){
+ // Sometimes the WooCommerce Class is not loaded...
+
+ if(!class_exists('Woocommerce', false)){
+ require_once(ABSPATH . 'wp-content/plugins/woocommerce/woocommerce.php');
+ }
+
+ // Important Classes Not included
+ if(!function_exists('has_post_thumbnail')){
+ require_once(ABSPATH . 'wp-includes/post-thumbnail-template.php');
+ }
+ }
+}
+
+
+//TODO: see why this is not used
+add_action(ShareYourCartWordpressPlugin::getPluginFile(), array('ShareYourCartWooCommerce','uninstallHook'));
+
+} //END IF
\ No newline at end of file
diff --git a/classes/integrations/shareyourcart/class.shareyourcart-wp.php b/classes/integrations/shareyourcart/class.shareyourcart-wp.php
new file mode 100644
index 00000000000..e341981a702
--- /dev/null
+++ b/classes/integrations/shareyourcart/class.shareyourcart-wp.php
@@ -0,0 +1,382 @@
+canLoad()) return;
+
+ //make sure we add this instance
+ self::$_INSTANCES []= $this;
+ $this->_PLUGIN_PATH = WP_PLUGIN_URL.'/'.str_replace(basename( __FILE__),"",plugin_basename(__FILE__));
+
+ //setup the hooks
+ register_activation_hook(self::getPluginFile(), array(&$this,'activateHook'));
+ register_deactivation_hook(self::getPluginFile(), array(&$this,'deactivateHook'));
+
+ //perform the rest of the loading AFTER all plugins have been loaded
+ add_action('plugins_loaded', array(&$this,'pluginsLoadedHook'));
+ }
+
+ /**
+ * Abstract isCartActive
+ * @param null
+ * @return boolean
+ */
+ protected abstract function isCartActive();
+
+ /**
+ *
+ * Get the plugin version.
+ * @return an integer
+ *
+ */
+ protected function getPluginVersion(){
+
+ return self::$_VERSION;
+ }
+
+ /**
+ *
+ * Return the project's URL
+ *
+ */
+ protected function getDomain(){
+
+ return get_bloginfo('url');
+ }
+
+ /**
+ *
+ * Return the admin's email
+ *
+ */
+ protected function getAdminEmail(){
+
+ return get_settings('admin_email');
+ }
+
+ /**
+ *
+ * Set the field value
+ *
+ */
+ protected function setConfigValue($field,$value){
+ update_option('_shareyourcart_'.$field,$value);
+ }
+
+ /**
+ *
+ * Get the field value
+ *
+ */
+ protected function getConfigValue($field){
+ return get_option('_shareyourcart_'.$field);
+ }
+
+ /**
+ *
+ * Get the path to the main file of the plugin
+ *
+ */
+ public static function getPluginFile(){
+ global $plugin;
+
+ return $plugin;
+ }
+
+ /**
+ *
+ * Get the upload directory
+ *
+ */
+ public function getUploadDir(){
+ $dir = wp_upload_dir();
+
+ return (!empty($dir['path']) ? $dir['path'] : parent::getUploadDir());
+ }
+
+ /**
+ *
+ * Execute the SQL statement
+ *
+ */
+ protected function executeNonQuery($sql){
+
+ if(substr($sql,0,12) == "CREATE TABLE"){
+
+ require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
+
+ //if this is a create table command, use the special function which compares tables
+ dbDelta($sql);
+
+ } else {
+
+ global $wpdb;
+
+ //use the normal query
+ $wpdb->query($sql);
+ }
+ }
+
+ /**
+ *
+ * Get the row returned from the SQL
+ *
+ * @return an associative array containing the data of the row OR NULL
+ * if there is none
+ */
+ protected function getRow($sql){
+
+ global $wpdb;
+
+ //get the row as an associative array
+ return $wpdb->get_row($sql,ARRAY_A);
+ }
+
+ /**
+ *
+ * Get the table name based on the key
+ *
+ */
+ protected function getTableName($key){
+ global $wpdb;
+
+ return $wpdb->base_prefix.$key;
+ }
+
+ /**
+ *
+ * Insert the row into the specified table
+ *
+ */
+ protected function insertRow($tableName,$data){
+ global $wpdb;
+
+ $wpdb->insert($tableName,$data);
+ }
+
+ /**
+ *
+ * Create url for the specified file. The file must be specified in relative path
+ * to the base of the plugin
+ */
+ protected function createUrl($file){
+ //get the real file path
+ $file = realpath($file);
+
+ //calculate the relative path from this file
+ $file = SyC::relativepath(dirname(__FILE__),$file);
+
+ //append the relative path to the current file's URL
+ return WP_PLUGIN_URL.'/'.str_replace(basename( __FILE__),"",plugin_basename(__FILE__)).$file;
+ }
+
+ /**
+ *
+ * Part of the initialization process, this is used to check if the cart is
+ * really active
+ *
+ */
+ public function pluginsLoadedHook() {
+
+ //if the cart is not loaded, do not load this plugin further
+ if(!$this->isCartActive()) return;
+
+ add_action('wp_head', array(&$this,'showPageHeader'));
+ add_action('admin_menu', array(&$this,'showAdminMenu'));
+
+ //add the shortcodes ONLY if they where not added before, by another plugin
+ global $shortcode_tags;
+ if(!array_key_exists('shareyourcart',$shortcode_tags)){
+ add_shortcode('shareyourcart', array(&$this,'getButton'));
+ add_shortcode('shareyourcart_button', array(&$this,'getButton'));
+ }
+ }
+
+ /**
+ *
+ * This is the activate hook called by WordPress. It is used for both install and activate
+ *
+ */
+ public function activateHook() {
+
+ if(!$this->isCartActive()) return;
+
+ $message = '';
+
+ //the db version is old, so install it again
+ if(version_compare($this->getConfigValue('db_version'),self::$_DB_VERSION)!=0){
+
+ $this->install($message);
+ } else { //if the version are equal, simply activate the plugin
+
+ $this->activate($message);
+ }
+
+ //TODO: perhaps we can show the message somehow to the user. For now, just log it
+ error_log($message);
+ }
+
+ /**
+ *
+ * This is the deactivate hook called by WordPress.
+ *
+ */
+ public function deactivateHook() {
+
+ if(!$this->isCartActive()) return;
+
+ $message = '';
+
+ $this->deactivate($message);
+
+ //TODO: perhaps we can show the message somehow to the user. For now, just log it
+ error_log($message);
+ }
+
+ /**
+ *
+ * When installing the new wordpress plugin, make sure to move the old data
+ *
+ */
+ public function install(&$message = null) {
+
+ global $wpdb;
+
+ $old_table_name = $this->getTableName('shareyourcart_settings');
+ if($wpdb->get_var("show tables like '$old_table_name'") == $old_table_name) {
+
+ //get the old app_key and client_id
+ $settings = $wpdb->get_row("SELECT app_key, client_id FROM ".$wpdb->base_prefix."shareyourcart_settings LIMIT 1");
+ if($settings) {
+
+ $this->setConfigValue('appKey', $settings->app_key);
+ $this->setConfigValue('clientId', $settings->client_id);
+ }
+
+ //remove the old table
+ $wpdb->query("DROP TABLE $old_table_name");
+ }
+
+ parent::install($message);
+ }
+
+ /**
+ *
+ * This is the deactivate hook called by WordPress.
+ *
+ */
+ public static function uninstallHook() {
+
+ //this hook is required by WordPress to be static
+ //so call uninstall on the first instance
+ if(!empty(self::$_INSTANCES)){
+
+ self::$_INSTANCES[0]->uninstall();
+ } else {
+
+ //log the error
+ error_log("There is no instance created when calling uninstall hook");
+ }
+ }
+
+ /**
+ * show the admin menu
+ * @param null
+ * @return boolean
+ */
+ public function showAdminMenu() {
+
+ //this is a single call function
+ if(!$this->isFirstCall(__FUNCTION__)) return;
+
+ //first, check the SDK status
+ $this->checkSDKStatus();
+
+ //see if we need to show the update notification
+ $notification = null;
+ if($this->hasNewerVersion())
+ $notification = "" . number_format_i18n(1) . "";
+
+ $page = add_menu_page(
+ __('Share your cart settings'),
+ __('ShareYourCart').$notification,
+ 1,
+ basename(__FILE__),
+ array(&$this, 'showAdminPage'),
+ $this->_PLUGIN_PATH .'sdk/img/shareyourcart.png'
+ );
+ add_action( 'admin_head-'.$page, array(&$this, 'showAdminHeader'));
+
+ if($this->isActive())
+ {
+ //show the rest of the menu ONLY if the plugin is active
+ $page = add_submenu_page(
+ basename(__FILE__),
+ __('Button'),
+ __('Customize Button'),
+ 1,
+ basename(__FILE__).'-button',
+ array(&$this, 'showButtonCustomizationPage'));
+ add_action( 'admin_head-'. $page, array(&$this, 'showAdminHeader'));
+
+ $page = add_submenu_page(
+ basename(__FILE__),
+ __('Documentation'),
+ __('Documentation'),
+ 1,
+ basename(__FILE__).'-documentation',
+ array(&$this, 'showDocumentationPage'));
+ add_action( 'admin_head-'. $page, array(&$this, 'showAdminHeader'));
+ }
+ }
+
+ /*
+ *
+ * Called when a new coupon is generated
+ *
+ */
+ public function couponCallback(){
+
+ //since there are a lot of plugins for wordpress, first make sure this plugin
+ //is active
+ if(!$this->isCartActive()) {
+
+ throw new Exception(SyC::t('sdk','Shopping Cart is not active'));
+ }
+
+ parent::couponCallback();
+
+ //since this is actually an API, exit
+ exit;
+ }
+ }
+
+} //END IF
+?>
\ No newline at end of file
diff --git a/classes/integrations/shareyourcart/css/admin-style.css b/classes/integrations/shareyourcart/css/admin-style.css
new file mode 100644
index 00000000000..0e91440c005
--- /dev/null
+++ b/classes/integrations/shareyourcart/css/admin-style.css
@@ -0,0 +1,73 @@
+/*use our own save buttons, in order to determine what actions the user made*/
+p.submit .button-primary{
+ display:none
+}
+
+/* disable extra padding */
+.wrap {
+ padding: 0px;
+}
+
+.form-table th {
+ padding: 10px;
+ text-align: left;
+ vertical-align: top;
+ width: 200px;
+}
+
+.form-table td{
+ font-size: 12px;
+ line-height: 20px;
+ margin-bottom: 9px;
+ padding: 8px 10px;
+}
+
+.form-table a{
+ color: #21759B;
+ font-weight: normal;
+}
+
+.api-link {
+ color: #464646;
+ font-weight: normal;
+ text-decoration: none;
+}
+
+.api-status {
+ float: left;
+}
+
+.api-link:hover{
+ color: #d54e21;
+ font-weight: normal;
+}
+
+.syc-configuration {
+ width: 60%;
+}
+.configure-button-container {
+ width: auto;
+ margin: 0;
+}
+
+.buttonTextarea {
+ width: auto;
+ height: 120px;
+}
+
+.buttonOption {
+ height: 170px;
+ background-position: right -54px;
+}
+
+body .buttonCheckbox {
+ margin: 0 9px 0 0;
+}
+
+.buttonOptions {
+ border-bottom: 1px solid #ccc;
+}
+
+#visual-options>fieldset {
+ margin: 0 0 20px;
+}
\ No newline at end of file
diff --git a/classes/integrations/shareyourcart/sdk/class.shareyourcart-api.php b/classes/integrations/shareyourcart/sdk/class.shareyourcart-api.php
index 6666d311670..982b1fcef8c 100755
--- a/classes/integrations/shareyourcart/sdk/class.shareyourcart-api.php
+++ b/classes/integrations/shareyourcart/sdk/class.shareyourcart-api.php
@@ -9,8 +9,6 @@
* * Copyright (C) 2011 Barandi Solutions
*/
-if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
-
if(!class_exists('ShareYourCartAPI',false)){
class ShareYourCartAPI {
@@ -25,6 +23,7 @@ class ShareYourCartAPI {
protected $SHAREYOURCART_API_CREATE;
protected $SHAREYOURCART_API_VALIDATE;
protected $SHAREYOURCART_API_STATUS;
+ protected $SHAREYOURCART_API_TRANSLATION;
protected $SHAREYOURCART_CONFIGURE;
protected $SHAREYOURCART_BUTTON_JS;
protected $SHAREYOURCART_BUTTON_URL;
@@ -42,7 +41,7 @@ class ShareYourCartAPI {
if(method_exists ($this,'getSecretKey')){
$secretKey = $this->getSecretKey();
if(empty($secretKey)){
- throw new Exception("You must specify a valid secret key");
+ throw new Exception(SyC::t('sdk',"You must specify a valid secret key"));
}
//check if the secret key is a sandbox one
@@ -61,6 +60,7 @@ class ShareYourCartAPI {
$this->SHAREYOURCART_API_CREATE = $this->SHAREYOURCART_API.'/session/create';
$this->SHAREYOURCART_API_VALIDATE = $this->SHAREYOURCART_API.'/session/validate';
$this->SHAREYOURCART_API_STATUS = $this->SHAREYOURCART_API.'/sdk';
+ $this->SHAREYOURCART_API_TRANSLATION = $this->SHAREYOURCART_API.'/sdk/translation';
$this->SHAREYOURCART_CONFIGURE = $this->SHAREYOURCART_API.'/configure';
$this->SHAREYOURCART_BUTTON_JS = $this->SHAREYOURCART_API.'/js/'.($is_live ? 'button.js' : 'button_sandbox.js');
$this->SHAREYOURCART_BUTTON_URL = $this->SHAREYOURCART_API.'/button';
@@ -354,6 +354,41 @@ class ShareYourCartAPI {
// Decode the result
return json_decode($response, true);
}
+
+ /**
+ *
+ * Returns an array of messages for the SDK, in the specified language
+ *
+ */
+ public function getSDKTranslation($lang, &$message = null)
+ {
+ $params = array('lang' => $lang);
+
+ //make the API call
+ $session = curl_init($this->SHAREYOURCART_API_TRANSLATION);
+
+ // Tell curl to use HTTP POST
+ curl_setopt($session, CURLOPT_POST, true);
+ // Tell curl that this is the body of the POST
+ curl_setopt($session, CURLOPT_POSTFIELDS, http_build_query($params,'','&'));
+ // Tell curl not to return headers, but do return the response
+ curl_setopt($session, CURLOPT_HEADER, false);
+ curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
+
+ $response = curl_exec($session);
+ $httpCode = curl_getinfo($session, CURLINFO_HTTP_CODE);
+ curl_close($session);
+
+ // Notify the caller
+ if($httpCode != 200) {
+ if(isset($message)) $message = $response;
+
+ return false;
+ }
+
+ // Decode the result
+ return json_decode($response, true);
+ }
}
@@ -366,6 +401,7 @@ class SyC
{
static $_messages;
static $_language = 'en';
+ static $loadLanguage = array('SyC','loadFileLanguage'); //variable that holds the name of the function used to load a particular language
/**
*
@@ -379,6 +415,38 @@ class SyC
self::$_messages = null;
}
+ /**
+ *
+ * Get the language that is currently loaded
+ *
+ */
+ public static function getLanguage(){
+ return self::$_language;
+ }
+
+ /**
+ * Return the checksum of the currently loaded translation
+ */
+ public static function getLanguageChecksum($category = 'sdk')
+ {
+ //load the translation from file if not done so
+ if(!isset(self::$_messages)){
+
+ //load the language
+ self::$_messages = call_user_func(self::$loadLanguage,self::$_language,$category);
+ }
+
+ return md5(json_encode(self::$_messages));
+ }
+
+ /**
+ * Reload the language
+ */
+ public static function reloadLanguage()
+ {
+ self::$_messages = null;
+ }
+
/*
* Translate the specified message
*
@@ -388,16 +456,8 @@ class SyC
//load the translation from file if not done so
if(!isset(self::$_messages)){
- //The language is the folder name, and the category is the name of the file
- $messageFile = dirname(__FILE__).DIRECTORY_SEPARATOR.'messages'.DIRECTORY_SEPARATOR.self::$_language.DIRECTORY_SEPARATOR.$category.'.php';
-
- if(is_file($messageFile))
- {
- self::$_messages=include($messageFile);
- }
-
- //make sure we have an array for this variable
- if(!is_array(self::$_messages)) self::$_messages=array();
+ //load the language
+ self::$_messages = call_user_func(self::$loadLanguage,self::$_language,$category);
}
//check if the text has a valid translation
@@ -409,8 +469,46 @@ class SyC
return $params!==array() ? strtr($message,$params) : $message;
}
+ /**
+ *
+ * change the language loader method
+ *
+ */
+ public static function setLanguageLoader($loader)
+ {
+ //make sure the loader is ok
+ if(!is_callable($loader))
+ throw new Exception(SyC::t('sdk',"The language loader is not a valid callback"));
+
+ self::$loadLanguage = $loader;
+
+ //reset the old messages, so that they are reloaded with the new loader
+ self::$_messages = null;
+ }
- function relativepath($from, $to, $ps = '/' ,$ds = DIRECTORY_SEPARATOR)
+ /**
+ *
+ * Function to load a language from the hard-drive.
+ *
+ */
+ public static function loadFileLanguage($lang, $category)
+ {
+ //The language is the folder name, and the category is the name of the file
+ $messageFile = dirname(__FILE__).DIRECTORY_SEPARATOR.'messages'.DIRECTORY_SEPARATOR.$lang.DIRECTORY_SEPARATOR.$category.'.php';
+
+ $messages = null;
+ if(is_file($messageFile))
+ {
+ $messages=include($messageFile);
+ }
+
+ //make sure we have an array for this variable
+ if(!is_array($messages)) $messages=array();
+
+ return $messages;
+ }
+
+ public static function relativepath($from, $to, $ps = '/' ,$ds = DIRECTORY_SEPARATOR)
{
$arFrom = explode($ds, rtrim($from, $ds));
$arTo = explode($ds, rtrim($to, $ds));
@@ -428,7 +526,7 @@ class SyC
* @param string $src
* @return string
*/
- function rel2Abs($rel, $base) {
+ public static function rel2Abs($rel, $base) {
/* return if already absolute URL */
if (parse_url($rel, PHP_URL_SCHEME) != '')
@@ -467,7 +565,7 @@ class SyC
* @param string $src
* @return string
*/
- function htmlIndent($src) {
+ public static function htmlIndent($src) {
//replace all leading spaces with
//Attention: this will render wrong html if you split a tag on more lines!
@@ -475,6 +573,22 @@ class SyC
), $src);
}
+ /**
+ * returns TRUE if haystack starts with needle
+ */
+ public static function startsWith($haystack, $needle)
+ {
+ $length = strlen($needle);
+ return (substr($haystack, 0, $length) === $needle);
+ }
+
+ /**
+ * returns TRUE if haystack ends with needle
+ */
+ public static function endsWith($haystack, $needle)
+ {
+ return (substr($haystack, strlen($haystack) - strlen($needle)) === $needle);
+ }
}
} //END IF
diff --git a/classes/integrations/shareyourcart/sdk/class.shareyourcart-base.php b/classes/integrations/shareyourcart/sdk/class.shareyourcart-base.php
index 40b547bad03..7947141e4e4 100755
--- a/classes/integrations/shareyourcart/sdk/class.shareyourcart-base.php
+++ b/classes/integrations/shareyourcart/sdk/class.shareyourcart-base.php
@@ -9,9 +9,6 @@
* DESCRIPTION: This class is used as a base class for every PHP plugin we create.
* * Copyright (C) 2012 Barandi Solutions
*/
-
-if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
-
require_once(dirname(__FILE__) ."/class.shareyourcart-api.php");
if(!class_exists('ShareYourCartBase',false)){
@@ -20,8 +17,9 @@ abstract class ShareYourCartBase extends ShareYourCartAPI {
//this array is used to hold function calls between different instances of this class
private static $_SINGLE_FUNCTIONS_CALLS = array();
- private static $_SDK_VERSION = '1.6'; //the first one is the SDK main version, while the second one is it's revision
+ private static $_SDK_VERSION = '1.9'; //the first one is the SDK main version, while the second one is it's revision
protected static $_DB_VERSION = '1.1';
+ protected $SDK_ANALYTICS = true;
/**
* Constructor
@@ -37,10 +35,15 @@ abstract class ShareYourCartBase extends ShareYourCartAPI {
//now, add the api version to the button_js, in order to force users to download the latest
//JS file
- $this->SHAREYOURCART_BUTTON_JS .= '?v='. $this->getConfigValue('api_version');
+ if(!$this->isDebugMode()){
+ $this->SHAREYOURCART_BUTTON_JS .= '?v='. $this->getConfigValue('api_version');
+ } else { //for debug mode, use a different JS ( one that is not minified, and can be cached thus debugged
+ $this->SHAREYOURCART_BUTTON_JS = $this->SHAREYOURCART_API.'/js/button.dev.js';
+ }
$this->SHAREYOURCART_BUTTON_URL .= '?client_id='. $this->getClientId();
- //set the language
+ //set the language & it's loader
+ SyC::setLanguageLoader(array(&$this,'loadLanguage'));
SyC::setLanguage($this->getConfigValue('lang'));
}
@@ -77,7 +80,7 @@ abstract class ShareYourCartBase extends ShareYourCartAPI {
protected abstract function setConfigValue($field, $value);
/**
- * Abstract setConfigValue
+ * Abstract getConfigValue
* @param string option
* @param string value
* @return string
@@ -104,6 +107,15 @@ abstract class ShareYourCartBase extends ShareYourCartAPI {
*/
protected abstract function isSingleProduct();
+ /**
+ *
+ * Return FALSE if the curent single product is out of stock, or not
+ *
+ */
+ public function isOutOfStock(){
+ return FALSE;
+ }
+
/**
*
* Return the URL to be called when the button is pressed
@@ -148,6 +160,24 @@ abstract class ShareYourCartBase extends ShareYourCartAPI {
*/
protected abstract function applyCoupon($coupon_code);
+ /**
+ *
+ * Return the jQuery sibling selector for the product button
+ *
+ */
+ protected function getProductButtonPosition(){
+ return $this->getConfigValue('product_button_position');
+ }
+
+ /**
+ *
+ * Return the jQuery sibling selector for the cart button
+ *
+ */
+ protected function getCartButtonPosition(){
+ return $this->getConfigValue('cart_button_position');
+ }
+
/**
*
* Get the plugin version.
@@ -170,6 +200,18 @@ abstract class ShareYourCartBase extends ShareYourCartAPI {
return self::$_SDK_VERSION.'.'.$minor_version;
}
+ /**
+ *
+ * Returns TRUE if the account is in debug mode
+ *
+ */
+ public function isDebugMode()
+ {
+ $val =$this->getConfigValue('debug');
+
+ return !empty($val);
+ }
+
/**
*
* Return TRUE if there is a newer version of the plugin
@@ -236,6 +278,12 @@ abstract class ShareYourCartBase extends ShareYourCartAPI {
$activated = $this->activate($message);
}
+
+ //set some default value, like the button skin
+ $skin = $this->getConfigValue('button_skin');
+ if(empty($skin)){
+ $this->setConfigValue("button_skin", "light");
+ }
return true;
}
@@ -295,12 +343,12 @@ abstract class ShareYourCartBase extends ShareYourCartAPI {
public function deactivate(&$message = null) {
//send the notification to the API
- $this->setAccountStatus($this->getSecretKey(), $this->getClientID(), $this->getAppKey(), false, $message);
+ $success = $this->setAccountStatus($this->getSecretKey(), $this->getClientID(), $this->getAppKey(), false, $message);
//no matter what the API says, disable this plugin
$this->setConfigValue("account_status", "inactive");
- return true;
+ return $success;
}
/**
@@ -349,6 +397,11 @@ abstract class ShareYourCartBase extends ShareYourCartAPI {
//create a new session
$data = parent::startSession($params);
+ //reset the Location, as the following code might give an error
+ //and the developer needs to be aware of it
+ $headers = headers_list();
+ header('Location:');
+
//save session details
$this->insertRow($this->getTableName('shareyourcart_tokens'), $data);
@@ -356,6 +409,13 @@ abstract class ShareYourCartBase extends ShareYourCartAPI {
if($this->getSessionId($data['token']) === null)
throw new Exception(SyC::t('sdk','Token cannot be saved. Check your "{table_name}" table permissions.', array('{table_name}' => $this->getTableName('shareyourcart_tokens'))));
+
+ //since everything is ok, resume the Location header
+ foreach($headers as $header)
+ {
+ header($header);
+ }
+
return true;
}
@@ -390,9 +450,9 @@ abstract class ShareYourCartBase extends ShareYourCartAPI {
* @param null
* @return boolean
*/
- public function showButton() {
+ public function showButton($position = null) {
- echo $this->getButton();
+ echo $this->getButton($position);
}
/**
@@ -400,12 +460,12 @@ abstract class ShareYourCartBase extends ShareYourCartAPI {
* get the button code
*
*/
- public function getButton() {
+ public function getButton($position = null) {
//make sure the API is active
if(!$this->isActive()) return;
- return $this->renderButton($this->getButtonCallbackURL());
+ return $this->renderButton($this->getButtonCallbackURL(), $position);
}
/**
@@ -413,38 +473,44 @@ abstract class ShareYourCartBase extends ShareYourCartAPI {
* @param null
* @return boolean
*/
- protected function renderButton($callback_url) {
- ob_start();
-
- $current_button_type = $this->getConfigValue("button_type");
- $button_html = $this->getConfigValue("button_html");
+ protected function renderButton($callback_url,$position = null) {
- $button_img = $this->getConfigValue("btn-img");
- $button_img_width = $this->getConfigValue("btn-img-width");
- $button_img_height = $this->getConfigValue("btn-img-height");
+ $data = array(
+ 'current_button_type' => $this->getConfigValue("button_type"),
+ 'button_html' => $this->getConfigValue("button_html"),
- $button_img_hover = $this->getConfigValue("btn-img-h");
- $button_img_hover_width = $this->getConfigValue("btn-img-h-width");
- $button_img_hover_height = $this->getConfigValue("btn-img-h-height");
+ 'button_img' => $this->getUrl($this->getConfigValue("btn-img")),
+ 'button_img_width' => $this->getConfigValue("btn-img-width"),
+ 'button_img_height' => $this->getConfigValue("btn-img-height"),
+
+ 'button_img_hover' => $this->getUrl($this->getConfigValue("btn-img-h")),
+ 'button_img_hover_width' => $this->getConfigValue("btn-img-h-width"),
+ 'button_img_hover_height' => $this->getConfigValue("btn-img-h-height"),
- switch ($current_button_type)
+ 'is_product_page' => $this->isSingleProduct(),
+
+ 'position_'.(SyC::startsWith($position,"/*before*/") ? 'before' : 'after') => $position,
+ );
+
+ $output = null;
+ switch ($data['current_button_type'])
{
case '1':
- include(dirname(__FILE__) . '/views/button.php');
+ $output = $this->renderView('button',$data);
break;
case '2':
- include(dirname(__FILE__) . '/views/button-img.php');
+ $output = $this->renderView('button-img',$data);
break;
case '3':
- include(dirname(__FILE__) . '/views/button-custom.php');
+ $output = $this->renderView('button-custom',$data);
break;
default:
- include(dirname(__FILE__) . '/views/button.php');
+ $output = $this->renderView('button',$data);
break;
}
- return ob_get_clean();
+ return $output;
}
/**
@@ -464,9 +530,9 @@ abstract class ShareYourCartBase extends ShareYourCartAPI {
*/
public function getProductButton() {
- if($this->isSingleProduct() && !$this->getConfigValue('hide_on_product')){
+ if($this->isSingleProduct() && !$this->getConfigValue('hide_on_product') && !$this->isOutOfStock()){
- return $this->getButton();
+ return $this->getButton($this->getProductButtonPosition());
}
//else return nothing
@@ -492,7 +558,7 @@ abstract class ShareYourCartBase extends ShareYourCartAPI {
if(!$this->getConfigValue('hide_on_checkout')){
- return $this->getButton();
+ return $this->getButton($this->getCartButtonPosition(),false);
}
//return nothing
@@ -520,11 +586,9 @@ abstract class ShareYourCartBase extends ShareYourCartAPI {
if (!$this->isFirstCall(__FUNCTION__))
return;
- $data = $this->getCurrentProductDetails();
-
- ob_start();
- include(dirname(__FILE__) . '/views/page-header.php');
- return ob_get_clean();
+ return $this->renderView('page-header',array(
+ 'data' => $this->getCurrentProductDetails(),
+ ));
}
/**
@@ -549,11 +613,9 @@ abstract class ShareYourCartBase extends ShareYourCartAPI {
return;
//check the SDK status
- $this->checkSDKStatus(true); //for a check, as the admin might have changed the language in the configure page, so we need to sync with it
+ $this->checkSDKStatus(true); //force a check, as the admin might have changed the language in the configure page, so we need to sync with it
- ob_start();
- include(dirname(__FILE__) . '/views/admin-header.php');
- return ob_get_clean();
+ return $this->renderView('admin-header');
}
/**
@@ -577,7 +639,8 @@ abstract class ShareYourCartBase extends ShareYourCartAPI {
if (!$this->isFirstCall(__FUNCTION__))
return;
- $status_message = '';
+ $status_message = ''; //this is to be used for good messages
+ $error_message = ''; //this is to be used for bad messages
$refresh = false;
//check if this is a post for this particular page
@@ -596,7 +659,7 @@ abstract class ShareYourCartBase extends ShareYourCartAPI {
} else {
//the account did not activate, so show the error
- $status_message = $message;
+ $error_message = $message;
}
//since we might have changed the status, REFRESH
@@ -606,7 +669,14 @@ abstract class ShareYourCartBase extends ShareYourCartAPI {
else if ($_SERVER['REQUEST_METHOD'] == 'POST' &&
!empty($_POST['disable-API'])){
- $this->deactivate($status_message);
+ $message = '';
+ if($this->deactivate($message) == true) {
+
+ $status_message = $message;
+ } else {
+
+ $error_message = $message;
+ }
//since we might have changed the status, REFRESH
$refresh = true;
@@ -615,7 +685,14 @@ abstract class ShareYourCartBase extends ShareYourCartAPI {
else if ($_SERVER['REQUEST_METHOD'] == 'POST' &&
!empty($_POST['enable-API'])){
- $this->activate($status_message);
+ $message = '';
+ if($this->activate($message) == true) {
+
+ $status_message = $message;
+ } else {
+
+ $error_message = $message;
+ }
//since we might have changed the status, REFRESH
$refresh = true;
@@ -632,16 +709,12 @@ abstract class ShareYourCartBase extends ShareYourCartAPI {
$show_form = !$this->recover($this->getSecretKey(), @$_REQUEST['domain'], @$_REQUEST['email'], $status_message);
}
- //if we need to show the form
+ //if we need to show the form, the recovery failed
if($show_form)
{
//if there is a message, put the form on a new line
- if(!empty($status_message))
- $status_message .= "
";
-
- ob_start();
- include(dirname(__FILE__) . '/views/account-recover-partial.php');
- $status_message .= ob_get_clean();
+ $error_message = $status_message;
+ $status_message = $this->renderView('account-recover-partial');
}
else
{
@@ -674,6 +747,7 @@ abstract class ShareYourCartBase extends ShareYourCartAPI {
}
else
{
+ //put it in the status message, as it will be moved to error_message in the following IF
$status_message = SyC::t('sdk',"Error. You must agree with the terms and conditions bellow");
}
}
@@ -681,47 +755,51 @@ abstract class ShareYourCartBase extends ShareYourCartAPI {
//if we need to show the form
if($show_form)
{
- //if there is a message, put the form on a new line
- if(!empty($status_message))
- $status_message .= "
";
-
- ob_start();
- include(dirname(__FILE__) . '/views/account-create-partial.php');
- $status_message .= ob_get_clean();
+ //move any message to errors
+ $error_message = $status_message;
+ $status_message = $this->renderView('account-create-partial');
}
}
//make sure there is a session variable setup
- session_start();
+ @session_start();
//since switching the API status has a great impact on how the UI looks, refresh the page
//just to make sure the UI is using the latest value
if($refresh)
{
- //first, save the status message
+ //make sure to save the messages
$_SESSION['_syc_status_message'] = $status_message;
-
- //recreate the url ( but before that make sure there is no syc-account parameter in it )
- unset($_GET['syc-account']);
- $url = '?'.http_build_query($_GET,'','&');
-
- @header("HTTP/1.1 302 Found");
- @header("Location: $url");
- echo ""; //it can happen that the headers have allready been sent, so use the html version as well
- exit;
+ $_SESSION['_syc_error_message'] = $error_message;
+ }
+ else
+ {
+ //load the variables, if any
+
+ //if there is a status message
+ if(!empty($_SESSION['_syc_status_message']))
+ {
+ $status_message = $_SESSION['_syc_status_message'];
+ unset($_SESSION['_syc_status_message']);
+ }
+
+ //if there is an error message
+ if(!empty($_SESSION['_syc_error_message']))
+ {
+ $error_message = $_SESSION['_syc_error_message'];
+ unset($_SESSION['_syc_error_message']);
+ }
}
- //if there is a status message
- if(!empty($_SESSION['_syc_status_message']))
- {
- $status_message = $_SESSION['_syc_status_message'];
- unset($_SESSION['_syc_status_message']);
- }
-
// Display the view
- ob_start();
- include(dirname(__FILE__) . '/views/admin-page.php');
- return ob_get_clean();
+ return $this->renderView('admin-page',array(
+ 'html' => $html,
+ 'show_header' => $show_header,
+ 'show_footer' => $show_footer,
+ 'status_message' => $status_message,
+ 'error_message' => $error_message,
+ 'refresh' => $refresh,
+ ));
}
/**
@@ -764,11 +842,16 @@ abstract class ShareYourCartBase extends ShareYourCartAPI {
//set the show'
$this->setConfigValue("hide_on_checkout", empty($_POST['show_on_checkout']));
+
+ //set button position
+ $this->setConfigValue("product_button_position",$_POST['product_button_position']);
+ $this->setConfigValue("cart_button_position",$_POST['cart_button_position']);
if($_FILES["button-img"]["name"]!='') {
- $target_path = dirname(__FILE__). "/img/";
-
+ $target_path = $this->getUploadDir();
+ if(!SyC::endsWith($target_path,'/')) $target_path .= '/'; //make sure that the path has a / in it's end
+
$target_path = $target_path . 'button-img.png';
if(file_exists($target_path)) unlink($target_path);
@@ -778,14 +861,20 @@ abstract class ShareYourCartBase extends ShareYourCartAPI {
if (move_uploaded_file($_FILES['button-img']['tmp_name'], $target_path))
{
//set the button img
- $this->setConfigValue("btn-img", $this->createUrl($target_path));
+ $this->setConfigValue("btn-img", $this->getUrl($target_path));
$this->setConfigValue("btn-img-width", $width);
$this->setConfigValue("btn-img-height", $height);
}
+ else
+ {
+ //upload failed, so notify the user
+ throw new Exception(SyC::t('sdk','Cannot upload image to directory {directory}. Check the permissions',array('{directory}',$this->getUploadDir())));
+ }
}
if($_FILES["button-img-hover"]["name"]!='') {
- $target_path = dirname(__FILE__). "/img/";
+ $target_path = $this->getUploadDir();
+ if(!SyC::endsWith($target_path,'/')) $target_path .= '/'; //make sure that the path has a / in it's end
$target_path = $target_path . 'btn-img-hover.png';
@@ -796,32 +885,50 @@ abstract class ShareYourCartBase extends ShareYourCartAPI {
if(move_uploaded_file($_FILES['button-img-hover']['tmp_name'], $target_path))
{
//set the show'
- $this->setConfigValue("btn-img-h", $this->createUrl($target_path));
+ $this->setConfigValue("btn-img-h", $this->getUrl($target_path));
$this->setConfigValue("btn-img-h-width", $width);
$this->setConfigValue("btn-img-h-height", $height);
}
+ else
+ {
+ //upload failed, so notify the user
+ throw new Exception(SyC::t('sdk','Cannot upload image to directory {directory}. Check the permissions',array('{directory}',$this->getUploadDir())));
+ }
}
$status_message = SyC::t('sdk','Button settings successfully updated.');
}
- $current_button_type = $this->getConfigValue("button_type");
- $current_skin = $this->getConfigValue("button_skin");
- $current_position = $this->getConfigValue("button_position");
- $show_on_checkout = !$this->getConfigValue("hide_on_checkout");
- $show_on_product = !$this->getConfigValue("hide_on_product");
- $show_on_single_row = !$this->getConfigValue("dont_set_height");
-
- $button_html = $this->getConfigValue("button_html");
- $button_img = $this->getConfigValue("btn-img");
- $button_img_hover = $this->getConfigValue("btn-img-h");
-
//render the view
- ob_start();
- include(dirname(__FILE__) . '/views/button-settings-page.php');
- return ob_get_clean();
+ return $this->renderView('button-settings-page', array(
+ 'current_button_type' => $this->getConfigValue("button_type"),
+ 'current_skin' => $this->getConfigValue("button_skin"),
+ 'current_position' => $this->getConfigValue("button_position"),
+ 'show_on_checkout' => !$this->getConfigValue("hide_on_checkout"),
+ 'show_on_product' => !$this->getConfigValue("hide_on_product"),
+ 'show_on_single_row' => !$this->getConfigValue("dont_set_height"),
+
+ 'button_html' => $this->getConfigValue("button_html"),
+ 'button_img' => $this->getUrl($this->getConfigValue("btn-img")),
+ 'button_img_hover' => $this->getUrl($this->getConfigValue("btn-img-h")),
+
+ 'html' => $html,
+ 'show_header' => $show_header,
+ 'show_footer' => $show_footer,
+ 'status_message' => @$status_message,
+ ));
}
+ /**
+ *
+ * Override this function and provide a writable folder to upload
+ * the files to
+ *
+ */
+ public function getUploadDir(){
+ return dirname(_FILE_). "/img/";
+ }
+
/**
* showDocumentation
* @param null
@@ -842,13 +949,15 @@ abstract class ShareYourCartBase extends ShareYourCartAPI {
//this is a single call function
if (!$this->isFirstCall(__FUNCTION__))
return;
-
- $action_url = $this->getButtonCallbackURL();
//render the view
- ob_start();
- include(dirname(__FILE__) . '/views/documentation.php');
- return ob_get_clean();
+ return $this->renderView('documentation',array(
+ 'action_url' => $this->getButtonCallbackURL(),
+
+ 'html' => $html,
+ 'show_header' => $show_header,
+ 'show_footer' => $show_footer,
+ ));
}
/**
@@ -865,9 +974,7 @@ abstract class ShareYourCartBase extends ShareYourCartAPI {
*/
public function getUpdateNotification(){
//render the view
- ob_start();
- include(dirname(__FILE__) . '/views/update-notification-partial.php');
- return ob_get_clean();
+ return $this->renderView('update-notification-partial');
}
/*
@@ -888,7 +995,7 @@ abstract class ShareYourCartBase extends ShareYourCartAPI {
$this->assertCouponIsValid($_POST['token'], $_POST['coupon_code'], $_POST['coupon_value'], $_POST['coupon_type']);
//save the coupon
- $this->saveCoupon($_POST['token'], $_POST['coupon_code'], $_POST['coupon_value'], $_POST['coupon_type']);
+ $this->saveCoupon($_POST['token'], $_POST['coupon_code'], $_POST['coupon_value'], $_POST['coupon_type'], (isset($_POST['product_unique_ids']) && is_array($_POST['product_unique_ids']) ? $_POST['product_unique_ids'] : array()));
//check if the coupon is intended to be applied to the current cart
if (empty($_POST['save_only'])) {
@@ -898,6 +1005,10 @@ abstract class ShareYourCartBase extends ShareYourCartAPI {
header("HTTP/1.0 403");
echo $e->getMessage();
+
+ if($this->isDebugMode()){
+ echo $e->getTraceAsString();
+ }
}
}
@@ -906,7 +1017,7 @@ abstract class ShareYourCartBase extends ShareYourCartAPI {
* @param null
* @return boolean
*/
- protected function saveCoupon($token, $coupon_code, $coupon_value, $coupon_type) {
+ protected function saveCoupon($token, $coupon_code, $coupon_value, $coupon_type, $product_unique_ids = array()) {
//add the coupon id in shareyourcart coupons table
$data = array(
@@ -957,7 +1068,7 @@ abstract class ShareYourCartBase extends ShareYourCartAPI {
//we can't relly on the fact that the table has been properly created, so check it!
if(!$this->existsTable($tableName))
- throw new Exception(SyC::t('sdk','Cannot create table "{table_name}". Check your database permissions.', array('{table_name}' => $tableName)));
+ throw new Exception(SyC::t('sdk','Cannot create table "{table_name}". Check your database permissions or manually run the following SQL command and try again: {sql}', array('{table_name}' => $tableName,'{sql}' => nl2br($sql))));
}
/**
@@ -980,12 +1091,88 @@ abstract class ShareYourCartBase extends ShareYourCartAPI {
*/
protected function dropTable($tableName) {
- $this->executeNonQuery("DROP TABLE $tableName");
+ $sql = "DROP TABLE $tableName";
+ $this->executeNonQuery($sql);
//we can't relly on the fact that the table has been properly droped, so check it!
- if(!$this->existsTable($tableName))
- throw new Exception(SyC::t('sdk','Cannot drop table "{table_name}". Check your database permissions.', array('{table_name}' => $tableName)));
+ if($this->existsTable($tableName))
+ throw new Exception(SyC::t('sdk','Cannot drop table "{table_name}". Check your database permissions or manually run the following SQL command and try again: {sql}', array('{table_name}' => $tableName, '{sql}' => nl2br($sql))));
}
+
+ /**
+ *
+ * Render the specified views. we use special variable names here to avoid conflict when extracting data
+ *
+ */
+ protected function renderView($_viewName_, $_data_=NULL, $_return_=true){
+
+ //get information about the Top Parent class
+ $_reflection_ = new ReflectionClass(get_class($this));
+ $_viewFile_ = dirname($_reflection_->getFileName())."/views/$_viewName_.php";
+
+ //check if there is a file in the specified location
+ if(!file_exists($_viewFile_)){
+
+ //the view has not been overrided, so use the SDK one
+ $_viewFile_ = dirname(__FILE__) . "/views/$_viewName_.php";
+ }
+
+ //extract the data
+ if(is_array($_data_))
+ extract($_data_,EXTR_PREFIX_SAME,'data');
+ else
+ $data=$_data_;
+
+ //render the view
+ if($_return_)
+ {
+ ob_start();
+ ob_implicit_flush(false);
+ require($_viewFile_);
+ return ob_get_clean();
+ }
+ else
+ require($_viewFile_);
+ }
+
+ /**
+ *
+ * This function is used to make sure that the created url returns a proper scheme
+ *
+ */
+ protected function getUrl($file){
+
+ //if there is no file, return an empty string
+ if(empty($file)) return $file;
+
+ //test if the files is a url, as one migt send it that way
+ $parts = parse_url($file);
+ $is_url = is_array($parts) && isset($parts['scheme']);
+
+ //if this is not a url, create one for it
+ if(!$is_url)
+ {
+ //as we can't control what if the developers
+ //will take care of the HTTP / HTTPS matching,
+ $url = $this->createUrl($file);
+ }
+ else
+ {
+ $url = $file;
+ }
+
+ //do it here. the problem is loading an insecure object over a secure page, so check for this situation
+
+ if( (isset($_SERVER['HTTPS']) && !strcasecmp($_SERVER['HTTPS'],'on')) && //the page is a secure one
+ SyC::startsWith($url,'http://') //the created url is an insecure one, adjust it
+ )
+ {
+ $url = "https://".substr($url, 7);
+ }
+
+ return $url;
+ }
+
/**
*
@@ -993,7 +1180,7 @@ abstract class ShareYourCartBase extends ShareYourCartAPI {
* @param $force. TRUE to check, no matter how soon the previous check was. This can have a great impact on the experience of the admin
*
*/
- protected function checkSDKStatus($force = false) {
+ public function checkSDKStatus($force = false) {
//call the API at most only once every 5 minutes, not sooner
if(!$force && (time()-$this->getConfigValue('api_last_check')) < 5*60)
@@ -1006,15 +1193,30 @@ abstract class ShareYourCartBase extends ShareYourCartAPI {
$message = '';
if(is_array($result = $this->getSDKStatus($this->getSecretKey(), $this->getClientId(), $this->getAppKey(), $message)))
{
+
//save the data
$this->setConfigValue('api_version', @$result['api_version']);
$this->setConfigValue('latest_version', @$result['plugin_latest_version']);
$this->setConfigValue('download_url', @$result['plugin_download_url']);
+ $this->setConfigValue('debug', @$result['debug']);
//set the current language the SDK should be displayed in
if(isset($result['lang'])){
$this->setConfigValue('lang', $result['lang']);
SyC::setLanguage($result['lang']);
+
+ //check if there is a new translation available for this language
+ if(!empty($result['lang_checksum']) && $result['lang_checksum'] != SyC::getLanguageChecksum()){
+
+ //download the translation
+ $messages = $this->getSDKTranslation(SyC::getLanguage());
+
+ //save the translation
+ $this->setConfigValue('messages', $messages);
+
+ //reset the loaded messages so that the new ones are being used
+ SyC::reloadLanguage();
+ }
}
}else{
//simply log the error, for now!
@@ -1022,6 +1224,27 @@ abstract class ShareYourCartBase extends ShareYourCartAPI {
}
}
+ /**
+ *
+ * Language loader ( from the DB )
+ *
+ */
+ public function loadLanguage($lang, $category)
+ {
+ //see if we have the language saved in the db
+ $messages = $this->getConfigValue('messages');
+
+ if(empty($messages)) //no language is saved, so revert to the file one
+ {
+ $messages = SyC::loadFileLanguage($lang,$category);
+ }
+
+ //make sure we have an array for this variable
+ if(!is_array($messages)) $messages=array();
+
+ return $messages;
+ }
+
/*
*
* Call to see if the function was called once, or not
@@ -1044,6 +1267,10 @@ abstract class ShareYourCartBase extends ShareYourCartAPI {
public function UncaughtExceptionHandler(Exception $e) {
//@header("HTTP/1.0 403");
echo $e->getMessage();
+
+ if($this->isDebugMode()){
+ echo $e->getTraceAsString();
+ }
}
}
diff --git a/classes/integrations/shareyourcart/sdk/css/style.css b/classes/integrations/shareyourcart/sdk/css/style.css
index a61acdae2a5..ad016e3d559 100755
--- a/classes/integrations/shareyourcart/sdk/css/style.css
+++ b/classes/integrations/shareyourcart/sdk/css/style.css
@@ -7,13 +7,22 @@
}
.button_iframe-normal iframe {
- float:right;
- height: 58px;
+ height: 78px;
width: 230px;
position:relative;
z-index:1000;
+ vertical-align: middle;
+}
+
+.button_iframe-normal[data-syc-skin="light"] iframe, .button_iframe-normal[data-syc-skin="dark"] iframe{
+ height: 25px;
+ width: 125px;
}
.button_iframe-normal.button_height {
height: 60px;
+}
+
+.button_iframe-normal.button_height[data-syc-skin="light"],.button_iframe-normal.button_height[data-syc-skin="dark"] {
+ height: 27px;
}
\ No newline at end of file
diff --git a/classes/integrations/shareyourcart/sdk/messages/config.php b/classes/integrations/shareyourcart/sdk/messages/config.php
index 49708bcaa7f..86e3fdac672 100755
--- a/classes/integrations/shareyourcart/sdk/messages/config.php
+++ b/classes/integrations/shareyourcart/sdk/messages/config.php
@@ -1,7 +1,4 @@
'',
'App Key' => '',
diff --git a/classes/integrations/shareyourcart/sdk/messages/fr/sdk.php b/classes/integrations/shareyourcart/sdk/messages/fr/sdk.php
index 7746490c0a2..e1e9fb31db5 100755
--- a/classes/integrations/shareyourcart/sdk/messages/fr/sdk.php
+++ b/classes/integrations/shareyourcart/sdk/messages/fr/sdk.php
@@ -18,9 +18,6 @@
*
* @version $Id: $
*/
-
-if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
-
return array (
'API Status:' => '',
'App Key' => '',
diff --git a/classes/integrations/shareyourcart/sdk/messages/ro/sdk.php b/classes/integrations/shareyourcart/sdk/messages/ro/sdk.php
index 7746490c0a2..e1e9fb31db5 100755
--- a/classes/integrations/shareyourcart/sdk/messages/ro/sdk.php
+++ b/classes/integrations/shareyourcart/sdk/messages/ro/sdk.php
@@ -18,9 +18,6 @@
*
* @version $Id: $
*/
-
-if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
-
return array (
'API Status:' => '',
'App Key' => '',
diff --git a/classes/integrations/shareyourcart/sdk/views/account-create-partial.php b/classes/integrations/shareyourcart/sdk/views/account-create-partial.php
index 360bfaaffdc..5dcdeadc07b 100755
--- a/classes/integrations/shareyourcart/sdk/views/account-create-partial.php
+++ b/classes/integrations/shareyourcart/sdk/views/account-create-partial.php
@@ -1,7 +1,4 @@
-
-
+
@@ -26,7 +23,7 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
@@ -60,7 +86,7 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
-
+
diff --git a/classes/integrations/shareyourcart/sdk/views/button-custom.php b/classes/integrations/shareyourcart/sdk/views/button-custom.php
index 0148a80c84a..40aa3a42ef3 100755
--- a/classes/integrations/shareyourcart/sdk/views/button-custom.php
+++ b/classes/integrations/shareyourcart/sdk/views/button-custom.php
@@ -1,15 +1,13 @@
-
-
- data-syc-layout="custom">
+
+" data-syc-layout="custom" >
+
\ No newline at end of file
diff --git a/classes/integrations/shareyourcart/sdk/views/button-img.php b/classes/integrations/shareyourcart/sdk/views/button-img.php
index 965647f01c6..e94b5f7f31e 100755
--- a/classes/integrations/shareyourcart/sdk/views/button-img.php
+++ b/classes/integrations/shareyourcart/sdk/views/button-img.php
@@ -1,6 +1,6 @@
-
- data-syc-layout="custom">
- ShareYourCart Discount
+" data-syc-layout="custom" >
+
-
+
\ No newline at end of file
diff --git a/classes/integrations/shareyourcart/sdk/views/button-settings-page.php b/classes/integrations/shareyourcart/sdk/views/button-settings-page.php
index 12948e09389..3be9c2115d0 100755
--- a/classes/integrations/shareyourcart/sdk/views/button-settings-page.php
+++ b/classes/integrations/shareyourcart/sdk/views/button-settings-page.php
@@ -1,7 +1,4 @@
-
-
+
isActive()) return; //if the plugin is not active, do not show this page ?>
\ No newline at end of file
+ -->
\ No newline at end of file
diff --git a/classes/integrations/shareyourcart/sdk/views/documentation.php b/classes/integrations/shareyourcart/sdk/views/documentation.php
index 2c9e96ee9db..9d350289ad2 100755
--- a/classes/integrations/shareyourcart/sdk/views/documentation.php
+++ b/classes/integrations/shareyourcart/sdk/views/documentation.php
@@ -1,7 +1,4 @@
-
-
+
isActive()) return; //if the plugin is not active, do not show this page ?>
+
diff --git a/classes/integrations/shareyourcart/sdk/views/update-notification-partial.php b/classes/integrations/shareyourcart/sdk/views/update-notification-partial.php
index 0f26722ba99..1a349f89d90 100755
--- a/classes/integrations/shareyourcart/sdk/views/update-notification-partial.php
+++ b/classes/integrations/shareyourcart/sdk/views/update-notification-partial.php
@@ -1,7 +1,4 @@
-
-
+
hasNewerVersion()): //if there is a newer version, show the upgrade message?>
is available! {link}Please update now.', array('{version}' => $this->getConfigValue('latest_version'), '{link}' => '')); ?>
diff --git a/classes/integrations/shareyourcart/views/account-create-partial.php b/classes/integrations/shareyourcart/views/account-create-partial.php
new file mode 100644
index 00000000000..d1811ab2802
--- /dev/null
+++ b/classes/integrations/shareyourcart/views/account-create-partial.php
@@ -0,0 +1,36 @@
+
+
+
+
\ No newline at end of file
diff --git a/classes/integrations/shareyourcart/views/account-recover-partial.php b/classes/integrations/shareyourcart/views/account-recover-partial.php
new file mode 100644
index 00000000000..6e009c7791a
--- /dev/null
+++ b/classes/integrations/shareyourcart/views/account-recover-partial.php
@@ -0,0 +1,28 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/classes/integrations/shareyourcart/views/admin-page.php b/classes/integrations/shareyourcart/views/admin-page.php
new file mode 100644
index 00000000000..366ba69df0a
--- /dev/null
+++ b/classes/integrations/shareyourcart/views/admin-page.php
@@ -0,0 +1,139 @@
+
+
+
+
+
+ getUpdateNotification(); ?>
+
+ getClientId() && !$this->getAppKey()): //show the get started message ?>
+
+
+
+ isActive()): //show the configure part only if it is active ?>
+
Configuration
+
+
+
+
+
\ No newline at end of file
diff --git a/classes/integrations/shareyourcart/views/button-settings-page.php b/classes/integrations/shareyourcart/views/button-settings-page.php
new file mode 100644
index 00000000000..74bfeb3c452
--- /dev/null
+++ b/classes/integrations/shareyourcart/views/button-settings-page.php
@@ -0,0 +1,151 @@
+
+isActive()) return; //if the plugin is not active, do not show this page ?>
+
+
+