public static function cc_product($args, $content)
 {
     $product_loader = CC_Admin_Setting::get_option('cart66_main_settings', 'product_loader');
     $subdomain = CC_Cloud_Subdomain::load_from_wp();
     $id = cc_rand_string(12, 'lower');
     $product_form = '';
     $client_loading = 'true';
     $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'] : '';
     CC_Log::write("cc_product shortcode: subdomain: {$subdomain} :: product loader: {$product_loader}");
     if ($product_loader == 'server' || preg_match('/(?i)msie [2-9]/', $_SERVER['HTTP_USER_AGENT'])) {
         // if IE<=9 do not use the ajax product form method
         $product_form = self::cc_product_via_api($args, $content);
         $client_loading = 'false';
     }
     $out = "<div class=\"cc_product_wrapper\"><div id='" . $id . "' class='cc_product' data-subdomain='{$subdomain}' data-sku='{$product_sku}' data-quantity='{$display_quantity}' data-price='{$display_price}' data-display='{$display_mode}' data-client='{$client_loading}'>{$product_form}</div></div>";
     // Enqueue client side script when needed
     $product_loader = CC_Admin_Setting::get_option('cart66_main_settings', 'product_loader');
     if ('client' == $product_loader) {
         CC_Log::write('Force load client add to cart scripts');
         cc_enqueue_cart66_wordpress_js(true);
     }
     return $out;
 }
 /**
  * Attempt to load subdomain from WordPress database. If not available, load from the cloud.
  */
 public static function load_from_wp()
 {
     $subdomain = null;
     if (isset(self::$subdomain)) {
         $subdomain = self::$subdomain;
     } else {
         $subdomain = CC_Admin_Setting::get_option('cart66_main_settings', 'subdomain');
     }
     return $subdomain;
 }
 /**
  * Construct the WordPress setting.
  *
  * Set the page_slug where the settings sections should be located and the option name.
  * The option name is set to the same value as the option group if the optional third
  * parameter is omitted.
  *
  * @param string $page_slug
  * @param string $option_group
  * @param string $option_name
  * @return void
  */
 public function __construct($page_slug = null, $option_group = null, $option_name = null)
 {
     $this->page_slug = $page_slug;
     $this->option_group = $option_group;
     $this->option_name = is_null($option_name) ? $option_group : $option_name;
     $this->sections = array();
     if (!isset(self::$option_values)) {
         self::$option_values = array();
     }
     $this->register_actions();
 }
function cc_auth_settings_create()
{
    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');
            $main_settings['subdomain'] = $settings->subdomain;
            CC_Admin_Setting::update_options('cart66_main_settings', $main_settings);
            status_header('201');
        }
        exit;
    }
}
 public function get_secret_key()
 {
     if (!isset($this->secret_key)) {
         $settings = CC_Admin_Setting::get_options('cart66_main_settings');
         if (isset($settings['secret_key']) && !empty($settings['secret_key'])) {
             $this->secret_key = $settings['secret_key'];
         }
     }
     // Throw exception when accessing unset secret key
     if (!isset($this->secret_key)) {
         throw new CC_Exception_API_InvalidSecretKey('Secret key not set');
     }
     return $this->secret_key;
 }
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
}
 public function render($args)
 {
     $skip_types = array('cc_product', 'revision', 'attachment');
     $this->new_option('products', 'cc_product', true, false);
     $post_types = get_post_types();
     foreach ($post_types as $type) {
         if (!in_array($type, $skip_types)) {
             $this->new_option($type, $type, false);
         }
     }
     $selected_post_types = CC_Admin_Setting::get_option('cart66_main_settings', 'product_post_types');
     $selected_post_types[] = 'cc_product';
     $this->set_selected($selected_post_types);
     parent::render($args);
 }
 /**
  * Return the title for the page depending on the context of the request
  *
  * @return string
  */
 function cc_page_title()
 {
     if (is_search()) {
         $page_title = sprintf(__('Search Results: &ldquo;%s&rdquo;', 'cart66'), get_search_query());
         if (get_query_var('paged')) {
             $page_title .= sprintf(__('&nbsp;&ndash; Page %s', 'cart66'), get_query_var('paged'));
         }
     } elseif (is_tax()) {
         $page_title = single_term_title("", false);
     } else {
         $page_title = CC_Admin_Setting::get_option('cart66_post_type_settings', 'shop_name', 'Shop');
     }
     $page_title = apply_filters('cc_page_title', $page_title);
     return $page_title;
 }
 public function sign_in($send_return_url = false)
 {
     $url = self::$cloud->subdomain_url() . 'sign_in';
     $send_return_url = is_bool($send_return_url) ? $send_return_url : false;
     // A non-boolean may be passed in from CC_Library
     if ($send_return_url) {
         $return_url = '';
         $page_id = CC_Admin_Setting::get_option('cart66_members_notifications', 'member_home');
         if ($page_id > 0) {
             $return_url = get_permalink($page_id);
             $encoded_return_url = empty($return_url) ? '' : '?return_url=' . urlencode($return_url);
             $url .= $encoded_return_url;
         }
     }
     return $url;
 }
 public function register_actions()
 {
     // Initialize core classes
     add_action('init', array($this, 'init'), 0);
     // Check for incoming cart66 tasks and actions
     add_action('wp_loaded', 'cc_task_dispatcher');
     add_action('parse_query', 'cc_route_handler');
     // Register custom post type for products
     add_action('init', 'cc_register_product_post_type');
     // Add actions to process all add to cart requests via ajax
     add_action('wp_enqueue_scripts', 'cc_enqueue_ajax_add_to_cart');
     add_action('wp_enqueue_scripts', 'cc_enqueue_cart66_wordpress_js');
     add_action('wp_enqueue_scripts', 'cc_enqueue_cart66_styles');
     add_action('wp_enqueue_scripts', 'cc_enqueue_featherlight');
     add_action('wp_ajax_cc_ajax_add_to_cart', array('CC_Cart', 'ajax_add_to_cart'));
     add_action('wp_ajax_nopriv_cc_ajax_add_to_cart', array('CC_Cart', 'ajax_add_to_cart'));
     // Check if request is a page slurp
     add_action('template_redirect', array('CC_Page_Slurp', 'check_slurp'));
     // Preload cart summary if available, otherwise drop unknown carts
     add_action('template_redirect', array('CC_Cart', 'preload_summary'));
     // Register sidebar widget
     add_action('widgets_init', function () {
         register_widget('CC_Cart_Widget');
     });
     // Write custom css to the head
     add_action('wp_head', 'cc_custom_css');
     // Refresh notices after theme switch
     add_action('after_switch_theme', 'cc_reset_theme_notices');
     // Register activation and deactivation hooks
     register_activation_hook(__FILE__, 'cc_activate');
     register_deactivation_hook(__FILE__, 'cc_deactivate');
     // Add filter for hiding slurp page from navigation
     add_filter('get_pages', 'CC_Page_Slurp::hide_page_slurp');
     if ('yes' == CC_Admin_Setting::get_option('cart66_post_type_settings', 'product_templates')) {
         // Add filter for rendering post type page templates
         add_filter('template_include', 'cc_template_include');
         // Only register category widget when using product post type templates
         add_action('widgets_init', create_function('', 'return register_widget("CC_Category_Widget");'));
     } else {
         // Add filter for to attempt to get products showing as pages rather than posts
         add_filter('template_include', 'cc_use_page_template');
         // Add filter for rendering product partial with gallery and order form
         add_filter('the_content', 'cc_filter_product_single');
     }
 }
/**
 * 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);
}
        </p>
    <?php 
} else {
    ?>
        <p class="cc-product-price">
            <span class="cc-product-price-label"><?php 
    echo CC_Admin_Setting::get_option('cart66_labels', 'price');
    ?>
</span> 
            <span class="cc-product-price-amount"><?php 
    echo get_post_meta($post->ID, '_cc_product_formatted_price', true);
    ?>
</span>
        </p>
    <?php 
}
?>

    <a class="cc-button-primary" href="<?php 
echo get_permalink();
?>
" title="<?php 
the_title();
?>
"><?php 
echo CC_Admin_Setting::get_option('cart66_labels', 'view');
?>
</a>

</li>
Example #13
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);
            }
        }
Example #14
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">';
/**
 * 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
}
Example #16
0
 public static function ajax_add_to_cart()
 {
     $response = self::add_to_cart($_POST);
     if (is_wp_error($response)) {
         $response_code = $response->get_error_code();
     } else {
         $response_code = $response['response']['code'];
     }
     // CC_Log::write('Ajax response code: ' . print_r($response_code, TRUE));
     if ($response_code == '500') {
         header('HTTP/1.1 500: SERVER ERROR', true, 500);
     } elseif ($response_code != '201') {
         header('HTTP/1.1 422: UNPROCESSABLE ENTITY', true, 422);
         echo $response['body'];
     } else {
         $redirect_type = CC_Admin_Setting::get_option('cart66_main_settings', 'add_to_cart_redirect_type');
         $out = array('task' => 'redirect');
         $url = new CC_Cloud_URL();
         if ('view_cart' == $redirect_type) {
             $out['url'] = $url->view_cart();
         } elseif ('checkout' == $redirect_type) {
             $out['url'] = $url->checkout();
         } else {
             $product_info = json_decode($response['body'], true);
             $product_name = $product_info['product_name'];
             $message = $product_name . ' added to cart';
             $view_cart = '<a href="' . $url->view_cart() . '" class="btn btn-small pull-right ajax_view_cart_button" rel="nofollow">View Cart <i class="icon-arrow-right" /></a>';
             $out = array('task' => 'stay', 'response' => $message . $view_cart);
         }
         CC_Log::write('Ajax created :: response code 201 :: output: ' . print_r($out, TRUE));
         header('HTTP/1.1 201 Created', true, 201);
         header('Content-Type: application/json');
         echo json_encode($out);
         do_action('cc_after_add_to_cart');
     }
     die;
 }
 public function migrate_member_restrictions()
 {
     $old = get_option('ccm_category_restrictions');
     $this->member_restrictions = $old;
     CC_Admin_Setting::update_options('cart66_members_restrictions', $this->member_restrictions);
 }
 /**
  * Register cart66_main_settings
  *
  * Include the following keys:
  *   - subdomain: string
  *   - add_to_cart_redirect_type: cart, checkout, stay
  *   - product_loader: client, server
  *   - slurp_mode: physical, virtual
  *   - debug: on, off
  */
 public function register_settings()
 {
     // Set the name for the options in this section and load any stored values
     $option_values = self::get_options($this->option_name, array('secret_key' => '', 'add_to_cart_redirect_type' => '', 'product_loader' => '', 'shop_name' => 'Shop', 'custom_css' => '', 'default_css' => 'yes', 'use_product_post_type' => 'yes', 'debug' => ''));
     /*****************************************************
      * Post Type Advanced Options
      *****************************************************/
     // Create section for theme content wrappers
     $defaults = array('product_templates' => 'no', 'shop_name' => '', 'sort_method' => 'price_desc', 'max_products' => 4, 'start_markup' => '', 'end_markup' => '', 'default_css' => 'yes');
     $option_values = CC_Admin_Setting::get_options('cart66_post_type_settings', $defaults);
     // Create a section for product options
     $post_type_section = new CC_Admin_Settings_Section(__('Product Post Type Options (Advanced Settings For Theme Developers)', 'cart66'), 'cart66_post_type_settings');
     $post_type_section->description = __('These are advanced settings for theme developers.<br>If you are not creating page templates for the product post type you probably do not want to use these settings.', 'cart66');
     $post_type_section->description .= '<br /><br /><strong>';
     $post_type_section->description .= __('If You Are Using Catalog Shortcodes: ', 'cart66');
     $post_type_section->description .= '</strong><br />';
     $post_type_section->description .= __('Ignore the settings below and leave Custom Page Templates set to No.', 'cart66');
     $post_type_section->description .= '<br />';
     $post_type_section->description .= __('All the same features below are managed by the catalog shortcode parameters.', 'cart66');
     $post_type_section->description .= '<br /><br /><strong>';
     $post_type_section->description .= __('If You Are Using Custom Post Type Templates: ', 'cart66');
     $post_type_section->description .= '</strong><br />';
     $post_type_section->description .= __('Selecting Yes will disable all of the catalog shortcodes.', 'cart66');
     // Add option to disable Cart66 custom post type
     $use_product_post_type = new CC_Admin_Settings_Radio_Buttons(__('Use product post type', 'cart66'), 'use_product_post_type');
     $use_product_post_type->new_option(__('Yes (recommended)', 'cart66'), 'yes', true);
     $use_product_post_type->new_option(__('Hide', 'cart66'), 'no', false);
     $use_product_post_type->new_option(__('Disable', 'cart66'), 'disable', false);
     $use_product_post_type->description = __('If you do not want to use the cart66 catalog, photo gallery, or custom page templates, you can turn off the Cart66 custom post type', 'cart66');
     $use_product_post_type->set_selected($option_values['use_product_post_type']);
     $post_type_section->add_field($use_product_post_type);
     // Use custom page templates
     $product_templates = new CC_Admin_Settings_Radio_Buttons(__('Custom Post Type Templates', 'cart66'), 'product_templates');
     $product_templates->new_option(__('Yes', 'cart66'), 'yes', false);
     $product_templates->new_option(__('No', 'cart66'), 'no', false);
     $product_templates->description = '<strong>';
     $product_templates->description = __('If you are using shortcodes for the catalog view you must select No.', 'cart66');
     $product_templates->description .= '</strong><br />';
     $product_templates->description .= __('If you are using your own custom page templates then select Yes.', 'cart66');
     $product_templates->description .= '<br />';
     $product_templates->description .= __('The settings below only apply if you select Yes.', 'cart66');
     $product_templates->set_selected($option_values['product_templates']);
     $post_type_section->add_field($product_templates);
     // Add name of main shop page
     $shop_name_value = $option_values['shop_name'];
     $shop_name = new CC_Admin_Settings_Text_Field(__('Shop name', 'cart66'), 'shop_name', $shop_name_value);
     $shop_name->description = __('The title for your main shop page', 'cart66');
     $post_type_section->add_field($shop_name);
     // Add setting for sorting products
     $sort_value = $option_values['sort_method'];
     $sort = new CC_Admin_Settings_Select_Box(__('Sort Products By', 'cart66'), 'sort_method');
     $sort->new_option(__('Price ascending', 'cart66'), 'price_asc');
     $sort->new_option(__('Price descending', 'cart66'), 'price_desc');
     $sort->new_option(__('Name ascending', 'cart66'), 'name_asc');
     $sort->new_option(__('Name descending', 'cart66'), 'name_desc');
     $sort->new_option(__('Menu order', 'cart66'), 'menu_order');
     $plugin = '<a href="https://wordpress.org/plugins/intuitive-custom-post-order/">Intuitive Custom Post Order</a>';
     $sort->description = __('When sorting by menu order you may enjoy a plugin such as ');
     $sort->description .= $plugin . '<br/>';
     $sort->description .= __('This plugin lets you drag-and-drop the order of your products and product categories', 'cart66');
     $sort->set_selected($option_values['sort_method']);
     $post_type_section->add_field($sort);
     // Add setting for number of products on a page
     $max_products_value = $option_values['max_products'];
     $max_products = new CC_Admin_Settings_Select_Box(__('Products Per Page', 'cart66'), 'max_products');
     for ($i = 2; $i <= 50; $i++) {
         $max_products->new_option($i, $i);
     }
     $max_products->set_selected($max_products_value);
     $post_type_section->add_field($max_products);
     // Add start markup wrapper box
     $start_markup_value = $option_values['start_markup'];
     $start_markup = new CC_Admin_Settings_Text_Area(__('Start Markup', 'cart66'), 'start_markup', $start_markup_value);
     $start_markup->description = __('If using the Cart66 Product post type upsets your theme layout, the problem is most likely caused by the markup wrapping the page content. This is usually fixed by copying the markup from your theme\'s page.php file into these settings.', 'cart66');
     $start_markup->description .= ' <a href="http://cart66.com/tutorial/content-wrapper">';
     $start_markup->description .= __('Learn more about fixing layout problems.', 'cart66');
     $start_markup->description .= '</a>';
     $post_type_section->add_field($start_markup);
     // Add end markup wrapper box
     $end_markup_value = $option_values['end_markup'];
     $end_markup = new CC_Admin_Settings_Text_Area(__('End Markup', 'cart66'), 'end_markup', $end_markup_value);
     $post_type_section->add_field($end_markup);
     // Disable default css
     $default_css = new CC_Admin_Settings_Radio_Buttons(__('Include Default CSS', 'cart66'), 'default_css');
     $default_css->new_option(__('Yes'), 'yes', true);
     $default_css->new_option(__('No', 'cart66'), 'no', false);
     $default_css->description = __('You can choose whether or not to include the default cart66 CSS for product templates.', 'cart66');
     $default_css->set_selected($option_values['default_css']);
     $post_type_section->add_field($default_css);
     // Add Post Type section to the main settings
     $this->add_section($post_type_section);
     // Register all of the settings
     $this->register();
 }
Example #19
0
function cc_theme_support_notice()
{
    $product_templates = CC_Admin_Setting::get_option('cart66_post_type_settings', 'product_templates');
    if (!current_theme_supports('cart66') && 'yes' == $product_templates && CC_Admin_Notifications::show('cart66_theme_support')) {
        ?>
        <div class="error">
            <p> 
                <?php 
        _e('The active theme does not declare support for the Cart66 product post type. ', 'cart66');
        ?>
 <br />
                <?php 
        _e('Here are some times for <a href="http://help.cart66.com/article/330-fixing-layout-problems">fixing layout problems</a> and making <a href="http://help.cart66.com/article/329-custom-page-layouts">custom page layouts</a>.', 'cart66');
        ?>
<br/>
                <a href="<?php 
        echo add_query_arg('cc-task', 'dismiss_notification_theme_support');
        ?>
" class="button" style="margin-top: 10px;" ><?php 
        _e('Dismiss this message', 'cart66');
        ?>
</a>
            </p>
        </div>
        <?php 
    }
}
 /**
  * Register cart66_main_settings
  *
  * Include the following keys:
  *   - subdomain: string
  *   - add_to_cart_redirect_type: cart, checkout, stay
  *   - product_loader: client, server
  *   - slurp_mode: physical, virtual
  *   - debug: on, off
  */
 public function register_settings()
 {
     // Set the name for the options in this section and load any stored values
     $option_values = self::get_options($this->option_name, array('secret_key' => '', 'add_to_cart_redirect_type' => '', 'product_loader' => '', 'product_post_types' => '', 'shop_name' => 'Shop', 'custom_css' => '', 'default_css' => 'yes', 'debug' => ''));
     /*****************************************************
      * Main settings section
      *****************************************************/
     // Create the section for the cart66_main_settings section
     $main_title = __('Cart66 Cloud Main Settings', 'cart66');
     $main_description = __('Connect your WordPress site to your secure Cart66 account', 'cart66');
     $main_section = new CC_Admin_Settings_Section($main_title, $this->option_name);
     $main_section->description = $main_description;
     // Add secret key field
     $secret_key_title = __('Secret Key', 'cart66');
     $secret_key_value = esc_attr($option_values['secret_key']);
     $secret_key = new CC_Admin_Settings_Text_Field($secret_key_title, 'secret_key', $secret_key_value);
     $secret_key->description = __('The secret key from your secure Cart66 management console', 'cart66');
     $main_section->add_field($secret_key);
     // Add cart66 subdomain field
     $subdomain = CC_Cloud_Subdomain::load_from_wp();
     $subdomain = isset($subdomain) ? $subdomain : 'Not Set';
     $subdomain_field = new CC_Admin_Settings_Hidden_Field(__('Cart66 Subdomain', 'cart66'), 'subdomain', $subdomain);
     $subdomain_field->header = '<p>' . $subdomain . '</p>';
     $cart66_link = '<a href="https://manage.cart66.com">' . __('Cart66 Cloud Management Console', 'cart66') . '</a>';
     $description = __('Set your subdomain on the Settings tab of your ', 'cart66') . $cart66_link . '<br />';
     $description .= __('Then save these settings with a valid secret key to update this value.', 'cart66');
     $subdomain_field->description = $description;
     $main_section->add_field($subdomain_field);
     // Add to cart redirect option
     $cart_redirect = new CC_Admin_Settings_Radio_Buttons(__('Add To Cart Redirect', 'cart66'), 'add_to_cart_redirect_type');
     $cart_redirect->new_option(__('Go to view cart page', 'cart66'), 'view_cart', true);
     $cart_redirect->new_option(__('Go to checkout page', 'cart66'), 'checkout', false);
     $cart_redirect->new_option(__('Stay on same page', 'cart66'), 'stay', false);
     $cart_redirect->description = __('Where to direct the buyer after adding a product to the shopping cart', 'cart66');
     $cart_redirect->set_selected($option_values['add_to_cart_redirect_type']);
     $main_section->add_field($cart_redirect);
     // Add product loader option
     $product_loader = new CC_Admin_Settings_Radio_Buttons(__('Product Loader', 'cart66'), 'product_loader');
     $product_loader->new_option(__('Client side loading (recommended)', 'cart66'), 'client', true);
     $product_loader->new_option(__('Server side loading', 'cart66'), 'server', false);
     $product_loader->description = __('Client side is faster, but requires Javascript', 'cart66');
     $product_loader->set_selected($option_values['product_loader']);
     $main_section->add_field($product_loader);
     // Add page slurp mode option
     /*
             $slurp_mode = new CC_Admin_Settings_Radio_Buttons( __( 'Page Slurp Mode', 'cart66' ), 'slurp_mode' );
             $slurp_mode->new_option( __( 'Physical Page (recommended)', 'cart66' ), 'physical', true );
             $slurp_mode->new_option( __( 'Virtual Page', 'cart66' ), 'virtual', false );
             $slurp_mode->set_selected( $option_values[ 'slurp_mode' ] );
             $main_section->add_field( $slurp_mode );
     */
     // Add custom post type selector
     $post_types = $option_values['product_post_types'];
     $product_post_types = new CC_Admin_Settings_Post_Type_Selector(__('Product post types', 'cart66'), 'product_post_types');
     $product_post_types->description = __('Select post types that will contain product order forms', 'cart66');
     $main_section->add_field($product_post_types);
     // Add custom css field
     $css = $option_values['custom_css'];
     $custom_css = new CC_Admin_Settings_Text_Area(__('Custom CSS', 'cart66'), 'custom_css', $css);
     $custom_css->description = __('Enter your own CSS to customize the display of Cart66', 'cart66');
     $main_section->add_field($custom_css);
     // Add debug mode option
     $debug = new CC_Admin_Settings_Radio_Buttons(__('Debugging', 'cart66'), 'debug');
     $debug->new_option(__('Off', 'cart66'), 'off', true);
     $debug->new_option(__('On', 'cart66'), 'on', false);
     $debug->set_selected($option_values['debug']);
     $debug->description = __('Enable logging of debug and error messages in the log.txt file of the Cart66 Cloud plugin.<br />
                                Be careful, the log gets big quick. Only use for testing.', 'cart66');
     $debug_buttons = '<p>';
     $debug_buttons .= '<a href="' . add_query_arg('cc-task', 'download_log') . '" class="button">' . __('Download Log', 'cart66') . '</a> ';
     $debug_buttons .= '<a href="' . add_query_arg('cc-task', 'reset_log') . '" class="button">' . __('Reset Log File', 'cart66') . '</a> ';
     $debug_buttons .= '<a href="' . add_query_arg('cc-task', 'test_remote_calls') . '" class="button">' . __('Test Remote Calls', 'cart66') . '</a> ';
     $debug_buttons .= '</p>';
     if ($results = CC_Flash_Data::get('remote_call_test_results')) {
         $debug_buttons .= $results;
     }
     $debug->footer = $debug_buttons;
     $main_section->add_field($debug);
     // Add the settings sections for the page and register the settings
     $this->add_section($main_section);
     /*****************************************************
      * Cart66 Cloud Labels section
      *****************************************************/
     // Load saved label text
     $defaults = array('price' => 'Price:', 'on_sale' => 'Sale:', 'view' => 'View Details');
     $option_values = CC_Admin_Setting::get_options('cart66_labels', $defaults);
     // Create a section for configuring labels
     $labels_title = __('Cart66 Cloud Labels', 'cart66');
     $labels_description = __('Customize the display text for various labels when listing products', 'cart66');
     $labels_section = new CC_Admin_Settings_Section($labels_title, 'cart66_labels');
     $labels_section->description = $labels_description;
     // Add label for price
     $price_value = $option_values['price'];
     $price = new CC_Admin_Settings_Text_Field(__('Price Label', 'cart66'), 'price', $price_value);
     $price->description = __('The label displayed next to the product price', 'cart66');
     $labels_section->add_field($price);
     // Add label for on sale
     $on_sale_value = $option_values['on_sale'];
     $on_sale = new CC_Admin_Settings_Text_Field(__('On Sale Label', 'cart66'), 'on_sale', $on_sale_value);
     $on_sale->description = __('The label displayed next to the product price when the item is on sale', 'cart66');
     $labels_section->add_field($on_sale);
     // Add label for view details
     $view_value = $option_values['view'];
     $view = new CC_Admin_Settings_Text_Field(__('View Button', 'cart66'), 'view', $view_value);
     $view->description = __('The text in the button to view the details of the product ', 'cart66');
     $labels_section->add_field($view);
     $this->add_section($labels_section);
     // Register all of the settings
     $this->register();
 }
/**
 * Handle public actions for cart66
 */
function cc_route_handler()
{
    global $wp;
    CC_Log::write('cc_route_handler: starting');
    // If the cc-action is not available forget about doing anything else here
    if (!isset($wp->query_vars['cc-action'])) {
        CC_Log::write('cc-action not set in WP query vars so bailing out of route handler.');
        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();
        // Check for PHP_AUTH_USER when Apache is run in CGI mode
        CC_Log::write('Display SERVER: ' . print_r($_SERVER, true));
        if (isset($_SERVER['REDIRECT_HTTP_AUTHORIZATION'])) {
            CC_Log::write('Checking for basic auth headers: ' . $_SERVER['REDIRECT_HTTP_AUTHORIZATION']);
            if (preg_match('/Basic\\s+(.*)$/i', $_SERVER['REDIRECT_HTTP_AUTHORIZATION'], $matches)) {
                list($name, $password) = explode(':', base64_decode($matches[1]));
                $_SERVER['PHP_AUTH_USER'] = strip_tags($name);
                $_SERVER['PHP_AUTH_PW'] = strip_tags($password);
                CC_Log::write("Found basic auth :: {$name} :: {$password}");
            }
        }
        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 {
            CC_Log::write("PHP_AUTH_USER not set - assuming unauthenticated request: {$action}");
            // Open requests
            switch ($action) {
                case 'sign-in':
                    wp_redirect($url->sign_in());
                    exit;
                    break;
                case 'sign-out':
                    if (class_exists('CM_Visitor')) {
                        $visitor = CM_Visitor::get_instance();
                        $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("CC API Call: 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('document_title_parts', '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
}