PluginProbe
FeedWordPress / 2011.1019
FeedWordPress v2011.1019
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.1019, at feedwordpress_file.class.php

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