WP Tab Widget - Version 1.2.3

Version Description

  • Fixed issue where tab content couldn't be loaded on servers with non UTF8 character encoding
  • List only comments from default comment type in Comments tab
  • Prevent conflict with Pro version
  • Added Notification & Banner for Pro Version
Download this release

Release Info

Developer MyThemeShop
Plugin Icon 128x128 WP Tab Widget
Version 1.2.3
Comparing to
See all releases

Code changes from version 1.2.2 to 1.2.3

css/wp-tab-widget.css CHANGED
File without changes
img/largethumb.png CHANGED
File without changes
img/smallthumb.png CHANGED
File without changes
img/wp-tab-widget-pro.jpg ADDED
Binary file
js/wp-tab-widget.js CHANGED
@@ -5,7 +5,7 @@ Description: WP Tab Widget is the AJAXified plugin which loads content by demand
5
  Author: MyThemeShop
6
  Author URI: http://mythemeshop.com/
7
  */
8
- function wpt_loadTabContent(tab_name, page_num, container, args_obj) {
9
 
10
  var container = jQuery(container);
11
  var tab_content = container.find('#'+tab_name+'-tab-content');
@@ -21,6 +21,7 @@ function wpt_loadTabContent(tab_name, page_num, container, args_obj) {
21
  action: 'wpt_widget_content',
22
  tab: tab_name,
23
  page: page_num,
 
24
  args: args_obj
25
  }, function() {
26
  container.removeClass('wpt-loading');
@@ -38,13 +39,14 @@ jQuery(document).ready(function() {
38
  var $this = jQuery(this);
39
  var widget_id = this.id;
40
  var args = $this.data('args');
 
41
 
42
  // load tab content on click
43
  $this.find('.wpt-tabs a').click(function(e) {
44
  e.preventDefault();
45
  jQuery(this).parent().addClass('selected').siblings().removeClass('selected');
46
  var tab_name = this.id.slice(0, -4); // -tab
47
- wpt_loadTabContent(tab_name, 1, $this, args);
48
  });
49
 
50
  // pagination
@@ -55,10 +57,10 @@ jQuery(document).ready(function() {
55
  var page_num = parseInt($this_a.closest('.tab-content').children('.page_num').val());
56
 
57
  if ($this_a.hasClass('next')) {
58
- wpt_loadTabContent(tab_name, page_num + 1, $this, args);
59
  } else {
60
  $this.find('#'+tab_name+'-tab-content').data('loaded', 0);
61
- wpt_loadTabContent(tab_name, page_num - 1, $this, args);
62
  }
63
 
64
  });
5
  Author: MyThemeShop
6
  Author URI: http://mythemeshop.com/
7
  */
8
+ function wpt_loadTabContent(tab_name, page_num, container, args_obj, widget_number) {
9
 
10
  var container = jQuery(container);
11
  var tab_content = container.find('#'+tab_name+'-tab-content');
21
  action: 'wpt_widget_content',
22
  tab: tab_name,
23
  page: page_num,
24
+ widget_number: widget_number,
25
  args: args_obj
26
  }, function() {
27
  container.removeClass('wpt-loading');
39
  var $this = jQuery(this);
40
  var widget_id = this.id;
41
  var args = $this.data('args');
42
+ var widget_number = $this.data('widget-number');
43
 
44
  // load tab content on click
45
  $this.find('.wpt-tabs a').click(function(e) {
46
  e.preventDefault();
47
  jQuery(this).parent().addClass('selected').siblings().removeClass('selected');
48
  var tab_name = this.id.slice(0, -4); // -tab
49
+ wpt_loadTabContent(tab_name, 1, $this, args, widget_number);
50
  });
51
 
52
  // pagination
57
  var page_num = parseInt($this_a.closest('.tab-content').children('.page_num').val());
58
 
59
  if ($this_a.hasClass('next')) {
60
+ wpt_loadTabContent(tab_name, page_num + 1, $this, args, widget_number);
61
  } else {
62
  $this.find('#'+tab_name+'-tab-content').data('loaded', 0);
63
+ wpt_loadTabContent(tab_name, page_num - 1, $this, args, widget_number);
64
  }
65
 
66
  });
js/wpt-admin.js CHANGED
File without changes
languages/default.mo CHANGED
File without changes
languages/default.po CHANGED
File without changes
readme.txt CHANGED
@@ -4,7 +4,7 @@ Creator's website link: http://mythemeshop.com/
4
  Tags: tabs, tab widget, recent posts tab, tabs widget, ajax tabs, ajax widget.
5
  Requires at least: 3.0.1
6
  Tested up to: 4.4
7
- Stable tag: 1.2.2
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -87,6 +87,12 @@ Please disable all plugins and check if shortcode plugin is working properly. Th
87
 
88
  == Changelog ==
89
 
 
 
 
 
 
 
90
  = 1.2.2 =
91
  * Changed text domain to make plugin compatible with WordPress Language Packs
92
 
4
  Tags: tabs, tab widget, recent posts tab, tabs widget, ajax tabs, ajax widget.
5
  Requires at least: 3.0.1
6
  Tested up to: 4.4
7
+ Stable tag: 1.2.3
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
87
 
88
  == Changelog ==
89
 
90
+ = 1.2.3 =
91
+ * Fixed issue where tab content couldn't be loaded on servers with non UTF8 character encoding
92
+ * List only comments from default comment type in Comments tab
93
+ * Prevent conflict with Pro version
94
+ * Added Notification & Banner for Pro Version
95
+
96
  = 1.2.2 =
97
  * Changed text domain to make plugin compatible with WordPress Language Packs
98
 
wp-tab-widget.php CHANGED
@@ -4,558 +4,577 @@ Plugin Name: WP Tab Widget
4
  Plugin URI: http://mythemeshop.com/plugins/wp-tab-widget/
5
  Description: WP Tab Widget is the AJAXified plugin which loads content by demand, and thus it makes the plugin incredibly lightweight.
6
  Author: MyThemeShop
7
- Version: 1.2.2
8
  Author URI: http://mythemeshop.com/
9
  */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
 
11
- class wpt_widget extends WP_Widget {
12
- function __construct() {
13
-
14
- // add image sizes and load language file
15
- add_action( 'init', array(&$this, 'wpt_init') );
16
-
17
- // ajax functions
18
- add_action('wp_ajax_wpt_widget_content', array(&$this, 'ajax_wpt_widget_content'));
19
- add_action('wp_ajax_nopriv_wpt_widget_content', array(&$this, 'ajax_wpt_widget_content'));
20
-
21
- // css
22
- add_action('wp_enqueue_scripts', array(&$this, 'wpt_register_scripts'));
23
- add_action('admin_enqueue_scripts', array(&$this, 'wpt_admin_scripts'));
24
-
25
- $widget_ops = array('classname' => 'widget_wpt', 'description' => __('Display popular posts, recent posts, comments, and tags in tabbed format.', 'wp-tab-widget'));
26
- $control_ops = array('width' => 300, 'height' => 350);
27
- parent::__construct('wpt_widget', __('WP Tab Widget by MyThemeShop', 'wp-tab-widget'), $widget_ops, $control_ops);
28
- }
29
-
30
- function wpt_init() {
31
- load_plugin_textdomain('wp-tab-widget', false, dirname(plugin_basename(__FILE__)) . '/languages/' );
32
-
33
- add_image_size( 'wp_review_small', 65, 65, true ); // small thumb
34
- add_image_size( 'wp_review_large', 320, 240, true ); // large thumb
35
- }
36
- function wpt_admin_scripts($hook) {
37
- if ($hook != 'widgets.php')
38
- return;
39
- wp_register_script('wpt_widget_admin', plugins_url('js/wpt-admin.js', __FILE__), array('jquery'));
40
- wp_enqueue_script('wpt_widget_admin');
41
- }
42
- function wpt_register_scripts() {
43
- // JS
44
- wp_register_script('wpt_widget', plugins_url('js/wp-tab-widget.js', __FILE__), array('jquery'));
45
- wp_localize_script( 'wpt_widget', 'wpt',
46
- array( 'ajax_url' => admin_url( 'admin-ajax.php' ))
47
- );
48
- // CSS
49
- wp_register_style('wpt_widget', plugins_url('css/wp-tab-widget.css', __FILE__), true);
50
- }
51
-
52
- function form( $instance ) {
53
- $instance = wp_parse_args( (array) $instance, array(
54
- 'tabs' => array('recent' => 1, 'popular' => 1, 'comments' => 0, 'tags' => 0),
55
- 'tab_order' => array('popular' => 1, 'recent' => 2, 'comments' => 3, 'tags' => 4),
56
- 'allow_pagination' => 1,
57
- 'post_num' => '5',
58
- 'comment_num' => '5',
59
- 'show_thumb' => 1,
60
- 'thumb_size' => 'small',
61
- 'show_date' => 1,
62
- 'show_excerpt' => 0,
63
- 'excerpt_length' => apply_filters( 'wpt_excerpt_length_default', '15' ),
64
- 'show_comment_num' => 0,
65
- 'show_avatar' => 1,
66
- 'title_length' => apply_filters( 'wpt_title_length_default', '15' )
67
- ) );
68
-
69
- extract($instance);
70
 
71
- ?>
72
- <div class="wpt_options_form">
73
-
74
- <h4><?php _e('Select Tabs', 'wp-tab-widget'); ?></h4>
75
-
76
- <div class="wpt_select_tabs">
77
- <label class="alignleft" style="display: block; width: 50%; margin-bottom: 5px" for="<?php echo $this->get_field_id("tabs"); ?>_popular">
78
- <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id("tabs"); ?>_popular" name="<?php echo $this->get_field_name("tabs"); ?>[popular]" value="1" <?php if (isset($tabs['popular'])) { checked( 1, $tabs['popular'], true ); } ?> />
79
- <?php _e( 'Popular Tab', 'wp-tab-widget'); ?>
80
- </label>
81
- <label class="alignleft" style="display: block; width: 50%; margin-bottom: 5px;" for="<?php echo $this->get_field_id("tabs"); ?>_recent">
82
- <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id("tabs"); ?>_recent" name="<?php echo $this->get_field_name("tabs"); ?>[recent]" value="1" <?php if (isset($tabs['recent'])) { checked( 1, $tabs['recent'], true ); } ?> />
83
- <?php _e( 'Recent Tab', 'wp-tab-widget'); ?>
84
- </label>
85
- <label class="alignleft" style="display: block; width: 50%;" for="<?php echo $this->get_field_id("tabs"); ?>_comments">
86
- <input type="checkbox" class="checkbox wpt_enable_comments" id="<?php echo $this->get_field_id("tabs"); ?>_comments" name="<?php echo $this->get_field_name("tabs"); ?>[comments]" value="1" <?php if (isset($tabs['comments'])) { checked( 1, $tabs['comments'], true ); } ?> />
87
- <?php _e( 'Comments Tab', 'wp-tab-widget'); ?>
88
- </label>
89
- <label class="alignleft" style="display: block; width: 50%;" for="<?php echo $this->get_field_id("tabs"); ?>_tags">
90
- <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id("tabs"); ?>_tags" name="<?php echo $this->get_field_name("tabs"); ?>[tags]" value="1" <?php if (isset($tabs['tags'])) { checked( 1, $tabs['tags'], true ); } ?> />
91
- <?php _e( 'Tags Tab', 'wp-tab-widget'); ?>
92
- </label>
93
- </div>
94
- <div class="clear"></div>
95
-
96
- <h4 class="wpt_tab_order_header"><a href="#"><?php _e('Tab Order', 'wp-tab-widget'); ?></a></h4>
97
-
98
- <div class="wpt_tab_order" style="display: none;">
99
-
100
- <label class="alignleft" for="<?php echo $this->get_field_id('tab_order'); ?>_popular" style="width: 50%;">
101
- <input id="<?php echo $this->get_field_id('tab_order'); ?>_popular" name="<?php echo $this->get_field_name('tab_order'); ?>[popular]" type="number" min="1" step="1" value="<?php echo $tab_order['popular']; ?>" style="width: 48px;" />
102
- <?php _e('Popular', 'wp-tab-widget'); ?>
103
- </label>
104
- <label class="alignleft" for="<?php echo $this->get_field_id('tab_order'); ?>_recent" style="width: 50%;">
105
- <input id="<?php echo $this->get_field_id('tab_order'); ?>_recent" name="<?php echo $this->get_field_name('tab_order'); ?>[recent]" type="number" min="1" step="1" value="<?php echo $tab_order['recent']; ?>" style="width: 48px;" />
106
- <?php _e('Recent', 'wp-tab-widget'); ?>
107
- </label>
108
- <label class="alignleft" for="<?php echo $this->get_field_id('tab_order'); ?>_comments" style="width: 50%;">
109
- <input id="<?php echo $this->get_field_id('tab_order'); ?>_comments" name="<?php echo $this->get_field_name('tab_order'); ?>[comments]" type="number" min="1" step="1" value="<?php echo $tab_order['comments']; ?>" style="width: 48px;" />
110
- <?php _e('Comments', 'wp-tab-widget'); ?>
111
- </label>
112
- <label class="alignleft" for="<?php echo $this->get_field_id('tab_order'); ?>_tags" style="width: 50%;">
113
- <input id="<?php echo $this->get_field_id('tab_order'); ?>_tags" name="<?php echo $this->get_field_name('tab_order'); ?>[tags]" type="number" min="1" step="1" value="<?php echo $tab_order['tags']; ?>" style="width: 48px;" />
114
- <?php _e('Tags', 'wp-tab-widget'); ?>
115
- </label>
116
- </div>
117
- <div class="clear"></div>
118
-
119
- <h4 class="wpt_advanced_options_header"><a href="#"><?php _e('Advanced Options', 'wp-tab-widget'); ?></a></h4>
120
-
121
- <div class="wpt_advanced_options" style="display: none;">
122
- <p>
123
- <label for="<?php echo $this->get_field_id("allow_pagination"); ?>">
124
- <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id("allow_pagination"); ?>" name="<?php echo $this->get_field_name("allow_pagination"); ?>" value="1" <?php if (isset($allow_pagination)) { checked( 1, $allow_pagination, true ); } ?> />
125
- <?php _e( 'Allow pagination', 'wp-tab-widget'); ?>
126
- </label>
127
- </p>
128
-
129
- <div class="wpt_post_options">
130
 
131
- <p>
132
- <label for="<?php echo $this->get_field_id('post_num'); ?>"><?php _e('Number of posts to show:', 'wp-tab-widget'); ?>
133
- <br />
134
- <input id="<?php echo $this->get_field_id('post_num'); ?>" name="<?php echo $this->get_field_name('post_num'); ?>" type="number" min="1" step="1" value="<?php echo $post_num; ?>" />
135
- </label>
136
- </p>
137
 
138
- <p>
139
- <label for="<?php echo $this->get_field_id('title_length'); ?>"><?php _e('Title length (words):', 'wp-tab-widget'); ?>
140
- <br />
141
- <input id="<?php echo $this->get_field_id('title_length'); ?>" name="<?php echo $this->get_field_name('title_length'); ?>" type="number" min="1" step="1" value="<?php echo $title_length; ?>" />
142
- </label>
143
- </p>
144
-
145
- <p>
146
- <label for="<?php echo $this->get_field_id("show_thumb"); ?>">
147
- <input type="checkbox" class="checkbox wpt_show_thumbnails" id="<?php echo $this->get_field_id("show_thumb"); ?>" name="<?php echo $this->get_field_name("show_thumb"); ?>" value="1" <?php if (isset($show_thumb)) { checked( 1, $show_thumb, true ); } ?> />
148
- <?php _e( 'Show post thumbnails', 'wp-tab-widget'); ?>
149
- </label>
150
- </p>
151
-
152
- <p class="wpt_thumbnail_size"<?php echo (empty($show_thumb) ? ' style="display: none;"' : ''); ?>>
153
- <label for="<?php echo $this->get_field_id('thumb_size'); ?>"><?php _e('Thumbnail size:', 'wp-tab-widget'); ?></label>
154
- <select id="<?php echo $this->get_field_id('thumb_size'); ?>" name="<?php echo $this->get_field_name('thumb_size'); ?>" style="margin-left: 12px;">
155
- <option value="small" <?php selected($thumb_size, 'small', true); ?>><?php _e('Small', 'wp-tab-widget'); ?></option>
156
- <option value="large" <?php selected($thumb_size, 'large', true); ?>><?php _e('Large', 'wp-tab-widget'); ?></option>
157
- </select>
158
- </p>
159
-
160
- <p>
161
- <label for="<?php echo $this->get_field_id("show_date"); ?>">
162
- <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id("show_date"); ?>" name="<?php echo $this->get_field_name("show_date"); ?>" value="1" <?php if (isset($show_date)) { checked( 1, $show_date, true ); } ?> />
163
- <?php _e( 'Show post date', 'wp-tab-widget'); ?>
164
- </label>
165
- </p>
166
-
167
- <p>
168
- <label for="<?php echo $this->get_field_id("show_comment_num"); ?>">
169
- <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id("show_comment_num"); ?>" name="<?php echo $this->get_field_name("show_comment_num"); ?>" value="1" <?php if (isset($show_comment_num)) { checked( 1, $show_comment_num, true ); } ?> />
170
- <?php _e( 'Show number of comments', 'wp-tab-widget'); ?>
171
- </label>
172
- </p>
173
-
174
- <p>
175
- <label for="<?php echo $this->get_field_id("show_excerpt"); ?>">
176
- <input type="checkbox" class="checkbox wpt_show_excerpt" id="<?php echo $this->get_field_id("show_excerpt"); ?>" name="<?php echo $this->get_field_name("show_excerpt"); ?>" value="1" <?php if (isset($show_excerpt)) { checked( 1, $show_excerpt, true ); } ?> />
177
- <?php _e( 'Show post excerpt', 'wp-tab-widget'); ?>
178
- </label>
179
- </p>
180
-
181
- <p class="wpt_excerpt_length"<?php echo (empty($show_excerpt) ? ' style="display: none;"' : ''); ?>>
182
- <label for="<?php echo $this->get_field_id('excerpt_length'); ?>">
183
- <?php _e('Excerpt length (words):', 'wp-tab-widget'); ?>
184
- <br />
185
- <input type="number" min="1" step="1" id="<?php echo $this->get_field_id('excerpt_length'); ?>" name="<?php echo $this->get_field_name('excerpt_length'); ?>" value="<?php echo $excerpt_length; ?>" />
186
- </label>
187
- </p>
188
-
189
- </div>
190
- <div class="clear"></div>
191
-
192
- <div class="wpt_comment_options"<?php echo (empty($tabs['comments']) ? ' style="display: none;"' : ''); ?>>
193
-
194
- <p>
195
- <label for="<?php echo $this->get_field_id('comment_num'); ?>">
196
- <?php _e('Number of comments on Comments Tab:', 'wp-tab-widget'); ?>
197
- <br />
198
- <input type="number" min="1" step="1" id="<?php echo $this->get_field_id('comment_num'); ?>" name="<?php echo $this->get_field_name('comment_num'); ?>" value="<?php echo $comment_num; ?>" />
199
- </label>
200
- </p>
 
 
 
 
 
 
 
 
 
 
 
 
 
201
 
202
- <p>
203
- <label for="<?php echo $this->get_field_id("show_avatar"); ?>">
204
- <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id("show_avatar"); ?>" name="<?php echo $this->get_field_name("show_avatar"); ?>" value="1" <?php if (isset($show_avatar)) { checked( 1, $show_avatar, true ); } ?> />
205
- <?php _e( 'Show avatars on Comments Tab', 'wp-tab-widget'); ?>
206
- </label>
207
- </p>
208
- </div><!-- .wpt_comment_options -->
209
- </div><!-- .wpt_advanced_options -->
210
- </div><!-- .wpt_options_form -->
211
- <?php
212
- }
213
-
214
- function update( $new_instance, $old_instance ) {
215
- $instance = $old_instance;
216
- $instance['tabs'] = $new_instance['tabs'];
217
- $instance['tab_order'] = $new_instance['tab_order'];
218
- $instance['allow_pagination'] = $new_instance['allow_pagination'];
219
- $instance['post_num'] = $new_instance['post_num'];
220
- $instance['title_length'] = $new_instance['title_length'];
221
- $instance['comment_num'] = $new_instance['comment_num'];
222
- $instance['show_thumb'] = $new_instance['show_thumb'];
223
- $instance['thumb_size'] = $new_instance['thumb_size'];
224
- $instance['show_date'] = $new_instance['show_date'];
225
- $instance['show_excerpt'] = $new_instance['show_excerpt'];
226
- $instance['excerpt_length'] = $new_instance['excerpt_length'];
227
- $instance['show_comment_num'] = $new_instance['show_comment_num'];
228
- $instance['show_avatar'] = $new_instance['show_avatar'];
229
- return $instance;
230
- }
231
- function widget( $args, $instance ) {
232
- extract($args);
233
- extract($instance);
234
- wp_enqueue_script('wpt_widget');
235
- wp_enqueue_style('wpt_widget');
236
- if (empty($tabs)) $tabs = array('recent' => 1, 'popular' => 1);
237
- $tabs_count = count($tabs);
238
- if ($tabs_count <= 1) {
239
- $tabs_count = 1;
240
- } elseif($tabs_count > 3) {
241
- $tabs_count = 4;
242
- }
243
-
244
- $available_tabs = array('popular' => __('Popular', 'wp-tab-widget'),
245
- 'recent' => __('Recent', 'wp-tab-widget'),
246
- 'comments' => __('Comments', 'wp-tab-widget'),
247
- 'tags' => __('Tags', 'wp-tab-widget'));
248
-
249
- array_multisort($tab_order, $available_tabs);
250
-
251
- ?>
252
- <?php echo $before_widget; ?>
253
- <div class="wpt_widget_content" id="<?php echo $widget_id; ?>_content">
254
- <ul class="wpt-tabs <?php echo "has-$tabs_count-"; ?>tabs">
255
- <?php foreach ($available_tabs as $tab => $label) { ?>
256
- <?php if (!empty($tabs[$tab])): ?>
257
- <li class="tab_title"><a href="#" id="<?php echo $tab; ?>-tab"><?php echo $label; ?></a></li>
258
- <?php endif; ?>
259
- <?php } ?>
260
- </ul> <!--end .tabs-->
261
- <div class="clear"></div>
262
- <div class="inside">
263
- <?php if (!empty($tabs['popular'])): ?>
264
- <div id="popular-tab-content" class="tab-content">
265
- </div> <!--end #popular-tab-content-->
266
- <?php endif; ?>
267
- <?php if (!empty($tabs['recent'])): ?>
268
- <div id="recent-tab-content" class="tab-content">
269
- </div> <!--end #recent-tab-content-->
270
- <?php endif; ?>
271
- <?php if (!empty($tabs['comments'])): ?>
272
- <div id="comments-tab-content" class="tab-content">
273
- <ul>
274
- </ul>
275
- </div> <!--end #comments-tab-content-->
276
- <?php endif; ?>
277
- <?php if (!empty($tabs['tags'])): ?>
278
- <div id="tags-tab-content" class="tab-content">
279
- <ul>
280
- </ul>
281
- </div> <!--end #tags-tab-content-->
282
- <?php endif; ?>
283
- <div class="clear"></div>
284
- </div> <!--end .inside -->
285
- <div class="clear"></div>
286
- </div><!--end #tabber -->
287
- <?php
288
- // inline script
289
- // to support multiple instances per page with different settings
290
 
291
- unset($instance['tabs'], $instance['tab_order']); // unset unneeded
292
- ?>
293
- <script type="text/javascript">
294
- jQuery(function($) {
295
- $('#<?php echo $widget_id; ?>_content').data('args', <?php echo json_encode($instance); ?>);
296
- });
297
- </script>
298
- <?php echo $after_widget; ?>
299
- <?php
300
- }
301
-
302
-
303
- function ajax_wpt_widget_content() {
304
- $tab = $_POST['tab'];
305
- $args = $_POST['args'];
306
- $page = intval($_POST['page']);
307
- if ($page < 1)
308
- $page = 1;
309
- if (!is_array($args))
310
- return '';
311
-
312
- // sanitize args
313
- $post_num = (empty($args['post_num']) ? 5 : intval($args['post_num']));
314
- if ($post_num > 20 || $post_num < 1) { // max 20 posts
315
- $post_num = 5;
316
- }
317
- $comment_num = (empty($args['comment_num']) ? 5 : intval($args['comment_num']));
318
- if ($comment_num > 20 || $comment_num < 1) {
319
- $comment_num = 5;
320
- }
321
- $show_thumb = !empty($args['show_thumb']);
322
- $thumb_size = $args['thumb_size'];
323
- if ($thumb_size != 'small' && $thumb_size != 'large') {
324
- $thumb_size = 'small'; // default
325
- }
326
- $show_date = !empty($args['show_date']);
327
- $show_excerpt = !empty($args['show_excerpt']);
328
- $excerpt_length = intval($args['excerpt_length']);
329
- if ($excerpt_length > 50 || $excerpt_length < 1) {
330
- $excerpt_length = 10;
331
- }
332
- $show_comment_num = !empty($args['show_comment_num']);
333
- $show_avatar = !empty($args['show_avatar']);
334
- $allow_pagination = !empty($args['allow_pagination']);
335
 
336
- $title_length = ! empty($args['title_length']) ? $args['title_length'] : apply_filters( 'wpt_title_length_default', '15' );
337
-
338
- /* ---------- Tab Contents ---------- */
339
- switch ($tab) {
340
-
341
- /* ---------- Popular Posts ---------- */
342
- case "popular":
343
- ?>
344
- <ul>
345
- <?php
346
- $popular = new WP_Query( array('ignore_sticky_posts' => 1, 'posts_per_page' => $post_num, 'post_status' => 'publish', 'orderby' => 'meta_value_num', 'meta_key' => '_wpt_view_count', 'order' => 'desc', 'paged' => $page));
347
- $last_page = $popular->max_num_pages;
348
- while ($popular->have_posts()) : $popular->the_post(); ?>
349
- <li>
350
- <?php if ( $show_thumb == 1 ) : ?>
351
- <div class="wpt_thumbnail wpt_thumb_<?php echo $thumb_size; ?>">
352
- <a title="<?php the_title(); ?>" href="<?php the_permalink() ?>">
353
- <?php if(has_post_thumbnail()): ?>
354
- <?php the_post_thumbnail('wp_review_'.$thumb_size, array('title' => '')); ?>
355
- <?php else: ?>
356
- <img src="<?php echo plugins_url('img/'.$thumb_size.'thumb.png', __FILE__); ?>" alt="<?php the_title(); ?>" class="wp-post-image" />
357
- <?php endif; ?>
358
- </a>
359
- </div>
360
- <?php endif; ?>
361
- <div class="entry-title"><a title="<?php the_title(); ?>" href="<?php the_permalink() ?>"><?php echo $this->post_title( $title_length ); ?></a></div>
362
- <?php if ( $show_date == 1 || $show_comment_num == 1) : ?>
363
- <div class="wpt-postmeta">
364
- <?php if ( $show_date == 1 ) : ?>
365
- <?php the_time('F j, Y'); ?>
366
- <?php endif; ?>
367
- <?php if ( $show_date == 1 && $show_comment_num == 1) : ?>
368
- &bull;
369
- <?php endif; ?>
370
- <?php if ( $show_comment_num == 1 ) : ?>
371
- <?php echo comments_number(__('No Comment','wp-tab-widget'), __('One Comment','wp-tab-widget'), '<span class="comments-number">%</span> '.__('Comments','wp-tab-widget'));?>
372
- <?php endif; ?>
373
- </div> <!--end .entry-meta-->
374
- <?php endif; ?>
375
-
376
- <?php if ( $show_excerpt == 1 ) : ?>
377
- <div class="wpt_excerpt">
378
- <p><?php echo $this->excerpt($excerpt_length); ?></p>
379
- </div>
380
- <?php endif; ?>
381
-
382
- <div class="clear"></div>
383
- </li>
384
- <?php $post_num++; endwhile; wp_reset_query(); ?>
385
- </ul>
386
- <div class="clear"></div>
387
- <?php if ($allow_pagination) : ?>
388
- <?php $this->tab_pagination($page, $last_page); ?>
389
- <?php endif; ?>
390
- <?php
391
- break;
392
-
393
- /* ---------- Recent Posts ---------- */
394
- case "recent":
395
- ?>
396
- <ul>
397
- <?php
398
- $recent = new WP_Query('posts_per_page='. $post_num .'&orderby=post_date&order=desc&post_status=publish&paged='. $page);
399
- $last_page = $recent->max_num_pages;
400
- while ($recent->have_posts()) : $recent->the_post();
401
- ?>
402
- <li>
403
- <?php if ( $show_thumb == 1 ) : ?>
404
- <div class="wpt_thumbnail wpt_thumb_<?php echo $thumb_size; ?>">
405
- <a title="<?php the_title(); ?>" href="<?php the_permalink() ?>">
406
- <?php if(has_post_thumbnail()): ?>
407
- <?php the_post_thumbnail('wp_review_'.$thumb_size, array('title' => '')); ?>
408
- <?php else: ?>
409
- <img src="<?php echo plugins_url('img/'.$thumb_size.'thumb.png', __FILE__); ?>" alt="<?php the_title(); ?>" class="wp-post-image" />
410
- <?php endif; ?>
411
- </a>
412
- </div>
413
- <?php endif; ?>
414
- <div class="entry-title"><a title="<?php the_title(); ?>" href="<?php the_permalink() ?>"><?php echo $this->post_title( $title_length ); ?></a></div>
415
- <?php if ( $show_date == 1 || $show_comment_num == 1) : ?>
416
- <div class="wpt-postmeta">
417
- <?php if ( $show_date == 1 ) : ?>
418
- <?php the_time('F j, Y'); ?>
419
- <?php endif; ?>
420
- <?php if ( $show_date == 1 && $show_comment_num == 1) : ?>
421
- &bull;
422
- <?php endif; ?>
423
- <?php if ( $show_comment_num == 1 ) : ?>
424
- <?php echo comments_number(__('No Comment','wp-tab-widget'), __('One Comment','wp-tab-widget'), '<span class="comm">%</span> '.__('Comments','wp-tab-widget'));?>
425
- <?php endif; ?>
426
- </div> <!--end .entry-meta-->
427
- <?php endif; ?>
428
-
429
- <?php if ( $show_excerpt == 1 ) : ?>
430
- <div class="wpt_excerpt">
431
- <p><?php echo $this->excerpt($excerpt_length); ?></p>
432
- </div>
433
- <?php endif; ?>
434
-
435
- <div class="clear"></div>
436
- </li>
437
- <?php endwhile; wp_reset_query(); ?>
438
- </ul>
439
- <div class="clear"></div>
440
- <?php if ($allow_pagination) : ?>
441
- <?php $this->tab_pagination($page, $last_page); ?>
442
- <?php endif; ?>
443
- <?php
444
- break;
445
-
446
- /* ---------- Latest Comments ---------- */
447
- case "comments":
448
- ?>
449
- <ul>
450
- <?php
451
- $no_comments = false;
452
- $avatar_size = 65;
453
- $comment_length = 90; // max length for comments
454
- $comments_total = new WP_Comment_Query();
455
- $comments_total_number = $comments_total->query(array('count' => 1));
456
- $last_page = ceil($comments_total_number / $comment_num);
457
- $comments_query = new WP_Comment_Query();
458
- $offset = ($page-1) * $comment_num;
459
- $comments = $comments_query->query( array( 'number' => $comment_num, 'offset' => $offset, 'status' => 'approve' ) );
460
- if ( $comments ) : foreach ( $comments as $comment ) : ?>
461
- <li>
462
- <?php if ($show_avatar) : ?>
463
- <div class="wpt_avatar">
464
- <a href="<?php echo get_comment_link($comment->comment_ID); ?>">
465
- <?php echo get_avatar( $comment->comment_author_email, $avatar_size ); ?>
466
- </a>
467
- </div>
468
- <?php endif; ?>
469
- <div class="wpt_comment_meta">
470
- <a href="<?php echo get_comment_link($comment->comment_ID); ?>">
471
- <span class="wpt_comment_author"><?php echo get_comment_author( $comment->comment_ID ); ?> </span> - <span class="wpt_comment_post"><?php echo get_the_title($comment->comment_post_ID); ?></span>
472
- </a>
473
- </div>
474
- <div class="wpt_comment_content">
475
- <p><?php echo $this->truncate(strip_tags(apply_filters( 'get_comment_text', $comment->comment_content )), $comment_length);?></p>
476
- </div>
477
- <div class="clear"></div>
478
- </li>
479
- <?php endforeach; else : ?>
480
- <li>
481
- <div class="no-comments"><?php _e('No comments yet.', 'wp-tab-widget'); ?></div>
482
- </li>
483
- <?php $no_comments = true;
484
- endif; ?>
485
- </ul>
486
- <?php if ($allow_pagination && !$no_comments) : ?>
487
- <?php $this->tab_pagination($page, $last_page); ?>
488
- <?php endif; ?>
489
- <?php
490
- break;
491
-
492
- /* ---------- Tags ---------- */
493
- case "tags":
494
- ?>
495
- <ul>
496
- <?php
497
- $tags = get_tags(array('get'=>'all'));
498
- if($tags) {
499
- foreach ($tags as $tag): ?>
500
- <li><a href="<?php echo get_term_link($tag); ?>"><?php echo $tag->name; ?></a></li>
501
- <?php
502
- endforeach;
503
- } else {
504
- _e('No tags created.', 'wp-tab-widget');
505
- }
506
  ?>
507
- </ul>
508
- <?php
509
- break;
510
- }
511
- die(); // required to return a proper result
512
- }
513
- function tab_pagination($page, $last_page) {
514
- ?>
515
- <div class="wpt-pagination">
516
- <?php if ($page > 1) : ?>
517
- <a href="#" class="previous"><span><?php _e('&laquo; Previous', 'wp-tab-widget'); ?></span></a>
518
- <?php endif; ?>
519
- <?php if ($page != $last_page) : ?>
520
- <a href="#" class="next"><span><?php _e('Next &raquo;', 'wp-tab-widget'); ?></span></a>
521
- <?php endif; ?>
522
- </div>
523
- <div class="clear"></div>
524
- <input type="hidden" class="page_num" name="page_num" value="<?php echo $page; ?>" />
525
- <?php
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
526
  }
527
-
528
- function excerpt($limit = 10) {
529
- $limit++;
530
- $excerpt = explode(' ', get_the_excerpt(), $limit);
531
- if (count($excerpt)>=$limit) {
532
- array_pop($excerpt);
533
- $excerpt = implode(" ",$excerpt).'...';
534
- } else {
535
- $excerpt = implode(" ",$excerpt);
536
- }
537
- $excerpt = preg_replace('`[[^]]*]`','',$excerpt);
538
- return $excerpt;
539
- }
540
- function post_title($limit = 10) {
541
- $limit++;
542
- $title = explode(' ', get_the_title(), $limit);
543
- if (count($title)>=$limit) {
544
- array_pop($title);
545
- $title = implode(" ",$title).'...';
546
- } else {
547
- $title = implode(" ",$title);
548
- }
549
- return $title;
550
- }
551
- function truncate($str, $length = 24) {
552
- if (mb_strlen($str) > $length) {
553
- return mb_substr($str, 0, $length).'...';
554
- } else {
555
- return $str;
556
- }
557
- }
558
-
559
  }
560
  add_action( 'widgets_init', create_function( '', 'register_widget( "wpt_widget" );' ) );
561
 
@@ -647,4 +666,27 @@ function unregister_mts_tabs_widget() {
647
  unregister_widget('mts_Widget_Tabs');
648
  }
649
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
650
  ?>
4
  Plugin URI: http://mythemeshop.com/plugins/wp-tab-widget/
5
  Description: WP Tab Widget is the AJAXified plugin which loads content by demand, and thus it makes the plugin incredibly lightweight.
6
  Author: MyThemeShop
7
+ Version: 1.2.3
8
  Author URI: http://mythemeshop.com/
9
  */
10
+ if ( !class_exists('wpt_widget') ) {
11
+ class wpt_widget extends WP_Widget {
12
+ function __construct() {
13
+
14
+ // add image sizes and load language file
15
+ add_action( 'init', array(&$this, 'wpt_init') );
16
+
17
+ // ajax functions
18
+ add_action('wp_ajax_wpt_widget_content', array(&$this, 'ajax_wpt_widget_content'));
19
+ add_action('wp_ajax_nopriv_wpt_widget_content', array(&$this, 'ajax_wpt_widget_content'));
20
+
21
+ // css
22
+ add_action('wp_enqueue_scripts', array(&$this, 'wpt_register_scripts'));
23
+ add_action('admin_enqueue_scripts', array(&$this, 'wpt_admin_scripts'));
24
 
25
+ $widget_ops = array('classname' => 'widget_wpt', 'description' => __('Display popular posts, recent posts, comments, and tags in tabbed format.', 'wp-tab-widget'));
26
+ $control_ops = array('width' => 300, 'height' => 350);
27
+ parent::__construct('wpt_widget', __('WP Tab Widget by MyThemeShop', 'wp-tab-widget'), $widget_ops, $control_ops);
28
+ }
29
+
30
+ function wpt_init() {
31
+ load_plugin_textdomain('wp-tab-widget', false, dirname(plugin_basename(__FILE__)) . '/languages/' );
32
+
33
+ add_image_size( 'wp_review_small', 65, 65, true ); // small thumb
34
+ add_image_size( 'wp_review_large', 320, 240, true ); // large thumb
35
+ }
36
+ function wpt_admin_scripts($hook) {
37
+ if ($hook != 'widgets.php')
38
+ return;
39
+ wp_register_script('wpt_widget_admin', plugins_url('js/wpt-admin.js', __FILE__), array('jquery'));
40
+ wp_enqueue_script('wpt_widget_admin');
41
+ }
42
+ function wpt_register_scripts() {
43
+ // JS
44
+ wp_register_script('wpt_widget', plugins_url('js/wp-tab-widget.js', __FILE__), array('jquery'));
45
+ wp_localize_script( 'wpt_widget', 'wpt',
46
+ array( 'ajax_url' => admin_url( 'admin-ajax.php' ))
47
+ );
48
+ // CSS
49
+ wp_register_style('wpt_widget', plugins_url('css/wp-tab-widget.css', __FILE__), true);
50
+ }
51
+
52
+ function form( $instance ) {
53
+ $instance = wp_parse_args( (array) $instance, array(
54
+ 'tabs' => array('recent' => 1, 'popular' => 1, 'comments' => 0, 'tags' => 0),
55
+ 'tab_order' => array('popular' => 1, 'recent' => 2, 'comments' => 3, 'tags' => 4),
56
+ 'allow_pagination' => 1,
57
+ 'post_num' => '5',
58
+ 'comment_num' => '5',
59
+ 'show_thumb' => 1,
60
+ 'thumb_size' => 'small',
61
+ 'show_date' => 1,
62
+ 'show_excerpt' => 0,
63
+ 'excerpt_length' => apply_filters( 'wpt_excerpt_length_default', '15' ),
64
+ 'show_comment_num' => 0,
65
+ 'show_avatar' => 1,
66
+ 'title_length' => apply_filters( 'wpt_title_length_default', '15' )
67
+ ) );
68
+
69
+ extract($instance);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
70
 
71
+ ?>
72
+ <div class="wpt_options_form">
73
+
74
+ <h4><?php _e('Select Tabs', 'wp-tab-widget'); ?></h4>
75
+
76
+ <div class="wpt_select_tabs">
77
+ <label class="alignleft" style="display: block; width: 50%; margin-bottom: 5px" for="<?php echo $this->get_field_id("tabs"); ?>_popular">
78
+ <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id("tabs"); ?>_popular" name="<?php echo $this->get_field_name("tabs"); ?>[popular]" value="1" <?php if (isset($tabs['popular'])) { checked( 1, $tabs['popular'], true ); } ?> />
79
+ <?php _e( 'Popular Tab', 'wp-tab-widget'); ?>
80
+ </label>
81
+ <label class="alignleft" style="display: block; width: 50%; margin-bottom: 5px;" for="<?php echo $this->get_field_id("tabs"); ?>_recent">
82
+ <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id("tabs"); ?>_recent" name="<?php echo $this->get_field_name("tabs"); ?>[recent]" value="1" <?php if (isset($tabs['recent'])) { checked( 1, $tabs['recent'], true ); } ?> />
83
+ <?php _e( 'Recent Tab', 'wp-tab-widget'); ?>
84
+ </label>
85
+ <label class="alignleft" style="display: block; width: 50%;" for="<?php echo $this->get_field_id("tabs"); ?>_comments">
86
+ <input type="checkbox" class="checkbox wpt_enable_comments" id="<?php echo $this->get_field_id("tabs"); ?>_comments" name="<?php echo $this->get_field_name("tabs"); ?>[comments]" value="1" <?php if (isset($tabs['comments'])) { checked( 1, $tabs['comments'], true ); } ?> />
87
+ <?php _e( 'Comments Tab', 'wp-tab-widget'); ?>
88
+ </label>
89
+ <label class="alignleft" style="display: block; width: 50%;" for="<?php echo $this->get_field_id("tabs"); ?>_tags">
90
+ <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id("tabs"); ?>_tags" name="<?php echo $this->get_field_name("tabs"); ?>[tags]" value="1" <?php if (isset($tabs['tags'])) { checked( 1, $tabs['tags'], true ); } ?> />
91
+ <?php _e( 'Tags Tab', 'wp-tab-widget'); ?>
92
+ </label>
93
+ </div>
94
+ <div class="clear"></div>
95
+
96
+ <h4 class="wpt_tab_order_header"><a href="#"><?php _e('Tab Order', 'wp-tab-widget'); ?></a></h4>
97
+
98
+ <div class="wpt_tab_order" style="display: none;">
99
+
100
+ <label class="alignleft" for="<?php echo $this->get_field_id('tab_order'); ?>_popular" style="width: 50%;">
101
+ <input id="<?php echo $this->get_field_id('tab_order'); ?>_popular" name="<?php echo $this->get_field_name('tab_order'); ?>[popular]" type="number" min="1" step="1" value="<?php echo $tab_order['popular']; ?>" style="width: 48px;" />
102
+ <?php _e('Popular', 'wp-tab-widget'); ?>
103
+ </label>
104
+ <label class="alignleft" for="<?php echo $this->get_field_id('tab_order'); ?>_recent" style="width: 50%;">
105
+ <input id="<?php echo $this->get_field_id('tab_order'); ?>_recent" name="<?php echo $this->get_field_name('tab_order'); ?>[recent]" type="number" min="1" step="1" value="<?php echo $tab_order['recent']; ?>" style="width: 48px;" />
106
+ <?php _e('Recent', 'wp-tab-widget'); ?>
107
+ </label>
108
+ <label class="alignleft" for="<?php echo $this->get_field_id('tab_order'); ?>_comments" style="width: 50%;">
109
+ <input id="<?php echo $this->get_field_id('tab_order'); ?>_comments" name="<?php echo $this->get_field_name('tab_order'); ?>[comments]" type="number" min="1" step="1" value="<?php echo $tab_order['comments']; ?>" style="width: 48px;" />
110
+ <?php _e('Comments', 'wp-tab-widget'); ?>
111
+ </label>
112
+ <label class="alignleft" for="<?php echo $this->get_field_id('tab_order'); ?>_tags" style="width: 50%;">
113
+ <input id="<?php echo $this->get_field_id('tab_order'); ?>_tags" name="<?php echo $this->get_field_name('tab_order'); ?>[tags]" type="number" min="1" step="1" value="<?php echo $tab_order['tags']; ?>" style="width: 48px;" />
114
+ <?php _e('Tags', 'wp-tab-widget'); ?>
115
+ </label>
116
+ </div>
117
+ <div class="clear"></div>
118
+
119
+ <h4 class="wpt_advanced_options_header"><a href="#"><?php _e('Advanced Options', 'wp-tab-widget'); ?></a></h4>
120
+
121
+ <div class="wpt_advanced_options" style="display: none;">
122
+ <p>
123
+ <label for="<?php echo $this->get_field_id("allow_pagination"); ?>">
124
+ <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id("allow_pagination"); ?>" name="<?php echo $this->get_field_name("allow_pagination"); ?>" value="1" <?php if (isset($allow_pagination)) { checked( 1, $allow_pagination, true ); } ?> />
125
+ <?php _e( 'Allow pagination', 'wp-tab-widget'); ?>
126
+ </label>
127
+ </p>
128
+
129
+ <div class="wpt_post_options">
130
 
131
+ <p>
132
+ <label for="<?php echo $this->get_field_id('post_num'); ?>"><?php _e('Number of posts to show:', 'wp-tab-widget'); ?>
133
+ <br />
134
+ <input id="<?php echo $this->get_field_id('post_num'); ?>" name="<?php echo $this->get_field_name('post_num'); ?>" type="number" min="1" step="1" value="<?php echo $post_num; ?>" />
135
+ </label>
136
+ </p>
137
 
138
+ <p>
139
+ <label for="<?php echo $this->get_field_id('title_length'); ?>"><?php _e('Title length (words):', 'wp-tab-widget'); ?>
140
+ <br />
141
+ <input id="<?php echo $this->get_field_id('title_length'); ?>" name="<?php echo $this->get_field_name('title_length'); ?>" type="number" min="1" step="1" value="<?php echo $title_length; ?>" />
142
+ </label>
143
+ </p>
144
+
145
+ <p>
146
+ <label for="<?php echo $this->get_field_id("show_thumb"); ?>">
147
+ <input type="checkbox" class="checkbox wpt_show_thumbnails" id="<?php echo $this->get_field_id("show_thumb"); ?>" name="<?php echo $this->get_field_name("show_thumb"); ?>" value="1" <?php if (isset($show_thumb)) { checked( 1, $show_thumb, true ); } ?> />
148
+ <?php _e( 'Show post thumbnails', 'wp-tab-widget'); ?>
149
+ </label>
150
+ </p>
151
+
152
+ <p class="wpt_thumbnail_size"<?php echo (empty($show_thumb) ? ' style="display: none;"' : ''); ?>>
153
+ <label for="<?php echo $this->get_field_id('thumb_size'); ?>"><?php _e('Thumbnail size:', 'wp-tab-widget'); ?></label>
154
+ <select id="<?php echo $this->get_field_id('thumb_size'); ?>" name="<?php echo $this->get_field_name('thumb_size'); ?>" style="margin-left: 12px;">
155
+ <option value="small" <?php selected($thumb_size, 'small', true); ?>><?php _e('Small', 'wp-tab-widget'); ?></option>
156
+ <option value="large" <?php selected($thumb_size, 'large', true); ?>><?php _e('Large', 'wp-tab-widget'); ?></option>
157
+ </select>
158
+ </p>
159
+
160
+ <p>
161
+ <label for="<?php echo $this->get_field_id("show_date"); ?>">
162
+ <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id("show_date"); ?>" name="<?php echo $this->get_field_name("show_date"); ?>" value="1" <?php if (isset($show_date)) { checked( 1, $show_date, true ); } ?> />
163
+ <?php _e( 'Show post date', 'wp-tab-widget'); ?>
164
+ </label>
165
+ </p>
166
+
167
+ <p>
168
+ <label for="<?php echo $this->get_field_id("show_comment_num"); ?>">
169
+ <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id("show_comment_num"); ?>" name="<?php echo $this->get_field_name("show_comment_num"); ?>" value="1" <?php if (isset($show_comment_num)) { checked( 1, $show_comment_num, true ); } ?> />
170
+ <?php _e( 'Show number of comments', 'wp-tab-widget'); ?>
171
+ </label>
172
+ </p>
173
+
174
+ <p>
175
+ <label for="<?php echo $this->get_field_id("show_excerpt"); ?>">
176
+ <input type="checkbox" class="checkbox wpt_show_excerpt" id="<?php echo $this->get_field_id("show_excerpt"); ?>" name="<?php echo $this->get_field_name("show_excerpt"); ?>" value="1" <?php if (isset($show_excerpt)) { checked( 1, $show_excerpt, true ); } ?> />
177
+ <?php _e( 'Show post excerpt', 'wp-tab-widget'); ?>
178
+ </label>
179
+ </p>
180
+
181
+ <p class="wpt_excerpt_length"<?php echo (empty($show_excerpt) ? ' style="display: none;"' : ''); ?>>
182
+ <label for="<?php echo $this->get_field_id('excerpt_length'); ?>">
183
+ <?php _e('Excerpt length (words):', 'wp-tab-widget'); ?>
184
+ <br />
185
+ <input type="number" min="1" step="1" id="<?php echo $this->get_field_id('excerpt_length'); ?>" name="<?php echo $this->get_field_name('excerpt_length'); ?>" value="<?php echo $excerpt_length; ?>" />
186
+ </label>
187
+ </p>
188
+
189
+ </div>
190
+ <div class="clear"></div>
191
+
192
+ <div class="wpt_comment_options"<?php echo (empty($tabs['comments']) ? ' style="display: none;"' : ''); ?>>
193
+
194
+ <p>
195
+ <label for="<?php echo $this->get_field_id('comment_num'); ?>">
196
+ <?php _e('Number of comments on Comments Tab:', 'wp-tab-widget'); ?>
197
+ <br />
198
+ <input type="number" min="1" step="1" id="<?php echo $this->get_field_id('comment_num'); ?>" name="<?php echo $this->get_field_name('comment_num'); ?>" value="<?php echo $comment_num; ?>" />
199
+ </label>
200
+ </p>
201
+
202
+ <p>
203
+ <label for="<?php echo $this->get_field_id("show_avatar"); ?>">
204
+ <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id("show_avatar"); ?>" name="<?php echo $this->get_field_name("show_avatar"); ?>" value="1" <?php if (isset($show_avatar)) { checked( 1, $show_avatar, true ); } ?> />
205
+ <?php _e( 'Show avatars on Comments Tab', 'wp-tab-widget'); ?>
206
+ </label>
207
+ </p>
208
+ </div><!-- .wpt_comment_options -->
209
+ </div><!-- .wpt_advanced_options -->
210
+ <a href="https://mythemeshop.com/plugins/wp-tab-widget-pro/?utm_source=WP+Tab+Widget+Free&utm_medium=Banner+CPC&utm_content=WP+Tab+Widget+Pro+LP&utm_campaign=WordPressOrg&wpmts" target="_blank"><img src="<?php echo plugin_dir_url( __FILE__ ); ?>/img/wp-tab-widget-pro.jpg" style="width:100%; max-width: 100%; margin-bottom: 10px;"></a>
211
+ </div><!-- .wpt_options_form -->
212
+ <?php
213
+ }
214
 
215
+ function update( $new_instance, $old_instance ) {
216
+ $instance = $old_instance;
217
+ $instance['tabs'] = $new_instance['tabs'];
218
+ $instance['tab_order'] = $new_instance['tab_order'];
219
+ $instance['allow_pagination'] = $new_instance['allow_pagination'];
220
+ $instance['post_num'] = $new_instance['post_num'];
221
+ $instance['title_length'] = $new_instance['title_length'];
222
+ $instance['comment_num'] = $new_instance['comment_num'];
223
+ $instance['show_thumb'] = $new_instance['show_thumb'];
224
+ $instance['thumb_size'] = $new_instance['thumb_size'];
225
+ $instance['show_date'] = $new_instance['show_date'];
226
+ $instance['show_excerpt'] = $new_instance['show_excerpt'];
227
+ $instance['excerpt_length'] = $new_instance['excerpt_length'];
228
+ $instance['show_comment_num'] = $new_instance['show_comment_num'];
229
+ $instance['show_avatar'] = $new_instance['show_avatar'];
230
+ return $instance;
231
+ }
232
+ function widget( $args, $instance ) {
233
+ extract($args);
234
+ extract($instance);
235
+ wp_enqueue_script('wpt_widget');
236
+ wp_enqueue_style('wpt_widget');
237
+ if (empty($tabs)) $tabs = array('recent' => 1, 'popular' => 1);
238
+ $tabs_count = count($tabs);
239
+ if ($tabs_count <= 1) {
240
+ $tabs_count = 1;
241
+ } elseif($tabs_count > 3) {
242
+ $tabs_count = 4;
243
+ }
244
+
245
+ $available_tabs = array('popular' => __('Popular', 'wp-tab-widget'),
246
+ 'recent' => __('Recent', 'wp-tab-widget'),
247
+ 'comments' => __('Comments', 'wp-tab-widget'),
248
+ 'tags' => __('Tags', 'wp-tab-widget'));
249
+
250
+ array_multisort($tab_order, $available_tabs);
251
+
252
+ ?>
253
+ <?php echo $before_widget; ?>
254
+ <div class="wpt_widget_content" id="<?php echo $widget_id; ?>_content" data-widget-number="<?php echo esc_attr( $this->number ); ?>">
255
+ <ul class="wpt-tabs <?php echo "has-$tabs_count-"; ?>tabs">
256
+ <?php foreach ($available_tabs as $tab => $label) { ?>
257
+ <?php if (!empty($tabs[$tab])): ?>
258
+ <li class="tab_title"><a href="#" id="<?php echo $tab; ?>-tab"><?php echo $label; ?></a></li>
259
+ <?php endif; ?>
260
+ <?php } ?>
261
+ </ul> <!--end .tabs-->
262
+ <div class="clear"></div>
263
+ <div class="inside">
264
+ <?php if (!empty($tabs['popular'])): ?>
265
+ <div id="popular-tab-content" class="tab-content">
266
+ </div> <!--end #popular-tab-content-->
267
+ <?php endif; ?>
268
+ <?php if (!empty($tabs['recent'])): ?>
269
+ <div id="recent-tab-content" class="tab-content">
270
+ </div> <!--end #recent-tab-content-->
271
+ <?php endif; ?>
272
+ <?php if (!empty($tabs['comments'])): ?>
273
+ <div id="comments-tab-content" class="tab-content">
274
+ <ul>
275
+ </ul>
276
+ </div> <!--end #comments-tab-content-->
277
+ <?php endif; ?>
278
+ <?php if (!empty($tabs['tags'])): ?>
279
+ <div id="tags-tab-content" class="tab-content">
280
+ <ul>
281
+ </ul>
282
+ </div> <!--end #tags-tab-content-->
283
+ <?php endif; ?>
284
+ <div class="clear"></div>
285
+ </div> <!--end .inside -->
286
+ <div class="clear"></div>
287
+ </div><!--end #tabber -->
288
+ <?php
289
+ // inline script
290
+ // to support multiple instances per page with different settings
291
+
292
+ unset($instance['tabs'], $instance['tab_order']); // unset unneeded
293
+ ?>
294
+ <script type="text/javascript">
295
+ jQuery(function($) {
296
+ $('#<?php echo $widget_id; ?>_content').data('args', <?php echo json_encode($instance); ?>);
297
+ });
298
+ </script>
299
+ <?php echo $after_widget; ?>
300
+ <?php
301
+ }
 
302
 
303
+
304
+ function ajax_wpt_widget_content() {
305
+ $tab = $_POST['tab'];
306
+ $args = $_POST['args'];
307
+ $number = intval( $_POST['widget_number'] );
308
+ $page = intval($_POST['page']);
309
+ if ($page < 1)
310
+ $page = 1;
311
+
312
+ if ( !is_array( $args ) || empty( $args ) ) { // json_encode() failed
313
+ $wpt_widgets = new wpt_widget();
314
+ $settings = $wpt_widgets->get_settings();
315
+
316
+ if ( isset( $settings[ $number ] ) ) {
317
+ $args = $settings[ $number ];
318
+ } else {
319
+ die( __('Unable to load tab content', 'wp-tab-widget') );
320
+ }
321
+ }
322
+
323
+
324
+ // sanitize args
325
+ $post_num = (empty($args['post_num']) ? 5 : intval($args['post_num']));
326
+ if ($post_num > 20 || $post_num < 1) { // max 20 posts
327
+ $post_num = 5;
328
+ }
329
+ $comment_num = (empty($args['comment_num']) ? 5 : intval($args['comment_num']));
330
+ if ($comment_num > 20 || $comment_num < 1) {
331
+ $comment_num = 5;
332
+ }
333
+ $show_thumb = !empty($args['show_thumb']);
334
+ $thumb_size = $args['thumb_size'];
335
+ if ($thumb_size != 'small' && $thumb_size != 'large') {
336
+ $thumb_size = 'small'; // default
337
+ }
338
+ $show_date = !empty($args['show_date']);
339
+ $show_excerpt = !empty($args['show_excerpt']);
340
+ $excerpt_length = intval($args['excerpt_length']);
341
+ if ($excerpt_length > 50 || $excerpt_length < 1) {
342
+ $excerpt_length = 10;
343
+ }
344
+ $show_comment_num = !empty($args['show_comment_num']);
345
+ $show_avatar = !empty($args['show_avatar']);
346
+ $allow_pagination = !empty($args['allow_pagination']);
347
 
348
+ $title_length = ! empty($args['title_length']) ? $args['title_length'] : apply_filters( 'wpt_title_length_default', '15' );
349
+
350
+ /* ---------- Tab Contents ---------- */
351
+ switch ($tab) {
352
+
353
+ /* ---------- Popular Posts ---------- */
354
+ case "popular":
355
+ ?>
356
+ <ul>
357
+ <?php
358
+ $popular = new WP_Query( array('ignore_sticky_posts' => 1, 'posts_per_page' => $post_num, 'post_status' => 'publish', 'orderby' => 'meta_value_num', 'meta_key' => '_wpt_view_count', 'order' => 'desc', 'paged' => $page));
359
+ $last_page = $popular->max_num_pages;
360
+ while ($popular->have_posts()) : $popular->the_post(); ?>
361
+ <li>
362
+ <?php if ( $show_thumb == 1 ) : ?>
363
+ <div class="wpt_thumbnail wpt_thumb_<?php echo $thumb_size; ?>">
364
+ <a title="<?php the_title(); ?>" href="<?php the_permalink() ?>">
365
+ <?php if(has_post_thumbnail()): ?>
366
+ <?php the_post_thumbnail('wp_review_'.$thumb_size, array('title' => '')); ?>
367
+ <?php else: ?>
368
+ <img src="<?php echo plugins_url('img/'.$thumb_size.'thumb.png', __FILE__); ?>" alt="<?php the_title(); ?>" class="wp-post-image" />
369
+ <?php endif; ?>
370
+ </a>
371
+ </div>
372
+ <?php endif; ?>
373
+ <div class="entry-title"><a title="<?php the_title(); ?>" href="<?php the_permalink() ?>"><?php echo $this->post_title( $title_length ); ?></a></div>
374
+ <?php if ( $show_date == 1 || $show_comment_num == 1) : ?>
375
+ <div class="wpt-postmeta">
376
+ <?php if ( $show_date == 1 ) : ?>
377
+ <?php the_time('F j, Y'); ?>
378
+ <?php endif; ?>
379
+ <?php if ( $show_date == 1 && $show_comment_num == 1) : ?>
380
+ &bull;
381
+ <?php endif; ?>
382
+ <?php if ( $show_comment_num == 1 ) : ?>
383
+ <?php echo comments_number(__('No Comment','wp-tab-widget'), __('One Comment','wp-tab-widget'), '<span class="comments-number">%</span> '.__('Comments','wp-tab-widget'));?>
384
+ <?php endif; ?>
385
+ </div> <!--end .entry-meta-->
386
+ <?php endif; ?>
387
+
388
+ <?php if ( $show_excerpt == 1 ) : ?>
389
+ <div class="wpt_excerpt">
390
+ <p><?php echo $this->excerpt($excerpt_length); ?></p>
391
+ </div>
392
+ <?php endif; ?>
393
+
394
+ <div class="clear"></div>
395
+ </li>
396
+ <?php $post_num++; endwhile; wp_reset_query(); ?>
397
+ </ul>
398
+ <div class="clear"></div>
399
+ <?php if ($allow_pagination) : ?>
400
+ <?php $this->tab_pagination($page, $last_page); ?>
401
+ <?php endif; ?>
402
+ <?php
403
+ break;
404
+
405
+ /* ---------- Recent Posts ---------- */
406
+ case "recent":
407
+ ?>
408
+ <ul>
409
+ <?php
410
+ $recent = new WP_Query('posts_per_page='. $post_num .'&orderby=post_date&order=desc&post_status=publish&paged='. $page);
411
+ $last_page = $recent->max_num_pages;
412
+ while ($recent->have_posts()) : $recent->the_post();
413
+ ?>
414
+ <li>
415
+ <?php if ( $show_thumb == 1 ) : ?>
416
+ <div class="wpt_thumbnail wpt_thumb_<?php echo $thumb_size; ?>">
417
+ <a title="<?php the_title(); ?>" href="<?php the_permalink() ?>">
418
+ <?php if(has_post_thumbnail()): ?>
419
+ <?php the_post_thumbnail('wp_review_'.$thumb_size, array('title' => '')); ?>
420
+ <?php else: ?>
421
+ <img src="<?php echo plugins_url('img/'.$thumb_size.'thumb.png', __FILE__); ?>" alt="<?php the_title(); ?>" class="wp-post-image" />
422
+ <?php endif; ?>
423
+ </a>
424
+ </div>
425
+ <?php endif; ?>
426
+ <div class="entry-title"><a title="<?php the_title(); ?>" href="<?php the_permalink() ?>"><?php echo $this->post_title( $title_length ); ?></a></div>
427
+ <?php if ( $show_date == 1 || $show_comment_num == 1) : ?>
428
+ <div class="wpt-postmeta">
429
+ <?php if ( $show_date == 1 ) : ?>
430
+ <?php the_time('F j, Y'); ?>
431
+ <?php endif; ?>
432
+ <?php if ( $show_date == 1 && $show_comment_num == 1) : ?>
433
+ &bull;
434
+ <?php endif; ?>
435
+ <?php if ( $show_comment_num == 1 ) : ?>
436
+ <?php echo comments_number(__('No Comment','wp-tab-widget'), __('One Comment','wp-tab-widget'), '<span class="comm">%</span> '.__('Comments','wp-tab-widget'));?>
437
+ <?php endif; ?>
438
+ </div> <!--end .entry-meta-->
439
+ <?php endif; ?>
440
+
441
+ <?php if ( $show_excerpt == 1 ) : ?>
442
+ <div class="wpt_excerpt">
443
+ <p><?php echo $this->excerpt($excerpt_length); ?></p>
444
+ </div>
445
+ <?php endif; ?>
446
+
447
+ <div class="clear"></div>
448
+ </li>
449
+ <?php endwhile; wp_reset_query(); ?>
450
+ </ul>
451
+ <div class="clear"></div>
452
+ <?php if ($allow_pagination) : ?>
453
+ <?php $this->tab_pagination($page, $last_page); ?>
454
+ <?php endif; ?>
455
+ <?php
456
+ break;
457
+
458
+ /* ---------- Latest Comments ---------- */
459
+ case "comments":
460
+ ?>
461
+ <ul>
462
+ <?php
463
+ $no_comments = false;
464
+ $avatar_size = 65;
465
+ $comment_length = 90; // max length for comments
466
+ $comment_args = apply_filters(
467
+ 'wpt_comments_tab_args',
468
+ array(
469
+ 'type' => 'comments',
470
+ 'status' => 'approve'
471
+ )
472
+ );
473
+ $comments_total = new WP_Comment_Query();
474
+ $comments_total_number = $comments_total->query( array_merge( array('count' => 1 ), $comment_args ) );
475
+ $last_page = (int) ceil($comments_total_number / $comment_num);
476
+ $comments_query = new WP_Comment_Query();
477
+ $offset = ($page-1) * $comment_num;
478
+ $comments = $comments_query->query( array_merge( array( 'number' => $comment_num, 'offset' => $offset ), $comment_args ) );
479
+ if ( $comments ) : foreach ( $comments as $comment ) : ?>
480
+ <li>
481
+ <?php if ($show_avatar) : ?>
482
+ <div class="wpt_avatar">
483
+ <a href="<?php echo get_comment_link($comment->comment_ID); ?>">
484
+ <?php echo get_avatar( $comment->comment_author_email, $avatar_size ); ?>
485
+ </a>
486
+ </div>
487
+ <?php endif; ?>
488
+ <div class="wpt_comment_meta">
489
+ <a href="<?php echo get_comment_link($comment->comment_ID); ?>">
490
+ <span class="wpt_comment_author"><?php echo get_comment_author( $comment->comment_ID ); ?> </span> - <span class="wpt_comment_post"><?php echo get_the_title($comment->comment_post_ID); ?></span>
491
+ </a>
492
+ </div>
493
+ <div class="wpt_comment_content">
494
+ <p><?php echo $this->truncate(strip_tags(apply_filters( 'get_comment_text', $comment->comment_content )), $comment_length);?></p>
495
+ </div>
496
+ <div class="clear"></div>
497
+ </li>
498
+ <?php endforeach; else : ?>
499
+ <li>
500
+ <div class="no-comments"><?php _e('No comments yet.', 'wp-tab-widget'); ?></div>
501
+ </li>
502
+ <?php $no_comments = true;
503
+ endif; ?>
504
+ </ul>
505
+ <?php if ($allow_pagination && !$no_comments) : ?>
506
+ <?php $this->tab_pagination($page, $last_page); ?>
507
+ <?php endif; ?>
508
+ <?php
509
+ break;
510
+
511
+ /* ---------- Tags ---------- */
512
+ case "tags":
 
 
 
 
 
513
  ?>
514
+ <ul>
515
+ <?php
516
+ $tags = get_tags(array('get'=>'all'));
517
+ if($tags) {
518
+ foreach ($tags as $tag): ?>
519
+ <li><a href="<?php echo get_term_link($tag); ?>"><?php echo $tag->name; ?></a></li>
520
+ <?php
521
+ endforeach;
522
+ } else {
523
+ _e('No tags created.', 'wp-tab-widget');
524
+ }
525
+ ?>
526
+ </ul>
527
+ <?php
528
+ break;
529
+ }
530
+ die(); // required to return a proper result
531
+ }
532
+ function tab_pagination($page, $last_page) {
533
+ ?>
534
+ <div class="wpt-pagination">
535
+ <?php if ($page > 1) : ?>
536
+ <a href="#" class="previous"><span><?php _e('&laquo; Previous', 'wp-tab-widget'); ?></span></a>
537
+ <?php endif; ?>
538
+ <?php if ($page != $last_page) : ?>
539
+ <a href="#" class="next"><span><?php _e('Next &raquo;', 'wp-tab-widget'); ?></span></a>
540
+ <?php endif; ?>
541
+ </div>
542
+ <div class="clear"></div>
543
+ <input type="hidden" class="page_num" name="page_num" value="<?php echo $page; ?>" />
544
+ <?php
545
+ }
546
+
547
+ function excerpt($limit = 10) {
548
+ $limit++;
549
+ $excerpt = explode(' ', get_the_excerpt(), $limit);
550
+ if (count($excerpt)>=$limit) {
551
+ array_pop($excerpt);
552
+ $excerpt = implode(" ",$excerpt).'...';
553
+ } else {
554
+ $excerpt = implode(" ",$excerpt);
555
+ }
556
+ $excerpt = preg_replace('`[[^]]*]`','',$excerpt);
557
+ return $excerpt;
558
+ }
559
+ function post_title($limit = 10) {
560
+ $limit++;
561
+ $title = explode(' ', get_the_title(), $limit);
562
+ if (count($title)>=$limit) {
563
+ array_pop($title);
564
+ $title = implode(" ",$title).'...';
565
+ } else {
566
+ $title = implode(" ",$title);
567
+ }
568
+ return $title;
569
+ }
570
+ function truncate($str, $length = 24) {
571
+ if (mb_strlen($str) > $length) {
572
+ return mb_substr($str, 0, $length).'...';
573
+ } else {
574
+ return $str;
575
+ }
576
+ }
577
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
578
  }
579
  add_action( 'widgets_init', create_function( '', 'register_widget( "wpt_widget" );' ) );
580
 
666
  unregister_widget('mts_Widget_Tabs');
667
  }
668
 
669
+ /* Display a admin notice */
670
+
671
+ add_action('admin_notices', 'wp_tab_widget_admin_notice');
672
+ function wp_tab_widget_admin_notice() {
673
+ global $current_user ;
674
+ $user_id = $current_user->ID;
675
+ /* Check that the user hasn't already clicked to ignore the message */
676
+ if ( ! get_user_meta($user_id, 'wp_tab_widget_ignore_notice') ) {
677
+ echo '<div class="updated notice-info wp-tab-widget-pro-notice" style="position:relative;"><p>';
678
+ printf(__('Like WP Tab Widget? You will <strong>LOVE WP Tab Widget Pro</strong>!','wp-tab-widget').'<a href="https://mythemeshop.com/plugins/wp-tab-widget-pro/?utm_source=WP+Tab+Widget+Free&utm_medium=Notification+Link&utm_content=WP+Tab+Widget+Pro+LP&utm_campaign=WordPressOrg&wpmts" target="_blank">&nbsp;'.__('Click here for all the exciting features.','wp-tab-widget').'</a><a href="%1$s" class="dashicons dashicons-dismiss dashicons-dismiss-icon" style="position: absolute; top: 8px; right: 8px; color: #222; opacity: 0.4; text-decoration: none !important;"></a>', '?wp_tab_widget_notice_ignore=0');
679
+ echo "</p></div>";
680
+ }
681
+ }
682
+
683
+ add_action('admin_init', 'wp_tab_widget_notice_ignore');
684
+ function wp_tab_widget_notice_ignore() {
685
+ global $current_user;
686
+ $user_id = $current_user->ID;
687
+ /* If user clicks to ignore the notice, add that to their user meta */
688
+ if ( isset($_GET['wp_tab_widget_notice_ignore']) && '0' == $_GET['wp_tab_widget_notice_ignore'] ) {
689
+ add_user_meta($user_id, 'wp_tab_widget_ignore_notice', 'true', true);
690
+ }
691
+ }
692
  ?>