Ejemplo n.º 1
0
 protected static function download($url, $timeout = 300)
 {
     //WARNING: The file is not automatically deleted, The script must unlink() the file.
     if (!$url) {
         return new WP_Error('http_no_url', __('Invalid URL Provided.', 'wp-e-commerce'));
     }
     $tmpfname = wp_tempnam($url);
     if (!$tmpfname) {
         return new WP_Error('http_no_file', __('Could not create Temporary file.', 'wp-e-commerce'));
     }
     $args = array('timeout' => $timeout, 'stream' => true, 'filename' => $tmpfname, 'headers' => array('X-WP-Domain' => Sputnik_API::domain()), 'user-agent' => 'WP eCommerce Marketplace: ' . WPSC_VERSION);
     Sputnik_API::sign_download($url, $args);
     $response = wp_safe_remote_get($url, $args);
     if (is_wp_error($response)) {
         unlink($tmpfname);
         return $response;
     }
     if (200 != wp_remote_retrieve_response_code($response)) {
         unlink($tmpfname);
         return new WP_Error('http_404', trim(wp_remote_retrieve_response_message($response)));
     }
     return $tmpfname;
 }
Ejemplo n.º 2
0
 public static function mangle_bulk_http($r, $url)
 {
     if (strpos($url, Sputnik::API_BASE) === false) {
         return $r;
     }
     $auth_header = Sputnik_API::get_auth_for_download($url);
     list($key, $auth_header) = explode(':', $auth_header);
     $r['headers']['X-WP-Domain'] = Sputnik_API::domain();
     $r['headers']['Authorization'] = $auth_header;
     return $r;
 }
Ejemplo n.º 3
0
 protected function http($url, $method, $postfields = NULL)
 {
     $args = array('method' => $method);
     switch ($method) {
         case 'POST':
             if (!empty($postfields)) {
                 $args['body'] = $postfields;
             }
             break;
     }
     $args['headers'] = array('X-WP-Domain' => Sputnik_API::domain());
     $response = wp_remote_request($url, $args);
     if (is_wp_error($response)) {
         throw new Exception($response->get_error_message());
     }
     if ($response['response']['code'] != 200) {
         throw new Exception($response['body']);
     }
     return $response['body'];
 }
Ejemplo n.º 4
0
 public static function add_download_link_page($purchase_log_object, $sessionid, $display_to_screen)
 {
     if (!$display_to_screen) {
         return;
     }
     $cart_contents = $purchase_log_object->get_cart_contents();
     $products = '';
     foreach ($cart_contents as $product) {
         $download_link = get_post_meta($product->prodid, '_download_url', true);
         if (!empty($download_link)) {
             $download_link = esc_url(add_query_arg('marketplace', Sputnik_API::domain(), $download_link));
             $products .= "\n" . '<a href="' . $download_link . '">Download ' . $product->name . '</a>' . "\n";
         }
     }
     echo $products;
 }