kk Star Ratings - Version 2.6

Version Description

  • Fix: Parse legend correctly when not using google rich snippets.
  • Fix: Admin screen colum notice bug.
  • Fix: Show ratings at correct location when shortcode is used.
  • Fix: Widget average values to reflect amount of stars being used.
  • Update: Use one decimal point in average.
  • Update: Use a single source of truth for parsing the legend.
  • Update: Optimize images.
  • Add: Allow [best] value in legend to show the total possible stars.
Download this release

Release Info

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

Code changes from version 2.5.2 to 2.6

admin.php CHANGED
@@ -1,446 +1,447 @@
1
- <div class="bhittani-framework">
2
- <?php if(isset($sidebar)) : ?>
3
- <div class="bf-wrap-small _right">
4
-
5
- <a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=CM659D9SHGKE6" target="_blank"
6
- style="background-color: #B24747;
7
- border: 1px solid #883232;
8
- border-radius: 3px;
9
- color: #fff;
10
- padding: .75em;
11
- display: block;
12
- width: 140px;
13
- text-align: center;
14
- font-size: 14px;">
15
- Donate to this plugin
16
- </a>
17
-
18
- <br>
19
-
20
- <!-- Place this tag where you want the button to render. -->
21
- <a class="github-button" href="https://github.com/kamalkhan/kk-star-ratings" data-icon="octicon-star" data-style="mega" data-count-href="/kamalkhan/kk-star-ratings/stargazers" data-count-api="/repos/kamalkhan/kk-star-ratings#stargazers_count" data-count-aria-label="# stargazers on GitHub" aria-label="Star kamalkhan/kk-star-ratings on GitHub">
22
- kk Star Ratings
23
- </a>
24
- <br><br>
25
- <!-- Place this tag right after the last button or just before your close body tag. -->
26
- <script async defer id="github-bjs" src="https://buttons.github.io/buttons.js"></script>
27
-
28
- <a href="http://bit.ly/awesome-live-chat" title="Awesome Live Chat" target="_blank">
29
- <img alt="Awesome Live Chat - CodeCanyon Item for Sale" border="0" class="landscape-image-magnifier preload no_preview" data-google-analytics-payload="{&quot;id&quot;:9931156,&quot;name&quot;:&quot;Awesome Live Chat&quot;,&quot;brand&quot;:&quot;KamalKhan&quot;,&quot;category&quot;:&quot;codecanyon.net/category/wordpress&quot;,&quot;position&quot;:5,&quot;list&quot;:&quot;Author portfolio&quot;}" data-item-author="KamalKhan" data-item-category="WordPress" data-item-cost="25" data-item-id="9931156" data-item-name="Awesome Live Chat" data-preview-height="" data-preview-url="https://preview-cc.s3.envato.com/files/116826712/jumbotron.jpg" data-preview-width="" height="80" src="https://thumb-cc.s3.envato.com/files/116826711/thumbnail.jpg" title="" width="80" data-tooltip="Awesome Live Chat">
30
- </a>
31
- <a href="http://bit.ly/awesome-live-chat-os-x" title="Awesome Live Chat Desk OS X" target="_blank">
32
- <img alt="Awesome Live Chat Desk OS X - CodeCanyon Item for Sale" border="0" class="landscape-image-magnifier preload no_preview" data-google-analytics-payload="{&quot;id&quot;:10106623,&quot;name&quot;:&quot;Awesome Live Chat Desk OS X&quot;,&quot;brand&quot;:&quot;KamalKhan&quot;,&quot;category&quot;:&quot;codecanyon.net/category/apps/mac&quot;,&quot;position&quot;:3,&quot;list&quot;:&quot;Author portfolio&quot;}" data-item-author="KamalKhan" data-item-category="Apps / Mac" data-item-cost="10" data-item-id="10106623" data-item-name="Awesome Live Chat Desk OS X" data-preview-height="" data-preview-url="https://preview-cc.s3.envato.com/files/118693278/jumbotron-osx.png" data-preview-width="" height="80" src="https://thumb-cc.s3.envato.com/files/118693274/thumbnail.png" title="" width="80" data-tooltip="Awesome Live Chat Desk OS X">
33
- </a>
34
- <a href="http://bit.ly/awesome-live-chat-pc" title="Awesome Live Chat Desk PC" target="_blank">
35
- <img alt="Awesome Live Chat Desk PC - CodeCanyon Item for Sale" border="0" class="landscape-image-magnifier preload no_preview" data-google-analytics-payload="{&quot;id&quot;:10398931,&quot;name&quot;:&quot;Awesome Live Chat Desk PC&quot;,&quot;brand&quot;:&quot;KamalKhan&quot;,&quot;category&quot;:&quot;codecanyon.net/category/apps/windows&quot;,&quot;position&quot;:2,&quot;list&quot;:&quot;Author portfolio&quot;}" data-item-author="KamalKhan" data-item-category="Apps / Windows" data-item-cost="11" data-item-id="10398931" data-item-name="Awesome Live Chat Desk PC" data-preview-height="" data-preview-url="https://preview-cc.s3.envato.com/files/122225936/jumbotron-pc.png" data-preview-width="" height="80" src="https://thumb-cc.s3.envato.com/files/122225933/thumbnail.png" title="" width="80" data-tooltip="Awesome Live Chat Desk PC">
36
- </a>
37
- <a href="http://bit.ly/awesome-live-chat-desk-linux" title="Awesome Live Chat Desk Linux" target="_blank">
38
- <img alt="Awesome Live Chat Desk Linux - CodeCanyon Item for Sale" border="0" class="landscape-image-magnifier preload no_preview" data-google-analytics-payload="{&quot;id&quot;:11996346,&quot;name&quot;:&quot;Awesome Live Chat Desk Linux&quot;,&quot;brand&quot;:&quot;KamalKhan&quot;,&quot;category&quot;:&quot;codecanyon.net/category/html5/miscellaneous&quot;,&quot;position&quot;:1,&quot;list&quot;:&quot;Author portfolio&quot;}" data-item-author="KamalKhan" data-item-category="HTML5 / Miscellaneous" data-item-cost="11" data-item-id="11996346" data-item-name="Awesome Live Chat Desk Linux" data-preview-height="" data-preview-url="https://preview-cc.s3.envato.com/files/140022646/jumbotron-linux.png" data-preview-width="" height="80" src="https://thumb-cc.s3.envato.com/files/140022645/thumbnail.png" title="" width="80" data-tooltip="Awesome Live Chat Desk Linux">
39
- </a>
40
- <?php
41
- /*
42
- <a href="http://bit.ly/awesome-live-chat-server" title="Awesome Live Chat Server" target="_blank">
43
- <img alt="Awesome Live Chat Server - CodeCanyon Item for Sale" border="0" class="landscape-image-magnifier preload no_preview" data-google-analytics-payload="{&quot;id&quot;:10010235,&quot;name&quot;:&quot;Awesome Live Chat Server&quot;,&quot;brand&quot;:&quot;KamalKhan&quot;,&quot;category&quot;:&quot;codecanyon.net/category/javascript/miscellaneous&quot;,&quot;position&quot;:4,&quot;list&quot;:&quot;Author portfolio&quot;}" data-item-author="KamalKhan" data-item-category="JavaScript / Miscellaneous" data-item-cost="14" data-item-id="10010235" data-item-name="Awesome Live Chat Server" data-preview-height="" data-preview-url="https://preview-cc.s3.envato.com/files/117666866/jumbotron.png" data-preview-width="" height="80" src="https://thumb-cc.s3.envato.com/files/117666864/thumbnail.png" title="" width="80" data-tooltip="Awesome Live Chat Server">
44
- </a>
45
- */
46
- ?>
47
- </div>
48
- <!-- bf-wrap-small -->
49
- <?php endif; ?>
50
- <div class="bf-wrap">
51
- <div class="bf_head">
52
- <ul class="bf_navs _right">
53
- <li<?php echo ($opt=='general')?' class="active"':''; ?>><a href="#Settings">Settings</a></li>
54
- <li<?php echo ($opt=='stars')?' class="active"':''; ?>><a href="#Stars">Stars</a></li>
55
- <li<?php echo ($opt=='tooltips')?' class="active"':''; ?>><a href="#Tooltips">Tooltips</a></li>
56
- <li<?php echo ($opt=='reset')?' class="active"':''; ?>><a href="#Reset">Reset</a></li>
57
- <li<?php echo ($opt=='info')?' class="active"':''; ?>><a href="#Help">Help</a></li>
58
- <li class="bf-save"><a href="#" rel="save-options">Save</a></li>
59
- </ul>
60
- <!--bf_navs-->
61
- <div class="bf_logo">
62
- <h3>
63
- <?php echo $h3; ?>
64
- </h3>
65
- <div class="links">
66
- <div id="fb-root"></div>
67
- <script>(function(d, s, id) {
68
- var js, fjs = d.getElementsByTagName(s)[0];
69
- if (d.getElementById(id)) return;
70
- js = d.createElement(s); js.id = id;
71
- js.src = "//connect.facebook.net/en_US/sdk.js#xfbml=1&version=v2.5";
72
- fjs.parentNode.insertBefore(js, fjs);
73
- }(document, 'script', 'facebook-jssdk'));</script>
74
- <div class="fb-like" data-href="https://github.com/kamalkhan/kk-star-ratings" data-width="167" data-layout="button_count" data-action="like" data-show-faces="true" data-share="true"></div>
75
- <?php
76
- if(isset($Url) && is_array($Url))
77
- {
78
- $url_sep = '';
79
- foreach($Url as $url)
80
- {
81
- echo $url_sep . '<a href="'.$url['link'].'" target="_blank">' . $url['title'] . '</a>';
82
- $url_sep = ' | ';
83
- }
84
- }
85
- ?>
86
- </div>
87
- </div>
88
- <!--bf_logo-->
89
- </div>
90
- <!--bf_head-->
91
- <form method="post" action="" name="bf_form">
92
- <div class="bf_container __settings <?php echo ($opt=='general')?'__active':''; ?>">
93
- <?php
94
-
95
- BhittaniPlugin_AdminMarkup::checkbox(array(
96
- 'title' => 'Enable/Disable',
97
- 'description' => 'Choose whether you want to enable or disable the plugin',
98
- 'obj' => array(
99
- array(
100
- 'field' => 'kksr_enable',
101
- 'label' => 'Enable',
102
- 'value' => get_option('kksr_enable')
103
- )
104
- )
105
- ));
106
- BhittaniPlugin_AdminMarkup::checkbox(array(
107
- 'title' => 'Placement',
108
- 'description' => 'Choose where you want the ratings to be placed',
109
- 'obj' => array(
110
- array(
111
- 'field' => 'kksr_show_in_home',
112
- 'label' => 'Show on Home Page',
113
- 'value' => get_option('kksr_show_in_home')
114
- ),
115
- array(
116
- 'field' => 'kksr_show_in_archives',
117
- 'label' => 'Show in Archives',
118
- 'value' => get_option('kksr_show_in_archives')
119
- ),
120
- array(
121
- 'field' => 'kksr_show_in_posts',
122
- 'label' => 'Show in Posts',
123
- 'value' => get_option('kksr_show_in_posts')
124
- ),
125
- array(
126
- 'field' => 'kksr_show_in_pages',
127
- 'label' => 'Show in Pages',
128
- 'value' => get_option('kksr_show_in_pages')
129
- ),
130
- array(
131
- 'field' => 'kksr_disable_in_archives',
132
- 'label' => 'Disable voting in archives',
133
- 'value' => get_option('kksr_disable_in_archives')
134
- )
135
- )
136
- ));
137
- BhittaniPlugin_AdminMarkup::input(array(
138
- 'title' => 'Exclude following category(s)',
139
- 'description' => 'Comma seperated ids of categories.<br />e.g. <em>5,47,2</em>',
140
- 'field' => 'kksr_exclude_categories',
141
- 'value' => get_option('kksr_exclude_categories')
142
- ));
143
- BhittaniPlugin_AdminMarkup::checkbox(array(
144
- 'title' => 'Google Rich Snippets',
145
- 'description' => 'Do you want Google to index the ratings and hopefully show it in the search results',
146
- 'obj' => array(
147
- array(
148
- 'field' => 'kksr_grs',
149
- 'label' => 'Enable',
150
- 'value' => get_option('kksr_grs')
151
- )
152
- )
153
- ));
154
- BhittaniPlugin_AdminMarkup::checkbox(array(
155
- 'title' => 'Unique voting',
156
- 'description' => 'Choose whether you want unique votings based on IP or not',
157
- 'obj' => array(
158
- array(
159
- 'field' => 'kksr_unique',
160
- 'label' => 'Unique based on User IP',
161
- 'value' => get_option('kksr_unique')
162
- )
163
- )
164
- ));
165
- BhittaniPlugin_AdminMarkup::checkbox(array(
166
- 'title' => 'Clear line',
167
- 'description' => 'Choose whether you want the ratings to be on its own line rather than floated',
168
- 'obj' => array(
169
- array(
170
- 'field' => 'kksr_clear',
171
- 'label' => 'Clear',
172
- 'value' => get_option('kksr_clear')
173
- )
174
- )
175
- ));
176
- BhittaniPlugin_AdminMarkup::checkbox(array(
177
- 'title' => 'Admin screen column',
178
- 'description' => 'Choose whether you want a ratings column in the admin post/page screen',
179
- 'obj' => array(
180
- array(
181
- 'field' => 'kksr_column',
182
- 'label' => 'Admin Posts/Pages Column',
183
- 'value' => get_option('kksr_column')
184
- )
185
- )
186
- ));
187
- BhittaniPlugin_AdminMarkup::input(array(
188
- 'title' => 'Legend',
189
- 'description' => '
190
- How do you want the legend of the ratings to be shown? <br />
191
- <strong>Variables</strong> <br />
192
- <code>[total]</code>=total ratings <br />
193
- <code>[avg]</code>=average <br />
194
- <code>[per]</code>=percentage <br />
195
- <code>[s]</code>=for plural vs singular of votes occurred <br />
196
- <strong>NOTE</strong> <br />
197
- <code>[total]</code> and <code>[avg]</code> is mandatory for Google Rich Snippets to work
198
- ',
199
- 'field' => 'kksr_legend',
200
- 'value' => get_option('kksr_legend')
201
- ));
202
- BhittaniPlugin_AdminMarkup::select(array(
203
- 'title' => 'Position',
204
- 'description' => 'Choose the position of the ratings',
205
- 'field' => 'kksr_position',
206
- 'options' => array(
207
- array('top-left','Top Left'),
208
- array('top-right','Top Right'),
209
- array('bottom-left','Bottom Left'),
210
- array('bottom-right','Bottom Right'),
211
- ),
212
- 'value' => get_option('kksr_position')
213
- ));
214
- BhittaniPlugin_AdminMarkup::input(array(
215
- 'title' => 'Speed of fueling (in milliseconds)',
216
- 'description' => 'Adjust the speed of the fueling of stars in milliseconds',
217
- 'field' => 'kksr_js_fuelspeed',
218
- 'value' => get_option('kksr_js_fuelspeed')
219
- ));
220
- BhittaniPlugin_AdminMarkup::input(array(
221
- 'title' => 'Initial text',
222
- 'description' => 'Text to be displayed when there are no ratings',
223
- 'field' => 'kksr_init_msg',
224
- 'value' => get_option('kksr_init_msg')
225
- ));
226
- BhittaniPlugin_AdminMarkup::input(array(
227
- 'title' => 'Thank you message',
228
- 'description' => 'Text to be displayed when user places a vote',
229
- 'field' => 'kksr_js_thankyou',
230
- 'value' => get_option('kksr_js_thankyou')
231
- ));
232
- BhittaniPlugin_AdminMarkup::input(array(
233
- 'title' => 'Error message',
234
- 'description' => 'Text to be displayed when something goes wrong unexpectidly',
235
- 'field' => 'kksr_js_error',
236
- 'value' => get_option('kksr_js_error')
237
- ));
238
- ?>
239
- </div>
240
- <!--bf_container __general-->
241
- <div class="bf_container __stars <?php echo ($opt=='stars')?'__active':''; ?>">
242
- <?php
243
- BhittaniPlugin_AdminMarkup::input(array(
244
- 'title' => 'Amount of stars',
245
- 'description' => 'How many stars do you want the ratings based on? Enter a numeric value',
246
- 'field' => 'kksr_stars',
247
- 'value' => get_option('kksr_stars')
248
- ));
249
- BhittaniPlugin_AdminMarkup::input(array(
250
- 'title' => 'Width of single star',
251
- 'description' => 'Set the width of a single star in pixels(px).<br /><strong>Note: </strong>All stars must be of equal width',
252
- 'field' => 'kksr_stars_w',
253
- 'value' => get_option('kksr_stars_w')
254
- ));
255
- BhittaniPlugin_AdminMarkup::input(array(
256
- 'title' => 'Height of single star',
257
- 'description' => 'Set the height of a single star in pixels(px).<br /><strong>Note: </strong>All stars must be of equal height',
258
- 'field' => 'kksr_stars_h',
259
- 'value' => get_option('kksr_stars_h')
260
- ));
261
- BhittaniPlugin_AdminMarkup::image(array(
262
- 'title' => 'Gray Star',
263
- 'description' => 'You can modify the gray star image here',
264
- 'field' => 'kksr_stars_gray',
265
- 'label' => 'Choose an image',
266
- 'caption' => 'Gray Star',
267
- 'value' => get_option('kksr_stars_gray') ? get_option('kksr_stars_gray') : BhittaniPlugin_kkStarRatings::file_uri('gray.png')
268
- ));
269
- BhittaniPlugin_AdminMarkup::image(array(
270
- 'title' => 'Yellow Star',
271
- 'description' => 'You can modify the yellow star image here',
272
- 'field' => 'kksr_stars_yellow',
273
- 'label' => 'Choose an image',
274
- 'caption' => 'Yellow Star',
275
- 'value' => get_option('kksr_stars_yellow') ? get_option('kksr_stars_yellow') : BhittaniPlugin_kkStarRatings::file_uri('yellow.png')
276
- ));
277
- BhittaniPlugin_AdminMarkup::image(array(
278
- 'title' => 'Orange Star',
279
- 'description' => 'You can modify the orange star image here',
280
- 'field' => 'kksr_stars_orange',
281
- 'label' => 'Choose an image',
282
- 'caption' => 'Orange Star',
283
- 'value' => get_option('kksr_stars_orange') ? get_option('kksr_stars_orange') : BhittaniPlugin_kkStarRatings::file_uri('orange.png')
284
- ));
285
- ?>
286
- </div>
287
- <!--bf_container __stars-->
288
- <div class="bf_container __tooltips <?php echo ($opt=='tooltips')?'__active':''; ?>">
289
- <?php
290
- BhittaniPlugin_AdminMarkup::checkbox(array(
291
- 'title' => 'Tooltips',
292
- 'description' => 'Choose whether you want to enable or disable the tooltips',
293
- 'obj' => array(
294
- array(
295
- 'field' => 'kksr_tooltip',
296
- 'label' => 'Enable Tooltips',
297
- 'value' => get_option('kksr_tooltip')
298
- )
299
- )
300
- ));
301
- $Tooltips = get_option('kksr_tooltips');
302
- for($tooltip_i=0;$tooltip_i<get_option('kksr_stars');$tooltip_i++)
303
- {
304
- BhittaniPlugin_AdminMarkup::input(array(
305
- 'title' => 'Tooltip - star '.($tooltip_i+1),
306
- 'description' => 'Displayed when mouse is hovered over star '.($tooltip_i+1),
307
- 'field' => 'kksr_tooltips['.($tooltip_i).'][tip]',
308
- 'value' => isset($Tooltips[$tooltip_i]['tip']) ? $Tooltips[$tooltip_i]['tip'] : ''
309
- ));
310
- BhittaniPlugin_AdminMarkup::color(array(
311
- 'title' => 'Tooltip Color - star '.($tooltip_i+1),
312
- 'description' => 'Color for tooltip of star '.($tooltip_i+1),
313
- 'field' => 'kksr_tooltips['.($tooltip_i).'][color]',
314
- 'label' => 'Choose a color',
315
- 'value' => isset($Tooltips[$tooltip_i]['color']) ? $Tooltips[$tooltip_i]['color'] : '#ffffff'
316
- ));
317
- }
318
- ?>
319
- </div>
320
- <!--bf_container __tooltips-->
321
- <div class="bf_container __reset <?php echo ($opt=='reset')?'__active':''; ?>">
322
- <?php
323
- global $wpdb;
324
- $table = $wpdb->prefix . 'postmeta';
325
- $Posts = $wpdb->get_results("SELECT a.ID, a.post_title
326
- FROM " . $wpdb->posts . " a, $table b
327
- WHERE a.ID=b.post_id AND
328
- b.meta_key='_kksr_ratings'
329
- ORDER BY a.ID ASC");
330
- if(is_array($Posts))
331
- {
332
- $Obj = array();
333
- foreach($Posts as $post)
334
- {
335
- $Obj[] = array(
336
- 'field' => 'kksr_reset['.$post->ID.']',
337
- 'label' => $post->post_title,
338
- 'class' => '_kksr_reset'
339
- );
340
- }
341
- if(count($Obj))
342
- {
343
- BhittaniPlugin_AdminMarkup::html('<p>Select the posts/pages below
344
- and click the reset button to reset
345
- their ratings.</p>
346
- <p>
347
- <a href="#" rel="kksr-reset-all" class="button">Select All</a>
348
- <a href="#" rel="kksr-reset-none" class="button">Select None</a>
349
- <a href="#" rel="kksr-reset" class="button-primary" style="color:white;">Reset</a>
350
- </p>'
351
- );
352
- BhittaniPlugin_AdminMarkup::checkbox(array(
353
- 'title' => '',
354
- 'description' => '',
355
- 'pclass' => '_left',
356
- 'obj' => $Obj
357
- ));
358
- }
359
- else
360
- {
361
- BhittaniPlugin_AdminMarkup::html('No ratings have been placed.');
362
- }
363
- }
364
- else
365
- {
366
- BhittaniPlugin_AdminMarkup::html('No ratings have been placed.');
367
- }
368
- ?>
369
- </div>
370
- <!--bf_container __reset-->
371
- <div class="bf_container __help <?php echo ($opt=='info')?'__active':''; ?>">
372
- <?php
373
- BhittaniPlugin_AdminMarkup::html(
374
- '<p>
375
- <strong>To manually use in your post/page using admin screen, use the star icon in your post/page editor</strong>
376
- <br /><br />
377
- <strong>For use in theme files:</strong>
378
- <br /> <code class="_block">&lt;?php if(function_exists("kk_star_ratings")) : echo kk_star_ratings($pid); endif; ?&gt;</code>
379
- <br />Where $pid is the id of the post
380
- <br /><br />
381
- <strong>Get top rated posts as array of objects:</strong>
382
- <br /> <code class="_block">&lt;?php <br /> if(function_exists("kk_star_ratings_get")) <br /> { <br /> $top_rated_posts = kk_star_ratings_get($total); <br /> } <br />?&gt;</code>
383
- <br />Where $total is the limit (int)
384
- <br />$top_rated_posts will contain an array of objects, each containing an ID and ratings.
385
- <br />
386
- Example Usage:
387
- <code class="_block">
388
- <pre>
389
- foreach($top_rated_posts as $post)
390
- {
391
- // you get $post->ID and $post->ratings
392
- // Do anything with it like get_post($post->ID)
393
- // ...
394
- }
395
- </pre>
396
- </code>
397
- <strong>Action Hooks</strong>
398
- <br />
399
- When post rating is fetched initially.
400
- <code class="_block">
401
- <pre>
402
- add_action("kksr_init", "my_super_function1", 10, 3);
403
- </pre>
404
- </code>
405
- example usage:
406
- <code class="_block">
407
- <pre>
408
- function my_super_function1($post_id, $avg, $votes);
409
- {
410
- // $post_id is the id of the post.
411
- // $avg is the average ratings as a string (e.g. 4.3/5).
412
- // $votes is the total amount of votes occured.
413
-
414
- // Do your magic below
415
- }
416
- </pre>
417
- </code>
418
- When a post gets rated
419
- <code class="_block">
420
- <pre>
421
- add_action("kksr_rate", "my_super_function2", 10, 3);
422
- </pre>
423
- </code>
424
- example usage:
425
- <code class="_block">
426
- <pre>
427
- function my_super_function2($post_id, $no_of_stars, $ip_address);
428
- {
429
- // $post_id is the id of the post.
430
- // $no_of_stars is the amount of stars the user rated.
431
- // $ip_address is the ip address of the user.
432
-
433
- // Do your magic below
434
- }
435
- </pre>
436
- </code>
437
- </p>'
438
- );
439
- ?>
440
- </div>
441
- <!--bf_container __help-->
442
- </form>
443
- </div>
444
- <!-- bf-wrap -->
445
- </div>
446
- <!--bhittani-framework-->
 
1
+ <div class="bhittani-framework">
2
+ <?php if(isset($sidebar)) : ?>
3
+ <div class="bf-wrap-small _right">
4
+
5
+ <a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=CM659D9SHGKE6" target="_blank"
6
+ style="background-color: #B24747;
7
+ border: 1px solid #883232;
8
+ border-radius: 3px;
9
+ color: #fff;
10
+ padding: .75em;
11
+ display: block;
12
+ width: 140px;
13
+ text-align: center;
14
+ font-size: 14px;">
15
+ Donate to this plugin
16
+ </a>
17
+
18
+ <br>
19
+
20
+ <!-- Place this tag where you want the button to render. -->
21
+ <a class="github-button" href="https://github.com/kamalkhan/kk-star-ratings" data-icon="octicon-star" data-style="mega" data-count-href="/kamalkhan/kk-star-ratings/stargazers" data-count-api="/repos/kamalkhan/kk-star-ratings#stargazers_count" data-count-aria-label="# stargazers on GitHub" aria-label="Star kamalkhan/kk-star-ratings on GitHub">
22
+ kk Star Ratings
23
+ </a>
24
+ <br><br>
25
+ <!-- Place this tag right after the last button or just before your close body tag. -->
26
+ <script async defer id="github-bjs" src="https://buttons.github.io/buttons.js"></script>
27
+
28
+ <a href="http://bit.ly/awesome-live-chat" title="Awesome Live Chat" target="_blank">
29
+ <img alt="Awesome Live Chat - CodeCanyon Item for Sale" border="0" class="landscape-image-magnifier preload no_preview" data-google-analytics-payload="{&quot;id&quot;:9931156,&quot;name&quot;:&quot;Awesome Live Chat&quot;,&quot;brand&quot;:&quot;KamalKhan&quot;,&quot;category&quot;:&quot;codecanyon.net/category/wordpress&quot;,&quot;position&quot;:5,&quot;list&quot;:&quot;Author portfolio&quot;}" data-item-author="KamalKhan" data-item-category="WordPress" data-item-cost="25" data-item-id="9931156" data-item-name="Awesome Live Chat" data-preview-height="" data-preview-url="https://preview-cc.s3.envato.com/files/116826712/jumbotron.jpg" data-preview-width="" height="80" src="https://thumb-cc.s3.envato.com/files/116826711/thumbnail.jpg" title="" width="80" data-tooltip="Awesome Live Chat">
30
+ </a>
31
+ <a href="http://bit.ly/awesome-live-chat-os-x" title="Awesome Live Chat Desk OS X" target="_blank">
32
+ <img alt="Awesome Live Chat Desk OS X - CodeCanyon Item for Sale" border="0" class="landscape-image-magnifier preload no_preview" data-google-analytics-payload="{&quot;id&quot;:10106623,&quot;name&quot;:&quot;Awesome Live Chat Desk OS X&quot;,&quot;brand&quot;:&quot;KamalKhan&quot;,&quot;category&quot;:&quot;codecanyon.net/category/apps/mac&quot;,&quot;position&quot;:3,&quot;list&quot;:&quot;Author portfolio&quot;}" data-item-author="KamalKhan" data-item-category="Apps / Mac" data-item-cost="10" data-item-id="10106623" data-item-name="Awesome Live Chat Desk OS X" data-preview-height="" data-preview-url="https://preview-cc.s3.envato.com/files/118693278/jumbotron-osx.png" data-preview-width="" height="80" src="https://thumb-cc.s3.envato.com/files/118693274/thumbnail.png" title="" width="80" data-tooltip="Awesome Live Chat Desk OS X">
33
+ </a>
34
+ <a href="http://bit.ly/awesome-live-chat-pc" title="Awesome Live Chat Desk PC" target="_blank">
35
+ <img alt="Awesome Live Chat Desk PC - CodeCanyon Item for Sale" border="0" class="landscape-image-magnifier preload no_preview" data-google-analytics-payload="{&quot;id&quot;:10398931,&quot;name&quot;:&quot;Awesome Live Chat Desk PC&quot;,&quot;brand&quot;:&quot;KamalKhan&quot;,&quot;category&quot;:&quot;codecanyon.net/category/apps/windows&quot;,&quot;position&quot;:2,&quot;list&quot;:&quot;Author portfolio&quot;}" data-item-author="KamalKhan" data-item-category="Apps / Windows" data-item-cost="11" data-item-id="10398931" data-item-name="Awesome Live Chat Desk PC" data-preview-height="" data-preview-url="https://preview-cc.s3.envato.com/files/122225936/jumbotron-pc.png" data-preview-width="" height="80" src="https://thumb-cc.s3.envato.com/files/122225933/thumbnail.png" title="" width="80" data-tooltip="Awesome Live Chat Desk PC">
36
+ </a>
37
+ <a href="http://bit.ly/awesome-live-chat-desk-linux" title="Awesome Live Chat Desk Linux" target="_blank">
38
+ <img alt="Awesome Live Chat Desk Linux - CodeCanyon Item for Sale" border="0" class="landscape-image-magnifier preload no_preview" data-google-analytics-payload="{&quot;id&quot;:11996346,&quot;name&quot;:&quot;Awesome Live Chat Desk Linux&quot;,&quot;brand&quot;:&quot;KamalKhan&quot;,&quot;category&quot;:&quot;codecanyon.net/category/html5/miscellaneous&quot;,&quot;position&quot;:1,&quot;list&quot;:&quot;Author portfolio&quot;}" data-item-author="KamalKhan" data-item-category="HTML5 / Miscellaneous" data-item-cost="11" data-item-id="11996346" data-item-name="Awesome Live Chat Desk Linux" data-preview-height="" data-preview-url="https://preview-cc.s3.envato.com/files/140022646/jumbotron-linux.png" data-preview-width="" height="80" src="https://thumb-cc.s3.envato.com/files/140022645/thumbnail.png" title="" width="80" data-tooltip="Awesome Live Chat Desk Linux">
39
+ </a>
40
+ <?php
41
+ /*
42
+ <a href="http://bit.ly/awesome-live-chat-server" title="Awesome Live Chat Server" target="_blank">
43
+ <img alt="Awesome Live Chat Server - CodeCanyon Item for Sale" border="0" class="landscape-image-magnifier preload no_preview" data-google-analytics-payload="{&quot;id&quot;:10010235,&quot;name&quot;:&quot;Awesome Live Chat Server&quot;,&quot;brand&quot;:&quot;KamalKhan&quot;,&quot;category&quot;:&quot;codecanyon.net/category/javascript/miscellaneous&quot;,&quot;position&quot;:4,&quot;list&quot;:&quot;Author portfolio&quot;}" data-item-author="KamalKhan" data-item-category="JavaScript / Miscellaneous" data-item-cost="14" data-item-id="10010235" data-item-name="Awesome Live Chat Server" data-preview-height="" data-preview-url="https://preview-cc.s3.envato.com/files/117666866/jumbotron.png" data-preview-width="" height="80" src="https://thumb-cc.s3.envato.com/files/117666864/thumbnail.png" title="" width="80" data-tooltip="Awesome Live Chat Server">
44
+ </a>
45
+ */
46
+ ?>
47
+ </div>
48
+ <!-- bf-wrap-small -->
49
+ <?php endif; ?>
50
+ <div class="bf-wrap">
51
+ <div class="bf_head">
52
+ <ul class="bf_navs _right">
53
+ <li<?php echo ($opt=='general')?' class="active"':''; ?>><a href="#Settings">Settings</a></li>
54
+ <li<?php echo ($opt=='stars')?' class="active"':''; ?>><a href="#Stars">Stars</a></li>
55
+ <li<?php echo ($opt=='tooltips')?' class="active"':''; ?>><a href="#Tooltips">Tooltips</a></li>
56
+ <li<?php echo ($opt=='reset')?' class="active"':''; ?>><a href="#Reset">Reset</a></li>
57
+ <li<?php echo ($opt=='info')?' class="active"':''; ?>><a href="#Help">Help</a></li>
58
+ <li class="bf-save"><a href="#" rel="save-options">Save</a></li>
59
+ </ul>
60
+ <!--bf_navs-->
61
+ <div class="bf_logo">
62
+ <h3>
63
+ <?php echo $h3; ?>
64
+ </h3>
65
+ <div class="links">
66
+ <div id="fb-root"></div>
67
+ <script>(function(d, s, id) {
68
+ var js, fjs = d.getElementsByTagName(s)[0];
69
+ if (d.getElementById(id)) return;
70
+ js = d.createElement(s); js.id = id;
71
+ js.src = "//connect.facebook.net/en_US/sdk.js#xfbml=1&version=v2.5";
72
+ fjs.parentNode.insertBefore(js, fjs);
73
+ }(document, 'script', 'facebook-jssdk'));</script>
74
+ <div class="fb-like" data-href="https://github.com/kamalkhan/kk-star-ratings" data-width="167" data-layout="button_count" data-action="like" data-show-faces="true" data-share="true"></div>
75
+ <?php
76
+ if(isset($Url) && is_array($Url))
77
+ {
78
+ $url_sep = '';
79
+ foreach($Url as $url)
80
+ {
81
+ echo $url_sep . '<a href="'.$url['link'].'" target="_blank">' . $url['title'] . '</a>';
82
+ $url_sep = ' | ';
83
+ }
84
+ }
85
+ ?>
86
+ </div>
87
+ </div>
88
+ <!--bf_logo-->
89
+ </div>
90
+ <!--bf_head-->
91
+ <form method="post" action="" name="bf_form">
92
+ <div class="bf_container __settings <?php echo ($opt=='general')?'__active':''; ?>">
93
+ <?php
94
+
95
+ BhittaniPlugin_AdminMarkup::checkbox(array(
96
+ 'title' => 'Enable/Disable',
97
+ 'description' => 'Choose whether you want to enable or disable the plugin',
98
+ 'obj' => array(
99
+ array(
100
+ 'field' => 'kksr_enable',
101
+ 'label' => 'Enable',
102
+ 'value' => get_option('kksr_enable')
103
+ )
104
+ )
105
+ ));
106
+ BhittaniPlugin_AdminMarkup::checkbox(array(
107
+ 'title' => 'Placement',
108
+ 'description' => 'Choose where you want the ratings to be placed',
109
+ 'obj' => array(
110
+ array(
111
+ 'field' => 'kksr_show_in_home',
112
+ 'label' => 'Show on Home Page',
113
+ 'value' => get_option('kksr_show_in_home')
114
+ ),
115
+ array(
116
+ 'field' => 'kksr_show_in_archives',
117
+ 'label' => 'Show in Archives',
118
+ 'value' => get_option('kksr_show_in_archives')
119
+ ),
120
+ array(
121
+ 'field' => 'kksr_show_in_posts',
122
+ 'label' => 'Show in Posts',
123
+ 'value' => get_option('kksr_show_in_posts')
124
+ ),
125
+ array(
126
+ 'field' => 'kksr_show_in_pages',
127
+ 'label' => 'Show in Pages',
128
+ 'value' => get_option('kksr_show_in_pages')
129
+ ),
130
+ array(
131
+ 'field' => 'kksr_disable_in_archives',
132
+ 'label' => 'Disable voting in archives',
133
+ 'value' => get_option('kksr_disable_in_archives')
134
+ )
135
+ )
136
+ ));
137
+ BhittaniPlugin_AdminMarkup::input(array(
138
+ 'title' => 'Exclude following category(s)',
139
+ 'description' => 'Comma seperated ids of categories.<br />e.g. <em>5,47,2</em>',
140
+ 'field' => 'kksr_exclude_categories',
141
+ 'value' => get_option('kksr_exclude_categories')
142
+ ));
143
+ BhittaniPlugin_AdminMarkup::checkbox(array(
144
+ 'title' => 'Google Rich Snippets',
145
+ 'description' => 'Do you want Google to index the ratings and hopefully show it in the search results',
146
+ 'obj' => array(
147
+ array(
148
+ 'field' => 'kksr_grs',
149
+ 'label' => 'Enable',
150
+ 'value' => get_option('kksr_grs')
151
+ )
152
+ )
153
+ ));
154
+ BhittaniPlugin_AdminMarkup::checkbox(array(
155
+ 'title' => 'Unique voting',
156
+ 'description' => 'Choose whether you want unique votings based on IP or not',
157
+ 'obj' => array(
158
+ array(
159
+ 'field' => 'kksr_unique',
160
+ 'label' => 'Unique based on User IP',
161
+ 'value' => get_option('kksr_unique')
162
+ )
163
+ )
164
+ ));
165
+ BhittaniPlugin_AdminMarkup::checkbox(array(
166
+ 'title' => 'Clear line',
167
+ 'description' => 'Choose whether you want the ratings to be on its own line rather than floated',
168
+ 'obj' => array(
169
+ array(
170
+ 'field' => 'kksr_clear',
171
+ 'label' => 'Clear',
172
+ 'value' => get_option('kksr_clear')
173
+ )
174
+ )
175
+ ));
176
+ BhittaniPlugin_AdminMarkup::checkbox(array(
177
+ 'title' => 'Admin screen column',
178
+ 'description' => 'Choose whether you want a ratings column in the admin post/page screen',
179
+ 'obj' => array(
180
+ array(
181
+ 'field' => 'kksr_column',
182
+ 'label' => 'Admin Posts/Pages Column',
183
+ 'value' => get_option('kksr_column')
184
+ )
185
+ )
186
+ ));
187
+ BhittaniPlugin_AdminMarkup::input(array(
188
+ 'title' => 'Legend',
189
+ 'description' => '
190
+ How do you want the legend of the ratings to be shown? <br />
191
+ <strong>Variables</strong> <br />
192
+ <code>[best]</code>=max stars <br />
193
+ <code>[total]</code>=total ratings <br />
194
+ <code>[avg]</code>=average <br />
195
+ <code>[per]</code>=percentage <br />
196
+ <code>[s]</code>=for plural vs singular of votes occurred <br />
197
+ <strong>NOTE</strong> <br />
198
+ <code>[total]</code> and <code>[avg]</code> is mandatory for Google Rich Snippets to work
199
+ ',
200
+ 'field' => 'kksr_legend',
201
+ 'value' => get_option('kksr_legend')
202
+ ));
203
+ BhittaniPlugin_AdminMarkup::select(array(
204
+ 'title' => 'Position',
205
+ 'description' => 'Choose the position of the ratings',
206
+ 'field' => 'kksr_position',
207
+ 'options' => array(
208
+ array('top-left','Top Left'),
209
+ array('top-right','Top Right'),
210
+ array('bottom-left','Bottom Left'),
211
+ array('bottom-right','Bottom Right'),
212
+ ),
213
+ 'value' => get_option('kksr_position')
214
+ ));
215
+ BhittaniPlugin_AdminMarkup::input(array(
216
+ 'title' => 'Speed of fueling (in milliseconds)',
217
+ 'description' => 'Adjust the speed of the fueling of stars in milliseconds',
218
+ 'field' => 'kksr_js_fuelspeed',
219
+ 'value' => get_option('kksr_js_fuelspeed')
220
+ ));
221
+ BhittaniPlugin_AdminMarkup::input(array(
222
+ 'title' => 'Initial text',
223
+ 'description' => 'Text to be displayed when there are no ratings',
224
+ 'field' => 'kksr_init_msg',
225
+ 'value' => get_option('kksr_init_msg')
226
+ ));
227
+ BhittaniPlugin_AdminMarkup::input(array(
228
+ 'title' => 'Thank you message',
229
+ 'description' => 'Text to be displayed when user places a vote',
230
+ 'field' => 'kksr_js_thankyou',
231
+ 'value' => get_option('kksr_js_thankyou')
232
+ ));
233
+ BhittaniPlugin_AdminMarkup::input(array(
234
+ 'title' => 'Error message',
235
+ 'description' => 'Text to be displayed when something goes wrong unexpectidly',
236
+ 'field' => 'kksr_js_error',
237
+ 'value' => get_option('kksr_js_error')
238
+ ));
239
+ ?>
240
+ </div>
241
+ <!--bf_container __general-->
242
+ <div class="bf_container __stars <?php echo ($opt=='stars')?'__active':''; ?>">
243
+ <?php
244
+ BhittaniPlugin_AdminMarkup::input(array(
245
+ 'title' => 'Amount of stars',
246
+ 'description' => 'How many stars do you want the ratings based on? Enter a numeric value',
247
+ 'field' => 'kksr_stars',
248
+ 'value' => get_option('kksr_stars')
249
+ ));
250
+ BhittaniPlugin_AdminMarkup::input(array(
251
+ 'title' => 'Width of single star',
252
+ 'description' => 'Set the width of a single star in pixels(px).<br /><strong>Note: </strong>All stars must be of equal width',
253
+ 'field' => 'kksr_stars_w',
254
+ 'value' => get_option('kksr_stars_w')
255
+ ));
256
+ BhittaniPlugin_AdminMarkup::input(array(
257
+ 'title' => 'Height of single star',
258
+ 'description' => 'Set the height of a single star in pixels(px).<br /><strong>Note: </strong>All stars must be of equal height',
259
+ 'field' => 'kksr_stars_h',
260
+ 'value' => get_option('kksr_stars_h')
261
+ ));
262
+ BhittaniPlugin_AdminMarkup::image(array(
263
+ 'title' => 'Gray Star',
264
+ 'description' => 'You can modify the gray star image here',
265
+ 'field' => 'kksr_stars_gray',
266
+ 'label' => 'Choose an image',
267
+ 'caption' => 'Gray Star',
268
+ 'value' => get_option('kksr_stars_gray') ? get_option('kksr_stars_gray') : BhittaniPlugin_kkStarRatings::file_uri('gray.png')
269
+ ));
270
+ BhittaniPlugin_AdminMarkup::image(array(
271
+ 'title' => 'Yellow Star',
272
+ 'description' => 'You can modify the yellow star image here',
273
+ 'field' => 'kksr_stars_yellow',
274
+ 'label' => 'Choose an image',
275
+ 'caption' => 'Yellow Star',
276
+ 'value' => get_option('kksr_stars_yellow') ? get_option('kksr_stars_yellow') : BhittaniPlugin_kkStarRatings::file_uri('yellow.png')
277
+ ));
278
+ BhittaniPlugin_AdminMarkup::image(array(
279
+ 'title' => 'Orange Star',
280
+ 'description' => 'You can modify the orange star image here',
281
+ 'field' => 'kksr_stars_orange',
282
+ 'label' => 'Choose an image',
283
+ 'caption' => 'Orange Star',
284
+ 'value' => get_option('kksr_stars_orange') ? get_option('kksr_stars_orange') : BhittaniPlugin_kkStarRatings::file_uri('orange.png')
285
+ ));
286
+ ?>
287
+ </div>
288
+ <!--bf_container __stars-->
289
+ <div class="bf_container __tooltips <?php echo ($opt=='tooltips')?'__active':''; ?>">
290
+ <?php
291
+ BhittaniPlugin_AdminMarkup::checkbox(array(
292
+ 'title' => 'Tooltips',
293
+ 'description' => 'Choose whether you want to enable or disable the tooltips',
294
+ 'obj' => array(
295
+ array(
296
+ 'field' => 'kksr_tooltip',
297
+ 'label' => 'Enable Tooltips',
298
+ 'value' => get_option('kksr_tooltip')
299
+ )
300
+ )
301
+ ));
302
+ $Tooltips = get_option('kksr_tooltips');
303
+ for($tooltip_i=0;$tooltip_i<get_option('kksr_stars');$tooltip_i++)
304
+ {
305
+ BhittaniPlugin_AdminMarkup::input(array(
306
+ 'title' => 'Tooltip - star '.($tooltip_i+1),
307
+ 'description' => 'Displayed when mouse is hovered over star '.($tooltip_i+1),
308
+ 'field' => 'kksr_tooltips['.($tooltip_i).'][tip]',
309
+ 'value' => isset($Tooltips[$tooltip_i]['tip']) ? $Tooltips[$tooltip_i]['tip'] : ''
310
+ ));
311
+ BhittaniPlugin_AdminMarkup::color(array(
312
+ 'title' => 'Tooltip Color - star '.($tooltip_i+1),
313
+ 'description' => 'Color for tooltip of star '.($tooltip_i+1),
314
+ 'field' => 'kksr_tooltips['.($tooltip_i).'][color]',
315
+ 'label' => 'Choose a color',
316
+ 'value' => isset($Tooltips[$tooltip_i]['color']) ? $Tooltips[$tooltip_i]['color'] : '#ffffff'
317
+ ));
318
+ }
319
+ ?>
320
+ </div>
321
+ <!--bf_container __tooltips-->
322
+ <div class="bf_container __reset <?php echo ($opt=='reset')?'__active':''; ?>">
323
+ <?php
324
+ global $wpdb;
325
+ $table = $wpdb->prefix . 'postmeta';
326
+ $Posts = $wpdb->get_results("SELECT a.ID, a.post_title
327
+ FROM " . $wpdb->posts . " a, $table b
328
+ WHERE a.ID=b.post_id AND
329
+ b.meta_key='_kksr_ratings'
330
+ ORDER BY a.ID ASC");
331
+ if(is_array($Posts))
332
+ {
333
+ $Obj = array();
334
+ foreach($Posts as $post)
335
+ {
336
+ $Obj[] = array(
337
+ 'field' => 'kksr_reset['.$post->ID.']',
338
+ 'label' => $post->post_title,
339
+ 'class' => '_kksr_reset'
340
+ );
341
+ }
342
+ if(count($Obj))
343
+ {
344
+ BhittaniPlugin_AdminMarkup::html('<p>Select the posts/pages below
345
+ and click the reset button to reset
346
+ their ratings.</p>
347
+ <p>
348
+ <a href="#" rel="kksr-reset-all" class="button">Select All</a>
349
+ <a href="#" rel="kksr-reset-none" class="button">Select None</a>
350
+ <a href="#" rel="kksr-reset" class="button-primary" style="color:white;">Reset</a>
351
+ </p>'
352
+ );
353
+ BhittaniPlugin_AdminMarkup::checkbox(array(
354
+ 'title' => '',
355
+ 'description' => '',
356
+ 'pclass' => '_left',
357
+ 'obj' => $Obj
358
+ ));
359
+ }
360
+ else
361
+ {
362
+ BhittaniPlugin_AdminMarkup::html('No ratings have been placed.');
363
+ }
364
+ }
365
+ else
366
+ {
367
+ BhittaniPlugin_AdminMarkup::html('No ratings have been placed.');
368
+ }
369
+ ?>
370
+ </div>
371
+ <!--bf_container __reset-->
372
+ <div class="bf_container __help <?php echo ($opt=='info')?'__active':''; ?>">
373
+ <?php
374
+ BhittaniPlugin_AdminMarkup::html(
375
+ '<p>
376
+ <strong>To manually use in your post/page using admin screen, use the star icon in your post/page editor</strong>
377
+ <br /><br />
378
+ <strong>For use in theme files:</strong>
379
+ <br /> <code class="_block">&lt;?php if(function_exists("kk_star_ratings")) : echo kk_star_ratings($pid); endif; ?&gt;</code>
380
+ <br />Where $pid is the id of the post
381
+ <br /><br />
382
+ <strong>Get top rated posts as array of objects:</strong>
383
+ <br /> <code class="_block">&lt;?php <br /> if(function_exists("kk_star_ratings_get")) <br /> { <br /> $top_rated_posts = kk_star_ratings_get($total); <br /> } <br />?&gt;</code>
384
+ <br />Where $total is the limit (int)
385
+ <br />$top_rated_posts will contain an array of objects, each containing an ID and ratings.
386
+ <br />
387
+ Example Usage:
388
+ <code class="_block">
389
+ <pre>
390
+ foreach($top_rated_posts as $post)
391
+ {
392
+ // you get $post->ID and $post->ratings
393
+ // Do anything with it like get_post($post->ID)
394
+ // ...
395
+ }
396
+ </pre>
397
+ </code>
398
+ <strong>Action Hooks</strong>
399
+ <br />
400
+ When post rating is fetched initially.
401
+ <code class="_block">
402
+ <pre>
403
+ add_action("kksr_init", "my_super_function1", 10, 3);
404
+ </pre>
405
+ </code>
406
+ example usage:
407
+ <code class="_block">
408
+ <pre>
409
+ function my_super_function1($post_id, $avg, $votes);
410
+ {
411
+ // $post_id is the id of the post.
412
+ // $avg is the average ratings as a string (e.g. 4.3/5).
413
+ // $votes is the total amount of votes occured.
414
+
415
+ // Do your magic below
416
+ }
417
+ </pre>
418
+ </code>
419
+ When a post gets rated
420
+ <code class="_block">
421
+ <pre>
422
+ add_action("kksr_rate", "my_super_function2", 10, 3);
423
+ </pre>
424
+ </code>
425
+ example usage:
426
+ <code class="_block">
427
+ <pre>
428
+ function my_super_function2($post_id, $no_of_stars, $ip_address);
429
+ {
430
+ // $post_id is the id of the post.
431
+ // $no_of_stars is the amount of stars the user rated.
432
+ // $ip_address is the ip address of the user.
433
+
434
+ // Do your magic below
435
+ }
436
+ </pre>
437
+ </code>
438
+ </p>'
439
+ );
440
+ ?>
441
+ </div>
442
+ <!--bf_container __help-->
443
+ </form>
444
+ </div>
445
+ <!-- bf-wrap -->
446
+ </div>
447
+ <!--bhittani-framework-->
bhittani-framework/admin/images/error.png CHANGED
Binary file
bhittani-framework/admin/images/loading.gif CHANGED
Binary file
bhittani-framework/admin/images/overlay.png CHANGED
Binary file
bhittani-framework/admin/images/tick.png CHANGED
Binary file
error.png CHANGED
Binary file
gray.png CHANGED
Binary file
icon.png CHANGED
Binary file
index.php CHANGED
@@ -4,7 +4,7 @@
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
@@ -389,6 +389,31 @@ if(!class_exists('BhittaniPlugin_kkStarRatings')) :
389
  echo json_encode($Response);
390
  die();
391
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
392
  public function kksr_ajax()
393
  {
394
  header('Content-type: application/json; charset=utf-8');
@@ -448,8 +473,10 @@ if(!class_exists('BhittaniPlugin_kkStarRatings')) :
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;
@@ -507,10 +534,9 @@ if(!class_exists('BhittaniPlugin_kkStarRatings')) :
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 -->
@@ -551,9 +577,15 @@ if(!class_exists('BhittaniPlugin_kkStarRatings')) :
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' :
@@ -574,13 +606,17 @@ if(!class_exists('BhittaniPlugin_kkStarRatings')) :
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;
@@ -593,23 +629,29 @@ if(!class_exists('BhittaniPlugin_kkStarRatings')) :
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
@@ -642,41 +684,41 @@ if(!class_exists('BhittaniPlugin_kkStarRatings')) :
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
 
@@ -705,7 +747,8 @@ if(!class_exists('BhittaniPlugin_kkStarRatings')) :
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') );
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.6
8
  Author: Kamal Khan
9
  Author URI: http://bhittani.com
10
  License: GPLv2 or later
389
  echo json_encode($Response);
390
  die();
391
  }
392
+ public function extract_ratings($id)
393
+ {
394
+ $best = (int) parent::get_options('kksr_stars');
395
+ $score = get_post_meta($id, '_kksr_ratings', true) ? ((int) get_post_meta($id, '_kksr_ratings', true)) : 0;
396
+ $votes = get_post_meta($id, '_kksr_casts', true) ? ((int) get_post_meta($id, '_kksr_casts', true)) : 0;
397
+ $avg = $score && $votes ? round((float)(($score/$votes)*($best/5)), 1) : 0;
398
+ $per = $score && $votes ? round((float)((($score/$votes)/5)*100), 2) : 0;
399
+
400
+ return compact('best', 'score', 'votes', 'avg', 'per');
401
+ }
402
+ public function ratings_as_legend($id, $ratings = null)
403
+ {
404
+ $ratings = $ratings ? $ratings : $this->extract_ratings($id);
405
+
406
+ return apply_filters(
407
+ 'kksr_legend',
408
+ parent::get_options('kksr_legend'),
409
+ $id,
410
+ $ratings['best'],
411
+ $ratings['score'],
412
+ $ratings['votes'],
413
+ $ratings['avg'],
414
+ $ratings['per']
415
+ );
416
+ }
417
  public function kksr_ajax()
418
  {
419
  header('Content-type: application/json; charset=utf-8');
473
  // $legend = str_replace('[avg]', number_format((float)($avg*($total_stars/5)), 2, '.', '').'/'.$total_stars, $legend);
474
  // $legend = str_replace('[s]', $ncasts==1?'':'s', $legend);
475
  // $Response[$pid]['legend'] = str_replace('[per]',$per.'%', $legend);
476
+ // $Response[$pid]['legend'] = apply_filters('kksr_legend', parent::get_options('kksr_legend'), $pid);
477
+ $Response[$pid]['meta'] = $this->extract_ratings($pid);
478
+ $Response[$pid]['legend'] = $this->ratings_as_legend($pid, $Response[$pid]['meta']);
479
+ $Response[$pid]['fuel'] = (float) $per;
480
  }
481
 
482
  $Response[$pid]['success'] = true;
534
  </div>
535
  <!-- kksr-stars -->
536
  <div class="kksr-legend">';
537
+
538
+ $markup .= $this->ratings_as_legend($id);
539
+
 
540
  $markup .=
541
  '</div>
542
  <!-- kksr-legend -->
577
  ) :
578
  remove_shortcode('kkratings');
579
  remove_shortcode('kkstarratings');
 
 
580
  $markup = $this->markup();
581
+ if (strpos($content, '[kkratings]') !== false
582
+ || strpos($content, '[kkstarratings]') !== false
583
+ ) {
584
+ $markup = '<div style="display: inline-block">' . $markup . '</div>';
585
+ $content = str_replace('[kkratings]', $markup, $content);
586
+ $content = str_replace('[kkstarratings]', $markup, $content);
587
+ return $content;
588
+ }
589
  switch(parent::get_options('kksr_position'))
590
  {
591
  case 'bottom-left' :
606
  {
607
  global $wpdb;
608
  $table = $wpdb->prefix . 'postmeta';
609
+ $best = (int) parent::get_options('kksr_stars');
610
+ $q = "SELECT a.ID, a.post_title, ROUND(b.meta_value * %f, 1) AS 'ratings' FROM " . $wpdb->posts . " a, $table b, ";
611
+ if(!$cat) {
612
+ $query = $wpdb->prepare("$q $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 %d", $best / 5, $total);
613
+ $rated_posts = $wpdb->get_results($query);
614
+ } else
615
  {
616
  $table2 = $wpdb->prefix . 'term_taxonomy';
617
  $table3 = $wpdb->prefix . 'term_relationships';
618
+ $query = $wpdb->prepare("$q $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 %d", $best / 5, $total);
619
+ $rated_posts = $wpdb->get_results($query);
620
  }
621
 
622
  return $rated_posts;
629
  }
630
  public function add_row($Columns, $id)
631
  {
632
+ if(! parent::get_options('kksr_column'))
633
  {
634
+ return;
635
+ }
636
+
637
+ $row = 'No ratings';
638
+
639
+ $ratings = $this->extract_ratings($id);
640
+ if ($ratings['score']) {
641
+ $row = $this->sanitize_legend(
642
+ parent::get_options('kksr_legend'),
643
+ $id,
644
+ $ratings['best'],
645
+ $ratings['score'],
646
+ $ratings['votes'],
647
+ $ratings['avg'],
648
+ $ratings['per']
649
+ );
650
+ }
651
+
652
+ switch($Columns)
653
+ {
654
+ case 'kk_star_ratings' : echo $row; break;
655
  }
656
  }
657
  /** function/method
684
  $Query->set('orderby','meta_value_num');
685
  }
686
  }
687
+ public function sanitize_legend($legend, $id, $best, $score, $votes, $avg, $per)
688
  {
689
+ if(!$score)
690
  {
691
+ return parent::get_options('kksr_init_msg');
692
+ }
 
 
693
 
694
+ $leg = str_replace('[total]', '<span itemprop="ratingCount">'.$votes.'</span>', $legend);
695
+ $leg = str_replace('[avg]', '<span itemprop="ratingValue">'.$avg.'</span>', $leg);
696
+ $leg = str_replace('[per]', $per .'%', $leg);
697
+ $leg = str_replace('[s]', $votes == 1 ? '' : 's', $leg);
698
+ $leg = str_replace('[best]', $best, $leg);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
699
 
700
+ return $leg;
701
+ }
702
+ public function grs_legend($legend, $id, $best, $score, $votes, $avg, $per)
703
+ {
704
+ if(!parent::get_options('kksr_grs'))
705
+ {
706
+ return $legend;
707
  }
708
+
709
+ $title = get_the_title($id);
710
+
711
+ $snippet = '<div itemprop="aggregateRating" itemscope itemtype="http://schema.org/AggregateRating">';
712
+ $snippet .= ' <div itemprop="name" class="kksr-title">' . $title . '</div>';
713
+ $snippet .= $legend;
714
+ $snippet .= ' <meta itemprop="bestRating" content="'. $best . '"/>';
715
+ $snippet .= ' <meta itemprop="worstRating" content="1"/>';
716
+ $snippet .= ' <div itemprop="itemReviewed" itemscope itemtype="http://schema.org/CreativeWork">';
717
+ $snippet .= ' <!-- Product properties -->';
718
+ $snippet .= ' </div>';
719
+ $snippet .= '</div>';
720
+
721
+ return $snippet;
722
  }
723
  }
724
 
747
  add_shortcode('kkstarratings', array($kkStarRatings_obj, 'manual'));
748
 
749
  // Google Rich Snippets
750
+ add_filter('kksr_legend', array($kkStarRatings_obj, 'sanitize_legend'), 10, 7);
751
+ add_filter('kksr_legend', array($kkStarRatings_obj, 'grs_legend'), 10, 7);
752
 
753
  // Posts/Pages Column
754
  add_filter( 'manage_posts_columns', array($kkStarRatings_obj, 'add_column') );
orange.png CHANGED
Binary file
readme.txt CHANGED
@@ -11,7 +11,7 @@ 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.
@@ -147,6 +147,16 @@ Visit the help tab in the settings to find out what you can do.
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)
11
 
12
  Tested up to: 4.8
13
 
14
+ Stable tag: 2.6
15
 
16
 
17
  kk Star Ratings allows blog visitors to involve and interact more effectively with your website by rating posts.
147
 
148
  == Changelog ==
149
 
150
+ = 2.6 =
151
+ * Fix: Parse legend correctly when not using google rich snippets.
152
+ * Fix: Admin screen colum notice bug.
153
+ * Fix: Show ratings at correct location when shortcode is used.
154
+ * Fix: Widget average values to reflect amount of stars being used.
155
+ * Update: Use one decimal point in average.
156
+ * Update: Use a single source of truth for parsing the legend.
157
+ * Update: Optimize images.
158
+ * Add: Allow [best] value in legend to show the total possible stars.
159
+
160
  = 2.5.2 =
161
  * Fix: See [PR #6](https://github.com/kamalkhan/kk-star-ratings/pull/6)
162
  * Fix: See [PR #24](https://github.com/kamalkhan/kk-star-ratings/pull/24)
screenshot-1.png CHANGED
Binary file
screenshot-10.png CHANGED
Binary file
screenshot-2.png CHANGED
Binary file
screenshot-3.png CHANGED
Binary file
screenshot-4.png CHANGED
Binary file
screenshot-5.png CHANGED
Binary file
screenshot-6.png CHANGED
Binary file
screenshot-7.png CHANGED
Binary file
screenshot-8.png CHANGED
Binary file
screenshot-9.png CHANGED
Binary file
widget.php CHANGED
@@ -34,7 +34,8 @@ class BhittaniPlugin_kkStarRatings_Widget extends WP_Widget
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
  }
34
  echo "<li><a href='".get_permalink($post->ID)."'>".$post->post_title."</a>";
35
  if($sr)
36
  {
37
+ $best = get_option('kksr_stars');
38
+ echo " <span style='font-size:10px;'>(".$post->ratings."/".$best.")</span>";
39
  }
40
  echo "</li>";
41
  }
yellow.png CHANGED
Binary file