Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class avia_fb_likebox extends WP_Widget {
- static $script_loaded = 0;
- function __construct() {
- //Constructor
- $widget_ops = array('classname' => 'avia_fb_likebox', 'description' => __('A widget that displays a facebook Likebox to a facebook page of your choice', 'avia_framework') );
- parent::__construct( 'avia_fb_likebox', THEMENAME.' Facebook Likebox', $widget_ops );
- }
- function widget($args, $instance)
- {
- // prints the widget
- extract($args, EXTR_SKIP);
- if(empty($instance['url'])) return;
- $url = $instance['url'];
- $title = empty($instance['title']) ? '' : apply_filters('widget_title', $instance['title']);
- $height = 151;
- $faces = "true";
- $extraClass = "";
- $style = "";
- if(strpos($height, "%") !== false)
- {
- $extraClass = "av_facebook_widget_wrap_positioner";
- $style = "style='padding-bottom:{$height}'";
- $height = "100%";
- }
- echo $before_widget;
- if ( !empty( $title ) ) { echo $before_title . $title . $after_title; };
- echo "<div class='av_facebook_widget_wrap {$extraClass}' {$style}>";
- echo '<div class="fb-page" data-width="1210" data-href="'.$url.'" data-small-header="false" data-adapt-container-width="true" data-hide-cover="false" data-show-facepile="true" data-show-posts="false"><div class="fb-xfbml-parse-ignore"></div></div>';
- echo "</div>";
- echo $after_widget;
- add_action('wp_footer', array( $this,'fb_js' ));
- }
- function fb_js()
- {
- if ( function_exists('icl_object_id') ) {
- $locale = ICL_LANGUAGE_NAME_EN;
- $fbxml = @simplexml_load_file( AVIA_BASE . '/config-wpml/FacebookLocales.xml' );
- if(is_object($fbxml))
- {
- $langcode = array();
- foreach($fbxml as $loc) {
- if($loc->englishName == $locale) {
- $langcode = $loc->codes->code->standard->representation;
- }
- }
- }
- }
- $langcode = function_exists('icl_object_id') && !empty($langcode) ? $langcode : get_locale();
- if(self::$script_loaded == 1) return;
- self::$script_loaded = 1;
- echo '
- <script>(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/'. $langcode .'/sdk.js#xfbml=1&version=v2.7";
- fjs.parentNode.insertBefore(js, fjs);
- }(document, "script", "facebook-jssdk"));</script>';
- }
- function update($new_instance, $old_instance)
- {
- $instance = $old_instance;
- foreach($new_instance as $key=>$value)
- {
- $instance[$key] = strip_tags($new_instance[$key]);
- }
- return $instance;
- }
- function form($instance) {
- //widgetform in backend
- $instance = wp_parse_args( (array) $instance, array('url' => 'https://www.facebook.com/kriesi.at', 'title' => '') );
- $html = new avia_htmlhelper();
- ?>
- <p>
- <label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:', 'avia_framework'); ?>
- <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($instance['title']); ?>" /></label>
- </p>
- <p>
- <label for="<?php echo $this->get_field_id('url'); ?>"><?php _e('Enter the url to the Page. Please note that it needs to be a link to a <strong>facebook fanpage</strong>. Personal profiles are not allowed!', 'avia_framework'); ?>
- <input class="widefat" id="<?php echo $this->get_field_id('url'); ?>" name="<?php echo $this->get_field_name('url'); ?>" type="text" value="<?php echo esc_attr($instance['url']); ?>" /></label>
- </p>
- <?php
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement