15 const ALERT =
'WPDKUIControlAlert';
16 const BUTTON =
'WPDKUIControlButton';
19 const CHOOSE =
'WPDKUIControlChoose';
20 const CUSTOM =
'WPDKUIControlCustom';
21 const DATE =
'WPDKUIControlDate';
23 const EMAIL =
'WPDKUIControlEmail';
24 const FILE =
'WPDKUIControlFile';
25 const HIDDEN =
'WPDKUIControlHidden';
26 const LABEL =
'WPDKUIControlLabel';
27 const NUMBER =
'WPDKUIControlNumber';
30 const PHONE =
'WPDKUIControlPhone';
31 const RADIO =
'WPDKUIControlRadio';
33 const SELECT =
'WPDKUIControlSelect';
35 const SUBMIT =
'WPDKUIControlSubmit';
36 const SWIPE =
'WPDKUIControlSwipe';
38 const TEXT =
'WPDKUIControlText';
160 private $_sizeForType = array();
171 $this->item = $item_control;
179 if ( isset( $this->item['id'] ) ) {
180 $this->
id = sanitize_key( $this->item[
'id'] );
182 elseif ( isset( $this->item[
'name'] ) ) {
183 $this->
id = sanitize_key( $this->item[
'name'] );
186 $this->name = isset( $this->item[
'name'] ) ? $this->item[
'name'] :
'';
189 $this->_sizeForType = array(
209 if ( isset( $this->item[
'attrs'] ) ) {
210 if ( is_array( $this->item[
'attrs'] ) ) {
212 foreach ( $this->item[
'attrs'] as $attr => $value ) {
213 $stack[] = sprintf(
' %s="%s"', $attr, $value );
215 if ( !empty( $stack ) ) {
216 $result = join(
' ', $stack );
219 elseif ( is_string( $this->item[
'attrs'] ) ) {
220 $result = $this->item[
'attrs'];
242 if ( isset( $this->item[
'data'] ) && !empty( $this->item[
'data'] ) ) {
258 if ( isset( $this->item[
'class'] ) && !empty( $this->item[
'class'] ) ) {
281 die( __METHOD__ .
' must be override in your subclass' );
301 $html = ob_get_contents();
334 if (
'append' == $key && !empty( $this->item[
'append'] ) ) {
335 $append = array_merge( (array)$this->item[
'append'], array(0,0,0) );
337 list( $code, $destination_select, $label ) = $append;
342 $label = empty( $destination_select ) ? __(
'Remove', WPDK_TEXTDOMAIN ) : $destination_select;
343 $this->item[
'append'] =
'<input data-remove_from="' . $this->item[
'id'] .
344 '" class="wpdk-form-button wpdk-form-button-remove button-secondary" style="vertical-align:top" type="button" value="' .
349 if ( !empty( $destination_select ) ) {
350 $label = empty( $label ) ? __(
'Add', WPDK_TEXTDOMAIN ) : $label;
351 $this->item[
'append'] =
352 '<input type="button" data-copy="' . $this->item[
'name'] .
'" data-paste="' . $destination_select .
353 '" class="wpdk-form-button wpdk-form-button-copy-paste button-secondary" value="' . $label .
'" />';
359 if ( isset( $this->item[$key] ) ) {
360 $content = $this->item[$key];
361 if ( is_object( $content ) && is_a( $content,
'WPDKUIControl' ) ) {
362 $result = $content->html();
364 elseif ( is_array( $content ) && isset( $content[
'type'] ) ) {
365 $class_name = $content[
'type'];
366 $control =
new $class_name( $content );
367 $result = $control->html();
369 elseif ( is_string( $content ) ) {
372 elseif( is_callable( $content ) ) {
373 $result = call_user_func( $content, $this->item );
393 $label = $this->
label();
396 echo is_null( $label ) ?
'' : $label->html();
399 $input->type = $type;
402 $input->data = isset( $this->item[
'data'] ) ? $this->item[
'data'] :
'';
403 $input->value = isset( $this->item[
'value'] ) ? $this->item[
'value'] :
'';
404 $input->autocomplete = isset( $this->item[
'autocomplete'] ) ? $this->item[
'autocomplete'] : null;
405 $input->disabled = isset( $this->item[
'disabled'] ) ? $this->item[
'disabled'] ?
'disabled' : null : null;
406 $input->readonly = isset( $this->item[
'readonly'] ) ? $this->item[
'readonly'] ?
'readonly' : null : null;
407 $input->required = isset( $this->item[
'required'] ) ? $this->item[
'required'] ?
'required' : null : null;
410 $input->size = isset( $this->item[
'size'] ) ? $this->item[
'size'] : $this->sizeForType( $this->item[
'type'] );
411 $input->title = isset( $this->item[
'title'] ) ? $this->item[
'title'] :
'';
412 $input->placeholder = isset( $this->item[
'placeholder'] ) ? $this->item[
'placeholder'] :
'';
415 $input->setPropertiesByArray( isset( $this->item[
'attrs'] ) ? $this->item[
'attrs'] :
'' );
417 if ( isset( $this->item[
'locked'] ) &&
true == $this->item[
'locked'] ) {
418 $input->readonly =
'readonly';
424 $span_clear->class[] =
'wpdk-form-clear-left';
426 $span_clear->display();
431 if ( isset( $this->item[
'locked'] ) &&
true == $this->item[
'locked'] ) {
432 printf(
'<span title="%s" class="wpdk-form-locked wpdk-has-tooltip"></span>', __(
'This field is locked for your security. However you can unlock just by click here.', WPDK_TEXTDOMAIN ) );
437 echo
' ' . $this->
guide();
450 if ( !isset( $this->item[
'label'] ) || empty( $this->item[
'label'] ) ) {
456 if ( is_string( $this->item[
'label'] ) ) {
457 $content = trim( $this->item[
'label'] );
459 elseif ( is_array( $this->item[
'label'] ) ) {
460 $content = trim( $this->item[
'label'][
'value'] );
463 $before_label = isset( $this->item[
'beforelabel'] ) ? $this->item[
'beforelabel'] :
'';
464 $after_label = isset( $this->item[
'afterlabel'] ) ? $this->item[
'afterlabel'] :
'';
467 switch ( $this->item[
'type'] ) {
470 $after_label = isset( $this->item[
'afterlabel'] ) ? $this->item[
'afterlabel'] :
'';
474 if ( isset( $this->item[
'label_placement'] ) &&
'right' == $this->item[
'label_placement'] ) {
475 $after_label = isset( $this->item[
'afterlabel'] ) ? $this->item[
'afterlabel'] :
'';
480 if ( empty( $content ) ) {
481 $after_label = isset( $this->item[
'afterlabel'] ) ? $this->item[
'afterlabel'] :
'';
489 $label->class[] =
'wpdk-has-tooltip';
490 $label->class[] =
'wpdk-form-label';
491 $label->class[] =
'wpdk-ui-control';
493 if ( is_array( $this->item[
'label'] ) ) {
494 $label->data = isset( $this->item[
'label'][
'data'] ) ? $this->item[
'label'][
'data'] :
'';
495 $label->style = isset( $this->item[
'label'][
'style'] ) ? $this->item[
'label'][
'style'] :
'';
496 $label->setPropertiesByArray( isset( $this->item[
'label'][
'attrs'] ) ? $this->item[
'label'][
'attrs'] :
'' );
500 switch ( $this->item[
'type'] ) {
502 $label->class[] =
'wpdk-form-checkbox';
503 $label->class[] =
'wpdk-ui-control';
507 if ( !isset( $this->item[
'label_placement'] ) ||
'left' == $this->item[
'label_placement'] ) {
508 $label->class[] =
'wpdk-form-switch-left';
510 $label->data = $this->item[
'data'];
514 if ( isset( $this->item[
'label_placement'] ) &&
'right' == $this->item[
'label_placement'] ) {
515 $label->class = str_replace(
'wpdk-has-tooltip',
'wpdk-form-label-inline', $label->class );
521 $label->class[] =
'wpdk-form-label-top';
525 $label->title = isset( $this->item[
'title'] ) ? $this->item[
'title'] :
'';
539 private function sizeForType( $type ) {
540 if ( !empty( $type ) && isset( $this->_sizeForType[$type] ) && !empty( $this->_sizeForType[$type] ) ) {
541 return $this->_sizeForType[$type];
543 return self::DEFAULT_SIZE_ATTRIBUTE;
556 if ( isset( $this->item[
'guide'] ) && !empty( $this->item[
'guide'] ) ) {
557 $guide = $this->item[
'guide'];
560 $button_title = __(
'Guide', WPDK_TEXTDOMAIN );
563 $title = __(
'Guide', WPDK_TEXTDOMAIN );
566 $tooltip = __(
'Open the guide', WPDK_TEXTDOMAIN );
569 if ( is_string( $guide ) ) {
570 return sprintf(
'<a href="%s" data-title="%s" class="wpdk-guide wpdk-has-tooltip" title="%s">%s</a>', $guide, $title, $tooltip, $button_title );
574 if ( is_array( $guide ) && is_numeric( key( $guide ) ) ) {
577 return sprintf(
'<a href="%s" data-title="%s" class="wpdk-guide wpdk-has-tooltip" title="%s">%s</a>', $uri, $title, $tooltip, $button_title );
592 if ( is_array( $guide ) && !empty( $guide[
'uri'] ) ) {
593 $uri = $guide[
'uri'];
594 $title = isset( $guide[
'title'] ) ? $guide[
'title'] : $title;
595 $button_title = isset( $guide[
'button'] ) ? $guide[
'button'] : $button_title;
596 $tooltip = isset( $guide[
'tooltip'] ) ? $guide[
'tooltip'] : $tooltip;
597 $classes = isset( $guide[
'classes'] ) ? $guide[
'classes'] :
'';
599 return sprintf(
'<a href="%s" data-title="%s" class="wpdk-guide wpdk-has-tooltip %s" title="%s">%s</a>', $uri, $title, $classes, $tooltip, $button_title );
602 $result =
'<span>[#internal error - wrong guide]</span>';
641 $value = isset( $this->item[
'value'] ) ? $this->item[
'value'] :
'';
642 $title = isset( $this->item[
'title'] ) ? $this->item[
'title'] :
'';
643 $alert_type = isset( $this->item[
'alert_type'] ) ? $this->item[
'alert_type'] : WPDKTwitterBootstrapAlertType::INFORMATION;
645 $alert =
new WPDKTwitterBootstrapAlert( $this->
id, $value, $alert_type, $title );
646 $alert->dismissButton = isset( $this->item[
'dismiss_button'] ) ? $this->item[
'dismiss_button'] :
true;
647 $alert->class = isset( $this->item[
'classes'] ) ? $this->item[
'classes'] : isset( $this->item[
'class'] ) ? $this->item[
'class'] :
'';
697 parent::__construct(
$item );
710 if ( isset( $this->item[
'content'] ) ) {
713 $button->class[] =
'wpdk-form-button';
714 $button->class[] =
'wpdk-ui-control';
715 $button->id = isset( $this->item[
'id'] ) ? $this->item[
'id'] :
'';
716 $button->name = isset( $this->item[
'name'] ) ? $this->item[
'name'] :
'';
717 $button->data = isset( $this->item[
'data'] ) ? $this->item[
'data'] :
'';
718 $button->value = isset( $this->item[
'value'] ) ? $this->item[
'value'] :
'';
719 $button->setPropertiesByArray( isset( $this->item[
'attrs'] ) ? $this->item[
'attrs'] :
'' );
727 $button->data = isset( $this->item[
'data'] ) ? $this->item[
'data'] :
'';
728 $button->value = isset( $this->item[
'value'] ) ? $this->item[
'value'] :
'';
729 $button->setPropertiesByArray( isset( $this->item[
'attrs'] ) ? $this->item[
'attrs'] :
'' );
780 parent::__construct(
$item );
792 $label = $this->
label();
797 $input->class[] =
'wpdk-form-checkbox';
798 $input->class[] =
'wpdk-ui-control';
799 $input->data = isset( $this->item[
'data'] ) ? $this->item[
'data'] :
'';
800 $input->value = isset( $this->item[
'value'] ) ? $this->item[
'value'] :
'';
801 $input->title = isset( $this->item[
'title'] ) ? $this->item[
'title'] :
'';
802 $input->setPropertiesByArray( isset( $this->item[
'attrs'] ) ? $this->item[
'attrs'] :
'' );
804 if ( isset( $this->item[
'checked'] ) ) {
805 if ( $input->value === $this->item[
'checked'] ) {
806 $input->checked =
'checked';
813 echo is_null( $label ) ?
'' : $label->html();
817 echo
' ' . $this->
guide();
855 parent::__construct(
$item );
867 if ( isset( $this->item[
'list'] ) && !empty( $this->item[
'list'] ) && is_array( $this->item[
'list'] ) ) {
869 foreach ( $this->item[
'list'] as $checkbox ) {
875 $content .= $cb->html();
878 if ( isset( $this->item[
'label'] ) && !empty( $this->item[
'label'] ) ) {
880 $field_set->display();
888 echo
' ' . $this->
guide();
935 parent::__construct(
$item );
948 $input_hidden->data = isset( $this->item[
'data'] ) ? $this->item[
'data'] :
'';
949 $input_hidden->value = isset( $this->item[
'value'] ) ? $this->item[
'value'] :
'';
950 $input_hidden->setPropertiesByArray( isset( $this->item[
'attrs'] ) ? $this->item[
'attrs'] :
'' );
952 $input_button =
new WPDKHTMLTagInput(
'',
'',
'wpdk-form-choose-button_' . $this->
id );
954 $input_button->class[] =
'wpdk-form-choose-button';
955 $input_button->value =
'...';
959 $span_inner->title = isset( $this->item[
'title'] ) ? $this->item[
'title'] :
'';
960 $hide_class = isset( $this->item[
'label'] ) ? $this->item[
'label'] :
'';
962 $span_inner->class[] =
'wpdk-form-choose-label';
963 $span_inner->class[] = $hide_class;
965 $content = $input_hidden->html() . $span_inner->html() . $input_button->html();
969 $span->class[] =
'wpdk-form-choose wpdk-control-choose';
1007 parent::__construct(
$item );
1017 if ( isset( $this->item[
'content'] ) ) {
1018 if ( is_callable( $this->item[
'content'] ) ) {
1019 if ( isset( $this->item[
'param'] ) ) {
1020 $content = call_user_func( $this->item[
'content'], $this->item[
'param'] );
1023 $content = call_user_func( $this->item[
'content'] );
1026 elseif ( is_string( $this->item[
'content'] ) ) {
1027 $content = $this->item[
'content'];
1075 parent::__construct(
$item );
1131 parent::__construct(
$item );
1187 parent::__construct(
$item );
1242 parent::__construct(
$item );
1288 parent::__construct(
$item );
1341 parent::__construct(
$item );
1353 $value = isset( $this->item[
'value'] ) ? $this->item[
'value'] :
'';
1357 $label->class[] =
'wpdk-form-label-inline';
1358 $label->data = isset( $this->item[
'data'] ) ? $this->item[
'data'] :
'';
1359 $label->style = isset( $this->item[
'style'] ) ? $this->item[
'style'] :
'';
1360 $label->setPropertiesByArray( isset( $this->item[
'attrs'] ) ? $this->item[
'attrs'] :
'' );
1411 parent::__construct(
$item );
1465 parent::__construct(
$item );
1521 parent::__construct(
$item );
1577 parent::__construct(
$item );
1619 parent::__construct(
$item );
1673 parent::__construct(
$item );
1687 $label = $this->
label();
1690 echo is_null( $label ) ?
'' : $label->html();
1692 $input =
new WPDKHTMLTagSelect( $this->item[
'options'], $this->name, $this->
id );
1694 $input->class[] =
'wpdk-form-select';
1695 $input->class[] =
'wpdk-ui-control';
1696 $input->_first_item = isset( $this->item[
'first_item'] ) ? $this->item[
'first_item'] :
'';
1697 $input->data = isset( $this->item[
'data'] ) ? $this->item[
'data'] : array();
1698 $input->style = isset( $this->item[
'style'] ) ? $this->item[
'style'] : null;
1699 $input->multiple = isset( $this->item[
'multiple'] ) ? $this->item[
'multiple'] : null;
1700 $input->size = isset( $this->item[
'size'] ) ? $this->item[
'size'] : null;
1701 $input->disabled = isset( $this->item[
'disabled'] ) ? $this->item[
'disabled'] ?
'disabled' : null : null;
1702 $input->value = isset( $this->item[
'value'] ) ? $this->item[
'value'] : array();
1703 $input->setPropertiesByArray( isset( $this->item[
'attrs'] ) ? $this->item[
'attrs'] :
'' );
1751 parent::__construct(
$item );
1764 $label = $this->
label();
1767 echo is_null( $label ) ?
'' : $label->html();
1769 $input =
new WPDKHTMLTagSelect( $this->item[
'options'], $this->name, $this->
id );
1771 $input->class[] =
'wpdk-form-select';
1772 $input->class[] =
'wpdk-form-select-size';
1773 $input->class[] =
'wpdk-ui-control';
1774 $input->data = isset( $this->item[
'data'] ) ? $this->item[
'data'] : array();
1775 $input->style = isset( $this->item[
'style'] ) ? $this->item[
'style'] : null;
1776 $input->multiple =
'multiple';
1777 $input->size = isset( $this->item[
'size'] ) ? $this->item[
'size'] : 5;
1778 $input->value = isset( $this->item[
'value'] ) ? $this->item[
'value'] : array();
1779 $input->setPropertiesByArray( isset( $this->item[
'attrs'] ) ? $this->item[
'attrs'] :
'' );
1827 parent::__construct(
$item );
1838 $label = $this->
label();
1841 echo is_null( $label ) ?
'' : $label->html();
1846 $input->data = isset( $this->item[
'data'] ) ? $this->item[
'data'] :
'';
1847 $input->value = isset( $this->item[
'value'] ) ? $this->item[
'value'] :
'';
1848 $input->setPropertiesByArray( isset( $this->item[
'attrs'] ) ? $this->item[
'attrs'] :
'' );
1898 parent::__construct(
$item );
1906 public function draw()
1911 if ( isset( $this->item[
'popover'] ) && is_a( $this->item[
'popover'],
'WPDKUIPopover' ) ) :
1918 $popover = $this->item[
'popover']; ?>
1920 <div
class=
'wpdk-has-popover wpdk-popover-container'
1921 data-title=
'<?php echo $popover->title() ?>'
1922 data-content=
'<?php echo esc_attr( $popover->content() ) ?>'
1923 data-placement=
'<?php echo $popover->placement ?>'
1924 data-trigger=
'<?php echo $popover->trigger ?>'
1925 data-
html=
'<?php echo $popover->html ? 'true' : 'false' ?>'
1926 data-animation=
'<?php echo $popover->animation ? 'true' : 'false' ?>'
1927 data-container=
'<?php echo $popover->container ?>'
1928 data-delay=
'<?php echo empty( $popover->delay ) ? 0 : json_encode( $popover->delay ) ?>'>
1934 $label = $this->
label();
1937 if ( !isset( $this->item[
'label_placement'] ) ||
'left' == $this->item[
'label_placement'] ) {
1938 echo is_null( $label ) ?
'' : $label->html();
1941 $input_hidden =
new WPDKHTMLTagInput(
'', $this->name,
'wpdk-swipe-' . $this->
id );
1943 $input_hidden->value = isset( $this->item[
'value'] ) ? $this->item[
'value'] :
'';
1945 $status =
wpdk_is_bool( $this->item[
'value'] ) ?
'wpdk-form-swipe-on' :
'';
1947 $swipe =
new WPDKHTMLTagSpan(
'<span></span>' . $input_hidden->html() );
1948 $class = isset( $this->item[
'class'] ) ? $this->item[
'class'] :
'';
1951 $swipe->data = isset( $this->item[
'data'] ) ? $this->item[
'data'] : array();
1953 if ( isset( $this->item[
'userdata'] ) ) {
1954 $swipe->data[
'userdata'] = esc_attr( $this->item[
'userdata'] );
1958 $swipe->title = isset( $this->item[
'title'] ) ? $this->item[
'title'] :
'';
1959 if ( !empty( $swipe->title ) ) {
1960 $swipe->class[] =
'wpdk-has-tooltip';
1963 $swipe->setPropertiesByArray( isset( $this->item[
'attrs'] ) ? $this->item[
'attrs'] :
'' );
1968 if ( isset( $this->item[
'label_placement'] ) &&
'right' == $this->item[
'label_placement'] ) {
1969 echo is_null( $label ) ?
'' : $label->html();
2024 parent::__construct(
$item );
2039 $input->class[] =
'wpdk-form-switch';
2040 $input->class[] =
'wpdk-ui-control';
2041 $input->data = isset( $this->item[
'data'] ) ? $this->item[
'data'] :
'';
2042 $input->value = isset( $this->item[
'value'] ) ? $this->item[
'value'] :
'';
2043 $input->title = isset( $this->item[
'title'] ) ? $this->item[
'title'] :
'';
2044 $input->setPropertiesByArray( isset( $this->item[
'attrs'] ) ? $this->item[
'attrs'] :
'' );
2046 if ( isset( $this->item[
'checked'] ) ) {
2047 if ( $input->value === $this->item[
'checked'] ) {
2048 $input->checked =
'checked';
2055 $label = $this->
label();
2060 echo
' ' . $this->
guide();
2121 parent::__construct(
$item );
2175 parent::__construct(
$item );
2187 $label = $this->
label();
2190 echo is_null( $label ) ?
'' : $label->html();
2192 $content = isset( $this->item[
'value'] ) ? $this->item[
'value'] :
'';
2196 $input->class[] =
'wpdk-form-textarea';
2197 $input->class[] =
'wpdk-ui-control';
2198 $input->data = isset( $this->item[
'data'] ) ? $this->item[
'data'] :
'';
2199 $input->content = $content;
2200 $input->cols = isset( $this->item[
'cols'] ) ? $this->item[
'cols'] :
'10';
2201 $input->rows = isset( $this->item[
'rows'] ) ? $this->item[
'rows'] :
'4';
2202 $input->disabled = isset( $this->item[
'disabled'] ) ? $this->item[
'disabled'] ?
'disabled' : null : null;
2203 $input->placeholder = isset( $this->item[
'placeholder'] ) ? $this->item[
'placeholder'] : null;
2204 $input->setPropertiesByArray( isset( $this->item[
'attrs'] ) ? $this->item[
'attrs'] :
'' );
2269 public static function init( $cla )
2271 return new self( $cla );
2284 public static function item( $item )
2287 self::_processItem( $item );
2288 $content = ob_get_contents();
2300 private function _processItem( $item )
2302 $class_name = isset( $item[
'type'] ) ? $item[
'type'] :
'';
2303 if ( !empty( $class_name ) && class_exists( $class_name ) ) {
2304 $control =
new $class_name( $item );
2305 $control->display();
2331 foreach ( $this->_cla as $key => $value ) : ?>
2333 <fieldset
class=
"wpdk-form-fieldset wpdk-ui-control">
2334 <legend><?php echo $key ?></legend>
2335 <div
class=
"wpdk-fieldset-container">
2336 <?php $this->_processRows( $value ) ?>
2352 private function _processRows( $rows )
2354 foreach ( $rows as $item ) {
2355 if ( is_string( $item ) && !empty( $item ) ) {
2357 <div
class=
"wpdk-form-description"><?php echo $item ?></div><?php
2359 elseif ( isset( $item[
'type'] ) ) {
2360 $this->_processItem( $item );
2362 elseif ( isset( $item[
'container'] ) ) {
2363 echo apply_filters(
'wpdk_form_html_group_before', $this->container( $item ), $item );
2364 $this->_processRows( $item[
'container'] );
2365 echo apply_filters(
'wpdk_form_html_group_after',
'</div>', $item );
2367 elseif ( !empty( $item ) ) {
2368 echo apply_filters(
'wpdk_form_html_row_before',
'<div class="wpdk-form-row">', $item );
2369 $this->_processRows( $item );
2370 echo apply_filters(
'wpdk_form_html_row_after',
'</div>', $item );
2384 private function container( $item )
2386 $class = isset( $item[
'class'] ) ? $item[
'class'] :
'';
2387 return sprintf(
'<div class="%s">', $class );