border.php 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. <?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
  2. /**
  3. *
  4. * Field: border
  5. *
  6. * @since 1.0.0
  7. * @version 1.0.0
  8. *
  9. */
  10. if ( ! class_exists( 'CSF_Field_border' ) ) {
  11. class CSF_Field_border extends CSF_Fields {
  12. public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) {
  13. parent::__construct( $field, $value, $unique, $where, $parent );
  14. }
  15. public function render() {
  16. $args = wp_parse_args( $this->field, array(
  17. 'top_icon' => '<i class="fas fa-long-arrow-alt-up"></i>',
  18. 'left_icon' => '<i class="fas fa-long-arrow-alt-left"></i>',
  19. 'bottom_icon' => '<i class="fas fa-long-arrow-alt-down"></i>',
  20. 'right_icon' => '<i class="fas fa-long-arrow-alt-right"></i>',
  21. 'all_icon' => '<i class="fas fa-arrows-alt"></i>',
  22. 'top_placeholder' => esc_html__( 'top', 'sakurairo_csf' ),
  23. 'right_placeholder' => esc_html__( 'right', 'sakurairo_csf' ),
  24. 'bottom_placeholder' => esc_html__( 'bottom', 'sakurairo_csf' ),
  25. 'left_placeholder' => esc_html__( 'left', 'sakurairo_csf' ),
  26. 'all_placeholder' => esc_html__( 'all', 'sakurairo_csf' ),
  27. 'top' => true,
  28. 'left' => true,
  29. 'bottom' => true,
  30. 'right' => true,
  31. 'all' => false,
  32. 'color' => true,
  33. 'style' => true,
  34. 'unit' => 'px',
  35. ) );
  36. $default_value = array(
  37. 'top' => '',
  38. 'right' => '',
  39. 'bottom' => '',
  40. 'left' => '',
  41. 'color' => '',
  42. 'style' => 'solid',
  43. 'all' => '',
  44. );
  45. $border_props = array(
  46. 'solid' => esc_html__( 'Solid', 'sakurairo_csf' ),
  47. 'dashed' => esc_html__( 'Dashed', 'sakurairo_csf' ),
  48. 'dotted' => esc_html__( 'Dotted', 'sakurairo_csf' ),
  49. 'double' => esc_html__( 'Double', 'sakurairo_csf' ),
  50. 'inset' => esc_html__( 'Inset', 'sakurairo_csf' ),
  51. 'outset' => esc_html__( 'Outset', 'sakurairo_csf' ),
  52. 'groove' => esc_html__( 'Groove', 'sakurairo_csf' ),
  53. 'ridge' => esc_html__( 'ridge', 'sakurairo_csf' ),
  54. 'none' => esc_html__( 'None', 'sakurairo_csf' )
  55. );
  56. $default_value = ( ! empty( $this->field['default'] ) ) ? wp_parse_args( $this->field['default'], $default_value ) : $default_value;
  57. $value = wp_parse_args( $this->value, $default_value );
  58. echo $this->field_before();
  59. echo '<div class="csf--inputs" data-depend-id="'. esc_attr( $this->field['id'] ) .'">';
  60. if ( ! empty( $args['all'] ) ) {
  61. $placeholder = ( ! empty( $args['all_placeholder'] ) ) ? ' placeholder="'. esc_attr( $args['all_placeholder'] ) .'"' : '';
  62. echo '<div class="csf--input">';
  63. echo ( ! empty( $args['all_icon'] ) ) ? '<span class="csf--label csf--icon">'. $args['all_icon'] .'</span>' : '';
  64. echo '<input type="number" name="'. esc_attr( $this->field_name( '[all]' ) ) .'" value="'. esc_attr( $value['all'] ) .'"'. $placeholder .' class="csf-input-number csf--is-unit" step="any" />';
  65. echo ( ! empty( $args['unit'] ) ) ? '<span class="csf--label csf--unit">'. esc_attr( $args['unit'] ) .'</span>' : '';
  66. echo '</div>';
  67. } else {
  68. $properties = array();
  69. foreach ( array( 'top', 'right', 'bottom', 'left' ) as $prop ) {
  70. if ( ! empty( $args[$prop] ) ) {
  71. $properties[] = $prop;
  72. }
  73. }
  74. $properties = ( $properties === array( 'right', 'left' ) ) ? array_reverse( $properties ) : $properties;
  75. foreach ( $properties as $property ) {
  76. $placeholder = ( ! empty( $args[$property.'_placeholder'] ) ) ? ' placeholder="'. esc_attr( $args[$property.'_placeholder'] ) .'"' : '';
  77. echo '<div class="csf--input">';
  78. echo ( ! empty( $args[$property.'_icon'] ) ) ? '<span class="csf--label csf--icon">'. $args[$property.'_icon'] .'</span>' : '';
  79. echo '<input type="number" name="'. esc_attr( $this->field_name( '['. $property .']' ) ) .'" value="'. esc_attr( $value[$property] ) .'"'. $placeholder .' class="csf-input-number csf--is-unit" step="any" />';
  80. echo ( ! empty( $args['unit'] ) ) ? '<span class="csf--label csf--unit">'. esc_attr( $args['unit'] ) .'</span>' : '';
  81. echo '</div>';
  82. }
  83. }
  84. if ( ! empty( $args['style'] ) ) {
  85. echo '<div class="csf--input">';
  86. echo '<select name="'. esc_attr( $this->field_name( '[style]' ) ) .'">';
  87. foreach ( $border_props as $border_prop_key => $border_prop_value ) {
  88. $selected = ( $value['style'] === $border_prop_key ) ? ' selected' : '';
  89. echo '<option value="'. esc_attr( $border_prop_key ) .'"'. esc_attr( $selected ) .'>'. esc_attr( $border_prop_value ) .'</option>';
  90. }
  91. echo '</select>';
  92. echo '</div>';
  93. }
  94. echo '</div>';
  95. if ( ! empty( $args['color'] ) ) {
  96. $default_color_attr = ( ! empty( $default_value['color'] ) ) ? ' data-default-color="'. esc_attr( $default_value['color'] ) .'"' : '';
  97. echo '<div class="csf--color">';
  98. echo '<div class="csf-field-color">';
  99. echo '<input type="text" name="'. esc_attr( $this->field_name( '[color]' ) ) .'" value="'. esc_attr( $value['color'] ) .'" class="csf-color"'. $default_color_attr .' />';
  100. echo '</div>';
  101. echo '</div>';
  102. }
  103. echo $this->field_after();
  104. }
  105. public function output() {
  106. $output = '';
  107. $unit = ( ! empty( $this->value['unit'] ) ) ? $this->value['unit'] : 'px';
  108. $important = ( ! empty( $this->field['output_important'] ) ) ? '!important' : '';
  109. $element = ( is_array( $this->field['output'] ) ) ? join( ',', $this->field['output'] ) : $this->field['output'];
  110. // properties
  111. $top = ( isset( $this->value['top'] ) && $this->value['top'] !== '' ) ? $this->value['top'] : '';
  112. $right = ( isset( $this->value['right'] ) && $this->value['right'] !== '' ) ? $this->value['right'] : '';
  113. $bottom = ( isset( $this->value['bottom'] ) && $this->value['bottom'] !== '' ) ? $this->value['bottom'] : '';
  114. $left = ( isset( $this->value['left'] ) && $this->value['left'] !== '' ) ? $this->value['left'] : '';
  115. $style = ( isset( $this->value['style'] ) && $this->value['style'] !== '' ) ? $this->value['style'] : '';
  116. $color = ( isset( $this->value['color'] ) && $this->value['color'] !== '' ) ? $this->value['color'] : '';
  117. $all = ( isset( $this->value['all'] ) && $this->value['all'] !== '' ) ? $this->value['all'] : '';
  118. if ( ! empty( $this->field['all'] ) && ( $all !== '' || $color !== '' ) ) {
  119. $output = $element .'{';
  120. $output .= ( $all !== '' ) ? 'border-width:'. $all . $unit . $important .';' : '';
  121. $output .= ( $color !== '' ) ? 'border-color:'. $color . $important .';' : '';
  122. $output .= ( $style !== '' ) ? 'border-style:'. $style . $important .';' : '';
  123. $output .= '}';
  124. } else if ( $top !== '' || $right !== '' || $bottom !== '' || $left !== '' || $color !== '' ) {
  125. $output = $element .'{';
  126. $output .= ( $top !== '' ) ? 'border-top-width:'. $top . $unit . $important .';' : '';
  127. $output .= ( $right !== '' ) ? 'border-right-width:'. $right . $unit . $important .';' : '';
  128. $output .= ( $bottom !== '' ) ? 'border-bottom-width:'. $bottom . $unit . $important .';' : '';
  129. $output .= ( $left !== '' ) ? 'border-left-width:'. $left . $unit . $important .';' : '';
  130. $output .= ( $color !== '' ) ? 'border-color:'. $color . $important .';' : '';
  131. $output .= ( $style !== '' ) ? 'border-style:'. $style . $important .';' : '';
  132. $output .= '}';
  133. }
  134. $this->parent->output_css .= $output;
  135. return $output;
  136. }
  137. }
  138. }