'; // phpcs:ignore WordPress.WP.EnqueuedResources.NonEnqueuedScript ?> add_facebook_scripts(); } /** * Adds the facebook script. * * @access public * @since 2.2.0 * @return void */ public function add_facebook_scripts() { ?> element_id; if ( $this->args['class'] ) { $attr['class'] .= ' ' . $this->args['class']; } if ( $this->args['fusion_align'] ) { $attr['class'] .= ' fusion-widget-align-' . $this->args['fusion_align']; } if ( $this->args['fusion_align_mobile'] ) { $attr['class'] .= ' fusion-widget-mobile-align-' . $this->args['fusion_align_mobile']; } $attr = fusion_builder_visibility_atts( $this->args['hide_on_mobile'], $attr ); $attr['id'] = $this->args['id']; $styles .= ( $this->args['fusion_bg_color'] ) ? 'background-color:' . $this->args['fusion_bg_color'] . ';' : ''; $styles .= ( $this->args['fusion_padding_color'] ) ? 'padding:' . $this->args['fusion_padding_color'] . ';' : ''; $styles .= ( $this->args['fusion_border_size'] ) ? 'border-width:' . $this->args['fusion_border_size'] . ';' : ''; $styles .= ( $this->args['fusion_border_color'] ) ? 'border-color:' . $this->args['fusion_border_color'] . ';' : ''; $styles .= ( $this->args['fusion_border_style'] && '' !== $this->args['fusion_border_size'] ) ? 'border-style:' . $this->args['fusion_border_style'] . ';' : ''; $styles .= ( $this->args['fusion_bg_radius_size'] ) ? 'border-radius:' . $this->args['fusion_bg_radius_size'] . ';' : ''; $styles .= ( $this->args['fusion_margin'] ) ? 'margin:' . $this->args['fusion_margin'] . ';' : ''; if ( $styles ) { $attr['style'] = $styles; } return $attr; } /** * Builds the dynamic styling. * * @access public * @since 1.1 * @return array */ public function add_styling() { global $content_media_query; $css[ $content_media_query ]['.fusion-widget.fusion-widget-mobile-align-left']['text-align'] = 'left'; $css[ $content_media_query ]['.fusion-widget.fusion-widget-mobile-align-right']['text-align'] = 'right'; $css[ $content_media_query ]['.fusion-widget.fusion-widget-mobile-align-center']['text-align'] = 'center'; return $css; } /** * Maps style-options to our parameters. * * @access public * @since 2.2.0 * @param array $all_elements An array of all our elements. * @return array Returns $all_elements after modifications. */ public function map_style_options_to_params( $all_elements ) { if ( ! class_exists( 'Avada' ) || ! class_exists( 'Avada_Widget_Style' ) ) { return $all_elements; } $style_options = Avada_Widget_Style::get_instance()->widget_options; $widget_styles = []; foreach ( $style_options as $option ) { if ( 'text' === $option['type'] ) { $option['type'] = 'textfield'; } $widget_styles[ $option['key'] ]['type'] = $option['type']; $widget_styles[ $option['key'] ]['param_name'] = $option['key']; $widget_styles[ $option['key'] ]['group'] = esc_attr__( 'Design', 'fusion-builder' ); $widget_styles[ $option['key'] ]['description'] = $option['description']; $widget_styles[ $option['key'] ]['heading'] = $option['title']; $widget_styles[ $option['key'] ]['value'] = ''; if ( isset( $option['css_property'] ) ) { $widget_styles[ $option['key'] ]['css_property'] = $option['css_property']; } if ( isset( $option['dependency'] ) ) { $widget_styles[ $option['key'] ]['dependency'] = $option['dependency']; } if ( isset( $option['default'] ) ) { $widget_styles[ $option['key'] ]['default'] = $option['default']; } if ( 'range' === $option['type'] ) { $widget_styles[ $option['key'] ]['min'] = $option['min']; $widget_styles[ $option['key'] ]['max'] = $option['max']; $widget_styles[ $option['key'] ]['step'] = $option['step']; $widget_styles[ $option['key'] ]['value'] = $option['value']; } if ( 'select' === $option['type'] || 'radio_button_set' === $option['type'] ) { $widget_styles[ $option['key'] ]['value'] = $option['choices']; } }; $all_elements['fusion_widget']['params'] = array_merge( $all_elements['fusion_widget']['params'], $widget_styles ); return $all_elements; } /** * Adds the script for Events-Calendar widgets. * * @access public * @since 2.2.0 * @param string $classname The widget's class-name. * @return string */ public function events_pro_scripts( $classname ) { $url = ''; switch ( $classname ) { case 'Tribe__Events__Pro__Countdown_Widget': $url = tribe_events_pro_resource_url( 'widget-countdown.js' ); break; case 'Tribe__Events__Pro__Mini_Calendar_Widget': $url = tribe_events_pro_resource_url( 'widget-calendar.js' ); break; case 'Tribe__Events__Pro__This_Week_Widget': $url = tribe_events_pro_resource_url( 'widget-this-week.js' ); break; default: break; } return $url ? '' : ''; // phpcs:ignore WordPress.WP.EnqueuedResources } /** * Fetch markup for specific widget instance. * * @access public * @since 2.2.0 * @return void */ public function get_widget_markup() { check_ajax_referer( 'fusion_load_nonce', 'fusion_load_nonce' ); $instance = []; $args = []; $widget = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : ''; $params = isset( $_POST['params'] ) ? stripslashes_deep( wp_unslash( $_POST['params'] ) ) : []; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput $widget_id = isset( $_POST['widget_id'] ) ? sanitize_text_field( wp_unslash( $_POST['widget_id'] ) ) : random_int( 100, 1000 ); $prefix = strtolower( $widget ) . '__'; if ( 'default' === $widget ) { echo wp_json_encode( '' ); wp_die(); } foreach ( $params as $key => $param ) { if ( strpos( $key, $prefix ) === 0 ) { $instance[ substr( $key, strlen( $prefix ) ) ] = $param; } } $args = [ 'before_title' => '

', 'after_title' => '

', 'widget_id' => $this->get_widget_id( $widget_id ), ]; ob_start(); the_widget( $widget, $instance, $args ); $content = ( isset( $content ) ) ? $content : ''; $content .= ob_get_clean(); if ( class_exists( 'Tribe__Events__Pro__Main' ) ) { $content .= $this->events_pro_scripts( $widget ); } echo wp_json_encode( $content ); wp_die(); } /** * Gets the default values. * * @static * @access public * @since 2.2.0 * @return array */ public static function get_element_defaults() { return [ 'hide_on_mobile' => fusion_builder_default_visibility( 'string' ), 'class' => '', 'id' => '', 'type' => '', 'fusion_bg_color' => '', 'fusion_padding_color' => '', 'fusion_border_style' => '', 'fusion_border_color' => '', 'fusion_border_size' => '', 'fusion_bg_radius_size' => '', 'fusion_margin' => '', 'fusion_align' => '', 'fusion_align_mobile' => '', 'fusion_display_title' => '', 'fusion_divider_color' => '', ]; } /** * Get the widget-ID. * * @access public * @since 2.2.0 * @param int $id The widget id/counter as an integer. * @return string Returns wpWidget-{$id}. If $id is null get int from counter. */ public function get_widget_id( $id = null ) { $key = 'wpWidget'; $id = $id ? $id : $this->widget_counter; return $key . '-' . $id; } /** * Get the style tag with additional styles. * * @access public * @since 3.0 * @param array $instance The widget instance. * @return string The style tag with styles. */ public function get_style_tag( $instance ) { $divider_styles = ''; if ( isset( $this->args['fusion_divider_color'] ) && '' !== $this->args['fusion_divider_color'] ) { $fusion_divider_color = Fusion_Sanitize::color( $this->args['fusion_divider_color'] ); $divider_styles = '#wrapper .' . $this->element_id . ' li { border-color:' . $fusion_divider_color . ';}'; if ( 'WP_Widget_Tag_Cloud' === $this->args['type'] ) { $divider_styles .= '#wrapper .' . $this->element_id . ' .tagcloud a { border-color:' . $fusion_divider_color . ';}'; } elseif ( 'Fusion_Widget_Menu' === $this->args['type'] ) { $divider_styles .= '#wrapper .' . $this->element_id . ' .fusion-widget-menu ul li a:after { color:' . $fusion_divider_color . ';}'; } } // Special handling for vertical menu widget, to take into account the deprecated border_color option. if ( 'Fusion_Widget_Vertical_Menu' === $this->args['type'] ) { if ( isset( $instance['border_color'] ) && ! isset( $args['fusion_divider_color'] ) ) { $this->args['fusion_divider_color'] = $instance['border_color']; } if ( '' !== $this->args['fusion_divider_color'] ) { $fusion_divider_color = Fusion_Sanitize::color( $this->args['fusion_divider_color'] ); $divider_styles .= '#wrapper .' . $this->element_id . ' .menu { border-right-color:' . $fusion_divider_color . ' !important; border-top-color:' . $fusion_divider_color . ' !important;}'; $divider_styles .= '#wrapper .' . $this->element_id . ' .menu li a { border-bottom-color:' . $fusion_divider_color . ' !important; }'; $divider_styles .= '#wrapper .' . $this->element_id . ' .right .menu { border-left-color:' . $fusion_divider_color . ' !important; }'; } else { $divider_styles .= '#wrapper .' . $this->element_id . ' > ul.menu { margin-top: -8px; }'; // phpcs:ignore WordPress.Security.EscapeOutput } } if ( ! empty( $divider_styles ) ) { return ''; } return ''; } /** * Render the shortcode * * @access public * @since 2.2.0 * @param array $args Shortcode parameters. * @param string $content Content between shortcode. * @return string HTML output. */ public function render( $args, $content = '' ) { $this->set_element_id( $this->get_widget_id() ); $defaults = FusionBuilder::set_shortcode_defaults( self::get_element_defaults(), $args, 'fusion_widget' ); $defaults['fusion_border_size'] = FusionBuilder::validate_shortcode_attr_value( $defaults['fusion_border_size'], 'px' ); $defaults['fusion_bg_radius_size'] = FusionBuilder::validate_shortcode_attr_value( $defaults['fusion_bg_radius_size'], 'px' ); extract( $defaults ); $this->args = $defaults; $instance = []; if ( ! isset( $this->args['type'] ) || 'default' === $this->args['type'] ) { return; } $prefix = strtolower( $args['type'] ) . '__'; foreach ( $args as $key => $param ) { if ( 0 === strpos( $key, $prefix ) ) { $instance[ substr( $key, strlen( $prefix ) ) ] = $param; } elseif ( 'fusion_display_title' === $key ) { $instance[ $key ] = $param; } } // HTML and Text widget especial unescape. if ( 'WP_Widget_Custom_HTML' === $type && isset( $instance['content'] ) ) { $instance['content'] = html_entity_decode( $instance['content'] ); } elseif ( 'WP_Widget_Text' === $type && isset( $instance['text'] ) ) { $instance['text'] = html_entity_decode( $instance['text'] ); } $args = [ 'before_title' => '

', 'after_title' => '

', 'widget_id' => $this->widget_counter, ]; $html = '
'; if ( ! fusion_is_preview_frame() ) { $html .= $this->get_style_tag( $instance ); } fusion_element_rendering_elements( true ); ob_start(); the_widget( $type, $instance, $args ); $html .= ob_get_clean(); fusion_element_rendering_elements( false ); $html .= '
'; $this->widget_counter++; return apply_filters( 'fusion_element_widget_content', $html, $args ); } /** * Load base CSS. * * @access public * @since 3.0 * @return void */ public function add_css_files() { FusionBuilder()->add_element_css( FUSION_BUILDER_PLUGIN_DIR . 'assets/css/shortcodes/widget.min.css' ); } } } new FusionSC_Widget(); } /** * Map shortcode to Avada Builder * * @since 2.2.0 */ function fusion_element_widget() { $widgets = is_fusion_editor() ? fusion_get_available_widgets() : []; fusion_builder_map( fusion_builder_frontend_data( 'FusionSC_Widget', [ 'name' => esc_attr__( 'Widget', 'fusion-builder' ), 'shortcode' => 'fusion_widget', 'icon' => 'fusion-module-icon fusiona-widget', 'custom_settings_view_name' => 'ModuleSettingsWidget', 'custom_settings_view_js' => FUSION_BUILDER_PLUGIN_URL . 'inc/templates/custom/js/fusion-widget-settings.js', 'custom_settings_template_file' => FUSION_BUILDER_PLUGIN_DIR . 'inc/templates/custom/front-end/fusion-widget-settings.php', 'front_end_custom_settings_view_js' => FUSION_BUILDER_PLUGIN_URL . 'inc/templates/custom/front-end/js/fusion-widget-settings.js', 'admin_enqueue_js' => FUSION_BUILDER_PLUGIN_URL . 'shortcodes/js/fusion-widget.js', 'on_save' => 'widgetShortcodeFilter', 'help_url' => 'https://theme-fusion.com/documentation/fusion-builder/elements/widget/', 'preview' => FUSION_BUILDER_PLUGIN_DIR . 'inc/templates/previews/fusion-widget-preview.php', 'preview_id' => 'fusion-builder-block-module-widget-preview-template', 'params' => [ [ 'type' => 'select', 'heading' => esc_attr__( 'Widget', 'fusion-builder' ), 'description' => esc_attr__( 'Choose widget type.', 'fusion-builder' ), 'param_name' => 'type', 'value' => $widgets, 'default' => 'default', 'callback' => [ 'function' => 'fusion_widget_changed', ], ], [ 'type' => 'checkbox_button_set', 'heading' => esc_attr__( 'Element Visibility', 'fusion-builder' ), 'param_name' => 'hide_on_mobile', 'value' => fusion_builder_visibility_options( 'full' ), 'default' => fusion_builder_default_visibility( 'array' ), 'description' => esc_attr__( 'Choose to show or hide the element on small, medium or large screens. You can choose more than one at a time.', 'fusion-builder' ), ], [ 'type' => 'textfield', 'heading' => esc_attr__( 'CSS Class', 'fusion-builder' ), 'param_name' => 'class', 'value' => '', 'description' => esc_attr__( 'Add a class to the wrapping HTML element.', 'fusion-builder' ), ], [ 'type' => 'textfield', 'heading' => esc_attr__( 'CSS ID', 'fusion-builder' ), 'param_name' => 'id', 'value' => '', 'description' => esc_attr__( 'Add an ID to the wrapping HTML element.', 'fusion-builder' ), ], ], ] ) ); } add_action( 'wp_loaded', 'fusion_element_widget' );