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); }
function hocwp_facebook_login_script($args = array()) { $connect = hocwp_get_value_by_key($args, 'connect'); if (is_user_logged_in() && !$connect) { return; } $lang = hocwp_get_language(); $language = hocwp_get_value_by_key($args, 'language'); if (empty($language) && 'vi' === $lang) { $language = 'vi_VN'; } $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; } ?> <script type="text/javascript"> window.hocwp = window.hocwp || {}; function hocwp_facebook_login_status_callback(response) { if (response.status === 'connected') { hocwp_facebook_login_connected_callback(); } else if (response.status === 'not_authorized') { } else { } } function hocwp_facebook_login() { FB.login(function (response) { hocwp_facebook_login_status_callback(response); }, {scope: 'email,public_profile,user_friends'}); } window.fbAsyncInit = function () { FB.init({ appId: '<?php echo $app_id; ?> ', cookie: true, xfbml: true, version: 'v<?php echo HOCWP_FACEBOOK_GRAPH_API_VERSION; ?> ' }); }; if (typeof FB === 'undefined') { (function (d, s, id) { var js, fjs = d.getElementsByTagName(s)[0]; if (d.getElementById(id)) return; js = d.createElement(s); js.id = id; js.src = "//connect.facebook.net/<?php echo $language; ?> /sdk.js"; fjs.parentNode.insertBefore(js, fjs); }(document, 'script', 'facebook-jssdk')); } function hocwp_facebook_login_connected_callback() { FB.api('/me', {fields: 'id,name,first_name,last_name,picture,verified,email'}, function (response) { (function ($) { $.ajax({ type: 'POST', dataType: 'json', url: hocwp.ajax_url, cache: true, data: { action: 'hocwp_social_login_facebook', data: JSON.stringify(response), connect: <?php echo hocwp_bool_to_int($connect); ?> }, success: function (response) { var href = window.location.href; if ($.trim(response.redirect_to)) { href = response.redirect_to; } if (response.logged_in) { window.location.href = href; } } }); })(jQuery); }); } </script> <?php }
function hocwp_facebook_like_and_recommend_button($args = array()) { $url = isset($args['url']) ? $args['url'] : ''; if (empty($url)) { $url = get_permalink(); } $app_id = hocwp_get_wpseo_social_facebook_app_id(); ?> <div class="fb-like-buttons like-recommend like-recommend-buttons"> <div class="item"> <div data-share="false" data-show-faces="false" data-action="like" data-layout="button_count" data-href="<?php echo $url; ?> " class="fb-like fb_iframe_widget" fb-xfbml-state="rendered" fb-iframe-plugin-query="action=like&app_id=<?php echo $app_id; ?> &container_width=0&href=<?php echo $url; ?> &layout=button_count&locale=en_US&sdk=joey&share=false&show_faces=false"></div> </div> <div class="item"> <div data-share="true" data-show-faces="false" data-action="recommend" data-layout="button_count" data-href="<?php echo $url; ?> " class="fb-like fb_iframe_widget" fb-xfbml-state="rendered" fb-iframe-plugin-query="action=recommend&app_id=<?php echo $app_id; ?> &container_width=0&href=<?php echo $url; ?> &layout=button_count&locale=en_US&sdk=joey&share=false&show_faces=false"></div> </div> </div> <?php }
function hocwp_theme_default_script_localize_object() { $defaults = hocwp_default_script_localize_object(); $args = array('home_url' => esc_url(home_url('/')), 'login_logo_url' => hocwp_get_login_logo_url(), 'login_url' => wp_login_url(), 'facebook_appid' => hocwp_get_wpseo_social_facebook_app_id(), 'mobile_menu_icon' => '<button class="menu-toggle mobile-menu-button" aria-expanded="false" aria-controls=""><i class="fa fa fa-bars"></i><span class="text">' . __('Menu', 'hocwp-theme') . '</span></button>', 'search_form' => get_search_form(false)); $args = wp_parse_args($args, $defaults); return apply_filters('hocwp_theme_default_script_object', $args); }