@@ -13,247 +13,247 @@ |
||
13 | 13 | |
14 | 14 | class CountsManager |
15 | 15 | { |
16 | - const LIMIT = 500; |
|
17 | - const META_AVERAGE = '_glsr_average'; |
|
18 | - const META_COUNT = '_glsr_count'; |
|
19 | - const META_RANKING = '_glsr_ranking'; |
|
16 | + const LIMIT = 500; |
|
17 | + const META_AVERAGE = '_glsr_average'; |
|
18 | + const META_COUNT = '_glsr_count'; |
|
19 | + const META_RANKING = '_glsr_ranking'; |
|
20 | 20 | |
21 | - /** |
|
22 | - * @return array |
|
23 | - */ |
|
24 | - public function buildCounts(array $args = []) |
|
25 | - { |
|
26 | - $counts = [ |
|
27 | - 'local' => $this->generateEmptyCountsArray(), |
|
28 | - ]; |
|
29 | - $query = $this->queryReviews($args); |
|
30 | - while ($query) { |
|
31 | - $counts = $this->populateCountsFromQuery($query, $counts); |
|
32 | - $query = $query->has_more |
|
33 | - ? $this->queryReviews($args, end($query->reviews)->ID) |
|
34 | - : false; |
|
35 | - } |
|
36 | - return $counts; |
|
37 | - } |
|
21 | + /** |
|
22 | + * @return array |
|
23 | + */ |
|
24 | + public function buildCounts(array $args = []) |
|
25 | + { |
|
26 | + $counts = [ |
|
27 | + 'local' => $this->generateEmptyCountsArray(), |
|
28 | + ]; |
|
29 | + $query = $this->queryReviews($args); |
|
30 | + while ($query) { |
|
31 | + $counts = $this->populateCountsFromQuery($query, $counts); |
|
32 | + $query = $query->has_more |
|
33 | + ? $this->queryReviews($args, end($query->reviews)->ID) |
|
34 | + : false; |
|
35 | + } |
|
36 | + return $counts; |
|
37 | + } |
|
38 | 38 | |
39 | - /** |
|
40 | - * @return void |
|
41 | - */ |
|
42 | - public function decreaseAll(Review $review) |
|
43 | - { |
|
44 | - glsr(GlobalCountsManager::class)->decrease($review); |
|
45 | - glsr(PostCountsManager::class)->decrease($review); |
|
46 | - glsr(TermCountsManager::class)->decrease($review); |
|
47 | - } |
|
39 | + /** |
|
40 | + * @return void |
|
41 | + */ |
|
42 | + public function decreaseAll(Review $review) |
|
43 | + { |
|
44 | + glsr(GlobalCountsManager::class)->decrease($review); |
|
45 | + glsr(PostCountsManager::class)->decrease($review); |
|
46 | + glsr(TermCountsManager::class)->decrease($review); |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * @param string $type |
|
51 | - * @param int $rating |
|
52 | - * @return array |
|
53 | - */ |
|
54 | - public function decreaseRating(array $reviewCounts, $type, $rating) |
|
55 | - { |
|
56 | - if (isset($reviewCounts[$type][$rating])) { |
|
57 | - $reviewCounts[$type][$rating] = max(0, $reviewCounts[$type][$rating] - 1); |
|
58 | - } |
|
59 | - return $reviewCounts; |
|
60 | - } |
|
49 | + /** |
|
50 | + * @param string $type |
|
51 | + * @param int $rating |
|
52 | + * @return array |
|
53 | + */ |
|
54 | + public function decreaseRating(array $reviewCounts, $type, $rating) |
|
55 | + { |
|
56 | + if (isset($reviewCounts[$type][$rating])) { |
|
57 | + $reviewCounts[$type][$rating] = max(0, $reviewCounts[$type][$rating] - 1); |
|
58 | + } |
|
59 | + return $reviewCounts; |
|
60 | + } |
|
61 | 61 | |
62 | - /** |
|
63 | - * @return array |
|
64 | - */ |
|
65 | - public function flatten(array $reviewCounts, array $args = []) |
|
66 | - { |
|
67 | - $counts = []; |
|
68 | - array_walk_recursive($reviewCounts, function ($num, $index) use (&$counts) { |
|
69 | - $counts[$index] = $num + intval(Arr::get($counts, $index, 0)); |
|
70 | - }); |
|
71 | - $min = Arr::get($args, 'min', glsr()->constant('MIN_RATING', Rating::class)); |
|
72 | - $max = Arr::get($args, 'max', glsr()->constant('MAX_RATING', Rating::class)); |
|
73 | - foreach ($counts as $index => &$num) { |
|
74 | - if (!Helper::inRange($index, $min, $max)) { |
|
75 | - $num = 0; |
|
76 | - } |
|
77 | - } |
|
78 | - return $counts; |
|
79 | - } |
|
62 | + /** |
|
63 | + * @return array |
|
64 | + */ |
|
65 | + public function flatten(array $reviewCounts, array $args = []) |
|
66 | + { |
|
67 | + $counts = []; |
|
68 | + array_walk_recursive($reviewCounts, function ($num, $index) use (&$counts) { |
|
69 | + $counts[$index] = $num + intval(Arr::get($counts, $index, 0)); |
|
70 | + }); |
|
71 | + $min = Arr::get($args, 'min', glsr()->constant('MIN_RATING', Rating::class)); |
|
72 | + $max = Arr::get($args, 'max', glsr()->constant('MAX_RATING', Rating::class)); |
|
73 | + foreach ($counts as $index => &$num) { |
|
74 | + if (!Helper::inRange($index, $min, $max)) { |
|
75 | + $num = 0; |
|
76 | + } |
|
77 | + } |
|
78 | + return $counts; |
|
79 | + } |
|
80 | 80 | |
81 | - /** |
|
82 | - * @return array |
|
83 | - */ |
|
84 | - public function getCounts(array $args = []) |
|
85 | - { |
|
86 | - $args = $this->normalizeArgs($args); |
|
87 | - $counts = $this->hasMixedAssignment($args) |
|
88 | - ? $this->buildCounts($args) // force query the database |
|
89 | - : $this->get($args); |
|
90 | - return $this->normalize($counts); |
|
91 | - } |
|
81 | + /** |
|
82 | + * @return array |
|
83 | + */ |
|
84 | + public function getCounts(array $args = []) |
|
85 | + { |
|
86 | + $args = $this->normalizeArgs($args); |
|
87 | + $counts = $this->hasMixedAssignment($args) |
|
88 | + ? $this->buildCounts($args) // force query the database |
|
89 | + : $this->get($args); |
|
90 | + return $this->normalize($counts); |
|
91 | + } |
|
92 | 92 | |
93 | - /** |
|
94 | - * @return void |
|
95 | - */ |
|
96 | - public function increaseAll(Review $review) |
|
97 | - { |
|
98 | - glsr(GlobalCountsManager::class)->increase($review); |
|
99 | - glsr(PostCountsManager::class)->increase($review); |
|
100 | - glsr(TermCountsManager::class)->increase($review); |
|
101 | - } |
|
93 | + /** |
|
94 | + * @return void |
|
95 | + */ |
|
96 | + public function increaseAll(Review $review) |
|
97 | + { |
|
98 | + glsr(GlobalCountsManager::class)->increase($review); |
|
99 | + glsr(PostCountsManager::class)->increase($review); |
|
100 | + glsr(TermCountsManager::class)->increase($review); |
|
101 | + } |
|
102 | 102 | |
103 | - /** |
|
104 | - * @param string $type |
|
105 | - * @param int $rating |
|
106 | - * @return array |
|
107 | - */ |
|
108 | - public function increaseRating(array $reviewCounts, $type, $rating) |
|
109 | - { |
|
110 | - if (!array_key_exists($type, glsr()->reviewTypes)) { |
|
111 | - return $reviewCounts; |
|
112 | - } |
|
113 | - if (!array_key_exists($type, $reviewCounts)) { |
|
114 | - $reviewCounts[$type] = []; |
|
115 | - } |
|
116 | - $reviewCounts = $this->normalize($reviewCounts); |
|
117 | - $reviewCounts[$type][$rating] = intval($reviewCounts[$type][$rating]) + 1; |
|
118 | - return $reviewCounts; |
|
119 | - } |
|
103 | + /** |
|
104 | + * @param string $type |
|
105 | + * @param int $rating |
|
106 | + * @return array |
|
107 | + */ |
|
108 | + public function increaseRating(array $reviewCounts, $type, $rating) |
|
109 | + { |
|
110 | + if (!array_key_exists($type, glsr()->reviewTypes)) { |
|
111 | + return $reviewCounts; |
|
112 | + } |
|
113 | + if (!array_key_exists($type, $reviewCounts)) { |
|
114 | + $reviewCounts[$type] = []; |
|
115 | + } |
|
116 | + $reviewCounts = $this->normalize($reviewCounts); |
|
117 | + $reviewCounts[$type][$rating] = intval($reviewCounts[$type][$rating]) + 1; |
|
118 | + return $reviewCounts; |
|
119 | + } |
|
120 | 120 | |
121 | - /** |
|
122 | - * @return void |
|
123 | - */ |
|
124 | - public function updateAll() |
|
125 | - { |
|
126 | - glsr(GlobalCountsManager::class)->updateAll(); |
|
127 | - glsr(PostCountsManager::class)->updateAll(); |
|
128 | - glsr(TermCountsManager::class)->updateAll(); |
|
129 | - } |
|
121 | + /** |
|
122 | + * @return void |
|
123 | + */ |
|
124 | + public function updateAll() |
|
125 | + { |
|
126 | + glsr(GlobalCountsManager::class)->updateAll(); |
|
127 | + glsr(PostCountsManager::class)->updateAll(); |
|
128 | + glsr(TermCountsManager::class)->updateAll(); |
|
129 | + } |
|
130 | 130 | |
131 | - /** |
|
132 | - * @return array |
|
133 | - */ |
|
134 | - protected function combine(array $results) |
|
135 | - { |
|
136 | - if (!wp_is_numeric_array($results)) { |
|
137 | - return $results; |
|
138 | - } |
|
139 | - $mergedKeys = array_keys(array_merge(...$results)); |
|
140 | - $counts = array_fill_keys($mergedKeys, $this->generateEmptyCountsArray()); |
|
141 | - foreach ($results as $typeRatings) { |
|
142 | - foreach ($typeRatings as $type => $ratings) { |
|
143 | - foreach ($ratings as $index => $rating) { |
|
144 | - $counts[$type][$index] = intval($rating) + $counts[$type][$index]; |
|
145 | - } |
|
146 | - } |
|
147 | - } |
|
148 | - return $counts; |
|
149 | - } |
|
131 | + /** |
|
132 | + * @return array |
|
133 | + */ |
|
134 | + protected function combine(array $results) |
|
135 | + { |
|
136 | + if (!wp_is_numeric_array($results)) { |
|
137 | + return $results; |
|
138 | + } |
|
139 | + $mergedKeys = array_keys(array_merge(...$results)); |
|
140 | + $counts = array_fill_keys($mergedKeys, $this->generateEmptyCountsArray()); |
|
141 | + foreach ($results as $typeRatings) { |
|
142 | + foreach ($typeRatings as $type => $ratings) { |
|
143 | + foreach ($ratings as $index => $rating) { |
|
144 | + $counts[$type][$index] = intval($rating) + $counts[$type][$index]; |
|
145 | + } |
|
146 | + } |
|
147 | + } |
|
148 | + return $counts; |
|
149 | + } |
|
150 | 150 | |
151 | - /** |
|
152 | - * @return array |
|
153 | - */ |
|
154 | - protected function generateEmptyCountsArray() |
|
155 | - { |
|
156 | - return array_fill_keys(range(0, glsr()->constant('MAX_RATING', Rating::class)), 0); |
|
157 | - } |
|
151 | + /** |
|
152 | + * @return array |
|
153 | + */ |
|
154 | + protected function generateEmptyCountsArray() |
|
155 | + { |
|
156 | + return array_fill_keys(range(0, glsr()->constant('MAX_RATING', Rating::class)), 0); |
|
157 | + } |
|
158 | 158 | |
159 | - /** |
|
160 | - * @return array |
|
161 | - */ |
|
162 | - protected function get($args) |
|
163 | - { |
|
164 | - $results = []; |
|
165 | - foreach ($args['post_ids'] as $postId) { |
|
166 | - $results[] = glsr(PostCountsManager::class)->get($postId); |
|
167 | - } |
|
168 | - foreach ($args['term_ids'] as $termId) { |
|
169 | - $results[] = glsr(TermCountsManager::class)->get($termId); |
|
170 | - } |
|
171 | - if (empty($results)) { |
|
172 | - $results[] = glsr(GlobalCountsManager::class)->get(); |
|
173 | - } |
|
174 | - $results[] = ['local' => $this->generateEmptyCountsArray()]; // make sure there is a fallback |
|
175 | - return $this->combine($results); |
|
176 | - } |
|
159 | + /** |
|
160 | + * @return array |
|
161 | + */ |
|
162 | + protected function get($args) |
|
163 | + { |
|
164 | + $results = []; |
|
165 | + foreach ($args['post_ids'] as $postId) { |
|
166 | + $results[] = glsr(PostCountsManager::class)->get($postId); |
|
167 | + } |
|
168 | + foreach ($args['term_ids'] as $termId) { |
|
169 | + $results[] = glsr(TermCountsManager::class)->get($termId); |
|
170 | + } |
|
171 | + if (empty($results)) { |
|
172 | + $results[] = glsr(GlobalCountsManager::class)->get(); |
|
173 | + } |
|
174 | + $results[] = ['local' => $this->generateEmptyCountsArray()]; // make sure there is a fallback |
|
175 | + return $this->combine($results); |
|
176 | + } |
|
177 | 177 | |
178 | - /** |
|
179 | - * @return bool |
|
180 | - */ |
|
181 | - protected function hasMixedAssignment(array $args) |
|
182 | - { |
|
183 | - return !empty($args['post_ids']) && !empty($args['term_ids']); |
|
184 | - } |
|
178 | + /** |
|
179 | + * @return bool |
|
180 | + */ |
|
181 | + protected function hasMixedAssignment(array $args) |
|
182 | + { |
|
183 | + return !empty($args['post_ids']) && !empty($args['term_ids']); |
|
184 | + } |
|
185 | 185 | |
186 | - /** |
|
187 | - * @return array |
|
188 | - */ |
|
189 | - protected function normalize(array $reviewCounts) |
|
190 | - { |
|
191 | - foreach ($reviewCounts as &$counts) { |
|
192 | - foreach (array_keys($this->generateEmptyCountsArray()) as $index) { |
|
193 | - if (!isset($counts[$index])) { |
|
194 | - $counts[$index] = 0; |
|
195 | - } |
|
196 | - } |
|
197 | - ksort($counts); |
|
198 | - } |
|
199 | - return $reviewCounts; |
|
200 | - } |
|
186 | + /** |
|
187 | + * @return array |
|
188 | + */ |
|
189 | + protected function normalize(array $reviewCounts) |
|
190 | + { |
|
191 | + foreach ($reviewCounts as &$counts) { |
|
192 | + foreach (array_keys($this->generateEmptyCountsArray()) as $index) { |
|
193 | + if (!isset($counts[$index])) { |
|
194 | + $counts[$index] = 0; |
|
195 | + } |
|
196 | + } |
|
197 | + ksort($counts); |
|
198 | + } |
|
199 | + return $reviewCounts; |
|
200 | + } |
|
201 | 201 | |
202 | - /** |
|
203 | - * @return array |
|
204 | - */ |
|
205 | - protected function normalizeArgs(array $args) |
|
206 | - { |
|
207 | - $args = wp_parse_args(array_filter($args), [ |
|
208 | - 'post_ids' => [], |
|
209 | - 'term_ids' => [], |
|
210 | - 'type' => 'local', |
|
211 | - ]); |
|
212 | - $args['post_ids'] = glsr(Multilingual::class)->getPostIds($args['post_ids']); |
|
213 | - $args['type'] = $this->normalizeType($args['type']); |
|
214 | - return $args; |
|
215 | - } |
|
202 | + /** |
|
203 | + * @return array |
|
204 | + */ |
|
205 | + protected function normalizeArgs(array $args) |
|
206 | + { |
|
207 | + $args = wp_parse_args(array_filter($args), [ |
|
208 | + 'post_ids' => [], |
|
209 | + 'term_ids' => [], |
|
210 | + 'type' => 'local', |
|
211 | + ]); |
|
212 | + $args['post_ids'] = glsr(Multilingual::class)->getPostIds($args['post_ids']); |
|
213 | + $args['type'] = $this->normalizeType($args['type']); |
|
214 | + return $args; |
|
215 | + } |
|
216 | 216 | |
217 | - /** |
|
218 | - * @param string $type |
|
219 | - * @return string |
|
220 | - */ |
|
221 | - protected function normalizeType($type) |
|
222 | - { |
|
223 | - return empty($type) || !is_string($type) |
|
224 | - ? 'local' |
|
225 | - : $type; |
|
226 | - } |
|
217 | + /** |
|
218 | + * @param string $type |
|
219 | + * @return string |
|
220 | + */ |
|
221 | + protected function normalizeType($type) |
|
222 | + { |
|
223 | + return empty($type) || !is_string($type) |
|
224 | + ? 'local' |
|
225 | + : $type; |
|
226 | + } |
|
227 | 227 | |
228 | - /** |
|
229 | - * @param object $query |
|
230 | - * @return array |
|
231 | - */ |
|
232 | - protected function populateCountsFromQuery($query, array $counts) |
|
233 | - { |
|
234 | - foreach ($query->reviews as $review) { |
|
235 | - $type = $this->normalizeType($review->type); |
|
236 | - if (!array_key_exists($type, $counts)) { |
|
237 | - $counts[$type] = $this->generateEmptyCountsArray(); |
|
238 | - } |
|
239 | - ++$counts[$type][$review->rating]; |
|
240 | - } |
|
241 | - return $counts; |
|
242 | - } |
|
228 | + /** |
|
229 | + * @param object $query |
|
230 | + * @return array |
|
231 | + */ |
|
232 | + protected function populateCountsFromQuery($query, array $counts) |
|
233 | + { |
|
234 | + foreach ($query->reviews as $review) { |
|
235 | + $type = $this->normalizeType($review->type); |
|
236 | + if (!array_key_exists($type, $counts)) { |
|
237 | + $counts[$type] = $this->generateEmptyCountsArray(); |
|
238 | + } |
|
239 | + ++$counts[$type][$review->rating]; |
|
240 | + } |
|
241 | + return $counts; |
|
242 | + } |
|
243 | 243 | |
244 | - /** |
|
245 | - * @param int $lastPostId |
|
246 | - * @return object |
|
247 | - */ |
|
248 | - protected function queryReviews(array $args = [], $lastPostId = 0) |
|
249 | - { |
|
250 | - $reviews = glsr(SqlQueries::class)->getReviewCounts($args, $lastPostId, static::LIMIT); |
|
251 | - $hasMore = is_array($reviews) |
|
252 | - ? count($reviews) == static::LIMIT |
|
253 | - : false; |
|
254 | - return (object) [ |
|
255 | - 'has_more' => $hasMore, |
|
256 | - 'reviews' => $reviews, |
|
257 | - ]; |
|
258 | - } |
|
244 | + /** |
|
245 | + * @param int $lastPostId |
|
246 | + * @return object |
|
247 | + */ |
|
248 | + protected function queryReviews(array $args = [], $lastPostId = 0) |
|
249 | + { |
|
250 | + $reviews = glsr(SqlQueries::class)->getReviewCounts($args, $lastPostId, static::LIMIT); |
|
251 | + $hasMore = is_array($reviews) |
|
252 | + ? count($reviews) == static::LIMIT |
|
253 | + : false; |
|
254 | + return (object) [ |
|
255 | + 'has_more' => $hasMore, |
|
256 | + 'reviews' => $reviews, |
|
257 | + ]; |
|
258 | + } |
|
259 | 259 | } |
@@ -21,16 +21,16 @@ discard block |
||
21 | 21 | /** |
22 | 22 | * @return array |
23 | 23 | */ |
24 | - public function buildCounts(array $args = []) |
|
24 | + public function buildCounts( array $args = [] ) |
|
25 | 25 | { |
26 | 26 | $counts = [ |
27 | 27 | 'local' => $this->generateEmptyCountsArray(), |
28 | 28 | ]; |
29 | - $query = $this->queryReviews($args); |
|
30 | - while ($query) { |
|
31 | - $counts = $this->populateCountsFromQuery($query, $counts); |
|
29 | + $query = $this->queryReviews( $args ); |
|
30 | + while( $query ) { |
|
31 | + $counts = $this->populateCountsFromQuery( $query, $counts ); |
|
32 | 32 | $query = $query->has_more |
33 | - ? $this->queryReviews($args, end($query->reviews)->ID) |
|
33 | + ? $this->queryReviews( $args, end( $query->reviews )->ID ) |
|
34 | 34 | : false; |
35 | 35 | } |
36 | 36 | return $counts; |
@@ -39,11 +39,11 @@ discard block |
||
39 | 39 | /** |
40 | 40 | * @return void |
41 | 41 | */ |
42 | - public function decreaseAll(Review $review) |
|
42 | + public function decreaseAll( Review $review ) |
|
43 | 43 | { |
44 | - glsr(GlobalCountsManager::class)->decrease($review); |
|
45 | - glsr(PostCountsManager::class)->decrease($review); |
|
46 | - glsr(TermCountsManager::class)->decrease($review); |
|
44 | + glsr( GlobalCountsManager::class )->decrease( $review ); |
|
45 | + glsr( PostCountsManager::class )->decrease( $review ); |
|
46 | + glsr( TermCountsManager::class )->decrease( $review ); |
|
47 | 47 | } |
48 | 48 | |
49 | 49 | /** |
@@ -51,10 +51,10 @@ discard block |
||
51 | 51 | * @param int $rating |
52 | 52 | * @return array |
53 | 53 | */ |
54 | - public function decreaseRating(array $reviewCounts, $type, $rating) |
|
54 | + public function decreaseRating( array $reviewCounts, $type, $rating ) |
|
55 | 55 | { |
56 | - if (isset($reviewCounts[$type][$rating])) { |
|
57 | - $reviewCounts[$type][$rating] = max(0, $reviewCounts[$type][$rating] - 1); |
|
56 | + if( isset($reviewCounts[$type][$rating]) ) { |
|
57 | + $reviewCounts[$type][$rating] = max( 0, $reviewCounts[$type][$rating] - 1 ); |
|
58 | 58 | } |
59 | 59 | return $reviewCounts; |
60 | 60 | } |
@@ -62,16 +62,16 @@ discard block |
||
62 | 62 | /** |
63 | 63 | * @return array |
64 | 64 | */ |
65 | - public function flatten(array $reviewCounts, array $args = []) |
|
65 | + public function flatten( array $reviewCounts, array $args = [] ) |
|
66 | 66 | { |
67 | 67 | $counts = []; |
68 | - array_walk_recursive($reviewCounts, function ($num, $index) use (&$counts) { |
|
69 | - $counts[$index] = $num + intval(Arr::get($counts, $index, 0)); |
|
68 | + array_walk_recursive( $reviewCounts, function( $num, $index ) use (&$counts) { |
|
69 | + $counts[$index] = $num + intval( Arr::get( $counts, $index, 0 ) ); |
|
70 | 70 | }); |
71 | - $min = Arr::get($args, 'min', glsr()->constant('MIN_RATING', Rating::class)); |
|
72 | - $max = Arr::get($args, 'max', glsr()->constant('MAX_RATING', Rating::class)); |
|
73 | - foreach ($counts as $index => &$num) { |
|
74 | - if (!Helper::inRange($index, $min, $max)) { |
|
71 | + $min = Arr::get( $args, 'min', glsr()->constant( 'MIN_RATING', Rating::class ) ); |
|
72 | + $max = Arr::get( $args, 'max', glsr()->constant( 'MAX_RATING', Rating::class ) ); |
|
73 | + foreach( $counts as $index => &$num ) { |
|
74 | + if( !Helper::inRange( $index, $min, $max ) ) { |
|
75 | 75 | $num = 0; |
76 | 76 | } |
77 | 77 | } |
@@ -81,23 +81,23 @@ discard block |
||
81 | 81 | /** |
82 | 82 | * @return array |
83 | 83 | */ |
84 | - public function getCounts(array $args = []) |
|
84 | + public function getCounts( array $args = [] ) |
|
85 | 85 | { |
86 | - $args = $this->normalizeArgs($args); |
|
87 | - $counts = $this->hasMixedAssignment($args) |
|
88 | - ? $this->buildCounts($args) // force query the database |
|
89 | - : $this->get($args); |
|
90 | - return $this->normalize($counts); |
|
86 | + $args = $this->normalizeArgs( $args ); |
|
87 | + $counts = $this->hasMixedAssignment( $args ) |
|
88 | + ? $this->buildCounts( $args ) // force query the database |
|
89 | + : $this->get( $args ); |
|
90 | + return $this->normalize( $counts ); |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | /** |
94 | 94 | * @return void |
95 | 95 | */ |
96 | - public function increaseAll(Review $review) |
|
96 | + public function increaseAll( Review $review ) |
|
97 | 97 | { |
98 | - glsr(GlobalCountsManager::class)->increase($review); |
|
99 | - glsr(PostCountsManager::class)->increase($review); |
|
100 | - glsr(TermCountsManager::class)->increase($review); |
|
98 | + glsr( GlobalCountsManager::class )->increase( $review ); |
|
99 | + glsr( PostCountsManager::class )->increase( $review ); |
|
100 | + glsr( TermCountsManager::class )->increase( $review ); |
|
101 | 101 | } |
102 | 102 | |
103 | 103 | /** |
@@ -105,16 +105,16 @@ discard block |
||
105 | 105 | * @param int $rating |
106 | 106 | * @return array |
107 | 107 | */ |
108 | - public function increaseRating(array $reviewCounts, $type, $rating) |
|
108 | + public function increaseRating( array $reviewCounts, $type, $rating ) |
|
109 | 109 | { |
110 | - if (!array_key_exists($type, glsr()->reviewTypes)) { |
|
110 | + if( !array_key_exists( $type, glsr()->reviewTypes ) ) { |
|
111 | 111 | return $reviewCounts; |
112 | 112 | } |
113 | - if (!array_key_exists($type, $reviewCounts)) { |
|
113 | + if( !array_key_exists( $type, $reviewCounts ) ) { |
|
114 | 114 | $reviewCounts[$type] = []; |
115 | 115 | } |
116 | - $reviewCounts = $this->normalize($reviewCounts); |
|
117 | - $reviewCounts[$type][$rating] = intval($reviewCounts[$type][$rating]) + 1; |
|
116 | + $reviewCounts = $this->normalize( $reviewCounts ); |
|
117 | + $reviewCounts[$type][$rating] = intval( $reviewCounts[$type][$rating] ) + 1; |
|
118 | 118 | return $reviewCounts; |
119 | 119 | } |
120 | 120 | |
@@ -123,25 +123,25 @@ discard block |
||
123 | 123 | */ |
124 | 124 | public function updateAll() |
125 | 125 | { |
126 | - glsr(GlobalCountsManager::class)->updateAll(); |
|
127 | - glsr(PostCountsManager::class)->updateAll(); |
|
128 | - glsr(TermCountsManager::class)->updateAll(); |
|
126 | + glsr( GlobalCountsManager::class )->updateAll(); |
|
127 | + glsr( PostCountsManager::class )->updateAll(); |
|
128 | + glsr( TermCountsManager::class )->updateAll(); |
|
129 | 129 | } |
130 | 130 | |
131 | 131 | /** |
132 | 132 | * @return array |
133 | 133 | */ |
134 | - protected function combine(array $results) |
|
134 | + protected function combine( array $results ) |
|
135 | 135 | { |
136 | - if (!wp_is_numeric_array($results)) { |
|
136 | + if( !wp_is_numeric_array( $results ) ) { |
|
137 | 137 | return $results; |
138 | 138 | } |
139 | - $mergedKeys = array_keys(array_merge(...$results)); |
|
140 | - $counts = array_fill_keys($mergedKeys, $this->generateEmptyCountsArray()); |
|
141 | - foreach ($results as $typeRatings) { |
|
142 | - foreach ($typeRatings as $type => $ratings) { |
|
143 | - foreach ($ratings as $index => $rating) { |
|
144 | - $counts[$type][$index] = intval($rating) + $counts[$type][$index]; |
|
139 | + $mergedKeys = array_keys( array_merge( ...$results ) ); |
|
140 | + $counts = array_fill_keys( $mergedKeys, $this->generateEmptyCountsArray() ); |
|
141 | + foreach( $results as $typeRatings ) { |
|
142 | + foreach( $typeRatings as $type => $ratings ) { |
|
143 | + foreach( $ratings as $index => $rating ) { |
|
144 | + $counts[$type][$index] = intval( $rating ) + $counts[$type][$index]; |
|
145 | 145 | } |
146 | 146 | } |
147 | 147 | } |
@@ -153,32 +153,32 @@ discard block |
||
153 | 153 | */ |
154 | 154 | protected function generateEmptyCountsArray() |
155 | 155 | { |
156 | - return array_fill_keys(range(0, glsr()->constant('MAX_RATING', Rating::class)), 0); |
|
156 | + return array_fill_keys( range( 0, glsr()->constant( 'MAX_RATING', Rating::class ) ), 0 ); |
|
157 | 157 | } |
158 | 158 | |
159 | 159 | /** |
160 | 160 | * @return array |
161 | 161 | */ |
162 | - protected function get($args) |
|
162 | + protected function get( $args ) |
|
163 | 163 | { |
164 | 164 | $results = []; |
165 | - foreach ($args['post_ids'] as $postId) { |
|
166 | - $results[] = glsr(PostCountsManager::class)->get($postId); |
|
165 | + foreach( $args['post_ids'] as $postId ) { |
|
166 | + $results[] = glsr( PostCountsManager::class )->get( $postId ); |
|
167 | 167 | } |
168 | - foreach ($args['term_ids'] as $termId) { |
|
169 | - $results[] = glsr(TermCountsManager::class)->get($termId); |
|
168 | + foreach( $args['term_ids'] as $termId ) { |
|
169 | + $results[] = glsr( TermCountsManager::class )->get( $termId ); |
|
170 | 170 | } |
171 | - if (empty($results)) { |
|
172 | - $results[] = glsr(GlobalCountsManager::class)->get(); |
|
171 | + if( empty($results) ) { |
|
172 | + $results[] = glsr( GlobalCountsManager::class )->get(); |
|
173 | 173 | } |
174 | 174 | $results[] = ['local' => $this->generateEmptyCountsArray()]; // make sure there is a fallback |
175 | - return $this->combine($results); |
|
175 | + return $this->combine( $results ); |
|
176 | 176 | } |
177 | 177 | |
178 | 178 | /** |
179 | 179 | * @return bool |
180 | 180 | */ |
181 | - protected function hasMixedAssignment(array $args) |
|
181 | + protected function hasMixedAssignment( array $args ) |
|
182 | 182 | { |
183 | 183 | return !empty($args['post_ids']) && !empty($args['term_ids']); |
184 | 184 | } |
@@ -186,15 +186,15 @@ discard block |
||
186 | 186 | /** |
187 | 187 | * @return array |
188 | 188 | */ |
189 | - protected function normalize(array $reviewCounts) |
|
189 | + protected function normalize( array $reviewCounts ) |
|
190 | 190 | { |
191 | - foreach ($reviewCounts as &$counts) { |
|
192 | - foreach (array_keys($this->generateEmptyCountsArray()) as $index) { |
|
193 | - if (!isset($counts[$index])) { |
|
191 | + foreach( $reviewCounts as &$counts ) { |
|
192 | + foreach( array_keys( $this->generateEmptyCountsArray() ) as $index ) { |
|
193 | + if( !isset($counts[$index]) ) { |
|
194 | 194 | $counts[$index] = 0; |
195 | 195 | } |
196 | 196 | } |
197 | - ksort($counts); |
|
197 | + ksort( $counts ); |
|
198 | 198 | } |
199 | 199 | return $reviewCounts; |
200 | 200 | } |
@@ -202,15 +202,15 @@ discard block |
||
202 | 202 | /** |
203 | 203 | * @return array |
204 | 204 | */ |
205 | - protected function normalizeArgs(array $args) |
|
205 | + protected function normalizeArgs( array $args ) |
|
206 | 206 | { |
207 | - $args = wp_parse_args(array_filter($args), [ |
|
207 | + $args = wp_parse_args( array_filter( $args ), [ |
|
208 | 208 | 'post_ids' => [], |
209 | 209 | 'term_ids' => [], |
210 | 210 | 'type' => 'local', |
211 | - ]); |
|
212 | - $args['post_ids'] = glsr(Multilingual::class)->getPostIds($args['post_ids']); |
|
213 | - $args['type'] = $this->normalizeType($args['type']); |
|
211 | + ] ); |
|
212 | + $args['post_ids'] = glsr( Multilingual::class )->getPostIds( $args['post_ids'] ); |
|
213 | + $args['type'] = $this->normalizeType( $args['type'] ); |
|
214 | 214 | return $args; |
215 | 215 | } |
216 | 216 | |
@@ -218,9 +218,9 @@ discard block |
||
218 | 218 | * @param string $type |
219 | 219 | * @return string |
220 | 220 | */ |
221 | - protected function normalizeType($type) |
|
221 | + protected function normalizeType( $type ) |
|
222 | 222 | { |
223 | - return empty($type) || !is_string($type) |
|
223 | + return empty($type) || !is_string( $type ) |
|
224 | 224 | ? 'local' |
225 | 225 | : $type; |
226 | 226 | } |
@@ -229,11 +229,11 @@ discard block |
||
229 | 229 | * @param object $query |
230 | 230 | * @return array |
231 | 231 | */ |
232 | - protected function populateCountsFromQuery($query, array $counts) |
|
232 | + protected function populateCountsFromQuery( $query, array $counts ) |
|
233 | 233 | { |
234 | - foreach ($query->reviews as $review) { |
|
235 | - $type = $this->normalizeType($review->type); |
|
236 | - if (!array_key_exists($type, $counts)) { |
|
234 | + foreach( $query->reviews as $review ) { |
|
235 | + $type = $this->normalizeType( $review->type ); |
|
236 | + if( !array_key_exists( $type, $counts ) ) { |
|
237 | 237 | $counts[$type] = $this->generateEmptyCountsArray(); |
238 | 238 | } |
239 | 239 | ++$counts[$type][$review->rating]; |
@@ -245,13 +245,13 @@ discard block |
||
245 | 245 | * @param int $lastPostId |
246 | 246 | * @return object |
247 | 247 | */ |
248 | - protected function queryReviews(array $args = [], $lastPostId = 0) |
|
248 | + protected function queryReviews( array $args = [], $lastPostId = 0 ) |
|
249 | 249 | { |
250 | - $reviews = glsr(SqlQueries::class)->getReviewCounts($args, $lastPostId, static::LIMIT); |
|
251 | - $hasMore = is_array($reviews) |
|
252 | - ? count($reviews) == static::LIMIT |
|
250 | + $reviews = glsr( SqlQueries::class )->getReviewCounts( $args, $lastPostId, static::LIMIT ); |
|
251 | + $hasMore = is_array( $reviews ) |
|
252 | + ? count( $reviews ) == static::LIMIT |
|
253 | 253 | : false; |
254 | - return (object) [ |
|
254 | + return (object)[ |
|
255 | 255 | 'has_more' => $hasMore, |
256 | 256 | 'reviews' => $reviews, |
257 | 257 | ]; |
@@ -1,25 +1,25 @@ discard block |
||
1 | -<?php defined('WPINC') || die; ?> |
|
1 | +<?php defined( 'WPINC' ) || die; ?> |
|
2 | 2 | |
3 | -<?php if (glsr()->hasPermission('settings')) : ?> |
|
3 | +<?php if( glsr()->hasPermission( 'settings' ) ) : ?> |
|
4 | 4 | <div class="glsr-card card"> |
5 | 5 | <h3>Export Settings</h3> |
6 | 6 | <p>Export the Site Reviews settings for this site to a <code>*.json</code> file. This allows you to easily import the plugin settings into another site.</p> |
7 | - <p>To export your Site Reviews reviews and categories, please use the WordPress <a href="<?= admin_url('export.php'); ?>">Export</a> tool.</p> |
|
7 | + <p>To export your Site Reviews reviews and categories, please use the WordPress <a href="<?= admin_url( 'export.php' ); ?>">Export</a> tool.</p> |
|
8 | 8 | <form method="post"> |
9 | 9 | <input type="hidden" name="{{ id }}[_action]" value="export-settings"> |
10 | - <?php wp_nonce_field('export-settings'); ?> |
|
11 | - <?php submit_button(__('Export Settings', 'site-reviews'), 'secondary'); ?> |
|
10 | + <?php wp_nonce_field( 'export-settings' ); ?> |
|
11 | + <?php submit_button( __( 'Export Settings', 'site-reviews' ), 'secondary' ); ?> |
|
12 | 12 | </form> |
13 | 13 | </div> |
14 | 14 | <div class="glsr-card card"> |
15 | 15 | <h3>Import Settings</h3> |
16 | 16 | <p>Import the Site Reviews settings from a <code>*.json</code> file. This file can be obtained by exporting the settings on another site using the export tool below.</p> |
17 | - <p>To import your Site Reviews reviews and categories from another website, please use the WordPress <a href="<?= admin_url('import.php'); ?>">Import</a> tool.</p> |
|
17 | + <p>To import your Site Reviews reviews and categories from another website, please use the WordPress <a href="<?= admin_url( 'import.php' ); ?>">Import</a> tool.</p> |
|
18 | 18 | <form method="post" enctype="multipart/form-data"> |
19 | 19 | <input type="file" name="import-file"> |
20 | 20 | <input type="hidden" name="{{ id }}[_action]" value="import-settings"> |
21 | - <?php wp_nonce_field('import-settings'); ?> |
|
22 | - <?php submit_button(__('Import Settings', 'site-reviews'), 'secondary'); ?> |
|
21 | + <?php wp_nonce_field( 'import-settings' ); ?> |
|
22 | + <?php submit_button( __( 'Import Settings', 'site-reviews' ), 'secondary' ); ?> |
|
23 | 23 | </form> |
24 | 24 | </div> |
25 | 25 | <?php endif; ?> |
@@ -29,10 +29,10 @@ discard block |
||
29 | 29 | <p>Run this tool if your reviews stopped working correctly after upgrading the plugin to version 4 (i.e. read-only reviews, zero-star ratings, etc.).</p> |
30 | 30 | <form method="post"> |
31 | 31 | <input type="hidden" name="{{ id }}[_action]" value="migrate-reviews"> |
32 | - <?php wp_nonce_field('migrate-reviews'); ?> |
|
32 | + <?php wp_nonce_field( 'migrate-reviews' ); ?> |
|
33 | 33 | <p class="submit"> |
34 | 34 | <button type="submit" class="glsr-button button" name="migrate-reviews" id="migrate-reviews"> |
35 | - <span data-loading="<?= __('Migrating Reviews...', 'site-reviews'); ?>"><?= __('Run Migration', 'site-reviews'); ?></span> |
|
35 | + <span data-loading="<?= __( 'Migrating Reviews...', 'site-reviews' ); ?>"><?= __( 'Run Migration', 'site-reviews' ); ?></span> |
|
36 | 36 | </button> |
37 | 37 | </p> |
38 | 38 | </form> |
@@ -44,10 +44,10 @@ discard block |
||
44 | 44 | <p>If you suspect that the rating counts are incorrect (perhaps you have edited reviews directly in your database), you can recalculate them here.</p> |
45 | 45 | <form method="post"> |
46 | 46 | <input type="hidden" name="{{ id }}[_action]" value="count-reviews"> |
47 | - <?php wp_nonce_field('count-reviews'); ?> |
|
47 | + <?php wp_nonce_field( 'count-reviews' ); ?> |
|
48 | 48 | <p class="submit"> |
49 | 49 | <button type="submit" class="glsr-button button" name="count-reviews" id="count-reviews"> |
50 | - <span data-loading="<?= __('Recalculating Counts...', 'site-reviews'); ?>"><?= __('Recalculate Counts', 'site-reviews'); ?></span> |
|
50 | + <span data-loading="<?= __( 'Recalculating Counts...', 'site-reviews' ); ?>"><?= __( 'Recalculate Counts', 'site-reviews' ); ?></span> |
|
51 | 51 | </button> |
52 | 52 | </p> |
53 | 53 | </form> |
@@ -9,70 +9,70 @@ |
||
9 | 9 | |
10 | 10 | class Upgrade_4_0_2 |
11 | 11 | { |
12 | - /** |
|
13 | - * @return void |
|
14 | - */ |
|
15 | - public function deleteSessions() |
|
16 | - { |
|
17 | - global $wpdb; |
|
18 | - $wpdb->query(" |
|
12 | + /** |
|
13 | + * @return void |
|
14 | + */ |
|
15 | + public function deleteSessions() |
|
16 | + { |
|
17 | + global $wpdb; |
|
18 | + $wpdb->query(" |
|
19 | 19 | DELETE |
20 | 20 | FROM {$wpdb->options} |
21 | 21 | WHERE option_name LIKE '_glsr_session%' |
22 | 22 | "); |
23 | - } |
|
23 | + } |
|
24 | 24 | |
25 | - /** |
|
26 | - * @return void |
|
27 | - */ |
|
28 | - public function migrateSettings() |
|
29 | - { |
|
30 | - if ($settings = get_option(OptionManager::databaseKey(3))) { |
|
31 | - $multilingual = 'yes' == Arr::get($settings, 'settings.general.support.polylang') |
|
32 | - ? 'polylang' |
|
33 | - : ''; |
|
34 | - $settings = Arr::set($settings, 'settings.general.multilingual', $multilingual); |
|
35 | - $settings = Arr::set($settings, 'settings.general.rebusify', 'no'); |
|
36 | - $settings = Arr::set($settings, 'settings.general.rebusify_email', ''); |
|
37 | - $settings = Arr::set($settings, 'settings.general.rebusify_serial', ''); |
|
38 | - $settings = Arr::set($settings, 'settings.reviews.name.format', ''); |
|
39 | - $settings = Arr::set($settings, 'settings.reviews.name.initial', ''); |
|
40 | - $settings = Arr::set($settings, 'settings.submissions.blacklist.integration', ''); |
|
41 | - $settings = Arr::set($settings, 'settings.submissions.limit', ''); |
|
42 | - $settings = Arr::set($settings, 'settings.submissions.limit_whitelist.email', ''); |
|
43 | - $settings = Arr::set($settings, 'settings.submissions.limit_whitelist.ip_address', ''); |
|
44 | - $settings = Arr::set($settings, 'settings.submissions.limit_whitelist.username', ''); |
|
45 | - unset($settings['settings']['general']['support']); |
|
46 | - update_option(OptionManager::databaseKey(4), $settings); |
|
47 | - } |
|
48 | - } |
|
25 | + /** |
|
26 | + * @return void |
|
27 | + */ |
|
28 | + public function migrateSettings() |
|
29 | + { |
|
30 | + if ($settings = get_option(OptionManager::databaseKey(3))) { |
|
31 | + $multilingual = 'yes' == Arr::get($settings, 'settings.general.support.polylang') |
|
32 | + ? 'polylang' |
|
33 | + : ''; |
|
34 | + $settings = Arr::set($settings, 'settings.general.multilingual', $multilingual); |
|
35 | + $settings = Arr::set($settings, 'settings.general.rebusify', 'no'); |
|
36 | + $settings = Arr::set($settings, 'settings.general.rebusify_email', ''); |
|
37 | + $settings = Arr::set($settings, 'settings.general.rebusify_serial', ''); |
|
38 | + $settings = Arr::set($settings, 'settings.reviews.name.format', ''); |
|
39 | + $settings = Arr::set($settings, 'settings.reviews.name.initial', ''); |
|
40 | + $settings = Arr::set($settings, 'settings.submissions.blacklist.integration', ''); |
|
41 | + $settings = Arr::set($settings, 'settings.submissions.limit', ''); |
|
42 | + $settings = Arr::set($settings, 'settings.submissions.limit_whitelist.email', ''); |
|
43 | + $settings = Arr::set($settings, 'settings.submissions.limit_whitelist.ip_address', ''); |
|
44 | + $settings = Arr::set($settings, 'settings.submissions.limit_whitelist.username', ''); |
|
45 | + unset($settings['settings']['general']['support']); |
|
46 | + update_option(OptionManager::databaseKey(4), $settings); |
|
47 | + } |
|
48 | + } |
|
49 | 49 | |
50 | - /** |
|
51 | - * @return void |
|
52 | - */ |
|
53 | - public function protectMetaKeys() |
|
54 | - { |
|
55 | - global $wpdb; |
|
56 | - $keys = array_keys(glsr(CreateReviewDefaults::class)->defaults()); |
|
57 | - $keys = implode("','", $keys); |
|
58 | - $postType = Application::POST_TYPE; |
|
59 | - $wpdb->query(" |
|
50 | + /** |
|
51 | + * @return void |
|
52 | + */ |
|
53 | + public function protectMetaKeys() |
|
54 | + { |
|
55 | + global $wpdb; |
|
56 | + $keys = array_keys(glsr(CreateReviewDefaults::class)->defaults()); |
|
57 | + $keys = implode("','", $keys); |
|
58 | + $postType = Application::POST_TYPE; |
|
59 | + $wpdb->query(" |
|
60 | 60 | UPDATE {$wpdb->postmeta} pm |
61 | 61 | INNER JOIN {$wpdb->posts} p ON p.id = pm.post_id |
62 | 62 | SET pm.meta_key = CONCAT('_', pm.meta_key) |
63 | 63 | WHERE pm.meta_key IN ('{$keys}') |
64 | 64 | AND p.post_type = '{$postType}' |
65 | 65 | "); |
66 | - } |
|
66 | + } |
|
67 | 67 | |
68 | - /** |
|
69 | - * @return void |
|
70 | - */ |
|
71 | - public function run() |
|
72 | - { |
|
73 | - $this->migrateSettings(); |
|
74 | - $this->protectMetaKeys(); |
|
75 | - $this->deleteSessions(); |
|
76 | - delete_transient(Application::ID.'_cloudflare_ips'); |
|
77 | - } |
|
68 | + /** |
|
69 | + * @return void |
|
70 | + */ |
|
71 | + public function run() |
|
72 | + { |
|
73 | + $this->migrateSettings(); |
|
74 | + $this->protectMetaKeys(); |
|
75 | + $this->deleteSessions(); |
|
76 | + delete_transient(Application::ID.'_cloudflare_ips'); |
|
77 | + } |
|
78 | 78 | } |
@@ -15,11 +15,11 @@ discard block |
||
15 | 15 | public function deleteSessions() |
16 | 16 | { |
17 | 17 | global $wpdb; |
18 | - $wpdb->query(" |
|
18 | + $wpdb->query( " |
|
19 | 19 | DELETE |
20 | 20 | FROM {$wpdb->options} |
21 | 21 | WHERE option_name LIKE '_glsr_session%' |
22 | - "); |
|
22 | + " ); |
|
23 | 23 | } |
24 | 24 | |
25 | 25 | /** |
@@ -27,23 +27,23 @@ discard block |
||
27 | 27 | */ |
28 | 28 | public function migrateSettings() |
29 | 29 | { |
30 | - if ($settings = get_option(OptionManager::databaseKey(3))) { |
|
31 | - $multilingual = 'yes' == Arr::get($settings, 'settings.general.support.polylang') |
|
30 | + if( $settings = get_option( OptionManager::databaseKey( 3 ) ) ) { |
|
31 | + $multilingual = 'yes' == Arr::get( $settings, 'settings.general.support.polylang' ) |
|
32 | 32 | ? 'polylang' |
33 | 33 | : ''; |
34 | - $settings = Arr::set($settings, 'settings.general.multilingual', $multilingual); |
|
35 | - $settings = Arr::set($settings, 'settings.general.rebusify', 'no'); |
|
36 | - $settings = Arr::set($settings, 'settings.general.rebusify_email', ''); |
|
37 | - $settings = Arr::set($settings, 'settings.general.rebusify_serial', ''); |
|
38 | - $settings = Arr::set($settings, 'settings.reviews.name.format', ''); |
|
39 | - $settings = Arr::set($settings, 'settings.reviews.name.initial', ''); |
|
40 | - $settings = Arr::set($settings, 'settings.submissions.blacklist.integration', ''); |
|
41 | - $settings = Arr::set($settings, 'settings.submissions.limit', ''); |
|
42 | - $settings = Arr::set($settings, 'settings.submissions.limit_whitelist.email', ''); |
|
43 | - $settings = Arr::set($settings, 'settings.submissions.limit_whitelist.ip_address', ''); |
|
44 | - $settings = Arr::set($settings, 'settings.submissions.limit_whitelist.username', ''); |
|
34 | + $settings = Arr::set( $settings, 'settings.general.multilingual', $multilingual ); |
|
35 | + $settings = Arr::set( $settings, 'settings.general.rebusify', 'no' ); |
|
36 | + $settings = Arr::set( $settings, 'settings.general.rebusify_email', '' ); |
|
37 | + $settings = Arr::set( $settings, 'settings.general.rebusify_serial', '' ); |
|
38 | + $settings = Arr::set( $settings, 'settings.reviews.name.format', '' ); |
|
39 | + $settings = Arr::set( $settings, 'settings.reviews.name.initial', '' ); |
|
40 | + $settings = Arr::set( $settings, 'settings.submissions.blacklist.integration', '' ); |
|
41 | + $settings = Arr::set( $settings, 'settings.submissions.limit', '' ); |
|
42 | + $settings = Arr::set( $settings, 'settings.submissions.limit_whitelist.email', '' ); |
|
43 | + $settings = Arr::set( $settings, 'settings.submissions.limit_whitelist.ip_address', '' ); |
|
44 | + $settings = Arr::set( $settings, 'settings.submissions.limit_whitelist.username', '' ); |
|
45 | 45 | unset($settings['settings']['general']['support']); |
46 | - update_option(OptionManager::databaseKey(4), $settings); |
|
46 | + update_option( OptionManager::databaseKey( 4 ), $settings ); |
|
47 | 47 | } |
48 | 48 | } |
49 | 49 | |
@@ -53,16 +53,16 @@ discard block |
||
53 | 53 | public function protectMetaKeys() |
54 | 54 | { |
55 | 55 | global $wpdb; |
56 | - $keys = array_keys(glsr(CreateReviewDefaults::class)->defaults()); |
|
57 | - $keys = implode("','", $keys); |
|
56 | + $keys = array_keys( glsr( CreateReviewDefaults::class )->defaults() ); |
|
57 | + $keys = implode( "','", $keys ); |
|
58 | 58 | $postType = Application::POST_TYPE; |
59 | - $wpdb->query(" |
|
59 | + $wpdb->query( " |
|
60 | 60 | UPDATE {$wpdb->postmeta} pm |
61 | 61 | INNER JOIN {$wpdb->posts} p ON p.id = pm.post_id |
62 | 62 | SET pm.meta_key = CONCAT('_', pm.meta_key) |
63 | 63 | WHERE pm.meta_key IN ('{$keys}') |
64 | 64 | AND p.post_type = '{$postType}' |
65 | - "); |
|
65 | + " ); |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | /** |
@@ -73,6 +73,6 @@ discard block |
||
73 | 73 | $this->migrateSettings(); |
74 | 74 | $this->protectMetaKeys(); |
75 | 75 | $this->deleteSessions(); |
76 | - delete_transient(Application::ID.'_cloudflare_ips'); |
|
76 | + delete_transient( Application::ID.'_cloudflare_ips' ); |
|
77 | 77 | } |
78 | 78 | } |
@@ -17,231 +17,231 @@ |
||
17 | 17 | |
18 | 18 | class AdminController extends Controller |
19 | 19 | { |
20 | - /** |
|
21 | - * @return void |
|
22 | - * @action admin_enqueue_scripts |
|
23 | - */ |
|
24 | - public function enqueueAssets() |
|
25 | - { |
|
26 | - $command = new EnqueueAdminAssets([ |
|
27 | - 'pointers' => [[ |
|
28 | - 'content' => __('You can pin exceptional reviews so that they are always shown first.', 'site-reviews'), |
|
29 | - 'id' => 'glsr-pointer-pinned', |
|
30 | - 'position' => [ |
|
31 | - 'edge' => 'right', |
|
32 | - 'align' => 'middle', |
|
33 | - ], |
|
34 | - 'screen' => Application::POST_TYPE, |
|
35 | - 'target' => '#misc-pub-pinned', |
|
36 | - 'title' => __('Pin Your Reviews', 'site-reviews'), |
|
37 | - ]], |
|
38 | - ]); |
|
39 | - $this->execute($command); |
|
40 | - } |
|
41 | - |
|
42 | - /** |
|
43 | - * @return array |
|
44 | - * @filter plugin_action_links_site-reviews/site-reviews.php |
|
45 | - */ |
|
46 | - public function filterActionLinks(array $links) |
|
47 | - { |
|
48 | - $links['documentation'] = glsr(Builder::class)->a(__('Help', 'site-reviews'), [ |
|
49 | - 'href' => admin_url('edit.php?post_type='.Application::POST_TYPE.'&page=documentation'), |
|
50 | - ]); |
|
51 | - $links['settings'] = glsr(Builder::class)->a(__('Settings', 'site-reviews'), [ |
|
52 | - 'href' => admin_url('edit.php?post_type='.Application::POST_TYPE.'&page=settings'), |
|
53 | - ]); |
|
54 | - return $links; |
|
55 | - } |
|
56 | - |
|
57 | - /** |
|
58 | - * @param array $capabilities |
|
59 | - * @param string $capability |
|
60 | - * @return array |
|
61 | - * @filter map_meta_cap |
|
62 | - */ |
|
63 | - public function filterCreateCapability($capabilities, $capability) |
|
64 | - { |
|
65 | - if ($capability == 'create_'.Application::POST_TYPE) { |
|
66 | - $capabilities[] = 'do_not_allow'; |
|
67 | - } |
|
68 | - return $capabilities; |
|
69 | - } |
|
70 | - |
|
71 | - /** |
|
72 | - * @param array $items |
|
73 | - * @return array |
|
74 | - * @filter dashboard_glance_items |
|
75 | - */ |
|
76 | - public function filterDashboardGlanceItems($items) |
|
77 | - { |
|
78 | - $postCount = wp_count_posts(Application::POST_TYPE); |
|
79 | - if (empty($postCount->publish)) { |
|
80 | - return $items; |
|
81 | - } |
|
82 | - $text = _n('%s Review', '%s Reviews', $postCount->publish, 'site-reviews'); |
|
83 | - $text = sprintf($text, number_format_i18n($postCount->publish)); |
|
84 | - $items = Arr::consolidateArray($items); |
|
85 | - $items[] = current_user_can(get_post_type_object(Application::POST_TYPE)->cap->edit_posts) |
|
86 | - ? glsr(Builder::class)->a($text, [ |
|
87 | - 'class' => 'glsr-review-count', |
|
88 | - 'href' => 'edit.php?post_type='.Application::POST_TYPE, |
|
89 | - ]) |
|
90 | - : glsr(Builder::class)->span($text, [ |
|
91 | - 'class' => 'glsr-review-count', |
|
92 | - ]); |
|
93 | - return $items; |
|
94 | - } |
|
95 | - |
|
96 | - /** |
|
97 | - * @param array $plugins |
|
98 | - * @return array |
|
99 | - * @filter mce_external_plugins |
|
100 | - */ |
|
101 | - public function filterTinymcePlugins($plugins) |
|
102 | - { |
|
103 | - if (current_user_can('edit_posts') || current_user_can('edit_pages')) { |
|
104 | - $plugins = Arr::consolidateArray($plugins); |
|
105 | - $plugins['glsr_shortcode'] = glsr()->url('assets/scripts/mce-plugin.js'); |
|
106 | - } |
|
107 | - return $plugins; |
|
108 | - } |
|
109 | - |
|
110 | - /** |
|
111 | - * @return void |
|
112 | - * @action admin_init |
|
113 | - */ |
|
114 | - public function registerTinymcePopups() |
|
115 | - { |
|
116 | - $command = new RegisterTinymcePopups([ |
|
117 | - 'site_reviews' => esc_html__('Recent Reviews', 'site-reviews'), |
|
118 | - 'site_reviews_form' => esc_html__('Submit a Review', 'site-reviews'), |
|
119 | - 'site_reviews_summary' => esc_html__('Summary of Reviews', 'site-reviews'), |
|
120 | - ]); |
|
121 | - $this->execute($command); |
|
122 | - } |
|
123 | - |
|
124 | - /** |
|
125 | - * @param string $editorId |
|
126 | - * @return void|null |
|
127 | - * @action media_buttons |
|
128 | - */ |
|
129 | - public function renderTinymceButton($editorId) |
|
130 | - { |
|
131 | - $allowedEditors = apply_filters('site-reviews/tinymce/editor-ids', ['content'], $editorId); |
|
132 | - if ('post' != glsr_current_screen()->base || !in_array($editorId, $allowedEditors)) { |
|
133 | - return; |
|
134 | - } |
|
135 | - $shortcodes = []; |
|
136 | - foreach (glsr()->mceShortcodes as $shortcode => $values) { |
|
137 | - $shortcodes[$shortcode] = $values; |
|
138 | - } |
|
139 | - if (empty($shortcodes)) { |
|
140 | - return; |
|
141 | - } |
|
142 | - glsr()->render('partials/editor/tinymce', [ |
|
143 | - 'shortcodes' => $shortcodes, |
|
144 | - ]); |
|
145 | - } |
|
146 | - |
|
147 | - /** |
|
148 | - * @return void |
|
149 | - */ |
|
150 | - public function routerClearConsole() |
|
151 | - { |
|
152 | - glsr(Console::class)->clear(); |
|
153 | - glsr(Notice::class)->addSuccess(__('Console cleared.', 'site-reviews')); |
|
154 | - } |
|
155 | - |
|
156 | - /** |
|
157 | - * @return void |
|
158 | - */ |
|
159 | - public function routerFetchConsole() |
|
160 | - { |
|
161 | - glsr(Notice::class)->addSuccess(__('Console reloaded.', 'site-reviews')); |
|
162 | - } |
|
163 | - |
|
164 | - /** |
|
165 | - * @param bool $showNotice |
|
166 | - * @return void |
|
167 | - */ |
|
168 | - public function routerCountReviews($showNotice = true) |
|
169 | - { |
|
170 | - glsr(CountsManager::class)->updateAll(); |
|
171 | - glsr(OptionManager::class)->set('last_review_count', current_time('timestamp')); |
|
172 | - if ($showNotice) { |
|
173 | - glsr(Notice::class)->clear()->addSuccess(__('Recalculated rating counts.', 'site-reviews')); |
|
174 | - } |
|
175 | - } |
|
176 | - |
|
177 | - /** |
|
178 | - * @return void |
|
179 | - */ |
|
180 | - public function routerMigrateReviews() |
|
181 | - { |
|
182 | - glsr(Upgrade_4_0_2::class)->protectMetaKeys(); |
|
183 | - glsr(Notice::class)->clear()->addSuccess(__('All reviews have been migrated.', 'site-reviews')); |
|
184 | - } |
|
185 | - |
|
186 | - /** |
|
187 | - * @return void |
|
188 | - */ |
|
189 | - public function routerDownloadConsole() |
|
190 | - { |
|
191 | - $this->download(Application::ID.'-console.txt', glsr(Console::class)->get()); |
|
192 | - } |
|
193 | - |
|
194 | - /** |
|
195 | - * @return void |
|
196 | - */ |
|
197 | - public function routerDownloadSystemInfo() |
|
198 | - { |
|
199 | - $this->download(Application::ID.'-system-info.txt', glsr(System::class)->get()); |
|
200 | - } |
|
201 | - |
|
202 | - /** |
|
203 | - * @return void |
|
204 | - */ |
|
205 | - public function routerExportSettings() |
|
206 | - { |
|
207 | - $this->download(Application::ID.'-settings.json', glsr(OptionManager::class)->json()); |
|
208 | - } |
|
209 | - |
|
210 | - /** |
|
211 | - * @return void |
|
212 | - */ |
|
213 | - public function routerImportSettings() |
|
214 | - { |
|
215 | - $file = $_FILES['import-file']; |
|
216 | - if (UPLOAD_ERR_OK !== $file['error']) { |
|
217 | - return glsr(Notice::class)->addError($this->getUploadError($file['error'])); |
|
218 | - } |
|
219 | - if ('application/json' !== $file['type'] || !Str::endsWith('.json', $file['name'])) { |
|
220 | - return glsr(Notice::class)->addError(__('Please use a valid Site Reviews settings file.', 'site-reviews')); |
|
221 | - } |
|
222 | - $settings = json_decode(file_get_contents($file['tmp_name']), true); |
|
223 | - if (empty($settings)) { |
|
224 | - return glsr(Notice::class)->addWarning(__('There were no settings found to import.', 'site-reviews')); |
|
225 | - } |
|
226 | - glsr(OptionManager::class)->set(glsr(OptionManager::class)->normalize($settings)); |
|
227 | - glsr(Notice::class)->addSuccess(__('Settings imported.', 'site-reviews')); |
|
228 | - } |
|
229 | - |
|
230 | - /** |
|
231 | - * @param int $errorCode |
|
232 | - * @return string |
|
233 | - */ |
|
234 | - protected function getUploadError($errorCode) |
|
235 | - { |
|
236 | - $errors = [ |
|
237 | - UPLOAD_ERR_INI_SIZE => __('The uploaded file exceeds the upload_max_filesize directive in php.ini.', 'site-reviews'), |
|
238 | - UPLOAD_ERR_FORM_SIZE => __('The uploaded file is too big.', 'site-reviews'), |
|
239 | - UPLOAD_ERR_PARTIAL => __('The uploaded file was only partially uploaded.', 'site-reviews'), |
|
240 | - UPLOAD_ERR_NO_FILE => __('No file was uploaded.', 'site-reviews'), |
|
241 | - UPLOAD_ERR_NO_TMP_DIR => __('Missing a temporary folder.', 'site-reviews'), |
|
242 | - UPLOAD_ERR_CANT_WRITE => __('Failed to write file to disk.', 'site-reviews'), |
|
243 | - UPLOAD_ERR_EXTENSION => __('A PHP extension stopped the file upload.', 'site-reviews'), |
|
244 | - ]; |
|
245 | - return Arr::get($errors, $errorCode, __('Unknown upload error.', 'site-reviews')); |
|
246 | - } |
|
20 | + /** |
|
21 | + * @return void |
|
22 | + * @action admin_enqueue_scripts |
|
23 | + */ |
|
24 | + public function enqueueAssets() |
|
25 | + { |
|
26 | + $command = new EnqueueAdminAssets([ |
|
27 | + 'pointers' => [[ |
|
28 | + 'content' => __('You can pin exceptional reviews so that they are always shown first.', 'site-reviews'), |
|
29 | + 'id' => 'glsr-pointer-pinned', |
|
30 | + 'position' => [ |
|
31 | + 'edge' => 'right', |
|
32 | + 'align' => 'middle', |
|
33 | + ], |
|
34 | + 'screen' => Application::POST_TYPE, |
|
35 | + 'target' => '#misc-pub-pinned', |
|
36 | + 'title' => __('Pin Your Reviews', 'site-reviews'), |
|
37 | + ]], |
|
38 | + ]); |
|
39 | + $this->execute($command); |
|
40 | + } |
|
41 | + |
|
42 | + /** |
|
43 | + * @return array |
|
44 | + * @filter plugin_action_links_site-reviews/site-reviews.php |
|
45 | + */ |
|
46 | + public function filterActionLinks(array $links) |
|
47 | + { |
|
48 | + $links['documentation'] = glsr(Builder::class)->a(__('Help', 'site-reviews'), [ |
|
49 | + 'href' => admin_url('edit.php?post_type='.Application::POST_TYPE.'&page=documentation'), |
|
50 | + ]); |
|
51 | + $links['settings'] = glsr(Builder::class)->a(__('Settings', 'site-reviews'), [ |
|
52 | + 'href' => admin_url('edit.php?post_type='.Application::POST_TYPE.'&page=settings'), |
|
53 | + ]); |
|
54 | + return $links; |
|
55 | + } |
|
56 | + |
|
57 | + /** |
|
58 | + * @param array $capabilities |
|
59 | + * @param string $capability |
|
60 | + * @return array |
|
61 | + * @filter map_meta_cap |
|
62 | + */ |
|
63 | + public function filterCreateCapability($capabilities, $capability) |
|
64 | + { |
|
65 | + if ($capability == 'create_'.Application::POST_TYPE) { |
|
66 | + $capabilities[] = 'do_not_allow'; |
|
67 | + } |
|
68 | + return $capabilities; |
|
69 | + } |
|
70 | + |
|
71 | + /** |
|
72 | + * @param array $items |
|
73 | + * @return array |
|
74 | + * @filter dashboard_glance_items |
|
75 | + */ |
|
76 | + public function filterDashboardGlanceItems($items) |
|
77 | + { |
|
78 | + $postCount = wp_count_posts(Application::POST_TYPE); |
|
79 | + if (empty($postCount->publish)) { |
|
80 | + return $items; |
|
81 | + } |
|
82 | + $text = _n('%s Review', '%s Reviews', $postCount->publish, 'site-reviews'); |
|
83 | + $text = sprintf($text, number_format_i18n($postCount->publish)); |
|
84 | + $items = Arr::consolidateArray($items); |
|
85 | + $items[] = current_user_can(get_post_type_object(Application::POST_TYPE)->cap->edit_posts) |
|
86 | + ? glsr(Builder::class)->a($text, [ |
|
87 | + 'class' => 'glsr-review-count', |
|
88 | + 'href' => 'edit.php?post_type='.Application::POST_TYPE, |
|
89 | + ]) |
|
90 | + : glsr(Builder::class)->span($text, [ |
|
91 | + 'class' => 'glsr-review-count', |
|
92 | + ]); |
|
93 | + return $items; |
|
94 | + } |
|
95 | + |
|
96 | + /** |
|
97 | + * @param array $plugins |
|
98 | + * @return array |
|
99 | + * @filter mce_external_plugins |
|
100 | + */ |
|
101 | + public function filterTinymcePlugins($plugins) |
|
102 | + { |
|
103 | + if (current_user_can('edit_posts') || current_user_can('edit_pages')) { |
|
104 | + $plugins = Arr::consolidateArray($plugins); |
|
105 | + $plugins['glsr_shortcode'] = glsr()->url('assets/scripts/mce-plugin.js'); |
|
106 | + } |
|
107 | + return $plugins; |
|
108 | + } |
|
109 | + |
|
110 | + /** |
|
111 | + * @return void |
|
112 | + * @action admin_init |
|
113 | + */ |
|
114 | + public function registerTinymcePopups() |
|
115 | + { |
|
116 | + $command = new RegisterTinymcePopups([ |
|
117 | + 'site_reviews' => esc_html__('Recent Reviews', 'site-reviews'), |
|
118 | + 'site_reviews_form' => esc_html__('Submit a Review', 'site-reviews'), |
|
119 | + 'site_reviews_summary' => esc_html__('Summary of Reviews', 'site-reviews'), |
|
120 | + ]); |
|
121 | + $this->execute($command); |
|
122 | + } |
|
123 | + |
|
124 | + /** |
|
125 | + * @param string $editorId |
|
126 | + * @return void|null |
|
127 | + * @action media_buttons |
|
128 | + */ |
|
129 | + public function renderTinymceButton($editorId) |
|
130 | + { |
|
131 | + $allowedEditors = apply_filters('site-reviews/tinymce/editor-ids', ['content'], $editorId); |
|
132 | + if ('post' != glsr_current_screen()->base || !in_array($editorId, $allowedEditors)) { |
|
133 | + return; |
|
134 | + } |
|
135 | + $shortcodes = []; |
|
136 | + foreach (glsr()->mceShortcodes as $shortcode => $values) { |
|
137 | + $shortcodes[$shortcode] = $values; |
|
138 | + } |
|
139 | + if (empty($shortcodes)) { |
|
140 | + return; |
|
141 | + } |
|
142 | + glsr()->render('partials/editor/tinymce', [ |
|
143 | + 'shortcodes' => $shortcodes, |
|
144 | + ]); |
|
145 | + } |
|
146 | + |
|
147 | + /** |
|
148 | + * @return void |
|
149 | + */ |
|
150 | + public function routerClearConsole() |
|
151 | + { |
|
152 | + glsr(Console::class)->clear(); |
|
153 | + glsr(Notice::class)->addSuccess(__('Console cleared.', 'site-reviews')); |
|
154 | + } |
|
155 | + |
|
156 | + /** |
|
157 | + * @return void |
|
158 | + */ |
|
159 | + public function routerFetchConsole() |
|
160 | + { |
|
161 | + glsr(Notice::class)->addSuccess(__('Console reloaded.', 'site-reviews')); |
|
162 | + } |
|
163 | + |
|
164 | + /** |
|
165 | + * @param bool $showNotice |
|
166 | + * @return void |
|
167 | + */ |
|
168 | + public function routerCountReviews($showNotice = true) |
|
169 | + { |
|
170 | + glsr(CountsManager::class)->updateAll(); |
|
171 | + glsr(OptionManager::class)->set('last_review_count', current_time('timestamp')); |
|
172 | + if ($showNotice) { |
|
173 | + glsr(Notice::class)->clear()->addSuccess(__('Recalculated rating counts.', 'site-reviews')); |
|
174 | + } |
|
175 | + } |
|
176 | + |
|
177 | + /** |
|
178 | + * @return void |
|
179 | + */ |
|
180 | + public function routerMigrateReviews() |
|
181 | + { |
|
182 | + glsr(Upgrade_4_0_2::class)->protectMetaKeys(); |
|
183 | + glsr(Notice::class)->clear()->addSuccess(__('All reviews have been migrated.', 'site-reviews')); |
|
184 | + } |
|
185 | + |
|
186 | + /** |
|
187 | + * @return void |
|
188 | + */ |
|
189 | + public function routerDownloadConsole() |
|
190 | + { |
|
191 | + $this->download(Application::ID.'-console.txt', glsr(Console::class)->get()); |
|
192 | + } |
|
193 | + |
|
194 | + /** |
|
195 | + * @return void |
|
196 | + */ |
|
197 | + public function routerDownloadSystemInfo() |
|
198 | + { |
|
199 | + $this->download(Application::ID.'-system-info.txt', glsr(System::class)->get()); |
|
200 | + } |
|
201 | + |
|
202 | + /** |
|
203 | + * @return void |
|
204 | + */ |
|
205 | + public function routerExportSettings() |
|
206 | + { |
|
207 | + $this->download(Application::ID.'-settings.json', glsr(OptionManager::class)->json()); |
|
208 | + } |
|
209 | + |
|
210 | + /** |
|
211 | + * @return void |
|
212 | + */ |
|
213 | + public function routerImportSettings() |
|
214 | + { |
|
215 | + $file = $_FILES['import-file']; |
|
216 | + if (UPLOAD_ERR_OK !== $file['error']) { |
|
217 | + return glsr(Notice::class)->addError($this->getUploadError($file['error'])); |
|
218 | + } |
|
219 | + if ('application/json' !== $file['type'] || !Str::endsWith('.json', $file['name'])) { |
|
220 | + return glsr(Notice::class)->addError(__('Please use a valid Site Reviews settings file.', 'site-reviews')); |
|
221 | + } |
|
222 | + $settings = json_decode(file_get_contents($file['tmp_name']), true); |
|
223 | + if (empty($settings)) { |
|
224 | + return glsr(Notice::class)->addWarning(__('There were no settings found to import.', 'site-reviews')); |
|
225 | + } |
|
226 | + glsr(OptionManager::class)->set(glsr(OptionManager::class)->normalize($settings)); |
|
227 | + glsr(Notice::class)->addSuccess(__('Settings imported.', 'site-reviews')); |
|
228 | + } |
|
229 | + |
|
230 | + /** |
|
231 | + * @param int $errorCode |
|
232 | + * @return string |
|
233 | + */ |
|
234 | + protected function getUploadError($errorCode) |
|
235 | + { |
|
236 | + $errors = [ |
|
237 | + UPLOAD_ERR_INI_SIZE => __('The uploaded file exceeds the upload_max_filesize directive in php.ini.', 'site-reviews'), |
|
238 | + UPLOAD_ERR_FORM_SIZE => __('The uploaded file is too big.', 'site-reviews'), |
|
239 | + UPLOAD_ERR_PARTIAL => __('The uploaded file was only partially uploaded.', 'site-reviews'), |
|
240 | + UPLOAD_ERR_NO_FILE => __('No file was uploaded.', 'site-reviews'), |
|
241 | + UPLOAD_ERR_NO_TMP_DIR => __('Missing a temporary folder.', 'site-reviews'), |
|
242 | + UPLOAD_ERR_CANT_WRITE => __('Failed to write file to disk.', 'site-reviews'), |
|
243 | + UPLOAD_ERR_EXTENSION => __('A PHP extension stopped the file upload.', 'site-reviews'), |
|
244 | + ]; |
|
245 | + return Arr::get($errors, $errorCode, __('Unknown upload error.', 'site-reviews')); |
|
246 | + } |
|
247 | 247 | } |
@@ -23,9 +23,9 @@ discard block |
||
23 | 23 | */ |
24 | 24 | public function enqueueAssets() |
25 | 25 | { |
26 | - $command = new EnqueueAdminAssets([ |
|
26 | + $command = new EnqueueAdminAssets( [ |
|
27 | 27 | 'pointers' => [[ |
28 | - 'content' => __('You can pin exceptional reviews so that they are always shown first.', 'site-reviews'), |
|
28 | + 'content' => __( 'You can pin exceptional reviews so that they are always shown first.', 'site-reviews' ), |
|
29 | 29 | 'id' => 'glsr-pointer-pinned', |
30 | 30 | 'position' => [ |
31 | 31 | 'edge' => 'right', |
@@ -33,24 +33,24 @@ discard block |
||
33 | 33 | ], |
34 | 34 | 'screen' => Application::POST_TYPE, |
35 | 35 | 'target' => '#misc-pub-pinned', |
36 | - 'title' => __('Pin Your Reviews', 'site-reviews'), |
|
36 | + 'title' => __( 'Pin Your Reviews', 'site-reviews' ), |
|
37 | 37 | ]], |
38 | - ]); |
|
39 | - $this->execute($command); |
|
38 | + ] ); |
|
39 | + $this->execute( $command ); |
|
40 | 40 | } |
41 | 41 | |
42 | 42 | /** |
43 | 43 | * @return array |
44 | 44 | * @filter plugin_action_links_site-reviews/site-reviews.php |
45 | 45 | */ |
46 | - public function filterActionLinks(array $links) |
|
46 | + public function filterActionLinks( array $links ) |
|
47 | 47 | { |
48 | - $links['documentation'] = glsr(Builder::class)->a(__('Help', 'site-reviews'), [ |
|
49 | - 'href' => admin_url('edit.php?post_type='.Application::POST_TYPE.'&page=documentation'), |
|
50 | - ]); |
|
51 | - $links['settings'] = glsr(Builder::class)->a(__('Settings', 'site-reviews'), [ |
|
52 | - 'href' => admin_url('edit.php?post_type='.Application::POST_TYPE.'&page=settings'), |
|
53 | - ]); |
|
48 | + $links['documentation'] = glsr( Builder::class )->a( __( 'Help', 'site-reviews' ), [ |
|
49 | + 'href' => admin_url( 'edit.php?post_type='.Application::POST_TYPE.'&page=documentation' ), |
|
50 | + ] ); |
|
51 | + $links['settings'] = glsr( Builder::class )->a( __( 'Settings', 'site-reviews' ), [ |
|
52 | + 'href' => admin_url( 'edit.php?post_type='.Application::POST_TYPE.'&page=settings' ), |
|
53 | + ] ); |
|
54 | 54 | return $links; |
55 | 55 | } |
56 | 56 | |
@@ -60,9 +60,9 @@ discard block |
||
60 | 60 | * @return array |
61 | 61 | * @filter map_meta_cap |
62 | 62 | */ |
63 | - public function filterCreateCapability($capabilities, $capability) |
|
63 | + public function filterCreateCapability( $capabilities, $capability ) |
|
64 | 64 | { |
65 | - if ($capability == 'create_'.Application::POST_TYPE) { |
|
65 | + if( $capability == 'create_'.Application::POST_TYPE ) { |
|
66 | 66 | $capabilities[] = 'do_not_allow'; |
67 | 67 | } |
68 | 68 | return $capabilities; |
@@ -73,23 +73,23 @@ discard block |
||
73 | 73 | * @return array |
74 | 74 | * @filter dashboard_glance_items |
75 | 75 | */ |
76 | - public function filterDashboardGlanceItems($items) |
|
76 | + public function filterDashboardGlanceItems( $items ) |
|
77 | 77 | { |
78 | - $postCount = wp_count_posts(Application::POST_TYPE); |
|
79 | - if (empty($postCount->publish)) { |
|
78 | + $postCount = wp_count_posts( Application::POST_TYPE ); |
|
79 | + if( empty($postCount->publish) ) { |
|
80 | 80 | return $items; |
81 | 81 | } |
82 | - $text = _n('%s Review', '%s Reviews', $postCount->publish, 'site-reviews'); |
|
83 | - $text = sprintf($text, number_format_i18n($postCount->publish)); |
|
84 | - $items = Arr::consolidateArray($items); |
|
85 | - $items[] = current_user_can(get_post_type_object(Application::POST_TYPE)->cap->edit_posts) |
|
86 | - ? glsr(Builder::class)->a($text, [ |
|
82 | + $text = _n( '%s Review', '%s Reviews', $postCount->publish, 'site-reviews' ); |
|
83 | + $text = sprintf( $text, number_format_i18n( $postCount->publish ) ); |
|
84 | + $items = Arr::consolidateArray( $items ); |
|
85 | + $items[] = current_user_can( get_post_type_object( Application::POST_TYPE )->cap->edit_posts ) |
|
86 | + ? glsr( Builder::class )->a( $text, [ |
|
87 | 87 | 'class' => 'glsr-review-count', |
88 | 88 | 'href' => 'edit.php?post_type='.Application::POST_TYPE, |
89 | - ]) |
|
90 | - : glsr(Builder::class)->span($text, [ |
|
89 | + ] ) |
|
90 | + : glsr( Builder::class )->span( $text, [ |
|
91 | 91 | 'class' => 'glsr-review-count', |
92 | - ]); |
|
92 | + ] ); |
|
93 | 93 | return $items; |
94 | 94 | } |
95 | 95 | |
@@ -98,11 +98,11 @@ discard block |
||
98 | 98 | * @return array |
99 | 99 | * @filter mce_external_plugins |
100 | 100 | */ |
101 | - public function filterTinymcePlugins($plugins) |
|
101 | + public function filterTinymcePlugins( $plugins ) |
|
102 | 102 | { |
103 | - if (current_user_can('edit_posts') || current_user_can('edit_pages')) { |
|
104 | - $plugins = Arr::consolidateArray($plugins); |
|
105 | - $plugins['glsr_shortcode'] = glsr()->url('assets/scripts/mce-plugin.js'); |
|
103 | + if( current_user_can( 'edit_posts' ) || current_user_can( 'edit_pages' ) ) { |
|
104 | + $plugins = Arr::consolidateArray( $plugins ); |
|
105 | + $plugins['glsr_shortcode'] = glsr()->url( 'assets/scripts/mce-plugin.js' ); |
|
106 | 106 | } |
107 | 107 | return $plugins; |
108 | 108 | } |
@@ -113,12 +113,12 @@ discard block |
||
113 | 113 | */ |
114 | 114 | public function registerTinymcePopups() |
115 | 115 | { |
116 | - $command = new RegisterTinymcePopups([ |
|
117 | - 'site_reviews' => esc_html__('Recent Reviews', 'site-reviews'), |
|
118 | - 'site_reviews_form' => esc_html__('Submit a Review', 'site-reviews'), |
|
119 | - 'site_reviews_summary' => esc_html__('Summary of Reviews', 'site-reviews'), |
|
120 | - ]); |
|
121 | - $this->execute($command); |
|
116 | + $command = new RegisterTinymcePopups( [ |
|
117 | + 'site_reviews' => esc_html__( 'Recent Reviews', 'site-reviews' ), |
|
118 | + 'site_reviews_form' => esc_html__( 'Submit a Review', 'site-reviews' ), |
|
119 | + 'site_reviews_summary' => esc_html__( 'Summary of Reviews', 'site-reviews' ), |
|
120 | + ] ); |
|
121 | + $this->execute( $command ); |
|
122 | 122 | } |
123 | 123 | |
124 | 124 | /** |
@@ -126,22 +126,22 @@ discard block |
||
126 | 126 | * @return void|null |
127 | 127 | * @action media_buttons |
128 | 128 | */ |
129 | - public function renderTinymceButton($editorId) |
|
129 | + public function renderTinymceButton( $editorId ) |
|
130 | 130 | { |
131 | - $allowedEditors = apply_filters('site-reviews/tinymce/editor-ids', ['content'], $editorId); |
|
132 | - if ('post' != glsr_current_screen()->base || !in_array($editorId, $allowedEditors)) { |
|
131 | + $allowedEditors = apply_filters( 'site-reviews/tinymce/editor-ids', ['content'], $editorId ); |
|
132 | + if( 'post' != glsr_current_screen()->base || !in_array( $editorId, $allowedEditors ) ) { |
|
133 | 133 | return; |
134 | 134 | } |
135 | 135 | $shortcodes = []; |
136 | - foreach (glsr()->mceShortcodes as $shortcode => $values) { |
|
136 | + foreach( glsr()->mceShortcodes as $shortcode => $values ) { |
|
137 | 137 | $shortcodes[$shortcode] = $values; |
138 | 138 | } |
139 | - if (empty($shortcodes)) { |
|
139 | + if( empty($shortcodes) ) { |
|
140 | 140 | return; |
141 | 141 | } |
142 | - glsr()->render('partials/editor/tinymce', [ |
|
142 | + glsr()->render( 'partials/editor/tinymce', [ |
|
143 | 143 | 'shortcodes' => $shortcodes, |
144 | - ]); |
|
144 | + ] ); |
|
145 | 145 | } |
146 | 146 | |
147 | 147 | /** |
@@ -149,8 +149,8 @@ discard block |
||
149 | 149 | */ |
150 | 150 | public function routerClearConsole() |
151 | 151 | { |
152 | - glsr(Console::class)->clear(); |
|
153 | - glsr(Notice::class)->addSuccess(__('Console cleared.', 'site-reviews')); |
|
152 | + glsr( Console::class )->clear(); |
|
153 | + glsr( Notice::class )->addSuccess( __( 'Console cleared.', 'site-reviews' ) ); |
|
154 | 154 | } |
155 | 155 | |
156 | 156 | /** |
@@ -158,19 +158,19 @@ discard block |
||
158 | 158 | */ |
159 | 159 | public function routerFetchConsole() |
160 | 160 | { |
161 | - glsr(Notice::class)->addSuccess(__('Console reloaded.', 'site-reviews')); |
|
161 | + glsr( Notice::class )->addSuccess( __( 'Console reloaded.', 'site-reviews' ) ); |
|
162 | 162 | } |
163 | 163 | |
164 | 164 | /** |
165 | 165 | * @param bool $showNotice |
166 | 166 | * @return void |
167 | 167 | */ |
168 | - public function routerCountReviews($showNotice = true) |
|
168 | + public function routerCountReviews( $showNotice = true ) |
|
169 | 169 | { |
170 | - glsr(CountsManager::class)->updateAll(); |
|
171 | - glsr(OptionManager::class)->set('last_review_count', current_time('timestamp')); |
|
172 | - if ($showNotice) { |
|
173 | - glsr(Notice::class)->clear()->addSuccess(__('Recalculated rating counts.', 'site-reviews')); |
|
170 | + glsr( CountsManager::class )->updateAll(); |
|
171 | + glsr( OptionManager::class )->set( 'last_review_count', current_time( 'timestamp' ) ); |
|
172 | + if( $showNotice ) { |
|
173 | + glsr( Notice::class )->clear()->addSuccess( __( 'Recalculated rating counts.', 'site-reviews' ) ); |
|
174 | 174 | } |
175 | 175 | } |
176 | 176 | |
@@ -179,8 +179,8 @@ discard block |
||
179 | 179 | */ |
180 | 180 | public function routerMigrateReviews() |
181 | 181 | { |
182 | - glsr(Upgrade_4_0_2::class)->protectMetaKeys(); |
|
183 | - glsr(Notice::class)->clear()->addSuccess(__('All reviews have been migrated.', 'site-reviews')); |
|
182 | + glsr( Upgrade_4_0_2::class )->protectMetaKeys(); |
|
183 | + glsr( Notice::class )->clear()->addSuccess( __( 'All reviews have been migrated.', 'site-reviews' ) ); |
|
184 | 184 | } |
185 | 185 | |
186 | 186 | /** |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | */ |
189 | 189 | public function routerDownloadConsole() |
190 | 190 | { |
191 | - $this->download(Application::ID.'-console.txt', glsr(Console::class)->get()); |
|
191 | + $this->download( Application::ID.'-console.txt', glsr( Console::class )->get() ); |
|
192 | 192 | } |
193 | 193 | |
194 | 194 | /** |
@@ -196,7 +196,7 @@ discard block |
||
196 | 196 | */ |
197 | 197 | public function routerDownloadSystemInfo() |
198 | 198 | { |
199 | - $this->download(Application::ID.'-system-info.txt', glsr(System::class)->get()); |
|
199 | + $this->download( Application::ID.'-system-info.txt', glsr( System::class )->get() ); |
|
200 | 200 | } |
201 | 201 | |
202 | 202 | /** |
@@ -204,7 +204,7 @@ discard block |
||
204 | 204 | */ |
205 | 205 | public function routerExportSettings() |
206 | 206 | { |
207 | - $this->download(Application::ID.'-settings.json', glsr(OptionManager::class)->json()); |
|
207 | + $this->download( Application::ID.'-settings.json', glsr( OptionManager::class )->json() ); |
|
208 | 208 | } |
209 | 209 | |
210 | 210 | /** |
@@ -213,35 +213,35 @@ discard block |
||
213 | 213 | public function routerImportSettings() |
214 | 214 | { |
215 | 215 | $file = $_FILES['import-file']; |
216 | - if (UPLOAD_ERR_OK !== $file['error']) { |
|
217 | - return glsr(Notice::class)->addError($this->getUploadError($file['error'])); |
|
216 | + if( UPLOAD_ERR_OK !== $file['error'] ) { |
|
217 | + return glsr( Notice::class )->addError( $this->getUploadError( $file['error'] ) ); |
|
218 | 218 | } |
219 | - if ('application/json' !== $file['type'] || !Str::endsWith('.json', $file['name'])) { |
|
220 | - return glsr(Notice::class)->addError(__('Please use a valid Site Reviews settings file.', 'site-reviews')); |
|
219 | + if( 'application/json' !== $file['type'] || !Str::endsWith( '.json', $file['name'] ) ) { |
|
220 | + return glsr( Notice::class )->addError( __( 'Please use a valid Site Reviews settings file.', 'site-reviews' ) ); |
|
221 | 221 | } |
222 | - $settings = json_decode(file_get_contents($file['tmp_name']), true); |
|
223 | - if (empty($settings)) { |
|
224 | - return glsr(Notice::class)->addWarning(__('There were no settings found to import.', 'site-reviews')); |
|
222 | + $settings = json_decode( file_get_contents( $file['tmp_name'] ), true ); |
|
223 | + if( empty($settings) ) { |
|
224 | + return glsr( Notice::class )->addWarning( __( 'There were no settings found to import.', 'site-reviews' ) ); |
|
225 | 225 | } |
226 | - glsr(OptionManager::class)->set(glsr(OptionManager::class)->normalize($settings)); |
|
227 | - glsr(Notice::class)->addSuccess(__('Settings imported.', 'site-reviews')); |
|
226 | + glsr( OptionManager::class )->set( glsr( OptionManager::class )->normalize( $settings ) ); |
|
227 | + glsr( Notice::class )->addSuccess( __( 'Settings imported.', 'site-reviews' ) ); |
|
228 | 228 | } |
229 | 229 | |
230 | 230 | /** |
231 | 231 | * @param int $errorCode |
232 | 232 | * @return string |
233 | 233 | */ |
234 | - protected function getUploadError($errorCode) |
|
234 | + protected function getUploadError( $errorCode ) |
|
235 | 235 | { |
236 | 236 | $errors = [ |
237 | - UPLOAD_ERR_INI_SIZE => __('The uploaded file exceeds the upload_max_filesize directive in php.ini.', 'site-reviews'), |
|
238 | - UPLOAD_ERR_FORM_SIZE => __('The uploaded file is too big.', 'site-reviews'), |
|
239 | - UPLOAD_ERR_PARTIAL => __('The uploaded file was only partially uploaded.', 'site-reviews'), |
|
240 | - UPLOAD_ERR_NO_FILE => __('No file was uploaded.', 'site-reviews'), |
|
241 | - UPLOAD_ERR_NO_TMP_DIR => __('Missing a temporary folder.', 'site-reviews'), |
|
242 | - UPLOAD_ERR_CANT_WRITE => __('Failed to write file to disk.', 'site-reviews'), |
|
243 | - UPLOAD_ERR_EXTENSION => __('A PHP extension stopped the file upload.', 'site-reviews'), |
|
237 | + UPLOAD_ERR_INI_SIZE => __( 'The uploaded file exceeds the upload_max_filesize directive in php.ini.', 'site-reviews' ), |
|
238 | + UPLOAD_ERR_FORM_SIZE => __( 'The uploaded file is too big.', 'site-reviews' ), |
|
239 | + UPLOAD_ERR_PARTIAL => __( 'The uploaded file was only partially uploaded.', 'site-reviews' ), |
|
240 | + UPLOAD_ERR_NO_FILE => __( 'No file was uploaded.', 'site-reviews' ), |
|
241 | + UPLOAD_ERR_NO_TMP_DIR => __( 'Missing a temporary folder.', 'site-reviews' ), |
|
242 | + UPLOAD_ERR_CANT_WRITE => __( 'Failed to write file to disk.', 'site-reviews' ), |
|
243 | + UPLOAD_ERR_EXTENSION => __( 'A PHP extension stopped the file upload.', 'site-reviews' ), |
|
244 | 244 | ]; |
245 | - return Arr::get($errors, $errorCode, __('Unknown upload error.', 'site-reviews')); |
|
245 | + return Arr::get( $errors, $errorCode, __( 'Unknown upload error.', 'site-reviews' ) ); |
|
246 | 246 | } |
247 | 247 | } |
@@ -14,180 +14,180 @@ |
||
14 | 14 | |
15 | 15 | class AjaxController extends Controller |
16 | 16 | { |
17 | - /** |
|
18 | - * @return void |
|
19 | - */ |
|
20 | - public function routerChangeStatus(array $request) |
|
21 | - { |
|
22 | - wp_send_json_success($this->execute(new ChangeStatus($request))); |
|
23 | - } |
|
17 | + /** |
|
18 | + * @return void |
|
19 | + */ |
|
20 | + public function routerChangeStatus(array $request) |
|
21 | + { |
|
22 | + wp_send_json_success($this->execute(new ChangeStatus($request))); |
|
23 | + } |
|
24 | 24 | |
25 | - /** |
|
26 | - * @return void |
|
27 | - */ |
|
28 | - public function routerClearConsole() |
|
29 | - { |
|
30 | - glsr(AdminController::class)->routerClearConsole(); |
|
31 | - wp_send_json_success([ |
|
32 | - 'console' => glsr(Console::class)->get(), |
|
33 | - 'notices' => glsr(Notice::class)->get(), |
|
34 | - ]); |
|
35 | - } |
|
25 | + /** |
|
26 | + * @return void |
|
27 | + */ |
|
28 | + public function routerClearConsole() |
|
29 | + { |
|
30 | + glsr(AdminController::class)->routerClearConsole(); |
|
31 | + wp_send_json_success([ |
|
32 | + 'console' => glsr(Console::class)->get(), |
|
33 | + 'notices' => glsr(Notice::class)->get(), |
|
34 | + ]); |
|
35 | + } |
|
36 | 36 | |
37 | - /** |
|
38 | - * @return void |
|
39 | - */ |
|
40 | - public function routerCountReviews() |
|
41 | - { |
|
42 | - glsr(AdminController::class)->routerCountReviews(); |
|
43 | - wp_send_json_success([ |
|
44 | - 'notices' => glsr(Notice::class)->get(), |
|
45 | - ]); |
|
46 | - } |
|
37 | + /** |
|
38 | + * @return void |
|
39 | + */ |
|
40 | + public function routerCountReviews() |
|
41 | + { |
|
42 | + glsr(AdminController::class)->routerCountReviews(); |
|
43 | + wp_send_json_success([ |
|
44 | + 'notices' => glsr(Notice::class)->get(), |
|
45 | + ]); |
|
46 | + } |
|
47 | 47 | |
48 | - /** |
|
49 | - * @return void |
|
50 | - */ |
|
51 | - public function routerMigrateReviews() |
|
52 | - { |
|
53 | - glsr(AdminController::class)->routerMigrateReviews(); |
|
54 | - wp_send_json_success([ |
|
55 | - 'notices' => glsr(Notice::class)->get(), |
|
56 | - ]); |
|
57 | - } |
|
48 | + /** |
|
49 | + * @return void |
|
50 | + */ |
|
51 | + public function routerMigrateReviews() |
|
52 | + { |
|
53 | + glsr(AdminController::class)->routerMigrateReviews(); |
|
54 | + wp_send_json_success([ |
|
55 | + 'notices' => glsr(Notice::class)->get(), |
|
56 | + ]); |
|
57 | + } |
|
58 | 58 | |
59 | - /** |
|
60 | - * @return void |
|
61 | - */ |
|
62 | - public function routerDismissNotice(array $request) |
|
63 | - { |
|
64 | - glsr(NoticeController::class)->routerDismissNotice($request); |
|
65 | - wp_send_json_success(); |
|
66 | - } |
|
59 | + /** |
|
60 | + * @return void |
|
61 | + */ |
|
62 | + public function routerDismissNotice(array $request) |
|
63 | + { |
|
64 | + glsr(NoticeController::class)->routerDismissNotice($request); |
|
65 | + wp_send_json_success(); |
|
66 | + } |
|
67 | 67 | |
68 | - /** |
|
69 | - * @return void |
|
70 | - */ |
|
71 | - public function routerMceShortcode(array $request) |
|
72 | - { |
|
73 | - $shortcode = $request['shortcode']; |
|
74 | - $response = false; |
|
75 | - if (array_key_exists($shortcode, glsr()->mceShortcodes)) { |
|
76 | - $data = glsr()->mceShortcodes[$shortcode]; |
|
77 | - if (!empty($data['errors'])) { |
|
78 | - $data['btn_okay'] = [esc_html__('Okay', 'site-reviews')]; |
|
79 | - } |
|
80 | - $response = [ |
|
81 | - 'body' => $data['fields'], |
|
82 | - 'close' => $data['btn_close'], |
|
83 | - 'ok' => $data['btn_okay'], |
|
84 | - 'shortcode' => $shortcode, |
|
85 | - 'title' => $data['title'], |
|
86 | - ]; |
|
87 | - } |
|
88 | - wp_send_json_success($response); |
|
89 | - } |
|
68 | + /** |
|
69 | + * @return void |
|
70 | + */ |
|
71 | + public function routerMceShortcode(array $request) |
|
72 | + { |
|
73 | + $shortcode = $request['shortcode']; |
|
74 | + $response = false; |
|
75 | + if (array_key_exists($shortcode, glsr()->mceShortcodes)) { |
|
76 | + $data = glsr()->mceShortcodes[$shortcode]; |
|
77 | + if (!empty($data['errors'])) { |
|
78 | + $data['btn_okay'] = [esc_html__('Okay', 'site-reviews')]; |
|
79 | + } |
|
80 | + $response = [ |
|
81 | + 'body' => $data['fields'], |
|
82 | + 'close' => $data['btn_close'], |
|
83 | + 'ok' => $data['btn_okay'], |
|
84 | + 'shortcode' => $shortcode, |
|
85 | + 'title' => $data['title'], |
|
86 | + ]; |
|
87 | + } |
|
88 | + wp_send_json_success($response); |
|
89 | + } |
|
90 | 90 | |
91 | - /** |
|
92 | - * @return void |
|
93 | - */ |
|
94 | - public function routerFetchConsole() |
|
95 | - { |
|
96 | - glsr(AdminController::class)->routerFetchConsole(); |
|
97 | - wp_send_json_success([ |
|
98 | - 'console' => glsr(Console::class)->get(), |
|
99 | - 'notices' => glsr(Notice::class)->get(), |
|
100 | - ]); |
|
101 | - } |
|
91 | + /** |
|
92 | + * @return void |
|
93 | + */ |
|
94 | + public function routerFetchConsole() |
|
95 | + { |
|
96 | + glsr(AdminController::class)->routerFetchConsole(); |
|
97 | + wp_send_json_success([ |
|
98 | + 'console' => glsr(Console::class)->get(), |
|
99 | + 'notices' => glsr(Notice::class)->get(), |
|
100 | + ]); |
|
101 | + } |
|
102 | 102 | |
103 | - /** |
|
104 | - * @return void |
|
105 | - */ |
|
106 | - public function routerSearchPosts(array $request) |
|
107 | - { |
|
108 | - $results = glsr(Database::class)->searchPosts($request['search']); |
|
109 | - wp_send_json_success([ |
|
110 | - 'empty' => '<div>'.__('Nothing found.', 'site-reviews').'</div>', |
|
111 | - 'items' => $results, |
|
112 | - ]); |
|
113 | - } |
|
103 | + /** |
|
104 | + * @return void |
|
105 | + */ |
|
106 | + public function routerSearchPosts(array $request) |
|
107 | + { |
|
108 | + $results = glsr(Database::class)->searchPosts($request['search']); |
|
109 | + wp_send_json_success([ |
|
110 | + 'empty' => '<div>'.__('Nothing found.', 'site-reviews').'</div>', |
|
111 | + 'items' => $results, |
|
112 | + ]); |
|
113 | + } |
|
114 | 114 | |
115 | - /** |
|
116 | - * @return void |
|
117 | - */ |
|
118 | - public function routerSearchTranslations(array $request) |
|
119 | - { |
|
120 | - if (empty($request['exclude'])) { |
|
121 | - $request['exclude'] = []; |
|
122 | - } |
|
123 | - $results = glsr(Translation::class) |
|
124 | - ->search($request['search']) |
|
125 | - ->exclude() |
|
126 | - ->exclude($request['exclude']) |
|
127 | - ->renderResults(); |
|
128 | - wp_send_json_success([ |
|
129 | - 'empty' => '<div>'.__('Nothing found.', 'site-reviews').'</div>', |
|
130 | - 'items' => $results, |
|
131 | - ]); |
|
132 | - } |
|
115 | + /** |
|
116 | + * @return void |
|
117 | + */ |
|
118 | + public function routerSearchTranslations(array $request) |
|
119 | + { |
|
120 | + if (empty($request['exclude'])) { |
|
121 | + $request['exclude'] = []; |
|
122 | + } |
|
123 | + $results = glsr(Translation::class) |
|
124 | + ->search($request['search']) |
|
125 | + ->exclude() |
|
126 | + ->exclude($request['exclude']) |
|
127 | + ->renderResults(); |
|
128 | + wp_send_json_success([ |
|
129 | + 'empty' => '<div>'.__('Nothing found.', 'site-reviews').'</div>', |
|
130 | + 'items' => $results, |
|
131 | + ]); |
|
132 | + } |
|
133 | 133 | |
134 | - /** |
|
135 | - * @return void |
|
136 | - */ |
|
137 | - public function routerSubmitReview(array $request) |
|
138 | - { |
|
139 | - $command = glsr(PublicController::class)->routerSubmitReview($request); |
|
140 | - $redirect = trim(strval(get_post_meta($command->post_id, 'redirect_to', true))); |
|
141 | - $redirect = apply_filters('site-reviews/review/redirect', $redirect, $command); |
|
142 | - $data = [ |
|
143 | - 'errors' => glsr()->sessionGet($command->form_id.'errors', false), |
|
144 | - 'message' => glsr()->sessionGet($command->form_id.'message', ''), |
|
145 | - 'recaptcha' => glsr()->sessionGet($command->form_id.'recaptcha', false), |
|
146 | - 'redirect' => $redirect, |
|
147 | - ]; |
|
148 | - if (false === $data['errors']) { |
|
149 | - glsr()->sessionClear(); |
|
150 | - wp_send_json_success($data); |
|
151 | - } |
|
152 | - wp_send_json_error($data); |
|
153 | - } |
|
134 | + /** |
|
135 | + * @return void |
|
136 | + */ |
|
137 | + public function routerSubmitReview(array $request) |
|
138 | + { |
|
139 | + $command = glsr(PublicController::class)->routerSubmitReview($request); |
|
140 | + $redirect = trim(strval(get_post_meta($command->post_id, 'redirect_to', true))); |
|
141 | + $redirect = apply_filters('site-reviews/review/redirect', $redirect, $command); |
|
142 | + $data = [ |
|
143 | + 'errors' => glsr()->sessionGet($command->form_id.'errors', false), |
|
144 | + 'message' => glsr()->sessionGet($command->form_id.'message', ''), |
|
145 | + 'recaptcha' => glsr()->sessionGet($command->form_id.'recaptcha', false), |
|
146 | + 'redirect' => $redirect, |
|
147 | + ]; |
|
148 | + if (false === $data['errors']) { |
|
149 | + glsr()->sessionClear(); |
|
150 | + wp_send_json_success($data); |
|
151 | + } |
|
152 | + wp_send_json_error($data); |
|
153 | + } |
|
154 | 154 | |
155 | - /** |
|
156 | - * @return void |
|
157 | - */ |
|
158 | - public function routerFetchPagedReviews(array $request) |
|
159 | - { |
|
160 | - $homePath = untrailingslashit(parse_url(home_url(), PHP_URL_PATH)); |
|
161 | - $urlPath = untrailingslashit(parse_url(Arr::get($request, 'url'), PHP_URL_PATH)); |
|
162 | - $urlQuery = []; |
|
163 | - parse_str(parse_url(Arr::get($request, 'url'), PHP_URL_QUERY), $urlQuery); |
|
164 | - $pagedUrl = $homePath === $urlPath |
|
165 | - ? home_url() |
|
166 | - : home_url($urlPath); |
|
167 | - $args = [ |
|
168 | - 'paged' => (int) Arr::get($urlQuery, glsr()->constant('PAGED_QUERY_VAR'), 1), |
|
169 | - 'pagedUrl' => trailingslashit($pagedUrl), |
|
170 | - 'pagination' => 'ajax', |
|
171 | - 'schema' => false, |
|
172 | - ]; |
|
173 | - $atts = (array) json_decode(Arr::get($request, 'atts')); |
|
174 | - $atts = glsr(SiteReviewsShortcode::class)->normalizeAtts($atts); |
|
175 | - $html = glsr(SiteReviewsPartial::class)->build(wp_parse_args($args, $atts)); |
|
176 | - return wp_send_json_success([ |
|
177 | - 'pagination' => $html->getPagination(), |
|
178 | - 'reviews' => $html->getReviews(), |
|
179 | - ]); |
|
180 | - } |
|
155 | + /** |
|
156 | + * @return void |
|
157 | + */ |
|
158 | + public function routerFetchPagedReviews(array $request) |
|
159 | + { |
|
160 | + $homePath = untrailingslashit(parse_url(home_url(), PHP_URL_PATH)); |
|
161 | + $urlPath = untrailingslashit(parse_url(Arr::get($request, 'url'), PHP_URL_PATH)); |
|
162 | + $urlQuery = []; |
|
163 | + parse_str(parse_url(Arr::get($request, 'url'), PHP_URL_QUERY), $urlQuery); |
|
164 | + $pagedUrl = $homePath === $urlPath |
|
165 | + ? home_url() |
|
166 | + : home_url($urlPath); |
|
167 | + $args = [ |
|
168 | + 'paged' => (int) Arr::get($urlQuery, glsr()->constant('PAGED_QUERY_VAR'), 1), |
|
169 | + 'pagedUrl' => trailingslashit($pagedUrl), |
|
170 | + 'pagination' => 'ajax', |
|
171 | + 'schema' => false, |
|
172 | + ]; |
|
173 | + $atts = (array) json_decode(Arr::get($request, 'atts')); |
|
174 | + $atts = glsr(SiteReviewsShortcode::class)->normalizeAtts($atts); |
|
175 | + $html = glsr(SiteReviewsPartial::class)->build(wp_parse_args($args, $atts)); |
|
176 | + return wp_send_json_success([ |
|
177 | + 'pagination' => $html->getPagination(), |
|
178 | + 'reviews' => $html->getReviews(), |
|
179 | + ]); |
|
180 | + } |
|
181 | 181 | |
182 | - /** |
|
183 | - * @return void |
|
184 | - */ |
|
185 | - public function routerTogglePinned(array $request) |
|
186 | - { |
|
187 | - $isPinned = $this->execute(new TogglePinned($request)); |
|
188 | - wp_send_json_success([ |
|
189 | - 'notices' => glsr(Notice::class)->get(), |
|
190 | - 'pinned' => $isPinned, |
|
191 | - ]); |
|
192 | - } |
|
182 | + /** |
|
183 | + * @return void |
|
184 | + */ |
|
185 | + public function routerTogglePinned(array $request) |
|
186 | + { |
|
187 | + $isPinned = $this->execute(new TogglePinned($request)); |
|
188 | + wp_send_json_success([ |
|
189 | + 'notices' => glsr(Notice::class)->get(), |
|
190 | + 'pinned' => $isPinned, |
|
191 | + ]); |
|
192 | + } |
|
193 | 193 | } |
@@ -17,9 +17,9 @@ discard block |
||
17 | 17 | /** |
18 | 18 | * @return void |
19 | 19 | */ |
20 | - public function routerChangeStatus(array $request) |
|
20 | + public function routerChangeStatus( array $request ) |
|
21 | 21 | { |
22 | - wp_send_json_success($this->execute(new ChangeStatus($request))); |
|
22 | + wp_send_json_success( $this->execute( new ChangeStatus( $request ) ) ); |
|
23 | 23 | } |
24 | 24 | |
25 | 25 | /** |
@@ -27,11 +27,11 @@ discard block |
||
27 | 27 | */ |
28 | 28 | public function routerClearConsole() |
29 | 29 | { |
30 | - glsr(AdminController::class)->routerClearConsole(); |
|
31 | - wp_send_json_success([ |
|
32 | - 'console' => glsr(Console::class)->get(), |
|
33 | - 'notices' => glsr(Notice::class)->get(), |
|
34 | - ]); |
|
30 | + glsr( AdminController::class )->routerClearConsole(); |
|
31 | + wp_send_json_success( [ |
|
32 | + 'console' => glsr( Console::class )->get(), |
|
33 | + 'notices' => glsr( Notice::class )->get(), |
|
34 | + ] ); |
|
35 | 35 | } |
36 | 36 | |
37 | 37 | /** |
@@ -39,10 +39,10 @@ discard block |
||
39 | 39 | */ |
40 | 40 | public function routerCountReviews() |
41 | 41 | { |
42 | - glsr(AdminController::class)->routerCountReviews(); |
|
43 | - wp_send_json_success([ |
|
44 | - 'notices' => glsr(Notice::class)->get(), |
|
45 | - ]); |
|
42 | + glsr( AdminController::class )->routerCountReviews(); |
|
43 | + wp_send_json_success( [ |
|
44 | + 'notices' => glsr( Notice::class )->get(), |
|
45 | + ] ); |
|
46 | 46 | } |
47 | 47 | |
48 | 48 | /** |
@@ -50,32 +50,32 @@ discard block |
||
50 | 50 | */ |
51 | 51 | public function routerMigrateReviews() |
52 | 52 | { |
53 | - glsr(AdminController::class)->routerMigrateReviews(); |
|
54 | - wp_send_json_success([ |
|
55 | - 'notices' => glsr(Notice::class)->get(), |
|
56 | - ]); |
|
53 | + glsr( AdminController::class )->routerMigrateReviews(); |
|
54 | + wp_send_json_success( [ |
|
55 | + 'notices' => glsr( Notice::class )->get(), |
|
56 | + ] ); |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | /** |
60 | 60 | * @return void |
61 | 61 | */ |
62 | - public function routerDismissNotice(array $request) |
|
62 | + public function routerDismissNotice( array $request ) |
|
63 | 63 | { |
64 | - glsr(NoticeController::class)->routerDismissNotice($request); |
|
64 | + glsr( NoticeController::class )->routerDismissNotice( $request ); |
|
65 | 65 | wp_send_json_success(); |
66 | 66 | } |
67 | 67 | |
68 | 68 | /** |
69 | 69 | * @return void |
70 | 70 | */ |
71 | - public function routerMceShortcode(array $request) |
|
71 | + public function routerMceShortcode( array $request ) |
|
72 | 72 | { |
73 | 73 | $shortcode = $request['shortcode']; |
74 | 74 | $response = false; |
75 | - if (array_key_exists($shortcode, glsr()->mceShortcodes)) { |
|
75 | + if( array_key_exists( $shortcode, glsr()->mceShortcodes ) ) { |
|
76 | 76 | $data = glsr()->mceShortcodes[$shortcode]; |
77 | - if (!empty($data['errors'])) { |
|
78 | - $data['btn_okay'] = [esc_html__('Okay', 'site-reviews')]; |
|
77 | + if( !empty($data['errors']) ) { |
|
78 | + $data['btn_okay'] = [esc_html__( 'Okay', 'site-reviews' )]; |
|
79 | 79 | } |
80 | 80 | $response = [ |
81 | 81 | 'body' => $data['fields'], |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | 'title' => $data['title'], |
86 | 86 | ]; |
87 | 87 | } |
88 | - wp_send_json_success($response); |
|
88 | + wp_send_json_success( $response ); |
|
89 | 89 | } |
90 | 90 | |
91 | 91 | /** |
@@ -93,101 +93,101 @@ discard block |
||
93 | 93 | */ |
94 | 94 | public function routerFetchConsole() |
95 | 95 | { |
96 | - glsr(AdminController::class)->routerFetchConsole(); |
|
97 | - wp_send_json_success([ |
|
98 | - 'console' => glsr(Console::class)->get(), |
|
99 | - 'notices' => glsr(Notice::class)->get(), |
|
100 | - ]); |
|
96 | + glsr( AdminController::class )->routerFetchConsole(); |
|
97 | + wp_send_json_success( [ |
|
98 | + 'console' => glsr( Console::class )->get(), |
|
99 | + 'notices' => glsr( Notice::class )->get(), |
|
100 | + ] ); |
|
101 | 101 | } |
102 | 102 | |
103 | 103 | /** |
104 | 104 | * @return void |
105 | 105 | */ |
106 | - public function routerSearchPosts(array $request) |
|
106 | + public function routerSearchPosts( array $request ) |
|
107 | 107 | { |
108 | - $results = glsr(Database::class)->searchPosts($request['search']); |
|
109 | - wp_send_json_success([ |
|
110 | - 'empty' => '<div>'.__('Nothing found.', 'site-reviews').'</div>', |
|
108 | + $results = glsr( Database::class )->searchPosts( $request['search'] ); |
|
109 | + wp_send_json_success( [ |
|
110 | + 'empty' => '<div>'.__( 'Nothing found.', 'site-reviews' ).'</div>', |
|
111 | 111 | 'items' => $results, |
112 | - ]); |
|
112 | + ] ); |
|
113 | 113 | } |
114 | 114 | |
115 | 115 | /** |
116 | 116 | * @return void |
117 | 117 | */ |
118 | - public function routerSearchTranslations(array $request) |
|
118 | + public function routerSearchTranslations( array $request ) |
|
119 | 119 | { |
120 | - if (empty($request['exclude'])) { |
|
120 | + if( empty($request['exclude']) ) { |
|
121 | 121 | $request['exclude'] = []; |
122 | 122 | } |
123 | - $results = glsr(Translation::class) |
|
124 | - ->search($request['search']) |
|
123 | + $results = glsr( Translation::class ) |
|
124 | + ->search( $request['search'] ) |
|
125 | 125 | ->exclude() |
126 | - ->exclude($request['exclude']) |
|
126 | + ->exclude( $request['exclude'] ) |
|
127 | 127 | ->renderResults(); |
128 | - wp_send_json_success([ |
|
129 | - 'empty' => '<div>'.__('Nothing found.', 'site-reviews').'</div>', |
|
128 | + wp_send_json_success( [ |
|
129 | + 'empty' => '<div>'.__( 'Nothing found.', 'site-reviews' ).'</div>', |
|
130 | 130 | 'items' => $results, |
131 | - ]); |
|
131 | + ] ); |
|
132 | 132 | } |
133 | 133 | |
134 | 134 | /** |
135 | 135 | * @return void |
136 | 136 | */ |
137 | - public function routerSubmitReview(array $request) |
|
137 | + public function routerSubmitReview( array $request ) |
|
138 | 138 | { |
139 | - $command = glsr(PublicController::class)->routerSubmitReview($request); |
|
140 | - $redirect = trim(strval(get_post_meta($command->post_id, 'redirect_to', true))); |
|
141 | - $redirect = apply_filters('site-reviews/review/redirect', $redirect, $command); |
|
139 | + $command = glsr( PublicController::class )->routerSubmitReview( $request ); |
|
140 | + $redirect = trim( strval( get_post_meta( $command->post_id, 'redirect_to', true ) ) ); |
|
141 | + $redirect = apply_filters( 'site-reviews/review/redirect', $redirect, $command ); |
|
142 | 142 | $data = [ |
143 | - 'errors' => glsr()->sessionGet($command->form_id.'errors', false), |
|
144 | - 'message' => glsr()->sessionGet($command->form_id.'message', ''), |
|
145 | - 'recaptcha' => glsr()->sessionGet($command->form_id.'recaptcha', false), |
|
143 | + 'errors' => glsr()->sessionGet( $command->form_id.'errors', false ), |
|
144 | + 'message' => glsr()->sessionGet( $command->form_id.'message', '' ), |
|
145 | + 'recaptcha' => glsr()->sessionGet( $command->form_id.'recaptcha', false ), |
|
146 | 146 | 'redirect' => $redirect, |
147 | 147 | ]; |
148 | - if (false === $data['errors']) { |
|
148 | + if( false === $data['errors'] ) { |
|
149 | 149 | glsr()->sessionClear(); |
150 | - wp_send_json_success($data); |
|
150 | + wp_send_json_success( $data ); |
|
151 | 151 | } |
152 | - wp_send_json_error($data); |
|
152 | + wp_send_json_error( $data ); |
|
153 | 153 | } |
154 | 154 | |
155 | 155 | /** |
156 | 156 | * @return void |
157 | 157 | */ |
158 | - public function routerFetchPagedReviews(array $request) |
|
158 | + public function routerFetchPagedReviews( array $request ) |
|
159 | 159 | { |
160 | - $homePath = untrailingslashit(parse_url(home_url(), PHP_URL_PATH)); |
|
161 | - $urlPath = untrailingslashit(parse_url(Arr::get($request, 'url'), PHP_URL_PATH)); |
|
160 | + $homePath = untrailingslashit( parse_url( home_url(), PHP_URL_PATH ) ); |
|
161 | + $urlPath = untrailingslashit( parse_url( Arr::get( $request, 'url' ), PHP_URL_PATH ) ); |
|
162 | 162 | $urlQuery = []; |
163 | - parse_str(parse_url(Arr::get($request, 'url'), PHP_URL_QUERY), $urlQuery); |
|
163 | + parse_str( parse_url( Arr::get( $request, 'url' ), PHP_URL_QUERY ), $urlQuery ); |
|
164 | 164 | $pagedUrl = $homePath === $urlPath |
165 | 165 | ? home_url() |
166 | - : home_url($urlPath); |
|
166 | + : home_url( $urlPath ); |
|
167 | 167 | $args = [ |
168 | - 'paged' => (int) Arr::get($urlQuery, glsr()->constant('PAGED_QUERY_VAR'), 1), |
|
169 | - 'pagedUrl' => trailingslashit($pagedUrl), |
|
168 | + 'paged' => (int)Arr::get( $urlQuery, glsr()->constant( 'PAGED_QUERY_VAR' ), 1 ), |
|
169 | + 'pagedUrl' => trailingslashit( $pagedUrl ), |
|
170 | 170 | 'pagination' => 'ajax', |
171 | 171 | 'schema' => false, |
172 | 172 | ]; |
173 | - $atts = (array) json_decode(Arr::get($request, 'atts')); |
|
174 | - $atts = glsr(SiteReviewsShortcode::class)->normalizeAtts($atts); |
|
175 | - $html = glsr(SiteReviewsPartial::class)->build(wp_parse_args($args, $atts)); |
|
176 | - return wp_send_json_success([ |
|
173 | + $atts = (array)json_decode( Arr::get( $request, 'atts' ) ); |
|
174 | + $atts = glsr( SiteReviewsShortcode::class )->normalizeAtts( $atts ); |
|
175 | + $html = glsr( SiteReviewsPartial::class )->build( wp_parse_args( $args, $atts ) ); |
|
176 | + return wp_send_json_success( [ |
|
177 | 177 | 'pagination' => $html->getPagination(), |
178 | 178 | 'reviews' => $html->getReviews(), |
179 | - ]); |
|
179 | + ] ); |
|
180 | 180 | } |
181 | 181 | |
182 | 182 | /** |
183 | 183 | * @return void |
184 | 184 | */ |
185 | - public function routerTogglePinned(array $request) |
|
185 | + public function routerTogglePinned( array $request ) |
|
186 | 186 | { |
187 | - $isPinned = $this->execute(new TogglePinned($request)); |
|
188 | - wp_send_json_success([ |
|
189 | - 'notices' => glsr(Notice::class)->get(), |
|
187 | + $isPinned = $this->execute( new TogglePinned( $request ) ); |
|
188 | + wp_send_json_success( [ |
|
189 | + 'notices' => glsr( Notice::class )->get(), |
|
190 | 190 | 'pinned' => $isPinned, |
191 | - ]); |
|
191 | + ] ); |
|
192 | 192 | } |
193 | 193 | } |
@@ -9,153 +9,153 @@ |
||
9 | 9 | |
10 | 10 | class OptionManager |
11 | 11 | { |
12 | - /** |
|
13 | - * @var array |
|
14 | - */ |
|
15 | - protected $options; |
|
12 | + /** |
|
13 | + * @var array |
|
14 | + */ |
|
15 | + protected $options; |
|
16 | 16 | |
17 | - /** |
|
18 | - * @return string |
|
19 | - */ |
|
20 | - public static function databaseKey($version = null) |
|
21 | - { |
|
22 | - if (null === $version) { |
|
23 | - $version = explode('.', glsr()->version); |
|
24 | - $version = array_shift($version); |
|
25 | - } |
|
26 | - return Str::snakeCase( |
|
27 | - Application::ID.'-v'.intval($version) |
|
28 | - ); |
|
29 | - } |
|
17 | + /** |
|
18 | + * @return string |
|
19 | + */ |
|
20 | + public static function databaseKey($version = null) |
|
21 | + { |
|
22 | + if (null === $version) { |
|
23 | + $version = explode('.', glsr()->version); |
|
24 | + $version = array_shift($version); |
|
25 | + } |
|
26 | + return Str::snakeCase( |
|
27 | + Application::ID.'-v'.intval($version) |
|
28 | + ); |
|
29 | + } |
|
30 | 30 | |
31 | - /** |
|
32 | - * @return array |
|
33 | - */ |
|
34 | - public function all() |
|
35 | - { |
|
36 | - if (empty($this->options)) { |
|
37 | - $this->reset(); |
|
38 | - } |
|
39 | - return $this->options; |
|
40 | - } |
|
31 | + /** |
|
32 | + * @return array |
|
33 | + */ |
|
34 | + public function all() |
|
35 | + { |
|
36 | + if (empty($this->options)) { |
|
37 | + $this->reset(); |
|
38 | + } |
|
39 | + return $this->options; |
|
40 | + } |
|
41 | 41 | |
42 | - /** |
|
43 | - * @param string $path |
|
44 | - * @return bool |
|
45 | - */ |
|
46 | - public function delete($path) |
|
47 | - { |
|
48 | - $keys = explode('.', $path); |
|
49 | - $last = array_pop($keys); |
|
50 | - $options = $this->all(); |
|
51 | - $pointer = &$options; |
|
52 | - foreach ($keys as $key) { |
|
53 | - if (!isset($pointer[$key]) || !is_array($pointer[$key])) { |
|
54 | - continue; |
|
55 | - } |
|
56 | - $pointer = &$pointer[$key]; |
|
57 | - } |
|
58 | - unset($pointer[$last]); |
|
59 | - return $this->set($options); |
|
60 | - } |
|
42 | + /** |
|
43 | + * @param string $path |
|
44 | + * @return bool |
|
45 | + */ |
|
46 | + public function delete($path) |
|
47 | + { |
|
48 | + $keys = explode('.', $path); |
|
49 | + $last = array_pop($keys); |
|
50 | + $options = $this->all(); |
|
51 | + $pointer = &$options; |
|
52 | + foreach ($keys as $key) { |
|
53 | + if (!isset($pointer[$key]) || !is_array($pointer[$key])) { |
|
54 | + continue; |
|
55 | + } |
|
56 | + $pointer = &$pointer[$key]; |
|
57 | + } |
|
58 | + unset($pointer[$last]); |
|
59 | + return $this->set($options); |
|
60 | + } |
|
61 | 61 | |
62 | - /** |
|
63 | - * @param string $path |
|
64 | - * @param mixed $fallback |
|
65 | - * @param string $cast |
|
66 | - * @return mixed |
|
67 | - */ |
|
68 | - public function get($path = '', $fallback = '', $cast = '') |
|
69 | - { |
|
70 | - $result = Arr::get($this->all(), $path, $fallback); |
|
71 | - return Helper::castTo($cast, $result); |
|
72 | - } |
|
62 | + /** |
|
63 | + * @param string $path |
|
64 | + * @param mixed $fallback |
|
65 | + * @param string $cast |
|
66 | + * @return mixed |
|
67 | + */ |
|
68 | + public function get($path = '', $fallback = '', $cast = '') |
|
69 | + { |
|
70 | + $result = Arr::get($this->all(), $path, $fallback); |
|
71 | + return Helper::castTo($cast, $result); |
|
72 | + } |
|
73 | 73 | |
74 | - /** |
|
75 | - * @param string $path |
|
76 | - * @return bool |
|
77 | - */ |
|
78 | - public function getBool($path) |
|
79 | - { |
|
80 | - return Helper::castToBool($this->get($path)); |
|
81 | - } |
|
74 | + /** |
|
75 | + * @param string $path |
|
76 | + * @return bool |
|
77 | + */ |
|
78 | + public function getBool($path) |
|
79 | + { |
|
80 | + return Helper::castToBool($this->get($path)); |
|
81 | + } |
|
82 | 82 | |
83 | - /** |
|
84 | - * @param string $path |
|
85 | - * @param mixed $fallback |
|
86 | - * @param string $cast |
|
87 | - * @return mixed |
|
88 | - */ |
|
89 | - public function getWP($path, $fallback = '', $cast = '') |
|
90 | - { |
|
91 | - $option = get_option($path, $fallback); |
|
92 | - if (empty($option)) { |
|
93 | - $option = $fallback; |
|
94 | - } |
|
95 | - return Helper::castTo($cast, $option); |
|
96 | - } |
|
83 | + /** |
|
84 | + * @param string $path |
|
85 | + * @param mixed $fallback |
|
86 | + * @param string $cast |
|
87 | + * @return mixed |
|
88 | + */ |
|
89 | + public function getWP($path, $fallback = '', $cast = '') |
|
90 | + { |
|
91 | + $option = get_option($path, $fallback); |
|
92 | + if (empty($option)) { |
|
93 | + $option = $fallback; |
|
94 | + } |
|
95 | + return Helper::castTo($cast, $option); |
|
96 | + } |
|
97 | 97 | |
98 | - /** |
|
99 | - * @return string |
|
100 | - */ |
|
101 | - public function json() |
|
102 | - { |
|
103 | - return json_encode($this->all()); |
|
104 | - } |
|
98 | + /** |
|
99 | + * @return string |
|
100 | + */ |
|
101 | + public function json() |
|
102 | + { |
|
103 | + return json_encode($this->all()); |
|
104 | + } |
|
105 | 105 | |
106 | - /** |
|
107 | - * @return array |
|
108 | - */ |
|
109 | - public function normalize(array $options = []) |
|
110 | - { |
|
111 | - $options = wp_parse_args( |
|
112 | - Arr::flattenArray($options), |
|
113 | - glsr(DefaultsManager::class)->defaults() |
|
114 | - ); |
|
115 | - array_walk($options, function (&$value) { |
|
116 | - if (!is_string($value)) { |
|
117 | - return; |
|
118 | - } |
|
119 | - $value = wp_kses($value, wp_kses_allowed_html('post')); |
|
120 | - }); |
|
121 | - return Arr::convertDotNotationArray($options); |
|
122 | - } |
|
106 | + /** |
|
107 | + * @return array |
|
108 | + */ |
|
109 | + public function normalize(array $options = []) |
|
110 | + { |
|
111 | + $options = wp_parse_args( |
|
112 | + Arr::flattenArray($options), |
|
113 | + glsr(DefaultsManager::class)->defaults() |
|
114 | + ); |
|
115 | + array_walk($options, function (&$value) { |
|
116 | + if (!is_string($value)) { |
|
117 | + return; |
|
118 | + } |
|
119 | + $value = wp_kses($value, wp_kses_allowed_html('post')); |
|
120 | + }); |
|
121 | + return Arr::convertDotNotationArray($options); |
|
122 | + } |
|
123 | 123 | |
124 | - /** |
|
125 | - * @return bool |
|
126 | - */ |
|
127 | - public function isRecaptchaEnabled() |
|
128 | - { |
|
129 | - $integration = $this->get('settings.submissions.recaptcha.integration'); |
|
130 | - return 'all' == $integration || ('guest' == $integration && !is_user_logged_in()); |
|
131 | - } |
|
124 | + /** |
|
125 | + * @return bool |
|
126 | + */ |
|
127 | + public function isRecaptchaEnabled() |
|
128 | + { |
|
129 | + $integration = $this->get('settings.submissions.recaptcha.integration'); |
|
130 | + return 'all' == $integration || ('guest' == $integration && !is_user_logged_in()); |
|
131 | + } |
|
132 | 132 | |
133 | - /** |
|
134 | - * @return array |
|
135 | - */ |
|
136 | - public function reset() |
|
137 | - { |
|
138 | - $options = $this->getWP(static::databaseKey(), []); |
|
139 | - if (!is_array($options) || empty($options)) { |
|
140 | - delete_option(static::databaseKey()); |
|
141 | - $options = glsr()->defaults ?: []; |
|
142 | - } |
|
143 | - $this->options = $options; |
|
144 | - } |
|
133 | + /** |
|
134 | + * @return array |
|
135 | + */ |
|
136 | + public function reset() |
|
137 | + { |
|
138 | + $options = $this->getWP(static::databaseKey(), []); |
|
139 | + if (!is_array($options) || empty($options)) { |
|
140 | + delete_option(static::databaseKey()); |
|
141 | + $options = glsr()->defaults ?: []; |
|
142 | + } |
|
143 | + $this->options = $options; |
|
144 | + } |
|
145 | 145 | |
146 | - /** |
|
147 | - * @param string|array $pathOrOptions |
|
148 | - * @param mixed $value |
|
149 | - * @return bool |
|
150 | - */ |
|
151 | - public function set($pathOrOptions, $value = '') |
|
152 | - { |
|
153 | - if (is_string($pathOrOptions)) { |
|
154 | - $pathOrOptions = Arr::set($this->all(), $pathOrOptions, $value); |
|
155 | - } |
|
156 | - if ($result = update_option(static::databaseKey(), (array) $pathOrOptions)) { |
|
157 | - $this->reset(); |
|
158 | - } |
|
159 | - return $result; |
|
160 | - } |
|
146 | + /** |
|
147 | + * @param string|array $pathOrOptions |
|
148 | + * @param mixed $value |
|
149 | + * @return bool |
|
150 | + */ |
|
151 | + public function set($pathOrOptions, $value = '') |
|
152 | + { |
|
153 | + if (is_string($pathOrOptions)) { |
|
154 | + $pathOrOptions = Arr::set($this->all(), $pathOrOptions, $value); |
|
155 | + } |
|
156 | + if ($result = update_option(static::databaseKey(), (array) $pathOrOptions)) { |
|
157 | + $this->reset(); |
|
158 | + } |
|
159 | + return $result; |
|
160 | + } |
|
161 | 161 | } |
@@ -17,14 +17,14 @@ 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 (null === $version) { |
|
23 | - $version = explode('.', glsr()->version); |
|
24 | - $version = array_shift($version); |
|
22 | + if( null === $version ) { |
|
23 | + $version = explode( '.', glsr()->version ); |
|
24 | + $version = array_shift( $version ); |
|
25 | 25 | } |
26 | 26 | return Str::snakeCase( |
27 | - Application::ID.'-v'.intval($version) |
|
27 | + Application::ID.'-v'.intval( $version ) |
|
28 | 28 | ); |
29 | 29 | } |
30 | 30 | |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | */ |
34 | 34 | public function all() |
35 | 35 | { |
36 | - if (empty($this->options)) { |
|
36 | + if( empty($this->options) ) { |
|
37 | 37 | $this->reset(); |
38 | 38 | } |
39 | 39 | return $this->options; |
@@ -43,20 +43,20 @@ discard block |
||
43 | 43 | * @param string $path |
44 | 44 | * @return bool |
45 | 45 | */ |
46 | - public function delete($path) |
|
46 | + public function delete( $path ) |
|
47 | 47 | { |
48 | - $keys = explode('.', $path); |
|
49 | - $last = array_pop($keys); |
|
48 | + $keys = explode( '.', $path ); |
|
49 | + $last = array_pop( $keys ); |
|
50 | 50 | $options = $this->all(); |
51 | 51 | $pointer = &$options; |
52 | - foreach ($keys as $key) { |
|
53 | - if (!isset($pointer[$key]) || !is_array($pointer[$key])) { |
|
52 | + foreach( $keys as $key ) { |
|
53 | + if( !isset($pointer[$key]) || !is_array( $pointer[$key] ) ) { |
|
54 | 54 | continue; |
55 | 55 | } |
56 | 56 | $pointer = &$pointer[$key]; |
57 | 57 | } |
58 | 58 | unset($pointer[$last]); |
59 | - return $this->set($options); |
|
59 | + return $this->set( $options ); |
|
60 | 60 | } |
61 | 61 | |
62 | 62 | /** |
@@ -65,19 +65,19 @@ discard block |
||
65 | 65 | * @param string $cast |
66 | 66 | * @return mixed |
67 | 67 | */ |
68 | - public function get($path = '', $fallback = '', $cast = '') |
|
68 | + public function get( $path = '', $fallback = '', $cast = '' ) |
|
69 | 69 | { |
70 | - $result = Arr::get($this->all(), $path, $fallback); |
|
71 | - return Helper::castTo($cast, $result); |
|
70 | + $result = Arr::get( $this->all(), $path, $fallback ); |
|
71 | + return Helper::castTo( $cast, $result ); |
|
72 | 72 | } |
73 | 73 | |
74 | 74 | /** |
75 | 75 | * @param string $path |
76 | 76 | * @return bool |
77 | 77 | */ |
78 | - public function getBool($path) |
|
78 | + public function getBool( $path ) |
|
79 | 79 | { |
80 | - return Helper::castToBool($this->get($path)); |
|
80 | + return Helper::castToBool( $this->get( $path ) ); |
|
81 | 81 | } |
82 | 82 | |
83 | 83 | /** |
@@ -86,13 +86,13 @@ discard block |
||
86 | 86 | * @param string $cast |
87 | 87 | * @return mixed |
88 | 88 | */ |
89 | - public function getWP($path, $fallback = '', $cast = '') |
|
89 | + public function getWP( $path, $fallback = '', $cast = '' ) |
|
90 | 90 | { |
91 | - $option = get_option($path, $fallback); |
|
92 | - if (empty($option)) { |
|
91 | + $option = get_option( $path, $fallback ); |
|
92 | + if( empty($option) ) { |
|
93 | 93 | $option = $fallback; |
94 | 94 | } |
95 | - return Helper::castTo($cast, $option); |
|
95 | + return Helper::castTo( $cast, $option ); |
|
96 | 96 | } |
97 | 97 | |
98 | 98 | /** |
@@ -100,25 +100,25 @@ discard block |
||
100 | 100 | */ |
101 | 101 | public function json() |
102 | 102 | { |
103 | - return json_encode($this->all()); |
|
103 | + return json_encode( $this->all() ); |
|
104 | 104 | } |
105 | 105 | |
106 | 106 | /** |
107 | 107 | * @return array |
108 | 108 | */ |
109 | - public function normalize(array $options = []) |
|
109 | + public function normalize( array $options = [] ) |
|
110 | 110 | { |
111 | 111 | $options = wp_parse_args( |
112 | - Arr::flattenArray($options), |
|
113 | - glsr(DefaultsManager::class)->defaults() |
|
112 | + Arr::flattenArray( $options ), |
|
113 | + glsr( DefaultsManager::class )->defaults() |
|
114 | 114 | ); |
115 | - array_walk($options, function (&$value) { |
|
116 | - if (!is_string($value)) { |
|
115 | + array_walk( $options, function( &$value ) { |
|
116 | + if( !is_string( $value ) ) { |
|
117 | 117 | return; |
118 | 118 | } |
119 | - $value = wp_kses($value, wp_kses_allowed_html('post')); |
|
119 | + $value = wp_kses( $value, wp_kses_allowed_html( 'post' ) ); |
|
120 | 120 | }); |
121 | - return Arr::convertDotNotationArray($options); |
|
121 | + return Arr::convertDotNotationArray( $options ); |
|
122 | 122 | } |
123 | 123 | |
124 | 124 | /** |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | */ |
127 | 127 | public function isRecaptchaEnabled() |
128 | 128 | { |
129 | - $integration = $this->get('settings.submissions.recaptcha.integration'); |
|
129 | + $integration = $this->get( 'settings.submissions.recaptcha.integration' ); |
|
130 | 130 | return 'all' == $integration || ('guest' == $integration && !is_user_logged_in()); |
131 | 131 | } |
132 | 132 | |
@@ -135,9 +135,9 @@ discard block |
||
135 | 135 | */ |
136 | 136 | public function reset() |
137 | 137 | { |
138 | - $options = $this->getWP(static::databaseKey(), []); |
|
139 | - if (!is_array($options) || empty($options)) { |
|
140 | - delete_option(static::databaseKey()); |
|
138 | + $options = $this->getWP( static::databaseKey(), [] ); |
|
139 | + if( !is_array( $options ) || empty($options) ) { |
|
140 | + delete_option( static::databaseKey() ); |
|
141 | 141 | $options = glsr()->defaults ?: []; |
142 | 142 | } |
143 | 143 | $this->options = $options; |
@@ -148,12 +148,12 @@ discard block |
||
148 | 148 | * @param mixed $value |
149 | 149 | * @return bool |
150 | 150 | */ |
151 | - public function set($pathOrOptions, $value = '') |
|
151 | + public function set( $pathOrOptions, $value = '' ) |
|
152 | 152 | { |
153 | - if (is_string($pathOrOptions)) { |
|
154 | - $pathOrOptions = Arr::set($this->all(), $pathOrOptions, $value); |
|
153 | + if( is_string( $pathOrOptions ) ) { |
|
154 | + $pathOrOptions = Arr::set( $this->all(), $pathOrOptions, $value ); |
|
155 | 155 | } |
156 | - if ($result = update_option(static::databaseKey(), (array) $pathOrOptions)) { |
|
156 | + if( $result = update_option( static::databaseKey(), (array)$pathOrOptions ) ) { |
|
157 | 157 | $this->reset(); |
158 | 158 | } |
159 | 159 | return $result; |
@@ -8,178 +8,178 @@ |
||
8 | 8 | |
9 | 9 | class Helper |
10 | 10 | { |
11 | - /** |
|
12 | - * @param string $name |
|
13 | - * @param string $path |
|
14 | - * @return string |
|
15 | - */ |
|
16 | - public static function buildClassName($name, $path = '') |
|
17 | - { |
|
18 | - $className = Str::camelCase($name); |
|
19 | - $path = ltrim(str_replace(__NAMESPACE__, '', $path), '\\'); |
|
20 | - return !empty($path) |
|
21 | - ? __NAMESPACE__.'\\'.$path.'\\'.$className |
|
22 | - : $className; |
|
23 | - } |
|
24 | - |
|
25 | - /** |
|
26 | - * @param string $name |
|
27 | - * @param string $prefix |
|
28 | - * @return string |
|
29 | - */ |
|
30 | - public static function buildMethodName($name, $prefix = '') |
|
31 | - { |
|
32 | - return lcfirst($prefix.static::buildClassName($name)); |
|
33 | - } |
|
34 | - |
|
35 | - /** |
|
36 | - * @param string $name |
|
37 | - * @return string |
|
38 | - */ |
|
39 | - public static function buildPropertyName($name) |
|
40 | - { |
|
41 | - return static::buildMethodName($name); |
|
42 | - } |
|
43 | - |
|
44 | - /** |
|
45 | - * @param string $cast |
|
46 | - * @param mixed $value |
|
47 | - * @return mixed |
|
48 | - */ |
|
49 | - public static function castTo($cast = '', $value) |
|
50 | - { |
|
51 | - $method = static::buildMethodName($cast, 'castTo'); |
|
52 | - return !empty($cast) && method_exists(__CLASS__, $method) |
|
53 | - ? static::$method($value) |
|
54 | - : $value; |
|
55 | - } |
|
56 | - |
|
57 | - /** |
|
58 | - * @param mixed $value |
|
59 | - * @return array |
|
60 | - */ |
|
61 | - public static function castToArray($value) |
|
62 | - { |
|
63 | - return (array) $value; |
|
64 | - } |
|
65 | - |
|
66 | - /** |
|
67 | - * @param mixed $value |
|
68 | - * @return bool |
|
69 | - */ |
|
70 | - public static function castToBool($value) |
|
71 | - { |
|
72 | - return filter_var($value, FILTER_VALIDATE_BOOLEAN); |
|
73 | - } |
|
74 | - |
|
75 | - /** |
|
76 | - * @param mixed $value |
|
77 | - * @return float |
|
78 | - */ |
|
79 | - public static function castToFloat($value) |
|
80 | - { |
|
81 | - return (float) filter_var($value, FILTER_VALIDATE_FLOAT, FILTER_FLAG_ALLOW_THOUSAND); |
|
82 | - } |
|
83 | - |
|
84 | - /** |
|
85 | - * @param mixed $value |
|
86 | - * @return int |
|
87 | - */ |
|
88 | - public static function castToInt($value) |
|
89 | - { |
|
90 | - return (int) filter_var($value, FILTER_VALIDATE_INT); |
|
91 | - } |
|
92 | - |
|
93 | - /** |
|
94 | - * @param mixed $value |
|
95 | - * @return object |
|
96 | - */ |
|
97 | - public static function castToObject($value) |
|
98 | - { |
|
99 | - return (object) (array) $value; |
|
100 | - } |
|
101 | - |
|
102 | - /** |
|
103 | - * @param mixed $value |
|
104 | - * @return string |
|
105 | - */ |
|
106 | - public static function castToString($value) |
|
107 | - { |
|
108 | - if (is_object($value) && in_array('__toString', get_class_methods($value))) { |
|
109 | - return (string) $value->__toString(); |
|
110 | - } |
|
111 | - if (is_array($value) || is_object($value)) { |
|
112 | - return serialize($value); |
|
113 | - } |
|
114 | - return (string) $value; |
|
115 | - } |
|
116 | - |
|
117 | - /** |
|
118 | - * @param string $key |
|
119 | - * @return mixed |
|
120 | - */ |
|
121 | - public static function filterInput($key, array $request = []) |
|
122 | - { |
|
123 | - if (isset($request[$key])) { |
|
124 | - return $request[$key]; |
|
125 | - } |
|
126 | - $variable = filter_input(INPUT_POST, $key); |
|
127 | - if (is_null($variable) && isset($_POST[$key])) { |
|
128 | - $variable = $_POST[$key]; |
|
129 | - } |
|
130 | - return $variable; |
|
131 | - } |
|
132 | - |
|
133 | - /** |
|
134 | - * @param string $key |
|
135 | - * @return array |
|
136 | - */ |
|
137 | - public static function filterInputArray($key) |
|
138 | - { |
|
139 | - $variable = filter_input(INPUT_POST, $key, FILTER_DEFAULT, FILTER_REQUIRE_ARRAY); |
|
140 | - if (empty($variable) && !empty($_POST[$key]) && is_array($_POST[$key])) { |
|
141 | - $variable = $_POST[$key]; |
|
142 | - } |
|
143 | - return (array) $variable; |
|
144 | - } |
|
145 | - |
|
146 | - /** |
|
147 | - * @return string |
|
148 | - */ |
|
149 | - public static function getIpAddress() |
|
150 | - { |
|
151 | - $whitelist = []; |
|
152 | - $isUsingCloudflare = !empty(filter_input(INPUT_SERVER, 'CF-Connecting-IP')); |
|
153 | - if (apply_filters('site-reviews/whip/whitelist/cloudflare', $isUsingCloudflare)) { |
|
154 | - $cloudflareIps = glsr(Cache::class)->getCloudflareIps(); |
|
155 | - $whitelist[Whip::CLOUDFLARE_HEADERS] = [Whip::IPV4 => $cloudflareIps['v4']]; |
|
156 | - if (defined('AF_INET6')) { |
|
157 | - $whitelist[Whip::CLOUDFLARE_HEADERS][Whip::IPV6] = $cloudflareIps['v6']; |
|
158 | - } |
|
159 | - } |
|
160 | - $whitelist = apply_filters('site-reviews/whip/whitelist', $whitelist); |
|
161 | - $methods = apply_filters('site-reviews/whip/methods', Whip::ALL_METHODS); |
|
162 | - $whip = new Whip($methods, $whitelist); |
|
163 | - do_action_ref_array('site-reviews/whip', [$whip]); |
|
164 | - if (false !== ($clientAddress = $whip->getValidIpAddress())) { |
|
165 | - return (string) $clientAddress; |
|
166 | - } |
|
167 | - glsr_log()->error('Unable to detect IP address.'); |
|
168 | - return 'unknown'; |
|
169 | - } |
|
170 | - |
|
171 | - /** |
|
172 | - * @param mixed $value |
|
173 | - * @param string|int $min |
|
174 | - * @param string|int $max |
|
175 | - * @return bool |
|
176 | - */ |
|
177 | - public static function inRange($value, $min, $max) |
|
178 | - { |
|
179 | - $inRange = filter_var($value, FILTER_VALIDATE_INT, ['options' => [ |
|
180 | - 'min_range' => intval($min), |
|
181 | - 'max_range' => intval($max), |
|
182 | - ]]); |
|
183 | - return false !== $inRange; |
|
184 | - } |
|
11 | + /** |
|
12 | + * @param string $name |
|
13 | + * @param string $path |
|
14 | + * @return string |
|
15 | + */ |
|
16 | + public static function buildClassName($name, $path = '') |
|
17 | + { |
|
18 | + $className = Str::camelCase($name); |
|
19 | + $path = ltrim(str_replace(__NAMESPACE__, '', $path), '\\'); |
|
20 | + return !empty($path) |
|
21 | + ? __NAMESPACE__.'\\'.$path.'\\'.$className |
|
22 | + : $className; |
|
23 | + } |
|
24 | + |
|
25 | + /** |
|
26 | + * @param string $name |
|
27 | + * @param string $prefix |
|
28 | + * @return string |
|
29 | + */ |
|
30 | + public static function buildMethodName($name, $prefix = '') |
|
31 | + { |
|
32 | + return lcfirst($prefix.static::buildClassName($name)); |
|
33 | + } |
|
34 | + |
|
35 | + /** |
|
36 | + * @param string $name |
|
37 | + * @return string |
|
38 | + */ |
|
39 | + public static function buildPropertyName($name) |
|
40 | + { |
|
41 | + return static::buildMethodName($name); |
|
42 | + } |
|
43 | + |
|
44 | + /** |
|
45 | + * @param string $cast |
|
46 | + * @param mixed $value |
|
47 | + * @return mixed |
|
48 | + */ |
|
49 | + public static function castTo($cast = '', $value) |
|
50 | + { |
|
51 | + $method = static::buildMethodName($cast, 'castTo'); |
|
52 | + return !empty($cast) && method_exists(__CLASS__, $method) |
|
53 | + ? static::$method($value) |
|
54 | + : $value; |
|
55 | + } |
|
56 | + |
|
57 | + /** |
|
58 | + * @param mixed $value |
|
59 | + * @return array |
|
60 | + */ |
|
61 | + public static function castToArray($value) |
|
62 | + { |
|
63 | + return (array) $value; |
|
64 | + } |
|
65 | + |
|
66 | + /** |
|
67 | + * @param mixed $value |
|
68 | + * @return bool |
|
69 | + */ |
|
70 | + public static function castToBool($value) |
|
71 | + { |
|
72 | + return filter_var($value, FILTER_VALIDATE_BOOLEAN); |
|
73 | + } |
|
74 | + |
|
75 | + /** |
|
76 | + * @param mixed $value |
|
77 | + * @return float |
|
78 | + */ |
|
79 | + public static function castToFloat($value) |
|
80 | + { |
|
81 | + return (float) filter_var($value, FILTER_VALIDATE_FLOAT, FILTER_FLAG_ALLOW_THOUSAND); |
|
82 | + } |
|
83 | + |
|
84 | + /** |
|
85 | + * @param mixed $value |
|
86 | + * @return int |
|
87 | + */ |
|
88 | + public static function castToInt($value) |
|
89 | + { |
|
90 | + return (int) filter_var($value, FILTER_VALIDATE_INT); |
|
91 | + } |
|
92 | + |
|
93 | + /** |
|
94 | + * @param mixed $value |
|
95 | + * @return object |
|
96 | + */ |
|
97 | + public static function castToObject($value) |
|
98 | + { |
|
99 | + return (object) (array) $value; |
|
100 | + } |
|
101 | + |
|
102 | + /** |
|
103 | + * @param mixed $value |
|
104 | + * @return string |
|
105 | + */ |
|
106 | + public static function castToString($value) |
|
107 | + { |
|
108 | + if (is_object($value) && in_array('__toString', get_class_methods($value))) { |
|
109 | + return (string) $value->__toString(); |
|
110 | + } |
|
111 | + if (is_array($value) || is_object($value)) { |
|
112 | + return serialize($value); |
|
113 | + } |
|
114 | + return (string) $value; |
|
115 | + } |
|
116 | + |
|
117 | + /** |
|
118 | + * @param string $key |
|
119 | + * @return mixed |
|
120 | + */ |
|
121 | + public static function filterInput($key, array $request = []) |
|
122 | + { |
|
123 | + if (isset($request[$key])) { |
|
124 | + return $request[$key]; |
|
125 | + } |
|
126 | + $variable = filter_input(INPUT_POST, $key); |
|
127 | + if (is_null($variable) && isset($_POST[$key])) { |
|
128 | + $variable = $_POST[$key]; |
|
129 | + } |
|
130 | + return $variable; |
|
131 | + } |
|
132 | + |
|
133 | + /** |
|
134 | + * @param string $key |
|
135 | + * @return array |
|
136 | + */ |
|
137 | + public static function filterInputArray($key) |
|
138 | + { |
|
139 | + $variable = filter_input(INPUT_POST, $key, FILTER_DEFAULT, FILTER_REQUIRE_ARRAY); |
|
140 | + if (empty($variable) && !empty($_POST[$key]) && is_array($_POST[$key])) { |
|
141 | + $variable = $_POST[$key]; |
|
142 | + } |
|
143 | + return (array) $variable; |
|
144 | + } |
|
145 | + |
|
146 | + /** |
|
147 | + * @return string |
|
148 | + */ |
|
149 | + public static function getIpAddress() |
|
150 | + { |
|
151 | + $whitelist = []; |
|
152 | + $isUsingCloudflare = !empty(filter_input(INPUT_SERVER, 'CF-Connecting-IP')); |
|
153 | + if (apply_filters('site-reviews/whip/whitelist/cloudflare', $isUsingCloudflare)) { |
|
154 | + $cloudflareIps = glsr(Cache::class)->getCloudflareIps(); |
|
155 | + $whitelist[Whip::CLOUDFLARE_HEADERS] = [Whip::IPV4 => $cloudflareIps['v4']]; |
|
156 | + if (defined('AF_INET6')) { |
|
157 | + $whitelist[Whip::CLOUDFLARE_HEADERS][Whip::IPV6] = $cloudflareIps['v6']; |
|
158 | + } |
|
159 | + } |
|
160 | + $whitelist = apply_filters('site-reviews/whip/whitelist', $whitelist); |
|
161 | + $methods = apply_filters('site-reviews/whip/methods', Whip::ALL_METHODS); |
|
162 | + $whip = new Whip($methods, $whitelist); |
|
163 | + do_action_ref_array('site-reviews/whip', [$whip]); |
|
164 | + if (false !== ($clientAddress = $whip->getValidIpAddress())) { |
|
165 | + return (string) $clientAddress; |
|
166 | + } |
|
167 | + glsr_log()->error('Unable to detect IP address.'); |
|
168 | + return 'unknown'; |
|
169 | + } |
|
170 | + |
|
171 | + /** |
|
172 | + * @param mixed $value |
|
173 | + * @param string|int $min |
|
174 | + * @param string|int $max |
|
175 | + * @return bool |
|
176 | + */ |
|
177 | + public static function inRange($value, $min, $max) |
|
178 | + { |
|
179 | + $inRange = filter_var($value, FILTER_VALIDATE_INT, ['options' => [ |
|
180 | + 'min_range' => intval($min), |
|
181 | + 'max_range' => intval($max), |
|
182 | + ]]); |
|
183 | + return false !== $inRange; |
|
184 | + } |
|
185 | 185 | } |
@@ -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 | } |
@@ -13,299 +13,299 @@ |
||
13 | 13 | |
14 | 14 | class ValidateReview |
15 | 15 | { |
16 | - const RECAPTCHA_ENDPOINT = 'https://www.google.com/recaptcha/api/siteverify'; |
|
16 | + const RECAPTCHA_ENDPOINT = 'https://www.google.com/recaptcha/api/siteverify'; |
|
17 | 17 | |
18 | - const RECAPTCHA_DISABLED = 0; |
|
19 | - const RECAPTCHA_EMPTY = 1; |
|
20 | - const RECAPTCHA_FAILED = 2; |
|
21 | - const RECAPTCHA_INVALID = 3; |
|
22 | - const RECAPTCHA_VALID = 4; |
|
18 | + const RECAPTCHA_DISABLED = 0; |
|
19 | + const RECAPTCHA_EMPTY = 1; |
|
20 | + const RECAPTCHA_FAILED = 2; |
|
21 | + const RECAPTCHA_INVALID = 3; |
|
22 | + const RECAPTCHA_VALID = 4; |
|
23 | 23 | |
24 | - const VALIDATION_RULES = [ |
|
25 | - 'content' => 'required', |
|
26 | - 'email' => 'required|email', |
|
27 | - 'name' => 'required', |
|
28 | - 'rating' => 'required|number|between:1,5', |
|
29 | - 'terms' => 'accepted', |
|
30 | - 'title' => 'required', |
|
31 | - ]; |
|
24 | + const VALIDATION_RULES = [ |
|
25 | + 'content' => 'required', |
|
26 | + 'email' => 'required|email', |
|
27 | + 'name' => 'required', |
|
28 | + 'rating' => 'required|number|between:1,5', |
|
29 | + 'terms' => 'accepted', |
|
30 | + 'title' => 'required', |
|
31 | + ]; |
|
32 | 32 | |
33 | - /** |
|
34 | - * @var string|void |
|
35 | - */ |
|
36 | - public $error; |
|
33 | + /** |
|
34 | + * @var string|void |
|
35 | + */ |
|
36 | + public $error; |
|
37 | 37 | |
38 | - /** |
|
39 | - * @var string |
|
40 | - */ |
|
41 | - public $form_id; |
|
38 | + /** |
|
39 | + * @var string |
|
40 | + */ |
|
41 | + public $form_id; |
|
42 | 42 | |
43 | - /** |
|
44 | - * @var bool |
|
45 | - */ |
|
46 | - public $recaptchaIsUnset = false; |
|
43 | + /** |
|
44 | + * @var bool |
|
45 | + */ |
|
46 | + public $recaptchaIsUnset = false; |
|
47 | 47 | |
48 | - /** |
|
49 | - * @var array |
|
50 | - */ |
|
51 | - public $request; |
|
48 | + /** |
|
49 | + * @var array |
|
50 | + */ |
|
51 | + public $request; |
|
52 | 52 | |
53 | - /** |
|
54 | - * @var array |
|
55 | - */ |
|
56 | - protected $options; |
|
53 | + /** |
|
54 | + * @var array |
|
55 | + */ |
|
56 | + protected $options; |
|
57 | 57 | |
58 | - /** |
|
59 | - * @return static |
|
60 | - */ |
|
61 | - public function validate(array $request) |
|
62 | - { |
|
63 | - $request['ip_address'] = Helper::getIpAddress(); // required for Akismet and Blacklist validation |
|
64 | - $this->form_id = $request['form_id']; |
|
65 | - $this->options = glsr(OptionManager::class)->all(); |
|
66 | - $this->request = $this->validateRequest($request); |
|
67 | - $this->validateCustom(); |
|
68 | - $this->validatePermission(); |
|
69 | - $this->validateHoneyPot(); |
|
70 | - $this->validateReviewLimits(); |
|
71 | - $this->validateBlacklist(); |
|
72 | - $this->validateAkismet(); |
|
73 | - $this->validateRecaptcha(); |
|
74 | - if (!empty($this->error)) { |
|
75 | - $this->setSessionValues('message', $this->error); |
|
76 | - } |
|
77 | - return $this; |
|
78 | - } |
|
58 | + /** |
|
59 | + * @return static |
|
60 | + */ |
|
61 | + public function validate(array $request) |
|
62 | + { |
|
63 | + $request['ip_address'] = Helper::getIpAddress(); // required for Akismet and Blacklist validation |
|
64 | + $this->form_id = $request['form_id']; |
|
65 | + $this->options = glsr(OptionManager::class)->all(); |
|
66 | + $this->request = $this->validateRequest($request); |
|
67 | + $this->validateCustom(); |
|
68 | + $this->validatePermission(); |
|
69 | + $this->validateHoneyPot(); |
|
70 | + $this->validateReviewLimits(); |
|
71 | + $this->validateBlacklist(); |
|
72 | + $this->validateAkismet(); |
|
73 | + $this->validateRecaptcha(); |
|
74 | + if (!empty($this->error)) { |
|
75 | + $this->setSessionValues('message', $this->error); |
|
76 | + } |
|
77 | + return $this; |
|
78 | + } |
|
79 | 79 | |
80 | - /** |
|
81 | - * @param string $path |
|
82 | - * @param mixed $fallback |
|
83 | - * @return mixed |
|
84 | - */ |
|
85 | - protected function getOption($path, $fallback = '') |
|
86 | - { |
|
87 | - return Arr::get($this->options, $path, $fallback); |
|
88 | - } |
|
80 | + /** |
|
81 | + * @param string $path |
|
82 | + * @param mixed $fallback |
|
83 | + * @return mixed |
|
84 | + */ |
|
85 | + protected function getOption($path, $fallback = '') |
|
86 | + { |
|
87 | + return Arr::get($this->options, $path, $fallback); |
|
88 | + } |
|
89 | 89 | |
90 | - /** |
|
91 | - * @return int |
|
92 | - */ |
|
93 | - protected function getRecaptchaStatus() |
|
94 | - { |
|
95 | - if (!glsr(OptionManager::class)->isRecaptchaEnabled()) { |
|
96 | - return static::RECAPTCHA_DISABLED; |
|
97 | - } |
|
98 | - if (empty($this->request['_recaptcha-token'])) { |
|
99 | - return $this->request['_counter'] < intval(apply_filters('site-reviews/recaptcha/timeout', 5)) |
|
100 | - ? static::RECAPTCHA_EMPTY |
|
101 | - : static::RECAPTCHA_FAILED; |
|
102 | - } |
|
103 | - return $this->getRecaptchaTokenStatus(); |
|
104 | - } |
|
90 | + /** |
|
91 | + * @return int |
|
92 | + */ |
|
93 | + protected function getRecaptchaStatus() |
|
94 | + { |
|
95 | + if (!glsr(OptionManager::class)->isRecaptchaEnabled()) { |
|
96 | + return static::RECAPTCHA_DISABLED; |
|
97 | + } |
|
98 | + if (empty($this->request['_recaptcha-token'])) { |
|
99 | + return $this->request['_counter'] < intval(apply_filters('site-reviews/recaptcha/timeout', 5)) |
|
100 | + ? static::RECAPTCHA_EMPTY |
|
101 | + : static::RECAPTCHA_FAILED; |
|
102 | + } |
|
103 | + return $this->getRecaptchaTokenStatus(); |
|
104 | + } |
|
105 | 105 | |
106 | - /** |
|
107 | - * @return int |
|
108 | - */ |
|
109 | - protected function getRecaptchaTokenStatus() |
|
110 | - { |
|
111 | - $endpoint = add_query_arg([ |
|
112 | - 'remoteip' => Helper::getIpAddress(), |
|
113 | - 'response' => $this->request['_recaptcha-token'], |
|
114 | - 'secret' => $this->getOption('settings.submissions.recaptcha.secret'), |
|
115 | - ], static::RECAPTCHA_ENDPOINT); |
|
116 | - if (is_wp_error($response = wp_remote_get($endpoint))) { |
|
117 | - glsr_log()->error($response->get_error_message()); |
|
118 | - return static::RECAPTCHA_FAILED; |
|
119 | - } |
|
120 | - $response = json_decode(wp_remote_retrieve_body($response)); |
|
121 | - if (!empty($response->success)) { |
|
122 | - return boolval($response->success) |
|
123 | - ? static::RECAPTCHA_VALID |
|
124 | - : static::RECAPTCHA_INVALID; |
|
125 | - } |
|
126 | - foreach ($response->{'error-codes'} as $error) { |
|
127 | - glsr_log()->error('reCAPTCHA error: '.$error); |
|
128 | - } |
|
129 | - return static::RECAPTCHA_INVALID; |
|
130 | - } |
|
106 | + /** |
|
107 | + * @return int |
|
108 | + */ |
|
109 | + protected function getRecaptchaTokenStatus() |
|
110 | + { |
|
111 | + $endpoint = add_query_arg([ |
|
112 | + 'remoteip' => Helper::getIpAddress(), |
|
113 | + 'response' => $this->request['_recaptcha-token'], |
|
114 | + 'secret' => $this->getOption('settings.submissions.recaptcha.secret'), |
|
115 | + ], static::RECAPTCHA_ENDPOINT); |
|
116 | + if (is_wp_error($response = wp_remote_get($endpoint))) { |
|
117 | + glsr_log()->error($response->get_error_message()); |
|
118 | + return static::RECAPTCHA_FAILED; |
|
119 | + } |
|
120 | + $response = json_decode(wp_remote_retrieve_body($response)); |
|
121 | + if (!empty($response->success)) { |
|
122 | + return boolval($response->success) |
|
123 | + ? static::RECAPTCHA_VALID |
|
124 | + : static::RECAPTCHA_INVALID; |
|
125 | + } |
|
126 | + foreach ($response->{'error-codes'} as $error) { |
|
127 | + glsr_log()->error('reCAPTCHA error: '.$error); |
|
128 | + } |
|
129 | + return static::RECAPTCHA_INVALID; |
|
130 | + } |
|
131 | 131 | |
132 | - /** |
|
133 | - * @return array |
|
134 | - */ |
|
135 | - protected function getValidationRules(array $request) |
|
136 | - { |
|
137 | - $rules = array_intersect_key( |
|
138 | - apply_filters('site-reviews/validation/rules', static::VALIDATION_RULES, $request), |
|
139 | - array_flip($this->getOption('settings.submissions.required', [])) |
|
140 | - ); |
|
141 | - $excluded = explode(',', Arr::get($request, 'excluded')); |
|
142 | - return array_diff_key($rules, array_flip($excluded)); |
|
143 | - } |
|
132 | + /** |
|
133 | + * @return array |
|
134 | + */ |
|
135 | + protected function getValidationRules(array $request) |
|
136 | + { |
|
137 | + $rules = array_intersect_key( |
|
138 | + apply_filters('site-reviews/validation/rules', static::VALIDATION_RULES, $request), |
|
139 | + array_flip($this->getOption('settings.submissions.required', [])) |
|
140 | + ); |
|
141 | + $excluded = explode(',', Arr::get($request, 'excluded')); |
|
142 | + return array_diff_key($rules, array_flip($excluded)); |
|
143 | + } |
|
144 | 144 | |
145 | - /** |
|
146 | - * @return bool |
|
147 | - */ |
|
148 | - protected function isRequestValid(array $request) |
|
149 | - { |
|
150 | - $rules = $this->getValidationRules($request); |
|
151 | - $errors = glsr(Validator::class)->validate($request, $rules); |
|
152 | - if (empty($errors)) { |
|
153 | - return true; |
|
154 | - } |
|
155 | - $this->error = __('Please fix the submission errors.', 'site-reviews'); |
|
156 | - $this->setSessionValues('errors', $errors); |
|
157 | - $this->setSessionValues('values', $request); |
|
158 | - return false; |
|
159 | - } |
|
145 | + /** |
|
146 | + * @return bool |
|
147 | + */ |
|
148 | + protected function isRequestValid(array $request) |
|
149 | + { |
|
150 | + $rules = $this->getValidationRules($request); |
|
151 | + $errors = glsr(Validator::class)->validate($request, $rules); |
|
152 | + if (empty($errors)) { |
|
153 | + return true; |
|
154 | + } |
|
155 | + $this->error = __('Please fix the submission errors.', 'site-reviews'); |
|
156 | + $this->setSessionValues('errors', $errors); |
|
157 | + $this->setSessionValues('values', $request); |
|
158 | + return false; |
|
159 | + } |
|
160 | 160 | |
161 | - protected function setError($message, $loggedMessage = '') |
|
162 | - { |
|
163 | - $this->setSessionValues('errors', [], $loggedMessage); |
|
164 | - $this->error = $message; |
|
165 | - } |
|
161 | + protected function setError($message, $loggedMessage = '') |
|
162 | + { |
|
163 | + $this->setSessionValues('errors', [], $loggedMessage); |
|
164 | + $this->error = $message; |
|
165 | + } |
|
166 | 166 | |
167 | - /** |
|
168 | - * @param string $type |
|
169 | - * @param mixed $value |
|
170 | - * @param string $loggedMessage |
|
171 | - * @return void |
|
172 | - */ |
|
173 | - protected function setSessionValues($type, $value, $loggedMessage = '') |
|
174 | - { |
|
175 | - glsr()->sessionSet($this->form_id.$type, $value); |
|
176 | - if (!empty($loggedMessage)) { |
|
177 | - glsr_log()->warning($loggedMessage)->debug($this->request); |
|
178 | - } |
|
179 | - } |
|
167 | + /** |
|
168 | + * @param string $type |
|
169 | + * @param mixed $value |
|
170 | + * @param string $loggedMessage |
|
171 | + * @return void |
|
172 | + */ |
|
173 | + protected function setSessionValues($type, $value, $loggedMessage = '') |
|
174 | + { |
|
175 | + glsr()->sessionSet($this->form_id.$type, $value); |
|
176 | + if (!empty($loggedMessage)) { |
|
177 | + glsr_log()->warning($loggedMessage)->debug($this->request); |
|
178 | + } |
|
179 | + } |
|
180 | 180 | |
181 | - /** |
|
182 | - * @return void |
|
183 | - */ |
|
184 | - protected function validateAkismet() |
|
185 | - { |
|
186 | - if (!empty($this->error)) { |
|
187 | - return; |
|
188 | - } |
|
189 | - if (glsr(Akismet::class)->isSpam($this->request)) { |
|
190 | - $this->setError(__('This review has been flagged as possible spam and cannot be submitted.', 'site-reviews'), |
|
191 | - 'Akismet caught a spam submission (consider adding the IP address to the blacklist):' |
|
192 | - ); |
|
193 | - } |
|
194 | - } |
|
181 | + /** |
|
182 | + * @return void |
|
183 | + */ |
|
184 | + protected function validateAkismet() |
|
185 | + { |
|
186 | + if (!empty($this->error)) { |
|
187 | + return; |
|
188 | + } |
|
189 | + if (glsr(Akismet::class)->isSpam($this->request)) { |
|
190 | + $this->setError(__('This review has been flagged as possible spam and cannot be submitted.', 'site-reviews'), |
|
191 | + 'Akismet caught a spam submission (consider adding the IP address to the blacklist):' |
|
192 | + ); |
|
193 | + } |
|
194 | + } |
|
195 | 195 | |
196 | - /** |
|
197 | - * @return void |
|
198 | - */ |
|
199 | - protected function validateBlacklist() |
|
200 | - { |
|
201 | - if (!empty($this->error)) { |
|
202 | - return; |
|
203 | - } |
|
204 | - if (!glsr(Blacklist::class)->isBlacklisted($this->request)) { |
|
205 | - return; |
|
206 | - } |
|
207 | - $blacklistAction = $this->getOption('settings.submissions.blacklist.action'); |
|
208 | - if ('reject' != $blacklistAction) { |
|
209 | - $this->request['blacklisted'] = true; |
|
210 | - return; |
|
211 | - } |
|
212 | - $this->setError(__('Your review cannot be submitted at this time.', 'site-reviews'), |
|
213 | - 'Blacklisted submission detected:' |
|
214 | - ); |
|
215 | - } |
|
196 | + /** |
|
197 | + * @return void |
|
198 | + */ |
|
199 | + protected function validateBlacklist() |
|
200 | + { |
|
201 | + if (!empty($this->error)) { |
|
202 | + return; |
|
203 | + } |
|
204 | + if (!glsr(Blacklist::class)->isBlacklisted($this->request)) { |
|
205 | + return; |
|
206 | + } |
|
207 | + $blacklistAction = $this->getOption('settings.submissions.blacklist.action'); |
|
208 | + if ('reject' != $blacklistAction) { |
|
209 | + $this->request['blacklisted'] = true; |
|
210 | + return; |
|
211 | + } |
|
212 | + $this->setError(__('Your review cannot be submitted at this time.', 'site-reviews'), |
|
213 | + 'Blacklisted submission detected:' |
|
214 | + ); |
|
215 | + } |
|
216 | 216 | |
217 | - /** |
|
218 | - * @return void |
|
219 | - */ |
|
220 | - protected function validateCustom() |
|
221 | - { |
|
222 | - if (!empty($this->error)) { |
|
223 | - return; |
|
224 | - } |
|
225 | - $validated = apply_filters('site-reviews/validate/custom', true, $this->request); |
|
226 | - if (true === $validated) { |
|
227 | - return; |
|
228 | - } |
|
229 | - $errorMessage = is_string($validated) |
|
230 | - ? $validated |
|
231 | - : __('The review submission failed. Please notify the site administrator.', 'site-reviews'); |
|
232 | - $this->setError($errorMessage); |
|
233 | - $this->setSessionValues('values', $this->request); |
|
234 | - } |
|
217 | + /** |
|
218 | + * @return void |
|
219 | + */ |
|
220 | + protected function validateCustom() |
|
221 | + { |
|
222 | + if (!empty($this->error)) { |
|
223 | + return; |
|
224 | + } |
|
225 | + $validated = apply_filters('site-reviews/validate/custom', true, $this->request); |
|
226 | + if (true === $validated) { |
|
227 | + return; |
|
228 | + } |
|
229 | + $errorMessage = is_string($validated) |
|
230 | + ? $validated |
|
231 | + : __('The review submission failed. Please notify the site administrator.', 'site-reviews'); |
|
232 | + $this->setError($errorMessage); |
|
233 | + $this->setSessionValues('values', $this->request); |
|
234 | + } |
|
235 | 235 | |
236 | - /** |
|
237 | - * @return void |
|
238 | - */ |
|
239 | - protected function validateHoneyPot() |
|
240 | - { |
|
241 | - if (!empty($this->error)) { |
|
242 | - return; |
|
243 | - } |
|
244 | - if (!empty($this->request['gotcha'])) { |
|
245 | - $this->setError(__('The review submission failed. Please notify the site administrator.', 'site-reviews'), |
|
246 | - 'The Honeypot caught a bad submission:' |
|
247 | - ); |
|
248 | - } |
|
249 | - } |
|
236 | + /** |
|
237 | + * @return void |
|
238 | + */ |
|
239 | + protected function validateHoneyPot() |
|
240 | + { |
|
241 | + if (!empty($this->error)) { |
|
242 | + return; |
|
243 | + } |
|
244 | + if (!empty($this->request['gotcha'])) { |
|
245 | + $this->setError(__('The review submission failed. Please notify the site administrator.', 'site-reviews'), |
|
246 | + 'The Honeypot caught a bad submission:' |
|
247 | + ); |
|
248 | + } |
|
249 | + } |
|
250 | 250 | |
251 | - /** |
|
252 | - * @return void |
|
253 | - */ |
|
254 | - protected function validatePermission() |
|
255 | - { |
|
256 | - if (!empty($this->error)) { |
|
257 | - return; |
|
258 | - } |
|
259 | - if (!is_user_logged_in() && glsr(OptionManager::class)->getBool('settings.general.require.login')) { |
|
260 | - $this->setError(__('You must be logged in to submit a review.', 'site-reviews')); |
|
261 | - } |
|
262 | - } |
|
251 | + /** |
|
252 | + * @return void |
|
253 | + */ |
|
254 | + protected function validatePermission() |
|
255 | + { |
|
256 | + if (!empty($this->error)) { |
|
257 | + return; |
|
258 | + } |
|
259 | + if (!is_user_logged_in() && glsr(OptionManager::class)->getBool('settings.general.require.login')) { |
|
260 | + $this->setError(__('You must be logged in to submit a review.', 'site-reviews')); |
|
261 | + } |
|
262 | + } |
|
263 | 263 | |
264 | - /** |
|
265 | - * @return void |
|
266 | - */ |
|
267 | - protected function validateReviewLimits() |
|
268 | - { |
|
269 | - if (!empty($this->error)) { |
|
270 | - return; |
|
271 | - } |
|
272 | - if (glsr(ReviewLimits::class)->hasReachedLimit($this->request)) { |
|
273 | - $this->setError(__('You have already submitted a review.', 'site-reviews')); |
|
274 | - } |
|
275 | - } |
|
264 | + /** |
|
265 | + * @return void |
|
266 | + */ |
|
267 | + protected function validateReviewLimits() |
|
268 | + { |
|
269 | + if (!empty($this->error)) { |
|
270 | + return; |
|
271 | + } |
|
272 | + if (glsr(ReviewLimits::class)->hasReachedLimit($this->request)) { |
|
273 | + $this->setError(__('You have already submitted a review.', 'site-reviews')); |
|
274 | + } |
|
275 | + } |
|
276 | 276 | |
277 | - /** |
|
278 | - * @return void |
|
279 | - */ |
|
280 | - protected function validateRecaptcha() |
|
281 | - { |
|
282 | - if (!empty($this->error)) { |
|
283 | - return; |
|
284 | - } |
|
285 | - $status = $this->getRecaptchaStatus(); |
|
286 | - if (in_array($status, [static::RECAPTCHA_DISABLED, static::RECAPTCHA_VALID])) { |
|
287 | - return; |
|
288 | - } |
|
289 | - if (static::RECAPTCHA_EMPTY === $status) { |
|
290 | - $this->setSessionValues('recaptcha', 'unset'); |
|
291 | - $this->recaptchaIsUnset = true; |
|
292 | - return; |
|
293 | - } |
|
294 | - $this->setSessionValues('recaptcha', 'reset'); |
|
295 | - $errors = [ |
|
296 | - static::RECAPTCHA_FAILED => __('The reCAPTCHA failed to load, please refresh the page and try again.', 'site-reviews'), |
|
297 | - static::RECAPTCHA_INVALID => __('The reCAPTCHA verification failed, please try again.', 'site-reviews'), |
|
298 | - ]; |
|
299 | - $this->setError($errors[$status]); |
|
300 | - } |
|
277 | + /** |
|
278 | + * @return void |
|
279 | + */ |
|
280 | + protected function validateRecaptcha() |
|
281 | + { |
|
282 | + if (!empty($this->error)) { |
|
283 | + return; |
|
284 | + } |
|
285 | + $status = $this->getRecaptchaStatus(); |
|
286 | + if (in_array($status, [static::RECAPTCHA_DISABLED, static::RECAPTCHA_VALID])) { |
|
287 | + return; |
|
288 | + } |
|
289 | + if (static::RECAPTCHA_EMPTY === $status) { |
|
290 | + $this->setSessionValues('recaptcha', 'unset'); |
|
291 | + $this->recaptchaIsUnset = true; |
|
292 | + return; |
|
293 | + } |
|
294 | + $this->setSessionValues('recaptcha', 'reset'); |
|
295 | + $errors = [ |
|
296 | + static::RECAPTCHA_FAILED => __('The reCAPTCHA failed to load, please refresh the page and try again.', 'site-reviews'), |
|
297 | + static::RECAPTCHA_INVALID => __('The reCAPTCHA verification failed, please try again.', 'site-reviews'), |
|
298 | + ]; |
|
299 | + $this->setError($errors[$status]); |
|
300 | + } |
|
301 | 301 | |
302 | - /** |
|
303 | - * @return array |
|
304 | - */ |
|
305 | - protected function validateRequest(array $request) |
|
306 | - { |
|
307 | - return $this->isRequestValid($request) |
|
308 | - ? array_merge(glsr(ValidateReviewDefaults::class)->defaults(), $request) |
|
309 | - : $request; |
|
310 | - } |
|
302 | + /** |
|
303 | + * @return array |
|
304 | + */ |
|
305 | + protected function validateRequest(array $request) |
|
306 | + { |
|
307 | + return $this->isRequestValid($request) |
|
308 | + ? array_merge(glsr(ValidateReviewDefaults::class)->defaults(), $request) |
|
309 | + : $request; |
|
310 | + } |
|
311 | 311 | } |
@@ -58,12 +58,12 @@ discard block |
||
58 | 58 | /** |
59 | 59 | * @return static |
60 | 60 | */ |
61 | - public function validate(array $request) |
|
61 | + public function validate( array $request ) |
|
62 | 62 | { |
63 | 63 | $request['ip_address'] = Helper::getIpAddress(); // required for Akismet and Blacklist validation |
64 | 64 | $this->form_id = $request['form_id']; |
65 | - $this->options = glsr(OptionManager::class)->all(); |
|
66 | - $this->request = $this->validateRequest($request); |
|
65 | + $this->options = glsr( OptionManager::class )->all(); |
|
66 | + $this->request = $this->validateRequest( $request ); |
|
67 | 67 | $this->validateCustom(); |
68 | 68 | $this->validatePermission(); |
69 | 69 | $this->validateHoneyPot(); |
@@ -71,8 +71,8 @@ discard block |
||
71 | 71 | $this->validateBlacklist(); |
72 | 72 | $this->validateAkismet(); |
73 | 73 | $this->validateRecaptcha(); |
74 | - if (!empty($this->error)) { |
|
75 | - $this->setSessionValues('message', $this->error); |
|
74 | + if( !empty($this->error) ) { |
|
75 | + $this->setSessionValues( 'message', $this->error ); |
|
76 | 76 | } |
77 | 77 | return $this; |
78 | 78 | } |
@@ -82,9 +82,9 @@ discard block |
||
82 | 82 | * @param mixed $fallback |
83 | 83 | * @return mixed |
84 | 84 | */ |
85 | - protected function getOption($path, $fallback = '') |
|
85 | + protected function getOption( $path, $fallback = '' ) |
|
86 | 86 | { |
87 | - return Arr::get($this->options, $path, $fallback); |
|
87 | + return Arr::get( $this->options, $path, $fallback ); |
|
88 | 88 | } |
89 | 89 | |
90 | 90 | /** |
@@ -92,11 +92,11 @@ discard block |
||
92 | 92 | */ |
93 | 93 | protected function getRecaptchaStatus() |
94 | 94 | { |
95 | - if (!glsr(OptionManager::class)->isRecaptchaEnabled()) { |
|
95 | + if( !glsr( OptionManager::class )->isRecaptchaEnabled() ) { |
|
96 | 96 | return static::RECAPTCHA_DISABLED; |
97 | 97 | } |
98 | - if (empty($this->request['_recaptcha-token'])) { |
|
99 | - return $this->request['_counter'] < intval(apply_filters('site-reviews/recaptcha/timeout', 5)) |
|
98 | + if( empty($this->request['_recaptcha-token']) ) { |
|
99 | + return $this->request['_counter'] < intval( apply_filters( 'site-reviews/recaptcha/timeout', 5 ) ) |
|
100 | 100 | ? static::RECAPTCHA_EMPTY |
101 | 101 | : static::RECAPTCHA_FAILED; |
102 | 102 | } |
@@ -108,23 +108,23 @@ discard block |
||
108 | 108 | */ |
109 | 109 | protected function getRecaptchaTokenStatus() |
110 | 110 | { |
111 | - $endpoint = add_query_arg([ |
|
111 | + $endpoint = add_query_arg( [ |
|
112 | 112 | 'remoteip' => Helper::getIpAddress(), |
113 | 113 | 'response' => $this->request['_recaptcha-token'], |
114 | - 'secret' => $this->getOption('settings.submissions.recaptcha.secret'), |
|
115 | - ], static::RECAPTCHA_ENDPOINT); |
|
116 | - if (is_wp_error($response = wp_remote_get($endpoint))) { |
|
117 | - glsr_log()->error($response->get_error_message()); |
|
114 | + 'secret' => $this->getOption( 'settings.submissions.recaptcha.secret' ), |
|
115 | + ], static::RECAPTCHA_ENDPOINT ); |
|
116 | + if( is_wp_error( $response = wp_remote_get( $endpoint ) ) ) { |
|
117 | + glsr_log()->error( $response->get_error_message() ); |
|
118 | 118 | return static::RECAPTCHA_FAILED; |
119 | 119 | } |
120 | - $response = json_decode(wp_remote_retrieve_body($response)); |
|
121 | - if (!empty($response->success)) { |
|
122 | - return boolval($response->success) |
|
120 | + $response = json_decode( wp_remote_retrieve_body( $response ) ); |
|
121 | + if( !empty($response->success) ) { |
|
122 | + return boolval( $response->success ) |
|
123 | 123 | ? static::RECAPTCHA_VALID |
124 | 124 | : static::RECAPTCHA_INVALID; |
125 | 125 | } |
126 | - foreach ($response->{'error-codes'} as $error) { |
|
127 | - glsr_log()->error('reCAPTCHA error: '.$error); |
|
126 | + foreach( $response->{'error-codes'} as $error ) { |
|
127 | + glsr_log()->error( 'reCAPTCHA error: '.$error ); |
|
128 | 128 | } |
129 | 129 | return static::RECAPTCHA_INVALID; |
130 | 130 | } |
@@ -132,35 +132,35 @@ discard block |
||
132 | 132 | /** |
133 | 133 | * @return array |
134 | 134 | */ |
135 | - protected function getValidationRules(array $request) |
|
135 | + protected function getValidationRules( array $request ) |
|
136 | 136 | { |
137 | 137 | $rules = array_intersect_key( |
138 | - apply_filters('site-reviews/validation/rules', static::VALIDATION_RULES, $request), |
|
139 | - array_flip($this->getOption('settings.submissions.required', [])) |
|
138 | + apply_filters( 'site-reviews/validation/rules', static::VALIDATION_RULES, $request ), |
|
139 | + array_flip( $this->getOption( 'settings.submissions.required', [] ) ) |
|
140 | 140 | ); |
141 | - $excluded = explode(',', Arr::get($request, 'excluded')); |
|
142 | - return array_diff_key($rules, array_flip($excluded)); |
|
141 | + $excluded = explode( ',', Arr::get( $request, 'excluded' ) ); |
|
142 | + return array_diff_key( $rules, array_flip( $excluded ) ); |
|
143 | 143 | } |
144 | 144 | |
145 | 145 | /** |
146 | 146 | * @return bool |
147 | 147 | */ |
148 | - protected function isRequestValid(array $request) |
|
148 | + protected function isRequestValid( array $request ) |
|
149 | 149 | { |
150 | - $rules = $this->getValidationRules($request); |
|
151 | - $errors = glsr(Validator::class)->validate($request, $rules); |
|
152 | - if (empty($errors)) { |
|
150 | + $rules = $this->getValidationRules( $request ); |
|
151 | + $errors = glsr( Validator::class )->validate( $request, $rules ); |
|
152 | + if( empty($errors) ) { |
|
153 | 153 | return true; |
154 | 154 | } |
155 | - $this->error = __('Please fix the submission errors.', 'site-reviews'); |
|
156 | - $this->setSessionValues('errors', $errors); |
|
157 | - $this->setSessionValues('values', $request); |
|
155 | + $this->error = __( 'Please fix the submission errors.', 'site-reviews' ); |
|
156 | + $this->setSessionValues( 'errors', $errors ); |
|
157 | + $this->setSessionValues( 'values', $request ); |
|
158 | 158 | return false; |
159 | 159 | } |
160 | 160 | |
161 | - protected function setError($message, $loggedMessage = '') |
|
161 | + protected function setError( $message, $loggedMessage = '' ) |
|
162 | 162 | { |
163 | - $this->setSessionValues('errors', [], $loggedMessage); |
|
163 | + $this->setSessionValues( 'errors', [], $loggedMessage ); |
|
164 | 164 | $this->error = $message; |
165 | 165 | } |
166 | 166 | |
@@ -170,11 +170,11 @@ discard block |
||
170 | 170 | * @param string $loggedMessage |
171 | 171 | * @return void |
172 | 172 | */ |
173 | - protected function setSessionValues($type, $value, $loggedMessage = '') |
|
173 | + protected function setSessionValues( $type, $value, $loggedMessage = '' ) |
|
174 | 174 | { |
175 | - glsr()->sessionSet($this->form_id.$type, $value); |
|
176 | - if (!empty($loggedMessage)) { |
|
177 | - glsr_log()->warning($loggedMessage)->debug($this->request); |
|
175 | + glsr()->sessionSet( $this->form_id.$type, $value ); |
|
176 | + if( !empty($loggedMessage) ) { |
|
177 | + glsr_log()->warning( $loggedMessage )->debug( $this->request ); |
|
178 | 178 | } |
179 | 179 | } |
180 | 180 | |
@@ -183,11 +183,11 @@ discard block |
||
183 | 183 | */ |
184 | 184 | protected function validateAkismet() |
185 | 185 | { |
186 | - if (!empty($this->error)) { |
|
186 | + if( !empty($this->error) ) { |
|
187 | 187 | return; |
188 | 188 | } |
189 | - if (glsr(Akismet::class)->isSpam($this->request)) { |
|
190 | - $this->setError(__('This review has been flagged as possible spam and cannot be submitted.', 'site-reviews'), |
|
189 | + if( glsr( Akismet::class )->isSpam( $this->request ) ) { |
|
190 | + $this->setError( __( 'This review has been flagged as possible spam and cannot be submitted.', 'site-reviews' ), |
|
191 | 191 | 'Akismet caught a spam submission (consider adding the IP address to the blacklist):' |
192 | 192 | ); |
193 | 193 | } |
@@ -198,18 +198,18 @@ discard block |
||
198 | 198 | */ |
199 | 199 | protected function validateBlacklist() |
200 | 200 | { |
201 | - if (!empty($this->error)) { |
|
201 | + if( !empty($this->error) ) { |
|
202 | 202 | return; |
203 | 203 | } |
204 | - if (!glsr(Blacklist::class)->isBlacklisted($this->request)) { |
|
204 | + if( !glsr( Blacklist::class )->isBlacklisted( $this->request ) ) { |
|
205 | 205 | return; |
206 | 206 | } |
207 | - $blacklistAction = $this->getOption('settings.submissions.blacklist.action'); |
|
208 | - if ('reject' != $blacklistAction) { |
|
207 | + $blacklistAction = $this->getOption( 'settings.submissions.blacklist.action' ); |
|
208 | + if( 'reject' != $blacklistAction ) { |
|
209 | 209 | $this->request['blacklisted'] = true; |
210 | 210 | return; |
211 | 211 | } |
212 | - $this->setError(__('Your review cannot be submitted at this time.', 'site-reviews'), |
|
212 | + $this->setError( __( 'Your review cannot be submitted at this time.', 'site-reviews' ), |
|
213 | 213 | 'Blacklisted submission detected:' |
214 | 214 | ); |
215 | 215 | } |
@@ -219,18 +219,18 @@ discard block |
||
219 | 219 | */ |
220 | 220 | protected function validateCustom() |
221 | 221 | { |
222 | - if (!empty($this->error)) { |
|
222 | + if( !empty($this->error) ) { |
|
223 | 223 | return; |
224 | 224 | } |
225 | - $validated = apply_filters('site-reviews/validate/custom', true, $this->request); |
|
226 | - if (true === $validated) { |
|
225 | + $validated = apply_filters( 'site-reviews/validate/custom', true, $this->request ); |
|
226 | + if( true === $validated ) { |
|
227 | 227 | return; |
228 | 228 | } |
229 | - $errorMessage = is_string($validated) |
|
229 | + $errorMessage = is_string( $validated ) |
|
230 | 230 | ? $validated |
231 | - : __('The review submission failed. Please notify the site administrator.', 'site-reviews'); |
|
232 | - $this->setError($errorMessage); |
|
233 | - $this->setSessionValues('values', $this->request); |
|
231 | + : __( 'The review submission failed. Please notify the site administrator.', 'site-reviews' ); |
|
232 | + $this->setError( $errorMessage ); |
|
233 | + $this->setSessionValues( 'values', $this->request ); |
|
234 | 234 | } |
235 | 235 | |
236 | 236 | /** |
@@ -238,11 +238,11 @@ discard block |
||
238 | 238 | */ |
239 | 239 | protected function validateHoneyPot() |
240 | 240 | { |
241 | - if (!empty($this->error)) { |
|
241 | + if( !empty($this->error) ) { |
|
242 | 242 | return; |
243 | 243 | } |
244 | - if (!empty($this->request['gotcha'])) { |
|
245 | - $this->setError(__('The review submission failed. Please notify the site administrator.', 'site-reviews'), |
|
244 | + if( !empty($this->request['gotcha']) ) { |
|
245 | + $this->setError( __( 'The review submission failed. Please notify the site administrator.', 'site-reviews' ), |
|
246 | 246 | 'The Honeypot caught a bad submission:' |
247 | 247 | ); |
248 | 248 | } |
@@ -253,11 +253,11 @@ discard block |
||
253 | 253 | */ |
254 | 254 | protected function validatePermission() |
255 | 255 | { |
256 | - if (!empty($this->error)) { |
|
256 | + if( !empty($this->error) ) { |
|
257 | 257 | return; |
258 | 258 | } |
259 | - if (!is_user_logged_in() && glsr(OptionManager::class)->getBool('settings.general.require.login')) { |
|
260 | - $this->setError(__('You must be logged in to submit a review.', 'site-reviews')); |
|
259 | + if( !is_user_logged_in() && glsr( OptionManager::class )->getBool( 'settings.general.require.login' ) ) { |
|
260 | + $this->setError( __( 'You must be logged in to submit a review.', 'site-reviews' ) ); |
|
261 | 261 | } |
262 | 262 | } |
263 | 263 | |
@@ -266,11 +266,11 @@ discard block |
||
266 | 266 | */ |
267 | 267 | protected function validateReviewLimits() |
268 | 268 | { |
269 | - if (!empty($this->error)) { |
|
269 | + if( !empty($this->error) ) { |
|
270 | 270 | return; |
271 | 271 | } |
272 | - if (glsr(ReviewLimits::class)->hasReachedLimit($this->request)) { |
|
273 | - $this->setError(__('You have already submitted a review.', 'site-reviews')); |
|
272 | + if( glsr( ReviewLimits::class )->hasReachedLimit( $this->request ) ) { |
|
273 | + $this->setError( __( 'You have already submitted a review.', 'site-reviews' ) ); |
|
274 | 274 | } |
275 | 275 | } |
276 | 276 | |
@@ -279,33 +279,33 @@ discard block |
||
279 | 279 | */ |
280 | 280 | protected function validateRecaptcha() |
281 | 281 | { |
282 | - if (!empty($this->error)) { |
|
282 | + if( !empty($this->error) ) { |
|
283 | 283 | return; |
284 | 284 | } |
285 | 285 | $status = $this->getRecaptchaStatus(); |
286 | - if (in_array($status, [static::RECAPTCHA_DISABLED, static::RECAPTCHA_VALID])) { |
|
286 | + if( in_array( $status, [static::RECAPTCHA_DISABLED, static::RECAPTCHA_VALID] ) ) { |
|
287 | 287 | return; |
288 | 288 | } |
289 | - if (static::RECAPTCHA_EMPTY === $status) { |
|
290 | - $this->setSessionValues('recaptcha', 'unset'); |
|
289 | + if( static::RECAPTCHA_EMPTY === $status ) { |
|
290 | + $this->setSessionValues( 'recaptcha', 'unset' ); |
|
291 | 291 | $this->recaptchaIsUnset = true; |
292 | 292 | return; |
293 | 293 | } |
294 | - $this->setSessionValues('recaptcha', 'reset'); |
|
294 | + $this->setSessionValues( 'recaptcha', 'reset' ); |
|
295 | 295 | $errors = [ |
296 | - static::RECAPTCHA_FAILED => __('The reCAPTCHA failed to load, please refresh the page and try again.', 'site-reviews'), |
|
297 | - static::RECAPTCHA_INVALID => __('The reCAPTCHA verification failed, please try again.', 'site-reviews'), |
|
296 | + static::RECAPTCHA_FAILED => __( 'The reCAPTCHA failed to load, please refresh the page and try again.', 'site-reviews' ), |
|
297 | + static::RECAPTCHA_INVALID => __( 'The reCAPTCHA verification failed, please try again.', 'site-reviews' ), |
|
298 | 298 | ]; |
299 | - $this->setError($errors[$status]); |
|
299 | + $this->setError( $errors[$status] ); |
|
300 | 300 | } |
301 | 301 | |
302 | 302 | /** |
303 | 303 | * @return array |
304 | 304 | */ |
305 | - protected function validateRequest(array $request) |
|
305 | + protected function validateRequest( array $request ) |
|
306 | 306 | { |
307 | - return $this->isRequestValid($request) |
|
308 | - ? array_merge(glsr(ValidateReviewDefaults::class)->defaults(), $request) |
|
307 | + return $this->isRequestValid( $request ) |
|
308 | + ? array_merge( glsr( ValidateReviewDefaults::class )->defaults(), $request ) |
|
309 | 309 | : $request; |
310 | 310 | } |
311 | 311 | } |
@@ -12,335 +12,335 @@ |
||
12 | 12 | |
13 | 13 | class Schema |
14 | 14 | { |
15 | - /** |
|
16 | - * @var array |
|
17 | - */ |
|
18 | - protected $args; |
|
15 | + /** |
|
16 | + * @var array |
|
17 | + */ |
|
18 | + protected $args; |
|
19 | 19 | |
20 | - /** |
|
21 | - * @var array |
|
22 | - */ |
|
23 | - protected $keyValues = []; |
|
20 | + /** |
|
21 | + * @var array |
|
22 | + */ |
|
23 | + protected $keyValues = []; |
|
24 | 24 | |
25 | - /** |
|
26 | - * @var array |
|
27 | - */ |
|
28 | - protected $ratingCounts; |
|
25 | + /** |
|
26 | + * @var array |
|
27 | + */ |
|
28 | + protected $ratingCounts; |
|
29 | 29 | |
30 | - /** |
|
31 | - * @return array |
|
32 | - */ |
|
33 | - public function build(array $args = []) |
|
34 | - { |
|
35 | - $this->args = $args; |
|
36 | - $schema = $this->buildSummary($args); |
|
37 | - if (!empty($schema)) { |
|
38 | - $reviews = $this->buildReviews(); |
|
39 | - foreach ($reviews as &$review) { |
|
40 | - unset($review['@context']); |
|
41 | - unset($review['itemReviewed']); |
|
42 | - }); |
|
43 | - } |
|
44 | - if (!empty($reviews)) { |
|
45 | - $schema['review'] = $reviews; |
|
46 | - } |
|
47 | - return $schema; |
|
48 | - } |
|
30 | + /** |
|
31 | + * @return array |
|
32 | + */ |
|
33 | + public function build(array $args = []) |
|
34 | + { |
|
35 | + $this->args = $args; |
|
36 | + $schema = $this->buildSummary($args); |
|
37 | + if (!empty($schema)) { |
|
38 | + $reviews = $this->buildReviews(); |
|
39 | + foreach ($reviews as &$review) { |
|
40 | + unset($review['@context']); |
|
41 | + unset($review['itemReviewed']); |
|
42 | + }); |
|
43 | + } |
|
44 | + if (!empty($reviews)) { |
|
45 | + $schema['review'] = $reviews; |
|
46 | + } |
|
47 | + return $schema; |
|
48 | + } |
|
49 | 49 | |
50 | - /** |
|
51 | - * @param array|null $args |
|
52 | - * @return array |
|
53 | - */ |
|
54 | - public function buildSummary($args = null) |
|
55 | - { |
|
56 | - if (is_array($args)) { |
|
57 | - $this->args = $args; |
|
58 | - } |
|
59 | - $buildSummary = Helper::buildMethodName($this->getSchemaOptionValue('type'), 'buildSummaryFor'); |
|
60 | - if ($count = array_sum($this->getRatingCounts())) { |
|
61 | - $schema = method_exists($this, $buildSummary) |
|
62 | - ? $this->$buildSummary() |
|
63 | - : $this->buildSummaryForCustom(); |
|
64 | - $schema->aggregateRating( |
|
65 | - $this->getSchemaType('AggregateRating') |
|
66 | - ->ratingValue($this->getRatingValue()) |
|
67 | - ->reviewCount($count) |
|
68 | - ->bestRating(glsr()->constant('MAX_RATING', Rating::class)) |
|
69 | - ->worstRating(glsr()->constant('MIN_RATING', Rating::class)) |
|
70 | - ); |
|
71 | - $schema = $schema->toArray(); |
|
72 | - return apply_filters('site-reviews/schema/'.$schema['@type'], $schema, $args); |
|
73 | - } |
|
74 | - return []; |
|
75 | - } |
|
50 | + /** |
|
51 | + * @param array|null $args |
|
52 | + * @return array |
|
53 | + */ |
|
54 | + public function buildSummary($args = null) |
|
55 | + { |
|
56 | + if (is_array($args)) { |
|
57 | + $this->args = $args; |
|
58 | + } |
|
59 | + $buildSummary = Helper::buildMethodName($this->getSchemaOptionValue('type'), 'buildSummaryFor'); |
|
60 | + if ($count = array_sum($this->getRatingCounts())) { |
|
61 | + $schema = method_exists($this, $buildSummary) |
|
62 | + ? $this->$buildSummary() |
|
63 | + : $this->buildSummaryForCustom(); |
|
64 | + $schema->aggregateRating( |
|
65 | + $this->getSchemaType('AggregateRating') |
|
66 | + ->ratingValue($this->getRatingValue()) |
|
67 | + ->reviewCount($count) |
|
68 | + ->bestRating(glsr()->constant('MAX_RATING', Rating::class)) |
|
69 | + ->worstRating(glsr()->constant('MIN_RATING', Rating::class)) |
|
70 | + ); |
|
71 | + $schema = $schema->toArray(); |
|
72 | + return apply_filters('site-reviews/schema/'.$schema['@type'], $schema, $args); |
|
73 | + } |
|
74 | + return []; |
|
75 | + } |
|
76 | 76 | |
77 | - /** |
|
78 | - * @return void |
|
79 | - */ |
|
80 | - public function render() |
|
81 | - { |
|
82 | - if (empty(glsr()->schemas)) { |
|
83 | - return; |
|
84 | - } |
|
85 | - printf('<script type="application/ld+json">%s</script>', json_encode( |
|
86 | - apply_filters('site-reviews/schema/all', glsr()->schemas), |
|
87 | - JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES |
|
88 | - )); |
|
89 | - } |
|
77 | + /** |
|
78 | + * @return void |
|
79 | + */ |
|
80 | + public function render() |
|
81 | + { |
|
82 | + if (empty(glsr()->schemas)) { |
|
83 | + return; |
|
84 | + } |
|
85 | + printf('<script type="application/ld+json">%s</script>', json_encode( |
|
86 | + apply_filters('site-reviews/schema/all', glsr()->schemas), |
|
87 | + JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES |
|
88 | + )); |
|
89 | + } |
|
90 | 90 | |
91 | - /** |
|
92 | - * @return void |
|
93 | - */ |
|
94 | - public function store(array $schema) |
|
95 | - { |
|
96 | - if (empty($schema)) { |
|
97 | - return; |
|
98 | - } |
|
99 | - $schemas = glsr()->schemas; |
|
100 | - $schemas[] = $schema; |
|
101 | - glsr()->schemas = array_map('unserialize', array_unique(array_map('serialize', $schemas))); |
|
102 | - } |
|
91 | + /** |
|
92 | + * @return void |
|
93 | + */ |
|
94 | + public function store(array $schema) |
|
95 | + { |
|
96 | + if (empty($schema)) { |
|
97 | + return; |
|
98 | + } |
|
99 | + $schemas = glsr()->schemas; |
|
100 | + $schemas[] = $schema; |
|
101 | + glsr()->schemas = array_map('unserialize', array_unique(array_map('serialize', $schemas))); |
|
102 | + } |
|
103 | 103 | |
104 | - /** |
|
105 | - * @param Review $review |
|
106 | - * @return array |
|
107 | - */ |
|
108 | - protected function buildReview($review) |
|
109 | - { |
|
110 | - $schema = $this->getSchemaType('Review') |
|
111 | - ->doIf(!in_array('title', $this->args['hide']), function ($schema) use ($review) { |
|
112 | - $schema->name($review->title); |
|
113 | - }) |
|
114 | - ->doIf(!in_array('excerpt', $this->args['hide']), function ($schema) use ($review) { |
|
115 | - $schema->reviewBody($review->content); |
|
116 | - }) |
|
117 | - ->datePublished((new DateTime($review->date))) |
|
118 | - ->author($this->getSchemaType('Person')->name($review->author)) |
|
119 | - ->itemReviewed($this->getSchemaType()->name($this->getSchemaOptionValue('name'))); |
|
120 | - if (!empty($review->rating)) { |
|
121 | - $schema->reviewRating( |
|
122 | - $this->getSchemaType('Rating') |
|
123 | - ->ratingValue($review->rating) |
|
124 | - ->bestRating(glsr()->constant('MAX_RATING', Rating::class)) |
|
125 | - ->worstRating(glsr()->constant('MIN_RATING', Rating::class)) |
|
126 | - ); |
|
127 | - } |
|
128 | - return apply_filters('site-reviews/schema/review', $schema->toArray(), $review, $this->args); |
|
129 | - } |
|
104 | + /** |
|
105 | + * @param Review $review |
|
106 | + * @return array |
|
107 | + */ |
|
108 | + protected function buildReview($review) |
|
109 | + { |
|
110 | + $schema = $this->getSchemaType('Review') |
|
111 | + ->doIf(!in_array('title', $this->args['hide']), function ($schema) use ($review) { |
|
112 | + $schema->name($review->title); |
|
113 | + }) |
|
114 | + ->doIf(!in_array('excerpt', $this->args['hide']), function ($schema) use ($review) { |
|
115 | + $schema->reviewBody($review->content); |
|
116 | + }) |
|
117 | + ->datePublished((new DateTime($review->date))) |
|
118 | + ->author($this->getSchemaType('Person')->name($review->author)) |
|
119 | + ->itemReviewed($this->getSchemaType()->name($this->getSchemaOptionValue('name'))); |
|
120 | + if (!empty($review->rating)) { |
|
121 | + $schema->reviewRating( |
|
122 | + $this->getSchemaType('Rating') |
|
123 | + ->ratingValue($review->rating) |
|
124 | + ->bestRating(glsr()->constant('MAX_RATING', Rating::class)) |
|
125 | + ->worstRating(glsr()->constant('MIN_RATING', Rating::class)) |
|
126 | + ); |
|
127 | + } |
|
128 | + return apply_filters('site-reviews/schema/review', $schema->toArray(), $review, $this->args); |
|
129 | + } |
|
130 | 130 | |
131 | - /** |
|
132 | - * @return array |
|
133 | - */ |
|
134 | - protected function buildReviews() |
|
135 | - { |
|
136 | - $reviews = []; |
|
137 | - foreach (glsr(ReviewManager::class)->get($this->args) as $review) { |
|
138 | - // Only include critic reviews that have been directly produced by your site, not reviews from third-party sites or syndicated reviews. |
|
139 | - // @see https://developers.google.com/search/docs/data-types/review |
|
140 | - if ('local' === $review->review_type) { |
|
141 | - $reviews[] = $this->buildReview($review); |
|
142 | - } |
|
143 | - } |
|
144 | - return $reviews; |
|
145 | - } |
|
131 | + /** |
|
132 | + * @return array |
|
133 | + */ |
|
134 | + protected function buildReviews() |
|
135 | + { |
|
136 | + $reviews = []; |
|
137 | + foreach (glsr(ReviewManager::class)->get($this->args) as $review) { |
|
138 | + // Only include critic reviews that have been directly produced by your site, not reviews from third-party sites or syndicated reviews. |
|
139 | + // @see https://developers.google.com/search/docs/data-types/review |
|
140 | + if ('local' === $review->review_type) { |
|
141 | + $reviews[] = $this->buildReview($review); |
|
142 | + } |
|
143 | + } |
|
144 | + return $reviews; |
|
145 | + } |
|
146 | 146 | |
147 | - /** |
|
148 | - * @param mixed $schema |
|
149 | - * @return mixed |
|
150 | - */ |
|
151 | - protected function buildSchemaValues($schema, array $values = []) |
|
152 | - { |
|
153 | - foreach ($values as $value) { |
|
154 | - $option = $this->getSchemaOptionValue($value); |
|
155 | - if (empty($option)) { |
|
156 | - continue; |
|
157 | - } |
|
158 | - $schema->$value($option); |
|
159 | - } |
|
160 | - return $schema; |
|
161 | - } |
|
147 | + /** |
|
148 | + * @param mixed $schema |
|
149 | + * @return mixed |
|
150 | + */ |
|
151 | + protected function buildSchemaValues($schema, array $values = []) |
|
152 | + { |
|
153 | + foreach ($values as $value) { |
|
154 | + $option = $this->getSchemaOptionValue($value); |
|
155 | + if (empty($option)) { |
|
156 | + continue; |
|
157 | + } |
|
158 | + $schema->$value($option); |
|
159 | + } |
|
160 | + return $schema; |
|
161 | + } |
|
162 | 162 | |
163 | - /** |
|
164 | - * @return mixed |
|
165 | - */ |
|
166 | - protected function buildSummaryForCustom() |
|
167 | - { |
|
168 | - return $this->buildSchemaValues($this->getSchemaType(), [ |
|
169 | - 'description', 'image', 'name', 'url', |
|
170 | - ]); |
|
171 | - } |
|
163 | + /** |
|
164 | + * @return mixed |
|
165 | + */ |
|
166 | + protected function buildSummaryForCustom() |
|
167 | + { |
|
168 | + return $this->buildSchemaValues($this->getSchemaType(), [ |
|
169 | + 'description', 'image', 'name', 'url', |
|
170 | + ]); |
|
171 | + } |
|
172 | 172 | |
173 | - /** |
|
174 | - * @return mixed |
|
175 | - */ |
|
176 | - protected function buildSummaryForLocalBusiness() |
|
177 | - { |
|
178 | - return $this->buildSchemaValues($this->buildSummaryForCustom(), [ |
|
179 | - 'address', 'priceRange', 'telephone', |
|
180 | - ]); |
|
181 | - } |
|
173 | + /** |
|
174 | + * @return mixed |
|
175 | + */ |
|
176 | + protected function buildSummaryForLocalBusiness() |
|
177 | + { |
|
178 | + return $this->buildSchemaValues($this->buildSummaryForCustom(), [ |
|
179 | + 'address', 'priceRange', 'telephone', |
|
180 | + ]); |
|
181 | + } |
|
182 | 182 | |
183 | - /** |
|
184 | - * @return mixed |
|
185 | - */ |
|
186 | - protected function buildSummaryForProduct() |
|
187 | - { |
|
188 | - $offerType = $this->getSchemaOption('offerType', 'AggregateOffer'); |
|
189 | - $offers = $this->buildSchemaValues($this->getSchemaType($offerType), [ |
|
190 | - 'highPrice', 'lowPrice', 'price', 'priceCurrency', |
|
191 | - ]); |
|
192 | - return $this->buildSummaryForCustom() |
|
193 | - ->doIf(!empty($offers->getProperties()), function ($schema) use ($offers) { |
|
194 | - $schema->offers($offers); |
|
195 | - }) |
|
196 | - ->setProperty('@id', $this->getSchemaOptionValue('url').'#product'); |
|
197 | - } |
|
183 | + /** |
|
184 | + * @return mixed |
|
185 | + */ |
|
186 | + protected function buildSummaryForProduct() |
|
187 | + { |
|
188 | + $offerType = $this->getSchemaOption('offerType', 'AggregateOffer'); |
|
189 | + $offers = $this->buildSchemaValues($this->getSchemaType($offerType), [ |
|
190 | + 'highPrice', 'lowPrice', 'price', 'priceCurrency', |
|
191 | + ]); |
|
192 | + return $this->buildSummaryForCustom() |
|
193 | + ->doIf(!empty($offers->getProperties()), function ($schema) use ($offers) { |
|
194 | + $schema->offers($offers); |
|
195 | + }) |
|
196 | + ->setProperty('@id', $this->getSchemaOptionValue('url').'#product'); |
|
197 | + } |
|
198 | 198 | |
199 | - /** |
|
200 | - * @return array |
|
201 | - */ |
|
202 | - protected function getRatingCounts() |
|
203 | - { |
|
204 | - if (!isset($this->ratingCounts)) { |
|
205 | - $this->ratingCounts = glsr(ReviewManager::class)->getRatingCounts($this->args); |
|
206 | - } |
|
207 | - return $this->ratingCounts; |
|
208 | - } |
|
199 | + /** |
|
200 | + * @return array |
|
201 | + */ |
|
202 | + protected function getRatingCounts() |
|
203 | + { |
|
204 | + if (!isset($this->ratingCounts)) { |
|
205 | + $this->ratingCounts = glsr(ReviewManager::class)->getRatingCounts($this->args); |
|
206 | + } |
|
207 | + return $this->ratingCounts; |
|
208 | + } |
|
209 | 209 | |
210 | - /** |
|
211 | - * @return int|float |
|
212 | - */ |
|
213 | - protected function getRatingValue() |
|
214 | - { |
|
215 | - return glsr(Rating::class)->getAverage($this->getRatingCounts()); |
|
216 | - } |
|
210 | + /** |
|
211 | + * @return int|float |
|
212 | + */ |
|
213 | + protected function getRatingValue() |
|
214 | + { |
|
215 | + return glsr(Rating::class)->getAverage($this->getRatingCounts()); |
|
216 | + } |
|
217 | 217 | |
218 | - /** |
|
219 | - * @param string $option |
|
220 | - * @param string $fallback |
|
221 | - * @return string |
|
222 | - */ |
|
223 | - protected function getSchemaOption($option, $fallback) |
|
224 | - { |
|
225 | - $option = strtolower($option); |
|
226 | - if ($schemaOption = trim((string) get_post_meta(intval(get_the_ID()), 'schema_'.$option, true))) { |
|
227 | - return $schemaOption; |
|
228 | - } |
|
229 | - $setting = glsr(OptionManager::class)->get('settings.schema.'.$option); |
|
230 | - if (is_array($setting)) { |
|
231 | - return $this->getSchemaOptionDefault($setting, $fallback); |
|
232 | - } |
|
233 | - return !empty($setting) |
|
234 | - ? $setting |
|
235 | - : $fallback; |
|
236 | - } |
|
218 | + /** |
|
219 | + * @param string $option |
|
220 | + * @param string $fallback |
|
221 | + * @return string |
|
222 | + */ |
|
223 | + protected function getSchemaOption($option, $fallback) |
|
224 | + { |
|
225 | + $option = strtolower($option); |
|
226 | + if ($schemaOption = trim((string) get_post_meta(intval(get_the_ID()), 'schema_'.$option, true))) { |
|
227 | + return $schemaOption; |
|
228 | + } |
|
229 | + $setting = glsr(OptionManager::class)->get('settings.schema.'.$option); |
|
230 | + if (is_array($setting)) { |
|
231 | + return $this->getSchemaOptionDefault($setting, $fallback); |
|
232 | + } |
|
233 | + return !empty($setting) |
|
234 | + ? $setting |
|
235 | + : $fallback; |
|
236 | + } |
|
237 | 237 | |
238 | - /** |
|
239 | - * @param string $fallback |
|
240 | - * @return string |
|
241 | - */ |
|
242 | - protected function getSchemaOptionDefault(array $setting, $fallback) |
|
243 | - { |
|
244 | - $setting = wp_parse_args($setting, [ |
|
245 | - 'custom' => '', |
|
246 | - 'default' => $fallback, |
|
247 | - ]); |
|
248 | - return 'custom' != $setting['default'] |
|
249 | - ? $setting['default'] |
|
250 | - : $setting['custom']; |
|
251 | - } |
|
238 | + /** |
|
239 | + * @param string $fallback |
|
240 | + * @return string |
|
241 | + */ |
|
242 | + protected function getSchemaOptionDefault(array $setting, $fallback) |
|
243 | + { |
|
244 | + $setting = wp_parse_args($setting, [ |
|
245 | + 'custom' => '', |
|
246 | + 'default' => $fallback, |
|
247 | + ]); |
|
248 | + return 'custom' != $setting['default'] |
|
249 | + ? $setting['default'] |
|
250 | + : $setting['custom']; |
|
251 | + } |
|
252 | 252 | |
253 | - /** |
|
254 | - * @param string $option |
|
255 | - * @param string $fallback |
|
256 | - * @return void|string |
|
257 | - */ |
|
258 | - protected function getSchemaOptionValue($option, $fallback = 'post') |
|
259 | - { |
|
260 | - if (array_key_exists($option, $this->keyValues)) { |
|
261 | - return $this->keyValues[$option]; |
|
262 | - } |
|
263 | - $value = $this->getSchemaOption($option, $fallback); |
|
264 | - if ($value != $fallback) { |
|
265 | - return $this->setAndGetKeyValue($option, $value); |
|
266 | - } |
|
267 | - if (!is_single() && !is_page()) { |
|
268 | - return; |
|
269 | - } |
|
270 | - $method = Helper::buildMethodName($option, 'getThing'); |
|
271 | - if (method_exists($this, $method)) { |
|
272 | - return $this->setAndGetKeyValue($option, $this->$method()); |
|
273 | - } |
|
274 | - } |
|
253 | + /** |
|
254 | + * @param string $option |
|
255 | + * @param string $fallback |
|
256 | + * @return void|string |
|
257 | + */ |
|
258 | + protected function getSchemaOptionValue($option, $fallback = 'post') |
|
259 | + { |
|
260 | + if (array_key_exists($option, $this->keyValues)) { |
|
261 | + return $this->keyValues[$option]; |
|
262 | + } |
|
263 | + $value = $this->getSchemaOption($option, $fallback); |
|
264 | + if ($value != $fallback) { |
|
265 | + return $this->setAndGetKeyValue($option, $value); |
|
266 | + } |
|
267 | + if (!is_single() && !is_page()) { |
|
268 | + return; |
|
269 | + } |
|
270 | + $method = Helper::buildMethodName($option, 'getThing'); |
|
271 | + if (method_exists($this, $method)) { |
|
272 | + return $this->setAndGetKeyValue($option, $this->$method()); |
|
273 | + } |
|
274 | + } |
|
275 | 275 | |
276 | - /** |
|
277 | - * @param string|null $type |
|
278 | - * @return mixed |
|
279 | - */ |
|
280 | - protected function getSchemaType($type = null) |
|
281 | - { |
|
282 | - if (!is_string($type)) { |
|
283 | - $type = $this->getSchemaOption('type', 'LocalBusiness'); |
|
284 | - } |
|
285 | - $className = Helper::buildClassName($type, 'Modules\Schema'); |
|
286 | - return class_exists($className) |
|
287 | - ? new $className() |
|
288 | - : new UnknownType($type); |
|
289 | - } |
|
276 | + /** |
|
277 | + * @param string|null $type |
|
278 | + * @return mixed |
|
279 | + */ |
|
280 | + protected function getSchemaType($type = null) |
|
281 | + { |
|
282 | + if (!is_string($type)) { |
|
283 | + $type = $this->getSchemaOption('type', 'LocalBusiness'); |
|
284 | + } |
|
285 | + $className = Helper::buildClassName($type, 'Modules\Schema'); |
|
286 | + return class_exists($className) |
|
287 | + ? new $className() |
|
288 | + : new UnknownType($type); |
|
289 | + } |
|
290 | 290 | |
291 | - /** |
|
292 | - * @return string |
|
293 | - */ |
|
294 | - protected function getThingDescription() |
|
295 | - { |
|
296 | - $post = get_post(); |
|
297 | - $text = Arr::get($post, 'post_excerpt'); |
|
298 | - if (empty($text)) { |
|
299 | - $text = Arr::get($post, 'post_content'); |
|
300 | - } |
|
301 | - if (function_exists('excerpt_remove_blocks')) { |
|
302 | - $text = excerpt_remove_blocks($text); |
|
303 | - } |
|
304 | - $text = strip_shortcodes($text); |
|
305 | - $text = wpautop($text); |
|
306 | - $text = wptexturize($text); |
|
307 | - $text = wp_strip_all_tags($text); |
|
308 | - $text = str_replace(']]>', ']]>', $text); |
|
309 | - return wp_trim_words($text, apply_filters('excerpt_length', 55)); |
|
310 | - } |
|
291 | + /** |
|
292 | + * @return string |
|
293 | + */ |
|
294 | + protected function getThingDescription() |
|
295 | + { |
|
296 | + $post = get_post(); |
|
297 | + $text = Arr::get($post, 'post_excerpt'); |
|
298 | + if (empty($text)) { |
|
299 | + $text = Arr::get($post, 'post_content'); |
|
300 | + } |
|
301 | + if (function_exists('excerpt_remove_blocks')) { |
|
302 | + $text = excerpt_remove_blocks($text); |
|
303 | + } |
|
304 | + $text = strip_shortcodes($text); |
|
305 | + $text = wpautop($text); |
|
306 | + $text = wptexturize($text); |
|
307 | + $text = wp_strip_all_tags($text); |
|
308 | + $text = str_replace(']]>', ']]>', $text); |
|
309 | + return wp_trim_words($text, apply_filters('excerpt_length', 55)); |
|
310 | + } |
|
311 | 311 | |
312 | - /** |
|
313 | - * @return string |
|
314 | - */ |
|
315 | - protected function getThingImage() |
|
316 | - { |
|
317 | - return (string) get_the_post_thumbnail_url(null, 'large'); |
|
318 | - } |
|
312 | + /** |
|
313 | + * @return string |
|
314 | + */ |
|
315 | + protected function getThingImage() |
|
316 | + { |
|
317 | + return (string) get_the_post_thumbnail_url(null, 'large'); |
|
318 | + } |
|
319 | 319 | |
320 | - /** |
|
321 | - * @return string |
|
322 | - */ |
|
323 | - protected function getThingName() |
|
324 | - { |
|
325 | - return get_the_title(); |
|
326 | - } |
|
320 | + /** |
|
321 | + * @return string |
|
322 | + */ |
|
323 | + protected function getThingName() |
|
324 | + { |
|
325 | + return get_the_title(); |
|
326 | + } |
|
327 | 327 | |
328 | - /** |
|
329 | - * @return string |
|
330 | - */ |
|
331 | - protected function getThingUrl() |
|
332 | - { |
|
333 | - return (string) get_the_permalink(); |
|
334 | - } |
|
328 | + /** |
|
329 | + * @return string |
|
330 | + */ |
|
331 | + protected function getThingUrl() |
|
332 | + { |
|
333 | + return (string) get_the_permalink(); |
|
334 | + } |
|
335 | 335 | |
336 | - /** |
|
337 | - * @param string $option |
|
338 | - * @param string $value |
|
339 | - * @return string |
|
340 | - */ |
|
341 | - protected function setAndGetKeyValue($option, $value) |
|
342 | - { |
|
343 | - $this->keyValues[$option] = $value; |
|
344 | - return $value; |
|
345 | - } |
|
336 | + /** |
|
337 | + * @param string $option |
|
338 | + * @param string $value |
|
339 | + * @return string |
|
340 | + */ |
|
341 | + protected function setAndGetKeyValue($option, $value) |
|
342 | + { |
|
343 | + $this->keyValues[$option] = $value; |
|
344 | + return $value; |
|
345 | + } |
|
346 | 346 | } |
@@ -30,18 +30,18 @@ discard block |
||
30 | 30 | /** |
31 | 31 | * @return array |
32 | 32 | */ |
33 | - public function build(array $args = []) |
|
33 | + public function build( array $args = [] ) |
|
34 | 34 | { |
35 | 35 | $this->args = $args; |
36 | - $schema = $this->buildSummary($args); |
|
37 | - if (!empty($schema)) { |
|
36 | + $schema = $this->buildSummary( $args ); |
|
37 | + if( !empty($schema) ) { |
|
38 | 38 | $reviews = $this->buildReviews(); |
39 | - foreach ($reviews as &$review) { |
|
39 | + foreach( $reviews as &$review ) { |
|
40 | 40 | unset($review['@context']); |
41 | 41 | unset($review['itemReviewed']); |
42 | 42 | }); |
43 | 43 | } |
44 | - if (!empty($reviews)) { |
|
44 | + if( !empty($reviews) ) { |
|
45 | 45 | $schema['review'] = $reviews; |
46 | 46 | } |
47 | 47 | return $schema; |
@@ -51,25 +51,25 @@ discard block |
||
51 | 51 | * @param array|null $args |
52 | 52 | * @return array |
53 | 53 | */ |
54 | - public function buildSummary($args = null) |
|
54 | + public function buildSummary( $args = null ) |
|
55 | 55 | { |
56 | - if (is_array($args)) { |
|
56 | + if( is_array( $args ) ) { |
|
57 | 57 | $this->args = $args; |
58 | 58 | } |
59 | - $buildSummary = Helper::buildMethodName($this->getSchemaOptionValue('type'), 'buildSummaryFor'); |
|
60 | - if ($count = array_sum($this->getRatingCounts())) { |
|
61 | - $schema = method_exists($this, $buildSummary) |
|
59 | + $buildSummary = Helper::buildMethodName( $this->getSchemaOptionValue( 'type' ), 'buildSummaryFor' ); |
|
60 | + if( $count = array_sum( $this->getRatingCounts() ) ) { |
|
61 | + $schema = method_exists( $this, $buildSummary ) |
|
62 | 62 | ? $this->$buildSummary() |
63 | 63 | : $this->buildSummaryForCustom(); |
64 | 64 | $schema->aggregateRating( |
65 | - $this->getSchemaType('AggregateRating') |
|
66 | - ->ratingValue($this->getRatingValue()) |
|
67 | - ->reviewCount($count) |
|
68 | - ->bestRating(glsr()->constant('MAX_RATING', Rating::class)) |
|
69 | - ->worstRating(glsr()->constant('MIN_RATING', Rating::class)) |
|
65 | + $this->getSchemaType( 'AggregateRating' ) |
|
66 | + ->ratingValue( $this->getRatingValue() ) |
|
67 | + ->reviewCount( $count ) |
|
68 | + ->bestRating( glsr()->constant( 'MAX_RATING', Rating::class ) ) |
|
69 | + ->worstRating( glsr()->constant( 'MIN_RATING', Rating::class ) ) |
|
70 | 70 | ); |
71 | 71 | $schema = $schema->toArray(); |
72 | - return apply_filters('site-reviews/schema/'.$schema['@type'], $schema, $args); |
|
72 | + return apply_filters( 'site-reviews/schema/'.$schema['@type'], $schema, $args ); |
|
73 | 73 | } |
74 | 74 | return []; |
75 | 75 | } |
@@ -79,53 +79,53 @@ discard block |
||
79 | 79 | */ |
80 | 80 | public function render() |
81 | 81 | { |
82 | - if (empty(glsr()->schemas)) { |
|
82 | + if( empty(glsr()->schemas) ) { |
|
83 | 83 | return; |
84 | 84 | } |
85 | - printf('<script type="application/ld+json">%s</script>', json_encode( |
|
86 | - apply_filters('site-reviews/schema/all', glsr()->schemas), |
|
85 | + printf( '<script type="application/ld+json">%s</script>', json_encode( |
|
86 | + apply_filters( 'site-reviews/schema/all', glsr()->schemas ), |
|
87 | 87 | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES |
88 | - )); |
|
88 | + ) ); |
|
89 | 89 | } |
90 | 90 | |
91 | 91 | /** |
92 | 92 | * @return void |
93 | 93 | */ |
94 | - public function store(array $schema) |
|
94 | + public function store( array $schema ) |
|
95 | 95 | { |
96 | - if (empty($schema)) { |
|
96 | + if( empty($schema) ) { |
|
97 | 97 | return; |
98 | 98 | } |
99 | 99 | $schemas = glsr()->schemas; |
100 | 100 | $schemas[] = $schema; |
101 | - glsr()->schemas = array_map('unserialize', array_unique(array_map('serialize', $schemas))); |
|
101 | + glsr()->schemas = array_map( 'unserialize', array_unique( array_map( 'serialize', $schemas ) ) ); |
|
102 | 102 | } |
103 | 103 | |
104 | 104 | /** |
105 | 105 | * @param Review $review |
106 | 106 | * @return array |
107 | 107 | */ |
108 | - protected function buildReview($review) |
|
108 | + protected function buildReview( $review ) |
|
109 | 109 | { |
110 | - $schema = $this->getSchemaType('Review') |
|
111 | - ->doIf(!in_array('title', $this->args['hide']), function ($schema) use ($review) { |
|
112 | - $schema->name($review->title); |
|
110 | + $schema = $this->getSchemaType( 'Review' ) |
|
111 | + ->doIf( !in_array( 'title', $this->args['hide'] ), function( $schema ) use ($review) { |
|
112 | + $schema->name( $review->title ); |
|
113 | 113 | }) |
114 | - ->doIf(!in_array('excerpt', $this->args['hide']), function ($schema) use ($review) { |
|
115 | - $schema->reviewBody($review->content); |
|
114 | + ->doIf( !in_array( 'excerpt', $this->args['hide'] ), function( $schema ) use ($review) { |
|
115 | + $schema->reviewBody( $review->content ); |
|
116 | 116 | }) |
117 | - ->datePublished((new DateTime($review->date))) |
|
118 | - ->author($this->getSchemaType('Person')->name($review->author)) |
|
119 | - ->itemReviewed($this->getSchemaType()->name($this->getSchemaOptionValue('name'))); |
|
120 | - if (!empty($review->rating)) { |
|
117 | + ->datePublished( (new DateTime( $review->date )) ) |
|
118 | + ->author( $this->getSchemaType( 'Person' )->name( $review->author ) ) |
|
119 | + ->itemReviewed( $this->getSchemaType()->name( $this->getSchemaOptionValue( 'name' ) ) ); |
|
120 | + if( !empty($review->rating) ) { |
|
121 | 121 | $schema->reviewRating( |
122 | - $this->getSchemaType('Rating') |
|
123 | - ->ratingValue($review->rating) |
|
124 | - ->bestRating(glsr()->constant('MAX_RATING', Rating::class)) |
|
125 | - ->worstRating(glsr()->constant('MIN_RATING', Rating::class)) |
|
122 | + $this->getSchemaType( 'Rating' ) |
|
123 | + ->ratingValue( $review->rating ) |
|
124 | + ->bestRating( glsr()->constant( 'MAX_RATING', Rating::class ) ) |
|
125 | + ->worstRating( glsr()->constant( 'MIN_RATING', Rating::class ) ) |
|
126 | 126 | ); |
127 | 127 | } |
128 | - return apply_filters('site-reviews/schema/review', $schema->toArray(), $review, $this->args); |
|
128 | + return apply_filters( 'site-reviews/schema/review', $schema->toArray(), $review, $this->args ); |
|
129 | 129 | } |
130 | 130 | |
131 | 131 | /** |
@@ -134,11 +134,11 @@ discard block |
||
134 | 134 | protected function buildReviews() |
135 | 135 | { |
136 | 136 | $reviews = []; |
137 | - foreach (glsr(ReviewManager::class)->get($this->args) as $review) { |
|
137 | + foreach( glsr( ReviewManager::class )->get( $this->args ) as $review ) { |
|
138 | 138 | // Only include critic reviews that have been directly produced by your site, not reviews from third-party sites or syndicated reviews. |
139 | 139 | // @see https://developers.google.com/search/docs/data-types/review |
140 | - if ('local' === $review->review_type) { |
|
141 | - $reviews[] = $this->buildReview($review); |
|
140 | + if( 'local' === $review->review_type ) { |
|
141 | + $reviews[] = $this->buildReview( $review ); |
|
142 | 142 | } |
143 | 143 | } |
144 | 144 | return $reviews; |
@@ -148,14 +148,14 @@ discard block |
||
148 | 148 | * @param mixed $schema |
149 | 149 | * @return mixed |
150 | 150 | */ |
151 | - protected function buildSchemaValues($schema, array $values = []) |
|
151 | + protected function buildSchemaValues( $schema, array $values = [] ) |
|
152 | 152 | { |
153 | - foreach ($values as $value) { |
|
154 | - $option = $this->getSchemaOptionValue($value); |
|
155 | - if (empty($option)) { |
|
153 | + foreach( $values as $value ) { |
|
154 | + $option = $this->getSchemaOptionValue( $value ); |
|
155 | + if( empty($option) ) { |
|
156 | 156 | continue; |
157 | 157 | } |
158 | - $schema->$value($option); |
|
158 | + $schema->$value( $option ); |
|
159 | 159 | } |
160 | 160 | return $schema; |
161 | 161 | } |
@@ -165,9 +165,9 @@ discard block |
||
165 | 165 | */ |
166 | 166 | protected function buildSummaryForCustom() |
167 | 167 | { |
168 | - return $this->buildSchemaValues($this->getSchemaType(), [ |
|
168 | + return $this->buildSchemaValues( $this->getSchemaType(), [ |
|
169 | 169 | 'description', 'image', 'name', 'url', |
170 | - ]); |
|
170 | + ] ); |
|
171 | 171 | } |
172 | 172 | |
173 | 173 | /** |
@@ -175,9 +175,9 @@ discard block |
||
175 | 175 | */ |
176 | 176 | protected function buildSummaryForLocalBusiness() |
177 | 177 | { |
178 | - return $this->buildSchemaValues($this->buildSummaryForCustom(), [ |
|
178 | + return $this->buildSchemaValues( $this->buildSummaryForCustom(), [ |
|
179 | 179 | 'address', 'priceRange', 'telephone', |
180 | - ]); |
|
180 | + ] ); |
|
181 | 181 | } |
182 | 182 | |
183 | 183 | /** |
@@ -185,15 +185,15 @@ discard block |
||
185 | 185 | */ |
186 | 186 | protected function buildSummaryForProduct() |
187 | 187 | { |
188 | - $offerType = $this->getSchemaOption('offerType', 'AggregateOffer'); |
|
189 | - $offers = $this->buildSchemaValues($this->getSchemaType($offerType), [ |
|
188 | + $offerType = $this->getSchemaOption( 'offerType', 'AggregateOffer' ); |
|
189 | + $offers = $this->buildSchemaValues( $this->getSchemaType( $offerType ), [ |
|
190 | 190 | 'highPrice', 'lowPrice', 'price', 'priceCurrency', |
191 | - ]); |
|
191 | + ] ); |
|
192 | 192 | return $this->buildSummaryForCustom() |
193 | - ->doIf(!empty($offers->getProperties()), function ($schema) use ($offers) { |
|
194 | - $schema->offers($offers); |
|
193 | + ->doIf( !empty($offers->getProperties()), function( $schema ) use ($offers) { |
|
194 | + $schema->offers( $offers ); |
|
195 | 195 | }) |
196 | - ->setProperty('@id', $this->getSchemaOptionValue('url').'#product'); |
|
196 | + ->setProperty( '@id', $this->getSchemaOptionValue( 'url' ).'#product' ); |
|
197 | 197 | } |
198 | 198 | |
199 | 199 | /** |
@@ -201,8 +201,8 @@ discard block |
||
201 | 201 | */ |
202 | 202 | protected function getRatingCounts() |
203 | 203 | { |
204 | - if (!isset($this->ratingCounts)) { |
|
205 | - $this->ratingCounts = glsr(ReviewManager::class)->getRatingCounts($this->args); |
|
204 | + if( !isset($this->ratingCounts) ) { |
|
205 | + $this->ratingCounts = glsr( ReviewManager::class )->getRatingCounts( $this->args ); |
|
206 | 206 | } |
207 | 207 | return $this->ratingCounts; |
208 | 208 | } |
@@ -212,7 +212,7 @@ discard block |
||
212 | 212 | */ |
213 | 213 | protected function getRatingValue() |
214 | 214 | { |
215 | - return glsr(Rating::class)->getAverage($this->getRatingCounts()); |
|
215 | + return glsr( Rating::class )->getAverage( $this->getRatingCounts() ); |
|
216 | 216 | } |
217 | 217 | |
218 | 218 | /** |
@@ -220,15 +220,15 @@ discard block |
||
220 | 220 | * @param string $fallback |
221 | 221 | * @return string |
222 | 222 | */ |
223 | - protected function getSchemaOption($option, $fallback) |
|
223 | + protected function getSchemaOption( $option, $fallback ) |
|
224 | 224 | { |
225 | - $option = strtolower($option); |
|
226 | - if ($schemaOption = trim((string) get_post_meta(intval(get_the_ID()), 'schema_'.$option, true))) { |
|
225 | + $option = strtolower( $option ); |
|
226 | + if( $schemaOption = trim( (string)get_post_meta( intval( get_the_ID() ), 'schema_'.$option, true ) ) ) { |
|
227 | 227 | return $schemaOption; |
228 | 228 | } |
229 | - $setting = glsr(OptionManager::class)->get('settings.schema.'.$option); |
|
230 | - if (is_array($setting)) { |
|
231 | - return $this->getSchemaOptionDefault($setting, $fallback); |
|
229 | + $setting = glsr( OptionManager::class )->get( 'settings.schema.'.$option ); |
|
230 | + if( is_array( $setting ) ) { |
|
231 | + return $this->getSchemaOptionDefault( $setting, $fallback ); |
|
232 | 232 | } |
233 | 233 | return !empty($setting) |
234 | 234 | ? $setting |
@@ -239,12 +239,12 @@ discard block |
||
239 | 239 | * @param string $fallback |
240 | 240 | * @return string |
241 | 241 | */ |
242 | - protected function getSchemaOptionDefault(array $setting, $fallback) |
|
242 | + protected function getSchemaOptionDefault( array $setting, $fallback ) |
|
243 | 243 | { |
244 | - $setting = wp_parse_args($setting, [ |
|
244 | + $setting = wp_parse_args( $setting, [ |
|
245 | 245 | 'custom' => '', |
246 | 246 | 'default' => $fallback, |
247 | - ]); |
|
247 | + ] ); |
|
248 | 248 | return 'custom' != $setting['default'] |
249 | 249 | ? $setting['default'] |
250 | 250 | : $setting['custom']; |
@@ -255,21 +255,21 @@ discard block |
||
255 | 255 | * @param string $fallback |
256 | 256 | * @return void|string |
257 | 257 | */ |
258 | - protected function getSchemaOptionValue($option, $fallback = 'post') |
|
258 | + protected function getSchemaOptionValue( $option, $fallback = 'post' ) |
|
259 | 259 | { |
260 | - if (array_key_exists($option, $this->keyValues)) { |
|
260 | + if( array_key_exists( $option, $this->keyValues ) ) { |
|
261 | 261 | return $this->keyValues[$option]; |
262 | 262 | } |
263 | - $value = $this->getSchemaOption($option, $fallback); |
|
264 | - if ($value != $fallback) { |
|
265 | - return $this->setAndGetKeyValue($option, $value); |
|
263 | + $value = $this->getSchemaOption( $option, $fallback ); |
|
264 | + if( $value != $fallback ) { |
|
265 | + return $this->setAndGetKeyValue( $option, $value ); |
|
266 | 266 | } |
267 | - if (!is_single() && !is_page()) { |
|
267 | + if( !is_single() && !is_page() ) { |
|
268 | 268 | return; |
269 | 269 | } |
270 | - $method = Helper::buildMethodName($option, 'getThing'); |
|
271 | - if (method_exists($this, $method)) { |
|
272 | - return $this->setAndGetKeyValue($option, $this->$method()); |
|
270 | + $method = Helper::buildMethodName( $option, 'getThing' ); |
|
271 | + if( method_exists( $this, $method ) ) { |
|
272 | + return $this->setAndGetKeyValue( $option, $this->$method() ); |
|
273 | 273 | } |
274 | 274 | } |
275 | 275 | |
@@ -277,15 +277,15 @@ discard block |
||
277 | 277 | * @param string|null $type |
278 | 278 | * @return mixed |
279 | 279 | */ |
280 | - protected function getSchemaType($type = null) |
|
280 | + protected function getSchemaType( $type = null ) |
|
281 | 281 | { |
282 | - if (!is_string($type)) { |
|
283 | - $type = $this->getSchemaOption('type', 'LocalBusiness'); |
|
282 | + if( !is_string( $type ) ) { |
|
283 | + $type = $this->getSchemaOption( 'type', 'LocalBusiness' ); |
|
284 | 284 | } |
285 | - $className = Helper::buildClassName($type, 'Modules\Schema'); |
|
286 | - return class_exists($className) |
|
285 | + $className = Helper::buildClassName( $type, 'Modules\Schema' ); |
|
286 | + return class_exists( $className ) |
|
287 | 287 | ? new $className() |
288 | - : new UnknownType($type); |
|
288 | + : new UnknownType( $type ); |
|
289 | 289 | } |
290 | 290 | |
291 | 291 | /** |
@@ -294,19 +294,19 @@ discard block |
||
294 | 294 | protected function getThingDescription() |
295 | 295 | { |
296 | 296 | $post = get_post(); |
297 | - $text = Arr::get($post, 'post_excerpt'); |
|
298 | - if (empty($text)) { |
|
299 | - $text = Arr::get($post, 'post_content'); |
|
297 | + $text = Arr::get( $post, 'post_excerpt' ); |
|
298 | + if( empty($text) ) { |
|
299 | + $text = Arr::get( $post, 'post_content' ); |
|
300 | 300 | } |
301 | - if (function_exists('excerpt_remove_blocks')) { |
|
302 | - $text = excerpt_remove_blocks($text); |
|
301 | + if( function_exists( 'excerpt_remove_blocks' ) ) { |
|
302 | + $text = excerpt_remove_blocks( $text ); |
|
303 | 303 | } |
304 | - $text = strip_shortcodes($text); |
|
305 | - $text = wpautop($text); |
|
306 | - $text = wptexturize($text); |
|
307 | - $text = wp_strip_all_tags($text); |
|
308 | - $text = str_replace(']]>', ']]>', $text); |
|
309 | - return wp_trim_words($text, apply_filters('excerpt_length', 55)); |
|
304 | + $text = strip_shortcodes( $text ); |
|
305 | + $text = wpautop( $text ); |
|
306 | + $text = wptexturize( $text ); |
|
307 | + $text = wp_strip_all_tags( $text ); |
|
308 | + $text = str_replace( ']]>', ']]>', $text ); |
|
309 | + return wp_trim_words( $text, apply_filters( 'excerpt_length', 55 ) ); |
|
310 | 310 | } |
311 | 311 | |
312 | 312 | /** |
@@ -314,7 +314,7 @@ discard block |
||
314 | 314 | */ |
315 | 315 | protected function getThingImage() |
316 | 316 | { |
317 | - return (string) get_the_post_thumbnail_url(null, 'large'); |
|
317 | + return (string)get_the_post_thumbnail_url( null, 'large' ); |
|
318 | 318 | } |
319 | 319 | |
320 | 320 | /** |
@@ -330,7 +330,7 @@ discard block |
||
330 | 330 | */ |
331 | 331 | protected function getThingUrl() |
332 | 332 | { |
333 | - return (string) get_the_permalink(); |
|
333 | + return (string)get_the_permalink(); |
|
334 | 334 | } |
335 | 335 | |
336 | 336 | /** |
@@ -338,7 +338,7 @@ discard block |
||
338 | 338 | * @param string $value |
339 | 339 | * @return string |
340 | 340 | */ |
341 | - protected function setAndGetKeyValue($option, $value) |
|
341 | + protected function setAndGetKeyValue( $option, $value ) |
|
342 | 342 | { |
343 | 343 | $this->keyValues[$option] = $value; |
344 | 344 | return $value; |