$v )
$this->$k = $v;
//if ( $mega_package === '0' )//if enabled also enable from mega_admin
parent::__construct( $manager, $id, $args );
}
}
else :
class Mega_Control_Bridge_Base
{
public function __construct( $manager, $id, $args = array() )
{
//$keys = array_keys( get_object_vars( $this ));
$this->id = $id;
foreach ( $args as $key => $d )
{
//if ( isset( $args[$key] ))
//{
$this->$key = $d;
//}
}
}
public function link() {}
}
endif;
class Mega_Control_Bridge extends Mega_Control_Bridge_Base
{
public function __construct( $form, $args = array() )
{
$this->form = $form;
$block = $form->callback[0];
$default = array(
'show_label' => 1,
'label' => '',
'name' => '',
'value' => '',
'placeholder' => '',
'desc' => '',
'class' => $this->type,
'required' => 0,
'use_list' => 0,
'list' => '',
'pro' => 0,
'i' => 0,
'sanitize' => apply_filters( 'mega_sanitize_' . $this->type, array( $this, 'sanitize' )),
'validate' => array( $this, 'validate' ),
'priority' => 2,
'control_value' => '',
'transport' => isset( $block->mega['args']['universal'] ) && $block->mega['args']['universal'] ? 'postMessage' : 'refresh'
);
$args = wp_parse_args( $args, $default );
if ( !empty( $args['name'] ) && isset( $block->filter[$args['name']] ))
$args['value'] = $block->filter[$args['name']];
$args['class'] .= ' ' . $block->mega['args']['id_base_low'] . '_' . $args['name'];
$this->pro_id = $block->mega['args']['id_base_low'] . '_' . $args['name'];
$form->add_setting( MEGA_DB_ID . '[' . $block->mega['args']['id_base_low'] . '][' . $args['name'] . ']', array(
'sanitize_callback' => $args['sanitize'],
'default' => $args['value'],
'type' => 'option',
'transport' => $args['transport']
));
if ( $args['use_list'] && !empty( $args['list'] ))
$args['choices'] = apply_filters( $args['list'], array() );
$this->set_id = MEGA_DB_ID . '[' . $block->mega['args']['id_base_low'] . '][' . $args['name'] . ']';
if ( isset( $form->callback[1] ))
call_user_func_array( $form->callback, array( &$args ));
$this->block_id = $block->mega['args']['id_base_low'];
if ( isset( $args['control'] ))
$this->control = $block->mega['args']['id_base_low'] . '_' . $args['control'];
$args = wp_parse_args( $args, array(
'section' => $block->mega['args']['id_base_low'] . '_section',
'settings' => MEGA_DB_ID . '[' . $block->mega['args']['id_base_low'] . '][' . $args['name'] . ']',
//$block->mega['args']['id_base_low'] . '_' . $args['name'],
));
parent::__construct( $form, $block->mega['args']['id_base_low'] . '_' . $args['name'], $args );
}
public function lock( $status )
{
global $mega_package;
echo $mega_package === '0' && $status ? ' data-lock="true" ' : '';
}
public function showLock( $status, $type = '' )
{
global $mega_package;
echo $mega_package === '0' && $status ? '' : '';//lock
}
public function upgradeURL( $medium = '', $type = '' )
{
$screen = get_current_screen();
if ( isset( $screen->id ))
$sc_id = $screen->id;
else
$sc_id = 'widgets';
if ( $type === 'widget' && $sc_id === 'customize' )
$sc_id = $sc_id . '_widgets';
$url = 'http://www.megathemes.com/themes/' . wp_get_theme()->get( 'TextDomain' ) . '/upgrade/';
return $url . '?utm_source=' . wp_get_theme()->get( 'Name' ) . '&utm_medium=' . $sc_id . '_' . $medium . '&utm_content=' . $this->pro_id . '&utm_campaign=upgrade';
}
public function link( $setting_key = 'default' )
{
if ( !empty( $this->class ))
echo ' class="' . esc_attr( $this->class ) . '" ';
if ( !empty( $this->placeholder ))
echo ' placeholder="' . esc_attr( $this->placeholder ) . '" ';
$this->lock( $this->pro );
parent::link();
}
public function widget()
{
echo '
';
}
public function callback()
{
echo '';
}
public function render_content()
{
echo 'control ) ? 'data-p-control="' . esc_attr( $this->block_id . '_' . $this->control ) . '" data-p-control-v="' . esc_attr( $this->control_value ) . '"' : '' ) . '>';
$this->showLock( $this->pro );
if ( !empty( $this->label ))
echo '' . esc_html( $this->label ) . '';
if ( !empty( $this->desc ))
echo '' . $this->desc . '';
$this->control( '_customize-' . $this->type . '-' . $this->id, $this->value() );
echo '
';
}
public function sanitize( $value )
{
return $value;
}
public function validate( $value, $mega_error )//validateCallback
{
if ( $this->required && empty( $value ))
{
$mega_error->add_error( $this->id, sprintf( esc_html__( '%s cannot be empty! Please enter a valid value.', 'mega' ), !empty( $this->label ) ? $this->label : $this->name ));//filter?
return false;
}
return $this->validateSingle( $value, $mega_error ) ? true : false;
}
public function validateSingle( $value, $mega_error )
{
return true;
}
public function choicesIterator( $choices, $name, $selected, $depth = 0, $echo = true )//no echo at all?
{
if ( $echo )
$this->choicesIteratorBefore( $depth, $name );
foreach ( $choices as $key => $option )
{
$id = is_array( $option ) ? $option['id'] : $key;
$label = is_array( $option ) ? $option['label'] : $option;
if ( $echo )
$this->choicesIteratorSingle( $id, $label, $name, $selected, $depth );
else if ( $r = $this->choicesIteratorCompare( $id, $selected ))
return $r;
if ( isset( $option['children'] ) && is_array( $option['children'] ) && count( $option['children'] ) > 0 )
{
if ( $echo )
$this->choicesIterator( $option['children'], $name, $selected, $depth + 1, $echo );
else if ( $r = $this->choicesIterator( $option['children'], $name, $selected, $depth + 1, $echo ))
return $r;
}
}
if ( $echo )
$this->choicesIteratorAfter( $depth );
else
return '';
}
}
class Mega_Control_Checklist extends Mega_Control_Bridge
{
public $type = 'checklist';
public function render_content()
{
if ( empty( $this->choices ))
return;
parent::render_content();
}
public function enqueue()
{
//wp_enqueue_script( 'mega.jquery.control.checklist' );
}
public function control( $name, $value )
{
$this->choicesIterator( $this->choices, $name, $value );
if ( class_exists( 'WP_Customize_Control' ))
{
echo 'link(); echo ' name="' . esc_attr( $name ) . '" value="' . esc_attr( json_encode( $value )) . '" />';
}
}
public function choicesIteratorBefore()
{
echo '';
}
public function choicesIteratorAfter()
{
echo '
';
}
public function choicesIteratorSingle( $key, $label, $name, $selected, $depth )
{
echo '';
echo '';
echo '';
}
public function sanitize( $value )
{
if ( !is_array( $value ))
$value = json_decode( html_entity_decode( $value ), true );
$this->clean = array();
$this->choicesIterator( $this->choices, '', $value, 0, 0 );
return $this->clean;
}
public function choicesIteratorCompare( $id, $selected )
{
$this->clean[$id] = isset( $selected[$id] ) && ( $selected[$id] === 1 OR $selected[$id] === '1' ) ? 1 : 0;
//return $clean;
}
}
class Mega_Control_Checkbox extends Mega_Control_Bridge
{
public $type = 'checkbox';
public function control( $name, $value )
{
global $mega_package;
echo '';
echo 'link(); echo ' />';
}
public function sanitize( $value )
{
return isset( $value ) && $value == 1 ? 1 : 0;
}
}
class Mega_Control_onOff extends Mega_Control_Checkbox
{
public $type = 'mega_form_onoff';
}
class Mega_Control_Text extends Mega_Control_Bridge
{
public $type = 'mega_block_form_text';
public function control( $name, $value )
{
echo 'link(); echo ' />';
}
public function sanitize( $value )
{
return wp_kses_data( $value );
}
}
class Mega_Control_Email extends Mega_Control_Bridge
{
public $type = 'mega_control_email';
public function control( $name, $value )
{
echo 'link(); echo ' />' . ( $this->i ? '' : '' );
}
public function sanitize( $value )
{
return sanitize_email( $value );
}
public function validateSingle( $value, $mega_error )
{
if ( is_email( $value ))
return true;
$mega_error->add_error( $this->id, esc_html__( 'Email address is invalid.', 'mega' ));
return false;
}
}
class Mega_Control_Number extends Mega_Control_Bridge
{
public $type = 'mega_block_form_number';
public function control( $name, $value )
{
echo 'link(); echo ' />';
}
public function sanitize( $value )
{
return intval( $value );
}
public function validateSingle( $value, $mega_error )
{
if ( is_numeric( intval( $value )))
return true;
$mega_error->add_error( $this->id, esc_html__( 'Expecting a Numeric value!', 'mega' ));
return false;
}
}
class Mega_Control_Textarea extends Mega_Control_Bridge
{
public $type = 'textarea';
public function control( $name, $value )
{
echo '';
}
public function sanitize( $value )
{
return wp_kses_post( $value );//wp_kses_data
}
}
class Mega_Control_WP_Editor extends Mega_Control_Bridge
{
public $type = 'wp_editor';
public function __construct( $form, $args = array() )
{
if ( class_exists( 'WP_Customize_Control' ))
$this->type = 'textarea';
parent::__construct( $form, $args );
}
public function control( $name, $value )
{
if ( class_exists( 'WP_Customize_Control' ))
{
echo '';
//Mega_Control_Textarea::control( $name, $value );
}
else
wp_editor( $value, $this->id, array( 'textarea_name' => $name, 'editor_class' => '', 'tinymce' => 0, 'media_buttons' => false ));
}
public function sanitize( $value )
{
return wp_kses_post( $value );
}
}
class Mega_Control_Select extends Mega_Control_Bridge
{
public $type = 'select';
public function control( $name, $value )
{
$this->choicesIterator( $this->choices, $name, $value );
}
public function choicesIteratorBefore( $depth, $name )//'