/wp-content/themes/Avada/includes/class-fusion-widget-facebook-page.php

https://gitlab.com/woxiprogrammers/infinia-wordpress · PHP · 148 lines · 110 code · 37 blank · 1 comment · 18 complexity · 6c5f7eb017aa17527e50ad098345ac1d MD5 · raw file

  1. <?php
  2. class Fusion_Widget_Facebook_Page extends WP_Widget {
  3. function __construct() {
  4. $widget_ops = array(
  5. 'classname' => 'facebook_like',
  6. 'description' => __( 'Adds support for Facebook Page Plugin.', 'Avada' )
  7. );
  8. $control_ops = array( 'id_base' => 'facebook-like-widget' );
  9. parent::__construct( 'facebook-like-widget', 'Avada: Facebook Page Plugin', $widget_ops, $control_ops );
  10. }
  11. function widget( $args, $instance ) {
  12. extract( $args );
  13. $title = apply_filters( 'widget_title', isset( $instance['title'] ) ? $instance['title'] : '' );
  14. $app_id = isset( $instance['app_id'] ) ? $instance['app_id'] : '';
  15. $language = get_locale();
  16. $page_url = isset( $instance['page_url'] ) ? $instance['page_url'] : '';
  17. $widget_width = isset( $instance['width'] ) ? $instance['width'] : 268;
  18. $show_faces = isset( $instance['show_faces'] ) ? 'true' : 'false';
  19. $show_stream = isset( $instance['show_stream'] ) ? 'true' : 'false';
  20. $show_header = isset( $instance['show_header'] ) ? 'false' : 'true';
  21. $small_header = isset( $instance['small_header'] ) ? 'true' : 'false';
  22. $height = '65';
  23. $height = ( 'true' == $show_faces ) ? '240' : $height;
  24. $height = ( 'true' == $show_stream ) ? '515' : $height;
  25. $height = ( 'true' == $show_stream && 'true' == $show_faces && 'true' == $show_header ) ? '540' : $height;
  26. $height = ( 'true' == $show_stream && 'true' == $show_faces && 'false' == $show_header ) ? '540' : $height;
  27. $height = ( 'true' == $show_header ) ? $height + 30 : $height;
  28. echo $before_widget;
  29. if ( $title ) {
  30. echo $before_title . $title . $after_title;
  31. }
  32. ?>
  33. <?php if ( $page_url ) : ?>
  34. <script>
  35. (function(d, s, id) {
  36. var js, fjs = d.getElementsByTagName(s)[0];
  37. if (d.getElementById(id)) return;
  38. js = d.createElement(s); js.id = id;
  39. js.src = "//connect.facebook.net/<?php echo $language; ?>/sdk.js#xfbml=1&version=v2.3";
  40. fjs.parentNode.insertBefore(js, fjs);
  41. }(document, 'script', 'facebook-jssdk'));
  42. jQuery( window ).resize(function() {
  43. var $container_width = jQuery( '.<?php echo $args['widget_id']; ?>' ).width();
  44. if ( $container_width != jQuery('.<?php echo $args['widget_id']; ?> .fb-page' ).data( 'width' ) ) {
  45. jQuery('.<?php echo $args['widget_id']; ?> .fb-page' ).attr( 'data-width', $container_width );
  46. FB.XFBML.parse();
  47. }
  48. });
  49. </script>
  50. <div class="fb-like-box-container <?php echo $args['widget_id']; ?>" id="fb-root">
  51. <div class="fb-page" data-href="<?php echo $page_url; ?>" data-width="<?php echo $widget_width; ?>" data-adapt-container-width="true" data-small-header="<?php echo $small_header; ?>" data-height="<?php echo $height; ?>" data-hide-cover="<?php echo $show_header; ?>" data-show-facepile="<?php echo $show_faces; ?>" data-show-posts="<?php echo $show_stream; ?>"></div>
  52. </div>
  53. <?php endif;
  54. echo $after_widget;
  55. }
  56. function update( $new_instance, $old_instance ) {
  57. $instance = $old_instance;
  58. $instance['title'] = strip_tags( $new_instance['title'] );
  59. $instance['page_url'] = $new_instance['page_url'];
  60. $instance['width'] = $new_instance['width'];
  61. $instance['show_faces'] = $new_instance['show_faces'];
  62. $instance['show_stream'] = $new_instance['show_stream'];
  63. $instance['show_header'] = $new_instance['show_header'];
  64. $instance['small_header'] = $new_instance['small_header'];
  65. return $instance;
  66. }
  67. function form( $instance ) {
  68. $defaults = array(
  69. 'title' => __( 'Find us on Facebook', 'Avada' ),
  70. 'app_id' => '',
  71. 'page_url' => '',
  72. 'width' => '268',
  73. 'show_faces' => 'on',
  74. 'show_stream' => false,
  75. 'show_header' => false,
  76. 'small_header' => false
  77. );
  78. $instance = wp_parse_args( ( array ) $instance, $defaults ); ?>
  79. <h4 style="line-height: 1.6em;"><?php _e( 'IMPORTANT: Facebook has abandoned color scheme option for the page plugin, thus the option is also no longer available in the widget.', 'Avada' ); ?></a></h4>
  80. <p>
  81. <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:', 'Avada' ); ?></label>
  82. <input class="widefat" type="text" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" value="<?php echo $instance['title']; ?>" />
  83. </p>
  84. <p>
  85. <label for="<?php echo $this->get_field_id( 'page_url' ); ?>"><?php _e( 'Facebook Page URL:', 'Avada' ); ?></label>
  86. <input class="widefat" type="text" id="<?php echo $this->get_field_id( 'page_url' ); ?>" name="<?php echo $this->get_field_name( 'page_url' ); ?>" value="<?php echo $instance['page_url']; ?>" />
  87. </p>
  88. <p>
  89. <label for="<?php echo $this->get_field_id( 'width' ); ?>"><?php _e( 'Width (has to be between 180 and 500):', 'Avada' ); ?></label>
  90. <input class="widefat" type="text" style="width: 80px;" id="<?php echo $this->get_field_id( 'width' ); ?>" name="<?php echo $this->get_field_name( 'width' ); ?>" value="<?php echo $instance['width']; ?>" />
  91. </p>
  92. <p>
  93. <input class="checkbox" type="checkbox" <?php checked( $instance['show_faces'], 'on' ); ?> id="<?php echo $this->get_field_id( 'show_faces' ); ?>" name="<?php echo $this->get_field_name( 'show_faces' ); ?>" />
  94. <label for="<?php echo $this->get_field_id( 'show_faces' ); ?>"><?php _e( 'Show Friends Faces', 'Avada' ); ?></label>
  95. </p>
  96. <p>
  97. <input class="checkbox" type="checkbox" <?php checked( $instance['show_stream'], 'on' ); ?> id="<?php echo $this->get_field_id( 'show_stream' ); ?>" name="<?php echo $this->get_field_name( 'show_stream' ); ?>" />
  98. <label for="<?php echo $this->get_field_id( 'show_stream' ); ?>"><?php _e( 'Show Posts', 'Avada' ); ?></label>
  99. </p>
  100. <p>
  101. <input class="checkbox" type="checkbox" <?php checked( $instance['show_header'], 'on' ); ?> id="<?php echo $this->get_field_id( 'show_header' ); ?>" name="<?php echo $this->get_field_name( 'show_header' ); ?>" />
  102. <label for="<?php echo $this->get_field_id( 'show_header' ); ?>"><?php _e( 'Show Cover Photo', 'Avada' ); ?></label>
  103. </p>
  104. <p>
  105. <input class="checkbox" type="checkbox" <?php checked( $instance['small_header'], 'on' ); ?> id="<?php echo $this->get_field_id( 'small_header' ); ?>" name="<?php echo $this->get_field_name( 'small_header' ); ?>" />
  106. <label for="<?php echo $this->get_field_id( 'small_header' ); ?>"><?php _e( 'Use Small Header', 'Avada' ); ?></label>
  107. </p>
  108. <?php
  109. }
  110. }
  111. // Omit closing PHP tag to avoid "Headers already sent" issues.