PluginProbe
FeedWordPress / 2013.0504
FeedWordPress v2013.0504
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 2013.0504, at feedwordpress_file.class.php

105 lines 3.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 global $fwp_credentials;
3
4 $fwp_credentials = NULL;
5
6 class FeedWordPress_File extends WP_SimplePie_File {
7 function FeedWordPress_File ($url, $timeout = 10, $redirects = 5, $headers = null, $useragent = null, $force_fsockopen = false) {
8 self::__construct($url, $timeout, $redirects, $headers, $useragent, $force_fsockopen);
9 }
10
11 function __construct ($url, $timeout = 10, $redirects = 5, $headers = null, $useragent = null, $force_fsockopen = false) {
12 global $feedwordpress;
13 global $wp_version;
14
15 $source = NULL;
16 if ($feedwordpress->subscribed($url)) :
17 $source = $feedwordpress->subscription($url);
18 endif;
19
20 $this->url = $url;
21 $this->timeout = $timeout;
22 $this->redirects = $redirects;
23 $this->headers = $headers;
24 $this->useragent = $useragent;
25
26 $this->method = SIMPLEPIE_FILE_SOURCE_REMOTE;
27
28 global $wpdb;
29 global $fwp_credentials;
30
31 if ( preg_match('/^http(s)?:\/\//i', $url) ) :
32 $args = array( 'timeout' => $this->timeout, 'redirection' => $this->redirects);
33
34 if ( !empty($this->headers) )
35 $args['headers'] = $this->headers;
36
37 // Use default FWP user agent unless custom has been specified
38 if ( SIMPLEPIE_USERAGENT != $this->useragent ) :
39 $args['user-agent'] = $this->useragent;
40 else :
41 $args['user-agent'] = apply_filters('feedwordpress_user_agent',
42 'FeedWordPress/'.FEEDWORDPRESS_VERSION
43 .' (aggregator:feedwordpress; WordPress/'.$wp_version
44 .' + '.SIMPLEPIE_NAME.'/'.SIMPLEPIE_VERSION
45 .'; Allow like Gecko; +http://feedwordpress.radgeek.com/) at '
46 . feedwordpress_display_url(get_bloginfo('url')),
47 $this
48 );
49 endif;
50
51 // This is ugly as hell, but communicating up and down the chain
52 // in any other way is difficult.
53
54 if (!is_null($fwp_credentials)) :
55
56 $args['authentication'] = $fwp_credentials['authentication'];
57 $args['username'] = $fwp_credentials['username'];
58 $args['password'] = $fwp_credentials['password'];
59
60 elseif ($source InstanceOf SyndicatedLink) :
61
62 $args['authentication'] = $source->authentication_method();
63 $args['username'] = $source->username();
64 $args['password'] = $source->password();
65
66 endif;
67
68 FeedWordPress::diagnostic('updated_feeds:http', "HTTP [$url] &#8668; ".esc_html(FeedWordPress::val($args)));
69 $res = wp_remote_request($url, $args);
70 FeedWordPress::diagnostic('updated_feeds:http', "HTTP [$url] &#8669; ".esc_html(FeedWordPress::val($res)));
71
72 if ( is_wp_error($res) ) {
73 $this->error = 'WP HTTP Error: ' . $res->get_error_message();
74 $this->success = false;
75 } else {
76 $this->headers = wp_remote_retrieve_headers( $res );
77 $this->body = wp_remote_retrieve_body( $res );
78 $this->status_code = wp_remote_retrieve_response_code( $res );
79 }
80
81 if ($source InstanceOf SyndicatedLink) :
82 $source->update_setting('link/filesize', strlen($this->body));
83 $source->update_setting('link/http status', $this->status_code);
84 $source->save_settings(/*reload=*/ true);
85 endif;
86
87 // Do not allow schemes other than http(s)? for the time being.
88 // They are unlikely to be used; and unrestricted use of schemes
89 // allows for user to use an unrestricted file:/// scheme, which
90 // may result in exploits by WordPress users against the web
91 // hosting environment.
92 else :
93 $this->error = 'FeedWordPress only allows http or https URLs';
94 $this->success = false;
95 endif;
96
97 // SimplePie makes a strongly typed check against integers with
98 // this, but WordPress puts a string in. Which causes caching
99 // to break and fall on its ass when SimplePie is getting a 304,
100 // but doesn't realize it because this member is "304" instead.
101 $this->status_code = (int) $this->status_code;
102 }
103 } /* class FeedWordPress_File () */
104
105