| 1 |
<?php |
| 2 |
/** |
| 3 |
* The framework column fields file. |
| 4 |
* |
| 5 |
* @package Smart_Post_Show |
| 6 |
* @subpackage Smart_Post_Show/admin |
| 7 |
*/ |
| 8 |
|
| 9 |
if ( ! defined( 'ABSPATH' ) ) { |
| 10 |
exit; // Exit if accessed directly. |
| 11 |
} |
| 12 |
|
| 13 |
/** |
| 14 |
* |
| 15 |
* Field: column |
| 16 |
* |
| 17 |
* @since 1.0.0 |
| 18 |
* @version 1.0.0 |
| 19 |
*/ |
| 20 |
if ( ! class_exists( 'SP_PC_Field_column' ) ) { |
| 21 |
|
| 22 |
/** |
| 23 |
* The column field class. |
| 24 |
*/ |
| 25 |
class SP_PC_Field_column extends SP_PC_Fields { |
| 26 |
|
| 27 |
/** |
| 28 |
* Column field constructor. |
| 29 |
* |
| 30 |
* @param array $field The field type. |
| 31 |
* @param string $value The values of the field. |
| 32 |
* @param string $unique The unique ID for the field. |
| 33 |
* @param string $where To where show the output CSS. |
| 34 |
* @param string $parent The parent args. |
| 35 |
*/ |
| 36 |
public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) { |
| 37 |
parent::__construct( $field, $value, $unique, $where, $parent ); |
| 38 |
} |
| 39 |
|
| 40 |
/** |
| 41 |
* Render column function. |
| 42 |
* |
| 43 |
* @return void |
| 44 |
*/ |
| 45 |
public function render() { |
| 46 |
|
| 47 |
$args = wp_parse_args( |
| 48 |
$this->field, |
| 49 |
array( |
| 50 |
'lg_desktop_icon' => '<i class="fa fa-television"></i>', |
| 51 |
'desktop_icon' => '<i class="fa fa-desktop"></i>', |
| 52 |
'tablet_icon' => '<i class="fa fa-tablet"></i>', |
| 53 |
'mobile_landscape_icon' => '<i class="fa fa-mobile"></i>', |
| 54 |
'mobile_icon' => '<i class="fa fa-mobile"></i>', |
| 55 |
'all_icon' => '<i class="fa fa-arrows"></i>', |
| 56 |
'lg_desktop_placeholder' => esc_html__( 'Large Desktop', 'post-carousel' ), |
| 57 |
'desktop_placeholder' => esc_html__( 'Desktop', 'post-carousel' ), |
| 58 |
'tablet_placeholder' => esc_html__( 'Tablet', 'post-carousel' ), |
| 59 |
'mobile_landscape_placeholder' => esc_html__( 'Mobile Landscape', 'post-carousel' ), |
| 60 |
'mobile_placeholder' => esc_html__( 'Mobile', 'post-carousel' ), |
| 61 |
'all_placeholder' => esc_html__( 'all', 'post-carousel' ), |
| 62 |
'lg_desktop' => true, |
| 63 |
'desktop' => true, |
| 64 |
'tablet' => true, |
| 65 |
'mobile_landscape' => true, |
| 66 |
'mobile' => true, |
| 67 |
'min' => '1', |
| 68 |
'unit' => false, |
| 69 |
'decimal' => false, |
| 70 |
'all' => false, |
| 71 |
'units' => array( 'px', '%', 'em' ), |
| 72 |
) |
| 73 |
); |
| 74 |
|
| 75 |
$default_values = array( |
| 76 |
'lg_desktop' => '5', |
| 77 |
'desktop' => '4', |
| 78 |
'tablet' => '3', |
| 79 |
'mobile_landscape' => '2', |
| 80 |
'mobile' => '1', |
| 81 |
'min' => '', |
| 82 |
'all' => '', |
| 83 |
'unit' => 'px', |
| 84 |
); |
| 85 |
|
| 86 |
// $value = wp_parse_args( $this->value, $default_values ); |
| 87 |
$value = wp_parse_args( $this->value, $default_values ); |
| 88 |
$unit = ( count( $args['units'] ) === 1 && ! empty( $args['unit'] ) ) ? $args['units'][0] : ''; |
| 89 |
$is_unit = ( ! empty( $unit ) ) ? ' spf--is-unit' : ''; |
| 90 |
|
| 91 |
echo wp_kses_post( $this->field_before() ); |
| 92 |
|
| 93 |
echo '<div class="spf--inputs">'; |
| 94 |
|
| 95 |
$min = ( isset( $args['min'] ) ) ? ' min="' . $args['min'] . '"' : ''; |
| 96 |
$decimal = ( isset( $args['decimal'] ) && $args['decimal'] ) ? ' step="any"' : ''; |
| 97 |
|
| 98 |
if ( ! empty( $args['all'] ) ) { |
| 99 |
|
| 100 |
$placeholder = ( ! empty( $args['all_placeholder'] ) ) ? ' placeholder="' . $args['all_placeholder'] . '"' : ''; |
| 101 |
|
| 102 |
echo '<div class="spf--input">'; |
| 103 |
echo ( ! empty( $args['all_icon'] ) ) ? '<span class="spf--label spf--icon">' . wp_kses_post( $args['all_icon'] ) . '</span>' : ''; |
| 104 |
echo '<input type="number" name="' . esc_attr( $this->field_name( '[all]' ) ) . '" value="' . esc_attr( $value['all'] ) . '"' . wp_kses_post( $placeholder ) . wp_kses_post( $min . $decimal ) . ' class="spf-number" required/>'; |
| 105 |
echo ( count( $args['units'] ) === 1 && ! empty( $args['unit'] ) ) ? '<span class="spf--label spf--unit">' . esc_html( $args['units'][0] ) . '</span>' : ''; |
| 106 |
echo '</div>'; |
| 107 |
|
| 108 |
} else { |
| 109 |
|
| 110 |
$properties = array(); |
| 111 |
|
| 112 |
foreach ( array( 'lg_desktop', 'desktop', 'tablet', 'mobile_landscape', 'mobile' ) as $prop ) { |
| 113 |
if ( ! empty( $args[ $prop ] ) ) { |
| 114 |
$properties[] = $prop; |
| 115 |
} |
| 116 |
} |
| 117 |
|
| 118 |
$properties = ( array( 'tablet', 'mobile' ) === $properties ) ? array_reverse( $properties ) : $properties; |
| 119 |
|
| 120 |
foreach ( $properties as $property ) { |
| 121 |
|
| 122 |
$placeholder = ( ! empty( $args[ $property . '_placeholder' ] ) ) ? ' placeholder="' . $args[ $property . '_placeholder' ] . '"' : ''; |
| 123 |
|
| 124 |
echo '<div class="spf--input">'; |
| 125 |
echo ( ! empty( $args[ $property . '_icon' ] ) ) ? '<span class="spf--label spf--icon">' . wp_kses_post( $args[ $property . '_icon' ] ) . '</span>' : ''; |
| 126 |
echo '<input type="number" name="' . esc_attr( $this->field_name( '[' . $property . ']' ) ) . '" value="' . esc_attr( $value[ $property ] ) . '"' . wp_kses_post( $placeholder ) . wp_kses_post( $min ) . ' class="spf-number" required/>'; |
| 127 |
echo ( count( $args['units'] ) === 1 && ! empty( $args['unit'] ) ) ? '<span class="spf--label spf--unit">' . esc_html( $args['units'][0] ) . '</span>' : ''; |
| 128 |
echo '</div>'; |
| 129 |
|
| 130 |
} |
| 131 |
} |
| 132 |
|
| 133 |
if ( ! empty( $args['unit'] ) && count( $args['units'] ) > 1 ) { |
| 134 |
echo '<div class="spf--input">'; |
| 135 |
|
| 136 |
echo '<select name="' . esc_attr( $this->field_name( '[unit]' ) ) . '">'; |
| 137 |
foreach ( $args['units'] as $unit ) { |
| 138 |
$selected = ( $value['unit'] === $unit ) ? ' selected' : ''; |
| 139 |
echo '<option value="' . esc_attr( $unit ) . '"' . esc_attr( $selected ) . '>' . esc_html( $unit ) . '</option>'; |
| 140 |
} |
| 141 |
echo '</select>'; |
| 142 |
echo '</div>'; |
| 143 |
} |
| 144 |
|
| 145 |
echo '</div>'; |
| 146 |
|
| 147 |
echo wp_kses_post( $this->field_after() ); |
| 148 |
} |
| 149 |
} |
| 150 |
} |
| 151 |
|