11<?php
22
3- class HTMLPurifier_HTML5Config
3+ class HTMLPurifier_HTML5Config extends HTMLPurifier_Config
44{
5+ const REVISION = 0x000106 ;
6+
57 /**
68 * @param string|array|HTMLPurifier_Config $config
79 * @param HTMLPurifier_ConfigSchema $schema
810 * @return HTMLPurifier_Config
911 */
10- public static function create ($ config , HTMLPurifier_ConfigSchema $ schema = null )
12+ public static function create ($ config , $ schema = null )
1113 {
14+ if ($ config instanceof HTMLPurifier_Config) {
15+ $ schema = $ config ->def ;
16+ $ config = null ;
17+ }
18+
1219 if (!$ schema instanceof HTMLPurifier_ConfigSchema) {
1320 $ schema = HTMLPurifier_ConfigSchema::instance ();
1421 }
1522
16- if ($ config instanceof HTMLPurifier_Config) {
17- $ configObj = $ config ;
23+ $ configObj = new self ($ schema );
24+ $ configObj ->set ('Core.Encoding ' , 'UTF-8 ' );
25+ $ configObj ->set ('HTML.Doctype ' , 'HTML 4.01 Transitional ' );
1826
19- } else {
20- $ configObj = new HTMLPurifier_Config ($ schema );
21- $ configObj ->set ('Core.Encoding ' , 'UTF-8 ' );
22- $ configObj ->set ('HTML.Doctype ' , 'HTML 4.01 Transitional ' );
27+ $ configObj ->set ('HTML.DefinitionID ' , __CLASS__ );
28+ $ configObj ->set ('HTML.DefinitionRev ' , self ::REVISION );
2329
24- if (is_string ($ config )) {
25- $ configObj ->loadIni ($ config );
30+ if (is_string ($ config )) {
31+ $ configObj ->loadIni ($ config );
2632
27- } elseif (is_array ($ config )) {
28- $ configObj ->loadArray ($ config );
29- }
33+ } elseif (is_array ($ config )) {
34+ $ configObj ->loadArray ($ config );
3035 }
3136
32- // Prevent auto-finalization of config when retrieving HTML definition
33- $ autoFinalize = $ configObj ->autoFinalize ;
34- $ configObj ->autoFinalize = false ;
35-
36- $ def = $ configObj ->getHTMLDefinition (true );
37- HTMLPurifier_HTML5Definition::setup ($ def );
38-
39- $ configObj ->autoFinalize = $ autoFinalize ;
40-
4137 return $ configObj ;
4238 }
4339
@@ -52,4 +48,17 @@ public static function createDefault()
5248 $ config = self ::create (null , $ schema );
5349 return $ config ;
5450 }
51+
52+ public function getDefinition ($ type , $ raw = false , $ optimized = false )
53+ {
54+ // Setting HTML.* keys removes any previously instantiated HTML
55+ // definition object, so set up HTML5 definition as late as possible
56+ $ needSetup = $ type === 'HTML ' && !isset ($ this ->definitions [$ type ]);
57+ if ($ needSetup ) {
58+ if ($ def = parent ::getDefinition ($ type , true , true )) {
59+ HTMLPurifier_HTML5Definition::setup ($ def );
60+ }
61+ }
62+ return parent ::getDefinition ($ type , $ raw , $ optimized );
63+ }
5564}
0 commit comments