diff --git a/inc/class-alpha-color-control.php b/inc/class-alpha-color-control.php new file mode 100644 index 0000000..0589091 --- /dev/null +++ b/inc/class-alpha-color-control.php @@ -0,0 +1,105 @@ +. + */ +class Alpha_Color_Control extends WP_Customize_Control { + + /** + * Official control name. + * + * @var string + */ + public $type = 'alpha-color'; + + /** + * Add support for palettes to be passed in. + * + * Supported palette values are true, false, or an array of RGBa and Hex colors. + * + * @var bool|array + */ + public $palette; + + /** + * Add support for showing the opacity value on the slider handle. + * + * @var int + */ + public $show_opacity; + + /** + * Enqueue scripts and styles. + * + * Ideally these would get registered and given proper paths before this control object + * gets initialized, then we could simply enqueue them here, but for completeness as a + * stand alone class we'll register and enqueue them here. + */ + public function enqueue() { + + } + + /** + * Render the control. + */ + public function render_content() { + + // Process the palette. + if ( is_array( $this->palette ) ) { + $palette = implode( '|', $this->palette ); + } else { + // Default to true. + $palette = ( false === $this->palette || 'false' === $this->palette ) ? 'false' : 'true'; + } + + // Support passing show_opacity as string or boolean. Default to true. + $show_opacity = ( false === $this->show_opacity || 'false' === $this->show_opacity ) ? 'false' : 'true'; + + // Begin the output. + ?> + + $op ) { + $args['fields'][ $key ]['id'] = $key; + if ( ! isset( $op['value'] ) ) { + if ( isset( $op['default'] ) ) { + $args['fields'][ $key ]['value'] = $op['default']; + } else { + $args['fields'][ $key ]['value'] = ''; + } + } + } + + $this->fields = $args['fields']; + $this->live_title_id = isset( $args['live_title_id'] ) ? $args['live_title_id'] : false; + $this->defined_values = isset( $args['defined_values'] ) ? $args['defined_values'] : false; + $this->id_key = isset( $args['id_key'] ) ? $args['id_key'] : false; + if ( isset( $args['title_format'] ) && '' !== $args['title_format'] ) { + $this->title_format = $args['title_format']; + } else { + $this->title_format = ''; + } + + if ( isset( $args['limited_msg'] ) && '' !== $args['limited_msg'] ) { + $this->limited_msg = $args['limited_msg']; + } else { + $this->limited_msg = ''; + } + + if ( ! isset( $args['max_item'] ) ) { + $args['max_item'] = 0; + } + + if ( ! isset( $args['allow_unlimited'] ) || false !== $args['allow_unlimited'] ) { + $this->max_item = apply_filters( 'coletivo_reepeatable_max_item', absint( $args['max_item'] ) ); + } else { + $this->max_item = absint( $args['max_item'] ); + } + + $this->changeable = isset( $args['changeable'] ) && 'no' === $args['changeable'] ? 'no' : 'yes'; + $this->default_empty_title = isset( $args['default_empty_title'] ) && '' !== $args['default_empty_title'] ? $args['default_empty_title'] : esc_html__( 'Item', 'coletivo' ); + } + + /** + * Merge data + * + * @access public + * @param array $array_value Array value. + * @param array $array_default Array value. + * + * @return array + */ + public function merge_data( $array_value, $array_default ) { + + if ( ! $this->id_key ) { + return $array_value; + } + + if ( ! is_array( $array_value ) ) { + $array_value = array(); + } + + if ( ! is_array( $array_default ) ) { + $array_default = array(); + } + + $new_array = array(); + foreach ( $array_value as $k => $a ) { + + if ( is_array( $a ) ) { + if ( isset( $a[ $this->id_key ] ) && '' !== $a[ $this->id_key ] ) { + $new_array[ $a[ $this->id_key ] ] = $a; + } else { + $new_array[ $k ] = $a; + } + } + } + + foreach ( $array_default as $k => $a ) { + if ( is_array( $a ) && isset( $a[ $this->id_key ] ) ) { + if ( ! isset( $new_array[ $a[ $this->id_key ] ] ) ) { + $new_array[ $a[ $this->id_key ] ] = $a; + } + } + } + + return array_values( $new_array ); + } + + /** + * To JSON + * + * @access public + * + * @return void + */ + public function to_json() { + parent::to_json(); + $value = $this->value(); + + if ( is_string( $value ) ) { + $value = json_decode( $value, true ); + } + if ( empty( $value ) ) { + $value = $this->defined_values; + } elseif ( is_array( $this->defined_values ) && ! empty( $this->defined_values ) ) { + $value = $this->merge_data( $value, $this->defined_values ); + } + + $this->json['live_title_id'] = $this->live_title_id; + $this->json['title_format'] = $this->title_format; + $this->json['max_item'] = $this->max_item; + $this->json['limited_msg'] = $this->limited_msg; + $this->json['changeable'] = $this->changeable; + $this->json['default_empty_title'] = $this->default_empty_title; + $this->json['value'] = $value; + $this->json['id_key'] = $this->id_key; + $this->json['fields'] = $this->fields; + } + + /** + * Enqueue scripts/styles. + * + * @since 1.0.0 + * @access public + * + * @return void + */ + public function enqueue() { + add_action( 'customize_controls_print_footer_scripts', array( $this, 'item_tpl' ), 66 ); + } + + /** + * Item TPL + * + * @access public + * + * @return void + */ + public function item_tpl() { + ?> + + + + input_attrs(); ?> value="" link(); ?> /> +
+ +
+
+ +
+ +
  • +
    +
    +
    + +
    +
    +

    +
    +
    + +
    +
    +
    + <# var cond_v; #> + <# for ( i in data ) { #> + <# if ( ! data.hasOwnProperty( i ) ) continue; #> + <# field = data[i]; #> + <# if ( ! field.type ) continue; #> + <# if ( field.type ){ #> + + <# + if ( field.required && field.required.length >= 3 ) { + #> +
    + <# + } else { + #> +
    + <# + } + #> + <# if ( 'checkbox' !== field.type ) { #> + <# if ( field.title ) { #> + + <# } #> + + <# if ( field.desc ) { #> +

    {{{ field.desc }}}

    + <# } #> + <# } #> + + <# if ( 'hidden' === field.type ) { #> + + <# } else if ( 'add_by' === field.type ) { #> + + <# } else if ( 'text' === field.type ) { #> + + <# } else if ( 'checkbox' === field.type ) { #> + + <# if ( field.title ) { #> + + <# } #> + + <# if ( field.desc ) { #> +

    {{ field.desc }}

    + <# } #> + + + <# } else if ( 'select' === field.type ) { #> + + <# if ( field.multiple ) { #> + + <# } #> + + <# for ( k in field.options ) { #> + <# if ( _.isArray( field.value ) ) { #> + + <# } else { #> + + <# } #> + <# } #> + + + <# } else if ( 'radio' === field.type ) { #> + + <# for ( k in field.options ) { #> + + <# if ( field.options.hasOwnProperty( k ) ) { #> + + + + <# } #> + <# } #> + + <# } else if ( 'color' === field.type || 'coloralpha' === field.type ) { #> + + <# if ( '' !== field.value ) { field.value = '#'+field.value ; } #> + + + + <# } else if ( 'media' === field.type ) { #> + + <# if ( ! field.media || '' === field.media || 'image' === field.media ) { #> + + <# } else { #> + + <# } #> + + + <# if ( ! field.media || '' === field.media || 'image' === field.media ) { #> +
    +
    +
    +
    + <# if ( '' !== field.value.url ){ #> + + <# } #> +
    +
    +
    +
    + <# } #> + +
    + + +
    +
    + + <# } else if ( 'textarea' === field.type || 'editor' === field.type ) { #> + + <# } else if ( 'icon' === field.type ) { #> + <# + var icon_class = field.value; + if ( 0 !== icon_class.indexOf( 'fa-' ) ) { + icon_class = 'fa-' + field.value; + } else { + icon_class = icon_class.replace( 'fa ', '' ); + } + icon_class = icon_class.replace( 'fa-fa', '' ); + + #> +
    + + +
    + + <# } #> + +
    + + <# } #> + <# } #> +
    +
    + + + | + + +
    +
    +
    +
    +
    + +
    + +
    +
  • + mod = strtolower( (string) $this->mod ); + if ( ! 'html' === $this->mod ) { + $this->mod = 'tmce'; + } + ?> +
    + + +

    description ); ?>

    +
    + + + type ) { + case 'heading': + echo '' . esc_html( $this->title ) . ''; + break; + + case 'custom_message': + echo '

    ' . esc_html( $this->description ) . '

    '; + break; + + case 'hr': + echo '
    '; + break; + } + } +} diff --git a/inc/class-textarea-custom-control.php b/inc/class-textarea-custom-control.php new file mode 100644 index 0000000..2464046 --- /dev/null +++ b/inc/class-textarea-custom-control.php @@ -0,0 +1,35 @@ + + + type ) { - case 'heading': - echo '' . esc_html( $this->title ) . ''; - break; +namespace Coletivo; - case 'custom_message': - echo '

    ' . esc_html( $this->description ) . '

    '; - break; +/* Autoload */ +if ( version_compare( PHP_VERSION, '5.6.0', '>=' ) ) { + require get_template_directory() . '/vendor/autoload.php'; +} - case 'hr': - echo '
    '; - break; - } - } +if ( ! class_exists( 'Misc_Control' ) ) { + require_once get_template_directory() . '/inc/class-misc-control.php'; } -/** - * Text Area Custom Control Class - */ -class Coletivo_Textarea_Custom_Control extends WP_Customize_Control { - /** - * Render the description and title for the sections - */ - public function render_content() { - ?> - - mod = strtolower( $this->mod ); - if ( ! 'html' === $this->mod ) { - $this->mod = 'tmce'; - } - ?> -
    - - -

    description ); ?>

    -
    - . - */ -class Coletivo_Alpha_Color_Control extends WP_Customize_Control { - - /** - * Official control name. - * - * @var string - */ - public $type = 'alpha-color'; - - /** - * Add support for palettes to be passed in. - * - * Supported palette values are true, false, or an array of RGBa and Hex colors. - * - * @var bool|array - */ - public $palette; - - /** - * Add support for showing the opacity value on the slider handle. - * - * @var int - */ - public $show_opacity; - - /** - * Enqueue scripts and styles. - * - * Ideally these would get registered and given proper paths before this control object - * gets initialized, then we could simply enqueue them here, but for completeness as a - * stand alone class we'll register and enqueue them here. - */ - public function enqueue() { - - } - - /** - * Render the control. - */ - public function render_content() { - - // Process the palette. - if ( is_array( $this->palette ) ) { - $palette = implode( '|', $this->palette ); - } else { - // Default to true. - $palette = ( false === $this->palette || 'false' === $this->palette ) ? 'false' : 'true'; - } - - // Support passing show_opacity as string or boolean. Default to true. - $show_opacity = ( false === $this->show_opacity || 'false' === $this->show_opacity ) ? 'false' : 'true'; - - // Begin the output. - ?> - - $op ) { - $args['fields'][ $key ]['id'] = $key; - if ( ! isset( $op['value'] ) ) { - if ( isset( $op['default'] ) ) { - $args['fields'][ $key ]['value'] = $op['default']; - } else { - $args['fields'][ $key ]['value'] = ''; - } - } - } - - $this->fields = $args['fields']; - $this->live_title_id = isset( $args['live_title_id'] ) ? $args['live_title_id'] : false; - $this->defined_values = isset( $args['defined_values'] ) ? $args['defined_values'] : false; - $this->id_key = isset( $args['id_key'] ) ? $args['id_key'] : false; - if ( isset( $args['title_format'] ) && '' !== $args['title_format'] ) { - $this->title_format = $args['title_format']; - } else { - $this->title_format = ''; - } - - if ( isset( $args['limited_msg'] ) && '' !== $args['limited_msg'] ) { - $this->limited_msg = $args['limited_msg']; - } else { - $this->limited_msg = ''; - } - - if ( ! isset( $args['max_item'] ) ) { - $args['max_item'] = 0; - } - - if ( ! isset( $args['allow_unlimited'] ) || false !== $args['allow_unlimited'] ) { - $this->max_item = apply_filters( 'coletivo_reepeatable_max_item', absint( $args['max_item'] ) ); - } else { - $this->max_item = absint( $args['max_item'] ); - } - - $this->changeable = isset( $args['changeable'] ) && 'no' === $args['changeable'] ? 'no' : 'yes'; - $this->default_empty_title = isset( $args['default_empty_title'] ) && '' !== $args['default_empty_title'] ? $args['default_empty_title'] : esc_html__( 'Item', 'coletivo' ); - } - - /** - * Merge data - * - * @access public - * @param array $array_value Array value. - * @param array $array_default Array value. - * - * @return array - */ - public function merge_data( $array_value, $array_default ) { - - if ( ! $this->id_key ) { - return $array_value; - } - - if ( ! is_array( $array_value ) ) { - $array_value = array(); - } - - if ( ! is_array( $array_default ) ) { - $array_default = array(); - } - - $new_array = array(); - foreach ( $array_value as $k => $a ) { - - if ( is_array( $a ) ) { - if ( isset( $a[ $this->id_key ] ) && '' !== $a[ $this->id_key ] ) { - $new_array[ $a[ $this->id_key ] ] = $a; - } else { - $new_array[ $k ] = $a; - } - } - } - - foreach ( $array_default as $k => $a ) { - if ( is_array( $a ) && isset( $a[ $this->id_key ] ) ) { - if ( ! isset( $new_array[ $a[ $this->id_key ] ] ) ) { - $new_array[ $a[ $this->id_key ] ] = $a; - } - } - } - - return array_values( $new_array ); - } - - /** - * To JSON - * - * @access public - * - * @return void - */ - public function to_json() { - parent::to_json(); - $value = $this->value(); - - if ( is_string( $value ) ) { - $value = json_decode( $value, true ); - } - if ( empty( $value ) ) { - $value = $this->defined_values; - } elseif ( is_array( $this->defined_values ) && ! empty( $this->defined_values ) ) { - $value = $this->merge_data( $value, $this->defined_values ); - } - - $this->json['live_title_id'] = $this->live_title_id; - $this->json['title_format'] = $this->title_format; - $this->json['max_item'] = $this->max_item; - $this->json['limited_msg'] = $this->limited_msg; - $this->json['changeable'] = $this->changeable; - $this->json['default_empty_title'] = $this->default_empty_title; - $this->json['value'] = $value; - $this->json['id_key'] = $this->id_key; - $this->json['fields'] = $this->fields; - } - - /** - * Enqueue scripts/styles. - * - * @since 1.0.0 - * @access public - * - * @return void - */ - public function enqueue() { - add_action( 'customize_controls_print_footer_scripts', array( $this, 'item_tpl' ), 66 ); - } - - /** - * Item TPL - * - * @access public - * - * @return void - */ - public function item_tpl() { - ?> - - - - input_attrs(); ?> value="" link(); ?> /> -
    - -
    -
    - -
    - -
  • -
    -
    -
    - -
    -
    -

    -
    -
    - -
    -
    -
    - <# var cond_v; #> - <# for ( i in data ) { #> - <# if ( ! data.hasOwnProperty( i ) ) continue; #> - <# field = data[i]; #> - <# if ( ! field.type ) continue; #> - <# if ( field.type ){ #> - - <# - if ( field.required && field.required.length >= 3 ) { - #> -
    - <# - } else { - #> -
    - <# - } - #> - <# if ( 'checkbox' !== field.type ) { #> - <# if ( field.title ) { #> - - <# } #> - - <# if ( field.desc ) { #> -

    {{{ field.desc }}}

    - <# } #> - <# } #> - - <# if ( 'hidden' === field.type ) { #> - - <# } else if ( 'add_by' === field.type ) { #> - - <# } else if ( 'text' === field.type ) { #> - - <# } else if ( 'checkbox' === field.type ) { #> - - <# if ( field.title ) { #> - - <# } #> - - <# if ( field.desc ) { #> -

    {{ field.desc }}

    - <# } #> - - - <# } else if ( 'select' === field.type ) { #> - - <# if ( field.multiple ) { #> - - <# } #> - - <# for ( k in field.options ) { #> - <# if ( _.isArray( field.value ) ) { #> - - <# } else { #> - - <# } #> - <# } #> - - - <# } else if ( 'radio' === field.type ) { #> - - <# for ( k in field.options ) { #> - - <# if ( field.options.hasOwnProperty( k ) ) { #> - - - - <# } #> - <# } #> - - <# } else if ( 'color' === field.type || 'coloralpha' === field.type ) { #> - - <# if ( '' !== field.value ) { field.value = '#'+field.value ; } #> - - - - <# } else if ( 'media' === field.type ) { #> - - <# if ( ! field.media || '' === field.media || 'image' === field.media ) { #> - - <# } else { #> - - <# } #> - - - <# if ( ! field.media || '' === field.media || 'image' === field.media ) { #> -
    -
    -
    -
    - <# if ( '' !== field.value.url ){ #> - - <# } #> -
    -
    -
    -
    - <# } #> - -
    - - -
    -
    - - <# } else if ( 'textarea' === field.type || 'editor' === field.type ) { #> - - <# } else if ( 'icon' === field.type ) { #> - <# - var icon_class = field.value; - if ( 0 !== icon_class.indexOf( 'fa-' ) ) { - icon_class = 'fa-' + field.value; - } else { - icon_class = icon_class.replace( 'fa ', '' ); - } - icon_class = icon_class.replace( 'fa-fa', '' ); - - #> -
    - - -
    - - <# } #> - -
    - - <# } #> - <# } #> -
    -
    - - - | - - -
    -
    -
    -
    -
    - -
    - -
    -
  • - - - __( 'Section: ', 'coletivo' ) ) ); } -add_action( 'customize_controls_enqueue_scripts', 'coletivo_customizer_control_scripts', 99 ); -add_action( 'customize_controls_enqueue_scripts', array( 'coletivo_Editor_Scripts', 'enqueue' ), 95 ); +/** + * Init function + */ +function init() { + add_action( 'customize_controls_enqueue_scripts', 'coletivo_customizer_control_scripts', 99 ); +}