| @@ -1,27 +1,27 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | class FeedWordPressHTTPAuthenticator { |
| 3 | 3 | var $args = array(); |
| 4 | - | |
| 4 | + | |
| 5 | 5 | function __construct () { |
| 6 | 6 | add_filter('use_curl_transport', array($this, 'digest_do_it'), 2, 1000); |
| 7 | 7 | foreach (array('fsockopen', 'fopen', 'streams', 'http_extension') as $transport) : |
| 8 | 8 | add_filter("use_{$transport}_transport", array($this, 'digest_dont'), 2, 1000); |
| 9 | 9 | endforeach; |
| 10 | - | |
| 10 | + | |
| 11 | 11 | add_filter('pre_http_request', array($this, 'pre_http_request'), 10, 3); |
| 12 | - add_action('http_api_curl', array($this, 'set_auth_options'), 1000, 3); | |
| 12 | + add_action('http_api_curl', array($this, 'set_auth_options'), 1000, 1); | |
| 13 | 13 | } /* FeedWordPressHTTPAuthenticator::__construct () */ |
| 14 | 14 | |
| 15 | 15 | function methods_available () { |
| 16 | 16 | $methods = array('-' => 'None'); |
| 17 | - | |
| 17 | + | |
| 18 | 18 | if ($this->have_curl(array('authentication' => 'digest'))) : |
| 19 | 19 | $methods = array_merge(array( |
| 20 | 20 | 'digest' => 'Digest', |
| 21 | 21 | ), $methods); |
| 22 | 22 | endif; |
| 23 | - | |
| 23 | + | |
| 24 | 24 | if ( |
| 25 | 25 | $this->have_curl(array('authentication' => 'basic')) |
| 26 | 26 | or $this->have_streams(array('authentication' => 'basic')) |
| 27 | 27 | ) : |
| @@ -28,9 +28,9 @@ | ||
| 28 | 28 | $methods = array_merge(array( |
| 29 | 29 | 'basic' => 'Basic', |
| 30 | 30 | ), $methods); |
| 31 | 31 | endif; |
| 32 | - | |
| 32 | + | |
| 33 | 33 | return $methods; |
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | function pre_http_request ($pre, $args, $url) { |
| @@ -38,15 +38,15 @@ | ||
| 38 | 38 | 'authentication' => NULL, |
| 39 | 39 | 'username' => NULL, |
| 40 | 40 | 'password' => NULL, |
| 41 | 41 | )); |
| 42 | - | |
| 42 | + | |
| 43 | 43 | // Ruh roh... |
| 44 | 44 | $auth = $this->args['authentication']; |
| 45 | 45 | if (is_null($auth) or (strlen($auth) == 0)) : |
| 46 | 46 | $this->args['authentication'] = '-'; |
| 47 | 47 | endif; |
| 48 | - | |
| 48 | + | |
| 49 | 49 | switch ($this->args['authentication']) : |
| 50 | 50 | case '-' : |
| 51 | 51 | // No HTTP Auth method. Remove this stuff. |
| 52 | 52 | $this->args['authentication'] = NULL; |
| @@ -64,19 +64,19 @@ | ||
| 64 | 64 | // make a recursive call with the credentials in the URL. |
| 65 | 65 | // Wee ha! |
| 66 | 66 | $method = $this->args['authentication']; |
| 67 | 67 | $credentials = $this->args['username']; |
| 68 | - if ( !is_null($this->args['password'])) : | |
| 68 | + if (!is_null($this->args['password'])) : | |
| 69 | 69 | $credentials .= ':'.$args['password']; |
| 70 | 70 | endif; |
| 71 | - | |
| 71 | + | |
| 72 | 72 | // Remove these so we don't recurse all the way down |
| 73 | 73 | unset($this->args['authentication']); |
| 74 | 74 | unset($this->args['username']); |
| 75 | 75 | unset($this->args['password']); |
| 76 | - | |
| 76 | + | |
| 77 | 77 | $url = preg_replace('!(https?://)!', '$1'.$credentials.'@', $url); |
| 78 | - | |
| 78 | + | |
| 79 | 79 | // Subsidiary request |
| 80 | 80 | $pre = wp_remote_request($url, $this->args); |
| 81 | 81 | break; |
| 82 | 82 | endif; |
| @@ -88,18 +88,18 @@ | ||
| 88 | 88 | endif; |
| 89 | 89 | default : |
| 90 | 90 | if (is_callable('WP_Http', '_get_first_available_transport')) : |
| 91 | 91 | $trans = WP_Http::_get_first_available_transport($args, $url); |
| 92 | - if ( ! $trans) : | |
| 92 | + if (!$trans) : | |
| 93 | 93 | $trans = WP_Http::_get_first_available_transport(array(), $url); |
| 94 | 94 | endif; |
| 95 | 95 | elseif (is_callable('WP_Http', '_getTransport')) : |
| 96 | - $transports = WP_Http::_getTransport($args); // absolutely deprecated & removed. (gwyneth 20230920) | |
| 96 | + $transports = WP_Http::_getTransport($args); | |
| 97 | 97 | $trans = get_class(reset($transports)); |
| 98 | 98 | else : |
| 99 | 99 | $trans = 'HTTP'; |
| 100 | 100 | endif; |
| 101 | - | |
| 101 | + | |
| 102 | 102 | $pre = new WP_Error('http_request_failed', |
| 103 | 103 | sprintf( |
| 104 | 104 | __('%s cannot use %s authentication with the %s transport.'), |
| 105 | 105 | __CLASS__, |
| @@ -114,18 +114,18 @@ | ||
| 114 | 114 | |
| 115 | 115 | function have_curl ($args, $url = NULL) { |
| 116 | 116 | return WP_Http_Curl::test($args); |
| 117 | 117 | } |
| 118 | - | |
| 118 | + | |
| 119 | 119 | function have_streams ($args, $url = NULL) { |
| 120 | 120 | return WP_Http_Streams::test($args); |
| 121 | 121 | } |
| 122 | - | |
| 122 | + | |
| 123 | 123 | function need_curl ($args) { |
| 124 | 124 | $args = wp_parse_args($args, array( |
| 125 | 125 | 'authentication' => NULL, |
| 126 | 126 | )); |
| 127 | - | |
| 127 | + | |
| 128 | 128 | switch ($args['authentication']) : |
| 129 | 129 | case 'digest' : |
| 130 | 130 | $use = true; |
| 131 | 131 | break; |
| @@ -133,17 +133,17 @@ | ||
| 133 | 133 | $use = false; |
| 134 | 134 | endswitch; |
| 135 | 135 | return $use; |
| 136 | 136 | } /* FeedWordPressHTTPAuthenticator::need_curl () */ |
| 137 | - | |
| 137 | + | |
| 138 | 138 | function digest_do_it ($use, $args) { |
| 139 | 139 | return $this->if_curl($use, $args, true); |
| 140 | 140 | } /* FeedWordPerssHTTPAuthenticator::digest_do_it () */ |
| 141 | - | |
| 141 | + | |
| 142 | 142 | function digest_dont ($use, $args) { |
| 143 | 143 | return $this->if_curl($use, $args, false); |
| 144 | 144 | } /* FeedWordPressHTTPAuthenticator::digest_dont () */ |
| 145 | - | |
| 145 | + | |
| 146 | 146 | function if_curl ($use, $args, $what) { |
| 147 | 147 | if ($this->need_curl($args)) : |
| 148 | 148 | $use = $what; |
| 149 | 149 | endif; |
| @@ -148,22 +148,22 @@ | ||
| 148 | 148 | $use = $what; |
| 149 | 149 | endif; |
| 150 | 150 | return $use; |
| 151 | 151 | } /* FeedWordPressHTTPAuthenticator::if_curl () */ |
| 152 | - | |
| 153 | - function set_auth_options ($handle, $r, $url) { | |
| 152 | + | |
| 153 | + function set_auth_options (&$handle) { | |
| 154 | 154 | if ('digest'==$this->args['authentication']) : |
| 155 | 155 | curl_setopt($handle, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST); |
| 156 | 156 | endif; |
| 157 | - | |
| 158 | - if ( !is_null($this->args['username'])) : | |
| 157 | + | |
| 158 | + if (!is_null($this->args['username'])) : | |
| 159 | 159 | $userPass = $this->args['username']; |
| 160 | - if ( !is_null($this->args['password'])) : | |
| 160 | + if (!is_null($this->args['password'])) : | |
| 161 | 161 | $userPass .= ':'.$this->args['password']; |
| 162 | 162 | endif; |
| 163 | - | |
| 163 | + | |
| 164 | 164 | curl_setopt($handle, CURLOPT_USERPWD, $userPass); |
| 165 | 165 | endif; |
| 166 | 166 | |
| 167 | 167 | } /* FeedWordPressHTTPAuthenticator::set_auth_options() */ |
| 168 | - | |
| 168 | + | |
| 169 | 169 | } /* class FeedWordPressHTTPAuthenticator */ |