Advertisement
Guest User

class-framework-widgets.php

a guest
Oct 29th, 2015
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 7.45 KB | None | 0 0
  1.  /**
  2.   * AVIA COMBO WIDGET
  3.   *
  4.   * Widget that retrieves, stores and displays the number of twitter and rss followers
  5.   *
  6.   * @package AviaFramework
  7.   * @todo replace the widget system with a dynamic one, based on config files for easier widget creation
  8.   */
  9.  
  10.  if (!class_exists('avia_fb_likebox'))
  11.  {
  12.          class avia_fb_likebox extends WP_Widget {
  13.  
  14.                  function __construct() {
  15.                          //Constructor
  16.                          $widget_ops = array('classname' => 'avia_fb_likebox', 'description' => 'A widget that displays a facebook Likebox to a facebook page of your choice' );
  17.                          parent::__construct( 'avia_fb_likebox', THEMENAME.' Facebook Likebox', $widget_ops );
  18.                  }
  19.  
  20.                  function widget($args, $instance)
  21.                  {
  22.                          // prints the widget
  23.  
  24.                          $this->fbsdk();
  25.  
  26.                          extract($args, EXTR_SKIP);
  27.                          if(empty($instance['url'])) return;
  28.                          $url            = $instance['url'];
  29.                          $height         = $instance['height'];
  30.                          $border         = $instance['border'];
  31.                          $profiles       = 3000; // since the height determines the number of images loaded
  32.                          $faces          = "true";
  33.                          $extraClass = "";
  34.                          $style          = "";
  35.  
  36.                          if(strpos($height, "%") === false && strpos($height, "px") === false) $height = $height."px";
  37.  
  38.                          if(strpos($height, "%") !== false)
  39.                          {
  40.                                  $extraClass = "av_facebook_widget_wrap_positioner";
  41.                          }
  42.  
  43.  
  44.                          echo $before_widget;
  45.                          echo "<div class='av_facebook_widget_wrap {$extraClass} av_facebook_widget_wrap_border_{$border}'>";
  46.                          echo '<div class="fb-page" data-href="'.$url.'" data-width="100%" data-height="'.$instance['height'].'" data-small-header="false" data-adapt-container-width="true" data-hide-cover="false" data-show-facepile="'.$instance['fb-images'].'" data-show-posts="'.$instance['fb-posts'].'"><div class="fb-xfbml-parse-ignore"></div></div>';
  47.                          echo "</div>";
  48.                          echo $after_widget;
  49.                  }
  50.  
  51.  
  52.                  function update($new_instance, $old_instance)
  53.                  {
  54.                          $instance = $old_instance;
  55.                          foreach($new_instance as $key=>$value)
  56.                          {
  57.                                  $instance[$key] = strip_tags($new_instance[$key]);
  58.                          }
  59.  
  60.                          return $instance;
  61.                  }
  62.  
  63.                  function form($instance) {
  64.                          //widgetform in backend
  65.  
  66.                          $instance = wp_parse_args( (array) $instance, array('url' => 'https://www.facebook.com/kriesi.at', 'height' => '258px', 'border' => 'yes', 'fb-posts' => 'yes', 'fb-image' => 'yes') );
  67.                          $html = new avia_htmlhelper();
  68.                          $elementCat = array("name"      => "",
  69.                                                                  "desc"  => "",
  70.                                                      "id"        => $this->get_field_name('border'),
  71.                                                      "type"      => "select",
  72.                                                      "std"   => strip_tags($instance['border']),
  73.                                                      "class" => "",
  74.                                                      "no_first" => true,
  75.                                                      "subtype" => array('Yes, display border'=>'yes', 'No, do not display border'=>'no'));
  76.  
  77.                          $fbpost = array("name"      => "",
  78.                                                                  "desc"  => "",
  79.                                                      "id"        => $this->get_field_name('fb-posts'),
  80.                                                      "type"      => "select",
  81.                                                      "std"   => strip_tags($instance['fb-posts']),
  82.                                                      "class" => "",
  83.                                                      "no_first" => true,
  84.                                                      "subtype" => array('Yes, display the posts'=>'yes', 'No, do not display the posts'=>'no'));
  85.  
  86.                          $fbimage = array("name"      => "",
  87.                                                                  "desc"  => "",
  88.                                                      "id"        => $this->get_field_name('fb-image'),
  89.                                                      "type"      => "select",
  90.                                                      "std"   => strip_tags($instance['fb-image']),
  91.                                                      "class" => "",
  92.                                                      "no_first" => true,
  93.                                                      "subtype" => array('Yes, display images'=>'true', 'No, do not display images'=>'false'));
  94.  
  95.          ?>
  96.                          <p>
  97.                          <label for="<?php echo $this->get_field_id('url'); ?>">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!
  98.                          <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>
  99.                          </p>
  100.  
  101.  
  102.                          <p>
  103.                          <label for="<?php echo $this->get_field_id('height'); ?>">Enter the widget height in pixel or % <br/><small>(100% would create a widget of equal height and width)</small>
  104.                          <input class="widefat" id="<?php echo $this->get_field_id('height'); ?>" name="<?php echo $this->get_field_name('height'); ?>" type="text" value="<?php echo esc_attr($instance['height']); ?>" /></label>
  105.                          </p>
  106.  
  107.  
  108.                          <p><label for="<?php echo $this->get_field_id('border'); ?>">Display Border around the widget?
  109.                          <?php echo $html->select($elementCat); ?>
  110.                          </label></p>
  111.  
  112.              <p><label for="<?php echo $this->get_field_id('fb-posts'); ?>">Display Posts?
  113.                          <?php echo $html->select($fbpost); ?>
  114.                          </label></p>
  115.  
  116.              <p><label for="<?php echo $this->get_field_id('fb-images'); ?>">Display Facebook Images?
  117.                          <?php echo $html->select($fbimage); ?>
  118.                          </label></p>
  119.  
  120.  
  121.                  <?php
  122.                  }
  123.  
  124.                  function fbsdk() { ?>
  125.                  <div id="fb-root"></div>
  126.                          <script>(function(d, s, id) {
  127.  var js, fjs = d.getElementsByTagName(s)[0];
  128.  if (d.getElementById(id)) return;
  129.  js = d.createElement(s); js.id = id;
  130.  js.src = "//connect.facebook.net/en_US/sdk.js#xfbml=1&version=v2.5";
  131.  fjs.parentNode.insertBefore(js, fjs);
  132.  }(document, 'script', 'facebook-jssdk'));</script>
  133.  
  134.                          <?php
  135.  
  136.                          add_action('wp_footer', 'sdk', 50);
  137.                  }
  138.          }
  139.  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement