File indexing completed on 2025-01-26 05:29:08
0001 <?php 0002 0003 class HTMLPurifier_URIFilter_DisableExternal extends HTMLPurifier_URIFilter 0004 { 0005 /** 0006 * @type string 0007 */ 0008 public $name = 'DisableExternal'; 0009 0010 /** 0011 * @type array 0012 */ 0013 protected $ourHostParts = false; 0014 0015 /** 0016 * @param HTMLPurifier_Config $config 0017 * @return void 0018 */ 0019 public function prepare($config) 0020 { 0021 $our_host = $config->getDefinition('URI')->host; 0022 if ($our_host !== null) { 0023 $this->ourHostParts = array_reverse(explode('.', $our_host)); 0024 } 0025 } 0026 0027 /** 0028 * @param HTMLPurifier_URI $uri Reference 0029 * @param HTMLPurifier_Config $config 0030 * @param HTMLPurifier_Context $context 0031 * @return bool 0032 */ 0033 public function filter(&$uri, $config, $context) 0034 { 0035 if (is_null($uri->host)) { 0036 return true; 0037 } 0038 if ($this->ourHostParts === false) { 0039 return false; 0040 } 0041 $host_parts = array_reverse(explode('.', $uri->host)); 0042 foreach ($this->ourHostParts as $i => $x) { 0043 if (!isset($host_parts[$i])) { 0044 return false; 0045 } 0046 if ($host_parts[$i] != $this->ourHostParts[$i]) { 0047 return false; 0048 } 0049 } 0050 return true; 0051 } 0052 } 0053 0054 // vim: et sw=4 sts=4