1 | <?php |
||
22 | class html extends xml |
||
23 | { |
||
24 | /** |
||
25 | * @var html\Writer The writer instance to use by default |
||
26 | */ |
||
27 | public static $writer=null; |
||
28 | |||
29 | 1 | public static function __callStatic( $name, $args ) |
|
30 | { |
||
31 | 1 | if ( !isset(self::$writer) ) { |
|
32 | 1 | self::$writer = new html\Writer(); |
|
33 | } |
||
34 | 1 | return call_user_func_array( [ self::$writer, $name ], $args ); |
|
35 | } |
||
36 | |||
37 | /** |
||
38 | * This parses an HTML string and returns a Proxy |
||
39 | * @param string|Proxy $html |
||
40 | * @param string $encoding |
||
41 | * @return Proxy |
||
42 | * @throws \arc\Exception |
||
43 | */ |
||
44 | 4 | public static function parse( $html=null, $encoding = null ) |
|
49 | |||
50 | /** |
||
51 | * Returns a guaranteed valid HTML attribute value. Removes illegal characters. |
||
52 | * @param string|array|bool $value |
||
53 | * @return string |
||
54 | */ |
||
55 | 1 | static public function value( $value ) |
|
|
|||
56 | { |
||
57 | 1 | if ( is_array( $value ) ) { |
|
58 | $content = array_reduce( $value, function( $result, $value ) |
||
59 | { |
||
60 | return $result . ' ' . static::value( $value ); |
||
61 | } ); |
||
62 | 1 | } else if ( is_bool( $value ) ) { |
|
63 | $content = $value ? 'true' : 'false'; |
||
64 | } else { |
||
65 | 1 | $content = htmlspecialchars( (string) $value, ENT_QUOTES, 'UTF-8' ); |
|
66 | } |
||
67 | 1 | return $content; |
|
68 | } |
||
69 | |||
70 | /** |
||
71 | * Returns a guaranteed valid HTML attribute. Removes illegal characters. |
||
72 | * Allows for 'naked' attributes, without a value. |
||
73 | * @param string $name |
||
74 | * @param string|array|bool $value |
||
75 | * @return string |
||
76 | */ |
||
77 | 1 | static public function attribute( $name, $value ) |
|
87 | |||
88 | /** |
||
89 | * Returns a HTML doctype string |
||
90 | * @param string $version The doctype version to use, available are: 'html5', 'html4' (strict), 'transitional' (html4) and 'xhtml' |
||
91 | * @retun string |
||
92 | */ |
||
93 | 1 | static public function doctype( $version='html5' ) |
|
104 | |||
105 | } |
||
106 |