PluginProbe
FeedWordPress / 2011.1018
FeedWordPress v2011.1018
trunk 0.8 0.9 0.91 0.95 0.96 0.97 0.98 0.981 0.99 0.991 0.992 0.993 2008.1030 2008.1101 2008.1105 2008.1214 2009.0612 2009.0613 2009.0618 2009.0707 2009.1111 2009.1112 2010.0127 2010.0528 All 65 releases
feedwordpress / feedwordpress_file.class.php

feedwordpress_file.class.php in FeedWordPress 2011.1018, at feedwordpress_file.class.php

62 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 class FeedWordPress_File extends WP_SimplePie_File {
3 function FeedWordPress_File ($url, $timeout = 10, $redirects = 5, $headers = null, $useragent = null, $force_fsockopen = false) {
4 self::__construct($url, $timeout, $redirects, $headers, $useragent, $force_fsockopen);
5 }
6
7 function __construct ($url, $timeout = 10, $redirects = 5, $headers = null, $useragent = null, $force_fsockopen = false) {
8 $this->url = $url;
9 $this->timeout = $timeout;
10 $this->redirects = $redirects;
11 $this->headers = $headers;
12 $this->useragent = $useragent;
13
14 $this->method = SIMPLEPIE_FILE_SOURCE_REMOTE;
15
16 global $wpdb;
17
18 if ( preg_match('/^http(s)?:\/\//i', $url) ) {
19 $args = array( 'timeout' => $this->timeout, 'redirection' => $this->redirects);
20
21 if ( !empty($this->headers) )
22 $args['headers'] = $this->headers;
23
24 if ( SIMPLEPIE_USERAGENT != $this->useragent ) //Use default WP user agent unless custom has been specified
25 $args['user-agent'] = $this->useragent;
26
27 $links = $wpdb->get_results(
28 $wpdb->prepare("SELECT * FROM {$wpdb->links} WHERE link_rss = '%s'", $url)
29 );
30 if ($links) :
31 $source = new SyndicatedLink($links[0]);
32 $args['authentication'] = $source->authentication_method();
33 $args['username'] = $source->username();
34 $args['password'] = $source->password();
35 endif;
36
37 $res = wp_remote_request($url, $args);
38
39 if ( is_wp_error($res) ) {
40 $this->error = 'WP HTTP Error: ' . $res->get_error_message();
41 $this->success = false;
42 } else {
43 $this->headers = wp_remote_retrieve_headers( $res );
44 $this->body = wp_remote_retrieve_body( $res );
45 $this->status_code = wp_remote_retrieve_response_code( $res );
46 }
47 } else {
48 if ( ! $this->body = file_get_contents($url) ) {
49 $this->error = 'file_get_contents could not read the file';
50 $this->success = false;
51 }
52 }
53
54 // SimplePie makes a strongly typed check against integers with
55 // this, but WordPress puts a string in. Which causes caching
56 // to break and fall on its ass when SimplePie is getting a 304,
57 // but doesn't realize it because this member is "304" instead.
58 $this->status_code = (int) $this->status_code;
59 }
60 } /* class FeedWordPress_File () */
61
62