コード例 #1
0
 public static function http_post_request($url, $data = array())
 {
     $result = null;
     if (get_option('ecwid_http_use_stream', false) !== true) {
         $result = wp_remote_post($url, array('body' => $data));
     }
     if (!is_array($result)) {
         self::$http_use_streams = true;
         $result = wp_remote_post($url, array('body' => $data));
         self::$http_use_streams = false;
         if (is_array($result)) {
             update_option('ecwid_http_use_stream', true);
         }
     }
     return $result;
 }
コード例 #2
0
 protected function trigger_auth_error($mode = 'default')
 {
     update_option('ecwid_last_oauth_fail_time', time());
     $logs = get_option('ecwid_error_log');
     if ($logs) {
         $logs = json_decode($logs);
     }
     if (is_array($logs) && count($logs) > 0) {
         $entry = $logs[count($logs) - 1];
         if (isset($entry->message)) {
             $last_error = $entry->message;
         }
     }
     if ($mode == self::MODE_RECONNECT) {
         $this->update_state(array('mode' => 'reconnect', 'error' => 'other'));
     }
     if (isset($last_error)) {
         $url = 'http://' . APP_ECWID_COM . '/script.js?805056&data_platform=wporg&data_wporg_error=' . urlencode($last_error) . '&url=' . urlencode(get_bloginfo('url'));
         EcwidPlatform::fetch_url($url);
     }
     wp_redirect('admin.php?page=ecwid&connection_error' . ($mode == self::MODE_RECONNECT ? '&reconnect' : ''));
     exit;
 }
コード例 #3
0
 function get_method_response_stream($method)
 {
     $request_url = '';
     switch ($method) {
         case 'products':
         case 'categories':
             $request_url = $this->ECWID_PRODUCT_API_ENDPOINT . '/' . $this->store_id . '/' . $method;
             break;
         default:
             return false;
     }
     $stream = null;
     try {
         if (ini_get('allow_url_fopen')) {
             $stream = fopen($request_url, 'r');
         } else {
             $response = EcwidPlatform::fetch_url($request_url);
             $body = $response['data'];
             $stream = fopen('php://temp', 'rw');
             fwrite($stream, $body);
             rewind($stream);
         }
     } catch (Exception $e) {
         $stream = null;
     }
     return $stream;
 }
コード例 #4
0
 public function get_category($id)
 {
     $params = array(array("alias" => "c", "action" => "categories", "params" => array("parent" => $id)), array("alias" => "p", "action" => "products", "params" => array("category" => $id)), array("alias" => "pf", "action" => "profile"));
     if ($id > 0) {
         $params[] = array('alias' => 'category', "action" => "category", "params" => array("id" => $id));
     }
     $batch_result = $this->ecwid_api->get_batch_request($params);
     $category = $id > 0 ? $batch_result['category'] : null;
     $categories = $batch_result["c"];
     $products = $batch_result["p"];
     $profile = $batch_result["pf"];
     $return = $this->_l('');
     if (!is_null($category)) {
         $return .= $this->_l('<h2>' . EcwidPlatform::esc_html($category['name']) . '</h2>');
         $return .= $this->_l('<div>' . $category['description'] . '</div>');
     }
     if (is_array($categories)) {
         foreach ($categories as $category) {
             $category_url = $this->get_category_url($category);
             $category_name = $category["name"];
             $return .= $this->_l('<div class="ecwid_catalog_category_name">', 1);
             $return .= $this->_l('<a href="' . EcwidPlatform::esc_attr($category_url) . '">' . EcwidPlatform::esc_html($category_name) . '</a>');
             $return .= $this->_l('</div>', -1);
         }
     }
     if (is_array($products)) {
         foreach ($products as $product) {
             $product_url = $this->get_product_url($product);
             $product_name = $product['name'];
             $product_price = $product['price'] . ' ' . $profile['currency'];
             $return .= $this->_l('<div>', 1);
             $return .= $this->_l('<span class="ecwid_product_name">', 1);
             $return .= $this->_l('<a href="' . EcwidPlatform::esc_attr($product_url) . '">' . EcwidPlatform::esc_html($product_name) . '</a>');
             $return .= $this->_l('</span>', -1);
             $return .= $this->_l('<span class="ecwid_product_price">' . EcwidPlatform::esc_html($product_price) . '</span>');
             $return .= $this->_l('</div>', -1);
         }
     }
     return $return;
 }