WPDK  1.5.0
WordPress Development Kit
 All Data Structures Files Functions Variables Pages
wpdk-ui-controls.php
Go to the documentation of this file.
1 <?php
2 
14 
15  const ALERT = 'WPDKUIControlAlert';
16  const BUTTON = 'WPDKUIControlButton';
17  const CHECKBOX = 'WPDKUIControlCheckbox';
18  const CHECKBOXES = 'WPDKUIControlCheckboxes';
19  const CHOOSE = 'WPDKUIControlChoose';
20  const CUSTOM = 'WPDKUIControlCustom';
21  const DATE = 'WPDKUIControlDate';
22  const DATETIME = 'WPDKUIControlDateTime';
23  const EMAIL = 'WPDKUIControlEmail';
24  const FILE = 'WPDKUIControlFile';
25  const HIDDEN = 'WPDKUIControlHidden';
26  const LABEL = 'WPDKUIControlLabel';
27  const NUMBER = 'WPDKUIControlNumber';
28  const PASSWORD = 'WPDKUIControlPassword';
29  const PARAGRAPH = 'paragraph';
30  const PHONE = 'WPDKUIControlPhone';
31  const RADIO = 'WPDKUIControlRadio';
32  const SECTION = 'WPDKUIControlSection';
33  const SELECT = 'WPDKUIControlSelect';
34  const SELECT_LIST = 'WPDKUIControlSelectList';
35  const SUBMIT = 'WPDKUIControlSubmit';
36  const SWIPE = 'WPDKUIControlSwipe';
37  const SWITCHBOX = 'WPDKUIControlSwitch';
38  const TEXT = 'WPDKUIControlText';
39  const TEXTAREA = 'WPDKUIControlTextarea';
40 }
41 
72 
80 
86  const APPEND_SELECT_LIST_REMOVE = 'append_select_list_remove';
87 
93  const APPEND_SELECT_LIST_ADD = 'append_select_list_add';
94 
102  protected $attrs = array();
103 
111  protected $class = array();
119  protected $data = array();
127  protected $id = '';
135  protected $item = '';
143  protected $name = '';
151  protected $style = '';
160  private $_sizeForType = array();
161 
169  public function __construct( $item_control )
170  {
171  $this->item = $item_control;
172 
173  // Sanitize the common array key
174 
175  $this->attrs = WPDKHTMLTag::sanitizeAttributes( isset( $this->item['attrs'] ) ? $this->item['attrs'] : array() );
176  $this->data = WPDKHTMLTag::sanitizeData( isset( $this->item['data'] ) ? $this->item['data'] : array() );
177  $this->class = WPDKHTMLTag::sanitizeClasses( isset( $this->item['class'] ) ? $this->item['class'] : array() );
178 
179  if ( isset( $this->item['id'] ) ) {
180  $this->id = sanitize_key( $this->item['id'] );
181  }
182  elseif ( isset( $this->item['name'] ) ) {
183  $this->id = sanitize_key( $this->item['name'] );
184  }
185 
186  $this->name = isset( $this->item['name'] ) ? $this->item['name'] : '';
187 
188  // Input size attribute for specific type
189  $this->_sizeForType = array(
197  );
198  }
199 
207  protected function attrs() {
208  $result = '';
209  if ( isset( $this->item['attrs'] ) ) {
210  if ( is_array( $this->item['attrs'] ) ) {
211  $stack = array();
212  foreach ( $this->item['attrs'] as $attr => $value ) {
213  $stack[] = sprintf( ' %s="%s"', $attr, $value );
214  }
215  if ( !empty( $stack ) ) {
216  $result = join( ' ', $stack );
217  }
218  }
219  elseif ( is_string( $this->item['attrs'] ) ) {
220  $result = $this->item['attrs'];
221  }
222  }
223  return $result;
224  }
225 
239  protected function data()
240  {
241  $result = '';
242  if ( isset( $this->item['data'] ) && !empty( $this->item['data'] ) ) {
243  $result = WPDKHTMLTag::dataInline( $this->item['data'] );
244  }
245  return $result;
246  }
247 
255  protected function classes()
256  {
257  $result = '';
258  if ( isset( $this->item['class'] ) && !empty( $this->item['class'] ) ) {
259  $result = WPDKHTMLTag::classInline( $this->item['class'] );
260  }
261  return $result;
262  }
263 
269  public function display()
270  {
271  echo $this->html();
272  }
273 
279  public function draw()
280  {
281  die( __METHOD__ . ' must be override in your subclass' );
282  }
283 
291  public function html()
292  {
294 
295  echo $this->contentWithKey( 'before' );
296 
297  $this->draw();
298 
299  echo $this->contentWithKey( 'after' );
300 
301  $html = ob_get_contents();
302  ob_end_clean();
303 
304  return $html;
305  }
306 
317  protected function contentWithKey( $key )
318  {
319 
320  $result = '';
321 
322  /*
323  * Append predefined content
324  *
325  * 'append' => WPDKUIControl::APPEND_SELECT_LIST_REMOVE
326  * OR
327  * 'append' => array( WPDKUIControl::APPEND_SELECT_LIST_REMOVE, 'Remove' )
328  * OR
329  * 'append' => array( WPDKUIControl::APPEND_SELECT_LIST_ADD, 'destination_select' )
330  * OR
331  * 'append' => array( WPDKUIControl::APPEND_SELECT_LIST_ADD, 'destination_select', 'Add' )
332  *
333  */
334  if ( 'append' == $key && !empty( $this->item['append'] ) ) {
335  $append = array_merge( (array)$this->item['append'], array(0,0,0) );
336 
337  list( $code, $destination_select, $label ) = $append;
338 
339  switch ( $code ) {
340 
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="' .
345  $label . '" />';
346  break;
347 
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 . '" />';
354  }
355  break;
356  }
357  }
358 
359  if ( isset( $this->item[$key] ) ) {
360  $content = $this->item[$key];
361  if ( is_object( $content ) && is_a( $content, 'WPDKUIControl' ) ) {
362  $result = $content->html();
363  }
364  elseif ( is_array( $content ) && isset( $content['type'] ) ) {
365  $class_name = $content['type'];
366  $control = new $class_name( $content );
367  $result = $control->html();
368  }
369  elseif ( is_string( $content ) ) {
370  $result = $content;
371  }
372  elseif( is_callable( $content ) ) {
373  $result = call_user_func( $content, $this->item );
374  }
375  }
376  return $result;
377  }
378 
387  protected function inputType( $type = WPDKHTMLTagInputType::TEXT, $class = '' )
388  {
389 
390  echo $this->contentWithKey( 'prepend' );
391 
392  // Create the label
393  $label = $this->label();
394 
395  // Display right label
396  echo is_null( $label ) ? '' : $label->html();
397 
398  $input = new WPDKHTMLTagInput( '', $this->name, $this->id );
399  $input->type = $type;
400  $input->class = WPDKHTMLTag::mergeClasses( $this->class, $class, 'wpdk-form-input wpdk-ui-control' );
401  $input->style = WPDKHTMLTag::styleInline( isset( $this->item['style'] ) ? $this->item['style'] : '' );
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;
408 
409  if ( WPDKHTMLTagInputType::HIDDEN != $type ) {
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'] : '';
413  }
414 
415  $input->setPropertiesByArray( isset( $this->item['attrs'] ) ? $this->item['attrs'] : '' );
416 
417  if ( isset( $this->item['locked'] ) && true == $this->item['locked'] ) {
418  $input->readonly = 'readonly';
419  }
420 
421  // Add a clear field button only
422  if ( in_array( $this->item['type'], array( WPDKUIControlType::DATE, WPDKUIControlType::DATETIME ) ) ) {
423  $span_clear = new WPDKHTMLTagSpan();
424  $span_clear->class[] = 'wpdk-form-clear-left';
425  $span_clear->content = $input->html() . WPDKGlyphIcons::html( WPDKGlyphIcons::CANCEL_CIRCLED );
426  $span_clear->display();
427  } else {
428  $input->display();
429  }
430 
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 ) );
433  }
434 
435  echo $this->contentWithKey( 'append' );
436 
437  echo ' ' . $this->guide();
438  }
439 
447  protected function label()
448  {
449 
450  if ( !isset( $this->item['label'] ) || empty( $this->item['label'] ) ) {
451  return null;
452  }
453 
454  $content = '';
455 
456  if ( is_string( $this->item['label'] ) ) {
457  $content = trim( $this->item['label'] );
458  }
459  elseif ( is_array( $this->item['label'] ) ) {
460  $content = trim( $this->item['label']['value'] );
461  }
462 
463  $before_label = isset( $this->item['beforelabel'] ) ? $this->item['beforelabel'] : '';
464  $after_label = isset( $this->item['afterlabel'] ) ? $this->item['afterlabel'] : '';
465 
466  // Special behavior (before) for these controls
467  switch ( $this->item['type'] ) {
468 
470  $after_label = isset( $this->item['afterlabel'] ) ? $this->item['afterlabel'] : '';
471  break;
472 
474  if ( isset( $this->item['label_placement'] ) && 'right' == $this->item['label_placement'] ) {
475  $after_label = isset( $this->item['afterlabel'] ) ? $this->item['afterlabel'] : '';
476  }
477  break;
478 
479  default:
480  if ( empty( $content ) ) {
481  $after_label = isset( $this->item['afterlabel'] ) ? $this->item['afterlabel'] : '';
482  }
483  break;
484  }
485 
486  // Create the lable
487  $label = new WPDKHTMLTagLabel( $before_label . $content . $after_label );
488  $label->for = $this->id;
489  $label->class[] = 'wpdk-has-tooltip';
490  $label->class[] = 'wpdk-form-label';
491  $label->class[] = 'wpdk-ui-control';
492 
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'] : '' );
497  }
498 
499  // Special behavior (after) for these controls
500  switch ( $this->item['type'] ) {
502  $label->class[] = 'wpdk-form-checkbox';
503  $label->class[] = 'wpdk-ui-control';
504  break;
505 
507  if ( !isset( $this->item['label_placement'] ) || 'left' == $this->item['label_placement'] ) {
508  $label->class[] = 'wpdk-form-switch-left';
509  }
510  $label->data = $this->item['data'];
511  break;
512 
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 );
516  }
517  break;
518 
521  $label->class[] = 'wpdk-form-label-top';
522  break;
523  }
524 
525  $label->title = isset( $this->item['title'] ) ? $this->item['title'] : '';
526 
527  return $label;
528  }
529 
539  private function sizeForType( $type ) {
540  if ( !empty( $type ) && isset( $this->_sizeForType[$type] ) && !empty( $this->_sizeForType[$type] ) ) {
541  return $this->_sizeForType[$type];
542  }
543  return self::DEFAULT_SIZE_ATTRIBUTE;
544  }
545 
554  protected function guide() {
555  $result = '';
556  if ( isset( $this->item['guide'] ) && !empty( $this->item['guide'] ) ) {
557  $guide = $this->item['guide'];
558 
559  /* Standard assets. */
560  $button_title = __( 'Guide', WPDK_TEXTDOMAIN );
561 
562  /* Title of modal window. */
563  $title = __( 'Guide', WPDK_TEXTDOMAIN );
564 
565  /* Tooltip. */
566  $tooltip = __( 'Open the guide', WPDK_TEXTDOMAIN );
567 
568  /* Simple guide link: 'unique uri' */
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 );
571  }
572 
573  /* Array args guide: array( 'Title of modal', 'unique uri' ) */
574  if ( is_array( $guide ) && is_numeric( key( $guide ) ) ) {
575  $title = $guide[0];
576  $uri = $guide[1];
577  return sprintf( '<a href="%s" data-title="%s" class="wpdk-guide wpdk-has-tooltip" title="%s">%s</a>', $uri, $title, $tooltip, $button_title );
578  }
579 
580  /*
581  * Array args guide:
582  *
583  * array(
584  * 'title' => 'Title of modal',
585  * 'uri' => 'unique uri',
586  * 'button' => 'Button label',
587  * 'tooltip' => 'Title tooltips',
588  * 'classes' => 'Additional css classes'
589  * );
590  *
591  */
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'] : '';
598 
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 );
600  }
601 
602  $result = '<span>[#internal error - wrong guide]</span>';
603  }
604 
605  return $result;
606  }
607 
608 }
609 
633 
639  public function draw()
640  {
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;
644 
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'] : '';
648 
649  echo $this->contentWithKey( 'prepend' );
650 
651  $alert->display();
652 
653  echo $this->contentWithKey( 'append' );
654  }
655 
656 }
657 
683 
694  public function __construct( $item )
695  {
697  parent::__construct( $item );
698  }
699 
705  public function draw()
706  {
707  echo $this->contentWithKey( 'prepend' );
708 
709  // Since 1.4.21
710  if ( isset( $this->item['content'] ) ) {
711  $button = new WPDKHTMLTagButton( $this->item['content'] );
712  $button->class = $this->class;
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'] : '' );
720  }
721 
722  // Backward compatibility - deprecated - will be remove asap
723  else {
724  $button = new WPDKHTMLTagInput( '', $this->name, $this->id );
725  $button->type = WPDKHTMLTagInputType::BUTTON;
726  $button->class = $this->class;
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'] : '' );
730  }
731  $button->display();
732 
733  echo $this->contentWithKey( 'append' );
734  }
735 
736 }
737 
767 
778  public function __construct( $item ) {
780  parent::__construct( $item );
781  }
782 
788  public function draw() {
789  echo $this->contentWithKey( 'prepend' );
790 
791  /* Create the label. */
792  $label = $this->label();
793 
794  $input = new WPDKHTMLTagInput( '', $this->name, $this->id );
795  $input->type = WPDKHTMLTagInputType::CHECKBOX;
796  $input->class = $this->class;
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'] : '' );
803 
804  if ( isset( $this->item['checked'] ) ) {
805  if ( $input->value === $this->item['checked'] ) {
806  $input->checked = 'checked';
807  }
808  }
809 
810  $input->display();
811 
812  /* Display right label. */
813  echo is_null( $label ) ? '' : $label->html();
814 
815  echo $this->contentWithKey( 'append' );
816 
817  echo ' ' . $this->guide();
818  }
819 
820 }
821 
841 
852  public function __construct( $item )
853  {
855  parent::__construct( $item );
856  }
857 
863  public function draw()
864  {
865  echo $this->contentWithKey( 'prepend' );
866 
867  if ( isset( $this->item['list'] ) && !empty( $this->item['list'] ) && is_array( $this->item['list'] ) ) {
868  $content = '';
869  foreach ( $this->item['list'] as $checkbox ) {
870  /*
871  * @todo Introducing the indent by checcking $checkbox['list']
872  */
873  $checkbox['type'] = WPDKUIControlType::CHECKBOX;
874  $cb = new WPDKUIControlCheckbox( $checkbox );
875  $content .= $cb->html();
876  }
877 
878  if ( isset( $this->item['label'] ) && !empty( $this->item['label'] ) ) {
879  $field_set = new WPDKHTMLTagFieldset( $content, $this->item['label'] );
880  $field_set->display();
881  }
882  else {
883  echo $content;
884  }
885 
886  echo $this->contentWithKey( 'append' );
887 
888  echo ' ' . $this->guide();
889  }
890  }
891 
892 }
893 
922 
933  public function __construct( $item ) {
935  parent::__construct( $item );
936  }
937 
943  public function draw() {
944  echo $this->contentWithKey( 'prepend' );
945 
946  $input_hidden = new WPDKHTMLTagInput( '', $this->name, $this->id );
947  $input_hidden->type = WPDKHTMLTagInputType::HIDDEN;
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'] : '' );
951 
952  $input_button = new WPDKHTMLTagInput( '', '', 'wpdk-form-choose-button_' . $this->id );
953  $input_button->type = WPDKHTMLTagInputType::BUTTON;
954  $input_button->class[] = 'wpdk-form-choose-button';
955  $input_button->value = '...';
956 
957  /* Create the span container. */
958  $span_inner = new WPDKHTMLTagSpan();
959  $span_inner->title = isset( $this->item['title'] ) ? $this->item['title'] : '';
960  $hide_class = isset( $this->item['label'] ) ? $this->item['label'] : '';
961  $span_inner->class = $this->class;
962  $span_inner->class[] = 'wpdk-form-choose-label';
963  $span_inner->class[] = $hide_class;
964 
965  $content = $input_hidden->html() . $span_inner->html() . $input_button->html();
966 
967  /* Create the span container. */
968  $span = new WPDKHTMLTagSpan( $content );
969  $span->class[] = 'wpdk-form-choose wpdk-control-choose';
970 
971  $span->display();
972 
973  echo $this->contentWithKey( 'append' );
974  }
975 
976 }
977 
995 
1005  public function __construct( $item ) {
1006  $item['type'] = WPDKUIControlType::CUSTOM;
1007  parent::__construct( $item );
1008  }
1009 
1015  public function draw() {
1016  $content = '';
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'] );
1021  }
1022  else {
1023  $content = call_user_func( $this->item['content'] );
1024  }
1025  }
1026  elseif ( is_string( $this->item['content'] ) ) {
1027  $content = $this->item['content'];
1028  }
1029  }
1030  echo $content;
1031  }
1032 }
1033 
1062 
1073  public function __construct( $item ) {
1074  $item['type'] = WPDKUIControlType::DATE;
1075  parent::__construct( $item );
1076  }
1077 
1083  public function draw()
1084  {
1085  $this->inputType( WPDKHTMLTagInputType::TEXT, 'wpdk-form-date wpdk-form-has-button-clear-left ' );
1086  }
1087 
1088 }
1089 
1118 
1129  public function __construct( $item ) {
1131  parent::__construct( $item );
1132  }
1133 
1139  public function draw()
1140  {
1141  $this->inputType( WPDKHTMLTagInputType::TEXT, 'wpdk-form-datetime wpdk-form-has-button-clear-left ' );
1142  }
1143 
1144 }
1145 
1174 
1185  public function __construct( $item ) {
1186  $item['type'] = WPDKUIControlType::EMAIL;
1187  parent::__construct( $item );
1188  }
1189 
1195  public function draw() {
1196  $this->inputType( WPDKHTMLTagInputType::TEXT, 'wpdk-form-email' );
1197  }
1198 
1199 }
1200 
1229 
1240  public function __construct( $item ) {
1241  $item['type'] = WPDKUIControlType::FILE;
1242  parent::__construct( $item );
1243  }
1244 
1250  public function draw() {
1251  $this->inputType( WPDKHTMLTagInputType::FILE, 'wpdk-form-file' );
1252  }
1253 
1254 }
1255 
1275 
1286  public function __construct( $item ) {
1287  $item['type'] = WPDKUIControlType::HIDDEN;
1288  parent::__construct( $item );
1289  }
1290 
1296  public function draw() {
1298  }
1299 
1300 }
1301 
1327 
1338  public function __construct( $item )
1339  {
1340  $item['type'] = WPDKUIControlType::LABEL;
1341  parent::__construct( $item );
1342  }
1343 
1349  public function draw()
1350  {
1351  echo $this->contentWithKey( 'prepend' );
1352 
1353  $value = isset( $this->item['value'] ) ? $this->item['value'] : '';
1354 
1355  $label = new WPDKHTMLTagLabel( $value, $this->name, $this->id );
1356  $label->class = $this->class;
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'] : '' );
1361 
1362  $label->display();
1363 
1364  echo $this->contentWithKey( 'append' );
1365  }
1366 
1367 }
1368 
1398 
1409  public function __construct( $item ) {
1410  $item['type'] = WPDKUIControlType::NUMBER;
1411  parent::__construct( $item );
1412  }
1413 
1419  public function draw() {
1420  $this->inputType( WPDKHTMLTagInputType::NUMBER, 'wpdk-form-number' );
1421  }
1422 
1423 }
1424 
1452 
1463  public function __construct( $item ) {
1465  parent::__construct( $item );
1466  }
1467 
1473  public function draw() {
1474  $this->inputType( WPDKHTMLTagInputType::PASSWORD, 'wpdk-form-password' );
1475  }
1476 
1477 }
1478 
1479 // TODO Paragraph
1480 
1508 
1519  public function __construct( $item ) {
1520  $item['type'] = WPDKUIControlType::PHONE;
1521  parent::__construct( $item );
1522  }
1523 
1529  public function draw() {
1530  $this->inputType( WPDKHTMLTagInputType::TEL, 'wpdk-form-phone' );
1531  }
1532 
1533 }
1534 
1564 
1575  public function __construct( $item ) {
1576  $item['type'] = WPDKUIControlType::RADIO;
1577  parent::__construct( $item );
1578  }
1579 
1585  public function draw() {
1586  $this->inputType( WPDKHTMLTagInputType::RADIO, 'wpdk-form-radio' );
1587  }
1588 
1589 }
1590 
1617  public function __construct( $item ) {
1618  $item['type'] = WPDKUIControlType::SELECT;
1619  parent::__construct( $item );
1620  }
1621 
1627  public function draw() {
1628  /* Nothing to display. */
1629  }
1630 }
1631 
1659 
1670  public function __construct( $item )
1671  {
1672  $item['type'] = WPDKUIControlType::SELECT;
1673  parent::__construct( $item );
1674  }
1675 
1681  public function draw()
1682  {
1683 
1684  echo $this->contentWithKey( 'prepend' );
1685 
1686  // Create the label
1687  $label = $this->label();
1688 
1689  // Display right label
1690  echo is_null( $label ) ? '' : $label->html();
1691 
1692  $input = new WPDKHTMLTagSelect( $this->item['options'], $this->name, $this->id );
1693  $input->class = $this->class;
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'] : '' );
1704 
1705  $input->display();
1706 
1707  echo $this->contentWithKey( 'append' );
1708  }
1709 
1710 }
1711 
1737 
1748  public function __construct( $item )
1749  {
1751  parent::__construct( $item );
1752  }
1753 
1759  public function draw()
1760  {
1761  echo $this->contentWithKey( 'prepend' );
1762 
1763  // Create the label
1764  $label = $this->label();
1765 
1766  // Display right label
1767  echo is_null( $label ) ? '' : $label->html();
1768 
1769  $input = new WPDKHTMLTagSelect( $this->item['options'], $this->name, $this->id );
1770  $input->class = $this->class;
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'] : '' );
1780 
1781  $input->display();
1782 
1783  echo $this->contentWithKey( 'append' );
1784  }
1785 
1786 }
1787 
1814 
1825  public function __construct( $item ) {
1826  $item['type'] = WPDKUIControlType::SUBMIT;
1827  parent::__construct( $item );
1828  }
1829 
1835  public function draw() {
1836  echo $this->contentWithKey( 'prepend' );
1837 
1838  $label = $this->label();
1839 
1840  /* Display right label. */
1841  echo is_null( $label ) ? '' : $label->html();
1842 
1843  $input = new WPDKHTMLTagInput( '', $this->name, $this->id );
1844  $input->type = WPDKHTMLTagInputType::SUBMIT;
1845  $input->class = $this->class;
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'] : '' );
1849 
1850  $input->display();
1851 
1852  echo $this->contentWithKey( 'append' );
1853  }
1854 }
1855 
1884 
1895  public function __construct( $item )
1896  {
1897  $item['type'] = WPDKUIControlType::SWIPE;
1898  parent::__construct( $item );
1899  }
1900 
1906  public function draw()
1907  {
1908 
1909  // since 1.5.0 - check for popover
1910  $popover = false;
1911  if ( isset( $this->item['popover'] ) && is_a( $this->item['popover'], 'WPDKUIPopover' ) ) :
1912 
1918  $popover = $this->item['popover']; ?>
1919 
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 ) ?>'>
1929  <?php endif;
1930 
1931  echo $this->contentWithKey( 'prepend' );
1932 
1933  // Create the label
1934  $label = $this->label();
1935 
1936  // Display left label
1937  if ( !isset( $this->item['label_placement'] ) || 'left' == $this->item['label_placement'] ) {
1938  echo is_null( $label ) ? '' : $label->html();
1939  }
1940 
1941  $input_hidden = new WPDKHTMLTagInput( '', $this->name, 'wpdk-swipe-' . $this->id );
1942  $input_hidden->type = WPDKHTMLTagInputType::HIDDEN;
1943  $input_hidden->value = isset( $this->item['value'] ) ? $this->item['value'] : '';
1944 
1945  $status = wpdk_is_bool( $this->item['value'] ) ? 'wpdk-form-swipe-on' : '';
1946 
1947  $swipe = new WPDKHTMLTagSpan( '<span></span>' . $input_hidden->html() );
1948  $class = isset( $this->item['class'] ) ? $this->item['class'] : '';
1949  $swipe->class = WPDKHTMLTag::mergeClasses( $class, 'wpdk-form-swipe ' . $status );
1950  $swipe->id = $this->id;
1951  $swipe->data = isset( $this->item['data'] ) ? $this->item['data'] : array();
1952 
1953  if ( isset( $this->item['userdata'] ) ) {
1954  $swipe->data['userdata'] = esc_attr( $this->item['userdata'] );
1955  }
1956 
1957  // Title and tooltip
1958  $swipe->title = isset( $this->item['title'] ) ? $this->item['title'] : '';
1959  if ( !empty( $swipe->title ) ) {
1960  $swipe->class[] = 'wpdk-has-tooltip';
1961  }
1962 
1963  $swipe->setPropertiesByArray( isset( $this->item['attrs'] ) ? $this->item['attrs'] : '' );
1964 
1965  $swipe->display();
1966 
1967  // Display right label
1968  if ( isset( $this->item['label_placement'] ) && 'right' == $this->item['label_placement'] ) {
1969  echo is_null( $label ) ? '' : $label->html();
1970  }
1971 
1972  echo $this->contentWithKey( 'append' );
1973 
1974  if( $popover ) {
1975  echo '</div>';
1976  }
1977  }
1978 }
1979 
2010 
2021  public function __construct( $item )
2022  {
2024  parent::__construct( $item );
2025  }
2026 
2032  public function draw()
2033  {
2034  echo $this->contentWithKey( 'prepend' );
2035 
2036  $input = new WPDKHTMLTagInput( '', $this->name, $this->id );
2037  $input->type = WPDKHTMLTagInputType::CHECKBOX;
2038  $input->class = $this->class;
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'] : '' );
2045 
2046  if ( isset( $this->item['checked'] ) ) {
2047  if ( $input->value === $this->item['checked'] ) {
2048  $input->checked = 'checked';
2049  }
2050  }
2051 
2052  $input->display();
2053 
2054  /* Create the label. */
2055  $label = $this->label();
2056  $label->display();
2057 
2058  echo $this->contentWithKey( 'append' );
2059 
2060  echo ' ' . $this->guide();
2061  }
2062 }
2063 
2119  public function __construct( $item ) {
2120  $item['type'] = WPDKUIControlType::TEXT;
2121  parent::__construct( $item );
2122  }
2123 
2129  public function draw() {
2131  }
2132 }
2133 
2162 
2173  public function __construct( $item ) {
2175  parent::__construct( $item );
2176  }
2177 
2183  public function draw() {
2184  echo $this->contentWithKey( 'prepend' );
2185 
2186  /* Create the label. @todo usually you like set this label on the top. */
2187  $label = $this->label();
2188 
2189  /* Display right label. */
2190  echo is_null( $label ) ? '' : $label->html();
2191 
2192  $content = isset( $this->item['value'] ) ? $this->item['value'] : '';
2193 
2194  $input = new WPDKHTMLTagTextarea( $content, $this->name, $this->id );
2195  $input->class = $this->class;
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'] : '' );
2205 
2206  $input->display();
2207 
2208  echo $this->contentWithKey( 'append' );
2209  }
2210 }
2211 
2241 
2247  private $_cla;
2248 
2256  public function __construct( $cla )
2257  {
2258  $this->_cla = $cla;
2259  }
2260 
2269  public static function init( $cla )
2270  {
2271  return new self( $cla );
2272  }
2273 
2284  public static function item( $item )
2285  {
2286  ob_start();
2287  self::_processItem( $item );
2288  $content = ob_get_contents();
2289  ob_end_clean();
2290  return $content;
2291  }
2292 
2300  private function _processItem( $item )
2301  {
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();
2306  }
2307  }
2308 
2314  public function display()
2315  {
2316  echo $this->html();
2317  }
2318 
2326  public function html()
2327  {
2328  // Buffering...
2330 
2331  foreach ( $this->_cla as $key => $value ) : ?>
2332 
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 ) ?>
2337  </div>
2338  </fieldset>
2339 
2340  <?php endforeach;
2341 
2342  return WPDKHTML::endCompress();
2343  }
2344 
2352  private function _processRows( $rows )
2353  {
2354  foreach ( $rows as $item ) {
2355  if ( is_string( $item ) && !empty( $item ) ) {
2356  ?>
2357  <div class="wpdk-form-description"><?php echo $item ?></div><?php
2358  }
2359  elseif ( isset( $item['type'] ) ) {
2360  $this->_processItem( $item );
2361  }
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 );
2366  }
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 );
2371  }
2372  }
2373  }
2374 
2384  private function container( $item )
2385  {
2386  $class = isset( $item['class'] ) ? $item['class'] : '';
2387  return sprintf( '<div class="%s">', $class );
2388  }
2389 
2390 }