$options['name'],
'class_name' => $options['class_name'],
'output_types' => !empty($options['output_types']) ? $options['output_types'] : array()
);
$this->base_id = $options['base_id'];
// lets filter the options before we do anything
$options = apply_filters( "wp_super_duper_options", $options );
$options = apply_filters( "wp_super_duper_options_{$this->base_id}", $options );
$options = $this->add_name_from_key( $options );
$this->options = $options;
$this->base_id = $options['base_id'];
$this->arguments = isset( $options['arguments'] ) ? $options['arguments'] : array();
// nested blocks can't work as a widget
if(!empty($this->options['nested-block'])){
if(empty($this->options['output_types'])){
$this->options['output_types'] = array('shortcode','block');
}elseif (($key = array_search('widget', $this->options['output_types'])) !== false) {
unset($this->options['output_types'][$key]);
}
}
// init parent
if(empty($this->options['output_types']) || in_array('widget',$this->options['output_types'])){
parent::__construct( $options['base_id'], $options['name'], $options['widget_ops'] );
}
if ( isset( $options['class_name'] ) ) {
// register widget
$this->class_name = $options['class_name'];
// register shortcode, this needs to be done even for blocks and widgets
$this->register_shortcode();
// Fusion Builder (avada) support
if ( function_exists( 'fusion_builder_map' ) ) {
add_action( 'init', array( $this, 'register_fusion_element' ) );
}
// register block
if(empty($this->options['output_types']) || in_array('block',$this->options['output_types'])){
add_action( 'admin_enqueue_scripts', array( $this, 'register_block' ) );
}
}
// add the CSS and JS we need ONCE
global $sd_widget_scripts;
if ( ! $sd_widget_scripts ) {
wp_add_inline_script( 'admin-widgets', $this->widget_js() );
wp_add_inline_script( 'customize-controls', $this->widget_js() );
wp_add_inline_style( 'widgets', $this->widget_css() );
// maybe add elementor editor styles
add_action( 'elementor/editor/after_enqueue_styles', array( $this, 'elementor_editor_styles' ) );
$sd_widget_scripts = true;
// add shortcode insert button once
add_action( 'media_buttons', array( $this, 'shortcode_insert_button' ) );
// generatepress theme sections compatibility
if ( function_exists( 'generate_sections_sections_metabox' ) ) {
add_action( 'generate_sections_metabox', array( $this, 'shortcode_insert_button_script' ) );
}
/* Load script on Divi theme builder page */
if ( function_exists( 'et_builder_is_tb_admin_screen' ) && et_builder_is_tb_admin_screen() ) {
add_thickbox();
add_action( 'admin_footer', array( $this, 'shortcode_insert_button_script' ) );
}
if ( $this->is_preview() ) {
add_action( 'wp_footer', array( $this, 'shortcode_insert_button_script' ) );
// this makes the insert button work for elementor
add_action( 'elementor/editor/after_enqueue_scripts', array(
$this,
'shortcode_insert_button_script'
) ); // for elementor
}
// this makes the insert button work for cornerstone
add_action( 'wp_print_footer_scripts', array( __CLASS__, 'maybe_cornerstone_builder' ) );
add_action( 'wp_ajax_super_duper_get_widget_settings', array( __CLASS__, 'get_widget_settings' ) );
add_action( 'wp_ajax_super_duper_get_picker', array( __CLASS__, 'get_picker' ) );
// add generator text to admin head
add_action( 'admin_head', array( $this, 'generator' ) );
}
do_action( 'wp_super_duper_widget_init', $options, $this );
}
/**
* The register widget function
* @return void
*/
public function _register() {
if(empty($this->options['output_types']) || in_array('widget',$this->options['output_types'])){
parent::_register();
}
}
/**
* Add our widget CSS to elementor editor.
*/
public function elementor_editor_styles() {
wp_add_inline_style( 'elementor-editor', $this->widget_css( false ) );
}
public function register_fusion_element() {
$options = $this->options;
if ( $this->base_id ) {
$params = $this->get_fusion_params();
$args = array(
'name' => $options['name'],
'shortcode' => $this->base_id,
'icon' => $options['block-icon'] ? $options['block-icon'] : 'far fa-square',
'allow_generator' => true,
);
if ( ! empty( $params ) ) {
$args['params'] = $params;
}
fusion_builder_map( $args );
}
}
public function get_fusion_params() {
$params = array();
$arguments = $this->get_arguments();
if ( ! empty( $arguments ) ) {
foreach ( $arguments as $key => $val ) {
$param = array();
// type
$param['type'] = str_replace(
array(
"text",
"number",
"email",
"color",
"checkbox"
),
array(
"textfield",
"textfield",
"textfield",
"colorpicker",
"select",
),
$val['type'] );
// multiselect
if ( $val['type'] == 'multiselect' || ( ( $param['type'] == 'select' || $val['type'] == 'select' ) && ! empty( $val['multiple'] ) ) ) {
$param['type'] = 'multiple_select';
$param['multiple'] = true;
}
// heading
$param['heading'] = $val['title'];
// description
$param['description'] = isset( $val['desc'] ) ? $val['desc'] : '';
// param_name
$param['param_name'] = $key;
// Default
$param['default'] = isset( $val['default'] ) ? $val['default'] : '';
// Group
if ( isset( $val['group'] ) ) {
$param['group'] = $val['group'];
}
// value
if ( $val['type'] == 'checkbox' ) {
if ( isset( $val['default'] ) && $val['default'] == '0' ) {
unset( $param['default'] );
}
$param['value'] = array( '' => __( "No" ), '1' => __( "Yes" ) );
} elseif ( $param['type'] == 'select' || $param['type'] == 'multiple_select' ) {
$param['value'] = isset( $val['options'] ) ? $val['options'] : array();
} else {
$param['value'] = isset( $val['default'] ) ? $val['default'] : '';
}
// setup the param
$params[] = $param;
}
}
return $params;
}
/**
* Maybe insert the shortcode inserter button in the footer if we are in the cornerstone builder
*/
public static function maybe_cornerstone_builder() {
if ( did_action( 'cornerstone_before_boot_app' ) ) {
self::shortcode_insert_button_script();
}
}
/**
* A function to ge the shortcode builder picker html.
*
* @param string $editor_id
*
* @return string
*/
public static function get_picker( $editor_id = '' ) {
ob_start();
if ( isset( $_POST['editor_id'] ) ) {
$editor_id = esc_attr( $_POST['editor_id'] );
} elseif ( isset( $_REQUEST['et_fb'] ) ) {
$editor_id = 'main_content_content_vb_tiny_mce';
}
global $sd_widgets;
// print_r($sd_widgets);exit;
?>
';
echo "
";
foreach ( $sd_widgets as $shortcode => $class ) {
if(!empty($class['output_types']) && !in_array('shortcode', $class['output_types'])){ continue; }
echo "
";
}
echo "";
}
?>
version . '" />';
}
/**
* Get widget settings.
*
* @since 1.0.0
*/
public static function get_widget_settings() {
global $sd_widgets;
$shortcode = isset( $_REQUEST['shortcode'] ) && $_REQUEST['shortcode'] ? sanitize_title_with_dashes( $_REQUEST['shortcode'] ) : '';
if ( ! $shortcode ) {
wp_die();
}
$widget_args = isset( $sd_widgets[ $shortcode ] ) ? $sd_widgets[ $shortcode ] : '';
if ( ! $widget_args ) {
wp_die();
}
$class_name = isset( $widget_args['class_name'] ) && $widget_args['class_name'] ? $widget_args['class_name'] : '';
if ( ! $class_name ) {
wp_die();
}
// invoke an instance method
$widget = new $class_name;
ob_start();
$widget->form( array() );
$form = ob_get_clean();
echo "";
echo "";
echo "";
?>
';
}
echo self::shortcode_button( 'this', 'true' );
// see opening note
if ( function_exists( 'cornerstone_plugin_init' ) && ! is_admin() ) {
echo ''; // end #insert-media-button
}
// Add separate script for generatepress theme sections
if ( function_exists( 'generate_sections_sections_metabox' ) && did_action( 'generate_sections_metabox' ) ) {
} else {
self::shortcode_insert_button_script( $editor_id, $insert_shortcode_function );
}
$shortcode_insert_button_once = true;
}
/**
* Gets the shortcode insert button html.
*
* @param string $id
* @param string $search_for_id
*
* @return mixed
*/
public static function shortcode_button( $id = '', $search_for_id = '' ) {
ob_start();
?>
);" href="#TB_inline?width=100%&height=550&inlineId=super-duper-content-ajaxed"
class="thickbox button super-duper-content-open" title="Add Shortcode">
Loading
tags for code highlighting, so we strip them from the output.
*/
return str_replace( array(
''
), '', $output );
}
/**
* Output the JS and CSS for the shortcode insert button.
*
* @param string $editor_id
* @param string $insert_shortcode_function
*
*@since 1.0.6
*
*/
public static function shortcode_insert_button_script( $editor_id = '', $insert_shortcode_function = '' ) {
?>
" . self::siteorigin_js() . "";
}
?>
tags for code highlighting, so we strip them from the output.
*/
return str_replace( array(
''
), '', $output );
}
/**
* Gets some JS for the widgets screen.
*
* @return mixed
*/
public function widget_js() {
ob_start();
?>
tags for code highlighting, so we strip them from the output.
*/
return str_replace( array(
''
), '', $output );
}
/**
* Set the name from the argument key.
*
* @param $options
*
* @return mixed
*/
private function add_name_from_key( $options, $arguments = false ) {
if ( ! empty( $options['arguments'] ) ) {
foreach ( $options['arguments'] as $key => $val ) {
$options['arguments'][ $key ]['name'] = $key;
}
} elseif ( $arguments && is_array( $options ) && ! empty( $options ) ) {
foreach ( $options as $key => $val ) {
$options[ $key ]['name'] = $key;
}
}
return $options;
}
/**
* Register the parent shortcode.
*
* @since 1.0.0
*/
public function register_shortcode() {
add_shortcode( $this->base_id, array( $this, 'shortcode_output' ) );
add_action( 'wp_ajax_super_duper_output_shortcode', array( $this, 'render_shortcode' ) );
}
/**
* Render the shortcode via ajax so we can return it to Gutenberg.
*
* @since 1.0.0
*/
public function render_shortcode() {
check_ajax_referer( 'super_duper_output_shortcode', '_ajax_nonce', true );
if ( ! current_user_can( 'manage_options' ) ) {
wp_die();
}
// we might need the $post value here so lets set it.
if ( isset( $_POST['post_id'] ) && $_POST['post_id'] ) {
$post_obj = get_post( absint( $_POST['post_id'] ) );
if ( ! empty( $post_obj ) && empty( $post ) ) {
global $post;
$post = $post_obj;
}
}
if ( isset( $_POST['shortcode'] ) && $_POST['shortcode'] ) {
$is_preview = $this->is_preview();
$shortcode_name = sanitize_title_with_dashes( $_POST['shortcode'] );
$attributes_array = isset( $_POST['attributes'] ) && $_POST['attributes'] ? $_POST['attributes'] : array();
$attributes = '';
if ( ! empty( $attributes_array ) ) {
foreach ( $attributes_array as $key => $value ) {
if ( is_array( $value ) ) {
$value = implode( ",", $value );
}
if ( ! empty( $value ) ) {
$value = wp_unslash( $value );
// Encode [ and ].
if ( $is_preview ) {
$value = $this->encode_shortcodes( $value );
}
}
$attributes .= " " . sanitize_title_with_dashes( $key ) . "='" . esc_attr( $value ) . "' ";
}
}
$shortcode = "[" . $shortcode_name . " " . $attributes . "]";
$content = do_shortcode( $shortcode );
// Decode [ and ].
if ( ! empty( $content ) && $is_preview ) {
$content = $this->decode_shortcodes( $content );
}
echo $content;
}
wp_die();
}
/**
* Output the shortcode.
*
* @param array $args
* @param string $content
*
* @return string
*/
public function shortcode_output( $args = array(), $content = '' ) {
$_instance = $args;
$args = $this->argument_values( $args );
// add extra argument so we know its a output to gutenberg
//$args
$args = $this->string_to_bool( $args );
// if we have a enclosed shortcode we add it to the special `html` argument
if ( ! empty( $content ) ) {
$args['html'] = $content;
}
if ( ! $this->is_preview() ) {
/**
* Filters the settings for a particular widget args.
*
* @param array $args The current widget instance's settings.
* @param WP_Super_Duper $widget The current widget settings.
* @param array $_instance An array of default widget arguments.
*
*@since 1.0.28
*
*/
$args = apply_filters( 'wp_super_duper_widget_display_callback', $args, $this, $_instance );
if ( ! is_array( $args ) ) {
return $args;
}
}
$class = isset( $this->options['widget_ops']['classname'] ) ? esc_attr( $this->options['widget_ops']['classname'] ) : '';
$class .= " sdel-".$this->get_instance_hash();
$class = apply_filters( 'wp_super_duper_div_classname', $class, $args, $this );
$class = apply_filters( 'wp_super_duper_div_classname_' . $this->base_id, $class, $args, $this );
$attrs = apply_filters( 'wp_super_duper_div_attrs', '', $args, $this );
$attrs = apply_filters( 'wp_super_duper_div_attrs_' . $this->base_id, '', $args, $this );
$shortcode_args = array();
$output = '';
$no_wrap = isset( $this->options['no_wrap'] ) && $this->options['no_wrap'] ? true : false;
if ( isset( $args['no_wrap'] ) && $args['no_wrap'] ) {
$no_wrap = true;
}
$main_content = $this->output( $args, $shortcode_args, $content );
if ( $main_content && ! $no_wrap ) {
// wrap the shortcode in a div with the same class as the widget
$output .= '';
if ( ! empty( $args['title'] ) ) {
// if its a shortcode and there is a title try to grab the title wrappers
$shortcode_args = array( 'before_title' => '', 'after_title' => '' );
if ( empty( $instance ) ) {
global $wp_registered_sidebars;
if ( ! empty( $wp_registered_sidebars ) ) {
foreach ( $wp_registered_sidebars as $sidebar ) {
if ( ! empty( $sidebar['before_title'] ) ) {
$shortcode_args['before_title'] = $sidebar['before_title'];
$shortcode_args['after_title'] = $sidebar['after_title'];
break;
}
}
}
}
$output .= $this->output_title( $shortcode_args, $args );
}
$output .= $main_content;
$output .= '
';
} elseif ( $main_content && $no_wrap ) {
$output .= $main_content;
}
// if preview show a placeholder if empty
if ( $this->is_preview() && $output == '' ) {
$output = $this->preview_placeholder_text( "{{" . $this->base_id . "}}" );
}
return apply_filters( 'wp_super_duper_widget_output', $output, $args, $shortcode_args, $this );
}
/**
* Placeholder text to show if output is empty and we are on a preview/builder page.
*
* @param string $name
*
* @return string
*/
public function preview_placeholder_text( $name = '' ) {
return "" . sprintf( __( 'Placeholder for: %s' ), $name ) . "
";
}
/**
* Sometimes booleans values can be turned to strings, so we fix that.
*
* @param $options
*
* @return mixed
*/
public function string_to_bool( $options ) {
// convert bool strings to booleans
foreach ( $options as $key => $val ) {
if ( $val == 'false' ) {
$options[ $key ] = false;
} elseif ( $val == 'true' ) {
$options[ $key ] = true;
}
}
return $options;
}
/**
* Get the argument values that are also filterable.
*
* @param $instance
*
* @return array
*@since 1.0.12 Don't set checkbox default value if the value is empty.
*
*/
public function argument_values( $instance ) {
$argument_values = array();
// set widget instance
$this->instance = $instance;
if ( empty( $this->arguments ) ) {
$this->arguments = $this->get_arguments();
}
if ( ! empty( $this->arguments ) ) {
foreach ( $this->arguments as $key => $args ) {
// set the input name from the key
$args['name'] = $key;
//
$argument_values[ $key ] = isset( $instance[ $key ] ) ? $instance[ $key ] : '';
if ( $args['type'] == 'checkbox' && $argument_values[ $key ] == '' ) {
// don't set default for an empty checkbox
} elseif ( $argument_values[ $key ] == '' && isset( $args['default'] ) ) {
$argument_values[ $key ] = $args['default'];
}
}
}
return $argument_values;
}
/**
* Set arguments in super duper.
*
* @return array Set arguments.
*@since 1.0.0
*
*/
public function set_arguments() {
return $this->arguments;
}
/**
* Get arguments in super duper.
*
* @return array Get arguments.
*@since 1.0.0
*
*/
public function get_arguments() {
if ( empty( $this->arguments ) ) {
$this->arguments = $this->set_arguments();
}
$this->arguments = apply_filters( 'wp_super_duper_arguments', $this->arguments, $this->options, $this->instance );
$this->arguments = $this->add_name_from_key( $this->arguments, true );
return $this->arguments;
}
/**
* This is the main output class for all 3 items, widget, shortcode and block, it is extended in the calling class.
*
* @param array $args
* @param array $widget_args
* @param string $content
*/
public function output( $args = array(), $widget_args = array(), $content = '' ) {
}
/**
* Add the dynamic block code inline when the wp-block in enqueued.
*/
public function register_block() {
wp_add_inline_script( 'wp-blocks', $this->block() );
if ( class_exists( 'SiteOrigin_Panels' ) ) {
wp_add_inline_script( 'wp-blocks', $this->siteorigin_js() );
}
}
/**
* Check if we need to show advanced options.
*
* @return bool
*/
public function block_show_advanced() {
$show = false;
$arguments = $this->get_arguments();
if ( ! empty( $arguments ) ) {
foreach ( $arguments as $argument ) {
if ( isset( $argument['advanced'] ) && $argument['advanced'] ) {
$show = true;
break; // no need to continue if we know we have it
}
}
}
return $show;
}
/**
* Get the url path to the current folder.
*
* @return string
*/
public function get_url() {
$url = $this->url;
if ( ! $url ) {
$content_dir = wp_normalize_path( untrailingslashit( WP_CONTENT_DIR ) );
$content_url = untrailingslashit( WP_CONTENT_URL );
// Replace http:// to https://.
if ( strpos( $content_url, 'http://' ) === 0 && strpos( plugins_url(), 'https://' ) === 0 ) {
$content_url = str_replace( 'http://', 'https://', $content_url );
}
// Check if we are inside a plugin
$file_dir = str_replace( "/includes", "", wp_normalize_path( dirname( __FILE__ ) ) );
$url = str_replace( $content_dir, $content_url, $file_dir );
$url = trailingslashit( $url );
$this->url = $url;
}
return $url;
}
/**
* Get the url path to the current folder.
*
* @return string
*/
public function get_url_old() {
$url = $this->url;
if ( ! $url ) {
// check if we are inside a plugin
$file_dir = str_replace( "/includes", "", dirname( __FILE__ ) );
$dir_parts = explode( "/wp-content/", $file_dir );
$url_parts = explode( "/wp-content/", plugins_url() );
if ( ! empty( $url_parts[0] ) && ! empty( $dir_parts[1] ) ) {
$url = trailingslashit( $url_parts[0] . "/wp-content/" . $dir_parts[1] );
$this->url = $url;
}
}
return $url;
}
/**
* Generate the block icon.
*
* Enables the use of Font Awesome icons.
*
* @note xlink:href is actually deprecated but href is not supported by all so we use both.
*
* @param $icon
*
* @return string
*@since 1.1.0
*/
public function get_block_icon( $icon ) {
// check if we have a Font Awesome icon
$fa_type = '';
if ( substr( $icon, 0, 7 ) === "fas fa-" ) {
$fa_type = 'solid';
} elseif ( substr( $icon, 0, 7 ) === "far fa-" ) {
$fa_type = 'regular';
} elseif ( substr( $icon, 0, 7 ) === "fab fa-" ) {
$fa_type = 'brands';
} else {
$icon = "'" . $icon . "'";
}
// set the icon if we found one
if ( $fa_type ) {
$fa_icon = str_replace( array( "fas fa-", "far fa-", "fab fa-" ), "", $icon );
$icon = "el('svg',{width: 20, height: 20, viewBox: '0 0 20 20'},el('use', {'xlink:href': '" . $this->get_url() . "icons/" . $fa_type . ".svg#" . $fa_icon . "','href': '" . $this->get_url() . "icons/" . $fa_type . ".svg#" . $fa_icon . "'}))";
}
return $icon;
}
public function group_arguments( $arguments ) {
// echo '###';print_r($arguments);
if ( ! empty( $arguments ) ) {
$temp_arguments = array();
$general = __( "General" );
$add_sections = false;
foreach ( $arguments as $key => $args ) {
if ( isset( $args['group'] ) ) {
$temp_arguments[ $args['group'] ][ $key ] = $args;
$add_sections = true;
} else {
$temp_arguments[ $general ][ $key ] = $args;
}
}
// only add sections if more than one
if ( $add_sections ) {
$arguments = $temp_arguments;
}
}
// echo '###';print_r($arguments);
return $arguments;
}
/**
* Output the JS for building the dynamic Guntenberg block.
*
* @return mixed
*@since 1.0.9 Save numbers as numbers and not strings.
* @since 1.1.0 Font Awesome classes can be used for icons.
* @since 1.0.4 Added block_wrap property which will set the block wrapping output element ie: div, span, p or empty for no wrap.
*/
public function block() {
global $sd_is_js_functions_loaded;
ob_start();
$show_advanced = $this->block_show_advanced();
?>
tags for code highlighting, so we strip them from the output.
*/
return str_replace( array(
''
), '', $output );
}
public function block_row_start($key, $args){
// check for row
if(!empty($args['row'])){
if(!empty($args['row']['open'])){
// element require
$element_require = ! empty( $args['element_require'] ) ? $this->block_props_replace( $args['element_require'], true ) . " && " : "";
$device_type = ! empty( $args['device_type'] ) ? esc_attr($args['device_type']) : '';
$device_type_require = ! empty( $args['device_type'] ) ? " deviceType == '" . esc_attr($device_type) . "' && " : '';
$device_type_icon = '';
if($device_type=='Desktop'){
$device_type_icon = '';
}elseif($device_type=='Tablet'){
$device_type_icon = '';
}elseif($device_type=='Mobile'){
$device_type_icon = '';
}
echo $element_require;
echo $device_type_require;
if(false){?>array_to_attributes( $args['custom_attributes'] ) : '';
$options = '';
$extra = '';
$require = '';
$inside_elements = '';
// `content` is a protected and special argument
if ( $key == 'content' ) {
return;
}
$device_type = ! empty( $args['device_type'] ) ? esc_attr($args['device_type']) : '';
$device_type_require = ! empty( $args['device_type'] ) ? " deviceType == '" . esc_attr($device_type) . "' && " : '';
$device_type_icon = '';
if($device_type=='Desktop'){
$device_type_icon = '';
}elseif($device_type=='Tablet'){
$device_type_icon = '';
}elseif($device_type=='Mobile'){
$device_type_icon = '';
}
// icon
$icon = '';
if( !empty( $args['icon'] ) ){
$icon .= "el('div', {";
$icon .= "dangerouslySetInnerHTML: {__html: '".self::get_widget_icon( esc_attr($args['icon']))."'},";
$icon .= "className: 'text-center',";
$icon .= "title: '".addslashes( $args['title'] )."',";
$icon .= "}),";
// blank title as its added to the icon.
$args['title'] = '';
}
// require advanced
$require_advanced = ! empty( $args['advanced'] ) ? "props.attributes.show_advanced && " : "";
// element require
$element_require = ! empty( $args['element_require'] ) ? $this->block_props_replace( $args['element_require'], true ) . " && " : "";
$onchange = "props.setAttributes({ $key: $key } )";
$onchangecomplete = "";
$value = "props.attributes.$key";
$text_type = array( 'text', 'password', 'number', 'email', 'tel', 'url', 'colorx','range' );
if ( in_array( $args['type'], $text_type ) ) {
$type = 'TextControl';
// Save numbers as numbers and not strings
if ( $args['type'] == 'number' ) {
$onchange = "props.setAttributes({ $key: $key ? Number($key) : '' } )";
}
}else if ( $args['type'] == 'styleid' ) {
$type = 'TextControl';
$args['type'] == 'text';
// Save numbers as numbers and not strings
$value = "props.attributes.$key ? props.attributes.$key : 'aaabbbccc'";
}else if ( $args['type'] == 'notice' ) {
$notice_message = !empty($args['desc']) ? addslashes($args['desc']) : '';
$notice_status = !empty($args['status']) ? esc_attr($args['status']) : 'info';
$notice = "el('div',{className:'bsui'},el(wp.components.Notice, {status: '$notice_status',isDismissible: false,className: 'm-0 pr-0 mb-3'},el('div',{dangerouslySetInnerHTML: {__html: '$notice_message'}}))),";
echo $notice_message ? $element_require . $notice : '';
return;
}
/*
* https://www.wptricks.com/question/set-current-tab-on-a-gutenberg-tabpanel-component-from-outside-that-component/ es5 layout
elseif($args['type']=='tabs'){
?>
el(
wp.components.TabPanel,
{
activeClass: 'active-tab',
initialTabName: deviceType,
tabs: [
{
name: 'Desktop',
title: el('div', {dangerouslySetInnerHTML: {__html: ''}}),
className: 'tab-one' + deviceType == 'Desktop' ? ' active-tab' : '',
content: el('div', {dangerouslySetInnerHTML: {__html: 'ddd'}})
},
{
name: 'Tablet',
title: el('div', {dangerouslySetInnerHTML: {__html: ''}}),
className: 'tab-two' + deviceType == 'Tablet' ? ' active-tab' : '',
content: el('div', {dangerouslySetInnerHTML: {__html: 'ttt'}})
},
{
name: 'Mobile',
title: el('div', {dangerouslySetInnerHTML: {__html: ''}}),
className: 'tab-two' + deviceType == 'Mobile' ? ' active-tab' : '',
content: el('div', {dangerouslySetInnerHTML: {__html: 'mmm'}})
},
],
},
( tab ) => {
// @todo https://github.com/WordPress/gutenberg/issues/39248
if(tab.name=='Desktop'){
wp.data.dispatch('core/edit-post').__experimentalSetPreviewDeviceType('Desktop');
wp.data.select('core/edit-post').__experimentalGetPreviewDeviceType();
}else if(tab.name=='Tablet'){
wp.data.dispatch('core/edit-post').__experimentalSetPreviewDeviceType('Tablet');
wp.data.select('core/edit-post').__experimentalGetPreviewDeviceType();
}else if(tab.name=='Mobile'){
wp.data.dispatch('core/edit-post').__experimentalSetPreviewDeviceType('Mobile');
wp.data.select('core/edit-post').__experimentalGetPreviewDeviceType();
}
return tab.content;
}
),
get_url()."icons/placeholder.png' : props.attributes.$key,
value: props.attributes.{$key}_xy.x !== undefined && props.attributes.{$key}_xy.x >= 0 ? props.attributes.{$key}_xy : {x: 0.5,y: 0.5,},
// value: props.attributes.{$key}_xy,
onChange: function(focalPoint){
console.log(props.attributes);
return props.setAttributes({
{$key}_xy: focalPoint
});
},
// @todo for some reason this does not work as expected.
// onDrag: function(focalPointTemp){
// return props.setAttributes({
// {$key}_xy: focalPointTemp
// });
// }
}), ";
$value = '""';
$type = 'MediaUpload';
$extra .= "onSelect: function(media){
return props.setAttributes({
$key: media.url,
{$key}_id: media.id
});
},";
$extra .= "type: 'image',";
$extra .= "render: function (obj) {
return el( 'div',{},
( !props.attributes.$key && !props.attributes.{$key}_use_featured ) && el( wp.components.Button, {
className: 'components-button components-circular-option-picker__clear is-primary is-smallx',
onClick: obj.open
},
'Upload Image'
),
$img_preview
props.attributes.$key && el( wp.components.Button, {
className: 'components-button components-circular-option-picker__clear is-secondary is-small',
style: {margin:'8px 0',display: 'block'},
onClick: function(){
return props.setAttributes({
$key: '',
{$key}_id: ''
});
}
},
props.attributes.$key? 'Clear' : ''
)
)
}";
$onchange = "";
//$inside_elements = ",el('div',{},'file upload')";
}elseif ( $args['type'] == 'images' ) {
// print_r($args);
$img_preview = "props.attributes.$key && (function() {
let uploads = JSON.parse('['+props.attributes.$key+']');
let images = [];
uploads.map((upload, index) => (
images.push( el('div',{className: 'col p-2',draggable: 'true','data-index': index}, el('img', { src: upload.sizes.thumbnail.url,style: {maxWidth:'100%',background: '#ccc',pointerEvents:'none'}}),el('i',{
className: 'fas fa-times-circle text-danger position-absolute ml-n2 mt-n1 bg-white rounded-circle c-pointer',
onClick: function(){
aui_confirm('".__('Are you sure?')."', '".__('Delete')."', '".__('Cancel')."', true).then(function(confirmed) {
if (confirmed) {
let new_uploads = JSON.parse(props.attributes.$key);
new_uploads.splice(index, 1); //remove
return props.setAttributes({
{$key}: JSON.stringify( new_uploads ),
});
}
});
}},'') ) )
));
return images;
})(),";
$value = '""';
$type = 'MediaUpload';
$extra .= "onSelect: function(media){
let slim_images = props.attributes.$key ? JSON.parse('['+props.attributes.$key+']') : [];
if(media.length){
for (var i=0; i < media.length; i++) {
slim_images.push({id: media[i].id, caption: media[i].caption, description: media[i].description,title: media[i].title,alt: media[i].alt,sizes: media[i].sizes});
}
}
return props.setAttributes({
$key: JSON.stringify(slim_images).replace('[','').replace(']',''),
});
},";
$extra .= "type: 'image',";
$extra .= "multiple: true,";
$extra .= "render: function (obj) {
// init the sort
enableDragSort('sd-sortable');
return el( 'div',{},
el( wp.components.Button, {
className: 'components-button components-circular-option-picker__clear is-primary is-smallx',
onClick: obj.open
},
'Upload Images'
),
el('div',{className: 'row row-cols-3 px-2 sd-sortable','data-field':'$key'},
$img_preview
),
props.attributes.$key && el( wp.components.Button, {
className: 'components-button components-circular-option-picker__clear is-secondary is-small',
style: {margin:'8px 0'},
onClick: function(){
return props.setAttributes({
$key: '',
});
}
},
props.attributes.$key? 'Clear All' : ''
)
)
}";
$onchange = "";
//$inside_elements = ",el('div',{},'file upload')";
}
elseif ( $args['type'] == 'checkbox' ) {
$type = 'CheckboxControl';
$extra .= "checked: props.attributes.$key,";
$onchange = "props.setAttributes({ $key: ! props.attributes.$key } )";
} elseif ( $args['type'] == 'textarea' ) {
$type = 'TextareaControl';
} elseif ( $args['type'] == 'select' || $args['type'] == 'multiselect' ) {
$type = 'SelectControl';
if($args['name'] == 'category' && !empty($args['post_type_linked'])){
$options .= "options: taxonomies_".str_replace("-","_", $this->id).",";
}elseif($args['name'] == 'sort_by' && !empty($args['post_type_linked'])){
$options .= "options: sort_by_".str_replace("-","_", $this->id).",";
}else {
if ( ! empty( $args['options'] ) ) {
$options .= "options: [";
foreach ( $args['options'] as $option_val => $option_label ) {
$options .= "{ value: '" . esc_attr( $option_val ) . "', label: '" . addslashes( $option_label ) . "' },";
}
$options .= "],";
}
}
if ( isset( $args['multiple'] ) && $args['multiple'] ) { //@todo multiselect does not work at the moment: https://github.com/WordPress/gutenberg/issues/5550
$extra .= ' multiple:true,style:{height:"auto",paddingRight:"8px","overflow-y":"auto"}, ';
}
} elseif ( $args['type'] == 'tagselect' ) {
// $type = 'FormTokenField';
//
// if ( ! empty( $args['options'] ) ) {
// $options .= "suggestions: [";
// foreach ( $args['options'] as $option_val => $option_label ) {
// $options .= "{ value: '" . esc_attr( $option_val ) . "', title: '" . addslashes( $option_label ) . "' },";
//// $options .= "'" . esc_attr( $option_val ) . "':'" . addslashes( $option_label ) . "',";
// }
// $options .= "],";
// }
//
// $onchangex = "{ ( selectedItems ) => {
// // Build array of selected posts.
// let selectedPostsArray = [];
// selectedPosts.map(
// ( postName ) => {
// const matchingPost = posts.find( ( post ) => {
// return post.title.raw === postName;
//
// } );
// if ( matchingPost !== undefined ) {
// selectedPostsArray.push( matchingPost.id );
// }
// }
// )
//
// setAttributes( { selectedPosts: selectedPostsArray } );
// } } ";
// $onchange = '';// "props.setAttributes({ $key: [ props.attributes.$key ] } )";
//
//// $options = "";
// $value = "[]";
// $extra .= ' __experimentalExpandOnFocus: true,';
} elseif ( $args['type'] == 'alignment' ) {
$type = 'AlignmentToolbar'; // @todo this does not seem to work but cant find a example
}elseif ( $args['type'] == 'margins' ) {
} else {
return;// if we have not implemented the control then don't break the JS.
}
// color input does not show the labels so we add them
if($args['type']=='color'){
// add show only if advanced
echo $require_advanced;
// add setting require if defined
echo $element_require;
echo "el('div', {style: {'marginBottom': '8px'}}, '".addslashes( $args['title'] )."'),";
}
// add show only if advanced
echo $require_advanced;
// add setting require if defined
echo $element_require;
echo $device_type_require;
// icon
echo $icon;
?>
el( , {
label: el('label', {
className: 'components-base-control__label',
style: {width:"100%"}
},
el('span',{dangerouslySetInnerHTML: {__html: ''}}),
deviceType == '' && el('span',{dangerouslySetInnerHTML: {__html: ''},title: deviceType + ": Set preview mode to change",style: {right:"0",position:"absolute",color:"var(--wp-admin-theme-color)"}})
)'',
help: ,
value: ,
onChange: function ( ) {
}
} ),
$val ) {
if(is_array($val)){
$attributes .= $key.': {'.$this->array_to_attributes( $val, $html ).'},';
}else{
$attributes .= $html ? " $key='$val' " : "'$key': '$val',";
}
}
}
return $attributes;
}
/**
* A self looping function to create the output for JS block elements.
*
* This is what is output in the WP Editor visual view.
*
* @param $args
*/
public function block_element( $args, $save = false ) {
if ( ! empty( $args ) ) {
foreach ( $args as $element => $new_args ) {
if ( is_array( $new_args ) ) { // its an element
if ( isset( $new_args['element'] ) ) {
if ( isset( $new_args['element_require'] ) ) {
echo str_replace( array(
"'+",
"+'"
), '', $this->block_props_replace( $new_args['element_require'] ) ) . " && ";
unset( $new_args['element_require'] );
}
if($new_args['element']=='InnerBlocks'){
echo "\n el( InnerBlocks, {";
}elseif($new_args['element']=='innerBlocksProps'){
$element = isset($new_args['inner_element']) ? esc_attr($new_args['inner_element']) : 'div';
// echo "\n el( 'section', wp.blockEditor.useInnerBlocksProps( blockProps, {";
// echo $save ? "\n el( '$element', wp.blockEditor.useInnerBlocksProps.save( " : "\n el( '$element', wp.blockEditor.useInnerBlocksProps( ";
echo $save ? "\n el( '$element', wp.blockEditor.useInnerBlocksProps.save( " : "\n el( '$element', wp.blockEditor.useInnerBlocksProps( ";
echo $save ? "wp.blockEditor.useBlockProps.save( {" : "wp.blockEditor.useBlockProps( {";
echo !empty($new_args['blockProps']) ? $this->block_element( $new_args['blockProps'],$save ) : '';
echo "} ), {";
echo !empty($new_args['innerBlocksProps']) && !$save ? $this->block_element( $new_args['innerBlocksProps'],$save ) : '';
// echo '###';
// echo '###';
}elseif($new_args['element']=='BlocksProps'){
if ( isset($new_args['if_inner_element']) ) {
$element = $new_args['if_inner_element'];
}else {
$element = isset($new_args['inner_element']) ? "'".esc_attr($new_args['inner_element'])."'" : "'div'";
}
unset($new_args['inner_element']);
echo $save ? "\n el( $element, wp.blockEditor.useBlockProps.save( {" : "\n el( $element, wp.blockEditor.useBlockProps( {";
echo !empty($new_args['blockProps']) ? $this->block_element( $new_args['blockProps'],$save ) : '';
// echo "} ),";
}else{
echo "\n el( '" . $new_args['element'] . "', {";
}
// get the attributes
foreach ( $new_args as $new_key => $new_value ) {
if ( $new_key == 'element' || $new_key == 'content'|| $new_key == 'if_content' || $new_key == 'element_require' || $new_key == 'element_repeat' || is_array( $new_value ) ) {
// do nothing
} else {
echo $this->block_element( array( $new_key => $new_value ),$save );
}
}
echo $new_args['element']=='BlocksProps' ? '} ),' : "},";// end attributes
// get the content
$first_item = 0;
foreach ( $new_args as $new_key => $new_value ) {
if ( $new_key === 'content' || $new_key === 'if_content' || is_array( $new_value ) ) {
if ( $new_key === 'content' ) {
echo "'" . $this->block_props_replace( wp_slash( $new_value ) ) . "'";
}else if ( $new_key === 'if_content' ) {
echo $this->block_props_replace( $new_value );
}
if ( is_array( $new_value ) ) {
if ( isset( $new_value['element_require'] ) ) {
echo str_replace( array(
"'+",
"+'"
), '', $this->block_props_replace( $new_value['element_require'] ) ) . " && ";
unset( $new_value['element_require'] );
}
if ( isset( $new_value['element_repeat'] ) ) {
$x = 1;
while ( $x <= absint( $new_value['element_repeat'] ) ) {
$this->block_element( array( '' => $new_value ),$save );
$x ++;
}
} else {
$this->block_element( array( '' => $new_value ),$save );
}
}
$first_item ++;
}
}
if($new_args['element']=='innerBlocksProps' || $new_args['element']=='xBlocksProps'){
echo "))";// end content
}else{
echo ")";// end content
}
echo ", \n";
}
} else {
if ( substr( $element, 0, 3 ) === "if_" ) {
$extra = '';
if( strpos($new_args, '[%WrapClass%]') !== false ){
$new_args = str_replace('[%WrapClass%]"','" + sd_build_aui_class(props.attributes)',$new_args);
$new_args = str_replace('[%WrapClass%]','+ sd_build_aui_class(props.attributes)',$new_args);
}
echo str_replace( "if_", "", $element ) . ": " . $this->block_props_replace( $new_args, true ) . ",";
} elseif ( $element == 'style' && strpos($new_args, '[%WrapStyle%]') !== false ) {
$new_args = str_replace('[%WrapStyle%]','',$new_args);
echo $element . ": {..." . $this->block_props_replace( $new_args ) . " , ...sd_build_aui_styles(props.attributes) },";
// echo $element . ": " . $this->block_props_replace( $new_args ) . ",";
} elseif ( $element == 'style' ) {
echo $element . ": " . $this->block_props_replace( $new_args ) . ",";
} elseif ( ( $element == 'class' || $element == 'className' ) && strpos($new_args, '[%WrapClass%]') !== false ) {
$new_args = str_replace('[%WrapClass%]','',$new_args);
echo $element . ": '" . $this->block_props_replace( $new_args ) . "' + sd_build_aui_class(props.attributes),";
} elseif ( $element == 'template' && $new_args ) {
echo $element . ": $new_args,";
} else {
echo $element . ": '" . $this->block_props_replace( $new_args ) . "',";
}
}
}
}
}
/**
* Replace block attributes placeholders with the proper naming.
*
* @param $string
*
* @return mixed
*/
public function block_props_replace( $string, $no_wrap = false ) {
if ( $no_wrap ) {
$string = str_replace( array( "[%", "%]" ), array( "props.attributes.", "" ), $string );
} else {
$string = str_replace( array( "[%", "%]" ), array( "'+props.attributes.", "+'" ), $string );
}
return $string;
}
/**
* Outputs the content of the widget
*
* @param array $args
* @param array $instance
*/
public function widget( $args, $instance ) {
// get the filtered values
$argument_values = $this->argument_values( $instance );
$argument_values = $this->string_to_bool( $argument_values );
$output = $this->output( $argument_values, $args );
$no_wrap = false;
if ( isset( $argument_values['no_wrap'] ) && $argument_values['no_wrap'] ) {
$no_wrap = true;
}
ob_start();
if ( $output && ! $no_wrap ) {
$class_original = $this->options['widget_ops']['classname'];
$class = $this->options['widget_ops']['classname']." sdel-".$this->get_instance_hash();
// Before widget
$before_widget = $args['before_widget'];
$before_widget = str_replace($class_original,$class,$before_widget);
$before_widget = apply_filters( 'wp_super_duper_before_widget', $before_widget, $args, $instance, $this );
$before_widget = apply_filters( 'wp_super_duper_before_widget_' . $this->base_id, $before_widget, $args, $instance, $this );
// After widget
$after_widget = $args['after_widget'];
$after_widget = apply_filters( 'wp_super_duper_after_widget', $after_widget, $args, $instance, $this );
$after_widget = apply_filters( 'wp_super_duper_after_widget_' . $this->base_id, $after_widget, $args, $instance, $this );
echo $before_widget;
// elementor strips the widget wrapping div so we check for and add it back if needed
if ( $this->is_elementor_widget_output() ) {
// Filter class & attrs for elementor widget output.
$class = apply_filters( 'wp_super_duper_div_classname', $class, $args, $this );
$class = apply_filters( 'wp_super_duper_div_classname_' . $this->base_id, $class, $args, $this );
$attrs = apply_filters( 'wp_super_duper_div_attrs', '', $args, $this );
$attrs = apply_filters( 'wp_super_duper_div_attrs_' . $this->base_id, '', $args, $this );
echo "";
}
echo $this->output_title( $args, $instance );
echo $output;
if ( $this->is_elementor_widget_output() ) {
echo "";
}
echo $after_widget;
} elseif ( $this->is_preview() && $output == '' ) {// if preview show a placeholder if empty
$output = $this->preview_placeholder_text( "{{" . $this->base_id . "}}" );
echo $output;
} elseif ( $output && $no_wrap ) {
echo $output;
}
$output = ob_get_clean();
$output = apply_filters( 'wp_super_duper_widget_output', $output, $instance, $args, $this );
echo $output;
}
/**
* Tests if the current output is inside a elementor container.
*
* @return bool
*@since 1.0.4
*/
public function is_elementor_widget_output() {
$result = false;
if ( defined( 'ELEMENTOR_VERSION' ) && isset( $this->number ) && $this->number == 'REPLACE_TO_ID' ) {
$result = true;
}
return $result;
}
/**
* Tests if the current output is inside a elementor preview.
*
* @return bool
*@since 1.0.4
*/
public function is_elementor_preview() {
$result = false;
if ( isset( $_REQUEST['elementor-preview'] ) || ( is_admin() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor' ) || ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor_ajax' ) ) {
$result = true;
}
return $result;
}
/**
* Tests if the current output is inside a Divi preview.
*
* @return bool
*@since 1.0.6
*/
public function is_divi_preview() {
$result = false;
if ( isset( $_REQUEST['et_fb'] ) || isset( $_REQUEST['et_pb_preview'] ) || ( is_admin() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor' ) ) {
$result = true;
}
return $result;
}
/**
* Tests if the current output is inside a Beaver builder preview.
*
* @return bool
*@since 1.0.6
*/
public function is_beaver_preview() {
$result = false;
if ( isset( $_REQUEST['fl_builder'] ) ) {
$result = true;
}
return $result;
}
/**
* Tests if the current output is inside a siteorigin builder preview.
*
* @return bool
*@since 1.0.6
*/
public function is_siteorigin_preview() {
$result = false;
if ( ! empty( $_REQUEST['siteorigin_panels_live_editor'] ) ) {
$result = true;
}
return $result;
}
/**
* Tests if the current output is inside a cornerstone builder preview.
*
* @return bool
*@since 1.0.8
*/
public function is_cornerstone_preview() {
$result = false;
if ( ! empty( $_REQUEST['cornerstone_preview'] ) || basename( $_SERVER['REQUEST_URI'] ) == 'cornerstone-endpoint' ) {
$result = true;
}
return $result;
}
/**
* Tests if the current output is inside a fusion builder preview.
*
* @return bool
*@since 1.1.0
*/
public function is_fusion_preview() {
$result = false;
if ( ! empty( $_REQUEST['fb-edit'] ) || ! empty( $_REQUEST['fusion_load_nonce'] ) ) {
$result = true;
}
return $result;
}
/**
* Tests if the current output is inside a Oxygen builder preview.
*
* @return bool
*@since 1.0.18
*/
public function is_oxygen_preview() {
$result = false;
if ( ! empty( $_REQUEST['ct_builder'] ) || ( ! empty( $_REQUEST['action'] ) && ( substr( $_REQUEST['action'], 0, 11 ) === "oxy_render_" || substr( $_REQUEST['action'], 0, 10 ) === "ct_render_" ) ) ) {
$result = true;
}
return $result;
}
/**
* General function to check if we are in a preview situation.
*
* @return bool
*@since 1.0.6
*/
public function is_preview() {
$preview = false;
if ( $this->is_divi_preview() ) {
$preview = true;
} elseif ( $this->is_elementor_preview() ) {
$preview = true;
} elseif ( $this->is_beaver_preview() ) {
$preview = true;
} elseif ( $this->is_siteorigin_preview() ) {
$preview = true;
} elseif ( $this->is_cornerstone_preview() ) {
$preview = true;
} elseif ( $this->is_fusion_preview() ) {
$preview = true;
} elseif ( $this->is_oxygen_preview() ) {
$preview = true;
} elseif( $this->is_block_content_call() ) {
$preview = true;
}
return $preview;
}
/**
* Output the super title.
*
* @param $args
* @param array $instance
*
* @return string
*/
public function output_title( $args, $instance = array() ) {
$output = '';
if ( ! empty( $instance['title'] ) ) {
/** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */
$title = apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base );
if(empty($instance['widget_title_tag'])){
$output = $args['before_title'] . $title . $args['after_title'];
}else{
$title_tag = esc_attr( $instance['widget_title_tag'] );
// classes
$title_classes = array();
$title_classes[] = !empty( $instance['widget_title_size_class'] ) ? sanitize_html_class( $instance['widget_title_size_class'] ) : '';
$title_classes[] = !empty( $instance['widget_title_align_class'] ) ? sanitize_html_class( $instance['widget_title_align_class'] ) : '';
$title_classes[] = !empty( $instance['widget_title_color_class'] ) ? "text-".sanitize_html_class( $instance['widget_title_color_class'] ) : '';
$title_classes[] = !empty( $instance['widget_title_border_class'] ) ? sanitize_html_class( $instance['widget_title_border_class'] ) : '';
$title_classes[] = !empty( $instance['widget_title_border_color_class'] ) ? "border-".sanitize_html_class( $instance['widget_title_border_color_class'] ) : '';
$title_classes[] = !empty( $instance['widget_title_mt_class'] ) ? "mt-".absint( $instance['widget_title_mt_class'] ) : '';
$title_classes[] = !empty( $instance['widget_title_mr_class'] ) ? "mr-".absint( $instance['widget_title_mr_class'] ) : '';
$title_classes[] = !empty( $instance['widget_title_mb_class'] ) ? "mb-".absint( $instance['widget_title_mb_class'] ) : '';
$title_classes[] = !empty( $instance['widget_title_ml_class'] ) ? "ml-".absint( $instance['widget_title_ml_class'] ) : '';
$title_classes[] = !empty( $instance['widget_title_pt_class'] ) ? "pt-".absint( $instance['widget_title_pt_class'] ) : '';
$title_classes[] = !empty( $instance['widget_title_pr_class'] ) ? "pr-".absint( $instance['widget_title_pr_class'] ) : '';
$title_classes[] = !empty( $instance['widget_title_pb_class'] ) ? "pb-".absint( $instance['widget_title_pb_class'] ) : '';
$title_classes[] = !empty( $instance['widget_title_pl_class'] ) ? "pl-".absint( $instance['widget_title_pl_class'] ) : '';
$class = !empty( $title_classes ) ? implode(" ",$title_classes) : '';
$output = "<$title_tag class='$class' >$title$title_tag>";
}
}
return $output;
}
/**
* Outputs the options form inputs for the widget.
*
* @param array $instance The widget options.
*/
public function form( $instance ) {
// set widget instance
$this->instance = $instance;
// set it as a SD widget
echo $this->widget_advanced_toggle();
echo "" . esc_attr( $this->options['widget_ops']['description'] ) . "
";
$arguments_raw = $this->get_arguments();
if ( is_array( $arguments_raw ) ) {
$arguments = $this->group_arguments( $arguments_raw );
// Do we have sections?
$has_sections = $arguments == $arguments_raw ? false : true;
if ( $has_sections ) {
$panel_count = 0;
foreach ( $arguments as $key => $args ) {
?>
" . esc_attr( $key ) . " ";
echo "";
foreach ( $args as $k => $a ) {
$this->widget_inputs_row_start($k, $a);
$this->widget_inputs( $a, $instance );
$this->widget_inputs_row_end($k, $a);
}
echo "
";
$panel_count ++;
}
} else {
foreach ( $arguments as $key => $args ) {
$this->widget_inputs_row_start($key, $args);
$this->widget_inputs( $args, $instance );
$this->widget_inputs_row_end($key, $args);
}
}
}
}
public function widget_inputs_row_start($key, $args){
if(!empty($args['row'])){
// maybe open
if(!empty($args['row']['open'])){
?>
' data-element_require='convert_element_require( $args['row']['element_require'] );
} ?>'>
'>
";
}else{
echo "
";
}
}
}
public function widget_inputs_row_end($key, $args){
if(!empty($args['row'])){
// maybe close
if(!empty($args['row']['close'])){
echo "
";
}
echo "
";
}
}
/**
* Get the hidden input that when added makes the advanced button show on widget settings.
*
* @return string
*/
public function widget_advanced_toggle() {
$output = '';
if ( $this->block_show_advanced() ) {
$val = 1;
} else {
$val = 0;
}
$output .= "
";
return $output;
}
/**
* Convert require element.
*
* @param string $input Input element.
*
* @return string $output
*@since 1.0.0
*
*/
public function convert_element_require( $input ) {
$input = str_replace( "'", '"', $input );// we only want double quotes
$output = esc_attr( str_replace( array( "[%", "%]" ), array(
"jQuery(form).find('[data-argument=\"",
"\"]').find('input,select,textarea').val()"
), $input ) );
return $output;
}
/**
* Builds the inputs for the widget options.
*
* @param $args
* @param $instance
*/
public function widget_inputs( $args, $instance ) {
$class = "";
$element_require = "";
$custom_attributes = "";
// get value
if ( isset( $instance[ $args['name'] ] ) ) {
$value = $instance[ $args['name'] ];
} elseif ( ! isset( $instance[ $args['name'] ] ) && ! empty( $args['default'] ) ) {
$value = is_array( $args['default'] ) ? array_map( "esc_html", $args['default'] ) : esc_html( $args['default'] );
} else {
$value = '';
}
// get placeholder
if ( ! empty( $args['placeholder'] ) ) {
$placeholder = "placeholder='" . esc_html( $args['placeholder'] ) . "'";
} else {
$placeholder = '';
}
// get if advanced
if ( isset( $args['advanced'] ) && $args['advanced'] ) {
$class .= " sd-advanced-setting ";
}
// element_require
if ( isset( $args['element_require'] ) && $args['element_require'] ) {
$element_require = $args['element_require'];
}
// custom_attributes
if ( isset( $args['custom_attributes'] ) && $args['custom_attributes'] ) {
$custom_attributes = $this->array_to_attributes( $args['custom_attributes'], true );
}
// before wrapper
?>
'
data-element_require='convert_element_require( $element_require );
} ?>'
>
class="widefat"
id="get_field_id( $args['name'] ) ); ?>"
name="get_field_name( $args['name'] ) ); ?>"
type=""
value="">
class="widefat" id="get_field_id( $args['name'] ) ); ?>"
name="get_field_name( $args['name'] ) ); ?>" type="checkbox"
value="1">
';
}elseif($icon=='box-right'){
return '
';
}elseif($icon=='box-bottom'){
return '
';
}elseif($icon=='box-left'){
return '
';
}
}
/**
* Get the widget input description html.
*
* @param $args
*
* @return string
* @todo, need to make its own tooltip script
*/
public function widget_field_desc( $args ) {
$description = '';
if ( isset( $args['desc'] ) && $args['desc'] ) {
if ( isset( $args['desc_tip'] ) && $args['desc_tip'] ) {
$description = $this->desc_tip( $args['desc'] );
} else {
$description = '
' . wp_kses_post( $args['desc'] ) . '';
}
}
return $description;
}
/**
* Get the widget input title html.
*
* @param $args
*
* @return string
*/
public function widget_field_title( $args ) {
$title = '';
if ( isset( $args['title'] ) && $args['title'] ) {
if ( isset( $args['icon'] ) && $args['icon'] ) {
$title = self::get_widget_icon( $args['icon'], $args['title'] );
} else {
$title = esc_attr($args['title']);
}
}
return $title;
}
/**
* Get the tool tip html.
*
* @param $tip
* @param bool $allow_html
*
* @return string
*/
function desc_tip( $tip, $allow_html = false ) {
if ( $allow_html ) {
$tip = $this->sanitize_tooltip( $tip );
} else {
$tip = esc_attr( $tip );
}
return '
';
}
/**
* Sanitize a string destined to be a tooltip.
*
* @param string $var
*
* @return string
*/
public function sanitize_tooltip( $var ) {
return htmlspecialchars( wp_kses( html_entity_decode( $var ), array(
'br' => array(),
'em' => array(),
'strong' => array(),
'small' => array(),
'span' => array(),
'ul' => array(),
'li' => array(),
'ol' => array(),
'p' => array(),
) ) );
}
/**
* Processing widget options on save
*
* @param array $new_instance The new options
* @param array $old_instance The previous options
*
* @return array
* @todo we should add some sanitation here.
*/
public function update( $new_instance, $old_instance ) {
//save the widget
$instance = array_merge( (array) $old_instance, (array) $new_instance );
// set widget instance
$this->instance = $instance;
if ( empty( $this->arguments ) ) {
$this->get_arguments();
}
// check for checkboxes
if ( ! empty( $this->arguments ) ) {
foreach ( $this->arguments as $argument ) {
if ( isset( $argument['type'] ) && $argument['type'] == 'checkbox' && ! isset( $new_instance[ $argument['name'] ] ) ) {
$instance[ $argument['name'] ] = '0';
}
}
}
return $instance;
}
/**
* Checks if the current call is a ajax call to get the block content.
*
* This can be used in your widget to return different content as the block content.
*
* @return bool
*@since 1.0.3
*/
public function is_block_content_call() {
$result = false;
if ( wp_doing_ajax() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'super_duper_output_shortcode' ) {
$result = true;
}
return $result;
}
/**
* Get an instance hash that will be unique to the type and settings.
*
* @return string
*@since 1.0.20
*/
public function get_instance_hash(){
$instance_string = $this->base_id.serialize($this->instance);
return hash('crc32b',$instance_string);
}
/**
* Generate and return inline styles from CSS rules that will match the unique class of the instance.
*
* @param array $rules
*
* @return string
*@since 1.0.20
*/
public function get_instance_style($rules = array()){
$css = '';
if(!empty($rules)){
$rules = array_unique($rules);
$instance_hash = $this->get_instance_hash();
$css .= "";
}
return $css;
}
/**
* Encode shortcodes tags.
*
* @param string $content Content to search for shortcode tags.
*
*@return string Content with shortcode tags removed.
*@since 1.0.28
*
*/
public function encode_shortcodes( $content ) {
// Avoids existing encoded tags.
$trans = array(
'[' => '[',
']' => ']',
'[' => '[',
']' => ']',
'<' => '&0lt;',
'>' => '&0gt;',
'<' => '&0lt;',
'>' => '&0gt;',
);
$content = strtr( $content, $trans );
$trans = array(
'[' => '[',
']' => ']',
'<' => '<',
'>' => '>',
'"' => '"',
"'" => ''',
);
$content = strtr( $content, $trans );
return $content;
}
/**
* Remove encoded shortcod tags.
*
* @param string $content Content to search for shortcode tags.
*
*@return string Content with decoded shortcode tags.
*@since 1.0.28
*
*/
public function decode_shortcodes( $content ) {
$trans = array(
'[' => '[',
']' => ']',
'[' => '[',
']' => ']',
'<' => '<',
'>' => '>',
'<' => '<',
'>' => '>',
'"' => '"',
''' => "'",
);
$content = strtr( $content, $trans );
$trans = array(
'[' => '[',
']' => ']',
'[' => '[',
']' => ']',
'&0lt;' => '<',
'&0gt;' => '>',
'&0lt;' => '<',
'&0gt;' => '>',
);
$content = strtr( $content, $trans );
return $content;
}
}
}