kk Star Ratings - Version 2.5.2

Version Description

  • Fix: See PR #6
  • Fix: See PR #24
  • Fix: See PR #25
  • Fix: See PR #28
Download this release

Release Info

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

Code changes from version 2.5.1 to 2.5.2

Files changed (6) hide show
  1. gray.png +0 -0
  2. index.php +739 -743
  3. orange.png +0 -0
  4. readme.txt +249 -243
  5. widget.php +102 -104
  6. yellow.png +0 -0
gray.png CHANGED
Binary file
index.php CHANGED
@@ -1,743 +1,739 @@
1
- <?php
2
-
3
- /*
4
- Plugin Name: kk Star Ratings
5
- Plugin URI: https://github.com/kamalkhan/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.5.1
8
- Author: Kamal Khan
9
- Author URI: http://bhittani.com
10
- License: GPLv2 or later
11
- */
12
-
13
- require_once 'bhittani-framework/plugin.php';
14
-
15
- if(!class_exists('BhittaniPlugin_kkStarRatings')) :
16
-
17
- class BhittaniPlugin_kkStarRatings extends BhittaniPlugin
18
- {
19
- private $_Menus;
20
-
21
- public function __construct($id, $nick, $ver)
22
- {
23
- parent::__construct($id, $nick, $ver);
24
- $this->_Menus = array();
25
- }
26
- /**
27
- * File uri
28
- *
29
- * @since 1.0 Initially defined
30
- *
31
- * @param string $path Path to file.
32
- *
33
- * @return string full uri.
34
- */
35
- public static function file_uri($path)
36
- {
37
- return plugins_url($path, __FILE__);
38
- }
39
- /**
40
- * File path
41
- *
42
- * @since 1.0 Initially defined
43
- *
44
- * @param string $path Path to file.
45
- *
46
- * @return string full path.
47
- */
48
- public static function file_path($path)
49
- {
50
- return dirname(__FILE__).'/'.$path;
51
- }
52
- /** function/method
53
- * Usage: hook js frontend
54
- * Arg(0): null
55
- * Return: void
56
- */
57
- public function js()
58
- {
59
- $nonce = wp_create_nonce($this->id);
60
- $Params = array();
61
- $Params['nonce'] = $nonce; //for security
62
- $Params['grs'] = parent::get_options('kksr_grs') ? true : false;
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
75
- * Arg(0): null
76
- * Return: void
77
- */
78
- public function js_admin()
79
- {
80
- $nonce = wp_create_nonce($this->id);
81
- $Params = array();
82
- $Params['nonce'] = $nonce;
83
- $Params['func_reset'] = 'kksr_admin_reset_ajax';
84
- $this->enqueue_js('js_admin', self::file_uri('js_admin.js'), $this->ver, array('jquery', 'bhittaniplugin_admin_script'), $Params);
85
- }
86
- /** function/method
87
- * Usage: hook admin scripts
88
- * Arg(0): null
89
- * Return: void
90
- */
91
- public function admin_scripts()
92
- {
93
- foreach($this->_Menus as $menu)
94
- {
95
- add_action('admin_print_scripts-'.$menu, array(&$this, 'js_admin'));
96
- }
97
- }
98
- /** function/method
99
- * Usage: hook css
100
- * Arg(0): null
101
- * Return: void
102
- */
103
- public function css()
104
- {
105
- $this->enqueue_css('', self::file_uri('css.css'));
106
- }
107
- /** function/method
108
- * Usage: hook custom css
109
- * Arg(0): null
110
- * Return: void
111
- */
112
- public function css_custom()
113
- {
114
- $stars = parent::get_options('kksr_stars') ? parent::get_options('kksr_stars') : 5;
115
-
116
- $star_w = parent::get_options('kksr_stars_w') ? parent::get_options('kksr_stars_w') : 24;
117
- $star_h = parent::get_options('kksr_stars_h') ? parent::get_options('kksr_stars_h') : 24;
118
-
119
- $star_gray = parent::get_options('kksr_stars_gray');
120
- $star_yellow = parent::get_options('kksr_stars_yellow');
121
- $star_orange = parent::get_options('kksr_stars_orange');
122
-
123
- echo '<style>';
124
-
125
- echo '.kk-star-ratings { width:'.($star_w*$stars).'px; }';
126
- echo '.kk-star-ratings .kksr-stars a { width:'.($star_w).'px; }';
127
- echo '.kk-star-ratings .kksr-stars, .kk-star-ratings .kksr-stars .kksr-fuel, .kk-star-ratings .kksr-stars a { height:'.($star_h).'px; }';
128
-
129
- echo $star_gray ? '.kk-star-ratings .kksr-star.gray { background-image: url('.$star_gray.'); }' : '';
130
- echo $star_yellow ? '.kk-star-ratings .kksr-star.yellow { background-image: url('.$star_yellow.'); }' : '';
131
- echo $star_orange ? '.kk-star-ratings .kksr-star.orange { background-image: url('.$star_orange.'); }' : '';
132
-
133
- echo '</style>';
134
- }
135
- /** function/method
136
- * Usage: Setting defaults and backwards compatibility
137
- * Arg(0): null
138
- * Return: void
139
- */
140
- public function activate()
141
- {
142
- $ver_current = $this->ver;
143
- $ver_previous = parent::get_options('kksr_ver') ? parent::get_options('kksr_ver') : false;
144
- $Old_plugin = parent::get_options('kk-ratings');
145
-
146
- $opt_enable = 1; // 1|0
147
- $opt_clear = 0; // 1|0
148
- $opt_show_in_home = 0; // 1|0
149
- $opt_show_in_archives = 0; // 1|0
150
- $opt_show_in_posts = 1; // 1|0
151
- $opt_show_in_pages = 0; // 1|0
152
- $opt_unique = 0; // 1|0
153
- $opt_position = 'top-left'; // 'top-left', 'top-right', 'bottom-left', 'bottom-right'
154
- $opt_legend = '[avg] ([per]) [total] vote[s]'; // [total]=total ratings, [avg]=average, [per]=percentage [s]=singular/plural
155
- $opt_init_msg = 'Rate this post'; // string
156
- $opt_column = 1; // 1|0
157
-
158
- $Options = array();
159
- $Options['kksr_enable'] = isset($Old_plugin['enable']) ? $Old_plugin['enable'] : $opt_enable;
160
- $Options['kksr_clear'] = isset($Old_plugin['clear']) ? $Old_plugin['clear'] : $opt_clear;
161
- $Options['kksr_show_in_home'] = isset($Old_plugin['show_in_home']) ? $Old_plugin['show_in_home'] : $opt_show_in_home;
162
- $Options['kksr_show_in_archives'] = isset($Old_plugin['show_in_archives']) ? $Old_plugin['show_in_archives'] : $opt_show_in_archives;
163
- $Options['kksr_show_in_posts'] = isset($Old_plugin['show_in_posts']) ? $Old_plugin['show_in_posts'] : $opt_show_in_posts;
164
- $Options['kksr_show_in_pages'] = isset($Old_plugin['show_in_pages']) ? $Old_plugin['show_in_pages'] : $opt_show_in_pages;
165
- $Options['kksr_unique'] = isset($Old_plugin['unique']) ? $Old_plugin['unique'] : $opt_unique;
166
- $Options['kksr_position'] = isset($Old_plugin['position']) ? $Old_plugin['position'] : $opt_position;
167
- $Options['kksr_legend'] = isset($Old_plugin['legend']) ? $Old_plugin['legend'] : $opt_legend;
168
- $Options['kksr_init_msg'] = isset($Old_plugin['init_msg']) ? $Old_plugin['init_msg'] : $opt_init_msg;
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');
176
-
177
- // Update previous ratings
178
- global $wpdb;
179
- $table = $wpdb->prefix . 'postmeta';
180
- $Posts = $wpdb->get_results("SELECT a.ID, b.meta_key, b.meta_value
181
- FROM " . $wpdb->posts . " a, $table b
182
- WHERE a.ID=b.post_id AND
183
- (
184
- b.meta_key='_kk_ratings_ratings' OR
185
- b.meta_key='_kk_ratings_casts' OR
186
- b.meta_key='_kk_ratings_ips'
187
- ) ORDER BY a.ID ASC");
188
- $Wrap = array();
189
- foreach ($Posts as $post)
190
- {
191
- $Wrap[$post->ID]['id'] = $post->ID;
192
- $Wrap[$post->ID][$post->meta_key] = $post->meta_value;
193
- }
194
- foreach($Wrap as $p)
195
- {
196
- update_post_meta($p['id'], '_kksr_ratings', $p['_kk_ratings_ratings']);
197
- update_post_meta($p['id'], '_kksr_casts', $p['_kk_ratings_casts']);
198
- $Ips = array();
199
- $Ips = explode('|', $p['_kk_ratings_ips']);
200
- $ip = base64_encode(serialize($Ips));
201
- update_post_meta($p['id'], '_kksr_ips', $ip);
202
- update_post_meta($p['id'], '_kksr_avg', round($p['_kk_ratings_ratings']/$p['_kk_ratings_casts'],1));
203
- }
204
- }
205
- if(!parent::get_options('kksr_ver'))
206
- {
207
- $Options['kksr_ver'] = $ver_current;
208
- $Options['kksr_stars'] = 5;
209
- $Options['kksr_stars_w'] = 24;
210
- $Options['kksr_stars_h'] = 24;
211
- $Options['kksr_stars_gray'] = 0;
212
- $Options['kksr_stars_yellow'] = 0;
213
- $Options['kksr_stars_orange'] = 0;
214
- $Options['kksr_js_fuelspeed'] = 400;
215
- $Options['kksr_js_thankyou'] = 'Thank you for your vote';
216
- $Options['kksr_js_error'] = 'An error occurred';
217
- $Options['kksr_tooltip'] = 1;
218
- $Opt_tooltips = array();
219
- $Opt_tooltips[0]['color'] = 'red';
220
- $Opt_tooltips[0]['tip'] = 'Poor';
221
- $Opt_tooltips[1]['color'] = 'brown';
222
- $Opt_tooltips[1]['tip'] = 'Fair';
223
- $Opt_tooltips[2]['color'] = 'orange';
224
- $Opt_tooltips[2]['tip'] = 'Average';
225
- $Opt_tooltips[3]['color'] = 'blue';
226
- $Opt_tooltips[3]['tip'] = 'Good';
227
- $Opt_tooltips[4]['color'] = 'green';
228
- $Opt_tooltips[4]['tip'] = 'Excellent';
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
237
- * Arg(0): null
238
- * Return: void
239
- */
240
- public function menu()
241
- {
242
- // Create main menu tab
243
- $this->_Menus[] = add_menu_page(
244
- $this->nick.' - Settings',
245
- $this->nick,
246
- 'manage_options',
247
- $this->id.'_settings',
248
- array(&$this, 'options_general'),
249
- self::file_uri('icon.png')
250
- );
251
- // Create images menu tab
252
- $this->_Menus[] = add_submenu_page(
253
- $this->id.'_settings',
254
- $this->nick.' - Settings',
255
- 'Settings',
256
- 'manage_options',
257
- $this->id.'_settings',
258
- array(&$this, 'options_general')
259
- );
260
- // Create images menu tab
261
- $this->_Menus[] = add_submenu_page(
262
- $this->id.'_settings',
263
- $this->nick.' - Stars',
264
- 'Stars',
265
- 'manage_options',
266
- $this->id.'_settings_stars',
267
- array(&$this, 'options_stars')
268
- );
269
- // Create tooltips menu tab
270
- $this->_Menus[] = add_submenu_page(
271
- $this->id.'_settings',
272
- $this->nick.' - Tooltips',
273
- 'Tooltips',
274
- 'manage_options',
275
- $this->id.'_settings_tooltips',
276
- array(&$this, 'options_tooltips')
277
- );
278
- // Create reset menu tab
279
- $this->_Menus[] = add_submenu_page(
280
- $this->id.'_settings',
281
- $this->nick.' - Reset',
282
- 'Reset',
283
- 'manage_options',
284
- $this->id.'_settings_reset',
285
- array(&$this, 'options_reset')
286
- );
287
- // Create info menu tab
288
- $this->_Menus[] = add_submenu_page(
289
- $this->id.'_settings',
290
- $this->nick.' - Help',
291
- 'Help',
292
- 'manage_options',
293
- $this->id.'_settings_info',
294
- array(&$this, 'options_info')
295
- );
296
- }
297
- /** function/method
298
- * Usage: show options/settings form page
299
- * Arg(0): null
300
- * Return: void
301
- */
302
- public function options_page($opt)
303
- {
304
- if (!current_user_can('manage_options'))
305
- {
306
- wp_die( __('You do not have sufficient permissions to access this page.') );
307
- }
308
- $sidebar = true;
309
- $h3 = 'kk Star Ratings';
310
- $Url = array(
311
- // array(
312
- // 'title' => 'Github Repository',
313
- // 'link' => 'https://github.com/kamalkhan/kk-star-ratings'
314
- // ),
315
- // array(
316
- // 'title' => 'Changelog',
317
- // 'link' => '#'
318
- // )
319
- );
320
- include self::file_path('admin.php');
321
- }
322
- /** function/method
323
- * Usage: show general options
324
- * Arg(0): null
325
- * Return: void
326
- */
327
- public function options_general()
328
- {
329
- $this->options_page('general');
330
- }
331
- /** function/method
332
- * Usage: show images options
333
- * Arg(0): null
334
- * Return: void
335
- */
336
- public function options_stars()
337
- {
338
- $this->options_page('stars');
339
- }
340
- /** function/method
341
- * Usage: show tooltips options
342
- * Arg(0): null
343
- * Return: void
344
- */
345
- public function options_tooltips()
346
- {
347
- $this->options_page('tooltips');
348
- }
349
- /** function/method
350
- * Usage: show reset options
351
- * Arg(0): null
352
- * Return: void
353
- */
354
- public function options_reset()
355
- {
356
- $this->options_page('reset');
357
- }
358
- /** function/method
359
- * Usage: show info options
360
- * Arg(0): null
361
- * Return: void
362
- */
363
- public function options_info()
364
- {
365
- $this->options_page('info');
366
- }
367
- public function kksr_admin_reset_ajax()
368
- {
369
- header('content-type: application/json; charset=utf-8');
370
- check_ajax_referer($this->id);
371
-
372
- $Reset = $_POST['kksr_reset'];
373
- if(is_array($Reset))
374
- {
375
- foreach($Reset as $id => $val)
376
- {
377
- if($val=='1')
378
- {
379
- delete_post_meta($id, '_kksr_ratings');
380
- delete_post_meta($id, '_kksr_casts');
381
- delete_post_meta($id, '_kksr_ips');
382
- delete_post_meta($id, '_kksr_avg');
383
- }
384
- }
385
- }
386
-
387
- $Response = array();
388
- $Response['success'] = 'true';
389
- echo json_encode($Response);
390
- die();
391
- }
392
- public function kksr_ajax()
393
- {
394
- header('Content-type: application/json; charset=utf-8');
395
- check_ajax_referer($this->id);
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();
430
- if(!in_array($ip, $Ips))
431
- {
432
- $Ips[] = $ip;
433
- }
434
- $ips = base64_encode(serialize($Ips));
435
- update_post_meta($pid, '_kksr_ratings', $nratings);
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]['legend'] = apply_filters('kksr_legend', parent::get_options('kksr_legend'), $pid);
452
- $Response[$pid]['fuel'] = $per;
453
- }
454
-
455
- $Response[$pid]['success'] = true;
456
-
457
- endforeach;
458
-
459
- echo json_encode($Response);
460
- die();
461
- }
462
- protected function trim_csv_cb($value)
463
- {
464
- if(trim($value)!="")
465
- return true;
466
- return false;
467
- }
468
- protected function exclude_cat($id)
469
- {
470
- $excl_categories = parent::get_options('kksr_exclude_categories');
471
- $Cat_ids = $excl_categories ? array_filter(array_map('trim', explode(",", $excl_categories)), array(&$this, 'trim_csv_cb')) : array();
472
- $Post_cat_ids = wp_get_post_categories($id);
473
- $Intersection = array_intersect($Cat_ids, $Post_cat_ids);
474
- return count($Intersection);
475
- }
476
- public function markup($id=false)
477
- {
478
- $id = !$id ? get_the_ID() : $id;
479
- if($this->exclude_cat($id))
480
- {
481
- return '';
482
- }
483
-
484
- $disabled = false;
485
- if(get_post_meta($id, '_kksr_ips', true))
486
- {
487
- $Ips = unserialize(base64_decode(get_post_meta($id, '_kksr_ips', true)));
488
- $ip = $_SERVER['REMOTE_ADDR'];
489
- if(in_array($ip, $Ips))
490
- {
491
- $disabled = parent::get_options('kksr_unique') ? true : false;
492
- }
493
- }
494
- $pos = parent::get_options('kksr_position');
495
-
496
- $markup = '
497
- <div class="kk-star-ratings '.($disabled || (is_archive() && parent::get_options('kksr_disable_in_archives')) ? 'disabled ' : ' ').$pos.($pos=='top-right'||$pos=='bottom-right' ? ' rgt' : ' lft').'" data-id="'.$id.'">
498
- <div class="kksr-stars kksr-star gray">
499
- <div class="kksr-fuel kksr-star '.($disabled ? 'orange' : 'yellow').'" style="width:0%;"></div>
500
- <!-- kksr-fuel -->';
501
- $total_stars = parent::get_options('kksr_stars');
502
- for($ts = 1; $ts <= $total_stars; $ts++)
503
- {
504
- $markup .= '<a href="#'.$ts.'"></a>';
505
- }
506
- $markup .='
507
- </div>
508
- <!-- kksr-stars -->
509
- <div class="kksr-legend">';
510
- if(parent::get_options('kksr_grs'))
511
- {
512
- $markup .= apply_filters('kksr_legend', parent::get_options('kksr_legend'), $id);
513
- }
514
- $markup .=
515
- '</div>
516
- <!-- kksr-legend -->
517
- </div>
518
- <!-- kk-star-ratings -->
519
- ';
520
- $markup .= parent::get_options('kksr_clear') ? '<br clear="both" />' : '';
521
- return $markup;
522
- }
523
- public function manual($atts)
524
- {
525
- extract(shortcode_atts(array('id' => false), $atts));
526
- if(!is_admin() && parent::get_options('kksr_enable'))
527
- {
528
- if(
529
- ((parent::get_options('kksr_show_in_home')) && (is_front_page() || is_home()))
530
- || ((parent::get_options('kksr_show_in_archives')) && (is_archive()))
531
- )
532
- return $this->markup($id);
533
- else if(is_single() || is_page())
534
- return $this->markup($id);
535
- }
536
- else
537
- {
538
- remove_shortcode('kkratings');
539
- remove_shortcode('kkstarratings');
540
- }
541
- return '';
542
- }
543
- public function filter($content)
544
- {
545
- if(parent::get_options('kksr_enable')) :
546
- if(
547
- ((parent::get_options('kksr_show_in_home')) && (is_front_page() || is_home()))
548
- || ((parent::get_options('kksr_show_in_archives')) && (is_archive()))
549
- || ((parent::get_options('kksr_show_in_posts')) && (is_single()))
550
- || ((parent::get_options('kksr_show_in_pages')) && (is_page()))
551
- ) :
552
- remove_shortcode('kkratings');
553
- remove_shortcode('kkstarratings');
554
- $content = str_replace('[kkratings]', '', $content);
555
- $content = str_replace('[kkstarratings]', '', $content);
556
- $markup = $this->markup();
557
- switch(parent::get_options('kksr_position'))
558
- {
559
- case 'bottom-left' :
560
- case 'bottom-right' : return $content . $markup;
561
- default : return $markup . $content;
562
- }
563
- endif;
564
- endif;
565
- return $content;
566
- }
567
- public function kk_star_rating($pid=false)
568
- {
569
- if(parent::get_options('kksr_enable'))
570
- return $this->markup($pid);
571
- return '';
572
- }
573
- public function kk_star_ratings_get($total=5, $cat=false)
574
- {
575
- global $wpdb;
576
- $table = $wpdb->prefix . 'postmeta';
577
- if(!$cat)
578
- $rated_posts = $wpdb->get_results("SELECT a.ID, a.post_title, b.meta_value AS 'ratings' FROM " . $wpdb->posts . " a, $table b, $table c WHERE a.post_status='publish' AND a.ID=b.post_id AND a.ID=c.post_id AND b.meta_key='_kksr_avg' AND c.meta_key='_kksr_casts' ORDER BY b.meta_value DESC, c.meta_value DESC LIMIT $total");
579
- else
580
- {
581
- $table2 = $wpdb->prefix . 'term_taxonomy';
582
- $table3 = $wpdb->prefix . 'term_relationships';
583
- $rated_posts = $wpdb->get_results("SELECT a.ID, a.post_title, b.meta_value AS 'ratings' FROM " . $wpdb->posts . " a, $table b, $table2 c, $table3 d, $table e WHERE c.term_taxonomy_id=d.term_taxonomy_id AND c.term_id=$cat AND d.object_id=a.ID AND a.post_status='publish' AND a.ID=b.post_id AND a.ID=e.post_id AND b.meta_key='_kksr_avg' AND e.meta_key='_kksr_casts' ORDER BY b.meta_value DESC, e.meta_value DESC LIMIT $total");
584
- }
585
-
586
- return $rated_posts;
587
- }
588
- public function add_column($Columns)
589
- {
590
- if(parent::get_options('kksr_column'))
591
- $Columns['kk_star_ratings'] = 'Ratings';
592
- return $Columns;
593
- }
594
- public function add_row($Columns, $id)
595
- {
596
- if(parent::get_options('kksr_column'))
597
- {
598
- $total_stars = parent::get_options('kksr_stars');
599
- $row = 'No ratings';
600
- $raw = (get_post_meta($id, '_kksr_ratings', true)?get_post_meta($id, '_kksr_ratings', true):0);
601
- if($raw)
602
- {
603
- $_avg = get_post_meta($id, '_kksr_avg', true);
604
- $avg = '<strong>'.($_avg?((number_format((float)($_avg*($total_stars/5)), 2, '.', '')).'/'.$total_stars):'0').'</strong>';
605
- $cast = (get_post_meta($id, '_kksr_casts', true)?get_post_meta($id, '_kksr_casts', true):'0').' votes';
606
- $per = ($raw>0?ceil((($raw/$cast)/5)*100):0).'%';
607
- $row = $avg . ' (' . $per . ') ' . $cast;
608
- }
609
- switch($Columns)
610
- {
611
- case 'kk_star_ratings' : echo $row; break;
612
- }
613
- }
614
- }
615
- /** function/method
616
- * Usage: Allow sorting of columns
617
- * Arg(1): $Args (array)
618
- * Return: (array)
619
- */
620
- public function sort_columns($Args)
621
- {
622
- $Args = array_merge($Args,
623
- array('kk_star_ratings' => 'kk_star_ratings')
624
- );
625
- return wp_parse_args($Args);
626
- }
627
- /** function/method
628
- * Usage: Allow sorting of columns - helper
629
- * Arg(1): $Query (array)
630
- * Return: null
631
- */
632
- public function sort_columns_helper($Query)
633
- {
634
- if(!is_admin())
635
- {
636
- return;
637
- }
638
- $orderby = $Query->get( 'orderby');
639
- if($orderby=='kk_star_ratings')
640
- {
641
- $Query->set('meta_key','_kksr_avg');
642
- $Query->set('orderby','meta_value_num');
643
- }
644
- }
645
- public function grs_legend($legend, $id)
646
- {
647
- if(parent::get_options('kksr_grs'))
648
- {
649
- $title = get_the_title($id);
650
-
651
- $best = parent::get_options('kksr_stars');
652
- $score = get_post_meta($id, '_kksr_ratings', true) ? get_post_meta($id, '_kksr_ratings', true) : 0;
653
-
654
- if($score)
655
- {
656
- $votes = get_post_meta($id, '_kksr_casts', true) ? get_post_meta($id, '_kksr_casts', true) : 0;
657
- $avg = $score ? round((float)(($score/$votes)*($best/5)), 2) : 0;
658
- $per = $score ? round((float)((($score/$votes)/5)*100), 2) : 0;
659
-
660
- $leg = str_replace('[total]', '<span property="ratingCount">'.$votes.'</span>', $legend);
661
- $leg = str_replace('[avg]', '<span property="ratingValue">'.$avg.'</span>', $leg);
662
- $leg = str_replace('[per]', $per .'%', $leg);
663
- $leg = str_replace('[s]', $votes == 1 ? '' : 's', $leg);
664
-
665
- $snippet = '<div vocab="http://schema.org/" typeof="Blog">';
666
- $snippet .= ' <div property="name" class="kksr-title">' . $title . '</div>';
667
- $snippet .= ' <div property="aggregateRating" typeof="AggregateRating">';
668
- $snippet .= $leg;
669
- $snippet .= ' <meta property="bestRating" content="'. $best . '"/>';
670
- $snippet .= ' <meta property="worstRating" content="1"/>';
671
- $snippet .= ' </div>';
672
- $snippet .= '</div>';
673
- }
674
- else
675
- {
676
- $snippet = parent::get_options('kksr_init_msg');
677
- }
678
-
679
- return $snippet;
680
- }
681
- return $legend;
682
- }
683
- }
684
-
685
- $kkStarRatings_obj = new BhittaniPlugin_kkStarRatings('bhittani_plugin_kksr', 'kk Star Ratings', '2.5.1');
686
-
687
- // Setup
688
- register_activation_hook(__FILE__, array($kkStarRatings_obj, 'activate'));
689
-
690
- // Scripts
691
- add_action('wp_enqueue_scripts', array($kkStarRatings_obj, 'js'));
692
- add_action('wp_enqueue_scripts', array($kkStarRatings_obj, 'css'));
693
- add_action('wp_head', array($kkStarRatings_obj, 'css_custom'));
694
- add_action('admin_init', array($kkStarRatings_obj, 'admin_scripts'));
695
-
696
- // Menu
697
- add_action('admin_menu', array($kkStarRatings_obj, 'menu'));
698
-
699
- // AJAX
700
- add_action('wp_ajax_kksr_admin_reset_ajax', array($kkStarRatings_obj, 'kksr_admin_reset_ajax'));
701
- add_action('wp_ajax_kksr_ajax', array($kkStarRatings_obj, 'kksr_ajax'));
702
- add_action('wp_ajax_nopriv_kksr_ajax', array($kkStarRatings_obj, 'kksr_ajax'));
703
-
704
- // Main Hooks
705
- add_filter('the_content', array($kkStarRatings_obj, 'filter'));
706
- add_shortcode('kkratings', array($kkStarRatings_obj, 'manual'));
707
- add_shortcode('kkstarratings', array($kkStarRatings_obj, 'manual'));
708
-
709
- // Google Rich Snippets
710
- add_filter('kksr_legend', array($kkStarRatings_obj, 'grs_legend'), 1, 2);
711
-
712
- // Posts/Pages Column
713
- add_filter( 'manage_posts_columns', array($kkStarRatings_obj, 'add_column') );
714
- add_filter( 'manage_pages_columns', array($kkStarRatings_obj, 'add_column') );
715
- add_filter( 'manage_posts_custom_column', array($kkStarRatings_obj, 'add_row'), 10, 2 );
716
- add_filter( 'manage_pages_custom_column', array($kkStarRatings_obj, 'add_row'), 10, 2 );
717
- add_filter( 'manage_edit-post_sortable_columns', array($kkStarRatings_obj, 'sort_columns') );
718
- add_filter( 'pre_get_posts', array($kkStarRatings_obj, 'sort_columns_helper') );
719
-
720
- // For use in themes
721
- if(!function_exists('kk_star_ratings'))
722
- {
723
- function kk_star_ratings($pid=false)
724
- {
725
- global $kkStarRatings_obj;
726
- return $kkStarRatings_obj->kk_star_rating($pid);
727
- }
728
- }
729
- if(!function_exists('kk_star_ratings_get'))
730
- {
731
- function kk_star_ratings_get($lim=5, $cat=false)
732
- {
733
- global $kkStarRatings_obj;
734
- return $kkStarRatings_obj->kk_star_ratings_get($lim, $cat);
735
- }
736
- }
737
-
738
- require_once 'shortcode/shortcode.php';
739
- require_once 'widget.php';
740
-
741
- endif;
742
-
743
- ?>
1
+ <?php
2
+
3
+ /*
4
+ Plugin Name: kk Star Ratings
5
+ Plugin URI: https://github.com/kamalkhan/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.5.2
8
+ Author: Kamal Khan
9
+ Author URI: http://bhittani.com
10
+ License: GPLv2 or later
11
+ */
12
+
13
+ require_once 'bhittani-framework/plugin.php';
14
+
15
+ if(!class_exists('BhittaniPlugin_kkStarRatings')) :
16
+
17
+ class BhittaniPlugin_kkStarRatings extends BhittaniPlugin
18
+ {
19
+ private $_Menus;
20
+
21
+ public function __construct($id, $nick, $ver)
22
+ {
23
+ parent::__construct($id, $nick, $ver);
24
+ $this->_Menus = array();
25
+ }
26
+ /**
27
+ * File uri
28
+ *
29
+ * @since 1.0 Initially defined
30
+ *
31
+ * @param string $path Path to file.
32
+ *
33
+ * @return string full uri.
34
+ */
35
+ public static function file_uri($path)
36
+ {
37
+ return plugins_url($path, __FILE__);
38
+ }
39
+ /**
40
+ * File path
41
+ *
42
+ * @since 1.0 Initially defined
43
+ *
44
+ * @param string $path Path to file.
45
+ *
46
+ * @return string full path.
47
+ */
48
+ public static function file_path($path)
49
+ {
50
+ return dirname(__FILE__).'/'.$path;
51
+ }
52
+ /** function/method
53
+ * Usage: hook js frontend
54
+ * Arg(0): null
55
+ * Return: void
56
+ */
57
+ public function js()
58
+ {
59
+ $nonce = wp_create_nonce($this->id);
60
+ $Params = array();
61
+ $Params['nonce'] = $nonce; //for security
62
+ $Params['grs'] = parent::get_options('kksr_grs') ? true : false;
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
75
+ * Arg(0): null
76
+ * Return: void
77
+ */
78
+ public function js_admin()
79
+ {
80
+ $nonce = wp_create_nonce($this->id);
81
+ $Params = array();
82
+ $Params['nonce'] = $nonce;
83
+ $Params['func_reset'] = 'kksr_admin_reset_ajax';
84
+ $this->enqueue_js('js_admin', self::file_uri('js_admin.js'), $this->ver, array('jquery', 'bhittaniplugin_admin_script'), $Params);
85
+ }
86
+ /** function/method
87
+ * Usage: hook admin scripts
88
+ * Arg(0): null
89
+ * Return: void
90
+ */
91
+ public function admin_scripts()
92
+ {
93
+ foreach($this->_Menus as $menu)
94
+ {
95
+ add_action('admin_print_scripts-'.$menu, array(&$this, 'js_admin'));
96
+ }
97
+ }
98
+ /** function/method
99
+ * Usage: hook css
100
+ * Arg(0): null
101
+ * Return: void
102
+ */
103
+ public function css()
104
+ {
105
+ $this->enqueue_css('', self::file_uri('css.css'));
106
+ }
107
+ /** function/method
108
+ * Usage: hook custom css
109
+ * Arg(0): null
110
+ * Return: void
111
+ */
112
+ public function css_custom()
113
+ {
114
+ $stars = parent::get_options('kksr_stars') ? parent::get_options('kksr_stars') : 5;
115
+
116
+ $star_w = parent::get_options('kksr_stars_w') ? parent::get_options('kksr_stars_w') : 24;
117
+ $star_h = parent::get_options('kksr_stars_h') ? parent::get_options('kksr_stars_h') : 24;
118
+
119
+ $star_gray = parent::get_options('kksr_stars_gray');
120
+ $star_yellow = parent::get_options('kksr_stars_yellow');
121
+ $star_orange = parent::get_options('kksr_stars_orange');
122
+
123
+ echo '<style>';
124
+
125
+ echo '.kk-star-ratings { width:'.($star_w*$stars).'px; }';
126
+ echo '.kk-star-ratings .kksr-stars a { width:'.($star_w).'px; }';
127
+ echo '.kk-star-ratings .kksr-stars, .kk-star-ratings .kksr-stars .kksr-fuel, .kk-star-ratings .kksr-stars a { height:'.($star_h).'px; }';
128
+
129
+ echo $star_gray ? '.kk-star-ratings .kksr-star.gray { background-image: url('.$star_gray.'); }' : '';
130
+ echo $star_yellow ? '.kk-star-ratings .kksr-star.yellow { background-image: url('.$star_yellow.'); }' : '';
131
+ echo $star_orange ? '.kk-star-ratings .kksr-star.orange { background-image: url('.$star_orange.'); }' : '';
132
+
133
+ echo '</style>';
134
+ }
135
+ /** function/method
136
+ * Usage: Setting defaults and backwards compatibility
137
+ * Arg(0): null
138
+ * Return: void
139
+ */
140
+ public function activate()
141
+ {
142
+ $ver_current = $this->ver;
143
+ $ver_previous = parent::get_options('kksr_ver') ? parent::get_options('kksr_ver') : false;
144
+ $Old_plugin = parent::get_options('kk-ratings');
145
+
146
+ $opt_enable = 1; // 1|0
147
+ $opt_clear = 0; // 1|0
148
+ $opt_show_in_home = 0; // 1|0
149
+ $opt_show_in_archives = 0; // 1|0
150
+ $opt_show_in_posts = 1; // 1|0
151
+ $opt_show_in_pages = 0; // 1|0
152
+ $opt_unique = 0; // 1|0
153
+ $opt_position = 'top-left'; // 'top-left', 'top-right', 'bottom-left', 'bottom-right'
154
+ $opt_legend = '[avg] ([per]) [total] vote[s]'; // [total]=total ratings, [avg]=average, [per]=percentage [s]=singular/plural
155
+ $opt_init_msg = 'Rate this post'; // string
156
+ $opt_column = 1; // 1|0
157
+
158
+ $Options = array();
159
+ $Options['kksr_enable'] = isset($Old_plugin['enable']) ? $Old_plugin['enable'] : $opt_enable;
160
+ $Options['kksr_clear'] = isset($Old_plugin['clear']) ? $Old_plugin['clear'] : $opt_clear;
161
+ $Options['kksr_show_in_home'] = isset($Old_plugin['show_in_home']) ? $Old_plugin['show_in_home'] : $opt_show_in_home;
162
+ $Options['kksr_show_in_archives'] = isset($Old_plugin['show_in_archives']) ? $Old_plugin['show_in_archives'] : $opt_show_in_archives;
163
+ $Options['kksr_show_in_posts'] = isset($Old_plugin['show_in_posts']) ? $Old_plugin['show_in_posts'] : $opt_show_in_posts;
164
+ $Options['kksr_show_in_pages'] = isset($Old_plugin['show_in_pages']) ? $Old_plugin['show_in_pages'] : $opt_show_in_pages;
165
+ $Options['kksr_unique'] = isset($Old_plugin['unique']) ? $Old_plugin['unique'] : $opt_unique;
166
+ $Options['kksr_position'] = isset($Old_plugin['position']) ? $Old_plugin['position'] : $opt_position;
167
+ $Options['kksr_legend'] = isset($Old_plugin['legend']) ? $Old_plugin['legend'] : $opt_legend;
168
+ $Options['kksr_init_msg'] = isset($Old_plugin['init_msg']) ? $Old_plugin['init_msg'] : $opt_init_msg;
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');
176
+
177
+ // Update previous ratings
178
+ global $wpdb;
179
+ $table = $wpdb->prefix . 'postmeta';
180
+ $Posts = $wpdb->get_results("SELECT a.ID, b.meta_key, b.meta_value
181
+ FROM " . $wpdb->posts . " a, $table b
182
+ WHERE a.ID=b.post_id AND
183
+ (
184
+ b.meta_key='_kk_ratings_ratings' OR
185
+ b.meta_key='_kk_ratings_casts' OR
186
+ b.meta_key='_kk_ratings_ips'
187
+ ) ORDER BY a.ID ASC");
188
+ $Wrap = array();
189
+ foreach ($Posts as $post)
190
+ {
191
+ $Wrap[$post->ID]['id'] = $post->ID;
192
+ $Wrap[$post->ID][$post->meta_key] = $post->meta_value;
193
+ }
194
+ foreach($Wrap as $p)
195
+ {
196
+ update_post_meta($p['id'], '_kksr_ratings', $p['_kk_ratings_ratings']);
197
+ update_post_meta($p['id'], '_kksr_casts', $p['_kk_ratings_casts']);
198
+ $Ips = array();
199
+ $Ips = explode('|', $p['_kk_ratings_ips']);
200
+ $ip = base64_encode(serialize($Ips));
201
+ update_post_meta($p['id'], '_kksr_ips', $ip);
202
+ update_post_meta($p['id'], '_kksr_avg', round($p['_kk_ratings_ratings']/$p['_kk_ratings_casts'],1));
203
+ }
204
+ }
205
+ if(!parent::get_options('kksr_ver'))
206
+ {
207
+ $Options['kksr_ver'] = $ver_current;
208
+ $Options['kksr_stars'] = 5;
209
+ $Options['kksr_stars_w'] = 24;
210
+ $Options['kksr_stars_h'] = 24;
211
+ $Options['kksr_stars_gray'] = 0;
212
+ $Options['kksr_stars_yellow'] = 0;
213
+ $Options['kksr_stars_orange'] = 0;
214
+ $Options['kksr_js_fuelspeed'] = 400;
215
+ $Options['kksr_js_thankyou'] = 'Thank you for your vote';
216
+ $Options['kksr_js_error'] = 'An error occurred';
217
+ $Options['kksr_tooltip'] = 1;
218
+ $Opt_tooltips = array();
219
+ $Opt_tooltips[0]['color'] = 'red';
220
+ $Opt_tooltips[0]['tip'] = 'Poor';
221
+ $Opt_tooltips[1]['color'] = 'brown';
222
+ $Opt_tooltips[1]['tip'] = 'Fair';
223
+ $Opt_tooltips[2]['color'] = 'orange';
224
+ $Opt_tooltips[2]['tip'] = 'Average';
225
+ $Opt_tooltips[3]['color'] = 'blue';
226
+ $Opt_tooltips[3]['tip'] = 'Good';
227
+ $Opt_tooltips[4]['color'] = 'green';
228
+ $Opt_tooltips[4]['tip'] = 'Excellent';
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
237
+ * Arg(0): null
238
+ * Return: void
239
+ */
240
+ public function menu()
241
+ {
242
+ // Create main menu tab
243
+ $this->_Menus[] = add_menu_page(
244
+ $this->nick.' - Settings',
245
+ $this->nick,
246
+ 'manage_options',
247
+ $this->id.'_settings',
248
+ array(&$this, 'options_general'),
249
+ self::file_uri('icon.png')
250
+ );
251
+ // Create images menu tab
252
+ $this->_Menus[] = add_submenu_page(
253
+ $this->id.'_settings',
254
+ $this->nick.' - Settings',
255
+ 'Settings',
256
+ 'manage_options',
257
+ $this->id.'_settings',
258
+ array(&$this, 'options_general')
259
+ );
260
+ // Create images menu tab
261
+ $this->_Menus[] = add_submenu_page(
262
+ $this->id.'_settings',
263
+ $this->nick.' - Stars',
264
+ 'Stars',
265
+ 'manage_options',
266
+ $this->id.'_settings_stars',
267
+ array(&$this, 'options_stars')
268
+ );
269
+ // Create tooltips menu tab
270
+ $this->_Menus[] = add_submenu_page(
271
+ $this->id.'_settings',
272
+ $this->nick.' - Tooltips',
273
+ 'Tooltips',
274
+ 'manage_options',
275
+ $this->id.'_settings_tooltips',
276
+ array(&$this, 'options_tooltips')
277
+ );
278
+ // Create reset menu tab
279
+ $this->_Menus[] = add_submenu_page(
280
+ $this->id.'_settings',
281
+ $this->nick.' - Reset',
282
+ 'Reset',
283
+ 'manage_options',
284
+ $this->id.'_settings_reset',
285
+ array(&$this, 'options_reset')
286
+ );
287
+ // Create info menu tab
288
+ $this->_Menus[] = add_submenu_page(
289
+ $this->id.'_settings',
290
+ $this->nick.' - Help',
291
+ 'Help',
292
+ 'manage_options',
293
+ $this->id.'_settings_info',
294
+ array(&$this, 'options_info')
295
+ );
296
+ }
297
+ /** function/method
298
+ * Usage: show options/settings form page
299
+ * Arg(0): null
300
+ * Return: void
301
+ */
302
+ public function options_page($opt)
303
+ {
304
+ if (!current_user_can('manage_options'))
305
+ {
306
+ wp_die( __('You do not have sufficient permissions to access this page.') );
307
+ }
308
+ $sidebar = true;
309
+ $h3 = 'kk Star Ratings';
310
+ $Url = array(
311
+ // array(
312
+ // 'title' => 'Github Repository',
313
+ // 'link' => 'https://github.com/kamalkhan/kk-star-ratings'
314
+ // ),
315
+ // array(
316
+ // 'title' => 'Changelog',
317
+ // 'link' => '#'
318
+ // )
319
+ );
320
+ include self::file_path('admin.php');
321
+ }
322
+ /** function/method
323
+ * Usage: show general options
324
+ * Arg(0): null
325
+ * Return: void
326
+ */
327
+ public function options_general()
328
+ {
329
+ $this->options_page('general');
330
+ }
331
+ /** function/method
332
+ * Usage: show images options
333
+ * Arg(0): null
334
+ * Return: void
335
+ */
336
+ public function options_stars()
337
+ {
338
+ $this->options_page('stars');
339
+ }
340
+ /** function/method
341
+ * Usage: show tooltips options
342
+ * Arg(0): null
343
+ * Return: void
344
+ */
345
+ public function options_tooltips()
346
+ {
347
+ $this->options_page('tooltips');
348
+ }
349
+ /** function/method
350
+ * Usage: show reset options
351
+ * Arg(0): null
352
+ * Return: void
353
+ */
354
+ public function options_reset()
355
+ {
356
+ $this->options_page('reset');
357
+ }
358
+ /** function/method
359
+ * Usage: show info options
360
+ * Arg(0): null
361
+ * Return: void
362
+ */
363
+ public function options_info()
364
+ {
365
+ $this->options_page('info');
366
+ }
367
+ public function kksr_admin_reset_ajax()
368
+ {
369
+ header('content-type: application/json; charset=utf-8');
370
+ check_ajax_referer($this->id);
371
+
372
+ $Reset = $_POST['kksr_reset'];
373
+ if(is_array($Reset))
374
+ {
375
+ foreach($Reset as $id => $val)
376
+ {
377
+ if($val=='1')
378
+ {
379
+ delete_post_meta($id, '_kksr_ratings');
380
+ delete_post_meta($id, '_kksr_casts');
381
+ delete_post_meta($id, '_kksr_ips');
382
+ delete_post_meta($id, '_kksr_avg');
383
+ }
384
+ }
385
+ }
386
+
387
+ $Response = array();
388
+ $Response['success'] = 'true';
389
+ echo json_encode($Response);
390
+ die();
391
+ }
392
+ public function kksr_ajax()
393
+ {
394
+ header('Content-type: application/json; charset=utf-8');
395
+ check_ajax_referer($this->id);
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();
430
+ if(!in_array($ip, $Ips))
431
+ {
432
+ $Ips[] = $ip;
433
+ }
434
+ $ips = base64_encode(serialize($Ips));
435
+ update_post_meta($pid, '_kksr_ratings', $nratings);
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]['legend'] = apply_filters('kksr_legend', parent::get_options('kksr_legend'), $pid);
452
+ $Response[$pid]['fuel'] = $per;
453
+ }
454
+
455
+ $Response[$pid]['success'] = true;
456
+
457
+ endforeach;
458
+
459
+ echo json_encode($Response);
460
+ die();
461
+ }
462
+ protected function trim_csv_cb($value)
463
+ {
464
+ if(trim($value)!="")
465
+ return true;
466
+ return false;
467
+ }
468
+ protected function exclude_cat($id)
469
+ {
470
+ $excl_categories = parent::get_options('kksr_exclude_categories');
471
+ $Cat_ids = $excl_categories ? array_filter(array_map('trim', explode(",", $excl_categories)), array(&$this, 'trim_csv_cb')) : array();
472
+ $Post_cat_ids = wp_get_post_categories($id);
473
+ $Intersection = array_intersect($Cat_ids, $Post_cat_ids);
474
+ return count($Intersection);
475
+ }
476
+ public function markup($id=false)
477
+ {
478
+ $id = !$id ? get_the_ID() : $id;
479
+ if($this->exclude_cat($id))
480
+ {
481
+ return '';
482
+ }
483
+
484
+ $disabled = false;
485
+ if(get_post_meta($id, '_kksr_ips', true))
486
+ {
487
+ $Ips = unserialize(base64_decode(get_post_meta($id, '_kksr_ips', true)));
488
+ $ip = $_SERVER['REMOTE_ADDR'];
489
+ if(in_array($ip, $Ips))
490
+ {
491
+ $disabled = parent::get_options('kksr_unique') ? true : false;
492
+ }
493
+ }
494
+ $pos = parent::get_options('kksr_position');
495
+
496
+ $markup = '
497
+ <div class="kk-star-ratings '.($disabled || (is_archive() && parent::get_options('kksr_disable_in_archives')) ? 'disabled ' : ' ').$pos.($pos=='top-right'||$pos=='bottom-right' ? ' rgt' : ' lft').'" data-id="'.$id.'">
498
+ <div class="kksr-stars kksr-star gray">
499
+ <div class="kksr-fuel kksr-star '.($disabled ? 'orange' : 'yellow').'" style="width:0%;"></div>
500
+ <!-- kksr-fuel -->';
501
+ $total_stars = parent::get_options('kksr_stars');
502
+ for($ts = 1; $ts <= $total_stars; $ts++)
503
+ {
504
+ $markup .= '<a href="#'.$ts.'"></a>';
505
+ }
506
+ $markup .='
507
+ </div>
508
+ <!-- kksr-stars -->
509
+ <div class="kksr-legend">';
510
+ if(parent::get_options('kksr_grs'))
511
+ {
512
+ $markup .= apply_filters('kksr_legend', parent::get_options('kksr_legend'), $id);
513
+ }
514
+ $markup .=
515
+ '</div>
516
+ <!-- kksr-legend -->
517
+ </div>
518
+ <!-- kk-star-ratings -->
519
+ ';
520
+ $markup .= parent::get_options('kksr_clear') ? '<br clear="both" />' : '';
521
+ return $markup;
522
+ }
523
+ public function manual($atts)
524
+ {
525
+ extract(shortcode_atts(array('id' => false), $atts));
526
+ if(!is_admin() && parent::get_options('kksr_enable'))
527
+ {
528
+ if(
529
+ ((parent::get_options('kksr_show_in_home')) && (is_front_page() || is_home()))
530
+ || ((parent::get_options('kksr_show_in_archives')) && (is_archive()))
531
+ )
532
+ return $this->markup($id);
533
+ else if(is_single() || is_page())
534
+ return $this->markup($id);
535
+ }
536
+ else
537
+ {
538
+ remove_shortcode('kkratings');
539
+ remove_shortcode('kkstarratings');
540
+ }
541
+ return '';
542
+ }
543
+ public function filter($content)
544
+ {
545
+ if(parent::get_options('kksr_enable')) :
546
+ if(
547
+ ((parent::get_options('kksr_show_in_home')) && (is_front_page() || is_home()))
548
+ || ((parent::get_options('kksr_show_in_archives')) && (is_archive()))
549
+ || ((parent::get_options('kksr_show_in_posts')) && (is_single()))
550
+ || ((parent::get_options('kksr_show_in_pages')) && (is_page()))
551
+ ) :
552
+ remove_shortcode('kkratings');
553
+ remove_shortcode('kkstarratings');
554
+ $content = str_replace('[kkratings]', '', $content);
555
+ $content = str_replace('[kkstarratings]', '', $content);
556
+ $markup = $this->markup();
557
+ switch(parent::get_options('kksr_position'))
558
+ {
559
+ case 'bottom-left' :
560
+ case 'bottom-right' : return $content . $markup;
561
+ default : return $markup . $content;
562
+ }
563
+ endif;
564
+ endif;
565
+ return $content;
566
+ }
567
+ public function kk_star_rating($pid=false)
568
+ {
569
+ if(parent::get_options('kksr_enable'))
570
+ return $this->markup($pid);
571
+ return '';
572
+ }
573
+ public function kk_star_ratings_get($total=5, $cat=false)
574
+ {
575
+ global $wpdb;
576
+ $table = $wpdb->prefix . 'postmeta';
577
+ if(!$cat)
578
+ $rated_posts = $wpdb->get_results("SELECT a.ID, a.post_title, b.meta_value AS 'ratings' FROM " . $wpdb->posts . " a, $table b, $table c WHERE a.post_status='publish' AND a.ID=b.post_id AND a.ID=c.post_id AND b.meta_key='_kksr_avg' AND c.meta_key='_kksr_casts' ORDER BY CAST(b.meta_value AS UNSIGNED) DESC, CAST(c.meta_value AS UNSIGNED) DESC LIMIT $total");
579
+ else
580
+ {
581
+ $table2 = $wpdb->prefix . 'term_taxonomy';
582
+ $table3 = $wpdb->prefix . 'term_relationships';
583
+ $rated_posts = $wpdb->get_results("SELECT a.ID, a.post_title, b.meta_value AS 'ratings' FROM " . $wpdb->posts . " a, $table b, $table2 c, $table3 d, $table e WHERE c.term_taxonomy_id=d.term_taxonomy_id AND c.term_id=$cat AND d.object_id=a.ID AND a.post_status='publish' AND a.ID=b.post_id AND a.ID=e.post_id AND b.meta_key='_kksr_avg' AND e.meta_key='_kksr_casts' ORDER BY CAST(b.meta_value AS UNSIGNED) DESC, CAST(e.meta_value AS UNSIGNED) DESC LIMIT $total");
584
+ }
585
+
586
+ return $rated_posts;
587
+ }
588
+ public function add_column($Columns)
589
+ {
590
+ if(parent::get_options('kksr_column'))
591
+ $Columns['kk_star_ratings'] = 'Ratings';
592
+ return $Columns;
593
+ }
594
+ public function add_row($Columns, $id)
595
+ {
596
+ if(parent::get_options('kksr_column'))
597
+ {
598
+ $total_stars = parent::get_options('kksr_stars');
599
+ $row = 'No ratings';
600
+ $raw = (get_post_meta($id, '_kksr_ratings', true)?get_post_meta($id, '_kksr_ratings', true):0);
601
+ if($raw)
602
+ {
603
+ $_avg = get_post_meta($id, '_kksr_avg', true);
604
+ $avg = '<strong>'.($_avg?((number_format((float)($_avg*($total_stars/5)), 2, '.', '')).'/'.$total_stars):'0').'</strong>';
605
+ $cast = (get_post_meta($id, '_kksr_casts', true)?get_post_meta($id, '_kksr_casts', true):'0').' votes';
606
+ $per = ($raw>0?ceil((($raw/$cast)/5)*100):0).'%';
607
+ $row = $avg . ' (' . $per . ') ' . $cast;
608
+ }
609
+ switch($Columns)
610
+ {
611
+ case 'kk_star_ratings' : echo $row; break;
612
+ }
613
+ }
614
+ }
615
+ /** function/method
616
+ * Usage: Allow sorting of columns
617
+ * Arg(1): $Args (array)
618
+ * Return: (array)
619
+ */
620
+ public function sort_columns($Args)
621
+ {
622
+ $Args = array_merge($Args,
623
+ array('kk_star_ratings' => 'kk_star_ratings')
624
+ );
625
+ return wp_parse_args($Args);
626
+ }
627
+ /** function/method
628
+ * Usage: Allow sorting of columns - helper
629
+ * Arg(1): $Query (array)
630
+ * Return: null
631
+ */
632
+ public function sort_columns_helper($Query)
633
+ {
634
+ if(!is_admin())
635
+ {
636
+ return;
637
+ }
638
+ $orderby = $Query->get( 'orderby');
639
+ if($orderby=='kk_star_ratings')
640
+ {
641
+ $Query->set('meta_key','_kksr_avg');
642
+ $Query->set('orderby','meta_value_num');
643
+ }
644
+ }
645
+ public function grs_legend($legend, $id)
646
+ {
647
+ if(parent::get_options('kksr_grs'))
648
+ {
649
+ $title = get_the_title($id);
650
+
651
+ $best = parent::get_options('kksr_stars');
652
+ $score = get_post_meta($id, '_kksr_ratings', true) ? get_post_meta($id, '_kksr_ratings', true) : 0;
653
+
654
+ if($score)
655
+ {
656
+ $votes = get_post_meta($id, '_kksr_casts', true) ? get_post_meta($id, '_kksr_casts', true) : 0;
657
+ $avg = $score && $votes ? round((float)(($score/$votes)*($best/5)), 2) : 0;
658
+ $per = $score && $votes ? round((float)((($score/$votes)/5)*100), 2) : 0;
659
+
660
+ $leg = str_replace('[total]', '<span itemprop="ratingCount">'.$votes.'</span>', $legend);
661
+ $leg = str_replace('[avg]', '<span itemprop="ratingValue">'.$avg.'</span>', $leg);
662
+ $leg = str_replace('[per]', $per .'%', $leg);
663
+ $leg = str_replace('[s]', $votes == 1 ? '' : 's', $leg);
664
+
665
+ $snippet = '<div itemprop="aggregateRating" itemscope itemtype="http://schema.org/AggregateRating">';
666
+ $snippet .= ' <div itemprop="name" class="kksr-title">' . $title . '</div>';
667
+ $snippet .= $leg;
668
+ $snippet .= ' <meta itemprop="bestRating" content="'. $best . '"/>';
669
+ $snippet .= ' <meta itemprop="worstRating" content="1"/>';
670
+ $snippet .= '</div>';
671
+ }
672
+ else
673
+ {
674
+ $snippet = parent::get_options('kksr_init_msg');
675
+ }
676
+
677
+ return $snippet;
678
+ }
679
+ return $legend;
680
+ }
681
+ }
682
+
683
+ $kkStarRatings_obj = new BhittaniPlugin_kkStarRatings('bhittani_plugin_kksr', 'kk Star Ratings', '2.5.1');
684
+
685
+ // Setup
686
+ register_activation_hook(__FILE__, array($kkStarRatings_obj, 'activate'));
687
+
688
+ // Scripts
689
+ add_action('wp_enqueue_scripts', array($kkStarRatings_obj, 'js'));
690
+ add_action('wp_enqueue_scripts', array($kkStarRatings_obj, 'css'));
691
+ add_action('wp_head', array($kkStarRatings_obj, 'css_custom'));
692
+ add_action('admin_init', array($kkStarRatings_obj, 'admin_scripts'));
693
+
694
+ // Menu
695
+ add_action('admin_menu', array($kkStarRatings_obj, 'menu'));
696
+
697
+ // AJAX
698
+ add_action('wp_ajax_kksr_admin_reset_ajax', array($kkStarRatings_obj, 'kksr_admin_reset_ajax'));
699
+ add_action('wp_ajax_kksr_ajax', array($kkStarRatings_obj, 'kksr_ajax'));
700
+ add_action('wp_ajax_nopriv_kksr_ajax', array($kkStarRatings_obj, 'kksr_ajax'));
701
+
702
+ // Main Hooks
703
+ add_filter('the_content', array($kkStarRatings_obj, 'filter'));
704
+ add_shortcode('kkratings', array($kkStarRatings_obj, 'manual'));
705
+ add_shortcode('kkstarratings', array($kkStarRatings_obj, 'manual'));
706
+
707
+ // Google Rich Snippets
708
+ add_filter('kksr_legend', array($kkStarRatings_obj, 'grs_legend'), 1, 2);
709
+
710
+ // Posts/Pages Column
711
+ add_filter( 'manage_posts_columns', array($kkStarRatings_obj, 'add_column') );
712
+ add_filter( 'manage_pages_columns', array($kkStarRatings_obj, 'add_column') );
713
+ add_filter( 'manage_posts_custom_column', array($kkStarRatings_obj, 'add_row'), 10, 2 );
714
+ add_filter( 'manage_pages_custom_column', array($kkStarRatings_obj, 'add_row'), 10, 2 );
715
+ add_filter( 'manage_edit-post_sortable_columns', array($kkStarRatings_obj, 'sort_columns') );
716
+ add_filter( 'pre_get_posts', array($kkStarRatings_obj, 'sort_columns_helper') );
717
+
718
+ // For use in themes
719
+ if(!function_exists('kk_star_ratings'))
720
+ {
721
+ function kk_star_ratings($pid=false)
722
+ {
723
+ global $kkStarRatings_obj;
724
+ return $kkStarRatings_obj->kk_star_rating($pid);
725
+ }
726
+ }
727
+ if(!function_exists('kk_star_ratings_get'))
728
+ {
729
+ function kk_star_ratings_get($lim=5, $cat=false)
730
+ {
731
+ global $kkStarRatings_obj;
732
+ return $kkStarRatings_obj->kk_star_ratings_get($lim, $cat);
733
+ }
734
+ }
735
+
736
+ require_once 'shortcode/shortcode.php';
737
+ require_once 'widget.php';
738
+
739
+ endif;
 
 
 
 
orange.png CHANGED
Binary file
readme.txt CHANGED
@@ -1,243 +1,249 @@
1
- === kk Star Ratings ===
2
-
3
-
4
- Contributors: bhittani
5
-
6
- Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=CM659D9SHGKE6
7
-
8
- Tags: star ratings, votings, rate posts, ajax ratings, infinite stars, unlimited stars, google rich snippets
9
-
10
- Requires at least: 3.0
11
-
12
- Tested up to: 4.4.2
13
-
14
- Stable tag: 2.5.1
15
-
16
-
17
- kk Star Ratings allows blog visitors to involve and interact more effectively with your website by rating posts.
18
-
19
-
20
-
21
- == Description ==
22
-
23
-
24
-
25
-
26
- kk Star Ratings has been renewed from the ground up in version 2.0.
27
-
28
- This plugin displays a user defined amount of star ratings in your posts/pages.
29
-
30
- It has cool mouse over effects and animations such as fueling of stars.
31
-
32
- Supports Google Rich Snippets. Now the ratings will be indexed in google search :)
33
-
34
- Inludes a widget so you can show top rated posts in your sidebar as well. Can also be filtered by category.
35
-
36
- Custom template tag/function available
37
-
38
- Enhanced settings page where you can adjust quite anything you may need to. You can:
39
-
40
- 1. Select where to show the ratings. It can be on homepage, archives, posts, pages or manually.
41
-
42
- 1. A visual button in your editor to easily display the ratings manually in your posts/pages. No more typing a shortcode :)
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.
53
-
54
- 1. Choose placement. Top left, top right, bottom left or bottom right.
55
-
56
- 1. Adjust frequent messages and strings.
57
-
58
- 1. Choose your own images.
59
-
60
- 1. Attach tooltips when mouse is hovered while rating with colors.
61
-
62
- 1. Change amount of stars anytime you want. Default is 5.
63
-
64
- 1. Reset the ratings for individual posts or the entire site.
65
-
66
-
67
-
68
-
69
- == Installation ==
70
-
71
-
72
-
73
- 1. Upload the folder 'kk-star-ratings' found inside the zip to the `/wp-content/plugins/` directory
74
- 1. Activate the plugin through the 'Plugins' menu in WordPress
75
- 1. Adjust the settings under kk Star Ratings tab in wp-admin.
76
-
77
-
78
-
79
- == Frequently Asked Questions ==
80
- =
81
-
82
- Google rich snippets are not being displayed when I updated to v2.5.1
83
-
84
- =
85
-
86
- The snippet code vocabulary has been updated. Have some patience and let google crawl your posts/pages again for some days.
87
-
88
- =
89
-
90
- I found a bug or want to contribute.
91
-
92
- =
93
-
94
- The source of this plugin is located at https://github.com/kamalkhan/kk-star-ratings (as of v2.5+). Feel free to post an issue or submit a pull request.
95
-
96
- =
97
-
98
- I have been using an older verion of the plugin. Is it safe for me to update?
99
-
100
- =
101
-
102
- Version 2.0+ has been re-coded from the ground up preserving backwards compatibility. Feel free to upgrade safely.
103
-
104
- =
105
-
106
- I need some help or have some issues?
107
-
108
- =
109
-
110
- Visit the help tab in the settings to find out what you can do.
111
-
112
-
113
-
114
- == Screenshots ==
115
-
116
-
117
-
118
- 1. The general settings page
119
-
120
-
121
- 2. The stars settings page
122
-
123
-
124
- 3. The tooltips settings page
125
-
126
-
127
- 4. The reset settings page
128
-
129
-
130
- 5. The menu tab
131
-
132
-
133
- 6. The widget
134
-
135
-
136
- 7. Five stars with custom image
137
-
138
-
139
- 8. Eight stars with custom image
140
-
141
-
142
- 9. Five stars with default image
143
-
144
-
145
- 10. Single star with default image
146
-
147
-
148
- == Changelog ==
149
-
150
- = 2.5.1 =
151
- * Fix: Google rich snippets with new vocabulary code.
152
- * Fix: Average calculation when x amount of stars used and changed dynamically.
153
- * Fix: Shortcode.
154
- * Fix: Styling.
155
-
156
- = 2.5 =
157
- * Fix: Deprecate WP_Widget for __construct. Required for wp 4.3+.
158
- * Fix google rich snippets by using #Ratings as the vocabulary.
159
- * Update: social and sponsored links in admin.
160
- * Add: Css reset for star anchors.
161
- * Use github for managing the plugin source at https://github.com/kamalkhan/kk-star-ratings.
162
-
163
- = 2.4 =
164
- * Fix: Upper and Lower boundary limits for rating. Oops, had not noticed this before.
165
- * Fix: Fuelspeed. Strange! no one ever complained about it.
166
- * Update: Revamped the entire javascript (normal: 6.03KB, minified: 4.29KB).
167
- * Update: Two fixed decimal points for average and percentage instead of one.
168
- * Update: Icon star color from grey to yellow.
169
- * 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 :)
170
- * Added: Rating column can now be sorted in the admin screen.
171
-
172
- = 2.3.1 =
173
- * Update: Framework updated for no conflict mode with other kk plugins.
174
-
175
- = 2.3 =
176
- * Added: Ability to exclude specific category(s).
177
-
178
- = 2.2.1 =
179
- * Update: Restricted admin scripts to render in its own page scope.
180
-
181
- = 2.2 =
182
- * Fix: jquery ui causing problems in wordpress 3.5. It is removed because no longer required.
183
- * Update: Shortcode can contain optional 'id' argument to display ratings for a specific post intentionally. e.g. [kkstarratings id="192"]
184
-
185
- = 2.1 =
186
- * Fix: Google rich snippets is now stable and safe to use.
187
- * Fix: Grammers in admin settings.
188
- * Update: Control whether to allow users to rate in archives or not.
189
- * Update: Reordered directory tree structure.
190
- * Added: Useful hooks and filters for advanced developers.
191
-
192
- = 2.0 =
193
- * Update: Re-coded the plugin from the ground up, adding rich settings page and more features.
194
- * Update: Transparent stars and availability of custom stars as per needs.
195
- * Update: Ajax based settings page. No refreshes what so ever.
196
- * Update: Seperate settings tab.
197
- * Update: Visual flushing of ratings. No need to remember post ids.
198
- * Update: [s] added as a variable for use in the legend (description). Will display the s only if there are 0 or more than 1 ratings.
199
- * Added: kk Star Ratings now supports Google Rich Snippets. So the ratings will now be indexed in google search.
200
- * Added: Visual shortcode button. No need to type in a shortcode manually in your posts/pages when in manual mode.
201
- * Added: User specific amount of stars. Forget the fixed 5 stars.
202
- * Added: Choose your own images instead of the default ones.
203
- * Added: Tooltips. Now you can set tooltips for each star when mouse is hovered on each. You can also set colors.
204
- * Added: Adjustment of fueling speed of stars when being loaded or refilling.
205
- * Added: Set error message if anything goes unexpectidly.
206
- * Added: Set thank you message.
207
-
208
- = 1.7.2 =
209
- * Fix: This is a fix for the previous version (1.7.1). The plugin was not tagged with the latest files. Now it is fixed.
210
-
211
- = 1.7.1 =
212
- * Security Fix: Fixed a security issue in the ajax request for the file inclusion risk. This is a recommended update for all users.
213
-
214
- = 1.7 =
215
- * Update: The top rated posts now considers the vote count as well. This is a recommended update for all users.
216
-
217
- = 1.6 =
218
- * Added: Now you can see a column in the admin screen of posts and pages stating the ratings of each.
219
-
220
- = 1.5 =
221
- * Fixed: Some users complained about a fault: "An error occured" being displayed when someone rates a post. This was due to the charset of the returned response via ajax (Mentioned by jamk). Has been fixed as the ajax response is now retrieved as an xml dom instead of plain text.
222
- * Fixed: Regardless of unique voting set or not, a user could click on a star multiple times simultaneously and the post would be rated that much time. Has been fixed.
223
- * Added: Filter by category in the widget as well as the custom template tag/function.
224
-
225
- = 1.4.1 =
226
- * Fixed: Settings are now able to be saved. Was not being saved in v1.4.
227
-
228
- = 1.4 =
229
- * Added: ability to retrieve top rated posts in the template/theme.
230
-
231
- = 1.3.1 =
232
- * Fixed: flushing/removing of ratings for widget included. Thanks to feedback from glyn.
233
-
234
- = 1.3 =
235
- * Added a widget. Now you can show top rated posts in your sidebar :).
236
-
237
- = 1.2 =
238
- * Added possibility to show ratings of any post anywhere in your theme files.
239
-
240
- = 1.1 =
241
- * Fixed the [avg] error, so now it will display average ratings properly.
242
-
243
- == Upgrade Notice ==
 
 
 
 
 
 
1
+ === kk Star Ratings ===
2
+
3
+
4
+ Contributors: bhittani
5
+
6
+ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=CM659D9SHGKE6
7
+
8
+ Tags: star ratings, votings, rate posts, ajax ratings, infinite stars, unlimited stars, google rich snippets
9
+
10
+ Requires at least: 3.0
11
+
12
+ Tested up to: 4.8
13
+
14
+ Stable tag: 2.5.2
15
+
16
+
17
+ kk Star Ratings allows blog visitors to involve and interact more effectively with your website by rating posts.
18
+
19
+
20
+
21
+ == Description ==
22
+
23
+
24
+
25
+
26
+ kk Star Ratings has been renewed from the ground up in version 2.0.
27
+
28
+ This plugin displays a user defined amount of star ratings in your posts/pages.
29
+
30
+ It has cool mouse over effects and animations such as fueling of stars.
31
+
32
+ Supports Google Rich Snippets. Now the ratings will be indexed in google search :)
33
+
34
+ Inludes a widget so you can show top rated posts in your sidebar as well. Can also be filtered by category.
35
+
36
+ Custom template tag/function available
37
+
38
+ Enhanced settings page where you can adjust quite anything you may need to. You can:
39
+
40
+ 1. Select where to show the ratings. It can be on homepage, archives, posts, pages or manually.
41
+
42
+ 1. A visual button in your editor to easily display the ratings manually in your posts/pages. No more typing a shortcode :)
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.
53
+
54
+ 1. Choose placement. Top left, top right, bottom left or bottom right.
55
+
56
+ 1. Adjust frequent messages and strings.
57
+
58
+ 1. Choose your own images.
59
+
60
+ 1. Attach tooltips when mouse is hovered while rating with colors.
61
+
62
+ 1. Change amount of stars anytime you want. Default is 5.
63
+
64
+ 1. Reset the ratings for individual posts or the entire site.
65
+
66
+
67
+
68
+
69
+ == Installation ==
70
+
71
+
72
+
73
+ 1. Upload the folder 'kk-star-ratings' found inside the zip to the `/wp-content/plugins/` directory
74
+ 1. Activate the plugin through the 'Plugins' menu in WordPress
75
+ 1. Adjust the settings under kk Star Ratings tab in wp-admin.
76
+
77
+
78
+
79
+ == Frequently Asked Questions ==
80
+ =
81
+
82
+ Google rich snippets are not being displayed when I updated to v2.5.1
83
+
84
+ =
85
+
86
+ The snippet code vocabulary has been updated. Have some patience and let google crawl your posts/pages again for some days.
87
+
88
+ =
89
+
90
+ I found a bug or want to contribute.
91
+
92
+ =
93
+
94
+ The source of this plugin is located at https://github.com/kamalkhan/kk-star-ratings (as of v2.5+). Feel free to post an issue or submit a pull request.
95
+
96
+ =
97
+
98
+ I have been using an older verion of the plugin. Is it safe for me to update?
99
+
100
+ =
101
+
102
+ Version 2.0+ has been re-coded from the ground up preserving backwards compatibility. Feel free to upgrade safely.
103
+
104
+ =
105
+
106
+ I need some help or have some issues?
107
+
108
+ =
109
+
110
+ Visit the help tab in the settings to find out what you can do.
111
+
112
+
113
+
114
+ == Screenshots ==
115
+
116
+
117
+
118
+ 1. The general settings page
119
+
120
+
121
+ 2. The stars settings page
122
+
123
+
124
+ 3. The tooltips settings page
125
+
126
+
127
+ 4. The reset settings page
128
+
129
+
130
+ 5. The menu tab
131
+
132
+
133
+ 6. The widget
134
+
135
+
136
+ 7. Five stars with custom image
137
+
138
+
139
+ 8. Eight stars with custom image
140
+
141
+
142
+ 9. Five stars with default image
143
+
144
+
145
+ 10. Single star with default image
146
+
147
+
148
+ == Changelog ==
149
+
150
+ = 2.5.2 =
151
+ * Fix: See [PR #6](https://github.com/kamalkhan/kk-star-ratings/pull/6)
152
+ * Fix: See [PR #24](https://github.com/kamalkhan/kk-star-ratings/pull/24)
153
+ * Fix: See [PR #25](https://github.com/kamalkhan/kk-star-ratings/pull/25)
154
+ * Fix: See [PR #28](https://github.com/kamalkhan/kk-star-ratings/pull/28)
155
+
156
+ = 2.5.1 =
157
+ * Fix: Google rich snippets with new vocabulary code.
158
+ * Fix: Average calculation when x amount of stars used and changed dynamically.
159
+ * Fix: Shortcode.
160
+ * Fix: Styling.
161
+
162
+ = 2.5 =
163
+ * Fix: Deprecate WP_Widget for __construct. Required for wp 4.3+.
164
+ * Fix google rich snippets by using #Ratings as the vocabulary.
165
+ * Update: social and sponsored links in admin.
166
+ * Add: Css reset for star anchors.
167
+ * Use github for managing the plugin source at https://github.com/kamalkhan/kk-star-ratings.
168
+
169
+ = 2.4 =
170
+ * Fix: Upper and Lower boundary limits for rating. Oops, had not noticed this before.
171
+ * Fix: Fuelspeed. Strange! no one ever complained about it.
172
+ * Update: Revamped the entire javascript (normal: 6.03KB, minified: 4.29KB).
173
+ * Update: Two fixed decimal points for average and percentage instead of one.
174
+ * Update: Icon star color from grey to yellow.
175
+ * 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 :)
176
+ * Added: Rating column can now be sorted in the admin screen.
177
+
178
+ = 2.3.1 =
179
+ * Update: Framework updated for no conflict mode with other kk plugins.
180
+
181
+ = 2.3 =
182
+ * Added: Ability to exclude specific category(s).
183
+
184
+ = 2.2.1 =
185
+ * Update: Restricted admin scripts to render in its own page scope.
186
+
187
+ = 2.2 =
188
+ * Fix: jquery ui causing problems in wordpress 3.5. It is removed because no longer required.
189
+ * Update: Shortcode can contain optional 'id' argument to display ratings for a specific post intentionally. e.g. [kkstarratings id="192"]
190
+
191
+ = 2.1 =
192
+ * Fix: Google rich snippets is now stable and safe to use.
193
+ * Fix: Grammers in admin settings.
194
+ * Update: Control whether to allow users to rate in archives or not.
195
+ * Update: Reordered directory tree structure.
196
+ * Added: Useful hooks and filters for advanced developers.
197
+
198
+ = 2.0 =
199
+ * Update: Re-coded the plugin from the ground up, adding rich settings page and more features.
200
+ * Update: Transparent stars and availability of custom stars as per needs.
201
+ * Update: Ajax based settings page. No refreshes what so ever.
202
+ * Update: Seperate settings tab.
203
+ * Update: Visual flushing of ratings. No need to remember post ids.
204
+ * Update: [s] added as a variable for use in the legend (description). Will display the s only if there are 0 or more than 1 ratings.
205
+ * Added: kk Star Ratings now supports Google Rich Snippets. So the ratings will now be indexed in google search.
206
+ * Added: Visual shortcode button. No need to type in a shortcode manually in your posts/pages when in manual mode.
207
+ * Added: User specific amount of stars. Forget the fixed 5 stars.
208
+ * Added: Choose your own images instead of the default ones.
209
+ * Added: Tooltips. Now you can set tooltips for each star when mouse is hovered on each. You can also set colors.
210
+ * Added: Adjustment of fueling speed of stars when being loaded or refilling.
211
+ * Added: Set error message if anything goes unexpectidly.
212
+ * Added: Set thank you message.
213
+
214
+ = 1.7.2 =
215
+ * Fix: This is a fix for the previous version (1.7.1). The plugin was not tagged with the latest files. Now it is fixed.
216
+
217
+ = 1.7.1 =
218
+ * Security Fix: Fixed a security issue in the ajax request for the file inclusion risk. This is a recommended update for all users.
219
+
220
+ = 1.7 =
221
+ * Update: The top rated posts now considers the vote count as well. This is a recommended update for all users.
222
+
223
+ = 1.6 =
224
+ * Added: Now you can see a column in the admin screen of posts and pages stating the ratings of each.
225
+
226
+ = 1.5 =
227
+ * Fixed: Some users complained about a fault: "An error occured" being displayed when someone rates a post. This was due to the charset of the returned response via ajax (Mentioned by jamk). Has been fixed as the ajax response is now retrieved as an xml dom instead of plain text.
228
+ * Fixed: Regardless of unique voting set or not, a user could click on a star multiple times simultaneously and the post would be rated that much time. Has been fixed.
229
+ * Added: Filter by category in the widget as well as the custom template tag/function.
230
+
231
+ = 1.4.1 =
232
+ * Fixed: Settings are now able to be saved. Was not being saved in v1.4.
233
+
234
+ = 1.4 =
235
+ * Added: ability to retrieve top rated posts in the template/theme.
236
+
237
+ = 1.3.1 =
238
+ * Fixed: flushing/removing of ratings for widget included. Thanks to feedback from glyn.
239
+
240
+ = 1.3 =
241
+ * Added a widget. Now you can show top rated posts in your sidebar :).
242
+
243
+ = 1.2 =
244
+ * Added possibility to show ratings of any post anywhere in your theme files.
245
+
246
+ = 1.1 =
247
+ * Fixed the [avg] error, so now it will display average ratings properly.
248
+
249
+ == Upgrade Notice ==
widget.php CHANGED
@@ -1,104 +1,102 @@
1
- <?php
2
-
3
- // Make sure class does not already exist (Playing safe) and that the get function exists
4
- if(!class_exists('BhittaniPlugin_kkStarRatings_Widget') && function_exists('kk_star_ratings_get')) :
5
-
6
- class BhittaniPlugin_kkStarRatings_Widget extends WP_Widget
7
- {
8
- // Runs when OBJECT DECLARED (Instanciated)
9
- public function __construct()
10
- {
11
- $widget_options = array(
12
- 'classname' => 'kk-star-ratings-widget',
13
- 'description' => 'Show top rated posts'
14
- );
15
- parent::__construct('BhittaniPlugin_kkStarRatings_Widget', 'kk Star Ratings', $widget_options);
16
- }
17
- // Outputs USER INTERFACE
18
- public function widget($args, $instance)
19
- {
20
- extract( $args, EXTR_SKIP );
21
- $title = ( !empty($instance['title']) ) ? $instance['title'] : 'Top Posts';
22
- $total = ( !empty($instance['noofposts']) ) ? $instance['noofposts'] : '5';
23
- $category = ( $instance['category'] ) ? $instance['category'] : false;
24
- $sr = ($instance['showrating']) ? true : false;
25
-
26
- echo $before_widget;
27
- echo $before_title . $title . $after_title;
28
-
29
- // OUTPUT starts
30
- $posts = kk_star_ratings_get($total, $category);
31
- echo '<ul>';
32
- foreach ($posts as $post)
33
- {
34
- echo "<li><a href='".get_permalink($post->ID)."'>".$post->post_title."</a>";
35
- if($sr)
36
- {
37
- echo " <span style='font-size:10px;'>(".$post->ratings."/5)</span>";
38
- }
39
- echo "</li>";
40
- }
41
- echo '</ul>';
42
- // OUTPUT ends
43
-
44
- echo $after_widget;
45
- }
46
- // Updates OPTIONS
47
- /*
48
- public function update()
49
- {
50
-
51
- }
52
- */
53
- // The option FORM
54
- public function form( $instance )
55
- {
56
- ?>
57
- <p>
58
- <label for="<?php echo $this->get_field_id('title'); ?>">Title:
59
- <input id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr(!empty($instance['title'])?$instance['title']: 'Top Posts'); ?>" /></label>
60
- </p>
61
- <p>
62
- <label for="<?php echo $this->get_field_id('noofposts'); ?>">No of Posts:
63
- <input id="<?php echo $this->get_field_id('noofposts'); ?>" name="<?php echo $this->get_field_name('noofposts'); ?>" type="text" value="<?php echo esc_attr(!empty($instance['noofposts'])?$instance['noofposts']: '5'); ?>" size="3" /></label>
64
- </p>
65
- <p>
66
- <label for="<?php echo $this->get_field_id('showrating'); ?>">Show Average?:
67
- <select id="<?php echo $this->get_field_id('showrating'); ?>" name="<?php echo $this->get_field_name('showrating'); ?>">
68
- <option value="0" <?php if(isset($instance['showrating']) && !esc_attr($instance['showrating'])){echo "selected='selected'";} ?>>No</option>
69
- <option value="1" <?php if(isset($instance['showrating']) && esc_attr($instance['showrating'])){echo "selected='selected'";} ?>>Yes</option>
70
- </select>
71
- </label>
72
- </p>
73
- <p>
74
- <label for="<?php echo $this->get_field_id('category'); ?>">Filter by Category:
75
- <select id="<?php echo $this->get_field_id('category'); ?>" name="<?php echo $this->get_field_name('category'); ?>">
76
- <option value="0">Select</option>
77
- <?php
78
- foreach(get_categories(array()) as $category)
79
- {
80
- echo '<option value="'.$category->term_id.'"';
81
- if(isset($instance['category']) && esc_attr($instance['category'])==$category->term_id)
82
- echo ' selected="selected"';
83
- echo '>'.$category->name.'</option>';
84
- }
85
- ?>
86
- </select>
87
- </label>
88
- </p>
89
- <?php
90
- }
91
- }
92
-
93
- if(!function_exists('kk_star_ratings_widget_init'))
94
- {
95
- function kk_star_ratings_widget_init()
96
- {
97
- register_widget('BhittaniPlugin_kkStarRatings_Widget');
98
- }
99
- add_action('widgets_init', 'kk_star_ratings_widget_init');
100
- }
101
-
102
- endif;
103
-
104
- ?>
1
+ <?php
2
+
3
+ // Make sure class does not already exist (Playing safe) and that the get function exists
4
+ if(!class_exists('BhittaniPlugin_kkStarRatings_Widget') && function_exists('kk_star_ratings_get')) :
5
+
6
+ class BhittaniPlugin_kkStarRatings_Widget extends WP_Widget
7
+ {
8
+ // Runs when OBJECT DECLARED (Instanciated)
9
+ public function __construct()
10
+ {
11
+ $widget_options = array(
12
+ 'classname' => 'kk-star-ratings-widget',
13
+ 'description' => 'Show top rated posts'
14
+ );
15
+ parent::__construct('BhittaniPlugin_kkStarRatings_Widget', 'kk Star Ratings', $widget_options);
16
+ }
17
+ // Outputs USER INTERFACE
18
+ public function widget($args, $instance)
19
+ {
20
+ extract( $args, EXTR_SKIP );
21
+ $title = ( !empty($instance['title']) ) ? $instance['title'] : 'Top Posts';
22
+ $total = ( !empty($instance['noofposts']) ) ? $instance['noofposts'] : '5';
23
+ $category = ( $instance['category'] ) ? $instance['category'] : false;
24
+ $sr = ($instance['showrating']) ? true : false;
25
+
26
+ echo $before_widget;
27
+ echo $before_title . $title . $after_title;
28
+
29
+ // OUTPUT starts
30
+ $posts = kk_star_ratings_get($total, $category);
31
+ echo '<ul>';
32
+ foreach ($posts as $post)
33
+ {
34
+ echo "<li><a href='".get_permalink($post->ID)."'>".$post->post_title."</a>";
35
+ if($sr)
36
+ {
37
+ echo " <span style='font-size:10px;'>(".$post->ratings."/5)</span>";
38
+ }
39
+ echo "</li>";
40
+ }
41
+ echo '</ul>';
42
+ // OUTPUT ends
43
+
44
+ echo $after_widget;
45
+ }
46
+ // Updates OPTIONS
47
+ /*
48
+ public function update()
49
+ {
50
+
51
+ }
52
+ */
53
+ // The option FORM
54
+ public function form( $instance )
55
+ {
56
+ ?>
57
+ <p>
58
+ <label for="<?php echo $this->get_field_id('title'); ?>">Title:
59
+ <input id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr(!empty($instance['title'])?$instance['title']: 'Top Posts'); ?>" /></label>
60
+ </p>
61
+ <p>
62
+ <label for="<?php echo $this->get_field_id('noofposts'); ?>">No of Posts:
63
+ <input id="<?php echo $this->get_field_id('noofposts'); ?>" name="<?php echo $this->get_field_name('noofposts'); ?>" type="text" value="<?php echo esc_attr(!empty($instance['noofposts'])?$instance['noofposts']: '5'); ?>" size="3" /></label>
64
+ </p>
65
+ <p>
66
+ <label for="<?php echo $this->get_field_id('showrating'); ?>">Show Average?:
67
+ <select id="<?php echo $this->get_field_id('showrating'); ?>" name="<?php echo $this->get_field_name('showrating'); ?>">
68
+ <option value="0" <?php if(isset($instance['showrating']) && !esc_attr($instance['showrating'])){echo "selected='selected'";} ?>>No</option>
69
+ <option value="1" <?php if(isset($instance['showrating']) && esc_attr($instance['showrating'])){echo "selected='selected'";} ?>>Yes</option>
70
+ </select>
71
+ </label>
72
+ </p>
73
+ <p>
74
+ <label for="<?php echo $this->get_field_id('category'); ?>">Filter by Category:
75
+ <select id="<?php echo $this->get_field_id('category'); ?>" name="<?php echo $this->get_field_name('category'); ?>">
76
+ <option value="0">Select</option>
77
+ <?php
78
+ foreach(get_categories(array()) as $category)
79
+ {
80
+ echo '<option value="'.$category->term_id.'"';
81
+ if(isset($instance['category']) && esc_attr($instance['category'])==$category->term_id)
82
+ echo ' selected="selected"';
83
+ echo '>'.$category->name.'</option>';
84
+ }
85
+ ?>
86
+ </select>
87
+ </label>
88
+ </p>
89
+ <?php
90
+ }
91
+ }
92
+
93
+ if(!function_exists('kk_star_ratings_widget_init'))
94
+ {
95
+ function kk_star_ratings_widget_init()
96
+ {
97
+ register_widget('BhittaniPlugin_kkStarRatings_Widget');
98
+ }
99
+ add_action('widgets_init', 'kk_star_ratings_widget_init');
100
+ }
101
+
102
+ endif;
 
 
yellow.png CHANGED
Binary file