Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class HtmlTool
- {
- /**
- * @var array
- */
- protected static $valid_standard_tags = ['a', 'abbr', 'address', 'area',
- 'article', 'aside', 'audio', 'b',
- 'base', 'bdi', 'bdo', 'blockquote',
- 'body', 'br', 'button', 'canvas',
- 'caption', 'cite', 'code', 'col',
- 'colgroup', 'data', 'datalist', 'dd',
- 'del', 'details', 'dfn', 'dialog',
- 'div', 'dl', 'dt', 'em',
- 'embed', 'fieldset', 'figcaption', 'figure',
- 'footer', 'form', 'h1', 'h2',
- 'h3', 'h4', 'h5', 'h6',
- 'head', 'header', 'hgroup', 'hr',
- 'html', 'i', 'iframe', 'img',
- 'input', 'ins', 'kbd', 'keygen',
- 'label', 'legend', 'li', 'link',
- 'main', 'map', 'mark', 'menu',
- 'menuitem', 'meta', 'meter', 'nav',
- 'noscript', 'object', 'ol', 'optgroup',
- 'option', 'output', 'p', 'param',
- 'pre', 'progress', 'q', 'rb',
- 'rp', 'rt', 'rtc', 'ruby',
- 's', 'samp', 'script', 'section',
- 'select', 'small', 'source', 'span',
- 'strong', 'style', 'sub', 'summary',
- 'sup', 'table', 'tbody', 'td',
- 'template', 'textarea', 'tfoot', 'th',
- 'thead', 'time', 'title', 'tr',
- 'track', 'u', 'ul', 'var',
- 'video', 'wbr'];
- /**
- * @var array
- */
- protected static $valid_self_closed_tags = ['area', 'base', 'br', 'col', 'command', 'embed', 'hr', 'img', 'input', 'keygen', 'link', 'meta', 'param', 'source', 'track', 'wbr'];
- /**
- * @param $str
- * @param $tag
- * @param array $attributes
- * @return string
- */
- public static function wrap($str, $tag, array $attributes = [])/*: String *//* PHP NG */
- {
- if ( in_array( $tag, self::$valid_standard_tags ) )
- {
- if ( in_array( $tag, self::$valid_self_closed_tags ) )
- {
- return "<{$tag} data-content=\"" . htmlspecialchars( $str, ENT_QUOTES ) . self::generate_attributes( $attributes ) . "\"/>";
- }
- else
- {
- return "<{$tag}>" . htmlspecialchars( $str ) . self::generate_attributes( $attributes ) . "</{$tag}>";
- }
- }
- return $str;
- }
- public static function generate_attributes(array $attributes = [])
- {
- $attributes_str = '';
- foreach ( $attributes AS $attr_name => $attr_value )
- {
- $attributes_str .= " {$attr_name}=\"" . htmlspecialchars( $attr_value, ENT_QUOTES ) . '"';
- }
- return $attributes_str;
- }
- public static function __callStatic($name, array $arguments)
- {
- return call_user_func_array( [__CLASS__, $name], $arguments );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement