Changeset 52393 for trunk/src/wp-includes/SimplePie/Sanitize.php
- Timestamp:
- 12/20/2021 07:31:37 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/SimplePie/Sanitize.php
r47733 r52393 72 72 var $force_fsockopen = false; 73 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 84 public function __construct() … … 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 315 public function sanitize($data, $type, $base = '') 245 316 { … … 444 515 if ($value !== false) 445 516 { 517 $value = $this->https_url($value); 446 518 $element->setAttribute($attribute, $value); 447 519 }
Note: See TracChangeset
for help on using the changeset viewer.