| @@ -8,105 +8,105 @@ | ||
| 8 | 8 | |
| 9 | 9 | class ReviewLimits | 
| 10 | 10 |  { | 
| 11 | - protected $request; | |
| 11 | + protected $request; | |
| 12 | 12 | |
| 13 | - /** | |
| 14 | - * @return array | |
| 15 | - * @filter site-reviews/get/reviews/query | |
| 16 | - */ | |
| 17 | - public function filterReviewsQuery(array $parameters, array $args) | |
| 18 | -    { | |
| 19 | -        if ($authorId = get_current_user_id()) { | |
| 20 | - $parameters['author'] = $authorId; | |
| 21 | - } | |
| 22 | - $parameters['post_status'] = ['pending', 'publish']; | |
| 23 | -        return apply_filters('site-reviews/review-limits/query', $parameters, $args); | |
| 24 | - } | |
| 13 | + /** | |
| 14 | + * @return array | |
| 15 | + * @filter site-reviews/get/reviews/query | |
| 16 | + */ | |
| 17 | + public function filterReviewsQuery(array $parameters, array $args) | |
| 18 | +	{ | |
| 19 | +		if ($authorId = get_current_user_id()) { | |
| 20 | + $parameters['author'] = $authorId; | |
| 21 | + } | |
| 22 | + $parameters['post_status'] = ['pending', 'publish']; | |
| 23 | +		return apply_filters('site-reviews/review-limits/query', $parameters, $args); | |
| 24 | + } | |
| 25 | 25 | |
| 26 | - /** | |
| 27 | - * @return bool | |
| 28 | - */ | |
| 29 | - public function hasReachedLimit(array $request = []) | |
| 30 | -    { | |
| 31 | - $this->request = $request; | |
| 32 | - $method = Helper::buildMethodName( | |
| 33 | -            glsr(OptionManager::class)->get('settings.submissions.limit'), 'validateBy' | |
| 34 | - ); | |
| 35 | - return method_exists($this, $method) | |
| 36 | - ? !call_user_func([$this, $method]) | |
| 37 | - : false; | |
| 38 | - } | |
| 26 | + /** | |
| 27 | + * @return bool | |
| 28 | + */ | |
| 29 | + public function hasReachedLimit(array $request = []) | |
| 30 | +	{ | |
| 31 | + $this->request = $request; | |
| 32 | + $method = Helper::buildMethodName( | |
| 33 | +			glsr(OptionManager::class)->get('settings.submissions.limit'), 'validateBy' | |
| 34 | + ); | |
| 35 | + return method_exists($this, $method) | |
| 36 | + ? !call_user_func([$this, $method]) | |
| 37 | + : false; | |
| 38 | + } | |
| 39 | 39 | |
| 40 | - /** | |
| 41 | - * @param string $value | |
| 42 | - * @param string $whitelist | |
| 43 | - * @return bool | |
| 44 | - */ | |
| 45 | - public function isWhitelisted($value, $whitelist) | |
| 46 | -    { | |
| 47 | -        if (empty($whitelist)) { | |
| 48 | - return false; | |
| 49 | - } | |
| 50 | -        return in_array($value, array_filter(explode("\n", $whitelist), 'trim')); | |
| 51 | - } | |
| 40 | + /** | |
| 41 | + * @param string $value | |
| 42 | + * @param string $whitelist | |
| 43 | + * @return bool | |
| 44 | + */ | |
| 45 | + public function isWhitelisted($value, $whitelist) | |
| 46 | +	{ | |
| 47 | +		if (empty($whitelist)) { | |
| 48 | + return false; | |
| 49 | + } | |
| 50 | +		return in_array($value, array_filter(explode("\n", $whitelist), 'trim')); | |
| 51 | + } | |
| 52 | 52 | |
| 53 | - /** | |
| 54 | - * @param string $whitelistName | |
| 55 | - * @return string | |
| 56 | - */ | |
| 57 | - protected function getWhitelist($whitelistName) | |
| 58 | -    { | |
| 59 | -        return glsr(OptionManager::class)->get('settings.submissions.limit_whitelist.'.$whitelistName); | |
| 60 | - } | |
| 53 | + /** | |
| 54 | + * @param string $whitelistName | |
| 55 | + * @return string | |
| 56 | + */ | |
| 57 | + protected function getWhitelist($whitelistName) | |
| 58 | +	{ | |
| 59 | +		return glsr(OptionManager::class)->get('settings.submissions.limit_whitelist.'.$whitelistName); | |
| 60 | + } | |
| 61 | 61 | |
| 62 | - /** | |
| 63 | - * @return bool | |
| 64 | - */ | |
| 65 | - protected function validate($key, $value, $addMetaQuery = true) | |
| 66 | -    { | |
| 67 | -        if ($this->isWhitelisted($value, $this->getWhitelist($key))) { | |
| 68 | - return true; | |
| 69 | - } | |
| 70 | -        add_filter('site-reviews/get/reviews/query', [$this, 'filterReviewsQuery'], 5, 2); | |
| 71 | - $args = ['assigned_to' => Arr::get($this->request, 'assign_to')]; | |
| 72 | -        if ($addMetaQuery) { | |
| 73 | - $args[$key] = $value; | |
| 74 | - } | |
| 75 | - $reviews = glsr_get_reviews($args); | |
| 76 | -        remove_filter('site-reviews/get/reviews/query', [$this, 'filterReviewsQuery'], 5); | |
| 77 | - $result = 0 === count($reviews); | |
| 78 | -        $result = apply_filters('site-reviews/review-limits/validate', $result, $reviews, $key); | |
| 79 | - return wp_validate_boolean($result); | |
| 80 | - } | |
| 62 | + /** | |
| 63 | + * @return bool | |
| 64 | + */ | |
| 65 | + protected function validate($key, $value, $addMetaQuery = true) | |
| 66 | +	{ | |
| 67 | +		if ($this->isWhitelisted($value, $this->getWhitelist($key))) { | |
| 68 | + return true; | |
| 69 | + } | |
| 70 | +		add_filter('site-reviews/get/reviews/query', [$this, 'filterReviewsQuery'], 5, 2); | |
| 71 | + $args = ['assigned_to' => Arr::get($this->request, 'assign_to')]; | |
| 72 | +		if ($addMetaQuery) { | |
| 73 | + $args[$key] = $value; | |
| 74 | + } | |
| 75 | + $reviews = glsr_get_reviews($args); | |
| 76 | +		remove_filter('site-reviews/get/reviews/query', [$this, 'filterReviewsQuery'], 5); | |
| 77 | + $result = 0 === count($reviews); | |
| 78 | +		$result = apply_filters('site-reviews/review-limits/validate', $result, $reviews, $key); | |
| 79 | + return wp_validate_boolean($result); | |
| 80 | + } | |
| 81 | 81 | |
| 82 | - /** | |
| 83 | - * @return bool | |
| 84 | - */ | |
| 85 | - protected function validateByEmail() | |
| 86 | -    { | |
| 87 | -        glsr_log()->debug('Email is: '.Arr::get($this->request, 'email')); | |
| 88 | -        return $this->validate('email', Arr::get($this->request, 'email')); | |
| 89 | - } | |
| 82 | + /** | |
| 83 | + * @return bool | |
| 84 | + */ | |
| 85 | + protected function validateByEmail() | |
| 86 | +	{ | |
| 87 | +		glsr_log()->debug('Email is: '.Arr::get($this->request, 'email')); | |
| 88 | +		return $this->validate('email', Arr::get($this->request, 'email')); | |
| 89 | + } | |
| 90 | 90 | |
| 91 | - /** | |
| 92 | - * @return bool | |
| 93 | - */ | |
| 94 | - protected function validateByIpAddress() | |
| 95 | -    { | |
| 96 | -        glsr_log()->debug('IP Address is: '.Arr::get($this->request, 'ip_address')); | |
| 97 | -        return $this->validate('ip_address', Arr::get($this->request, 'ip_address')); | |
| 98 | - } | |
| 91 | + /** | |
| 92 | + * @return bool | |
| 93 | + */ | |
| 94 | + protected function validateByIpAddress() | |
| 95 | +	{ | |
| 96 | +		glsr_log()->debug('IP Address is: '.Arr::get($this->request, 'ip_address')); | |
| 97 | +		return $this->validate('ip_address', Arr::get($this->request, 'ip_address')); | |
| 98 | + } | |
| 99 | 99 | |
| 100 | - /** | |
| 101 | - * @return bool | |
| 102 | - */ | |
| 103 | - protected function validateByUsername() | |
| 104 | -    { | |
| 105 | - $user = wp_get_current_user(); | |
| 106 | -        if (!$user->exists()) { | |
| 107 | - return true; | |
| 108 | - } | |
| 109 | -        glsr_log()->debug('Username is: '.$user->user_login); | |
| 110 | -        return $this->validate('username', $user->user_login, false); | |
| 111 | - } | |
| 100 | + /** | |
| 101 | + * @return bool | |
| 102 | + */ | |
| 103 | + protected function validateByUsername() | |
| 104 | +	{ | |
| 105 | + $user = wp_get_current_user(); | |
| 106 | +		if (!$user->exists()) { | |
| 107 | + return true; | |
| 108 | + } | |
| 109 | +		glsr_log()->debug('Username is: '.$user->user_login); | |
| 110 | +		return $this->validate('username', $user->user_login, false); | |
| 111 | + } | |
| 112 | 112 | } |