function hocwp_twitter_follow_button($args = array()) { $username = hocwp_get_value_by_key($args, 'username'); if (empty($username)) { $username = hocwp_get_value_by_key($args, 'account'); } $permalink = hocwp_get_value_by_key($args, 'permalink'); if (empty($permalink)) { $permalink = $username; } if (!empty($permalink) && !hocwp_is_url($permalink)) { $permalink = 'https://twitter.com/' . $permalink; } if (empty($permalink)) { $permalink = hocwp_get_option_by_name('hocwp_option_social', 'twitter_site'); } if (empty($permalink)) { return; } $show_screen_name = hocwp_get_value_by_key($args, 'show_screen_name'); $show_count = hocwp_get_value_by_key($args, 'show_count'); $show_count = hocwp_bool_to_string($show_count); if (empty($username)) { $username = hocwp_get_last_part_in_url($permalink); } if (!empty($username)) { $first_char = hocwp_get_first_char($username); if ('@' != $first_char) { $username = '******' . $username; } } $text = __('Follow', 'hocwp-theme'); if ($show_screen_name) { $username = $text . ' ' . $username; } else { $username = $text; } $username = trim($username); $size = hocwp_get_value_by_key($args, 'size'); $show_screen_name = hocwp_bool_to_string($show_screen_name); ?> <a data-show-screen-name="<?php echo $show_screen_name; ?> " data-size="<?php echo $size; ?> " href="<?php echo esc_url($permalink); ?> " class="twitter-follow-button" data-show-count="<?php echo $show_count; ?> "><?php echo $username; ?> </a> <script type="text/javascript"> window.twttr = (function (d, s, id) { var js, fjs = d.getElementsByTagName(s)[0], t = window.twttr || {}; if (d.getElementById(id)) return t; js = d.createElement(s); js.id = id; js.src = "https://platform.twitter.com/widgets.js"; fjs.parentNode.insertBefore(js, fjs); t._e = []; t.ready = function (f) { t._e.push(f); }; return t; }(document, "script", "twitter-wjs")); </script> <?php }
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_page_plugin($args = array()) { $href = hocwp_get_value_by_key($args, 'href', hocwp_get_value_by_key($args, 'url')); if (empty($href)) { $page_id = isset($args['page_id']) ? $args['page_id'] : 'hocwpnet'; if (!empty($page_id)) { $href = 'https://www.facebook.com/' . $page_id; } } if (!hocwp_is_url($href)) { $href = 'https://www.facebook.com/' . $href; } if (empty($href)) { return; } $page_name = isset($args['page_name']) ? $args['page_name'] : ''; $width = isset($args['width']) ? $args['width'] : 340; $height = isset($args['height']) ? $args['height'] : 500; $hide_cover = (bool) (isset($args['hide_cover']) ? $args['hide_cover'] : false); $hide_cover = hocwp_bool_to_string($hide_cover); $show_facepile = (bool) (isset($args['show_facepile']) ? $args['show_facepile'] : true); $show_facepile = hocwp_bool_to_string($show_facepile); $show_posts = (bool) (isset($args['show_posts']) ? $args['show_posts'] : false); $tabs = hocwp_get_value_by_key($args, 'tabs'); if (!is_array($tabs)) { $tabs = explode(',', $tabs); } $tabs = array_map('trim', $tabs); if ($show_posts && !hocwp_in_array('timeline', $tabs)) { $tabs[] = 'timeline'; } $show_posts = hocwp_bool_to_string($show_posts); $hide_cta = (bool) (isset($args['hide_cta']) ? $args['hide_cta'] : false); $hide_cta = hocwp_bool_to_string($hide_cta); $small_header = (bool) (isset($args['small_header']) ? $args['small_header'] : false); $small_header = hocwp_bool_to_string($small_header); $adapt_container_width = (bool) (isset($args['adapt_container_width']) ? $args['adapt_container_width'] : true); $adapt_container_width = hocwp_bool_to_string($adapt_container_width); ?> <div class="fb-page" data-href="<?php echo $href; ?> " data-width="<?php echo $width; ?> " data-height="<?php echo $height; ?> " data-hide-cta="<?php echo $hide_cta; ?> " data-small-header="<?php echo $small_header; ?> " data-adapt-container-width="<?php echo $adapt_container_width; ?> " data-hide-cover="<?php echo $hide_cover; ?> " data-show-facepile="<?php echo $show_facepile; ?> " data-show-posts="<?php echo $show_posts; ?> " data-tabs="<?php echo implode(',', $tabs); ?> "> <div class="fb-xfbml-parse-ignore"> <?php if (!empty($page_name)) { ?> <blockquote cite="<?php echo $href; ?> "> <a href="<?php echo $href; ?> "><?php echo $page_name; ?> </a> </blockquote> <?php } ?> </div> </div> <?php }