public function send_version_info()
 {
     $info = array('plugin_version' => CC_VERSION_NUMBER);
     $url = self::$cloud->api . 'stores';
     $options = self::$cloud->basic_auth_header();
     $options['method'] = 'PUT';
     $options['body'] = json_encode($info);
     CC_Log::write('Send version info options: ' . print_r($options, true));
     $response = wp_remote_request($url, $options);
     CC_Log::write('Send version info response: ' . print_r($response, true));
     return $response;
 }
Exemplo n.º 2
0
 /**
  * Return the entire array of $_data
  *
  * If no data has been set, return an empty array
  *
  * @return array
  */
 public static function get_all($space = 'default')
 {
     CC_Log::write('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] Getting all flash data for space: {$space} :: " . print_r(self::$_data, true));
     $data = array();
     self::init();
     if (isset(self::$_data[$space])) {
         if (is_array(self::$_data[$space])) {
             $data = self::$_data[$space];
         }
     }
     return $data;
 }
Exemplo n.º 3
0
 public static function get_data($order_id)
 {
     $order_data = array();
     $cloud = new CC_Cloud_API_V1();
     $url = $cloud->api . "orders/{$order_id}";
     $headers = array('Accept' => 'application/json');
     $response = wp_remote_get($url, $cloud->basic_auth_header($headers));
     if ($cloud->response_ok($response)) {
         $order_data = json_decode($response['body'], true);
         CC_Log::write('Order data: ' . print_r($order_data, true));
     }
     return $order_data;
 }
Exemplo n.º 4
0
function product_sort_order($wp_query)
{
    if (!is_admin() && $wp_query->is_main_query()) {
        $sort_method = CC_Admin_Setting::get_option('cart66_post_type_settings', 'sort_method');
        $is_product_query = false;
        // Is this a query for cart66 products?
        if (isset($wp_query->query['post_type']) && 'cc_product' == $wp_query->query['post_type']) {
            $is_product_query = true;
            CC_Log::write('The post type is cc_product');
        } elseif (isset($wp_query->query['product-category'])) {
            $is_product_query = true;
            CC_Log::write('The product category is set');
        }
        if ($wp_query->is_main_query() && $is_product_query) {
            // $wp_query->set('orderby', 'title');
            switch ($sort_method) {
                case 'price_desc':
                    $wp_query->set('orderby', 'meta_value_num');
                    $wp_query->set('meta_key', '_cc_product_price');
                    $wp_query->set('order', 'DESC');
                    break;
                case 'price_asc':
                    $wp_query->set('orderby', 'meta_value_num');
                    $wp_query->set('meta_key', '_cc_product_price');
                    $wp_query->set('order', 'ASC');
                    break;
                case 'name_desc':
                    $wp_query->set('orderby', 'title');
                    $wp_query->set('order', 'DESC');
                    break;
                case 'name_asc':
                    $wp_query->set('orderby', 'title');
                    $wp_query->set('order', 'ASC');
                    break;
                case 'menu_order':
                    $wp_query->set('orderby', 'menu_order');
                    $wp_query->set('order', 'ASC');
                    break;
            }
            // Set the number of products to show per page
            $max_products = CC_Admin_Setting::get_option('cart66_post_type_settings', 'max_products');
            if (!(is_numeric($max_products) && $max_products >= 2)) {
                $max_products = 4;
            }
            $wp_query->set('posts_per_page', $max_products);
        }
    }
    // End of is_main_query
}
Exemplo n.º 5
0
 /**
  * Get the URL to view the secure cart in the cloud
  *
  * The cart must exist and have a cart key in order to view the cart. If no
  * cart key exists, the view cart URL is null
  *
  * @param boolean $force_create_cart When true, create a cart if no cart key exists
  * @return string
  */
 public function view_cart($force_create_cart = false)
 {
     $url = null;
     // Do not create a cart if the id is not available in the cookie unless it is forced
     $cloud_cart = new CC_Cloud_Cart();
     $cart_key = $cloud_cart->get_cart_key($force_create_cart);
     if ($cart_key) {
         $subdomain_url = self::$cloud->subdomain_url();
         if ($subdomain_url) {
             $url = $subdomain_url . 'carts/' . $cart_key;
         }
     }
     CC_Log::write("Cart Key: {$cart_key} :: view cart URL: {$url}");
     return $url;
 }
 public static function get_receipt_content($order_number)
 {
     if (empty(self::$receipt_content)) {
         $cloud = new CC_Cloud_API_V1();
         $url = $cloud->subdomain_url() . "receipt/{$order_number}";
         $response = wp_remote_get($url, array('sslverify' => false));
         if (!is_wp_error($response)) {
             if ($response['response']['code'] == '200') {
                 self::$receipt_content = $response['body'];
             }
         } else {
             CC_Log::write('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] Unable to locate a receipt with the order number: {$order_number}");
             throw new CC_Exception_Store_ReceiptNotFound('Unable to locate a receipt with the given order number.');
         }
     }
     return self::$receipt_content;
 }
Exemplo n.º 7
0
/**
 * Return true if the global $post is a WP_Post and the content contains a cc_product shortcode
 *
 * @return boolean
 */
function cc_page_has_products()
{
    global $post;
    $has_products = false;
    $post_type = get_post_type();
    $product_post_types = CC_Admin_Setting::get_option('cart66_main_settings', 'product_post_types');
    $product_post_types[] = 'cc_product';
    if (has_filter('cc_product_post_types')) {
        $product_post_types = apply_filter('cc_product_post_types', $product_post_types);
    }
    // Check if this is the cart66 product post type
    if (in_array($post_type, $product_post_types)) {
        $has_products = true;
        CC_Log::write("This is a page with products because it is a post type known to hold products: {$post_type}\n" . print_r($product_post_types, true));
    } elseif (is_a($post, 'WP_Post') && has_shortcode($post->post_content, 'cc_product')) {
        $has_products = true;
        CC_Log::write('This is a page with products because it has a cc_product shortcode');
    }
    return $has_products;
}
 public static function load_from_cloud($secret_key = null)
 {
     self::$subdomain = null;
     $cloud = new CC_Cloud_API_V1();
     if (isset($secret_key)) {
         $cloud->secret_key = $secret_key;
     }
     $url = $cloud->api . 'subdomain';
     $headers = array('Accept' => 'text/html');
     $response = wp_remote_get($url, $cloud->basic_auth_header($headers));
     if ($cloud->response_ok($response)) {
         $subdomain = $response['body'];
         self::$subdomain = $subdomain;
         CC_Log::write('Successfully retrieved subdomain from the cloud: ' . self::$subdomain);
         // Send plugin version information to the cloud
         $messenger = new CC_Cloud_Messenger();
         $messenger->send_version_info();
         CC_Log::write('Sent version information to cloud after loading subdomain');
     }
     return self::$subdomain;
 }
Exemplo n.º 9
0
 public function basic_auth_header($extra_headers = array())
 {
     $headers = false;
     try {
         $username = $this->get_secret_key();
         if (strlen($username) > 5) {
             $password = '';
             // not in use
             $headers = array('sslverify' => false, 'timeout' => 30, 'headers' => array('Authorization' => 'Basic ' . base64_encode($username . ':' . $password)));
             if (is_array($extra_headers)) {
                 foreach ($extra_headers as $key => $value) {
                     $headers['headers'][$key] = $value;
                 }
             }
             // CC_Log::write( "Sending header for :: Authorization Basic $username:$password" );
         }
     } catch (CC_Exception_API_InvalidSecretKey $e) {
         CC_Log::write("Secret key is not set when trying to get basic auth header");
     }
     return $headers;
 }
Exemplo n.º 10
0
/**
 * Register custom post type and taxonomy for cart66 products
 */
function cc_register_product_post_type()
{
    // If the post type should not be used, just stop
    $use_post_type = CC_Admin_Setting::get_option('cart66_post_type_settings', 'use_product_post_type');
    if ('disable' == $use_post_type) {
        CC_Log::write('Cart66 post type is disabled - not registering custom post type or taxonomies');
        return;
    }
    register_taxonomy('product-category', 'cc_product', array('label' => __('Product Categories'), 'name' => 'Product Categories', 'singular_name' => 'Product Category', 'rewrite' => array('slug' => 'product-category'), 'hierarchical' => true));
    $labels = array('name' => 'Products', 'singular_name' => 'Product', 'add_new' => 'Add New', 'add_new_item' => 'Add New Product', 'edit_item' => 'Edit Product', 'new_item' => 'New Product', 'all_items' => 'All Products', 'view_item' => 'View Product', 'search_items' => 'Search Products', 'not_found' => 'No products found', 'not_found_in_trash' => 'No products found in trash', 'parent_item_colon' => '', 'menu_name' => 'Products');
    $show = false;
    if ('no' != $use_post_type) {
        $show = true;
    } else {
        // CC_Log::write( 'Hiding Cart66 Product Custom Post Types' );
    }
    $post_type_attrs = array('labels' => $labels, 'public' => $show, 'publicly_queryable' => true, 'show_ui' => $show, 'show_in_menu' => $show, 'show_in_nav_menus' => $show, 'query_var' => true, 'rewrite' => array('slug' => 'products'), 'capability_type' => 'post', 'taxonomies' => array('product-category'), 'has_archive' => true, 'hierarchical' => false, 'menu_position' => null, 'menu_icon' => 'dashicons-tag', 'supports' => array('title', 'editor', 'thumbnail', 'excerpt', 'comments', 'revisions'));
    /* Register the post type. */
    // CC_Log::write( 'Registering Cart66 product post type: cc_product' );
    register_post_type('cc_product', $post_type_attrs);
}
function cc_auth_product_create()
{
    if ('POST' == $_SERVER['REQUEST_METHOD']) {
        $post_body = file_get_contents('php://input');
        CC_Log::write("Create product from post body: {$post_body}");
        if ($product_data = json_decode($post_body)) {
            $product = new CC_Product();
            // Check for demo product
            if ('cc-cellerciser' == $product_data->sku) {
                $content = $product->cellerciser_content();
                $excerpt = $product->cellerciser_excerpt();
                $post_id = $product->create_post($product_data->sku, $content, $excerpt);
                $product->attach_cellerciser_images($post_id);
            } else {
                // Create a normal product pressed from the cloud
                CC_Log::write('Create a normal product pressed from the cloud with sku: ' . $product_data->sku);
                $product->create_post($product_data->sku);
            }
        }
        exit;
    }
}
Exemplo n.º 12
0
 public static function add_routes()
 {
     add_rewrite_rule('sign-in', 'index.php?cc-action=sign-in', 'top');
     add_rewrite_rule('sign-out', 'index.php?cc-action=sign-out', 'top');
     add_rewrite_rule('view-cart', 'index.php?cc-action=view-cart', 'top');
     add_rewrite_rule('checkout', 'index.php?cc-action=checkout', 'top');
     add_rewrite_rule('order-history', 'index.php?cc-action=order-history', 'top');
     add_rewrite_rule('profile', 'index.php?cc-action=profile', 'top');
     add_rewrite_rule('receipts/([^/]*)', 'index.php?cc-action=receipts&cc-order-number=$matches[1]', 'top');
     // Legacy URL formats
     add_rewrite_rule('view_cart', 'index.php?cc-action=view-cart', 'top');
     add_rewrite_rule('sign_in', 'index.php?cc-action=sign-in', 'top');
     add_rewrite_rule('sign_out', 'index.php?cc-action=sign-out', 'top');
     add_rewrite_rule('order_history', 'index.php?cc-action=order-history', 'top');
     // API end points
     add_rewrite_rule('cc-api/v1/products/([^/]*)', 'index.php?cc-action=product-update&cc-sku=$matches[1]', 'top');
     add_rewrite_rule('cc-api/v1/products', 'index.php?cc-action=product-create', 'top');
     add_rewrite_rule('cc-api/v1/settings', 'index.php?cc-action=settings-create', 'top');
     add_rewrite_rule('cc-api/v1/plugin', 'index.php?cc-action=plugin-info', 'top');
     add_rewrite_rule('cc-api/v1/init', 'index.php?cc-action=save-secret-key', 'top');
     CC_Log::write('Cart66 routes have been added');
 }
Exemplo n.º 13
0
 /**
  * Attach a remote image to a the post with the given post id
  *
  * If successful, return the id of the attachment otherwise return WP_Error
  *
  * @param int $post_id
  * @param string $url URL to remote image
  * @return int or WP_Error
  */
 public function attach_image_to_post($post_id, $url)
 {
     require_once ABSPATH . 'wp-admin' . '/includes/image.php';
     require_once ABSPATH . 'wp-admin' . '/includes/file.php';
     require_once ABSPATH . 'wp-admin' . '/includes/media.php';
     $tmp = download_url($url);
     $file_info = array('name' => basename($url), 'tmp_name' => $tmp);
     // Abort if the file download failed
     if (is_wp_error($tmp)) {
         @unlink($file_info['tmp_name']);
         return $tmp;
     }
     cc_add_gallery_image_sizes();
     // Add the custom image sizes
     $attachment_id = media_handle_sideload($file_info, $post_id);
     CC_Log::write('Media handle sideload attachment id: ' . print_r($attachment_id, true));
     // Abort if the sideload failed
     if (is_wp_error($attachment_id)) {
         @unlink($file_info['tmp_name']);
     } else {
         $metadata = wp_get_attachment_metadata($attachment_id);
         // CC_Log::write( 'Metadata: ' . print_r( $metadata, true ) );
         $upload_dir = wp_upload_dir();
         $file = $upload_dir['path'] . '/' . $metadata['file'];
     }
     return $attachment_id;
 }
 /**
  * Return an array of arrays of product data
  *
  * The returned array looks like this:
  *
  *  [0] => Array
  *     (
  *       [id] => 521e468adab9981ae6000709
  *       [name] => Lifetime Member
  *       [sku] => lifetime
  *       [price] => 49.0
  *       [on_sale] => 
  *       [sale_price] => 
  *       [currency] => $
  *       [expires_after] => 0
  *       [formatted_price] => $49.00
  *       [formatted_sale_price] => $
  *       [digital] => 
  *       [type] => membership
  *       [status] => available
  *     )
  * 
  *
  * @param string $query
  * @return array
  */
 public static function search($query)
 {
     self::init();
     $products = array();
     CC_Log::write("CC_Cloud_Product search query param: " . print_r($query, true));
     $url = self::$cloud->api . 'products/search/?search=' . urlencode($query);
     CC_Log::write("Search the cloud for products with this URL: {$url}");
     $headers = self::$cloud->basic_auth_header(array('Accept' => 'application/json'));
     if ($headers) {
         $response = wp_remote_get($url, $headers);
         if (self::$cloud->response_ok($response)) {
             $products = json_decode($response['body'], true);
         } else {
             CC_Log::write("Product search failed: {$url} :: " . print_r($response, true));
             throw new CC_Exception_API("Failed to retrieve products from Cart66 Cloud");
         }
     }
     return $products;
 }
Exemplo n.º 15
0
 public static function show_errors()
 {
     $data = CC_Flash_Data::get_all('cart_error');
     if (count($data)) {
         $data['link'] = add_query_arg(array('cc-task' => FALSE, 'sku' => FALSE, 'quantity' => FALSE, 'redirect' => FALSE));
         CC_Log::write('Checking for cart errors in footer: ' . print_r($data, true));
         $view = CC_View::get(CC_PATH . 'views/error-overlay.php', $data);
         echo $view;
     }
 }
Exemplo n.º 16
0
/**
 * Helper function for getting variable out of $_GET and $_POST or any other array
 *
 * First check if the given $key is set in the $source array
 * If the $key is set, return the sanitized value for the given value $type
 * If the $key is not set, return an empty string
 * 
 * The key type will return  lowercase alphanumeric  characters, dashes and underscores.
 * Uppercase characters will be converted to lowercase.
 *
 * Types of data include:
 *  - key: Lowercase alphanumeric characters, dashes and underscores
 *  - html_class: A-Z,a-z,0-9,_,- are allowed
 *  - text_field
 *  - email
 *  - file_name
 *  - int
 *
 * @param string $name The name of the GET parameter
 * @param string $type The type of expected data
 * @return string The sanitized string or an empty string
 */
function cc_sanitize($key, $type, $source)
{
    $value = '';
    if (is_array($source) && !empty($source)) {
        if (isset($source[$key])) {
            switch ($type) {
                case 'key':
                    $value = sanitize_key($source[$key]);
                    break;
                case 'html_class':
                    $value = sanitize_html_class($source[$key]);
                    break;
                case 'text_field':
                    $value = sanitize_text_field($source[$key]);
                    break;
                case 'email':
                    $value = sanitize_email($source[$key]);
                    break;
                case 'file_key':
                    $value = sanitize_file_key($source[$name]);
                    break;
                case 'int':
                    $value = (int) $source[$key];
                    break;
            }
        } else {
            CC_Log::write("{$key} was not set in: " . print_r($source, true));
        }
    }
    return $value;
}
Exemplo n.º 17
0
 /**
  * Locate a template and return the path for inclusion.
  *
  * This is the load order:
  *
  *		yourtheme		/	$template_path	/	$template_name
  *		yourtheme		/	$template_name
  *		$default_path	/	$template_name
  *
  * @access public
  * @param string $template_name
  * @param string $template_path (default: '')
  * @param string $default_path (default: '')
  * @return string
  */
 function cc_locate_template($template_name, $template_path = 'cart66/', $default_path = '')
 {
     if (!$default_path) {
         $default_path = CC_PATH . 'templates/';
     }
     // Look within passed path within the theme - this is priority
     $template_names = array(trailingslashit($template_path) . $template_name, $template_name);
     CC_Log::write('Locating template: ' . print_r($template_names, true));
     $template = locate_template($template_names);
     CC_Log::write('Found template: ' . print_r($template, true));
     // Get default template
     if (!$template) {
         $template = $default_path . $template_name;
     }
     // Return what we found
     return apply_filters('cart66_locate_template', $template, $template_name, $template_path);
 }
Exemplo n.º 18
0
 public static function product_price($product_sku)
 {
     $price = '';
     if ($product_sku) {
         try {
             $product = new CC_Cloud_Product();
             $products = $product->get_products();
             foreach ($products as $p) {
                 if ($p['sku'] == $product_sku) {
                     CC_Log::write("Getting price for product: " . print_r($p, TRUE));
                     $price = $p['on_sale'] == 1 ? $p['formatted_sale_price'] : $p['formatted_price'];
                 }
             }
         } catch (CC_Exception_API $e) {
             $price = "Error: " . $e->getMessage();
         }
     }
     CC_Log::write("Returning product price for {$product_sku}: {$price}");
     return $price;
 }
Exemplo n.º 19
0
function cc_page_slurp_notice()
{
    $task = cc_get('cc-task', 'key');
    if ('create_slurp_page' != $task) {
        CC_Log::write("Showing page slurp notice. The task is: {$task}");
        ?>
        <div class="error">
            <p><?php 
        _e('The page slurp page is not found. Please be sure to creat a page with the slug <strong>page-slurp-template</strong>', 'cart66');
        ?>
</p>
            <p>
                <a href="http://cart66.com/tutorial/page-slurp" class="button"><?php 
        _e('More information', 'cart66');
        ?>
</a>
                <a href="<?php 
        echo add_query_arg('cc-task', 'create_slurp_page');
        ?>
" class="button"><?php 
        _e('Create Slurp Page', 'cart66');
        ?>
</a>
            </p>
        </div>
        <?php 
    }
}
Exemplo n.º 20
0
 /**
  * Returns the HTML markup for the add to cart form for the given product id
  *
  * @return string
  */
 public function get_order_form($product_id, $redirect_url, $display_quantity = null, $display_price = null, $display_mode = null)
 {
     // Prepare the query string
     $params = array('redirect_url' => urlencode($redirect_url));
     if (isset($display_mode)) {
         $params[] = 'display=' . $display_mode;
     }
     if (isset($display_quantity)) {
         $params[] = 'quantity=' . $display_quantity;
     }
     if (isset($display_price)) {
         $params[] = 'price=' . $display_price;
     }
     $query_string = '?' . implode('&', $params);
     // Prepare the url
     $headers = array('Accept' => 'text/html');
     $subdomain_url = self::$cloud->subdomain_url();
     $url = $subdomain_url . 'products/' . $product_id . '/forms/add_to_cart' . $query_string;
     CC_Log::write("Getting order form get_order_form URL: {$url}");
     $response = wp_remote_get($url, self::$cloud->basic_auth_header($headers));
     if (is_wp_error($response)) {
         CC_Log::write('CC_Cloud_Cart::get_add_to_cart_form had an error: ' . print_r($response, true));
         throw new CC_Exception_API('Failed to retrieve product add to cart form from Cart66 Cloud');
     } elseif ($response['response']['code'] != 200) {
         CC_Log::write('CC_Cloud_Cart::get_add_to_cart_form invalid response code: ' . print_r($response, true));
         throw new CC_Exception_API('Failed to retrieve product add to cart form from Cart66 Cloud :: Response code error :: ' . $response['response']['code']);
     }
     $form_html = $response['body'];
     return $form_html;
 }
 public function save()
 {
     CC_Log::write('Saving admin notifications');
     update_option($this->option_name, $this->notifications);
 }
Exemplo n.º 22
0
<?php

/**
 * Output necessary content wrappers based on active theme
 */
if (!defined('ABSPATH')) {
    exit;
}
// Exit if accessed directly
$template = get_option('template');
$out = '';
CC_Log::write('template for starting out: ' . $template);
$wrapper = CC_Admin_Setting::get_options('cart66_content_wrapper');
if (is_array($wrapper) && isset($wrapper['start_markup']) && !empty($wrapper['start_markup'])) {
    $out = $wrapper['start_markup'];
    CC_Log::write("Set content wrapping start output: {$out}");
} else {
    switch ($template) {
        case 'twentyeleven':
            $out = '<div id="primary" class="site-content"><div id="content" role="main">';
            break;
        case 'twentytwelve':
            $out = '<div id="primary" class="site-content"><div id="content" role="main">';
            break;
        case 'twentythirteen':
            $out = '<div id="primary" class="content-area"><div id="content" role="main" class="site-content entry-content twentythirteen"><article class="hentry">';
            break;
        case 'twentyfourteen':
            $url = cc_url();
            wp_enqueue_style('cc_twentyfourteen', $url . 'templates/css/twentyfourteen.css');
            $out = '<div id="primary" class="content-area"><div id="content" role="main" class="site-content twentyfourteen"><div class="cc-twentyfourteen">';
 public function sanitize($options)
 {
     $clean = true;
     CC_Log::write('########## SANITZE OPTIONS FOR MAIN SETTINGS :: ' . get_class() . ' ########## ' . print_r($options, true));
     // Attempt to sanitize, validate, and save the options
     if (is_array($options)) {
         foreach ($options as $key => $value) {
             if ('secret_key' == $key) {
                 if (cc_starts_with($value, 's_')) {
                     // Attempt to get the subdomain from the cloud and save it locally
                     $subdomain = CC_Cloud_Subdomain::load_from_cloud($value);
                     if (isset($subdomain)) {
                         $options['subdomain'] = $subdomain;
                     }
                 } else {
                     $clean = false;
                     $error_message = __('The secret key is invalid', 'cart66');
                     add_settings_error('cart66_main_settings_group', 'invalid-secret-key', $error_message, 'error');
                     CC_Log::write("Cart66 settings validation error added: {$error_message}");
                 }
             }
         }
     } else {
         $message = __('Cart66 settings were not saved', 'cart66');
         add_settings_error('cart66_main_settings_group', 'settings-valid', $message, 'error');
     }
     // Sanitize options registered by add-on plugins
     $options = apply_filters('cart66_main_settings_sanitize', $options);
     /*
     if( true == self::$is_valid ) {
         $message = __( 'Cart66 settings saved', 'cart66' );
         add_settings_error(
             'cart66_main_settings_group',
             'settings-valid',
             $message,
             'updated'
         );
     }
     */
     return $options;
 }
/**
 * Function to add, update, or delete post meta
 *
 * Note that the given $meta_key is both the HTML form field name and the 
 * meta_key in the wp_postmeta table
 * 
 * If a new product is selected, the submitted value will be in the format:
 * cloud_id~~product_name
 *
 * If the stored value is being displayed, the submitted value is empty
 *
 * @param int $post_id
 * @param string $meta_key
 */
function cc_store_meta_box_values($post_id)
{
    $json_key = '_cc_product_json';
    $prefix = '_cc_product_';
    // Get the posted data and sanitize it for use as an HTML class.
    $product_info = isset($_POST['_cc_product_json']) ? sanitize_text_field($_POST['_cc_product_json']) : '';
    $product_info = stripslashes($product_info);
    $product_info = json_decode($product_info, true);
    if (is_array($product_info)) {
        // Get the meta value of the custom field key.
        $old_value = get_post_meta($post_id, $json_key, true);
        if ('' == $old_value) {
            // If a new meta value was added and there was no previous value, add it.
            add_post_meta($post_id, $json_key, $product_info, true);
            foreach ($product_info as $key => $value) {
                add_post_meta($post_id, $prefix . $key, $value, true);
            }
        } elseif ($product_info != $old_value) {
            // If the new meta value does not match the old value, update it.
            update_post_meta($post_id, $json_key, $product_info);
            foreach ($product_info as $key => $value) {
                update_post_meta($post_id, $prefix . $key, $value);
            }
        } elseif ('' == $product_info && $old_value) {
            // TODO: $product_info will never be empty here because in order to get here it has to be an array
            // If there is no new meta value but an old value exists, delete it.
            delete_post_meta($post_id, $json_key);
        } else {
            CC_Log::write("Totally skipping saving meta data for a reason currently unknown to me.");
        }
    }
    // Save the product layout value
    if (!empty($_POST['_cc_product_layout'])) {
        $layout = sanitize_text_field($_POST['_cc_product_layout']);
        update_post_meta($post_id, '_cc_product_layout', $layout);
    }
}
Exemplo n.º 25
0
 public static function set_query_to_slurp($wp_query)
 {
     if ($wp_query->is_main_query()) {
         $slurp_id = self::slurp_page_id();
         CC_Log::write("Setting query to use slurp ID: {$slurp_id}");
         $wp_query->set('post_type', 'page');
         $wp_query->set('page_id', $slurp_id);
     }
 }
Exemplo n.º 26
0
/**
 * Close the content with the appropriate tags based on active theme.
 *
 * This file is used in conjunction with content-start.php to attempt to get 
 * the page content styled according to the active theme.
 */
if (!defined('ABSPATH')) {
    exit;
}
// Exit if accessed directly
$template = get_option('template');
$out = '';
$wrapper = CC_Admin_Setting::get_options('cart66_content_wrapper');
if (is_array($wrapper) && isset($wrapper['end_markup']) && !empty($wrapper['end_markup'])) {
    $out = $wrapper['end_markup'];
    CC_Log::write("Set content wrapping end output: {$out}");
} else {
    switch ($template) {
        case 'twentyeleven':
            $out = '</div></div>';
            break;
        case 'twentytwelve':
            $out = '</div></div>';
            break;
        case 'twentythirteen':
            $out = '</article></div></div>';
            break;
        case 'twentyfourteen':
            $out = '</div></div></div>';
            $out .= cc_get_sidebar('content');
            break;
Exemplo n.º 27
0
<?php

// Allow a defined constant to override the database setting for debugging
if (!defined('CC_DEBUG')) {
    $debug = CC_Admin_Setting::get_option('cart66_main_settings', 'debug');
    CC_Log::write('Debug value: ' . $debug);
    $debug = 'on' == $debug ? true : false;
    define('CC_DEBUG', $debug);
}
class CC_Log
{
    public static $log_file;
    public static function init()
    {
        if (!isset(self::$log_file)) {
            self::$log_file = CC_PATH . 'log.txt';
        }
    }
    public static function write($data)
    {
        if (defined('CC_DEBUG') && CC_DEBUG) {
            self::init();
            $backtrace = debug_backtrace();
            $file = $backtrace[0]['file'];
            $line = $backtrace[0]['line'];
            $date = current_time('m/d/Y g:i:s A') . ' ' . get_option('timezone_string');
            $out = "========== {$date} ==========\nFile: {$file}" . ' :: Line: ' . $line . "\n{$data}";
            if (is_writable(CC_PATH)) {
                file_put_contents(self::$log_file, $out . "\n\n", FILE_APPEND);
            }
        }
Exemplo n.º 28
0
<?php

/**
 * Pagination - Show numbered pagination for product listing pages.
 */
CC_Log::write('Inside pagination.php');
if (!defined('ABSPATH')) {
    exit;
    // Exit if accessed directly
}
global $wp_query;
if ($wp_query->max_num_pages <= 1) {
    return;
}
?>
<nav class="cart66-pagination">
	<?php 
echo paginate_links(apply_filters('cart66_pagination_args', array('base' => esc_url_raw(str_replace(999999999, '%#%', remove_query_arg('add-to-cart', get_pagenum_link(999999999, false)))), 'format' => '', 'add_args' => '', 'current' => max(1, get_query_var('paged')), 'total' => $wp_query->max_num_pages, 'prev_text' => '&larr;', 'next_text' => '&rarr;', 'type' => 'list', 'end_size' => 3, 'mid_size' => 3)));
?>
</nav>
 public static function cc_product_via_api($args, $content)
 {
     $form = '';
     if ($error_message = CC_Flash_Data::get('api_error')) {
         $form .= "<p class=\"cc_error\">{$error_message}</p>";
     }
     $product_id = isset($args['id']) ? $args['id'] : false;
     $product_sku = isset($args['sku']) ? $args['sku'] : false;
     $display_quantity = isset($args['quantity']) ? $args['quantity'] : 'true';
     $display_price = isset($args['price']) ? $args['price'] : 'true';
     $display_mode = isset($args['display']) ? $args['display'] : null;
     if ($form_with_errors = CC_Flash_Data::get($product_sku)) {
         $form .= $form_with_errors;
     } else {
         $product = new CC_Product();
         if ($product_sku) {
             $product->sku = $product_sku;
         } elseif ($product_id) {
             $product->id = $product_id;
         } else {
             throw new CC_Exception_Product('Unable to add product to cart without know the product sku or id');
         }
         try {
             $form .= $product->get_order_form($display_quantity, $display_price, $display_mode);
         } catch (CC_Exception_Product $e) {
             $form = "Product order form unavailable";
             CC_Log::write('Failed to get product order form: ' . $e->getMessage());
         }
     }
     return $form;
 }
Exemplo n.º 30
0
/**
 * Handle public actions for cart66
 */
function cc_route_handler()
{
    global $wp;
    // If the cc-action is not available forget about doing anything else here
    if (!isset($wp->query_vars['cc-action'])) {
        return;
    }
    $action = $wp->query_vars['cc-action'];
    CC_Log::write("Route handler found action: {$action}");
    if ($action) {
        unset($wp->query_vars['cc-action']);
        $url = new CC_Cloud_URL();
        if (isset($_SERVER['PHP_AUTH_USER'])) {
            // Authenticated requests
            if (cc_auth_verify_secret_key($_SERVER['PHP_AUTH_USER'])) {
                switch ($action) {
                    case 'product-update':
                        cc_auth_product_update();
                        break;
                    case 'product-create':
                        CC_Log::write('About to create a product');
                        cc_auth_product_create();
                        break;
                    case 'settings-create':
                        cc_auth_settings_create();
                        break;
                }
            } else {
                CC_Log::write("Protected request failed authentication: {$action}");
                status_header('401');
                exit;
            }
        } else {
            // Open requests
            switch ($action) {
                case 'sign-in':
                    wp_redirect($url->sign_in());
                    exit;
                    break;
                case 'sign-out':
                    if (class_exists('CM_Visitor')) {
                        $visitor = new CM_Visitor();
                        $visitor->sign_out();
                    }
                    wp_redirect($url->sign_out());
                    exit;
                    break;
                case 'view-cart':
                    wp_redirect($url->view_cart(true));
                    exit;
                    break;
                case 'checkout':
                    wp_redirect($url->checkout(true));
                    exit;
                    break;
                case 'order-history':
                    wp_redirect($url->order_history());
                    exit;
                    break;
                case 'profile':
                    wp_redirect($url->profile());
                    exit;
                    break;
                case 'receipts':
                    $order_id = $wp->query_vars['cc-order-number'];
                    CC_Log::write("Getting receipt for order number: {$order_id}");
                    $_GET['cc_page_title'] = 'Receipt';
                    $_GET['cc_page_name'] = 'Receipt';
                    $_GET['cc_order_id'] = $order_id;
                    add_action('pre_get_posts', 'CC_Page_Slurp::set_query_to_slurp');
                    add_filter('wp_title', 'CC_Page_Slurp::set_page_title');
                    add_filter('the_title', 'CC_Page_Slurp::set_page_heading');
                    CC_Page_Slurp::check_receipt();
                    break;
                case 'plugin-info':
                    $data = cc_plugin_info();
                    header('Content-Type: application/json');
                    echo json_encode($data);
                    exit;
                    break;
                case 'save-secret-key':
                    if ('POST' == $_SERVER['REQUEST_METHOD']) {
                        $post_body = file_get_contents('php://input');
                        if ($settings = json_decode($post_body)) {
                            $main_settings = CC_Admin_Setting::get_options('cart66_main_settings');
                            if (!isset($main_settings['secret_key']) || empty($main_settings['secret_key'])) {
                                $main_settings['secret_key'] = $settings->secret_key;
                                CC_Admin_Setting::update_options('cart66_main_settings', $main_settings);
                                status_header('201');
                            } else {
                                CC_Log::write('Not overwriting existing secret key');
                                status_header('412');
                            }
                        }
                        exit;
                    }
                    break;
                default:
                    CC_Log::write("Unknown open request: {$action}");
                    status_header('404');
                    exit;
            }
            // end switch $action
        }
        // end open requests
    }
    // end if $action
}