PluginProbe
FeedWordPress / 2015.0514
FeedWordPress v2015.0514
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 2015.0514, at feedwordpress_file.class.php

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