File indexing completed on 2025-01-26 05:29:06
0001 <?php 0002 0003 // must be called POST validation 0004 0005 /** 0006 * Adds target="blank" to all outbound links. This transform is 0007 * only attached if Attr.TargetBlank is TRUE. This works regardless 0008 * of whether or not Attr.AllowedFrameTargets 0009 */ 0010 class HTMLPurifier_AttrTransform_TargetBlank extends HTMLPurifier_AttrTransform 0011 { 0012 /** 0013 * @type HTMLPurifier_URIParser 0014 */ 0015 private $parser; 0016 0017 public function __construct() 0018 { 0019 $this->parser = new HTMLPurifier_URIParser(); 0020 } 0021 0022 /** 0023 * @param array $attr 0024 * @param HTMLPurifier_Config $config 0025 * @param HTMLPurifier_Context $context 0026 * @return array 0027 */ 0028 public function transform($attr, $config, $context) 0029 { 0030 if (!isset($attr['href'])) { 0031 return $attr; 0032 } 0033 0034 // XXX Kind of inefficient 0035 $url = $this->parser->parse($attr['href']); 0036 $scheme = $url->getSchemeObj($config, $context); 0037 0038 if ($scheme->browsable && !$url->isBenign($config, $context)) { 0039 $attr['target'] = '_blank'; 0040 } 0041 return $attr; 0042 } 0043 } 0044 0045 // vim: et sw=4 sts=4