Exemplo n.º 1
0
 /**
  * Return the subdomain URL or null if no subdomain is set
  *
  * @return string
  */
 public function subdomain_url()
 {
     $url = null;
     $subdomain = CC_Cloud_Subdomain::load_from_wp();
     if (!isset($subdomain) || empty($subdomain) || 'Not Set' == $subdomain) {
         wp_redirect(cc_help_secret_key());
         exit;
     } else {
         $url = $this->protocol . $subdomain . '.' . $this->app_domain . '/';
     }
     return $url;
 }
 /**
  * Return a buy now link for the product with the given sku
  *
  * $args['sku'] => The sku for the product
  *
  * @param array $args 
  * @param string $content The link text
  * @return string Buy now anchor link
  */
 public static function cc_product_link($args, $content)
 {
     $product_sku = isset($args['sku']) ? $args['sku'] : false;
     $css_class = isset($args['class']) ? $args['sku'] : '';
     $link = "link not available for product with sku: {$product_sku}";
     if ($product_sku) {
         $subdomain = CC_Cloud_Subdomain::load_from_wp();
         if ($subdomain) {
             $url = 'https://' . $subdomain . '.cart66.com/buy/' . $product_sku;
             $link = '<a href="' . $url . '" class="' . $css_class . '">' . $content . '</a>';
         }
     }
     return $link;
 }
 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;
 }
 /**
  * Return the custom subdomain from the cloud or null if the subdomain could not be retrieved
  */
 public static function get_subdomain_form_cloud()
 {
     return CC_Cloud_Subdomain::load_from_cloud();
 }
 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;
 }