@@ -42,284 +42,284 @@ |
||
| 42 | 42 | class HTMLPurifier_Lexer |
| 43 | 43 | { |
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * Whether or not this lexer implements line-number/column-number tracking. |
|
| 47 | - * If it does, set to true. |
|
| 48 | - */ |
|
| 49 | - public $tracksLineNumbers = false; |
|
| 50 | - |
|
| 51 | - // -- STATIC ---------------------------------------------------------- |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * Retrieves or sets the default Lexer as a Prototype Factory. |
|
| 55 | - * |
|
| 56 | - * By default HTMLPurifier_Lexer_DOMLex will be returned. There are |
|
| 57 | - * a few exceptions involving special features that only DirectLex |
|
| 58 | - * implements. |
|
| 59 | - * |
|
| 60 | - * @note The behavior of this class has changed, rather than accepting |
|
| 61 | - * a prototype object, it now accepts a configuration object. |
|
| 62 | - * To specify your own prototype, set %Core.LexerImpl to it. |
|
| 63 | - * This change in behavior de-singletonizes the lexer object. |
|
| 64 | - * |
|
| 65 | - * @param $config Instance of HTMLPurifier_Config |
|
| 66 | - * @return Concrete lexer. |
|
| 67 | - */ |
|
| 68 | - public static function create($config) { |
|
| 69 | - |
|
| 70 | - if (!($config instanceof HTMLPurifier_Config)) { |
|
| 71 | - $lexer = $config; |
|
| 72 | - trigger_error("Passing a prototype to |
|
| 45 | + /** |
|
| 46 | + * Whether or not this lexer implements line-number/column-number tracking. |
|
| 47 | + * If it does, set to true. |
|
| 48 | + */ |
|
| 49 | + public $tracksLineNumbers = false; |
|
| 50 | + |
|
| 51 | + // -- STATIC ---------------------------------------------------------- |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * Retrieves or sets the default Lexer as a Prototype Factory. |
|
| 55 | + * |
|
| 56 | + * By default HTMLPurifier_Lexer_DOMLex will be returned. There are |
|
| 57 | + * a few exceptions involving special features that only DirectLex |
|
| 58 | + * implements. |
|
| 59 | + * |
|
| 60 | + * @note The behavior of this class has changed, rather than accepting |
|
| 61 | + * a prototype object, it now accepts a configuration object. |
|
| 62 | + * To specify your own prototype, set %Core.LexerImpl to it. |
|
| 63 | + * This change in behavior de-singletonizes the lexer object. |
|
| 64 | + * |
|
| 65 | + * @param $config Instance of HTMLPurifier_Config |
|
| 66 | + * @return Concrete lexer. |
|
| 67 | + */ |
|
| 68 | + public static function create($config) { |
|
| 69 | + |
|
| 70 | + if (!($config instanceof HTMLPurifier_Config)) { |
|
| 71 | + $lexer = $config; |
|
| 72 | + trigger_error("Passing a prototype to |
|
| 73 | 73 | HTMLPurifier_Lexer::create() is deprecated, please instead |
| 74 | 74 | use %Core.LexerImpl", E_USER_WARNING); |
| 75 | - } else { |
|
| 76 | - $lexer = $config->get('Core.LexerImpl'); |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - $needs_tracking = |
|
| 80 | - $config->get('Core.MaintainLineNumbers') || |
|
| 81 | - $config->get('Core.CollectErrors'); |
|
| 82 | - |
|
| 83 | - $inst = null; |
|
| 84 | - if (is_object($lexer)) { |
|
| 85 | - $inst = $lexer; |
|
| 86 | - } else { |
|
| 87 | - |
|
| 88 | - if (is_null($lexer)) { do { |
|
| 89 | - // auto-detection algorithm |
|
| 90 | - |
|
| 91 | - if ($needs_tracking) { |
|
| 92 | - $lexer = 'DirectLex'; |
|
| 93 | - break; |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - if ( |
|
| 97 | - class_exists('DOMDocument') && |
|
| 98 | - method_exists('DOMDocument', 'loadHTML') && |
|
| 99 | - !extension_loaded('domxml') |
|
| 100 | - ) { |
|
| 101 | - // check for DOM support, because while it's part of the |
|
| 102 | - // core, it can be disabled compile time. Also, the PECL |
|
| 103 | - // domxml extension overrides the default DOM, and is evil |
|
| 104 | - // and nasty and we shan't bother to support it |
|
| 105 | - $lexer = 'DOMLex'; |
|
| 106 | - } else { |
|
| 107 | - $lexer = 'DirectLex'; |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - } while(0); } // do..while so we can break |
|
| 111 | - |
|
| 112 | - // instantiate recognized string names |
|
| 113 | - switch ($lexer) { |
|
| 114 | - case 'DOMLex': |
|
| 115 | - $inst = new HTMLPurifier_Lexer_DOMLex(); |
|
| 116 | - break; |
|
| 117 | - case 'DirectLex': |
|
| 118 | - $inst = new HTMLPurifier_Lexer_DirectLex(); |
|
| 119 | - break; |
|
| 120 | - case 'PH5P': |
|
| 121 | - $inst = new HTMLPurifier_Lexer_PH5P(); |
|
| 122 | - break; |
|
| 123 | - default: |
|
| 124 | - throw new HTMLPurifier_Exception("Cannot instantiate unrecognized Lexer type " . htmlspecialchars($lexer, ENT_COMPAT | ENT_HTML401, 'UTF-8', false)); |
|
| 125 | - } |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - if (!$inst) throw new HTMLPurifier_Exception('No lexer was instantiated'); |
|
| 129 | - |
|
| 130 | - // once PHP DOM implements native line numbers, or we |
|
| 131 | - // hack out something using XSLT, remove this stipulation |
|
| 132 | - if ($needs_tracking && !$inst->tracksLineNumbers) { |
|
| 133 | - throw new HTMLPurifier_Exception('Cannot use lexer that does not support line numbers with Core.MaintainLineNumbers or Core.CollectErrors (use DirectLex instead)'); |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - return $inst; |
|
| 137 | - |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - // -- CONVENIENCE MEMBERS --------------------------------------------- |
|
| 141 | - |
|
| 142 | - public function __construct() { |
|
| 143 | - $this->_entity_parser = new HTMLPurifier_EntityParser(); |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - /** |
|
| 147 | - * Most common entity to raw value conversion table for special entities. |
|
| 148 | - */ |
|
| 149 | - protected $_special_entity2str = |
|
| 150 | - array( |
|
| 151 | - '"' => '"', |
|
| 152 | - '&' => '&', |
|
| 153 | - '<' => '<', |
|
| 154 | - '>' => '>', |
|
| 155 | - ''' => "'", |
|
| 156 | - ''' => "'", |
|
| 157 | - ''' => "'" |
|
| 158 | - ); |
|
| 159 | - |
|
| 160 | - /** |
|
| 161 | - * Parses special entities into the proper characters. |
|
| 162 | - * |
|
| 163 | - * This string will translate escaped versions of the special characters |
|
| 164 | - * into the correct ones. |
|
| 165 | - * |
|
| 166 | - * @warning |
|
| 167 | - * You should be able to treat the output of this function as |
|
| 168 | - * completely parsed, but that's only because all other entities should |
|
| 169 | - * have been handled previously in substituteNonSpecialEntities() |
|
| 170 | - * |
|
| 171 | - * @param $string String character data to be parsed. |
|
| 172 | - * @returns Parsed character data. |
|
| 173 | - */ |
|
| 174 | - public function parseData($string) { |
|
| 175 | - |
|
| 176 | - // following functions require at least one character |
|
| 177 | - if ($string === '') return ''; |
|
| 178 | - |
|
| 179 | - // subtracts amps that cannot possibly be escaped |
|
| 180 | - $num_amp = substr_count($string, '&') - substr_count($string, '& ') - |
|
| 181 | - ($string[strlen($string)-1] === '&' ? 1 : 0); |
|
| 182 | - |
|
| 183 | - if (!$num_amp) return $string; // abort if no entities |
|
| 184 | - $num_esc_amp = substr_count($string, '&'); |
|
| 185 | - $string = strtr($string, $this->_special_entity2str); |
|
| 186 | - |
|
| 187 | - // code duplication for sake of optimization, see above |
|
| 188 | - $num_amp_2 = substr_count($string, '&') - substr_count($string, '& ') - |
|
| 189 | - ($string[strlen($string)-1] === '&' ? 1 : 0); |
|
| 190 | - |
|
| 191 | - if ($num_amp_2 <= $num_esc_amp) return $string; |
|
| 192 | - |
|
| 193 | - // hmm... now we have some uncommon entities. Use the callback. |
|
| 194 | - $string = $this->_entity_parser->substituteSpecialEntities($string); |
|
| 195 | - return $string; |
|
| 196 | - } |
|
| 197 | - |
|
| 198 | - /** |
|
| 199 | - * Lexes an HTML string into tokens. |
|
| 200 | - * |
|
| 201 | - * @param $string String HTML. |
|
| 202 | - * @return HTMLPurifier_Token array representation of HTML. |
|
| 203 | - */ |
|
| 204 | - public function tokenizeHTML($string, $config, $context) { |
|
| 205 | - trigger_error('Call to abstract class', E_USER_ERROR); |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - /** |
|
| 209 | - * Translates CDATA sections into regular sections (through escaping). |
|
| 210 | - * |
|
| 211 | - * @param $string HTML string to process. |
|
| 212 | - * @returns HTML with CDATA sections escaped. |
|
| 213 | - */ |
|
| 214 | - protected static function escapeCDATA($string) { |
|
| 215 | - return preg_replace_callback( |
|
| 216 | - '/<!\[CDATA\[(.+?)\]\]>/s', |
|
| 217 | - array('HTMLPurifier_Lexer', 'CDATACallback'), |
|
| 218 | - $string |
|
| 219 | - ); |
|
| 220 | - } |
|
| 221 | - |
|
| 222 | - /** |
|
| 223 | - * Special CDATA case that is especially convoluted for <script> |
|
| 224 | - */ |
|
| 225 | - protected static function escapeCommentedCDATA($string) { |
|
| 226 | - return preg_replace_callback( |
|
| 227 | - '#<!--//--><!\[CDATA\[//><!--(.+?)//--><!\]\]>#s', |
|
| 228 | - array('HTMLPurifier_Lexer', 'CDATACallback'), |
|
| 229 | - $string |
|
| 230 | - ); |
|
| 231 | - } |
|
| 232 | - |
|
| 233 | - /** |
|
| 234 | - * Special Internet Explorer conditional comments should be removed. |
|
| 235 | - */ |
|
| 236 | - protected static function removeIEConditional($string) { |
|
| 237 | - return preg_replace( |
|
| 238 | - '#<!--\[if [^>]+\]>.*?<!\[endif\]-->#si', // probably should generalize for all strings |
|
| 239 | - '', |
|
| 240 | - $string |
|
| 241 | - ); |
|
| 242 | - } |
|
| 243 | - |
|
| 244 | - /** |
|
| 245 | - * Callback function for escapeCDATA() that does the work. |
|
| 246 | - * |
|
| 247 | - * @warning Though this is public in order to let the callback happen, |
|
| 248 | - * calling it directly is not recommended. |
|
| 249 | - * @params $matches PCRE matches array, with index 0 the entire match |
|
| 250 | - * and 1 the inside of the CDATA section. |
|
| 251 | - * @returns Escaped internals of the CDATA section. |
|
| 252 | - */ |
|
| 253 | - protected static function CDATACallback($matches) { |
|
| 254 | - // not exactly sure why the character set is needed, but whatever |
|
| 255 | - return htmlspecialchars($matches[1], ENT_COMPAT, 'UTF-8', false); |
|
| 256 | - } |
|
| 257 | - |
|
| 258 | - /** |
|
| 259 | - * Takes a piece of HTML and normalizes it by converting entities, fixing |
|
| 260 | - * encoding, extracting bits, and other good stuff. |
|
| 261 | - * @todo Consider making protected |
|
| 262 | - */ |
|
| 263 | - public function normalize($html, $config, $context) { |
|
| 264 | - |
|
| 265 | - // normalize newlines to \n |
|
| 266 | - if ($config->get('Core.NormalizeNewlines')) { |
|
| 267 | - $html = str_replace("\r\n", "\n", $html); |
|
| 268 | - $html = str_replace("\r", "\n", $html); |
|
| 269 | - } |
|
| 270 | - |
|
| 271 | - if ($config->get('HTML.Trusted')) { |
|
| 272 | - // escape convoluted CDATA |
|
| 273 | - $html = $this->escapeCommentedCDATA($html); |
|
| 274 | - } |
|
| 275 | - |
|
| 276 | - // escape CDATA |
|
| 277 | - $html = $this->escapeCDATA($html); |
|
| 278 | - |
|
| 279 | - $html = $this->removeIEConditional($html); |
|
| 280 | - |
|
| 281 | - // extract body from document if applicable |
|
| 282 | - if ($config->get('Core.ConvertDocumentToFragment')) { |
|
| 283 | - $e = false; |
|
| 284 | - if ($config->get('Core.CollectErrors')) { |
|
| 285 | - $e =& $context->get('ErrorCollector'); |
|
| 286 | - } |
|
| 287 | - $new_html = $this->extractBody($html); |
|
| 288 | - if ($e && $new_html != $html) { |
|
| 289 | - $e->send(E_WARNING, 'Lexer: Extracted body'); |
|
| 290 | - } |
|
| 291 | - $html = $new_html; |
|
| 292 | - } |
|
| 293 | - |
|
| 294 | - // expand entities that aren't the big five |
|
| 295 | - $html = $this->_entity_parser->substituteNonSpecialEntities($html); |
|
| 296 | - |
|
| 297 | - // clean into wellformed UTF-8 string for an SGML context: this has |
|
| 298 | - // to be done after entity expansion because the entities sometimes |
|
| 299 | - // represent non-SGML characters (horror, horror!) |
|
| 300 | - $html = HTMLPurifier_Encoder::cleanUTF8($html); |
|
| 301 | - |
|
| 302 | - // if processing instructions are to removed, remove them now |
|
| 303 | - if ($config->get('Core.RemoveProcessingInstructions')) { |
|
| 304 | - $html = preg_replace('#<\?.+?\?>#s', '', $html); |
|
| 305 | - } |
|
| 306 | - |
|
| 307 | - return $html; |
|
| 308 | - } |
|
| 309 | - |
|
| 310 | - /** |
|
| 311 | - * Takes a string of HTML (fragment or document) and returns the content |
|
| 312 | - * @todo Consider making protected |
|
| 313 | - */ |
|
| 314 | - public function extractBody($html) { |
|
| 315 | - $matches = array(); |
|
| 316 | - $result = preg_match('!<body[^>]*>(.*)</body>!is', $html, $matches); |
|
| 317 | - if ($result) { |
|
| 318 | - return $matches[1]; |
|
| 319 | - } else { |
|
| 320 | - return $html; |
|
| 321 | - } |
|
| 322 | - } |
|
| 75 | + } else { |
|
| 76 | + $lexer = $config->get('Core.LexerImpl'); |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + $needs_tracking = |
|
| 80 | + $config->get('Core.MaintainLineNumbers') || |
|
| 81 | + $config->get('Core.CollectErrors'); |
|
| 82 | + |
|
| 83 | + $inst = null; |
|
| 84 | + if (is_object($lexer)) { |
|
| 85 | + $inst = $lexer; |
|
| 86 | + } else { |
|
| 87 | + |
|
| 88 | + if (is_null($lexer)) { do { |
|
| 89 | + // auto-detection algorithm |
|
| 90 | + |
|
| 91 | + if ($needs_tracking) { |
|
| 92 | + $lexer = 'DirectLex'; |
|
| 93 | + break; |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + if ( |
|
| 97 | + class_exists('DOMDocument') && |
|
| 98 | + method_exists('DOMDocument', 'loadHTML') && |
|
| 99 | + !extension_loaded('domxml') |
|
| 100 | + ) { |
|
| 101 | + // check for DOM support, because while it's part of the |
|
| 102 | + // core, it can be disabled compile time. Also, the PECL |
|
| 103 | + // domxml extension overrides the default DOM, and is evil |
|
| 104 | + // and nasty and we shan't bother to support it |
|
| 105 | + $lexer = 'DOMLex'; |
|
| 106 | + } else { |
|
| 107 | + $lexer = 'DirectLex'; |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + } while(0); } // do..while so we can break |
|
| 111 | + |
|
| 112 | + // instantiate recognized string names |
|
| 113 | + switch ($lexer) { |
|
| 114 | + case 'DOMLex': |
|
| 115 | + $inst = new HTMLPurifier_Lexer_DOMLex(); |
|
| 116 | + break; |
|
| 117 | + case 'DirectLex': |
|
| 118 | + $inst = new HTMLPurifier_Lexer_DirectLex(); |
|
| 119 | + break; |
|
| 120 | + case 'PH5P': |
|
| 121 | + $inst = new HTMLPurifier_Lexer_PH5P(); |
|
| 122 | + break; |
|
| 123 | + default: |
|
| 124 | + throw new HTMLPurifier_Exception("Cannot instantiate unrecognized Lexer type " . htmlspecialchars($lexer, ENT_COMPAT | ENT_HTML401, 'UTF-8', false)); |
|
| 125 | + } |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + if (!$inst) throw new HTMLPurifier_Exception('No lexer was instantiated'); |
|
| 129 | + |
|
| 130 | + // once PHP DOM implements native line numbers, or we |
|
| 131 | + // hack out something using XSLT, remove this stipulation |
|
| 132 | + if ($needs_tracking && !$inst->tracksLineNumbers) { |
|
| 133 | + throw new HTMLPurifier_Exception('Cannot use lexer that does not support line numbers with Core.MaintainLineNumbers or Core.CollectErrors (use DirectLex instead)'); |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + return $inst; |
|
| 137 | + |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + // -- CONVENIENCE MEMBERS --------------------------------------------- |
|
| 141 | + |
|
| 142 | + public function __construct() { |
|
| 143 | + $this->_entity_parser = new HTMLPurifier_EntityParser(); |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + /** |
|
| 147 | + * Most common entity to raw value conversion table for special entities. |
|
| 148 | + */ |
|
| 149 | + protected $_special_entity2str = |
|
| 150 | + array( |
|
| 151 | + '"' => '"', |
|
| 152 | + '&' => '&', |
|
| 153 | + '<' => '<', |
|
| 154 | + '>' => '>', |
|
| 155 | + ''' => "'", |
|
| 156 | + ''' => "'", |
|
| 157 | + ''' => "'" |
|
| 158 | + ); |
|
| 159 | + |
|
| 160 | + /** |
|
| 161 | + * Parses special entities into the proper characters. |
|
| 162 | + * |
|
| 163 | + * This string will translate escaped versions of the special characters |
|
| 164 | + * into the correct ones. |
|
| 165 | + * |
|
| 166 | + * @warning |
|
| 167 | + * You should be able to treat the output of this function as |
|
| 168 | + * completely parsed, but that's only because all other entities should |
|
| 169 | + * have been handled previously in substituteNonSpecialEntities() |
|
| 170 | + * |
|
| 171 | + * @param $string String character data to be parsed. |
|
| 172 | + * @returns Parsed character data. |
|
| 173 | + */ |
|
| 174 | + public function parseData($string) { |
|
| 175 | + |
|
| 176 | + // following functions require at least one character |
|
| 177 | + if ($string === '') return ''; |
|
| 178 | + |
|
| 179 | + // subtracts amps that cannot possibly be escaped |
|
| 180 | + $num_amp = substr_count($string, '&') - substr_count($string, '& ') - |
|
| 181 | + ($string[strlen($string)-1] === '&' ? 1 : 0); |
|
| 182 | + |
|
| 183 | + if (!$num_amp) return $string; // abort if no entities |
|
| 184 | + $num_esc_amp = substr_count($string, '&'); |
|
| 185 | + $string = strtr($string, $this->_special_entity2str); |
|
| 186 | + |
|
| 187 | + // code duplication for sake of optimization, see above |
|
| 188 | + $num_amp_2 = substr_count($string, '&') - substr_count($string, '& ') - |
|
| 189 | + ($string[strlen($string)-1] === '&' ? 1 : 0); |
|
| 190 | + |
|
| 191 | + if ($num_amp_2 <= $num_esc_amp) return $string; |
|
| 192 | + |
|
| 193 | + // hmm... now we have some uncommon entities. Use the callback. |
|
| 194 | + $string = $this->_entity_parser->substituteSpecialEntities($string); |
|
| 195 | + return $string; |
|
| 196 | + } |
|
| 197 | + |
|
| 198 | + /** |
|
| 199 | + * Lexes an HTML string into tokens. |
|
| 200 | + * |
|
| 201 | + * @param $string String HTML. |
|
| 202 | + * @return HTMLPurifier_Token array representation of HTML. |
|
| 203 | + */ |
|
| 204 | + public function tokenizeHTML($string, $config, $context) { |
|
| 205 | + trigger_error('Call to abstract class', E_USER_ERROR); |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + /** |
|
| 209 | + * Translates CDATA sections into regular sections (through escaping). |
|
| 210 | + * |
|
| 211 | + * @param $string HTML string to process. |
|
| 212 | + * @returns HTML with CDATA sections escaped. |
|
| 213 | + */ |
|
| 214 | + protected static function escapeCDATA($string) { |
|
| 215 | + return preg_replace_callback( |
|
| 216 | + '/<!\[CDATA\[(.+?)\]\]>/s', |
|
| 217 | + array('HTMLPurifier_Lexer', 'CDATACallback'), |
|
| 218 | + $string |
|
| 219 | + ); |
|
| 220 | + } |
|
| 221 | + |
|
| 222 | + /** |
|
| 223 | + * Special CDATA case that is especially convoluted for <script> |
|
| 224 | + */ |
|
| 225 | + protected static function escapeCommentedCDATA($string) { |
|
| 226 | + return preg_replace_callback( |
|
| 227 | + '#<!--//--><!\[CDATA\[//><!--(.+?)//--><!\]\]>#s', |
|
| 228 | + array('HTMLPurifier_Lexer', 'CDATACallback'), |
|
| 229 | + $string |
|
| 230 | + ); |
|
| 231 | + } |
|
| 232 | + |
|
| 233 | + /** |
|
| 234 | + * Special Internet Explorer conditional comments should be removed. |
|
| 235 | + */ |
|
| 236 | + protected static function removeIEConditional($string) { |
|
| 237 | + return preg_replace( |
|
| 238 | + '#<!--\[if [^>]+\]>.*?<!\[endif\]-->#si', // probably should generalize for all strings |
|
| 239 | + '', |
|
| 240 | + $string |
|
| 241 | + ); |
|
| 242 | + } |
|
| 243 | + |
|
| 244 | + /** |
|
| 245 | + * Callback function for escapeCDATA() that does the work. |
|
| 246 | + * |
|
| 247 | + * @warning Though this is public in order to let the callback happen, |
|
| 248 | + * calling it directly is not recommended. |
|
| 249 | + * @params $matches PCRE matches array, with index 0 the entire match |
|
| 250 | + * and 1 the inside of the CDATA section. |
|
| 251 | + * @returns Escaped internals of the CDATA section. |
|
| 252 | + */ |
|
| 253 | + protected static function CDATACallback($matches) { |
|
| 254 | + // not exactly sure why the character set is needed, but whatever |
|
| 255 | + return htmlspecialchars($matches[1], ENT_COMPAT, 'UTF-8', false); |
|
| 256 | + } |
|
| 257 | + |
|
| 258 | + /** |
|
| 259 | + * Takes a piece of HTML and normalizes it by converting entities, fixing |
|
| 260 | + * encoding, extracting bits, and other good stuff. |
|
| 261 | + * @todo Consider making protected |
|
| 262 | + */ |
|
| 263 | + public function normalize($html, $config, $context) { |
|
| 264 | + |
|
| 265 | + // normalize newlines to \n |
|
| 266 | + if ($config->get('Core.NormalizeNewlines')) { |
|
| 267 | + $html = str_replace("\r\n", "\n", $html); |
|
| 268 | + $html = str_replace("\r", "\n", $html); |
|
| 269 | + } |
|
| 270 | + |
|
| 271 | + if ($config->get('HTML.Trusted')) { |
|
| 272 | + // escape convoluted CDATA |
|
| 273 | + $html = $this->escapeCommentedCDATA($html); |
|
| 274 | + } |
|
| 275 | + |
|
| 276 | + // escape CDATA |
|
| 277 | + $html = $this->escapeCDATA($html); |
|
| 278 | + |
|
| 279 | + $html = $this->removeIEConditional($html); |
|
| 280 | + |
|
| 281 | + // extract body from document if applicable |
|
| 282 | + if ($config->get('Core.ConvertDocumentToFragment')) { |
|
| 283 | + $e = false; |
|
| 284 | + if ($config->get('Core.CollectErrors')) { |
|
| 285 | + $e =& $context->get('ErrorCollector'); |
|
| 286 | + } |
|
| 287 | + $new_html = $this->extractBody($html); |
|
| 288 | + if ($e && $new_html != $html) { |
|
| 289 | + $e->send(E_WARNING, 'Lexer: Extracted body'); |
|
| 290 | + } |
|
| 291 | + $html = $new_html; |
|
| 292 | + } |
|
| 293 | + |
|
| 294 | + // expand entities that aren't the big five |
|
| 295 | + $html = $this->_entity_parser->substituteNonSpecialEntities($html); |
|
| 296 | + |
|
| 297 | + // clean into wellformed UTF-8 string for an SGML context: this has |
|
| 298 | + // to be done after entity expansion because the entities sometimes |
|
| 299 | + // represent non-SGML characters (horror, horror!) |
|
| 300 | + $html = HTMLPurifier_Encoder::cleanUTF8($html); |
|
| 301 | + |
|
| 302 | + // if processing instructions are to removed, remove them now |
|
| 303 | + if ($config->get('Core.RemoveProcessingInstructions')) { |
|
| 304 | + $html = preg_replace('#<\?.+?\?>#s', '', $html); |
|
| 305 | + } |
|
| 306 | + |
|
| 307 | + return $html; |
|
| 308 | + } |
|
| 309 | + |
|
| 310 | + /** |
|
| 311 | + * Takes a string of HTML (fragment or document) and returns the content |
|
| 312 | + * @todo Consider making protected |
|
| 313 | + */ |
|
| 314 | + public function extractBody($html) { |
|
| 315 | + $matches = array(); |
|
| 316 | + $result = preg_match('!<body[^>]*>(.*)</body>!is', $html, $matches); |
|
| 317 | + if ($result) { |
|
| 318 | + return $matches[1]; |
|
| 319 | + } else { |
|
| 320 | + return $html; |
|
| 321 | + } |
|
| 322 | + } |
|
| 323 | 323 | |
| 324 | 324 | } |
| 325 | 325 | |
@@ -125,7 +125,9 @@ discard block |
||
| 125 | 125 | } |
| 126 | 126 | } |
| 127 | 127 | |
| 128 | - if (!$inst) throw new HTMLPurifier_Exception('No lexer was instantiated'); |
|
| 128 | + if (!$inst) { |
|
| 129 | + throw new HTMLPurifier_Exception('No lexer was instantiated'); |
|
| 130 | + } |
|
| 129 | 131 | |
| 130 | 132 | // once PHP DOM implements native line numbers, or we |
| 131 | 133 | // hack out something using XSLT, remove this stipulation |
@@ -174,13 +176,18 @@ discard block |
||
| 174 | 176 | public function parseData($string) { |
| 175 | 177 | |
| 176 | 178 | // following functions require at least one character |
| 177 | - if ($string === '') return ''; |
|
| 179 | + if ($string === '') { |
|
| 180 | + return ''; |
|
| 181 | + } |
|
| 178 | 182 | |
| 179 | 183 | // subtracts amps that cannot possibly be escaped |
| 180 | 184 | $num_amp = substr_count($string, '&') - substr_count($string, '& ') - |
| 181 | 185 | ($string[strlen($string)-1] === '&' ? 1 : 0); |
| 182 | 186 | |
| 183 | - if (!$num_amp) return $string; // abort if no entities |
|
| 187 | + if (!$num_amp) { |
|
| 188 | + return $string; |
|
| 189 | + } |
|
| 190 | + // abort if no entities |
|
| 184 | 191 | $num_esc_amp = substr_count($string, '&'); |
| 185 | 192 | $string = strtr($string, $this->_special_entity2str); |
| 186 | 193 | |
@@ -188,7 +195,9 @@ discard block |
||
| 188 | 195 | $num_amp_2 = substr_count($string, '&') - substr_count($string, '& ') - |
| 189 | 196 | ($string[strlen($string)-1] === '&' ? 1 : 0); |
| 190 | 197 | |
| 191 | - if ($num_amp_2 <= $num_esc_amp) return $string; |
|
| 198 | + if ($num_amp_2 <= $num_esc_amp) { |
|
| 199 | + return $string; |
|
| 200 | + } |
|
| 192 | 201 | |
| 193 | 202 | // hmm... now we have some uncommon entities. Use the callback. |
| 194 | 203 | $string = $this->_entity_parser->substituteSpecialEntities($string); |
@@ -107,7 +107,7 @@ discard block |
||
| 107 | 107 | $lexer = 'DirectLex'; |
| 108 | 108 | } |
| 109 | 109 | |
| 110 | - } while(0); } // do..while so we can break |
|
| 110 | + } while (0); } // do..while so we can break |
|
| 111 | 111 | |
| 112 | 112 | // instantiate recognized string names |
| 113 | 113 | switch ($lexer) { |
@@ -121,7 +121,7 @@ discard block |
||
| 121 | 121 | $inst = new HTMLPurifier_Lexer_PH5P(); |
| 122 | 122 | break; |
| 123 | 123 | default: |
| 124 | - throw new HTMLPurifier_Exception("Cannot instantiate unrecognized Lexer type " . htmlspecialchars($lexer, ENT_COMPAT | ENT_HTML401, 'UTF-8', false)); |
|
| 124 | + throw new HTMLPurifier_Exception("Cannot instantiate unrecognized Lexer type ".htmlspecialchars($lexer, ENT_COMPAT | ENT_HTML401, 'UTF-8', false)); |
|
| 125 | 125 | } |
| 126 | 126 | } |
| 127 | 127 | |
@@ -178,7 +178,7 @@ discard block |
||
| 178 | 178 | |
| 179 | 179 | // subtracts amps that cannot possibly be escaped |
| 180 | 180 | $num_amp = substr_count($string, '&') - substr_count($string, '& ') - |
| 181 | - ($string[strlen($string)-1] === '&' ? 1 : 0); |
|
| 181 | + ($string[strlen($string) - 1] === '&' ? 1 : 0); |
|
| 182 | 182 | |
| 183 | 183 | if (!$num_amp) return $string; // abort if no entities |
| 184 | 184 | $num_esc_amp = substr_count($string, '&'); |
@@ -186,7 +186,7 @@ discard block |
||
| 186 | 186 | |
| 187 | 187 | // code duplication for sake of optimization, see above |
| 188 | 188 | $num_amp_2 = substr_count($string, '&') - substr_count($string, '& ') - |
| 189 | - ($string[strlen($string)-1] === '&' ? 1 : 0); |
|
| 189 | + ($string[strlen($string) - 1] === '&' ? 1 : 0); |
|
| 190 | 190 | |
| 191 | 191 | if ($num_amp_2 <= $num_esc_amp) return $string; |
| 192 | 192 | |
@@ -282,7 +282,7 @@ discard block |
||
| 282 | 282 | if ($config->get('Core.ConvertDocumentToFragment')) { |
| 283 | 283 | $e = false; |
| 284 | 284 | if ($config->get('Core.CollectErrors')) { |
| 285 | - $e =& $context->get('ErrorCollector'); |
|
| 285 | + $e = & $context->get('ErrorCollector'); |
|
| 286 | 286 | } |
| 287 | 287 | $new_html = $this->extractBody($html); |
| 288 | 288 | if ($e && $new_html != $html) { |
@@ -11,87 +11,87 @@ |
||
| 11 | 11 | class HTMLPurifier_PercentEncoder |
| 12 | 12 | { |
| 13 | 13 | |
| 14 | - /** |
|
| 15 | - * Reserved characters to preserve when using encode(). |
|
| 16 | - */ |
|
| 17 | - protected $preserve = array(); |
|
| 14 | + /** |
|
| 15 | + * Reserved characters to preserve when using encode(). |
|
| 16 | + */ |
|
| 17 | + protected $preserve = array(); |
|
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * String of characters that should be preserved while using encode(). |
|
| 21 | - */ |
|
| 22 | - public function __construct($preserve = false) { |
|
| 23 | - // unreserved letters, ought to const-ify |
|
| 24 | - for ($i = 48; $i <= 57; $i++) $this->preserve[$i] = true; // digits |
|
| 25 | - for ($i = 65; $i <= 90; $i++) $this->preserve[$i] = true; // upper-case |
|
| 26 | - for ($i = 97; $i <= 122; $i++) $this->preserve[$i] = true; // lower-case |
|
| 27 | - $this->preserve[45] = true; // Dash - |
|
| 28 | - $this->preserve[46] = true; // Period . |
|
| 29 | - $this->preserve[95] = true; // Underscore _ |
|
| 30 | - $this->preserve[126]= true; // Tilde ~ |
|
| 19 | + /** |
|
| 20 | + * String of characters that should be preserved while using encode(). |
|
| 21 | + */ |
|
| 22 | + public function __construct($preserve = false) { |
|
| 23 | + // unreserved letters, ought to const-ify |
|
| 24 | + for ($i = 48; $i <= 57; $i++) $this->preserve[$i] = true; // digits |
|
| 25 | + for ($i = 65; $i <= 90; $i++) $this->preserve[$i] = true; // upper-case |
|
| 26 | + for ($i = 97; $i <= 122; $i++) $this->preserve[$i] = true; // lower-case |
|
| 27 | + $this->preserve[45] = true; // Dash - |
|
| 28 | + $this->preserve[46] = true; // Period . |
|
| 29 | + $this->preserve[95] = true; // Underscore _ |
|
| 30 | + $this->preserve[126]= true; // Tilde ~ |
|
| 31 | 31 | |
| 32 | - // extra letters not to escape |
|
| 33 | - if ($preserve !== false) { |
|
| 34 | - for ($i = 0, $c = strlen($preserve); $i < $c; $i++) { |
|
| 35 | - $this->preserve[ord($preserve[$i])] = true; |
|
| 36 | - } |
|
| 37 | - } |
|
| 38 | - } |
|
| 32 | + // extra letters not to escape |
|
| 33 | + if ($preserve !== false) { |
|
| 34 | + for ($i = 0, $c = strlen($preserve); $i < $c; $i++) { |
|
| 35 | + $this->preserve[ord($preserve[$i])] = true; |
|
| 36 | + } |
|
| 37 | + } |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * Our replacement for urlencode, it encodes all non-reserved characters, |
|
| 42 | - * as well as any extra characters that were instructed to be preserved. |
|
| 43 | - * @note |
|
| 44 | - * Assumes that the string has already been normalized, making any |
|
| 45 | - * and all percent escape sequences valid. Percents will not be |
|
| 46 | - * re-escaped, regardless of their status in $preserve |
|
| 47 | - * @param $string String to be encoded |
|
| 48 | - * @return Encoded string. |
|
| 49 | - */ |
|
| 50 | - public function encode($string) { |
|
| 51 | - $ret = ''; |
|
| 52 | - for ($i = 0, $c = strlen($string); $i < $c; $i++) { |
|
| 53 | - if ($string[$i] !== '%' && !isset($this->preserve[$int = ord($string[$i])]) ) { |
|
| 54 | - $ret .= '%' . sprintf('%02X', $int); |
|
| 55 | - } else { |
|
| 56 | - $ret .= $string[$i]; |
|
| 57 | - } |
|
| 58 | - } |
|
| 59 | - return $ret; |
|
| 60 | - } |
|
| 40 | + /** |
|
| 41 | + * Our replacement for urlencode, it encodes all non-reserved characters, |
|
| 42 | + * as well as any extra characters that were instructed to be preserved. |
|
| 43 | + * @note |
|
| 44 | + * Assumes that the string has already been normalized, making any |
|
| 45 | + * and all percent escape sequences valid. Percents will not be |
|
| 46 | + * re-escaped, regardless of their status in $preserve |
|
| 47 | + * @param $string String to be encoded |
|
| 48 | + * @return Encoded string. |
|
| 49 | + */ |
|
| 50 | + public function encode($string) { |
|
| 51 | + $ret = ''; |
|
| 52 | + for ($i = 0, $c = strlen($string); $i < $c; $i++) { |
|
| 53 | + if ($string[$i] !== '%' && !isset($this->preserve[$int = ord($string[$i])]) ) { |
|
| 54 | + $ret .= '%' . sprintf('%02X', $int); |
|
| 55 | + } else { |
|
| 56 | + $ret .= $string[$i]; |
|
| 57 | + } |
|
| 58 | + } |
|
| 59 | + return $ret; |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - /** |
|
| 63 | - * Fix up percent-encoding by decoding unreserved characters and normalizing. |
|
| 64 | - * @warning This function is affected by $preserve, even though the |
|
| 65 | - * usual desired behavior is for this not to preserve those |
|
| 66 | - * characters. Be careful when reusing instances of PercentEncoder! |
|
| 67 | - * @param $string String to normalize |
|
| 68 | - */ |
|
| 69 | - public function normalize($string) { |
|
| 70 | - if ($string == '') return ''; |
|
| 71 | - $parts = explode('%', $string); |
|
| 72 | - $ret = array_shift($parts); |
|
| 73 | - foreach ($parts as $part) { |
|
| 74 | - $length = strlen($part); |
|
| 75 | - if ($length < 2) { |
|
| 76 | - $ret .= '%25' . $part; |
|
| 77 | - continue; |
|
| 78 | - } |
|
| 79 | - $encoding = substr($part, 0, 2); |
|
| 80 | - $text = substr($part, 2); |
|
| 81 | - if (!ctype_xdigit($encoding)) { |
|
| 82 | - $ret .= '%25' . $part; |
|
| 83 | - continue; |
|
| 84 | - } |
|
| 85 | - $int = hexdec($encoding); |
|
| 86 | - if (isset($this->preserve[$int])) { |
|
| 87 | - $ret .= chr($int) . $text; |
|
| 88 | - continue; |
|
| 89 | - } |
|
| 90 | - $encoding = strtoupper($encoding); |
|
| 91 | - $ret .= '%' . $encoding . $text; |
|
| 92 | - } |
|
| 93 | - return $ret; |
|
| 94 | - } |
|
| 62 | + /** |
|
| 63 | + * Fix up percent-encoding by decoding unreserved characters and normalizing. |
|
| 64 | + * @warning This function is affected by $preserve, even though the |
|
| 65 | + * usual desired behavior is for this not to preserve those |
|
| 66 | + * characters. Be careful when reusing instances of PercentEncoder! |
|
| 67 | + * @param $string String to normalize |
|
| 68 | + */ |
|
| 69 | + public function normalize($string) { |
|
| 70 | + if ($string == '') return ''; |
|
| 71 | + $parts = explode('%', $string); |
|
| 72 | + $ret = array_shift($parts); |
|
| 73 | + foreach ($parts as $part) { |
|
| 74 | + $length = strlen($part); |
|
| 75 | + if ($length < 2) { |
|
| 76 | + $ret .= '%25' . $part; |
|
| 77 | + continue; |
|
| 78 | + } |
|
| 79 | + $encoding = substr($part, 0, 2); |
|
| 80 | + $text = substr($part, 2); |
|
| 81 | + if (!ctype_xdigit($encoding)) { |
|
| 82 | + $ret .= '%25' . $part; |
|
| 83 | + continue; |
|
| 84 | + } |
|
| 85 | + $int = hexdec($encoding); |
|
| 86 | + if (isset($this->preserve[$int])) { |
|
| 87 | + $ret .= chr($int) . $text; |
|
| 88 | + continue; |
|
| 89 | + } |
|
| 90 | + $encoding = strtoupper($encoding); |
|
| 91 | + $ret .= '%' . $encoding . $text; |
|
| 92 | + } |
|
| 93 | + return $ret; |
|
| 94 | + } |
|
| 95 | 95 | |
| 96 | 96 | } |
| 97 | 97 | |
@@ -21,9 +21,18 @@ discard block |
||
| 21 | 21 | */ |
| 22 | 22 | public function __construct($preserve = false) { |
| 23 | 23 | // unreserved letters, ought to const-ify |
| 24 | - for ($i = 48; $i <= 57; $i++) $this->preserve[$i] = true; // digits |
|
| 25 | - for ($i = 65; $i <= 90; $i++) $this->preserve[$i] = true; // upper-case |
|
| 26 | - for ($i = 97; $i <= 122; $i++) $this->preserve[$i] = true; // lower-case |
|
| 24 | + for ($i = 48; $i <= 57; $i++) { |
|
| 25 | + $this->preserve[$i] = true; |
|
| 26 | + } |
|
| 27 | + // digits |
|
| 28 | + for ($i = 65; $i <= 90; $i++) { |
|
| 29 | + $this->preserve[$i] = true; |
|
| 30 | + } |
|
| 31 | + // upper-case |
|
| 32 | + for ($i = 97; $i <= 122; $i++) { |
|
| 33 | + $this->preserve[$i] = true; |
|
| 34 | + } |
|
| 35 | + // lower-case |
|
| 27 | 36 | $this->preserve[45] = true; // Dash - |
| 28 | 37 | $this->preserve[46] = true; // Period . |
| 29 | 38 | $this->preserve[95] = true; // Underscore _ |
@@ -67,7 +76,9 @@ discard block |
||
| 67 | 76 | * @param $string String to normalize |
| 68 | 77 | */ |
| 69 | 78 | public function normalize($string) { |
| 70 | - if ($string == '') return ''; |
|
| 79 | + if ($string == '') { |
|
| 80 | + return ''; |
|
| 81 | + } |
|
| 71 | 82 | $parts = explode('%', $string); |
| 72 | 83 | $ret = array_shift($parts); |
| 73 | 84 | foreach ($parts as $part) { |
@@ -21,13 +21,13 @@ discard block |
||
| 21 | 21 | */ |
| 22 | 22 | public function __construct($preserve = false) { |
| 23 | 23 | // unreserved letters, ought to const-ify |
| 24 | - for ($i = 48; $i <= 57; $i++) $this->preserve[$i] = true; // digits |
|
| 25 | - for ($i = 65; $i <= 90; $i++) $this->preserve[$i] = true; // upper-case |
|
| 24 | + for ($i = 48; $i <= 57; $i++) $this->preserve[$i] = true; // digits |
|
| 25 | + for ($i = 65; $i <= 90; $i++) $this->preserve[$i] = true; // upper-case |
|
| 26 | 26 | for ($i = 97; $i <= 122; $i++) $this->preserve[$i] = true; // lower-case |
| 27 | 27 | $this->preserve[45] = true; // Dash - |
| 28 | 28 | $this->preserve[46] = true; // Period . |
| 29 | 29 | $this->preserve[95] = true; // Underscore _ |
| 30 | - $this->preserve[126]= true; // Tilde ~ |
|
| 30 | + $this->preserve[126] = true; // Tilde ~ |
|
| 31 | 31 | |
| 32 | 32 | // extra letters not to escape |
| 33 | 33 | if ($preserve !== false) { |
@@ -50,8 +50,8 @@ discard block |
||
| 50 | 50 | public function encode($string) { |
| 51 | 51 | $ret = ''; |
| 52 | 52 | for ($i = 0, $c = strlen($string); $i < $c; $i++) { |
| 53 | - if ($string[$i] !== '%' && !isset($this->preserve[$int = ord($string[$i])]) ) { |
|
| 54 | - $ret .= '%' . sprintf('%02X', $int); |
|
| 53 | + if ($string[$i] !== '%' && !isset($this->preserve[$int = ord($string[$i])])) { |
|
| 54 | + $ret .= '%'.sprintf('%02X', $int); |
|
| 55 | 55 | } else { |
| 56 | 56 | $ret .= $string[$i]; |
| 57 | 57 | } |
@@ -73,22 +73,22 @@ discard block |
||
| 73 | 73 | foreach ($parts as $part) { |
| 74 | 74 | $length = strlen($part); |
| 75 | 75 | if ($length < 2) { |
| 76 | - $ret .= '%25' . $part; |
|
| 76 | + $ret .= '%25'.$part; |
|
| 77 | 77 | continue; |
| 78 | 78 | } |
| 79 | 79 | $encoding = substr($part, 0, 2); |
| 80 | 80 | $text = substr($part, 2); |
| 81 | 81 | if (!ctype_xdigit($encoding)) { |
| 82 | - $ret .= '%25' . $part; |
|
| 82 | + $ret .= '%25'.$part; |
|
| 83 | 83 | continue; |
| 84 | 84 | } |
| 85 | 85 | $int = hexdec($encoding); |
| 86 | 86 | if (isset($this->preserve[$int])) { |
| 87 | - $ret .= chr($int) . $text; |
|
| 87 | + $ret .= chr($int).$text; |
|
| 88 | 88 | continue; |
| 89 | 89 | } |
| 90 | 90 | $encoding = strtoupper($encoding); |
| 91 | - $ret .= '%' . $encoding . $text; |
|
| 91 | + $ret .= '%'.$encoding.$text; |
|
| 92 | 92 | } |
| 93 | 93 | return $ret; |
| 94 | 94 | } |
@@ -3,35 +3,35 @@ |
||
| 3 | 3 | class HTMLPurifier_Printer_CSSDefinition extends HTMLPurifier_Printer |
| 4 | 4 | { |
| 5 | 5 | |
| 6 | - protected $def; |
|
| 6 | + protected $def; |
|
| 7 | 7 | |
| 8 | - public function render($config) { |
|
| 9 | - $this->def = $config->getCSSDefinition(); |
|
| 10 | - $ret = ''; |
|
| 8 | + public function render($config) { |
|
| 9 | + $this->def = $config->getCSSDefinition(); |
|
| 10 | + $ret = ''; |
|
| 11 | 11 | |
| 12 | - $ret .= $this->start('div', array('class' => 'HTMLPurifier_Printer')); |
|
| 13 | - $ret .= $this->start('table'); |
|
| 12 | + $ret .= $this->start('div', array('class' => 'HTMLPurifier_Printer')); |
|
| 13 | + $ret .= $this->start('table'); |
|
| 14 | 14 | |
| 15 | - $ret .= $this->element('caption', 'Properties ($info)'); |
|
| 15 | + $ret .= $this->element('caption', 'Properties ($info)'); |
|
| 16 | 16 | |
| 17 | - $ret .= $this->start('thead'); |
|
| 18 | - $ret .= $this->start('tr'); |
|
| 19 | - $ret .= $this->element('th', 'Property', array('class' => 'heavy')); |
|
| 20 | - $ret .= $this->element('th', 'Definition', array('class' => 'heavy', 'style' => 'width:auto;')); |
|
| 21 | - $ret .= $this->end('tr'); |
|
| 22 | - $ret .= $this->end('thead'); |
|
| 17 | + $ret .= $this->start('thead'); |
|
| 18 | + $ret .= $this->start('tr'); |
|
| 19 | + $ret .= $this->element('th', 'Property', array('class' => 'heavy')); |
|
| 20 | + $ret .= $this->element('th', 'Definition', array('class' => 'heavy', 'style' => 'width:auto;')); |
|
| 21 | + $ret .= $this->end('tr'); |
|
| 22 | + $ret .= $this->end('thead'); |
|
| 23 | 23 | |
| 24 | - ksort($this->def->info); |
|
| 25 | - foreach ($this->def->info as $property => $obj) { |
|
| 26 | - $name = $this->getClass($obj, 'AttrDef_'); |
|
| 27 | - $ret .= $this->row($property, $name); |
|
| 28 | - } |
|
| 24 | + ksort($this->def->info); |
|
| 25 | + foreach ($this->def->info as $property => $obj) { |
|
| 26 | + $name = $this->getClass($obj, 'AttrDef_'); |
|
| 27 | + $ret .= $this->row($property, $name); |
|
| 28 | + } |
|
| 29 | 29 | |
| 30 | - $ret .= $this->end('table'); |
|
| 31 | - $ret .= $this->end('div'); |
|
| 30 | + $ret .= $this->end('table'); |
|
| 31 | + $ret .= $this->end('div'); |
|
| 32 | 32 | |
| 33 | - return $ret; |
|
| 34 | - } |
|
| 33 | + return $ret; |
|
| 34 | + } |
|
| 35 | 35 | |
| 36 | 36 | } |
| 37 | 37 | |
@@ -6,179 +6,179 @@ discard block |
||
| 6 | 6 | class HTMLPurifier_Printer_ConfigForm extends HTMLPurifier_Printer |
| 7 | 7 | { |
| 8 | 8 | |
| 9 | - /** |
|
| 10 | - * Printers for specific fields |
|
| 11 | - */ |
|
| 12 | - protected $fields = array(); |
|
| 9 | + /** |
|
| 10 | + * Printers for specific fields |
|
| 11 | + */ |
|
| 12 | + protected $fields = array(); |
|
| 13 | 13 | |
| 14 | - /** |
|
| 15 | - * Documentation URL, can have fragment tagged on end |
|
| 16 | - */ |
|
| 17 | - protected $docURL; |
|
| 14 | + /** |
|
| 15 | + * Documentation URL, can have fragment tagged on end |
|
| 16 | + */ |
|
| 17 | + protected $docURL; |
|
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * Name of form element to stuff config in |
|
| 21 | - */ |
|
| 22 | - protected $name; |
|
| 19 | + /** |
|
| 20 | + * Name of form element to stuff config in |
|
| 21 | + */ |
|
| 22 | + protected $name; |
|
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * Whether or not to compress directive names, clipping them off |
|
| 26 | - * after a certain amount of letters. False to disable or integer letters |
|
| 27 | - * before clipping. |
|
| 28 | - */ |
|
| 29 | - protected $compress = false; |
|
| 24 | + /** |
|
| 25 | + * Whether or not to compress directive names, clipping them off |
|
| 26 | + * after a certain amount of letters. False to disable or integer letters |
|
| 27 | + * before clipping. |
|
| 28 | + */ |
|
| 29 | + protected $compress = false; |
|
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * @param $name Form element name for directives to be stuffed into |
|
| 33 | - * @param $doc_url String documentation URL, will have fragment tagged on |
|
| 34 | - * @param $compress Integer max length before compressing a directive name, set to false to turn off |
|
| 35 | - */ |
|
| 36 | - public function __construct( |
|
| 37 | - $name, $doc_url = null, $compress = false |
|
| 38 | - ) { |
|
| 39 | - parent::__construct(); |
|
| 40 | - $this->docURL = $doc_url; |
|
| 41 | - $this->name = $name; |
|
| 42 | - $this->compress = $compress; |
|
| 43 | - // initialize sub-printers |
|
| 44 | - $this->fields[0] = new HTMLPurifier_Printer_ConfigForm_default(); |
|
| 45 | - $this->fields[HTMLPurifier_VarParser::BOOL] = new HTMLPurifier_Printer_ConfigForm_bool(); |
|
| 46 | - } |
|
| 31 | + /** |
|
| 32 | + * @param $name Form element name for directives to be stuffed into |
|
| 33 | + * @param $doc_url String documentation URL, will have fragment tagged on |
|
| 34 | + * @param $compress Integer max length before compressing a directive name, set to false to turn off |
|
| 35 | + */ |
|
| 36 | + public function __construct( |
|
| 37 | + $name, $doc_url = null, $compress = false |
|
| 38 | + ) { |
|
| 39 | + parent::__construct(); |
|
| 40 | + $this->docURL = $doc_url; |
|
| 41 | + $this->name = $name; |
|
| 42 | + $this->compress = $compress; |
|
| 43 | + // initialize sub-printers |
|
| 44 | + $this->fields[0] = new HTMLPurifier_Printer_ConfigForm_default(); |
|
| 45 | + $this->fields[HTMLPurifier_VarParser::BOOL] = new HTMLPurifier_Printer_ConfigForm_bool(); |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * Sets default column and row size for textareas in sub-printers |
|
| 50 | - * @param $cols Integer columns of textarea, null to use default |
|
| 51 | - * @param $rows Integer rows of textarea, null to use default |
|
| 52 | - */ |
|
| 53 | - public function setTextareaDimensions($cols = null, $rows = null) { |
|
| 54 | - if ($cols) $this->fields['default']->cols = $cols; |
|
| 55 | - if ($rows) $this->fields['default']->rows = $rows; |
|
| 56 | - } |
|
| 48 | + /** |
|
| 49 | + * Sets default column and row size for textareas in sub-printers |
|
| 50 | + * @param $cols Integer columns of textarea, null to use default |
|
| 51 | + * @param $rows Integer rows of textarea, null to use default |
|
| 52 | + */ |
|
| 53 | + public function setTextareaDimensions($cols = null, $rows = null) { |
|
| 54 | + if ($cols) $this->fields['default']->cols = $cols; |
|
| 55 | + if ($rows) $this->fields['default']->rows = $rows; |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | - /** |
|
| 59 | - * Retrieves styling, in case it is not accessible by webserver |
|
| 60 | - */ |
|
| 61 | - public static function getCSS() { |
|
| 62 | - return file_get_contents(HTMLPURIFIER_PREFIX . '/HTMLPurifier/Printer/ConfigForm.css'); |
|
| 63 | - } |
|
| 58 | + /** |
|
| 59 | + * Retrieves styling, in case it is not accessible by webserver |
|
| 60 | + */ |
|
| 61 | + public static function getCSS() { |
|
| 62 | + return file_get_contents(HTMLPURIFIER_PREFIX . '/HTMLPurifier/Printer/ConfigForm.css'); |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | - /** |
|
| 66 | - * Retrieves JavaScript, in case it is not accessible by webserver |
|
| 67 | - */ |
|
| 68 | - public static function getJavaScript() { |
|
| 69 | - return file_get_contents(HTMLPURIFIER_PREFIX . '/HTMLPurifier/Printer/ConfigForm.js'); |
|
| 70 | - } |
|
| 65 | + /** |
|
| 66 | + * Retrieves JavaScript, in case it is not accessible by webserver |
|
| 67 | + */ |
|
| 68 | + public static function getJavaScript() { |
|
| 69 | + return file_get_contents(HTMLPURIFIER_PREFIX . '/HTMLPurifier/Printer/ConfigForm.js'); |
|
| 70 | + } |
|
| 71 | 71 | |
| 72 | - /** |
|
| 73 | - * Returns HTML output for a configuration form |
|
| 74 | - * @param $config Configuration object of current form state, or an array |
|
| 75 | - * where [0] has an HTML namespace and [1] is being rendered. |
|
| 76 | - * @param $allowed Optional namespace(s) and directives to restrict form to. |
|
| 77 | - */ |
|
| 78 | - public function render($config, $allowed = true, $render_controls = true) { |
|
| 79 | - if (is_array($config) && isset($config[0])) { |
|
| 80 | - $gen_config = $config[0]; |
|
| 81 | - $config = $config[1]; |
|
| 82 | - } else { |
|
| 83 | - $gen_config = $config; |
|
| 84 | - } |
|
| 72 | + /** |
|
| 73 | + * Returns HTML output for a configuration form |
|
| 74 | + * @param $config Configuration object of current form state, or an array |
|
| 75 | + * where [0] has an HTML namespace and [1] is being rendered. |
|
| 76 | + * @param $allowed Optional namespace(s) and directives to restrict form to. |
|
| 77 | + */ |
|
| 78 | + public function render($config, $allowed = true, $render_controls = true) { |
|
| 79 | + if (is_array($config) && isset($config[0])) { |
|
| 80 | + $gen_config = $config[0]; |
|
| 81 | + $config = $config[1]; |
|
| 82 | + } else { |
|
| 83 | + $gen_config = $config; |
|
| 84 | + } |
|
| 85 | 85 | |
| 86 | - $this->config = $config; |
|
| 87 | - $this->genConfig = $gen_config; |
|
| 88 | - $this->prepareGenerator($gen_config); |
|
| 86 | + $this->config = $config; |
|
| 87 | + $this->genConfig = $gen_config; |
|
| 88 | + $this->prepareGenerator($gen_config); |
|
| 89 | 89 | |
| 90 | - $allowed = HTMLPurifier_Config::getAllowedDirectivesForForm($allowed, $config->def); |
|
| 91 | - $all = array(); |
|
| 92 | - foreach ($allowed as $key) { |
|
| 93 | - list($ns, $directive) = $key; |
|
| 94 | - $all[$ns][$directive] = $config->get($ns .'.'. $directive); |
|
| 95 | - } |
|
| 90 | + $allowed = HTMLPurifier_Config::getAllowedDirectivesForForm($allowed, $config->def); |
|
| 91 | + $all = array(); |
|
| 92 | + foreach ($allowed as $key) { |
|
| 93 | + list($ns, $directive) = $key; |
|
| 94 | + $all[$ns][$directive] = $config->get($ns .'.'. $directive); |
|
| 95 | + } |
|
| 96 | 96 | |
| 97 | - $ret = ''; |
|
| 98 | - $ret .= $this->start('table', array('class' => 'hp-config')); |
|
| 99 | - $ret .= $this->start('thead'); |
|
| 100 | - $ret .= $this->start('tr'); |
|
| 101 | - $ret .= $this->element('th', 'Directive', array('class' => 'hp-directive')); |
|
| 102 | - $ret .= $this->element('th', 'Value', array('class' => 'hp-value')); |
|
| 103 | - $ret .= $this->end('tr'); |
|
| 104 | - $ret .= $this->end('thead'); |
|
| 105 | - foreach ($all as $ns => $directives) { |
|
| 106 | - $ret .= $this->renderNamespace($ns, $directives); |
|
| 107 | - } |
|
| 108 | - if ($render_controls) { |
|
| 109 | - $ret .= $this->start('tbody'); |
|
| 110 | - $ret .= $this->start('tr'); |
|
| 111 | - $ret .= $this->start('td', array('colspan' => 2, 'class' => 'controls')); |
|
| 112 | - $ret .= $this->elementEmpty('input', array('type' => 'submit', 'value' => 'Submit')); |
|
| 113 | - $ret .= '[<a href="?">Reset</a>]'; |
|
| 114 | - $ret .= $this->end('td'); |
|
| 115 | - $ret .= $this->end('tr'); |
|
| 116 | - $ret .= $this->end('tbody'); |
|
| 117 | - } |
|
| 118 | - $ret .= $this->end('table'); |
|
| 119 | - return $ret; |
|
| 120 | - } |
|
| 97 | + $ret = ''; |
|
| 98 | + $ret .= $this->start('table', array('class' => 'hp-config')); |
|
| 99 | + $ret .= $this->start('thead'); |
|
| 100 | + $ret .= $this->start('tr'); |
|
| 101 | + $ret .= $this->element('th', 'Directive', array('class' => 'hp-directive')); |
|
| 102 | + $ret .= $this->element('th', 'Value', array('class' => 'hp-value')); |
|
| 103 | + $ret .= $this->end('tr'); |
|
| 104 | + $ret .= $this->end('thead'); |
|
| 105 | + foreach ($all as $ns => $directives) { |
|
| 106 | + $ret .= $this->renderNamespace($ns, $directives); |
|
| 107 | + } |
|
| 108 | + if ($render_controls) { |
|
| 109 | + $ret .= $this->start('tbody'); |
|
| 110 | + $ret .= $this->start('tr'); |
|
| 111 | + $ret .= $this->start('td', array('colspan' => 2, 'class' => 'controls')); |
|
| 112 | + $ret .= $this->elementEmpty('input', array('type' => 'submit', 'value' => 'Submit')); |
|
| 113 | + $ret .= '[<a href="?">Reset</a>]'; |
|
| 114 | + $ret .= $this->end('td'); |
|
| 115 | + $ret .= $this->end('tr'); |
|
| 116 | + $ret .= $this->end('tbody'); |
|
| 117 | + } |
|
| 118 | + $ret .= $this->end('table'); |
|
| 119 | + return $ret; |
|
| 120 | + } |
|
| 121 | 121 | |
| 122 | - /** |
|
| 123 | - * Renders a single namespace |
|
| 124 | - * @param $ns String namespace name |
|
| 125 | - * @param $directive Associative array of directives to values |
|
| 126 | - */ |
|
| 127 | - protected function renderNamespace($ns, $directives) { |
|
| 128 | - $ret = ''; |
|
| 129 | - $ret .= $this->start('tbody', array('class' => 'namespace')); |
|
| 130 | - $ret .= $this->start('tr'); |
|
| 131 | - $ret .= $this->element('th', $ns, array('colspan' => 2)); |
|
| 132 | - $ret .= $this->end('tr'); |
|
| 133 | - $ret .= $this->end('tbody'); |
|
| 134 | - $ret .= $this->start('tbody'); |
|
| 135 | - foreach ($directives as $directive => $value) { |
|
| 136 | - $ret .= $this->start('tr'); |
|
| 137 | - $ret .= $this->start('th'); |
|
| 138 | - if ($this->docURL) { |
|
| 139 | - $url = str_replace('%s', urlencode("$ns.$directive"), $this->docURL); |
|
| 140 | - $ret .= $this->start('a', array('href' => $url)); |
|
| 141 | - } |
|
| 142 | - $attr = array('for' => "{$this->name}:$ns.$directive"); |
|
| 122 | + /** |
|
| 123 | + * Renders a single namespace |
|
| 124 | + * @param $ns String namespace name |
|
| 125 | + * @param $directive Associative array of directives to values |
|
| 126 | + */ |
|
| 127 | + protected function renderNamespace($ns, $directives) { |
|
| 128 | + $ret = ''; |
|
| 129 | + $ret .= $this->start('tbody', array('class' => 'namespace')); |
|
| 130 | + $ret .= $this->start('tr'); |
|
| 131 | + $ret .= $this->element('th', $ns, array('colspan' => 2)); |
|
| 132 | + $ret .= $this->end('tr'); |
|
| 133 | + $ret .= $this->end('tbody'); |
|
| 134 | + $ret .= $this->start('tbody'); |
|
| 135 | + foreach ($directives as $directive => $value) { |
|
| 136 | + $ret .= $this->start('tr'); |
|
| 137 | + $ret .= $this->start('th'); |
|
| 138 | + if ($this->docURL) { |
|
| 139 | + $url = str_replace('%s', urlencode("$ns.$directive"), $this->docURL); |
|
| 140 | + $ret .= $this->start('a', array('href' => $url)); |
|
| 141 | + } |
|
| 142 | + $attr = array('for' => "{$this->name}:$ns.$directive"); |
|
| 143 | 143 | |
| 144 | - // crop directive name if it's too long |
|
| 145 | - if (!$this->compress || (strlen($directive) < $this->compress)) { |
|
| 146 | - $directive_disp = $directive; |
|
| 147 | - } else { |
|
| 148 | - $directive_disp = substr($directive, 0, $this->compress - 2) . '...'; |
|
| 149 | - $attr['title'] = $directive; |
|
| 150 | - } |
|
| 144 | + // crop directive name if it's too long |
|
| 145 | + if (!$this->compress || (strlen($directive) < $this->compress)) { |
|
| 146 | + $directive_disp = $directive; |
|
| 147 | + } else { |
|
| 148 | + $directive_disp = substr($directive, 0, $this->compress - 2) . '...'; |
|
| 149 | + $attr['title'] = $directive; |
|
| 150 | + } |
|
| 151 | 151 | |
| 152 | - $ret .= $this->element( |
|
| 153 | - 'label', |
|
| 154 | - $directive_disp, |
|
| 155 | - // component printers must create an element with this id |
|
| 156 | - $attr |
|
| 157 | - ); |
|
| 158 | - if ($this->docURL) $ret .= $this->end('a'); |
|
| 159 | - $ret .= $this->end('th'); |
|
| 152 | + $ret .= $this->element( |
|
| 153 | + 'label', |
|
| 154 | + $directive_disp, |
|
| 155 | + // component printers must create an element with this id |
|
| 156 | + $attr |
|
| 157 | + ); |
|
| 158 | + if ($this->docURL) $ret .= $this->end('a'); |
|
| 159 | + $ret .= $this->end('th'); |
|
| 160 | 160 | |
| 161 | - $ret .= $this->start('td'); |
|
| 162 | - $def = $this->config->def->info["$ns.$directive"]; |
|
| 163 | - if (is_int($def)) { |
|
| 164 | - $allow_null = $def < 0; |
|
| 165 | - $type = abs($def); |
|
| 166 | - } else { |
|
| 167 | - $type = $def->type; |
|
| 168 | - $allow_null = isset($def->allow_null); |
|
| 169 | - } |
|
| 170 | - if (!isset($this->fields[$type])) $type = 0; // default |
|
| 171 | - $type_obj = $this->fields[$type]; |
|
| 172 | - if ($allow_null) { |
|
| 173 | - $type_obj = new HTMLPurifier_Printer_ConfigForm_NullDecorator($type_obj); |
|
| 174 | - } |
|
| 175 | - $ret .= $type_obj->render($ns, $directive, $value, $this->name, array($this->genConfig, $this->config)); |
|
| 176 | - $ret .= $this->end('td'); |
|
| 177 | - $ret .= $this->end('tr'); |
|
| 178 | - } |
|
| 179 | - $ret .= $this->end('tbody'); |
|
| 180 | - return $ret; |
|
| 181 | - } |
|
| 161 | + $ret .= $this->start('td'); |
|
| 162 | + $def = $this->config->def->info["$ns.$directive"]; |
|
| 163 | + if (is_int($def)) { |
|
| 164 | + $allow_null = $def < 0; |
|
| 165 | + $type = abs($def); |
|
| 166 | + } else { |
|
| 167 | + $type = $def->type; |
|
| 168 | + $allow_null = isset($def->allow_null); |
|
| 169 | + } |
|
| 170 | + if (!isset($this->fields[$type])) $type = 0; // default |
|
| 171 | + $type_obj = $this->fields[$type]; |
|
| 172 | + if ($allow_null) { |
|
| 173 | + $type_obj = new HTMLPurifier_Printer_ConfigForm_NullDecorator($type_obj); |
|
| 174 | + } |
|
| 175 | + $ret .= $type_obj->render($ns, $directive, $value, $this->name, array($this->genConfig, $this->config)); |
|
| 176 | + $ret .= $this->end('td'); |
|
| 177 | + $ret .= $this->end('tr'); |
|
| 178 | + } |
|
| 179 | + $ret .= $this->end('tbody'); |
|
| 180 | + return $ret; |
|
| 181 | + } |
|
| 182 | 182 | |
| 183 | 183 | } |
| 184 | 184 | |
@@ -186,183 +186,183 @@ discard block |
||
| 186 | 186 | * Printer decorator for directives that accept null |
| 187 | 187 | */ |
| 188 | 188 | class HTMLPurifier_Printer_ConfigForm_NullDecorator extends HTMLPurifier_Printer { |
| 189 | - /** |
|
| 190 | - * Printer being decorated |
|
| 191 | - */ |
|
| 192 | - protected $obj; |
|
| 193 | - /** |
|
| 194 | - * @param $obj Printer to decorate |
|
| 195 | - */ |
|
| 196 | - public function __construct($obj) { |
|
| 197 | - parent::__construct(); |
|
| 198 | - $this->obj = $obj; |
|
| 199 | - } |
|
| 200 | - public function render($ns, $directive, $value, $name, $config) { |
|
| 201 | - if (is_array($config) && isset($config[0])) { |
|
| 202 | - $gen_config = $config[0]; |
|
| 203 | - $config = $config[1]; |
|
| 204 | - } else { |
|
| 205 | - $gen_config = $config; |
|
| 206 | - } |
|
| 207 | - $this->prepareGenerator($gen_config); |
|
| 189 | + /** |
|
| 190 | + * Printer being decorated |
|
| 191 | + */ |
|
| 192 | + protected $obj; |
|
| 193 | + /** |
|
| 194 | + * @param $obj Printer to decorate |
|
| 195 | + */ |
|
| 196 | + public function __construct($obj) { |
|
| 197 | + parent::__construct(); |
|
| 198 | + $this->obj = $obj; |
|
| 199 | + } |
|
| 200 | + public function render($ns, $directive, $value, $name, $config) { |
|
| 201 | + if (is_array($config) && isset($config[0])) { |
|
| 202 | + $gen_config = $config[0]; |
|
| 203 | + $config = $config[1]; |
|
| 204 | + } else { |
|
| 205 | + $gen_config = $config; |
|
| 206 | + } |
|
| 207 | + $this->prepareGenerator($gen_config); |
|
| 208 | 208 | |
| 209 | - $ret = ''; |
|
| 210 | - $ret .= $this->start('label', array('for' => "$name:Null_$ns.$directive")); |
|
| 211 | - $ret .= $this->element('span', "$ns.$directive:", array('class' => 'verbose')); |
|
| 212 | - $ret .= $this->text(' Null/Disabled'); |
|
| 213 | - $ret .= $this->end('label'); |
|
| 214 | - $attr = array( |
|
| 215 | - 'type' => 'checkbox', |
|
| 216 | - 'value' => '1', |
|
| 217 | - 'class' => 'null-toggle', |
|
| 218 | - 'name' => "$name"."[Null_$ns.$directive]", |
|
| 219 | - 'id' => "$name:Null_$ns.$directive", |
|
| 220 | - 'onclick' => "toggleWriteability('$name:$ns.$directive',checked)" // INLINE JAVASCRIPT!!!! |
|
| 221 | - ); |
|
| 222 | - if ($this->obj instanceof HTMLPurifier_Printer_ConfigForm_bool) { |
|
| 223 | - // modify inline javascript slightly |
|
| 224 | - $attr['onclick'] = "toggleWriteability('$name:Yes_$ns.$directive',checked);toggleWriteability('$name:No_$ns.$directive',checked)"; |
|
| 225 | - } |
|
| 226 | - if ($value === null) $attr['checked'] = 'checked'; |
|
| 227 | - $ret .= $this->elementEmpty('input', $attr); |
|
| 228 | - $ret .= $this->text(' or '); |
|
| 229 | - $ret .= $this->elementEmpty('br'); |
|
| 230 | - $ret .= $this->obj->render($ns, $directive, $value, $name, array($gen_config, $config)); |
|
| 231 | - return $ret; |
|
| 232 | - } |
|
| 209 | + $ret = ''; |
|
| 210 | + $ret .= $this->start('label', array('for' => "$name:Null_$ns.$directive")); |
|
| 211 | + $ret .= $this->element('span', "$ns.$directive:", array('class' => 'verbose')); |
|
| 212 | + $ret .= $this->text(' Null/Disabled'); |
|
| 213 | + $ret .= $this->end('label'); |
|
| 214 | + $attr = array( |
|
| 215 | + 'type' => 'checkbox', |
|
| 216 | + 'value' => '1', |
|
| 217 | + 'class' => 'null-toggle', |
|
| 218 | + 'name' => "$name"."[Null_$ns.$directive]", |
|
| 219 | + 'id' => "$name:Null_$ns.$directive", |
|
| 220 | + 'onclick' => "toggleWriteability('$name:$ns.$directive',checked)" // INLINE JAVASCRIPT!!!! |
|
| 221 | + ); |
|
| 222 | + if ($this->obj instanceof HTMLPurifier_Printer_ConfigForm_bool) { |
|
| 223 | + // modify inline javascript slightly |
|
| 224 | + $attr['onclick'] = "toggleWriteability('$name:Yes_$ns.$directive',checked);toggleWriteability('$name:No_$ns.$directive',checked)"; |
|
| 225 | + } |
|
| 226 | + if ($value === null) $attr['checked'] = 'checked'; |
|
| 227 | + $ret .= $this->elementEmpty('input', $attr); |
|
| 228 | + $ret .= $this->text(' or '); |
|
| 229 | + $ret .= $this->elementEmpty('br'); |
|
| 230 | + $ret .= $this->obj->render($ns, $directive, $value, $name, array($gen_config, $config)); |
|
| 231 | + return $ret; |
|
| 232 | + } |
|
| 233 | 233 | } |
| 234 | 234 | |
| 235 | 235 | /** |
| 236 | 236 | * Swiss-army knife configuration form field printer |
| 237 | 237 | */ |
| 238 | 238 | class HTMLPurifier_Printer_ConfigForm_default extends HTMLPurifier_Printer { |
| 239 | - public $cols = 18; |
|
| 240 | - public $rows = 5; |
|
| 241 | - public function render($ns, $directive, $value, $name, $config) { |
|
| 242 | - if (is_array($config) && isset($config[0])) { |
|
| 243 | - $gen_config = $config[0]; |
|
| 244 | - $config = $config[1]; |
|
| 245 | - } else { |
|
| 246 | - $gen_config = $config; |
|
| 247 | - } |
|
| 248 | - $this->prepareGenerator($gen_config); |
|
| 249 | - // this should probably be split up a little |
|
| 250 | - $ret = ''; |
|
| 251 | - $def = $config->def->info["$ns.$directive"]; |
|
| 252 | - if (is_int($def)) { |
|
| 253 | - $type = abs($def); |
|
| 254 | - } else { |
|
| 255 | - $type = $def->type; |
|
| 256 | - } |
|
| 257 | - if (is_array($value)) { |
|
| 258 | - switch ($type) { |
|
| 259 | - case HTMLPurifier_VarParser::LOOKUP: |
|
| 260 | - $array = $value; |
|
| 261 | - $value = array(); |
|
| 262 | - foreach ($array as $val => $b) { |
|
| 263 | - $value[] = $val; |
|
| 264 | - } |
|
| 265 | - case HTMLPurifier_VarParser::ALIST: |
|
| 266 | - $value = implode(PHP_EOL, $value); |
|
| 267 | - break; |
|
| 268 | - case HTMLPurifier_VarParser::HASH: |
|
| 269 | - $nvalue = ''; |
|
| 270 | - foreach ($value as $i => $v) { |
|
| 271 | - $nvalue .= "$i:$v" . PHP_EOL; |
|
| 272 | - } |
|
| 273 | - $value = $nvalue; |
|
| 274 | - break; |
|
| 275 | - default: |
|
| 276 | - $value = ''; |
|
| 277 | - } |
|
| 278 | - } |
|
| 279 | - if ($type === HTMLPurifier_VarParser::MIXED) { |
|
| 280 | - return 'Not supported'; |
|
| 281 | - $value = serialize($value); |
|
| 282 | - } |
|
| 283 | - $attr = array( |
|
| 284 | - 'name' => "$name"."[$ns.$directive]", |
|
| 285 | - 'id' => "$name:$ns.$directive" |
|
| 286 | - ); |
|
| 287 | - if ($value === null) $attr['disabled'] = 'disabled'; |
|
| 288 | - if (isset($def->allowed)) { |
|
| 289 | - $ret .= $this->start('select', $attr); |
|
| 290 | - foreach ($def->allowed as $val => $b) { |
|
| 291 | - $attr = array(); |
|
| 292 | - if ($value == $val) $attr['selected'] = 'selected'; |
|
| 293 | - $ret .= $this->element('option', $val, $attr); |
|
| 294 | - } |
|
| 295 | - $ret .= $this->end('select'); |
|
| 296 | - } elseif ( |
|
| 297 | - $type === HTMLPurifier_VarParser::TEXT || |
|
| 298 | - $type === HTMLPurifier_VarParser::ITEXT || |
|
| 299 | - $type === HTMLPurifier_VarParser::ALIST || |
|
| 300 | - $type === HTMLPurifier_VarParser::HASH || |
|
| 301 | - $type === HTMLPurifier_VarParser::LOOKUP |
|
| 302 | - ) { |
|
| 303 | - $attr['cols'] = $this->cols; |
|
| 304 | - $attr['rows'] = $this->rows; |
|
| 305 | - $ret .= $this->start('textarea', $attr); |
|
| 306 | - $ret .= $this->text($value); |
|
| 307 | - $ret .= $this->end('textarea'); |
|
| 308 | - } else { |
|
| 309 | - $attr['value'] = $value; |
|
| 310 | - $attr['type'] = 'text'; |
|
| 311 | - $ret .= $this->elementEmpty('input', $attr); |
|
| 312 | - } |
|
| 313 | - return $ret; |
|
| 314 | - } |
|
| 239 | + public $cols = 18; |
|
| 240 | + public $rows = 5; |
|
| 241 | + public function render($ns, $directive, $value, $name, $config) { |
|
| 242 | + if (is_array($config) && isset($config[0])) { |
|
| 243 | + $gen_config = $config[0]; |
|
| 244 | + $config = $config[1]; |
|
| 245 | + } else { |
|
| 246 | + $gen_config = $config; |
|
| 247 | + } |
|
| 248 | + $this->prepareGenerator($gen_config); |
|
| 249 | + // this should probably be split up a little |
|
| 250 | + $ret = ''; |
|
| 251 | + $def = $config->def->info["$ns.$directive"]; |
|
| 252 | + if (is_int($def)) { |
|
| 253 | + $type = abs($def); |
|
| 254 | + } else { |
|
| 255 | + $type = $def->type; |
|
| 256 | + } |
|
| 257 | + if (is_array($value)) { |
|
| 258 | + switch ($type) { |
|
| 259 | + case HTMLPurifier_VarParser::LOOKUP: |
|
| 260 | + $array = $value; |
|
| 261 | + $value = array(); |
|
| 262 | + foreach ($array as $val => $b) { |
|
| 263 | + $value[] = $val; |
|
| 264 | + } |
|
| 265 | + case HTMLPurifier_VarParser::ALIST: |
|
| 266 | + $value = implode(PHP_EOL, $value); |
|
| 267 | + break; |
|
| 268 | + case HTMLPurifier_VarParser::HASH: |
|
| 269 | + $nvalue = ''; |
|
| 270 | + foreach ($value as $i => $v) { |
|
| 271 | + $nvalue .= "$i:$v" . PHP_EOL; |
|
| 272 | + } |
|
| 273 | + $value = $nvalue; |
|
| 274 | + break; |
|
| 275 | + default: |
|
| 276 | + $value = ''; |
|
| 277 | + } |
|
| 278 | + } |
|
| 279 | + if ($type === HTMLPurifier_VarParser::MIXED) { |
|
| 280 | + return 'Not supported'; |
|
| 281 | + $value = serialize($value); |
|
| 282 | + } |
|
| 283 | + $attr = array( |
|
| 284 | + 'name' => "$name"."[$ns.$directive]", |
|
| 285 | + 'id' => "$name:$ns.$directive" |
|
| 286 | + ); |
|
| 287 | + if ($value === null) $attr['disabled'] = 'disabled'; |
|
| 288 | + if (isset($def->allowed)) { |
|
| 289 | + $ret .= $this->start('select', $attr); |
|
| 290 | + foreach ($def->allowed as $val => $b) { |
|
| 291 | + $attr = array(); |
|
| 292 | + if ($value == $val) $attr['selected'] = 'selected'; |
|
| 293 | + $ret .= $this->element('option', $val, $attr); |
|
| 294 | + } |
|
| 295 | + $ret .= $this->end('select'); |
|
| 296 | + } elseif ( |
|
| 297 | + $type === HTMLPurifier_VarParser::TEXT || |
|
| 298 | + $type === HTMLPurifier_VarParser::ITEXT || |
|
| 299 | + $type === HTMLPurifier_VarParser::ALIST || |
|
| 300 | + $type === HTMLPurifier_VarParser::HASH || |
|
| 301 | + $type === HTMLPurifier_VarParser::LOOKUP |
|
| 302 | + ) { |
|
| 303 | + $attr['cols'] = $this->cols; |
|
| 304 | + $attr['rows'] = $this->rows; |
|
| 305 | + $ret .= $this->start('textarea', $attr); |
|
| 306 | + $ret .= $this->text($value); |
|
| 307 | + $ret .= $this->end('textarea'); |
|
| 308 | + } else { |
|
| 309 | + $attr['value'] = $value; |
|
| 310 | + $attr['type'] = 'text'; |
|
| 311 | + $ret .= $this->elementEmpty('input', $attr); |
|
| 312 | + } |
|
| 313 | + return $ret; |
|
| 314 | + } |
|
| 315 | 315 | } |
| 316 | 316 | |
| 317 | 317 | /** |
| 318 | 318 | * Bool form field printer |
| 319 | 319 | */ |
| 320 | 320 | class HTMLPurifier_Printer_ConfigForm_bool extends HTMLPurifier_Printer { |
| 321 | - public function render($ns, $directive, $value, $name, $config) { |
|
| 322 | - if (is_array($config) && isset($config[0])) { |
|
| 323 | - $gen_config = $config[0]; |
|
| 324 | - $config = $config[1]; |
|
| 325 | - } else { |
|
| 326 | - $gen_config = $config; |
|
| 327 | - } |
|
| 328 | - $this->prepareGenerator($gen_config); |
|
| 329 | - $ret = ''; |
|
| 330 | - $ret .= $this->start('div', array('id' => "$name:$ns.$directive")); |
|
| 321 | + public function render($ns, $directive, $value, $name, $config) { |
|
| 322 | + if (is_array($config) && isset($config[0])) { |
|
| 323 | + $gen_config = $config[0]; |
|
| 324 | + $config = $config[1]; |
|
| 325 | + } else { |
|
| 326 | + $gen_config = $config; |
|
| 327 | + } |
|
| 328 | + $this->prepareGenerator($gen_config); |
|
| 329 | + $ret = ''; |
|
| 330 | + $ret .= $this->start('div', array('id' => "$name:$ns.$directive")); |
|
| 331 | 331 | |
| 332 | - $ret .= $this->start('label', array('for' => "$name:Yes_$ns.$directive")); |
|
| 333 | - $ret .= $this->element('span', "$ns.$directive:", array('class' => 'verbose')); |
|
| 334 | - $ret .= $this->text(' Yes'); |
|
| 335 | - $ret .= $this->end('label'); |
|
| 332 | + $ret .= $this->start('label', array('for' => "$name:Yes_$ns.$directive")); |
|
| 333 | + $ret .= $this->element('span', "$ns.$directive:", array('class' => 'verbose')); |
|
| 334 | + $ret .= $this->text(' Yes'); |
|
| 335 | + $ret .= $this->end('label'); |
|
| 336 | 336 | |
| 337 | - $attr = array( |
|
| 338 | - 'type' => 'radio', |
|
| 339 | - 'name' => "$name"."[$ns.$directive]", |
|
| 340 | - 'id' => "$name:Yes_$ns.$directive", |
|
| 341 | - 'value' => '1' |
|
| 342 | - ); |
|
| 343 | - if ($value === true) $attr['checked'] = 'checked'; |
|
| 344 | - if ($value === null) $attr['disabled'] = 'disabled'; |
|
| 345 | - $ret .= $this->elementEmpty('input', $attr); |
|
| 337 | + $attr = array( |
|
| 338 | + 'type' => 'radio', |
|
| 339 | + 'name' => "$name"."[$ns.$directive]", |
|
| 340 | + 'id' => "$name:Yes_$ns.$directive", |
|
| 341 | + 'value' => '1' |
|
| 342 | + ); |
|
| 343 | + if ($value === true) $attr['checked'] = 'checked'; |
|
| 344 | + if ($value === null) $attr['disabled'] = 'disabled'; |
|
| 345 | + $ret .= $this->elementEmpty('input', $attr); |
|
| 346 | 346 | |
| 347 | - $ret .= $this->start('label', array('for' => "$name:No_$ns.$directive")); |
|
| 348 | - $ret .= $this->element('span', "$ns.$directive:", array('class' => 'verbose')); |
|
| 349 | - $ret .= $this->text(' No'); |
|
| 350 | - $ret .= $this->end('label'); |
|
| 347 | + $ret .= $this->start('label', array('for' => "$name:No_$ns.$directive")); |
|
| 348 | + $ret .= $this->element('span', "$ns.$directive:", array('class' => 'verbose')); |
|
| 349 | + $ret .= $this->text(' No'); |
|
| 350 | + $ret .= $this->end('label'); |
|
| 351 | 351 | |
| 352 | - $attr = array( |
|
| 353 | - 'type' => 'radio', |
|
| 354 | - 'name' => "$name"."[$ns.$directive]", |
|
| 355 | - 'id' => "$name:No_$ns.$directive", |
|
| 356 | - 'value' => '0' |
|
| 357 | - ); |
|
| 358 | - if ($value === false) $attr['checked'] = 'checked'; |
|
| 359 | - if ($value === null) $attr['disabled'] = 'disabled'; |
|
| 360 | - $ret .= $this->elementEmpty('input', $attr); |
|
| 352 | + $attr = array( |
|
| 353 | + 'type' => 'radio', |
|
| 354 | + 'name' => "$name"."[$ns.$directive]", |
|
| 355 | + 'id' => "$name:No_$ns.$directive", |
|
| 356 | + 'value' => '0' |
|
| 357 | + ); |
|
| 358 | + if ($value === false) $attr['checked'] = 'checked'; |
|
| 359 | + if ($value === null) $attr['disabled'] = 'disabled'; |
|
| 360 | + $ret .= $this->elementEmpty('input', $attr); |
|
| 361 | 361 | |
| 362 | - $ret .= $this->end('div'); |
|
| 362 | + $ret .= $this->end('div'); |
|
| 363 | 363 | |
| 364 | - return $ret; |
|
| 365 | - } |
|
| 364 | + return $ret; |
|
| 365 | + } |
|
| 366 | 366 | } |
| 367 | 367 | |
| 368 | 368 | // vim: et sw=4 sts=4 |
@@ -51,8 +51,12 @@ discard block |
||
| 51 | 51 | * @param $rows Integer rows of textarea, null to use default |
| 52 | 52 | */ |
| 53 | 53 | public function setTextareaDimensions($cols = null, $rows = null) { |
| 54 | - if ($cols) $this->fields['default']->cols = $cols; |
|
| 55 | - if ($rows) $this->fields['default']->rows = $rows; |
|
| 54 | + if ($cols) { |
|
| 55 | + $this->fields['default']->cols = $cols; |
|
| 56 | + } |
|
| 57 | + if ($rows) { |
|
| 58 | + $this->fields['default']->rows = $rows; |
|
| 59 | + } |
|
| 56 | 60 | } |
| 57 | 61 | |
| 58 | 62 | /** |
@@ -155,7 +159,9 @@ discard block |
||
| 155 | 159 | // component printers must create an element with this id |
| 156 | 160 | $attr |
| 157 | 161 | ); |
| 158 | - if ($this->docURL) $ret .= $this->end('a'); |
|
| 162 | + if ($this->docURL) { |
|
| 163 | + $ret .= $this->end('a'); |
|
| 164 | + } |
|
| 159 | 165 | $ret .= $this->end('th'); |
| 160 | 166 | |
| 161 | 167 | $ret .= $this->start('td'); |
@@ -167,7 +173,10 @@ discard block |
||
| 167 | 173 | $type = $def->type; |
| 168 | 174 | $allow_null = isset($def->allow_null); |
| 169 | 175 | } |
| 170 | - if (!isset($this->fields[$type])) $type = 0; // default |
|
| 176 | + if (!isset($this->fields[$type])) { |
|
| 177 | + $type = 0; |
|
| 178 | + } |
|
| 179 | + // default |
|
| 171 | 180 | $type_obj = $this->fields[$type]; |
| 172 | 181 | if ($allow_null) { |
| 173 | 182 | $type_obj = new HTMLPurifier_Printer_ConfigForm_NullDecorator($type_obj); |
@@ -223,7 +232,9 @@ discard block |
||
| 223 | 232 | // modify inline javascript slightly |
| 224 | 233 | $attr['onclick'] = "toggleWriteability('$name:Yes_$ns.$directive',checked);toggleWriteability('$name:No_$ns.$directive',checked)"; |
| 225 | 234 | } |
| 226 | - if ($value === null) $attr['checked'] = 'checked'; |
|
| 235 | + if ($value === null) { |
|
| 236 | + $attr['checked'] = 'checked'; |
|
| 237 | + } |
|
| 227 | 238 | $ret .= $this->elementEmpty('input', $attr); |
| 228 | 239 | $ret .= $this->text(' or '); |
| 229 | 240 | $ret .= $this->elementEmpty('br'); |
@@ -284,12 +295,16 @@ discard block |
||
| 284 | 295 | 'name' => "$name"."[$ns.$directive]", |
| 285 | 296 | 'id' => "$name:$ns.$directive" |
| 286 | 297 | ); |
| 287 | - if ($value === null) $attr['disabled'] = 'disabled'; |
|
| 298 | + if ($value === null) { |
|
| 299 | + $attr['disabled'] = 'disabled'; |
|
| 300 | + } |
|
| 288 | 301 | if (isset($def->allowed)) { |
| 289 | 302 | $ret .= $this->start('select', $attr); |
| 290 | 303 | foreach ($def->allowed as $val => $b) { |
| 291 | 304 | $attr = array(); |
| 292 | - if ($value == $val) $attr['selected'] = 'selected'; |
|
| 305 | + if ($value == $val) { |
|
| 306 | + $attr['selected'] = 'selected'; |
|
| 307 | + } |
|
| 293 | 308 | $ret .= $this->element('option', $val, $attr); |
| 294 | 309 | } |
| 295 | 310 | $ret .= $this->end('select'); |
@@ -340,8 +355,12 @@ discard block |
||
| 340 | 355 | 'id' => "$name:Yes_$ns.$directive", |
| 341 | 356 | 'value' => '1' |
| 342 | 357 | ); |
| 343 | - if ($value === true) $attr['checked'] = 'checked'; |
|
| 344 | - if ($value === null) $attr['disabled'] = 'disabled'; |
|
| 358 | + if ($value === true) { |
|
| 359 | + $attr['checked'] = 'checked'; |
|
| 360 | + } |
|
| 361 | + if ($value === null) { |
|
| 362 | + $attr['disabled'] = 'disabled'; |
|
| 363 | + } |
|
| 345 | 364 | $ret .= $this->elementEmpty('input', $attr); |
| 346 | 365 | |
| 347 | 366 | $ret .= $this->start('label', array('for' => "$name:No_$ns.$directive")); |
@@ -355,8 +374,12 @@ discard block |
||
| 355 | 374 | 'id' => "$name:No_$ns.$directive", |
| 356 | 375 | 'value' => '0' |
| 357 | 376 | ); |
| 358 | - if ($value === false) $attr['checked'] = 'checked'; |
|
| 359 | - if ($value === null) $attr['disabled'] = 'disabled'; |
|
| 377 | + if ($value === false) { |
|
| 378 | + $attr['checked'] = 'checked'; |
|
| 379 | + } |
|
| 380 | + if ($value === null) { |
|
| 381 | + $attr['disabled'] = 'disabled'; |
|
| 382 | + } |
|
| 360 | 383 | $ret .= $this->elementEmpty('input', $attr); |
| 361 | 384 | |
| 362 | 385 | $ret .= $this->end('div'); |
@@ -41,8 +41,8 @@ discard block |
||
| 41 | 41 | $this->name = $name; |
| 42 | 42 | $this->compress = $compress; |
| 43 | 43 | // initialize sub-printers |
| 44 | - $this->fields[0] = new HTMLPurifier_Printer_ConfigForm_default(); |
|
| 45 | - $this->fields[HTMLPurifier_VarParser::BOOL] = new HTMLPurifier_Printer_ConfigForm_bool(); |
|
| 44 | + $this->fields[0] = new HTMLPurifier_Printer_ConfigForm_default(); |
|
| 45 | + $this->fields[HTMLPurifier_VarParser::BOOL] = new HTMLPurifier_Printer_ConfigForm_bool(); |
|
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | /** |
@@ -59,14 +59,14 @@ discard block |
||
| 59 | 59 | * Retrieves styling, in case it is not accessible by webserver |
| 60 | 60 | */ |
| 61 | 61 | public static function getCSS() { |
| 62 | - return file_get_contents(HTMLPURIFIER_PREFIX . '/HTMLPurifier/Printer/ConfigForm.css'); |
|
| 62 | + return file_get_contents(HTMLPURIFIER_PREFIX.'/HTMLPurifier/Printer/ConfigForm.css'); |
|
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | /** |
| 66 | 66 | * Retrieves JavaScript, in case it is not accessible by webserver |
| 67 | 67 | */ |
| 68 | 68 | public static function getJavaScript() { |
| 69 | - return file_get_contents(HTMLPURIFIER_PREFIX . '/HTMLPurifier/Printer/ConfigForm.js'); |
|
| 69 | + return file_get_contents(HTMLPURIFIER_PREFIX.'/HTMLPurifier/Printer/ConfigForm.js'); |
|
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | /** |
@@ -91,7 +91,7 @@ discard block |
||
| 91 | 91 | $all = array(); |
| 92 | 92 | foreach ($allowed as $key) { |
| 93 | 93 | list($ns, $directive) = $key; |
| 94 | - $all[$ns][$directive] = $config->get($ns .'.'. $directive); |
|
| 94 | + $all[$ns][$directive] = $config->get($ns.'.'.$directive); |
|
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | $ret = ''; |
@@ -145,7 +145,7 @@ discard block |
||
| 145 | 145 | if (!$this->compress || (strlen($directive) < $this->compress)) { |
| 146 | 146 | $directive_disp = $directive; |
| 147 | 147 | } else { |
| 148 | - $directive_disp = substr($directive, 0, $this->compress - 2) . '...'; |
|
| 148 | + $directive_disp = substr($directive, 0, $this->compress - 2).'...'; |
|
| 149 | 149 | $attr['title'] = $directive; |
| 150 | 150 | } |
| 151 | 151 | |
@@ -268,7 +268,7 @@ discard block |
||
| 268 | 268 | case HTMLPurifier_VarParser::HASH: |
| 269 | 269 | $nvalue = ''; |
| 270 | 270 | foreach ($value as $i => $v) { |
| 271 | - $nvalue .= "$i:$v" . PHP_EOL; |
|
| 271 | + $nvalue .= "$i:$v".PHP_EOL; |
|
| 272 | 272 | } |
| 273 | 273 | $value = $nvalue; |
| 274 | 274 | break; |
@@ -3,269 +3,269 @@ |
||
| 3 | 3 | class HTMLPurifier_Printer_HTMLDefinition extends HTMLPurifier_Printer |
| 4 | 4 | { |
| 5 | 5 | |
| 6 | - /** |
|
| 7 | - * Instance of HTMLPurifier_HTMLDefinition, for easy access |
|
| 8 | - */ |
|
| 9 | - protected $def; |
|
| 10 | - |
|
| 11 | - public function render($config) { |
|
| 12 | - $ret = ''; |
|
| 13 | - $this->config =& $config; |
|
| 14 | - |
|
| 15 | - $this->def = $config->getHTMLDefinition(); |
|
| 16 | - |
|
| 17 | - $ret .= $this->start('div', array('class' => 'HTMLPurifier_Printer')); |
|
| 18 | - |
|
| 19 | - $ret .= $this->renderDoctype(); |
|
| 20 | - $ret .= $this->renderEnvironment(); |
|
| 21 | - $ret .= $this->renderContentSets(); |
|
| 22 | - $ret .= $this->renderInfo(); |
|
| 23 | - |
|
| 24 | - $ret .= $this->end('div'); |
|
| 25 | - |
|
| 26 | - return $ret; |
|
| 27 | - } |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * Renders the Doctype table |
|
| 31 | - */ |
|
| 32 | - protected function renderDoctype() { |
|
| 33 | - $doctype = $this->def->doctype; |
|
| 34 | - $ret = ''; |
|
| 35 | - $ret .= $this->start('table'); |
|
| 36 | - $ret .= $this->element('caption', 'Doctype'); |
|
| 37 | - $ret .= $this->row('Name', $doctype->name); |
|
| 38 | - $ret .= $this->row('XML', $doctype->xml ? 'Yes' : 'No'); |
|
| 39 | - $ret .= $this->row('Default Modules', implode($doctype->modules, ', ')); |
|
| 40 | - $ret .= $this->row('Default Tidy Modules', implode($doctype->tidyModules, ', ')); |
|
| 41 | - $ret .= $this->end('table'); |
|
| 42 | - return $ret; |
|
| 43 | - } |
|
| 44 | - |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * Renders environment table, which is miscellaneous info |
|
| 48 | - */ |
|
| 49 | - protected function renderEnvironment() { |
|
| 50 | - $def = $this->def; |
|
| 51 | - |
|
| 52 | - $ret = ''; |
|
| 53 | - |
|
| 54 | - $ret .= $this->start('table'); |
|
| 55 | - $ret .= $this->element('caption', 'Environment'); |
|
| 56 | - |
|
| 57 | - $ret .= $this->row('Parent of fragment', $def->info_parent); |
|
| 58 | - $ret .= $this->renderChildren($def->info_parent_def->child); |
|
| 59 | - $ret .= $this->row('Block wrap name', $def->info_block_wrapper); |
|
| 60 | - |
|
| 61 | - $ret .= $this->start('tr'); |
|
| 62 | - $ret .= $this->element('th', 'Global attributes'); |
|
| 63 | - $ret .= $this->element('td', $this->listifyAttr($def->info_global_attr),0,0); |
|
| 64 | - $ret .= $this->end('tr'); |
|
| 65 | - |
|
| 66 | - $ret .= $this->start('tr'); |
|
| 67 | - $ret .= $this->element('th', 'Tag transforms'); |
|
| 68 | - $list = array(); |
|
| 69 | - foreach ($def->info_tag_transform as $old => $new) { |
|
| 70 | - $new = $this->getClass($new, 'TagTransform_'); |
|
| 71 | - $list[] = "<$old> with $new"; |
|
| 72 | - } |
|
| 73 | - $ret .= $this->element('td', $this->listify($list)); |
|
| 74 | - $ret .= $this->end('tr'); |
|
| 75 | - |
|
| 76 | - $ret .= $this->start('tr'); |
|
| 77 | - $ret .= $this->element('th', 'Pre-AttrTransform'); |
|
| 78 | - $ret .= $this->element('td', $this->listifyObjectList($def->info_attr_transform_pre)); |
|
| 79 | - $ret .= $this->end('tr'); |
|
| 80 | - |
|
| 81 | - $ret .= $this->start('tr'); |
|
| 82 | - $ret .= $this->element('th', 'Post-AttrTransform'); |
|
| 83 | - $ret .= $this->element('td', $this->listifyObjectList($def->info_attr_transform_post)); |
|
| 84 | - $ret .= $this->end('tr'); |
|
| 85 | - |
|
| 86 | - $ret .= $this->end('table'); |
|
| 87 | - return $ret; |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - /** |
|
| 91 | - * Renders the Content Sets table |
|
| 92 | - */ |
|
| 93 | - protected function renderContentSets() { |
|
| 94 | - $ret = ''; |
|
| 95 | - $ret .= $this->start('table'); |
|
| 96 | - $ret .= $this->element('caption', 'Content Sets'); |
|
| 97 | - foreach ($this->def->info_content_sets as $name => $lookup) { |
|
| 98 | - $ret .= $this->heavyHeader($name); |
|
| 99 | - $ret .= $this->start('tr'); |
|
| 100 | - $ret .= $this->element('td', $this->listifyTagLookup($lookup)); |
|
| 101 | - $ret .= $this->end('tr'); |
|
| 102 | - } |
|
| 103 | - $ret .= $this->end('table'); |
|
| 104 | - return $ret; |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * Renders the Elements ($info) table |
|
| 109 | - */ |
|
| 110 | - protected function renderInfo() { |
|
| 111 | - $ret = ''; |
|
| 112 | - $ret .= $this->start('table'); |
|
| 113 | - $ret .= $this->element('caption', 'Elements ($info)'); |
|
| 114 | - ksort($this->def->info); |
|
| 115 | - $ret .= $this->heavyHeader('Allowed tags', 2); |
|
| 116 | - $ret .= $this->start('tr'); |
|
| 117 | - $ret .= $this->element('td', $this->listifyTagLookup($this->def->info), array('colspan' => 2)); |
|
| 118 | - $ret .= $this->end('tr'); |
|
| 119 | - foreach ($this->def->info as $name => $def) { |
|
| 120 | - $ret .= $this->start('tr'); |
|
| 121 | - $ret .= $this->element('th', "<$name>", array('class'=>'heavy', 'colspan' => 2)); |
|
| 122 | - $ret .= $this->end('tr'); |
|
| 123 | - $ret .= $this->start('tr'); |
|
| 124 | - $ret .= $this->element('th', 'Inline content'); |
|
| 125 | - $ret .= $this->element('td', $def->descendants_are_inline ? 'Yes' : 'No'); |
|
| 126 | - $ret .= $this->end('tr'); |
|
| 127 | - if (!empty($def->excludes)) { |
|
| 128 | - $ret .= $this->start('tr'); |
|
| 129 | - $ret .= $this->element('th', 'Excludes'); |
|
| 130 | - $ret .= $this->element('td', $this->listifyTagLookup($def->excludes)); |
|
| 131 | - $ret .= $this->end('tr'); |
|
| 132 | - } |
|
| 133 | - if (!empty($def->attr_transform_pre)) { |
|
| 134 | - $ret .= $this->start('tr'); |
|
| 135 | - $ret .= $this->element('th', 'Pre-AttrTransform'); |
|
| 136 | - $ret .= $this->element('td', $this->listifyObjectList($def->attr_transform_pre)); |
|
| 137 | - $ret .= $this->end('tr'); |
|
| 138 | - } |
|
| 139 | - if (!empty($def->attr_transform_post)) { |
|
| 140 | - $ret .= $this->start('tr'); |
|
| 141 | - $ret .= $this->element('th', 'Post-AttrTransform'); |
|
| 142 | - $ret .= $this->element('td', $this->listifyObjectList($def->attr_transform_post)); |
|
| 143 | - $ret .= $this->end('tr'); |
|
| 144 | - } |
|
| 145 | - if (!empty($def->auto_close)) { |
|
| 146 | - $ret .= $this->start('tr'); |
|
| 147 | - $ret .= $this->element('th', 'Auto closed by'); |
|
| 148 | - $ret .= $this->element('td', $this->listifyTagLookup($def->auto_close)); |
|
| 149 | - $ret .= $this->end('tr'); |
|
| 150 | - } |
|
| 151 | - $ret .= $this->start('tr'); |
|
| 152 | - $ret .= $this->element('th', 'Allowed attributes'); |
|
| 153 | - $ret .= $this->element('td',$this->listifyAttr($def->attr), array(), 0); |
|
| 154 | - $ret .= $this->end('tr'); |
|
| 155 | - |
|
| 156 | - if (!empty($def->required_attr)) { |
|
| 157 | - $ret .= $this->row('Required attributes', $this->listify($def->required_attr)); |
|
| 158 | - } |
|
| 159 | - |
|
| 160 | - $ret .= $this->renderChildren($def->child); |
|
| 161 | - } |
|
| 162 | - $ret .= $this->end('table'); |
|
| 163 | - return $ret; |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - /** |
|
| 167 | - * Renders a row describing the allowed children of an element |
|
| 168 | - * @param $def HTMLPurifier_ChildDef of pertinent element |
|
| 169 | - */ |
|
| 170 | - protected function renderChildren($def) { |
|
| 171 | - $context = new HTMLPurifier_Context(); |
|
| 172 | - $ret = ''; |
|
| 173 | - $ret .= $this->start('tr'); |
|
| 174 | - $elements = array(); |
|
| 175 | - $attr = array(); |
|
| 176 | - if (isset($def->elements)) { |
|
| 177 | - if ($def->type == 'strictblockquote') { |
|
| 178 | - $def->validateChildren(array(), $this->config, $context); |
|
| 179 | - } |
|
| 180 | - $elements = $def->elements; |
|
| 181 | - } |
|
| 182 | - if ($def->type == 'chameleon') { |
|
| 183 | - $attr['rowspan'] = 2; |
|
| 184 | - } elseif ($def->type == 'empty') { |
|
| 185 | - $elements = array(); |
|
| 186 | - } elseif ($def->type == 'table') { |
|
| 187 | - $elements = array_flip(array('col', 'caption', 'colgroup', 'thead', |
|
| 188 | - 'tfoot', 'tbody', 'tr')); |
|
| 189 | - } |
|
| 190 | - $ret .= $this->element('th', 'Allowed children', $attr); |
|
| 191 | - |
|
| 192 | - if ($def->type == 'chameleon') { |
|
| 193 | - |
|
| 194 | - $ret .= $this->element('td', |
|
| 195 | - '<em>Block</em>: ' . |
|
| 196 | - $this->escape($this->listifyTagLookup($def->block->elements)),0,0); |
|
| 197 | - $ret .= $this->end('tr'); |
|
| 198 | - $ret .= $this->start('tr'); |
|
| 199 | - $ret .= $this->element('td', |
|
| 200 | - '<em>Inline</em>: ' . |
|
| 201 | - $this->escape($this->listifyTagLookup($def->inline->elements)),0,0); |
|
| 202 | - |
|
| 203 | - } elseif ($def->type == 'custom') { |
|
| 204 | - |
|
| 205 | - $ret .= $this->element('td', '<em>'.ucfirst($def->type).'</em>: ' . |
|
| 206 | - $def->dtd_regex); |
|
| 207 | - |
|
| 208 | - } else { |
|
| 209 | - $ret .= $this->element('td', |
|
| 210 | - '<em>'.ucfirst($def->type).'</em>: ' . |
|
| 211 | - $this->escape($this->listifyTagLookup($elements)),0,0); |
|
| 212 | - } |
|
| 213 | - $ret .= $this->end('tr'); |
|
| 214 | - return $ret; |
|
| 215 | - } |
|
| 216 | - |
|
| 217 | - /** |
|
| 218 | - * Listifies a tag lookup table. |
|
| 219 | - * @param $array Tag lookup array in form of array('tagname' => true) |
|
| 220 | - */ |
|
| 221 | - protected function listifyTagLookup($array) { |
|
| 222 | - ksort($array); |
|
| 223 | - $list = array(); |
|
| 224 | - foreach ($array as $name => $discard) { |
|
| 225 | - if ($name !== '#PCDATA' && !isset($this->def->info[$name])) continue; |
|
| 226 | - $list[] = $name; |
|
| 227 | - } |
|
| 228 | - return $this->listify($list); |
|
| 229 | - } |
|
| 230 | - |
|
| 231 | - /** |
|
| 232 | - * Listifies a list of objects by retrieving class names and internal state |
|
| 233 | - * @param $array List of objects |
|
| 234 | - * @todo Also add information about internal state |
|
| 235 | - */ |
|
| 236 | - protected function listifyObjectList($array) { |
|
| 237 | - ksort($array); |
|
| 238 | - $list = array(); |
|
| 239 | - foreach ($array as $discard => $obj) { |
|
| 240 | - $list[] = $this->getClass($obj, 'AttrTransform_'); |
|
| 241 | - } |
|
| 242 | - return $this->listify($list); |
|
| 243 | - } |
|
| 244 | - |
|
| 245 | - /** |
|
| 246 | - * Listifies a hash of attributes to AttrDef classes |
|
| 247 | - * @param $array Array hash in form of array('attrname' => HTMLPurifier_AttrDef) |
|
| 248 | - */ |
|
| 249 | - protected function listifyAttr($array) { |
|
| 250 | - ksort($array); |
|
| 251 | - $list = array(); |
|
| 252 | - foreach ($array as $name => $obj) { |
|
| 253 | - if ($obj === false) continue; |
|
| 254 | - $list[] = "$name = <i>" . $this->getClass($obj, 'AttrDef_') . '</i>'; |
|
| 255 | - } |
|
| 256 | - return $this->listify($list); |
|
| 257 | - } |
|
| 258 | - |
|
| 259 | - /** |
|
| 260 | - * Creates a heavy header row |
|
| 261 | - */ |
|
| 262 | - protected function heavyHeader($text, $num = 1) { |
|
| 263 | - $ret = ''; |
|
| 264 | - $ret .= $this->start('tr'); |
|
| 265 | - $ret .= $this->element('th', $text, array('colspan' => $num, 'class' => 'heavy')); |
|
| 266 | - $ret .= $this->end('tr'); |
|
| 267 | - return $ret; |
|
| 268 | - } |
|
| 6 | + /** |
|
| 7 | + * Instance of HTMLPurifier_HTMLDefinition, for easy access |
|
| 8 | + */ |
|
| 9 | + protected $def; |
|
| 10 | + |
|
| 11 | + public function render($config) { |
|
| 12 | + $ret = ''; |
|
| 13 | + $this->config =& $config; |
|
| 14 | + |
|
| 15 | + $this->def = $config->getHTMLDefinition(); |
|
| 16 | + |
|
| 17 | + $ret .= $this->start('div', array('class' => 'HTMLPurifier_Printer')); |
|
| 18 | + |
|
| 19 | + $ret .= $this->renderDoctype(); |
|
| 20 | + $ret .= $this->renderEnvironment(); |
|
| 21 | + $ret .= $this->renderContentSets(); |
|
| 22 | + $ret .= $this->renderInfo(); |
|
| 23 | + |
|
| 24 | + $ret .= $this->end('div'); |
|
| 25 | + |
|
| 26 | + return $ret; |
|
| 27 | + } |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * Renders the Doctype table |
|
| 31 | + */ |
|
| 32 | + protected function renderDoctype() { |
|
| 33 | + $doctype = $this->def->doctype; |
|
| 34 | + $ret = ''; |
|
| 35 | + $ret .= $this->start('table'); |
|
| 36 | + $ret .= $this->element('caption', 'Doctype'); |
|
| 37 | + $ret .= $this->row('Name', $doctype->name); |
|
| 38 | + $ret .= $this->row('XML', $doctype->xml ? 'Yes' : 'No'); |
|
| 39 | + $ret .= $this->row('Default Modules', implode($doctype->modules, ', ')); |
|
| 40 | + $ret .= $this->row('Default Tidy Modules', implode($doctype->tidyModules, ', ')); |
|
| 41 | + $ret .= $this->end('table'); |
|
| 42 | + return $ret; |
|
| 43 | + } |
|
| 44 | + |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * Renders environment table, which is miscellaneous info |
|
| 48 | + */ |
|
| 49 | + protected function renderEnvironment() { |
|
| 50 | + $def = $this->def; |
|
| 51 | + |
|
| 52 | + $ret = ''; |
|
| 53 | + |
|
| 54 | + $ret .= $this->start('table'); |
|
| 55 | + $ret .= $this->element('caption', 'Environment'); |
|
| 56 | + |
|
| 57 | + $ret .= $this->row('Parent of fragment', $def->info_parent); |
|
| 58 | + $ret .= $this->renderChildren($def->info_parent_def->child); |
|
| 59 | + $ret .= $this->row('Block wrap name', $def->info_block_wrapper); |
|
| 60 | + |
|
| 61 | + $ret .= $this->start('tr'); |
|
| 62 | + $ret .= $this->element('th', 'Global attributes'); |
|
| 63 | + $ret .= $this->element('td', $this->listifyAttr($def->info_global_attr),0,0); |
|
| 64 | + $ret .= $this->end('tr'); |
|
| 65 | + |
|
| 66 | + $ret .= $this->start('tr'); |
|
| 67 | + $ret .= $this->element('th', 'Tag transforms'); |
|
| 68 | + $list = array(); |
|
| 69 | + foreach ($def->info_tag_transform as $old => $new) { |
|
| 70 | + $new = $this->getClass($new, 'TagTransform_'); |
|
| 71 | + $list[] = "<$old> with $new"; |
|
| 72 | + } |
|
| 73 | + $ret .= $this->element('td', $this->listify($list)); |
|
| 74 | + $ret .= $this->end('tr'); |
|
| 75 | + |
|
| 76 | + $ret .= $this->start('tr'); |
|
| 77 | + $ret .= $this->element('th', 'Pre-AttrTransform'); |
|
| 78 | + $ret .= $this->element('td', $this->listifyObjectList($def->info_attr_transform_pre)); |
|
| 79 | + $ret .= $this->end('tr'); |
|
| 80 | + |
|
| 81 | + $ret .= $this->start('tr'); |
|
| 82 | + $ret .= $this->element('th', 'Post-AttrTransform'); |
|
| 83 | + $ret .= $this->element('td', $this->listifyObjectList($def->info_attr_transform_post)); |
|
| 84 | + $ret .= $this->end('tr'); |
|
| 85 | + |
|
| 86 | + $ret .= $this->end('table'); |
|
| 87 | + return $ret; |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + /** |
|
| 91 | + * Renders the Content Sets table |
|
| 92 | + */ |
|
| 93 | + protected function renderContentSets() { |
|
| 94 | + $ret = ''; |
|
| 95 | + $ret .= $this->start('table'); |
|
| 96 | + $ret .= $this->element('caption', 'Content Sets'); |
|
| 97 | + foreach ($this->def->info_content_sets as $name => $lookup) { |
|
| 98 | + $ret .= $this->heavyHeader($name); |
|
| 99 | + $ret .= $this->start('tr'); |
|
| 100 | + $ret .= $this->element('td', $this->listifyTagLookup($lookup)); |
|
| 101 | + $ret .= $this->end('tr'); |
|
| 102 | + } |
|
| 103 | + $ret .= $this->end('table'); |
|
| 104 | + return $ret; |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * Renders the Elements ($info) table |
|
| 109 | + */ |
|
| 110 | + protected function renderInfo() { |
|
| 111 | + $ret = ''; |
|
| 112 | + $ret .= $this->start('table'); |
|
| 113 | + $ret .= $this->element('caption', 'Elements ($info)'); |
|
| 114 | + ksort($this->def->info); |
|
| 115 | + $ret .= $this->heavyHeader('Allowed tags', 2); |
|
| 116 | + $ret .= $this->start('tr'); |
|
| 117 | + $ret .= $this->element('td', $this->listifyTagLookup($this->def->info), array('colspan' => 2)); |
|
| 118 | + $ret .= $this->end('tr'); |
|
| 119 | + foreach ($this->def->info as $name => $def) { |
|
| 120 | + $ret .= $this->start('tr'); |
|
| 121 | + $ret .= $this->element('th', "<$name>", array('class'=>'heavy', 'colspan' => 2)); |
|
| 122 | + $ret .= $this->end('tr'); |
|
| 123 | + $ret .= $this->start('tr'); |
|
| 124 | + $ret .= $this->element('th', 'Inline content'); |
|
| 125 | + $ret .= $this->element('td', $def->descendants_are_inline ? 'Yes' : 'No'); |
|
| 126 | + $ret .= $this->end('tr'); |
|
| 127 | + if (!empty($def->excludes)) { |
|
| 128 | + $ret .= $this->start('tr'); |
|
| 129 | + $ret .= $this->element('th', 'Excludes'); |
|
| 130 | + $ret .= $this->element('td', $this->listifyTagLookup($def->excludes)); |
|
| 131 | + $ret .= $this->end('tr'); |
|
| 132 | + } |
|
| 133 | + if (!empty($def->attr_transform_pre)) { |
|
| 134 | + $ret .= $this->start('tr'); |
|
| 135 | + $ret .= $this->element('th', 'Pre-AttrTransform'); |
|
| 136 | + $ret .= $this->element('td', $this->listifyObjectList($def->attr_transform_pre)); |
|
| 137 | + $ret .= $this->end('tr'); |
|
| 138 | + } |
|
| 139 | + if (!empty($def->attr_transform_post)) { |
|
| 140 | + $ret .= $this->start('tr'); |
|
| 141 | + $ret .= $this->element('th', 'Post-AttrTransform'); |
|
| 142 | + $ret .= $this->element('td', $this->listifyObjectList($def->attr_transform_post)); |
|
| 143 | + $ret .= $this->end('tr'); |
|
| 144 | + } |
|
| 145 | + if (!empty($def->auto_close)) { |
|
| 146 | + $ret .= $this->start('tr'); |
|
| 147 | + $ret .= $this->element('th', 'Auto closed by'); |
|
| 148 | + $ret .= $this->element('td', $this->listifyTagLookup($def->auto_close)); |
|
| 149 | + $ret .= $this->end('tr'); |
|
| 150 | + } |
|
| 151 | + $ret .= $this->start('tr'); |
|
| 152 | + $ret .= $this->element('th', 'Allowed attributes'); |
|
| 153 | + $ret .= $this->element('td',$this->listifyAttr($def->attr), array(), 0); |
|
| 154 | + $ret .= $this->end('tr'); |
|
| 155 | + |
|
| 156 | + if (!empty($def->required_attr)) { |
|
| 157 | + $ret .= $this->row('Required attributes', $this->listify($def->required_attr)); |
|
| 158 | + } |
|
| 159 | + |
|
| 160 | + $ret .= $this->renderChildren($def->child); |
|
| 161 | + } |
|
| 162 | + $ret .= $this->end('table'); |
|
| 163 | + return $ret; |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + /** |
|
| 167 | + * Renders a row describing the allowed children of an element |
|
| 168 | + * @param $def HTMLPurifier_ChildDef of pertinent element |
|
| 169 | + */ |
|
| 170 | + protected function renderChildren($def) { |
|
| 171 | + $context = new HTMLPurifier_Context(); |
|
| 172 | + $ret = ''; |
|
| 173 | + $ret .= $this->start('tr'); |
|
| 174 | + $elements = array(); |
|
| 175 | + $attr = array(); |
|
| 176 | + if (isset($def->elements)) { |
|
| 177 | + if ($def->type == 'strictblockquote') { |
|
| 178 | + $def->validateChildren(array(), $this->config, $context); |
|
| 179 | + } |
|
| 180 | + $elements = $def->elements; |
|
| 181 | + } |
|
| 182 | + if ($def->type == 'chameleon') { |
|
| 183 | + $attr['rowspan'] = 2; |
|
| 184 | + } elseif ($def->type == 'empty') { |
|
| 185 | + $elements = array(); |
|
| 186 | + } elseif ($def->type == 'table') { |
|
| 187 | + $elements = array_flip(array('col', 'caption', 'colgroup', 'thead', |
|
| 188 | + 'tfoot', 'tbody', 'tr')); |
|
| 189 | + } |
|
| 190 | + $ret .= $this->element('th', 'Allowed children', $attr); |
|
| 191 | + |
|
| 192 | + if ($def->type == 'chameleon') { |
|
| 193 | + |
|
| 194 | + $ret .= $this->element('td', |
|
| 195 | + '<em>Block</em>: ' . |
|
| 196 | + $this->escape($this->listifyTagLookup($def->block->elements)),0,0); |
|
| 197 | + $ret .= $this->end('tr'); |
|
| 198 | + $ret .= $this->start('tr'); |
|
| 199 | + $ret .= $this->element('td', |
|
| 200 | + '<em>Inline</em>: ' . |
|
| 201 | + $this->escape($this->listifyTagLookup($def->inline->elements)),0,0); |
|
| 202 | + |
|
| 203 | + } elseif ($def->type == 'custom') { |
|
| 204 | + |
|
| 205 | + $ret .= $this->element('td', '<em>'.ucfirst($def->type).'</em>: ' . |
|
| 206 | + $def->dtd_regex); |
|
| 207 | + |
|
| 208 | + } else { |
|
| 209 | + $ret .= $this->element('td', |
|
| 210 | + '<em>'.ucfirst($def->type).'</em>: ' . |
|
| 211 | + $this->escape($this->listifyTagLookup($elements)),0,0); |
|
| 212 | + } |
|
| 213 | + $ret .= $this->end('tr'); |
|
| 214 | + return $ret; |
|
| 215 | + } |
|
| 216 | + |
|
| 217 | + /** |
|
| 218 | + * Listifies a tag lookup table. |
|
| 219 | + * @param $array Tag lookup array in form of array('tagname' => true) |
|
| 220 | + */ |
|
| 221 | + protected function listifyTagLookup($array) { |
|
| 222 | + ksort($array); |
|
| 223 | + $list = array(); |
|
| 224 | + foreach ($array as $name => $discard) { |
|
| 225 | + if ($name !== '#PCDATA' && !isset($this->def->info[$name])) continue; |
|
| 226 | + $list[] = $name; |
|
| 227 | + } |
|
| 228 | + return $this->listify($list); |
|
| 229 | + } |
|
| 230 | + |
|
| 231 | + /** |
|
| 232 | + * Listifies a list of objects by retrieving class names and internal state |
|
| 233 | + * @param $array List of objects |
|
| 234 | + * @todo Also add information about internal state |
|
| 235 | + */ |
|
| 236 | + protected function listifyObjectList($array) { |
|
| 237 | + ksort($array); |
|
| 238 | + $list = array(); |
|
| 239 | + foreach ($array as $discard => $obj) { |
|
| 240 | + $list[] = $this->getClass($obj, 'AttrTransform_'); |
|
| 241 | + } |
|
| 242 | + return $this->listify($list); |
|
| 243 | + } |
|
| 244 | + |
|
| 245 | + /** |
|
| 246 | + * Listifies a hash of attributes to AttrDef classes |
|
| 247 | + * @param $array Array hash in form of array('attrname' => HTMLPurifier_AttrDef) |
|
| 248 | + */ |
|
| 249 | + protected function listifyAttr($array) { |
|
| 250 | + ksort($array); |
|
| 251 | + $list = array(); |
|
| 252 | + foreach ($array as $name => $obj) { |
|
| 253 | + if ($obj === false) continue; |
|
| 254 | + $list[] = "$name = <i>" . $this->getClass($obj, 'AttrDef_') . '</i>'; |
|
| 255 | + } |
|
| 256 | + return $this->listify($list); |
|
| 257 | + } |
|
| 258 | + |
|
| 259 | + /** |
|
| 260 | + * Creates a heavy header row |
|
| 261 | + */ |
|
| 262 | + protected function heavyHeader($text, $num = 1) { |
|
| 263 | + $ret = ''; |
|
| 264 | + $ret .= $this->start('tr'); |
|
| 265 | + $ret .= $this->element('th', $text, array('colspan' => $num, 'class' => 'heavy')); |
|
| 266 | + $ret .= $this->end('tr'); |
|
| 267 | + return $ret; |
|
| 268 | + } |
|
| 269 | 269 | |
| 270 | 270 | } |
| 271 | 271 | |
@@ -222,7 +222,9 @@ discard block |
||
| 222 | 222 | ksort($array); |
| 223 | 223 | $list = array(); |
| 224 | 224 | foreach ($array as $name => $discard) { |
| 225 | - if ($name !== '#PCDATA' && !isset($this->def->info[$name])) continue; |
|
| 225 | + if ($name !== '#PCDATA' && !isset($this->def->info[$name])) { |
|
| 226 | + continue; |
|
| 227 | + } |
|
| 226 | 228 | $list[] = $name; |
| 227 | 229 | } |
| 228 | 230 | return $this->listify($list); |
@@ -250,7 +252,9 @@ discard block |
||
| 250 | 252 | ksort($array); |
| 251 | 253 | $list = array(); |
| 252 | 254 | foreach ($array as $name => $obj) { |
| 253 | - if ($obj === false) continue; |
|
| 255 | + if ($obj === false) { |
|
| 256 | + continue; |
|
| 257 | + } |
|
| 254 | 258 | $list[] = "$name = <i>" . $this->getClass($obj, 'AttrDef_') . '</i>'; |
| 255 | 259 | } |
| 256 | 260 | return $this->listify($list); |
@@ -10,7 +10,7 @@ discard block |
||
| 10 | 10 | |
| 11 | 11 | public function render($config) { |
| 12 | 12 | $ret = ''; |
| 13 | - $this->config =& $config; |
|
| 13 | + $this->config = & $config; |
|
| 14 | 14 | |
| 15 | 15 | $this->def = $config->getHTMLDefinition(); |
| 16 | 16 | |
@@ -60,7 +60,7 @@ discard block |
||
| 60 | 60 | |
| 61 | 61 | $ret .= $this->start('tr'); |
| 62 | 62 | $ret .= $this->element('th', 'Global attributes'); |
| 63 | - $ret .= $this->element('td', $this->listifyAttr($def->info_global_attr),0,0); |
|
| 63 | + $ret .= $this->element('td', $this->listifyAttr($def->info_global_attr), 0, 0); |
|
| 64 | 64 | $ret .= $this->end('tr'); |
| 65 | 65 | |
| 66 | 66 | $ret .= $this->start('tr'); |
@@ -150,7 +150,7 @@ discard block |
||
| 150 | 150 | } |
| 151 | 151 | $ret .= $this->start('tr'); |
| 152 | 152 | $ret .= $this->element('th', 'Allowed attributes'); |
| 153 | - $ret .= $this->element('td',$this->listifyAttr($def->attr), array(), 0); |
|
| 153 | + $ret .= $this->element('td', $this->listifyAttr($def->attr), array(), 0); |
|
| 154 | 154 | $ret .= $this->end('tr'); |
| 155 | 155 | |
| 156 | 156 | if (!empty($def->required_attr)) { |
@@ -192,23 +192,23 @@ discard block |
||
| 192 | 192 | if ($def->type == 'chameleon') { |
| 193 | 193 | |
| 194 | 194 | $ret .= $this->element('td', |
| 195 | - '<em>Block</em>: ' . |
|
| 196 | - $this->escape($this->listifyTagLookup($def->block->elements)),0,0); |
|
| 195 | + '<em>Block</em>: '. |
|
| 196 | + $this->escape($this->listifyTagLookup($def->block->elements)), 0, 0); |
|
| 197 | 197 | $ret .= $this->end('tr'); |
| 198 | 198 | $ret .= $this->start('tr'); |
| 199 | 199 | $ret .= $this->element('td', |
| 200 | - '<em>Inline</em>: ' . |
|
| 201 | - $this->escape($this->listifyTagLookup($def->inline->elements)),0,0); |
|
| 200 | + '<em>Inline</em>: '. |
|
| 201 | + $this->escape($this->listifyTagLookup($def->inline->elements)), 0, 0); |
|
| 202 | 202 | |
| 203 | 203 | } elseif ($def->type == 'custom') { |
| 204 | 204 | |
| 205 | - $ret .= $this->element('td', '<em>'.ucfirst($def->type).'</em>: ' . |
|
| 205 | + $ret .= $this->element('td', '<em>'.ucfirst($def->type).'</em>: '. |
|
| 206 | 206 | $def->dtd_regex); |
| 207 | 207 | |
| 208 | 208 | } else { |
| 209 | 209 | $ret .= $this->element('td', |
| 210 | - '<em>'.ucfirst($def->type).'</em>: ' . |
|
| 211 | - $this->escape($this->listifyTagLookup($elements)),0,0); |
|
| 210 | + '<em>'.ucfirst($def->type).'</em>: '. |
|
| 211 | + $this->escape($this->listifyTagLookup($elements)), 0, 0); |
|
| 212 | 212 | } |
| 213 | 213 | $ret .= $this->end('tr'); |
| 214 | 214 | return $ret; |
@@ -251,7 +251,7 @@ discard block |
||
| 251 | 251 | $list = array(); |
| 252 | 252 | foreach ($array as $name => $obj) { |
| 253 | 253 | if ($obj === false) continue; |
| 254 | - $list[] = "$name = <i>" . $this->getClass($obj, 'AttrDef_') . '</i>'; |
|
| 254 | + $list[] = "$name = <i>".$this->getClass($obj, 'AttrDef_').'</i>'; |
|
| 255 | 255 | } |
| 256 | 256 | return $this->listify($list); |
| 257 | 257 | } |
@@ -5,82 +5,82 @@ |
||
| 5 | 5 | */ |
| 6 | 6 | class HTMLPurifier_PropertyList |
| 7 | 7 | { |
| 8 | - /** |
|
| 9 | - * Internal data-structure for properties |
|
| 10 | - */ |
|
| 11 | - protected $data = array(); |
|
| 8 | + /** |
|
| 9 | + * Internal data-structure for properties |
|
| 10 | + */ |
|
| 11 | + protected $data = array(); |
|
| 12 | 12 | |
| 13 | - /** |
|
| 14 | - * Parent plist |
|
| 15 | - */ |
|
| 16 | - protected $parent; |
|
| 13 | + /** |
|
| 14 | + * Parent plist |
|
| 15 | + */ |
|
| 16 | + protected $parent; |
|
| 17 | 17 | |
| 18 | - protected $cache; |
|
| 18 | + protected $cache; |
|
| 19 | 19 | |
| 20 | - public function __construct($parent = null) { |
|
| 21 | - $this->parent = $parent; |
|
| 22 | - } |
|
| 20 | + public function __construct($parent = null) { |
|
| 21 | + $this->parent = $parent; |
|
| 22 | + } |
|
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * Recursively retrieves the value for a key |
|
| 26 | - */ |
|
| 27 | - public function get($name) { |
|
| 28 | - if ($this->has($name)) return $this->data[$name]; |
|
| 29 | - // possible performance bottleneck, convert to iterative if necessary |
|
| 30 | - if ($this->parent) return $this->parent->get($name); |
|
| 31 | - throw new HTMLPurifier_Exception("Key '$name' not found"); |
|
| 32 | - } |
|
| 24 | + /** |
|
| 25 | + * Recursively retrieves the value for a key |
|
| 26 | + */ |
|
| 27 | + public function get($name) { |
|
| 28 | + if ($this->has($name)) return $this->data[$name]; |
|
| 29 | + // possible performance bottleneck, convert to iterative if necessary |
|
| 30 | + if ($this->parent) return $this->parent->get($name); |
|
| 31 | + throw new HTMLPurifier_Exception("Key '$name' not found"); |
|
| 32 | + } |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * Sets the value of a key, for this plist |
|
| 36 | - */ |
|
| 37 | - public function set($name, $value) { |
|
| 38 | - $this->data[$name] = $value; |
|
| 39 | - } |
|
| 34 | + /** |
|
| 35 | + * Sets the value of a key, for this plist |
|
| 36 | + */ |
|
| 37 | + public function set($name, $value) { |
|
| 38 | + $this->data[$name] = $value; |
|
| 39 | + } |
|
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * Returns true if a given key exists |
|
| 43 | - */ |
|
| 44 | - public function has($name) { |
|
| 45 | - return array_key_exists($name, $this->data); |
|
| 46 | - } |
|
| 41 | + /** |
|
| 42 | + * Returns true if a given key exists |
|
| 43 | + */ |
|
| 44 | + public function has($name) { |
|
| 45 | + return array_key_exists($name, $this->data); |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * Resets a value to the value of it's parent, usually the default. If |
|
| 50 | - * no value is specified, the entire plist is reset. |
|
| 51 | - */ |
|
| 52 | - public function reset($name = null) { |
|
| 53 | - if ($name == null) $this->data = array(); |
|
| 54 | - else unset($this->data[$name]); |
|
| 55 | - } |
|
| 48 | + /** |
|
| 49 | + * Resets a value to the value of it's parent, usually the default. If |
|
| 50 | + * no value is specified, the entire plist is reset. |
|
| 51 | + */ |
|
| 52 | + public function reset($name = null) { |
|
| 53 | + if ($name == null) $this->data = array(); |
|
| 54 | + else unset($this->data[$name]); |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | - /** |
|
| 58 | - * Squashes this property list and all of its property lists into a single |
|
| 59 | - * array, and returns the array. This value is cached by default. |
|
| 60 | - * @param $force If true, ignores the cache and regenerates the array. |
|
| 61 | - */ |
|
| 62 | - public function squash($force = false) { |
|
| 63 | - if ($this->cache !== null && !$force) return $this->cache; |
|
| 64 | - if ($this->parent) { |
|
| 65 | - return $this->cache = array_merge($this->parent->squash($force), $this->data); |
|
| 66 | - } else { |
|
| 67 | - return $this->cache = $this->data; |
|
| 68 | - } |
|
| 69 | - } |
|
| 57 | + /** |
|
| 58 | + * Squashes this property list and all of its property lists into a single |
|
| 59 | + * array, and returns the array. This value is cached by default. |
|
| 60 | + * @param $force If true, ignores the cache and regenerates the array. |
|
| 61 | + */ |
|
| 62 | + public function squash($force = false) { |
|
| 63 | + if ($this->cache !== null && !$force) return $this->cache; |
|
| 64 | + if ($this->parent) { |
|
| 65 | + return $this->cache = array_merge($this->parent->squash($force), $this->data); |
|
| 66 | + } else { |
|
| 67 | + return $this->cache = $this->data; |
|
| 68 | + } |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | - /** |
|
| 72 | - * Returns the parent plist. |
|
| 73 | - */ |
|
| 74 | - public function getParent() { |
|
| 75 | - return $this->parent; |
|
| 76 | - } |
|
| 71 | + /** |
|
| 72 | + * Returns the parent plist. |
|
| 73 | + */ |
|
| 74 | + public function getParent() { |
|
| 75 | + return $this->parent; |
|
| 76 | + } |
|
| 77 | 77 | |
| 78 | - /** |
|
| 79 | - * Sets the parent plist. |
|
| 80 | - */ |
|
| 81 | - public function setParent($plist) { |
|
| 82 | - $this->parent = $plist; |
|
| 83 | - } |
|
| 78 | + /** |
|
| 79 | + * Sets the parent plist. |
|
| 80 | + */ |
|
| 81 | + public function setParent($plist) { |
|
| 82 | + $this->parent = $plist; |
|
| 83 | + } |
|
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | // vim: et sw=4 sts=4 |
@@ -25,9 +25,13 @@ discard block |
||
| 25 | 25 | * Recursively retrieves the value for a key |
| 26 | 26 | */ |
| 27 | 27 | public function get($name) { |
| 28 | - if ($this->has($name)) return $this->data[$name]; |
|
| 28 | + if ($this->has($name)) { |
|
| 29 | + return $this->data[$name]; |
|
| 30 | + } |
|
| 29 | 31 | // possible performance bottleneck, convert to iterative if necessary |
| 30 | - if ($this->parent) return $this->parent->get($name); |
|
| 32 | + if ($this->parent) { |
|
| 33 | + return $this->parent->get($name); |
|
| 34 | + } |
|
| 31 | 35 | throw new HTMLPurifier_Exception("Key '$name' not found"); |
| 32 | 36 | } |
| 33 | 37 | |
@@ -50,8 +54,11 @@ discard block |
||
| 50 | 54 | * no value is specified, the entire plist is reset. |
| 51 | 55 | */ |
| 52 | 56 | public function reset($name = null) { |
| 53 | - if ($name == null) $this->data = array(); |
|
| 54 | - else unset($this->data[$name]); |
|
| 57 | + if ($name == null) { |
|
| 58 | + $this->data = array(); |
|
| 59 | + } else { |
|
| 60 | + unset($this->data[$name]); |
|
| 61 | + } |
|
| 55 | 62 | } |
| 56 | 63 | |
| 57 | 64 | /** |
@@ -60,7 +67,9 @@ discard block |
||
| 60 | 67 | * @param $force If true, ignores the cache and regenerates the array. |
| 61 | 68 | */ |
| 62 | 69 | public function squash($force = false) { |
| 63 | - if ($this->cache !== null && !$force) return $this->cache; |
|
| 70 | + if ($this->cache !== null && !$force) { |
|
| 71 | + return $this->cache; |
|
| 72 | + } |
|
| 64 | 73 | if ($this->parent) { |
| 65 | 74 | return $this->cache = array_merge($this->parent->squash($force), $this->data); |
| 66 | 75 | } else { |
@@ -6,26 +6,26 @@ |
||
| 6 | 6 | class HTMLPurifier_PropertyListIterator extends FilterIterator |
| 7 | 7 | { |
| 8 | 8 | |
| 9 | - protected $l; |
|
| 10 | - protected $filter; |
|
| 9 | + protected $l; |
|
| 10 | + protected $filter; |
|
| 11 | 11 | |
| 12 | - /** |
|
| 13 | - * @param $data Array of data to iterate over |
|
| 14 | - * @param $filter Optional prefix to only allow values of |
|
| 15 | - */ |
|
| 16 | - public function __construct(Iterator $iterator, $filter = null) { |
|
| 17 | - parent::__construct($iterator); |
|
| 18 | - $this->l = strlen($filter); |
|
| 19 | - $this->filter = $filter; |
|
| 20 | - } |
|
| 12 | + /** |
|
| 13 | + * @param $data Array of data to iterate over |
|
| 14 | + * @param $filter Optional prefix to only allow values of |
|
| 15 | + */ |
|
| 16 | + public function __construct(Iterator $iterator, $filter = null) { |
|
| 17 | + parent::__construct($iterator); |
|
| 18 | + $this->l = strlen($filter); |
|
| 19 | + $this->filter = $filter; |
|
| 20 | + } |
|
| 21 | 21 | |
| 22 | - public function accept() { |
|
| 23 | - $key = $this->getInnerIterator()->key(); |
|
| 24 | - if( strncmp($key, $this->filter, $this->l) !== 0 ) { |
|
| 25 | - return false; |
|
| 26 | - } |
|
| 27 | - return true; |
|
| 28 | - } |
|
| 22 | + public function accept() { |
|
| 23 | + $key = $this->getInnerIterator()->key(); |
|
| 24 | + if( strncmp($key, $this->filter, $this->l) !== 0 ) { |
|
| 25 | + return false; |
|
| 26 | + } |
|
| 27 | + return true; |
|
| 28 | + } |
|
| 29 | 29 | |
| 30 | 30 | } |
| 31 | 31 | |
@@ -21,7 +21,7 @@ |
||
| 21 | 21 | |
| 22 | 22 | public function accept() { |
| 23 | 23 | $key = $this->getInnerIterator()->key(); |
| 24 | - if( strncmp($key, $this->filter, $this->l) !== 0 ) { |
|
| 24 | + if (strncmp($key, $this->filter, $this->l) !== 0) { |
|
| 25 | 25 | return false; |
| 26 | 26 | } |
| 27 | 27 | return true; |
@@ -12,14 +12,14 @@ |
||
| 12 | 12 | abstract class HTMLPurifier_Strategy |
| 13 | 13 | { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * Executes the strategy on the tokens. |
|
| 17 | - * |
|
| 18 | - * @param $tokens Array of HTMLPurifier_Token objects to be operated on. |
|
| 19 | - * @param $config Configuration options |
|
| 20 | - * @returns Processed array of token objects. |
|
| 21 | - */ |
|
| 22 | - abstract public function execute($tokens, $config, $context); |
|
| 15 | + /** |
|
| 16 | + * Executes the strategy on the tokens. |
|
| 17 | + * |
|
| 18 | + * @param $tokens Array of HTMLPurifier_Token objects to be operated on. |
|
| 19 | + * @param $config Configuration options |
|
| 20 | + * @returns Processed array of token objects. |
|
| 21 | + */ |
|
| 22 | + abstract public function execute($tokens, $config, $context); |
|
| 23 | 23 | |
| 24 | 24 | } |
| 25 | 25 | |
@@ -6,17 +6,17 @@ |
||
| 6 | 6 | abstract class HTMLPurifier_Strategy_Composite extends HTMLPurifier_Strategy |
| 7 | 7 | { |
| 8 | 8 | |
| 9 | - /** |
|
| 10 | - * List of strategies to run tokens through. |
|
| 11 | - */ |
|
| 12 | - protected $strategies = array(); |
|
| 9 | + /** |
|
| 10 | + * List of strategies to run tokens through. |
|
| 11 | + */ |
|
| 12 | + protected $strategies = array(); |
|
| 13 | 13 | |
| 14 | - public function execute($tokens, $config, $context) { |
|
| 15 | - foreach ($this->strategies as $strategy) { |
|
| 16 | - $tokens = $strategy->execute($tokens, $config, $context); |
|
| 17 | - } |
|
| 18 | - return $tokens; |
|
| 19 | - } |
|
| 14 | + public function execute($tokens, $config, $context) { |
|
| 15 | + foreach ($this->strategies as $strategy) { |
|
| 16 | + $tokens = $strategy->execute($tokens, $config, $context); |
|
| 17 | + } |
|
| 18 | + return $tokens; |
|
| 19 | + } |
|
| 20 | 20 | |
| 21 | 21 | } |
| 22 | 22 | |