PageRenderTime 48ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://gitlab.com/woxiprogrammers/infinia-wordpress
PHP | 240 lines | 192 code | 47 blank | 1 comment | 30 complexity | ffe422d41766c183e41528b35eae5900 MD5 | raw file
  1. <?php
  2. class Fusion_Widget_Tabs extends WP_Widget {
  3. function __construct() {
  4. $widget_ops = array( 'classname' => 'fusion-tabs-widget pyre_tabs', 'description' => 'Popular posts, recent post and comments.' );
  5. $control_ops = array( 'id_base' => 'pyre_tabs-widget' );
  6. parent::__construct( 'pyre_tabs-widget', 'Avada: Tabs', $widget_ops, $control_ops );
  7. }
  8. function widget( $args, $instance ) {
  9. global $post;
  10. extract( $args );
  11. $posts = isset( $instance['posts'] ) ? $instance['posts'] : 3;
  12. $comments = isset( $instance['comments'] ) ? $instance['comments'] : '3';
  13. $tags_count = isset( $instance['tags'] ) ? $instance['tags'] : 3;
  14. $show_popular_posts = isset( $instance['show_popular_posts'] ) ? 'true' : 'false';
  15. $show_recent_posts = isset( $instance['show_recent_posts'] ) ? 'true' : 'false';
  16. $show_comments = isset( $instance['show_comments'] ) ? 'true' : 'false';
  17. $show_tags = isset( $instance['show_tags'] ) ? 'true' : 'false';
  18. if ( isset( $instance['orderby'] ) ) {
  19. $orderby = $instance['orderby'];
  20. } else {
  21. $orderby = 'Highest Comments';
  22. }
  23. echo $before_widget;
  24. ?>
  25. <div class="tab-holder tabs-widget">
  26. <div class="tab-hold tabs-wrapper">
  27. <ul id="tabs" class="tabset tabs">
  28. <?php if ( 'true' == $show_popular_posts ) : ?>
  29. <li><a href="#tab-popular"><?php echo __( 'Popular', 'Avada' ); ?></a></li>
  30. <?php endif; ?>
  31. <?php if ( 'true' == $show_recent_posts ) : ?>
  32. <li><a href="#tab-recent"><?php echo __( 'Recent', 'Avada' ); ?></a></li>
  33. <?php endif; ?>
  34. <?php if ( 'true' == $show_comments ) : ?>
  35. <li><a href="#tab-comments"><span class="fusion-icon-bubbles"></span></a></li>
  36. <?php endif; ?>
  37. </ul>
  38. <div class="tab-box tabs-container">
  39. <?php if ( 'true' == $show_popular_posts ) : ?>
  40. <div id="tab-popular" class="tab tab_content" style="display: none;">
  41. <?php
  42. if ( 'Highest Comments' == $orderby ) {
  43. $order_string = '&orderby=comment_count';
  44. } else {
  45. $order_string = '&meta_key=avada_post_views_count&orderby=meta_value_num';
  46. }
  47. $popular_posts = new WP_Query( 'showposts=' . $posts . $order_string . '&order=DESC&ignore_sticky_posts=1' );
  48. ?>
  49. <ul class="news-list">
  50. <?php if ( $popular_posts->have_posts() ) : ?>
  51. <?php while ( $popular_posts->have_posts() ) : $popular_posts->the_post(); ?>
  52. <li>
  53. <?php if ( has_post_thumbnail() ) : ?>
  54. <div class="image">
  55. <a href="<?php the_permalink(); ?>"><?php the_post_thumbnail( 'tabs-img' ); ?></a>
  56. </div>
  57. <?php endif; ?>
  58. <div class="post-holder">
  59. <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
  60. <div class="fusion-meta">
  61. <?php the_time( Avada()->settings->get( 'date_format' ) ); ?>
  62. </div>
  63. </div>
  64. </li>
  65. <?php endwhile; ?>
  66. <?php wp_reset_postdata(); ?>
  67. <?php else : ?>
  68. <li><?php _e( 'No posts have been published yet.', 'Avada' ); ?></li>
  69. <?php endif; ?>
  70. </ul>
  71. </div>
  72. <?php endif; ?>
  73. <?php if ( 'true' == $show_recent_posts ) : ?>
  74. <div id="tab-recent" class="tab tab_content" style="display: none;">
  75. <?php $recent_posts = new WP_Query( 'showposts=' . $tags_count . '&ignore_sticky_posts=1' ); ?>
  76. <ul class="news-list">
  77. <?php if ( $recent_posts->have_posts() ) : ?>
  78. <?php while ( $recent_posts->have_posts() ) : $recent_posts->the_post(); ?>
  79. <li>
  80. <?php if ( has_post_thumbnail() ) : ?>
  81. <div class="image">
  82. <a href="<?php the_permalink(); ?>"><?php the_post_thumbnail( 'tabs-img' ); ?></a>
  83. </div>
  84. <?php endif; ?>
  85. <div class="post-holder">
  86. <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
  87. <div class="fusion-meta">
  88. <?php the_time( Avada()->settings->get( 'date_format' ) ); ?>
  89. </div>
  90. </div>
  91. </li>
  92. <?php endwhile; ?>
  93. <?php wp_reset_postdata(); ?>
  94. <?php else: ?>
  95. <li><?php _e( 'No posts have been published yet.', 'Avada' ); ?></li>
  96. <?php endif; ?>
  97. </ul>
  98. </div>
  99. <?php endif; ?>
  100. <?php if ( 'true' == $show_comments ) : ?>
  101. <div id="tab-comments" class="tab tab_content" style="display: none;">
  102. <ul class="news-list">
  103. <?php
  104. global $wpdb;
  105. $number = $instance['comments'];
  106. $recent_comments = "SELECT DISTINCT ID, post_title, post_password, comment_ID, comment_post_ID, comment_author, comment_author_email, comment_date_gmt, comment_approved, comment_type, comment_author_url, SUBSTRING(comment_content,1,110) AS com_excerpt FROM $wpdb->comments LEFT OUTER JOIN $wpdb->posts ON ($wpdb->comments.comment_post_ID = $wpdb->posts.ID) WHERE comment_approved = '1' AND comment_type = '' AND post_password = '' ORDER BY comment_date_gmt DESC LIMIT $number";
  107. $the_comments = $wpdb->get_results( $recent_comments );
  108. ?>
  109. <?php if ( $the_comments ) : ?>
  110. <?php foreach ( $the_comments as $comment ) : ?>
  111. <li>
  112. <div class="image">
  113. <a><?php echo get_avatar( $comment, '52' ); ?></a>
  114. </div>
  115. <div class="post-holder">
  116. <p><?php echo strip_tags( $comment->comment_author ); ?> <?php _e( 'says:', 'Avada' ); ?></p>
  117. <div class="fusion-meta">
  118. <a class="comment-text-side" href="<?php echo get_permalink( $comment->ID ); ?>#comment-<?php echo $comment->comment_ID; ?>" title="<?php printf( __( '%1$s on %2$s', 'Avada' ), strip_tags( $comment->comment_author ), $comment->post_title ); ?>"><?php printf( __( '%s...', 'Avada' ), fusion_string_limit_words( strip_tags( $comment->com_excerpt ), 12 ) ); ?></a>
  119. </div>
  120. </div>
  121. </li>
  122. <?php endforeach; ?>
  123. <?php else : ?>
  124. <li><?php _e( 'No comments have been published yet.', 'Avada' ); ?></li>
  125. <?php endif; ?>
  126. </ul>
  127. </div>
  128. <?php endif; ?>
  129. </div>
  130. </div>
  131. </div>
  132. <?php
  133. echo $after_widget;
  134. }
  135. function update( $new_instance, $old_instance ) {
  136. $instance = $old_instance;
  137. $instance['posts'] = $new_instance['posts'];
  138. $instance['comments'] = $new_instance['comments'];
  139. $instance['tags'] = $new_instance['tags'];
  140. $instance['show_popular_posts'] = $new_instance['show_popular_posts'];
  141. $instance['show_recent_posts'] = $new_instance['show_recent_posts'];
  142. $instance['show_comments'] = $new_instance['show_comments'];
  143. $instance['show_tags'] = $new_instance['show_tags'];
  144. $instance['orderby'] = $new_instance['orderby'];
  145. return $instance;
  146. }
  147. function form( $instance ) {
  148. $defaults = array(
  149. 'posts' => 3,
  150. 'comments' => '3',
  151. 'tags' => 3,
  152. 'show_popular_posts' => 'on',
  153. 'show_recent_posts' => 'on',
  154. 'show_comments' => 'on',
  155. 'show_tags' => 'on',
  156. 'orderby' => __( 'Highest Comments', 'Avada' ),
  157. );
  158. $instance = wp_parse_args( (array) $instance, $defaults ); ?>
  159. <p>
  160. <label for="<?php echo $this->get_field_id( 'orderby' ); ?>"><?php _e( 'Popular Posts Order By:', 'Avada' ); ?></label>
  161. <select id="<?php echo $this->get_field_id( 'orderby' ); ?>" name="<?php echo $this->get_field_name( 'orderby' ); ?>" class="widefat" style="width:100%;">
  162. <option <?php if ( __( 'Highest Comments', 'Avada' ) == $instance['orderby'] ) echo 'selected="selected"'; ?>><?php _e( 'Highest Comments', 'Avada' ); ?></option>
  163. <option <?php if ( __( 'Highest Views', 'Avada' ) == $instance['orderby'] ) echo 'selected="selected"'; ?>><?php _e( 'Highest Views', 'Avada' ); ?></option>
  164. </select>
  165. </p>
  166. <p>
  167. <label for="<?php echo $this->get_field_id('posts'); ?>"><?php _e( 'Number of popular posts:', 'Avada' ); ?></label>
  168. <input class="widefat" type="text" style="width: 30px;" id="<?php echo $this->get_field_id( 'posts' ); ?>" name="<?php echo $this->get_field_name( 'posts' ); ?>" value="<?php echo $instance['posts']; ?>" />
  169. </p>
  170. <p>
  171. <label for="<?php echo $this->get_field_id( 'tags' ); ?>"><?php _e( 'Number of recent posts:', 'Avada' ); ?></label>
  172. <input class="widefat" type="text" style="width: 30px;" id="<?php echo $this->get_field_id( 'tags' ); ?>" name="<?php echo $this->get_field_name( 'tags' ); ?>" value="<?php echo $instance['tags']; ?>" />
  173. </p>
  174. <p>
  175. <label for="<?php echo $this->get_field_id( 'comments' ); ?>"><?php _e( 'Number of comments:', 'Avada' ); ?></label>
  176. <input class="widefat" type="text" style="width: 30px;" id="<?php echo $this->get_field_id('comments'); ?>" name="<?php echo $this->get_field_name('comments'); ?>" value="<?php echo $instance['comments']; ?>" />
  177. </p>
  178. <p>
  179. <input class="checkbox" type="checkbox" <?php checked( $instance['show_popular_posts'], 'on' ); ?> id="<?php echo $this->get_field_id( 'show_popular_posts' ); ?>" name="<?php echo $this->get_field_name( 'show_popular_posts' ); ?>" />
  180. <label for="<?php echo $this->get_field_id( 'show_popular_posts' ); ?>"><?php _e( 'Show popular posts', 'Avada' ); ?></label>
  181. </p>
  182. <p>
  183. <input class="checkbox" type="checkbox" <?php checked( $instance['show_recent_posts'], 'on' ); ?> id="<?php echo $this->get_field_id( 'show_recent_posts' ); ?>" name="<?php echo $this->get_field_name( 'show_recent_posts' ); ?>" />
  184. <label for="<?php echo $this->get_field_id( 'show_recent_posts' ); ?>"><?php _e( 'Show recent posts', 'Avada' ); ?></label>
  185. </p>
  186. <p>
  187. <input class="checkbox" type="checkbox" <?php checked( $instance['show_comments'], 'on' ); ?> id="<?php echo $this->get_field_id( 'show_comments' ); ?>" name="<?php echo $this->get_field_name( 'show_comments' ); ?>" />
  188. <label for="<?php echo $this->get_field_id( 'show_comments' ); ?>"><?php _e( 'Show comments', 'Avada' ); ?></label>
  189. </p>
  190. <?php
  191. }
  192. }
  193. // Omit closing PHP tag to avoid "Headers already sent" issues.