Version Description
(2020-10-25) =
- Fixed validation in the glsr_create_review helper function
Download this release
Release Info
Developer | geminilabs |
Plugin | Site Reviews |
Version | 5.1.5 |
Comparing to | |
See all releases |
Code changes from version 5.1.4 to 5.1.5
- helpers.php +8 -8
- languages/site-reviews-en_US.po +10 -10
- languages/site-reviews.pot +10 -10
- plugin/Commands/CreateReview.php +10 -0
- plugin/Modules/Validator/AkismetValidator.php +31 -31
- plugin/Modules/Validator/BlacklistValidator.php +16 -16
- plugin/Modules/Validator/CustomValidator.php +8 -0
- plugin/Modules/Validator/DefaultValidator.php +26 -16
- plugin/Modules/Validator/HoneypotValidator.php +10 -10
- plugin/Modules/Validator/PermissionValidator.php +9 -9
- plugin/Modules/Validator/RecaptchaValidator.php +16 -16
- plugin/Modules/Validator/ReviewLimitsValidator.php +11 -11
- readme.txt +5 -1
- site-reviews.php +1 -1
helpers.php
CHANGED
@@ -26,7 +26,7 @@ defined('ABSPATH') || die;
|
|
26 |
* @return mixed
|
27 |
*/
|
28 |
add_filter('plugins_loaded', function () {
|
29 |
-
$hooks =
|
30 |
'glsr_create_review' => 2,
|
31 |
'glsr_debug' => 10,
|
32 |
'glsr_get' => 4,
|
@@ -38,7 +38,7 @@ add_filter('plugins_loaded', function () {
|
|
38 |
'glsr_get_reviews' => 2,
|
39 |
'glsr_log' => 3,
|
40 |
'glsr_star_rating' => 2,
|
41 |
-
|
42 |
foreach ($hooks as $function => $acceptedArgs) {
|
43 |
add_filter($function, function () use ($function) {
|
44 |
$args = func_get_args();
|
@@ -68,11 +68,11 @@ function glsr($alias = null, array $parameters = [])
|
|
68 |
/**
|
69 |
* @return \GeminiLabs\SiteReviews\Review|false
|
70 |
*/
|
71 |
-
function glsr_create_review($reviewValues =
|
72 |
{
|
73 |
$request = new Request(Arr::consolidate($reviewValues));
|
74 |
$command = new CreateReview($request);
|
75 |
-
return $command->
|
76 |
? glsr(ReviewManager::class)->create($command)
|
77 |
: false;
|
78 |
}
|
@@ -143,17 +143,17 @@ function glsr_get_options()
|
|
143 |
/**
|
144 |
* @return \GeminiLabs\SiteReviews\Arguments
|
145 |
*/
|
146 |
-
function glsr_get_ratings($args =
|
147 |
{
|
148 |
$counts = glsr(RatingManager::class)->ratings(Arr::consolidate($args));
|
149 |
-
return new Arguments(
|
150 |
'average' => glsr(Rating::class)->average($counts),
|
151 |
'maximum' => Cast::toInt(glsr()->constant('MAX_RATING', Rating::class)),
|
152 |
'minimum' => Cast::toInt(glsr()->constant('MIN_RATING', Rating::class)),
|
153 |
'ranking' => glsr(Rating::class)->ranking($counts),
|
154 |
'ratings' => $counts,
|
155 |
'reviews' => array_sum($counts),
|
156 |
-
)
|
157 |
}
|
158 |
|
159 |
/**
|
@@ -168,7 +168,7 @@ function glsr_get_review($postId)
|
|
168 |
/**
|
169 |
* @return \GeminiLabs\SiteReviews\Reviews
|
170 |
*/
|
171 |
-
function glsr_get_reviews($args =
|
172 |
{
|
173 |
glsr()->sessionSet('glsr_get_reviews', true); // Tell Site Reviews that the helper function was used
|
174 |
return glsr(ReviewManager::class)->reviews(Arr::consolidate($args));
|
26 |
* @return mixed
|
27 |
*/
|
28 |
add_filter('plugins_loaded', function () {
|
29 |
+
$hooks = [
|
30 |
'glsr_create_review' => 2,
|
31 |
'glsr_debug' => 10,
|
32 |
'glsr_get' => 4,
|
38 |
'glsr_get_reviews' => 2,
|
39 |
'glsr_log' => 3,
|
40 |
'glsr_star_rating' => 2,
|
41 |
+
];
|
42 |
foreach ($hooks as $function => $acceptedArgs) {
|
43 |
add_filter($function, function () use ($function) {
|
44 |
$args = func_get_args();
|
68 |
/**
|
69 |
* @return \GeminiLabs\SiteReviews\Review|false
|
70 |
*/
|
71 |
+
function glsr_create_review($reviewValues = [])
|
72 |
{
|
73 |
$request = new Request(Arr::consolidate($reviewValues));
|
74 |
$command = new CreateReview($request);
|
75 |
+
return $command->isValid()
|
76 |
? glsr(ReviewManager::class)->create($command)
|
77 |
: false;
|
78 |
}
|
143 |
/**
|
144 |
* @return \GeminiLabs\SiteReviews\Arguments
|
145 |
*/
|
146 |
+
function glsr_get_ratings($args = [])
|
147 |
{
|
148 |
$counts = glsr(RatingManager::class)->ratings(Arr::consolidate($args));
|
149 |
+
return new Arguments([
|
150 |
'average' => glsr(Rating::class)->average($counts),
|
151 |
'maximum' => Cast::toInt(glsr()->constant('MAX_RATING', Rating::class)),
|
152 |
'minimum' => Cast::toInt(glsr()->constant('MIN_RATING', Rating::class)),
|
153 |
'ranking' => glsr(Rating::class)->ranking($counts),
|
154 |
'ratings' => $counts,
|
155 |
'reviews' => array_sum($counts),
|
156 |
+
]);
|
157 |
}
|
158 |
|
159 |
/**
|
168 |
/**
|
169 |
* @return \GeminiLabs\SiteReviews\Reviews
|
170 |
*/
|
171 |
+
function glsr_get_reviews($args = [])
|
172 |
{
|
173 |
glsr()->sessionSet('glsr_get_reviews', true); // Tell Site Reviews that the helper function was used
|
174 |
return glsr(ReviewManager::class)->reviews(Arr::consolidate($args));
|
languages/site-reviews-en_US.po
CHANGED
@@ -82,11 +82,11 @@ msgstr "This review is based on my own experience and is my genuine opinion."
|
|
82 |
msgid "Show more"
|
83 |
msgstr "Show more"
|
84 |
|
85 |
-
#: plugin/Commands/CreateReview.php:
|
86 |
msgid "Your review has been submitted!"
|
87 |
msgstr "Your review has been submitted!"
|
88 |
|
89 |
-
#: plugin/Commands/CreateReview.php:
|
90 |
msgid ""
|
91 |
"Your review could not be submitted and the error has been logged. Please "
|
92 |
"notify the site admin."
|
@@ -126,7 +126,7 @@ msgstr "This field must have between %s and %s characters."
|
|
126 |
msgid "This field requires a valid e-mail address."
|
127 |
msgstr "This field requires a valid e-mail address."
|
128 |
|
129 |
-
#: plugin/Defaults/ValidationStringsDefaults.php:19, plugin/Modules/Validator/DefaultValidator.php:
|
130 |
msgid "Please fix the submission errors."
|
131 |
msgstr "Please fix the submission errors."
|
132 |
|
@@ -232,31 +232,31 @@ msgstr "Poor"
|
|
232 |
msgid "Terrible"
|
233 |
msgstr "Terrible"
|
234 |
|
235 |
-
#: plugin/Modules/Validator/AkismetValidator.php:
|
236 |
msgid "This review has been flagged as possible spam and cannot be submitted."
|
237 |
msgstr "This review has been flagged as possible spam and cannot be submitted."
|
238 |
|
239 |
-
#: plugin/Modules/Validator/BlacklistValidator.php:
|
240 |
msgid "Your review cannot be submitted at this time."
|
241 |
msgstr "Your review cannot be submitted at this time."
|
242 |
|
243 |
-
#: plugin/Modules/Validator/CustomValidator.php:
|
244 |
msgid "The review submission failed. Please notify the site administrator."
|
245 |
msgstr "The review submission failed. Please notify the site administrator."
|
246 |
|
247 |
-
#: plugin/Modules/Validator/PermissionValidator.php:
|
248 |
msgid "You must be logged in to submit a review."
|
249 |
msgstr "You must be logged in to submit a review."
|
250 |
|
251 |
-
#: plugin/Modules/Validator/RecaptchaValidator.php:
|
252 |
msgid "The reCAPTCHA failed to load, please refresh the page and try again."
|
253 |
msgstr "The reCAPTCHA failed to load, please refresh the page and try again."
|
254 |
|
255 |
-
#: plugin/Modules/Validator/RecaptchaValidator.php:
|
256 |
msgid "The reCAPTCHA verification failed, please try again."
|
257 |
msgstr "The reCAPTCHA verification failed, please try again."
|
258 |
|
259 |
-
#: plugin/Modules/Validator/ReviewLimitsValidator.php:
|
260 |
msgid "You have already submitted a review."
|
261 |
msgstr "You have already submitted a review."
|
262 |
|
82 |
msgid "Show more"
|
83 |
msgstr "Show more"
|
84 |
|
85 |
+
#: plugin/Commands/CreateReview.php:155
|
86 |
msgid "Your review has been submitted!"
|
87 |
msgstr "Your review has been submitted!"
|
88 |
|
89 |
+
#: plugin/Commands/CreateReview.php:160
|
90 |
msgid ""
|
91 |
"Your review could not be submitted and the error has been logged. Please "
|
92 |
"notify the site admin."
|
126 |
msgid "This field requires a valid e-mail address."
|
127 |
msgstr "This field requires a valid e-mail address."
|
128 |
|
129 |
+
#: plugin/Defaults/ValidationStringsDefaults.php:19, plugin/Modules/Validator/DefaultValidator.php:52
|
130 |
msgid "Please fix the submission errors."
|
131 |
msgstr "Please fix the submission errors."
|
132 |
|
232 |
msgid "Terrible"
|
233 |
msgstr "Terrible"
|
234 |
|
235 |
+
#: plugin/Modules/Validator/AkismetValidator.php:49
|
236 |
msgid "This review has been flagged as possible spam and cannot be submitted."
|
237 |
msgstr "This review has been flagged as possible spam and cannot be submitted."
|
238 |
|
239 |
+
#: plugin/Modules/Validator/BlacklistValidator.php:37
|
240 |
msgid "Your review cannot be submitted at this time."
|
241 |
msgstr "Your review cannot be submitted at this time."
|
242 |
|
243 |
+
#: plugin/Modules/Validator/CustomValidator.php:27, plugin/Modules/Validator/HoneypotValidator.php:26
|
244 |
msgid "The review submission failed. Please notify the site administrator."
|
245 |
msgstr "The review submission failed. Please notify the site administrator."
|
246 |
|
247 |
+
#: plugin/Modules/Validator/PermissionValidator.php:26
|
248 |
msgid "You must be logged in to submit a review."
|
249 |
msgstr "You must be logged in to submit a review."
|
250 |
|
251 |
+
#: plugin/Modules/Validator/RecaptchaValidator.php:44
|
252 |
msgid "The reCAPTCHA failed to load, please refresh the page and try again."
|
253 |
msgstr "The reCAPTCHA failed to load, please refresh the page and try again."
|
254 |
|
255 |
+
#: plugin/Modules/Validator/RecaptchaValidator.php:45
|
256 |
msgid "The reCAPTCHA verification failed, please try again."
|
257 |
msgstr "The reCAPTCHA verification failed, please try again."
|
258 |
|
259 |
+
#: plugin/Modules/Validator/ReviewLimitsValidator.php:43
|
260 |
msgid "You have already submitted a review."
|
261 |
msgstr "You have already submitted a review."
|
262 |
|
languages/site-reviews.pot
CHANGED
@@ -1085,11 +1085,11 @@ msgstr ""
|
|
1085 |
msgid "Show more"
|
1086 |
msgstr ""
|
1087 |
|
1088 |
-
#: plugin/Commands/CreateReview.php:
|
1089 |
msgid "Your review has been submitted!"
|
1090 |
msgstr ""
|
1091 |
|
1092 |
-
#: plugin/Commands/CreateReview.php:
|
1093 |
msgid "Your review could not be submitted and the error has been logged. Please notify the site admin."
|
1094 |
msgstr ""
|
1095 |
|
@@ -1736,7 +1736,7 @@ msgstr ""
|
|
1736 |
msgid "This field requires a valid e-mail address."
|
1737 |
msgstr ""
|
1738 |
|
1739 |
-
#: plugin/Defaults/ValidationStringsDefaults.php:19, plugin/Modules/Validator/DefaultValidator.php:
|
1740 |
msgid "Please fix the submission errors."
|
1741 |
msgstr ""
|
1742 |
|
@@ -2247,31 +2247,31 @@ msgctxt "admin-text"
|
|
2247 |
msgid "Unsupported Type"
|
2248 |
msgstr ""
|
2249 |
|
2250 |
-
#: plugin/Modules/Validator/AkismetValidator.php:
|
2251 |
msgid "This review has been flagged as possible spam and cannot be submitted."
|
2252 |
msgstr ""
|
2253 |
|
2254 |
-
#: plugin/Modules/Validator/BlacklistValidator.php:
|
2255 |
msgid "Your review cannot be submitted at this time."
|
2256 |
msgstr ""
|
2257 |
|
2258 |
-
#: plugin/Modules/Validator/CustomValidator.php:
|
2259 |
msgid "The review submission failed. Please notify the site administrator."
|
2260 |
msgstr ""
|
2261 |
|
2262 |
-
#: plugin/Modules/Validator/PermissionValidator.php:
|
2263 |
msgid "You must be logged in to submit a review."
|
2264 |
msgstr ""
|
2265 |
|
2266 |
-
#: plugin/Modules/Validator/RecaptchaValidator.php:
|
2267 |
msgid "The reCAPTCHA failed to load, please refresh the page and try again."
|
2268 |
msgstr ""
|
2269 |
|
2270 |
-
#: plugin/Modules/Validator/RecaptchaValidator.php:
|
2271 |
msgid "The reCAPTCHA verification failed, please try again."
|
2272 |
msgstr ""
|
2273 |
|
2274 |
-
#: plugin/Modules/Validator/ReviewLimitsValidator.php:
|
2275 |
msgid "You have already submitted a review."
|
2276 |
msgstr ""
|
2277 |
|
1085 |
msgid "Show more"
|
1086 |
msgstr ""
|
1087 |
|
1088 |
+
#: plugin/Commands/CreateReview.php:155
|
1089 |
msgid "Your review has been submitted!"
|
1090 |
msgstr ""
|
1091 |
|
1092 |
+
#: plugin/Commands/CreateReview.php:160
|
1093 |
msgid "Your review could not be submitted and the error has been logged. Please notify the site admin."
|
1094 |
msgstr ""
|
1095 |
|
1736 |
msgid "This field requires a valid e-mail address."
|
1737 |
msgstr ""
|
1738 |
|
1739 |
+
#: plugin/Defaults/ValidationStringsDefaults.php:19, plugin/Modules/Validator/DefaultValidator.php:52
|
1740 |
msgid "Please fix the submission errors."
|
1741 |
msgstr ""
|
1742 |
|
2247 |
msgid "Unsupported Type"
|
2248 |
msgstr ""
|
2249 |
|
2250 |
+
#: plugin/Modules/Validator/AkismetValidator.php:49
|
2251 |
msgid "This review has been flagged as possible spam and cannot be submitted."
|
2252 |
msgstr ""
|
2253 |
|
2254 |
+
#: plugin/Modules/Validator/BlacklistValidator.php:37
|
2255 |
msgid "Your review cannot be submitted at this time."
|
2256 |
msgstr ""
|
2257 |
|
2258 |
+
#: plugin/Modules/Validator/CustomValidator.php:27, plugin/Modules/Validator/HoneypotValidator.php:26
|
2259 |
msgid "The review submission failed. Please notify the site administrator."
|
2260 |
msgstr ""
|
2261 |
|
2262 |
+
#: plugin/Modules/Validator/PermissionValidator.php:26
|
2263 |
msgid "You must be logged in to submit a review."
|
2264 |
msgstr ""
|
2265 |
|
2266 |
+
#: plugin/Modules/Validator/RecaptchaValidator.php:44
|
2267 |
msgid "The reCAPTCHA failed to load, please refresh the page and try again."
|
2268 |
msgstr ""
|
2269 |
|
2270 |
+
#: plugin/Modules/Validator/RecaptchaValidator.php:45
|
2271 |
msgid "The reCAPTCHA verification failed, please try again."
|
2272 |
msgstr ""
|
2273 |
|
2274 |
+
#: plugin/Modules/Validator/ReviewLimitsValidator.php:43
|
2275 |
msgid "You have already submitted a review."
|
2276 |
msgstr ""
|
2277 |
|
plugin/Commands/CreateReview.php
CHANGED
@@ -10,6 +10,7 @@ use GeminiLabs\SiteReviews\Helper;
|
|
10 |
use GeminiLabs\SiteReviews\Helpers\Cast;
|
11 |
use GeminiLabs\SiteReviews\Modules\Avatar;
|
12 |
use GeminiLabs\SiteReviews\Modules\Notification;
|
|
|
13 |
use GeminiLabs\SiteReviews\Modules\Validator\ValidateReview;
|
14 |
use GeminiLabs\SiteReviews\Request;
|
15 |
|
@@ -122,6 +123,15 @@ class CreateReview implements Contract
|
|
122 |
return $validator->isValid();
|
123 |
}
|
124 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
125 |
/**
|
126 |
* @return string
|
127 |
*/
|
10 |
use GeminiLabs\SiteReviews\Helpers\Cast;
|
11 |
use GeminiLabs\SiteReviews\Modules\Avatar;
|
12 |
use GeminiLabs\SiteReviews\Modules\Notification;
|
13 |
+
use GeminiLabs\SiteReviews\Modules\Validator\DefaultValidator;
|
14 |
use GeminiLabs\SiteReviews\Modules\Validator\ValidateReview;
|
15 |
use GeminiLabs\SiteReviews\Request;
|
16 |
|
123 |
return $validator->isValid();
|
124 |
}
|
125 |
|
126 |
+
/**
|
127 |
+
* This only validates the provided values in the Request
|
128 |
+
* @return bool
|
129 |
+
*/
|
130 |
+
public function isValid()
|
131 |
+
{
|
132 |
+
return glsr(DefaultValidator::class, ['request' => $this->request])->isValidRequest();
|
133 |
+
}
|
134 |
+
|
135 |
/**
|
136 |
* @return string
|
137 |
*/
|
plugin/Modules/Validator/AkismetValidator.php
CHANGED
@@ -8,6 +8,37 @@ use GeminiLabs\SiteReviews\Request;
|
|
8 |
|
9 |
class AkismetValidator extends ValidatorAbstract
|
10 |
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
/**
|
12 |
* @return void
|
13 |
*/
|
@@ -56,37 +87,6 @@ class AkismetValidator extends ValidatorAbstract
|
|
56 |
return glsr()->filterBool('validate/akismet/is-active', $check);
|
57 |
}
|
58 |
|
59 |
-
/**
|
60 |
-
* @return bool
|
61 |
-
*/
|
62 |
-
protected function isValid()
|
63 |
-
{
|
64 |
-
if (!$this->isActive()) {
|
65 |
-
return true;
|
66 |
-
}
|
67 |
-
$submission = [
|
68 |
-
'blog' => glsr(OptionManager::class)->getWP('home'),
|
69 |
-
'blog_charset' => glsr(OptionManager::class)->getWP('blog_charset', 'UTF-8'),
|
70 |
-
'blog_lang' => get_locale(),
|
71 |
-
'comment_author' => $this->request->name,
|
72 |
-
'comment_author_email' => $this->request->email,
|
73 |
-
'comment_content' => $this->request->title."\n\n".$this->request->content,
|
74 |
-
'comment_type' => 'review',
|
75 |
-
'referrer' => filter_input(INPUT_SERVER, 'HTTP_REFERER'),
|
76 |
-
'user_agent' => filter_input(INPUT_SERVER, 'HTTP_USER_AGENT'),
|
77 |
-
'user_ip' => $this->request->ip_address,
|
78 |
-
// 'user_role' => 'administrator',
|
79 |
-
// 'is_test' => 1,
|
80 |
-
];
|
81 |
-
foreach ($_SERVER as $key => $value) {
|
82 |
-
if (!is_array($value) && !in_array($key, ['HTTP_COOKIE', 'HTTP_COOKIE2', 'PHP_AUTH_PW'])) {
|
83 |
-
$submission[$key] = $value;
|
84 |
-
}
|
85 |
-
}
|
86 |
-
$submission = glsr()->filterArray('validate/akismet/submission', $submission, $this->request);
|
87 |
-
return $this->validateAkismet($submission);
|
88 |
-
}
|
89 |
-
|
90 |
/**
|
91 |
* @return bool
|
92 |
*/
|
8 |
|
9 |
class AkismetValidator extends ValidatorAbstract
|
10 |
{
|
11 |
+
/**
|
12 |
+
* @return bool
|
13 |
+
*/
|
14 |
+
public function isValid()
|
15 |
+
{
|
16 |
+
if (!$this->isActive()) {
|
17 |
+
return true;
|
18 |
+
}
|
19 |
+
$submission = [
|
20 |
+
'blog' => glsr(OptionManager::class)->getWP('home'),
|
21 |
+
'blog_charset' => glsr(OptionManager::class)->getWP('blog_charset', 'UTF-8'),
|
22 |
+
'blog_lang' => get_locale(),
|
23 |
+
'comment_author' => $this->request->name,
|
24 |
+
'comment_author_email' => $this->request->email,
|
25 |
+
'comment_content' => $this->request->title."\n\n".$this->request->content,
|
26 |
+
'comment_type' => 'review',
|
27 |
+
'referrer' => filter_input(INPUT_SERVER, 'HTTP_REFERER'),
|
28 |
+
'user_agent' => filter_input(INPUT_SERVER, 'HTTP_USER_AGENT'),
|
29 |
+
'user_ip' => $this->request->ip_address,
|
30 |
+
// 'user_role' => 'administrator',
|
31 |
+
// 'is_test' => 1,
|
32 |
+
];
|
33 |
+
foreach ($_SERVER as $key => $value) {
|
34 |
+
if (!is_array($value) && !in_array($key, ['HTTP_COOKIE', 'HTTP_COOKIE2', 'PHP_AUTH_PW'])) {
|
35 |
+
$submission[$key] = $value;
|
36 |
+
}
|
37 |
+
}
|
38 |
+
$submission = glsr()->filterArray('validate/akismet/submission', $submission, $this->request);
|
39 |
+
return $this->validateAkismet($submission);
|
40 |
+
}
|
41 |
+
|
42 |
/**
|
43 |
* @return void
|
44 |
*/
|
87 |
return glsr()->filterBool('validate/akismet/is-active', $check);
|
88 |
}
|
89 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
90 |
/**
|
91 |
* @return bool
|
92 |
*/
|
plugin/Modules/Validator/BlacklistValidator.php
CHANGED
@@ -7,6 +7,22 @@ use GeminiLabs\SiteReviews\Request;
|
|
7 |
|
8 |
class BlacklistValidator extends ValidatorAbstract
|
9 |
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
/**
|
11 |
* @return void
|
12 |
*/
|
@@ -34,22 +50,6 @@ class BlacklistValidator extends ValidatorAbstract
|
|
34 |
: trim(glsr_get_option('submissions.blacklist.entries'));
|
35 |
}
|
36 |
|
37 |
-
/**
|
38 |
-
* @return bool
|
39 |
-
*/
|
40 |
-
protected function isValid()
|
41 |
-
{
|
42 |
-
$target = implode("\n", array_filter([
|
43 |
-
$this->request->name,
|
44 |
-
$this->request->content,
|
45 |
-
$this->request->email,
|
46 |
-
$this->request->ip_address,
|
47 |
-
$this->request->title,
|
48 |
-
]));
|
49 |
-
$isValid = $this->validateBlacklist($target);
|
50 |
-
return glsr()->filterBool('validate/blacklist', $isValid, $target, $this->request);
|
51 |
-
}
|
52 |
-
|
53 |
/**
|
54 |
* @param string $target
|
55 |
* @return bool
|
7 |
|
8 |
class BlacklistValidator extends ValidatorAbstract
|
9 |
{
|
10 |
+
/**
|
11 |
+
* @return bool
|
12 |
+
*/
|
13 |
+
public function isValid()
|
14 |
+
{
|
15 |
+
$target = implode("\n", array_filter([
|
16 |
+
$this->request->name,
|
17 |
+
$this->request->content,
|
18 |
+
$this->request->email,
|
19 |
+
$this->request->ip_address,
|
20 |
+
$this->request->title,
|
21 |
+
]));
|
22 |
+
$isValid = $this->validateBlacklist($target);
|
23 |
+
return glsr()->filterBool('validate/blacklist', $isValid, $target, $this->request);
|
24 |
+
}
|
25 |
+
|
26 |
/**
|
27 |
* @return void
|
28 |
*/
|
50 |
: trim(glsr_get_option('submissions.blacklist.entries'));
|
51 |
}
|
52 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
53 |
/**
|
54 |
* @param string $target
|
55 |
* @return bool
|
plugin/Modules/Validator/CustomValidator.php
CHANGED
@@ -6,6 +6,14 @@ use GeminiLabs\SiteReviews\Helpers\Cast;
|
|
6 |
|
7 |
class CustomValidator extends ValidatorAbstract
|
8 |
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
/**
|
10 |
* @return void
|
11 |
*/
|
6 |
|
7 |
class CustomValidator extends ValidatorAbstract
|
8 |
{
|
9 |
+
/**
|
10 |
+
* @return bool
|
11 |
+
*/
|
12 |
+
public function isValid()
|
13 |
+
{
|
14 |
+
return Cast::toBool(glsr()->filter('validate/custom', true, $this->request));
|
15 |
+
}
|
16 |
+
|
17 |
/**
|
18 |
* @return void
|
19 |
*/
|
plugin/Modules/Validator/DefaultValidator.php
CHANGED
@@ -20,30 +20,40 @@ class DefaultValidator extends ValidatorAbstract
|
|
20 |
];
|
21 |
|
22 |
/**
|
23 |
-
* @return
|
24 |
*/
|
25 |
-
public function
|
26 |
{
|
27 |
-
|
28 |
-
$this->
|
29 |
-
|
|
|
|
|
30 |
}
|
31 |
|
32 |
/**
|
|
|
33 |
* @return bool
|
34 |
*/
|
35 |
-
|
36 |
{
|
37 |
-
$
|
38 |
-
|
39 |
-
|
40 |
-
);
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
}
|
46 |
-
|
|
|
47 |
}
|
48 |
|
49 |
/**
|
@@ -55,7 +65,7 @@ class DefaultValidator extends ValidatorAbstract
|
|
55 |
$customRules = array_diff_key($rules,
|
56 |
glsr(DefaultsManager::class)->pluck('settings.submissions.required.options')
|
57 |
);
|
58 |
-
$requiredRules = array_intersect_key($rules,
|
59 |
array_flip(glsr_get_option('submissions.required', []))
|
60 |
);
|
61 |
$rules = array_merge($requiredRules, $customRules);
|
20 |
];
|
21 |
|
22 |
/**
|
23 |
+
* @return bool
|
24 |
*/
|
25 |
+
public function isValid()
|
26 |
{
|
27 |
+
$this->errors = glsr(Validator::class)->validate(
|
28 |
+
$this->request->toArray(),
|
29 |
+
$this->rules()
|
30 |
+
);
|
31 |
+
return empty($this->errors);
|
32 |
}
|
33 |
|
34 |
/**
|
35 |
+
* This only validates the provided values in the Request
|
36 |
* @return bool
|
37 |
*/
|
38 |
+
public function isValidRequest()
|
39 |
{
|
40 |
+
$options = glsr(DefaultsManager::class)->pluck('settings.submissions.required.options');
|
41 |
+
$excludedKeys = array_keys(array_diff_key($options, $this->request->toArray()));
|
42 |
+
$this->request->excluded = $excludedKeys;
|
43 |
+
return $this->isValid();
|
44 |
+
}
|
45 |
+
|
46 |
+
/**
|
47 |
+
* @return void
|
48 |
+
*/
|
49 |
+
public function performValidation()
|
50 |
+
{
|
51 |
+
if (!$this->isValid()) {
|
52 |
+
$this->setErrors(__('Please fix the submission errors.', 'site-reviews'));
|
53 |
+
return;
|
54 |
}
|
55 |
+
$values = glsr(ValidateReviewDefaults::class)->merge($this->request->toArray());
|
56 |
+
$this->request = new Request($values);
|
57 |
}
|
58 |
|
59 |
/**
|
65 |
$customRules = array_diff_key($rules,
|
66 |
glsr(DefaultsManager::class)->pluck('settings.submissions.required.options')
|
67 |
);
|
68 |
+
$requiredRules = array_intersect_key($rules,
|
69 |
array_flip(glsr_get_option('submissions.required', []))
|
70 |
);
|
71 |
$rules = array_merge($requiredRules, $customRules);
|
plugin/Modules/Validator/HoneypotValidator.php
CHANGED
@@ -6,6 +6,16 @@ use GeminiLabs\SiteReviews\Modules\Honeypot;
|
|
6 |
|
7 |
class HoneypotValidator extends ValidatorAbstract
|
8 |
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
/**
|
10 |
* @return void
|
11 |
*/
|
@@ -18,14 +28,4 @@ class HoneypotValidator extends ValidatorAbstract
|
|
18 |
);
|
19 |
}
|
20 |
}
|
21 |
-
|
22 |
-
/**
|
23 |
-
* @return bool
|
24 |
-
*/
|
25 |
-
protected function isValid()
|
26 |
-
{
|
27 |
-
$hash = glsr(Honeypot::class)->hash($this->request->form_id);
|
28 |
-
$isValid = isset($this->request[$hash]) && empty($this->request[$hash]);
|
29 |
-
return glsr()->filterBool('validate/honeypot', $isValid, $this->request);
|
30 |
-
}
|
31 |
}
|
6 |
|
7 |
class HoneypotValidator extends ValidatorAbstract
|
8 |
{
|
9 |
+
/**
|
10 |
+
* @return bool
|
11 |
+
*/
|
12 |
+
public function isValid()
|
13 |
+
{
|
14 |
+
$hash = glsr(Honeypot::class)->hash($this->request->form_id);
|
15 |
+
$isValid = isset($this->request[$hash]) && empty($this->request[$hash]);
|
16 |
+
return glsr()->filterBool('validate/honeypot', $isValid, $this->request);
|
17 |
+
}
|
18 |
+
|
19 |
/**
|
20 |
* @return void
|
21 |
*/
|
28 |
);
|
29 |
}
|
30 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
}
|
plugin/Modules/Validator/PermissionValidator.php
CHANGED
@@ -7,23 +7,23 @@ use GeminiLabs\SiteReviews\Helpers\Cast;
|
|
7 |
class PermissionValidator extends ValidatorAbstract
|
8 |
{
|
9 |
/**
|
10 |
-
* @return
|
11 |
*/
|
12 |
-
public function
|
13 |
{
|
14 |
-
if (
|
15 |
-
|
16 |
}
|
|
|
17 |
}
|
18 |
|
19 |
/**
|
20 |
-
* @return
|
21 |
*/
|
22 |
-
|
23 |
{
|
24 |
-
if (
|
25 |
-
|
26 |
}
|
27 |
-
return true;
|
28 |
}
|
29 |
}
|
7 |
class PermissionValidator extends ValidatorAbstract
|
8 |
{
|
9 |
/**
|
10 |
+
* @return bool
|
11 |
*/
|
12 |
+
public function isValid()
|
13 |
{
|
14 |
+
if (Cast::toBool(glsr_get_option('general.require.login'))) {
|
15 |
+
return is_user_logged_in();
|
16 |
}
|
17 |
+
return true;
|
18 |
}
|
19 |
|
20 |
/**
|
21 |
+
* @return void
|
22 |
*/
|
23 |
+
public function performValidation()
|
24 |
{
|
25 |
+
if (!$this->isValid()) {
|
26 |
+
$this->setErrors(__('You must be logged in to submit a review.', 'site-reviews'));
|
27 |
}
|
|
|
28 |
}
|
29 |
}
|
plugin/Modules/Validator/RecaptchaValidator.php
CHANGED
@@ -17,25 +17,10 @@ class RecaptchaValidator extends ValidatorAbstract
|
|
17 |
|
18 |
protected $status;
|
19 |
|
20 |
-
/**
|
21 |
-
* @return void
|
22 |
-
*/
|
23 |
-
public function performValidation()
|
24 |
-
{
|
25 |
-
$this->status = $this->recaptchaStatus();
|
26 |
-
if (!$this->isValid()) {
|
27 |
-
$message = Helper::ifTrue($this->status === static::RECAPTCHA_FAILED,
|
28 |
-
__('The reCAPTCHA failed to load, please refresh the page and try again.', 'site-reviews'),
|
29 |
-
__('The reCAPTCHA verification failed, please try again.', 'site-reviews')
|
30 |
-
);
|
31 |
-
$this->setErrors($message);
|
32 |
-
}
|
33 |
-
}
|
34 |
-
|
35 |
/**
|
36 |
* @return bool
|
37 |
*/
|
38 |
-
|
39 |
{
|
40 |
if (in_array($this->status, [static::RECAPTCHA_DISABLED, static::RECAPTCHA_VALID])) {
|
41 |
return true;
|
@@ -48,6 +33,21 @@ class RecaptchaValidator extends ValidatorAbstract
|
|
48 |
return false;
|
49 |
}
|
50 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
/**
|
52 |
* @return int
|
53 |
*/
|
17 |
|
18 |
protected $status;
|
19 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
/**
|
21 |
* @return bool
|
22 |
*/
|
23 |
+
public function isValid()
|
24 |
{
|
25 |
if (in_array($this->status, [static::RECAPTCHA_DISABLED, static::RECAPTCHA_VALID])) {
|
26 |
return true;
|
33 |
return false;
|
34 |
}
|
35 |
|
36 |
+
/**
|
37 |
+
* @return void
|
38 |
+
*/
|
39 |
+
public function performValidation()
|
40 |
+
{
|
41 |
+
$this->status = $this->recaptchaStatus();
|
42 |
+
if (!$this->isValid()) {
|
43 |
+
$message = Helper::ifTrue($this->status === static::RECAPTCHA_FAILED,
|
44 |
+
__('The reCAPTCHA failed to load, please refresh the page and try again.', 'site-reviews'),
|
45 |
+
__('The reCAPTCHA verification failed, please try again.', 'site-reviews')
|
46 |
+
);
|
47 |
+
$this->setErrors($message);
|
48 |
+
}
|
49 |
+
}
|
50 |
+
|
51 |
/**
|
52 |
* @return int
|
53 |
*/
|
plugin/Modules/Validator/ReviewLimitsValidator.php
CHANGED
@@ -23,20 +23,10 @@ class ReviewLimitsValidator extends ValidatorAbstract
|
|
23 |
return !$this->isValid();
|
24 |
}
|
25 |
|
26 |
-
/**
|
27 |
-
* @return void
|
28 |
-
*/
|
29 |
-
public function performValidation()
|
30 |
-
{
|
31 |
-
if (!$this->isValid()) {
|
32 |
-
$this->setErrors(__('You have already submitted a review.', 'site-reviews'));
|
33 |
-
}
|
34 |
-
}
|
35 |
-
|
36 |
/**
|
37 |
* @return bool
|
38 |
*/
|
39 |
-
|
40 |
{
|
41 |
$method = Helper::buildMethodName(glsr_get_option('submissions.limit'), 'validateBy');
|
42 |
return method_exists($this, $method)
|
@@ -44,6 +34,16 @@ class ReviewLimitsValidator extends ValidatorAbstract
|
|
44 |
: true;
|
45 |
}
|
46 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
/**
|
48 |
* @param string $value
|
49 |
* @param string $whitelist
|
23 |
return !$this->isValid();
|
24 |
}
|
25 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
/**
|
27 |
* @return bool
|
28 |
*/
|
29 |
+
public function isValid()
|
30 |
{
|
31 |
$method = Helper::buildMethodName(glsr_get_option('submissions.limit'), 'validateBy');
|
32 |
return method_exists($this, $method)
|
34 |
: true;
|
35 |
}
|
36 |
|
37 |
+
/**
|
38 |
+
* @return void
|
39 |
+
*/
|
40 |
+
public function performValidation()
|
41 |
+
{
|
42 |
+
if (!$this->isValid()) {
|
43 |
+
$this->setErrors(__('You have already submitted a review.', 'site-reviews'));
|
44 |
+
}
|
45 |
+
}
|
46 |
+
|
47 |
/**
|
48 |
* @param string $value
|
49 |
* @param string $whitelist
|
readme.txt
CHANGED
@@ -5,7 +5,7 @@ Tags: reviews, ratings, testimonials, business reviews, product reviews, stars,
|
|
5 |
Tested up to: 5.5
|
6 |
Requires at least: 5.5
|
7 |
Requires PHP: 5.6
|
8 |
-
Stable tag: 5.1.
|
9 |
License: GPLv3
|
10 |
License URI: https://www.gnu.org/licenses/gpl-2.0.html
|
11 |
|
@@ -113,6 +113,10 @@ All documentation can be found in the "Help" page of the plugin. If your questio
|
|
113 |
|
114 |
== Changelog ==
|
115 |
|
|
|
|
|
|
|
|
|
116 |
= 5.1.4 (2020-10-25) =
|
117 |
|
118 |
- Added "ORDER BY" to migration SQL queries; this will make migrations run a little slower but fix a potential problem where database migrations may not complete successfully
|
5 |
Tested up to: 5.5
|
6 |
Requires at least: 5.5
|
7 |
Requires PHP: 5.6
|
8 |
+
Stable tag: 5.1.5
|
9 |
License: GPLv3
|
10 |
License URI: https://www.gnu.org/licenses/gpl-2.0.html
|
11 |
|
113 |
|
114 |
== Changelog ==
|
115 |
|
116 |
+
= 5.1.5 (2020-10-25) =
|
117 |
+
|
118 |
+
- Fixed validation in the glsr_create_review helper function
|
119 |
+
|
120 |
= 5.1.4 (2020-10-25) =
|
121 |
|
122 |
- Added "ORDER BY" to migration SQL queries; this will make migrations run a little slower but fix a potential problem where database migrations may not complete successfully
|
site-reviews.php
CHANGED
@@ -7,7 +7,7 @@
|
|
7 |
* Plugin Name: Site Reviews
|
8 |
* Plugin URI: https://wordpress.org/plugins/site-reviews
|
9 |
* Description: Receive and display reviews on your website
|
10 |
-
* Version: 5.1.
|
11 |
* Author: Paul Ryley
|
12 |
* Author URI: https://geminilabs.io
|
13 |
* License: GPL2
|
7 |
* Plugin Name: Site Reviews
|
8 |
* Plugin URI: https://wordpress.org/plugins/site-reviews
|
9 |
* Description: Receive and display reviews on your website
|
10 |
+
* Version: 5.1.5
|
11 |
* Author: Paul Ryley
|
12 |
* Author URI: https://geminilabs.io
|
13 |
* License: GPL2
|