first commit

This commit is contained in:
2024-07-15 11:28:08 +02:00
commit f52d538ea5
21891 changed files with 6161164 additions and 0 deletions

View File

@@ -0,0 +1,180 @@
<?php
/**
* Control base class
*/
/**
* CX_Controls_Base abstract class
*/
if ( ! class_exists( 'CX_Controls_Base' ) ) {
/**
* CX_Controls_Base Abstract Class
*
* @since 1.0.0
*/
abstract class CX_Controls_Base {
/**
* Base URL
*
* @var null
*/
public $base_url = null;
/**
* Settings list
*
* @since 1.0.0
* @var array
*/
protected $settings = array();
/**
* Default settings array
*
* @var array
*/
public $defaults_settings = array();
/**
* Constructor method for the CX_Controls_Base class.
*
* @since 1.0.0
*/
public function __construct( $args = array() ) {
$this->defaults_settings['id'] = 'cx-control-' . uniqid();
$this->settings = wp_parse_args( $args, $this->defaults_settings );
$this->init();
add_action( 'wp_enqueue_scripts', array( $this, 'register_depends' ) );
add_action( 'admin_enqueue_scripts', array( $this, 'register_depends' ) );
}
/**
* Returns control settings
*
* @return array
*/
public function get_settings() {
return $this->settings;
}
/**
* Render methos. Each UI element must implement own method
* @return [type] [description]
*/
abstract public function render();
/**
* Optional additional initializtion for control. Can be overriden from child class if needed.
* @return [type] [description]
*/
public function init() {}
/**
* Retrun scripts dependencies list for current control.
*
* @return array
*/
public function get_script_depends() {
return array();
}
/**
* Register required dependencies
*
* @return void
*/
public function register_depends() {}
/**
* Retrun styles dependencies list for current control.
*
* @return array
*/
public function get_style_depends() {
return array();
}
/**
* Set up base URL for next usage
*
* @param string $url array
*/
public function set_base_url( $url = '' ) {
$this->base_url = $url;
}
/**
* Get control value
*
* @since 1.0.0
* @return string control value.
*/
public function get_value() {
return $this->settings['value'];
}
/**
* Set control value
*
* @since 1.0.0
* @param [type] $value new.
*/
public function set_value( $value ) {
$this->settings['value'] = $value;
}
/**
* Get control name
*
* @since 1.0.0
* @return string control name.
*/
public function get_name() {
return $this->settings['name'];
}
/**
* Set control name
*
* @since 1.0.0
* @param [type] $name new control name.
* @throws Exception Invalid control name.
*/
public function set_name( $name ) {
$name = (string) $name;
if ( '' !== $name ) {
$this->settings['name'] = $name;
} else {
throw new Exception( "Invalid control name '" . $name . "'. Name can't be empty." );
}
}
/**
* Returns attributes string from attributes array
*
* @return string
*/
public function get_attr_string( $attr = array() ) {
$result = array();
foreach ( $attr as $key => $value ) {
if ( $key === $value ) {
$result[] = $key;
} else {
$result[] = sprintf( '%1$s="%2$s"', $key, $value );
}
}
return implode( ' ', $result );
}
}
}

View File

@@ -0,0 +1,79 @@
<?php
/**
* UI controls manager class
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
if ( ! class_exists( 'CX_Controls_Manager' ) ) {
/**
* Define CX_Controls_Manager class
*/
class CX_Controls_Manager {
/**
* Path to controls folder for current Inteface Builder instance
*
* @var string
*/
private $base_path = '';
/**
* Path to controls folder for current Inteface Builder instance
*
* @var string
*/
private $base_url = '';
/**
* Constructor for the class
*/
public function __construct( $base_path = null, $base_url = null ) {
$this->base_path = trailingslashit( $base_path );
$this->base_url = trailingslashit( $base_url );
require $this->base_path . 'inc/class-cx-controls-base.php';
$this->load_controls();
}
/**
* Automatically load found conrols
*
* @return void
*/
public function load_controls() {
foreach ( glob( $this->base_path . 'inc/controls/*.php' ) as $file ) {
require $file;
}
}
/**
* Register new control instance
*
* @return object
*/
public function register_control( $type = 'text', $args = array() ) {
$prefix = 'CX_Control_';
$classname = $prefix . str_replace( ' ', '_', ucwords( str_replace( '-', ' ', $type ) ) );
if ( ! class_exists( $classname ) ) {
return false;
}
$instance = new $classname( $args );
$instance->set_base_url( $this->base_url );
return $instance;
}
}
}

View File

@@ -0,0 +1,74 @@
<?php
/**
* Class for the building ui-button elements.
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
if ( ! class_exists( 'CX_Control_Button' ) ) {
/**
* Class for the building ui-button elements.
*/
class CX_Control_Button extends CX_Controls_Base {
/**
* Default settings.
*
* @since 1.0.0
* @var array
*/
public $defaults_settings = array(
'id' => 'cherry-ui-button-id',
'name' => 'cherry-ui-button-name',
'value' => 'button',
'disabled' => false,
'form' => '',
'formaction' => '',
'button_type' => 'button',
'style' => 'normal',
'content' => 'Button',
'class' => '',
);
/**
* Render html UI_Button.
*
* @since 1.0.0
*/
public function render() {
$classes = array(
'cx-button',
'cx-button-' . $this->settings['style'] . '-style',
$this->settings['class'],
);
$classes = array_filter( $classes );
$class = trim( implode( ' ', $classes ) );
$attrs = array(
'type' => esc_attr( $this->settings['button_type'] ),
'id' => esc_attr( $this->settings['id'] ),
'name' => esc_attr( $this->settings['name'] ),
'class' => esc_attr( $class ),
'form' => esc_attr( $this->settings['form'] ),
'formaction' => esc_attr( $this->settings['formaction'] ),
);
if ( filter_var( $this->settings['disabled'], FILTER_VALIDATE_BOOLEAN ) ) {
$attrs['disabled'] = 'disabled';
}
$html = sprintf(
'<button %1$s>%2$s</button>',
$this->get_attr_string( $attrs ),
$this->settings['content']
);
return $html;
}
}
}

View File

@@ -0,0 +1,105 @@
<?php
/**
* Class for the building checkbox elements.
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
if ( ! class_exists( 'CX_Control_Checkbox' ) ) {
/**
* Class for the building CX_Control_Checkbox elements.
*/
class CX_Control_Checkbox extends CX_Controls_Base {
/**
* Default settings.
*
* @since 1.0.0
* @var array
*/
public $defaults_settings = array(
'id' => 'cx-checkbox-id',
'name' => 'cx-checkbox-name',
'value' => array(
'checkbox-1' => 'true',
'checkbox-2' => 'true',
'checkbox-3' => 'true',
),
'options' => array(
'checkbox-1' => 'checkbox 1',
'checkbox-2' => 'checkbox 2',
'checkbox-3' => 'checkbox 3',
),
'label' => '',
'class' => '',
);
/**
* Render html UI_Checkbox.
*
* @since 1.0.0
*/
public function render() {
$html = '';
$class = implode( ' ',
array(
$this->settings['class'],
)
);
$html .= '<div class="cx-ui-control-container ' . esc_attr( $class ) . '">';
$counter = 0;
if ( isset( $this->settings['options_callback'] ) ) {
$this->settings['options'] = call_user_func( $this->settings['options_callback'] );
}
if ( ! empty( $this->settings['options'] ) && is_array( $this->settings['options'] ) ) {
if ( ! is_array( $this->settings['value'] ) ) {
$this->settings['value'] = array( $this->settings['value'] );
}
if ( '' !== $this->settings['label'] ) {
$html .= '<label class="cx-label" for="' . esc_attr( $this->settings['id'] ) . '">' . esc_html( $this->settings['label'] ) . '</label> ';
}
foreach ( $this->settings['options'] as $option => $option_value ) {
if ( ! empty( $this->settings['value'] ) ) {
$option_checked = array_key_exists( $option, $this->settings['value'] ) ? $option : '';
$item_value = ! empty( $option_checked ) ? $this->settings['value'][ $option ] : 'false';
} else {
$option_checked = '';
$item_value = 'false';
}
$checked = ( ! empty( $option_checked ) && filter_var( $item_value, FILTER_VALIDATE_BOOLEAN ) ) ? 'checked' : '';
$item_value = filter_var( $item_value, FILTER_VALIDATE_BOOLEAN ) ? 'true' : 'false';
$option_label = isset( $option_value ) && is_array( $option_value ) ? $option_value['label'] : $option_value;
$html .= '<div class="cx-checkbox-item-wrap">';
$html .= '<span class="cx-label-content">';
$html .= '<input type="hidden" id="' . esc_attr( $this->settings['id'] ) . '-' . $counter . '" class="cx-checkbox-input" name="' . esc_attr( $this->settings['name'] ) . '[' . $option . ']" ' . $checked . ' value="' . $item_value . '">';
$html .= '<span class="cx-checkbox-item"><span class="marker dashicons dashicons-yes"></span></span>';
$html .= '<label class="cx-checkbox-label" for="' . esc_attr( $this->settings['id'] ) . '-' . $counter . '"><span class="cx-label-content">' . esc_html( $option_label ) . '</span></label> ';
$html .= '</span>';
$html .= '</div>';
$counter++;
}
}
$html .= '</div>';
return $html;
}
}
}

View File

@@ -0,0 +1,92 @@
<?php
/**
* Class for the building colorpicker elements.
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
if ( ! class_exists( 'CX_Control_Colorpicker' ) ) {
/**
* Class for the building CX_Control_Colorpicker elements.
*/
class CX_Control_Colorpicker extends CX_Controls_Base {
/**
* Default settings.
*
* @since 1.0.0
* @var array
*/
public $defaults_settings = array(
'id' => 'cx-colorpicker-id',
'name' => 'cx-colorpicker-name',
'value' => '',
'label' => '',
'class' => '',
);
/**
* Register control dependencies
*
* @return [type] [description]
*/
public function register_depends() {
wp_register_script(
'cx-colorpicker-alpha',
$this->base_url . 'assets/lib/colorpicker/wp-color-picker-alpha.min.js',
array( 'wp-color-picker' ),
'1.0.0',
true
);
}
/**
* Retrun scripts dependencies list for current control.
*
* @return array
*/
public function get_script_depends() {
return array( 'cx-colorpicker-alpha' );
}
/**
* Retrun styles dependencies list for current control.
*
* @return array
*/
public function get_style_depends() {
return array( 'wp-color-picker' );
}
/**
* Render html UI_Colorpicker.
*
* @since 1.0.0
*/
public function render() {
$html = '';
$class = implode( ' ',
array(
$this->settings['class'],
)
);
$html .= '<div class="cx-ui-container ' . esc_attr( $class ) . '">';
if ( '' !== $this->settings['label'] ) {
$html .= '<label class="cx-label" for="' . esc_attr( $this->settings['id'] ) . '">' . esc_html( $this->settings['label'] ) . '</label> ';
}
$html .= '<div class="cx-ui-colorpicker-wrapper">';
$html .= '<input type="text" id="' . esc_attr( $this->settings['id'] ) . '" class="cx-ui-colorpicker" name="' . esc_attr( $this->settings['name'] ) . '" value="' . esc_html( $this->settings['value'] ) . '"/>';
$html .= '</div>';
$html .= '</div>';
return $html;
}
}
}

View File

@@ -0,0 +1,200 @@
<?php
/**
* Class for the building dimensions elements.
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
if ( ! class_exists( 'CX_Control_Dimensions' ) ) {
/**
* Class for the building ui-dimensions elements.
*/
class CX_Control_Dimensions extends CX_Controls_Base {
/**
* Default settings.
*
* @since 1.0.0
* @var array
*/
public $defaults_settings = array(
'id' => 'cx-dimensions-id',
'name' => 'cx-dimensions-name',
'value' => array(),
'range' => array(
'px' => array(
'min' => 0,
'max' => 100,
'step' => 1,
),
),
'dimension_labels' => array(
'top' => 'Top',
'right' => 'Right',
'bottom' => 'Bottom',
'left' => 'Left',
),
'label' => '',
'class' => '',
'required' => false,
);
protected $default_value = array(
'units' => 'px',
'is_linked' => true,
'top' => '',
'right' => '',
'bottom' => '',
'left' => '',
);
/**
* Get required attribute.
*
* @since 1.0.0
* @return string
*/
public function get_required() {
if ( $this->settings['required'] ) {
return 'required="required"';
}
return '';
}
/**
* Render html UI_Dimension.
*
* @since 1.0.0
*/
public function render() {
$html = '';
$class = implode( ' ',
array(
$this->settings['class'],
)
);
if ( empty( $this->settings['value'] ) ) {
$this->settings['value'] = $this->default_value;
} else {
$this->settings['value'] = array_merge( $this->default_value, $this->settings['value'] );
}
$html .= '<div class="cx-ui-container ' . esc_attr( $class ) . '">';
if ( '' !== $this->settings['label'] ) {
$html .= '<label class="cx-label" for="' . esc_attr( $this->settings['id'] ) . '">' . esc_html( $this->settings['label'] ) . '</label> ';
}
$html .= $this->get_fields();
$html .= '</div>';
return $html;
}
/**
* Return UI fileds
* @return [type] [description]
*/
public function get_fields() {
$hidden = '<input type="hidden" name="%1$s" id="%3$s" value="%2$s">';
$number = '<div class="cx-ui-dimensions__value-item"><input type="number" name="%1$s" id="%3$s" value="%2$s" min="%4$s" max="%5$s" step="%6$s" class="cx-ui-dimensions__val%7$s"><span class="cx-ui-dimensions__value-label">%8$s</span></div>';
$value = $this->settings['value'];
$value = array_merge( $this->default_value, $value );
$result = sprintf(
'<div class="cx-ui-dimensions" data-range=\'%s\'>',
json_encode( $this->settings['range'] )
);
foreach ( array( 'units', 'is_linked' ) as $field ) {
$result .= sprintf(
$hidden,
$this->get_name_attr( $field ), $value[ $field ], $this->get_id_attr( $field )
);
}
$result .= $this->get_units();
$result .= '<div class="cx-ui-dimensions__values">';
$value['is_linked'] = filter_var( $value['is_linked'], FILTER_VALIDATE_BOOLEAN );
foreach ( array( 'top', 'right', 'bottom', 'left' ) as $field ) {
$result .= sprintf(
$number,
$this->get_name_attr( $field ),
$value[ $field ],
$this->get_id_attr( $field ),
$this->settings['range'][ $value['units'] ]['min'],
$this->settings['range'][ $value['units'] ]['max'],
$this->settings['range'][ $value['units'] ]['step'],
( true === $value['is_linked'] ? ' is-linked' : '' ),
$this->settings['dimension_labels'][ $field ]
);
}
$result .= sprintf(
'<div class="cx-ui-dimensions__is-linked%s"><span class="dashicons dashicons-admin-links link-icon"></span><span class="dashicons dashicons-editor-unlink unlink-icon"></span></div>',
( true === $value['is_linked'] ? ' is-linked' : '' )
);
$result .= '</div>';
$result .= '</div>';
return $result;
}
/**
* Returns units selector
*
* @return string
*/
public function get_units() {
$units = array_keys( $this->settings['range'] );
$switcher = 'can-switch';
if ( 1 === count( $units ) ) {
$switcher = '';
}
$item = '<span class="cx-ui-dimensions__unit%2$s" data-unit="%1$s">%1$s</span>';
$result = '';
foreach ( $units as $unit ) {
$result .= sprintf(
$item,
$unit,
( $this->settings['value']['units'] === $unit ? ' is-active' : '' )
);
}
return sprintf( '<div class="cx-ui-dimensions__units">%s</div>', $result );
}
/**
* Retrurn full name attibute by name
*
* @param [type] $name [description]
* @return [type] [description]
*/
public function get_name_attr( $name = '' ) {
return sprintf( '%s[%s]', esc_attr( $this->settings['name'] ), esc_attr( $name ) );
}
/**
* Retrurn full ID attibute by name
*
* @param [type] $name [description]
* @return [type] [description]
*/
public function get_id_attr( $name = '' ) {
return sprintf( '%s_%s', esc_attr( $this->settings['name'] ), esc_attr( $name ) );
}
}
}

View File

@@ -0,0 +1,352 @@
<?php
/**
* Class for the building iconpicker elements.
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
if ( ! class_exists( 'CX_Control_Iconpicker' ) ) {
/**
* Class for the building ui-iconpicker elements.
*/
class CX_Control_Iconpicker extends CX_Controls_Base {
/**
* Default settings.
*
* @since 1.0.0
* @var array
*/
public $defaults_settings = array(
'type' => 'iconpicker',
'id' => 'cx-iconpicker-id',
'name' => 'cx-iconpicker-name',
'value' => '',
'placeholder' => '',
'icon_data' => array(),
'auto_parse' => false,
'label' => '',
'class' => '',
'master' => '',
'width' => 'fixed',
'required' => false,
);
/**
* Default icon data settings.
*
* @var array
*/
private $default_icon_data = array(
'icon_set' => '',
'icon_css' => '',
'icon_base' => 'icon',
'icon_prefix' => '',
'icons' => '',
);
/**
* Icons sets
*
* @var array
*/
public static $sets = array();
/**
* Check if sets already printed
*
* @var boolean
*/
public static $printed = false;
/**
* Array of already printed sets to check it before printing current
*
* @var array
*/
public static $printed_sets = array();
/**
* Temporary icons holder
*
* @var null
*/
public $temp_icons = null;
/**
* Init
* @return [type] [description]
*/
public function init() {
add_action( 'admin_footer', array( $this, 'print_icon_set' ), 1 );
add_action( 'customize_controls_print_footer_scripts', array( $this, 'print_icon_set' ), 9999 );
add_filter( 'cx_handler_response_data', array( $this, 'send_icon_set' ), 10, 1 );
}
/**
* Register control dependencies
*
* @return [type] [description]
*/
public function register_depends() {
wp_register_script(
'cx-iconpicker',
$this->base_url . 'assets/lib/iconpicker/jquery-iconpicker.js',
array( 'jquery' ),
'1.0.0',
true
);
}
/**
* Retrun scripts dependencies list for current control.
*
* @return array
*/
public function get_script_depends() {
return array( 'cx-iconpicker' );
}
/**
* Get required attribute
*
* @return string required attribute
*/
public function get_required() {
if ( $this->settings['required'] ) {
return 'required="required"';
}
return '';
}
/**
* Render html UI_Iconpicker.
*
* @since 1.0.0
*/
public function render() {
$html = '';
$class = implode( ' ',
array(
$this->settings['class'],
$this->settings['width'],
)
);
$html .= '<div class="cx-ui-container ' . esc_attr( $class ) . '">';
if ( '' !== $this->settings['label'] ) {
$html .= '<label class="cx-label" for="' . esc_attr( $this->settings['id'] ) . '">' . esc_html( $this->settings['label'] ) . '</label> ';
}
$this->settings['icon_data'] = wp_parse_args(
$this->settings['icon_data'],
$this->default_icon_data
);
$html .= '<div class="cx-ui-iconpicker-group">';
if ( $this->validate_icon_data( $this->settings['icon_data'] ) ) {
$html .= $this->render_picker();
} else {
$html .= 'Incorrect Icon Data Settings';
}
$html .= '</div>';
$html .= '</div>';
/**
* Maybe add js repeater template to response
*
* @var bool
*/
$add_js_to_response = apply_filters( 'cx_control/add_data_to_element', false );
if ( $add_js_to_response ) {
ob_start();
$this->print_icon_set();
$icons = ob_get_clean();
$in_repeater = apply_filters( 'cx_control/is_repeater', false );
if ( $in_repeater ) {
$this->temp_icons = $icons;
add_filter( 'cx_control/add_repeater_data', array( $this, 'store_icons' ) );
} else {
$html .= $icons;
}
}
return $html;
}
public function store_icons( $data = array() ) {
if ( ! is_array( $data ) ) {
$data = array();
}
$data[] = $this->temp_icons;
return $data;
}
/**
* Returns iconpicker html markup
*
* @return string
*/
private function render_picker() {
$format = '<span class="input-group-addon"></span><input type="text" name="%1$s" id="%2$s" value="%3$s" class="widefat cx-ui-text cx-ui-iconpicker %4$s" data-set="%5$s">';
$this->prepare_icon_set();
return sprintf(
$format,
$this->settings['name'],
$this->settings['id'],
$this->settings['value'],
$this->settings['class'],
$this->settings['icon_data']['icon_set']
);
}
/**
* Return JS markup for icon set variable.
*
* @return void
*/
public function prepare_icon_set() {
if ( empty( $this->settings['icon_data']['icons'] ) ) {
$this->maybe_parse_set_from_css();
}
if ( ! array_key_exists( $this->settings['icon_data']['icon_set'], self::$sets ) ) {
self::$sets[ $this->settings['icon_data']['icon_set'] ] = array(
'iconCSS' => $this->settings['icon_data']['icon_css'],
'iconBase' => $this->settings['icon_data']['icon_base'],
'iconPrefix' => $this->settings['icon_data']['icon_prefix'],
'icons' => $this->settings['icon_data']['icons'],
);
}
}
/**
* Check if 'parse_set' is true and try to get icons set from CSS file
*
* @return void
*/
private function maybe_parse_set_from_css() {
if ( true !== $this->settings['auto_parse'] || empty( $this->settings['icon_data']['icon_css'] ) ) {
return;
}
ob_start();
$path = str_replace( WP_CONTENT_URL, WP_CONTENT_DIR, $this->settings['icon_data']['icon_css'] );
if ( file_exists( $path ) ) {
include $path;
}
$result = ob_get_clean();
preg_match_all( '/\.([-_a-zA-Z0-9]+):before[, {]/', $result, $matches );
if ( ! is_array( $matches ) || empty( $matches[1] ) ) {
return;
}
if ( is_array( $this->settings['icon_data']['icons'] ) ) {
$this->settings['icon_data']['icons'] = array_merge(
$this->settings['icon_data']['icons'],
$matches[1]
);
} else {
$this->settings['icon_data']['icons'] = $matches[1];
}
}
/**
* Checks if all required icon data fields are passed
*
* @param array $data Icon data.
* @return bool
*/
private function validate_icon_data( $data ) {
$validate = array_diff( $this->default_icon_data, array( 'icon_base', 'icon_prefix' ) );
foreach ( $validate as $key => $field ) {
if ( empty( $data[ $key ] ) ) {
return false;
}
return true;
}
}
/**
* Function sends the icons into ajax response.
*
* @param array $data Icon data.
* @return array
*/
public function send_icon_set( $data ) {
if ( empty( $data['CxIconSets'] ) ) {
$data['CxIconSets'] = array();
}
foreach ( self::$sets as $key => $value ) {
$data['CxIconSets'][ $key ] = $value;
}
return $data;
}
/**
* Print icon sets
*
* @return void
*/
public function print_icon_set() {
if ( empty( self::$sets ) || true === self::$printed ) {
return;
}
self::$printed = true;
foreach ( self::$sets as $set => $data ) {
if ( in_array( $set, self::$printed_sets ) ) {
continue;
}
self::$printed_sets[] = $set;
$json = json_encode( $data );
printf(
'<script> if ( ! window.CxIconSets ) { window.CxIconSets = {} } window.CxIconSets.%1$s = %2$s</script>',
$set,
$json
);
}
}
}
}

View File

@@ -0,0 +1,154 @@
<?php
/**
* Class for the building ui-media elements.
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
if ( ! class_exists( 'CX_Control_Media' ) ) {
/**
* Class for the building CX_Control_Media elements.
*/
class CX_Control_Media extends CX_Controls_Base {
/**
* Default settings.
*
* @since 1.0.0
* @var array
*/
public $defaults_settings = array(
'id' => 'cx-ui-media-id',
'name' => 'cx-ui-media-name',
'value' => '',
'multi_upload' => true,
'library_type' => '', // image, video, sound
'upload_button_text' => 'Choose Media',
'label' => '',
'class' => '',
);
/**
* Register control dependencies
*
* @return [type] [description]
*/
public function register_depends() {
wp_enqueue_media();
}
/**
* Retrun scripts dependencies list for current control.
*
* @return array
*/
public function get_script_depends() {
return array( 'jquery-ui-sortable' );
}
/**
* Render html CX_Control_Media.
*
* @since 1.0.0
*/
public function render() {
$html = '';
if ( ! current_user_can( 'upload_files' ) ) {
return $html;
}
$class = implode( ' ',
array(
$this->settings['class'],
)
);
$html .= '<div class="cx-ui-container ' . esc_attr( $class ) . '">';
if ( '' != $this->settings['value'] ) {
$this->settings['value'] = str_replace( ' ', '', $this->settings['value'] );
$medias = explode( ',', $this->settings['value'] );
} else {
$this->settings['value'] = '';
$medias = array();
}
$img_style = ! $this->settings['value'] ? 'style="display:none;"' : '' ;
if ( '' !== $this->settings['label'] ) {
$html .= '<label class="cx-label" for="' . esc_attr( $this->settings['id'] ) . '">' . esc_html( $this->settings['label'] ) . '</label> ';
}
$html .= '<div class="cx-ui-media-wrap">';
$html .= '<div class="cx-upload-preview" >';
$html .= '<div class="cx-all-images-wrap">';
if ( is_array( $medias ) && ! empty( $medias ) ) {
foreach ( $medias as $medias_key => $medias_value ) {
$media_title = get_the_title( $medias_value );
$mime_type = get_post_mime_type( $medias_value );
$tmp = wp_get_attachment_metadata( $medias_value );
$img_src = '';
$thumb = '';
switch ( $mime_type ) {
case 'image/jpeg':
case 'image/png':
case 'image/gif':
$img_src = wp_get_attachment_image_src( $medias_value, 'thumbnail' );
$img_src = $img_src[0];
$thumb = '<img src="' . esc_html( $img_src ) . '" alt="">';
break;
case 'image/x-icon':
$thumb = '<span class="dashicons dashicons-format-image"></span>';
break;
case 'video/mpeg':
case 'video/mp4':
case 'video/quicktime':
case 'video/webm':
case 'video/ogg':
$thumb = '<span class="dashicons dashicons-format-video"></span>';
break;
case 'audio/mpeg':
case 'audio/wav':
case 'audio/ogg':
$thumb = '<span class="dashicons dashicons-format-audio"></span>';
break;
}
$html .= '<div class="cx-image-wrap">';
$html .= '<div class="inner">';
$html .= '<div class="preview-holder" data-id-attr="' . esc_attr( $medias_value ) . '">';
$html .= '<div class="centered">';
$html .= $thumb;
$html .= '</div>';
$html .= '</div>';
$html .= '<span class="title">' . $media_title . '</span>';
$html .= '<a class="cx-remove-image" href="#" title=""><i class="dashicons dashicons-no"></i></a>';
$html .= '</div>';
$html .= '</div>';
}
}
$html .= '</div>';
$html .= '</div>';
$html .= '<div class="cx-element-wrap">';
$html .= '<input type="hidden" id="' . esc_attr( $this->settings['id'] ) . '" class="cx-upload-input" name="' . esc_attr( $this->settings['name'] ) . '" value="' . esc_html( $this->settings['value'] ) . '">';
$html .= '<button type="button" class="upload-button cx-upload-button button-default_" value="' . esc_attr( $this->settings['upload_button_text'] ) . '" data-title="' . esc_attr( $this->settings['upload_button_text'] ) . '" data-multi-upload="' . esc_attr( $this->settings['multi_upload'] ) . '" data-library-type="' . esc_attr( $this->settings['library_type'] ) . '">' . esc_attr( $this->settings['upload_button_text'] ) . '</button>';
$html .= '<div class="clear"></div>';
$html .= '</div>';
$html .= '</div>';
$html .= '</div>';
return $html;
}
}
}

View File

@@ -0,0 +1,121 @@
<?php
/**
* Class for the building ui-radio elements.
*
* @package Cherry_Framework
* @subpackage Class
* @author Cherry Team <support@cxframework.com>
* @copyright Copyright (c) 2012 - 2015, Cherry Team
* @link http://www.cxframework.com/
* @license http://www.gnu.org/licenses/gpl-3.0.en.html
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
if ( ! class_exists( 'CX_Control_Radio' ) ) {
/**
* Class for the building CX_Control_Radio elements.
*/
class CX_Control_Radio extends CX_Controls_Base {
/**
* Default settings.
*
* @since 1.0.0
* @var array
*/
public $defaults_settings = array(
'id' => 'cx-ui-radio-id',
'name' => 'cx-ui-radio-name',
'value' => 'radio-2',
'options' => array(
'radio-1' => array(
'label' => 'Radio 1',
'img_src' => '',
),
'radio-2' => array(
'label' => 'Radio 2',
'img_src' => '',
),
'radio-3' => array(
'label' => 'Radio 3',
'img_src' => '',
),
),
'label' => '',
'class' => '',
);
/**
* Render html UI_Radio.
*
* @since 1.0.0
*/
public function render() {
$html = '';
$class = implode( ' ',
array(
$this->settings['class'],
)
);
if ( isset( $this->settings['options_callback'] ) ) {
$this->settings['options'] = call_user_func( $this->settings['options_callback'] );
}
$html .= '<div class="cx-ui-container ' . esc_attr( $class ) . '" >';
if ( $this->settings['options'] && ! empty( $this->settings['options'] ) && is_array( $this->settings['options'] ) ) {
if ( '' !== $this->settings['label'] ) {
$html .= '<label class="cx-label" for="' . esc_attr( $this->settings['id'] ) . '">' . $this->settings['label'] . '</label> ';
}
$html .= '<div class="cx-radio-group">';
foreach ( $this->settings['options'] as $option => $option_value ) {
$checked = $option == $this->settings['value'] ? ' checked' : '';
$radio_id = $this->settings['id'] . '-' . $option;
$img = isset( $option_value['img_src'] ) && ! empty( $option_value['img_src'] ) ? '<img src="' . esc_url( $option_value['img_src'] ) . '" alt="' . esc_html( $option_value['label'] ) . '">' : '<span class="cx-radio-item"><i></i></span>';
$class_box = isset( $option_value['img_src'] ) && ! empty( $option_value['img_src'] ) ? 'cx-radio-img' : 'cx-radio-item' ;
$html .= '<div class="' . $class_box . '">';
$html .= '<input type="radio" id="' . esc_attr( $radio_id ) . '" class="cx-radio-input" name="' . esc_attr( $this->settings['name'] ) . '" ' . checked( $option, $this->settings['value'], false ) . ' value="' . esc_attr( $option ) . '"/>';
$label_content = $img . $option_value['label'];
$html .= '<label for="' . esc_attr( $radio_id ) . '"><span class="cx-lable-content">' . $label_content . '</span></label> ';
$html .= '</div>';
}
$html .= '<div class="clear"></div>';
$html .= '</div>';
}
$html .= '</div>';
return $html;
}
/**
* Enqueue javascript and stylesheet UI_Radio.
*
* @since 1.0.0
*/
public static function enqueue_assets() {
wp_enqueue_style(
'ui-radio',
esc_url( Cherry_Core::base_url( 'inc/ui-elements/ui-radio/assets/min/ui-radio.min.css', Cherry_UI_Elements::$module_path ) ),
array(),
Cherry_UI_Elements::$core_version,
'all'
);
wp_enqueue_script(
'ui-radio-min',
esc_url( Cherry_Core::base_url( 'inc/ui-elements/ui-radio/assets/min/ui-radio.min.js', Cherry_UI_Elements::$module_path ) ),
array( 'jquery' ),
Cherry_UI_Elements::$core_version,
true
);
}
}
}

View File

@@ -0,0 +1,372 @@
<?php
/**
* Class for the building ui-repeater elements.
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
if ( ! class_exists( 'CX_Control_Repeater' ) ) {
/**
* Class for the building ui-repeater elements.
*/
class CX_Control_Repeater extends CX_Controls_Base {
/**
* Default settings
*
* @var array
*/
public $defaults_settings = array(
'type' => 'repeater',
'id' => 'cx-ui-repeater-id',
'name' => 'cx-ui-repeater-name',
'value' => array(),
'fields' => array(),
'label' => '',
'add_label' => 'Add Item',
'class' => '',
'ui_kit' => true,
'required' => false,
'title_field' => '',
);
/**
* Stored data to process it while renderinr row
*
* @var array
*/
public $data = array();
/**
* Repeater instances counter
*
* @var integer
*/
public static $instance_id = 0;
/**
* Current onstance TMPL name
*
* @var string
*/
public $tmpl_name = '';
/**
* Holder for templates to print it in bottom of customizer page
*
* @var string
*/
public static $customizer_tmpl_to_print = null;
/**
* Is tmpl scripts already printed in customizer
*
* @var boolean
*/
public static $customizer_tmpl_printed = false;
/**
* Child repeater instances
*
* @var array
*/
private $_childs = array();
/**
* Check if we render template for JS
*
* @var boolean
*/
private $_is_js_row = false;
/**
* Init.
*
* @since 1.0.0
*/
public function init() {
$this->set_tmpl_data();
add_action( 'admin_footer', array( $this, 'print_js_template' ), 0 );
add_action( 'customize_controls_print_footer_scripts', array( $this, 'fix_customizer_tmpl' ), 9999 );
}
/**
* Retrun scripts dependencies list for current control.
*
* @return array
*/
public function get_script_depends() {
return array( 'jquery-ui-sortable', 'wp-util' );
}
/**
* Get required attribute.
*
* @return string required attribute
*/
public function get_required() {
if ( $this->settings['required'] ) {
return 'required="required"';
}
return '';
}
/**
* Render html UI_Repeater.
*
* @since 1.0.1
*/
public function render() {
$html = '';
$class = $this->settings['class'];
$ui_kit = ! empty( $this->settings['ui_kit'] ) ? 'cx-ui-kit' : '';
$value = ! empty( $this->settings['value'] ) ? count( $this->settings['value'] ) : 0 ;
$title_field = ! empty( $this->settings['title_field'] ) ? 'data-title-field="' . $this->settings['title_field'] . '"' : '' ;
add_filter( 'cx_control/is_repeater', '__return_true' );
$html .= sprintf( '<div class="cx-ui-repeater-container cx-ui-container %1$s %2$s">',
$ui_kit,
esc_attr( $class )
);
if ( '' !== $this->settings['label'] ) {
$html .= '<label class="cx-label" for="' . esc_attr( $this->settings['id'] ) . '">' . esc_html( $this->settings['label'] ) . '</label> ';
}
$html .= sprintf(
'<div class="cx-ui-repeater-list" data-name="%1$s" data-index="%2$s" data-widget-id="__i__" %3$s id="%4$s">',
$this->get_tmpl_name(),
$value,
$title_field,
esc_attr( $this->settings['id'] )
);
if ( is_array( $this->settings['value'] ) ) {
$index = 0;
foreach ( $this->settings['value'] as $data ) {
$this->_is_js_row = false;
$html .= $this->render_row( $index, false, $data );
$index++;
}
}
$html .= '</div>';
$html .= sprintf(
'<a href="#" class="cx-ui-repeater-add">%1$s</a>',
esc_html( $this->settings['add_label'] )
);
$html .= '</div>';
/**
* Maybe add js repeater template to response
*
* @var bool
*/
$add_js_to_response = apply_filters( 'cx_control/add_data_to_element', false );
if ( $add_js_to_response ) {
$html .= $this->get_js_template();
}
$html .= $this->get_additional_data();
remove_all_filters( 'cx_control/is_repeater' );
return $html;
}
/**
* Get additional data to return
* @return [type] [description]
*/
public function get_additional_data() {
$data = apply_filters( 'cx_control/add_repeater_data', array() );
if ( ! empty( $data ) ) {
return implode( ' ', $data );
}
}
/**
* Render single row for repeater
*
* @param string $index Current row index.
* @param number $widget_index It contains widget index.
* @param array $data Values to paste.
* @since 1.0.1
*/
public function render_row( $index, $widget_index, $data ) {
$this->data = $data;
$html = '<div class="cx-ui-repeater-item" >';
$html .= '<div class="cx-ui-repeater-actions-box">';
$html .= '<a href="#" class="cx-ui-repeater-remove"></a>';
$html .= '<span class="cx-ui-repeater-title">' . $this->get_row_title() . '</span>';
$html .= '<a href="#" class="cx-ui-repeater-toggle"></a>';
$html .= '</div>';
$html .= '<div class="cheryr-ui-repeater-content-box">';
foreach ( $this->settings['fields'] as $field ) {
$field_classes = array(
$field['id'] . '-wrap',
);
if ( ! empty( $field['class'] ) ) {
$field_classes[] = $field['class'];
}
$field_classes = implode( ' ', $field_classes );
$html .= '<div class="' . $field_classes . '">';
$html .= $this->render_field( $index, $widget_index, $field );
$html .= '</div>';
}
$html .= '</div>';
$html .= '</div>';
$this->data = array();
return $html;
}
/**
* Get repeater item title
*
* @return string
* @since 1.0.1
*/
public function get_row_title() {
if ( empty( $this->settings['title_field'] ) ) {
return '';
}
if ( ! empty( $this->data[ $this->settings['title_field'] ] ) ) {
return $this->data[ $this->settings['title_field'] ];
}
return '';
}
/**
* Render single repeater field
*
* @param string $index Current row index.
* @param number $widget_index It contains widget index.
* @param array $field Values to paste.
* @return string
*/
public function render_field( $index, $widget_index, $field ) {
if ( empty( $field['type'] ) || empty( $field['name'] ) ) {
return '"type" and "name" are required fields for UI_Repeater items';
}
$field = wp_parse_args( $field, array(
'value' => '',
) );
$parent_name = str_replace( '__i__', $widget_index, $this->settings['name'] );
$parent_name = str_replace( '{{{data.index}}}', '{{{data.parentIndex}}}', $parent_name );
$field['id'] = sprintf( '%s-%s', $field['id'], $index );
$field['value'] = isset( $this->data[ $field['name'] ] ) ? $this->data[ $field['name'] ] : $field['value'];
$field['name'] = sprintf( '%1$s[item-%2$s][%3$s]', $parent_name, $index, $field['name'] );
$ui_class_name = 'CX_Control_' . ucwords( $field['type'] );
if ( ! class_exists( $ui_class_name ) ) {
return '<p>Class <b>' . $ui_class_name . '</b> not exist!</p>';
}
$ui_item = new $ui_class_name( $field );
if ( 'repeater' === $ui_item->settings['type'] && true === $this->_is_js_row ) {
$this->_childs[] = $ui_item;
}
return $ui_item->render();
}
/**
* Get TMPL name for current repeater instance.
*
* @return string
*/
public function get_tmpl_name() {
return $this->tmpl_name;
}
/**
* Set current repeater instance ID
*
* @return void
*/
public function set_tmpl_data() {
self::$instance_id++;
$this->tmpl_name = sprintf( 'repeater-template-%s', self::$instance_id );
global $wp_customize;
if ( isset( $wp_customize ) ) {
self::$customizer_tmpl_to_print .= $this->get_js_template();
}
}
/**
* Print JS template for current repeater instance
*
* @return void
*/
public function print_js_template() {
echo $this->get_js_template();
if ( ! empty( $this->_childs ) ) {
foreach ( $this->_childs as $child ) {
echo $child->get_js_template();
}
}
}
/**
* Get JS template to print
*
* @return string
*/
public function get_js_template() {
$this->_is_js_row = true;
return sprintf(
'<script type="text/html" id="tmpl-%1$s">%2$s</script>',
$this->get_tmpl_name(),
$this->render_row( '{{{data.index}}}', '{{{data.widgetId}}}', array() )
);
}
/**
* Outputs JS templates on customizer page
*
* @return void
*/
public function fix_customizer_tmpl() {
if ( true === self::$customizer_tmpl_printed ) {
return;
}
self::$customizer_tmpl_printed = true;
echo self::$customizer_tmpl_to_print;
}
}
}

View File

@@ -0,0 +1,185 @@
<?php
/**
* Class for the building ui-select elements.
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
if ( ! class_exists( 'CX_Control_Select' ) ) {
/**
* Class for the building CX_Control_Select elements.
*/
class CX_Control_Select extends CX_Controls_Base {
/**
* Default settings.
*
* @since 1.0.0
* @var array
*/
public $defaults_settings = array(
'id' => 'cx-ui-select-id',
'name' => 'cx-ui-select-name',
'multiple' => false,
'filter' => false,
'size' => 1,
'inline_style' => 'width: 100%',
'value' => 'select-8',
'placeholder' => null,
'options' => array(
'select-1' => 'select 1',
'select-2' => 'select 2',
'select-3' => 'select 3',
'select-4' => 'select 4',
'select-5' => array(
'label' => 'Group 1',
),
'optgroup-1' => array(
'label' => 'Group 1',
'group_options' => array(
'select-6' => 'select 6',
'select-7' => 'select 7',
'select-8' => 'select 8',
),
),
'optgroup-2' => array(
'label' => 'Group 2',
'group_options' => array(
'select-9' => 'select 9',
'select-10' => 'select 10',
'select-11' => 'select 11',
),
),
),
'label' => '',
'class' => '',
);
/**
* Register control dependencies
*
* @return [type] [description]
*/
public function register_depends() {
wp_register_script(
'cx-select2',
$this->base_url . 'assets/lib/select2/select2.min.js',
array( 'jquery' ),
'4.0.5',
true
);
wp_register_style(
'cx-select2',
$this->base_url . 'assets/lib/select2/select2.min.css',
array(),
'4.0.5',
'all'
);
}
/**
* Retrun scripts dependencies list for current control.
*
* @return array
*/
public function get_script_depends() {
return array( 'cx-select2' );
}
/**
* Retrun styles dependencies list for current control.
*
* @return array
*/
public function get_style_depends() {
return array( 'cx-select2' );
}
/**
* Render html UI_Select.
*
* @since 1.0.0
*/
public function render() {
$html = '';
$class = implode( ' ',
array(
$this->settings['class'],
)
);
if ( isset( $this->settings['options_callback'] ) ) {
$this->settings['options'] = call_user_func( $this->settings['options_callback'] );
}
$html .= '<div class="cx-ui-container ' . esc_attr( $class ) . '">';
$html .= '<div class="cx-ui-select-wrapper">';
( $this->settings['filter'] ) ? $filter_state = 'data-filter="true"' : $filter_state = 'data-filter="false"' ;
( $this->settings['multiple'] ) ? $multi_state = 'multiple="multiple"' : $multi_state = '' ;
( $this->settings['multiple'] ) ? $name = $this->settings['name'] . '[]' : $name = $this->settings['name'] ;
if ( '' !== $this->settings['label'] ) {
$html .= '<label class="cx-label" for="' . esc_attr( $this->settings['id'] ) . '">' . $this->settings['label'] . '</label> ';
}
$inline_style = $this->settings['inline_style'] ? 'style="' . esc_attr( $this->settings['inline_style'] ) . '"' : '' ;
$html .= '<select id="' . esc_attr( $this->settings['id'] ) . '" class="cx-ui-select" name="' . esc_attr( $name ) . '" size="' . esc_attr( $this->settings['size'] ) . '" ' . $multi_state . ' ' . $filter_state . ' data-placeholder="' . esc_attr( $this->settings['placeholder'] ) . '" ' . $inline_style . '>';
if ( $this->settings['options'] && ! empty( $this->settings['options'] ) && is_array( $this->settings['options'] ) ) {
foreach ( $this->settings['options'] as $option => $option_value ) {
if ( ! is_array( $this->settings['value'] ) ) {
$this->settings['value'] = array( $this->settings['value'] );
}
if ( false === strpos( $option, 'optgroup' ) ) {
$selected_state = '';
if ( $this->settings['value'] && ! empty( $this->settings['value'] ) ) {
foreach ( $this->settings['value'] as $key => $value ) {
$selected_state = selected( $value, $option, false );
if ( " selected='selected'" == $selected_state ) {
break;
}
}
}
if ( is_array( $option_value ) ) {
$label = $option_value['label'];
} else {
$label = $option_value;
}
$html .= '<option value="' . esc_attr( $option ) . '" ' . $selected_state . '>' . esc_html( $label ) . '</option>';
} else {
$html .= '<optgroup label="' . esc_attr( $option_value['label'] ) . '">';
$selected_state = '';
foreach ( $option_value['group_options'] as $group_item => $group_value ) {
foreach ( $this->settings['value'] as $key => $value ) {
$selected_state = selected( $value, $group_item, false );
if ( " selected='selected'" == $selected_state ) {
break;
}
}
$html .= '<option value="' . esc_attr( $group_item ) . '" ' . $selected_state . '>' . esc_html( $group_value ) . '</option>';
}
$html .= '</optgroup>';
}
}
}
$html .= '</select>';
$html .= '</div>';
$html .= '</div>';
return $html;
}
}
}

View File

@@ -0,0 +1,104 @@
<?php
/**
* Class for the building ui slider elements .
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
if ( ! class_exists( 'CX_Control_Slider' ) ) {
/**
* Class for the building UI_Slider elements.
*/
class CX_Control_Slider extends CX_Controls_Base {
/**
* Default settings.
*
* @since 1.0.0
* @var array
*/
public $defaults_settings = array(
'id' => 'cx-ui-slider-id',
'name' => 'cx-ui-slider-name',
'max_value' => 100,
'min_value' => 0,
'value' => 50,
'step_value' => 1,
'label' => '',
'class' => '',
);
/**
* Render html UI_Slider.
*
* @since 1.0.0
*/
public function render() {
$html = '';
$class = implode( ' ',
array(
$this->settings['class'],
)
);
$html .= '<div class="cx-ui-container ' . esc_attr( $class ) . '">';
$ui_stepper = new CX_Control_Stepper(
array(
'id' => $this->settings['id'] . '-stepper',
'name' => $this->settings['name'],
'max_value' => $this->settings['max_value'],
'min_value' => $this->settings['min_value'],
'value' => $this->settings['value'],
'step_value' => $this->settings['step_value'],
)
);
$ui_stepper_html = $ui_stepper->render();
if ( '' !== $this->settings['label'] ) {
$html .= '<label class="cx-label" for="' . esc_attr( $this->settings['id'] ) . '">' . esc_html( $this->settings['label'] ) . '</label> ';
}
$html .= '<div class="cx-slider-wrap">';
$html .= '<div class="cx-slider-holder">';
$html .= '<input type="range" class="cx-slider-unit" step="' . esc_attr( $this->settings['step_value'] ) . '" min="' . esc_attr( $this->settings['min_value'] ) . '" max="' . esc_attr( $this->settings['max_value'] ) . '" value="' . esc_attr( $this->settings['value'] ) . '">';
$html .= '</div>';
$html .= '<div class="cx-slider-input">';
$html .= $ui_stepper_html;
$html .= '</div>';
$html .= '</div>';
$html .= '</div>';
return $html;
}
/**
* Enqueue javascript and stylesheet UI_Slider.
*
* @since 1.0.0
*/
public static function enqueue_assets() {
wp_enqueue_script(
'ui-slider',
esc_url( Cherry_Core::base_url( 'inc/ui-elements/ui-slider/assets/min/ui-slider.min.js', Cherry_UI_Elements::$module_path ) ),
array( 'jquery' ),
Cherry_UI_Elements::$core_version,
true
);
wp_enqueue_style(
'ui-slider',
esc_url( Cherry_Core::base_url( 'inc/ui-elements/ui-slider/assets/min/ui-slider.min.css', Cherry_UI_Elements::$module_path ) ),
array(),
Cherry_UI_Elements::$core_version,
'all'
);
}
}
}

View File

@@ -0,0 +1,71 @@
<?php
/**
* Class for the building ui stepper elements.
*
* @package Cherry_Framework
* @subpackage Class
* @author Cherry Team <support@cxframework.com>
* @copyright Copyright (c) 2012 - 2015, Cherry Team
* @link http://www.cxframework.com/
* @license http://www.gnu.org/licenses/gpl-3.0.en.html
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
if ( ! class_exists( 'CX_Control_Stepper' ) ) {
/**
* Class for the building CX_Control_Stepper elements.
*/
class CX_Control_Stepper extends CX_Controls_Base {
/**
* Default settings.
*
* @since 1.0.0
* @var array
*/
public $defaults_settings = array(
'id' => 'cx-ui-stepper-id',
'name' => 'cx-ui-stepper-name',
'value' => '0',
'max_value' => '100',
'min_value' => '0',
'step_value' => '1',
'label' => '',
'class' => '',
'placeholder' => '',
);
/**
* Render html UI_Stepper.
*
* @since 1.0.0
*/
public function render() {
$html = '';
$class = implode( ' ',
array(
$this->settings['class'],
)
);
$html .= '<div class="cx-ui-container ' . esc_attr( $class ) . '">';
if ( '' !== $this->settings['label'] ) {
$html .= '<label class="cx-label" for="' . esc_attr( $this->settings['id'] ) . '">' . esc_html( $this->settings['label'] ) . '</label> ';
}
$html .= '<div class="cx-ui-stepper">';
$html .= '<input type="number" id="' . esc_attr( $this->settings['id'] ) . '" class="cx-ui-stepper-input" pattern="[0-5]+([\.,][0-5]+)?" name="' . esc_attr( $this->settings['name'] ) . '" value="' . esc_html( $this->settings['value'] ) . '" min="' . esc_html( $this->settings['min_value'] ) . '" max="' . esc_html( $this->settings['max_value'] ) . '" step="' . esc_html( $this->settings['step_value'] ) . '" placeholder="' . esc_attr( $this->settings['placeholder'] ) . '">';
$html .= '</div>';
$html .= '</div>';
return $html;
}
}
}

View File

@@ -0,0 +1,71 @@
<?php
/**
* Class for the building ui swither elements .
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
if ( ! class_exists( 'CX_Control_Switcher' ) ) {
/**
* Class for the building CX_Control_Switcher elements.
*/
class CX_Control_Switcher extends CX_Controls_Base {
/**
* Default settings.
*
* @since 1.0.0
* @var array
*/
public $defaults_settings = array(
'id' => 'cx-ui-swither-id',
'name' => 'cx-ui-swither-name',
'value' => true,
'toggle' => array(
'true_toggle' => 'On',
'false_toggle' => 'Off',
),
'label' => '',
'class' => '',
);
/**
* Render html UI_Switcher.
*
* @since 1.0.0
*/
public function render() {
$html = '';
$class = implode( ' ',
array(
$this->settings['class'],
)
);
$html .= '<div class="cx-ui-container ' . esc_attr( $class ) . '">';
if ( '' !== $this->settings['label'] ) {
$html .= '<label class="cx-label" for="' . esc_attr( $this->settings['id'] ) . '">' . esc_html( $this->settings['label'] ) . '</label> ';
}
$value = filter_var( $this->settings['value'], FILTER_VALIDATE_BOOLEAN );
$html .= '<div class="cx-switcher-wrap">';
$html .= '<input type="radio" id="' . esc_attr( $this->settings['id'] ) . '-true" class="cx-input-switcher cx-input-switcher-true" name="' . esc_attr( $this->settings['name'] ) . '" ' . checked( true, $value, false ) . ' value="true">';
$html .= '<input type="radio" id="' . esc_attr( $this->settings['id'] ) . '-false" class="cx-input-switcher cx-input-switcher-false" name="' . esc_attr( $this->settings['name'] ) . '" ' . checked( false, $value, false ) . ' value="false">';
$html .= '<span class="bg-cover"></span>';
$html .= '<label class="sw-enable"><span>' . esc_html( $this->settings['toggle']['true_toggle'] ) . '</span></label>';
$html .= '<label class="sw-disable"><span>' . esc_html( $this->settings['toggle']['false_toggle'] ) . '</span></label>';
$html .= '<span class="state-marker"></span>';
$html .= '</div>';
$html .= '</div>';
return $html;
}
}
}

View File

@@ -0,0 +1,72 @@
<?php
/**
* Class for the building ui-text elements.
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
if ( ! class_exists( 'CX_Control_Text' ) ) {
/**
* Class for the building ui-text elements.
*/
class CX_Control_Text extends CX_Controls_Base {
/**
* Default settings.
*
* @since 1.0.0
* @var array
*/
public $defaults_settings = array(
'type' => 'text',
'id' => 'cx-ui-input-id',
'name' => 'cx-ui-input-name',
'value' => '',
'placeholder' => '',
'label' => '',
'class' => '',
'required' => false,
);
/**
* Get required attribute.
*
* @since 1.0.0
* @return string
*/
public function get_required() {
if ( $this->settings['required'] ) {
return 'required="required"';
}
return '';
}
/**
* Render html UI_Text.
*
* @since 1.0.0
*/
public function render() {
$html = '';
$class = implode( ' ',
array(
$this->settings['class'],
)
);
$html .= '<div class="cx-ui-container ' . esc_attr( $class ) . '">';
if ( '' !== $this->settings['label'] ) {
$html .= '<label class="cx-label" for="' . esc_attr( $this->settings['id'] ) . '">' . esc_html( $this->settings['label'] ) . '</label> ';
}
$html .= '<input type="' . esc_attr( $this->settings['type'] ) . '" id="' . esc_attr( $this->settings['id'] ) . '" class="widefat cx-ui-text" name="' . esc_attr( $this->settings['name'] ) . '" value="' . esc_html( $this->settings['value'] ) . '" placeholder="' . esc_attr( $this->settings['placeholder'] ) . '" ' . $this->get_required() . '>';
$html .= '</div>';
return $html;
}
}
}

View File

@@ -0,0 +1,59 @@
<?php
/**
* Class for the building ui-textarea elements
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
if ( ! class_exists( 'CX_Control_Textarea' ) ) {
/**
* Class for the building CX_Control_Textarea elements.
*/
class CX_Control_Textarea extends CX_Controls_Base {
/**
* Default settings.
*
* @since 1.0.0
* @var array
*/
public $defaults_settings = array(
'id' => 'cx-ui-textarea-id',
'name' => 'cx-ui-textarea-name',
'value' => '',
'placeholder' => '',
'rows' => '10',
'cols' => '20',
'label' => '',
'class' => '',
);
/**
* Render html UI_Textarea.
*
* @since 1.0.0
*/
public function render() {
$html = '';
$class = implode( ' ',
array(
$this->settings['class'],
)
);
$html .= '<div class="cx-ui-container ' . esc_attr( $class ) . '">';
if ( '' !== $this->settings['label'] ) {
$html .= '<label class="cx-label" for="' . esc_attr( $this->settings['id'] ) . '">' . $this->settings['label'] . '</label> ';
}
$html .= '<textarea id="' . esc_attr( $this->settings['id'] ) . '" class="cx-ui-textarea" name="' . esc_attr( $this->settings['name'] ) . '" rows="' . esc_attr( $this->settings['rows'] ) . '" cols="' . esc_attr( $this->settings['cols'] ) . '" placeholder="' . esc_attr( $this->settings['placeholder'] ) . '">' . esc_html( $this->settings['value'] ) . '</textarea>';
$html .= '</div>';
return $html;
}
}
}