kk Star Ratings - Version 2.4

Version Description

  • Fix: Upper and Lower boundary limits for rating. Oops, had not noticed this before.
  • Fix: Fuelspeed. Strange! no one ever complained about it.
  • Update: Revamped the entire javascript (normal: 6.03KB, minified: 4.29KB).
  • Update: Two fixed decimal points for average and percentage instead of one.
  • Update: Icon star color from grey to yellow.
  • Added: Efficient fetching of ratings. No matter how many ratings you may have on a page, they will all be fetched in a single go :)
  • Added: Rating column can now be sorted in the admin screen.
Download this release

Release Info

Developer bhittani
Plugin Icon 128x128 kk Star Ratings
Version 2.4
Comparing to
See all releases

Code changes from version 2.3.1 to 2.4

Files changed (6) hide show
  1. icon.png +0 -0
  2. index.php +67 -29
  3. js.js +181 -150
  4. js.min.js +11 -0
  5. readme.txt +15 -2
  6. shortcode/mce/kkstarratings/icon.png +0 -0
icon.png CHANGED
Binary file
index.php CHANGED
@@ -4,7 +4,7 @@
4
  Plugin Name: kk Star Ratings
5
  Plugin URI: http://wakeusup.com/2011/05/kk-star-ratings/
6
  Description: Renewed from the ground up(as of v2.0), clean, animated and light weight ratings feature for your blog. With kk Star Ratings, you can <strong>allow your blog posts to be rated by your blog visitors</strong>. It also includes a <strong>widget</strong> which you can add to your sidebar to show the top rated post. Wait! There is more to it. Enjoy the extensive options you can set to customize this plugin.
7
- Version: 2.3.1
8
  Author: Kamal Khan
9
  Author URI: http://bhittani.com
10
  License: GPLv2 or later
@@ -63,12 +63,12 @@ if(!class_exists('BhittaniPlugin_kkStarRatings')) :
63
  $Params['ajaxurl'] = admin_url('admin-ajax.php');
64
  $Params['func'] = 'kksr_ajax';
65
  $Params['msg'] = parent::get_options('kksr_init_msg');
66
- $Params['fueldspeed'] = parent::get_options('kksr_js_fuelspeed');
67
  $Params['thankyou'] = parent::get_options('kksr_js_thankyou');
68
  $Params['error_msg'] = parent::get_options('kksr_js_error');
69
  $Params['tooltip'] = parent::get_options('kksr_tooltip');
70
  $Params['tooltips'] = parent::get_options('kksr_tooltips');
71
- $this->enqueue_js('js', self::file_uri('js.js'), $this->ver, array('jquery'), $Params, false, true);
72
  }
73
  /** function/method
74
  * Usage: hook js admin - helper
@@ -169,7 +169,7 @@ if(!class_exists('BhittaniPlugin_kkStarRatings')) :
169
  $Options['kksr_column'] = isset($Old_plugin['column']) ? $Old_plugin['column'] : $opt_column;
170
 
171
  // Upgrade from old plugin(<2.0) to renewed plugin(>=2.0)
172
- if($Old_plugin)
173
  {
174
  // Delete old options
175
  parent::delete_options('kk-ratings');
@@ -229,11 +229,8 @@ if(!class_exists('BhittaniPlugin_kkStarRatings')) :
229
  $Options['kksr_tooltips'] = base64_encode(serialize($Opt_tooltips));
230
  parent::update_options($Options);
231
  }
232
- if(parent::get_options('kksr_ver')!='2.1')
233
- {
234
- parent::update_options(array('kksr_grs'=>1));
235
- }
236
- parent::update_options(array('kksr_ver'=>2.1));
237
  }
238
  /** function/method
239
  * Usage: helper for hooking (registering) the menu
@@ -399,29 +396,34 @@ if(!class_exists('BhittaniPlugin_kkStarRatings')) :
399
 
400
  $Response = array();
401
 
402
- $total_stars = is_numeric(parent::get_options('kksr_stars')) ? parent::get_options('kksr_stars') : 5;
403
 
404
- $pid = $_POST['id'];
405
- $stars = $_POST['stars'];
 
406
  $ip = $_SERVER['REMOTE_ADDR'];
407
 
 
 
 
 
408
  $ratings = get_post_meta($pid, '_kksr_ratings', true) ? get_post_meta($pid, '_kksr_ratings', true) : 0;
409
  $casts = get_post_meta($pid, '_kksr_casts', true) ? get_post_meta($pid, '_kksr_casts', true) : 0;
410
 
411
  if($stars==0 && $ratings==0)
412
  {
413
- $Response['legend'] = parent::get_options('kksr_init_msg');
414
- $Response['disable'] = 'false';
415
- $Response['fuel'] = '0';
416
  do_action('kksr_init', $pid, false, false);
417
  }
418
  else
419
  {
420
  $nratings = $ratings + ($stars/($total_stars/5));
421
  $ncasts = $casts + ($stars>0);
422
- $avg = $nratings ? round($nratings/$ncasts,1) : 0;
423
- $per = $nratings ? round((($nratings/$ncasts)/5)*100) : 0;
424
- $Response['disable'] = 'false';
425
  if($stars)
426
  {
427
  $Ips = get_post_meta($pid, '_kksr_ips', true) ? unserialize(base64_decode(get_post_meta($pid, '_kksr_ips', true))) : array();
@@ -434,22 +436,25 @@ if(!class_exists('BhittaniPlugin_kkStarRatings')) :
434
  update_post_meta($pid, '_kksr_casts', $ncasts);
435
  update_post_meta($pid, '_kksr_ips', $ips);
436
  update_post_meta($pid, '_kksr_avg', $avg);
437
- $Response['disable'] = parent::get_options('kksr_unique') ? 'true' : 'false';
438
  do_action('kksr_rate', $pid, $stars, $ip);
439
  }
440
  else
441
  {
442
- do_action('kksr_init', $pid, ($avg*($total_stars/5)).'/'.$total_stars, $ncasts);
443
  }
444
  $legend = parent::get_options('kksr_legend');
445
  $legend = str_replace('[total]', $ncasts, $legend);
446
- $legend = str_replace('[avg]', ($avg*($total_stars/5)).'/'.$total_stars, $legend);
447
  $legend = str_replace('[s]', $ncasts==1?'':'s', $legend);
448
- $Response['legend'] = str_replace('[per]',$per.'%', $legend);
449
- $Response['fuel'] = $per;
450
  }
 
 
 
 
451
 
452
- $Response['success'] = 'true';
453
  echo json_encode($Response);
454
  die();
455
  }
@@ -587,14 +592,15 @@ if(!class_exists('BhittaniPlugin_kkStarRatings')) :
587
  }
588
  public function add_row($Columns, $id)
589
  {
590
- $total_stars = parent::get_options('kksr_stars');
591
  if(parent::get_options('kksr_column'))
592
  {
 
593
  $row = 'No ratings';
594
  $raw = (get_post_meta($id, '_kksr_ratings', true)?get_post_meta($id, '_kksr_ratings', true):0);
595
  if($raw)
596
  {
597
- $avg = '<strong>'.(get_post_meta($id, '_kksr_avg', true)?(get_post_meta($id, '_kksr_avg', true)*($total_stars/5)).'/'.$total_stars:'0').'</strong>';
 
598
  $cast = (get_post_meta($id, '_kksr_casts', true)?get_post_meta($id, '_kksr_casts', true):'0').' votes';
599
  $per = ($raw>0?ceil((($raw/$cast)/5)*100):0).'%';
600
  $row = $avg . ' (' . $per . ') ' . $cast;
@@ -605,6 +611,36 @@ if(!class_exists('BhittaniPlugin_kkStarRatings')) :
605
  }
606
  }
607
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
608
  public function grs_legend($legend, $id)
609
  {
610
  if(parent::get_options('kksr_grs'))
@@ -617,8 +653,8 @@ if(!class_exists('BhittaniPlugin_kkStarRatings')) :
617
  if($score)
618
  {
619
  $votes = get_post_meta($id, '_kksr_casts', true) ? get_post_meta($id, '_kksr_casts', true) : 0;
620
- $avg = $score ? round($score/$votes,1) : 0;
621
- $per = $score ? round((($score/$votes)/5)*100) : 0;
622
 
623
  $leg = str_replace('[total]', '<span property="v:votes">'.$votes.'</span>', $legend);
624
  $leg = str_replace('[avg]', '<span property="v:average">'.$avg.'</span>/<span property="v:best">'.$best.'</span>', $leg);
@@ -645,7 +681,7 @@ if(!class_exists('BhittaniPlugin_kkStarRatings')) :
645
  }
646
  }
647
 
648
- $kkStarRatings_obj = new BhittaniPlugin_kkStarRatings('bhittani_plugin_kksr', 'kk Star Ratings', '2.2');
649
 
650
  // Setup
651
  register_activation_hook(__FILE__, array($kkStarRatings_obj, 'activate'));
@@ -677,6 +713,8 @@ if(!class_exists('BhittaniPlugin_kkStarRatings')) :
677
  add_filter( 'manage_pages_columns', array($kkStarRatings_obj, 'add_column') );
678
  add_filter( 'manage_posts_custom_column', array($kkStarRatings_obj, 'add_row'), 10, 2 );
679
  add_filter( 'manage_pages_custom_column', array($kkStarRatings_obj, 'add_row'), 10, 2 );
 
 
680
 
681
  // For use in themes
682
  if(!function_exists('kk_star_ratings'))
4
  Plugin Name: kk Star Ratings
5
  Plugin URI: http://wakeusup.com/2011/05/kk-star-ratings/
6
  Description: Renewed from the ground up(as of v2.0), clean, animated and light weight ratings feature for your blog. With kk Star Ratings, you can <strong>allow your blog posts to be rated by your blog visitors</strong>. It also includes a <strong>widget</strong> which you can add to your sidebar to show the top rated post. Wait! There is more to it. Enjoy the extensive options you can set to customize this plugin.
7
+ Version: 2.4
8
  Author: Kamal Khan
9
  Author URI: http://bhittani.com
10
  License: GPLv2 or later
63
  $Params['ajaxurl'] = admin_url('admin-ajax.php');
64
  $Params['func'] = 'kksr_ajax';
65
  $Params['msg'] = parent::get_options('kksr_init_msg');
66
+ $Params['fuelspeed'] = (int) parent::get_options('kksr_js_fuelspeed');
67
  $Params['thankyou'] = parent::get_options('kksr_js_thankyou');
68
  $Params['error_msg'] = parent::get_options('kksr_js_error');
69
  $Params['tooltip'] = parent::get_options('kksr_tooltip');
70
  $Params['tooltips'] = parent::get_options('kksr_tooltips');
71
+ $this->enqueue_js('js', self::file_uri('js.min.js'), $this->ver, array('jquery'), $Params, false, true);
72
  }
73
  /** function/method
74
  * Usage: hook js admin - helper
169
  $Options['kksr_column'] = isset($Old_plugin['column']) ? $Old_plugin['column'] : $opt_column;
170
 
171
  // Upgrade from old plugin(<2.0) to renewed plugin(>=2.0)
172
+ if(!$ver_previous || version_compare($ver_previous, '2.0', '<'))
173
  {
174
  // Delete old options
175
  parent::delete_options('kk-ratings');
229
  $Options['kksr_tooltips'] = base64_encode(serialize($Opt_tooltips));
230
  parent::update_options($Options);
231
  }
232
+
233
+ parent::update_options(array('kksr_ver'=>$ver_current));
 
 
 
234
  }
235
  /** function/method
236
  * Usage: helper for hooking (registering) the menu
396
 
397
  $Response = array();
398
 
399
+ $total_stars = is_numeric(parent::get_options('kksr_stars')) ? parent::get_options('kksr_stars') : 5;
400
 
401
+ $stars = is_numeric($_POST['stars']) && ((int)$_POST['stars']>0) && ((int)$_POST['stars']<=$total_stars)
402
+ ? $_POST['stars']:
403
+ 0;
404
  $ip = $_SERVER['REMOTE_ADDR'];
405
 
406
+ $Ids = explode(',', $_POST['id']);
407
+
408
+ foreach($Ids as $pid) :
409
+
410
  $ratings = get_post_meta($pid, '_kksr_ratings', true) ? get_post_meta($pid, '_kksr_ratings', true) : 0;
411
  $casts = get_post_meta($pid, '_kksr_casts', true) ? get_post_meta($pid, '_kksr_casts', true) : 0;
412
 
413
  if($stars==0 && $ratings==0)
414
  {
415
+ $Response[$pid]['legend'] = parent::get_options('kksr_init_msg');
416
+ $Response[$pid]['disable'] = 'false';
417
+ $Response[$pid]['fuel'] = '0';
418
  do_action('kksr_init', $pid, false, false);
419
  }
420
  else
421
  {
422
  $nratings = $ratings + ($stars/($total_stars/5));
423
  $ncasts = $casts + ($stars>0);
424
+ $avg = $nratings ? number_format((float)($nratings/$ncasts), 2, '.', '') : 0;
425
+ $per = $nratings ? number_format((float)((($nratings/$ncasts)/5)*100), 2, '.', '') : 0;
426
+ $Response[$pid]['disable'] = 'false';
427
  if($stars)
428
  {
429
  $Ips = get_post_meta($pid, '_kksr_ips', true) ? unserialize(base64_decode(get_post_meta($pid, '_kksr_ips', true))) : array();
436
  update_post_meta($pid, '_kksr_casts', $ncasts);
437
  update_post_meta($pid, '_kksr_ips', $ips);
438
  update_post_meta($pid, '_kksr_avg', $avg);
439
+ $Response[$pid]['disable'] = parent::get_options('kksr_unique') ? 'true' : 'false';
440
  do_action('kksr_rate', $pid, $stars, $ip);
441
  }
442
  else
443
  {
444
+ do_action('kksr_init', $pid, number_format((float)($avg*($total_stars/5)), 2, '.', '').'/'.$total_stars, $ncasts);
445
  }
446
  $legend = parent::get_options('kksr_legend');
447
  $legend = str_replace('[total]', $ncasts, $legend);
448
+ $legend = str_replace('[avg]', number_format((float)($avg*($total_stars/5)), 2, '.', '').'/'.$total_stars, $legend);
449
  $legend = str_replace('[s]', $ncasts==1?'':'s', $legend);
450
+ $Response[$pid]['legend'] = str_replace('[per]',$per.'%', $legend);
451
+ $Response[$pid]['fuel'] = $per;
452
  }
453
+
454
+ $Response[$pid]['success'] = true;
455
+
456
+ endforeach;
457
 
 
458
  echo json_encode($Response);
459
  die();
460
  }
592
  }
593
  public function add_row($Columns, $id)
594
  {
 
595
  if(parent::get_options('kksr_column'))
596
  {
597
+ $total_stars = parent::get_options('kksr_stars');
598
  $row = 'No ratings';
599
  $raw = (get_post_meta($id, '_kksr_ratings', true)?get_post_meta($id, '_kksr_ratings', true):0);
600
  if($raw)
601
  {
602
+ $_avg = get_post_meta($id, '_kksr_avg', true);
603
+ $avg = '<strong>'.($_avg?((number_format((float)($_avg*($total_stars/5)), 2, '.', '')).'/'.$total_stars):'0').'</strong>';
604
  $cast = (get_post_meta($id, '_kksr_casts', true)?get_post_meta($id, '_kksr_casts', true):'0').' votes';
605
  $per = ($raw>0?ceil((($raw/$cast)/5)*100):0).'%';
606
  $row = $avg . ' (' . $per . ') ' . $cast;
611
  }
612
  }
613
  }
614
+ /** function/method
615
+ * Usage: Allow sorting of columns
616
+ * Arg(1): $Args (array)
617
+ * Return: (array)
618
+ */
619
+ public function sort_columns($Args)
620
+ {
621
+ $Args = array_merge($Args,
622
+ array('kk_star_ratings' => 'kk_star_ratings')
623
+ );
624
+ return wp_parse_args($Args);
625
+ }
626
+ /** function/method
627
+ * Usage: Allow sorting of columns - helper
628
+ * Arg(1): $Query (array)
629
+ * Return: null
630
+ */
631
+ public function sort_columns_helper($Query)
632
+ {
633
+ if(!is_admin())
634
+ {
635
+ return;
636
+ }
637
+ $orderby = $Query->get( 'orderby');
638
+ if($orderby=='kk_star_ratings')
639
+ {
640
+ $Query->set('meta_key','_kksr_avg');
641
+ $Query->set('orderby','meta_value_num');
642
+ }
643
+ }
644
  public function grs_legend($legend, $id)
645
  {
646
  if(parent::get_options('kksr_grs'))
653
  if($score)
654
  {
655
  $votes = get_post_meta($id, '_kksr_casts', true) ? get_post_meta($id, '_kksr_casts', true) : 0;
656
+ $avg = $score ? number_format((float)($score/$votes), 2, '.', '') : 0;
657
+ $per = $score ? number_format((float)((($score/$votes)/5)*100), 2, '.', '') : 0;
658
 
659
  $leg = str_replace('[total]', '<span property="v:votes">'.$votes.'</span>', $legend);
660
  $leg = str_replace('[avg]', '<span property="v:average">'.$avg.'</span>/<span property="v:best">'.$best.'</span>', $leg);
681
  }
682
  }
683
 
684
+ $kkStarRatings_obj = new BhittaniPlugin_kkStarRatings('bhittani_plugin_kksr', 'kk Star Ratings', '2.4');
685
 
686
  // Setup
687
  register_activation_hook(__FILE__, array($kkStarRatings_obj, 'activate'));
713
  add_filter( 'manage_pages_columns', array($kkStarRatings_obj, 'add_column') );
714
  add_filter( 'manage_posts_custom_column', array($kkStarRatings_obj, 'add_row'), 10, 2 );
715
  add_filter( 'manage_pages_custom_column', array($kkStarRatings_obj, 'add_row'), 10, 2 );
716
+ add_filter( 'manage_edit-post_sortable_columns', array($kkStarRatings_obj, 'sort_columns') );
717
+ add_filter( 'pre_get_posts', array($kkStarRatings_obj, 'sort_columns_helper') );
718
 
719
  // For use in themes
720
  if(!function_exists('kk_star_ratings'))
js.js CHANGED
@@ -1,174 +1,205 @@
 
 
 
 
 
 
 
 
 
 
1
 
2
- (function($){
3
-
4
- $.fn.kkstarratings = function(options) {
5
-
6
- var kksr_settings = {
7
- 'ajaxurl' : null,
8
- 'nonce' : null,
9
- 'func' : null,
10
- 'grs' : false,
11
- 'tooltip' : true,
12
- 'tooltips' : {
13
- "0":{"tip": "Poor", "color": "red"},
14
- "1":{"tip": "Fair", "color": "brown"},
15
- "2":{"tip": "Average", "color": "orange"},
16
- "3":{"tip": "Good", "color": "blue"},
17
- "4":{"tip": "Excellent", "color": "green"}
18
- },
19
- 'msg' : 'Rate this post',
20
- 'fuelspeed' : 400,
21
- 'thankyou' : 'Thank you for rating.',
22
- 'error_msg' : 'An error occured.'
23
- };
24
-
25
- return this.each(function() {
26
-
27
- if ( options ) {
28
- $.extend( kksr_settings, options );
29
- }
30
 
31
- var obj = $(this);
32
-
33
- function kksr_animate(obj)
34
- {
35
- if(!obj.hasClass('disabled'))
36
- {
37
- var legend = $('.kksr-legend', obj).html();
38
- var fuel = $('.kksr-fuel', obj).css('width');
39
- $('.kksr-stars a', obj).hover( function(){
40
- var stars = $(this).attr('href').split('#')[1];
41
- if(kksr_settings.tooltip!=0)
42
- {
43
- if(kksr_settings.tooltips[stars-1]!=null)
44
- {
45
- $('.kksr-legend', obj).html('<span style="color:'+kksr_settings.tooltips[stars-1].color+'">'+kksr_settings.tooltips[stars-1].tip+'</span>');
46
- }
47
- else
48
- {
49
- $('.kksr-legend', obj).html(legend);
50
- }
51
- }
52
- $('.kksr-fuel', obj).stop(true,true).css('width', '0%');
53
- $('.kksr-stars a', obj).each(function(index, element) {
54
- var a = $(this);
55
- var s = a.attr('href').split('#')[1];
56
- if(parseInt(s)<=parseInt(stars))
57
- {
58
- $('.kksr-stars a', obj).stop(true, true);
59
- a.hide().addClass('kksr-star').addClass('orange').fadeIn('fast');
60
- }
61
- });
62
- }, function(){
63
- $('.kksr-stars a', obj).removeClass('kksr-star').removeClass('orange');
64
- if(kksr_settings.tooltip!=0) $('.kksr-legend', obj).html(legend);
65
- $('.kksr-fuel', obj).stop(true,true).animate({'width':fuel}, kksr_settings.fuelspeed);
66
- }).unbind('click').click( function(){
67
- return kksr_click(obj, $(this).attr('href').split('#')[1]);
68
- });
69
- }
70
- else
71
- {
72
- $('.kksr-stars a', obj).unbind('click').click( function(){ return false; });
73
  }
74
  }
75
-
76
- function kksr_update(obj, per, legend, disable, is_fetch)
77
- {
78
- if(disable=='true')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
79
  {
80
- $('.kksr-fuel', obj).removeClass('yellow').addClass('orange');
81
- }
82
- $('.kksr-fuel', obj).stop(true, true).animate({'width':per}, kksr_settings.fuelspeed, 'linear', function(){
83
- if(disable=='true')
84
  {
85
- obj.addClass('disabled');
86
- $('.kksr-stars a', obj).unbind('hover');
87
  }
88
- if(!kksr_settings.grs || !is_fetch)
89
  {
90
- $('.kksr-legend', obj).stop(true,true).hide().html(legend?legend:kksr_settings.msg).fadeIn('slow', function(){
91
- kksr_animate(obj);
92
- });
93
  }
94
- else
 
 
 
 
 
95
  {
96
- kksr_animate(obj);
 
97
  }
98
  });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
99
  }
100
-
101
- function kksr_click(obj, stars)
102
  {
103
- $('.kksr-stars a', obj).unbind('hover').unbind('click').removeClass('kksr-star').removeClass('orange').click( function(){ return false; });
104
-
105
- var legend = $('.kksr-legend', obj).html();
106
- var fuel = $('.kksr-fuel', obj).css('width');
107
-
108
- kksr_fetch(obj, stars, fuel, legend, false);
109
-
110
- return false;
111
  }
112
-
113
- function kksr_fetch(obj, stars, fallback_fuel, fallback_legend, is_fetch)
114
  {
115
- $.ajax({
116
- url: kksr_settings.ajaxurl,
117
- data: 'action='+kksr_settings.func+'&id='+obj.attr('data-id')+'&stars='+stars+'&_wpnonce='+kksr_settings.nonce,
118
- type: "post",
119
- dataType: "json",
120
- beforeSend: function(){
121
- $('.kksr-fuel', obj).animate({'width':'0%'}, kksr_settings.fuelspeed);
122
- if(stars)
123
- {
124
- $('.kksr-legend', obj).fadeOut('fast', function(){
125
- $('.kksr-legend', obj).html('<span style="color: green">'+kksr_settings.thankyou+'</span>');
126
- }).fadeIn('slow');
127
- }
128
- },
129
- success: function(response){
130
- if(response.success=='true')
131
- {
132
- kksr_update(obj, response.fuel+'%', response.legend, response.disable, is_fetch);
133
- }
134
- else
135
- {
136
- kksr_update(obj, fallback_fuel, fallback_legend, false, is_fetch);
137
- }
138
- },
139
- complete: function(){
140
-
141
- },
142
- error: function(e){
143
- $('.kksr-legend', obj).fadeOut('fast', function(){
144
- $('.kksr-legend', obj).html('<span style="color: red">'+kksr_settings.error_msg+'</span>');
145
- }).fadeIn('slow', function(){
146
- kksr_update(obj, fallback_fuel, fallback_legend, false, is_fetch);
147
- });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
148
  }
149
  });
 
 
 
 
 
 
 
 
 
 
150
  }
151
-
152
- kksr_fetch(obj, 0, '0%', kksr_settings.msg, true);
153
-
154
  });
155
-
156
- };
157
-
158
- })( jQuery );
159
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
160
 
161
  jQuery(document).ready( function($){
162
- $('.kk-star-ratings').kkstarratings({
163
- 'ajaxurl' : bhittani_plugin_kksr_js.ajaxurl,
164
- 'func' : bhittani_plugin_kksr_js.func,
165
- 'nonce' : bhittani_plugin_kksr_js.nonce,
166
- 'grs' : bhittani_plugin_kksr_js.grs,
167
- 'tooltip' : bhittani_plugin_kksr_js.tooltip,
168
- 'tooltips' : bhittani_plugin_kksr_js.tooltips,
169
- 'msg' : bhittani_plugin_kksr_js.msg,
170
- 'fuelspeed' : bhittani_plugin_kksr_js.fuelspeed,
171
- 'thankyou' : bhittani_plugin_kksr_js.thankyou,
172
- 'error_msg' : bhittani_plugin_kksr_js.error_msg
173
- });
174
  });
1
+ /**
2
+ * Plugin: kk Star Ratings
3
+ *
4
+ * Description: js for the wordpress plugin kk Star Ratings.
5
+ *
6
+ * @package kk Star Ratings
7
+ * @subpackage WordPress Plugin
8
+ * @author Kamal Khan
9
+ * @plugin_uri http://wakeusup.com/2011/05/kk-star-ratings/
10
+ */
11
 
12
+ (function($, window, document, undefined){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
 
14
+ $.fn.kkstarratings = function(options)
15
+ {
16
+ $.fn.kkstarratings.options = $.extend({
17
+ ajaxurl : null,
18
+ nonce : null,
19
+ func : null,
20
+ grs : false,
21
+ msg : 'Rate this post',
22
+ fuelspeed : 400,
23
+ thankyou : 'Thank you for rating.',
24
+ error_msg : 'An error occured.',
25
+ tooltip : true,
26
+ tooltips : {
27
+ 0 : {
28
+ tip : "Poor",
29
+ color : "red"
30
+ },
31
+ 1 : {
32
+ tip : "Fair",
33
+ color : "brown"
34
+ },
35
+ 2 : {
36
+ tip : "Average",
37
+ color : "orange"
38
+ },
39
+ 3 : {
40
+ tip : "Good",
41
+ color : "blue"
42
+ },
43
+ 4 : {
44
+ tip : "Excellent",
45
+ color : "green"
 
 
 
 
 
 
 
 
 
 
46
  }
47
  }
48
+ }, $.fn.kkstarratings.options, options ? options : {});
49
+
50
+ var Objs = [];
51
+ this.each(function(){
52
+ Objs.push($(this));
53
+ });
54
+
55
+ $.fn.kkstarratings.fetch(Objs, 0, '0%', $.fn.kkstarratings.options.msg, true);
56
+
57
+ return this.each(function(){});
58
+
59
+ };
60
+
61
+ $.fn.kkstarratings.animate = function(obj)
62
+ {
63
+ if(!obj.hasClass('disabled'))
64
+ {
65
+ var legend = $('.kksr-legend', obj).html(),
66
+ fuel = $('.kksr-fuel', obj).css('width');
67
+ $('.kksr-stars a', obj).hover( function(){
68
+ var stars = $(this).attr('href').split('#')[1];
69
+ if($.fn.kkstarratings.options.tooltip!=0)
70
  {
71
+ if($.fn.kkstarratings.options.tooltips[stars-1]!=null)
 
 
 
72
  {
73
+ $('.kksr-legend', obj).html('<span style="color:'+$.fn.kkstarratings.options.tooltips[stars-1].color+'">'+$.fn.kkstarratings.options.tooltips[stars-1].tip+'</span>');
 
74
  }
75
+ else
76
  {
77
+ $('.kksr-legend', obj).html(legend);
 
 
78
  }
79
+ }
80
+ $('.kksr-fuel', obj).stop(true,true).css('width', '0%');
81
+ $('.kksr-stars a', obj).each(function(index, element) {
82
+ var a = $(this),
83
+ s = a.attr('href').split('#')[1];
84
+ if(parseInt(s)<=parseInt(stars))
85
  {
86
+ $('.kksr-stars a', obj).stop(true, true);
87
+ a.hide().addClass('kksr-star').addClass('orange').fadeIn('fast');
88
  }
89
  });
90
+ }, function(){
91
+ $('.kksr-stars a', obj).removeClass('kksr-star').removeClass('orange');
92
+ if($.fn.kkstarratings.options.tooltip!=0) $('.kksr-legend', obj).html(legend);
93
+ $('.kksr-fuel', obj).stop(true,true).animate({'width':fuel}, $.fn.kkstarratings.options.fuelspeed);
94
+ }).unbind('click').click( function(){
95
+ return $.fn.kkstarratings.click(obj, $(this).attr('href').split('#')[1]);
96
+ });
97
+ }
98
+ else
99
+ {
100
+ $('.kksr-stars a', obj).unbind('click').click( function(){ return false; });
101
+ }
102
+ };
103
+
104
+ $.fn.kkstarratings.update = function(obj, per, legend, disable, is_fetch)
105
+ {
106
+ if(disable=='true')
107
+ {
108
+ $('.kksr-fuel', obj).removeClass('yellow').addClass('orange');
109
+ }
110
+ $('.kksr-fuel', obj).stop(true, true).animate({'width':per}, $.fn.kkstarratings.options.fuelspeed, 'linear', function(){
111
+ if(disable=='true')
112
+ {
113
+ obj.addClass('disabled');
114
+ $('.kksr-stars a', obj).unbind('hover');
115
  }
116
+ if(!$.fn.kkstarratings.options.grs || !is_fetch)
 
117
  {
118
+ $('.kksr-legend', obj).stop(true,true).hide().html(legend?legend:$.fn.kkstarratings.options.msg).fadeIn('slow', function(){
119
+ $.fn.kkstarratings.animate(obj);
120
+ });
 
 
 
 
 
121
  }
122
+ else
 
123
  {
124
+ $.fn.kkstarratings.animate(obj);
125
+ }
126
+ });
127
+ };
128
+
129
+ $.fn.kkstarratings.click = function(obj, stars)
130
+ {
131
+ $('.kksr-stars a', obj).unbind('hover').unbind('click').removeClass('kksr-star').removeClass('orange').click( function(){ return false; });
132
+
133
+ var legend = $('.kksr-legend', obj).html(),
134
+ fuel = $('.kksr-fuel', obj).css('width');
135
+
136
+ $.fn.kkstarratings.fetch(obj, stars, fuel, legend, false);
137
+
138
+ return false;
139
+ };
140
+
141
+ $.fn.kkstarratings.fetch = function(obj, stars, fallback_fuel, fallback_legend, is_fetch)
142
+ {
143
+ var postids = [];
144
+ $.each(obj, function(){
145
+ postids.push($(this).attr('data-id'));
146
+ });
147
+ $.ajax({
148
+ url: $.fn.kkstarratings.options.ajaxurl,
149
+ data: 'action='+$.fn.kkstarratings.options.func+'&id='+postids+'&stars='+stars+'&_wpnonce='+$.fn.kkstarratings.options.nonce,
150
+ type: "post",
151
+ dataType: "json",
152
+ beforeSend: function(){
153
+ $('.kksr-fuel', obj).animate({'width':'0%'}, $.fn.kkstarratings.options.fuelspeed);
154
+ if(stars)
155
+ {
156
+ $('.kksr-legend', obj).fadeOut('fast', function(){
157
+ $('.kksr-legend', obj).html('<span style="color: green">'+$.fn.kkstarratings.options.thankyou+'</span>');
158
+ }).fadeIn('slow');
159
+ }
160
+ },
161
+ success: function(response){
162
+ $.each(obj, function(){
163
+ var current = $(this),
164
+ current_id = current.attr('data-id');
165
+ if(response[current_id].success)
166
+ {
167
+ $.fn.kkstarratings.update(current, response[current_id].fuel+'%', response[current_id].legend, response[current_id].disable, is_fetch);
168
+ }
169
+ else
170
+ {
171
+ $.fn.kkstarratings.update(current, fallback_fuel, fallback_legend, false, is_fetch);
172
  }
173
  });
174
+ },
175
+ complete: function(){
176
+
177
+ },
178
+ error: function(e){
179
+ $('.kksr-legend', obj).fadeOut('fast', function(){
180
+ $('.kksr-legend', obj).html('<span style="color: red">'+$.fn.kkstarratings.options.error_msg+'</span>');
181
+ }).fadeIn('slow', function(){
182
+ $.fn.kkstarratings.update(obj, fallback_fuel, fallback_legend, false, is_fetch);
183
+ });
184
  }
 
 
 
185
  });
186
+ };
 
 
 
187
 
188
+ $.fn.kkstarratings.options = {
189
+ ajaxurl : bhittani_plugin_kksr_js.ajaxurl,
190
+ func : bhittani_plugin_kksr_js.func,
191
+ nonce : bhittani_plugin_kksr_js.nonce,
192
+ grs : bhittani_plugin_kksr_js.grs,
193
+ tooltip : bhittani_plugin_kksr_js.tooltip,
194
+ tooltips : bhittani_plugin_kksr_js.tooltips,
195
+ msg : bhittani_plugin_kksr_js.msg,
196
+ fuelspeed : bhittani_plugin_kksr_js.fuelspeed,
197
+ thankyou : bhittani_plugin_kksr_js.thankyou,
198
+ error_msg : bhittani_plugin_kksr_js.error_msg
199
+ };
200
+
201
+ })(jQuery, window, document);
202
 
203
  jQuery(document).ready( function($){
204
+ $('.kk-star-ratings').kkstarratings();
 
 
 
 
 
 
 
 
 
 
 
205
  });
js.min.js ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * Plugin: kk Star Ratings
3
+ *
4
+ * Description: js for the wordpress plugin kk Star Ratings.
5
+ *
6
+ * @package kk Star Ratings
7
+ * @subpackage WordPress Plugin
8
+ * @author Kamal Khan
9
+ * @plugin_uri http://wakeusup.com/2011/05/kk-star-ratings/
10
+ */
11
+ (function(c,b,a,d){c.fn.kkstarratings=function(e){c.fn.kkstarratings.options=c.extend({ajaxurl:null,nonce:null,func:null,grs:false,msg:"Rate this post",fuelspeed:400,thankyou:"Thank you for rating.",error_msg:"An error occured.",tooltip:true,tooltips:{0:{tip:"Poor",color:"red"},1:{tip:"Fair",color:"brown"},2:{tip:"Average",color:"orange"},3:{tip:"Good",color:"blue"},4:{tip:"Excellent",color:"green"}}},c.fn.kkstarratings.options,e?e:{});var f=[];this.each(function(){f.push(c(this))});c.fn.kkstarratings.fetch(f,0,"0%",c.fn.kkstarratings.options.msg,true);return this.each(function(){})};c.fn.kkstarratings.animate=function(g){if(!g.hasClass("disabled")){var f=c(".kksr-legend",g).html(),e=c(".kksr-fuel",g).css("width");c(".kksr-stars a",g).hover(function(){var h=c(this).attr("href").split("#")[1];if(c.fn.kkstarratings.options.tooltip!=0){if(c.fn.kkstarratings.options.tooltips[h-1]!=null){c(".kksr-legend",g).html('<span style="color:'+c.fn.kkstarratings.options.tooltips[h-1].color+'">'+c.fn.kkstarratings.options.tooltips[h-1].tip+"</span>")}else{c(".kksr-legend",g).html(f)}}c(".kksr-fuel",g).stop(true,true).css("width","0%");c(".kksr-stars a",g).each(function(j,k){var i=c(this),l=i.attr("href").split("#")[1];if(parseInt(l)<=parseInt(h)){c(".kksr-stars a",g).stop(true,true);i.hide().addClass("kksr-star").addClass("orange").fadeIn("fast")}})},function(){c(".kksr-stars a",g).removeClass("kksr-star").removeClass("orange");if(c.fn.kkstarratings.options.tooltip!=0){c(".kksr-legend",g).html(f)}c(".kksr-fuel",g).stop(true,true).animate({width:e},c.fn.kkstarratings.options.fuelspeed)}).unbind("click").click(function(){return c.fn.kkstarratings.click(g,c(this).attr("href").split("#")[1])})}else{c(".kksr-stars a",g).unbind("click").click(function(){return false})}};c.fn.kkstarratings.update=function(h,e,g,f,i){if(f=="true"){c(".kksr-fuel",h).removeClass("yellow").addClass("orange")}c(".kksr-fuel",h).stop(true,true).animate({width:e},c.fn.kkstarratings.options.fuelspeed,"linear",function(){if(f=="true"){h.addClass("disabled");c(".kksr-stars a",h).unbind("hover")}if(!c.fn.kkstarratings.options.grs||!i){c(".kksr-legend",h).stop(true,true).hide().html(g?g:c.fn.kkstarratings.options.msg).fadeIn("slow",function(){c.fn.kkstarratings.animate(h)})}else{c.fn.kkstarratings.animate(h)}})};c.fn.kkstarratings.click=function(h,e){c(".kksr-stars a",h).unbind("hover").unbind("click").removeClass("kksr-star").removeClass("orange").click(function(){return false});var g=c(".kksr-legend",h).html(),f=c(".kksr-fuel",h).css("width");c.fn.kkstarratings.fetch(h,e,f,g,false);return false};c.fn.kkstarratings.fetch=function(g,e,i,h,j){var f=[];c.each(g,function(){f.push(c(this).attr("data-id"))});c.ajax({url:c.fn.kkstarratings.options.ajaxurl,data:"action="+c.fn.kkstarratings.options.func+"&id="+f+"&stars="+e+"&_wpnonce="+c.fn.kkstarratings.options.nonce,type:"post",dataType:"json",beforeSend:function(){c(".kksr-fuel",g).animate({width:"0%"},c.fn.kkstarratings.options.fuelspeed);if(e){c(".kksr-legend",g).fadeOut("fast",function(){c(".kksr-legend",g).html('<span style="color: green">'+c.fn.kkstarratings.options.thankyou+"</span>")}).fadeIn("slow")}},success:function(k){c.each(g,function(){var m=c(this),l=m.attr("data-id");if(k[l].success){c.fn.kkstarratings.update(m,k[l].fuel+"%",k[l].legend,k[l].disable,j)}else{c.fn.kkstarratings.update(m,i,h,false,j)}})},complete:function(){},error:function(k){c(".kksr-legend",g).fadeOut("fast",function(){c(".kksr-legend",g).html('<span style="color: red">'+c.fn.kkstarratings.options.error_msg+"</span>")}).fadeIn("slow",function(){c.fn.kkstarratings.update(g,i,h,false,j)})}})};c.fn.kkstarratings.options={ajaxurl:bhittani_plugin_kksr_js.ajaxurl,func:bhittani_plugin_kksr_js.func,nonce:bhittani_plugin_kksr_js.nonce,grs:bhittani_plugin_kksr_js.grs,tooltip:bhittani_plugin_kksr_js.tooltip,tooltips:bhittani_plugin_kksr_js.tooltips,msg:bhittani_plugin_kksr_js.msg,fuelspeed:bhittani_plugin_kksr_js.fuelspeed,thankyou:bhittani_plugin_kksr_js.thankyou,error_msg:bhittani_plugin_kksr_js.error_msg}})(jQuery,window,document);jQuery(document).ready(function(a){a(".kk-star-ratings").kkstarratings()});
readme.txt CHANGED
@@ -11,7 +11,7 @@ Requires at least: 3.0
11
 
12
  Tested up to: 3.5.1
13
 
14
- Stable tag: 2.3.1
15
 
16
 
17
  kk Star Ratings allows blog visitors to involve and interact more effectively with your website by rating posts.
@@ -43,6 +43,10 @@ Enhanced settings page where you can adjust quite anything you may need to. You
43
 
44
  1. Google rich snippets. Ratings will be shown in google search results :)
45
 
 
 
 
 
46
  1. Ratings column in your admin posts/pages screen so you can view the statistics at comfort.
47
 
48
  1. Restrict votings per unique ip.
@@ -128,8 +132,17 @@ Visit the help tab in the settings to find out what you can do.
128
 
129
  == Changelog ==
130
 
 
 
 
 
 
 
 
 
 
131
  = 2.3.1 =
132
- * Updated: Framework updated for no conflict mode with other kk plugins.
133
 
134
  = 2.3 =
135
  * Added: Ability to exclude specific category(s).
11
 
12
  Tested up to: 3.5.1
13
 
14
+ Stable tag: 2.4
15
 
16
 
17
  kk Star Ratings allows blog visitors to involve and interact more effectively with your website by rating posts.
43
 
44
  1. Google rich snippets. Ratings will be shown in google search results :)
45
 
46
+ 1. Have a thousand of ratings on a single page? No worries, all will be fetched in a single request (as of v2.4).
47
+
48
+ 1. Revamped the entire frontend js (normal: 6.03KB, minified: 4.29KB)
49
+
50
  1. Ratings column in your admin posts/pages screen so you can view the statistics at comfort.
51
 
52
  1. Restrict votings per unique ip.
132
 
133
  == Changelog ==
134
 
135
+ = 2.4 =
136
+ * Fix: Upper and Lower boundary limits for rating. Oops, had not noticed this before.
137
+ * Fix: Fuelspeed. Strange! no one ever complained about it.
138
+ * Update: Revamped the entire javascript (normal: 6.03KB, minified: 4.29KB).
139
+ * Update: Two fixed decimal points for average and percentage instead of one.
140
+ * Update: Icon star color from grey to yellow.
141
+ * Added: Efficient fetching of ratings. No matter how many ratings you may have on a page, they will all be fetched in a single go :)
142
+ * Added: Rating column can now be sorted in the admin screen.
143
+
144
  = 2.3.1 =
145
+ * Update: Framework updated for no conflict mode with other kk plugins.
146
 
147
  = 2.3 =
148
  * Added: Ability to exclude specific category(s).
shortcode/mce/kkstarratings/icon.png CHANGED
Binary file