public function widget($args, $instance)
 {
     $this->instance = $instance;
     $page_name = isset($instance['page_name']) ? $instance['page_name'] : '';
     $href = isset($instance['href']) ? $instance['href'] : '';
     $tabs = hocwp_get_value_by_key($instance, 'tabs', $this->args['tabs']);
     if (!is_array($tabs)) {
         $tabs = explode(',', $tabs);
     }
     $tabs = array_map('trim', $tabs);
     $width = isset($instance['width']) ? $instance['width'] : $this->args['width'];
     $height = isset($instance['height']) ? $instance['height'] : $this->args['height'];
     $hide_cover = (bool) (isset($instance['hide_cover']) ? $instance['hide_cover'] : $this->args['hide_cover']);
     $show_facepile = (bool) (isset($instance['show_facepile']) ? $instance['show_facepile'] : $this->args['show_facepile']);
     $show_posts = (bool) (isset($instance['show_posts']) ? $instance['show_posts'] : $this->args['show_posts']);
     $hide_cta = (bool) (isset($instance['hide_cta']) ? $instance['hide_cta'] : $this->args['hide_cta']);
     $small_header = (bool) (isset($instance['small_header']) ? $instance['small_header'] : $this->args['small_header']);
     $adapt_container_width = (bool) (isset($instance['adapt_container_width']) ? $instance['adapt_container_width'] : $this->args['adapt_container_width']);
     if (!empty($href)) {
         add_filter('hocwp_use_facebook_javascript_sdk', '__return_true');
     }
     hocwp_widget_before($args, $instance);
     $fanpage_args = array('page_name' => $page_name, 'href' => $href, 'width' => $width, 'height' => $height, 'tabs' => $tabs, 'hide_cover' => $hide_cover, 'show_facepile' => $show_facepile, 'show_posts' => $show_posts, 'hide_cta' => $hide_cta, 'small_header' => $small_header, 'adapt_container_width' => $adapt_container_width);
     ob_start();
     hocwp_facebook_page_plugin($fanpage_args);
     $widget_html = ob_get_clean();
     $widget_html = apply_filters('hocwp_widget_facebook_box_html', $widget_html, $args, $instance, $this);
     echo $widget_html;
     hocwp_widget_after($args, $instance);
 }
    public function widget($args, $instance)
    {
        $this->instance = $instance;
        $page_name = isset($instance['page_name']) ? $instance['page_name'] : '';
        $href = isset($instance['href']) ? $instance['href'] : '';
        $width = isset($instance['width']) ? $instance['width'] : $this->args['width'];
        $height = isset($instance['height']) ? $instance['height'] : $this->args['height'];
        $hide_cover = (bool) (isset($instance['hide_cover']) ? $instance['hide_cover'] : $this->args['hide_cover']);
        $show_facepile = (bool) (isset($instance['show_facepile']) ? $instance['show_facepile'] : $this->args['show_facepile']);
        $hide_cta = (bool) (isset($instance['hide_cta']) ? $instance['hide_cta'] : $this->args['hide_cta']);
        $small_header = (bool) (isset($instance['small_header']) ? $instance['small_header'] : $this->args['small_header']);
        $adapt_container_width = (bool) (isset($instance['adapt_container_width']) ? $instance['adapt_container_width'] : $this->args['adapt_container_width']);
        $fixed = hocwp_get_value_by_key($instance, 'fixed', $this->args['fixed']);
        $only_link = hocwp_get_value_by_key($instance, 'only_link', $this->args['only_link']);
        $button_text = hocwp_get_value_by_key($instance, 'button_text', $this->args['button_text']);
        $before_widget = hocwp_get_value_by_key($args, 'before_widget');
        $widget_class = '';
        if ($fixed) {
            hocwp_add_string_with_space_before($widget_class, 'fixed');
            $position = hocwp_get_value_by_key($instance, 'position', $this->args['position']);
            hocwp_add_string_with_space_before($widget_class, hocwp_sanitize_html_class($position));
        }
        $before_widget = hocwp_add_class_to_string('', $before_widget, $widget_class);
        $args['before_widget'] = $before_widget;
        $img = new HOCWP_HTML('img');
        $img->set_image_src(hocwp_get_image_url('icon-facebook-messenger-white-64.png'));
        $img->set_class('icon-messenger');
        hocwp_widget_before($args, $instance);
        if ($only_link) {
            if (!hocwp_is_url($href)) {
                $href = 'https://m.me/' . $href;
            }
            $span = new HOCWP_HTML('span');
            $span->set_text($button_text);
            $link_text = $img->build();
            $link_text .= $span->build();
            $a = new HOCWP_HTML('a');
            $a->add_class('button btn btn-facebook-messenger');
            $a->set_text($link_text);
            $a->set_href($href);
            $widget_html = $a->build();
        } else {
            $app_id = hocwp_get_wpseo_social_facebook_app_id();
            if (empty($app_id)) {
                hocwp_debug_log(__('Please set your Facebook APP ID first.', 'hocwp-theme'));
                return;
            }
            add_filter('hocwp_use_facebook_javascript_sdk', '__return_true');
            ?>
			<script type="text/javascript">
				window.fbAsyncInit = function () {
					FB.init({
						appId: '<?php 
            echo $app_id;
            ?>
',
						cookie: true,
						xfbml: true,
						version: 'v<?php 
            echo HOCWP_FACEBOOK_JAVASCRIPT_SDK_VERSION;
            ?>
'
					});
				};
			</script>
			<?php 
            $fanpage_args = array('page_name' => $page_name, 'href' => $href, 'width' => $width, 'height' => $height, 'tabs' => 'messages', 'hide_cover' => $hide_cover, 'show_facepile' => $show_facepile, 'hide_cta' => $hide_cta, 'small_header' => $small_header, 'adapt_container_width' => $adapt_container_width);
            ob_start();
            if ($fixed) {
                $fanpage_args['width'] = 300;
                ?>
				<div class="messenger-box module">
					<div class="module-header heading btn-facebook-messenger" title="<?php 
                echo $button_text;
                ?>
">
						<?php 
                $img->output();
                ?>
						<label><?php 
                echo $button_text;
                ?>
</label>
						<?php 
                if ('left' == $position || 'right' == $position) {
                    echo '<i class="fa fa-times" aria-hidden="true"></i>';
                    $span = new HOCWP_HTML('span');
                    $span->add_class('facebook-messenger-box-control');
                    $span->set_text($img);
                    $span->output();
                } else {
                    echo '<i class="fa fa-angle-up" aria-hidden="true"></i>';
                }
                ?>
					</div>
					<div class="module-body">
						<?php 
                hocwp_facebook_page_plugin($fanpage_args);
                ?>
					</div>
				</div>
				<?php 
            } else {
                hocwp_facebook_page_plugin($fanpage_args);
            }
            $widget_html = ob_get_clean();
        }
        $widget_html = apply_filters('hocwp_widget_facebook_messenger_html', $widget_html, $args, $instance, $this);
        echo $widget_html;
        hocwp_widget_after($args, $instance);
    }