WP Review - Version 3.2.1

Version Description

  • Fixed error appearing when plugin settings weren't saved.
  • Fixed JS issues.
  • Fixed Tabbed Widget issue.
Download this release

Release Info

Developer MyThemeShop
Plugin Icon 128x128 WP Review
Version 3.2.1
Comparing to
See all releases

Code changes from version 3.2 to 3.2.1

Files changed (4) hide show
  1. assets/css/wp-review.css +2 -3
  2. includes/functions.php +605 -609
  3. readme.txt +6 -1
  4. wp-review.php +2 -2
assets/css/wp-review.css CHANGED
@@ -2,7 +2,7 @@
2
* Plugin Name: WP Review
3
* Plugin URI: http://mythemeshop.com/plugins/wp-review/
4
* Description: Create reviews! Choose from Stars, Percentages or Points for review scores. Supports Retina Display, WPMU & Unlimited Color Schemes.
5
- * Version: 3.2
6
* Author: MyThemesShop
7
* Author URI: http://mythemeshop.com/
8
*/
@@ -26,7 +26,7 @@
26
.review-total-star.allowed-to-rate.has-not-rated-yet a { cursor: pointer }
27
.review-total-star.allowed-to-rate.has-not-rated-yet:hover .review-result { opacity: 0; filter: alpha(opacity=0); display: none; }
28
.review-total-star.allowed-to-rate.has-not-rated-yet a:hover > i { opacity: 1; filter: alpha(opacity=1); }
29
- .review-total-star.allowed-to-rate a.hovered i { opacity: 1; filter: alpha(opacity=1); }
30
.mts-review-wait-msg { display: none }
31
.review-total { position: absolute; top: 0px; left: 0px; height: 16px; z-index: 99; text-indent: -9999px; }
32
.review-star { position: absolute; right: 15px; top: 10px; }
@@ -83,7 +83,6 @@
83
.review-type-circle.latestPost-review-wrapper, .review-type-circle.wp-review-on-thumbnail { height: 35px ; background: #fff;}
84
.latestPost-review-wrapper .wp-review-circle-rating, .wp-review-on-thumbnail .wp-review-circle-rating { font-size: 11px !important; }
85
.review-type-circle.review-total-only, .review-type-circle.wp-review-show-total { padding-top: 6px; }
86
- .latestPost-review-wrapper i, .latestPost-review-wrapper span { color: #FFF!important; }
87
/**
88
* Font icon
89
*/
2
* Plugin Name: WP Review
3
* Plugin URI: http://mythemeshop.com/plugins/wp-review/
4
* Description: Create reviews! Choose from Stars, Percentages or Points for review scores. Supports Retina Display, WPMU & Unlimited Color Schemes.
5
+ * Version: 3.2.1
6
* Author: MyThemesShop
7
* Author URI: http://mythemeshop.com/
8
*/
26
.review-total-star.allowed-to-rate.has-not-rated-yet a { cursor: pointer }
27
.review-total-star.allowed-to-rate.has-not-rated-yet:hover .review-result { opacity: 0; filter: alpha(opacity=0); display: none; }
28
.review-total-star.allowed-to-rate.has-not-rated-yet a:hover > i { opacity: 1; filter: alpha(opacity=1); }
29
+ .review-total-star.allowed-to-rate a.hovered i { opacity: 1!important; filter: alpha(opacity=1)!important; }
30
.mts-review-wait-msg { display: none }
31
.review-total { position: absolute; top: 0px; left: 0px; height: 16px; z-index: 99; text-indent: -9999px; }
32
.review-star { position: absolute; right: 15px; top: 10px; }
83
.review-type-circle.latestPost-review-wrapper, .review-type-circle.wp-review-on-thumbnail { height: 35px ; background: #fff;}
84
.latestPost-review-wrapper .wp-review-circle-rating, .wp-review-on-thumbnail .wp-review-circle-rating { font-size: 11px !important; }
85
.review-type-circle.review-total-only, .review-type-circle.wp-review-show-total { padding-top: 6px; }
86
/**
87
* Font icon
88
*/
includes/functions.php CHANGED
@@ -1,610 +1,606 @@
1
- <?php
2
- ob_start();
3
- /**
4
- * WP Review
5
- *
6
- * @since 2.0
7
- * @copyright Copyright (c) 2013, MyThemesShop
8
- * @author MyThemesShop
9
- * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
10
- */
11
-
12
- $options = get_option('wp_review_options');
13
-
14
- /* Display the meta box data below 'the_content' hook. */
15
- add_filter( 'the_content', 'wp_review_inject_data' );
16
-
17
- /* Get review with Ajax */
18
- add_action('wp_ajax_mts_review_get_review', 'mts_review_get_review');
19
- add_action('wp_ajax_nopriv_mts_review_get_review', 'mts_review_get_review');
20
-
21
- /* Show with shortcode */
22
- add_shortcode('wp-review', 'wp_review_get_data');
23
- add_shortcode('wp-review-total', 'wp_review_total_shortcode');
24
- // aliases
25
- add_shortcode('wp_review', 'wp_review_get_data');
26
- add_shortcode('wp_review_total', 'wp_review_total_shortcode');
27
-
28
- // image sizes for the widgets
29
- add_image_size( 'wp_review_large', 320, 200, true );
30
- add_image_size( 'wp_review_small', 65, 65, true );
31
-
32
- /**
33
- * Get the meta box data.
34
- *
35
- * @since 1.0
36
- *
37
- */
38
- function wp_review_get_data() {
39
- global $post;
40
- global $blog_id;
41
- $options = get_option('wp_review_options');
42
-
43
- /* Retrieve the meta box data. */
44
- $heading = get_post_meta( $post->ID, 'wp_review_heading', true );
45
- $desc_title = get_post_meta( $post->ID, 'wp_review_desc_title', true );
46
- if ( ! $desc_title ) $desc_title = __('Summary', 'wp-review');
47
- $desc = get_post_meta( $post->ID, 'wp_review_desc', true );
48
- $items = get_post_meta( $post->ID, 'wp_review_item', true );
49
- $type = get_post_meta( $post->ID, 'wp_review_type', true );
50
- $total = get_post_meta( $post->ID, 'wp_review_total', true );
51
- $hide_desc = get_post_meta( $post->ID, 'wp_review_hide_desc', true );
52
- $allowUsers = get_post_meta( $post->ID, 'wp_review_userReview', true );
53
-
54
- $colors = array();
55
- $colors['custom_colors'] = get_post_meta( $post->ID, 'wp_review_custom_colors', true );
56
- $colors['color'] = get_post_meta( $post->ID, 'wp_review_color', true );
57
- $colors['type'] = get_post_meta( $post->ID, 'wp_review_type', true );
58
- $colors['fontcolor'] = get_post_meta( $post->ID, 'wp_review_fontcolor', true );
59
- $colors['bgcolor1'] = get_post_meta( $post->ID, 'wp_review_bgcolor1', true );
60
- $colors['bgcolor2'] = get_post_meta( $post->ID, 'wp_review_bgcolor2', true );
61
- $colors['bordercolor'] = get_post_meta( $post->ID, 'wp_review_bordercolor', true );
62
- $colors['total'] = get_post_meta( $post->ID, 'wp_review_total', true );
63
-
64
- if (!$colors['custom_colors']) {
65
- $colors = array_merge($colors, $options['colors']);
66
- }
67
- $colors = apply_filters('wp_review_colors', $colors, $post->ID);
68
- $color = $colors['color'];
69
-
70
- /* Define a custom class for bar type. */
71
- $class = '';
72
- if ( 'point' == $type ) {
73
- $class = 'bar-point';
74
- } elseif ( 'percentage' == $type ) {
75
- $class = 'percentage-point';
76
- }
77
- $post_types = get_post_types( array('public' => true), 'names' );
78
- $excluded_post_types = apply_filters('wp_review_excluded_post_types', array('attachment'));
79
- $allowed_post_types = array();
80
- foreach ($post_types as $i => $post_type) {
81
- if (!in_array($post_type, $excluded_post_types)) {
82
- $allowed_post_types[] = $post_type; // allow it if it's not excluded
83
- }
84
- }
85
-
86
- /**
87
- * Add the custom data from the meta box to the main query an
88
- * make sure the hook only apply on allowed post types
89
- */
90
- if ( $type != '' && is_singular($allowed_post_types) && is_main_query() ) {
91
- //if ( $type != '' && is_main_query() && in_array(get_post_type($post->ID), $allowed_post_types)) {
92
- // using this second if() instead of the first will allow reviews to be displayed on archive pages, but it may mess up excerpts
93
- $review = '<div id="review" class="review-wrapper wp-review-'.$post->ID.' ' . $class . ' delay-animation" >';
94
-
95
- /* Review title. */
96
- if( $heading != '' ){
97
- $review .= '<h5 class="review-title">' . __( $heading ) . '</h5>';
98
- }
99
-
100
-
101
- /* Review item. */
102
- if ( $items ) {
103
- $review .= '<ul class="review-list">';
104
- foreach( $items as $item ) {
105
-
106
- $item['wp_review_item_title'] = ( !empty( $item['wp_review_item_title'] ) ) ? $item['wp_review_item_title'] : '';
107
- $item['wp_review_item_star'] = ( !empty( $item['wp_review_item_star'] ) ) ? $item['wp_review_item_star'] : '';
108
-
109
- if ( 'star' == $type ) {
110
- $result = $item['wp_review_item_star'] * 20;
111
- $bestresult = '<meta itemprop="best" content="5"/>';
112
- $best = '5';
113
- } elseif( 'point' == $type ) {
114
- $result = $item['wp_review_item_star'] * 10;
115
- $bestresult = '<meta itemprop="best" content="10"/>';
116
- $best = '10';
117
- } else { // percentage
118
- $result = $item['wp_review_item_star'] * 100 / 100;
119
- $bestresult = '<meta itemprop="best" content="100"/>';
120
- $best = '100';
121
- }
122
-
123
- $review .= '<li>';
124
-
125
- if ( 'point' == $type ) {
126
- $review .= '<span>' . wp_kses_post( $item['wp_review_item_title'] ) . ' - <span>' . $item['wp_review_item_star'] . '/10</span></span>';
127
- } elseif( 'percentage' == $type ) {
128
- $review .= '<span>' . wp_kses_post( $item['wp_review_item_title'] ) . ' - <span>' . $item['wp_review_item_star'] . '%' . '</span></span>';
129
- } elseif ( 'star' == $type ) {
130
- $review .= '<span>' . wp_kses_post( $item['wp_review_item_title'] ) . '</span>';
131
- }
132
-
133
- $review .= '<div class="review-star">';
134
- $review .= '<div class="review-result-wrapper">';
135
-
136
- if ( 'star' == $type ) {
137
- $review .= '<i class="mts-icon-star"></i>';
138
- $review .= '<i class="mts-icon-star"></i>';
139
- $review .= '<i class="mts-icon-star"></i>';
140
- $review .= '<i class="mts-icon-star"></i>';
141
- $review .= '<i class="mts-icon-star"></i>';
142
- $review .= '<div class="review-result" style="width:' . $result . '%;">';
143
- $review .= '<i class="mts-icon-star"></i>';
144
- $review .= '<i class="mts-icon-star"></i>';
145
- $review .= '<i class="mts-icon-star"></i>';
146
- $review .= '<i class="mts-icon-star"></i>';
147
- $review .= '<i class="mts-icon-star"></i>';
148
- $review .= '</div><!-- .review-result -->';
149
- } elseif ( 'point' == $type ) {
150
- $review .= '<div class="review-result" style="width:' . $result . '%;">' . $item['wp_review_item_star'] . '/10</div>';
151
- } elseif ( 'percentage' == $type ) {
152
- $review .= '<div class="review-result" style="width:' . $result . '%;">' . $item['wp_review_item_star'] . '</div>';
153
- }
154
-
155
- $review .= '</div><!-- .review-result-wrapper -->';
156
- $review .= '</div><!-- .review-star -->';
157
- $review .= '</li>';
158
-
159
- }
160
- $review .= '</ul>';
161
- }
162
-
163
- /* Review description. */
164
- if ( ! $hide_desc ) {
165
- if ( $desc ) {
166
- $review .= '<div class="review-desc" >';
167
- $review .= '<p class="review-summary-title"><strong>' . $desc_title . '</strong></p>';
168
- $review .= do_shortcode ( shortcode_unautop( wp_kses_post( wpautop( $desc ) ) ) );
169
- $review .= '</div><!-- .review-desc -->';
170
-
171
- }//**END IF HAS DESCRIPTION**
172
- if( $total != '' ){
173
- $review .= '<div class="review-total-wrapper"> ';
174
-
175
- if ( 'percentage' == $type ) {
176
- $review .= '<span class="review-total-box"><span itemprop="review">' . $total . '</span> <i class="percentage-icon">%</i>' . '</span>';
177
- } elseif ( 'point' == $type ) {
178
- $review .= '<span class="review-total-box" itemprop="review">' . $total . '/10</span>';
179
- } elseif ( 'star' == $type ) {
180
- $review .= '<span class="review-total-box" itemprop="review">' . $total . '</span>';
181
-
182
- $review .= '<div class="review-total-star">';
183
- $review .= '<div class="review-result-wrapper">';
184
- $review .= '<i class="mts-icon-star"></i>';
185
- $review .= '<i class="mts-icon-star"></i>';
186
- $review .= '<i class="mts-icon-star"></i>';
187
- $review .= '<i class="mts-icon-star"></i>';
188
- $review .= '<i class="mts-icon-star"></i>';
189
- $review .= '<div class="review-result" style="width:' . $total*20 . '%;">';
190
- $review .= '<i class="mts-icon-star"></i>';
191
- $review .= '<i class="mts-icon-star"></i>';
192
- $review .= '<i class="mts-icon-star"></i>';
193
- $review .= '<i class="mts-icon-star"></i>';
194
- $review .= '<i class="mts-icon-star"></i>';
195
- $review .= '</div><!-- .review-result -->';
196
- $review .= '</div><!-- .review-result-wrapper -->';
197
- $review .= '</div><!-- .review-star -->';
198
- }
199
-
200
- $review .= '</div>';
201
-
202
-
203
- $review .= '<div itemscope="itemscope" itemtype="http://data-vocabulary.org/Review">
204
- <meta itemprop="itemreviewed" content="'.__( $heading ).'">
205
-
206
- <span itemprop="rating" itemscope="itemscope"itemtype="http://data-vocabulary.org/Rating">
207
- <meta itemprop="value" content="'.$total.'">
208
- <meta itemprop="best" content="'.$best.'">
209
- </span>
210
- <span itemprop="reviewer" itemscope="itemscope" itemtype="http://data-vocabulary.org/Person">
211
- <meta itemprop="name" content="'. get_the_author() .'">
212
- </span>
213
- </div>';
214
- }
215
- }
216
-
217
- /**
218
- * USERS REVIEW AREA
219
- */
220
-
221
- if( is_array( $allowUsers ) && $allowUsers[0] == 1 ){
222
- $allowedClass = 'allowed-to-rate';
223
- $hasNotRatedClass = 'has-not-rated-yet';
224
- $postReviews = mts_get_post_reviews( $post->ID );
225
- $userTotal = $postReviews[0]->reviewsAvg;
226
- $usersReviewsCount = $postReviews[0]->reviewsNum;
227
-
228
- $review .= '<div style="clear: both;"></div>';
229
-
230
- $review .= '<div class="user-review-area" title="'.__('Click on the stars to rate!', 'wp-review').'">';
231
- //$ip = $_SERVER['REMOTE_ADDR'];
232
- if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
233
- $ip = $_SERVER['HTTP_CLIENT_IP'];
234
- } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
235
- $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
236
- } else {
237
- $ip = $_SERVER['REMOTE_ADDR'];
238
- }
239
-
240
- $user_id = '';
241
- if ( is_user_logged_in() ) { $user_id = get_current_user_id(); }
242
- //echo $blog_id;
243
- $review .= '<input type="hidden" id="blog_id" value="'.$blog_id.'">';
244
- $review .= '<input type="hidden" id="post_id" value="'.$post->ID.'">';
245
- $review .= '<input type="hidden" id="user_id" value="'.$user_id.'">';
246
- $review .= '<input type="hidden" id="token" value="'.wp_create_nonce( "wp-review-security" ).'">';
247
-
248
-
249
- if( $userTotal == '' ) $userTotal = '0.0';
250
- $review .= '<div class="user-total-wrapper"><span class="user-review-title">'.__('User Rating','wp-review').': </span><span class="review-total-box"><span id="mts-user-reviews-total">' . $userTotal . '</span> ';
251
- $review.= '<small>(<span id="mts-user-reviews-counter" >'.$usersReviewsCount.'</span> '.__('votes', 'wp-review').')</small></span></div>';
252
-
253
- if( hasPreviousReview( $post->ID, $user_id, $ip )) {
254
- $hasNotRatedClass = '';
255
- }
256
-
257
- $review .= '<div class="review-total-star '.$allowedClass.' '.$hasNotRatedClass.'" >';
258
- $review .='<div class="mts-review-wait-msg"><span class="animate-spin mts-icon-loader"></span>'.__('Sending','wp-review').'</div>';
259
- $review .= '<div class="review-result-wrapper">';
260
- $review .= '<a data-input-value="1" title="1/5"><i class="mts-icon-star"></i></a>';
261
- $review .= '<a data-input-value="2" title="2/5"><i class="mts-icon-star"></i></a>';
262
- $review .= '<a data-input-value="3" title="3/5"><i class="mts-icon-star"></i></a>';
263
- $review .= '<a data-input-value="4" title="4/5"><i class="mts-icon-star"></i></a>';
264
- $review .= '<a data-input-value="5" title="5/5"><i class="mts-icon-star"></i></a>';
265
- $review .= '<div class="review-result" style="width:' . $userTotal*20 . '%;">';
266
- $review .= '<i class="mts-icon-star"></i>';
267
- $review .= '<i class="mts-icon-star"></i>';
268
- $review .= '<i class="mts-icon-star"></i>';
269
- $review .= '<i class="mts-icon-star" style=""></i>';
270
- $review .= '<i class="mts-icon-star"></i>';
271
- $review .= '</div><!-- .review-result -->';
272
- $review .= '</div><!-- .review-result-wrapper -->';
273
- $review .= '</div><!-- .review-star -->';
274
- $review .= '<input type="hidden" id="mts-review-user-rate" value="" />';
275
-
276
- $review .= '</div>';
277
-
278
- $review .= '<div itemscope itemtype="http://schema.org/Review">
279
- <div itemprop="reviewRating" itemscope itemtype="http://schema.org/AggregateRating">
280
- <meta itemprop="ratingValue" content="'.$userTotal.'" />
281
- <meta itemprop="bestRating" content="5"/>
282
- <meta itemprop="ratingCount" content="'.$usersReviewsCount.'" />
283
- </div>
284
- </div>';
285
-
286
- }//**END IF USERS ALLOWED TO RATE**
287
-
288
-
289
- $review .= '</div><!-- #review -->';
290
-
291
- $review = apply_filters('wp_review_get_data', $review, $post->ID, $type, $total, $items);
292
-
293
- return $review . wp_review_color_output(); // add color CSS to output
294
- } else {
295
- return '';
296
- }
297
- }
298
-
299
- function wp_review_inject_data( $content ) {
300
- global $post;
301
- $options = get_option('wp_review_options');
302
- $custom_location = get_post_meta( $post->ID, 'wp_review_custom_location', true );
303
- $location = get_post_meta( $post->ID, 'wp_review_location', true );
304
- if (!$custom_location && !empty($options['review_location'])) {
305
- $location = $options['review_location'];
306
- }
307
-
308
- $location = apply_filters('wp_review_location', $location, $post->ID);
309
-
310
- if (empty($location) || $location == 'custom') {
311
- return $content;
312
- }
313
- $review = wp_review_get_data();
314
- if ( 'bottom' == $location ) {
315
- global $multipage, $numpages, $page;
316
- if( $multipage ) {
317
- if ($page == $numpages) {
318
- return $content .= $review;
319
- } else {
320
- return $content;
321
- }
322
- } else {
323
- return $content .= $review;
324
- }
325
- } elseif ( 'top' == $location ) {
326
- return $review .= $content;
327
- } else {
328
- return $content;
329
- }
330
- }
331
-
332
- /**
333
- * Retrieve only total rating.
334
- * To be used on archive pages, etc.
335
- *
336
- * @since 1.0
337
- *
338
- */
339
- function wp_review_show_total($echo = true, $class = 'review-total-only') {
340
- global $post;
341
-
342
- $type = get_post_meta( $post->ID, 'wp_review_type', true );
343
- $total = get_post_meta( $post->ID, 'wp_review_total', true );
344
- $review = '';
345
-
346
- $options = get_option('wp_review_options');
347
- $colors = array();
348
- $colors['custom_location'] = get_post_meta( $post->ID, 'wp_review_custom_location', true );
349
- $colors['custom_colors'] = get_post_meta( $post->ID, 'wp_review_custom_colors', true );
350
- $colors['custom_width'] = get_post_meta( $post->ID, 'wp_review_custom_width', true );
351
-
352
- $colors['color'] = get_post_meta( $post->ID, 'wp_review_color', true );
353
- $colors['type'] = get_post_meta( $post->ID, 'wp_review_type', true );
354
- $colors['fontcolor'] = get_post_meta( $post->ID, 'wp_review_fontcolor', true );
355
- $colors['bgcolor1'] = get_post_meta( $post->ID, 'wp_review_bgcolor1', true );
356
- $colors['bgcolor2'] = get_post_meta( $post->ID, 'wp_review_bgcolor2', true );
357
- $colors['bordercolor'] = get_post_meta( $post->ID, 'wp_review_bordercolor', true );
358
- $colors['total'] = get_post_meta( $post->ID, 'wp_review_total', true );
359
-
360
- if (!$colors['custom_colors']) {
361
- $colors = array_merge($colors, $options['colors']);
362
- }
363
- $colors = apply_filters('wp_review_colors', $colors, $post->ID);
364
-
365
- if (!empty($type) && (!empty($total) || $total === '0')) {
366
- wp_enqueue_style( 'wp_review-style', trailingslashit( WP_REVIEW_ASSETS ) . 'css/wp-review.css', array(), '1.1', 'all' );
367
-
368
- $review = '<div class="review-type-'.$type.' '.esc_attr($class).' wp-review-show-total wp-review-total-'.$post->ID.'"> ';
369
-
370
- if ( 'percentage' == $type ) {
371
- $review .= '<span class="review-total-box"><span>' . $total . '</span> <i class="percentage-icon">%</i>' . '</span>';
372
- } elseif ( 'point' == $type ) {
373
- $review .= '<span class="review-total-box">' . $total . '/'.__('10','wp-review').'</span></span>';
374
- } elseif ( 'star' == $type ) {
375
- // star
376
- $review .= '<div class="review-total-star">';
377
- $review .= '<div class="review-result-wrapper">';
378
- $review .= '<i class="mts-icon-star"></i>';
379
- $review .= '<i class="mts-icon-star"></i>';
380
- $review .= '<i class="mts-icon-star"></i>';
381
- $review .= '<i class="mts-icon-star"></i>';
382
- $review .= '<i class="mts-icon-star"></i>';
383
- $review .= '<div class="review-result" style="width:' . $total*20 . '%;">';
384
- $review .= '<i class="mts-icon-star"></i>';
385
- $review .= '<i class="mts-icon-star"></i>';
386
- $review .= '<i class="mts-icon-star"></i>';
387
- $review .= '<i class="mts-icon-star"></i>';
388
- $review .= '<i class="mts-icon-star"></i>';
389
- $review .= '</div><!-- .review-result -->';
390
- $review .= '</div><!-- .review-result-wrapper -->';
391
- $review .= '</div><!-- .review-star -->';
392
- }
393
-
394
- $review .= '</div>';
395
-
396
- $review .= '<style type="text/css">';
397
- $review .= '.wp-review-total-'.$post->ID.' i, .wp-review-total-'.$post->ID.' .review-total-box { color: '.$colors['color'].' }';
398
- $review .= '</style>';
399
- }
400
-
401
- $review = apply_filters('wp_review_show_total', $review, $post->ID, $type, $total);
402
-
403
- if ($echo)
404
- echo $review;
405
- else
406
- return $review;
407
- }
408
- function wp_review_total_shortcode($atts, $content) {
409
- if (empty($atts['class']))
410
- $atts['class'] = 'review-total-only review-total-shortcode';
411
-
412
- return wp_review_show_total(false, $atts['class']);
413
- }
414
-
415
- function mts_get_post_reviews( $post_id ){
416
- if( is_numeric( $post_id ) && $post_id > 0 ){
417
- global $wpdb;
418
- global $blog_id;
419
- $table_name = $wpdb->prefix . MTS_WP_REVIEW_DB_TABLE;
420
- if (function_exists('is_multisite') && is_multisite()) {$table_name = $wpdb->base_prefix . MTS_WP_REVIEW_DB_TABLE;}
421
- $reviews = $wpdb->get_results( $wpdb->prepare("SELECT ROUND( AVG(rate) ,1 ) as reviewsAvg, COUNT(id) as reviewsNum FROM $table_name WHERE blog_id = '%d' AND post_id = '%d'", $blog_id, $post_id) );
422
- return $reviews;
423
- }
424
- }
425
-
426
-
427
- /**
428
- * Star review color
429
- *
430
- * @since 1.0
431
- */
432
- function wp_review_color_output() {
433
- global $post;
434
- $style = '';
435
- $options = get_option('wp_review_options');
436
- if (empty($options['colors'])) $options['colors'] = array();
437
- /* Retrieve the meta box data. */
438
- if(is_singular()) {
439
- $colors = array();
440
- $colors['custom_location'] = get_post_meta( $post->ID, 'wp_review_custom_location', true );
441
- $colors['custom_colors'] = get_post_meta( $post->ID, 'wp_review_custom_colors', true );
442
- $colors['custom_width'] = get_post_meta( $post->ID, 'wp_review_custom_width', true );
443
-
444
- $colors['color'] = get_post_meta( $post->ID, 'wp_review_color', true );
445
- $colors['type'] = get_post_meta( $post->ID, 'wp_review_type', true );
446
- $colors['fontcolor'] = get_post_meta( $post->ID, 'wp_review_fontcolor', true );
447
- $colors['bgcolor1'] = get_post_meta( $post->ID, 'wp_review_bgcolor1', true );
448
- $colors['bgcolor2'] = get_post_meta( $post->ID, 'wp_review_bgcolor2', true );
449
- $colors['bordercolor'] = get_post_meta( $post->ID, 'wp_review_bordercolor', true );
450
- $colors['total'] = get_post_meta( $post->ID, 'wp_review_total', true );
451
-
452
- if (!$colors['custom_colors']) {
453
- $colors = array_merge($colors, $options['colors']);
454
- }
455
- $colors = apply_filters('wp_review_colors', $colors, $post->ID);
456
-
457
- extract($colors, EXTR_SKIP);
458
-
459
- if( !$color ) $color = '#333333';
460
-
461
- $style = '<style type="text/css">';
462
-
463
- if ( 'star' == $type ) {
464
-
465
- $style .= '.wp-review-'.$post->ID.' .review-result-wrapper .review-result i { color: '.$color.'; opacity: 1; filter: alpha(opacity=100); }
466
- .wp-review-'.$post->ID.' .review-result-wrapper i{ color: '.$color.'; opacity: 0.50; filter: alpha(opacity=50); }';
467
-
468
- } elseif ( 'point' == $type ) {
469
-
470
- $style .= '.wp-review-'.$post->ID.'.bar-point .review-result { background-color: '.$color.'; }';
471
-
472
- } elseif ( 'percentage' == $type ) {
473
-
474
- $style .= '.wp-review-'.$post->ID.'.percentage-point .review-result { background-color: '.$color.'; }';
475
-
476
- }
477
-
478
- $style .= '.wp-review-'.$post->ID.'.review-wrapper, .wp-review-'.$post->ID.' .review-title, .wp-review-'.$post->ID.' .review-desc p{ color: '.$fontcolor.';}
479
- .wp-review-'.$post->ID.' .review-list li, .wp-review-'.$post->ID.'.review-wrapper{ background: '.$bgcolor2.';}
480
- .wp-review-'.$post->ID.' .review-title, .wp-review-'.$post->ID.' .review-list li:nth-child(2n){background: '.$bgcolor1.';}
481
-
482
- .wp-review-'.$post->ID.'.bar-point .allowed-to-rate .review-result, .wp-review-'.$post->ID.'.percentage-point .allowed-to-rate .review-result{background: none;}
483
- .wp-review-'.$post->ID.' .review-total-star.allowed-to-rate a i, .wp-review-comment-field a i, .wp-review-comment-rating a i { color: '.$color.'; opacity: 0.50; filter: alpha(opacity=50); }
484
- .wp-review-'.$post->ID.'.bar-point .allowed-to-rate .review-result, .wp-review-'.$post->ID.'.percentage-point .allowed-to-rate .review-result{text-indent:0;}
485
- .wp-review-'.$post->ID.'.bar-point .allowed-to-rate .review-result i, .wp-review-'.$post->ID.'.percentage-point .allowed-to-rate .review-result i, .wp-review-'.$post->ID.' .mts-user-review-star-container .selected i, .wp-review-'.$post->ID.' .user-review-area .review-result i, .wp-review-comment-field .review-result i, .wp-review-comment-rating .review-result i { color: '.$color.'; opacity: 1; filter: alpha(opacity=100); }
486
- .wp-review-'.$post->ID.'.review-wrapper, .wp-review-'.$post->ID.' .review-title, .wp-review-'.$post->ID.' .review-list li, .wp-review-'.$post->ID.' .review-list li:last-child, .wp-review-'.$post->ID.' .user-review-area{border-color: '.$bordercolor.';}';
487
-
488
- if( $total == '' ){
489
-
490
- $style .= '.wp-review-'.$post->ID.' .user-review-area{border: 1px solid '.$bordercolor.'; margin-top: 0px;}
491
- .wp-review-'.$post->ID.' .review-desc{width: 100%;}
492
- .wp-review-'.$post->ID.'.review-wrapper{border: none; overflow: visible;}';
493
- }
494
- $style .= '</style>';
495
-
496
- return $style;
497
- }
498
- }
499
-
500
- /**
501
- *Check if user has reviewed this post previously
502
- */
503
- function hasPreviousReview( $post_id, $user_id, $ip ){
504
- if( is_numeric( $post_id ) && $post_id > 0 ){
505
- global $wpdb;
506
- global $blog_id;
507
- $table_name = $wpdb->prefix . MTS_WP_REVIEW_DB_TABLE;
508
- if (function_exists('is_multisite') && is_multisite()) {$table_name = $wpdb->base_prefix . MTS_WP_REVIEW_DB_TABLE;}
509
- if( is_numeric( $user_id ) && $user_id > 0 ){
510
- $prevRates = $wpdb->get_row( $wpdb->prepare("SELECT COUNT(id) as reviewsNum FROM $table_name WHERE blog_id = '%d' AND post_id = '%d' AND user_id = '%d'", $blog_id, $post_id, $user_id) );
511
- if( $prevRates->reviewsNum > 0 ) return true; else return false;
512
- }
513
- elseif( $ip != '' ){
514
- $prevRates = $wpdb->get_row( $wpdb->prepare("SELECT COUNT(id) as reviewsNum FROM $table_name WHERE blog_id = '%d' AND post_id = '%d' AND user_ip = '%s' AND user_id = '0'", $blog_id, $post_id, $ip) );
515
- if( $prevRates->reviewsNum > 0 ) return true; else return false;
516
- }
517
- else return false;
518
- }
519
- return false;
520
- }
521
-
522
- function getPreviousReview( $post_id, $user_id, $ip ) {
523
- if( is_numeric( $post_id ) && $post_id > 0 ){
524
- global $wpdb;
525
- global $blog_id;
526
- $table_name = $wpdb->prefix . MTS_WP_REVIEW_DB_TABLE;
527
- if (function_exists('is_multisite') && is_multisite()) {$table_name = $wpdb->base_prefix . MTS_WP_REVIEW_DB_TABLE;}
528
- if( is_numeric( $user_id ) && $user_id > 0 ){
529
- $prevRates = $wpdb->get_row( $wpdb->prepare("SELECT rate FROM $table_name WHERE blog_id = '%d' AND post_id = '%d' AND user_id = '%d'", $blog_id, $post_id, $user_id) );
530
- if( $prevRates->rate ) return $prevRates->rate; else return 0;
531
- }
532
- elseif( $ip != '' ){
533
- $prevRates = $wpdb->get_row( $wpdb->prepare("SELECT rate FROM $table_name WHERE blog_id = '%d' AND post_id = '%d' AND user_ip = '%s' AND user_id = '0'", $blog_id, $post_id, $ip) );
534
- if( $prevRates->rate ) return $prevRates->rate; else return 0;
535
- }
536
- else return false;
537
- }
538
- return false;
539
- }
540
-
541
- /**
542
- *Get review with Ajax
543
- */
544
- function mts_review_get_review(){
545
- // security
546
- check_ajax_referer( 'wp-review-security', 'nonce' );
547
-
548
- global $wpdb;
549
-
550
- $table_name = $wpdb->prefix . MTS_WP_REVIEW_DB_TABLE;
551
- if (function_exists('is_multisite') && is_multisite()) {$table_name = $wpdb->base_prefix . MTS_WP_REVIEW_DB_TABLE;}
552
-
553
- global $blog_id;
554
- $post_id = intval($_POST['post_id']);
555
- $user_id = intval($_POST['user_id']);
556
-
557
- //$ip = $_SERVER['REMOTE_ADDR'];
558
- if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
559
- $uip = $_SERVER['HTTP_CLIENT_IP'];
560
- } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
561
- $uip = $_SERVER['HTTP_X_FORWARDED_FOR'];
562
- } else {
563
- $uip = $_SERVER['REMOTE_ADDR'];
564
- }
565
-
566
- if (!hasPreviousReview($post_id, $user_id, $uip)) {
567
- $data = intval($_POST['review']);
568
-
569
- if( $rows_affected = $wpdb->insert( $table_name, array('blog_id' => $blog_id, 'post_id' => $post_id, 'user_id' => $user_id, 'user_ip' => $uip, 'rate' => $data, 'date' => current_time('mysql')) ) ){
570
- $reviews = $wpdb->get_row( $wpdb->prepare("SELECT ROUND( AVG(rate) ,1 ) as reviewsAvg, COUNT(id) as reviewsNum FROM $table_name WHERE blog_id = '%d' AND post_id = '%d'", $blog_id, $post_id) );
571
- echo $reviews->reviewsAvg.'|'.$reviews->reviewsNum;
572
- } else {
573
- echo 'MTS_REVIEW_DB_ERROR';
574
- }
575
- } else {
576
- echo 'MTS_REVIEW_DB_ERROR';
577
- }
578
- exit;
579
- }
580
-
581
- function wp_review_theme_defaults($new_options, $force_change = false) {
582
- global $pagenow;
583
- $opt_name = 'wp_review_options_'.wp_get_theme();
584
- $options = get_option('wp_review_options');
585
- if (empty($options)) $options = array();
586
- $options_updated = get_option( $opt_name );
587
- // if the theme was just activated OR options weren't updated yet
588
- if ( empty( $options_updated ) || $options_updated != $new_options || $force_change || ( isset( $_GET['activated'] ) && $pagenow == 'themes.php' )) {
589
- update_option( 'wp_review_options', array_merge($options, $new_options) );
590
- update_option( $opt_name, $new_options );
591
- }
592
- }
593
-
594
- function wp_review_get_all_image_sizes() {
595
- global $_wp_additional_image_sizes;
596
-
597
- $default_image_sizes = array( 'thumbnail', 'medium', 'large' );
598
-
599
- foreach ( $default_image_sizes as $size ) {
600
- $image_sizes[$size]['width'] = intval( get_option( "{$size}_size_w") );
601
- $image_sizes[$size]['height'] = intval( get_option( "{$size}_size_h") );
602
- $image_sizes[$size]['crop'] = get_option( "{$size}_crop" ) ? get_option( "{$size}_crop" ) : false;
603
- }
604
-
605
- if ( isset( $_wp_additional_image_sizes ) && count( $_wp_additional_image_sizes ) )
606
- $image_sizes = array_merge( $image_sizes, $_wp_additional_image_sizes );
607
-
608
- return $image_sizes;
609
- }
610
?>
1
+ <?php
2
+ ob_start();
3
+ /**
4
+ * WP Review
5
+ *
6
+ * @since 2.0
7
+ * @copyright Copyright (c) 2013, MyThemesShop
8
+ * @author MyThemesShop
9
+ * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
10
+ */
11
+
12
+ $options = get_option('wp_review_options');
13
+
14
+ /* Display the meta box data below 'the_content' hook. */
15
+ add_filter( 'the_content', 'wp_review_inject_data' );
16
+
17
+ /* Get review with Ajax */
18
+ add_action('wp_ajax_mts_review_get_review', 'mts_review_get_review');
19
+ add_action('wp_ajax_nopriv_mts_review_get_review', 'mts_review_get_review');
20
+
21
+ /* Show with shortcode */
22
+ add_shortcode('wp-review', 'wp_review_get_data');
23
+ add_shortcode('wp-review-total', 'wp_review_total_shortcode');
24
+ // aliases
25
+ add_shortcode('wp_review', 'wp_review_get_data');
26
+ add_shortcode('wp_review_total', 'wp_review_total_shortcode');
27
+
28
+ // image sizes for the widgets
29
+ add_image_size( 'wp_review_large', 320, 200, true );
30
+ add_image_size( 'wp_review_small', 65, 65, true );
31
+
32
+ /**
33
+ * Get the meta box data.
34
+ *
35
+ * @since 1.0
36
+ *
37
+ */
38
+ function wp_review_get_data() {
39
+ global $post;
40
+ global $blog_id;
41
+ $options = get_option('wp_review_options');
42
+
43
+ /* Retrieve the meta box data. */
44
+ $heading = get_post_meta( $post->ID, 'wp_review_heading', true );
45
+ $desc_title = get_post_meta( $post->ID, 'wp_review_desc_title', true );
46
+ if ( ! $desc_title ) $desc_title = __('Summary', 'wp-review');
47
+ $desc = get_post_meta( $post->ID, 'wp_review_desc', true );
48
+ $items = get_post_meta( $post->ID, 'wp_review_item', true );
49
+ $type = get_post_meta( $post->ID, 'wp_review_type', true );
50
+ $total = get_post_meta( $post->ID, 'wp_review_total', true );
51
+ $hide_desc = get_post_meta( $post->ID, 'wp_review_hide_desc', true );
52
+ $allowUsers = get_post_meta( $post->ID, 'wp_review_userReview', true );
53
+
54
+ $colors = array();
55
+ $colors['custom_colors'] = get_post_meta( $post->ID, 'wp_review_custom_colors', true );
56
+ $colors['color'] = get_post_meta( $post->ID, 'wp_review_color', true );
57
+ $colors['type'] = get_post_meta( $post->ID, 'wp_review_type', true );
58
+ $colors['fontcolor'] = get_post_meta( $post->ID, 'wp_review_fontcolor', true );
59
+ $colors['bgcolor1'] = get_post_meta( $post->ID, 'wp_review_bgcolor1', true );
60
+ $colors['bgcolor2'] = get_post_meta( $post->ID, 'wp_review_bgcolor2', true );
61
+ $colors['bordercolor'] = get_post_meta( $post->ID, 'wp_review_bordercolor', true );
62
+ $colors['total'] = get_post_meta( $post->ID, 'wp_review_total', true );
63
+
64
+ if (!$colors['custom_colors'] && !empty($options['colors']) && is_array($options['colors'])) {
65
+ $colors = array_merge($colors, $options['colors']);
66
+ }
67
+ $colors = apply_filters('wp_review_colors', $colors, $post->ID);
68
+ $color = $colors['color'];
69
+
70
+ /* Define a custom class for bar type. */
71
+ $class = '';
72
+ if ( 'point' == $type ) {
73
+ $class = 'bar-point';
74
+ } elseif ( 'percentage' == $type ) {
75
+ $class = 'percentage-point';
76
+ }
77
+ $post_types = get_post_types( array('public' => true), 'names' );
78
+ $excluded_post_types = apply_filters('wp_review_excluded_post_types', array('attachment'));
79
+ $allowed_post_types = array();
80
+ foreach ($post_types as $i => $post_type) {
81
+ if (!in_array($post_type, $excluded_post_types)) {
82
+ $allowed_post_types[] = $post_type; // allow it if it's not excluded
83
+ }
84
+ }
85
+
86
+ /**
87
+ * Add the custom data from the meta box to the main query an
88
+ * make sure the hook only apply on allowed post types
89
+ */
90
+ if ( $type != '' && is_singular($allowed_post_types) && is_main_query() ) {
91
+ //if ( $type != '' && is_main_query() && in_array(get_post_type($post->ID), $allowed_post_types)) {
92
+ // using this second if() instead of the first will allow reviews to be displayed on archive pages, but it may mess up excerpts
93
+ $review = '<div id="review" class="review-wrapper wp-review-'.$post->ID.' ' . $class . ' delay-animation" >';
94
+
95
+ /* Review title. */
96
+ if( $heading != '' ){
97
+ $review .= '<h5 class="review-title">' . __( $heading ) . '</h5>';
98
+ }
99
+
100
+
101
+ /* Review item. */
102
+ if ( $items ) {
103
+ $review .= '<ul class="review-list">';
104
+ foreach( $items as $item ) {
105
+
106
+ $item['wp_review_item_title'] = ( !empty( $item['wp_review_item_title'] ) ) ? $item['wp_review_item_title'] : '';
107
+ $item['wp_review_item_star'] = ( !empty( $item['wp_review_item_star'] ) ) ? $item['wp_review_item_star'] : '';
108
+
109
+ if ( 'star' == $type ) {
110
+ $result = $item['wp_review_item_star'] * 20;
111
+ $bestresult = '<meta itemprop="best" content="5"/>';
112
+ $best = '5';
113
+ } elseif( 'point' == $type ) {
114
+ $result = $item['wp_review_item_star'] * 10;
115
+ $bestresult = '<meta itemprop="best" content="10"/>';
116
+ $best = '10';
117
+ } else { // percentage
118
+ $result = $item['wp_review_item_star'] * 100 / 100;
119
+ $bestresult = '<meta itemprop="best" content="100"/>';
120
+ $best = '100';
121
+ }
122
+
123
+ $review .= '<li>';
124
+
125
+ if ( 'point' == $type ) {
126
+ $review .= '<span>' . wp_kses_post( $item['wp_review_item_title'] ) . ' - <span>' . $item['wp_review_item_star'] . '/10</span></span>';
127
+ } elseif( 'percentage' == $type ) {
128
+ $review .= '<span>' . wp_kses_post( $item['wp_review_item_title'] ) . ' - <span>' . $item['wp_review_item_star'] . '%' . '</span></span>';
129
+ } elseif ( 'star' == $type ) {
130
+ $review .= '<span>' . wp_kses_post( $item['wp_review_item_title'] ) . '</span>';
131
+ }
132
+
133
+ $review .= '<div class="review-star">';
134
+ $review .= '<div class="review-result-wrapper">';
135
+
136
+ if ( 'star' == $type ) {
137
+ $review .= '<i class="mts-icon-star"></i>';
138
+ $review .= '<i class="mts-icon-star"></i>';
139
+ $review .= '<i class="mts-icon-star"></i>';
140
+ $review .= '<i class="mts-icon-star"></i>';
141
+ $review .= '<i class="mts-icon-star"></i>';
142
+ $review .= '<div class="review-result" style="width:' . $result . '%;">';
143
+ $review .= '<i class="mts-icon-star"></i>';
144
+ $review .= '<i class="mts-icon-star"></i>';
145
+ $review .= '<i class="mts-icon-star"></i>';
146
+ $review .= '<i class="mts-icon-star"></i>';
147
+ $review .= '<i class="mts-icon-star"></i>';
148
+ $review .= '</div><!-- .review-result -->';
149
+ } elseif ( 'point' == $type ) {
150
+ $review .= '<div class="review-result" style="width:' . $result . '%;">' . $item['wp_review_item_star'] . '/10</div>';
151
+ } elseif ( 'percentage' == $type ) {
152
+ $review .= '<div class="review-result" style="width:' . $result . '%;">' . $item['wp_review_item_star'] . '</div>';
153
+ }
154
+
155
+ $review .= '</div><!-- .review-result-wrapper -->';
156
+ $review .= '</div><!-- .review-star -->';
157
+ $review .= '</li>';
158
+
159
+ }
160
+ $review .= '</ul>';
161
+ }
162
+
163
+ /* Review description. */
164
+ if ( ! $hide_desc ) {
165
+ if ( $desc ) {
166
+ $review .= '<div class="review-desc" >';
167
+ $review .= '<p class="review-summary-title"><strong>' . $desc_title . '</strong></p>';
168
+ $review .= do_shortcode ( shortcode_unautop( wp_kses_post( wpautop( $desc ) ) ) );
169
+ $review .= '</div><!-- .review-desc -->';
170
+
171
+ }//**END IF HAS DESCRIPTION**
172
+ if( $total != '' ){
173
+ $review .= '<div class="review-total-wrapper"> ';
174
+
175
+ if ( 'percentage' == $type ) {
176
+ $review .= '<span class="review-total-box"><span itemprop="review">' . $total . '</span> <i class="percentage-icon">%</i>' . '</span>';
177
+ } elseif ( 'point' == $type ) {
178
+ $review .= '<span class="review-total-box" itemprop="review">' . $total . '/10</span>';
179
+ } elseif ( 'star' == $type ) {
180
+ $review .= '<span class="review-total-box" itemprop="review">' . $total . '</span>';
181
+
182
+ $review .= '<div class="review-total-star">';
183
+ $review .= '<div class="review-result-wrapper">';
184
+ $review .= '<i class="mts-icon-star"></i>';
185
+ $review .= '<i class="mts-icon-star"></i>';
186
+ $review .= '<i class="mts-icon-star"></i>';
187
+ $review .= '<i class="mts-icon-star"></i>';
188
+ $review .= '<i class="mts-icon-star"></i>';
189
+ $review .= '<div class="review-result" style="width:' . $total*20 . '%;">';
190
+ $review .= '<i class="mts-icon-star"></i>';
191
+ $review .= '<i class="mts-icon-star"></i>';
192
+ $review .= '<i class="mts-icon-star"></i>';
193
+ $review .= '<i class="mts-icon-star"></i>';
194
+ $review .= '<i class="mts-icon-star"></i>';
195
+ $review .= '</div><!-- .review-result -->';
196
+ $review .= '</div><!-- .review-result-wrapper -->';
197
+ $review .= '</div><!-- .review-star -->';
198
+ }
199
+
200
+ $review .= '</div>';
201
+
202
+
203
+ $review .= '<div itemscope="itemscope" itemtype="http://data-vocabulary.org/Review">
204
+ <meta itemprop="itemreviewed" content="'.__( $heading ).'">
205
+
206
+ <span itemprop="rating" itemscope="itemscope"itemtype="http://data-vocabulary.org/Rating">
207
+ <meta itemprop="value" content="'.$total.'">
208
+ <meta itemprop="best" content="'.$best.'">
209
+ </span>
210
+ <span itemprop="reviewer" itemscope="itemscope" itemtype="http://data-vocabulary.org/Person">
211
+ <meta itemprop="name" content="'. get_the_author() .'">
212
+ </span>
213
+ </div>';
214
+ }
215
+ }
216
+
217
+ /**
218
+ * USERS REVIEW AREA
219
+ */
220
+
221
+ if( is_array( $allowUsers ) && $allowUsers[0] == 1 ){
222
+ $allowedClass = 'allowed-to-rate';
223
+ $hasNotRatedClass = 'has-not-rated-yet';
224
+ $postReviews = mts_get_post_reviews( $post->ID );
225
+ $userTotal = $postReviews[0]->reviewsAvg;
226
+ $usersReviewsCount = $postReviews[0]->reviewsNum;
227
+
228
+ $review .= '<div style="clear: both;"></div>';
229
+
230
+ $review .= '<div class="user-review-area" title="'.__('Click on the stars to rate!', 'wp-review').'">';
231
+ //$ip = $_SERVER['REMOTE_ADDR'];
232
+ if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
233
+ $ip = $_SERVER['HTTP_CLIENT_IP'];
234
+ } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
235
+ $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
236
+ } else {
237
+ $ip = $_SERVER['REMOTE_ADDR'];
238
+ }
239
+
240
+ $user_id = '';
241
+ if ( is_user_logged_in() ) { $user_id = get_current_user_id(); }
242
+ //echo $blog_id;
243
+ $review .= '<input type="hidden" id="blog_id" value="'.$blog_id.'">';
244
+ $review .= '<input type="hidden" id="post_id" value="'.$post->ID.'">';
245
+ $review .= '<input type="hidden" id="user_id" value="'.$user_id.'">';
246
+ $review .= '<input type="hidden" id="token" value="'.wp_create_nonce( "wp-review-security" ).'">';
247
+
248
+
249
+ if( $userTotal == '' ) $userTotal = '0.0';
250
+ $review .= '<div class="user-total-wrapper"><span class="user-review-title">'.__('User Rating','wp-review').': </span><span class="review-total-box"><span id="mts-user-reviews-total">' . $userTotal . '</span> ';
251
+ $review.= '<small>(<span id="mts-user-reviews-counter" >'.$usersReviewsCount.'</span> '.__('votes', 'wp-review').')</small></span></div>';
252
+
253
+ if( hasPreviousReview( $post->ID, $user_id, $ip )) {
254
+ $hasNotRatedClass = '';
255
+ }
256
+
257
+ $review .= '<div class="review-total-star '.$allowedClass.' '.$hasNotRatedClass.'" >';
258
+ $review .='<div class="mts-review-wait-msg"><span class="animate-spin mts-icon-loader"></span>'.__('Sending','wp-review').'</div>';
259
+ $review .= '<div class="review-result-wrapper">';
260
+ $review .= '<a data-input-value="1" title="1/5"><i class="mts-icon-star"></i></a>';
261
+ $review .= '<a data-input-value="2" title="2/5"><i class="mts-icon-star"></i></a>';
262
+ $review .= '<a data-input-value="3" title="3/5"><i class="mts-icon-star"></i></a>';
263
+ $review .= '<a data-input-value="4" title="4/5"><i class="mts-icon-star"></i></a>';
264
+ $review .= '<a data-input-value="5" title="5/5"><i class="mts-icon-star"></i></a>';
265
+ $review .= '<div class="review-result" style="width:' . $userTotal*20 . '%;">';
266
+ $review .= '<i class="mts-icon-star"></i>';
267
+ $review .= '<i class="mts-icon-star"></i>';
268
+ $review .= '<i class="mts-icon-star"></i>';
269
+ $review .= '<i class="mts-icon-star" style=""></i>';
270
+ $review .= '<i class="mts-icon-star"></i>';
271
+ $review .= '</div><!-- .review-result -->';
272
+ $review .= '</div><!-- .review-result-wrapper -->';
273
+ $review .= '</div><!-- .review-star -->';
274
+ $review .= '<input type="hidden" id="mts-review-user-rate" value="" />';
275
+
276
+ $review .= '</div>';
277
+
278
+ $review .= '<div itemscope itemtype="http://schema.org/Review">
279
+ <div itemprop="reviewRating" itemscope itemtype="http://schema.org/AggregateRating">
280
+ <meta itemprop="ratingValue" content="'.$userTotal.'" />
281
+ <meta itemprop="bestRating" content="5"/>
282
+ <meta itemprop="ratingCount" content="'.$usersReviewsCount.'" />
283
+ </div>
284
+ </div>';
285
+
286
+ }//**END IF USERS ALLOWED TO RATE**
287
+
288
+
289
+ $review .= '</div><!-- #review -->';
290
+
291
+ $review = apply_filters('wp_review_get_data', $review, $post->ID, $type, $total, $items);
292
+
293
+ return $review . wp_review_color_output(); // add color CSS to output
294
+ } else {
295
+ return '';
296
+ }
297
+ }
298
+
299
+ function wp_review_inject_data( $content ) {
300
+ global $post;
301
+ $options = get_option('wp_review_options');
302
+ $custom_location = get_post_meta( $post->ID, 'wp_review_custom_location', true );
303
+ $location = get_post_meta( $post->ID, 'wp_review_location', true );
304
+ if (!$custom_location && !empty($options['review_location'])) {
305
+ $location = $options['review_location'];
306
+ }
307
+
308
+ $location = apply_filters('wp_review_location', $location, $post->ID);
309
+
310
+ if (empty($location) || $location == 'custom') {
311
+ return $content;
312
+ }
313
+ $review = wp_review_get_data();
314
+ if ( 'bottom' == $location ) {
315
+ global $multipage, $numpages, $page;
316
+ if( $multipage ) {
317
+ if ($page == $numpages) {
318
+ return $content .= $review;
319
+ } else {
320
+ return $content;
321
+ }
322
+ } else {
323
+ return $content .= $review;
324
+ }
325
+ } elseif ( 'top' == $location ) {
326
+ return $review .= $content;
327
+ } else {
328
+ return $content;
329
+ }
330
+ }
331
+
332
+ /**
333
+ * Retrieve only total rating.
334
+ * To be used on archive pages, etc.
335
+ *
336
+ * @since 1.0
337
+ *
338
+ */
339
+ function wp_review_show_total($echo = true, $class = 'review-total-only') {
340
+ global $post;
341
+
342
+ $type = get_post_meta( $post->ID, 'wp_review_type', true );
343
+ $total = get_post_meta( $post->ID, 'wp_review_total', true );
344
+ $review = '';
345
+
346
+ $options = get_option('wp_review_options');
347
+ $colors = array();
348
+ $colors['custom_location'] = get_post_meta( $post->ID, 'wp_review_custom_location', true );
349
+ $colors['custom_colors'] = get_post_meta( $post->ID, 'wp_review_custom_colors', true );
350
+ $colors['custom_width'] = get_post_meta( $post->ID, 'wp_review_custom_width', true );
351
+
352
+ $colors['color'] = get_post_meta( $post->ID, 'wp_review_color', true );
353
+ $colors['type'] = get_post_meta( $post->ID, 'wp_review_type', true );
354
+ $colors['fontcolor'] = get_post_meta( $post->ID, 'wp_review_fontcolor', true );
355
+ $colors['bgcolor1'] = get_post_meta( $post->ID, 'wp_review_bgcolor1', true );
356
+ $colors['bgcolor2'] = get_post_meta( $post->ID, 'wp_review_bgcolor2', true );
357
+ $colors['bordercolor'] = get_post_meta( $post->ID, 'wp_review_bordercolor', true );
358
+ $colors['total'] = get_post_meta( $post->ID, 'wp_review_total', true );
359
+
360
+ if (!$colors['custom_colors'] && !empty($options['colors']) && is_array($options['colors'])) {
361
+ $colors = array_merge($colors, $options['colors']);
362
+ }
363
+ $colors = apply_filters('wp_review_colors', $colors, $post->ID);
364
+
365
+ if (!empty($type) && (!empty($total) || $total === '0')) {
366
+ wp_enqueue_style( 'wp_review-style', trailingslashit( WP_REVIEW_ASSETS ) . 'css/wp-review.css', array(), '1.1', 'all' );
367
+
368
+ $review = '<div class="review-type-'.$type.' '.esc_attr($class).' wp-review-show-total wp-review-total-'.$post->ID.'"> ';
369
+
370
+ if ( 'percentage' == $type ) {
371
+ $review .= '<span class="review-total-box"><span>' . $total . '</span> <i class="percentage-icon">%</i>' . '</span>';
372
+ } elseif ( 'point' == $type ) {
373
+ $review .= '<span class="review-total-box">' . $total . '/'.__('10','wp-review').'</span></span>';
374
+ } elseif ( 'star' == $type ) {
375
+ // star
376
+ $review .= '<div class="review-total-star">';
377
+ $review .= '<div class="review-result-wrapper">';
378
+ $review .= '<i class="mts-icon-star"></i>';
379
+ $review .= '<i class="mts-icon-star"></i>';
380
+ $review .= '<i class="mts-icon-star"></i>';
381
+ $review .= '<i class="mts-icon-star"></i>';
382
+ $review .= '<i class="mts-icon-star"></i>';
383
+ $review .= '<div class="review-result" style="width:' . $total*20 . '%;">';
384
+ $review .= '<i class="mts-icon-star"></i>';
385
+ $review .= '<i class="mts-icon-star"></i>';
386
+ $review .= '<i class="mts-icon-star"></i>';
387
+ $review .= '<i class="mts-icon-star"></i>';
388
+ $review .= '<i class="mts-icon-star"></i>';
389
+ $review .= '</div><!-- .review-result -->';
390
+ $review .= '</div><!-- .review-result-wrapper -->';
391
+ $review .= '</div><!-- .review-star -->';
392
+ }
393
+
394
+ $review .= '</div>';
395
+ }
396
+
397
+ $review = apply_filters('wp_review_show_total', $review, $post->ID, $type, $total);
398
+
399
+ if ($echo)
400
+ echo $review;
401
+ else
402
+ return $review;
403
+ }
404
+ function wp_review_total_shortcode($atts, $content) {
405
+ if (empty($atts['class']))
406
+ $atts['class'] = 'review-total-only review-total-shortcode';
407
+
408
+ return wp_review_show_total(false, $atts['class']);
409
+ }
410
+
411
+ function mts_get_post_reviews( $post_id ){
412
+ if( is_numeric( $post_id ) && $post_id > 0 ){
413
+ global $wpdb;
414
+ global $blog_id;
415
+ $table_name = $wpdb->prefix . MTS_WP_REVIEW_DB_TABLE;
416
+ if (function_exists('is_multisite') && is_multisite()) {$table_name = $wpdb->base_prefix . MTS_WP_REVIEW_DB_TABLE;}
417
+ $reviews = $wpdb->get_results( $wpdb->prepare("SELECT ROUND( AVG(rate) ,1 ) as reviewsAvg, COUNT(id) as reviewsNum FROM $table_name WHERE blog_id = '%d' AND post_id = '%d'", $blog_id, $post_id) );
418
+ return $reviews;
419
+ }
420
+ }
421
+
422
+
423
+ /**
424
+ * Star review color
425
+ *
426
+ * @since 1.0
427
+ */
428
+ function wp_review_color_output() {
429
+ global $post;
430
+ $style = '';
431
+ $options = get_option('wp_review_options');
432
+ if (empty($options['colors'])) $options['colors'] = array();
433
+ /* Retrieve the meta box data. */
434
+ if(is_singular()) {
435
+ $colors = array();
436
+ $colors['custom_location'] = get_post_meta( $post->ID, 'wp_review_custom_location', true );
437
+ $colors['custom_colors'] = get_post_meta( $post->ID, 'wp_review_custom_colors', true );
438
+ $colors['custom_width'] = get_post_meta( $post->ID, 'wp_review_custom_width', true );
439
+
440
+ $colors['color'] = get_post_meta( $post->ID, 'wp_review_color', true );
441
+ $colors['type'] = get_post_meta( $post->ID, 'wp_review_type', true );
442
+ $colors['fontcolor'] = get_post_meta( $post->ID, 'wp_review_fontcolor', true );
443
+ $colors['bgcolor1'] = get_post_meta( $post->ID, 'wp_review_bgcolor1', true );
444
+ $colors['bgcolor2'] = get_post_meta( $post->ID, 'wp_review_bgcolor2', true );
445
+ $colors['bordercolor'] = get_post_meta( $post->ID, 'wp_review_bordercolor', true );
446
+ $colors['total'] = get_post_meta( $post->ID, 'wp_review_total', true );
447
+
448
+ if (!$colors['custom_colors']) {
449
+ $colors = array_merge($colors, $options['colors']);
450
+ }
451
+ $colors = apply_filters('wp_review_colors', $colors, $post->ID);
452
+
453
+ extract($colors, EXTR_SKIP);
454
+
455
+ if( !$color ) $color = '#333333';
456
+
457
+ $style = '<style type="text/css">';
458
+
459
+ if ( 'star' == $type ) {
460
+
461
+ $style .= '.wp-review-'.$post->ID.' .review-result-wrapper .review-result i { color: '.$color.'; opacity: 1; filter: alpha(opacity=100); }
462
+ .wp-review-'.$post->ID.' .review-result-wrapper i{ color: '.$color.'; opacity: 0.50; filter: alpha(opacity=50); }';
463
+
464
+ } elseif ( 'point' == $type ) {
465
+
466
+ $style .= '.wp-review-'.$post->ID.'.bar-point .review-result { background-color: '.$color.'; }';
467
+
468
+ } elseif ( 'percentage' == $type ) {
469
+
470
+ $style .= '.wp-review-'.$post->ID.'.percentage-point .review-result { background-color: '.$color.'; }';
471
+
472
+ }
473
+
474
+ $style .= '.wp-review-'.$post->ID.'.review-wrapper, .wp-review-'.$post->ID.' .review-title, .wp-review-'.$post->ID.' .review-desc p{ color: '.$fontcolor.';}
475
+ .wp-review-'.$post->ID.' .review-list li, .wp-review-'.$post->ID.'.review-wrapper{ background: '.$bgcolor2.';}
476
+ .wp-review-'.$post->ID.' .review-title, .wp-review-'.$post->ID.' .review-list li:nth-child(2n){background: '.$bgcolor1.';}
477
+
478
+ .wp-review-'.$post->ID.'.bar-point .allowed-to-rate .review-result, .wp-review-'.$post->ID.'.percentage-point .allowed-to-rate .review-result{background: none;}
479
+ .wp-review-'.$post->ID.' .review-total-star.allowed-to-rate a i, .wp-review-comment-field a i, .wp-review-comment-rating a i { color: '.$color.'; opacity: 0.50; filter: alpha(opacity=50); }
480
+ .wp-review-'.$post->ID.'.bar-point .allowed-to-rate .review-result, .wp-review-'.$post->ID.'.percentage-point .allowed-to-rate .review-result{text-indent:0;}
481
+ .wp-review-'.$post->ID.'.bar-point .allowed-to-rate .review-result i, .wp-review-'.$post->ID.'.percentage-point .allowed-to-rate .review-result i, .wp-review-'.$post->ID.' .mts-user-review-star-container .selected i, .wp-review-'.$post->ID.' .user-review-area .review-result i, .wp-review-comment-field .review-result i, .wp-review-comment-rating .review-result i { color: '.$color.'; opacity: 1; filter: alpha(opacity=100); }
482
+ .wp-review-'.$post->ID.'.review-wrapper, .wp-review-'.$post->ID.' .review-title, .wp-review-'.$post->ID.' .review-list li, .wp-review-'.$post->ID.' .review-list li:last-child, .wp-review-'.$post->ID.' .user-review-area{border-color: '.$bordercolor.';}';
483
+
484
+ if( $total == '' ){
485
+
486
+ $style .= '.wp-review-'.$post->ID.' .user-review-area{border: 1px solid '.$bordercolor.'; margin-top: 0px;}
487
+ .wp-review-'.$post->ID.' .review-desc{width: 100%;}
488
+ .wp-review-'.$post->ID.'.review-wrapper{border: none; overflow: visible;}';
489
+ }
490
+ $style .= '</style>';
491
+
492
+ return $style;
493
+ }
494
+ }
495
+
496
+ /**
497
+ *Check if user has reviewed this post previously
498
+ */
499
+ function hasPreviousReview( $post_id, $user_id, $ip ){
500
+ if( is_numeric( $post_id ) && $post_id > 0 ){
501
+ global $wpdb;
502
+ global $blog_id;
503
+ $table_name = $wpdb->prefix . MTS_WP_REVIEW_DB_TABLE;
504
+ if (function_exists('is_multisite') && is_multisite()) {$table_name = $wpdb->base_prefix . MTS_WP_REVIEW_DB_TABLE;}
505
+ if( is_numeric( $user_id ) && $user_id > 0 ){
506
+ $prevRates = $wpdb->get_row( $wpdb->prepare("SELECT COUNT(id) as reviewsNum FROM $table_name WHERE blog_id = '%d' AND post_id = '%d' AND user_id = '%d'", $blog_id, $post_id, $user_id) );
507
+ if( $prevRates->reviewsNum > 0 ) return true; else return false;
508
+ }
509
+ elseif( $ip != '' ){
510
+ $prevRates = $wpdb->get_row( $wpdb->prepare("SELECT COUNT(id) as reviewsNum FROM $table_name WHERE blog_id = '%d' AND post_id = '%d' AND user_ip = '%s' AND user_id = '0'", $blog_id, $post_id, $ip) );
511
+ if( $prevRates->reviewsNum > 0 ) return true; else return false;
512
+ }
513
+ else return false;
514
+ }
515
+ return false;
516
+ }
517
+
518
+ function getPreviousReview( $post_id, $user_id, $ip ) {
519
+ if( is_numeric( $post_id ) && $post_id > 0 ){
520
+ global $wpdb;
521
+ global $blog_id;
522
+ $table_name = $wpdb->prefix . MTS_WP_REVIEW_DB_TABLE;
523
+ if (function_exists('is_multisite') && is_multisite()) {$table_name = $wpdb->base_prefix . MTS_WP_REVIEW_DB_TABLE;}
524
+ if( is_numeric( $user_id ) && $user_id > 0 ){
525
+ $prevRates = $wpdb->get_row( $wpdb->prepare("SELECT rate FROM $table_name WHERE blog_id = '%d' AND post_id = '%d' AND user_id = '%d'", $blog_id, $post_id, $user_id) );
526
+ if( $prevRates->rate ) return $prevRates->rate; else return 0;
527
+ }
528
+ elseif( $ip != '' ){
529
+ $prevRates = $wpdb->get_row( $wpdb->prepare("SELECT rate FROM $table_name WHERE blog_id = '%d' AND post_id = '%d' AND user_ip = '%s' AND user_id = '0'", $blog_id, $post_id, $ip) );
530
+ if( $prevRates->rate ) return $prevRates->rate; else return 0;
531
+ }
532
+ else return false;
533
+ }
534
+ return false;
535
+ }
536
+
537
+ /**
538
+ *Get review with Ajax
539
+ */
540
+ function mts_review_get_review(){
541
+ // security
542
+ check_ajax_referer( 'wp-review-security', 'nonce' );
543
+
544
+ global $wpdb;
545
+
546
+ $table_name = $wpdb->prefix . MTS_WP_REVIEW_DB_TABLE;
547
+ if (function_exists('is_multisite') && is_multisite()) {$table_name = $wpdb->base_prefix . MTS_WP_REVIEW_DB_TABLE;}
548
+
549
+ global $blog_id;
550
+ $post_id = intval($_POST['post_id']);
551
+ $user_id = intval($_POST['user_id']);
552
+
553
+ //$ip = $_SERVER['REMOTE_ADDR'];
554
+ if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
555
+ $uip = $_SERVER['HTTP_CLIENT_IP'];
556
+ } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
557
+ $uip = $_SERVER['HTTP_X_FORWARDED_FOR'];
558
+ } else {
559
+ $uip = $_SERVER['REMOTE_ADDR'];
560
+ }
561
+
562
+ if (!hasPreviousReview($post_id, $user_id, $uip)) {
563
+ $data = intval($_POST['review']);
564
+
565
+ if( $rows_affected = $wpdb->insert( $table_name, array('blog_id' => $blog_id, 'post_id' => $post_id, 'user_id' => $user_id, 'user_ip' => $uip, 'rate' => $data, 'date' => current_time('mysql')) ) ){
566
+ $reviews = $wpdb->get_row( $wpdb->prepare("SELECT ROUND( AVG(rate) ,1 ) as reviewsAvg, COUNT(id) as reviewsNum FROM $table_name WHERE blog_id = '%d' AND post_id = '%d'", $blog_id, $post_id) );
567
+ echo $reviews->reviewsAvg.'|'.$reviews->reviewsNum;
568
+ } else {
569
+ echo 'MTS_REVIEW_DB_ERROR';
570
+ }
571
+ } else {
572
+ echo 'MTS_REVIEW_DB_ERROR';
573
+ }
574
+ exit;
575
+ }
576
+
577
+ function wp_review_theme_defaults($new_options, $force_change = false) {
578
+ global $pagenow;
579
+ $opt_name = 'wp_review_options_'.wp_get_theme();
580
+ $options = get_option('wp_review_options');
581
+ if (empty($options)) $options = array();
582
+ $options_updated = get_option( $opt_name );
583
+ // if the theme was just activated OR options weren't updated yet
584
+ if ( empty( $options_updated ) || $options_updated != $new_options || $force_change || ( isset( $_GET['activated'] ) && $pagenow == 'themes.php' )) {
585
+ update_option( 'wp_review_options', array_merge($options, $new_options) );
586
+ update_option( $opt_name, $new_options );
587
+ }
588
+ }
589
+
590
+ function wp_review_get_all_image_sizes() {
591
+ global $_wp_additional_image_sizes;
592
+
593
+ $default_image_sizes = array( 'thumbnail', 'medium', 'large' );
594
+
595
+ foreach ( $default_image_sizes as $size ) {
596
+ $image_sizes[$size]['width'] = intval( get_option( "{$size}_size_w") );
597
+ $image_sizes[$size]['height'] = intval( get_option( "{$size}_size_h") );
598
+ $image_sizes[$size]['crop'] = get_option( "{$size}_crop" ) ? get_option( "{$size}_crop" ) : false;
599
+ }
600
+
601
+ if ( isset( $_wp_additional_image_sizes ) && count( $_wp_additional_image_sizes ) )
602
+ $image_sizes = array_merge( $image_sizes, $_wp_additional_image_sizes );
603
+
604
+ return $image_sizes;
605
+ }
606
?>
readme.txt CHANGED
@@ -4,7 +4,7 @@ Creator's website link: http://mythemeshop.com/plugins/wp-review/
4
Tags: review, wp review, rating, wp rating, user rating, google rating, star rating, product review
5
Requires at least: 3.0.1
6
Tested up to: 4.0
7
- Stable tag: 3.2
8
License: GPLv2 or later
9
License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
@@ -89,6 +89,11 @@ Please disable all plugins and check if rating is working properly. Then you can
89
90
== Changelog ==
91
92
= 3.2 =
93
* Added Options Panel for Global Option
94
* Added option to set Global Colors.
4
Tags: review, wp review, rating, wp rating, user rating, google rating, star rating, product review
5
Requires at least: 3.0.1
6
Tested up to: 4.0
7
+ Stable tag: 3.2.1
8
License: GPLv2 or later
9
License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
89
90
== Changelog ==
91
92
+ = 3.2.1 =
93
+ - Fixed error appearing when plugin settings weren't saved.
94
+ - Fixed JS issues.
95
+ - Fixed Tabbed Widget issue.
96
+
97
= 3.2 =
98
* Added Options Panel for Global Option
99
* Added option to set Global Colors.
wp-review.php CHANGED
@@ -2,8 +2,8 @@
2
/**
3
* Plugin Name: WP Review
4
* Plugin URI: http://mythemeshop.com/plugins/wp-review/
5
- * Description: Create reviews! Choose from stars, percentages or points for review scores. Supports Retina Display, WPMU & Unlimited Color Schemes.
6
- * Version: 3.2
7
* Author: MyThemesShop
8
* Author URI: http://mythemeshop.com/
9
*
2
/**
3
* Plugin Name: WP Review
4
* Plugin URI: http://mythemeshop.com/plugins/wp-review/
5
+ * Description: Create reviews! Choose from stars, percentages or points for review scores. Supports Retina Display, WPMU and Unlimited Color Schemes.
6
+ * Version: 3.2.1
7
* Author: MyThemesShop
8
* Author URI: http://mythemeshop.com/
9
*