69 var $cache_name_function = 'md5'; |
69 var $cache_name_function = 'md5'; |
70 var $timeout = 10; |
70 var $timeout = 10; |
71 var $useragent = ''; |
71 var $useragent = ''; |
72 var $force_fsockopen = false; |
72 var $force_fsockopen = false; |
73 var $replace_url_attributes = null; |
73 var $replace_url_attributes = null; |
|
74 var $registry; |
|
75 |
|
76 /** |
|
77 * List of domains for which to force HTTPS. |
|
78 * @see SimplePie_Sanitize::set_https_domains() |
|
79 * Array is a tree split at DNS levels. Example: |
|
80 * array('biz' => true, 'com' => array('example' => true), 'net' => array('example' => array('www' => true))) |
|
81 */ |
|
82 var $https_domains = array(); |
74 |
83 |
75 public function __construct() |
84 public function __construct() |
76 { |
85 { |
77 // Set defaults |
86 // Set defaults |
78 $this->set_url_replacements(null); |
87 $this->set_url_replacements(null); |
239 ); |
248 ); |
240 } |
249 } |
241 $this->replace_url_attributes = (array) $element_attribute; |
250 $this->replace_url_attributes = (array) $element_attribute; |
242 } |
251 } |
243 |
252 |
|
253 /** |
|
254 * Set the list of domains for which to force HTTPS. |
|
255 * @see SimplePie_Misc::https_url() |
|
256 * Example array('biz', 'example.com', 'example.org', 'www.example.net'); |
|
257 */ |
|
258 public function set_https_domains($domains) |
|
259 { |
|
260 $this->https_domains = array(); |
|
261 foreach ($domains as $domain) |
|
262 { |
|
263 $domain = trim($domain, ". \t\n\r\0\x0B"); |
|
264 $segments = array_reverse(explode('.', $domain)); |
|
265 $node =& $this->https_domains; |
|
266 foreach ($segments as $segment) |
|
267 {//Build a tree |
|
268 if ($node === true) |
|
269 { |
|
270 break; |
|
271 } |
|
272 if (!isset($node[$segment])) |
|
273 { |
|
274 $node[$segment] = array(); |
|
275 } |
|
276 $node =& $node[$segment]; |
|
277 } |
|
278 $node = true; |
|
279 } |
|
280 } |
|
281 |
|
282 /** |
|
283 * Check if the domain is in the list of forced HTTPS. |
|
284 */ |
|
285 protected function is_https_domain($domain) |
|
286 { |
|
287 $domain = trim($domain, '. '); |
|
288 $segments = array_reverse(explode('.', $domain)); |
|
289 $node =& $this->https_domains; |
|
290 foreach ($segments as $segment) |
|
291 {//Explore the tree |
|
292 if (isset($node[$segment])) |
|
293 { |
|
294 $node =& $node[$segment]; |
|
295 } |
|
296 else |
|
297 { |
|
298 break; |
|
299 } |
|
300 } |
|
301 return $node === true; |
|
302 } |
|
303 |
|
304 /** |
|
305 * Force HTTPS for selected Web sites. |
|
306 */ |
|
307 public function https_url($url) |
|
308 { |
|
309 return (strtolower(substr($url, 0, 7)) === 'http://') && |
|
310 $this->is_https_domain(parse_url($url, PHP_URL_HOST)) ? |
|
311 substr_replace($url, 's', 4, 0) : //Add the 's' to HTTPS |
|
312 $url; |
|
313 } |
|
314 |
244 public function sanitize($data, $type, $base = '') |
315 public function sanitize($data, $type, $base = '') |
245 { |
316 { |
246 $data = trim($data); |
317 $data = trim($data); |
247 if ($data !== '' || $type & SIMPLEPIE_CONSTRUCT_IRI) |
318 if ($data !== '' || $type & SIMPLEPIE_CONSTRUCT_IRI) |
248 { |
319 { |
441 if ($element->hasAttribute($attribute)) |
512 if ($element->hasAttribute($attribute)) |
442 { |
513 { |
443 $value = $this->registry->call('Misc', 'absolutize_url', array($element->getAttribute($attribute), $this->base)); |
514 $value = $this->registry->call('Misc', 'absolutize_url', array($element->getAttribute($attribute), $this->base)); |
444 if ($value !== false) |
515 if ($value !== false) |
445 { |
516 { |
|
517 $value = $this->https_url($value); |
446 $element->setAttribute($attribute, $value); |
518 $element->setAttribute($attribute, $value); |
447 } |
519 } |
448 } |
520 } |
449 } |
521 } |
450 } |
522 } |