116 private $_globalAttributes;
128 $this->tagName = $tag_name;
131 $this->_globalAttributes = array(
160 if ( !empty( $name ) ) {
161 $this->data[$name] = $value;
204 foreach ( $this->attributes as $attr ) {
205 if ( isset( $this->$attr ) && !is_null( $this->$attr ) ) {
206 printf(
' %s="%s"', $attr, htmlspecialchars( stripslashes( $this->$attr ) ) );
211 foreach ( $this->_globalAttributes as $attr ) {
212 if ( isset( $this->$attr ) && !is_null( $this->$attr ) ) {
213 if (
'class' == $attr ) {
214 $classes = self::classInline( $this->$attr );
215 if( !empty( $classes ) ) {
216 printf(
' class="%s"', $classes );
220 printf(
' %s="%s"', $attr, htmlspecialchars( stripslashes( $this->$attr ) ) );
226 $data = self::dataInline( $this->data );
227 if ( !empty(
$data ) ) {
228 printf(
' %s',
$data );
232 if (
'/>' !== $this->close ) {
302 if ( !empty( $properties ) ) {
303 foreach ( $properties as $key => $value ) {
304 if ( in_array( $key, $this->attributes ) || in_array( $key, $this->_globalAttributes ) ) {
305 $this->$key = $value;
332 foreach ( $single_attrobutes as $attribute ) {
333 $parts = explode(
'=', $attribute );
334 $stack[$parts[0]] = trim( $parts[1],
"\"''" );
362 foreach ( $single_attrobutes as $attribute ) {
363 $parts = explode(
'=', $attribute );
365 if (
'data-' == substr( $key, 0, 5 ) ) {
366 $key = substr( $key, 5 );
368 $stack[$key] = trim( $parts[1],
"\"''" );
374 if (
'data-' == substr( $key, 0, 5 ) ) {
375 $key = substr( $key, 5 );
377 $stack[$key] = trim( $value,
"\"''" );
405 if( empty( $classes) || is_null( $classes ) ) {
410 if ( is_string( $classes ) ) {
411 $classes = explode(
' ', $classes );
414 $classes = array_filter( array_unique( $classes, SORT_STRING ) );
416 return array_combine( $classes, $classes );
440 if ( empty( $styles ) || is_null( $styles ) ) {
445 if ( is_string( $styles ) ) {
446 $entries = explode(
';', $styles );
448 foreach ( $entries as $entry ) {
449 list( $key, $value ) = explode(
':', $entry, 2 );
450 $styles[$key] = trim( $value );
454 return array_unique( $styles, SORT_STRING );
483 if ( !empty( $additional_attributes ) ) {
484 $additional_attributes = self::sanitizeAttributes( $additional_attributes );
489 $stack[] = sprintf(
'%s="%s"', $key, htmlspecialchars( stripslashes( $value ) ) );
491 return join(
' ', $stack );
515 if ( !empty( $additional_data ) ) {
516 $additional_data = self::sanitizeData( $additional_data );
517 $data = array_merge(
$data, $additional_data );
520 foreach (
$data as $key => $value ) {
521 $stack[] = sprintf(
'data-%s="%s"', $key, htmlspecialchars( stripslashes( $value ) ) );
523 return join(
' ', $stack );
546 public static function classInline( $classes, $additional_classes =
false )
548 $classes = self::sanitizeClasses( $classes );
550 if ( !empty( $additional_classes ) ) {
551 $additional_classes = self::sanitizeClasses( $additional_classes );
552 if ( !empty( $additional_classes ) ) {
553 $classes = array_merge( $classes, $additional_classes );
557 $keys = array_keys( $classes );
559 return join(
' ', $keys );
583 public static function styleInline( $styles, $additional_styles =
false )
585 $styles = self::sanitizeStyles( $styles );
587 if ( !empty( $additional_styles ) ) {
588 $additional_styles = self::sanitizeStyles( $additional_styles );
589 if ( !empty( $additional_styles ) ) {
590 $styles = array_merge( $styles, $additional_styles );
595 foreach ( $styles as $key => $value ) {
596 $result[] = $key .
':' . $value;
599 return rtrim( implode(
';', $result ),
';' );
623 if ( func_num_args() < 2 ) {
627 for ( $i = 1; $i < func_num_args(); $i++ ) {
628 $arg = func_get_arg( $i );
629 if ( !is_null( $arg ) ) {
630 $s = self::sanitizeClasses( $arg );
634 return self::sanitizeClasses(
$class );
826 $this->close =
'</a>';
827 $this->attributes = array(
974 $this->open =
'<button';
975 $this->close =
'</button>';
976 $this->attributes = array(
1065 $this->open =
'<fieldset';
1066 $this->close =
'</fieldset>';
1067 $this->attributes = array(
1080 if ( !empty( $this->legend ) ) {
1081 $this->legend->display();
1202 $this->open =
'<form';
1203 $this->close =
'</form>';
1204 $this->attributes = array(
1308 $this->open =
'<img';
1309 $this->close =
'/>';
1310 $this->attributes = array(
1605 if ( !empty(
$name ) ) {
1606 $this->name =
$name;
1610 if ( !empty(
$name ) && empty(
$id ) ) {
1613 if (
'[]' == substr(
$name, -2 ) ) {
1616 $this->
id = substr(
$name, 0, strlen(
$name ) - 2 );
1625 elseif ( !empty(
$id ) ) {
1630 $this->open =
'<input';
1631 $this->close =
'/>';
1632 $this->attributes = array(
1717 $this->open =
'<label';
1718 $this->close =
'</label>';
1719 $this->attributes = array(
1769 $this->open =
'<legend';
1770 $this->close =
'</legend>';
1771 $this->attributes = array(
1832 $this->_options = $options;
1835 if ( !empty(
$name ) ) {
1836 $this->name =
$name;
1840 if ( !empty(
$name ) && empty(
$id ) ) {
1842 if (
'[]' == substr(
$name, -2 ) ) {
1844 $this->
id = substr(
$name, 0, strlen(
$name ) - 2 );
1852 elseif ( !empty(
$id ) ) {
1857 $this->open =
'<select';
1858 $this->close =
'</select>';
1859 $this->attributes = array(
1877 if ( is_callable( $this->_options ) ) {
1878 $options = call_user_func( $this->_options, $this );
1880 elseif ( is_array( $this->_options ) ) {
1881 $options = $this->_options;
1883 $this->content = $this->
options( $options );
1899 $this->_options( $options );
1913 private function _options( $options )
1915 if ( !empty( $this->_first_item ) ) : ?>
1919 style=
"display:none"><?php echo $this->_first_item ?></option>
1922 foreach ( $options as $key => $option ) : ?>
1923 <?php
if ( is_array( $option ) ) : ?>
1924 <optgroup
class=
"wpdk-form-optiongroup" label=
"<?php echo $key ?>">
1925 <?php $this->_options( $option ); ?>
1929 value=
"<?php echo $key ?>"><?php echo $option ?></option>
1958 if ( is_array( $haystack ) && in_array( $current, $haystack ) ) {
1959 $current = $haystack = 1;
1961 return selected( $haystack, $current,
false );
1997 $this->open =
'<span';
1998 $this->close =
'</span>';
1999 $this->attributes = array();
2129 if ( !empty(
$name ) ) {
2130 $this->name =
$name;
2134 if ( !empty(
$name ) && empty(
$id ) ) {
2136 if (
'[]' == substr(
$name, -2 ) ) {
2138 $this->
id = substr(
$name, 0, strlen(
$name ) - 2 );
2146 elseif ( !empty(
$id ) ) {
2151 $this->open =
'<textarea';
2152 $this->close =
'</textarea>';
2153 $this->attributes = array(