LearnPress – Course Review - Version 1.0

Version Description

  • Compatible with LearnPress version 1.0
Download this release

Release Info

Developer tunnhn
Plugin Icon 128x128 LearnPress – Course Review
Version 1.0
Comparing to
See all releases

Code changes from version 0.9.1 to 1.0

assets/course-review.css CHANGED
@@ -1,163 +1,157 @@
1
  @charset "UTF-8";
2
- #review-overlay {
3
- background-color: rgba(0,0,0,.25);
4
- bottom: 0;
5
- display: flex;
6
- justify-content: center;
7
- left: 0;
8
- position: fixed;
9
- top: 0;
10
- width: 100%;
11
- }
12
-
13
- #review-overlay > .review-wrapper {
14
- align-self: center;
15
- background-color: rgba(0,0,0,.25);
16
- border-radius: 2px;
17
- padding: 6px;
18
- width: 450px;
19
- }
20
-
21
- #review-overlay .review-content {
22
- background-color: rgb(255,255,255);
23
- border-radius: 2px;
24
- padding: 24px;
25
- position: relative;
26
- }
27
-
28
- #review{
29
- position: fixed;
30
- z-index: 99999;
31
- display: none;
32
- align-self: center;
33
- background-color: rgba(0,0,0,.25);
34
- border-radius: 2px;
35
- padding: 6px;
36
- width: 500px;
37
- top: 50px;
38
- left: 50%;
39
- margin-left: -250px;
40
- }
41
- #review .review-content {
42
- background-color: rgb(255,255,255);
43
- border-radius: 2px;
44
- padding: 24px;
45
- position: relative;
46
- }
47
- #review h3{
48
- font-size: 16px;
49
- margin: 0 0 20px;
50
- }
51
- #review h3 .close{
52
- float: right;
53
- border: none;
54
- text-decoration: none;
55
- width: auto;
56
- height: auto;
57
- margin-right: -9px;
58
- margin-top: -7px;
59
- }
60
- #review h3 .close:before{font-size: 32px;}
61
- #review .review-fields{
62
- margin: 0 0 -20px;
63
- list-style: none;
64
- }
65
- #review .review-fields > li{
66
- margin: 0 0 20px 0;
67
- }
68
- #review .review-fields > li > label{
69
- display: block;
70
- margin: 0 0 7px;
71
- font-size: 15px;
72
- }
73
- #review .review-fields > li > label .required{
74
- margin-left: 5px;
75
- display: inline-block;
76
- vertical-align: middle;
77
- font-size: 24px;
78
- line-height: 1;
79
- height: 15px;
80
- margin-top: -3px;
81
- }
82
- .review-stars{
83
- margin: 0 0;
84
- list-style: none;
85
- }
86
- .review-stars:after{
87
- clear: both;
88
- content: '';
89
- display: block;
90
- }
91
- .review-stars > li{
92
- width: 40px;
93
- height: 40px;
94
- float: left;
95
- }
96
- .review-stars > li span{
97
- text-decoration: none;
98
- font-size: 40px;
99
- border-bottom: none;
100
- width: auto;
101
- height: auto;
102
  }
103
- .review-stars > li a:visited,
104
- .review-stars > li a:focus{
105
- border: none;
 
 
 
 
 
 
106
  }
107
- .review-stars > li span:before{
108
- width: 40px;
109
- height: 40px;
 
 
 
 
 
 
 
110
  }
111
- .review-stars > li span.hover:before{
112
- content: "\f155";
113
- color: #F05A19;
114
- cursor: pointer;
115
  }
116
- #review .review-actions{
117
- text-align: right;
118
- padding-top: 20px;
119
- border-top: 1px solid #F0F0F0;
 
 
 
 
 
120
  }
121
 
122
- #review .submitting{
123
- display: none;
124
  }
125
- #review .review-stars{
126
- cursor: pointer;
 
 
127
  }
128
 
129
- .review-stars-rated{
130
- display: inline-block;
131
- position: relative;
132
  }
133
- .review-stars-rated .review-stars{
134
- display: inline-block;
 
 
 
135
  }
136
- .review-stars-rated .review-stars.filled{
137
- position: absolute;
138
- top: 0;
139
- left: 0;
140
- z-index: 10;
141
- white-space: nowrap;
142
- overflow: hidden;
143
- color: #F05A19;
144
- height: 40px;
145
  }
146
- .review-stars.filled > li{
147
- position: absolute;
 
 
148
  }
149
- .review-stars.filled > li:nth-child(2){
150
- left: 40px;
 
 
 
151
  }
152
- .review-stars.filled > li:nth-child(3){
153
- left: 80px;
 
 
 
154
  }
155
- .review-stars.filled > li:nth-child(4){
156
- left: 120px;
 
 
 
157
  }
158
- .review-stars.filled > li:nth-child(5){
159
- left: 160px;
 
 
 
 
 
 
 
 
 
 
160
  }
161
- #course-reviews .loading{
162
- display: none;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
163
  }
1
  @charset "UTF-8";
2
+ .course-review-wrapper {
3
+ display: none;
4
+ position: fixed;
5
+ top: 0;
6
+ left: 0;
7
+ right: 0;
8
+ bottom: 0;
9
+ z-index: 99999;
10
+ text-align: center;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
  }
12
+
13
+ .review-overlay {
14
+ background: #000;
15
+ bottom: 0;
16
+ left: 0;
17
+ position: fixed;
18
+ top: 0;
19
+ width: 100%;
20
+ opacity: 0.6;
21
  }
22
+
23
+ .review-form {
24
+ background-color: rgb(255, 255, 255);
25
+ padding: 20px;
26
+ position: relative;
27
+ width: 80%;
28
+ max-width: 600px;
29
+ margin-top: 50px;
30
+ display: inline-block;
31
+ text-align: left;
32
  }
33
+
34
+ .review-form h3 {
35
+ font-size: 16px;
36
+ margin: 0 0 20px;
37
  }
38
+
39
+ .review-form h3 .close {
40
+ float: right;
41
+ border: none;
42
+ text-decoration: none;
43
+ width: auto;
44
+ height: auto;
45
+ margin-right: -9px;
46
+ margin-top: -7px;
47
  }
48
 
49
+ .review-form h3 .close:before {
50
+ font-size: 32px;
51
  }
52
+
53
+ .review-form .review-fields {
54
+ margin: 0 0 -20px;
55
+ list-style: none;
56
  }
57
 
58
+ .review-form .review-fields > li {
59
+ margin: 0 0 20px 0;
 
60
  }
61
+
62
+ .review-form .review-fields > li > label {
63
+ display: block;
64
+ margin: 0 0 7px;
65
+ font-size: 15px;
66
  }
67
+
68
+ .review-form .review-fields > li > label .required {
69
+ margin-left: 5px;
70
+ display: inline-block;
71
+ vertical-align: middle;
72
+ font-size: 24px;
73
+ line-height: 1;
74
+ height: 15px;
75
+ margin-top: -3px;
76
  }
77
+
78
+ .review-form .review-fields > li input[type="text"],
79
+ .review-form .review-fields > li textarea{
80
+ width: 100%;
81
  }
82
+
83
+ .review-stars {
84
+ margin: 0 0;
85
+ list-style: none;
86
+ overflow: hidden;
87
  }
88
+
89
+ .review-stars:after {
90
+ clear: both;
91
+ content: '';
92
+ display: block;
93
  }
94
+
95
+ .review-stars > li {
96
+ width: 24px;
97
+ height: 24px;
98
+ float: left;
99
  }
100
+
101
+ .review-stars > li span {
102
+ text-decoration: none;
103
+ font-size: 24px;
104
+ border-bottom: none;
105
+ width: auto;
106
+ height: auto;
107
+ }
108
+
109
+ .review-stars > li a:visited,
110
+ .review-stars > li a:focus {
111
+ border: none;
112
  }
113
+
114
+ .review-stars > li span:before {
115
+ width: 22px;
116
+ height: 24px;
117
+ }
118
+
119
+ .review-stars > li span.hover:before {
120
+ content: "\f155";
121
+ color: #F05A19;
122
+ cursor: pointer;
123
+ }
124
+ .review-form .ajaxload,
125
+ .review-form .message{
126
+ display: none;
127
+ }
128
+ .course-review-wrapper.submitting .ajaxload,
129
+ .course-review-wrapper.error .message{
130
+ display: inline-block;
131
+ }
132
+ .review-stars-rated{
133
+ width: 120px;
134
+ position: relative;
135
+ }
136
+ .review-stars-rated .review-stars.empty,
137
+ .review-stars-rated .review-stars.filled {
138
+ width: 120px;
139
+ height: 24px;
140
+ font-family: dashicons;
141
+ font-size: 24px;
142
+ }
143
+ .review-stars-rated .review-stars.empty:before{
144
+ content: '\f154\f154\f154\f154\f154';
145
+ line-height: 1;
146
+ vertical-align: top;
147
+ }
148
+ .review-stars-rated .review-stars.filled:before{
149
+ content: '\f155\f155\f155\f155\f155';
150
+ line-height: 1;
151
+ vertical-align: top;
152
+ }
153
+ .review-stars-rated .review-stars.filled{
154
+ position: absolute;
155
+ top:0;
156
+ left: 0;
157
  }
assets/course-review.js CHANGED
@@ -1,137 +1,270 @@
1
  /**
2
- * Created by foobla on 4/10/2015.
 
 
 
 
3
  */
 
4
 
5
- jQuery(document).ready(function ($){
6
- var $review = $('#review');
7
- function close_form(){
8
- $(document.body).unblock_ui();
9
- $review.fadeOut('fast');
10
- $(document.body).unbind('click.close_review_form')
11
- $(window).unbind('scroll.review-position');
12
- }
13
- $(".write-a-review").click(function( event ){
14
- event.preventDefault();
15
- $(document.body).block_ui({
16
- backgroundColor: '#000',
17
- opacity: 0.5,
18
- position: 'fixed'
19
- });
20
- $('input, textarea', $review).val('');
21
- stars.removeClass('hover')
22
- $review
23
- .removeData('selected')
24
- .css({
25
- top: $(window).scrollTop() + 50,
26
- marginTop: -$(window).scrollTop()
27
- })
28
- .fadeIn("fast", function(){
29
- $('input:first', $review).focus();
30
- });
31
- $(window).on('scroll.review-position', function(){
32
- $review.css({
33
- marginTop: -$(window).scrollTop()
34
- })
35
- });
36
- $(document.body).on('click.close_review_form', ">.block-ui", close_form)
37
- });
38
-
39
- $(".close", $review).click(function(evt){
40
- evt.preventDefault();
41
- close_form();
42
- });
43
-
44
- $('.cancel', $review).click(close_form);
45
-
46
- $(document).keyup(function(e) {
47
- if( e.keyCode == 27 && $review.is(':visible') ) {
48
- event.preventDefault();
49
- close_form();
50
- }
51
- });
52
-
53
- $('.review-title', $review).tipsy({gravity: 's'});
54
- var stars = $('.review-fields ul > li span', $review).each(function(i){
55
- $(this).hover(function(){
56
- stars.map(function(j){ j <= i ? $(this).addClass('hover') : $(this).removeClass('hover');})
57
- }, function(){
58
- var selected = $review.data('selected');
59
- stars.map(function(j){ j <= selected ? $(this).addClass('hover') : $(this).removeClass('hover');})
60
- }).click(function(e){
61
- e.preventDefault();
62
- $review.data('selected', i)
63
- });
64
- })
65
-
66
- $(document).on('click', '#course-review-load-more', function(){
67
- var $button = $(this);
68
- if( ! $button.is(':visible') ) return;
69
- $button.hide();
70
- var paged = parseInt($(this).attr('data-paged')) + 1;
71
- $('#course-reviews .loading').show();
72
- $.ajax({
73
- type: "POST",
74
- dataType: 'html',
75
- url: window.location.href,
76
- data: {
77
- action: 'learn_press_load_course_review',
78
- paged: paged
79
- },
80
- success: function (response) {
81
- var $content = $(response),
82
- $loading = $('#course-reviews .loading').hide();
83
- $content.find( '.course-reviews-list > li:not(.loading)').insertBefore( $loading );
84
- if( $content.find( '#course-review-load-more').length ) {
85
- $button.show().attr('data-paged', paged);
86
- }else{
87
- $button.remove();
88
- }
89
- }
90
- });
91
- });
92
- $('.submit-review').click(function (event){
93
- event.preventDefault();
94
-
95
- var $review_title = $('input[name="review-title"]');
96
- var $review_content = $('textarea[name="review-content"]');
97
- var review_rate = $review.data('selected');
98
- var course_id = $(this).attr('data-id');
99
-
100
- if( 0 == $review_title.val().length ){
101
- alert('Please enter the review title')
102
- $review_title.focus();
103
- return;
104
- }
105
-
106
- if( 0 == $review_content.val().length ){
107
- alert('Please enter the review content')
108
- $review_content.focus();
109
- return;
110
- }
111
-
112
- if( review_rate == undefined ){
113
- alert('Please select your rating')
114
- return;
115
- }
116
- $review.block_ui();
117
- $('.submitting', $review).show();
118
- $.ajax({
119
- type : "POST",
120
- dataType: 'html',
121
- url : ajaxurl,
122
- data : {
123
- action : 'learn_press_add_course_review',
124
- review_rate : parseInt( review_rate ) + 1,
125
- review_title : $review_title.val(),
126
- review_content : $review_content.val(),
127
- course_id : course_id
128
- },
129
- success: function (html) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
130
  $('.course-rate').replaceWith($(html))
131
- $('.submitting', $review).hide();
132
- $(".close", $review).trigger('click');
133
- $('button.write-a-review').remove();
134
  }
135
- })
136
- })
137
  })
1
  /**
2
+ * LearnPress Course Review addon
3
+ *
4
+ * WARNING: This script may not work correct with LP version before 1.0
5
+ *
6
+ * @version 1.0
7
  */
8
+ ;(function ($) {
9
 
10
+ function CourseReview() {
11
+ var $reviewForm = $('#course-review').appendTo(document.body),
12
+ $reviewBtn = $(".write-a-review"),
13
+ $stars = $('.review-fields ul > li span', $reviewForm).each(function (i) {
14
+ $(this).hover(function () {
15
+ if (submitting) {
16
+ return;
17
+ }
18
+ $stars.map(function (j) {
19
+ $(this).toggleClass('hover', j <= i);
20
+ })
21
+ }, function () {
22
+ if (submitting) {
23
+ return;
24
+ }
25
+ var selected = $reviewForm.find('input[name="rating"]').val();
26
+ if (selected) {
27
+ $stars.map(function (j) {
28
+ $(this).toggleClass('hover', j < selected);
29
+ });
30
+ } else {
31
+ $stars.removeClass('hover')
32
+ }
33
+ }).click(function (e) {
34
+ if (submitting) {
35
+ return;
36
+ }
37
+ e.preventDefault();
38
+ $reviewForm.find('input[name="rating"]').val($stars.index($(this)) + 1);
39
+ })
40
+ }),
41
+ that = this,
42
+ submitting = false,
43
+ showForm = null,
44
+ closeForm = null,
45
+ addReview = null;
46
+
47
+ showForm = this.showForm = function () {
48
+ var _completed = function () {
49
+ $('input[type="text"], textarea', this).val('');
50
+ $stars.removeClass('hover');
51
+ }
52
+ $reviewForm.fadeIn(_completed);
53
+ }
54
+
55
+ closeForm = this.closeForm = function () {
56
+ var _completed = function () {
57
+ $('button, input[type="text"], textarea', $reviewForm).prop('disabled', false);
58
+ $reviewForm.removeClass('submitting').data('selected', '');
59
+ $stars.removeClass('hover')
60
+ }
61
+ $reviewForm.find('input[name="rating"]').val('')
62
+ $(document).focus();
63
+ $reviewForm.fadeOut(_completed);
64
+ }
65
+
66
+ addReview = this.addReview = function () {
67
+ var $reviewTitle = $('input[name="review_title"]', $reviewForm);
68
+ var $reviewContent = $('textarea[name="review_content"]', $reviewForm);
69
+ var rating = $reviewForm.find('input[name="rating"]').val();
70
+ var course_id = $(this).attr('data-id');
71
+
72
+ if (0 == $reviewTitle.val().length) {
73
+ alert(learn_press_course_review.empty_title)
74
+ $reviewTitle.focus();
75
+ return;
76
+ }
77
+
78
+ if (0 == $reviewContent.val().length) {
79
+ alert(learn_press_course_review.empty_content)
80
+ $reviewContent.focus();
81
+ return;
82
+ }
83
+
84
+ if (!rating) {
85
+ alert(learn_press_course_review.empty_rating)
86
+ return;
87
+ }
88
+ $reviewForm.addClass('submitting');
89
+ $.ajax({
90
+ url : window.location.href,
91
+ data : $('form', $reviewForm).serialize(),
92
+ dataType: 'text',
93
+ success : function (response) {
94
+ submitting = false;
95
+ response = LearnPress.parseJSON(response);
96
+ if (response.result == 'success') {
97
+ closeForm();
98
+ LearnPress.reload();
99
+ } else {
100
+ $('button, input[type="text"], textarea', $reviewForm).prop('disabled', false);
101
+ $reviewForm.removeClass('submitting').addClass('error');
102
+ $reviewForm.find('message').html(response.message);
103
+ }
104
+ },
105
+ error : function (response) {
106
+ response = LearnPress.parseJSON(response);
107
+ submitting = false;
108
+ $('button, input[type="text"], textarea', $reviewForm).prop('disabled', false);
109
+ $reviewForm.removeClass('submitting').addClass('error');
110
+ $reviewForm.find('message').html(response.message);
111
+ }
112
+ });
113
+ $('button, input[type="text"], textarea', $reviewForm).prop('disabled', true);
114
+
115
+ }
116
+
117
+ $reviewBtn.click(function (e) {
118
+ e.preventDefault();
119
+ that.showForm();
120
+ });
121
+
122
+ $reviewForm
123
+ .on('click', '.submit-review', addReview)
124
+ .on('click', '.close', function (e) {
125
+ e.preventDefault();
126
+ closeForm();
127
+ })
128
+ }
129
+
130
+ $(document).ready(function () {
131
+ new CourseReview();
132
+ });
133
+
134
+ })
135
+ (jQuery);
136
+ jQuery(document).ready(function ($) {
137
+
138
+ return;
139
+ var $review = $('#review');
140
+
141
+ function close_form() {
142
+ $review.fadeOut('fast');
143
+ $(document.body).unbind('click.close_review_form')
144
+ $(window).unbind('scroll.review-position');
145
+ }
146
+
147
+ $(".write-a-review").click(function (event) {
148
+ event.preventDefault();
149
+
150
+ $('input, textarea', $review).val('');
151
+ stars.removeClass('hover')
152
+ $review
153
+ .removeData('selected')
154
+ .css({
155
+ top : $(window).scrollTop() + 50,
156
+ marginTop: -$(window).scrollTop()
157
+ })
158
+ .fadeIn("fast", function () {
159
+ $('input:first', $review).focus();
160
+ });
161
+ $(window).on('scroll.review-position', function () {
162
+ $review.css({
163
+ marginTop: -$(window).scrollTop()
164
+ })
165
+ });
166
+ $(document.body).on('click.close_review_form', ">.block-ui", close_form)
167
+ });
168
+
169
+ $(".close", $review).click(function (evt) {
170
+ evt.preventDefault();
171
+ close_form();
172
+ });
173
+
174
+ $('.cancel', $review).click(close_form);
175
+
176
+ $(document).keyup(function (e) {
177
+ if (e.keyCode == 27 && $review.is(':visible')) {
178
+ event.preventDefault();
179
+ close_form();
180
+ }
181
+ });
182
+
183
+ var stars = $('.review-fields ul > li span', $review).each(function (i) {
184
+ $(this).hover(function () {
185
+ stars.map(function (j) {
186
+ j <= i ? $(this).addClass('hover') : $(this).removeClass('hover');
187
+ })
188
+ }, function () {
189
+ var selected = $review.data('selected');
190
+ stars.map(function (j) {
191
+ j <= selected ? $(this).addClass('hover') : $(this).removeClass('hover');
192
+ })
193
+ }).click(function (e) {
194
+ e.preventDefault();
195
+ $review.data('selected', i)
196
+ });
197
+ })
198
+
199
+ $(document).on('click', '#course-review-load-more', function () {
200
+ var $button = $(this);
201
+ if (!$button.is(':visible')) return;
202
+ $button.hide();
203
+ var paged = parseInt($(this).attr('data-paged')) + 1;
204
+ $('#course-reviews .loading').show();
205
+ $.ajax({
206
+ type : "POST",
207
+ dataType: 'html',
208
+ url : window.location.href,
209
+ data : {
210
+ action: 'learn_press_load_course_review',
211
+ paged : paged
212
+ },
213
+ success : function (response) {
214
+ var $content = $(response),
215
+ $loading = $('#course-reviews .loading').hide();
216
+ $content.find('.course-reviews-list > li:not(.loading)').insertBefore($loading);
217
+ if ($content.find('#course-review-load-more').length) {
218
+ $button.show().attr('data-paged', paged);
219
+ } else {
220
+ $button.remove();
221
+ }
222
+ }
223
+ });
224
+ });
225
+ $('.submit-review').click(function (event) {
226
+ event.preventDefault();
227
+
228
+ var $review_title = $('input[name="review-title"]');
229
+ var $review_content = $('textarea[name="review-content"]');
230
+ var review_rate = $review.data('selected');
231
+ var course_id = $(this).attr('data-id');
232
+
233
+ if (0 == $review_title.val().length) {
234
+ alert('Please enter the review title')
235
+ $review_title.focus();
236
+ return;
237
+ }
238
+
239
+ if (0 == $review_content.val().length) {
240
+ alert('Please enter the review content')
241
+ $review_content.focus();
242
+ return;
243
+ }
244
+
245
+ if (review_rate == undefined) {
246
+ alert('Please select your rating')
247
+ return;
248
+ }
249
+ $review.block_ui();
250
+ $('.submitting', $review).show();
251
+ $.ajax({
252
+ type : "POST",
253
+ dataType: 'html',
254
+ url : ajaxurl,
255
+ data : {
256
+ action : 'learn_press_add_course_review',
257
+ review_rate : parseInt(review_rate) + 1,
258
+ review_title : $review_title.val(),
259
+ review_content: $review_content.val(),
260
+ course_id : course_id
261
+ },
262
+ success : function (html) {
263
  $('.course-rate').replaceWith($(html))
264
+ $('.submitting', $review).hide();
265
+ $(".close", $review).trigger('click');
266
+ $('button.write-a-review').remove();
267
  }
268
+ })
269
+ })
270
  })
incs/review-functions.php ADDED
@@ -0,0 +1,226 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Reviews functions
4
+ */
5
+
6
+ if ( !defined( 'ABSPATH' ) ) {
7
+ exit; // Exit if accessed directly
8
+ }
9
+ /**
10
+ * @param int $course_id
11
+ * @param int $paged
12
+ * @param int $per_page
13
+ * @param boolean $force
14
+ *
15
+ * @return mixed|void
16
+ */
17
+ function learn_press_get_course_review( $course_id, $paged = 1, $per_page = LP_ADDON_COURSE_REVIEW_PER_PAGE, $force = false ) {
18
+ static $course_reviews = array();
19
+ if ( !$force && !empty( $course_reviews[$course_id] ) ) {
20
+ return $course_reviews[$course_id];
21
+ }
22
+ global $wpdb;
23
+ $per_page = absint( apply_filters( 'learn_press_course_reviews_per_page', $per_page ) );
24
+ $paged = absint( $paged );
25
+ if ( $per_page == 0 ) {
26
+ $per_page = 9999999;
27
+ }
28
+ if ( $paged == 0 ) {
29
+ $paged = 1;
30
+ }
31
+ $start = ( $paged - 1 ) * $per_page;
32
+ $start = max( $start, 0 );
33
+ $per_page = max( $per_page, 1 );
34
+ $results = array(
35
+ 'reviews' => array(),
36
+ 'paged' => $paged,
37
+ 'total' => 0,
38
+ 'per_page' => $per_page
39
+ );
40
+
41
+ $query = $wpdb->prepare( "
42
+ SELECT SQL_CALC_FOUND_ROWS u.*, c.comment_ID as comment_id, cm1.meta_value as title, c.comment_content as content, cm2.meta_value as rate
43
+ FROM {$wpdb->posts} p
44
+ INNER JOIN {$wpdb->comments} c ON p.ID = c.comment_post_ID
45
+ INNER JOIN {$wpdb->users} u ON u.ID = c.user_id
46
+ INNER JOIN {$wpdb->commentmeta} cm1 ON cm1.comment_id = c.comment_ID AND cm1.meta_key=%s
47
+ INNER JOIN {$wpdb->commentmeta} cm2 ON cm2.comment_id = c.comment_ID AND cm2.meta_key=%s
48
+ WHERE p.ID=%d AND c.comment_type=%s
49
+ ORDER BY c.comment_date DESC
50
+ LIMIT %d, %d
51
+ ", '_lpr_review_title', '_lpr_rating', $course_id, 'review', $start, $per_page );
52
+ $course_review = $wpdb->get_results( $query );
53
+ if ( $course_review ) {
54
+ $results['reviews'] = $course_review;
55
+ $results['total'] = $wpdb->get_var( "SELECT FOUND_ROWS();" );
56
+ if ( $results['total'] <= $start + $per_page ) {
57
+ $results['finish'] = true;
58
+ }
59
+ }
60
+ $course_reviews[$course_id] = $results;
61
+ return $results;
62
+ }
63
+
64
+ /**
65
+ * @param $course_id
66
+ *
67
+ * @return mixed|void
68
+ */
69
+ function learn_press_get_course_rate( $course_id ) {
70
+ global $wpdb;
71
+ $query = $wpdb->prepare( "
72
+ SELECT avg( cm1.meta_value ) as rated
73
+ FROM {$wpdb->posts} p
74
+ INNER JOIN {$wpdb->comments} c ON p.ID = c.comment_post_ID
75
+ INNER JOIN {$wpdb->commentmeta} cm1 ON cm1.comment_id = c.comment_ID AND cm1.meta_key='_lpr_rating'
76
+ WHERE p.ID=%d
77
+ AND c.comment_type=%s
78
+ ", $course_id, 'review' );
79
+
80
+ $rated = $wpdb->get_var( $query );
81
+ return apply_filters( 'learn_press_get_course_rate', $rated );
82
+ }
83
+
84
+ function learn_press_get_course_rate_total( $course_id ) {
85
+ global $wpdb;
86
+ $query = $wpdb->prepare( "
87
+ SELECT COUNT(*)
88
+ FROM {$wpdb->posts} p
89
+ INNER JOIN {$wpdb->comments} c ON p.ID = c.comment_post_ID
90
+ INNER JOIN {$wpdb->users} u ON u.ID = c.user_id
91
+ INNER JOIN {$wpdb->commentmeta} cm1 ON cm1.comment_id = c.comment_ID AND cm1.meta_key=%s
92
+ INNER JOIN {$wpdb->commentmeta} cm2 ON cm2.comment_id = c.comment_ID AND cm2.meta_key=%s
93
+ WHERE p.ID=%d AND c.comment_type=%s
94
+ ORDER BY c.comment_date DESC",
95
+ '_lpr_review_title', '_lpr_rating', $course_id, 'review'
96
+ );
97
+ $total = $wpdb->get_var( $query );
98
+ return $total;
99
+ }
100
+
101
+ /**
102
+ * @param $course_id
103
+ * @param $user_id
104
+ *
105
+ * @return mixed|void
106
+ */
107
+ function learn_press_get_user_review_title( $course_id, $user_id ) {
108
+ $course_review = get_post_meta( $course_id, '_lpr_course_review', true );
109
+ if ( $course_review && array_key_exists( $user_id, $course_review['review_title'] ) ) {
110
+ return apply_filters( 'learn_press_get_user_review', $course_review['review_title'][$user_id] );
111
+ }
112
+ return false;
113
+ }
114
+
115
+ /**
116
+ * @param $course_id
117
+ * @param $user_id
118
+ *
119
+ * @return mixed|void
120
+ */
121
+ function learn_press_get_user_rate( $course_id = null, $user_id = null ) {
122
+ $course = LP_Course::get_course( $course_id );
123
+ if ( !$user_id ) $user_id = get_current_user_id();
124
+ if ( !$course->id || !$user_id ) return false;
125
+
126
+ $comment = false;
127
+ global $wpdb;
128
+ $query = $wpdb->prepare( "
129
+ SELECT *
130
+ FROM {$wpdb->posts} p
131
+ INNER JOIN {$wpdb->comments} c ON c.comment_post_ID = p.ID
132
+ WHERE c.comment_post_ID = %d AND user_id = %d
133
+ ", $course_id, $user_id );
134
+ $comments = $wpdb->get_results( $query );
135
+ if ( $comments ) {
136
+ $comment = $comments[0];
137
+ $comment->comment_title = get_comment_meta( $comment->comment_ID, '_lpr_review_title', true );
138
+ $comment->rating = get_comment_meta( $comment->comment_ID, '_lpr_rating', true );
139
+ }
140
+ return $comment;
141
+ }
142
+
143
+ /**
144
+ * @param array
145
+ *
146
+ * @return int
147
+ */
148
+ function learn_press_add_course_review( $args = array() ) {
149
+ $args = wp_parse_args(
150
+ $args,
151
+ array(
152
+ 'title' => '',
153
+ 'content' => '',
154
+ 'rate' => '',
155
+ 'user_id' => 0,
156
+ 'course_id' => 0
157
+ )
158
+ );
159
+ $user_id = $args['user_id'];
160
+ $course_id = $args['course_id'];
161
+ $user_review = learn_press_get_user_rate( $course_id, $user_id );
162
+ $comment_id = 0;
163
+ if( !$user_review ) {
164
+ $user = get_user_by( 'id', $user_id );
165
+ $comment_id = wp_new_comment(
166
+ array(
167
+ 'comment_post_ID' => $course_id,
168
+ 'comment_author' => 'LearnPress',
169
+ 'comment_author_email' => $user->user_email,
170
+ 'comment_author_url' => '',
171
+ 'comment_content' => $args['content'],
172
+ 'comment_parent' => 0,
173
+ 'user_id' => $user->ID,
174
+ 'comment_approved' => 1,
175
+ 'comment_type' => 'review' // let filter to not display it as comments
176
+ )
177
+ );
178
+ }
179
+ if ( $comment_id ) {
180
+ add_comment_meta( $comment_id, '_lpr_rating', $args['rate'] );
181
+ add_comment_meta( $comment_id, '_lpr_review_title', $args['title'] );
182
+ }
183
+
184
+ return $comment_id;
185
+ }
186
+
187
+ function learn_press_course_review_template( $name, $args = null ) {
188
+ learn_press_get_template( $name, $args, LP_ADDON_COURSE_REVIEW_THEME_TMPL, LP_ADDON_COURSE_REVIEW_TMPL );
189
+ }
190
+
191
+ /*
192
+ function learn_press_add_course_review( $args = array() ) {
193
+ $args = wp_parse_args(
194
+ $args,
195
+ array(
196
+ 'title' => '',
197
+ 'content' => '',
198
+ 'rate' => '',
199
+ 'user_id' => 0,
200
+ 'course_id' => 0
201
+ )
202
+ );
203
+ $user_id = $args['user_id'];
204
+ $course_id = $args['course_id'];
205
+ $user_review = learn_press_get_user_rate( $course_id, $user_id );//learn_press_get_user_review_title( $course_id, $user_id );
206
+ if ( !$user_review ) {
207
+ $review_title = $_POST['review_title'];
208
+ $review_content = $_POST['review_content'];
209
+ $review_rate = $_POST['review_rate'];
210
+ learn_press_save_course_review( $course_id, $review_rate, $review_title, $review_content );
211
+ }
212
+ global $post;
213
+ $post = get_post( $course_id );
214
+ setup_postdata( $post );
215
+ learn_press_course_review_template( 'course-rate.php' );
216
+ die();
217
+ }
218
+
219
+ add_action( 'wp_ajax_learn_press_add_course_review', 'learn_press_add_course_review' );
220
+ */
221
+ /**
222
+ * Print rate for course
223
+ */
224
+
225
+
226
+
init.php DELETED
@@ -1,249 +0,0 @@
1
- <?php
2
- /**
3
- * Created by PhpStorm.
4
- * User: foobla
5
- * Date: 4/7/2015
6
- * Time: 4:38 PM
7
- */
8
-
9
- if ( !defined( 'ABSPATH' ) ) {
10
- exit; // Exit if accessed directly
11
- }
12
- define( 'COURSE_REVIEWS_PER_PAGE', 5 );
13
- define( 'COURSE_REVIEW_TMPL', LPR_COURSE_REVIEW_PATH . '/template/' );
14
- define( 'COURSE_REVIEW_THEME_TMPL', learn_press_template_path() . '/addons/course-review/' );
15
- /**
16
- * @param int $course_id
17
- * @param int $paged
18
- * @param int $per_page
19
- * @return mixed|void
20
- */
21
- function learn_press_get_course_review( $course_id, $paged = 1, $per_page = COURSE_REVIEWS_PER_PAGE ) {
22
-
23
- if( empty( $GLOBALS['course_reviews'] ) ) $GLOBALS['course_reviews'] = array();
24
-
25
- if( ! empty( $GLOBALS['course_reviews'][ $course_id ] ) ) return $GLOBALS['course_reviews'][ $course_id ];
26
- global $wpdb;
27
- $per_page = apply_filters( 'learn_press_course_reviews_per_page', $per_page );
28
- $start = ( $paged - 1 ) * $per_page;
29
- $start = max( $start, 0 );
30
- $per_page = max( $per_page, 1 );
31
-
32
- $results = array(
33
- 'reviews' => array(),
34
- 'paged' => $paged,
35
- 'total' => 0,
36
- 'per_page' => $per_page
37
- );
38
-
39
- $query = $wpdb->prepare("
40
- SELECT SQL_CALC_FOUND_ROWS u.*, cm1.meta_value as title, c.comment_content as content, cm2.meta_value as rate
41
- FROM {$wpdb->posts} p
42
- INNER JOIN {$wpdb->comments} c ON p.ID = c.comment_post_ID
43
- INNER JOIN {$wpdb->users} u ON u.ID = c.user_id
44
- INNER JOIN {$wpdb->commentmeta} cm1 ON cm1.comment_id = c.comment_ID AND cm1.meta_key=%s
45
- INNER JOIN {$wpdb->commentmeta} cm2 ON cm2.comment_id = c.comment_ID AND cm2.meta_key=%s
46
- WHERE p.ID=%d AND c.comment_type=%s
47
- ORDER BY c.comment_date DESC
48
- LIMIT %d, %d
49
- ", '_lpr_review_title', '_lpr_rating', $course_id, 'review', $start, $per_page );
50
- $course_review = $wpdb->get_results( $query );
51
- if( $course_review ) {
52
- $results['reviews'] = $course_review;
53
- $results['total'] = $wpdb->get_var( "SELECT FOUND_ROWS();");
54
- if( $results['total'] <= $start + $per_page ){
55
- $results['finish'] = true;
56
- }
57
- }
58
- $GLOBALS['course_reviews'][ $course_id ] = apply_filters( 'learn_press_get_course_review', $results );
59
- return $GLOBALS['course_reviews'][ $course_id ];
60
- }
61
-
62
- /**
63
- * @param $course_id
64
- *
65
- * @return mixed|void
66
- */
67
- function learn_press_get_course_rate( $course_id ) {
68
- global $wpdb;
69
- $query = $wpdb->prepare("
70
- SELECT avg( cm1.meta_value ) as rated
71
- FROM {$wpdb->posts} p
72
- INNER JOIN {$wpdb->comments} c ON p.ID = c.comment_post_ID
73
- INNER JOIN {$wpdb->commentmeta} cm1 ON cm1.comment_id = c.comment_ID AND cm1.meta_key='_lpr_rating'
74
- WHERE p.ID=%d
75
- AND c.comment_type=%s
76
- ", $course_id, 'review');
77
-
78
- $rated = $wpdb->get_var( $query );
79
- return apply_filters( 'learn_press_get_course_rate', $rated );
80
- }
81
-
82
- function learn_press_get_course_rate_total( $course_id ) {
83
-
84
- $course_review = learn_press_get_course_review( $course_id );
85
-
86
- return $course_review['total'];
87
-
88
- $course_review = get_post_meta( $course_id, '_lpr_course_review', true );
89
- $total = 0;
90
- $rate = 0;
91
- if( $course_review ) {
92
- for( $i = 1; $i<6; $i++ ) {
93
- $total += $course_review['rate_value'][$i];
94
- }
95
- }
96
- return apply_filters( 'learn_press_get_course_rate', $total );
97
- }
98
-
99
- /**
100
- * @param $course_id
101
- * @param $user_id
102
- *
103
- * @return mixed|void
104
- */
105
- function learn_press_get_user_review_title( $course_id, $user_id ) {
106
- $course_review = get_post_meta( $course_id, '_lpr_course_review', true );
107
- if( $course_review && array_key_exists($user_id, $course_review['review_title'])) {
108
- return apply_filters( 'learn_press_get_user_review', $course_review['review_title'][$user_id] );
109
- }
110
- return false;
111
- }
112
-
113
- /**
114
- * @param $course_id
115
- * @param $user_id
116
- *
117
- * @return mixed|void
118
- */
119
- function learn_press_get_user_rate( $course_id = null, $user_id = null ){
120
- $course_id = learn_press_get_course_id( $course_id );
121
- if( ! $user_id ) $user_id = get_current_user_id();
122
- if( ! $course_id || ! $user_id ) return false;
123
-
124
- $comment = false;
125
- global $wpdb;
126
- $query = $wpdb->prepare("
127
- SELECT *
128
- FROM {$wpdb->posts} p
129
- INNER JOIN {$wpdb->comments} c ON c.comment_post_ID = p.ID
130
- WHERE c.comment_post_ID = %d AND user_id = %d
131
- ", $course_id, $user_id);
132
- $comments = $wpdb->get_results( $query );
133
- if( $comments ){
134
- $comment = $comments[0];
135
- $comment->comment_title = get_comment_meta( $comment->comment_ID, '_lpr_review_title', true );
136
- $comment->rating = get_comment_meta( $comment->comment_ID, '_lpr_rating', true );
137
- }
138
- return $comment;
139
- }
140
-
141
- /**
142
- * @param int $course_id
143
- * @param int $review_rate
144
- * @param string $review_title
145
- * @param string $review_content
146
- */
147
- function learn_press_save_course_review( $course_id, $review_rate, $review_title, $review_content) {
148
- $user = wp_get_current_user();
149
- $course_review = get_post_meta( $course_id, '_lpr_course_review', true );
150
- if( !isset($course_review) || !is_array($course_review) ) {
151
- $course_review = array();
152
- $course_review['rate_value'] = array( 0, 0, 0, 0, 0, 0, 0 );
153
-
154
- $course_review['user'] = array();
155
- $course_review['rate'] = array();
156
- $course_review['review_title'] = array();
157
- $course_review['review_content'] = array();
158
- }
159
- $comment_id = wp_new_comment(
160
- array(
161
- 'comment_post_ID' => $course_id,
162
- 'comment_author' => 'LearnPress',
163
- 'comment_author_email' => $user->user_email,
164
- 'comment_author_url' => '',
165
- 'comment_content' => $review_content,
166
- 'comment_type' => '',
167
- 'comment_parent' => 0,
168
- 'user_id' => $user->ID,
169
- 'comment_approved' => 1,
170
- 'comment_type' => 'review' // let filter to not display it as comments
171
- )
172
- );
173
- if( $comment_id ){
174
- add_comment_meta( $comment_id, '_lpr_rating', $review_rate );
175
- add_comment_meta( $comment_id, '_lpr_review_title', $review_title );
176
- }
177
-
178
- return $comment_id;
179
- $course_review['rate_value'][$review_rate]++;
180
- array_push($course_review['user'], $user_id);
181
- $course_review['rate'][$user_id] = $review_rate;
182
- $course_review['review_title'][$user_id] = $review_title;
183
- $course_review['review_content'][$user_id] = $review_content;
184
- update_post_meta( $course_id, '_lpr_course_review', $course_review );
185
- }
186
-
187
- function learn_press_course_review_template( $name, $args = null ){
188
- learn_press_get_template( $name, $args, COURSE_REVIEW_THEME_TMPL, COURSE_REVIEW_TMPL );
189
- }
190
- function learn_press_add_course_review() {
191
- $user_id = get_current_user_id();
192
- $course_id = $_POST['course_id'];
193
- $user_review = learn_press_get_user_rate( $course_id, $user_id );//learn_press_get_user_review_title( $course_id, $user_id );
194
- if( ! $user_review ) {
195
- $review_title = $_POST['review_title'];
196
- $review_content = $_POST['review_content'];
197
- $review_rate = $_POST['review_rate'];
198
- learn_press_save_course_review( $course_id, $review_rate, $review_title, $review_content );
199
- }
200
- global $post;
201
- $post = get_post( $course_id );
202
- setup_postdata($post);
203
- //learn_press_get_template('course-rate.php', null, LPR_COURSE_REVIEW_PATH . '/template' );
204
- learn_press_course_review_template( 'course-rate.php' );
205
- die();
206
- }
207
- add_action( 'wp_ajax_learn_press_add_course_review', 'learn_press_add_course_review' );
208
-
209
- /**
210
- * Print rate for course
211
- */
212
- function learn_press_print_rate( ) {
213
- learn_press_course_review_template( 'course-rate.php' );
214
- }
215
- add_action('learn_press_after_the_title', 'learn_press_print_rate', 10 , 1);
216
-
217
-
218
- function learn_press_print_review() {
219
- //learn_press_get_template('addons/course-review/course-review.php');
220
- learn_press_course_review_template( 'course-review.php' );
221
- }
222
- add_action( 'learn_press_course_landing_content', 'learn_press_print_review', 80 );
223
-
224
- function learn_press_add_review_button( ) {
225
- if( ! learn_press_get_user_rate() ) {
226
- ///learn_press_get_template('addons/course-review/add-review.php');
227
- learn_press_course_review_template( 'add-review.php' );
228
- }
229
- }
230
- add_action('learn_press_course_learning_content', 'learn_press_add_review_button', 5);
231
-
232
- function learn_press_review_assets(){
233
- wp_enqueue_script( 'block-ui', LPR_PLUGIN_URL . '/assets/js/jquery.block-ui.js', array('jquery'), '', true );
234
- wp_enqueue_script( 'lpr-print-rate-js', untrailingslashit(plugins_url('/', __FILE__)) . '/assets/course-review.js', array('jquery'), '', true );
235
- wp_enqueue_style( 'lpr-print-rate-css', untrailingslashit(plugins_url('/', __FILE__)) . '/assets/course-review.css' );
236
- wp_enqueue_style( 'dashicons' );
237
- }
238
- add_action( 'wp_enqueue_scripts', 'learn_press_review_assets' );
239
-
240
- function learn_press_course_review_init(){
241
- $paged = ! empty( $_REQUEST['paged'] ) ? intval( $_REQUEST['paged'] ) : 1;
242
- learn_press_get_course_review( get_the_ID(), $paged );
243
- }
244
- add_action( 'wp', 'learn_press_course_review_init' );
245
-
246
- function learn_press_exclude_rating( $query ){
247
- $query->query_vars['type__not_in'] = 'review';
248
- }
249
- add_action( 'parse_comment_query', 'learn_press_exclude_rating' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
lang/default.pot DELETED
@@ -1,71 +0,0 @@
1
- # SOME DESCRIPTIVE TITLE.
2
- # Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
3
- # This file is distributed under the same license as the PACKAGE package.
4
- # FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
5
- #
6
- #, fuzzy
7
- msgid ""
8
- msgstr ""
9
- "Project-Id-Version: PACKAGE VERSION\n"
10
- "Report-Msgid-Bugs-To: \n"
11
- "POT-Creation-Date: 2015-08-01 16:04+0700\n"
12
- "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
13
- "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
14
- "Language-Team: LANGUAGE <LL@li.org>\n"
15
- "Language: \n"
16
- "MIME-Version: 1.0\n"
17
- "Content-Type: text/plain; charset=CHARSET\n"
18
- "Content-Transfer-Encoding: 8bit\n"
19
-
20
- #: template/add-review.php:2
21
- msgid "Write a Review"
22
- msgstr ""
23
-
24
- #: template/add-review.php:6
25
- msgid "Write a review"
26
- msgstr ""
27
-
28
- #: template/add-review.php:12
29
- msgid "Title"
30
- msgstr ""
31
-
32
- #: template/add-review.php:16
33
- msgid "Content"
34
- msgstr ""
35
-
36
- #: template/add-review.php:20
37
- msgid "Rating"
38
- msgstr ""
39
-
40
- #: template/add-review.php:29
41
- msgid "Please wait..."
42
- msgstr ""
43
-
44
- #: template/add-review.php:30
45
- msgid "Add review"
46
- msgstr ""
47
-
48
- #: template/add-review.php:31
49
- msgid "Cancel"
50
- msgstr ""
51
-
52
- #: template/course-review.php:13
53
- msgid "Reviews"
54
- msgstr ""
55
-
56
- #: template/course-review.php:14
57
- #, php-format
58
- msgid "Average rate: <span>%.1f</span>"
59
- msgstr ""
60
-
61
- #: template/course-review.php:22
62
- msgid "Loading..."
63
- msgstr ""
64
-
65
- #: template/course-review.php:25
66
- msgid "No review to load"
67
- msgstr ""
68
-
69
- #: template/course-review.php:28
70
- msgid "Load More"
71
- msgstr ""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
lang/default.temp DELETED
@@ -1,71 +0,0 @@
1
- # SOME DESCRIPTIVE TITLE.
2
- # Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
3
- # This file is distributed under the same license as the PACKAGE package.
4
- # FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
5
- #
6
- #, fuzzy
7
- msgid ""
8
- msgstr ""
9
- "Project-Id-Version: PACKAGE VERSION\n"
10
- "Report-Msgid-Bugs-To: \n"
11
- "POT-Creation-Date: 2015-07-25 11:42+0700\n"
12
- "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
13
- "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
14
- "Language-Team: LANGUAGE <LL@li.org>\n"
15
- "Language: \n"
16
- "MIME-Version: 1.0\n"
17
- "Content-Type: text/plain; charset=CHARSET\n"
18
- "Content-Transfer-Encoding: 8bit\n"
19
-
20
- #: template/add-review.php:2
21
- msgid "Write a Review"
22
- msgstr ""
23
-
24
- #: template/add-review.php:6
25
- msgid "Write a review"
26
- msgstr ""
27
-
28
- #: template/add-review.php:12
29
- msgid "Title"
30
- msgstr ""
31
-
32
- #: template/add-review.php:16
33
- msgid "Content"
34
- msgstr ""
35
-
36
- #: template/add-review.php:20
37
- msgid "Rating"
38
- msgstr ""
39
-
40
- #: template/add-review.php:29
41
- msgid "Please wait..."
42
- msgstr ""
43
-
44
- #: template/add-review.php:30
45
- msgid "Add review"
46
- msgstr ""
47
-
48
- #: template/add-review.php:31
49
- msgid "Cancel"
50
- msgstr ""
51
-
52
- #: template/course-review.php:13
53
- msgid "Reviews"
54
- msgstr ""
55
-
56
- #: template/course-review.php:14
57
- #, php-format
58
- msgid "Average rate: <span>%.1f</span>"
59
- msgstr ""
60
-
61
- #: template/course-review.php:22
62
- msgid "Loading..."
63
- msgstr ""
64
-
65
- #: template/course-review.php:25
66
- msgid "No review to load"
67
- msgstr ""
68
-
69
- #: template/course-review.php:28
70
- msgid "Load More"
71
- msgstr ""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
languages/learnpress-course-review-vi.mo ADDED
Binary file
languages/learnpress-course-review-vi.po ADDED
@@ -0,0 +1,99 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ msgid ""
2
+ msgstr ""
3
+ "Project-Id-Version: PACKAGE VERSION\n"
4
+ "Report-Msgid-Bugs-To: \n"
5
+ "POT-Creation-Date: 2016-03-18 16:57+0700\n"
6
+ "PO-Revision-Date: Fri Mar 18 2016 16:58:45 GMT+0700 (SE Asia Standard Time)\n"
7
+ "Last-Translator: Nguyễn Ngọc Tú <tunnhn@gmail.com>\n"
8
+ "Language-Team: LANGUAGE <LL@li.org>\n"
9
+ "Language: Vietnamese\n"
10
+ "Plural-Forms: nplurals=1; plural=0\n"
11
+ "MIME-Version: 1.0\n"
12
+ "Content-Type: text/plain; charset=CHARSET\n"
13
+ "Content-Transfer-Encoding: 8bit\n"
14
+ "X-Poedit-SourceCharset: UTF-8\n"
15
+ "X-Poedit-Basepath: .\n"
16
+ "X-Poedit-SearchPath-0: ..\n"
17
+ "X-Poedit-KeywordsList: _:1;gettext:1;dgettext:2;ngettext:1,2;dngettext:2,3;"
18
+ "__:1;_e:1;_c:1;_n:1,2;_n_noop:1,2;_nc:1,2;__ngettext:1,2;__ngettext_noop:1,2;"
19
+ "_x:1,2c;_ex:1,2c;_nx:1,2,4c;_nx_noop:1,2,3c;_n_js:1,2;_nx_js:1,2,3c;"
20
+ "esc_attr__:1;esc_html__:1;esc_attr_e:1;esc_html_e:1;esc_attr_x:1,2c;"
21
+ "esc_html_x:1,2c;comments_number_link:2,3;t:1;st:1;trans:1;transChoice:1,2\n"
22
+ "X-Loco-Target-Locale: vi_VN\n"
23
+ "X-Generator: Loco - https://localise.biz/"
24
+
25
+ #: learnpress-course-review.php:109
26
+ msgid "Error"
27
+ msgstr ""
28
+
29
+ #: learnpress-course-review.php:114
30
+ msgid "Invalid course"
31
+ msgstr ""
32
+
33
+ #: templates/course-rate.php:13
34
+ #, php-format
35
+ msgid "%d rating"
36
+ msgid_plural "%d ratings"
37
+ msgstr[0] ""
38
+ msgstr[1] ""
39
+
40
+ #: templates/course-review.php:12
41
+ msgid "Reviews"
42
+ msgstr "Đánh giá"
43
+
44
+ #: templates/course-review.php:13
45
+ #, php-format
46
+ msgid "Average rate: <span>%.1f</span>"
47
+ msgstr ""
48
+
49
+ #: templates/course-review.php:21
50
+ msgid "Loading..."
51
+ msgstr ""
52
+
53
+ #: templates/course-review.php:24
54
+ msgid "No review to load"
55
+ msgstr ""
56
+
57
+ #: templates/course-review.php:27
58
+ msgid "Load More"
59
+ msgstr ""
60
+
61
+ #: templates/review-form.php:12 templates/review-form.php:18
62
+ msgid "Write a review"
63
+ msgstr ""
64
+
65
+ #: templates/review-form.php:24
66
+ msgid "Title"
67
+ msgstr ""
68
+
69
+ #: templates/review-form.php:28
70
+ msgid "Content"
71
+ msgstr ""
72
+
73
+ #: templates/review-form.php:32
74
+ msgid "Rating"
75
+ msgstr ""
76
+
77
+ #: templates/review-form.php:42
78
+ msgid "Add review"
79
+ msgstr ""
80
+
81
+ #: templates/review-form.php:43
82
+ msgid "Cancel"
83
+ msgstr ""
84
+
85
+ #: learnpress-course-review.php:80
86
+ msgid "Please enter the review title"
87
+ msgstr "Nhập vào tiêu đề"
88
+
89
+ #: learnpress-course-review.php:81
90
+ msgid "Please enter the review content"
91
+ msgstr "Nhập vào nội dung"
92
+
93
+ #: learnpress-course-review.php:82
94
+ msgid "Please select your rating"
95
+ msgstr "Chọn điểm"
96
+
97
+ #: templates/review-form.php:44
98
+ msgid "Please wait..."
99
+ msgstr "Chờ trong giây lát..."
languages/learnpress-course-review.pot ADDED
@@ -0,0 +1,95 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # SOME DESCRIPTIVE TITLE.
2
+ # Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
3
+ # This file is distributed under the same license as the PACKAGE package.
4
+ # FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
5
+ #
6
+ #, fuzzy
7
+ msgid ""
8
+ msgstr ""
9
+ "Project-Id-Version: PACKAGE VERSION\n"
10
+ "Report-Msgid-Bugs-To: \n"
11
+ "POT-Creation-Date: 2016-03-18 16:57+0700\n"
12
+ "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
13
+ "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
14
+ "Language-Team: LANGUAGE <LL@li.org>\n"
15
+ "Language: \n"
16
+ "MIME-Version: 1.0\n"
17
+ "Content-Type: text/plain; charset=CHARSET\n"
18
+ "Content-Transfer-Encoding: 8bit\n"
19
+ "Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"
20
+
21
+ #: learnpress-course-review.php:80
22
+ msgid "Please enter the review title"
23
+ msgstr ""
24
+
25
+ #: learnpress-course-review.php:81
26
+ msgid "Please enter the review content"
27
+ msgstr ""
28
+
29
+ #: learnpress-course-review.php:82
30
+ msgid "Please select your rating"
31
+ msgstr ""
32
+
33
+ #: learnpress-course-review.php:109
34
+ msgid "Error"
35
+ msgstr ""
36
+
37
+ #: learnpress-course-review.php:114
38
+ msgid "Invalid course"
39
+ msgstr ""
40
+
41
+ #: templates/course-rate.php:13
42
+ #, php-format
43
+ msgid "%d rating"
44
+ msgid_plural "%d ratings"
45
+ msgstr[0] ""
46
+ msgstr[1] ""
47
+
48
+ #: templates/course-review.php:12
49
+ msgid "Reviews"
50
+ msgstr ""
51
+
52
+ #: templates/course-review.php:13
53
+ #, php-format
54
+ msgid "Average rate: <span>%.1f</span>"
55
+ msgstr ""
56
+
57
+ #: templates/course-review.php:21
58
+ msgid "Loading..."
59
+ msgstr ""
60
+
61
+ #: templates/course-review.php:24
62
+ msgid "No review to load"
63
+ msgstr ""
64
+
65
+ #: templates/course-review.php:27
66
+ msgid "Load More"
67
+ msgstr ""
68
+
69
+ #: templates/review-form.php:12 templates/review-form.php:18
70
+ msgid "Write a review"
71
+ msgstr ""
72
+
73
+ #: templates/review-form.php:24
74
+ msgid "Title"
75
+ msgstr ""
76
+
77
+ #: templates/review-form.php:28
78
+ msgid "Content"
79
+ msgstr ""
80
+
81
+ #: templates/review-form.php:32
82
+ msgid "Rating"
83
+ msgstr ""
84
+
85
+ #: templates/review-form.php:42
86
+ msgid "Add review"
87
+ msgstr ""
88
+
89
+ #: templates/review-form.php:43
90
+ msgid "Cancel"
91
+ msgstr ""
92
+
93
+ #: templates/review-form.php:44
94
+ msgid "Please wait..."
95
+ msgstr ""
languages/learnpress-course-review.temp ADDED
@@ -0,0 +1,99 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # SOME DESCRIPTIVE TITLE.
2
+ # Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
3
+ # This file is distributed under the same license as the PACKAGE package.
4
+ # FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
5
+ #
6
+ #, fuzzy
7
+ msgid ""
8
+ msgstr ""
9
+ "Project-Id-Version: PACKAGE VERSION\n"
10
+ "Report-Msgid-Bugs-To: \n"
11
+ "POT-Creation-Date: 2016-03-18 16:51+0700\n"
12
+ "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
13
+ "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
14
+ "Language-Team: LANGUAGE <LL@li.org>\n"
15
+ "Language: \n"
16
+ "MIME-Version: 1.0\n"
17
+ "Content-Type: text/plain; charset=CHARSET\n"
18
+ "Content-Transfer-Encoding: 8bit\n"
19
+ "Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"
20
+
21
+ #: learnpress-course-review.php:80
22
+ msgid "Please enter the review title"
23
+ msgstr ""
24
+
25
+ #: learnpress-course-review.php:81
26
+ msgid "Please enter the review content"
27
+ msgstr ""
28
+
29
+ #: learnpress-course-review.php:82
30
+ msgid "Please select your rating"
31
+ msgstr ""
32
+
33
+ #: learnpress-course-review.php:109
34
+ msgid "Error"
35
+ msgstr ""
36
+
37
+ #: learnpress-course-review.php:114
38
+ msgid "Invalid course"
39
+ msgstr ""
40
+
41
+ #: templates/course-rate.php:13
42
+ #, php-format
43
+ msgid "%d rating"
44
+ msgid_plural "%d ratings"
45
+ msgstr[0] ""
46
+ msgstr[1] ""
47
+
48
+ #: templates/course-review.php:12
49
+ msgid "Reviews"
50
+ msgstr ""
51
+
52
+ #: templates/course-review.php:13
53
+ #, php-format
54
+ msgid "Average rate: <span>%.1f</span>"
55
+ msgstr ""
56
+
57
+ #: templates/course-review.php:21
58
+ msgid "Loading..."
59
+ msgstr ""
60
+
61
+ #: templates/course-review.php:24
62
+ msgid "No review to load"
63
+ msgstr ""
64
+
65
+ #: templates/course-review.php:27
66
+ msgid "Load More"
67
+ msgstr ""
68
+
69
+ #: templates/review-form.php:12
70
+ msgid "Write a Review"
71
+ msgstr ""
72
+
73
+ #: templates/review-form.php:18
74
+ msgid "Write a review"
75
+ msgstr ""
76
+
77
+ #: templates/review-form.php:24
78
+ msgid "Title"
79
+ msgstr ""
80
+
81
+ #: templates/review-form.php:28
82
+ msgid "Content"
83
+ msgstr ""
84
+
85
+ #: templates/review-form.php:32
86
+ msgid "Rating"
87
+ msgstr ""
88
+
89
+ #: templates/review-form.php:42
90
+ msgid "Add review"
91
+ msgstr ""
92
+
93
+ #: templates/review-form.php:43
94
+ msgid "Cancel"
95
+ msgstr ""
96
+
97
+ #: templates/review-form.php:44
98
+ msgid "Please wait..."
99
+ msgstr ""
learnpress-course-review.php CHANGED
@@ -3,36 +3,155 @@
3
  Plugin Name: LearnPress Course Review
4
  Plugin URI: http://thimpress.com/learnpress
5
  Description: Adding review for course
6
- Author: thimpress
7
- Version: 0.9.1
8
  Author URI: http://thimpress.com
9
  Tags: learnpress
 
 
10
  */
11
  if ( !defined( 'ABSPATH' ) ) {
12
- exit; // Exit if accessed directly
13
  }
14
 
15
- define( 'LPR_COURSE_REVIEW_PATH', dirname( __FILE__ ) );
 
 
 
16
 
17
  /**
18
- * Register course-review course addon
19
  */
20
- function learn_press_register_course_review() {
21
- require_once( LPR_COURSE_REVIEW_PATH . '/init.php' );
22
- }
23
- add_action( 'learn_press_register_add_ons', 'learn_press_register_course_review' );
24
-
25
- add_action('plugins_loaded','learnpress_course_review_translations');
26
- function learnpress_course_review_translations(){
27
- $textdomain = 'learnpress_course_review';
28
- $locale = apply_filters("plugin_locale", get_locale(), $textdomain);
29
- $lang_dir = dirname( __FILE__ ) . '/lang/';
30
- $mofile = sprintf( '%s.mo', $locale );
31
- $mofile_local = $lang_dir . $mofile;
32
- $mofile_global = WP_LANG_DIR . '/plugins/' . $mofile;
33
- if ( file_exists( $mofile_global ) ) {
34
- load_textdomain( $textdomain, $mofile_global );
35
- } else {
36
- load_textdomain( $textdomain, $mofile_local );
37
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
  }
 
 
 
 
3
  Plugin Name: LearnPress Course Review
4
  Plugin URI: http://thimpress.com/learnpress
5
  Description: Adding review for course
6
+ Author: ThimPress
7
+ Version: 1.0
8
  Author URI: http://thimpress.com
9
  Tags: learnpress
10
+ Text Domain: learnpress-course-review
11
+ Domain Path: /languages/
12
  */
13
  if ( !defined( 'ABSPATH' ) ) {
14
+ exit; // Exit if accessed directly
15
  }
16
 
17
+ define( 'LP_ADDON_COURSE_REVIEW_FILE', __FILE__ );
18
+ define( 'LP_ADDON_COURSE_REVIEW_PATH', dirname( __FILE__ ) );
19
+ define( 'LP_ADDON_COURSE_REVIEW_PER_PAGE', 5 );
20
+
21
 
22
  /**
23
+ * Class LP_Addon_Course_Review
24
  */
25
+ class LP_Addon_Course_Review {
26
+ /**
27
+ * @var null
28
+ */
29
+ protected static $_instance = null;
30
+
31
+ /**
32
+ * LP_Addon_Course_Review constructor.
33
+ */
34
+ function __construct() {
35
+ if ( !function_exists( 'learn_press_load_plugin_text_domain' ) ) {
36
+ return;
37
+ }
38
+ if ( self::$_instance || defined( 'LP_ADDON_COURSE_REVIEW_TMPL' ) ) {
39
+ return;
40
+ }
41
+
42
+ define( 'LP_ADDON_COURSE_REVIEW_TMPL', LP_ADDON_COURSE_REVIEW_PATH . '/templates/' );
43
+ define( 'LP_ADDON_COURSE_REVIEW_THEME_TMPL', learn_press_template_path() . '/addons/course-review/' );
44
+ define( 'LP_ADDON_COURSE_REVIEW_URL', untrailingslashit( plugins_url( '/', __FILE__ ) ) );
45
+
46
+ add_action( 'learn_press_after_the_title', array( $this, 'print_rate' ), 10, 1 );
47
+ add_action( 'learn_press_content_landing_summary', array( $this, 'print_review' ), 80 );
48
+ add_action( 'learn_press_content_learning_summary', array( $this, 'print_review' ), 80 );
49
+ add_action( 'learn_press_content_learning_summary', array( $this, 'add_review_button' ), 5 );
50
+ add_action( 'wp_enqueue_scripts', array( $this, 'review_assets' ) );
51
+ add_action( 'wp', array( $this, 'course_review_init' ) );
52
+ add_action( 'parse_comment_query', array( $this, 'exclude_rating' ) );
53
+
54
+ add_action( 'init', array( $this, 'load_text_domain' ) );
55
+
56
+
57
+ require_once LP_ADDON_COURSE_REVIEW_PATH . '/incs/review-functions.php';
58
+
59
+ LP_Request_Handler::register_ajax( 'add_review', array( $this, 'add_review' ) );
60
+
61
+ self::$_instance = $this;
62
+ }
63
+
64
+ function print_rate() {
65
+ learn_press_course_review_template( 'course-rate.php' );
66
+ }
67
+
68
+ function print_review() {
69
+ learn_press_course_review_template( 'course-review.php' );
70
+ }
71
+
72
+ function add_review_button() {
73
+ if ( !learn_press_get_user_rate( get_the_ID() ) ) {
74
+ learn_press_course_review_template( 'review-form.php' );
75
+ }
76
+ }
77
+
78
+ function review_assets() {
79
+ if ( learn_press_is_course() ) {
80
+ wp_enqueue_script( 'course-review', LP_ADDON_COURSE_REVIEW_URL . '/assets/course-review.js', array( 'jquery' ), '', true );
81
+ wp_enqueue_style( 'course-review', LP_ADDON_COURSE_REVIEW_URL . '/assets/course-review.css' );
82
+ wp_enqueue_style( 'dashicons' );
83
+ wp_localize_script( 'course-review', 'learn_press_course_review',
84
+ array(
85
+ 'localize' => array(
86
+ 'empty_title' => __( 'Please enter the review title', 'learnpress-course-review' ),
87
+ 'empty_content' => __( 'Please enter the review content', 'learnpress-course-review' ),
88
+ 'empty_rating' => __( 'Please select your rating', 'learnpress-course-review' )
89
+ )
90
+ )
91
+ );
92
+ }
93
+ }
94
+
95
+ function course_review_init() {
96
+ $paged = !empty( $_REQUEST['paged'] ) ? intval( $_REQUEST['paged'] ) : 1;
97
+ learn_press_get_course_review( get_the_ID(), $paged );
98
+ }
99
+
100
+ function exclude_rating( $query ) {
101
+ $query->query_vars['type__not_in'] = 'review';
102
+ }
103
+
104
+
105
+ function add_review() {
106
+ $response = array( 'result' => 'success' );
107
+ $nonce = !empty( $_REQUEST['review_nonce'] ) ? $_REQUEST['review_nonce'] : '';
108
+ $id = !empty( $_REQUEST['id'] ) ? absint( $_REQUEST['id'] ) : 0;
109
+ $rate = !empty( $_REQUEST['rating'] ) ? $_REQUEST['rating'] : '0';
110
+ $title = !empty( $_REQUEST['review_title'] ) ? $_REQUEST['review_title'] : '';
111
+ $content = !empty( $_REQUEST['review_content'] ) ? $_REQUEST['review_content'] : '';
112
+
113
+ if ( wp_verify_nonce( $nonce, 'learn_press_course_review_' . $id ) ) {
114
+ $response['result'] = 'fail';
115
+ $response['message'] = __( 'Error', 'learnpress-course-review' );
116
+ }
117
+
118
+ if ( get_post_type( $id ) != 'lp_course' ) {
119
+ $response['result'] = 'fail';
120
+ $response['message'] = __( 'Invalid course', 'learnpress-course-review' );
121
+ }
122
+
123
+ $return = learn_press_add_course_review(
124
+ array(
125
+ 'user_id' => get_current_user_id(),
126
+ 'course_id' => $id,
127
+ 'rate' => $rate,
128
+ 'title' => $title,
129
+ 'content' => $content
130
+ )
131
+ );
132
+ $response['comment'] = $return;
133
+ learn_press_send_json( $response );
134
+ }
135
+
136
+ /**
137
+ * Return unique instance of LP_Addon_Course_Review object
138
+ */
139
+ static function instance() {
140
+ if ( !self::$_instance ) {
141
+ self::$_instance = new self();
142
+
143
+ }
144
+ return self::$_instance;
145
+ }
146
+
147
+ /**
148
+ * Load text domain
149
+ */
150
+ static function load_text_domain() {
151
+ if( function_exists('learn_press_load_plugin_text_domain')){ learn_press_load_plugin_text_domain(LP_ADDON_COURSE_REVIEW_PATH, true ); }
152
+ }
153
  }
154
+
155
+ add_action( 'learn_press_ready', array( 'LP_Addon_Course_Review', 'instance' ) );
156
+
157
+
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link:
4
  Tags: lms, elearning, e-learning, learning management system, education, course, courses, quiz, quizzes, questions, training, guru, sell courses
5
  Requires at least: 3.8
6
  Tested up to: 4.2.2
7
- Stable tag: 0.9.1
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -56,6 +56,9 @@ Check out <a href="http://docs.thimpress.com/learnpress" target="_blank">LearnPr
56
 
57
  == Changelog ==
58
 
 
 
 
59
  = 0.9.1 =
60
  - Updated languages file
61
  - Fixed PHP5 version 5.3.x error
4
  Tags: lms, elearning, e-learning, learning management system, education, course, courses, quiz, quizzes, questions, training, guru, sell courses
5
  Requires at least: 3.8
6
  Tested up to: 4.2.2
7
+ Stable tag: 1.0
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
56
 
57
  == Changelog ==
58
 
59
+ = 1.0 =
60
+ + Compatible with LearnPress version 1.0
61
+
62
  = 0.9.1 =
63
  - Updated languages file
64
  - Fixed PHP5 version 5.3.x error
template/add-review.php DELETED
@@ -1,35 +0,0 @@
1
- <?php learn_press_prevent_access_directly(); ?>
2
- <button class="write-a-review"><?php _e( 'Write a Review', 'learnpress_course_review' );?></button>
3
- <div class="review-wrapper" id="review">
4
- <div class="review-content" id="reviewTarget">
5
- <h3>
6
- <?php _e( 'Write a review', 'learnpress_course_review' );?>
7
- <a href="" class="close dashicons dashicons-no-alt"></a>
8
- </h3>
9
- <ul class="review-fields">
10
- <?php do_action( 'learn_press_before_review_fields' );?>
11
- <li>
12
- <label><?php _e( 'Title', 'learnpress_course_review' );?> <span class="required">*</span></label>
13
- <input type="text" name="review-title" />
14
- </li>
15
- <li>
16
- <label><?php _e( 'Content', 'learnpress_course_review' );?><span class="required">*</span></label>
17
- <textarea name="review-content"></textarea>
18
- </li>
19
- <li>
20
- <label><?php _e( 'Rating', 'learnpress_course_review' );?><span class="required">*</span></label>
21
- <ul class="review-stars">
22
- <?php for( $i = 1; $i <= 5; $i ++ ){?>
23
- <li class="review-title" title="<?php echo $i;?>"><span class="dashicons dashicons-star-empty"></span> </li>
24
- <?php }?>
25
- </ul>
26
- </li>
27
- <?php do_action( 'learn_press_after_review_fields' );?>
28
- <li class="review-actions">
29
- <span class="submitting"><?php _e( 'Please wait...', 'learnpress_course_review' );?></span>
30
- <button type="button" class="submit-review" data-id="<?php the_ID();?>"><?php _e( 'Add review', 'learnpress_course_review' );?></button>
31
- <button type="button" class="cancel"><?php _e( 'Cancel', 'learnpress_course_review' );?></button>
32
- </li>
33
- </ul>
34
- </div>
35
- </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
template/course-review.php DELETED
@@ -1,32 +0,0 @@
1
- <?php
2
-
3
- if ( !defined( 'ABSPATH' ) ) {
4
- exit; // Exit if accessed directly
5
- }
6
- $course_id = get_the_ID();
7
- $course_review = learn_press_get_course_review( $course_id );
8
- if( $course_review['total'] ) {
9
- $course_rate = learn_press_get_course_rate( $course_id );
10
- $reviews = $course_review['reviews'];
11
- ?>
12
- <div id="course-reviews">
13
- <h3 class="course-review-head"><?php _e( 'Reviews', 'learnpress_course_review' );?></h3>
14
- <p class="course-average-rate"><?php printf( __( 'Average rate: <span>%.1f</span>', 'learnpress_course_review' ), $course_rate );?></p>
15
- <ul class="course-reviews-list">
16
- <?php foreach( $reviews as $review ) {?>
17
- <?php
18
- learn_press_course_review_template( 'loop-review.php', array( 'review' => $review ) );
19
- ?>
20
- <?php } ?>
21
- <?php if( empty( $course_review['finish'] ) ){?>
22
- <li class="loading"><?php _e( 'Loading...', 'learnpress_course_review' );?></li>
23
- <?php }
24
- //else?>
25
- <!-- <li><?php _e( 'No review to load', 'learnpress_course_review' );?></li> -->
26
- </ul>
27
- <?php if( empty( $course_review['finish'] ) ){?>
28
- <button class="button" id="course-review-load-more" data-paged="<?php echo $course_review['paged'];?>"><?php _e( 'Load More', 'learnpress_course_review' );?></button>
29
- <?php }?>
30
- </div>
31
- <?php
32
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
template/rating-stars.php DELETED
@@ -1,16 +0,0 @@
1
- <div class="review-stars-rated">
2
- <ul class="review-stars">
3
- <li><span class="dashicons dashicons-star-empty"></span> </li>
4
- <li><span class="dashicons dashicons-star-empty"></span> </li>
5
- <li><span class="dashicons dashicons-star-empty"></span> </li>
6
- <li><span class="dashicons dashicons-star-empty"></span> </li>
7
- <li><span class="dashicons dashicons-star-empty"></span> </li>
8
- </ul>
9
- <ul class="review-stars filled" style="width:<?php echo $rated*20; ?>%;">
10
- <li><span class="dashicons dashicons-star-filled"></span> </li>
11
- <li><span class="dashicons dashicons-star-filled"></span> </li>
12
- <li><span class="dashicons dashicons-star-filled"></span> </li>
13
- <li><span class="dashicons dashicons-star-filled"></span> </li>
14
- <li><span class="dashicons dashicons-star-filled"></span> </li>
15
- </ul>
16
- </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
{template → templates}/course-rate.php RENAMED
@@ -10,12 +10,11 @@ $total = learn_press_get_course_rate_total( $course_id );
10
  <div class="course-rate">
11
  <?php
12
  learn_press_course_review_template( 'rating-stars.php', array( 'rated' => $course_rate ) );
13
- $text=' ratings';
14
- if( $total <= 1 ) $text = ' rating';
15
  ?>
16
  <p class="review-number">
17
  <?php do_action( 'learn_press_before_total_review_number' );?>
18
- <?php echo $total . $text ; ?>
19
  <?php do_action( 'learn_press_after_total_review_number' );?>
20
  </p>
21
  </div>
10
  <div class="course-rate">
11
  <?php
12
  learn_press_course_review_template( 'rating-stars.php', array( 'rated' => $course_rate ) );
13
+ $text=sprintf( _n('%d rating', '%d ratings', $total, 'learnpress-course-review'), $total);
 
14
  ?>
15
  <p class="review-number">
16
  <?php do_action( 'learn_press_before_total_review_number' );?>
17
+ <?php echo $text ; ?>
18
  <?php do_action( 'learn_press_after_total_review_number' );?>
19
  </p>
20
  </div>
templates/course-review.php ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if ( !defined( 'ABSPATH' ) ) {
3
+ exit; // Exit if accessed directly
4
+ }
5
+ $course_id = get_the_ID();
6
+ $course_review = learn_press_get_course_review( $course_id );
7
+ if ( $course_review['total'] ) {
8
+ $course_rate = learn_press_get_course_rate( $course_id );
9
+ $reviews = $course_review['reviews'];
10
+ ?>
11
+ <div id="course-reviews">
12
+ <h3 class="course-review-head"><?php _e( 'Reviews', 'learnpress-course-review' ); ?></h3>
13
+ <p class="course-average-rate"><?php printf( __( 'Average rate: <span>%.1f</span>', 'learnpress-course-review' ), $course_rate ); ?></p>
14
+ <ul class="course-reviews-list">
15
+ <?php foreach ( $reviews as $review ) { ?>
16
+ <?php
17
+ learn_press_course_review_template( 'loop-review.php', array( 'review' => $review ) );
18
+ ?>
19
+ <?php } ?>
20
+ <?php if ( empty( $course_review['finish'] ) ) { ?>
21
+ <li class="loading"><?php _e( 'Loading...', 'learnpress-course-review' ); ?></li>
22
+ <?php }
23
+ //else?>
24
+ <!-- <li><?php _e( 'No review to load', 'learnpress-course-review' ); ?></li> -->
25
+ </ul>
26
+ <?php if ( empty( $course_review['finish'] ) ) { ?>
27
+ <button class="button" id="course-review-load-more" data-paged="<?php echo $course_review['paged']; ?>"><?php _e( 'Load More', 'learnpress-course-review' ); ?></button>
28
+ <?php } ?>
29
+ </div>
30
+ <?php
31
+ }
{template → templates}/loop-review.php RENAMED
File without changes
templates/rating-stars.php ADDED
@@ -0,0 +1,4 @@
 
 
 
 
1
+ <div class="review-stars-rated">
2
+ <div class="review-stars empty"></div>
3
+ <div class="review-stars filled" style="width:<?php echo $rated*20; ?>%;"></div>
4
+ </div>
templates/review-form.php ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Template for displaying add review form
4
+ *
5
+ * @author ThimPress
6
+ * @package LearnPress/Templates
7
+ * @version 1.0
8
+ */
9
+
10
+ defined( 'ABSPATH' ) || exit();
11
+ ?>
12
+ <button class="write-a-review"><?php _e( 'Write a review', 'learnpress-course-review' ); ?></button>
13
+ <div class="course-review-wrapper" id="course-review">
14
+ <div class="review-overlay"></div>
15
+ <div class="review-form" id="review-form">
16
+ <form>
17
+ <h3>
18
+ <?php _e( 'Write a review', 'learnpress-course-review' ); ?>
19
+ <a href="" class="close dashicons dashicons-no-alt"></a>
20
+ </h3>
21
+ <ul class="review-fields">
22
+ <?php do_action( 'learn_press_before_review_fields' ); ?>
23
+ <li>
24
+ <label><?php _e( 'Title', 'learnpress-course-review' ); ?> <span class="required">*</span></label>
25
+ <input type="text" name="review_title" />
26
+ </li>
27
+ <li>
28
+ <label><?php _e( 'Content', 'learnpress-course-review' ); ?><span class="required">*</span></label>
29
+ <textarea name="review_content"></textarea>
30
+ </li>
31
+ <li>
32
+ <label><?php _e( 'Rating', 'learnpress-course-review' ); ?><span class="required">*</span></label>
33
+ <ul class="review-stars">
34
+ <?php for ( $i = 1; $i <= 5; $i ++ ) { ?>
35
+ <li class="review-title" title="<?php echo $i; ?>">
36
+ <span class="dashicons dashicons-star-empty"></span></li>
37
+ <?php } ?>
38
+ </ul>
39
+ </li>
40
+ <?php do_action( 'learn_press_after_review_fields' ); ?>
41
+ <li class="review-actions">
42
+ <button type="button" class="submit-review" data-id="<?php the_ID(); ?>"><?php _e( 'Add review', 'learnpress-course-review' ); ?></button>
43
+ <button type="button" class="close"><?php _e( 'Cancel', 'learnpress-course-review' ); ?></button>
44
+ <span class="ajaxload"><?php _e( 'Please wait...', 'learnpress-course-review' ); ?></span>
45
+ <span class="error"></span>
46
+ <?php wp_nonce_field( 'learn_press_course_review_' . get_the_ID(), 'review-nonce' ); ?>
47
+ <input type="hidden" name="rating" value="0">
48
+ <input type="hidden" name="lp-ajax" value="add_review">
49
+ <input type="hidden" name="id" value="<?php echo get_the_ID(); ?>">
50
+ </li>
51
+ </ul>
52
+ </form>
53
+ </div>
54
+ </div>