fetch_timeout() static public method

static public fetch_timeout ( )
Esempio n. 1
0
 public function attach_image($url, $to, $args = array())
 {
     $attach_id = NULL;
     $p = wp_parse_args($args, array("crop" => NULL, "resize" => NULL));
     # Fetch the URI
     $headers['Connection'] = 'close';
     $headers['Referer'] = get_permalink($to);
     if (is_callable(array('FeedWordPress', 'fetch_timeout'))) {
         $timeout = FeedWordPress::fetch_timeout();
     } elseif (defined('FEEDWORDPRESS_FETCH_TIME_OUT')) {
         $timeout = FEEDWORDPRESS_FETCH_TIME_OUT;
     } elseif (defined('FEEDWORDPRESS_FETCH_TIMEOUT_DEFAULT')) {
         $timeout = FEEDWORDPRESS_FETCH_TIMEOUT_DEFAULT;
     } else {
         $timeout = 60;
     }
     FeedWordPress::diagnostic('sicem:capture:http', "HTTP »» GET [{$url}]");
     $params = apply_filters('sicem_remote_request_params', array('headers' => $headers, 'timeout' => $timeout), $url);
     $http = apply_filters('sicem_remote_request', NULL, $url, $params);
     if (is_null($http)) {
         $http = wp_remote_request($url, $params);
     }
     $imgBits = new SicWebImage($url, $params, $http);
     if ($imgBits->is_ok() and $imgBits->is_image()) {
         // Check whether our size filters or MIME constraints filter it out
         $imagesize = $imgBits->size();
         if (!is_null($imagesize)) {
             $minWidth = isset($args['min width']) ? $args['min width'] : 0;
             $minHeight = isset($args['min height']) ? $args['min height'] : 0;
             if ($imagesize[0] < $minWidth or $imagesize[1] < $minHeight or !$this->allowedtype($imagesize['mime'], $args)) {
                 FeedWordPress::diagnostic('sicem:capture:reject', "Image [{$url}] rejected. " . ($imagesize[0] < $minWidth ? 'width: ' . $imagesize[0] . ' &lt; ' . $minWidth . '. ' : '') . ($imagesize[1] < $minHeight ? 'height: ' . $imagesize[1] . ' &lt; ' . $minHeight . '. ' : '') . (!$this->allowedtype($imagesize['mime'], $args) ? 'type [' . $imagesize['mime'] . ']: whitelist [' . implode('|', $args['whitelist']) . '] blacklist [' . implode('|', $args['blacklist']) . '].' : ''));
                 $imgBits->set_image(NULL, NULL);
             }
         }
         // Apply (if applicable) crop and resize settings
         $imgBits->constrain($p['crop'], $p['resize']);
         if ($imgBits->is_image()) {
             $attach_id = $imgBits->upload($to);
         } else {
             $attach_id = -1;
             // Filtered
         }
     } else {
         // Got a WP_Error object back instead of a HTTP GET reply
         if (is_wp_error($http)) {
             $error_message = preg_replace('/\\s+/', " ", "WP_Error: " . implode(" / ", $http->get_error_messages()));
             // Got a HTTP GET reply other than 200 OK.
         } elseif (is_array($http) and isset($http['response'])) {
             $code = $http['response']['code'];
             $mesg = $http['response']['message'];
             $pcode = preg_replace('/\\s+/', '\\s+', preg_quote($code));
             $pmesg = preg_replace('/\\s+/', '\\s+', preg_quote($mesg));
             $pattern = ":<([^>]+)> \\s* ({$pcode}\\s*)? {$pmesg} \\s*</\\1>:ix";
             $stripped_body = strip_tags(preg_replace($pattern, '', $http['body']));
             $len = 66;
             $error_message = preg_replace('/\\s+/', " ", "{$code} {$mesg}: " . substr($stripped_body, 0, $len) . (strlen($stripped_body) > $len ? "&hellip;" : ''));
             // Well, who knows what the hell is going on, really?
         } else {
             $error_message = preg_replace('/\\s+/', " ", FeedWordPress::val($http));
         }
         // Send it to the diagnostix module.
         FeedWordPress::diagnostic('sicem:capture:error', "Failed GET [{$url}] &laquo;&laquo; " . $error_message);
     }
     return $attach_id;
 }
Esempio n. 2
0
 function _get($uri = NULL)
 {
     if ($uri) {
         $this->uri = $uri;
     }
     // Is the result not yet cached?
     if ($this->uri != 'tag:localhost' and $this->_cache_uri !== $this->uri) {
         $headers['Connection'] = 'close';
         $headers['Accept'] = 'application/atom+xml application/rdf+xml application/rss+xml application/xml text/html */*';
         $headers['User-Agent'] = 'feedfinder/1.2 (compatible; PHP FeedFinder) +http://projects.radgeek.com/feedwordpress';
         // Use WordPress API function
         $client = wp_remote_request($this->uri, array_merge($this->credentials, array('headers' => $headers, 'timeout' => FeedWordPress::fetch_timeout())));
         $this->_response = $client;
         if (is_wp_error($client)) {
             $this->_data = NULL;
             $this->_error = $client->get_error_messages();
         } else {
             $this->_data = $client['body'];
             $this->_error = NULL;
         }
         // Kilroy was here
         $this->_cache_uri = $this->uri;
     }
 }
 function fetch($url, $params = array())
 {
     if (is_wp_error($url)) {
         // Let's bounce.
         return $url;
     }
     $force_feed = true;
     // Default
     // Allow user to change default feed-fetch timeout with a global setting. Props Erigami Scholey-Fuller <http://www.piepalace.ca/blog/2010/11/feedwordpress-broke-my-heart.html>			'timeout' =>
     $timeout = FeedWordPress::fetch_timeout();
     if (!is_array($params)) {
         $force_feed = $params;
     } else {
         // Parameter array
         $args = wp_parse_args(array('force_feed' => $force_feed, 'timeout' => $timeout), $params);
         extract($args);
     }
     $timeout = intval($timeout);
     $pie_class = apply_filters('feedwordpress_simplepie_class', 'SimplePie');
     $cache_class = apply_filters('feedwordpress_cache_class', 'WP_Feed_Cache');
     $file_class = apply_filters('feedwordpress_file_class', 'FeedWordPress_File');
     $parser_class = apply_filters('feedwordpress_parser_class', 'FeedWordPress_Parser');
     $sniffer_class = apply_filters('feedwordpress_sniffer_class', 'FeedWordPress_Content_Type_Sniffer');
     $feed = new $pie_class();
     $feed->set_feed_url($url);
     $feed->set_cache_class($cache_class);
     $feed->set_timeout($timeout);
     $feed->set_content_type_sniffer_class($sniffer_class);
     $feed->set_file_class($file_class);
     $feed->set_parser_class($parser_class);
     $feed->force_feed($force_feed);
     $feed->set_cache_duration(FeedWordPress::cache_duration());
     $feed->init();
     $feed->handle_content_type();
     if ($feed->error()) {
         $ret = new WP_Error('simplepie-error', $feed->error());
     } else {
         $ret = $feed;
     }
     return $ret;
 }