@@ -8,218 +8,218 @@ |
||
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 | - } |
|
185 | - |
|
186 | - /** |
|
187 | - * @param int|string $value |
|
188 | - * @param int|string $compareWithValue |
|
189 | - * @return bool |
|
190 | - */ |
|
191 | - public static function isGreaterThan($value, $compareWithValue) |
|
192 | - { |
|
193 | - return version_compare($value, $compareWithValue, '>'); |
|
194 | - } |
|
195 | - |
|
196 | - /** |
|
197 | - * @param int|string $value |
|
198 | - * @param int|string $compareWithValue |
|
199 | - * @return bool |
|
200 | - */ |
|
201 | - public static function isGreaterThanOrEqual($value, $compareWithValue) |
|
202 | - { |
|
203 | - return version_compare($value, $compareWithValue, '>='); |
|
204 | - } |
|
205 | - |
|
206 | - /** |
|
207 | - * @param int|string $value |
|
208 | - * @param int|string $compareWithValue |
|
209 | - * @return bool |
|
210 | - */ |
|
211 | - public static function isLessThan($value, $compareWithValue) |
|
212 | - { |
|
213 | - return version_compare($value, $compareWithValue, '<'); |
|
214 | - } |
|
215 | - |
|
216 | - /** |
|
217 | - * @param int|string $value |
|
218 | - * @param int|string $compareWithValue |
|
219 | - * @return bool |
|
220 | - */ |
|
221 | - public static function isLessThanOrEqual($value, $compareWithValue) |
|
222 | - { |
|
223 | - return version_compare($value, $compareWithValue, '<='); |
|
224 | - } |
|
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 | + |
|
186 | + /** |
|
187 | + * @param int|string $value |
|
188 | + * @param int|string $compareWithValue |
|
189 | + * @return bool |
|
190 | + */ |
|
191 | + public static function isGreaterThan($value, $compareWithValue) |
|
192 | + { |
|
193 | + return version_compare($value, $compareWithValue, '>'); |
|
194 | + } |
|
195 | + |
|
196 | + /** |
|
197 | + * @param int|string $value |
|
198 | + * @param int|string $compareWithValue |
|
199 | + * @return bool |
|
200 | + */ |
|
201 | + public static function isGreaterThanOrEqual($value, $compareWithValue) |
|
202 | + { |
|
203 | + return version_compare($value, $compareWithValue, '>='); |
|
204 | + } |
|
205 | + |
|
206 | + /** |
|
207 | + * @param int|string $value |
|
208 | + * @param int|string $compareWithValue |
|
209 | + * @return bool |
|
210 | + */ |
|
211 | + public static function isLessThan($value, $compareWithValue) |
|
212 | + { |
|
213 | + return version_compare($value, $compareWithValue, '<'); |
|
214 | + } |
|
215 | + |
|
216 | + /** |
|
217 | + * @param int|string $value |
|
218 | + * @param int|string $compareWithValue |
|
219 | + * @return bool |
|
220 | + */ |
|
221 | + public static function isLessThanOrEqual($value, $compareWithValue) |
|
222 | + { |
|
223 | + return version_compare($value, $compareWithValue, '<='); |
|
224 | + } |
|
225 | 225 | } |
@@ -13,10 +13,10 @@ discard block |
||
13 | 13 | * @param string $path |
14 | 14 | * @return string |
15 | 15 | */ |
16 | - public static function buildClassName($name, $path = '') |
|
16 | + public static function buildClassName( $name, $path = '' ) |
|
17 | 17 | { |
18 | - $className = Str::camelCase($name); |
|
19 | - $path = ltrim(str_replace(__NAMESPACE__, '', $path), '\\'); |
|
18 | + $className = Str::camelCase( $name ); |
|
19 | + $path = ltrim( str_replace( __NAMESPACE__, '', $path ), '\\' ); |
|
20 | 20 | return !empty($path) |
21 | 21 | ? __NAMESPACE__.'\\'.$path.'\\'.$className |
22 | 22 | : $className; |
@@ -27,18 +27,18 @@ discard block |
||
27 | 27 | * @param string $prefix |
28 | 28 | * @return string |
29 | 29 | */ |
30 | - public static function buildMethodName($name, $prefix = '') |
|
30 | + public static function buildMethodName( $name, $prefix = '' ) |
|
31 | 31 | { |
32 | - return lcfirst($prefix.static::buildClassName($name)); |
|
32 | + return lcfirst( $prefix.static::buildClassName( $name ) ); |
|
33 | 33 | } |
34 | 34 | |
35 | 35 | /** |
36 | 36 | * @param string $name |
37 | 37 | * @return string |
38 | 38 | */ |
39 | - public static function buildPropertyName($name) |
|
39 | + public static function buildPropertyName( $name ) |
|
40 | 40 | { |
41 | - return static::buildMethodName($name); |
|
41 | + return static::buildMethodName( $name ); |
|
42 | 42 | } |
43 | 43 | |
44 | 44 | /** |
@@ -46,11 +46,11 @@ discard block |
||
46 | 46 | * @param mixed $value |
47 | 47 | * @return mixed |
48 | 48 | */ |
49 | - public static function castTo($cast = '', $value) |
|
49 | + public static function castTo( $cast = '', $value ) |
|
50 | 50 | { |
51 | - $method = static::buildMethodName($cast, 'castTo'); |
|
52 | - return !empty($cast) && method_exists(__CLASS__, $method) |
|
53 | - ? static::$method($value) |
|
51 | + $method = static::buildMethodName( $cast, 'castTo' ); |
|
52 | + return !empty($cast) && method_exists( __CLASS__, $method ) |
|
53 | + ? static::$method( $value ) |
|
54 | 54 | : $value; |
55 | 55 | } |
56 | 56 | |
@@ -58,73 +58,73 @@ discard block |
||
58 | 58 | * @param mixed $value |
59 | 59 | * @return array |
60 | 60 | */ |
61 | - public static function castToArray($value) |
|
61 | + public static function castToArray( $value ) |
|
62 | 62 | { |
63 | - return (array) $value; |
|
63 | + return (array)$value; |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | /** |
67 | 67 | * @param mixed $value |
68 | 68 | * @return bool |
69 | 69 | */ |
70 | - public static function castToBool($value) |
|
70 | + public static function castToBool( $value ) |
|
71 | 71 | { |
72 | - return filter_var($value, FILTER_VALIDATE_BOOLEAN); |
|
72 | + return filter_var( $value, FILTER_VALIDATE_BOOLEAN ); |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | /** |
76 | 76 | * @param mixed $value |
77 | 77 | * @return float |
78 | 78 | */ |
79 | - public static function castToFloat($value) |
|
79 | + public static function castToFloat( $value ) |
|
80 | 80 | { |
81 | - return (float) filter_var($value, FILTER_VALIDATE_FLOAT, FILTER_FLAG_ALLOW_THOUSAND); |
|
81 | + return (float)filter_var( $value, FILTER_VALIDATE_FLOAT, FILTER_FLAG_ALLOW_THOUSAND ); |
|
82 | 82 | } |
83 | 83 | |
84 | 84 | /** |
85 | 85 | * @param mixed $value |
86 | 86 | * @return int |
87 | 87 | */ |
88 | - public static function castToInt($value) |
|
88 | + public static function castToInt( $value ) |
|
89 | 89 | { |
90 | - return (int) filter_var($value, FILTER_VALIDATE_INT); |
|
90 | + return (int)filter_var( $value, FILTER_VALIDATE_INT ); |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | /** |
94 | 94 | * @param mixed $value |
95 | 95 | * @return object |
96 | 96 | */ |
97 | - public static function castToObject($value) |
|
97 | + public static function castToObject( $value ) |
|
98 | 98 | { |
99 | - return (object) (array) $value; |
|
99 | + return (object)(array)$value; |
|
100 | 100 | } |
101 | 101 | |
102 | 102 | /** |
103 | 103 | * @param mixed $value |
104 | 104 | * @return string |
105 | 105 | */ |
106 | - public static function castToString($value) |
|
106 | + public static function castToString( $value ) |
|
107 | 107 | { |
108 | - if (is_object($value) && in_array('__toString', get_class_methods($value))) { |
|
109 | - return (string) $value->__toString(); |
|
108 | + if( is_object( $value ) && in_array( '__toString', get_class_methods( $value ) ) ) { |
|
109 | + return (string)$value->__toString(); |
|
110 | 110 | } |
111 | - if (is_array($value) || is_object($value)) { |
|
112 | - return serialize($value); |
|
111 | + if( is_array( $value ) || is_object( $value ) ) { |
|
112 | + return serialize( $value ); |
|
113 | 113 | } |
114 | - return (string) $value; |
|
114 | + return (string)$value; |
|
115 | 115 | } |
116 | 116 | |
117 | 117 | /** |
118 | 118 | * @param string $key |
119 | 119 | * @return mixed |
120 | 120 | */ |
121 | - public static function filterInput($key, array $request = []) |
|
121 | + public static function filterInput( $key, array $request = [] ) |
|
122 | 122 | { |
123 | - if (isset($request[$key])) { |
|
123 | + if( isset($request[$key]) ) { |
|
124 | 124 | return $request[$key]; |
125 | 125 | } |
126 | - $variable = filter_input(INPUT_POST, $key); |
|
127 | - if (is_null($variable) && isset($_POST[$key])) { |
|
126 | + $variable = filter_input( INPUT_POST, $key ); |
|
127 | + if( is_null( $variable ) && isset($_POST[$key]) ) { |
|
128 | 128 | $variable = $_POST[$key]; |
129 | 129 | } |
130 | 130 | return $variable; |
@@ -134,13 +134,13 @@ discard block |
||
134 | 134 | * @param string $key |
135 | 135 | * @return array |
136 | 136 | */ |
137 | - public static function filterInputArray($key) |
|
137 | + public static function filterInputArray( $key ) |
|
138 | 138 | { |
139 | - $variable = filter_input(INPUT_POST, $key, FILTER_DEFAULT, FILTER_REQUIRE_ARRAY); |
|
140 | - if (empty($variable) && !empty($_POST[$key]) && is_array($_POST[$key])) { |
|
139 | + $variable = filter_input( INPUT_POST, $key, FILTER_DEFAULT, FILTER_REQUIRE_ARRAY ); |
|
140 | + if( empty($variable) && !empty($_POST[$key]) && is_array( $_POST[$key] ) ) { |
|
141 | 141 | $variable = $_POST[$key]; |
142 | 142 | } |
143 | - return (array) $variable; |
|
143 | + return (array)$variable; |
|
144 | 144 | } |
145 | 145 | |
146 | 146 | /** |
@@ -149,22 +149,22 @@ discard block |
||
149 | 149 | public static function getIpAddress() |
150 | 150 | { |
151 | 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(); |
|
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 | 155 | $whitelist[Whip::CLOUDFLARE_HEADERS] = [Whip::IPV4 => $cloudflareIps['v4']]; |
156 | - if (defined('AF_INET6')) { |
|
156 | + if( defined( 'AF_INET6' ) ) { |
|
157 | 157 | $whitelist[Whip::CLOUDFLARE_HEADERS][Whip::IPV6] = $cloudflareIps['v6']; |
158 | 158 | } |
159 | 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; |
|
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 | 166 | } |
167 | - glsr_log()->error('Unable to detect IP address.'); |
|
167 | + glsr_log()->error( 'Unable to detect IP address.' ); |
|
168 | 168 | return 'unknown'; |
169 | 169 | } |
170 | 170 | |
@@ -174,12 +174,12 @@ discard block |
||
174 | 174 | * @param string|int $max |
175 | 175 | * @return bool |
176 | 176 | */ |
177 | - public static function inRange($value, $min, $max) |
|
177 | + public static function inRange( $value, $min, $max ) |
|
178 | 178 | { |
179 | - $inRange = filter_var($value, FILTER_VALIDATE_INT, ['options' => [ |
|
180 | - 'min_range' => intval($min), |
|
181 | - 'max_range' => intval($max), |
|
182 | - ]]); |
|
179 | + $inRange = filter_var( $value, FILTER_VALIDATE_INT, ['options' => [ |
|
180 | + 'min_range' => intval( $min ), |
|
181 | + 'max_range' => intval( $max ), |
|
182 | + ]] ); |
|
183 | 183 | return false !== $inRange; |
184 | 184 | } |
185 | 185 | |
@@ -188,9 +188,9 @@ discard block |
||
188 | 188 | * @param int|string $compareWithValue |
189 | 189 | * @return bool |
190 | 190 | */ |
191 | - public static function isGreaterThan($value, $compareWithValue) |
|
191 | + public static function isGreaterThan( $value, $compareWithValue ) |
|
192 | 192 | { |
193 | - return version_compare($value, $compareWithValue, '>'); |
|
193 | + return version_compare( $value, $compareWithValue, '>' ); |
|
194 | 194 | } |
195 | 195 | |
196 | 196 | /** |
@@ -198,9 +198,9 @@ discard block |
||
198 | 198 | * @param int|string $compareWithValue |
199 | 199 | * @return bool |
200 | 200 | */ |
201 | - public static function isGreaterThanOrEqual($value, $compareWithValue) |
|
201 | + public static function isGreaterThanOrEqual( $value, $compareWithValue ) |
|
202 | 202 | { |
203 | - return version_compare($value, $compareWithValue, '>='); |
|
203 | + return version_compare( $value, $compareWithValue, '>=' ); |
|
204 | 204 | } |
205 | 205 | |
206 | 206 | /** |
@@ -208,9 +208,9 @@ discard block |
||
208 | 208 | * @param int|string $compareWithValue |
209 | 209 | * @return bool |
210 | 210 | */ |
211 | - public static function isLessThan($value, $compareWithValue) |
|
211 | + public static function isLessThan( $value, $compareWithValue ) |
|
212 | 212 | { |
213 | - return version_compare($value, $compareWithValue, '<'); |
|
213 | + return version_compare( $value, $compareWithValue, '<' ); |
|
214 | 214 | } |
215 | 215 | |
216 | 216 | /** |
@@ -218,8 +218,8 @@ discard block |
||
218 | 218 | * @param int|string $compareWithValue |
219 | 219 | * @return bool |
220 | 220 | */ |
221 | - public static function isLessThanOrEqual($value, $compareWithValue) |
|
221 | + public static function isLessThanOrEqual( $value, $compareWithValue ) |
|
222 | 222 | { |
223 | - return version_compare($value, $compareWithValue, '<='); |
|
223 | + return version_compare( $value, $compareWithValue, '<=' ); |
|
224 | 224 | } |
225 | 225 | } |
@@ -9,157 +9,157 @@ |
||
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 (1 == $version) { |
|
23 | - return 'geminilabs_site_reviews_settings'; |
|
24 | - } |
|
25 | - if (2 == $version) { |
|
26 | - return 'geminilabs_site_reviews-v2'; |
|
27 | - } |
|
28 | - if (null === $version) { |
|
29 | - $version = explode('.', glsr()->version); |
|
30 | - $version = array_shift($version); |
|
31 | - } |
|
32 | - return Str::snakeCase(Application::ID.'-v'.intval($version)); |
|
33 | - } |
|
17 | + /** |
|
18 | + * @return string |
|
19 | + */ |
|
20 | + public static function databaseKey($version = null) |
|
21 | + { |
|
22 | + if (1 == $version) { |
|
23 | + return 'geminilabs_site_reviews_settings'; |
|
24 | + } |
|
25 | + if (2 == $version) { |
|
26 | + return 'geminilabs_site_reviews-v2'; |
|
27 | + } |
|
28 | + if (null === $version) { |
|
29 | + $version = explode('.', glsr()->version); |
|
30 | + $version = array_shift($version); |
|
31 | + } |
|
32 | + return Str::snakeCase(Application::ID.'-v'.intval($version)); |
|
33 | + } |
|
34 | 34 | |
35 | - /** |
|
36 | - * @return array |
|
37 | - */ |
|
38 | - public function all() |
|
39 | - { |
|
40 | - if (empty($this->options)) { |
|
41 | - $this->reset(); |
|
42 | - } |
|
43 | - return $this->options; |
|
44 | - } |
|
35 | + /** |
|
36 | + * @return array |
|
37 | + */ |
|
38 | + public function all() |
|
39 | + { |
|
40 | + if (empty($this->options)) { |
|
41 | + $this->reset(); |
|
42 | + } |
|
43 | + return $this->options; |
|
44 | + } |
|
45 | 45 | |
46 | - /** |
|
47 | - * @param string $path |
|
48 | - * @return bool |
|
49 | - */ |
|
50 | - public function delete($path) |
|
51 | - { |
|
52 | - $keys = explode('.', $path); |
|
53 | - $last = array_pop($keys); |
|
54 | - $options = $this->all(); |
|
55 | - $pointer = &$options; |
|
56 | - foreach ($keys as $key) { |
|
57 | - if (!isset($pointer[$key]) || !is_array($pointer[$key])) { |
|
58 | - continue; |
|
59 | - } |
|
60 | - $pointer = &$pointer[$key]; |
|
61 | - } |
|
62 | - unset($pointer[$last]); |
|
63 | - return $this->set($options); |
|
64 | - } |
|
46 | + /** |
|
47 | + * @param string $path |
|
48 | + * @return bool |
|
49 | + */ |
|
50 | + public function delete($path) |
|
51 | + { |
|
52 | + $keys = explode('.', $path); |
|
53 | + $last = array_pop($keys); |
|
54 | + $options = $this->all(); |
|
55 | + $pointer = &$options; |
|
56 | + foreach ($keys as $key) { |
|
57 | + if (!isset($pointer[$key]) || !is_array($pointer[$key])) { |
|
58 | + continue; |
|
59 | + } |
|
60 | + $pointer = &$pointer[$key]; |
|
61 | + } |
|
62 | + unset($pointer[$last]); |
|
63 | + return $this->set($options); |
|
64 | + } |
|
65 | 65 | |
66 | - /** |
|
67 | - * @param string $path |
|
68 | - * @param mixed $fallback |
|
69 | - * @param string $cast |
|
70 | - * @return mixed |
|
71 | - */ |
|
72 | - public function get($path = '', $fallback = '', $cast = '') |
|
73 | - { |
|
74 | - $result = Arr::get($this->all(), $path, $fallback); |
|
75 | - return Helper::castTo($cast, $result); |
|
76 | - } |
|
66 | + /** |
|
67 | + * @param string $path |
|
68 | + * @param mixed $fallback |
|
69 | + * @param string $cast |
|
70 | + * @return mixed |
|
71 | + */ |
|
72 | + public function get($path = '', $fallback = '', $cast = '') |
|
73 | + { |
|
74 | + $result = Arr::get($this->all(), $path, $fallback); |
|
75 | + return Helper::castTo($cast, $result); |
|
76 | + } |
|
77 | 77 | |
78 | - /** |
|
79 | - * @param string $path |
|
80 | - * @return bool |
|
81 | - */ |
|
82 | - public function getBool($path) |
|
83 | - { |
|
84 | - return Helper::castToBool($this->get($path)); |
|
85 | - } |
|
78 | + /** |
|
79 | + * @param string $path |
|
80 | + * @return bool |
|
81 | + */ |
|
82 | + public function getBool($path) |
|
83 | + { |
|
84 | + return Helper::castToBool($this->get($path)); |
|
85 | + } |
|
86 | 86 | |
87 | - /** |
|
88 | - * @param string $path |
|
89 | - * @param mixed $fallback |
|
90 | - * @param string $cast |
|
91 | - * @return mixed |
|
92 | - */ |
|
93 | - public function getWP($path, $fallback = '', $cast = '') |
|
94 | - { |
|
95 | - $option = get_option($path, $fallback); |
|
96 | - if (empty($option)) { |
|
97 | - $option = $fallback; |
|
98 | - } |
|
99 | - return Helper::castTo($cast, $option); |
|
100 | - } |
|
87 | + /** |
|
88 | + * @param string $path |
|
89 | + * @param mixed $fallback |
|
90 | + * @param string $cast |
|
91 | + * @return mixed |
|
92 | + */ |
|
93 | + public function getWP($path, $fallback = '', $cast = '') |
|
94 | + { |
|
95 | + $option = get_option($path, $fallback); |
|
96 | + if (empty($option)) { |
|
97 | + $option = $fallback; |
|
98 | + } |
|
99 | + return Helper::castTo($cast, $option); |
|
100 | + } |
|
101 | 101 | |
102 | - /** |
|
103 | - * @return string |
|
104 | - */ |
|
105 | - public function json() |
|
106 | - { |
|
107 | - return json_encode($this->all()); |
|
108 | - } |
|
102 | + /** |
|
103 | + * @return string |
|
104 | + */ |
|
105 | + public function json() |
|
106 | + { |
|
107 | + return json_encode($this->all()); |
|
108 | + } |
|
109 | 109 | |
110 | - /** |
|
111 | - * @return array |
|
112 | - */ |
|
113 | - public function normalize(array $options = []) |
|
114 | - { |
|
115 | - $options = wp_parse_args( |
|
116 | - Arr::flattenArray($options), |
|
117 | - glsr(DefaultsManager::class)->defaults() |
|
118 | - ); |
|
119 | - array_walk($options, function (&$value) { |
|
120 | - if (!is_string($value)) { |
|
121 | - return; |
|
122 | - } |
|
123 | - $value = wp_kses($value, wp_kses_allowed_html('post')); |
|
124 | - }); |
|
125 | - return Arr::convertDotNotationArray($options); |
|
126 | - } |
|
110 | + /** |
|
111 | + * @return array |
|
112 | + */ |
|
113 | + public function normalize(array $options = []) |
|
114 | + { |
|
115 | + $options = wp_parse_args( |
|
116 | + Arr::flattenArray($options), |
|
117 | + glsr(DefaultsManager::class)->defaults() |
|
118 | + ); |
|
119 | + array_walk($options, function (&$value) { |
|
120 | + if (!is_string($value)) { |
|
121 | + return; |
|
122 | + } |
|
123 | + $value = wp_kses($value, wp_kses_allowed_html('post')); |
|
124 | + }); |
|
125 | + return Arr::convertDotNotationArray($options); |
|
126 | + } |
|
127 | 127 | |
128 | - /** |
|
129 | - * @return bool |
|
130 | - */ |
|
131 | - public function isRecaptchaEnabled() |
|
132 | - { |
|
133 | - $integration = $this->get('settings.submissions.recaptcha.integration'); |
|
134 | - return 'all' == $integration || ('guest' == $integration && !is_user_logged_in()); |
|
135 | - } |
|
128 | + /** |
|
129 | + * @return bool |
|
130 | + */ |
|
131 | + public function isRecaptchaEnabled() |
|
132 | + { |
|
133 | + $integration = $this->get('settings.submissions.recaptcha.integration'); |
|
134 | + return 'all' == $integration || ('guest' == $integration && !is_user_logged_in()); |
|
135 | + } |
|
136 | 136 | |
137 | - /** |
|
138 | - * @return array |
|
139 | - */ |
|
140 | - public function reset() |
|
141 | - { |
|
142 | - $options = $this->getWP(static::databaseKey(), []); |
|
143 | - if (!is_array($options) || empty($options)) { |
|
144 | - delete_option(static::databaseKey()); |
|
145 | - $options = glsr()->defaults ?: []; |
|
146 | - } |
|
147 | - $this->options = $options; |
|
148 | - } |
|
137 | + /** |
|
138 | + * @return array |
|
139 | + */ |
|
140 | + public function reset() |
|
141 | + { |
|
142 | + $options = $this->getWP(static::databaseKey(), []); |
|
143 | + if (!is_array($options) || empty($options)) { |
|
144 | + delete_option(static::databaseKey()); |
|
145 | + $options = glsr()->defaults ?: []; |
|
146 | + } |
|
147 | + $this->options = $options; |
|
148 | + } |
|
149 | 149 | |
150 | - /** |
|
151 | - * @param string|array $pathOrOptions |
|
152 | - * @param mixed $value |
|
153 | - * @return bool |
|
154 | - */ |
|
155 | - public function set($pathOrOptions, $value = '') |
|
156 | - { |
|
157 | - if (is_string($pathOrOptions)) { |
|
158 | - $pathOrOptions = Arr::set($this->all(), $pathOrOptions, $value); |
|
159 | - } |
|
160 | - if ($result = update_option(static::databaseKey(), (array) $pathOrOptions)) { |
|
161 | - $this->reset(); |
|
162 | - } |
|
163 | - return $result; |
|
164 | - } |
|
150 | + /** |
|
151 | + * @param string|array $pathOrOptions |
|
152 | + * @param mixed $value |
|
153 | + * @return bool |
|
154 | + */ |
|
155 | + public function set($pathOrOptions, $value = '') |
|
156 | + { |
|
157 | + if (is_string($pathOrOptions)) { |
|
158 | + $pathOrOptions = Arr::set($this->all(), $pathOrOptions, $value); |
|
159 | + } |
|
160 | + if ($result = update_option(static::databaseKey(), (array) $pathOrOptions)) { |
|
161 | + $this->reset(); |
|
162 | + } |
|
163 | + return $result; |
|
164 | + } |
|
165 | 165 | } |
@@ -17,19 +17,19 @@ discard block |
||
17 | 17 | /** |
18 | 18 | * @return string |
19 | 19 | */ |
20 | - public static function databaseKey($version = null) |
|
20 | + public static function databaseKey( $version = null ) |
|
21 | 21 | { |
22 | - if (1 == $version) { |
|
22 | + if( 1 == $version ) { |
|
23 | 23 | return 'geminilabs_site_reviews_settings'; |
24 | 24 | } |
25 | - if (2 == $version) { |
|
25 | + if( 2 == $version ) { |
|
26 | 26 | return 'geminilabs_site_reviews-v2'; |
27 | 27 | } |
28 | - if (null === $version) { |
|
29 | - $version = explode('.', glsr()->version); |
|
30 | - $version = array_shift($version); |
|
28 | + if( null === $version ) { |
|
29 | + $version = explode( '.', glsr()->version ); |
|
30 | + $version = array_shift( $version ); |
|
31 | 31 | } |
32 | - return Str::snakeCase(Application::ID.'-v'.intval($version)); |
|
32 | + return Str::snakeCase( Application::ID.'-v'.intval( $version ) ); |
|
33 | 33 | } |
34 | 34 | |
35 | 35 | /** |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | */ |
38 | 38 | public function all() |
39 | 39 | { |
40 | - if (empty($this->options)) { |
|
40 | + if( empty($this->options) ) { |
|
41 | 41 | $this->reset(); |
42 | 42 | } |
43 | 43 | return $this->options; |
@@ -47,20 +47,20 @@ discard block |
||
47 | 47 | * @param string $path |
48 | 48 | * @return bool |
49 | 49 | */ |
50 | - public function delete($path) |
|
50 | + public function delete( $path ) |
|
51 | 51 | { |
52 | - $keys = explode('.', $path); |
|
53 | - $last = array_pop($keys); |
|
52 | + $keys = explode( '.', $path ); |
|
53 | + $last = array_pop( $keys ); |
|
54 | 54 | $options = $this->all(); |
55 | 55 | $pointer = &$options; |
56 | - foreach ($keys as $key) { |
|
57 | - if (!isset($pointer[$key]) || !is_array($pointer[$key])) { |
|
56 | + foreach( $keys as $key ) { |
|
57 | + if( !isset($pointer[$key]) || !is_array( $pointer[$key] ) ) { |
|
58 | 58 | continue; |
59 | 59 | } |
60 | 60 | $pointer = &$pointer[$key]; |
61 | 61 | } |
62 | 62 | unset($pointer[$last]); |
63 | - return $this->set($options); |
|
63 | + return $this->set( $options ); |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | /** |
@@ -69,19 +69,19 @@ discard block |
||
69 | 69 | * @param string $cast |
70 | 70 | * @return mixed |
71 | 71 | */ |
72 | - public function get($path = '', $fallback = '', $cast = '') |
|
72 | + public function get( $path = '', $fallback = '', $cast = '' ) |
|
73 | 73 | { |
74 | - $result = Arr::get($this->all(), $path, $fallback); |
|
75 | - return Helper::castTo($cast, $result); |
|
74 | + $result = Arr::get( $this->all(), $path, $fallback ); |
|
75 | + return Helper::castTo( $cast, $result ); |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | /** |
79 | 79 | * @param string $path |
80 | 80 | * @return bool |
81 | 81 | */ |
82 | - public function getBool($path) |
|
82 | + public function getBool( $path ) |
|
83 | 83 | { |
84 | - return Helper::castToBool($this->get($path)); |
|
84 | + return Helper::castToBool( $this->get( $path ) ); |
|
85 | 85 | } |
86 | 86 | |
87 | 87 | /** |
@@ -90,13 +90,13 @@ discard block |
||
90 | 90 | * @param string $cast |
91 | 91 | * @return mixed |
92 | 92 | */ |
93 | - public function getWP($path, $fallback = '', $cast = '') |
|
93 | + public function getWP( $path, $fallback = '', $cast = '' ) |
|
94 | 94 | { |
95 | - $option = get_option($path, $fallback); |
|
96 | - if (empty($option)) { |
|
95 | + $option = get_option( $path, $fallback ); |
|
96 | + if( empty($option) ) { |
|
97 | 97 | $option = $fallback; |
98 | 98 | } |
99 | - return Helper::castTo($cast, $option); |
|
99 | + return Helper::castTo( $cast, $option ); |
|
100 | 100 | } |
101 | 101 | |
102 | 102 | /** |
@@ -104,25 +104,25 @@ discard block |
||
104 | 104 | */ |
105 | 105 | public function json() |
106 | 106 | { |
107 | - return json_encode($this->all()); |
|
107 | + return json_encode( $this->all() ); |
|
108 | 108 | } |
109 | 109 | |
110 | 110 | /** |
111 | 111 | * @return array |
112 | 112 | */ |
113 | - public function normalize(array $options = []) |
|
113 | + public function normalize( array $options = [] ) |
|
114 | 114 | { |
115 | 115 | $options = wp_parse_args( |
116 | - Arr::flattenArray($options), |
|
117 | - glsr(DefaultsManager::class)->defaults() |
|
116 | + Arr::flattenArray( $options ), |
|
117 | + glsr( DefaultsManager::class )->defaults() |
|
118 | 118 | ); |
119 | - array_walk($options, function (&$value) { |
|
120 | - if (!is_string($value)) { |
|
119 | + array_walk( $options, function( &$value ) { |
|
120 | + if( !is_string( $value ) ) { |
|
121 | 121 | return; |
122 | 122 | } |
123 | - $value = wp_kses($value, wp_kses_allowed_html('post')); |
|
123 | + $value = wp_kses( $value, wp_kses_allowed_html( 'post' ) ); |
|
124 | 124 | }); |
125 | - return Arr::convertDotNotationArray($options); |
|
125 | + return Arr::convertDotNotationArray( $options ); |
|
126 | 126 | } |
127 | 127 | |
128 | 128 | /** |
@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | */ |
131 | 131 | public function isRecaptchaEnabled() |
132 | 132 | { |
133 | - $integration = $this->get('settings.submissions.recaptcha.integration'); |
|
133 | + $integration = $this->get( 'settings.submissions.recaptcha.integration' ); |
|
134 | 134 | return 'all' == $integration || ('guest' == $integration && !is_user_logged_in()); |
135 | 135 | } |
136 | 136 | |
@@ -139,9 +139,9 @@ discard block |
||
139 | 139 | */ |
140 | 140 | public function reset() |
141 | 141 | { |
142 | - $options = $this->getWP(static::databaseKey(), []); |
|
143 | - if (!is_array($options) || empty($options)) { |
|
144 | - delete_option(static::databaseKey()); |
|
142 | + $options = $this->getWP( static::databaseKey(), [] ); |
|
143 | + if( !is_array( $options ) || empty($options) ) { |
|
144 | + delete_option( static::databaseKey() ); |
|
145 | 145 | $options = glsr()->defaults ?: []; |
146 | 146 | } |
147 | 147 | $this->options = $options; |
@@ -152,12 +152,12 @@ discard block |
||
152 | 152 | * @param mixed $value |
153 | 153 | * @return bool |
154 | 154 | */ |
155 | - public function set($pathOrOptions, $value = '') |
|
155 | + public function set( $pathOrOptions, $value = '' ) |
|
156 | 156 | { |
157 | - if (is_string($pathOrOptions)) { |
|
158 | - $pathOrOptions = Arr::set($this->all(), $pathOrOptions, $value); |
|
157 | + if( is_string( $pathOrOptions ) ) { |
|
158 | + $pathOrOptions = Arr::set( $this->all(), $pathOrOptions, $value ); |
|
159 | 159 | } |
160 | - if ($result = update_option(static::databaseKey(), (array) $pathOrOptions)) { |
|
160 | + if( $result = update_option( static::databaseKey(), (array)$pathOrOptions ) ) { |
|
161 | 161 | $this->reset(); |
162 | 162 | } |
163 | 163 | return $result; |
@@ -14,248 +14,248 @@ |
||
14 | 14 | |
15 | 15 | class CountsManager |
16 | 16 | { |
17 | - const LIMIT = 500; |
|
18 | - const META_AVERAGE = '_glsr_average'; |
|
19 | - const META_COUNT = '_glsr_count'; |
|
20 | - const META_RANKING = '_glsr_ranking'; |
|
17 | + const LIMIT = 500; |
|
18 | + const META_AVERAGE = '_glsr_average'; |
|
19 | + const META_COUNT = '_glsr_count'; |
|
20 | + const META_RANKING = '_glsr_ranking'; |
|
21 | 21 | |
22 | - /** |
|
23 | - * @return array |
|
24 | - */ |
|
25 | - public function buildCounts(array $args = []) |
|
26 | - { |
|
27 | - $counts = [ |
|
28 | - 'local' => $this->generateEmptyCountsArray(), |
|
29 | - ]; |
|
30 | - $query = $this->queryReviews($args); |
|
31 | - while ($query) { |
|
32 | - $counts = $this->populateCountsFromQuery($query, $counts); |
|
33 | - $query = $query->has_more |
|
34 | - ? $this->queryReviews($args, end($query->reviews)->ID) |
|
35 | - : false; |
|
36 | - } |
|
37 | - return $counts; |
|
38 | - } |
|
22 | + /** |
|
23 | + * @return array |
|
24 | + */ |
|
25 | + public function buildCounts(array $args = []) |
|
26 | + { |
|
27 | + $counts = [ |
|
28 | + 'local' => $this->generateEmptyCountsArray(), |
|
29 | + ]; |
|
30 | + $query = $this->queryReviews($args); |
|
31 | + while ($query) { |
|
32 | + $counts = $this->populateCountsFromQuery($query, $counts); |
|
33 | + $query = $query->has_more |
|
34 | + ? $this->queryReviews($args, end($query->reviews)->ID) |
|
35 | + : false; |
|
36 | + } |
|
37 | + return $counts; |
|
38 | + } |
|
39 | 39 | |
40 | - /** |
|
41 | - * @return void |
|
42 | - */ |
|
43 | - public function decreaseAll(Review $review) |
|
44 | - { |
|
45 | - glsr(GlobalCountsManager::class)->decrease($review); |
|
46 | - glsr(PostCountsManager::class)->decrease($review); |
|
47 | - glsr(TermCountsManager::class)->decrease($review); |
|
48 | - } |
|
40 | + /** |
|
41 | + * @return void |
|
42 | + */ |
|
43 | + public function decreaseAll(Review $review) |
|
44 | + { |
|
45 | + glsr(GlobalCountsManager::class)->decrease($review); |
|
46 | + glsr(PostCountsManager::class)->decrease($review); |
|
47 | + glsr(TermCountsManager::class)->decrease($review); |
|
48 | + } |
|
49 | 49 | |
50 | - /** |
|
51 | - * @param string $type |
|
52 | - * @param int $rating |
|
53 | - * @return array |
|
54 | - */ |
|
55 | - public function decreaseRating(array $reviewCounts, $type, $rating) |
|
56 | - { |
|
57 | - if (isset($reviewCounts[$type][$rating])) { |
|
58 | - $reviewCounts[$type][$rating] = max(0, $reviewCounts[$type][$rating] - 1); |
|
59 | - } |
|
60 | - return $reviewCounts; |
|
61 | - } |
|
50 | + /** |
|
51 | + * @param string $type |
|
52 | + * @param int $rating |
|
53 | + * @return array |
|
54 | + */ |
|
55 | + public function decreaseRating(array $reviewCounts, $type, $rating) |
|
56 | + { |
|
57 | + if (isset($reviewCounts[$type][$rating])) { |
|
58 | + $reviewCounts[$type][$rating] = max(0, $reviewCounts[$type][$rating] - 1); |
|
59 | + } |
|
60 | + return $reviewCounts; |
|
61 | + } |
|
62 | 62 | |
63 | - /** |
|
64 | - * @return array |
|
65 | - */ |
|
66 | - public function flatten(array $reviewCounts, array $args = []) |
|
67 | - { |
|
68 | - $counts = []; |
|
69 | - array_walk_recursive($reviewCounts, function ($num, $index) use (&$counts) { |
|
70 | - $counts[$index] = $num + intval(Arr::get($counts, $index, 0)); |
|
71 | - }); |
|
72 | - $min = Arr::get($args, 'min', glsr()->constant('MIN_RATING', Rating::class)); |
|
73 | - $max = Arr::get($args, 'max', glsr()->constant('MAX_RATING', Rating::class)); |
|
74 | - foreach ($counts as $index => &$num) { |
|
75 | - if (!Helper::inRange($index, $min, $max)) { |
|
76 | - $num = 0; |
|
77 | - } |
|
78 | - } |
|
79 | - return $counts; |
|
80 | - } |
|
63 | + /** |
|
64 | + * @return array |
|
65 | + */ |
|
66 | + public function flatten(array $reviewCounts, array $args = []) |
|
67 | + { |
|
68 | + $counts = []; |
|
69 | + array_walk_recursive($reviewCounts, function ($num, $index) use (&$counts) { |
|
70 | + $counts[$index] = $num + intval(Arr::get($counts, $index, 0)); |
|
71 | + }); |
|
72 | + $min = Arr::get($args, 'min', glsr()->constant('MIN_RATING', Rating::class)); |
|
73 | + $max = Arr::get($args, 'max', glsr()->constant('MAX_RATING', Rating::class)); |
|
74 | + foreach ($counts as $index => &$num) { |
|
75 | + if (!Helper::inRange($index, $min, $max)) { |
|
76 | + $num = 0; |
|
77 | + } |
|
78 | + } |
|
79 | + return $counts; |
|
80 | + } |
|
81 | 81 | |
82 | - /** |
|
83 | - * @return array |
|
84 | - */ |
|
85 | - public function getCounts(array $args = []) |
|
86 | - { |
|
87 | - $args = $this->normalizeArgs($args); |
|
88 | - $counts = $this->hasMixedAssignment($args) |
|
89 | - ? $this->buildCounts($args) // force query the database |
|
90 | - : $this->get($args); |
|
91 | - return $this->normalize($counts); |
|
92 | - } |
|
82 | + /** |
|
83 | + * @return array |
|
84 | + */ |
|
85 | + public function getCounts(array $args = []) |
|
86 | + { |
|
87 | + $args = $this->normalizeArgs($args); |
|
88 | + $counts = $this->hasMixedAssignment($args) |
|
89 | + ? $this->buildCounts($args) // force query the database |
|
90 | + : $this->get($args); |
|
91 | + return $this->normalize($counts); |
|
92 | + } |
|
93 | 93 | |
94 | - /** |
|
95 | - * @return void |
|
96 | - */ |
|
97 | - public function increaseAll(Review $review) |
|
98 | - { |
|
99 | - glsr(GlobalCountsManager::class)->increase($review); |
|
100 | - glsr(PostCountsManager::class)->increase($review); |
|
101 | - glsr(TermCountsManager::class)->increase($review); |
|
102 | - } |
|
94 | + /** |
|
95 | + * @return void |
|
96 | + */ |
|
97 | + public function increaseAll(Review $review) |
|
98 | + { |
|
99 | + glsr(GlobalCountsManager::class)->increase($review); |
|
100 | + glsr(PostCountsManager::class)->increase($review); |
|
101 | + glsr(TermCountsManager::class)->increase($review); |
|
102 | + } |
|
103 | 103 | |
104 | - /** |
|
105 | - * @param string $type |
|
106 | - * @param int $rating |
|
107 | - * @return array |
|
108 | - */ |
|
109 | - public function increaseRating(array $reviewCounts, $type, $rating) |
|
110 | - { |
|
111 | - if (!array_key_exists($type, glsr()->reviewTypes)) { |
|
112 | - return $reviewCounts; |
|
113 | - } |
|
114 | - if (!array_key_exists($type, $reviewCounts)) { |
|
115 | - $reviewCounts[$type] = []; |
|
116 | - } |
|
117 | - $reviewCounts = $this->normalize($reviewCounts); |
|
118 | - $reviewCounts[$type][$rating] = intval($reviewCounts[$type][$rating]) + 1; |
|
119 | - return $reviewCounts; |
|
120 | - } |
|
104 | + /** |
|
105 | + * @param string $type |
|
106 | + * @param int $rating |
|
107 | + * @return array |
|
108 | + */ |
|
109 | + public function increaseRating(array $reviewCounts, $type, $rating) |
|
110 | + { |
|
111 | + if (!array_key_exists($type, glsr()->reviewTypes)) { |
|
112 | + return $reviewCounts; |
|
113 | + } |
|
114 | + if (!array_key_exists($type, $reviewCounts)) { |
|
115 | + $reviewCounts[$type] = []; |
|
116 | + } |
|
117 | + $reviewCounts = $this->normalize($reviewCounts); |
|
118 | + $reviewCounts[$type][$rating] = intval($reviewCounts[$type][$rating]) + 1; |
|
119 | + return $reviewCounts; |
|
120 | + } |
|
121 | 121 | |
122 | - /** |
|
123 | - * @return void |
|
124 | - */ |
|
125 | - public function updateAll() |
|
126 | - { |
|
127 | - glsr(GlobalCountsManager::class)->updateAll(); |
|
128 | - glsr(PostCountsManager::class)->updateAll(); |
|
129 | - glsr(TermCountsManager::class)->updateAll(); |
|
130 | - glsr(OptionManager::class)->set('last_review_count', current_time('timestamp')); |
|
131 | - } |
|
122 | + /** |
|
123 | + * @return void |
|
124 | + */ |
|
125 | + public function updateAll() |
|
126 | + { |
|
127 | + glsr(GlobalCountsManager::class)->updateAll(); |
|
128 | + glsr(PostCountsManager::class)->updateAll(); |
|
129 | + glsr(TermCountsManager::class)->updateAll(); |
|
130 | + glsr(OptionManager::class)->set('last_review_count', current_time('timestamp')); |
|
131 | + } |
|
132 | 132 | |
133 | - /** |
|
134 | - * @return array |
|
135 | - */ |
|
136 | - protected function combine(array $results) |
|
137 | - { |
|
138 | - if (!wp_is_numeric_array($results)) { |
|
139 | - return $results; |
|
140 | - } |
|
141 | - $mergedKeys = array_keys(array_merge(...$results)); |
|
142 | - $counts = array_fill_keys($mergedKeys, $this->generateEmptyCountsArray()); |
|
143 | - foreach ($results as $typeRatings) { |
|
144 | - foreach ($typeRatings as $type => $ratings) { |
|
145 | - foreach ($ratings as $index => $rating) { |
|
146 | - $counts[$type][$index] = intval($rating) + $counts[$type][$index]; |
|
147 | - } |
|
148 | - } |
|
149 | - } |
|
150 | - return $counts; |
|
151 | - } |
|
133 | + /** |
|
134 | + * @return array |
|
135 | + */ |
|
136 | + protected function combine(array $results) |
|
137 | + { |
|
138 | + if (!wp_is_numeric_array($results)) { |
|
139 | + return $results; |
|
140 | + } |
|
141 | + $mergedKeys = array_keys(array_merge(...$results)); |
|
142 | + $counts = array_fill_keys($mergedKeys, $this->generateEmptyCountsArray()); |
|
143 | + foreach ($results as $typeRatings) { |
|
144 | + foreach ($typeRatings as $type => $ratings) { |
|
145 | + foreach ($ratings as $index => $rating) { |
|
146 | + $counts[$type][$index] = intval($rating) + $counts[$type][$index]; |
|
147 | + } |
|
148 | + } |
|
149 | + } |
|
150 | + return $counts; |
|
151 | + } |
|
152 | 152 | |
153 | - /** |
|
154 | - * @return array |
|
155 | - */ |
|
156 | - protected function generateEmptyCountsArray() |
|
157 | - { |
|
158 | - return array_fill_keys(range(0, glsr()->constant('MAX_RATING', Rating::class)), 0); |
|
159 | - } |
|
153 | + /** |
|
154 | + * @return array |
|
155 | + */ |
|
156 | + protected function generateEmptyCountsArray() |
|
157 | + { |
|
158 | + return array_fill_keys(range(0, glsr()->constant('MAX_RATING', Rating::class)), 0); |
|
159 | + } |
|
160 | 160 | |
161 | - /** |
|
162 | - * @return array |
|
163 | - */ |
|
164 | - protected function get($args) |
|
165 | - { |
|
166 | - $results = []; |
|
167 | - foreach ($args['post_ids'] as $postId) { |
|
168 | - $results[] = glsr(PostCountsManager::class)->get($postId); |
|
169 | - } |
|
170 | - foreach ($args['term_ids'] as $termId) { |
|
171 | - $results[] = glsr(TermCountsManager::class)->get($termId); |
|
172 | - } |
|
173 | - if (empty($results)) { |
|
174 | - $results[] = glsr(GlobalCountsManager::class)->get(); |
|
175 | - } |
|
176 | - $results[] = ['local' => $this->generateEmptyCountsArray()]; // make sure there is a fallback |
|
177 | - return $this->combine($results); |
|
178 | - } |
|
161 | + /** |
|
162 | + * @return array |
|
163 | + */ |
|
164 | + protected function get($args) |
|
165 | + { |
|
166 | + $results = []; |
|
167 | + foreach ($args['post_ids'] as $postId) { |
|
168 | + $results[] = glsr(PostCountsManager::class)->get($postId); |
|
169 | + } |
|
170 | + foreach ($args['term_ids'] as $termId) { |
|
171 | + $results[] = glsr(TermCountsManager::class)->get($termId); |
|
172 | + } |
|
173 | + if (empty($results)) { |
|
174 | + $results[] = glsr(GlobalCountsManager::class)->get(); |
|
175 | + } |
|
176 | + $results[] = ['local' => $this->generateEmptyCountsArray()]; // make sure there is a fallback |
|
177 | + return $this->combine($results); |
|
178 | + } |
|
179 | 179 | |
180 | - /** |
|
181 | - * @return bool |
|
182 | - */ |
|
183 | - protected function hasMixedAssignment(array $args) |
|
184 | - { |
|
185 | - return !empty($args['post_ids']) && !empty($args['term_ids']); |
|
186 | - } |
|
180 | + /** |
|
181 | + * @return bool |
|
182 | + */ |
|
183 | + protected function hasMixedAssignment(array $args) |
|
184 | + { |
|
185 | + return !empty($args['post_ids']) && !empty($args['term_ids']); |
|
186 | + } |
|
187 | 187 | |
188 | - /** |
|
189 | - * @return array |
|
190 | - */ |
|
191 | - protected function normalize(array $reviewCounts) |
|
192 | - { |
|
193 | - foreach ($reviewCounts as &$counts) { |
|
194 | - foreach (array_keys($this->generateEmptyCountsArray()) as $index) { |
|
195 | - if (!isset($counts[$index])) { |
|
196 | - $counts[$index] = 0; |
|
197 | - } |
|
198 | - } |
|
199 | - ksort($counts); |
|
200 | - } |
|
201 | - return $reviewCounts; |
|
202 | - } |
|
188 | + /** |
|
189 | + * @return array |
|
190 | + */ |
|
191 | + protected function normalize(array $reviewCounts) |
|
192 | + { |
|
193 | + foreach ($reviewCounts as &$counts) { |
|
194 | + foreach (array_keys($this->generateEmptyCountsArray()) as $index) { |
|
195 | + if (!isset($counts[$index])) { |
|
196 | + $counts[$index] = 0; |
|
197 | + } |
|
198 | + } |
|
199 | + ksort($counts); |
|
200 | + } |
|
201 | + return $reviewCounts; |
|
202 | + } |
|
203 | 203 | |
204 | - /** |
|
205 | - * @return array |
|
206 | - */ |
|
207 | - protected function normalizeArgs(array $args) |
|
208 | - { |
|
209 | - $args = wp_parse_args(array_filter($args), [ |
|
210 | - 'post_ids' => [], |
|
211 | - 'term_ids' => [], |
|
212 | - 'type' => 'local', |
|
213 | - ]); |
|
214 | - $args['post_ids'] = glsr(Multilingual::class)->getPostIds($args['post_ids']); |
|
215 | - $args['type'] = $this->normalizeType($args['type']); |
|
216 | - return $args; |
|
217 | - } |
|
204 | + /** |
|
205 | + * @return array |
|
206 | + */ |
|
207 | + protected function normalizeArgs(array $args) |
|
208 | + { |
|
209 | + $args = wp_parse_args(array_filter($args), [ |
|
210 | + 'post_ids' => [], |
|
211 | + 'term_ids' => [], |
|
212 | + 'type' => 'local', |
|
213 | + ]); |
|
214 | + $args['post_ids'] = glsr(Multilingual::class)->getPostIds($args['post_ids']); |
|
215 | + $args['type'] = $this->normalizeType($args['type']); |
|
216 | + return $args; |
|
217 | + } |
|
218 | 218 | |
219 | - /** |
|
220 | - * @param string $type |
|
221 | - * @return string |
|
222 | - */ |
|
223 | - protected function normalizeType($type) |
|
224 | - { |
|
225 | - return empty($type) || !is_string($type) |
|
226 | - ? 'local' |
|
227 | - : $type; |
|
228 | - } |
|
219 | + /** |
|
220 | + * @param string $type |
|
221 | + * @return string |
|
222 | + */ |
|
223 | + protected function normalizeType($type) |
|
224 | + { |
|
225 | + return empty($type) || !is_string($type) |
|
226 | + ? 'local' |
|
227 | + : $type; |
|
228 | + } |
|
229 | 229 | |
230 | - /** |
|
231 | - * @param object $query |
|
232 | - * @return array |
|
233 | - */ |
|
234 | - protected function populateCountsFromQuery($query, array $counts) |
|
235 | - { |
|
236 | - foreach ($query->reviews as $review) { |
|
237 | - $type = $this->normalizeType($review->type); |
|
238 | - if (!array_key_exists($type, $counts)) { |
|
239 | - $counts[$type] = $this->generateEmptyCountsArray(); |
|
240 | - } |
|
241 | - ++$counts[$type][$review->rating]; |
|
242 | - } |
|
243 | - return $counts; |
|
244 | - } |
|
230 | + /** |
|
231 | + * @param object $query |
|
232 | + * @return array |
|
233 | + */ |
|
234 | + protected function populateCountsFromQuery($query, array $counts) |
|
235 | + { |
|
236 | + foreach ($query->reviews as $review) { |
|
237 | + $type = $this->normalizeType($review->type); |
|
238 | + if (!array_key_exists($type, $counts)) { |
|
239 | + $counts[$type] = $this->generateEmptyCountsArray(); |
|
240 | + } |
|
241 | + ++$counts[$type][$review->rating]; |
|
242 | + } |
|
243 | + return $counts; |
|
244 | + } |
|
245 | 245 | |
246 | - /** |
|
247 | - * @param int $lastPostId |
|
248 | - * @return object |
|
249 | - */ |
|
250 | - protected function queryReviews(array $args = [], $lastPostId = 0) |
|
251 | - { |
|
252 | - $reviews = glsr(SqlQueries::class)->getReviewCounts($args, $lastPostId, static::LIMIT); |
|
253 | - $hasMore = is_array($reviews) |
|
254 | - ? count($reviews) == static::LIMIT |
|
255 | - : false; |
|
256 | - return (object) [ |
|
257 | - 'has_more' => $hasMore, |
|
258 | - 'reviews' => $reviews, |
|
259 | - ]; |
|
260 | - } |
|
246 | + /** |
|
247 | + * @param int $lastPostId |
|
248 | + * @return object |
|
249 | + */ |
|
250 | + protected function queryReviews(array $args = [], $lastPostId = 0) |
|
251 | + { |
|
252 | + $reviews = glsr(SqlQueries::class)->getReviewCounts($args, $lastPostId, static::LIMIT); |
|
253 | + $hasMore = is_array($reviews) |
|
254 | + ? count($reviews) == static::LIMIT |
|
255 | + : false; |
|
256 | + return (object) [ |
|
257 | + 'has_more' => $hasMore, |
|
258 | + 'reviews' => $reviews, |
|
259 | + ]; |
|
260 | + } |
|
261 | 261 | } |
@@ -22,16 +22,16 @@ discard block |
||
22 | 22 | /** |
23 | 23 | * @return array |
24 | 24 | */ |
25 | - public function buildCounts(array $args = []) |
|
25 | + public function buildCounts( array $args = [] ) |
|
26 | 26 | { |
27 | 27 | $counts = [ |
28 | 28 | 'local' => $this->generateEmptyCountsArray(), |
29 | 29 | ]; |
30 | - $query = $this->queryReviews($args); |
|
31 | - while ($query) { |
|
32 | - $counts = $this->populateCountsFromQuery($query, $counts); |
|
30 | + $query = $this->queryReviews( $args ); |
|
31 | + while( $query ) { |
|
32 | + $counts = $this->populateCountsFromQuery( $query, $counts ); |
|
33 | 33 | $query = $query->has_more |
34 | - ? $this->queryReviews($args, end($query->reviews)->ID) |
|
34 | + ? $this->queryReviews( $args, end( $query->reviews )->ID ) |
|
35 | 35 | : false; |
36 | 36 | } |
37 | 37 | return $counts; |
@@ -40,11 +40,11 @@ discard block |
||
40 | 40 | /** |
41 | 41 | * @return void |
42 | 42 | */ |
43 | - public function decreaseAll(Review $review) |
|
43 | + public function decreaseAll( Review $review ) |
|
44 | 44 | { |
45 | - glsr(GlobalCountsManager::class)->decrease($review); |
|
46 | - glsr(PostCountsManager::class)->decrease($review); |
|
47 | - glsr(TermCountsManager::class)->decrease($review); |
|
45 | + glsr( GlobalCountsManager::class )->decrease( $review ); |
|
46 | + glsr( PostCountsManager::class )->decrease( $review ); |
|
47 | + glsr( TermCountsManager::class )->decrease( $review ); |
|
48 | 48 | } |
49 | 49 | |
50 | 50 | /** |
@@ -52,10 +52,10 @@ discard block |
||
52 | 52 | * @param int $rating |
53 | 53 | * @return array |
54 | 54 | */ |
55 | - public function decreaseRating(array $reviewCounts, $type, $rating) |
|
55 | + public function decreaseRating( array $reviewCounts, $type, $rating ) |
|
56 | 56 | { |
57 | - if (isset($reviewCounts[$type][$rating])) { |
|
58 | - $reviewCounts[$type][$rating] = max(0, $reviewCounts[$type][$rating] - 1); |
|
57 | + if( isset($reviewCounts[$type][$rating]) ) { |
|
58 | + $reviewCounts[$type][$rating] = max( 0, $reviewCounts[$type][$rating] - 1 ); |
|
59 | 59 | } |
60 | 60 | return $reviewCounts; |
61 | 61 | } |
@@ -63,16 +63,16 @@ discard block |
||
63 | 63 | /** |
64 | 64 | * @return array |
65 | 65 | */ |
66 | - public function flatten(array $reviewCounts, array $args = []) |
|
66 | + public function flatten( array $reviewCounts, array $args = [] ) |
|
67 | 67 | { |
68 | 68 | $counts = []; |
69 | - array_walk_recursive($reviewCounts, function ($num, $index) use (&$counts) { |
|
70 | - $counts[$index] = $num + intval(Arr::get($counts, $index, 0)); |
|
69 | + array_walk_recursive( $reviewCounts, function( $num, $index ) use (&$counts) { |
|
70 | + $counts[$index] = $num + intval( Arr::get( $counts, $index, 0 ) ); |
|
71 | 71 | }); |
72 | - $min = Arr::get($args, 'min', glsr()->constant('MIN_RATING', Rating::class)); |
|
73 | - $max = Arr::get($args, 'max', glsr()->constant('MAX_RATING', Rating::class)); |
|
74 | - foreach ($counts as $index => &$num) { |
|
75 | - if (!Helper::inRange($index, $min, $max)) { |
|
72 | + $min = Arr::get( $args, 'min', glsr()->constant( 'MIN_RATING', Rating::class ) ); |
|
73 | + $max = Arr::get( $args, 'max', glsr()->constant( 'MAX_RATING', Rating::class ) ); |
|
74 | + foreach( $counts as $index => &$num ) { |
|
75 | + if( !Helper::inRange( $index, $min, $max ) ) { |
|
76 | 76 | $num = 0; |
77 | 77 | } |
78 | 78 | } |
@@ -82,23 +82,23 @@ discard block |
||
82 | 82 | /** |
83 | 83 | * @return array |
84 | 84 | */ |
85 | - public function getCounts(array $args = []) |
|
85 | + public function getCounts( array $args = [] ) |
|
86 | 86 | { |
87 | - $args = $this->normalizeArgs($args); |
|
88 | - $counts = $this->hasMixedAssignment($args) |
|
89 | - ? $this->buildCounts($args) // force query the database |
|
90 | - : $this->get($args); |
|
91 | - return $this->normalize($counts); |
|
87 | + $args = $this->normalizeArgs( $args ); |
|
88 | + $counts = $this->hasMixedAssignment( $args ) |
|
89 | + ? $this->buildCounts( $args ) // force query the database |
|
90 | + : $this->get( $args ); |
|
91 | + return $this->normalize( $counts ); |
|
92 | 92 | } |
93 | 93 | |
94 | 94 | /** |
95 | 95 | * @return void |
96 | 96 | */ |
97 | - public function increaseAll(Review $review) |
|
97 | + public function increaseAll( Review $review ) |
|
98 | 98 | { |
99 | - glsr(GlobalCountsManager::class)->increase($review); |
|
100 | - glsr(PostCountsManager::class)->increase($review); |
|
101 | - glsr(TermCountsManager::class)->increase($review); |
|
99 | + glsr( GlobalCountsManager::class )->increase( $review ); |
|
100 | + glsr( PostCountsManager::class )->increase( $review ); |
|
101 | + glsr( TermCountsManager::class )->increase( $review ); |
|
102 | 102 | } |
103 | 103 | |
104 | 104 | /** |
@@ -106,16 +106,16 @@ discard block |
||
106 | 106 | * @param int $rating |
107 | 107 | * @return array |
108 | 108 | */ |
109 | - public function increaseRating(array $reviewCounts, $type, $rating) |
|
109 | + public function increaseRating( array $reviewCounts, $type, $rating ) |
|
110 | 110 | { |
111 | - if (!array_key_exists($type, glsr()->reviewTypes)) { |
|
111 | + if( !array_key_exists( $type, glsr()->reviewTypes ) ) { |
|
112 | 112 | return $reviewCounts; |
113 | 113 | } |
114 | - if (!array_key_exists($type, $reviewCounts)) { |
|
114 | + if( !array_key_exists( $type, $reviewCounts ) ) { |
|
115 | 115 | $reviewCounts[$type] = []; |
116 | 116 | } |
117 | - $reviewCounts = $this->normalize($reviewCounts); |
|
118 | - $reviewCounts[$type][$rating] = intval($reviewCounts[$type][$rating]) + 1; |
|
117 | + $reviewCounts = $this->normalize( $reviewCounts ); |
|
118 | + $reviewCounts[$type][$rating] = intval( $reviewCounts[$type][$rating] ) + 1; |
|
119 | 119 | return $reviewCounts; |
120 | 120 | } |
121 | 121 | |
@@ -124,26 +124,26 @@ discard block |
||
124 | 124 | */ |
125 | 125 | public function updateAll() |
126 | 126 | { |
127 | - glsr(GlobalCountsManager::class)->updateAll(); |
|
128 | - glsr(PostCountsManager::class)->updateAll(); |
|
129 | - glsr(TermCountsManager::class)->updateAll(); |
|
130 | - glsr(OptionManager::class)->set('last_review_count', current_time('timestamp')); |
|
127 | + glsr( GlobalCountsManager::class )->updateAll(); |
|
128 | + glsr( PostCountsManager::class )->updateAll(); |
|
129 | + glsr( TermCountsManager::class )->updateAll(); |
|
130 | + glsr( OptionManager::class )->set( 'last_review_count', current_time( 'timestamp' ) ); |
|
131 | 131 | } |
132 | 132 | |
133 | 133 | /** |
134 | 134 | * @return array |
135 | 135 | */ |
136 | - protected function combine(array $results) |
|
136 | + protected function combine( array $results ) |
|
137 | 137 | { |
138 | - if (!wp_is_numeric_array($results)) { |
|
138 | + if( !wp_is_numeric_array( $results ) ) { |
|
139 | 139 | return $results; |
140 | 140 | } |
141 | - $mergedKeys = array_keys(array_merge(...$results)); |
|
142 | - $counts = array_fill_keys($mergedKeys, $this->generateEmptyCountsArray()); |
|
143 | - foreach ($results as $typeRatings) { |
|
144 | - foreach ($typeRatings as $type => $ratings) { |
|
145 | - foreach ($ratings as $index => $rating) { |
|
146 | - $counts[$type][$index] = intval($rating) + $counts[$type][$index]; |
|
141 | + $mergedKeys = array_keys( array_merge( ...$results ) ); |
|
142 | + $counts = array_fill_keys( $mergedKeys, $this->generateEmptyCountsArray() ); |
|
143 | + foreach( $results as $typeRatings ) { |
|
144 | + foreach( $typeRatings as $type => $ratings ) { |
|
145 | + foreach( $ratings as $index => $rating ) { |
|
146 | + $counts[$type][$index] = intval( $rating ) + $counts[$type][$index]; |
|
147 | 147 | } |
148 | 148 | } |
149 | 149 | } |
@@ -155,32 +155,32 @@ discard block |
||
155 | 155 | */ |
156 | 156 | protected function generateEmptyCountsArray() |
157 | 157 | { |
158 | - return array_fill_keys(range(0, glsr()->constant('MAX_RATING', Rating::class)), 0); |
|
158 | + return array_fill_keys( range( 0, glsr()->constant( 'MAX_RATING', Rating::class ) ), 0 ); |
|
159 | 159 | } |
160 | 160 | |
161 | 161 | /** |
162 | 162 | * @return array |
163 | 163 | */ |
164 | - protected function get($args) |
|
164 | + protected function get( $args ) |
|
165 | 165 | { |
166 | 166 | $results = []; |
167 | - foreach ($args['post_ids'] as $postId) { |
|
168 | - $results[] = glsr(PostCountsManager::class)->get($postId); |
|
167 | + foreach( $args['post_ids'] as $postId ) { |
|
168 | + $results[] = glsr( PostCountsManager::class )->get( $postId ); |
|
169 | 169 | } |
170 | - foreach ($args['term_ids'] as $termId) { |
|
171 | - $results[] = glsr(TermCountsManager::class)->get($termId); |
|
170 | + foreach( $args['term_ids'] as $termId ) { |
|
171 | + $results[] = glsr( TermCountsManager::class )->get( $termId ); |
|
172 | 172 | } |
173 | - if (empty($results)) { |
|
174 | - $results[] = glsr(GlobalCountsManager::class)->get(); |
|
173 | + if( empty($results) ) { |
|
174 | + $results[] = glsr( GlobalCountsManager::class )->get(); |
|
175 | 175 | } |
176 | 176 | $results[] = ['local' => $this->generateEmptyCountsArray()]; // make sure there is a fallback |
177 | - return $this->combine($results); |
|
177 | + return $this->combine( $results ); |
|
178 | 178 | } |
179 | 179 | |
180 | 180 | /** |
181 | 181 | * @return bool |
182 | 182 | */ |
183 | - protected function hasMixedAssignment(array $args) |
|
183 | + protected function hasMixedAssignment( array $args ) |
|
184 | 184 | { |
185 | 185 | return !empty($args['post_ids']) && !empty($args['term_ids']); |
186 | 186 | } |
@@ -188,15 +188,15 @@ discard block |
||
188 | 188 | /** |
189 | 189 | * @return array |
190 | 190 | */ |
191 | - protected function normalize(array $reviewCounts) |
|
191 | + protected function normalize( array $reviewCounts ) |
|
192 | 192 | { |
193 | - foreach ($reviewCounts as &$counts) { |
|
194 | - foreach (array_keys($this->generateEmptyCountsArray()) as $index) { |
|
195 | - if (!isset($counts[$index])) { |
|
193 | + foreach( $reviewCounts as &$counts ) { |
|
194 | + foreach( array_keys( $this->generateEmptyCountsArray() ) as $index ) { |
|
195 | + if( !isset($counts[$index]) ) { |
|
196 | 196 | $counts[$index] = 0; |
197 | 197 | } |
198 | 198 | } |
199 | - ksort($counts); |
|
199 | + ksort( $counts ); |
|
200 | 200 | } |
201 | 201 | return $reviewCounts; |
202 | 202 | } |
@@ -204,15 +204,15 @@ discard block |
||
204 | 204 | /** |
205 | 205 | * @return array |
206 | 206 | */ |
207 | - protected function normalizeArgs(array $args) |
|
207 | + protected function normalizeArgs( array $args ) |
|
208 | 208 | { |
209 | - $args = wp_parse_args(array_filter($args), [ |
|
209 | + $args = wp_parse_args( array_filter( $args ), [ |
|
210 | 210 | 'post_ids' => [], |
211 | 211 | 'term_ids' => [], |
212 | 212 | 'type' => 'local', |
213 | - ]); |
|
214 | - $args['post_ids'] = glsr(Multilingual::class)->getPostIds($args['post_ids']); |
|
215 | - $args['type'] = $this->normalizeType($args['type']); |
|
213 | + ] ); |
|
214 | + $args['post_ids'] = glsr( Multilingual::class )->getPostIds( $args['post_ids'] ); |
|
215 | + $args['type'] = $this->normalizeType( $args['type'] ); |
|
216 | 216 | return $args; |
217 | 217 | } |
218 | 218 | |
@@ -220,9 +220,9 @@ discard block |
||
220 | 220 | * @param string $type |
221 | 221 | * @return string |
222 | 222 | */ |
223 | - protected function normalizeType($type) |
|
223 | + protected function normalizeType( $type ) |
|
224 | 224 | { |
225 | - return empty($type) || !is_string($type) |
|
225 | + return empty($type) || !is_string( $type ) |
|
226 | 226 | ? 'local' |
227 | 227 | : $type; |
228 | 228 | } |
@@ -231,11 +231,11 @@ discard block |
||
231 | 231 | * @param object $query |
232 | 232 | * @return array |
233 | 233 | */ |
234 | - protected function populateCountsFromQuery($query, array $counts) |
|
234 | + protected function populateCountsFromQuery( $query, array $counts ) |
|
235 | 235 | { |
236 | - foreach ($query->reviews as $review) { |
|
237 | - $type = $this->normalizeType($review->type); |
|
238 | - if (!array_key_exists($type, $counts)) { |
|
236 | + foreach( $query->reviews as $review ) { |
|
237 | + $type = $this->normalizeType( $review->type ); |
|
238 | + if( !array_key_exists( $type, $counts ) ) { |
|
239 | 239 | $counts[$type] = $this->generateEmptyCountsArray(); |
240 | 240 | } |
241 | 241 | ++$counts[$type][$review->rating]; |
@@ -247,13 +247,13 @@ discard block |
||
247 | 247 | * @param int $lastPostId |
248 | 248 | * @return object |
249 | 249 | */ |
250 | - protected function queryReviews(array $args = [], $lastPostId = 0) |
|
250 | + protected function queryReviews( array $args = [], $lastPostId = 0 ) |
|
251 | 251 | { |
252 | - $reviews = glsr(SqlQueries::class)->getReviewCounts($args, $lastPostId, static::LIMIT); |
|
253 | - $hasMore = is_array($reviews) |
|
254 | - ? count($reviews) == static::LIMIT |
|
252 | + $reviews = glsr( SqlQueries::class )->getReviewCounts( $args, $lastPostId, static::LIMIT ); |
|
253 | + $hasMore = is_array( $reviews ) |
|
254 | + ? count( $reviews ) == static::LIMIT |
|
255 | 255 | : false; |
256 | - return (object) [ |
|
256 | + return (object)[ |
|
257 | 257 | 'has_more' => $hasMore, |
258 | 258 | 'reviews' => $reviews, |
259 | 259 | ]; |
@@ -6,145 +6,145 @@ |
||
6 | 6 | |
7 | 7 | class CreateReview |
8 | 8 | { |
9 | - public $ajax_request; |
|
10 | - public $assigned_to; |
|
11 | - public $author; |
|
12 | - public $avatar; |
|
13 | - public $blacklisted; |
|
14 | - public $category; |
|
15 | - public $content; |
|
16 | - public $custom; |
|
17 | - public $date; |
|
18 | - public $email; |
|
19 | - public $form_id; |
|
20 | - public $ip_address; |
|
21 | - public $post_id; |
|
22 | - public $rating; |
|
23 | - public $referer; |
|
24 | - public $request; |
|
25 | - public $response; |
|
26 | - public $terms; |
|
27 | - public $title; |
|
28 | - public $url; |
|
9 | + public $ajax_request; |
|
10 | + public $assigned_to; |
|
11 | + public $author; |
|
12 | + public $avatar; |
|
13 | + public $blacklisted; |
|
14 | + public $category; |
|
15 | + public $content; |
|
16 | + public $custom; |
|
17 | + public $date; |
|
18 | + public $email; |
|
19 | + public $form_id; |
|
20 | + public $ip_address; |
|
21 | + public $post_id; |
|
22 | + public $rating; |
|
23 | + public $referer; |
|
24 | + public $request; |
|
25 | + public $response; |
|
26 | + public $terms; |
|
27 | + public $title; |
|
28 | + public $url; |
|
29 | 29 | |
30 | - public function __construct($input) |
|
31 | - { |
|
32 | - $this->request = $input; |
|
33 | - $this->ajax_request = isset($input['_ajax_request']); |
|
34 | - $this->assigned_to = $this->getNumeric('assign_to'); |
|
35 | - $this->author = sanitize_text_field($this->getUser('name')); |
|
36 | - $this->avatar = $this->getAvatar(); |
|
37 | - $this->blacklisted = isset($input['blacklisted']); |
|
38 | - $this->category = $this->getCategory(); |
|
39 | - $this->content = sanitize_textarea_field($this->get('content')); |
|
40 | - $this->custom = $this->getCustom(); |
|
41 | - $this->date = $this->getDate('date'); |
|
42 | - $this->email = sanitize_email($this->getUser('email')); |
|
43 | - $this->form_id = sanitize_key($this->get('form_id')); |
|
44 | - $this->ip_address = $this->get('ip_address'); |
|
45 | - $this->post_id = intval($this->get('_post_id')); |
|
46 | - $this->rating = intval($this->get('rating')); |
|
47 | - $this->referer = sanitize_text_field($this->get('_referer')); |
|
48 | - $this->response = sanitize_textarea_field($this->get('response')); |
|
49 | - $this->terms = !empty($input['terms']); |
|
50 | - $this->title = sanitize_text_field($this->get('title')); |
|
51 | - $this->url = esc_url_raw(sanitize_text_field($this->get('url'))); |
|
52 | - } |
|
30 | + public function __construct($input) |
|
31 | + { |
|
32 | + $this->request = $input; |
|
33 | + $this->ajax_request = isset($input['_ajax_request']); |
|
34 | + $this->assigned_to = $this->getNumeric('assign_to'); |
|
35 | + $this->author = sanitize_text_field($this->getUser('name')); |
|
36 | + $this->avatar = $this->getAvatar(); |
|
37 | + $this->blacklisted = isset($input['blacklisted']); |
|
38 | + $this->category = $this->getCategory(); |
|
39 | + $this->content = sanitize_textarea_field($this->get('content')); |
|
40 | + $this->custom = $this->getCustom(); |
|
41 | + $this->date = $this->getDate('date'); |
|
42 | + $this->email = sanitize_email($this->getUser('email')); |
|
43 | + $this->form_id = sanitize_key($this->get('form_id')); |
|
44 | + $this->ip_address = $this->get('ip_address'); |
|
45 | + $this->post_id = intval($this->get('_post_id')); |
|
46 | + $this->rating = intval($this->get('rating')); |
|
47 | + $this->referer = sanitize_text_field($this->get('_referer')); |
|
48 | + $this->response = sanitize_textarea_field($this->get('response')); |
|
49 | + $this->terms = !empty($input['terms']); |
|
50 | + $this->title = sanitize_text_field($this->get('title')); |
|
51 | + $this->url = esc_url_raw(sanitize_text_field($this->get('url'))); |
|
52 | + } |
|
53 | 53 | |
54 | - /** |
|
55 | - * @param string $key |
|
56 | - * @return string |
|
57 | - */ |
|
58 | - protected function get($key) |
|
59 | - { |
|
60 | - return (string) Arr::get($this->request, $key); |
|
61 | - } |
|
54 | + /** |
|
55 | + * @param string $key |
|
56 | + * @return string |
|
57 | + */ |
|
58 | + protected function get($key) |
|
59 | + { |
|
60 | + return (string) Arr::get($this->request, $key); |
|
61 | + } |
|
62 | 62 | |
63 | - /** |
|
64 | - * @return string |
|
65 | - */ |
|
66 | - protected function getAvatar() |
|
67 | - { |
|
68 | - $avatar = $this->get('avatar'); |
|
69 | - return !filter_var($avatar, FILTER_VALIDATE_URL, FILTER_FLAG_PATH_REQUIRED) |
|
70 | - ? (string) get_avatar_url($this->get('email')) |
|
71 | - : $avatar; |
|
72 | - } |
|
63 | + /** |
|
64 | + * @return string |
|
65 | + */ |
|
66 | + protected function getAvatar() |
|
67 | + { |
|
68 | + $avatar = $this->get('avatar'); |
|
69 | + return !filter_var($avatar, FILTER_VALIDATE_URL, FILTER_FLAG_PATH_REQUIRED) |
|
70 | + ? (string) get_avatar_url($this->get('email')) |
|
71 | + : $avatar; |
|
72 | + } |
|
73 | 73 | |
74 | - /** |
|
75 | - * @return string |
|
76 | - */ |
|
77 | - protected function getCategory() |
|
78 | - { |
|
79 | - $categories = Arr::convertStringToArray($this->get('category')); |
|
80 | - return sanitize_key(Arr::get($categories, 0)); |
|
81 | - } |
|
74 | + /** |
|
75 | + * @return string |
|
76 | + */ |
|
77 | + protected function getCategory() |
|
78 | + { |
|
79 | + $categories = Arr::convertStringToArray($this->get('category')); |
|
80 | + return sanitize_key(Arr::get($categories, 0)); |
|
81 | + } |
|
82 | 82 | |
83 | - /** |
|
84 | - * @return array |
|
85 | - */ |
|
86 | - protected function getCustom() |
|
87 | - { |
|
88 | - $unset = [ |
|
89 | - '_action', '_ajax_request', '_counter', '_nonce', '_post_id', '_recaptcha-token', |
|
90 | - '_referer', 'assign_to', 'category', 'content', 'date', 'email', 'excluded', 'form_id', |
|
91 | - 'gotcha', 'ip_address', 'name', 'rating', 'response', 'terms', 'title', 'url', |
|
92 | - ]; |
|
93 | - $unset = apply_filters('site-reviews/create/unset-keys-from-custom', $unset); |
|
94 | - $custom = $this->request; |
|
95 | - foreach ($unset as $key) { |
|
96 | - unset($custom[$key]); |
|
97 | - } |
|
98 | - foreach ($custom as $key => $value) { |
|
99 | - if (is_string($value)) { |
|
100 | - $custom[$key] = sanitize_text_field($value); |
|
101 | - } |
|
102 | - } |
|
103 | - return $custom; |
|
104 | - } |
|
83 | + /** |
|
84 | + * @return array |
|
85 | + */ |
|
86 | + protected function getCustom() |
|
87 | + { |
|
88 | + $unset = [ |
|
89 | + '_action', '_ajax_request', '_counter', '_nonce', '_post_id', '_recaptcha-token', |
|
90 | + '_referer', 'assign_to', 'category', 'content', 'date', 'email', 'excluded', 'form_id', |
|
91 | + 'gotcha', 'ip_address', 'name', 'rating', 'response', 'terms', 'title', 'url', |
|
92 | + ]; |
|
93 | + $unset = apply_filters('site-reviews/create/unset-keys-from-custom', $unset); |
|
94 | + $custom = $this->request; |
|
95 | + foreach ($unset as $key) { |
|
96 | + unset($custom[$key]); |
|
97 | + } |
|
98 | + foreach ($custom as $key => $value) { |
|
99 | + if (is_string($value)) { |
|
100 | + $custom[$key] = sanitize_text_field($value); |
|
101 | + } |
|
102 | + } |
|
103 | + return $custom; |
|
104 | + } |
|
105 | 105 | |
106 | - /** |
|
107 | - * @param string $key |
|
108 | - * @return string |
|
109 | - */ |
|
110 | - protected function getDate($key) |
|
111 | - { |
|
112 | - $date = strtotime($this->get($key)); |
|
113 | - if (false === $date) { |
|
114 | - $date = time(); |
|
115 | - } |
|
116 | - return get_date_from_gmt(gmdate('Y-m-d H:i:s', $date)); |
|
117 | - } |
|
106 | + /** |
|
107 | + * @param string $key |
|
108 | + * @return string |
|
109 | + */ |
|
110 | + protected function getDate($key) |
|
111 | + { |
|
112 | + $date = strtotime($this->get($key)); |
|
113 | + if (false === $date) { |
|
114 | + $date = time(); |
|
115 | + } |
|
116 | + return get_date_from_gmt(gmdate('Y-m-d H:i:s', $date)); |
|
117 | + } |
|
118 | 118 | |
119 | - /** |
|
120 | - * @param string $key |
|
121 | - * @return string |
|
122 | - */ |
|
123 | - protected function getUser($key) |
|
124 | - { |
|
125 | - $value = $this->get($key); |
|
126 | - if (empty($value)) { |
|
127 | - $user = wp_get_current_user(); |
|
128 | - $userValues = [ |
|
129 | - 'email' => 'user_email', |
|
130 | - 'name' => 'display_name', |
|
131 | - ]; |
|
132 | - if ($user->exists() && array_key_exists($key, $userValues)) { |
|
133 | - return $user->{$userValues[$key]}; |
|
134 | - } |
|
135 | - } |
|
136 | - return $value; |
|
137 | - } |
|
119 | + /** |
|
120 | + * @param string $key |
|
121 | + * @return string |
|
122 | + */ |
|
123 | + protected function getUser($key) |
|
124 | + { |
|
125 | + $value = $this->get($key); |
|
126 | + if (empty($value)) { |
|
127 | + $user = wp_get_current_user(); |
|
128 | + $userValues = [ |
|
129 | + 'email' => 'user_email', |
|
130 | + 'name' => 'display_name', |
|
131 | + ]; |
|
132 | + if ($user->exists() && array_key_exists($key, $userValues)) { |
|
133 | + return $user->{$userValues[$key]}; |
|
134 | + } |
|
135 | + } |
|
136 | + return $value; |
|
137 | + } |
|
138 | 138 | |
139 | - /** |
|
140 | - * @param string $key |
|
141 | - * @return string |
|
142 | - */ |
|
143 | - protected function getNumeric($key) |
|
144 | - { |
|
145 | - $value = $this->get($key); |
|
146 | - return is_numeric($value) |
|
147 | - ? $value |
|
148 | - : ''; |
|
149 | - } |
|
139 | + /** |
|
140 | + * @param string $key |
|
141 | + * @return string |
|
142 | + */ |
|
143 | + protected function getNumeric($key) |
|
144 | + { |
|
145 | + $value = $this->get($key); |
|
146 | + return is_numeric($value) |
|
147 | + ? $value |
|
148 | + : ''; |
|
149 | + } |
|
150 | 150 | } |
@@ -27,37 +27,37 @@ discard block |
||
27 | 27 | public $title; |
28 | 28 | public $url; |
29 | 29 | |
30 | - public function __construct($input) |
|
30 | + public function __construct( $input ) |
|
31 | 31 | { |
32 | 32 | $this->request = $input; |
33 | 33 | $this->ajax_request = isset($input['_ajax_request']); |
34 | - $this->assigned_to = $this->getNumeric('assign_to'); |
|
35 | - $this->author = sanitize_text_field($this->getUser('name')); |
|
34 | + $this->assigned_to = $this->getNumeric( 'assign_to' ); |
|
35 | + $this->author = sanitize_text_field( $this->getUser( 'name' ) ); |
|
36 | 36 | $this->avatar = $this->getAvatar(); |
37 | 37 | $this->blacklisted = isset($input['blacklisted']); |
38 | 38 | $this->category = $this->getCategory(); |
39 | - $this->content = sanitize_textarea_field($this->get('content')); |
|
39 | + $this->content = sanitize_textarea_field( $this->get( 'content' ) ); |
|
40 | 40 | $this->custom = $this->getCustom(); |
41 | - $this->date = $this->getDate('date'); |
|
42 | - $this->email = sanitize_email($this->getUser('email')); |
|
43 | - $this->form_id = sanitize_key($this->get('form_id')); |
|
44 | - $this->ip_address = $this->get('ip_address'); |
|
45 | - $this->post_id = intval($this->get('_post_id')); |
|
46 | - $this->rating = intval($this->get('rating')); |
|
47 | - $this->referer = sanitize_text_field($this->get('_referer')); |
|
48 | - $this->response = sanitize_textarea_field($this->get('response')); |
|
41 | + $this->date = $this->getDate( 'date' ); |
|
42 | + $this->email = sanitize_email( $this->getUser( 'email' ) ); |
|
43 | + $this->form_id = sanitize_key( $this->get( 'form_id' ) ); |
|
44 | + $this->ip_address = $this->get( 'ip_address' ); |
|
45 | + $this->post_id = intval( $this->get( '_post_id' ) ); |
|
46 | + $this->rating = intval( $this->get( 'rating' ) ); |
|
47 | + $this->referer = sanitize_text_field( $this->get( '_referer' ) ); |
|
48 | + $this->response = sanitize_textarea_field( $this->get( 'response' ) ); |
|
49 | 49 | $this->terms = !empty($input['terms']); |
50 | - $this->title = sanitize_text_field($this->get('title')); |
|
51 | - $this->url = esc_url_raw(sanitize_text_field($this->get('url'))); |
|
50 | + $this->title = sanitize_text_field( $this->get( 'title' ) ); |
|
51 | + $this->url = esc_url_raw( sanitize_text_field( $this->get( 'url' ) ) ); |
|
52 | 52 | } |
53 | 53 | |
54 | 54 | /** |
55 | 55 | * @param string $key |
56 | 56 | * @return string |
57 | 57 | */ |
58 | - protected function get($key) |
|
58 | + protected function get( $key ) |
|
59 | 59 | { |
60 | - return (string) Arr::get($this->request, $key); |
|
60 | + return (string)Arr::get( $this->request, $key ); |
|
61 | 61 | } |
62 | 62 | |
63 | 63 | /** |
@@ -65,9 +65,9 @@ discard block |
||
65 | 65 | */ |
66 | 66 | protected function getAvatar() |
67 | 67 | { |
68 | - $avatar = $this->get('avatar'); |
|
69 | - return !filter_var($avatar, FILTER_VALIDATE_URL, FILTER_FLAG_PATH_REQUIRED) |
|
70 | - ? (string) get_avatar_url($this->get('email')) |
|
68 | + $avatar = $this->get( 'avatar' ); |
|
69 | + return !filter_var( $avatar, FILTER_VALIDATE_URL, FILTER_FLAG_PATH_REQUIRED ) |
|
70 | + ? (string)get_avatar_url( $this->get( 'email' ) ) |
|
71 | 71 | : $avatar; |
72 | 72 | } |
73 | 73 | |
@@ -76,8 +76,8 @@ discard block |
||
76 | 76 | */ |
77 | 77 | protected function getCategory() |
78 | 78 | { |
79 | - $categories = Arr::convertStringToArray($this->get('category')); |
|
80 | - return sanitize_key(Arr::get($categories, 0)); |
|
79 | + $categories = Arr::convertStringToArray( $this->get( 'category' ) ); |
|
80 | + return sanitize_key( Arr::get( $categories, 0 ) ); |
|
81 | 81 | } |
82 | 82 | |
83 | 83 | /** |
@@ -90,14 +90,14 @@ discard block |
||
90 | 90 | '_referer', 'assign_to', 'category', 'content', 'date', 'email', 'excluded', 'form_id', |
91 | 91 | 'gotcha', 'ip_address', 'name', 'rating', 'response', 'terms', 'title', 'url', |
92 | 92 | ]; |
93 | - $unset = apply_filters('site-reviews/create/unset-keys-from-custom', $unset); |
|
93 | + $unset = apply_filters( 'site-reviews/create/unset-keys-from-custom', $unset ); |
|
94 | 94 | $custom = $this->request; |
95 | - foreach ($unset as $key) { |
|
95 | + foreach( $unset as $key ) { |
|
96 | 96 | unset($custom[$key]); |
97 | 97 | } |
98 | - foreach ($custom as $key => $value) { |
|
99 | - if (is_string($value)) { |
|
100 | - $custom[$key] = sanitize_text_field($value); |
|
98 | + foreach( $custom as $key => $value ) { |
|
99 | + if( is_string( $value ) ) { |
|
100 | + $custom[$key] = sanitize_text_field( $value ); |
|
101 | 101 | } |
102 | 102 | } |
103 | 103 | return $custom; |
@@ -107,29 +107,29 @@ discard block |
||
107 | 107 | * @param string $key |
108 | 108 | * @return string |
109 | 109 | */ |
110 | - protected function getDate($key) |
|
110 | + protected function getDate( $key ) |
|
111 | 111 | { |
112 | - $date = strtotime($this->get($key)); |
|
113 | - if (false === $date) { |
|
112 | + $date = strtotime( $this->get( $key ) ); |
|
113 | + if( false === $date ) { |
|
114 | 114 | $date = time(); |
115 | 115 | } |
116 | - return get_date_from_gmt(gmdate('Y-m-d H:i:s', $date)); |
|
116 | + return get_date_from_gmt( gmdate( 'Y-m-d H:i:s', $date ) ); |
|
117 | 117 | } |
118 | 118 | |
119 | 119 | /** |
120 | 120 | * @param string $key |
121 | 121 | * @return string |
122 | 122 | */ |
123 | - protected function getUser($key) |
|
123 | + protected function getUser( $key ) |
|
124 | 124 | { |
125 | - $value = $this->get($key); |
|
126 | - if (empty($value)) { |
|
125 | + $value = $this->get( $key ); |
|
126 | + if( empty($value) ) { |
|
127 | 127 | $user = wp_get_current_user(); |
128 | 128 | $userValues = [ |
129 | 129 | 'email' => 'user_email', |
130 | 130 | 'name' => 'display_name', |
131 | 131 | ]; |
132 | - if ($user->exists() && array_key_exists($key, $userValues)) { |
|
132 | + if( $user->exists() && array_key_exists( $key, $userValues ) ) { |
|
133 | 133 | return $user->{$userValues[$key]}; |
134 | 134 | } |
135 | 135 | } |
@@ -140,10 +140,10 @@ discard block |
||
140 | 140 | * @param string $key |
141 | 141 | * @return string |
142 | 142 | */ |
143 | - protected function getNumeric($key) |
|
143 | + protected function getNumeric( $key ) |
|
144 | 144 | { |
145 | - $value = $this->get($key); |
|
146 | - return is_numeric($value) |
|
145 | + $value = $this->get( $key ); |
|
146 | + return is_numeric( $value ) |
|
147 | 147 | ? $value |
148 | 148 | : ''; |
149 | 149 | } |
@@ -7,39 +7,39 @@ |
||
7 | 7 | |
8 | 8 | abstract class Widget extends WP_Widget |
9 | 9 | { |
10 | - /** |
|
11 | - * @var array |
|
12 | - */ |
|
13 | - protected $widgetArgs; |
|
10 | + /** |
|
11 | + * @var array |
|
12 | + */ |
|
13 | + protected $widgetArgs; |
|
14 | 14 | |
15 | - /** |
|
16 | - * @param string $tag |
|
17 | - * @return void |
|
18 | - */ |
|
19 | - protected function renderField($tag, array $args = []) |
|
20 | - { |
|
21 | - $args = $this->normalizeFieldAttributes($tag, $args); |
|
22 | - $field = glsr(Builder::class)->$tag($args['name'], $args); |
|
23 | - echo glsr(Builder::class)->div($field, [ |
|
24 | - 'class' => 'glsr-field', |
|
25 | - ]); |
|
26 | - } |
|
15 | + /** |
|
16 | + * @param string $tag |
|
17 | + * @return void |
|
18 | + */ |
|
19 | + protected function renderField($tag, array $args = []) |
|
20 | + { |
|
21 | + $args = $this->normalizeFieldAttributes($tag, $args); |
|
22 | + $field = glsr(Builder::class)->$tag($args['name'], $args); |
|
23 | + echo glsr(Builder::class)->div($field, [ |
|
24 | + 'class' => 'glsr-field', |
|
25 | + ]); |
|
26 | + } |
|
27 | 27 | |
28 | - /** |
|
29 | - * @param string $tag |
|
30 | - * @return array |
|
31 | - */ |
|
32 | - protected function normalizeFieldAttributes($tag, array $args) |
|
33 | - { |
|
34 | - if (empty($args['value'])) { |
|
35 | - $args['value'] = $this->widgetArgs[$args['name']]; |
|
36 | - } |
|
37 | - if (empty($this->widgetArgs['options']) && in_array($tag, ['checkbox', 'radio'])) { |
|
38 | - $args['checked'] = in_array($args['value'], (array) $this->widgetArgs[$args['name']]); |
|
39 | - } |
|
40 | - $args['id'] = $this->get_field_id($args['name']); |
|
41 | - $args['name'] = $this->get_field_name($args['name']); |
|
42 | - $args['is_widget'] = true; |
|
43 | - return $args; |
|
44 | - } |
|
28 | + /** |
|
29 | + * @param string $tag |
|
30 | + * @return array |
|
31 | + */ |
|
32 | + protected function normalizeFieldAttributes($tag, array $args) |
|
33 | + { |
|
34 | + if (empty($args['value'])) { |
|
35 | + $args['value'] = $this->widgetArgs[$args['name']]; |
|
36 | + } |
|
37 | + if (empty($this->widgetArgs['options']) && in_array($tag, ['checkbox', 'radio'])) { |
|
38 | + $args['checked'] = in_array($args['value'], (array) $this->widgetArgs[$args['name']]); |
|
39 | + } |
|
40 | + $args['id'] = $this->get_field_id($args['name']); |
|
41 | + $args['name'] = $this->get_field_name($args['name']); |
|
42 | + $args['is_widget'] = true; |
|
43 | + return $args; |
|
44 | + } |
|
45 | 45 | } |
@@ -16,29 +16,29 @@ |
||
16 | 16 | * @param string $tag |
17 | 17 | * @return void |
18 | 18 | */ |
19 | - protected function renderField($tag, array $args = []) |
|
19 | + protected function renderField( $tag, array $args = [] ) |
|
20 | 20 | { |
21 | - $args = $this->normalizeFieldAttributes($tag, $args); |
|
22 | - $field = glsr(Builder::class)->$tag($args['name'], $args); |
|
23 | - echo glsr(Builder::class)->div($field, [ |
|
21 | + $args = $this->normalizeFieldAttributes( $tag, $args ); |
|
22 | + $field = glsr( Builder::class )->$tag( $args['name'], $args ); |
|
23 | + echo glsr( Builder::class )->div( $field, [ |
|
24 | 24 | 'class' => 'glsr-field', |
25 | - ]); |
|
25 | + ] ); |
|
26 | 26 | } |
27 | 27 | |
28 | 28 | /** |
29 | 29 | * @param string $tag |
30 | 30 | * @return array |
31 | 31 | */ |
32 | - protected function normalizeFieldAttributes($tag, array $args) |
|
32 | + protected function normalizeFieldAttributes( $tag, array $args ) |
|
33 | 33 | { |
34 | - if (empty($args['value'])) { |
|
34 | + if( empty($args['value']) ) { |
|
35 | 35 | $args['value'] = $this->widgetArgs[$args['name']]; |
36 | 36 | } |
37 | - if (empty($this->widgetArgs['options']) && in_array($tag, ['checkbox', 'radio'])) { |
|
38 | - $args['checked'] = in_array($args['value'], (array) $this->widgetArgs[$args['name']]); |
|
37 | + if( empty($this->widgetArgs['options']) && in_array( $tag, ['checkbox', 'radio'] ) ) { |
|
38 | + $args['checked'] = in_array( $args['value'], (array)$this->widgetArgs[$args['name']] ); |
|
39 | 39 | } |
40 | - $args['id'] = $this->get_field_id($args['name']); |
|
41 | - $args['name'] = $this->get_field_name($args['name']); |
|
40 | + $args['id'] = $this->get_field_id( $args['name'] ); |
|
41 | + $args['name'] = $this->get_field_name( $args['name'] ); |
|
42 | 42 | $args['is_widget'] = true; |
43 | 43 | return $args; |
44 | 44 | } |
@@ -8,103 +8,103 @@ |
||
8 | 8 | |
9 | 9 | class SiteReviewsWidget extends Widget |
10 | 10 | { |
11 | - public function __construct() |
|
12 | - { |
|
13 | - $idBase = Application::ID.'_site-reviews'; |
|
14 | - $name = __('Recent Reviews', 'site-reviews'); |
|
15 | - $widgetOptions = [ |
|
16 | - 'class' => 'glsr-widget glsr-widget-site-reviews', |
|
17 | - 'description' => __('Site Reviews: Display your recent reviews.', 'site-reviews'), |
|
18 | - ]; |
|
19 | - parent::__construct($idBase, $name, $widgetOptions); |
|
20 | - } |
|
11 | + public function __construct() |
|
12 | + { |
|
13 | + $idBase = Application::ID.'_site-reviews'; |
|
14 | + $name = __('Recent Reviews', 'site-reviews'); |
|
15 | + $widgetOptions = [ |
|
16 | + 'class' => 'glsr-widget glsr-widget-site-reviews', |
|
17 | + 'description' => __('Site Reviews: Display your recent reviews.', 'site-reviews'), |
|
18 | + ]; |
|
19 | + parent::__construct($idBase, $name, $widgetOptions); |
|
20 | + } |
|
21 | 21 | |
22 | - /** |
|
23 | - * @param array $instance |
|
24 | - * @return void |
|
25 | - */ |
|
26 | - public function form($instance) |
|
27 | - { |
|
28 | - $this->widgetArgs = glsr(SiteReviewsShortcode::class)->normalizeAtts($instance); |
|
29 | - $terms = glsr(Database::class)->getTerms(); |
|
30 | - $this->renderField('text', [ |
|
31 | - 'class' => 'widefat', |
|
32 | - 'label' => __('Title', 'site-reviews'), |
|
33 | - 'name' => 'title', |
|
34 | - ]); |
|
35 | - $this->renderField('number', [ |
|
36 | - 'class' => 'small-text', |
|
37 | - 'default' => 10, |
|
38 | - 'label' => __('How many reviews would you like to display?', 'site-reviews'), |
|
39 | - 'max' => 100, |
|
40 | - 'name' => 'display', |
|
41 | - ]); |
|
42 | - $this->renderField('select', [ |
|
43 | - 'label' => __('What is the minimum rating to display?', 'site-reviews'), |
|
44 | - 'name' => 'rating', |
|
45 | - 'options' => [ |
|
46 | - '5' => sprintf(_n('%s star', '%s stars', 5, 'site-reviews'), 5), |
|
47 | - '4' => sprintf(_n('%s star', '%s stars', 4, 'site-reviews'), 4), |
|
48 | - '3' => sprintf(_n('%s star', '%s stars', 3, 'site-reviews'), 3), |
|
49 | - '2' => sprintf(_n('%s star', '%s stars', 2, 'site-reviews'), 2), |
|
50 | - '1' => sprintf(_n('%s star', '%s stars', 1, 'site-reviews'), 1), |
|
51 | - ], |
|
52 | - ]); |
|
53 | - if (count(glsr()->reviewTypes) > 1) { |
|
54 | - $this->renderField('select', [ |
|
55 | - 'class' => 'widefat', |
|
56 | - 'label' => __('Which type of review would you like to display?', 'site-reviews'), |
|
57 | - 'name' => 'type', |
|
58 | - 'options' => ['' => __('All Reviews', 'site-reviews')] + glsr()->reviewTypes, |
|
59 | - ]); |
|
60 | - } |
|
61 | - if (!empty($terms)) { |
|
62 | - $this->renderField('select', [ |
|
63 | - 'class' => 'widefat', |
|
64 | - 'label' => __('Limit reviews to this category', 'site-reviews'), |
|
65 | - 'name' => 'category', |
|
66 | - 'options' => ['' => __('All Categories', 'site-reviews')] + $terms, |
|
67 | - ]); |
|
68 | - } |
|
69 | - $this->renderField('text', [ |
|
70 | - 'class' => 'widefat', |
|
71 | - 'default' => '', |
|
72 | - 'description' => sprintf(__("Separate multiple ID's with a comma. You may also enter %s to automatically represent the current page/post ID.", 'site-reviews'), '<code>post_id</code>'), |
|
73 | - 'label' => __('Limit reviews to those assigned to this page/post ID', 'site-reviews'), |
|
74 | - 'name' => 'assigned_to', |
|
75 | - ]); |
|
76 | - $this->renderField('text', [ |
|
77 | - 'class' => 'widefat', |
|
78 | - 'label' => __('Enter any custom CSS classes here', 'site-reviews'), |
|
79 | - 'name' => 'class', |
|
80 | - ]); |
|
81 | - $this->renderField('checkbox', [ |
|
82 | - 'name' => 'hide', |
|
83 | - 'options' => glsr(SiteReviewsShortcode::class)->getHideOptions(), |
|
84 | - ]); |
|
85 | - } |
|
22 | + /** |
|
23 | + * @param array $instance |
|
24 | + * @return void |
|
25 | + */ |
|
26 | + public function form($instance) |
|
27 | + { |
|
28 | + $this->widgetArgs = glsr(SiteReviewsShortcode::class)->normalizeAtts($instance); |
|
29 | + $terms = glsr(Database::class)->getTerms(); |
|
30 | + $this->renderField('text', [ |
|
31 | + 'class' => 'widefat', |
|
32 | + 'label' => __('Title', 'site-reviews'), |
|
33 | + 'name' => 'title', |
|
34 | + ]); |
|
35 | + $this->renderField('number', [ |
|
36 | + 'class' => 'small-text', |
|
37 | + 'default' => 10, |
|
38 | + 'label' => __('How many reviews would you like to display?', 'site-reviews'), |
|
39 | + 'max' => 100, |
|
40 | + 'name' => 'display', |
|
41 | + ]); |
|
42 | + $this->renderField('select', [ |
|
43 | + 'label' => __('What is the minimum rating to display?', 'site-reviews'), |
|
44 | + 'name' => 'rating', |
|
45 | + 'options' => [ |
|
46 | + '5' => sprintf(_n('%s star', '%s stars', 5, 'site-reviews'), 5), |
|
47 | + '4' => sprintf(_n('%s star', '%s stars', 4, 'site-reviews'), 4), |
|
48 | + '3' => sprintf(_n('%s star', '%s stars', 3, 'site-reviews'), 3), |
|
49 | + '2' => sprintf(_n('%s star', '%s stars', 2, 'site-reviews'), 2), |
|
50 | + '1' => sprintf(_n('%s star', '%s stars', 1, 'site-reviews'), 1), |
|
51 | + ], |
|
52 | + ]); |
|
53 | + if (count(glsr()->reviewTypes) > 1) { |
|
54 | + $this->renderField('select', [ |
|
55 | + 'class' => 'widefat', |
|
56 | + 'label' => __('Which type of review would you like to display?', 'site-reviews'), |
|
57 | + 'name' => 'type', |
|
58 | + 'options' => ['' => __('All Reviews', 'site-reviews')] + glsr()->reviewTypes, |
|
59 | + ]); |
|
60 | + } |
|
61 | + if (!empty($terms)) { |
|
62 | + $this->renderField('select', [ |
|
63 | + 'class' => 'widefat', |
|
64 | + 'label' => __('Limit reviews to this category', 'site-reviews'), |
|
65 | + 'name' => 'category', |
|
66 | + 'options' => ['' => __('All Categories', 'site-reviews')] + $terms, |
|
67 | + ]); |
|
68 | + } |
|
69 | + $this->renderField('text', [ |
|
70 | + 'class' => 'widefat', |
|
71 | + 'default' => '', |
|
72 | + 'description' => sprintf(__("Separate multiple ID's with a comma. You may also enter %s to automatically represent the current page/post ID.", 'site-reviews'), '<code>post_id</code>'), |
|
73 | + 'label' => __('Limit reviews to those assigned to this page/post ID', 'site-reviews'), |
|
74 | + 'name' => 'assigned_to', |
|
75 | + ]); |
|
76 | + $this->renderField('text', [ |
|
77 | + 'class' => 'widefat', |
|
78 | + 'label' => __('Enter any custom CSS classes here', 'site-reviews'), |
|
79 | + 'name' => 'class', |
|
80 | + ]); |
|
81 | + $this->renderField('checkbox', [ |
|
82 | + 'name' => 'hide', |
|
83 | + 'options' => glsr(SiteReviewsShortcode::class)->getHideOptions(), |
|
84 | + ]); |
|
85 | + } |
|
86 | 86 | |
87 | - /** |
|
88 | - * @param array $newInstance |
|
89 | - * @param array $oldInstance |
|
90 | - * @return array |
|
91 | - */ |
|
92 | - public function update($newInstance, $oldInstance) |
|
93 | - { |
|
94 | - if (!is_numeric($newInstance['display'])) { |
|
95 | - $newInstance['display'] = 10; |
|
96 | - } |
|
97 | - $newInstance['display'] = min(50, max(0, intval($newInstance['display']))); |
|
98 | - return parent::update($newInstance, $oldInstance); |
|
99 | - } |
|
87 | + /** |
|
88 | + * @param array $newInstance |
|
89 | + * @param array $oldInstance |
|
90 | + * @return array |
|
91 | + */ |
|
92 | + public function update($newInstance, $oldInstance) |
|
93 | + { |
|
94 | + if (!is_numeric($newInstance['display'])) { |
|
95 | + $newInstance['display'] = 10; |
|
96 | + } |
|
97 | + $newInstance['display'] = min(50, max(0, intval($newInstance['display']))); |
|
98 | + return parent::update($newInstance, $oldInstance); |
|
99 | + } |
|
100 | 100 | |
101 | - /** |
|
102 | - * @param array $args |
|
103 | - * @param array $instance |
|
104 | - * @return void |
|
105 | - */ |
|
106 | - public function widget($args, $instance) |
|
107 | - { |
|
108 | - echo glsr(SiteReviewsShortcode::class)->build($instance, $args, 'widget'); |
|
109 | - } |
|
101 | + /** |
|
102 | + * @param array $args |
|
103 | + * @param array $instance |
|
104 | + * @return void |
|
105 | + */ |
|
106 | + public function widget($args, $instance) |
|
107 | + { |
|
108 | + echo glsr(SiteReviewsShortcode::class)->build($instance, $args, 'widget'); |
|
109 | + } |
|
110 | 110 | } |
@@ -11,77 +11,77 @@ discard block |
||
11 | 11 | public function __construct() |
12 | 12 | { |
13 | 13 | $idBase = Application::ID.'_site-reviews'; |
14 | - $name = __('Recent Reviews', 'site-reviews'); |
|
14 | + $name = __( 'Recent Reviews', 'site-reviews' ); |
|
15 | 15 | $widgetOptions = [ |
16 | 16 | 'class' => 'glsr-widget glsr-widget-site-reviews', |
17 | - 'description' => __('Site Reviews: Display your recent reviews.', 'site-reviews'), |
|
17 | + 'description' => __( 'Site Reviews: Display your recent reviews.', 'site-reviews' ), |
|
18 | 18 | ]; |
19 | - parent::__construct($idBase, $name, $widgetOptions); |
|
19 | + parent::__construct( $idBase, $name, $widgetOptions ); |
|
20 | 20 | } |
21 | 21 | |
22 | 22 | /** |
23 | 23 | * @param array $instance |
24 | 24 | * @return void |
25 | 25 | */ |
26 | - public function form($instance) |
|
26 | + public function form( $instance ) |
|
27 | 27 | { |
28 | - $this->widgetArgs = glsr(SiteReviewsShortcode::class)->normalizeAtts($instance); |
|
29 | - $terms = glsr(Database::class)->getTerms(); |
|
30 | - $this->renderField('text', [ |
|
28 | + $this->widgetArgs = glsr( SiteReviewsShortcode::class )->normalizeAtts( $instance ); |
|
29 | + $terms = glsr( Database::class )->getTerms(); |
|
30 | + $this->renderField( 'text', [ |
|
31 | 31 | 'class' => 'widefat', |
32 | - 'label' => __('Title', 'site-reviews'), |
|
32 | + 'label' => __( 'Title', 'site-reviews' ), |
|
33 | 33 | 'name' => 'title', |
34 | - ]); |
|
35 | - $this->renderField('number', [ |
|
34 | + ] ); |
|
35 | + $this->renderField( 'number', [ |
|
36 | 36 | 'class' => 'small-text', |
37 | 37 | 'default' => 10, |
38 | - 'label' => __('How many reviews would you like to display?', 'site-reviews'), |
|
38 | + 'label' => __( 'How many reviews would you like to display?', 'site-reviews' ), |
|
39 | 39 | 'max' => 100, |
40 | 40 | 'name' => 'display', |
41 | - ]); |
|
42 | - $this->renderField('select', [ |
|
43 | - 'label' => __('What is the minimum rating to display?', 'site-reviews'), |
|
41 | + ] ); |
|
42 | + $this->renderField( 'select', [ |
|
43 | + 'label' => __( 'What is the minimum rating to display?', 'site-reviews' ), |
|
44 | 44 | 'name' => 'rating', |
45 | 45 | 'options' => [ |
46 | - '5' => sprintf(_n('%s star', '%s stars', 5, 'site-reviews'), 5), |
|
47 | - '4' => sprintf(_n('%s star', '%s stars', 4, 'site-reviews'), 4), |
|
48 | - '3' => sprintf(_n('%s star', '%s stars', 3, 'site-reviews'), 3), |
|
49 | - '2' => sprintf(_n('%s star', '%s stars', 2, 'site-reviews'), 2), |
|
50 | - '1' => sprintf(_n('%s star', '%s stars', 1, 'site-reviews'), 1), |
|
46 | + '5' => sprintf( _n( '%s star', '%s stars', 5, 'site-reviews' ), 5 ), |
|
47 | + '4' => sprintf( _n( '%s star', '%s stars', 4, 'site-reviews' ), 4 ), |
|
48 | + '3' => sprintf( _n( '%s star', '%s stars', 3, 'site-reviews' ), 3 ), |
|
49 | + '2' => sprintf( _n( '%s star', '%s stars', 2, 'site-reviews' ), 2 ), |
|
50 | + '1' => sprintf( _n( '%s star', '%s stars', 1, 'site-reviews' ), 1 ), |
|
51 | 51 | ], |
52 | - ]); |
|
53 | - if (count(glsr()->reviewTypes) > 1) { |
|
54 | - $this->renderField('select', [ |
|
52 | + ] ); |
|
53 | + if( count( glsr()->reviewTypes ) > 1 ) { |
|
54 | + $this->renderField( 'select', [ |
|
55 | 55 | 'class' => 'widefat', |
56 | - 'label' => __('Which type of review would you like to display?', 'site-reviews'), |
|
56 | + 'label' => __( 'Which type of review would you like to display?', 'site-reviews' ), |
|
57 | 57 | 'name' => 'type', |
58 | - 'options' => ['' => __('All Reviews', 'site-reviews')] + glsr()->reviewTypes, |
|
59 | - ]); |
|
58 | + 'options' => ['' => __( 'All Reviews', 'site-reviews' )] + glsr()->reviewTypes, |
|
59 | + ] ); |
|
60 | 60 | } |
61 | - if (!empty($terms)) { |
|
62 | - $this->renderField('select', [ |
|
61 | + if( !empty($terms) ) { |
|
62 | + $this->renderField( 'select', [ |
|
63 | 63 | 'class' => 'widefat', |
64 | - 'label' => __('Limit reviews to this category', 'site-reviews'), |
|
64 | + 'label' => __( 'Limit reviews to this category', 'site-reviews' ), |
|
65 | 65 | 'name' => 'category', |
66 | - 'options' => ['' => __('All Categories', 'site-reviews')] + $terms, |
|
67 | - ]); |
|
66 | + 'options' => ['' => __( 'All Categories', 'site-reviews' )] + $terms, |
|
67 | + ] ); |
|
68 | 68 | } |
69 | - $this->renderField('text', [ |
|
69 | + $this->renderField( 'text', [ |
|
70 | 70 | 'class' => 'widefat', |
71 | 71 | 'default' => '', |
72 | - 'description' => sprintf(__("Separate multiple ID's with a comma. You may also enter %s to automatically represent the current page/post ID.", 'site-reviews'), '<code>post_id</code>'), |
|
73 | - 'label' => __('Limit reviews to those assigned to this page/post ID', 'site-reviews'), |
|
72 | + 'description' => sprintf( __( "Separate multiple ID's with a comma. You may also enter %s to automatically represent the current page/post ID.", 'site-reviews' ), '<code>post_id</code>' ), |
|
73 | + 'label' => __( 'Limit reviews to those assigned to this page/post ID', 'site-reviews' ), |
|
74 | 74 | 'name' => 'assigned_to', |
75 | - ]); |
|
76 | - $this->renderField('text', [ |
|
75 | + ] ); |
|
76 | + $this->renderField( 'text', [ |
|
77 | 77 | 'class' => 'widefat', |
78 | - 'label' => __('Enter any custom CSS classes here', 'site-reviews'), |
|
78 | + 'label' => __( 'Enter any custom CSS classes here', 'site-reviews' ), |
|
79 | 79 | 'name' => 'class', |
80 | - ]); |
|
81 | - $this->renderField('checkbox', [ |
|
80 | + ] ); |
|
81 | + $this->renderField( 'checkbox', [ |
|
82 | 82 | 'name' => 'hide', |
83 | - 'options' => glsr(SiteReviewsShortcode::class)->getHideOptions(), |
|
84 | - ]); |
|
83 | + 'options' => glsr( SiteReviewsShortcode::class )->getHideOptions(), |
|
84 | + ] ); |
|
85 | 85 | } |
86 | 86 | |
87 | 87 | /** |
@@ -89,13 +89,13 @@ discard block |
||
89 | 89 | * @param array $oldInstance |
90 | 90 | * @return array |
91 | 91 | */ |
92 | - public function update($newInstance, $oldInstance) |
|
92 | + public function update( $newInstance, $oldInstance ) |
|
93 | 93 | { |
94 | - if (!is_numeric($newInstance['display'])) { |
|
94 | + if( !is_numeric( $newInstance['display'] ) ) { |
|
95 | 95 | $newInstance['display'] = 10; |
96 | 96 | } |
97 | - $newInstance['display'] = min(50, max(0, intval($newInstance['display']))); |
|
98 | - return parent::update($newInstance, $oldInstance); |
|
97 | + $newInstance['display'] = min( 50, max( 0, intval( $newInstance['display'] ) ) ); |
|
98 | + return parent::update( $newInstance, $oldInstance ); |
|
99 | 99 | } |
100 | 100 | |
101 | 101 | /** |
@@ -103,8 +103,8 @@ discard block |
||
103 | 103 | * @param array $instance |
104 | 104 | * @return void |
105 | 105 | */ |
106 | - public function widget($args, $instance) |
|
106 | + public function widget( $args, $instance ) |
|
107 | 107 | { |
108 | - echo glsr(SiteReviewsShortcode::class)->build($instance, $args, 'widget'); |
|
108 | + echo glsr( SiteReviewsShortcode::class )->build( $instance, $args, 'widget' ); |
|
109 | 109 | } |
110 | 110 | } |
@@ -8,66 +8,66 @@ |
||
8 | 8 | |
9 | 9 | class SiteReviewsFormWidget extends Widget |
10 | 10 | { |
11 | - public function __construct() |
|
12 | - { |
|
13 | - $idBase = Application::ID.'_site-reviews-form'; |
|
14 | - $name = __('Submit a Review', 'site-reviews'); |
|
15 | - $widgetOptions = [ |
|
16 | - 'classname' => 'glsr-widget glsr-widget-site-reviews-form', |
|
17 | - 'description' => __('Site Reviews: Display a form to submit reviews.', 'site-reviews'), |
|
18 | - ]; |
|
19 | - parent::__construct($idBase, $name, $widgetOptions); |
|
20 | - } |
|
11 | + public function __construct() |
|
12 | + { |
|
13 | + $idBase = Application::ID.'_site-reviews-form'; |
|
14 | + $name = __('Submit a Review', 'site-reviews'); |
|
15 | + $widgetOptions = [ |
|
16 | + 'classname' => 'glsr-widget glsr-widget-site-reviews-form', |
|
17 | + 'description' => __('Site Reviews: Display a form to submit reviews.', 'site-reviews'), |
|
18 | + ]; |
|
19 | + parent::__construct($idBase, $name, $widgetOptions); |
|
20 | + } |
|
21 | 21 | |
22 | - /** |
|
23 | - * @param array $instance |
|
24 | - * @return void |
|
25 | - */ |
|
26 | - public function form($instance) |
|
27 | - { |
|
28 | - $this->widgetArgs = glsr(SiteReviewsFormShortcode::class)->normalizeAtts($instance); |
|
29 | - $terms = glsr(Database::class)->getTerms(); |
|
30 | - $this->renderField('text', [ |
|
31 | - 'class' => 'widefat', |
|
32 | - 'label' => __('Title', 'site-reviews'), |
|
33 | - 'name' => 'title', |
|
34 | - ]); |
|
35 | - $this->renderField('textarea', [ |
|
36 | - 'class' => 'widefat', |
|
37 | - 'label' => __('Description', 'site-reviews'), |
|
38 | - 'name' => 'description', |
|
39 | - ]); |
|
40 | - $this->renderField('select', [ |
|
41 | - 'class' => 'widefat', |
|
42 | - 'label' => __('Automatically assign a category', 'site-reviews'), |
|
43 | - 'name' => 'category', |
|
44 | - 'options' => ['' => __('Do not assign a category', 'site-reviews')] + $terms, |
|
45 | - ]); |
|
46 | - $this->renderField('text', [ |
|
47 | - 'class' => 'widefat', |
|
48 | - 'default' => '', |
|
49 | - 'description' => sprintf(__('You may also enter %s to assign to the current post.', 'site-reviews'), '<code>post_id</code>'), |
|
50 | - 'label' => __('Assign reviews to a custom page/post ID', 'site-reviews'), |
|
51 | - 'name' => 'assign_to', |
|
52 | - ]); |
|
53 | - $this->renderField('text', [ |
|
54 | - 'class' => 'widefat', |
|
55 | - 'label' => __('Enter any custom CSS classes here', 'site-reviews'), |
|
56 | - 'name' => 'class', |
|
57 | - ]); |
|
58 | - $this->renderField('checkbox', [ |
|
59 | - 'name' => 'hide', |
|
60 | - 'options' => glsr(SiteReviewsFormShortcode::class)->getHideOptions(), |
|
61 | - ]); |
|
62 | - } |
|
22 | + /** |
|
23 | + * @param array $instance |
|
24 | + * @return void |
|
25 | + */ |
|
26 | + public function form($instance) |
|
27 | + { |
|
28 | + $this->widgetArgs = glsr(SiteReviewsFormShortcode::class)->normalizeAtts($instance); |
|
29 | + $terms = glsr(Database::class)->getTerms(); |
|
30 | + $this->renderField('text', [ |
|
31 | + 'class' => 'widefat', |
|
32 | + 'label' => __('Title', 'site-reviews'), |
|
33 | + 'name' => 'title', |
|
34 | + ]); |
|
35 | + $this->renderField('textarea', [ |
|
36 | + 'class' => 'widefat', |
|
37 | + 'label' => __('Description', 'site-reviews'), |
|
38 | + 'name' => 'description', |
|
39 | + ]); |
|
40 | + $this->renderField('select', [ |
|
41 | + 'class' => 'widefat', |
|
42 | + 'label' => __('Automatically assign a category', 'site-reviews'), |
|
43 | + 'name' => 'category', |
|
44 | + 'options' => ['' => __('Do not assign a category', 'site-reviews')] + $terms, |
|
45 | + ]); |
|
46 | + $this->renderField('text', [ |
|
47 | + 'class' => 'widefat', |
|
48 | + 'default' => '', |
|
49 | + 'description' => sprintf(__('You may also enter %s to assign to the current post.', 'site-reviews'), '<code>post_id</code>'), |
|
50 | + 'label' => __('Assign reviews to a custom page/post ID', 'site-reviews'), |
|
51 | + 'name' => 'assign_to', |
|
52 | + ]); |
|
53 | + $this->renderField('text', [ |
|
54 | + 'class' => 'widefat', |
|
55 | + 'label' => __('Enter any custom CSS classes here', 'site-reviews'), |
|
56 | + 'name' => 'class', |
|
57 | + ]); |
|
58 | + $this->renderField('checkbox', [ |
|
59 | + 'name' => 'hide', |
|
60 | + 'options' => glsr(SiteReviewsFormShortcode::class)->getHideOptions(), |
|
61 | + ]); |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * @param array $args |
|
66 | - * @param array $instance |
|
67 | - * @return void |
|
68 | - */ |
|
69 | - public function widget($args, $instance) |
|
70 | - { |
|
71 | - echo glsr(SiteReviewsFormShortcode::class)->build($instance, $args, 'widget'); |
|
72 | - } |
|
64 | + /** |
|
65 | + * @param array $args |
|
66 | + * @param array $instance |
|
67 | + * @return void |
|
68 | + */ |
|
69 | + public function widget($args, $instance) |
|
70 | + { |
|
71 | + echo glsr(SiteReviewsFormShortcode::class)->build($instance, $args, 'widget'); |
|
72 | + } |
|
73 | 73 | } |
@@ -11,54 +11,54 @@ discard block |
||
11 | 11 | public function __construct() |
12 | 12 | { |
13 | 13 | $idBase = Application::ID.'_site-reviews-form'; |
14 | - $name = __('Submit a Review', 'site-reviews'); |
|
14 | + $name = __( 'Submit a Review', 'site-reviews' ); |
|
15 | 15 | $widgetOptions = [ |
16 | 16 | 'classname' => 'glsr-widget glsr-widget-site-reviews-form', |
17 | - 'description' => __('Site Reviews: Display a form to submit reviews.', 'site-reviews'), |
|
17 | + 'description' => __( 'Site Reviews: Display a form to submit reviews.', 'site-reviews' ), |
|
18 | 18 | ]; |
19 | - parent::__construct($idBase, $name, $widgetOptions); |
|
19 | + parent::__construct( $idBase, $name, $widgetOptions ); |
|
20 | 20 | } |
21 | 21 | |
22 | 22 | /** |
23 | 23 | * @param array $instance |
24 | 24 | * @return void |
25 | 25 | */ |
26 | - public function form($instance) |
|
26 | + public function form( $instance ) |
|
27 | 27 | { |
28 | - $this->widgetArgs = glsr(SiteReviewsFormShortcode::class)->normalizeAtts($instance); |
|
29 | - $terms = glsr(Database::class)->getTerms(); |
|
30 | - $this->renderField('text', [ |
|
28 | + $this->widgetArgs = glsr( SiteReviewsFormShortcode::class )->normalizeAtts( $instance ); |
|
29 | + $terms = glsr( Database::class )->getTerms(); |
|
30 | + $this->renderField( 'text', [ |
|
31 | 31 | 'class' => 'widefat', |
32 | - 'label' => __('Title', 'site-reviews'), |
|
32 | + 'label' => __( 'Title', 'site-reviews' ), |
|
33 | 33 | 'name' => 'title', |
34 | - ]); |
|
35 | - $this->renderField('textarea', [ |
|
34 | + ] ); |
|
35 | + $this->renderField( 'textarea', [ |
|
36 | 36 | 'class' => 'widefat', |
37 | - 'label' => __('Description', 'site-reviews'), |
|
37 | + 'label' => __( 'Description', 'site-reviews' ), |
|
38 | 38 | 'name' => 'description', |
39 | - ]); |
|
40 | - $this->renderField('select', [ |
|
39 | + ] ); |
|
40 | + $this->renderField( 'select', [ |
|
41 | 41 | 'class' => 'widefat', |
42 | - 'label' => __('Automatically assign a category', 'site-reviews'), |
|
42 | + 'label' => __( 'Automatically assign a category', 'site-reviews' ), |
|
43 | 43 | 'name' => 'category', |
44 | - 'options' => ['' => __('Do not assign a category', 'site-reviews')] + $terms, |
|
45 | - ]); |
|
46 | - $this->renderField('text', [ |
|
44 | + 'options' => ['' => __( 'Do not assign a category', 'site-reviews' )] + $terms, |
|
45 | + ] ); |
|
46 | + $this->renderField( 'text', [ |
|
47 | 47 | 'class' => 'widefat', |
48 | 48 | 'default' => '', |
49 | - 'description' => sprintf(__('You may also enter %s to assign to the current post.', 'site-reviews'), '<code>post_id</code>'), |
|
50 | - 'label' => __('Assign reviews to a custom page/post ID', 'site-reviews'), |
|
49 | + 'description' => sprintf( __( 'You may also enter %s to assign to the current post.', 'site-reviews' ), '<code>post_id</code>' ), |
|
50 | + 'label' => __( 'Assign reviews to a custom page/post ID', 'site-reviews' ), |
|
51 | 51 | 'name' => 'assign_to', |
52 | - ]); |
|
53 | - $this->renderField('text', [ |
|
52 | + ] ); |
|
53 | + $this->renderField( 'text', [ |
|
54 | 54 | 'class' => 'widefat', |
55 | - 'label' => __('Enter any custom CSS classes here', 'site-reviews'), |
|
55 | + 'label' => __( 'Enter any custom CSS classes here', 'site-reviews' ), |
|
56 | 56 | 'name' => 'class', |
57 | - ]); |
|
58 | - $this->renderField('checkbox', [ |
|
57 | + ] ); |
|
58 | + $this->renderField( 'checkbox', [ |
|
59 | 59 | 'name' => 'hide', |
60 | - 'options' => glsr(SiteReviewsFormShortcode::class)->getHideOptions(), |
|
61 | - ]); |
|
60 | + 'options' => glsr( SiteReviewsFormShortcode::class )->getHideOptions(), |
|
61 | + ] ); |
|
62 | 62 | } |
63 | 63 | |
64 | 64 | /** |
@@ -66,8 +66,8 @@ discard block |
||
66 | 66 | * @param array $instance |
67 | 67 | * @return void |
68 | 68 | */ |
69 | - public function widget($args, $instance) |
|
69 | + public function widget( $args, $instance ) |
|
70 | 70 | { |
71 | - echo glsr(SiteReviewsFormShortcode::class)->build($instance, $args, 'widget'); |
|
71 | + echo glsr( SiteReviewsFormShortcode::class )->build( $instance, $args, 'widget' ); |
|
72 | 72 | } |
73 | 73 | } |
@@ -8,71 +8,71 @@ |
||
8 | 8 | |
9 | 9 | class SiteReviewsSummaryWidget extends Widget |
10 | 10 | { |
11 | - public function __construct() |
|
12 | - { |
|
13 | - $idBase = Application::ID.'_site-reviews-summary'; |
|
14 | - $name = __('Summary of Reviews', 'site-reviews'); |
|
15 | - $widgetOptions = [ |
|
16 | - 'classname' => 'glsr-widget glsr-widget-site-reviews-summary', |
|
17 | - 'description' => __('Site Reviews: Display a summary of your reviews.', 'site-reviews'), |
|
18 | - ]; |
|
19 | - parent::__construct($idBase, $name, $widgetOptions); |
|
20 | - } |
|
11 | + public function __construct() |
|
12 | + { |
|
13 | + $idBase = Application::ID.'_site-reviews-summary'; |
|
14 | + $name = __('Summary of Reviews', 'site-reviews'); |
|
15 | + $widgetOptions = [ |
|
16 | + 'classname' => 'glsr-widget glsr-widget-site-reviews-summary', |
|
17 | + 'description' => __('Site Reviews: Display a summary of your reviews.', 'site-reviews'), |
|
18 | + ]; |
|
19 | + parent::__construct($idBase, $name, $widgetOptions); |
|
20 | + } |
|
21 | 21 | |
22 | - /** |
|
23 | - * @param array $instance |
|
24 | - * @return void |
|
25 | - */ |
|
26 | - public function form($instance) |
|
27 | - { |
|
28 | - $this->widgetArgs = glsr(SiteReviewsSummaryShortcode::class)->normalizeAtts($instance); |
|
29 | - $terms = glsr(Database::class)->getTerms(); |
|
30 | - $this->renderField('text', [ |
|
31 | - 'class' => 'widefat', |
|
32 | - 'label' => __('Title', 'site-reviews'), |
|
33 | - 'name' => 'title', |
|
34 | - ]); |
|
35 | - if (count(glsr()->reviewTypes) > 1) { |
|
36 | - $this->renderField('select', [ |
|
37 | - 'class' => 'widefat', |
|
38 | - 'label' => __('Which type of review would you like to use?', 'site-reviews'), |
|
39 | - 'name' => 'type', |
|
40 | - 'options' => ['' => __('All review types', 'site-reviews')] + glsr()->reviewTypes, |
|
41 | - ]); |
|
42 | - } |
|
43 | - if (!empty($terms)) { |
|
44 | - $this->renderField('select', [ |
|
45 | - 'class' => 'widefat', |
|
46 | - 'label' => __('Limit summary to this category', 'site-reviews'), |
|
47 | - 'name' => 'category', |
|
48 | - 'options' => ['' => __('All Categories', 'site-reviews')] + $terms, |
|
49 | - ]); |
|
50 | - } |
|
51 | - $this->renderField('text', [ |
|
52 | - 'class' => 'widefat', |
|
53 | - 'default' => '', |
|
54 | - 'description' => sprintf(__("Separate multiple ID's with a comma. You may also enter %s to automatically represent the current page/post ID.", 'site-reviews'), '<code>post_id</code>'), |
|
55 | - 'label' => __('Limit summary to reviews assigned to a page/post ID', 'site-reviews'), |
|
56 | - 'name' => 'assigned_to', |
|
57 | - ]); |
|
58 | - $this->renderField('text', [ |
|
59 | - 'class' => 'widefat', |
|
60 | - 'label' => __('Enter any custom CSS classes here', 'site-reviews'), |
|
61 | - 'name' => 'class', |
|
62 | - ]); |
|
63 | - $this->renderField('checkbox', [ |
|
64 | - 'name' => 'hide', |
|
65 | - 'options' => glsr(SiteReviewsSummaryShortcode::class)->getHideOptions(), |
|
66 | - ]); |
|
67 | - } |
|
22 | + /** |
|
23 | + * @param array $instance |
|
24 | + * @return void |
|
25 | + */ |
|
26 | + public function form($instance) |
|
27 | + { |
|
28 | + $this->widgetArgs = glsr(SiteReviewsSummaryShortcode::class)->normalizeAtts($instance); |
|
29 | + $terms = glsr(Database::class)->getTerms(); |
|
30 | + $this->renderField('text', [ |
|
31 | + 'class' => 'widefat', |
|
32 | + 'label' => __('Title', 'site-reviews'), |
|
33 | + 'name' => 'title', |
|
34 | + ]); |
|
35 | + if (count(glsr()->reviewTypes) > 1) { |
|
36 | + $this->renderField('select', [ |
|
37 | + 'class' => 'widefat', |
|
38 | + 'label' => __('Which type of review would you like to use?', 'site-reviews'), |
|
39 | + 'name' => 'type', |
|
40 | + 'options' => ['' => __('All review types', 'site-reviews')] + glsr()->reviewTypes, |
|
41 | + ]); |
|
42 | + } |
|
43 | + if (!empty($terms)) { |
|
44 | + $this->renderField('select', [ |
|
45 | + 'class' => 'widefat', |
|
46 | + 'label' => __('Limit summary to this category', 'site-reviews'), |
|
47 | + 'name' => 'category', |
|
48 | + 'options' => ['' => __('All Categories', 'site-reviews')] + $terms, |
|
49 | + ]); |
|
50 | + } |
|
51 | + $this->renderField('text', [ |
|
52 | + 'class' => 'widefat', |
|
53 | + 'default' => '', |
|
54 | + 'description' => sprintf(__("Separate multiple ID's with a comma. You may also enter %s to automatically represent the current page/post ID.", 'site-reviews'), '<code>post_id</code>'), |
|
55 | + 'label' => __('Limit summary to reviews assigned to a page/post ID', 'site-reviews'), |
|
56 | + 'name' => 'assigned_to', |
|
57 | + ]); |
|
58 | + $this->renderField('text', [ |
|
59 | + 'class' => 'widefat', |
|
60 | + 'label' => __('Enter any custom CSS classes here', 'site-reviews'), |
|
61 | + 'name' => 'class', |
|
62 | + ]); |
|
63 | + $this->renderField('checkbox', [ |
|
64 | + 'name' => 'hide', |
|
65 | + 'options' => glsr(SiteReviewsSummaryShortcode::class)->getHideOptions(), |
|
66 | + ]); |
|
67 | + } |
|
68 | 68 | |
69 | - /** |
|
70 | - * @param array $args |
|
71 | - * @param array $instance |
|
72 | - * @return void |
|
73 | - */ |
|
74 | - public function widget($args, $instance) |
|
75 | - { |
|
76 | - echo glsr(SiteReviewsSummaryShortcode::class)->build($instance, $args, 'widget'); |
|
77 | - } |
|
69 | + /** |
|
70 | + * @param array $args |
|
71 | + * @param array $instance |
|
72 | + * @return void |
|
73 | + */ |
|
74 | + public function widget($args, $instance) |
|
75 | + { |
|
76 | + echo glsr(SiteReviewsSummaryShortcode::class)->build($instance, $args, 'widget'); |
|
77 | + } |
|
78 | 78 | } |
@@ -11,59 +11,59 @@ discard block |
||
11 | 11 | public function __construct() |
12 | 12 | { |
13 | 13 | $idBase = Application::ID.'_site-reviews-summary'; |
14 | - $name = __('Summary of Reviews', 'site-reviews'); |
|
14 | + $name = __( 'Summary of Reviews', 'site-reviews' ); |
|
15 | 15 | $widgetOptions = [ |
16 | 16 | 'classname' => 'glsr-widget glsr-widget-site-reviews-summary', |
17 | - 'description' => __('Site Reviews: Display a summary of your reviews.', 'site-reviews'), |
|
17 | + 'description' => __( 'Site Reviews: Display a summary of your reviews.', 'site-reviews' ), |
|
18 | 18 | ]; |
19 | - parent::__construct($idBase, $name, $widgetOptions); |
|
19 | + parent::__construct( $idBase, $name, $widgetOptions ); |
|
20 | 20 | } |
21 | 21 | |
22 | 22 | /** |
23 | 23 | * @param array $instance |
24 | 24 | * @return void |
25 | 25 | */ |
26 | - public function form($instance) |
|
26 | + public function form( $instance ) |
|
27 | 27 | { |
28 | - $this->widgetArgs = glsr(SiteReviewsSummaryShortcode::class)->normalizeAtts($instance); |
|
29 | - $terms = glsr(Database::class)->getTerms(); |
|
30 | - $this->renderField('text', [ |
|
28 | + $this->widgetArgs = glsr( SiteReviewsSummaryShortcode::class )->normalizeAtts( $instance ); |
|
29 | + $terms = glsr( Database::class )->getTerms(); |
|
30 | + $this->renderField( 'text', [ |
|
31 | 31 | 'class' => 'widefat', |
32 | - 'label' => __('Title', 'site-reviews'), |
|
32 | + 'label' => __( 'Title', 'site-reviews' ), |
|
33 | 33 | 'name' => 'title', |
34 | - ]); |
|
35 | - if (count(glsr()->reviewTypes) > 1) { |
|
36 | - $this->renderField('select', [ |
|
34 | + ] ); |
|
35 | + if( count( glsr()->reviewTypes ) > 1 ) { |
|
36 | + $this->renderField( 'select', [ |
|
37 | 37 | 'class' => 'widefat', |
38 | - 'label' => __('Which type of review would you like to use?', 'site-reviews'), |
|
38 | + 'label' => __( 'Which type of review would you like to use?', 'site-reviews' ), |
|
39 | 39 | 'name' => 'type', |
40 | - 'options' => ['' => __('All review types', 'site-reviews')] + glsr()->reviewTypes, |
|
41 | - ]); |
|
40 | + 'options' => ['' => __( 'All review types', 'site-reviews' )] + glsr()->reviewTypes, |
|
41 | + ] ); |
|
42 | 42 | } |
43 | - if (!empty($terms)) { |
|
44 | - $this->renderField('select', [ |
|
43 | + if( !empty($terms) ) { |
|
44 | + $this->renderField( 'select', [ |
|
45 | 45 | 'class' => 'widefat', |
46 | - 'label' => __('Limit summary to this category', 'site-reviews'), |
|
46 | + 'label' => __( 'Limit summary to this category', 'site-reviews' ), |
|
47 | 47 | 'name' => 'category', |
48 | - 'options' => ['' => __('All Categories', 'site-reviews')] + $terms, |
|
49 | - ]); |
|
48 | + 'options' => ['' => __( 'All Categories', 'site-reviews' )] + $terms, |
|
49 | + ] ); |
|
50 | 50 | } |
51 | - $this->renderField('text', [ |
|
51 | + $this->renderField( 'text', [ |
|
52 | 52 | 'class' => 'widefat', |
53 | 53 | 'default' => '', |
54 | - 'description' => sprintf(__("Separate multiple ID's with a comma. You may also enter %s to automatically represent the current page/post ID.", 'site-reviews'), '<code>post_id</code>'), |
|
55 | - 'label' => __('Limit summary to reviews assigned to a page/post ID', 'site-reviews'), |
|
54 | + 'description' => sprintf( __( "Separate multiple ID's with a comma. You may also enter %s to automatically represent the current page/post ID.", 'site-reviews' ), '<code>post_id</code>' ), |
|
55 | + 'label' => __( 'Limit summary to reviews assigned to a page/post ID', 'site-reviews' ), |
|
56 | 56 | 'name' => 'assigned_to', |
57 | - ]); |
|
58 | - $this->renderField('text', [ |
|
57 | + ] ); |
|
58 | + $this->renderField( 'text', [ |
|
59 | 59 | 'class' => 'widefat', |
60 | - 'label' => __('Enter any custom CSS classes here', 'site-reviews'), |
|
60 | + 'label' => __( 'Enter any custom CSS classes here', 'site-reviews' ), |
|
61 | 61 | 'name' => 'class', |
62 | - ]); |
|
63 | - $this->renderField('checkbox', [ |
|
62 | + ] ); |
|
63 | + $this->renderField( 'checkbox', [ |
|
64 | 64 | 'name' => 'hide', |
65 | - 'options' => glsr(SiteReviewsSummaryShortcode::class)->getHideOptions(), |
|
66 | - ]); |
|
65 | + 'options' => glsr( SiteReviewsSummaryShortcode::class )->getHideOptions(), |
|
66 | + ] ); |
|
67 | 67 | } |
68 | 68 | |
69 | 69 | /** |
@@ -71,8 +71,8 @@ discard block |
||
71 | 71 | * @param array $instance |
72 | 72 | * @return void |
73 | 73 | */ |
74 | - public function widget($args, $instance) |
|
74 | + public function widget( $args, $instance ) |
|
75 | 75 | { |
76 | - echo glsr(SiteReviewsSummaryShortcode::class)->build($instance, $args, 'widget'); |
|
76 | + echo glsr( SiteReviewsSummaryShortcode::class )->build( $instance, $args, 'widget' ); |
|
77 | 77 | } |
78 | 78 | } |
@@ -8,19 +8,19 @@ |
||
8 | 8 | |
9 | 9 | class RegisterWidgets |
10 | 10 | { |
11 | - /** |
|
12 | - * @return void |
|
13 | - */ |
|
14 | - public function handle(Command $command) |
|
15 | - { |
|
16 | - global $wp_widget_factory; |
|
17 | - foreach ($command->widgets as $widget) { |
|
18 | - $widgetClass = Helper::buildClassName($widget.'-widget', 'Widgets'); |
|
19 | - if (!class_exists($widgetClass)) { |
|
20 | - glsr_log()->error(sprintf('Class missing (%s)', $widgetClass)); |
|
21 | - continue; |
|
22 | - } |
|
23 | - $wp_widget_factory->widgets[$widgetClass] = new $widgetClass(); |
|
24 | - } |
|
25 | - } |
|
11 | + /** |
|
12 | + * @return void |
|
13 | + */ |
|
14 | + public function handle(Command $command) |
|
15 | + { |
|
16 | + global $wp_widget_factory; |
|
17 | + foreach ($command->widgets as $widget) { |
|
18 | + $widgetClass = Helper::buildClassName($widget.'-widget', 'Widgets'); |
|
19 | + if (!class_exists($widgetClass)) { |
|
20 | + glsr_log()->error(sprintf('Class missing (%s)', $widgetClass)); |
|
21 | + continue; |
|
22 | + } |
|
23 | + $wp_widget_factory->widgets[$widgetClass] = new $widgetClass(); |
|
24 | + } |
|
25 | + } |
|
26 | 26 | } |
@@ -11,13 +11,13 @@ |
||
11 | 11 | /** |
12 | 12 | * @return void |
13 | 13 | */ |
14 | - public function handle(Command $command) |
|
14 | + public function handle( Command $command ) |
|
15 | 15 | { |
16 | 16 | global $wp_widget_factory; |
17 | - foreach ($command->widgets as $widget) { |
|
18 | - $widgetClass = Helper::buildClassName($widget.'-widget', 'Widgets'); |
|
19 | - if (!class_exists($widgetClass)) { |
|
20 | - glsr_log()->error(sprintf('Class missing (%s)', $widgetClass)); |
|
17 | + foreach( $command->widgets as $widget ) { |
|
18 | + $widgetClass = Helper::buildClassName( $widget.'-widget', 'Widgets' ); |
|
19 | + if( !class_exists( $widgetClass ) ) { |
|
20 | + glsr_log()->error( sprintf( 'Class missing (%s)', $widgetClass ) ); |
|
21 | 21 | continue; |
22 | 22 | } |
23 | 23 | $wp_widget_factory->widgets[$widgetClass] = new $widgetClass(); |