Advertisement
cipher87

Change Width of FB Widget

Feb 9th, 2018
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.55 KB | None | 0 0
  1. class avia_fb_likebox extends WP_Widget {
  2.  
  3.     static $script_loaded = 0;
  4.  
  5.     function __construct() {
  6.         //Constructor
  7.         $widget_ops = array('classname' => 'avia_fb_likebox', 'description' => __('A widget that displays a facebook Likebox to a facebook page of your choice', 'avia_framework') );
  8.         parent::__construct( 'avia_fb_likebox', THEMENAME.' Facebook Likebox', $widget_ops );
  9.     }
  10.  
  11.     function widget($args, $instance)
  12.     {
  13.         // prints the widget
  14.  
  15.         extract($args, EXTR_SKIP);
  16.         if(empty($instance['url'])) return;
  17.         $url        = $instance['url'];
  18.         $title = empty($instance['title']) ? '' : apply_filters('widget_title', $instance['title']);
  19.         $height     = 151;
  20.         $faces      = "true";
  21.         $extraClass = "";
  22.         $style      = "";
  23.        
  24.        
  25.         if(strpos($height, "%") !== false)
  26.         {
  27.             $extraClass = "av_facebook_widget_wrap_positioner";
  28.             $style      = "style='padding-bottom:{$height}'";
  29.             $height     = "100%";
  30.         }
  31.        
  32.        
  33.         echo $before_widget;
  34.        
  35.         if ( !empty( $title ) ) { echo $before_title . $title . $after_title; };
  36.        
  37.         echo "<div class='av_facebook_widget_wrap {$extraClass}' {$style}>";
  38.         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>';
  39.         echo "</div>";
  40.         echo $after_widget;
  41.         add_action('wp_footer', array( $this,'fb_js' ));
  42.     }
  43.    
  44.    
  45.    
  46.     function fb_js()
  47.     {
  48.         if ( function_exists('icl_object_id') ) {
  49.             $locale = ICL_LANGUAGE_NAME_EN;
  50.             $fbxml = @simplexml_load_file( AVIA_BASE . '/config-wpml/FacebookLocales.xml' );
  51.            
  52.             if(is_object($fbxml))
  53.             {
  54.                 $langcode = array();
  55.                 foreach($fbxml as $loc) {
  56.                     if($loc->englishName == $locale) {
  57.                         $langcode = $loc->codes->code->standard->representation;
  58.                     }
  59.                 }
  60.             }
  61.         }
  62.  
  63.         $langcode = function_exists('icl_object_id') && !empty($langcode) ? $langcode : get_locale();
  64.  
  65.         if(self::$script_loaded == 1) return;
  66.         self::$script_loaded = 1;
  67.  
  68.         echo '
  69. <script>(function(d, s, id) {
  70. var js, fjs = d.getElementsByTagName(s)[0];
  71. if (d.getElementById(id)) return;
  72. js = d.createElement(s); js.id = id;
  73. js.src = "//connect.facebook.net/'. $langcode .'/sdk.js#xfbml=1&version=v2.7";
  74. fjs.parentNode.insertBefore(js, fjs);
  75. }(document, "script", "facebook-jssdk"));</script>';
  76.  
  77.     }
  78.  
  79.  
  80.     function update($new_instance, $old_instance)
  81.     {
  82.         $instance = $old_instance;
  83.         foreach($new_instance as $key=>$value)
  84.         {
  85.             $instance[$key] = strip_tags($new_instance[$key]);
  86.         }
  87.  
  88.         return $instance;
  89.     }
  90.  
  91.     function form($instance) {
  92.         //widgetform in backend
  93.  
  94.         $instance = wp_parse_args( (array) $instance, array('url' => 'https://www.facebook.com/kriesi.at', 'title' => '') );
  95.         $html = new avia_htmlhelper();
  96.        
  97.        
  98. ?>
  99.        
  100.         <p>
  101.         <label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:', 'avia_framework'); ?>
  102.         <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>
  103.         </p>
  104.        
  105.         <p>
  106.         <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'); ?>
  107.         <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>
  108.         </p>
  109.        
  110.        
  111.  
  112.  
  113.     <?php
  114.     }
  115. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement