@@ -21,384 +21,384 @@ |
||
21 | 21 | |
22 | 22 | class SiteReviews |
23 | 23 | { |
24 | - /** |
|
25 | - * @var array |
|
26 | - */ |
|
27 | - public $args; |
|
24 | + /** |
|
25 | + * @var array |
|
26 | + */ |
|
27 | + public $args; |
|
28 | 28 | |
29 | - /** |
|
30 | - * @var Review |
|
31 | - */ |
|
32 | - public $current; |
|
29 | + /** |
|
30 | + * @var Review |
|
31 | + */ |
|
32 | + public $current; |
|
33 | 33 | |
34 | - /** |
|
35 | - * @var array |
|
36 | - */ |
|
37 | - public $options; |
|
34 | + /** |
|
35 | + * @var array |
|
36 | + */ |
|
37 | + public $options; |
|
38 | 38 | |
39 | - /** |
|
40 | - * @var Reviews |
|
41 | - */ |
|
42 | - protected $reviews; |
|
39 | + /** |
|
40 | + * @var Reviews |
|
41 | + */ |
|
42 | + protected $reviews; |
|
43 | 43 | |
44 | - /** |
|
45 | - * @param Reviews|null $reviews |
|
46 | - * @return ReviewsHtml |
|
47 | - */ |
|
48 | - public function build(array $args = [], $reviews = null) |
|
49 | - { |
|
50 | - $this->args = glsr(SiteReviewsDefaults::class)->merge($args); |
|
51 | - $this->options = Arr::flattenArray(glsr(OptionManager::class)->all()); |
|
52 | - $this->reviews = $reviews instanceof Reviews |
|
53 | - ? $reviews |
|
54 | - : glsr(ReviewManager::class)->get($this->args); |
|
55 | - $this->generateSchema(); |
|
56 | - return $this->buildReviews(); |
|
57 | - } |
|
44 | + /** |
|
45 | + * @param Reviews|null $reviews |
|
46 | + * @return ReviewsHtml |
|
47 | + */ |
|
48 | + public function build(array $args = [], $reviews = null) |
|
49 | + { |
|
50 | + $this->args = glsr(SiteReviewsDefaults::class)->merge($args); |
|
51 | + $this->options = Arr::flattenArray(glsr(OptionManager::class)->all()); |
|
52 | + $this->reviews = $reviews instanceof Reviews |
|
53 | + ? $reviews |
|
54 | + : glsr(ReviewManager::class)->get($this->args); |
|
55 | + $this->generateSchema(); |
|
56 | + return $this->buildReviews(); |
|
57 | + } |
|
58 | 58 | |
59 | - /** |
|
60 | - * @return ReviewHtml |
|
61 | - */ |
|
62 | - public function buildReview(Review $review) |
|
63 | - { |
|
64 | - $review = apply_filters('site-reviews/review/build/before', $review); |
|
65 | - $this->current = $review; |
|
66 | - $renderedFields = []; |
|
67 | - foreach ($review as $key => $value) { |
|
68 | - $method = Helper::buildMethodName($key, 'buildOption'); |
|
69 | - $field = method_exists($this, $method) |
|
70 | - ? $this->$method($key, $value) |
|
71 | - : false; |
|
72 | - $field = apply_filters('site-reviews/review/build/'.$key, $field, $value, $review, $this); |
|
73 | - if (false === $field) { |
|
74 | - continue; |
|
75 | - } |
|
76 | - $renderedFields[$key] = $field; |
|
77 | - } |
|
78 | - $this->wrap($renderedFields, $review); |
|
79 | - $renderedFields = apply_filters('site-reviews/review/build/after', $renderedFields, $review, $this); |
|
80 | - $this->current = null; |
|
81 | - return new ReviewHtml($review, (array) $renderedFields); |
|
82 | - } |
|
59 | + /** |
|
60 | + * @return ReviewHtml |
|
61 | + */ |
|
62 | + public function buildReview(Review $review) |
|
63 | + { |
|
64 | + $review = apply_filters('site-reviews/review/build/before', $review); |
|
65 | + $this->current = $review; |
|
66 | + $renderedFields = []; |
|
67 | + foreach ($review as $key => $value) { |
|
68 | + $method = Helper::buildMethodName($key, 'buildOption'); |
|
69 | + $field = method_exists($this, $method) |
|
70 | + ? $this->$method($key, $value) |
|
71 | + : false; |
|
72 | + $field = apply_filters('site-reviews/review/build/'.$key, $field, $value, $review, $this); |
|
73 | + if (false === $field) { |
|
74 | + continue; |
|
75 | + } |
|
76 | + $renderedFields[$key] = $field; |
|
77 | + } |
|
78 | + $this->wrap($renderedFields, $review); |
|
79 | + $renderedFields = apply_filters('site-reviews/review/build/after', $renderedFields, $review, $this); |
|
80 | + $this->current = null; |
|
81 | + return new ReviewHtml($review, (array) $renderedFields); |
|
82 | + } |
|
83 | 83 | |
84 | - /** |
|
85 | - * @return ReviewsHtml |
|
86 | - */ |
|
87 | - public function buildReviews() |
|
88 | - { |
|
89 | - $renderedReviews = []; |
|
90 | - foreach ($this->reviews as $index => $review) { |
|
91 | - $renderedReviews[] = $this->buildReview($review); |
|
92 | - } |
|
93 | - return new ReviewsHtml($renderedReviews, $this->reviews->max_num_pages, $this->args); |
|
94 | - } |
|
84 | + /** |
|
85 | + * @return ReviewsHtml |
|
86 | + */ |
|
87 | + public function buildReviews() |
|
88 | + { |
|
89 | + $renderedReviews = []; |
|
90 | + foreach ($this->reviews as $index => $review) { |
|
91 | + $renderedReviews[] = $this->buildReview($review); |
|
92 | + } |
|
93 | + return new ReviewsHtml($renderedReviews, $this->reviews->max_num_pages, $this->args); |
|
94 | + } |
|
95 | 95 | |
96 | - /** |
|
97 | - * @return void |
|
98 | - */ |
|
99 | - public function generateSchema() |
|
100 | - { |
|
101 | - if (!wp_validate_boolean($this->args['schema'])) { |
|
102 | - return; |
|
103 | - } |
|
104 | - glsr(Schema::class)->store( |
|
105 | - glsr(Schema::class)->build($this->args) |
|
106 | - ); |
|
107 | - } |
|
96 | + /** |
|
97 | + * @return void |
|
98 | + */ |
|
99 | + public function generateSchema() |
|
100 | + { |
|
101 | + if (!wp_validate_boolean($this->args['schema'])) { |
|
102 | + return; |
|
103 | + } |
|
104 | + glsr(Schema::class)->store( |
|
105 | + glsr(Schema::class)->build($this->args) |
|
106 | + ); |
|
107 | + } |
|
108 | 108 | |
109 | - /** |
|
110 | - * @param string $text |
|
111 | - * @return string |
|
112 | - */ |
|
113 | - public function getExcerpt($text) |
|
114 | - { |
|
115 | - $limit = intval($this->getOption('settings.reviews.excerpts_length', 55)); |
|
116 | - $split = extension_loaded('intl') |
|
117 | - ? $this->getExcerptIntlSplit($text, $limit) |
|
118 | - : $this->getExcerptSplit($text, $limit); |
|
119 | - $hiddenText = substr($text, $split); |
|
120 | - if (!empty($hiddenText)) { |
|
121 | - $showMore = glsr(Builder::class)->span($hiddenText, [ |
|
122 | - 'class' => 'glsr-hidden glsr-hidden-text', |
|
123 | - 'data-show-less' => __('Show less', 'site-reviews'), |
|
124 | - 'data-show-more' => __('Show more', 'site-reviews'), |
|
125 | - ]); |
|
126 | - $text = ltrim(substr($text, 0, $split)).$showMore; |
|
127 | - } |
|
128 | - return $text; |
|
129 | - } |
|
109 | + /** |
|
110 | + * @param string $text |
|
111 | + * @return string |
|
112 | + */ |
|
113 | + public function getExcerpt($text) |
|
114 | + { |
|
115 | + $limit = intval($this->getOption('settings.reviews.excerpts_length', 55)); |
|
116 | + $split = extension_loaded('intl') |
|
117 | + ? $this->getExcerptIntlSplit($text, $limit) |
|
118 | + : $this->getExcerptSplit($text, $limit); |
|
119 | + $hiddenText = substr($text, $split); |
|
120 | + if (!empty($hiddenText)) { |
|
121 | + $showMore = glsr(Builder::class)->span($hiddenText, [ |
|
122 | + 'class' => 'glsr-hidden glsr-hidden-text', |
|
123 | + 'data-show-less' => __('Show less', 'site-reviews'), |
|
124 | + 'data-show-more' => __('Show more', 'site-reviews'), |
|
125 | + ]); |
|
126 | + $text = ltrim(substr($text, 0, $split)).$showMore; |
|
127 | + } |
|
128 | + return $text; |
|
129 | + } |
|
130 | 130 | |
131 | - /** |
|
132 | - * @param string $key |
|
133 | - * @param string $path |
|
134 | - * @return bool |
|
135 | - */ |
|
136 | - public function isHidden($key, $path = '') |
|
137 | - { |
|
138 | - $isOptionEnabled = !empty($path) |
|
139 | - ? $this->isOptionEnabled($path) |
|
140 | - : true; |
|
141 | - return in_array($key, $this->args['hide']) || !$isOptionEnabled; |
|
142 | - } |
|
131 | + /** |
|
132 | + * @param string $key |
|
133 | + * @param string $path |
|
134 | + * @return bool |
|
135 | + */ |
|
136 | + public function isHidden($key, $path = '') |
|
137 | + { |
|
138 | + $isOptionEnabled = !empty($path) |
|
139 | + ? $this->isOptionEnabled($path) |
|
140 | + : true; |
|
141 | + return in_array($key, $this->args['hide']) || !$isOptionEnabled; |
|
142 | + } |
|
143 | 143 | |
144 | - /** |
|
145 | - * @param string $key |
|
146 | - * @param string $value |
|
147 | - * @return bool |
|
148 | - */ |
|
149 | - public function isHiddenOrEmpty($key, $value) |
|
150 | - { |
|
151 | - return $this->isHidden($key) || empty($value); |
|
152 | - } |
|
144 | + /** |
|
145 | + * @param string $key |
|
146 | + * @param string $value |
|
147 | + * @return bool |
|
148 | + */ |
|
149 | + public function isHiddenOrEmpty($key, $value) |
|
150 | + { |
|
151 | + return $this->isHidden($key) || empty($value); |
|
152 | + } |
|
153 | 153 | |
154 | - /** |
|
155 | - * @param string $text |
|
156 | - * @return string |
|
157 | - */ |
|
158 | - public function normalizeText($text) |
|
159 | - { |
|
160 | - $text = wp_kses($text, wp_kses_allowed_html()); |
|
161 | - $text = convert_smilies(strip_shortcodes($text)); |
|
162 | - $text = str_replace(']]>', ']]>', $text); |
|
163 | - $text = preg_replace('/(\R){2,}/u', '$1', $text); |
|
164 | - if ($this->isOptionEnabled('settings.reviews.excerpts')) { |
|
165 | - $text = $this->getExcerpt($text); |
|
166 | - } |
|
167 | - return wptexturize(nl2br($text)); |
|
168 | - } |
|
154 | + /** |
|
155 | + * @param string $text |
|
156 | + * @return string |
|
157 | + */ |
|
158 | + public function normalizeText($text) |
|
159 | + { |
|
160 | + $text = wp_kses($text, wp_kses_allowed_html()); |
|
161 | + $text = convert_smilies(strip_shortcodes($text)); |
|
162 | + $text = str_replace(']]>', ']]>', $text); |
|
163 | + $text = preg_replace('/(\R){2,}/u', '$1', $text); |
|
164 | + if ($this->isOptionEnabled('settings.reviews.excerpts')) { |
|
165 | + $text = $this->getExcerpt($text); |
|
166 | + } |
|
167 | + return wptexturize(nl2br($text)); |
|
168 | + } |
|
169 | 169 | |
170 | - /** |
|
171 | - * @param string $key |
|
172 | - * @param string $value |
|
173 | - * @return void|string |
|
174 | - */ |
|
175 | - protected function buildOptionAssignedTo($key, $value) |
|
176 | - { |
|
177 | - if ($this->isHidden($key, 'settings.reviews.assigned_links')) { |
|
178 | - return; |
|
179 | - } |
|
180 | - $post = get_post(glsr(Multilingual::class)->getPostId($value)); |
|
181 | - if (empty($post->ID)) { |
|
182 | - return; |
|
183 | - } |
|
184 | - $permalink = glsr(Builder::class)->a(get_the_title($post->ID), [ |
|
185 | - 'href' => get_the_permalink($post->ID), |
|
186 | - ]); |
|
187 | - $assignedTo = sprintf(__('Review of %s', 'site-reviews'), $permalink); |
|
188 | - return '<span>'.$assignedTo.'</span>'; |
|
189 | - } |
|
170 | + /** |
|
171 | + * @param string $key |
|
172 | + * @param string $value |
|
173 | + * @return void|string |
|
174 | + */ |
|
175 | + protected function buildOptionAssignedTo($key, $value) |
|
176 | + { |
|
177 | + if ($this->isHidden($key, 'settings.reviews.assigned_links')) { |
|
178 | + return; |
|
179 | + } |
|
180 | + $post = get_post(glsr(Multilingual::class)->getPostId($value)); |
|
181 | + if (empty($post->ID)) { |
|
182 | + return; |
|
183 | + } |
|
184 | + $permalink = glsr(Builder::class)->a(get_the_title($post->ID), [ |
|
185 | + 'href' => get_the_permalink($post->ID), |
|
186 | + ]); |
|
187 | + $assignedTo = sprintf(__('Review of %s', 'site-reviews'), $permalink); |
|
188 | + return '<span>'.$assignedTo.'</span>'; |
|
189 | + } |
|
190 | 190 | |
191 | - /** |
|
192 | - * @param string $key |
|
193 | - * @param string $value |
|
194 | - * @return void|string |
|
195 | - */ |
|
196 | - protected function buildOptionAuthor($key, $value) |
|
197 | - { |
|
198 | - if (!$this->isHidden($key)) { |
|
199 | - $name = Str::convertName( |
|
200 | - $value, |
|
201 | - glsr_get_option('reviews.name.format'), |
|
202 | - glsr_get_option('reviews.name.initial') |
|
203 | - ); |
|
204 | - return '<span>'.$name.'</span>'; |
|
205 | - } |
|
206 | - } |
|
191 | + /** |
|
192 | + * @param string $key |
|
193 | + * @param string $value |
|
194 | + * @return void|string |
|
195 | + */ |
|
196 | + protected function buildOptionAuthor($key, $value) |
|
197 | + { |
|
198 | + if (!$this->isHidden($key)) { |
|
199 | + $name = Str::convertName( |
|
200 | + $value, |
|
201 | + glsr_get_option('reviews.name.format'), |
|
202 | + glsr_get_option('reviews.name.initial') |
|
203 | + ); |
|
204 | + return '<span>'.$name.'</span>'; |
|
205 | + } |
|
206 | + } |
|
207 | 207 | |
208 | - /** |
|
209 | - * @param string $key |
|
210 | - * @param string $value |
|
211 | - * @return void|string |
|
212 | - */ |
|
213 | - protected function buildOptionAvatar($key, $value) |
|
214 | - { |
|
215 | - if ($this->isHidden($key, 'settings.reviews.avatars')) { |
|
216 | - return; |
|
217 | - } |
|
218 | - $size = $this->getOption('settings.reviews.avatars_size', 40); |
|
219 | - return glsr(Builder::class)->img([ |
|
220 | - 'height' => $size, |
|
221 | - 'src' => $this->generateAvatar($value), |
|
222 | - 'style' => sprintf('width:%1$spx; height:%1$spx;', $size), |
|
223 | - 'width' => $size, |
|
224 | - ]); |
|
225 | - } |
|
208 | + /** |
|
209 | + * @param string $key |
|
210 | + * @param string $value |
|
211 | + * @return void|string |
|
212 | + */ |
|
213 | + protected function buildOptionAvatar($key, $value) |
|
214 | + { |
|
215 | + if ($this->isHidden($key, 'settings.reviews.avatars')) { |
|
216 | + return; |
|
217 | + } |
|
218 | + $size = $this->getOption('settings.reviews.avatars_size', 40); |
|
219 | + return glsr(Builder::class)->img([ |
|
220 | + 'height' => $size, |
|
221 | + 'src' => $this->generateAvatar($value), |
|
222 | + 'style' => sprintf('width:%1$spx; height:%1$spx;', $size), |
|
223 | + 'width' => $size, |
|
224 | + ]); |
|
225 | + } |
|
226 | 226 | |
227 | - /** |
|
228 | - * @param string $key |
|
229 | - * @param string $value |
|
230 | - * @return void|string |
|
231 | - */ |
|
232 | - protected function buildOptionContent($key, $value) |
|
233 | - { |
|
234 | - $text = $this->normalizeText($value); |
|
235 | - if (!$this->isHiddenOrEmpty($key, $text)) { |
|
236 | - return '<p>'.$text.'</p>'; |
|
237 | - } |
|
238 | - } |
|
227 | + /** |
|
228 | + * @param string $key |
|
229 | + * @param string $value |
|
230 | + * @return void|string |
|
231 | + */ |
|
232 | + protected function buildOptionContent($key, $value) |
|
233 | + { |
|
234 | + $text = $this->normalizeText($value); |
|
235 | + if (!$this->isHiddenOrEmpty($key, $text)) { |
|
236 | + return '<p>'.$text.'</p>'; |
|
237 | + } |
|
238 | + } |
|
239 | 239 | |
240 | - /** |
|
241 | - * @param string $key |
|
242 | - * @param string $value |
|
243 | - * @return void|string |
|
244 | - */ |
|
245 | - protected function buildOptionDate($key, $value) |
|
246 | - { |
|
247 | - if ($this->isHidden($key)) { |
|
248 | - return; |
|
249 | - } |
|
250 | - $dateFormat = $this->getOption('settings.reviews.date.format', 'default'); |
|
251 | - if ('relative' == $dateFormat) { |
|
252 | - $date = glsr(Date::class)->relative($value); |
|
253 | - } else { |
|
254 | - $format = 'custom' == $dateFormat |
|
255 | - ? $this->getOption('settings.reviews.date.custom', 'M j, Y') |
|
256 | - : glsr(OptionManager::class)->getWP('date_format', 'F j, Y'); |
|
257 | - $date = date_i18n($format, strtotime($value)); |
|
258 | - } |
|
259 | - return '<span>'.$date.'</span>'; |
|
260 | - } |
|
240 | + /** |
|
241 | + * @param string $key |
|
242 | + * @param string $value |
|
243 | + * @return void|string |
|
244 | + */ |
|
245 | + protected function buildOptionDate($key, $value) |
|
246 | + { |
|
247 | + if ($this->isHidden($key)) { |
|
248 | + return; |
|
249 | + } |
|
250 | + $dateFormat = $this->getOption('settings.reviews.date.format', 'default'); |
|
251 | + if ('relative' == $dateFormat) { |
|
252 | + $date = glsr(Date::class)->relative($value); |
|
253 | + } else { |
|
254 | + $format = 'custom' == $dateFormat |
|
255 | + ? $this->getOption('settings.reviews.date.custom', 'M j, Y') |
|
256 | + : glsr(OptionManager::class)->getWP('date_format', 'F j, Y'); |
|
257 | + $date = date_i18n($format, strtotime($value)); |
|
258 | + } |
|
259 | + return '<span>'.$date.'</span>'; |
|
260 | + } |
|
261 | 261 | |
262 | - /** |
|
263 | - * @param string $key |
|
264 | - * @param string $value |
|
265 | - * @return void|string |
|
266 | - */ |
|
267 | - protected function buildOptionRating($key, $value) |
|
268 | - { |
|
269 | - if (!$this->isHiddenOrEmpty($key, $value)) { |
|
270 | - return glsr_star_rating($value); |
|
271 | - } |
|
272 | - } |
|
262 | + /** |
|
263 | + * @param string $key |
|
264 | + * @param string $value |
|
265 | + * @return void|string |
|
266 | + */ |
|
267 | + protected function buildOptionRating($key, $value) |
|
268 | + { |
|
269 | + if (!$this->isHiddenOrEmpty($key, $value)) { |
|
270 | + return glsr_star_rating($value); |
|
271 | + } |
|
272 | + } |
|
273 | 273 | |
274 | - /** |
|
275 | - * @param string $key |
|
276 | - * @param string $value |
|
277 | - * @return void|string |
|
278 | - */ |
|
279 | - protected function buildOptionResponse($key, $value) |
|
280 | - { |
|
281 | - if ($this->isHiddenOrEmpty($key, $value)) { |
|
282 | - return; |
|
283 | - } |
|
284 | - $title = sprintf(__('Response from %s', 'site-reviews'), get_bloginfo('name')); |
|
285 | - $text = $this->normalizeText($value); |
|
286 | - $text = '<p><strong>'.$title.'</strong></p><p>'.$text.'</p>'; |
|
287 | - $response = glsr(Builder::class)->div($text, ['class' => 'glsr-review-response-inner']); |
|
288 | - $background = glsr(Builder::class)->div(['class' => 'glsr-review-response-background']); |
|
289 | - return $response.$background; |
|
290 | - } |
|
274 | + /** |
|
275 | + * @param string $key |
|
276 | + * @param string $value |
|
277 | + * @return void|string |
|
278 | + */ |
|
279 | + protected function buildOptionResponse($key, $value) |
|
280 | + { |
|
281 | + if ($this->isHiddenOrEmpty($key, $value)) { |
|
282 | + return; |
|
283 | + } |
|
284 | + $title = sprintf(__('Response from %s', 'site-reviews'), get_bloginfo('name')); |
|
285 | + $text = $this->normalizeText($value); |
|
286 | + $text = '<p><strong>'.$title.'</strong></p><p>'.$text.'</p>'; |
|
287 | + $response = glsr(Builder::class)->div($text, ['class' => 'glsr-review-response-inner']); |
|
288 | + $background = glsr(Builder::class)->div(['class' => 'glsr-review-response-background']); |
|
289 | + return $response.$background; |
|
290 | + } |
|
291 | 291 | |
292 | - /** |
|
293 | - * @param string $key |
|
294 | - * @param string $value |
|
295 | - * @return void|string |
|
296 | - */ |
|
297 | - protected function buildOptionTitle($key, $value) |
|
298 | - { |
|
299 | - if ($this->isHidden($key)) { |
|
300 | - return; |
|
301 | - } |
|
302 | - if (empty($value)) { |
|
303 | - $value = __('No Title', 'site-reviews'); |
|
304 | - } |
|
305 | - return '<h3>'.$value.'</h3>'; |
|
306 | - } |
|
292 | + /** |
|
293 | + * @param string $key |
|
294 | + * @param string $value |
|
295 | + * @return void|string |
|
296 | + */ |
|
297 | + protected function buildOptionTitle($key, $value) |
|
298 | + { |
|
299 | + if ($this->isHidden($key)) { |
|
300 | + return; |
|
301 | + } |
|
302 | + if (empty($value)) { |
|
303 | + $value = __('No Title', 'site-reviews'); |
|
304 | + } |
|
305 | + return '<h3>'.$value.'</h3>'; |
|
306 | + } |
|
307 | 307 | |
308 | - /** |
|
309 | - * @param string $avatarUrl |
|
310 | - * @return string |
|
311 | - */ |
|
312 | - protected function generateAvatar($avatarUrl) |
|
313 | - { |
|
314 | - if (!$this->isOptionEnabled('settings.reviews.avatars_regenerate') || 'local' != $this->current->review_type) { |
|
315 | - return $avatarUrl; |
|
316 | - } |
|
317 | - if ($this->current->user_id) { |
|
318 | - $authorIdOrEmail = get_the_author_meta('ID', $this->current->user_id); |
|
319 | - } |
|
320 | - if (empty($authorIdOrEmail)) { |
|
321 | - $authorIdOrEmail = $this->current->email; |
|
322 | - } |
|
323 | - if ($newAvatar = get_avatar_url($authorIdOrEmail)) { |
|
324 | - return $newAvatar; |
|
325 | - } |
|
326 | - return $avatarUrl; |
|
327 | - } |
|
308 | + /** |
|
309 | + * @param string $avatarUrl |
|
310 | + * @return string |
|
311 | + */ |
|
312 | + protected function generateAvatar($avatarUrl) |
|
313 | + { |
|
314 | + if (!$this->isOptionEnabled('settings.reviews.avatars_regenerate') || 'local' != $this->current->review_type) { |
|
315 | + return $avatarUrl; |
|
316 | + } |
|
317 | + if ($this->current->user_id) { |
|
318 | + $authorIdOrEmail = get_the_author_meta('ID', $this->current->user_id); |
|
319 | + } |
|
320 | + if (empty($authorIdOrEmail)) { |
|
321 | + $authorIdOrEmail = $this->current->email; |
|
322 | + } |
|
323 | + if ($newAvatar = get_avatar_url($authorIdOrEmail)) { |
|
324 | + return $newAvatar; |
|
325 | + } |
|
326 | + return $avatarUrl; |
|
327 | + } |
|
328 | 328 | |
329 | - /** |
|
330 | - * @param string $text |
|
331 | - * @param int $limit |
|
332 | - * @return int |
|
333 | - */ |
|
334 | - protected function getExcerptIntlSplit($text, $limit) |
|
335 | - { |
|
336 | - $words = IntlRuleBasedBreakIterator::createWordInstance(''); |
|
337 | - $words->setText($text); |
|
338 | - $count = 0; |
|
339 | - foreach ($words as $offset) { |
|
340 | - if (IntlRuleBasedBreakIterator::WORD_NONE === $words->getRuleStatus()) { |
|
341 | - continue; |
|
342 | - } |
|
343 | - ++$count; |
|
344 | - if ($count != $limit) { |
|
345 | - continue; |
|
346 | - } |
|
347 | - return $offset; |
|
348 | - } |
|
349 | - return strlen($text); |
|
350 | - } |
|
329 | + /** |
|
330 | + * @param string $text |
|
331 | + * @param int $limit |
|
332 | + * @return int |
|
333 | + */ |
|
334 | + protected function getExcerptIntlSplit($text, $limit) |
|
335 | + { |
|
336 | + $words = IntlRuleBasedBreakIterator::createWordInstance(''); |
|
337 | + $words->setText($text); |
|
338 | + $count = 0; |
|
339 | + foreach ($words as $offset) { |
|
340 | + if (IntlRuleBasedBreakIterator::WORD_NONE === $words->getRuleStatus()) { |
|
341 | + continue; |
|
342 | + } |
|
343 | + ++$count; |
|
344 | + if ($count != $limit) { |
|
345 | + continue; |
|
346 | + } |
|
347 | + return $offset; |
|
348 | + } |
|
349 | + return strlen($text); |
|
350 | + } |
|
351 | 351 | |
352 | - /** |
|
353 | - * @param string $text |
|
354 | - * @param int $limit |
|
355 | - * @return int |
|
356 | - */ |
|
357 | - protected function getExcerptSplit($text, $limit) |
|
358 | - { |
|
359 | - if (str_word_count($text, 0) > $limit) { |
|
360 | - $words = array_keys(str_word_count($text, 2)); |
|
361 | - return $words[$limit]; |
|
362 | - } |
|
363 | - return strlen($text); |
|
364 | - } |
|
352 | + /** |
|
353 | + * @param string $text |
|
354 | + * @param int $limit |
|
355 | + * @return int |
|
356 | + */ |
|
357 | + protected function getExcerptSplit($text, $limit) |
|
358 | + { |
|
359 | + if (str_word_count($text, 0) > $limit) { |
|
360 | + $words = array_keys(str_word_count($text, 2)); |
|
361 | + return $words[$limit]; |
|
362 | + } |
|
363 | + return strlen($text); |
|
364 | + } |
|
365 | 365 | |
366 | - /** |
|
367 | - * @param string $path |
|
368 | - * @param mixed $fallback |
|
369 | - * @return mixed |
|
370 | - */ |
|
371 | - protected function getOption($path, $fallback = '') |
|
372 | - { |
|
373 | - if (array_key_exists($path, $this->options)) { |
|
374 | - return $this->options[$path]; |
|
375 | - } |
|
376 | - return $fallback; |
|
377 | - } |
|
366 | + /** |
|
367 | + * @param string $path |
|
368 | + * @param mixed $fallback |
|
369 | + * @return mixed |
|
370 | + */ |
|
371 | + protected function getOption($path, $fallback = '') |
|
372 | + { |
|
373 | + if (array_key_exists($path, $this->options)) { |
|
374 | + return $this->options[$path]; |
|
375 | + } |
|
376 | + return $fallback; |
|
377 | + } |
|
378 | 378 | |
379 | - /** |
|
380 | - * @param string $path |
|
381 | - * @return bool |
|
382 | - */ |
|
383 | - protected function isOptionEnabled($path) |
|
384 | - { |
|
385 | - return 'yes' == $this->getOption($path); |
|
386 | - } |
|
379 | + /** |
|
380 | + * @param string $path |
|
381 | + * @return bool |
|
382 | + */ |
|
383 | + protected function isOptionEnabled($path) |
|
384 | + { |
|
385 | + return 'yes' == $this->getOption($path); |
|
386 | + } |
|
387 | 387 | |
388 | - /** |
|
389 | - * @return void |
|
390 | - */ |
|
391 | - protected function wrap(array &$renderedFields, Review $review) |
|
392 | - { |
|
393 | - $renderedFields = apply_filters('site-reviews/review/wrap', $renderedFields, $review, $this); |
|
394 | - array_walk($renderedFields, function (&$value, $key) use ($review) { |
|
395 | - $value = apply_filters('site-reviews/review/wrap/'.$key, $value, $review); |
|
396 | - if (empty($value)) { |
|
397 | - return; |
|
398 | - } |
|
399 | - $value = glsr(Builder::class)->div($value, [ |
|
400 | - 'class' => 'glsr-review-'.$key, |
|
401 | - ]); |
|
402 | - }); |
|
403 | - } |
|
388 | + /** |
|
389 | + * @return void |
|
390 | + */ |
|
391 | + protected function wrap(array &$renderedFields, Review $review) |
|
392 | + { |
|
393 | + $renderedFields = apply_filters('site-reviews/review/wrap', $renderedFields, $review, $this); |
|
394 | + array_walk($renderedFields, function (&$value, $key) use ($review) { |
|
395 | + $value = apply_filters('site-reviews/review/wrap/'.$key, $value, $review); |
|
396 | + if (empty($value)) { |
|
397 | + return; |
|
398 | + } |
|
399 | + $value = glsr(Builder::class)->div($value, [ |
|
400 | + 'class' => 'glsr-review-'.$key, |
|
401 | + ]); |
|
402 | + }); |
|
403 | + } |
|
404 | 404 | } |
@@ -7,106 +7,106 @@ |
||
7 | 7 | |
8 | 8 | class Labels |
9 | 9 | { |
10 | - /** |
|
11 | - * @param string $translation |
|
12 | - * @param string $test |
|
13 | - * @return string |
|
14 | - */ |
|
15 | - public function filterPostStatusLabels($translation, $text) |
|
16 | - { |
|
17 | - $replacements = $this->getStatusLabels(); |
|
18 | - return array_key_exists($text, $replacements) |
|
19 | - ? $replacements[$text] |
|
20 | - : $translation; |
|
21 | - } |
|
10 | + /** |
|
11 | + * @param string $translation |
|
12 | + * @param string $test |
|
13 | + * @return string |
|
14 | + */ |
|
15 | + public function filterPostStatusLabels($translation, $text) |
|
16 | + { |
|
17 | + $replacements = $this->getStatusLabels(); |
|
18 | + return array_key_exists($text, $replacements) |
|
19 | + ? $replacements[$text] |
|
20 | + : $translation; |
|
21 | + } |
|
22 | 22 | |
23 | - /** |
|
24 | - * @return array |
|
25 | - */ |
|
26 | - public function filterUpdateMessages(array $messages) |
|
27 | - { |
|
28 | - $post = get_post(); |
|
29 | - if (!($post instanceof WP_Post)) { |
|
30 | - return; |
|
31 | - } |
|
32 | - $strings = $this->getReviewLabels(); |
|
33 | - $restored = filter_input(INPUT_GET, 'revision'); |
|
34 | - if ($revisionTitle = wp_post_revision_title(intval($restored), false)) { |
|
35 | - $restored = sprintf($strings['restored'], $revisionTitle); |
|
36 | - } |
|
37 | - $scheduled_date = date_i18n('M j, Y @ H:i', strtotime($post->post_date)); |
|
38 | - $messages[Application::POST_TYPE] = [ |
|
39 | - 1 => $strings['updated'], |
|
40 | - 4 => $strings['updated'], |
|
41 | - 5 => $restored, |
|
42 | - 6 => $strings['published'], |
|
43 | - 7 => $strings['saved'], |
|
44 | - 8 => $strings['submitted'], |
|
45 | - 9 => sprintf($strings['scheduled'], '<strong>'.$scheduled_date.'</strong>'), |
|
46 | - 10 => $strings['draft_updated'], |
|
47 | - 50 => $strings['approved'], |
|
48 | - 51 => $strings['unapproved'], |
|
49 | - 52 => $strings['reverted'], |
|
50 | - ]; |
|
51 | - return $messages; |
|
52 | - } |
|
23 | + /** |
|
24 | + * @return array |
|
25 | + */ |
|
26 | + public function filterUpdateMessages(array $messages) |
|
27 | + { |
|
28 | + $post = get_post(); |
|
29 | + if (!($post instanceof WP_Post)) { |
|
30 | + return; |
|
31 | + } |
|
32 | + $strings = $this->getReviewLabels(); |
|
33 | + $restored = filter_input(INPUT_GET, 'revision'); |
|
34 | + if ($revisionTitle = wp_post_revision_title(intval($restored), false)) { |
|
35 | + $restored = sprintf($strings['restored'], $revisionTitle); |
|
36 | + } |
|
37 | + $scheduled_date = date_i18n('M j, Y @ H:i', strtotime($post->post_date)); |
|
38 | + $messages[Application::POST_TYPE] = [ |
|
39 | + 1 => $strings['updated'], |
|
40 | + 4 => $strings['updated'], |
|
41 | + 5 => $restored, |
|
42 | + 6 => $strings['published'], |
|
43 | + 7 => $strings['saved'], |
|
44 | + 8 => $strings['submitted'], |
|
45 | + 9 => sprintf($strings['scheduled'], '<strong>'.$scheduled_date.'</strong>'), |
|
46 | + 10 => $strings['draft_updated'], |
|
47 | + 50 => $strings['approved'], |
|
48 | + 51 => $strings['unapproved'], |
|
49 | + 52 => $strings['reverted'], |
|
50 | + ]; |
|
51 | + return $messages; |
|
52 | + } |
|
53 | 53 | |
54 | - /** |
|
55 | - * @return void |
|
56 | - */ |
|
57 | - public function translatePostStatusLabels() |
|
58 | - { |
|
59 | - global $wp_scripts; |
|
60 | - $strings = [ |
|
61 | - 'savePending' => __('Save as Unapproved', 'site-reviews'), |
|
62 | - 'published' => __('Approved', 'site-reviews'), |
|
63 | - ]; |
|
64 | - if (isset($wp_scripts->registered['post']->extra['data'])) { |
|
65 | - $l10n = &$wp_scripts->registered['post']->extra['data']; |
|
66 | - foreach ($strings as $search => $replace) { |
|
67 | - $l10n = preg_replace('/("'.$search.'":")([^"]+)/u', '$1'.$replace, $l10n); |
|
68 | - } |
|
69 | - } |
|
70 | - } |
|
54 | + /** |
|
55 | + * @return void |
|
56 | + */ |
|
57 | + public function translatePostStatusLabels() |
|
58 | + { |
|
59 | + global $wp_scripts; |
|
60 | + $strings = [ |
|
61 | + 'savePending' => __('Save as Unapproved', 'site-reviews'), |
|
62 | + 'published' => __('Approved', 'site-reviews'), |
|
63 | + ]; |
|
64 | + if (isset($wp_scripts->registered['post']->extra['data'])) { |
|
65 | + $l10n = &$wp_scripts->registered['post']->extra['data']; |
|
66 | + foreach ($strings as $search => $replace) { |
|
67 | + $l10n = preg_replace('/("'.$search.'":")([^"]+)/u', '$1'.$replace, $l10n); |
|
68 | + } |
|
69 | + } |
|
70 | + } |
|
71 | 71 | |
72 | - /** |
|
73 | - * @return array |
|
74 | - */ |
|
75 | - protected function getReviewLabels() |
|
76 | - { |
|
77 | - return [ |
|
78 | - 'approved' => __('Review has been approved and published.', 'site-reviews'), |
|
79 | - 'draft_updated' => __('Review draft updated.', 'site-reviews'), |
|
80 | - 'preview' => __('Preview review', 'site-reviews'), |
|
81 | - 'published' => __('Review approved and published.', 'site-reviews'), |
|
82 | - 'restored' => __('Review restored to revision from %s.', 'site-reviews'), |
|
83 | - 'reverted' => __('Review has been reverted to its original submission state (title, content, and submission date).', 'site-reviews'), |
|
84 | - 'saved' => __('Review saved.', 'site-reviews'), |
|
85 | - 'scheduled' => __('Review scheduled for: %s.', 'site-reviews'), |
|
86 | - 'submitted' => __('Review submitted.', 'site-reviews'), |
|
87 | - 'unapproved' => __('Review has been unapproved and is now pending.', 'site-reviews'), |
|
88 | - 'updated' => __('Review updated.', 'site-reviews'), |
|
89 | - 'view' => __('View review', 'site-reviews'), |
|
90 | - ]; |
|
91 | - } |
|
72 | + /** |
|
73 | + * @return array |
|
74 | + */ |
|
75 | + protected function getReviewLabels() |
|
76 | + { |
|
77 | + return [ |
|
78 | + 'approved' => __('Review has been approved and published.', 'site-reviews'), |
|
79 | + 'draft_updated' => __('Review draft updated.', 'site-reviews'), |
|
80 | + 'preview' => __('Preview review', 'site-reviews'), |
|
81 | + 'published' => __('Review approved and published.', 'site-reviews'), |
|
82 | + 'restored' => __('Review restored to revision from %s.', 'site-reviews'), |
|
83 | + 'reverted' => __('Review has been reverted to its original submission state (title, content, and submission date).', 'site-reviews'), |
|
84 | + 'saved' => __('Review saved.', 'site-reviews'), |
|
85 | + 'scheduled' => __('Review scheduled for: %s.', 'site-reviews'), |
|
86 | + 'submitted' => __('Review submitted.', 'site-reviews'), |
|
87 | + 'unapproved' => __('Review has been unapproved and is now pending.', 'site-reviews'), |
|
88 | + 'updated' => __('Review updated.', 'site-reviews'), |
|
89 | + 'view' => __('View review', 'site-reviews'), |
|
90 | + ]; |
|
91 | + } |
|
92 | 92 | |
93 | - /** |
|
94 | - * Store the labels to avoid unnecessary loops. |
|
95 | - * @return array |
|
96 | - */ |
|
97 | - protected function getStatusLabels() |
|
98 | - { |
|
99 | - static $labels; |
|
100 | - if (empty($labels)) { |
|
101 | - $labels = [ |
|
102 | - 'Pending' => __('Unapproved', 'site-reviews'), |
|
103 | - 'Pending Review' => __('Unapproved', 'site-reviews'), |
|
104 | - 'Privately Published' => __('Privately Approved', 'site-reviews'), |
|
105 | - 'Publish' => __('Approve', 'site-reviews'), |
|
106 | - 'Published' => __('Approved', 'site-reviews'), |
|
107 | - 'Save as Pending' => __('Save as Unapproved', 'site-reviews'), |
|
108 | - ]; |
|
109 | - } |
|
110 | - return $labels; |
|
111 | - } |
|
93 | + /** |
|
94 | + * Store the labels to avoid unnecessary loops. |
|
95 | + * @return array |
|
96 | + */ |
|
97 | + protected function getStatusLabels() |
|
98 | + { |
|
99 | + static $labels; |
|
100 | + if (empty($labels)) { |
|
101 | + $labels = [ |
|
102 | + 'Pending' => __('Unapproved', 'site-reviews'), |
|
103 | + 'Pending Review' => __('Unapproved', 'site-reviews'), |
|
104 | + 'Privately Published' => __('Privately Approved', 'site-reviews'), |
|
105 | + 'Publish' => __('Approve', 'site-reviews'), |
|
106 | + 'Published' => __('Approved', 'site-reviews'), |
|
107 | + 'Save as Pending' => __('Save as Unapproved', 'site-reviews'), |
|
108 | + ]; |
|
109 | + } |
|
110 | + return $labels; |
|
111 | + } |
|
112 | 112 | } |
@@ -7,115 +7,115 @@ |
||
7 | 7 | |
8 | 8 | class SiteReviewsFormBlock extends BlockGenerator |
9 | 9 | { |
10 | - /** |
|
11 | - * @return array |
|
12 | - */ |
|
13 | - public function attributes() |
|
14 | - { |
|
15 | - return [ |
|
16 | - 'assign_to' => [ |
|
17 | - 'default' => '', |
|
18 | - 'type' => 'string', |
|
19 | - ], |
|
20 | - 'category' => [ |
|
21 | - 'default' => '', |
|
22 | - 'type' => 'string', |
|
23 | - ], |
|
24 | - 'className' => [ |
|
25 | - 'default' => '', |
|
26 | - 'type' => 'string', |
|
27 | - ], |
|
28 | - 'hide' => [ |
|
29 | - 'default' => '', |
|
30 | - 'type' => 'string', |
|
31 | - ], |
|
32 | - 'id' => [ |
|
33 | - 'default' => '', |
|
34 | - 'type' => 'string', |
|
35 | - ], |
|
36 | - ]; |
|
37 | - } |
|
10 | + /** |
|
11 | + * @return array |
|
12 | + */ |
|
13 | + public function attributes() |
|
14 | + { |
|
15 | + return [ |
|
16 | + 'assign_to' => [ |
|
17 | + 'default' => '', |
|
18 | + 'type' => 'string', |
|
19 | + ], |
|
20 | + 'category' => [ |
|
21 | + 'default' => '', |
|
22 | + 'type' => 'string', |
|
23 | + ], |
|
24 | + 'className' => [ |
|
25 | + 'default' => '', |
|
26 | + 'type' => 'string', |
|
27 | + ], |
|
28 | + 'hide' => [ |
|
29 | + 'default' => '', |
|
30 | + 'type' => 'string', |
|
31 | + ], |
|
32 | + 'id' => [ |
|
33 | + 'default' => '', |
|
34 | + 'type' => 'string', |
|
35 | + ], |
|
36 | + ]; |
|
37 | + } |
|
38 | 38 | |
39 | - /** |
|
40 | - * @return string |
|
41 | - */ |
|
42 | - public function render(array $attributes) |
|
43 | - { |
|
44 | - $attributes['class'] = $attributes['className']; |
|
45 | - $shortcode = glsr(Shortcode::class); |
|
46 | - if ('edit' == filter_input(INPUT_GET, 'context')) { |
|
47 | - $this->filterFormFields(); |
|
48 | - $this->filterRatingField(); |
|
49 | - $this->filterShortcodeClass(); |
|
50 | - $this->filterSubmitButton(); |
|
51 | - if (!$this->hasVisibleFields($shortcode, $attributes)) { |
|
52 | - $this->filterInterpolation(); |
|
53 | - } |
|
54 | - } |
|
55 | - return $shortcode->buildShortcode($attributes); |
|
56 | - } |
|
39 | + /** |
|
40 | + * @return string |
|
41 | + */ |
|
42 | + public function render(array $attributes) |
|
43 | + { |
|
44 | + $attributes['class'] = $attributes['className']; |
|
45 | + $shortcode = glsr(Shortcode::class); |
|
46 | + if ('edit' == filter_input(INPUT_GET, 'context')) { |
|
47 | + $this->filterFormFields(); |
|
48 | + $this->filterRatingField(); |
|
49 | + $this->filterShortcodeClass(); |
|
50 | + $this->filterSubmitButton(); |
|
51 | + if (!$this->hasVisibleFields($shortcode, $attributes)) { |
|
52 | + $this->filterInterpolation(); |
|
53 | + } |
|
54 | + } |
|
55 | + return $shortcode->buildShortcode($attributes); |
|
56 | + } |
|
57 | 57 | |
58 | - /** |
|
59 | - * @return void |
|
60 | - */ |
|
61 | - protected function filterFormFields() |
|
62 | - { |
|
63 | - add_filter('site-reviews/config/forms/submission-form', function (array $config) { |
|
64 | - array_walk($config, function (&$field) { |
|
65 | - $field['disabled'] = true; |
|
66 | - $field['tabindex'] = '-1'; |
|
67 | - }); |
|
68 | - return $config; |
|
69 | - }); |
|
70 | - } |
|
58 | + /** |
|
59 | + * @return void |
|
60 | + */ |
|
61 | + protected function filterFormFields() |
|
62 | + { |
|
63 | + add_filter('site-reviews/config/forms/submission-form', function (array $config) { |
|
64 | + array_walk($config, function (&$field) { |
|
65 | + $field['disabled'] = true; |
|
66 | + $field['tabindex'] = '-1'; |
|
67 | + }); |
|
68 | + return $config; |
|
69 | + }); |
|
70 | + } |
|
71 | 71 | |
72 | - /** |
|
73 | - * @return void |
|
74 | - */ |
|
75 | - protected function filterInterpolation() |
|
76 | - { |
|
77 | - add_filter('site-reviews/interpolate/reviews-form', function ($context) { |
|
78 | - $context['class'] = 'glsr-default glsr-block-disabled'; |
|
79 | - $context['fields'] = __('You have hidden all of the fields for this block.', 'site-reviews'); |
|
80 | - $context['response'] = ''; |
|
81 | - $context['submit_button'] = ''; |
|
82 | - return $context; |
|
83 | - }); |
|
84 | - } |
|
72 | + /** |
|
73 | + * @return void |
|
74 | + */ |
|
75 | + protected function filterInterpolation() |
|
76 | + { |
|
77 | + add_filter('site-reviews/interpolate/reviews-form', function ($context) { |
|
78 | + $context['class'] = 'glsr-default glsr-block-disabled'; |
|
79 | + $context['fields'] = __('You have hidden all of the fields for this block.', 'site-reviews'); |
|
80 | + $context['response'] = ''; |
|
81 | + $context['submit_button'] = ''; |
|
82 | + return $context; |
|
83 | + }); |
|
84 | + } |
|
85 | 85 | |
86 | - /** |
|
87 | - * @return void |
|
88 | - */ |
|
89 | - protected function filterRatingField() |
|
90 | - { |
|
91 | - add_filter('site-reviews/rendered/field', function ($html, $type, $args) { |
|
92 | - if ('rating' == $args['path']) { |
|
93 | - $stars = '<span class="glsr-stars">'; |
|
94 | - $stars.= str_repeat('<span class="glsr-star glsr-star-empty" aria-hidden="true"></span>', (int) glsr()->constant('MAX_RATING', Rating::class)); |
|
95 | - $stars.= '</span>'; |
|
96 | - $html = preg_replace('/(.*)(<select.*)(<\/select>)(.*)/u', '$1'.$stars.'$4', $html); |
|
97 | - } |
|
98 | - return $html; |
|
99 | - }, 10, 3); |
|
100 | - } |
|
86 | + /** |
|
87 | + * @return void |
|
88 | + */ |
|
89 | + protected function filterRatingField() |
|
90 | + { |
|
91 | + add_filter('site-reviews/rendered/field', function ($html, $type, $args) { |
|
92 | + if ('rating' == $args['path']) { |
|
93 | + $stars = '<span class="glsr-stars">'; |
|
94 | + $stars.= str_repeat('<span class="glsr-star glsr-star-empty" aria-hidden="true"></span>', (int) glsr()->constant('MAX_RATING', Rating::class)); |
|
95 | + $stars.= '</span>'; |
|
96 | + $html = preg_replace('/(.*)(<select.*)(<\/select>)(.*)/u', '$1'.$stars.'$4', $html); |
|
97 | + } |
|
98 | + return $html; |
|
99 | + }, 10, 3); |
|
100 | + } |
|
101 | 101 | |
102 | - /** |
|
103 | - * @return void |
|
104 | - */ |
|
105 | - protected function filterShortcodeClass() |
|
106 | - { |
|
107 | - add_filter('site-reviews/style', function () { |
|
108 | - return 'default'; |
|
109 | - }); |
|
110 | - } |
|
102 | + /** |
|
103 | + * @return void |
|
104 | + */ |
|
105 | + protected function filterShortcodeClass() |
|
106 | + { |
|
107 | + add_filter('site-reviews/style', function () { |
|
108 | + return 'default'; |
|
109 | + }); |
|
110 | + } |
|
111 | 111 | |
112 | - /** |
|
113 | - * @return void |
|
114 | - */ |
|
115 | - protected function filterSubmitButton() |
|
116 | - { |
|
117 | - add_filter('site-reviews/rendered/template/form/submit-button', function ($template) { |
|
118 | - return str_replace('type="submit"', 'tabindex="-1"', $template); |
|
119 | - }); |
|
120 | - } |
|
112 | + /** |
|
113 | + * @return void |
|
114 | + */ |
|
115 | + protected function filterSubmitButton() |
|
116 | + { |
|
117 | + add_filter('site-reviews/rendered/template/form/submit-button', function ($template) { |
|
118 | + return str_replace('type="submit"', 'tabindex="-1"', $template); |
|
119 | + }); |
|
120 | + } |
|
121 | 121 | } |
@@ -6,124 +6,124 @@ |
||
6 | 6 | |
7 | 7 | class SiteReviewsBlock extends BlockGenerator |
8 | 8 | { |
9 | - /** |
|
10 | - * @return array |
|
11 | - */ |
|
12 | - public function attributes() |
|
13 | - { |
|
14 | - return [ |
|
15 | - 'assigned_to' => [ |
|
16 | - 'default' => '', |
|
17 | - 'type' => 'string', |
|
18 | - ], |
|
19 | - 'category' => [ |
|
20 | - 'default' => '', |
|
21 | - 'type' => 'string', |
|
22 | - ], |
|
23 | - 'className' => [ |
|
24 | - 'default' => '', |
|
25 | - 'type' => 'string', |
|
26 | - ], |
|
27 | - 'display' => [ |
|
28 | - 'default' => 5, |
|
29 | - 'type' => 'number', |
|
30 | - ], |
|
31 | - 'hide' => [ |
|
32 | - 'default' => '', |
|
33 | - 'type' => 'string', |
|
34 | - ], |
|
35 | - 'id' => [ |
|
36 | - 'default' => '', |
|
37 | - 'type' => 'string', |
|
38 | - ], |
|
39 | - 'pagination' => [ |
|
40 | - 'default' => '', |
|
41 | - 'type' => 'string', |
|
42 | - ], |
|
43 | - 'post_id' => [ |
|
44 | - 'default' => '', |
|
45 | - 'type' => 'string', |
|
46 | - ], |
|
47 | - 'rating' => [ |
|
48 | - 'default' => 0, |
|
49 | - 'type' => 'number', |
|
50 | - ], |
|
51 | - 'schema' => [ |
|
52 | - 'default' => false, |
|
53 | - 'type' => 'boolean', |
|
54 | - ], |
|
55 | - 'type' => [ |
|
56 | - 'default' => 'local', |
|
57 | - 'type' => 'string', |
|
58 | - ], |
|
59 | - ]; |
|
60 | - } |
|
9 | + /** |
|
10 | + * @return array |
|
11 | + */ |
|
12 | + public function attributes() |
|
13 | + { |
|
14 | + return [ |
|
15 | + 'assigned_to' => [ |
|
16 | + 'default' => '', |
|
17 | + 'type' => 'string', |
|
18 | + ], |
|
19 | + 'category' => [ |
|
20 | + 'default' => '', |
|
21 | + 'type' => 'string', |
|
22 | + ], |
|
23 | + 'className' => [ |
|
24 | + 'default' => '', |
|
25 | + 'type' => 'string', |
|
26 | + ], |
|
27 | + 'display' => [ |
|
28 | + 'default' => 5, |
|
29 | + 'type' => 'number', |
|
30 | + ], |
|
31 | + 'hide' => [ |
|
32 | + 'default' => '', |
|
33 | + 'type' => 'string', |
|
34 | + ], |
|
35 | + 'id' => [ |
|
36 | + 'default' => '', |
|
37 | + 'type' => 'string', |
|
38 | + ], |
|
39 | + 'pagination' => [ |
|
40 | + 'default' => '', |
|
41 | + 'type' => 'string', |
|
42 | + ], |
|
43 | + 'post_id' => [ |
|
44 | + 'default' => '', |
|
45 | + 'type' => 'string', |
|
46 | + ], |
|
47 | + 'rating' => [ |
|
48 | + 'default' => 0, |
|
49 | + 'type' => 'number', |
|
50 | + ], |
|
51 | + 'schema' => [ |
|
52 | + 'default' => false, |
|
53 | + 'type' => 'boolean', |
|
54 | + ], |
|
55 | + 'type' => [ |
|
56 | + 'default' => 'local', |
|
57 | + 'type' => 'string', |
|
58 | + ], |
|
59 | + ]; |
|
60 | + } |
|
61 | 61 | |
62 | - /** |
|
63 | - * @return string |
|
64 | - */ |
|
65 | - public function render(array $attributes) |
|
66 | - { |
|
67 | - $attributes['class'] = $attributes['className']; |
|
68 | - $shortcode = glsr(Shortcode::class); |
|
69 | - if ('edit' == filter_input(INPUT_GET, 'context')) { |
|
70 | - $attributes = $this->normalize($attributes); |
|
71 | - $this->filterReviewLinks(); |
|
72 | - $this->filterShortcodeClass(); |
|
73 | - $this->filterShowMoreLinks('content'); |
|
74 | - $this->filterShowMoreLinks('response'); |
|
75 | - if (!$this->hasVisibleFields($shortcode, $attributes)) { |
|
76 | - $this->filterInterpolation(); |
|
77 | - } |
|
78 | - } |
|
79 | - return $shortcode->buildShortcode($attributes); |
|
80 | - } |
|
62 | + /** |
|
63 | + * @return string |
|
64 | + */ |
|
65 | + public function render(array $attributes) |
|
66 | + { |
|
67 | + $attributes['class'] = $attributes['className']; |
|
68 | + $shortcode = glsr(Shortcode::class); |
|
69 | + if ('edit' == filter_input(INPUT_GET, 'context')) { |
|
70 | + $attributes = $this->normalize($attributes); |
|
71 | + $this->filterReviewLinks(); |
|
72 | + $this->filterShortcodeClass(); |
|
73 | + $this->filterShowMoreLinks('content'); |
|
74 | + $this->filterShowMoreLinks('response'); |
|
75 | + if (!$this->hasVisibleFields($shortcode, $attributes)) { |
|
76 | + $this->filterInterpolation(); |
|
77 | + } |
|
78 | + } |
|
79 | + return $shortcode->buildShortcode($attributes); |
|
80 | + } |
|
81 | 81 | |
82 | - /** |
|
83 | - * @return void |
|
84 | - */ |
|
85 | - protected function filterInterpolation() |
|
86 | - { |
|
87 | - add_filter('site-reviews/interpolate/reviews', function ($context) { |
|
88 | - $context['class'] = 'glsr-default glsr-block-disabled'; |
|
89 | - $context['reviews'] = __('You have hidden all of the fields for this block.', 'site-reviews'); |
|
90 | - return $context; |
|
91 | - }); |
|
92 | - } |
|
82 | + /** |
|
83 | + * @return void |
|
84 | + */ |
|
85 | + protected function filterInterpolation() |
|
86 | + { |
|
87 | + add_filter('site-reviews/interpolate/reviews', function ($context) { |
|
88 | + $context['class'] = 'glsr-default glsr-block-disabled'; |
|
89 | + $context['reviews'] = __('You have hidden all of the fields for this block.', 'site-reviews'); |
|
90 | + return $context; |
|
91 | + }); |
|
92 | + } |
|
93 | 93 | |
94 | - /** |
|
95 | - * @return void |
|
96 | - */ |
|
97 | - protected function filterReviewLinks() |
|
98 | - { |
|
99 | - add_filter('site-reviews/rendered/template/reviews', function ($template) { |
|
100 | - return str_replace('<a', '<a tabindex="-1"', $template); |
|
101 | - }); |
|
102 | - } |
|
94 | + /** |
|
95 | + * @return void |
|
96 | + */ |
|
97 | + protected function filterReviewLinks() |
|
98 | + { |
|
99 | + add_filter('site-reviews/rendered/template/reviews', function ($template) { |
|
100 | + return str_replace('<a', '<a tabindex="-1"', $template); |
|
101 | + }); |
|
102 | + } |
|
103 | 103 | |
104 | - /** |
|
105 | - * @return void |
|
106 | - */ |
|
107 | - protected function filterShortcodeClass() |
|
108 | - { |
|
109 | - add_filter('site-reviews/style', function () { |
|
110 | - return 'default'; |
|
111 | - }); |
|
112 | - } |
|
104 | + /** |
|
105 | + * @return void |
|
106 | + */ |
|
107 | + protected function filterShortcodeClass() |
|
108 | + { |
|
109 | + add_filter('site-reviews/style', function () { |
|
110 | + return 'default'; |
|
111 | + }); |
|
112 | + } |
|
113 | 113 | |
114 | - /** |
|
115 | - * @param string $field |
|
116 | - * @return void |
|
117 | - */ |
|
118 | - protected function filterShowMoreLinks($field) |
|
119 | - { |
|
120 | - add_filter('site-reviews/review/wrap/'.$field, function ($value) { |
|
121 | - $value = preg_replace( |
|
122 | - '/(.*)(<span class="glsr-hidden)(.*)(<\/span>)(.*)/us', |
|
123 | - '$1... <a href="#" class="glsr-read-more" tabindex="-1">'.__('Show more', 'site-reviews').'</a>$5', |
|
124 | - $value |
|
125 | - ); |
|
126 | - return $value; |
|
127 | - }); |
|
128 | - } |
|
114 | + /** |
|
115 | + * @param string $field |
|
116 | + * @return void |
|
117 | + */ |
|
118 | + protected function filterShowMoreLinks($field) |
|
119 | + { |
|
120 | + add_filter('site-reviews/review/wrap/'.$field, function ($value) { |
|
121 | + $value = preg_replace( |
|
122 | + '/(.*)(<span class="glsr-hidden)(.*)(<\/span>)(.*)/us', |
|
123 | + '$1... <a href="#" class="glsr-read-more" tabindex="-1">'.__('Show more', 'site-reviews').'</a>$5', |
|
124 | + $value |
|
125 | + ); |
|
126 | + return $value; |
|
127 | + }); |
|
128 | + } |
|
129 | 129 | } |
@@ -12,210 +12,210 @@ |
||
12 | 12 | |
13 | 13 | class TrustalyzeController extends Controller |
14 | 14 | { |
15 | - protected $apiKey = 'settings.general.trustalyze_serial'; |
|
16 | - protected $emailKey = 'settings.general.trustalyze_email'; |
|
17 | - protected $enabledKey = 'settings.general.trustalyze'; |
|
18 | - protected $trustalyzeKey = '_glsr_trustalyze'; |
|
19 | - |
|
20 | - /** |
|
21 | - * @return array |
|
22 | - * @filter site-reviews/settings/callback |
|
23 | - */ |
|
24 | - public function filterSettingsCallback(array $settings) |
|
25 | - { |
|
26 | - if ('yes' !== Arr::get($settings, $this->enabledKey)) { |
|
27 | - return $settings; |
|
28 | - } |
|
29 | - $isApiKeyModified = $this->isEmptyOrModified($this->apiKey, $settings); |
|
30 | - $isEmailModified = $this->isEmptyOrModified($this->emailKey, $settings); |
|
31 | - $isAccountVerified = glsr(OptionManager::class)->getWP($this->trustalyzeKey, false); |
|
32 | - if (!$isAccountVerified || $isApiKeyModified || $isEmailModified) { |
|
33 | - $settings = $this->sanitizeTrustalyzeSettings($settings); |
|
34 | - } |
|
35 | - return $settings; |
|
36 | - } |
|
37 | - |
|
38 | - /** |
|
39 | - * @param string $template |
|
40 | - * @return array |
|
41 | - * @filter site-reviews/interpolate/partials/form/table-row-multiple |
|
42 | - */ |
|
43 | - public function filterSettingsTableRow(array $context, $template, array $data) |
|
44 | - { |
|
45 | - if ($this->enabledKey !== Arr::get($data, 'field.path')) { |
|
46 | - return $context; |
|
47 | - } |
|
48 | - $isAccountValidated = !empty(glsr(OptionManager::class)->getWP($this->trustalyzeKey)); |
|
49 | - $isIntegrationEnabled = glsr(OptionManager::class)->getBool('settings.general.trustalyze'); |
|
50 | - if ($isAccountValidated && $isIntegrationEnabled) { |
|
51 | - return $context; |
|
52 | - } |
|
53 | - $context['field'].= $this->buildCreateButton(); |
|
54 | - return $context; |
|
55 | - } |
|
56 | - |
|
57 | - /** |
|
58 | - * Triggered when a review is created. |
|
59 | - * @return void |
|
60 | - * @action site-reviews/review/created |
|
61 | - */ |
|
62 | - public function onCreated(Review $review) |
|
63 | - { |
|
64 | - if (!$this->canPostReview($review)) { |
|
65 | - return; |
|
66 | - } |
|
67 | - $trustalyze = glsr(Trustalyze::class)->sendReview($review); |
|
68 | - if ($trustalyze->success) { |
|
69 | - glsr(Database::class)->set($review->ID, 'trustalyze', $trustalyze->review_id); |
|
70 | - } |
|
71 | - } |
|
72 | - |
|
73 | - /** |
|
74 | - * Triggered when a review is reverted to its original title/content/date_timestamp. |
|
75 | - * @return void |
|
76 | - * @action site-reviews/review/reverted |
|
77 | - */ |
|
78 | - public function onReverted(Review $review) |
|
79 | - { |
|
80 | - if (!$this->canPostReview($review)) { |
|
81 | - return; |
|
82 | - } |
|
83 | - $trustalyze = glsr(Trustalyze::class)->sendReview($review); |
|
84 | - if ($trustalyze->success) { |
|
85 | - glsr(Database::class)->set($review->ID, 'trustalyze', $trustalyze->review_id); |
|
86 | - } |
|
87 | - } |
|
88 | - |
|
89 | - /** |
|
90 | - * Triggered when an existing review is updated. |
|
91 | - * @return void |
|
92 | - * @action site-reviews/review/saved |
|
93 | - */ |
|
94 | - public function onSaved(Review $review) |
|
95 | - { |
|
96 | - if (!$this->canPostReview($review)) { |
|
97 | - return; |
|
98 | - } |
|
99 | - $trustalyze = glsr(Trustalyze::class)->sendReview($review); |
|
100 | - if ($trustalyze->success) { |
|
101 | - glsr(Database::class)->set($review->ID, 'trustalyze', $trustalyze->review_id); |
|
102 | - } |
|
103 | - } |
|
104 | - |
|
105 | - /** |
|
106 | - * Triggered when a review's response is added or updated. |
|
107 | - * @param int $metaId |
|
108 | - * @param int $postId |
|
109 | - * @param string $metaKey |
|
110 | - * @return void |
|
111 | - * @action updated_postmeta |
|
112 | - */ |
|
113 | - public function onUpdatedMeta($metaId, $postId, $metaKey) |
|
114 | - { |
|
115 | - $review = glsr_get_review($postId); |
|
116 | - if (!$this->canPostResponse($review) || '_response' !== $metaKey) { |
|
117 | - return; |
|
118 | - } |
|
119 | - $trustalyze = glsr(Trustalyze::class)->sendReviewResponse($review); |
|
120 | - if ($trustalyze->success) { |
|
121 | - glsr(Database::class)->set($review->ID, 'trustalyze_response', true); |
|
122 | - } |
|
123 | - } |
|
124 | - |
|
125 | - /** |
|
126 | - * @return string |
|
127 | - */ |
|
128 | - protected function buildCreateButton() |
|
129 | - { |
|
130 | - return glsr(Builder::class)->a(__('Create Your Trustalyze Account', 'site-reviews'), [ |
|
131 | - 'class' => 'button', |
|
132 | - 'href' => Trustalyze::WEB_URL, |
|
133 | - 'target' => '_blank', |
|
134 | - ]); |
|
135 | - } |
|
136 | - |
|
137 | - /** |
|
138 | - * @return bool |
|
139 | - */ |
|
140 | - protected function canPostResponse(Review $review) |
|
141 | - { |
|
142 | - $requiredValues = [ |
|
143 | - glsr(Database::class)->get($review->ID, 'trustalyze'), |
|
144 | - $review->response, |
|
145 | - $review->review_id, |
|
146 | - ]; |
|
147 | - return $this->canProceed($review, 'trustalyze_response') |
|
148 | - && 'publish' === $review->status |
|
149 | - && 3 === count(array_filter($requiredValues)); |
|
150 | - } |
|
151 | - |
|
152 | - /** |
|
153 | - * @return bool |
|
154 | - */ |
|
155 | - protected function canPostReview(Review $review) |
|
156 | - { |
|
157 | - $requiredValues = [ |
|
158 | - $review->author, |
|
159 | - $review->content, |
|
160 | - $review->rating, |
|
161 | - $review->review_id, |
|
162 | - $review->title, |
|
163 | - ]; |
|
164 | - return $this->canProceed($review) |
|
165 | - && 'publish' === $review->status |
|
166 | - && 5 === count(array_filter($requiredValues)); |
|
167 | - } |
|
168 | - |
|
169 | - /** |
|
170 | - * @param string $metaKey |
|
171 | - * @return bool |
|
172 | - */ |
|
173 | - protected function canProceed(Review $review, $metaKey = 'trustalyze') |
|
174 | - { |
|
175 | - return glsr(OptionManager::class)->getBool($this->enabledKey) |
|
176 | - && $this->isReviewPostId($review->ID) |
|
177 | - && !$this->hasMetaKey($review, $metaKey); |
|
178 | - } |
|
179 | - |
|
180 | - /** |
|
181 | - * @param string $metaKey |
|
182 | - * @return bool |
|
183 | - */ |
|
184 | - protected function hasMetaKey(Review $review, $metaKey = 'trustalyze') |
|
185 | - { |
|
186 | - return '' !== glsr(Database::class)->get($review->ID, $metaKey); |
|
187 | - } |
|
188 | - |
|
189 | - /** |
|
190 | - * @param string $key |
|
191 | - * @return bool |
|
192 | - */ |
|
193 | - protected function isEmptyOrModified($key, array $settings) |
|
194 | - { |
|
195 | - $oldValue = glsr_get_option($key); |
|
196 | - $newValue = Arr::get($settings, $key); |
|
197 | - return empty($newValue) || $newValue !== $oldValue; |
|
198 | - } |
|
199 | - |
|
200 | - /** |
|
201 | - * @return array |
|
202 | - */ |
|
203 | - protected function sanitizeTrustalyzeSettings(array $settings) |
|
204 | - { |
|
205 | - $trustalyze = glsr(Trustalyze::class)->activateKey( |
|
206 | - Arr::get($settings, $this->apiKey), |
|
207 | - Arr::get($settings, $this->emailKey) |
|
208 | - ); |
|
209 | - if ($trustalyze->success) { |
|
210 | - update_option($this->trustalyzeKey, Arr::get($trustalyze->response, 'producttype')); |
|
211 | - } else { |
|
212 | - delete_option($this->trustalyzeKey); |
|
213 | - $settings = Arr::set($settings, $this->enabledKey, 'no'); |
|
214 | - glsr(Notice::class)->addError(sprintf( |
|
215 | - __('Your Trustalyze account details could not be verified, please try again. %s', 'site-reviews'), |
|
216 | - '('.$trustalyze->message.')' |
|
217 | - )); |
|
218 | - } |
|
219 | - return $settings; |
|
220 | - } |
|
15 | + protected $apiKey = 'settings.general.trustalyze_serial'; |
|
16 | + protected $emailKey = 'settings.general.trustalyze_email'; |
|
17 | + protected $enabledKey = 'settings.general.trustalyze'; |
|
18 | + protected $trustalyzeKey = '_glsr_trustalyze'; |
|
19 | + |
|
20 | + /** |
|
21 | + * @return array |
|
22 | + * @filter site-reviews/settings/callback |
|
23 | + */ |
|
24 | + public function filterSettingsCallback(array $settings) |
|
25 | + { |
|
26 | + if ('yes' !== Arr::get($settings, $this->enabledKey)) { |
|
27 | + return $settings; |
|
28 | + } |
|
29 | + $isApiKeyModified = $this->isEmptyOrModified($this->apiKey, $settings); |
|
30 | + $isEmailModified = $this->isEmptyOrModified($this->emailKey, $settings); |
|
31 | + $isAccountVerified = glsr(OptionManager::class)->getWP($this->trustalyzeKey, false); |
|
32 | + if (!$isAccountVerified || $isApiKeyModified || $isEmailModified) { |
|
33 | + $settings = $this->sanitizeTrustalyzeSettings($settings); |
|
34 | + } |
|
35 | + return $settings; |
|
36 | + } |
|
37 | + |
|
38 | + /** |
|
39 | + * @param string $template |
|
40 | + * @return array |
|
41 | + * @filter site-reviews/interpolate/partials/form/table-row-multiple |
|
42 | + */ |
|
43 | + public function filterSettingsTableRow(array $context, $template, array $data) |
|
44 | + { |
|
45 | + if ($this->enabledKey !== Arr::get($data, 'field.path')) { |
|
46 | + return $context; |
|
47 | + } |
|
48 | + $isAccountValidated = !empty(glsr(OptionManager::class)->getWP($this->trustalyzeKey)); |
|
49 | + $isIntegrationEnabled = glsr(OptionManager::class)->getBool('settings.general.trustalyze'); |
|
50 | + if ($isAccountValidated && $isIntegrationEnabled) { |
|
51 | + return $context; |
|
52 | + } |
|
53 | + $context['field'].= $this->buildCreateButton(); |
|
54 | + return $context; |
|
55 | + } |
|
56 | + |
|
57 | + /** |
|
58 | + * Triggered when a review is created. |
|
59 | + * @return void |
|
60 | + * @action site-reviews/review/created |
|
61 | + */ |
|
62 | + public function onCreated(Review $review) |
|
63 | + { |
|
64 | + if (!$this->canPostReview($review)) { |
|
65 | + return; |
|
66 | + } |
|
67 | + $trustalyze = glsr(Trustalyze::class)->sendReview($review); |
|
68 | + if ($trustalyze->success) { |
|
69 | + glsr(Database::class)->set($review->ID, 'trustalyze', $trustalyze->review_id); |
|
70 | + } |
|
71 | + } |
|
72 | + |
|
73 | + /** |
|
74 | + * Triggered when a review is reverted to its original title/content/date_timestamp. |
|
75 | + * @return void |
|
76 | + * @action site-reviews/review/reverted |
|
77 | + */ |
|
78 | + public function onReverted(Review $review) |
|
79 | + { |
|
80 | + if (!$this->canPostReview($review)) { |
|
81 | + return; |
|
82 | + } |
|
83 | + $trustalyze = glsr(Trustalyze::class)->sendReview($review); |
|
84 | + if ($trustalyze->success) { |
|
85 | + glsr(Database::class)->set($review->ID, 'trustalyze', $trustalyze->review_id); |
|
86 | + } |
|
87 | + } |
|
88 | + |
|
89 | + /** |
|
90 | + * Triggered when an existing review is updated. |
|
91 | + * @return void |
|
92 | + * @action site-reviews/review/saved |
|
93 | + */ |
|
94 | + public function onSaved(Review $review) |
|
95 | + { |
|
96 | + if (!$this->canPostReview($review)) { |
|
97 | + return; |
|
98 | + } |
|
99 | + $trustalyze = glsr(Trustalyze::class)->sendReview($review); |
|
100 | + if ($trustalyze->success) { |
|
101 | + glsr(Database::class)->set($review->ID, 'trustalyze', $trustalyze->review_id); |
|
102 | + } |
|
103 | + } |
|
104 | + |
|
105 | + /** |
|
106 | + * Triggered when a review's response is added or updated. |
|
107 | + * @param int $metaId |
|
108 | + * @param int $postId |
|
109 | + * @param string $metaKey |
|
110 | + * @return void |
|
111 | + * @action updated_postmeta |
|
112 | + */ |
|
113 | + public function onUpdatedMeta($metaId, $postId, $metaKey) |
|
114 | + { |
|
115 | + $review = glsr_get_review($postId); |
|
116 | + if (!$this->canPostResponse($review) || '_response' !== $metaKey) { |
|
117 | + return; |
|
118 | + } |
|
119 | + $trustalyze = glsr(Trustalyze::class)->sendReviewResponse($review); |
|
120 | + if ($trustalyze->success) { |
|
121 | + glsr(Database::class)->set($review->ID, 'trustalyze_response', true); |
|
122 | + } |
|
123 | + } |
|
124 | + |
|
125 | + /** |
|
126 | + * @return string |
|
127 | + */ |
|
128 | + protected function buildCreateButton() |
|
129 | + { |
|
130 | + return glsr(Builder::class)->a(__('Create Your Trustalyze Account', 'site-reviews'), [ |
|
131 | + 'class' => 'button', |
|
132 | + 'href' => Trustalyze::WEB_URL, |
|
133 | + 'target' => '_blank', |
|
134 | + ]); |
|
135 | + } |
|
136 | + |
|
137 | + /** |
|
138 | + * @return bool |
|
139 | + */ |
|
140 | + protected function canPostResponse(Review $review) |
|
141 | + { |
|
142 | + $requiredValues = [ |
|
143 | + glsr(Database::class)->get($review->ID, 'trustalyze'), |
|
144 | + $review->response, |
|
145 | + $review->review_id, |
|
146 | + ]; |
|
147 | + return $this->canProceed($review, 'trustalyze_response') |
|
148 | + && 'publish' === $review->status |
|
149 | + && 3 === count(array_filter($requiredValues)); |
|
150 | + } |
|
151 | + |
|
152 | + /** |
|
153 | + * @return bool |
|
154 | + */ |
|
155 | + protected function canPostReview(Review $review) |
|
156 | + { |
|
157 | + $requiredValues = [ |
|
158 | + $review->author, |
|
159 | + $review->content, |
|
160 | + $review->rating, |
|
161 | + $review->review_id, |
|
162 | + $review->title, |
|
163 | + ]; |
|
164 | + return $this->canProceed($review) |
|
165 | + && 'publish' === $review->status |
|
166 | + && 5 === count(array_filter($requiredValues)); |
|
167 | + } |
|
168 | + |
|
169 | + /** |
|
170 | + * @param string $metaKey |
|
171 | + * @return bool |
|
172 | + */ |
|
173 | + protected function canProceed(Review $review, $metaKey = 'trustalyze') |
|
174 | + { |
|
175 | + return glsr(OptionManager::class)->getBool($this->enabledKey) |
|
176 | + && $this->isReviewPostId($review->ID) |
|
177 | + && !$this->hasMetaKey($review, $metaKey); |
|
178 | + } |
|
179 | + |
|
180 | + /** |
|
181 | + * @param string $metaKey |
|
182 | + * @return bool |
|
183 | + */ |
|
184 | + protected function hasMetaKey(Review $review, $metaKey = 'trustalyze') |
|
185 | + { |
|
186 | + return '' !== glsr(Database::class)->get($review->ID, $metaKey); |
|
187 | + } |
|
188 | + |
|
189 | + /** |
|
190 | + * @param string $key |
|
191 | + * @return bool |
|
192 | + */ |
|
193 | + protected function isEmptyOrModified($key, array $settings) |
|
194 | + { |
|
195 | + $oldValue = glsr_get_option($key); |
|
196 | + $newValue = Arr::get($settings, $key); |
|
197 | + return empty($newValue) || $newValue !== $oldValue; |
|
198 | + } |
|
199 | + |
|
200 | + /** |
|
201 | + * @return array |
|
202 | + */ |
|
203 | + protected function sanitizeTrustalyzeSettings(array $settings) |
|
204 | + { |
|
205 | + $trustalyze = glsr(Trustalyze::class)->activateKey( |
|
206 | + Arr::get($settings, $this->apiKey), |
|
207 | + Arr::get($settings, $this->emailKey) |
|
208 | + ); |
|
209 | + if ($trustalyze->success) { |
|
210 | + update_option($this->trustalyzeKey, Arr::get($trustalyze->response, 'producttype')); |
|
211 | + } else { |
|
212 | + delete_option($this->trustalyzeKey); |
|
213 | + $settings = Arr::set($settings, $this->enabledKey, 'no'); |
|
214 | + glsr(Notice::class)->addError(sprintf( |
|
215 | + __('Your Trustalyze account details could not be verified, please try again. %s', 'site-reviews'), |
|
216 | + '('.$trustalyze->message.')' |
|
217 | + )); |
|
218 | + } |
|
219 | + return $settings; |
|
220 | + } |
|
221 | 221 | } |
@@ -11,247 +11,247 @@ |
||
11 | 11 | |
12 | 12 | class TranslationController |
13 | 13 | { |
14 | - /** |
|
15 | - * @var Translator |
|
16 | - */ |
|
17 | - public $translator; |
|
14 | + /** |
|
15 | + * @var Translator |
|
16 | + */ |
|
17 | + public $translator; |
|
18 | 18 | |
19 | - public function __construct(Translator $translator) |
|
20 | - { |
|
21 | - $this->translator = $translator; |
|
22 | - } |
|
19 | + public function __construct(Translator $translator) |
|
20 | + { |
|
21 | + $this->translator = $translator; |
|
22 | + } |
|
23 | 23 | |
24 | - /** |
|
25 | - * @return void |
|
26 | - * @action plugins_loaded |
|
27 | - */ |
|
28 | - public function addTranslationFilters() |
|
29 | - { |
|
30 | - if (empty(glsr(Translation::class)->translations())) { |
|
31 | - return; |
|
32 | - } |
|
33 | - add_filter('gettext', [$this, 'filterGettext'], 9, 3); |
|
34 | - add_filter('site-reviews/gettext/site-reviews', [$this, 'filterGettextSiteReviews'], 10, 2); |
|
35 | - add_filter('gettext_with_context', [$this, 'filterGettextWithContext'], 9, 4); |
|
36 | - add_filter('site-reviews/gettext_with_context/site-reviews', [$this, 'filterGettextWithContextSiteReviews'], 10, 3); |
|
37 | - add_filter('ngettext', [$this, 'filterNgettext'], 9, 5); |
|
38 | - add_filter('site-reviews/ngettext/site-reviews', [$this, 'filterNgettextSiteReviews'], 10, 4); |
|
39 | - add_filter('ngettext_with_context', [$this, 'filterNgettextWithContext'], 9, 6); |
|
40 | - add_filter('site-reviews/ngettext_with_context/site-reviews', [$this, 'filterNgettextWithContextSiteReviews'], 10, 5); |
|
41 | - } |
|
24 | + /** |
|
25 | + * @return void |
|
26 | + * @action plugins_loaded |
|
27 | + */ |
|
28 | + public function addTranslationFilters() |
|
29 | + { |
|
30 | + if (empty(glsr(Translation::class)->translations())) { |
|
31 | + return; |
|
32 | + } |
|
33 | + add_filter('gettext', [$this, 'filterGettext'], 9, 3); |
|
34 | + add_filter('site-reviews/gettext/site-reviews', [$this, 'filterGettextSiteReviews'], 10, 2); |
|
35 | + add_filter('gettext_with_context', [$this, 'filterGettextWithContext'], 9, 4); |
|
36 | + add_filter('site-reviews/gettext_with_context/site-reviews', [$this, 'filterGettextWithContextSiteReviews'], 10, 3); |
|
37 | + add_filter('ngettext', [$this, 'filterNgettext'], 9, 5); |
|
38 | + add_filter('site-reviews/ngettext/site-reviews', [$this, 'filterNgettextSiteReviews'], 10, 4); |
|
39 | + add_filter('ngettext_with_context', [$this, 'filterNgettextWithContext'], 9, 6); |
|
40 | + add_filter('site-reviews/ngettext_with_context/site-reviews', [$this, 'filterNgettextWithContextSiteReviews'], 10, 5); |
|
41 | + } |
|
42 | 42 | |
43 | - /** |
|
44 | - * @param array $messages |
|
45 | - * @return array |
|
46 | - * @filter bulk_post_updated_messages |
|
47 | - */ |
|
48 | - public function filterBulkUpdateMessages($messages, array $counts) |
|
49 | - { |
|
50 | - $messages = Arr::consolidateArray($messages); |
|
51 | - $messages[Application::POST_TYPE] = [ |
|
52 | - 'updated' => _n('%s review updated.', '%s reviews updated.', $counts['updated'], 'site-reviews'), |
|
53 | - 'locked' => _n('%s review not updated, somebody is editing it.', '%s reviews not updated, somebody is editing them.', $counts['locked'], 'site-reviews'), |
|
54 | - 'deleted' => _n('%s review permanently deleted.', '%s reviews permanently deleted.', $counts['deleted'], 'site-reviews'), |
|
55 | - 'trashed' => _n('%s review moved to the Trash.', '%s reviews moved to the Trash.', $counts['trashed'], 'site-reviews'), |
|
56 | - 'untrashed' => _n('%s review restored from the Trash.', '%s reviews restored from the Trash.', $counts['untrashed'], 'site-reviews'), |
|
57 | - ]; |
|
58 | - return $messages; |
|
59 | - } |
|
43 | + /** |
|
44 | + * @param array $messages |
|
45 | + * @return array |
|
46 | + * @filter bulk_post_updated_messages |
|
47 | + */ |
|
48 | + public function filterBulkUpdateMessages($messages, array $counts) |
|
49 | + { |
|
50 | + $messages = Arr::consolidateArray($messages); |
|
51 | + $messages[Application::POST_TYPE] = [ |
|
52 | + 'updated' => _n('%s review updated.', '%s reviews updated.', $counts['updated'], 'site-reviews'), |
|
53 | + 'locked' => _n('%s review not updated, somebody is editing it.', '%s reviews not updated, somebody is editing them.', $counts['locked'], 'site-reviews'), |
|
54 | + 'deleted' => _n('%s review permanently deleted.', '%s reviews permanently deleted.', $counts['deleted'], 'site-reviews'), |
|
55 | + 'trashed' => _n('%s review moved to the Trash.', '%s reviews moved to the Trash.', $counts['trashed'], 'site-reviews'), |
|
56 | + 'untrashed' => _n('%s review restored from the Trash.', '%s reviews restored from the Trash.', $counts['untrashed'], 'site-reviews'), |
|
57 | + ]; |
|
58 | + return $messages; |
|
59 | + } |
|
60 | 60 | |
61 | - /** |
|
62 | - * @param string $translation |
|
63 | - * @param string $text |
|
64 | - * @param string $domain |
|
65 | - * @return string |
|
66 | - * @filter gettext |
|
67 | - */ |
|
68 | - public function filterGettext($translation, $text, $domain) |
|
69 | - { |
|
70 | - return apply_filters('site-reviews/gettext/'.$domain, $translation, $text); |
|
71 | - } |
|
61 | + /** |
|
62 | + * @param string $translation |
|
63 | + * @param string $text |
|
64 | + * @param string $domain |
|
65 | + * @return string |
|
66 | + * @filter gettext |
|
67 | + */ |
|
68 | + public function filterGettext($translation, $text, $domain) |
|
69 | + { |
|
70 | + return apply_filters('site-reviews/gettext/'.$domain, $translation, $text); |
|
71 | + } |
|
72 | 72 | |
73 | - /** |
|
74 | - * @param string $translation |
|
75 | - * @param string $text |
|
76 | - * @return string |
|
77 | - * @filter site-reviews/gettext/site-reviews |
|
78 | - */ |
|
79 | - public function filterGettextSiteReviews($translation, $text) |
|
80 | - { |
|
81 | - return $this->translator->translate($translation, Application::ID, [ |
|
82 | - 'single' => $text, |
|
83 | - ]); |
|
84 | - } |
|
73 | + /** |
|
74 | + * @param string $translation |
|
75 | + * @param string $text |
|
76 | + * @return string |
|
77 | + * @filter site-reviews/gettext/site-reviews |
|
78 | + */ |
|
79 | + public function filterGettextSiteReviews($translation, $text) |
|
80 | + { |
|
81 | + return $this->translator->translate($translation, Application::ID, [ |
|
82 | + 'single' => $text, |
|
83 | + ]); |
|
84 | + } |
|
85 | 85 | |
86 | - /** |
|
87 | - * @param string $translation |
|
88 | - * @param string $text |
|
89 | - * @param string $context |
|
90 | - * @param string $domain |
|
91 | - * @return string |
|
92 | - * @filter gettext_with_context |
|
93 | - */ |
|
94 | - public function filterGettextWithContext($translation, $text, $context, $domain) |
|
95 | - { |
|
96 | - return apply_filters('site-reviews/gettext_with_context/'.$domain, $translation, $text, $context); |
|
97 | - } |
|
86 | + /** |
|
87 | + * @param string $translation |
|
88 | + * @param string $text |
|
89 | + * @param string $context |
|
90 | + * @param string $domain |
|
91 | + * @return string |
|
92 | + * @filter gettext_with_context |
|
93 | + */ |
|
94 | + public function filterGettextWithContext($translation, $text, $context, $domain) |
|
95 | + { |
|
96 | + return apply_filters('site-reviews/gettext_with_context/'.$domain, $translation, $text, $context); |
|
97 | + } |
|
98 | 98 | |
99 | - /** |
|
100 | - * @param string $translation |
|
101 | - * @param string $text |
|
102 | - * @param string $context |
|
103 | - * @return string |
|
104 | - * @filter site-reviews/gettext_with_context/site-reviews |
|
105 | - */ |
|
106 | - public function filterGettextWithContextSiteReviews($translation, $text, $context) |
|
107 | - { |
|
108 | - return $this->translator->translate($translation, Application::ID, [ |
|
109 | - 'context' => $context, |
|
110 | - 'single' => $text, |
|
111 | - ]); |
|
112 | - } |
|
99 | + /** |
|
100 | + * @param string $translation |
|
101 | + * @param string $text |
|
102 | + * @param string $context |
|
103 | + * @return string |
|
104 | + * @filter site-reviews/gettext_with_context/site-reviews |
|
105 | + */ |
|
106 | + public function filterGettextWithContextSiteReviews($translation, $text, $context) |
|
107 | + { |
|
108 | + return $this->translator->translate($translation, Application::ID, [ |
|
109 | + 'context' => $context, |
|
110 | + 'single' => $text, |
|
111 | + ]); |
|
112 | + } |
|
113 | 113 | |
114 | - /** |
|
115 | - * @param string $translation |
|
116 | - * @param string $single |
|
117 | - * @param string $plural |
|
118 | - * @param int $number |
|
119 | - * @param string $domain |
|
120 | - * @return string |
|
121 | - * @filter ngettext |
|
122 | - */ |
|
123 | - public function filterNgettext($translation, $single, $plural, $number, $domain) |
|
124 | - { |
|
125 | - return apply_filters('site-reviews/ngettext/'.$domain, $translation, $single, $plural, $number); |
|
126 | - } |
|
114 | + /** |
|
115 | + * @param string $translation |
|
116 | + * @param string $single |
|
117 | + * @param string $plural |
|
118 | + * @param int $number |
|
119 | + * @param string $domain |
|
120 | + * @return string |
|
121 | + * @filter ngettext |
|
122 | + */ |
|
123 | + public function filterNgettext($translation, $single, $plural, $number, $domain) |
|
124 | + { |
|
125 | + return apply_filters('site-reviews/ngettext/'.$domain, $translation, $single, $plural, $number); |
|
126 | + } |
|
127 | 127 | |
128 | - /** |
|
129 | - * @param string $translation |
|
130 | - * @param string $single |
|
131 | - * @param string $plural |
|
132 | - * @param int $number |
|
133 | - * @return string |
|
134 | - * @filter site-reviews/ngettext/site-reviews |
|
135 | - */ |
|
136 | - public function filterNgettextSiteReviews($translation, $single, $plural, $number) |
|
137 | - { |
|
138 | - return $this->translator->translate($translation, Application::ID, [ |
|
139 | - 'number' => $number, |
|
140 | - 'plural' => $plural, |
|
141 | - 'single' => $single, |
|
142 | - ]); |
|
143 | - } |
|
128 | + /** |
|
129 | + * @param string $translation |
|
130 | + * @param string $single |
|
131 | + * @param string $plural |
|
132 | + * @param int $number |
|
133 | + * @return string |
|
134 | + * @filter site-reviews/ngettext/site-reviews |
|
135 | + */ |
|
136 | + public function filterNgettextSiteReviews($translation, $single, $plural, $number) |
|
137 | + { |
|
138 | + return $this->translator->translate($translation, Application::ID, [ |
|
139 | + 'number' => $number, |
|
140 | + 'plural' => $plural, |
|
141 | + 'single' => $single, |
|
142 | + ]); |
|
143 | + } |
|
144 | 144 | |
145 | - /** |
|
146 | - * @param string $translation |
|
147 | - * @param string $single |
|
148 | - * @param string $plural |
|
149 | - * @param int $number |
|
150 | - * @param string $context |
|
151 | - * @param string $domain |
|
152 | - * @return string |
|
153 | - * @filter ngettext_with_context |
|
154 | - */ |
|
155 | - public function filterNgettextWithContext($translation, $single, $plural, $number, $context, $domain) |
|
156 | - { |
|
157 | - return apply_filters('site-reviews/ngettext_with_context/'.$domain, $translation, $single, $plural, $number, $context); |
|
158 | - } |
|
145 | + /** |
|
146 | + * @param string $translation |
|
147 | + * @param string $single |
|
148 | + * @param string $plural |
|
149 | + * @param int $number |
|
150 | + * @param string $context |
|
151 | + * @param string $domain |
|
152 | + * @return string |
|
153 | + * @filter ngettext_with_context |
|
154 | + */ |
|
155 | + public function filterNgettextWithContext($translation, $single, $plural, $number, $context, $domain) |
|
156 | + { |
|
157 | + return apply_filters('site-reviews/ngettext_with_context/'.$domain, $translation, $single, $plural, $number, $context); |
|
158 | + } |
|
159 | 159 | |
160 | - /** |
|
161 | - * @param string $translation |
|
162 | - * @param string $single |
|
163 | - * @param string $plural |
|
164 | - * @param int $number |
|
165 | - * @param string $context |
|
166 | - * @return string |
|
167 | - * @filter site-reviews/ngettext_with_context/site-reviews |
|
168 | - */ |
|
169 | - public function filterNgettextWithContextSiteReviews($translation, $single, $plural, $number, $context) |
|
170 | - { |
|
171 | - return $this->translator->translate($translation, Application::ID, [ |
|
172 | - 'context' => $context, |
|
173 | - 'number' => $number, |
|
174 | - 'plural' => $plural, |
|
175 | - 'single' => $single, |
|
176 | - ]); |
|
177 | - } |
|
160 | + /** |
|
161 | + * @param string $translation |
|
162 | + * @param string $single |
|
163 | + * @param string $plural |
|
164 | + * @param int $number |
|
165 | + * @param string $context |
|
166 | + * @return string |
|
167 | + * @filter site-reviews/ngettext_with_context/site-reviews |
|
168 | + */ |
|
169 | + public function filterNgettextWithContextSiteReviews($translation, $single, $plural, $number, $context) |
|
170 | + { |
|
171 | + return $this->translator->translate($translation, Application::ID, [ |
|
172 | + 'context' => $context, |
|
173 | + 'number' => $number, |
|
174 | + 'plural' => $plural, |
|
175 | + 'single' => $single, |
|
176 | + ]); |
|
177 | + } |
|
178 | 178 | |
179 | - /** |
|
180 | - * @param array $postStates |
|
181 | - * @param \WP_Post $post |
|
182 | - * @return array |
|
183 | - * @filter display_post_states |
|
184 | - */ |
|
185 | - public function filterPostStates($postStates, $post) |
|
186 | - { |
|
187 | - $postStates = Arr::consolidateArray($postStates); |
|
188 | - if (Application::POST_TYPE == Arr::get($post, 'post_type') && array_key_exists('pending', $postStates)) { |
|
189 | - $postStates['pending'] = __('Unapproved', 'site-reviews'); |
|
190 | - } |
|
191 | - return $postStates; |
|
192 | - } |
|
179 | + /** |
|
180 | + * @param array $postStates |
|
181 | + * @param \WP_Post $post |
|
182 | + * @return array |
|
183 | + * @filter display_post_states |
|
184 | + */ |
|
185 | + public function filterPostStates($postStates, $post) |
|
186 | + { |
|
187 | + $postStates = Arr::consolidateArray($postStates); |
|
188 | + if (Application::POST_TYPE == Arr::get($post, 'post_type') && array_key_exists('pending', $postStates)) { |
|
189 | + $postStates['pending'] = __('Unapproved', 'site-reviews'); |
|
190 | + } |
|
191 | + return $postStates; |
|
192 | + } |
|
193 | 193 | |
194 | - /** |
|
195 | - * @param string $translation |
|
196 | - * @param string $text |
|
197 | - * @return string |
|
198 | - * @filter site-reviews/gettext/default |
|
199 | - * @filter site-reviews/gettext_with_context/default |
|
200 | - */ |
|
201 | - public function filterPostStatusLabels($translation, $text) |
|
202 | - { |
|
203 | - return $this->canModifyTranslation() |
|
204 | - ? glsr(Labels::class)->filterPostStatusLabels($translation, $text) |
|
205 | - : $translation; |
|
206 | - } |
|
194 | + /** |
|
195 | + * @param string $translation |
|
196 | + * @param string $text |
|
197 | + * @return string |
|
198 | + * @filter site-reviews/gettext/default |
|
199 | + * @filter site-reviews/gettext_with_context/default |
|
200 | + */ |
|
201 | + public function filterPostStatusLabels($translation, $text) |
|
202 | + { |
|
203 | + return $this->canModifyTranslation() |
|
204 | + ? glsr(Labels::class)->filterPostStatusLabels($translation, $text) |
|
205 | + : $translation; |
|
206 | + } |
|
207 | 207 | |
208 | - /** |
|
209 | - * @param string $translation |
|
210 | - * @param string $single |
|
211 | - * @param string $plural |
|
212 | - * @param int $number |
|
213 | - * @return string |
|
214 | - * @filter site-reviews/ngettext/default |
|
215 | - */ |
|
216 | - public function filterPostStatusText($translation, $single, $plural, $number) |
|
217 | - { |
|
218 | - if ($this->canModifyTranslation()) { |
|
219 | - $strings = [ |
|
220 | - 'Published' => __('Approved', 'site-reviews'), |
|
221 | - 'Pending' => __('Unapproved', 'site-reviews'), |
|
222 | - ]; |
|
223 | - foreach ($strings as $search => $replace) { |
|
224 | - if (!Str::contains($single, $search)) { |
|
225 | - continue; |
|
226 | - } |
|
227 | - return $this->translator->getTranslation([ |
|
228 | - 'number' => $number, |
|
229 | - 'plural' => str_replace($search, $replace, $plural), |
|
230 | - 'single' => str_replace($search, $replace, $single), |
|
231 | - ]); |
|
232 | - } |
|
233 | - } |
|
234 | - return $translation; |
|
235 | - } |
|
208 | + /** |
|
209 | + * @param string $translation |
|
210 | + * @param string $single |
|
211 | + * @param string $plural |
|
212 | + * @param int $number |
|
213 | + * @return string |
|
214 | + * @filter site-reviews/ngettext/default |
|
215 | + */ |
|
216 | + public function filterPostStatusText($translation, $single, $plural, $number) |
|
217 | + { |
|
218 | + if ($this->canModifyTranslation()) { |
|
219 | + $strings = [ |
|
220 | + 'Published' => __('Approved', 'site-reviews'), |
|
221 | + 'Pending' => __('Unapproved', 'site-reviews'), |
|
222 | + ]; |
|
223 | + foreach ($strings as $search => $replace) { |
|
224 | + if (!Str::contains($single, $search)) { |
|
225 | + continue; |
|
226 | + } |
|
227 | + return $this->translator->getTranslation([ |
|
228 | + 'number' => $number, |
|
229 | + 'plural' => str_replace($search, $replace, $plural), |
|
230 | + 'single' => str_replace($search, $replace, $single), |
|
231 | + ]); |
|
232 | + } |
|
233 | + } |
|
234 | + return $translation; |
|
235 | + } |
|
236 | 236 | |
237 | - /** |
|
238 | - * @return void |
|
239 | - * @action admin_enqueue_scripts |
|
240 | - */ |
|
241 | - public function translatePostStatusLabels() |
|
242 | - { |
|
243 | - if ($this->canModifyTranslation()) { |
|
244 | - glsr(Labels::class)->translatePostStatusLabels(); |
|
245 | - } |
|
246 | - } |
|
237 | + /** |
|
238 | + * @return void |
|
239 | + * @action admin_enqueue_scripts |
|
240 | + */ |
|
241 | + public function translatePostStatusLabels() |
|
242 | + { |
|
243 | + if ($this->canModifyTranslation()) { |
|
244 | + glsr(Labels::class)->translatePostStatusLabels(); |
|
245 | + } |
|
246 | + } |
|
247 | 247 | |
248 | - /** |
|
249 | - * @return bool |
|
250 | - */ |
|
251 | - protected function canModifyTranslation() |
|
252 | - { |
|
253 | - $screen = glsr_current_screen(); |
|
254 | - return Application::POST_TYPE == $screen->post_type |
|
255 | - && in_array($screen->base, ['edit', 'post']); |
|
256 | - } |
|
248 | + /** |
|
249 | + * @return bool |
|
250 | + */ |
|
251 | + protected function canModifyTranslation() |
|
252 | + { |
|
253 | + $screen = glsr_current_screen(); |
|
254 | + return Application::POST_TYPE == $screen->post_type |
|
255 | + && in_array($screen->base, ['edit', 'post']); |
|
256 | + } |
|
257 | 257 | } |
@@ -21,112 +21,112 @@ |
||
21 | 21 | |
22 | 22 | class Actions implements HooksContract |
23 | 23 | { |
24 | - protected $about; |
|
25 | - protected $admin; |
|
26 | - protected $app; |
|
27 | - protected $blocks; |
|
28 | - protected $console; |
|
29 | - protected $editor; |
|
30 | - protected $listtable; |
|
31 | - protected $menu; |
|
32 | - protected $main; |
|
33 | - protected $notices; |
|
34 | - protected $public; |
|
35 | - protected $review; |
|
36 | - protected $router; |
|
37 | - protected $settings; |
|
38 | - protected $taxonomy; |
|
39 | - protected $translator; |
|
40 | - protected $trustalyze; |
|
41 | - protected $welcome; |
|
24 | + protected $about; |
|
25 | + protected $admin; |
|
26 | + protected $app; |
|
27 | + protected $blocks; |
|
28 | + protected $console; |
|
29 | + protected $editor; |
|
30 | + protected $listtable; |
|
31 | + protected $menu; |
|
32 | + protected $main; |
|
33 | + protected $notices; |
|
34 | + protected $public; |
|
35 | + protected $review; |
|
36 | + protected $router; |
|
37 | + protected $settings; |
|
38 | + protected $taxonomy; |
|
39 | + protected $translator; |
|
40 | + protected $trustalyze; |
|
41 | + protected $welcome; |
|
42 | 42 | |
43 | - public function __construct(Application $app ) { |
|
44 | - $this->app = $app; |
|
45 | - $this->admin = $app->make(AdminController::class); |
|
46 | - $this->blocks = $app->make(BlocksController::class); |
|
47 | - $this->console = $app->make(Console::class); |
|
48 | - $this->editor = $app->make(EditorController::class); |
|
49 | - $this->listtable = $app->make(ListTableController::class); |
|
50 | - $this->main = $app->make(MainController::class); |
|
51 | - $this->menu = $app->make(MenuController::class); |
|
52 | - $this->notices = $app->make(NoticeController::class); |
|
53 | - $this->public = $app->make(PublicController::class); |
|
54 | - $this->review = $app->make(ReviewController::class); |
|
55 | - $this->router = $app->make(Router::class); |
|
56 | - $this->settings = $app->make(SettingsController::class); |
|
57 | - $this->taxonomy = $app->make(TaxonomyController::class); |
|
58 | - $this->translator = $app->make(TranslationController::class); |
|
59 | - $this->trustalyze = $app->make(TrustalyzeController::class); |
|
60 | - $this->welcome = $app->make(WelcomeController::class); |
|
61 | - } |
|
43 | + public function __construct(Application $app ) { |
|
44 | + $this->app = $app; |
|
45 | + $this->admin = $app->make(AdminController::class); |
|
46 | + $this->blocks = $app->make(BlocksController::class); |
|
47 | + $this->console = $app->make(Console::class); |
|
48 | + $this->editor = $app->make(EditorController::class); |
|
49 | + $this->listtable = $app->make(ListTableController::class); |
|
50 | + $this->main = $app->make(MainController::class); |
|
51 | + $this->menu = $app->make(MenuController::class); |
|
52 | + $this->notices = $app->make(NoticeController::class); |
|
53 | + $this->public = $app->make(PublicController::class); |
|
54 | + $this->review = $app->make(ReviewController::class); |
|
55 | + $this->router = $app->make(Router::class); |
|
56 | + $this->settings = $app->make(SettingsController::class); |
|
57 | + $this->taxonomy = $app->make(TaxonomyController::class); |
|
58 | + $this->translator = $app->make(TranslationController::class); |
|
59 | + $this->trustalyze = $app->make(TrustalyzeController::class); |
|
60 | + $this->welcome = $app->make(WelcomeController::class); |
|
61 | + } |
|
62 | 62 | |
63 | - /** |
|
64 | - * @return void |
|
65 | - */ |
|
66 | - public function run() |
|
67 | - { |
|
68 | - add_action('admin_enqueue_scripts', [$this->admin, 'enqueueAssets']); |
|
69 | - add_action('admin_init', [$this->admin, 'registerTinymcePopups']); |
|
70 | - add_action('media_buttons', [$this->admin, 'renderTinymceButton'], 11); |
|
71 | - add_action('admin_init', [$this->admin, 'runMigrations']); |
|
72 | - add_action('plugins_loaded', [$this->app, 'getDefaults'], 11); |
|
73 | - add_action('plugins_loaded', [$this->app, 'registerAddons']); |
|
74 | - add_action('plugins_loaded', [$this->app, 'registerLanguages']); |
|
75 | - add_action('plugins_loaded', [$this->app, 'registerReviewTypes']); |
|
76 | - add_action('admin_init', [$this->app, 'setDefaults']); |
|
77 | - add_action('init', [$this->blocks, 'registerAssets'], 9); |
|
78 | - add_action('init', [$this->blocks, 'registerBlocks']); |
|
79 | - add_action('admin_footer', [$this->console, 'logOnce']); |
|
80 | - add_action('wp_footer', [$this->console, 'logOnce']); |
|
81 | - add_action('add_meta_boxes_'.Application::POST_TYPE, [$this->editor, 'registerMetaBoxes']); |
|
82 | - add_action('admin_print_scripts', [$this->editor, 'removeAutosave'], 999); |
|
83 | - add_action('admin_menu', [$this->editor, 'removeMetaBoxes']); |
|
84 | - add_action('current_screen', [$this->editor, 'removePostTypeSupport']); |
|
85 | - add_action('post_submitbox_misc_actions', [$this->editor, 'renderPinnedInPublishMetaBox']); |
|
86 | - add_action('admin_head', [$this->editor, 'renderReviewFields']); |
|
87 | - add_action('admin_action_revert', [$this->editor, 'revertReview']); |
|
88 | - add_action('save_post_'.Application::POST_TYPE, [$this->editor, 'saveMetaboxes'], 10, 3); |
|
89 | - add_action('admin_action_approve', [$this->listtable, 'approve']); |
|
90 | - add_action('bulk_edit_custom_box', [$this->listtable, 'renderBulkEditFields'], 10, 2); |
|
91 | - add_action('restrict_manage_posts', [$this->listtable, 'renderColumnFilters']); |
|
92 | - add_action('manage_'.Application::POST_TYPE.'_posts_custom_column', [$this->listtable, 'renderColumnValues'], 10, 2); |
|
93 | - add_action('save_post_'.Application::POST_TYPE, [$this->listtable, 'saveBulkEditFields']); |
|
94 | - add_action('pre_get_posts', [$this->listtable, 'setQueryForColumn']); |
|
95 | - add_action('admin_action_unapprove', [$this->listtable, 'unapprove']); |
|
96 | - add_action('init', [$this->main, 'registerPostType'], 8); |
|
97 | - add_action('init', [$this->main, 'registerShortcodes']); |
|
98 | - add_action('init', [$this->main, 'registerTaxonomy']); |
|
99 | - add_action('widgets_init', [$this->main, 'registerWidgets']); |
|
100 | - add_action('admin_menu', [$this->menu, 'registerMenuCount']); |
|
101 | - add_action('admin_menu', [$this->menu, 'registerSubMenus']); |
|
102 | - add_action('admin_init', [$this->menu, 'setCustomPermissions'], 999); |
|
103 | - add_action('admin_notices', [$this->notices, 'filterAdminNotices']); |
|
104 | - add_action('wp_enqueue_scripts', [$this->public, 'enqueueAssets'], 999); |
|
105 | - add_filter('site-reviews/builder', [$this->public, 'modifyBuilder']); |
|
106 | - add_action('wp_footer', [$this->public, 'renderSchema']); |
|
107 | - add_action('set_object_terms', [$this->review, 'onAfterChangeCategory'], 10, 6); |
|
108 | - add_action('transition_post_status', [$this->review, 'onAfterChangeStatus'], 10, 3); |
|
109 | - add_action('site-reviews/review/created', [$this->review, 'onAfterCreate']); |
|
110 | - add_action('before_delete_post', [$this->review, 'onBeforeDelete']); |
|
111 | - add_action('update_postmeta', [$this->review, 'onBeforeUpdate'], 10, 4); |
|
112 | - add_action('admin_init', [$this->router, 'routeAdminPostRequest']); |
|
113 | - add_action('wp_ajax_'.Application::PREFIX.'action', [$this->router, 'routeAjaxRequest']); |
|
114 | - add_action('wp_ajax_nopriv_'.Application::PREFIX.'action', [$this->router, 'routeAjaxRequest']); |
|
115 | - add_action('init', [$this->router, 'routePublicPostRequest']); |
|
116 | - add_action('admin_init', [$this->settings, 'registerSettings']); |
|
117 | - add_action(Application::TAXONOMY.'_term_edit_form_top', [$this->taxonomy, 'disableParents']); |
|
118 | - add_action(Application::TAXONOMY.'_term_new_form_tag', [$this->taxonomy, 'disableParents']); |
|
119 | - add_action(Application::TAXONOMY.'_add_form_fields', [$this->taxonomy, 'enableParents']); |
|
120 | - add_action(Application::TAXONOMY.'_edit_form', [$this->taxonomy, 'enableParents']); |
|
121 | - add_action('restrict_manage_posts', [$this->taxonomy, 'renderTaxonomyFilter'], 9); |
|
122 | - add_action('set_object_terms', [$this->taxonomy, 'restrictTermSelection'], 9, 6); |
|
123 | - add_action('plugins_loaded', [$this->translator, 'addTranslationFilters']); |
|
124 | - add_action('admin_enqueue_scripts', [$this->translator, 'translatePostStatusLabels']); |
|
125 | - add_action('site-reviews/review/created', [$this->trustalyze, 'onCreated']); |
|
126 | - add_action('site-reviews/review/reverted', [$this->trustalyze, 'onReverted']); |
|
127 | - add_action('site-reviews/review/saved', [$this->trustalyze, 'onSaved']); |
|
128 | - add_action('updated_postmeta', [$this->trustalyze, 'onUpdatedMeta'], 10, 3); |
|
129 | - add_action('activated_plugin', [$this->welcome, 'redirectOnActivation'], 10, 2); |
|
130 | - add_action('admin_menu', [$this->welcome, 'registerPage']); |
|
131 | - } |
|
63 | + /** |
|
64 | + * @return void |
|
65 | + */ |
|
66 | + public function run() |
|
67 | + { |
|
68 | + add_action('admin_enqueue_scripts', [$this->admin, 'enqueueAssets']); |
|
69 | + add_action('admin_init', [$this->admin, 'registerTinymcePopups']); |
|
70 | + add_action('media_buttons', [$this->admin, 'renderTinymceButton'], 11); |
|
71 | + add_action('admin_init', [$this->admin, 'runMigrations']); |
|
72 | + add_action('plugins_loaded', [$this->app, 'getDefaults'], 11); |
|
73 | + add_action('plugins_loaded', [$this->app, 'registerAddons']); |
|
74 | + add_action('plugins_loaded', [$this->app, 'registerLanguages']); |
|
75 | + add_action('plugins_loaded', [$this->app, 'registerReviewTypes']); |
|
76 | + add_action('admin_init', [$this->app, 'setDefaults']); |
|
77 | + add_action('init', [$this->blocks, 'registerAssets'], 9); |
|
78 | + add_action('init', [$this->blocks, 'registerBlocks']); |
|
79 | + add_action('admin_footer', [$this->console, 'logOnce']); |
|
80 | + add_action('wp_footer', [$this->console, 'logOnce']); |
|
81 | + add_action('add_meta_boxes_'.Application::POST_TYPE, [$this->editor, 'registerMetaBoxes']); |
|
82 | + add_action('admin_print_scripts', [$this->editor, 'removeAutosave'], 999); |
|
83 | + add_action('admin_menu', [$this->editor, 'removeMetaBoxes']); |
|
84 | + add_action('current_screen', [$this->editor, 'removePostTypeSupport']); |
|
85 | + add_action('post_submitbox_misc_actions', [$this->editor, 'renderPinnedInPublishMetaBox']); |
|
86 | + add_action('admin_head', [$this->editor, 'renderReviewFields']); |
|
87 | + add_action('admin_action_revert', [$this->editor, 'revertReview']); |
|
88 | + add_action('save_post_'.Application::POST_TYPE, [$this->editor, 'saveMetaboxes'], 10, 3); |
|
89 | + add_action('admin_action_approve', [$this->listtable, 'approve']); |
|
90 | + add_action('bulk_edit_custom_box', [$this->listtable, 'renderBulkEditFields'], 10, 2); |
|
91 | + add_action('restrict_manage_posts', [$this->listtable, 'renderColumnFilters']); |
|
92 | + add_action('manage_'.Application::POST_TYPE.'_posts_custom_column', [$this->listtable, 'renderColumnValues'], 10, 2); |
|
93 | + add_action('save_post_'.Application::POST_TYPE, [$this->listtable, 'saveBulkEditFields']); |
|
94 | + add_action('pre_get_posts', [$this->listtable, 'setQueryForColumn']); |
|
95 | + add_action('admin_action_unapprove', [$this->listtable, 'unapprove']); |
|
96 | + add_action('init', [$this->main, 'registerPostType'], 8); |
|
97 | + add_action('init', [$this->main, 'registerShortcodes']); |
|
98 | + add_action('init', [$this->main, 'registerTaxonomy']); |
|
99 | + add_action('widgets_init', [$this->main, 'registerWidgets']); |
|
100 | + add_action('admin_menu', [$this->menu, 'registerMenuCount']); |
|
101 | + add_action('admin_menu', [$this->menu, 'registerSubMenus']); |
|
102 | + add_action('admin_init', [$this->menu, 'setCustomPermissions'], 999); |
|
103 | + add_action('admin_notices', [$this->notices, 'filterAdminNotices']); |
|
104 | + add_action('wp_enqueue_scripts', [$this->public, 'enqueueAssets'], 999); |
|
105 | + add_filter('site-reviews/builder', [$this->public, 'modifyBuilder']); |
|
106 | + add_action('wp_footer', [$this->public, 'renderSchema']); |
|
107 | + add_action('set_object_terms', [$this->review, 'onAfterChangeCategory'], 10, 6); |
|
108 | + add_action('transition_post_status', [$this->review, 'onAfterChangeStatus'], 10, 3); |
|
109 | + add_action('site-reviews/review/created', [$this->review, 'onAfterCreate']); |
|
110 | + add_action('before_delete_post', [$this->review, 'onBeforeDelete']); |
|
111 | + add_action('update_postmeta', [$this->review, 'onBeforeUpdate'], 10, 4); |
|
112 | + add_action('admin_init', [$this->router, 'routeAdminPostRequest']); |
|
113 | + add_action('wp_ajax_'.Application::PREFIX.'action', [$this->router, 'routeAjaxRequest']); |
|
114 | + add_action('wp_ajax_nopriv_'.Application::PREFIX.'action', [$this->router, 'routeAjaxRequest']); |
|
115 | + add_action('init', [$this->router, 'routePublicPostRequest']); |
|
116 | + add_action('admin_init', [$this->settings, 'registerSettings']); |
|
117 | + add_action(Application::TAXONOMY.'_term_edit_form_top', [$this->taxonomy, 'disableParents']); |
|
118 | + add_action(Application::TAXONOMY.'_term_new_form_tag', [$this->taxonomy, 'disableParents']); |
|
119 | + add_action(Application::TAXONOMY.'_add_form_fields', [$this->taxonomy, 'enableParents']); |
|
120 | + add_action(Application::TAXONOMY.'_edit_form', [$this->taxonomy, 'enableParents']); |
|
121 | + add_action('restrict_manage_posts', [$this->taxonomy, 'renderTaxonomyFilter'], 9); |
|
122 | + add_action('set_object_terms', [$this->taxonomy, 'restrictTermSelection'], 9, 6); |
|
123 | + add_action('plugins_loaded', [$this->translator, 'addTranslationFilters']); |
|
124 | + add_action('admin_enqueue_scripts', [$this->translator, 'translatePostStatusLabels']); |
|
125 | + add_action('site-reviews/review/created', [$this->trustalyze, 'onCreated']); |
|
126 | + add_action('site-reviews/review/reverted', [$this->trustalyze, 'onReverted']); |
|
127 | + add_action('site-reviews/review/saved', [$this->trustalyze, 'onSaved']); |
|
128 | + add_action('updated_postmeta', [$this->trustalyze, 'onUpdatedMeta'], 10, 3); |
|
129 | + add_action('activated_plugin', [$this->welcome, 'redirectOnActivation'], 10, 2); |
|
130 | + add_action('admin_menu', [$this->welcome, 'registerPage']); |
|
131 | + } |
|
132 | 132 | } |
@@ -15,64 +15,64 @@ |
||
15 | 15 | |
16 | 16 | class Filters implements HooksContract |
17 | 17 | { |
18 | - protected $admin; |
|
19 | - protected $app; |
|
20 | - protected $basename; |
|
21 | - protected $blocks; |
|
22 | - protected $editor; |
|
23 | - protected $listtable; |
|
24 | - protected $public; |
|
25 | - protected $translator; |
|
26 | - protected $trustalyze; |
|
27 | - protected $welcome; |
|
18 | + protected $admin; |
|
19 | + protected $app; |
|
20 | + protected $basename; |
|
21 | + protected $blocks; |
|
22 | + protected $editor; |
|
23 | + protected $listtable; |
|
24 | + protected $public; |
|
25 | + protected $translator; |
|
26 | + protected $trustalyze; |
|
27 | + protected $welcome; |
|
28 | 28 | |
29 | - public function __construct(Application $app) |
|
30 | - { |
|
31 | - $this->app = $app; |
|
32 | - $this->admin = $app->make(AdminController::class); |
|
33 | - $this->basename = plugin_basename($app->file); |
|
34 | - $this->blocks = $app->make(BlocksController::class); |
|
35 | - $this->editor = $app->make(EditorController::class); |
|
36 | - $this->listtable = $app->make(ListTableController::class); |
|
37 | - $this->public = $app->make(PublicController::class); |
|
38 | - $this->translator = $app->make(TranslationController::class); |
|
39 | - $this->trustalyze = $app->make(TrustalyzeController::class); |
|
40 | - $this->welcome = $app->make(WelcomeController::class); |
|
41 | - } |
|
29 | + public function __construct(Application $app) |
|
30 | + { |
|
31 | + $this->app = $app; |
|
32 | + $this->admin = $app->make(AdminController::class); |
|
33 | + $this->basename = plugin_basename($app->file); |
|
34 | + $this->blocks = $app->make(BlocksController::class); |
|
35 | + $this->editor = $app->make(EditorController::class); |
|
36 | + $this->listtable = $app->make(ListTableController::class); |
|
37 | + $this->public = $app->make(PublicController::class); |
|
38 | + $this->translator = $app->make(TranslationController::class); |
|
39 | + $this->trustalyze = $app->make(TrustalyzeController::class); |
|
40 | + $this->welcome = $app->make(WelcomeController::class); |
|
41 | + } |
|
42 | 42 | |
43 | - /** |
|
44 | - * @return void |
|
45 | - */ |
|
46 | - public function run() |
|
47 | - { |
|
48 | - add_filter('map_meta_cap', [$this->admin, 'filterCreateCapability'], 10, 2); |
|
49 | - add_filter('mce_external_plugins', [$this->admin, 'filterTinymcePlugins'], 15); |
|
50 | - add_filter('plugin_action_links_'.$this->basename, [$this->admin, 'filterActionLinks']); |
|
51 | - add_filter('dashboard_glance_items', [$this->admin, 'filterDashboardGlanceItems']); |
|
52 | - add_filter('block_categories', [$this->blocks, 'filterBlockCategories']); |
|
53 | - add_filter('classic_editor_enabled_editors_for_post_type', [$this->blocks, 'filterEnabledEditors'], 10, 2); |
|
54 | - add_filter('use_block_editor_for_post_type', [$this->blocks, 'filterUseBlockEditor'], 10, 2); |
|
55 | - add_filter('wp_editor_settings', [$this->editor, 'filterEditorSettings']); |
|
56 | - add_filter('the_editor', [$this->editor, 'filterEditorTextarea']); |
|
57 | - add_filter('is_protected_meta', [$this->editor, 'filterIsProtectedMeta'], 10, 3); |
|
58 | - add_filter('post_updated_messages', [$this->editor, 'filterUpdateMessages']); |
|
59 | - add_filter('manage_'.Application::POST_TYPE.'_posts_columns', [$this->listtable, 'filterColumnsForPostType']); |
|
60 | - add_filter('post_date_column_status', [$this->listtable, 'filterDateColumnStatus'], 10, 2); |
|
61 | - add_filter('default_hidden_columns', [$this->listtable, 'filterDefaultHiddenColumns'], 10, 2); |
|
62 | - add_filter('post_row_actions', [$this->listtable, 'filterRowActions'], 10, 2); |
|
63 | - add_filter('manage_edit-'.Application::POST_TYPE.'_sortable_columns', [$this->listtable, 'filterSortableColumns']); |
|
64 | - add_filter('script_loader_tag', [$this->public, 'filterEnqueuedScripts'], 10, 2); |
|
65 | - add_filter('site-reviews/config/forms/submission-form', [$this->public, 'filterFieldOrder'], 11); |
|
66 | - add_filter('site-reviews/render/view', [$this->public, 'filterRenderView']); |
|
67 | - add_filter('bulk_post_updated_messages', [$this->translator, 'filterBulkUpdateMessages'], 10, 2); |
|
68 | - add_filter('display_post_states', [$this->translator, 'filterPostStates'], 10, 2); |
|
69 | - add_filter('site-reviews/gettext/default', [$this->translator, 'filterPostStatusLabels'], 10, 2); |
|
70 | - add_filter('site-reviews/gettext_with_context/default', [$this->translator, 'filterPostStatusLabels'], 10, 2); |
|
71 | - add_filter('site-reviews/ngettext/default', [$this->translator, 'filterPostStatusText'], 10, 4); |
|
72 | - add_filter('site-reviews/settings/callback', [$this->trustalyze, 'filterSettingsCallback']); |
|
73 | - add_filter('site-reviews/interpolate/partials/form/table-row-multiple', [$this->trustalyze, 'filterSettingsTableRow'], 10, 3); |
|
74 | - add_filter('plugin_action_links_'.$this->basename, [$this->welcome, 'filterActionLinks'], 9); |
|
75 | - add_filter('admin_title', [$this->welcome, 'filterAdminTitle']); |
|
76 | - add_filter('admin_footer_text', [$this->welcome, 'filterFooterText']); |
|
77 | - } |
|
43 | + /** |
|
44 | + * @return void |
|
45 | + */ |
|
46 | + public function run() |
|
47 | + { |
|
48 | + add_filter('map_meta_cap', [$this->admin, 'filterCreateCapability'], 10, 2); |
|
49 | + add_filter('mce_external_plugins', [$this->admin, 'filterTinymcePlugins'], 15); |
|
50 | + add_filter('plugin_action_links_'.$this->basename, [$this->admin, 'filterActionLinks']); |
|
51 | + add_filter('dashboard_glance_items', [$this->admin, 'filterDashboardGlanceItems']); |
|
52 | + add_filter('block_categories', [$this->blocks, 'filterBlockCategories']); |
|
53 | + add_filter('classic_editor_enabled_editors_for_post_type', [$this->blocks, 'filterEnabledEditors'], 10, 2); |
|
54 | + add_filter('use_block_editor_for_post_type', [$this->blocks, 'filterUseBlockEditor'], 10, 2); |
|
55 | + add_filter('wp_editor_settings', [$this->editor, 'filterEditorSettings']); |
|
56 | + add_filter('the_editor', [$this->editor, 'filterEditorTextarea']); |
|
57 | + add_filter('is_protected_meta', [$this->editor, 'filterIsProtectedMeta'], 10, 3); |
|
58 | + add_filter('post_updated_messages', [$this->editor, 'filterUpdateMessages']); |
|
59 | + add_filter('manage_'.Application::POST_TYPE.'_posts_columns', [$this->listtable, 'filterColumnsForPostType']); |
|
60 | + add_filter('post_date_column_status', [$this->listtable, 'filterDateColumnStatus'], 10, 2); |
|
61 | + add_filter('default_hidden_columns', [$this->listtable, 'filterDefaultHiddenColumns'], 10, 2); |
|
62 | + add_filter('post_row_actions', [$this->listtable, 'filterRowActions'], 10, 2); |
|
63 | + add_filter('manage_edit-'.Application::POST_TYPE.'_sortable_columns', [$this->listtable, 'filterSortableColumns']); |
|
64 | + add_filter('script_loader_tag', [$this->public, 'filterEnqueuedScripts'], 10, 2); |
|
65 | + add_filter('site-reviews/config/forms/submission-form', [$this->public, 'filterFieldOrder'], 11); |
|
66 | + add_filter('site-reviews/render/view', [$this->public, 'filterRenderView']); |
|
67 | + add_filter('bulk_post_updated_messages', [$this->translator, 'filterBulkUpdateMessages'], 10, 2); |
|
68 | + add_filter('display_post_states', [$this->translator, 'filterPostStates'], 10, 2); |
|
69 | + add_filter('site-reviews/gettext/default', [$this->translator, 'filterPostStatusLabels'], 10, 2); |
|
70 | + add_filter('site-reviews/gettext_with_context/default', [$this->translator, 'filterPostStatusLabels'], 10, 2); |
|
71 | + add_filter('site-reviews/ngettext/default', [$this->translator, 'filterPostStatusText'], 10, 4); |
|
72 | + add_filter('site-reviews/settings/callback', [$this->trustalyze, 'filterSettingsCallback']); |
|
73 | + add_filter('site-reviews/interpolate/partials/form/table-row-multiple', [$this->trustalyze, 'filterSettingsTableRow'], 10, 3); |
|
74 | + add_filter('plugin_action_links_'.$this->basename, [$this->welcome, 'filterActionLinks'], 9); |
|
75 | + add_filter('admin_title', [$this->welcome, 'filterAdminTitle']); |
|
76 | + add_filter('admin_footer_text', [$this->welcome, 'filterFooterText']); |
|
77 | + } |
|
78 | 78 | } |
@@ -10,184 +10,184 @@ |
||
10 | 10 | |
11 | 11 | class Columns |
12 | 12 | { |
13 | - /** |
|
14 | - * @param int $postId |
|
15 | - * @return void|string |
|
16 | - */ |
|
17 | - public function buildColumnAssignedTo($postId) |
|
18 | - { |
|
19 | - $assignedPost = glsr(Database::class)->getAssignedToPost($postId); |
|
20 | - if ($assignedPost instanceof WP_Post && 'publish' == $assignedPost->post_status) { |
|
21 | - return glsr(Builder::class)->a(get_the_title($assignedPost->ID), [ |
|
22 | - 'href' => (string) get_the_permalink($assignedPost->ID), |
|
23 | - ]); |
|
24 | - } |
|
25 | - } |
|
13 | + /** |
|
14 | + * @param int $postId |
|
15 | + * @return void|string |
|
16 | + */ |
|
17 | + public function buildColumnAssignedTo($postId) |
|
18 | + { |
|
19 | + $assignedPost = glsr(Database::class)->getAssignedToPost($postId); |
|
20 | + if ($assignedPost instanceof WP_Post && 'publish' == $assignedPost->post_status) { |
|
21 | + return glsr(Builder::class)->a(get_the_title($assignedPost->ID), [ |
|
22 | + 'href' => (string) get_the_permalink($assignedPost->ID), |
|
23 | + ]); |
|
24 | + } |
|
25 | + } |
|
26 | 26 | |
27 | - /** |
|
28 | - * @param int $postId |
|
29 | - * @return void|string |
|
30 | - */ |
|
31 | - public function buildColumnEmail($postId) |
|
32 | - { |
|
33 | - if ($email = glsr(Database::class)->get($postId, 'email')) { |
|
34 | - return $email; |
|
35 | - } |
|
36 | - } |
|
27 | + /** |
|
28 | + * @param int $postId |
|
29 | + * @return void|string |
|
30 | + */ |
|
31 | + public function buildColumnEmail($postId) |
|
32 | + { |
|
33 | + if ($email = glsr(Database::class)->get($postId, 'email')) { |
|
34 | + return $email; |
|
35 | + } |
|
36 | + } |
|
37 | 37 | |
38 | - /** |
|
39 | - * @param int $postId |
|
40 | - * @return void|string |
|
41 | - */ |
|
42 | - public function buildColumnIpAddress($postId) |
|
43 | - { |
|
44 | - if ($ipAddress = glsr(Database::class)->get($postId, 'ip_address')) { |
|
45 | - return $ipAddress; |
|
46 | - } |
|
47 | - } |
|
38 | + /** |
|
39 | + * @param int $postId |
|
40 | + * @return void|string |
|
41 | + */ |
|
42 | + public function buildColumnIpAddress($postId) |
|
43 | + { |
|
44 | + if ($ipAddress = glsr(Database::class)->get($postId, 'ip_address')) { |
|
45 | + return $ipAddress; |
|
46 | + } |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * @param int $postId |
|
51 | - * @return string |
|
52 | - */ |
|
53 | - public function buildColumnPinned($postId) |
|
54 | - { |
|
55 | - $pinned = glsr(Database::class)->get($postId, 'pinned') |
|
56 | - ? 'pinned ' |
|
57 | - : ''; |
|
58 | - if (glsr()->can('edit_others_posts')) { |
|
59 | - $pinned.= 'pin-review '; |
|
60 | - } |
|
61 | - return glsr(Builder::class)->i([ |
|
62 | - 'class' => $pinned.'dashicons dashicons-sticky', |
|
63 | - 'data-id' => $postId, |
|
64 | - ]); |
|
65 | - } |
|
49 | + /** |
|
50 | + * @param int $postId |
|
51 | + * @return string |
|
52 | + */ |
|
53 | + public function buildColumnPinned($postId) |
|
54 | + { |
|
55 | + $pinned = glsr(Database::class)->get($postId, 'pinned') |
|
56 | + ? 'pinned ' |
|
57 | + : ''; |
|
58 | + if (glsr()->can('edit_others_posts')) { |
|
59 | + $pinned.= 'pin-review '; |
|
60 | + } |
|
61 | + return glsr(Builder::class)->i([ |
|
62 | + 'class' => $pinned.'dashicons dashicons-sticky', |
|
63 | + 'data-id' => $postId, |
|
64 | + ]); |
|
65 | + } |
|
66 | 66 | |
67 | - /** |
|
68 | - * @param int $postId |
|
69 | - * @return string |
|
70 | - */ |
|
71 | - public function buildColumnResponse($postId) |
|
72 | - { |
|
73 | - return glsr(Database::class)->get($postId, 'response') |
|
74 | - ? __('Yes', 'site-reviews') |
|
75 | - : __('No', 'site-reviews'); |
|
76 | - } |
|
67 | + /** |
|
68 | + * @param int $postId |
|
69 | + * @return string |
|
70 | + */ |
|
71 | + public function buildColumnResponse($postId) |
|
72 | + { |
|
73 | + return glsr(Database::class)->get($postId, 'response') |
|
74 | + ? __('Yes', 'site-reviews') |
|
75 | + : __('No', 'site-reviews'); |
|
76 | + } |
|
77 | 77 | |
78 | - /** |
|
79 | - * @param int $postId |
|
80 | - * @return string |
|
81 | - */ |
|
82 | - public function buildColumnReviewer($postId) |
|
83 | - { |
|
84 | - $author = strval(glsr(Database::class)->get($postId, 'author')); |
|
85 | - $userId = Helper::castToInt(get_post($postId)->post_author); |
|
86 | - return !empty($userId) |
|
87 | - ? glsr(Builder::class)->a($author, ['href' => get_author_posts_url($userId)]) |
|
88 | - : $author; |
|
89 | - } |
|
78 | + /** |
|
79 | + * @param int $postId |
|
80 | + * @return string |
|
81 | + */ |
|
82 | + public function buildColumnReviewer($postId) |
|
83 | + { |
|
84 | + $author = strval(glsr(Database::class)->get($postId, 'author')); |
|
85 | + $userId = Helper::castToInt(get_post($postId)->post_author); |
|
86 | + return !empty($userId) |
|
87 | + ? glsr(Builder::class)->a($author, ['href' => get_author_posts_url($userId)]) |
|
88 | + : $author; |
|
89 | + } |
|
90 | 90 | |
91 | - /** |
|
92 | - * @param int $postId |
|
93 | - * @param int|null $rating |
|
94 | - * @return string |
|
95 | - */ |
|
96 | - public function buildColumnRating($postId) |
|
97 | - { |
|
98 | - return glsr_star_rating(intval(glsr(Database::class)->get($postId, 'rating'))); |
|
99 | - } |
|
91 | + /** |
|
92 | + * @param int $postId |
|
93 | + * @param int|null $rating |
|
94 | + * @return string |
|
95 | + */ |
|
96 | + public function buildColumnRating($postId) |
|
97 | + { |
|
98 | + return glsr_star_rating(intval(glsr(Database::class)->get($postId, 'rating'))); |
|
99 | + } |
|
100 | 100 | |
101 | - /** |
|
102 | - * @param int $postId |
|
103 | - * @return string |
|
104 | - */ |
|
105 | - public function buildColumnReviewType($postId) |
|
106 | - { |
|
107 | - $type = glsr(Database::class)->get($postId, 'review_type'); |
|
108 | - return array_key_exists($type, glsr()->reviewTypes) |
|
109 | - ? glsr()->reviewTypes[$type] |
|
110 | - : __('Unsupported Type', 'site-reviews'); |
|
111 | - } |
|
101 | + /** |
|
102 | + * @param int $postId |
|
103 | + * @return string |
|
104 | + */ |
|
105 | + public function buildColumnReviewType($postId) |
|
106 | + { |
|
107 | + $type = glsr(Database::class)->get($postId, 'review_type'); |
|
108 | + return array_key_exists($type, glsr()->reviewTypes) |
|
109 | + ? glsr()->reviewTypes[$type] |
|
110 | + : __('Unsupported Type', 'site-reviews'); |
|
111 | + } |
|
112 | 112 | |
113 | - /** |
|
114 | - * @param string $postType |
|
115 | - * @return void |
|
116 | - */ |
|
117 | - public function renderFilters($postType) |
|
118 | - { |
|
119 | - if (Application::POST_TYPE !== $postType) { |
|
120 | - return; |
|
121 | - } |
|
122 | - if (!($status = filter_input(INPUT_GET, 'post_status'))) { |
|
123 | - $status = 'publish'; |
|
124 | - } |
|
125 | - $ratings = glsr(Database::class)->getReviewsMeta('rating', $status); |
|
126 | - $types = glsr(Database::class)->getReviewsMeta('review_type', $status); |
|
127 | - $this->renderFilterRatings($ratings); |
|
128 | - $this->renderFilterTypes($types); |
|
129 | - } |
|
113 | + /** |
|
114 | + * @param string $postType |
|
115 | + * @return void |
|
116 | + */ |
|
117 | + public function renderFilters($postType) |
|
118 | + { |
|
119 | + if (Application::POST_TYPE !== $postType) { |
|
120 | + return; |
|
121 | + } |
|
122 | + if (!($status = filter_input(INPUT_GET, 'post_status'))) { |
|
123 | + $status = 'publish'; |
|
124 | + } |
|
125 | + $ratings = glsr(Database::class)->getReviewsMeta('rating', $status); |
|
126 | + $types = glsr(Database::class)->getReviewsMeta('review_type', $status); |
|
127 | + $this->renderFilterRatings($ratings); |
|
128 | + $this->renderFilterTypes($types); |
|
129 | + } |
|
130 | 130 | |
131 | - /** |
|
132 | - * @param string $column |
|
133 | - * @param int $postId |
|
134 | - * @return void |
|
135 | - */ |
|
136 | - public function renderValues($column, $postId) |
|
137 | - { |
|
138 | - $method = Helper::buildMethodName($column, 'buildColumn'); |
|
139 | - $value = method_exists($this, $method) |
|
140 | - ? call_user_func([$this, $method], $postId) |
|
141 | - : ''; |
|
142 | - $value = apply_filters('site-reviews/columns/'.$column, $value, $postId); |
|
143 | - if (0 !== $value && empty($value)) { |
|
144 | - $value = '—'; |
|
145 | - } |
|
146 | - echo $value; |
|
147 | - } |
|
131 | + /** |
|
132 | + * @param string $column |
|
133 | + * @param int $postId |
|
134 | + * @return void |
|
135 | + */ |
|
136 | + public function renderValues($column, $postId) |
|
137 | + { |
|
138 | + $method = Helper::buildMethodName($column, 'buildColumn'); |
|
139 | + $value = method_exists($this, $method) |
|
140 | + ? call_user_func([$this, $method], $postId) |
|
141 | + : ''; |
|
142 | + $value = apply_filters('site-reviews/columns/'.$column, $value, $postId); |
|
143 | + if (0 !== $value && empty($value)) { |
|
144 | + $value = '—'; |
|
145 | + } |
|
146 | + echo $value; |
|
147 | + } |
|
148 | 148 | |
149 | - /** |
|
150 | - * @param array $ratings |
|
151 | - * @return void |
|
152 | - */ |
|
153 | - protected function renderFilterRatings($ratings) |
|
154 | - { |
|
155 | - if (empty($ratings)) { |
|
156 | - return; |
|
157 | - } |
|
158 | - $ratings = array_flip(array_reverse($ratings)); |
|
159 | - array_walk($ratings, function (&$value, $key) { |
|
160 | - $label = _n('%s star', '%s stars', $key, 'site-reviews'); |
|
161 | - $value = sprintf($label, $key); |
|
162 | - }); |
|
163 | - echo glsr(Builder::class)->label(__('Filter by rating', 'site-reviews'), [ |
|
164 | - 'class' => 'screen-reader-text', |
|
165 | - 'for' => 'rating', |
|
166 | - ]); |
|
167 | - echo glsr(Builder::class)->select([ |
|
168 | - 'name' => 'rating', |
|
169 | - 'options' => ['' => __('All ratings', 'site-reviews')] + $ratings, |
|
170 | - 'value' => filter_input(INPUT_GET, 'rating'), |
|
171 | - ]); |
|
172 | - } |
|
149 | + /** |
|
150 | + * @param array $ratings |
|
151 | + * @return void |
|
152 | + */ |
|
153 | + protected function renderFilterRatings($ratings) |
|
154 | + { |
|
155 | + if (empty($ratings)) { |
|
156 | + return; |
|
157 | + } |
|
158 | + $ratings = array_flip(array_reverse($ratings)); |
|
159 | + array_walk($ratings, function (&$value, $key) { |
|
160 | + $label = _n('%s star', '%s stars', $key, 'site-reviews'); |
|
161 | + $value = sprintf($label, $key); |
|
162 | + }); |
|
163 | + echo glsr(Builder::class)->label(__('Filter by rating', 'site-reviews'), [ |
|
164 | + 'class' => 'screen-reader-text', |
|
165 | + 'for' => 'rating', |
|
166 | + ]); |
|
167 | + echo glsr(Builder::class)->select([ |
|
168 | + 'name' => 'rating', |
|
169 | + 'options' => ['' => __('All ratings', 'site-reviews')] + $ratings, |
|
170 | + 'value' => filter_input(INPUT_GET, 'rating'), |
|
171 | + ]); |
|
172 | + } |
|
173 | 173 | |
174 | - /** |
|
175 | - * @param array $types |
|
176 | - * @return void |
|
177 | - */ |
|
178 | - protected function renderFilterTypes($types) |
|
179 | - { |
|
180 | - if (count(glsr()->reviewTypes) < 2) { |
|
181 | - return; |
|
182 | - } |
|
183 | - echo glsr(Builder::class)->label(__('Filter by type', 'site-reviews'), [ |
|
184 | - 'class' => 'screen-reader-text', |
|
185 | - 'for' => 'review_type', |
|
186 | - ]); |
|
187 | - echo glsr(Builder::class)->select([ |
|
188 | - 'name' => 'review_type', |
|
189 | - 'options' => ['' => __('All types', 'site-reviews')] + glsr()->reviewTypes, |
|
190 | - 'value' => filter_input(INPUT_GET, 'review_type'), |
|
191 | - ]); |
|
192 | - } |
|
174 | + /** |
|
175 | + * @param array $types |
|
176 | + * @return void |
|
177 | + */ |
|
178 | + protected function renderFilterTypes($types) |
|
179 | + { |
|
180 | + if (count(glsr()->reviewTypes) < 2) { |
|
181 | + return; |
|
182 | + } |
|
183 | + echo glsr(Builder::class)->label(__('Filter by type', 'site-reviews'), [ |
|
184 | + 'class' => 'screen-reader-text', |
|
185 | + 'for' => 'review_type', |
|
186 | + ]); |
|
187 | + echo glsr(Builder::class)->select([ |
|
188 | + 'name' => 'review_type', |
|
189 | + 'options' => ['' => __('All types', 'site-reviews')] + glsr()->reviewTypes, |
|
190 | + 'value' => filter_input(INPUT_GET, 'review_type'), |
|
191 | + ]); |
|
192 | + } |
|
193 | 193 | } |