Passed
Push — master ( 34ba2b...b9b7cf )
by Paul
08:22 queued 04:02
created
plugin/Database/OptionManager.php 1 patch
Indentation   +138 added lines, -138 removed lines patch added patch discarded remove patch
@@ -9,153 +9,153 @@
 block discarded – undo
9 9
 
10 10
 class OptionManager
11 11
 {
12
-    /**
13
-     * @var array
14
-     */
15
-    protected $options;
12
+	/**
13
+	 * @var array
14
+	 */
15
+	protected $options;
16 16
 
17
-    /**
18
-     * @return string
19
-     */
20
-    public static function databaseKey($version = null)
21
-    {
22
-        if (null === $version) {
23
-            $version = explode('.', glsr()->version);
24
-            $version = array_shift($version);
25
-        }
26
-        return Str::snakeCase(
27
-            Application::ID.'-v'.intval($version)
28
-        );
29
-    }
17
+	/**
18
+	 * @return string
19
+	 */
20
+	public static function databaseKey($version = null)
21
+	{
22
+		if (null === $version) {
23
+			$version = explode('.', glsr()->version);
24
+			$version = array_shift($version);
25
+		}
26
+		return Str::snakeCase(
27
+			Application::ID.'-v'.intval($version)
28
+		);
29
+	}
30 30
 
31
-    /**
32
-     * @return array
33
-     */
34
-    public function all()
35
-    {
36
-        if (empty($this->options)) {
37
-            $this->reset();
38
-        }
39
-        return $this->options;
40
-    }
31
+	/**
32
+	 * @return array
33
+	 */
34
+	public function all()
35
+	{
36
+		if (empty($this->options)) {
37
+			$this->reset();
38
+		}
39
+		return $this->options;
40
+	}
41 41
 
42
-    /**
43
-     * @param string $path
44
-     * @return bool
45
-     */
46
-    public function delete($path)
47
-    {
48
-        $keys = explode('.', $path);
49
-        $last = array_pop($keys);
50
-        $options = $this->all();
51
-        $pointer = &$options;
52
-        foreach ($keys as $key) {
53
-            if (!isset($pointer[$key]) || !is_array($pointer[$key])) {
54
-                continue;
55
-            }
56
-            $pointer = &$pointer[$key];
57
-        }
58
-        unset($pointer[$last]);
59
-        return $this->set($options);
60
-    }
42
+	/**
43
+	 * @param string $path
44
+	 * @return bool
45
+	 */
46
+	public function delete($path)
47
+	{
48
+		$keys = explode('.', $path);
49
+		$last = array_pop($keys);
50
+		$options = $this->all();
51
+		$pointer = &$options;
52
+		foreach ($keys as $key) {
53
+			if (!isset($pointer[$key]) || !is_array($pointer[$key])) {
54
+				continue;
55
+			}
56
+			$pointer = &$pointer[$key];
57
+		}
58
+		unset($pointer[$last]);
59
+		return $this->set($options);
60
+	}
61 61
 
62
-    /**
63
-     * @param string $path
64
-     * @param mixed $fallback
65
-     * @param string $cast
66
-     * @return mixed
67
-     */
68
-    public function get($path = '', $fallback = '', $cast = '')
69
-    {
70
-        $result = Arr::get($this->all(), $path, $fallback);
71
-        return Helper::castTo($cast, $result);
72
-    }
62
+	/**
63
+	 * @param string $path
64
+	 * @param mixed $fallback
65
+	 * @param string $cast
66
+	 * @return mixed
67
+	 */
68
+	public function get($path = '', $fallback = '', $cast = '')
69
+	{
70
+		$result = Arr::get($this->all(), $path, $fallback);
71
+		return Helper::castTo($cast, $result);
72
+	}
73 73
 
74
-    /**
75
-     * @param string $path
76
-     * @return bool
77
-     */
78
-    public function getBool($path)
79
-    {
80
-        return Helper::castToBool($this->get($path));
81
-    }
74
+	/**
75
+	 * @param string $path
76
+	 * @return bool
77
+	 */
78
+	public function getBool($path)
79
+	{
80
+		return Helper::castToBool($this->get($path));
81
+	}
82 82
 
83
-    /**
84
-     * @param string $path
85
-     * @param mixed $fallback
86
-     * @param string $cast
87
-     * @return mixed
88
-     */
89
-    public function getWP($path, $fallback = '', $cast = '')
90
-    {
91
-        $option = get_option($path, $fallback);
92
-        if (empty($option)) {
93
-            $option = $fallback;
94
-        }
95
-        return Helper::castTo($cast, $option);
96
-    }
83
+	/**
84
+	 * @param string $path
85
+	 * @param mixed $fallback
86
+	 * @param string $cast
87
+	 * @return mixed
88
+	 */
89
+	public function getWP($path, $fallback = '', $cast = '')
90
+	{
91
+		$option = get_option($path, $fallback);
92
+		if (empty($option)) {
93
+			$option = $fallback;
94
+		}
95
+		return Helper::castTo($cast, $option);
96
+	}
97 97
 
98
-    /**
99
-     * @return string
100
-     */
101
-    public function json()
102
-    {
103
-        return json_encode($this->all());
104
-    }
98
+	/**
99
+	 * @return string
100
+	 */
101
+	public function json()
102
+	{
103
+		return json_encode($this->all());
104
+	}
105 105
 
106
-    /**
107
-     * @return array
108
-     */
109
-    public function normalize(array $options = [])
110
-    {
111
-        $options = wp_parse_args(
112
-            Arr::flattenArray($options),
113
-            glsr(DefaultsManager::class)->defaults()
114
-        );
115
-        array_walk($options, function (&$value) {
116
-            if (!is_string($value)) {
117
-                return;
118
-            }
119
-            $value = wp_kses($value, wp_kses_allowed_html('post'));
120
-        });
121
-        return Arr::convertDotNotationArray($options);
122
-    }
106
+	/**
107
+	 * @return array
108
+	 */
109
+	public function normalize(array $options = [])
110
+	{
111
+		$options = wp_parse_args(
112
+			Arr::flattenArray($options),
113
+			glsr(DefaultsManager::class)->defaults()
114
+		);
115
+		array_walk($options, function (&$value) {
116
+			if (!is_string($value)) {
117
+				return;
118
+			}
119
+			$value = wp_kses($value, wp_kses_allowed_html('post'));
120
+		});
121
+		return Arr::convertDotNotationArray($options);
122
+	}
123 123
 
124
-    /**
125
-     * @return bool
126
-     */
127
-    public function isRecaptchaEnabled()
128
-    {
129
-        $integration = $this->get('settings.submissions.recaptcha.integration');
130
-        return 'all' == $integration || ('guest' == $integration && !is_user_logged_in());
131
-    }
124
+	/**
125
+	 * @return bool
126
+	 */
127
+	public function isRecaptchaEnabled()
128
+	{
129
+		$integration = $this->get('settings.submissions.recaptcha.integration');
130
+		return 'all' == $integration || ('guest' == $integration && !is_user_logged_in());
131
+	}
132 132
 
133
-    /**
134
-     * @return array
135
-     */
136
-    public function reset()
137
-    {
138
-        $options = $this->getWP(static::databaseKey(), []);
139
-        if (!is_array($options) || empty($options)) {
140
-            delete_option(static::databaseKey());
141
-            $options = glsr()->defaults ?: [];
142
-        }
143
-        $this->options = $options;
144
-    }
133
+	/**
134
+	 * @return array
135
+	 */
136
+	public function reset()
137
+	{
138
+		$options = $this->getWP(static::databaseKey(), []);
139
+		if (!is_array($options) || empty($options)) {
140
+			delete_option(static::databaseKey());
141
+			$options = glsr()->defaults ?: [];
142
+		}
143
+		$this->options = $options;
144
+	}
145 145
 
146
-    /**
147
-     * @param string|array $pathOrOptions
148
-     * @param mixed $value
149
-     * @return bool
150
-     */
151
-    public function set($pathOrOptions, $value = '')
152
-    {
153
-        if (is_string($pathOrOptions)) {
154
-            $pathOrOptions = Arr::set($this->all(), $pathOrOptions, $value);
155
-        }
156
-        if ($result = update_option(static::databaseKey(), (array) $pathOrOptions)) {
157
-            $this->reset();
158
-        }
159
-        return $result;
160
-    }
146
+	/**
147
+	 * @param string|array $pathOrOptions
148
+	 * @param mixed $value
149
+	 * @return bool
150
+	 */
151
+	public function set($pathOrOptions, $value = '')
152
+	{
153
+		if (is_string($pathOrOptions)) {
154
+			$pathOrOptions = Arr::set($this->all(), $pathOrOptions, $value);
155
+		}
156
+		if ($result = update_option(static::databaseKey(), (array) $pathOrOptions)) {
157
+			$this->reset();
158
+		}
159
+		return $result;
160
+	}
161 161
 }
Please login to merge, or discard this patch.
plugin/Helper.php 1 patch
Indentation   +174 added lines, -174 removed lines patch added patch discarded remove patch
@@ -8,178 +8,178 @@
 block discarded – undo
8 8
 
9 9
 class Helper
10 10
 {
11
-    /**
12
-     * @param string $name
13
-     * @param string $path
14
-     * @return string
15
-     */
16
-    public static function buildClassName($name, $path = '')
17
-    {
18
-        $className = Str::camelCase($name);
19
-        $path = ltrim(str_replace(__NAMESPACE__, '', $path), '\\');
20
-        return !empty($path)
21
-            ? __NAMESPACE__.'\\'.$path.'\\'.$className
22
-            : $className;
23
-    }
24
-
25
-    /**
26
-     * @param string $name
27
-     * @param string $prefix
28
-     * @return string
29
-     */
30
-    public static function buildMethodName($name, $prefix = '')
31
-    {
32
-        return lcfirst($prefix.static::buildClassName($name));
33
-    }
34
-
35
-    /**
36
-     * @param string $name
37
-     * @return string
38
-     */
39
-    public static function buildPropertyName($name)
40
-    {
41
-        return static::buildMethodName($name);
42
-    }
43
-
44
-    /**
45
-     * @param string $cast
46
-     * @param mixed $value
47
-     * @return mixed
48
-     */
49
-    public static function castTo($cast = '', $value)
50
-    {
51
-        $method = static::buildMethodName($cast, 'castTo');
52
-        return !empty($cast) && method_exists(__CLASS__, $method)
53
-            ? static::$method($value)
54
-            : $value;
55
-    }
56
-
57
-    /**
58
-     * @param mixed $value
59
-     * @return array
60
-     */
61
-    public static function castToArray($value)
62
-    {
63
-        return (array) $value;
64
-    }
65
-
66
-    /**
67
-     * @param mixed $value
68
-     * @return bool
69
-     */
70
-    public static function castToBool($value)
71
-    {
72
-        return filter_var($value, FILTER_VALIDATE_BOOLEAN);
73
-    }
74
-
75
-    /**
76
-     * @param mixed $value
77
-     * @return float
78
-     */
79
-    public static function castToFloat($value)
80
-    {
81
-        return (float) filter_var($value, FILTER_VALIDATE_FLOAT, FILTER_FLAG_ALLOW_THOUSAND);
82
-    }
83
-
84
-    /**
85
-     * @param mixed $value
86
-     * @return int
87
-     */
88
-    public static function castToInt($value)
89
-    {
90
-        return (int) filter_var($value, FILTER_VALIDATE_INT);
91
-    }
92
-
93
-    /**
94
-     * @param mixed $value
95
-     * @return object
96
-     */
97
-    public static function castToObject($value)
98
-    {
99
-        return (object) (array) $value;
100
-    }
101
-
102
-    /**
103
-     * @param mixed $value
104
-     * @return string
105
-     */
106
-    public static function castToString($value)
107
-    {
108
-        if (is_object($value) && in_array('__toString', get_class_methods($value))) {
109
-            return (string) $value->__toString();
110
-        }
111
-        if (is_array($value) || is_object($value)) {
112
-            return serialize($value);
113
-        }
114
-        return (string) $value;
115
-    }
116
-
117
-    /**
118
-     * @param string $key
119
-     * @return mixed
120
-     */
121
-    public static function filterInput($key, array $request = [])
122
-    {
123
-        if (isset($request[$key])) {
124
-            return $request[$key];
125
-        }
126
-        $variable = filter_input(INPUT_POST, $key);
127
-        if (is_null($variable) && isset($_POST[$key])) {
128
-            $variable = $_POST[$key];
129
-        }
130
-        return $variable;
131
-    }
132
-
133
-    /**
134
-     * @param string $key
135
-     * @return array
136
-     */
137
-    public static function filterInputArray($key)
138
-    {
139
-        $variable = filter_input(INPUT_POST, $key, FILTER_DEFAULT, FILTER_REQUIRE_ARRAY);
140
-        if (empty($variable) && !empty($_POST[$key]) && is_array($_POST[$key])) {
141
-            $variable = $_POST[$key];
142
-        }
143
-        return (array) $variable;
144
-    }
145
-
146
-    /**
147
-     * @return string
148
-     */
149
-    public static function getIpAddress()
150
-    {
151
-        $whitelist = [];
152
-        $isUsingCloudflare = !empty(filter_input(INPUT_SERVER, 'CF-Connecting-IP'));
153
-        if (apply_filters('site-reviews/whip/whitelist/cloudflare', $isUsingCloudflare)) {
154
-            $cloudflareIps = glsr(Cache::class)->getCloudflareIps();
155
-            $whitelist[Whip::CLOUDFLARE_HEADERS] = [Whip::IPV4 => $cloudflareIps['v4']];
156
-            if (defined('AF_INET6')) {
157
-                $whitelist[Whip::CLOUDFLARE_HEADERS][Whip::IPV6] = $cloudflareIps['v6'];
158
-            }
159
-        }
160
-        $whitelist = apply_filters('site-reviews/whip/whitelist', $whitelist);
161
-        $methods = apply_filters('site-reviews/whip/methods', Whip::ALL_METHODS);
162
-        $whip = new Whip($methods, $whitelist);
163
-        do_action_ref_array('site-reviews/whip', [$whip]);
164
-        if (false !== ($clientAddress = $whip->getValidIpAddress())) {
165
-            return (string) $clientAddress;
166
-        }
167
-        glsr_log()->error('Unable to detect IP address.');
168
-        return 'unknown';
169
-    }
170
-
171
-    /**
172
-     * @param mixed $value
173
-     * @param string|int $min
174
-     * @param string|int $max
175
-     * @return bool
176
-     */
177
-    public static function inRange($value, $min, $max)
178
-    {
179
-        $inRange = filter_var($value, FILTER_VALIDATE_INT, ['options' => [
180
-            'min_range' => intval($min),
181
-            'max_range' => intval($max),
182
-        ]]);
183
-        return false !== $inRange;
184
-    }
11
+	/**
12
+	 * @param string $name
13
+	 * @param string $path
14
+	 * @return string
15
+	 */
16
+	public static function buildClassName($name, $path = '')
17
+	{
18
+		$className = Str::camelCase($name);
19
+		$path = ltrim(str_replace(__NAMESPACE__, '', $path), '\\');
20
+		return !empty($path)
21
+			? __NAMESPACE__.'\\'.$path.'\\'.$className
22
+			: $className;
23
+	}
24
+
25
+	/**
26
+	 * @param string $name
27
+	 * @param string $prefix
28
+	 * @return string
29
+	 */
30
+	public static function buildMethodName($name, $prefix = '')
31
+	{
32
+		return lcfirst($prefix.static::buildClassName($name));
33
+	}
34
+
35
+	/**
36
+	 * @param string $name
37
+	 * @return string
38
+	 */
39
+	public static function buildPropertyName($name)
40
+	{
41
+		return static::buildMethodName($name);
42
+	}
43
+
44
+	/**
45
+	 * @param string $cast
46
+	 * @param mixed $value
47
+	 * @return mixed
48
+	 */
49
+	public static function castTo($cast = '', $value)
50
+	{
51
+		$method = static::buildMethodName($cast, 'castTo');
52
+		return !empty($cast) && method_exists(__CLASS__, $method)
53
+			? static::$method($value)
54
+			: $value;
55
+	}
56
+
57
+	/**
58
+	 * @param mixed $value
59
+	 * @return array
60
+	 */
61
+	public static function castToArray($value)
62
+	{
63
+		return (array) $value;
64
+	}
65
+
66
+	/**
67
+	 * @param mixed $value
68
+	 * @return bool
69
+	 */
70
+	public static function castToBool($value)
71
+	{
72
+		return filter_var($value, FILTER_VALIDATE_BOOLEAN);
73
+	}
74
+
75
+	/**
76
+	 * @param mixed $value
77
+	 * @return float
78
+	 */
79
+	public static function castToFloat($value)
80
+	{
81
+		return (float) filter_var($value, FILTER_VALIDATE_FLOAT, FILTER_FLAG_ALLOW_THOUSAND);
82
+	}
83
+
84
+	/**
85
+	 * @param mixed $value
86
+	 * @return int
87
+	 */
88
+	public static function castToInt($value)
89
+	{
90
+		return (int) filter_var($value, FILTER_VALIDATE_INT);
91
+	}
92
+
93
+	/**
94
+	 * @param mixed $value
95
+	 * @return object
96
+	 */
97
+	public static function castToObject($value)
98
+	{
99
+		return (object) (array) $value;
100
+	}
101
+
102
+	/**
103
+	 * @param mixed $value
104
+	 * @return string
105
+	 */
106
+	public static function castToString($value)
107
+	{
108
+		if (is_object($value) && in_array('__toString', get_class_methods($value))) {
109
+			return (string) $value->__toString();
110
+		}
111
+		if (is_array($value) || is_object($value)) {
112
+			return serialize($value);
113
+		}
114
+		return (string) $value;
115
+	}
116
+
117
+	/**
118
+	 * @param string $key
119
+	 * @return mixed
120
+	 */
121
+	public static function filterInput($key, array $request = [])
122
+	{
123
+		if (isset($request[$key])) {
124
+			return $request[$key];
125
+		}
126
+		$variable = filter_input(INPUT_POST, $key);
127
+		if (is_null($variable) && isset($_POST[$key])) {
128
+			$variable = $_POST[$key];
129
+		}
130
+		return $variable;
131
+	}
132
+
133
+	/**
134
+	 * @param string $key
135
+	 * @return array
136
+	 */
137
+	public static function filterInputArray($key)
138
+	{
139
+		$variable = filter_input(INPUT_POST, $key, FILTER_DEFAULT, FILTER_REQUIRE_ARRAY);
140
+		if (empty($variable) && !empty($_POST[$key]) && is_array($_POST[$key])) {
141
+			$variable = $_POST[$key];
142
+		}
143
+		return (array) $variable;
144
+	}
145
+
146
+	/**
147
+	 * @return string
148
+	 */
149
+	public static function getIpAddress()
150
+	{
151
+		$whitelist = [];
152
+		$isUsingCloudflare = !empty(filter_input(INPUT_SERVER, 'CF-Connecting-IP'));
153
+		if (apply_filters('site-reviews/whip/whitelist/cloudflare', $isUsingCloudflare)) {
154
+			$cloudflareIps = glsr(Cache::class)->getCloudflareIps();
155
+			$whitelist[Whip::CLOUDFLARE_HEADERS] = [Whip::IPV4 => $cloudflareIps['v4']];
156
+			if (defined('AF_INET6')) {
157
+				$whitelist[Whip::CLOUDFLARE_HEADERS][Whip::IPV6] = $cloudflareIps['v6'];
158
+			}
159
+		}
160
+		$whitelist = apply_filters('site-reviews/whip/whitelist', $whitelist);
161
+		$methods = apply_filters('site-reviews/whip/methods', Whip::ALL_METHODS);
162
+		$whip = new Whip($methods, $whitelist);
163
+		do_action_ref_array('site-reviews/whip', [$whip]);
164
+		if (false !== ($clientAddress = $whip->getValidIpAddress())) {
165
+			return (string) $clientAddress;
166
+		}
167
+		glsr_log()->error('Unable to detect IP address.');
168
+		return 'unknown';
169
+	}
170
+
171
+	/**
172
+	 * @param mixed $value
173
+	 * @param string|int $min
174
+	 * @param string|int $max
175
+	 * @return bool
176
+	 */
177
+	public static function inRange($value, $min, $max)
178
+	{
179
+		$inRange = filter_var($value, FILTER_VALIDATE_INT, ['options' => [
180
+			'min_range' => intval($min),
181
+			'max_range' => intval($max),
182
+		]]);
183
+		return false !== $inRange;
184
+	}
185 185
 }
Please login to merge, or discard this patch.
plugin/Modules/Validator/ValidateReview.php 1 patch
Indentation   +272 added lines, -272 removed lines patch added patch discarded remove patch
@@ -13,299 +13,299 @@
 block discarded – undo
13 13
 
14 14
 class ValidateReview
15 15
 {
16
-    const RECAPTCHA_ENDPOINT = 'https://www.google.com/recaptcha/api/siteverify';
16
+	const RECAPTCHA_ENDPOINT = 'https://www.google.com/recaptcha/api/siteverify';
17 17
 
18
-    const RECAPTCHA_DISABLED = 0;
19
-    const RECAPTCHA_EMPTY = 1;
20
-    const RECAPTCHA_FAILED = 2;
21
-    const RECAPTCHA_INVALID = 3;
22
-    const RECAPTCHA_VALID = 4;
18
+	const RECAPTCHA_DISABLED = 0;
19
+	const RECAPTCHA_EMPTY = 1;
20
+	const RECAPTCHA_FAILED = 2;
21
+	const RECAPTCHA_INVALID = 3;
22
+	const RECAPTCHA_VALID = 4;
23 23
 
24
-    const VALIDATION_RULES = [
25
-        'content' => 'required',
26
-        'email' => 'required|email',
27
-        'name' => 'required',
28
-        'rating' => 'required|number|between:1,5',
29
-        'terms' => 'accepted',
30
-        'title' => 'required',
31
-    ];
24
+	const VALIDATION_RULES = [
25
+		'content' => 'required',
26
+		'email' => 'required|email',
27
+		'name' => 'required',
28
+		'rating' => 'required|number|between:1,5',
29
+		'terms' => 'accepted',
30
+		'title' => 'required',
31
+	];
32 32
 
33
-    /**
34
-     * @var string|void
35
-     */
36
-    public $error;
33
+	/**
34
+	 * @var string|void
35
+	 */
36
+	public $error;
37 37
 
38
-    /**
39
-     * @var string
40
-     */
41
-    public $form_id;
38
+	/**
39
+	 * @var string
40
+	 */
41
+	public $form_id;
42 42
 
43
-    /**
44
-     * @var bool
45
-     */
46
-    public $recaptchaIsUnset = false;
43
+	/**
44
+	 * @var bool
45
+	 */
46
+	public $recaptchaIsUnset = false;
47 47
 
48
-    /**
49
-     * @var array
50
-     */
51
-    public $request;
48
+	/**
49
+	 * @var array
50
+	 */
51
+	public $request;
52 52
 
53
-    /**
54
-     * @var array
55
-     */
56
-    protected $options;
53
+	/**
54
+	 * @var array
55
+	 */
56
+	protected $options;
57 57
 
58
-    /**
59
-     * @return static
60
-     */
61
-    public function validate(array $request)
62
-    {
63
-        $request['ip_address'] = Helper::getIpAddress(); // required for Akismet and Blacklist validation
64
-        $this->form_id = $request['form_id'];
65
-        $this->options = glsr(OptionManager::class)->all();
66
-        $this->request = $this->validateRequest($request);
67
-        $this->validateCustom();
68
-        $this->validatePermission();
69
-        $this->validateHoneyPot();
70
-        $this->validateReviewLimits();
71
-        $this->validateBlacklist();
72
-        $this->validateAkismet();
73
-        $this->validateRecaptcha();
74
-        if (!empty($this->error)) {
75
-            $this->setSessionValues('message', $this->error);
76
-        }
77
-        return $this;
78
-    }
58
+	/**
59
+	 * @return static
60
+	 */
61
+	public function validate(array $request)
62
+	{
63
+		$request['ip_address'] = Helper::getIpAddress(); // required for Akismet and Blacklist validation
64
+		$this->form_id = $request['form_id'];
65
+		$this->options = glsr(OptionManager::class)->all();
66
+		$this->request = $this->validateRequest($request);
67
+		$this->validateCustom();
68
+		$this->validatePermission();
69
+		$this->validateHoneyPot();
70
+		$this->validateReviewLimits();
71
+		$this->validateBlacklist();
72
+		$this->validateAkismet();
73
+		$this->validateRecaptcha();
74
+		if (!empty($this->error)) {
75
+			$this->setSessionValues('message', $this->error);
76
+		}
77
+		return $this;
78
+	}
79 79
 
80
-    /**
81
-     * @param string $path
82
-     * @param mixed $fallback
83
-     * @return mixed
84
-     */
85
-    protected function getOption($path, $fallback = '')
86
-    {
87
-        return Arr::get($this->options, $path, $fallback);
88
-    }
80
+	/**
81
+	 * @param string $path
82
+	 * @param mixed $fallback
83
+	 * @return mixed
84
+	 */
85
+	protected function getOption($path, $fallback = '')
86
+	{
87
+		return Arr::get($this->options, $path, $fallback);
88
+	}
89 89
 
90
-    /**
91
-     * @return int
92
-     */
93
-    protected function getRecaptchaStatus()
94
-    {
95
-        if (!glsr(OptionManager::class)->isRecaptchaEnabled()) {
96
-            return static::RECAPTCHA_DISABLED;
97
-        }
98
-        if (empty($this->request['_recaptcha-token'])) {
99
-            return $this->request['_counter'] < intval(apply_filters('site-reviews/recaptcha/timeout', 5))
100
-                ? static::RECAPTCHA_EMPTY
101
-                : static::RECAPTCHA_FAILED;
102
-        }
103
-        return $this->getRecaptchaTokenStatus();
104
-    }
90
+	/**
91
+	 * @return int
92
+	 */
93
+	protected function getRecaptchaStatus()
94
+	{
95
+		if (!glsr(OptionManager::class)->isRecaptchaEnabled()) {
96
+			return static::RECAPTCHA_DISABLED;
97
+		}
98
+		if (empty($this->request['_recaptcha-token'])) {
99
+			return $this->request['_counter'] < intval(apply_filters('site-reviews/recaptcha/timeout', 5))
100
+				? static::RECAPTCHA_EMPTY
101
+				: static::RECAPTCHA_FAILED;
102
+		}
103
+		return $this->getRecaptchaTokenStatus();
104
+	}
105 105
 
106
-    /**
107
-     * @return int
108
-     */
109
-    protected function getRecaptchaTokenStatus()
110
-    {
111
-        $endpoint = add_query_arg([
112
-            'remoteip' => Helper::getIpAddress(),
113
-            'response' => $this->request['_recaptcha-token'],
114
-            'secret' => $this->getOption('settings.submissions.recaptcha.secret'),
115
-        ], static::RECAPTCHA_ENDPOINT);
116
-        if (is_wp_error($response = wp_remote_get($endpoint))) {
117
-            glsr_log()->error($response->get_error_message());
118
-            return static::RECAPTCHA_FAILED;
119
-        }
120
-        $response = json_decode(wp_remote_retrieve_body($response));
121
-        if (!empty($response->success)) {
122
-            return boolval($response->success)
123
-                ? static::RECAPTCHA_VALID
124
-                : static::RECAPTCHA_INVALID;
125
-        }
126
-        foreach ($response->{'error-codes'} as $error) {
127
-            glsr_log()->error('reCAPTCHA error: '.$error);
128
-        }
129
-        return static::RECAPTCHA_INVALID;
130
-    }
106
+	/**
107
+	 * @return int
108
+	 */
109
+	protected function getRecaptchaTokenStatus()
110
+	{
111
+		$endpoint = add_query_arg([
112
+			'remoteip' => Helper::getIpAddress(),
113
+			'response' => $this->request['_recaptcha-token'],
114
+			'secret' => $this->getOption('settings.submissions.recaptcha.secret'),
115
+		], static::RECAPTCHA_ENDPOINT);
116
+		if (is_wp_error($response = wp_remote_get($endpoint))) {
117
+			glsr_log()->error($response->get_error_message());
118
+			return static::RECAPTCHA_FAILED;
119
+		}
120
+		$response = json_decode(wp_remote_retrieve_body($response));
121
+		if (!empty($response->success)) {
122
+			return boolval($response->success)
123
+				? static::RECAPTCHA_VALID
124
+				: static::RECAPTCHA_INVALID;
125
+		}
126
+		foreach ($response->{'error-codes'} as $error) {
127
+			glsr_log()->error('reCAPTCHA error: '.$error);
128
+		}
129
+		return static::RECAPTCHA_INVALID;
130
+	}
131 131
 
132
-    /**
133
-     * @return array
134
-     */
135
-    protected function getValidationRules(array $request)
136
-    {
137
-        $rules = array_intersect_key(
138
-            apply_filters('site-reviews/validation/rules', static::VALIDATION_RULES, $request),
139
-            array_flip($this->getOption('settings.submissions.required', []))
140
-        );
141
-        $excluded = explode(',', Arr::get($request, 'excluded'));
142
-        return array_diff_key($rules, array_flip($excluded));
143
-    }
132
+	/**
133
+	 * @return array
134
+	 */
135
+	protected function getValidationRules(array $request)
136
+	{
137
+		$rules = array_intersect_key(
138
+			apply_filters('site-reviews/validation/rules', static::VALIDATION_RULES, $request),
139
+			array_flip($this->getOption('settings.submissions.required', []))
140
+		);
141
+		$excluded = explode(',', Arr::get($request, 'excluded'));
142
+		return array_diff_key($rules, array_flip($excluded));
143
+	}
144 144
 
145
-    /**
146
-     * @return bool
147
-     */
148
-    protected function isRequestValid(array $request)
149
-    {
150
-        $rules = $this->getValidationRules($request);
151
-        $errors = glsr(Validator::class)->validate($request, $rules);
152
-        if (empty($errors)) {
153
-            return true;
154
-        }
155
-        $this->error = __('Please fix the submission errors.', 'site-reviews');
156
-        $this->setSessionValues('errors', $errors);
157
-        $this->setSessionValues('values', $request);
158
-        return false;
159
-    }
145
+	/**
146
+	 * @return bool
147
+	 */
148
+	protected function isRequestValid(array $request)
149
+	{
150
+		$rules = $this->getValidationRules($request);
151
+		$errors = glsr(Validator::class)->validate($request, $rules);
152
+		if (empty($errors)) {
153
+			return true;
154
+		}
155
+		$this->error = __('Please fix the submission errors.', 'site-reviews');
156
+		$this->setSessionValues('errors', $errors);
157
+		$this->setSessionValues('values', $request);
158
+		return false;
159
+	}
160 160
 
161
-    protected function setError($message, $loggedMessage = '')
162
-    {
163
-        $this->setSessionValues('errors', [], $loggedMessage);
164
-        $this->error = $message;
165
-    }
161
+	protected function setError($message, $loggedMessage = '')
162
+	{
163
+		$this->setSessionValues('errors', [], $loggedMessage);
164
+		$this->error = $message;
165
+	}
166 166
 
167
-    /**
168
-     * @param string $type
169
-     * @param mixed $value
170
-     * @param string $loggedMessage
171
-     * @return void
172
-     */
173
-    protected function setSessionValues($type, $value, $loggedMessage = '')
174
-    {
175
-        glsr()->sessionSet($this->form_id.$type, $value);
176
-        if (!empty($loggedMessage)) {
177
-            glsr_log()->warning($loggedMessage)->debug($this->request);
178
-        }
179
-    }
167
+	/**
168
+	 * @param string $type
169
+	 * @param mixed $value
170
+	 * @param string $loggedMessage
171
+	 * @return void
172
+	 */
173
+	protected function setSessionValues($type, $value, $loggedMessage = '')
174
+	{
175
+		glsr()->sessionSet($this->form_id.$type, $value);
176
+		if (!empty($loggedMessage)) {
177
+			glsr_log()->warning($loggedMessage)->debug($this->request);
178
+		}
179
+	}
180 180
 
181
-    /**
182
-     * @return void
183
-     */
184
-    protected function validateAkismet()
185
-    {
186
-        if (!empty($this->error)) {
187
-            return;
188
-        }
189
-        if (glsr(Akismet::class)->isSpam($this->request)) {
190
-            $this->setError(__('This review has been flagged as possible spam and cannot be submitted.', 'site-reviews'),
191
-                'Akismet caught a spam submission (consider adding the IP address to the blacklist):'
192
-            );
193
-        }
194
-    }
181
+	/**
182
+	 * @return void
183
+	 */
184
+	protected function validateAkismet()
185
+	{
186
+		if (!empty($this->error)) {
187
+			return;
188
+		}
189
+		if (glsr(Akismet::class)->isSpam($this->request)) {
190
+			$this->setError(__('This review has been flagged as possible spam and cannot be submitted.', 'site-reviews'),
191
+				'Akismet caught a spam submission (consider adding the IP address to the blacklist):'
192
+			);
193
+		}
194
+	}
195 195
 
196
-    /**
197
-     * @return void
198
-     */
199
-    protected function validateBlacklist()
200
-    {
201
-        if (!empty($this->error)) {
202
-            return;
203
-        }
204
-        if (!glsr(Blacklist::class)->isBlacklisted($this->request)) {
205
-            return;
206
-        }
207
-        $blacklistAction = $this->getOption('settings.submissions.blacklist.action');
208
-        if ('reject' != $blacklistAction) {
209
-            $this->request['blacklisted'] = true;
210
-            return;
211
-        }
212
-        $this->setError(__('Your review cannot be submitted at this time.', 'site-reviews'),
213
-            'Blacklisted submission detected:'
214
-        );
215
-    }
196
+	/**
197
+	 * @return void
198
+	 */
199
+	protected function validateBlacklist()
200
+	{
201
+		if (!empty($this->error)) {
202
+			return;
203
+		}
204
+		if (!glsr(Blacklist::class)->isBlacklisted($this->request)) {
205
+			return;
206
+		}
207
+		$blacklistAction = $this->getOption('settings.submissions.blacklist.action');
208
+		if ('reject' != $blacklistAction) {
209
+			$this->request['blacklisted'] = true;
210
+			return;
211
+		}
212
+		$this->setError(__('Your review cannot be submitted at this time.', 'site-reviews'),
213
+			'Blacklisted submission detected:'
214
+		);
215
+	}
216 216
 
217
-    /**
218
-     * @return void
219
-     */
220
-    protected function validateCustom()
221
-    {
222
-        if (!empty($this->error)) {
223
-            return;
224
-        }
225
-        $validated = apply_filters('site-reviews/validate/custom', true, $this->request);
226
-        if (true === $validated) {
227
-            return;
228
-        }
229
-        $errorMessage = is_string($validated)
230
-            ? $validated
231
-            : __('The review submission failed. Please notify the site administrator.', 'site-reviews');
232
-        $this->setError($errorMessage);
233
-        $this->setSessionValues('values', $this->request);
234
-    }
217
+	/**
218
+	 * @return void
219
+	 */
220
+	protected function validateCustom()
221
+	{
222
+		if (!empty($this->error)) {
223
+			return;
224
+		}
225
+		$validated = apply_filters('site-reviews/validate/custom', true, $this->request);
226
+		if (true === $validated) {
227
+			return;
228
+		}
229
+		$errorMessage = is_string($validated)
230
+			? $validated
231
+			: __('The review submission failed. Please notify the site administrator.', 'site-reviews');
232
+		$this->setError($errorMessage);
233
+		$this->setSessionValues('values', $this->request);
234
+	}
235 235
 
236
-    /**
237
-     * @return void
238
-     */
239
-    protected function validateHoneyPot()
240
-    {
241
-        if (!empty($this->error)) {
242
-            return;
243
-        }
244
-        if (!empty($this->request['gotcha'])) {
245
-            $this->setError(__('The review submission failed. Please notify the site administrator.', 'site-reviews'),
246
-                'The Honeypot caught a bad submission:'
247
-            );
248
-        }
249
-    }
236
+	/**
237
+	 * @return void
238
+	 */
239
+	protected function validateHoneyPot()
240
+	{
241
+		if (!empty($this->error)) {
242
+			return;
243
+		}
244
+		if (!empty($this->request['gotcha'])) {
245
+			$this->setError(__('The review submission failed. Please notify the site administrator.', 'site-reviews'),
246
+				'The Honeypot caught a bad submission:'
247
+			);
248
+		}
249
+	}
250 250
 
251
-    /**
252
-     * @return void
253
-     */
254
-    protected function validatePermission()
255
-    {
256
-        if (!empty($this->error)) {
257
-            return;
258
-        }
259
-        if (!is_user_logged_in() && glsr(OptionManager::class)->getBool('settings.general.require.login')) {
260
-            $this->setError(__('You must be logged in to submit a review.', 'site-reviews'));
261
-        }
262
-    }
251
+	/**
252
+	 * @return void
253
+	 */
254
+	protected function validatePermission()
255
+	{
256
+		if (!empty($this->error)) {
257
+			return;
258
+		}
259
+		if (!is_user_logged_in() && glsr(OptionManager::class)->getBool('settings.general.require.login')) {
260
+			$this->setError(__('You must be logged in to submit a review.', 'site-reviews'));
261
+		}
262
+	}
263 263
 
264
-    /**
265
-     * @return void
266
-     */
267
-    protected function validateReviewLimits()
268
-    {
269
-        if (!empty($this->error)) {
270
-            return;
271
-        }
272
-        if (glsr(ReviewLimits::class)->hasReachedLimit($this->request)) {
273
-            $this->setError(__('You have already submitted a review.', 'site-reviews'));
274
-        }
275
-    }
264
+	/**
265
+	 * @return void
266
+	 */
267
+	protected function validateReviewLimits()
268
+	{
269
+		if (!empty($this->error)) {
270
+			return;
271
+		}
272
+		if (glsr(ReviewLimits::class)->hasReachedLimit($this->request)) {
273
+			$this->setError(__('You have already submitted a review.', 'site-reviews'));
274
+		}
275
+	}
276 276
 
277
-    /**
278
-     * @return void
279
-     */
280
-    protected function validateRecaptcha()
281
-    {
282
-        if (!empty($this->error)) {
283
-            return;
284
-        }
285
-        $status = $this->getRecaptchaStatus();
286
-        if (in_array($status, [static::RECAPTCHA_DISABLED, static::RECAPTCHA_VALID])) {
287
-            return;
288
-        }
289
-        if (static::RECAPTCHA_EMPTY === $status) {
290
-            $this->setSessionValues('recaptcha', 'unset');
291
-            $this->recaptchaIsUnset = true;
292
-            return;
293
-        }
294
-        $this->setSessionValues('recaptcha', 'reset');
295
-        $errors = [
296
-            static::RECAPTCHA_FAILED => __('The reCAPTCHA failed to load, please refresh the page and try again.', 'site-reviews'),
297
-            static::RECAPTCHA_INVALID => __('The reCAPTCHA verification failed, please try again.', 'site-reviews'),
298
-        ];
299
-        $this->setError($errors[$status]);
300
-    }
277
+	/**
278
+	 * @return void
279
+	 */
280
+	protected function validateRecaptcha()
281
+	{
282
+		if (!empty($this->error)) {
283
+			return;
284
+		}
285
+		$status = $this->getRecaptchaStatus();
286
+		if (in_array($status, [static::RECAPTCHA_DISABLED, static::RECAPTCHA_VALID])) {
287
+			return;
288
+		}
289
+		if (static::RECAPTCHA_EMPTY === $status) {
290
+			$this->setSessionValues('recaptcha', 'unset');
291
+			$this->recaptchaIsUnset = true;
292
+			return;
293
+		}
294
+		$this->setSessionValues('recaptcha', 'reset');
295
+		$errors = [
296
+			static::RECAPTCHA_FAILED => __('The reCAPTCHA failed to load, please refresh the page and try again.', 'site-reviews'),
297
+			static::RECAPTCHA_INVALID => __('The reCAPTCHA verification failed, please try again.', 'site-reviews'),
298
+		];
299
+		$this->setError($errors[$status]);
300
+	}
301 301
 
302
-    /**
303
-     * @return array
304
-     */
305
-    protected function validateRequest(array $request)
306
-    {
307
-        return $this->isRequestValid($request)
308
-            ? array_merge(glsr(ValidateReviewDefaults::class)->defaults(), $request)
309
-            : $request;
310
-    }
302
+	/**
303
+	 * @return array
304
+	 */
305
+	protected function validateRequest(array $request)
306
+	{
307
+		return $this->isRequestValid($request)
308
+			? array_merge(glsr(ValidateReviewDefaults::class)->defaults(), $request)
309
+			: $request;
310
+	}
311 311
 }
Please login to merge, or discard this patch.
plugin/Modules/Schema.php 1 patch
Indentation   +308 added lines, -308 removed lines patch added patch discarded remove patch
@@ -12,335 +12,335 @@
 block discarded – undo
12 12
 
13 13
 class Schema
14 14
 {
15
-    /**
16
-     * @var array
17
-     */
18
-    protected $args;
15
+	/**
16
+	 * @var array
17
+	 */
18
+	protected $args;
19 19
 
20
-    /**
21
-     * @var array
22
-     */
23
-    protected $keyValues = [];
20
+	/**
21
+	 * @var array
22
+	 */
23
+	protected $keyValues = [];
24 24
 
25
-    /**
26
-     * @var array
27
-     */
28
-    protected $ratingCounts;
25
+	/**
26
+	 * @var array
27
+	 */
28
+	protected $ratingCounts;
29 29
 
30
-    /**
31
-     * @return array
32
-     */
33
-    public function build(array $args = [])
34
-    {
35
-        $this->args = $args;
36
-        $schema = $this->buildSummary($args);
37
-        if (!empty($schema)) {
38
-            $reviews = $this->buildReviews();
39
-            $reviews = array_walk($reviews, function (&$review) {
40
-                unset($review['@context']);
41
-                unset($review['itemReviewed']);
42
-            });
43
-        }
44
-        if (!empty($reviews)) {
45
-            $schema['review'] = $reviews;
46
-        }
47
-        return $schema;
48
-    }
30
+	/**
31
+	 * @return array
32
+	 */
33
+	public function build(array $args = [])
34
+	{
35
+		$this->args = $args;
36
+		$schema = $this->buildSummary($args);
37
+		if (!empty($schema)) {
38
+			$reviews = $this->buildReviews();
39
+			$reviews = array_walk($reviews, function (&$review) {
40
+				unset($review['@context']);
41
+				unset($review['itemReviewed']);
42
+			});
43
+		}
44
+		if (!empty($reviews)) {
45
+			$schema['review'] = $reviews;
46
+		}
47
+		return $schema;
48
+	}
49 49
 
50
-    /**
51
-     * @param array|null $args
52
-     * @return array
53
-     */
54
-    public function buildSummary($args = null)
55
-    {
56
-        if (is_array($args)) {
57
-            $this->args = $args;
58
-        }
59
-        $buildSummary = Helper::buildMethodName($this->getSchemaOptionValue('type'), 'buildSummaryFor');
60
-        if ($count = array_sum($this->getRatingCounts())) {
61
-            $schema = method_exists($this, $buildSummary)
62
-                ? $this->$buildSummary()
63
-                : $this->buildSummaryForCustom();
64
-            $schema->aggregateRating(
65
-                $this->getSchemaType('AggregateRating')
66
-                    ->ratingValue($this->getRatingValue())
67
-                    ->reviewCount($count)
68
-                    ->bestRating(glsr()->constant('MAX_RATING', Rating::class))
69
-                    ->worstRating(glsr()->constant('MIN_RATING', Rating::class))
70
-            );
71
-            $schema = $schema->toArray();
72
-            return apply_filters('site-reviews/schema/'.$schema['@type'], $schema, $args);
73
-        }
74
-        return [];
75
-    }
50
+	/**
51
+	 * @param array|null $args
52
+	 * @return array
53
+	 */
54
+	public function buildSummary($args = null)
55
+	{
56
+		if (is_array($args)) {
57
+			$this->args = $args;
58
+		}
59
+		$buildSummary = Helper::buildMethodName($this->getSchemaOptionValue('type'), 'buildSummaryFor');
60
+		if ($count = array_sum($this->getRatingCounts())) {
61
+			$schema = method_exists($this, $buildSummary)
62
+				? $this->$buildSummary()
63
+				: $this->buildSummaryForCustom();
64
+			$schema->aggregateRating(
65
+				$this->getSchemaType('AggregateRating')
66
+					->ratingValue($this->getRatingValue())
67
+					->reviewCount($count)
68
+					->bestRating(glsr()->constant('MAX_RATING', Rating::class))
69
+					->worstRating(glsr()->constant('MIN_RATING', Rating::class))
70
+			);
71
+			$schema = $schema->toArray();
72
+			return apply_filters('site-reviews/schema/'.$schema['@type'], $schema, $args);
73
+		}
74
+		return [];
75
+	}
76 76
 
77
-    /**
78
-     * @return void
79
-     */
80
-    public function render()
81
-    {
82
-        if (empty(glsr()->schemas)) {
83
-            return;
84
-        }
85
-        printf('<script type="application/ld+json">%s</script>', json_encode(
86
-            apply_filters('site-reviews/schema/all', glsr()->schemas),
87
-            JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES
88
-        ));
89
-    }
77
+	/**
78
+	 * @return void
79
+	 */
80
+	public function render()
81
+	{
82
+		if (empty(glsr()->schemas)) {
83
+			return;
84
+		}
85
+		printf('<script type="application/ld+json">%s</script>', json_encode(
86
+			apply_filters('site-reviews/schema/all', glsr()->schemas),
87
+			JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES
88
+		));
89
+	}
90 90
 
91
-    /**
92
-     * @return void
93
-     */
94
-    public function store(array $schema)
95
-    {
96
-        if (empty(glsr()->schemas)) {
97
-            return;
98
-        }
99
-        $schemas = glsr()->schemas;
100
-        $schemas[] = $schema;
101
-        glsr()->schemas = array_map('unserialize', array_unique(array_map('serialize', $schemas)));
102
-    }
91
+	/**
92
+	 * @return void
93
+	 */
94
+	public function store(array $schema)
95
+	{
96
+		if (empty(glsr()->schemas)) {
97
+			return;
98
+		}
99
+		$schemas = glsr()->schemas;
100
+		$schemas[] = $schema;
101
+		glsr()->schemas = array_map('unserialize', array_unique(array_map('serialize', $schemas)));
102
+	}
103 103
 
104
-    /**
105
-     * @param Review $review
106
-     * @return array
107
-     */
108
-    protected function buildReview($review)
109
-    {
110
-        $schema = $this->getSchemaType('Review')
111
-            ->doIf(!in_array('title', $this->args['hide']), function ($schema) use ($review) {
112
-                $schema->name($review->title);
113
-            })
114
-            ->doIf(!in_array('excerpt', $this->args['hide']), function ($schema) use ($review) {
115
-                $schema->reviewBody($review->content);
116
-            })
117
-            ->datePublished((new DateTime($review->date)))
118
-            ->author($this->getSchemaType('Person')->name($review->author))
119
-            ->itemReviewed($this->getSchemaType()->name($this->getSchemaOptionValue('name')));
120
-        if (!empty($review->rating)) {
121
-            $schema->reviewRating(
122
-                $this->getSchemaType('Rating')
123
-                    ->ratingValue($review->rating)
124
-                    ->bestRating(glsr()->constant('MAX_RATING', Rating::class))
125
-                    ->worstRating(glsr()->constant('MIN_RATING', Rating::class))
126
-            );
127
-        }
128
-        return apply_filters('site-reviews/schema/review', $schema->toArray(), $review, $this->args);
129
-    }
104
+	/**
105
+	 * @param Review $review
106
+	 * @return array
107
+	 */
108
+	protected function buildReview($review)
109
+	{
110
+		$schema = $this->getSchemaType('Review')
111
+			->doIf(!in_array('title', $this->args['hide']), function ($schema) use ($review) {
112
+				$schema->name($review->title);
113
+			})
114
+			->doIf(!in_array('excerpt', $this->args['hide']), function ($schema) use ($review) {
115
+				$schema->reviewBody($review->content);
116
+			})
117
+			->datePublished((new DateTime($review->date)))
118
+			->author($this->getSchemaType('Person')->name($review->author))
119
+			->itemReviewed($this->getSchemaType()->name($this->getSchemaOptionValue('name')));
120
+		if (!empty($review->rating)) {
121
+			$schema->reviewRating(
122
+				$this->getSchemaType('Rating')
123
+					->ratingValue($review->rating)
124
+					->bestRating(glsr()->constant('MAX_RATING', Rating::class))
125
+					->worstRating(glsr()->constant('MIN_RATING', Rating::class))
126
+			);
127
+		}
128
+		return apply_filters('site-reviews/schema/review', $schema->toArray(), $review, $this->args);
129
+	}
130 130
 
131
-    /**
132
-     * @return array
133
-     */
134
-    protected function buildReviews()
135
-    {
136
-        $reviews = [];
137
-        foreach (glsr(ReviewManager::class)->get($this->args) as $review) {
138
-            // Only include critic reviews that have been directly produced by your site, not reviews from third-party sites or syndicated reviews.
139
-            // @see https://developers.google.com/search/docs/data-types/review
140
-            if ('local' === $review->review_type) {
141
-                $reviews[] = $this->buildReview($review);
142
-            }
143
-        }
144
-        return $reviews;
145
-    }
131
+	/**
132
+	 * @return array
133
+	 */
134
+	protected function buildReviews()
135
+	{
136
+		$reviews = [];
137
+		foreach (glsr(ReviewManager::class)->get($this->args) as $review) {
138
+			// Only include critic reviews that have been directly produced by your site, not reviews from third-party sites or syndicated reviews.
139
+			// @see https://developers.google.com/search/docs/data-types/review
140
+			if ('local' === $review->review_type) {
141
+				$reviews[] = $this->buildReview($review);
142
+			}
143
+		}
144
+		return $reviews;
145
+	}
146 146
 
147
-    /**
148
-     * @param mixed $schema
149
-     * @return mixed
150
-     */
151
-    protected function buildSchemaValues($schema, array $values = [])
152
-    {
153
-        foreach ($values as $value) {
154
-            $option = $this->getSchemaOptionValue($value);
155
-            if (empty($option)) {
156
-                continue;
157
-            }
158
-            $schema->$value($option);
159
-        }
160
-        return $schema;
161
-    }
147
+	/**
148
+	 * @param mixed $schema
149
+	 * @return mixed
150
+	 */
151
+	protected function buildSchemaValues($schema, array $values = [])
152
+	{
153
+		foreach ($values as $value) {
154
+			$option = $this->getSchemaOptionValue($value);
155
+			if (empty($option)) {
156
+				continue;
157
+			}
158
+			$schema->$value($option);
159
+		}
160
+		return $schema;
161
+	}
162 162
 
163
-    /**
164
-     * @return mixed
165
-     */
166
-    protected function buildSummaryForCustom()
167
-    {
168
-        return $this->buildSchemaValues($this->getSchemaType(), [
169
-            'description', 'image', 'name', 'url',
170
-        ]);
171
-    }
163
+	/**
164
+	 * @return mixed
165
+	 */
166
+	protected function buildSummaryForCustom()
167
+	{
168
+		return $this->buildSchemaValues($this->getSchemaType(), [
169
+			'description', 'image', 'name', 'url',
170
+		]);
171
+	}
172 172
 
173
-    /**
174
-     * @return mixed
175
-     */
176
-    protected function buildSummaryForLocalBusiness()
177
-    {
178
-        return $this->buildSchemaValues($this->buildSummaryForCustom(), [
179
-            'address', 'priceRange', 'telephone',
180
-        ]);
181
-    }
173
+	/**
174
+	 * @return mixed
175
+	 */
176
+	protected function buildSummaryForLocalBusiness()
177
+	{
178
+		return $this->buildSchemaValues($this->buildSummaryForCustom(), [
179
+			'address', 'priceRange', 'telephone',
180
+		]);
181
+	}
182 182
 
183
-    /**
184
-     * @return mixed
185
-     */
186
-    protected function buildSummaryForProduct()
187
-    {
188
-        $offerType = $this->getSchemaOption('offerType', 'AggregateOffer');
189
-        $offers = $this->buildSchemaValues($this->getSchemaType($offerType), [
190
-            'highPrice', 'lowPrice', 'price', 'priceCurrency',
191
-        ]);
192
-        return $this->buildSummaryForCustom()
193
-            ->doIf(!empty($offers->getProperties()), function ($schema) use ($offers) {
194
-                $schema->offers($offers);
195
-            })
196
-            ->setProperty('@id', $this->getSchemaOptionValue('url').'#product');
197
-    }
183
+	/**
184
+	 * @return mixed
185
+	 */
186
+	protected function buildSummaryForProduct()
187
+	{
188
+		$offerType = $this->getSchemaOption('offerType', 'AggregateOffer');
189
+		$offers = $this->buildSchemaValues($this->getSchemaType($offerType), [
190
+			'highPrice', 'lowPrice', 'price', 'priceCurrency',
191
+		]);
192
+		return $this->buildSummaryForCustom()
193
+			->doIf(!empty($offers->getProperties()), function ($schema) use ($offers) {
194
+				$schema->offers($offers);
195
+			})
196
+			->setProperty('@id', $this->getSchemaOptionValue('url').'#product');
197
+	}
198 198
 
199
-    /**
200
-     * @return array
201
-     */
202
-    protected function getRatingCounts()
203
-    {
204
-        if (!isset($this->ratingCounts)) {
205
-            $this->ratingCounts = glsr(ReviewManager::class)->getRatingCounts($this->args);
206
-        }
207
-        return $this->ratingCounts;
208
-    }
199
+	/**
200
+	 * @return array
201
+	 */
202
+	protected function getRatingCounts()
203
+	{
204
+		if (!isset($this->ratingCounts)) {
205
+			$this->ratingCounts = glsr(ReviewManager::class)->getRatingCounts($this->args);
206
+		}
207
+		return $this->ratingCounts;
208
+	}
209 209
 
210
-    /**
211
-     * @return int|float
212
-     */
213
-    protected function getRatingValue()
214
-    {
215
-        return glsr(Rating::class)->getAverage($this->getRatingCounts());
216
-    }
210
+	/**
211
+	 * @return int|float
212
+	 */
213
+	protected function getRatingValue()
214
+	{
215
+		return glsr(Rating::class)->getAverage($this->getRatingCounts());
216
+	}
217 217
 
218
-    /**
219
-     * @param string $option
220
-     * @param string $fallback
221
-     * @return string
222
-     */
223
-    protected function getSchemaOption($option, $fallback)
224
-    {
225
-        $option = strtolower($option);
226
-        if ($schemaOption = trim((string) get_post_meta(intval(get_the_ID()), 'schema_'.$option, true))) {
227
-            return $schemaOption;
228
-        }
229
-        $setting = glsr(OptionManager::class)->get('settings.schema.'.$option);
230
-        if (is_array($setting)) {
231
-            return $this->getSchemaOptionDefault($setting, $fallback);
232
-        }
233
-        return !empty($setting)
234
-            ? $setting
235
-            : $fallback;
236
-    }
218
+	/**
219
+	 * @param string $option
220
+	 * @param string $fallback
221
+	 * @return string
222
+	 */
223
+	protected function getSchemaOption($option, $fallback)
224
+	{
225
+		$option = strtolower($option);
226
+		if ($schemaOption = trim((string) get_post_meta(intval(get_the_ID()), 'schema_'.$option, true))) {
227
+			return $schemaOption;
228
+		}
229
+		$setting = glsr(OptionManager::class)->get('settings.schema.'.$option);
230
+		if (is_array($setting)) {
231
+			return $this->getSchemaOptionDefault($setting, $fallback);
232
+		}
233
+		return !empty($setting)
234
+			? $setting
235
+			: $fallback;
236
+	}
237 237
 
238
-    /**
239
-     * @param string $fallback
240
-     * @return string
241
-     */
242
-    protected function getSchemaOptionDefault(array $setting, $fallback)
243
-    {
244
-        $setting = wp_parse_args($setting, [
245
-            'custom' => '',
246
-            'default' => $fallback,
247
-        ]);
248
-        return 'custom' != $setting['default']
249
-            ? $setting['default']
250
-            : $setting['custom'];
251
-    }
238
+	/**
239
+	 * @param string $fallback
240
+	 * @return string
241
+	 */
242
+	protected function getSchemaOptionDefault(array $setting, $fallback)
243
+	{
244
+		$setting = wp_parse_args($setting, [
245
+			'custom' => '',
246
+			'default' => $fallback,
247
+		]);
248
+		return 'custom' != $setting['default']
249
+			? $setting['default']
250
+			: $setting['custom'];
251
+	}
252 252
 
253
-    /**
254
-     * @param string $option
255
-     * @param string $fallback
256
-     * @return void|string
257
-     */
258
-    protected function getSchemaOptionValue($option, $fallback = 'post')
259
-    {
260
-        if (array_key_exists($option, $this->keyValues)) {
261
-            return $this->keyValues[$option];
262
-        }
263
-        $value = $this->getSchemaOption($option, $fallback);
264
-        if ($value != $fallback) {
265
-            return $this->setAndGetKeyValue($option, $value);
266
-        }
267
-        if (!is_single() && !is_page()) {
268
-            return;
269
-        }
270
-        $method = Helper::buildMethodName($option, 'getThing');
271
-        if (method_exists($this, $method)) {
272
-            return $this->setAndGetKeyValue($option, $this->$method());
273
-        }
274
-    }
253
+	/**
254
+	 * @param string $option
255
+	 * @param string $fallback
256
+	 * @return void|string
257
+	 */
258
+	protected function getSchemaOptionValue($option, $fallback = 'post')
259
+	{
260
+		if (array_key_exists($option, $this->keyValues)) {
261
+			return $this->keyValues[$option];
262
+		}
263
+		$value = $this->getSchemaOption($option, $fallback);
264
+		if ($value != $fallback) {
265
+			return $this->setAndGetKeyValue($option, $value);
266
+		}
267
+		if (!is_single() && !is_page()) {
268
+			return;
269
+		}
270
+		$method = Helper::buildMethodName($option, 'getThing');
271
+		if (method_exists($this, $method)) {
272
+			return $this->setAndGetKeyValue($option, $this->$method());
273
+		}
274
+	}
275 275
 
276
-    /**
277
-     * @param string|null $type
278
-     * @return mixed
279
-     */
280
-    protected function getSchemaType($type = null)
281
-    {
282
-        if (!is_string($type)) {
283
-            $type = $this->getSchemaOption('type', 'LocalBusiness');
284
-        }
285
-        $className = Helper::buildClassName($type, 'Modules\Schema');
286
-        return class_exists($className)
287
-            ? new $className()
288
-            : new UnknownType($type);
289
-    }
276
+	/**
277
+	 * @param string|null $type
278
+	 * @return mixed
279
+	 */
280
+	protected function getSchemaType($type = null)
281
+	{
282
+		if (!is_string($type)) {
283
+			$type = $this->getSchemaOption('type', 'LocalBusiness');
284
+		}
285
+		$className = Helper::buildClassName($type, 'Modules\Schema');
286
+		return class_exists($className)
287
+			? new $className()
288
+			: new UnknownType($type);
289
+	}
290 290
 
291
-    /**
292
-     * @return string
293
-     */
294
-    protected function getThingDescription()
295
-    {
296
-        $post = get_post();
297
-        $text = Arr::get($post, 'post_excerpt');
298
-        if (empty($text)) {
299
-            $text = Arr::get($post, 'post_content');
300
-        }
301
-        if (function_exists('excerpt_remove_blocks')) {
302
-            $text = excerpt_remove_blocks($text);
303
-        }
304
-        $text = strip_shortcodes($text);
305
-        $text = wpautop($text);
306
-        $text = wptexturize($text);
307
-        $text = wp_strip_all_tags($text);
308
-        $text = str_replace(']]>', ']]&gt;', $text);
309
-        return wp_trim_words($text, apply_filters('excerpt_length', 55));
310
-    }
291
+	/**
292
+	 * @return string
293
+	 */
294
+	protected function getThingDescription()
295
+	{
296
+		$post = get_post();
297
+		$text = Arr::get($post, 'post_excerpt');
298
+		if (empty($text)) {
299
+			$text = Arr::get($post, 'post_content');
300
+		}
301
+		if (function_exists('excerpt_remove_blocks')) {
302
+			$text = excerpt_remove_blocks($text);
303
+		}
304
+		$text = strip_shortcodes($text);
305
+		$text = wpautop($text);
306
+		$text = wptexturize($text);
307
+		$text = wp_strip_all_tags($text);
308
+		$text = str_replace(']]>', ']]&gt;', $text);
309
+		return wp_trim_words($text, apply_filters('excerpt_length', 55));
310
+	}
311 311
 
312
-    /**
313
-     * @return string
314
-     */
315
-    protected function getThingImage()
316
-    {
317
-        return (string) get_the_post_thumbnail_url(null, 'large');
318
-    }
312
+	/**
313
+	 * @return string
314
+	 */
315
+	protected function getThingImage()
316
+	{
317
+		return (string) get_the_post_thumbnail_url(null, 'large');
318
+	}
319 319
 
320
-    /**
321
-     * @return string
322
-     */
323
-    protected function getThingName()
324
-    {
325
-        return get_the_title();
326
-    }
320
+	/**
321
+	 * @return string
322
+	 */
323
+	protected function getThingName()
324
+	{
325
+		return get_the_title();
326
+	}
327 327
 
328
-    /**
329
-     * @return string
330
-     */
331
-    protected function getThingUrl()
332
-    {
333
-        return (string) get_the_permalink();
334
-    }
328
+	/**
329
+	 * @return string
330
+	 */
331
+	protected function getThingUrl()
332
+	{
333
+		return (string) get_the_permalink();
334
+	}
335 335
 
336
-    /**
337
-     * @param string $option
338
-     * @param string $value
339
-     * @return string
340
-     */
341
-    protected function setAndGetKeyValue($option, $value)
342
-    {
343
-        $this->keyValues[$option] = $value;
344
-        return $value;
345
-    }
336
+	/**
337
+	 * @param string $option
338
+	 * @param string $value
339
+	 * @return string
340
+	 */
341
+	protected function setAndGetKeyValue($option, $value)
342
+	{
343
+		$this->keyValues[$option] = $value;
344
+		return $value;
345
+	}
346 346
 }
Please login to merge, or discard this patch.