Exemple #1
0
 /**
  * Tests the WordPress HTTP objects for an object to use and returns it.
  *
  * Tests all of the objects and returns the object that passes. Also caches
  * that object to be used later. This is for posting content to a URL and
  * is used when there is a body. The plain Fopen Transport can not be used
  * to send content, but the streams transport can. This is a limitation that
  * is addressed here, by just not including that transport.
  *
  * @since 2.7.0
  * @access private
  *
  * @param array $args Request args, default us an empty array
  * @return object|null Null if no transports are available, HTTP transport object.
  */
 function &_postTransport($args = array())
 {
     static $working_transport, $blocking_transport, $nonblocking_transport;
     if (is_null($working_transport)) {
         if (true === WP_Http_ExtHttp::test($args)) {
             $working_transport['exthttp'] = new WP_Http_ExtHttp();
             $blocking_transport[] =& $working_transport['exthttp'];
         } else {
             if (true === WP_Http_Curl::test($args)) {
                 $working_transport['curl'] = new WP_Http_Curl();
                 $blocking_transport[] =& $working_transport['curl'];
             } else {
                 if (true === WP_Http_Streams::test($args)) {
                     $working_transport['streams'] = new WP_Http_Streams();
                     $blocking_transport[] =& $working_transport['streams'];
                 } else {
                     if (true === WP_Http_Fsockopen::test($args)) {
                         $working_transport['fsockopen'] = new WP_Http_Fsockopen();
                         $blocking_transport[] =& $working_transport['fsockopen'];
                     }
                 }
             }
         }
         foreach (array('curl', 'streams', 'fsockopen', 'exthttp') as $transport) {
             if (isset($working_transport[$transport])) {
                 $nonblocking_transport[] =& $working_transport[$transport];
             }
         }
     }
     do_action('http_transport_post_debug', $working_transport, $blocking_transport, $nonblocking_transport);
     if (isset($args['blocking']) && !$args['blocking']) {
         return $nonblocking_transport;
     } else {
         return $blocking_transport;
     }
 }
 /**
  * Perform a HEAD request to the specified URL.
  * 
  * Note : 
  * 
  * Since the MediaFire checker works by parsing the "Location" header, redirect following
  * _must_ be disabled. This can become a problem on servers where WP is forced to fall back
  * on using WP_Http_Fopen which ignores the 'redirection' flag. WP_Http_Fsockopen would work, 
  * but it has the lowest priority of all transports. 
  * 
  * Alas, there is no way to reliably influence which transport is chosen - the WP_Http::_getTransport
  * function caches the available choices, so plugins can disable individual transports only during
  * its first run. Therefore, we must pick the best transport manually.
  * 
  * @param string $url
  * @return array|WP_Error
  */
 function head($url)
 {
     //Only consider transports that allow redirection to be disabled.
     $args = array();
     if (class_exists('WP_Http_ExtHttp') && true === WP_Http_ExtHttp::test($args)) {
         $transport = new WP_Http_ExtHttp();
     } else {
         if (class_exists('WP_Http_Curl') && true === WP_Http_Curl::test($args)) {
             $transport = new WP_Http_Curl();
         } else {
             if (class_exists('WP_Http_Curl') && true === WP_Http_Fsockopen::test($args)) {
                 $transport = new WP_Http_Fsockopen();
             } else {
                 return new WP_Error('no_suitable_transport', "No suitable HTTP transport found. Please upgrade to a more recent version of PHP or install the CURL extension.");
             }
         }
     }
     $conf = blc_get_configuration();
     $args = array('timeout' => $conf->options['timeout'], 'redirection' => 0, 'method' => 'HEAD');
     return $transport->request($url, $args);
 }
 /**
  * Update the Images get them from Server and check for existance on each image
  * @since: 5.0.5
  */
 private function _update_images()
 {
     $templates = get_option('rs-templates', array());
     $curl = new WP_Http_Curl();
     if (!$curl->test()) {
         $curl = false;
     }
     $connection = 0;
     $reload = array();
     if (!empty($templates) && is_array($templates)) {
         $upload_dir = wp_upload_dir();
         // Set upload folder
         if (!empty($templates['slider']) && is_array($templates['slider'])) {
             foreach ($templates['slider'] as $key => $temp) {
                 if ($connection > 3) {
                     continue;
                 }
                 //cant connect to server
                 // Check folder permission and define file location
                 if (wp_mkdir_p($upload_dir['basedir'] . $this->templates_path)) {
                     $file = $upload_dir['basedir'] . $this->templates_path . '/' . $temp['img'];
                     $file_plugin = RS_PLUGIN_PATH . $this->templates_path_plugin . '/' . $temp['img'];
                     if (!file_exists($file) && !file_exists($file_plugin) || isset($temp['push_image'])) {
                         if ($curl !== false) {
                             $image_data = @$curl->request($this->templates_url . $this->templates_server_path . $temp['img']);
                             // Get image data
                             if (isset($image_data['body']) && isset($image_data['response']) && isset($image_data['response']['code']) && $image_data['response']['code'] == '200') {
                                 $image_data = $image_data['body'];
                             } else {
                                 $image_data = false;
                             }
                         } else {
                             $image_data = @file_get_contents($this->templates_url . $this->templates_server_path . $temp['img']);
                             // Get image data
                         }
                         if ($image_data !== false) {
                             $reload[$temp['alias']] = true;
                             unset($templates['slider'][$key]['push_image']);
                             @mkdir(dirname($file));
                             @file_put_contents($file, $image_data);
                         } else {
                             //could not connect to server
                             $connection++;
                         }
                     } else {
                         //use default image
                     }
                 } else {
                     //use default images
                 }
             }
         }
         if (!empty($templates['slides']) && is_array($templates['slides'])) {
             foreach ($templates['slides'] as $key => $temp) {
                 foreach ($temp as $k => $tvalues) {
                     if ($connection > 3) {
                         continue;
                     }
                     //cant connect to server
                     // Check folder permission and define file location
                     if (wp_mkdir_p($upload_dir['basedir'] . $this->templates_path)) {
                         $file = $upload_dir['basedir'] . $this->templates_path . '/' . $tvalues['img'];
                         $file_plugin = RS_PLUGIN_PATH . $this->templates_path_plugin . '/' . $tvalues['img'];
                         if (!file_exists($file) && !file_exists($file_plugin) || isset($reload[$key])) {
                             //update, so load again
                             if ($curl !== false) {
                                 $image_data = @$curl->request($this->templates_url . $this->templates_server_path . $tvalues['img']);
                                 // Get image data
                                 if (isset($image_data['body']) && isset($image_data['response']) && isset($image_data['response']['code']) && $image_data['response']['code'] == '200') {
                                     $image_data = $image_data['body'];
                                 } else {
                                     $image_data = false;
                                 }
                             } else {
                                 $image_data = @file_get_contents($this->templates_url . $this->templates_server_path . $tvalues['img']);
                                 // Get image data
                             }
                             if ($image_data !== false) {
                                 @mkdir(dirname($file));
                                 @file_put_contents($file, $image_data);
                             } else {
                                 //could not connect to server
                                 $connection++;
                             }
                         } else {
                             //use default image
                         }
                     } else {
                         //use default images
                     }
                 }
             }
         }
     }
     if ($connection > 3) {
         //set value that the server cant be contacted
     }
     RevSliderFunctionsWP::update_option('rs-templates', $templates, false);
     //remove the push_image
 }
Exemple #4
0
 /**
  * Tests the WordPress HTTP objects for an object to use and returns it.
  *
  * Tests all of the objects and returns the object that passes. Also caches
  * that object to be used later.
  *
  * The order for the GET/HEAD requests are Streams, HTTP Extension, Fopen,
  * and finally Fsockopen. fsockopen() is used last, because it has the most
  * overhead in its implementation. There isn't any real way around it, since
  * redirects have to be supported, much the same way the other transports
  * also handle redirects.
  *
  * There are currently issues with "localhost" not resolving correctly with
  * DNS. This may cause an error "failed to open stream: A connection attempt
  * failed because the connected party did not properly respond after a
  * period of time, or established connection failed because connected host
  * has failed to respond."
  *
  * @since 2.7.0
  * @access private
  *
  * @param array $args Request args, default us an empty array
  * @return object|null Null if no transports are available, HTTP transport object.
  */
 function &_getTransport($args = array())
 {
     static $working_transport, $blocking_transport, $nonblocking_transport;
     if (is_null($working_transport)) {
         if (true === WP_Http_ExtHttp::test() && apply_filters('use_http_extension_transport', true)) {
             $working_transport['exthttp'] = new WP_Http_ExtHttp();
             $blocking_transport[] =& $working_transport['exthttp'];
         } else {
             if (true === WP_Http_Curl::test() && apply_filters('use_curl_transport', true)) {
                 $working_transport['curl'] = new WP_Http_Curl();
                 $blocking_transport[] =& $working_transport['curl'];
             } else {
                 if (true === WP_Http_Streams::test() && apply_filters('use_streams_transport', true)) {
                     $working_transport['streams'] = new WP_Http_Streams();
                     $blocking_transport[] =& $working_transport['streams'];
                 } else {
                     if (true === WP_Http_Fopen::test() && apply_filters('use_fopen_transport', true)) {
                         $working_transport['fopen'] = new WP_Http_Fopen();
                         $blocking_transport[] =& $working_transport['fopen'];
                     } else {
                         if (true === WP_Http_Fsockopen::test() && apply_filters('use_fsockopen_transport', true)) {
                             $working_transport['fsockopen'] = new WP_Http_Fsockopen();
                             $blocking_transport[] =& $working_transport['fsockopen'];
                         }
                     }
                 }
             }
         }
         foreach (array('curl', 'streams', 'fopen', 'fsockopen', 'exthttp') as $transport) {
             if (isset($working_transport[$transport])) {
                 $nonblocking_transport[] =& $working_transport[$transport];
             }
         }
     }
     if (has_filter('http_transport_get_debug')) {
         do_action('http_transport_get_debug', $working_transport, $blocking_transport, $nonblocking_transport);
     }
     if (isset($args['blocking']) && !$args['blocking']) {
         return $nonblocking_transport;
     } else {
         return $blocking_transport;
     }
 }
 function have_curl($args, $url = NULL)
 {
     return WP_Http_Curl::test($args);
 }