@@ -12,231 +12,231 @@ |
||
12 | 12 | |
13 | 13 | class RebusifyController extends Controller |
14 | 14 | { |
15 | - protected $apiKey = 'settings.general.rebusify_serial'; |
|
16 | - protected $emailKey = 'settings.general.rebusify_email'; |
|
17 | - protected $enabledKey = 'settings.general.rebusify'; |
|
18 | - protected $rebusifyKey = '_glsr_rebusify'; |
|
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->rebusifyKey, false); |
|
32 | - if (!$isAccountVerified || $isApiKeyModified || $isEmailModified) { |
|
33 | - $settings = $this->sanitizeRebusifySettings($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 | - $rebusifyProductType = glsr(OptionManager::class)->getWP($this->rebusifyKey); |
|
49 | - if ('P' === $rebusifyProductType) { |
|
50 | - return $context; |
|
51 | - } |
|
52 | - if ('F' === $rebusifyProductType && 'yes' === glsr_get_option('general.rebusify')) { |
|
53 | - $button = $this->buildUpgradeButton(); |
|
54 | - } else { |
|
55 | - $button = $this->buildCreateButton(); |
|
56 | - } |
|
57 | - $context['field'].= $button; |
|
58 | - return $context; |
|
59 | - } |
|
60 | - |
|
61 | - /** |
|
62 | - * Triggered when a review is created. |
|
63 | - * @return void |
|
64 | - * @action site-reviews/review/created |
|
65 | - */ |
|
66 | - public function onCreated(Review $review) |
|
67 | - { |
|
68 | - if (!$this->canPostReview($review)) { |
|
69 | - return; |
|
70 | - } |
|
71 | - $rebusify = glsr(Rebusify::class)->sendReview($review); |
|
72 | - if ($rebusify->success) { |
|
73 | - glsr(Database::class)->set($review->ID, 'rebusify', $rebusify->review_id); |
|
74 | - } |
|
75 | - } |
|
76 | - |
|
77 | - /** |
|
78 | - * Triggered when a review is reverted to its original title/content/date_timestamp. |
|
79 | - * @return void |
|
80 | - * @action site-reviews/review/reverted |
|
81 | - */ |
|
82 | - public function onReverted(Review $review) |
|
83 | - { |
|
84 | - if (!$this->canPostReview($review)) { |
|
85 | - return; |
|
86 | - } |
|
87 | - $rebusify = glsr(Rebusify::class)->sendReview($review); |
|
88 | - if ($rebusify->success) { |
|
89 | - glsr(Database::class)->set($review->ID, 'rebusify', $rebusify->review_id); |
|
90 | - } |
|
91 | - } |
|
92 | - |
|
93 | - /** |
|
94 | - * Triggered when an existing review is updated. |
|
95 | - * @return void |
|
96 | - * @action site-reviews/review/saved |
|
97 | - */ |
|
98 | - public function onSaved(Review $review) |
|
99 | - { |
|
100 | - if (!$this->canPostReview($review)) { |
|
101 | - return; |
|
102 | - } |
|
103 | - $rebusify = glsr(Rebusify::class)->sendReview($review); |
|
104 | - if ($rebusify->success) { |
|
105 | - glsr(Database::class)->set($review->ID, 'rebusify', $rebusify->review_id); |
|
106 | - } |
|
107 | - } |
|
108 | - |
|
109 | - /** |
|
110 | - * Triggered when a review's response is added or updated. |
|
111 | - * @param int $metaId |
|
112 | - * @param int $postId |
|
113 | - * @param string $metaKey |
|
114 | - * @return void |
|
115 | - * @action updated_postmeta |
|
116 | - */ |
|
117 | - public function onUpdatedMeta($metaId, $postId, $metaKey) |
|
118 | - { |
|
119 | - $review = glsr_get_review($postId); |
|
120 | - if (!$this->canPostResponse($review) || '_response' !== $metaKey) { |
|
121 | - return; |
|
122 | - } |
|
123 | - $rebusify = glsr(Rebusify::class)->sendReviewResponse($review); |
|
124 | - if ($rebusify->success) { |
|
125 | - glsr(Database::class)->set($review->ID, 'rebusify_response', true); |
|
126 | - } |
|
127 | - } |
|
128 | - |
|
129 | - /** |
|
130 | - * @return string |
|
131 | - */ |
|
132 | - protected function buildCreateButton() |
|
133 | - { |
|
134 | - return glsr(Builder::class)->a(__('Create Your Rebusify Account', 'site-reviews'), [ |
|
135 | - 'class' => 'button', |
|
136 | - 'href' => Rebusify::WEB_URL, |
|
137 | - 'target' => '_blank', |
|
138 | - ]); |
|
139 | - } |
|
140 | - |
|
141 | - /** |
|
142 | - * @return string |
|
143 | - */ |
|
144 | - protected function buildUpgradeButton() |
|
145 | - { |
|
146 | - $build = glsr(Builder::class); |
|
147 | - $notice = $build->p(__('Free Rebusify accounts are limited to 500 blockchain transactions per year.', 'site-reviews')); |
|
148 | - $button = $build->a(__('Upgrade Your Rebusify Plan', 'site-reviews'), [ |
|
149 | - 'class' => 'button', |
|
150 | - 'href' => Rebusify::WEB_URL, |
|
151 | - 'target' => '_blank', |
|
152 | - ]); |
|
153 | - return $build->div($notice.$button, [ |
|
154 | - 'class' => 'glsr-notice-inline', |
|
155 | - ]); |
|
156 | - } |
|
157 | - |
|
158 | - /** |
|
159 | - * @return bool |
|
160 | - */ |
|
161 | - protected function canPostResponse(Review $review) |
|
162 | - { |
|
163 | - $requiredValues = [ |
|
164 | - glsr(Database::class)->get($review->ID, 'rebusify'), |
|
165 | - $review->response, |
|
166 | - $review->review_id, |
|
167 | - ]; |
|
168 | - return $this->canProceed($review, 'rebusify_response') |
|
169 | - && 'publish' === $review->status |
|
170 | - && 3 === count(array_filter($requiredValues)); |
|
171 | - } |
|
172 | - |
|
173 | - /** |
|
174 | - * @return bool |
|
175 | - */ |
|
176 | - protected function canPostReview(Review $review) |
|
177 | - { |
|
178 | - $requiredValues = [ |
|
179 | - $review->author, |
|
180 | - $review->content, |
|
181 | - $review->rating, |
|
182 | - $review->review_id, |
|
183 | - $review->title, |
|
184 | - ]; |
|
185 | - return $this->canProceed($review) |
|
186 | - && 'publish' === $review->status |
|
187 | - && 5 === count(array_filter($requiredValues)); |
|
188 | - } |
|
189 | - |
|
190 | - /** |
|
191 | - * @param string $metaKey |
|
192 | - * @return bool |
|
193 | - */ |
|
194 | - protected function canProceed(Review $review, $metaKey = 'rebusify') |
|
195 | - { |
|
196 | - return glsr(OptionManager::class)->getBool($this->enabledKey) |
|
197 | - && $this->isReviewPostId($review->ID) |
|
198 | - && !$this->hasMetaKey($review, $metaKey); |
|
199 | - } |
|
200 | - |
|
201 | - /** |
|
202 | - * @param string $metaKey |
|
203 | - * @return bool |
|
204 | - */ |
|
205 | - protected function hasMetaKey(Review $review, $metaKey = 'rebusify') |
|
206 | - { |
|
207 | - return '' !== glsr(Database::class)->get($review->ID, $metaKey); |
|
208 | - } |
|
209 | - |
|
210 | - /** |
|
211 | - * @param string $key |
|
212 | - * @return bool |
|
213 | - */ |
|
214 | - protected function isEmptyOrModified($key, array $settings) |
|
215 | - { |
|
216 | - $oldValue = glsr_get_option($key); |
|
217 | - $newValue = Arr::get($settings, $key); |
|
218 | - return empty($newValue) || $newValue !== $oldValue; |
|
219 | - } |
|
220 | - |
|
221 | - /** |
|
222 | - * @return array |
|
223 | - */ |
|
224 | - protected function sanitizeRebusifySettings(array $settings) |
|
225 | - { |
|
226 | - $rebusify = glsr(Rebusify::class)->activateKey( |
|
227 | - Arr::get($settings, $this->apiKey), |
|
228 | - Arr::get($settings, $this->emailKey) |
|
229 | - ); |
|
230 | - if ($rebusify->success) { |
|
231 | - update_option($this->rebusifyKey, Arr::get($rebusify->response, 'producttype')); |
|
232 | - } else { |
|
233 | - delete_option($this->rebusifyKey); |
|
234 | - $settings = Arr::set($settings, $this->enabledKey, 'no'); |
|
235 | - glsr(Notice::class)->addError(sprintf( |
|
236 | - __('Your Rebusify account details could not be verified, please try again. %s', 'site-reviews'), |
|
237 | - '('.$rebusify->message.')' |
|
238 | - )); |
|
239 | - } |
|
240 | - return $settings; |
|
241 | - } |
|
15 | + protected $apiKey = 'settings.general.rebusify_serial'; |
|
16 | + protected $emailKey = 'settings.general.rebusify_email'; |
|
17 | + protected $enabledKey = 'settings.general.rebusify'; |
|
18 | + protected $rebusifyKey = '_glsr_rebusify'; |
|
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->rebusifyKey, false); |
|
32 | + if (!$isAccountVerified || $isApiKeyModified || $isEmailModified) { |
|
33 | + $settings = $this->sanitizeRebusifySettings($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 | + $rebusifyProductType = glsr(OptionManager::class)->getWP($this->rebusifyKey); |
|
49 | + if ('P' === $rebusifyProductType) { |
|
50 | + return $context; |
|
51 | + } |
|
52 | + if ('F' === $rebusifyProductType && 'yes' === glsr_get_option('general.rebusify')) { |
|
53 | + $button = $this->buildUpgradeButton(); |
|
54 | + } else { |
|
55 | + $button = $this->buildCreateButton(); |
|
56 | + } |
|
57 | + $context['field'].= $button; |
|
58 | + return $context; |
|
59 | + } |
|
60 | + |
|
61 | + /** |
|
62 | + * Triggered when a review is created. |
|
63 | + * @return void |
|
64 | + * @action site-reviews/review/created |
|
65 | + */ |
|
66 | + public function onCreated(Review $review) |
|
67 | + { |
|
68 | + if (!$this->canPostReview($review)) { |
|
69 | + return; |
|
70 | + } |
|
71 | + $rebusify = glsr(Rebusify::class)->sendReview($review); |
|
72 | + if ($rebusify->success) { |
|
73 | + glsr(Database::class)->set($review->ID, 'rebusify', $rebusify->review_id); |
|
74 | + } |
|
75 | + } |
|
76 | + |
|
77 | + /** |
|
78 | + * Triggered when a review is reverted to its original title/content/date_timestamp. |
|
79 | + * @return void |
|
80 | + * @action site-reviews/review/reverted |
|
81 | + */ |
|
82 | + public function onReverted(Review $review) |
|
83 | + { |
|
84 | + if (!$this->canPostReview($review)) { |
|
85 | + return; |
|
86 | + } |
|
87 | + $rebusify = glsr(Rebusify::class)->sendReview($review); |
|
88 | + if ($rebusify->success) { |
|
89 | + glsr(Database::class)->set($review->ID, 'rebusify', $rebusify->review_id); |
|
90 | + } |
|
91 | + } |
|
92 | + |
|
93 | + /** |
|
94 | + * Triggered when an existing review is updated. |
|
95 | + * @return void |
|
96 | + * @action site-reviews/review/saved |
|
97 | + */ |
|
98 | + public function onSaved(Review $review) |
|
99 | + { |
|
100 | + if (!$this->canPostReview($review)) { |
|
101 | + return; |
|
102 | + } |
|
103 | + $rebusify = glsr(Rebusify::class)->sendReview($review); |
|
104 | + if ($rebusify->success) { |
|
105 | + glsr(Database::class)->set($review->ID, 'rebusify', $rebusify->review_id); |
|
106 | + } |
|
107 | + } |
|
108 | + |
|
109 | + /** |
|
110 | + * Triggered when a review's response is added or updated. |
|
111 | + * @param int $metaId |
|
112 | + * @param int $postId |
|
113 | + * @param string $metaKey |
|
114 | + * @return void |
|
115 | + * @action updated_postmeta |
|
116 | + */ |
|
117 | + public function onUpdatedMeta($metaId, $postId, $metaKey) |
|
118 | + { |
|
119 | + $review = glsr_get_review($postId); |
|
120 | + if (!$this->canPostResponse($review) || '_response' !== $metaKey) { |
|
121 | + return; |
|
122 | + } |
|
123 | + $rebusify = glsr(Rebusify::class)->sendReviewResponse($review); |
|
124 | + if ($rebusify->success) { |
|
125 | + glsr(Database::class)->set($review->ID, 'rebusify_response', true); |
|
126 | + } |
|
127 | + } |
|
128 | + |
|
129 | + /** |
|
130 | + * @return string |
|
131 | + */ |
|
132 | + protected function buildCreateButton() |
|
133 | + { |
|
134 | + return glsr(Builder::class)->a(__('Create Your Rebusify Account', 'site-reviews'), [ |
|
135 | + 'class' => 'button', |
|
136 | + 'href' => Rebusify::WEB_URL, |
|
137 | + 'target' => '_blank', |
|
138 | + ]); |
|
139 | + } |
|
140 | + |
|
141 | + /** |
|
142 | + * @return string |
|
143 | + */ |
|
144 | + protected function buildUpgradeButton() |
|
145 | + { |
|
146 | + $build = glsr(Builder::class); |
|
147 | + $notice = $build->p(__('Free Rebusify accounts are limited to 500 blockchain transactions per year.', 'site-reviews')); |
|
148 | + $button = $build->a(__('Upgrade Your Rebusify Plan', 'site-reviews'), [ |
|
149 | + 'class' => 'button', |
|
150 | + 'href' => Rebusify::WEB_URL, |
|
151 | + 'target' => '_blank', |
|
152 | + ]); |
|
153 | + return $build->div($notice.$button, [ |
|
154 | + 'class' => 'glsr-notice-inline', |
|
155 | + ]); |
|
156 | + } |
|
157 | + |
|
158 | + /** |
|
159 | + * @return bool |
|
160 | + */ |
|
161 | + protected function canPostResponse(Review $review) |
|
162 | + { |
|
163 | + $requiredValues = [ |
|
164 | + glsr(Database::class)->get($review->ID, 'rebusify'), |
|
165 | + $review->response, |
|
166 | + $review->review_id, |
|
167 | + ]; |
|
168 | + return $this->canProceed($review, 'rebusify_response') |
|
169 | + && 'publish' === $review->status |
|
170 | + && 3 === count(array_filter($requiredValues)); |
|
171 | + } |
|
172 | + |
|
173 | + /** |
|
174 | + * @return bool |
|
175 | + */ |
|
176 | + protected function canPostReview(Review $review) |
|
177 | + { |
|
178 | + $requiredValues = [ |
|
179 | + $review->author, |
|
180 | + $review->content, |
|
181 | + $review->rating, |
|
182 | + $review->review_id, |
|
183 | + $review->title, |
|
184 | + ]; |
|
185 | + return $this->canProceed($review) |
|
186 | + && 'publish' === $review->status |
|
187 | + && 5 === count(array_filter($requiredValues)); |
|
188 | + } |
|
189 | + |
|
190 | + /** |
|
191 | + * @param string $metaKey |
|
192 | + * @return bool |
|
193 | + */ |
|
194 | + protected function canProceed(Review $review, $metaKey = 'rebusify') |
|
195 | + { |
|
196 | + return glsr(OptionManager::class)->getBool($this->enabledKey) |
|
197 | + && $this->isReviewPostId($review->ID) |
|
198 | + && !$this->hasMetaKey($review, $metaKey); |
|
199 | + } |
|
200 | + |
|
201 | + /** |
|
202 | + * @param string $metaKey |
|
203 | + * @return bool |
|
204 | + */ |
|
205 | + protected function hasMetaKey(Review $review, $metaKey = 'rebusify') |
|
206 | + { |
|
207 | + return '' !== glsr(Database::class)->get($review->ID, $metaKey); |
|
208 | + } |
|
209 | + |
|
210 | + /** |
|
211 | + * @param string $key |
|
212 | + * @return bool |
|
213 | + */ |
|
214 | + protected function isEmptyOrModified($key, array $settings) |
|
215 | + { |
|
216 | + $oldValue = glsr_get_option($key); |
|
217 | + $newValue = Arr::get($settings, $key); |
|
218 | + return empty($newValue) || $newValue !== $oldValue; |
|
219 | + } |
|
220 | + |
|
221 | + /** |
|
222 | + * @return array |
|
223 | + */ |
|
224 | + protected function sanitizeRebusifySettings(array $settings) |
|
225 | + { |
|
226 | + $rebusify = glsr(Rebusify::class)->activateKey( |
|
227 | + Arr::get($settings, $this->apiKey), |
|
228 | + Arr::get($settings, $this->emailKey) |
|
229 | + ); |
|
230 | + if ($rebusify->success) { |
|
231 | + update_option($this->rebusifyKey, Arr::get($rebusify->response, 'producttype')); |
|
232 | + } else { |
|
233 | + delete_option($this->rebusifyKey); |
|
234 | + $settings = Arr::set($settings, $this->enabledKey, 'no'); |
|
235 | + glsr(Notice::class)->addError(sprintf( |
|
236 | + __('Your Rebusify account details could not be verified, please try again. %s', 'site-reviews'), |
|
237 | + '('.$rebusify->message.')' |
|
238 | + )); |
|
239 | + } |
|
240 | + return $settings; |
|
241 | + } |
|
242 | 242 | } |
@@ -13,163 +13,163 @@ |
||
13 | 13 | |
14 | 14 | class AjaxController extends Controller |
15 | 15 | { |
16 | - /** |
|
17 | - * @return void |
|
18 | - */ |
|
19 | - public function routerChangeStatus(array $request) |
|
20 | - { |
|
21 | - wp_send_json_success($this->execute(new ChangeStatus($request))); |
|
22 | - } |
|
16 | + /** |
|
17 | + * @return void |
|
18 | + */ |
|
19 | + public function routerChangeStatus(array $request) |
|
20 | + { |
|
21 | + wp_send_json_success($this->execute(new ChangeStatus($request))); |
|
22 | + } |
|
23 | 23 | |
24 | - /** |
|
25 | - * @return void |
|
26 | - */ |
|
27 | - public function routerClearConsole() |
|
28 | - { |
|
29 | - glsr(AdminController::class)->routerClearConsole(); |
|
30 | - wp_send_json_success([ |
|
31 | - 'console' => glsr(Console::class)->get(), |
|
32 | - 'notices' => glsr(Notice::class)->get(), |
|
33 | - ]); |
|
34 | - } |
|
24 | + /** |
|
25 | + * @return void |
|
26 | + */ |
|
27 | + public function routerClearConsole() |
|
28 | + { |
|
29 | + glsr(AdminController::class)->routerClearConsole(); |
|
30 | + wp_send_json_success([ |
|
31 | + 'console' => glsr(Console::class)->get(), |
|
32 | + 'notices' => glsr(Notice::class)->get(), |
|
33 | + ]); |
|
34 | + } |
|
35 | 35 | |
36 | - /** |
|
37 | - * @return void |
|
38 | - */ |
|
39 | - public function routerCountReviews() |
|
40 | - { |
|
41 | - glsr(AdminController::class)->routerCountReviews(); |
|
42 | - wp_send_json_success([ |
|
43 | - 'notices' => glsr(Notice::class)->get(), |
|
44 | - ]); |
|
45 | - } |
|
36 | + /** |
|
37 | + * @return void |
|
38 | + */ |
|
39 | + public function routerCountReviews() |
|
40 | + { |
|
41 | + glsr(AdminController::class)->routerCountReviews(); |
|
42 | + wp_send_json_success([ |
|
43 | + 'notices' => glsr(Notice::class)->get(), |
|
44 | + ]); |
|
45 | + } |
|
46 | 46 | |
47 | - /** |
|
48 | - * @return void |
|
49 | - */ |
|
50 | - public function routerDismissNotice(array $request) |
|
51 | - { |
|
52 | - glsr(NoticeController::class)->routerDismissNotice($request); |
|
53 | - wp_send_json_success(); |
|
54 | - } |
|
47 | + /** |
|
48 | + * @return void |
|
49 | + */ |
|
50 | + public function routerDismissNotice(array $request) |
|
51 | + { |
|
52 | + glsr(NoticeController::class)->routerDismissNotice($request); |
|
53 | + wp_send_json_success(); |
|
54 | + } |
|
55 | 55 | |
56 | - /** |
|
57 | - * @return void |
|
58 | - */ |
|
59 | - public function routerMceShortcode(array $request) |
|
60 | - { |
|
61 | - $shortcode = $request['shortcode']; |
|
62 | - $response = false; |
|
63 | - if (array_key_exists($shortcode, glsr()->mceShortcodes)) { |
|
64 | - $data = glsr()->mceShortcodes[$shortcode]; |
|
65 | - if (!empty($data['errors'])) { |
|
66 | - $data['btn_okay'] = [esc_html__('Okay', 'site-reviews')]; |
|
67 | - } |
|
68 | - $response = [ |
|
69 | - 'body' => $data['fields'], |
|
70 | - 'close' => $data['btn_close'], |
|
71 | - 'ok' => $data['btn_okay'], |
|
72 | - 'shortcode' => $shortcode, |
|
73 | - 'title' => $data['title'], |
|
74 | - ]; |
|
75 | - } |
|
76 | - wp_send_json_success($response); |
|
77 | - } |
|
56 | + /** |
|
57 | + * @return void |
|
58 | + */ |
|
59 | + public function routerMceShortcode(array $request) |
|
60 | + { |
|
61 | + $shortcode = $request['shortcode']; |
|
62 | + $response = false; |
|
63 | + if (array_key_exists($shortcode, glsr()->mceShortcodes)) { |
|
64 | + $data = glsr()->mceShortcodes[$shortcode]; |
|
65 | + if (!empty($data['errors'])) { |
|
66 | + $data['btn_okay'] = [esc_html__('Okay', 'site-reviews')]; |
|
67 | + } |
|
68 | + $response = [ |
|
69 | + 'body' => $data['fields'], |
|
70 | + 'close' => $data['btn_close'], |
|
71 | + 'ok' => $data['btn_okay'], |
|
72 | + 'shortcode' => $shortcode, |
|
73 | + 'title' => $data['title'], |
|
74 | + ]; |
|
75 | + } |
|
76 | + wp_send_json_success($response); |
|
77 | + } |
|
78 | 78 | |
79 | - /** |
|
80 | - * @return void |
|
81 | - */ |
|
82 | - public function routerFetchConsole() |
|
83 | - { |
|
84 | - glsr(AdminController::class)->routerFetchConsole(); |
|
85 | - wp_send_json_success([ |
|
86 | - 'console' => glsr(Console::class)->get(), |
|
87 | - 'notices' => glsr(Notice::class)->get(), |
|
88 | - ]); |
|
89 | - } |
|
79 | + /** |
|
80 | + * @return void |
|
81 | + */ |
|
82 | + public function routerFetchConsole() |
|
83 | + { |
|
84 | + glsr(AdminController::class)->routerFetchConsole(); |
|
85 | + wp_send_json_success([ |
|
86 | + 'console' => glsr(Console::class)->get(), |
|
87 | + 'notices' => glsr(Notice::class)->get(), |
|
88 | + ]); |
|
89 | + } |
|
90 | 90 | |
91 | - /** |
|
92 | - * @return void |
|
93 | - */ |
|
94 | - public function routerSearchPosts(array $request) |
|
95 | - { |
|
96 | - $results = glsr(Database::class)->searchPosts($request['search']); |
|
97 | - wp_send_json_success([ |
|
98 | - 'empty' => '<div>'.__('Nothing found.', 'site-reviews').'</div>', |
|
99 | - 'items' => $results, |
|
100 | - ]); |
|
101 | - } |
|
91 | + /** |
|
92 | + * @return void |
|
93 | + */ |
|
94 | + public function routerSearchPosts(array $request) |
|
95 | + { |
|
96 | + $results = glsr(Database::class)->searchPosts($request['search']); |
|
97 | + wp_send_json_success([ |
|
98 | + 'empty' => '<div>'.__('Nothing found.', 'site-reviews').'</div>', |
|
99 | + 'items' => $results, |
|
100 | + ]); |
|
101 | + } |
|
102 | 102 | |
103 | - /** |
|
104 | - * @return void |
|
105 | - */ |
|
106 | - public function routerSearchTranslations(array $request) |
|
107 | - { |
|
108 | - if (empty($request['exclude'])) { |
|
109 | - $request['exclude'] = []; |
|
110 | - } |
|
111 | - $results = glsr(Translation::class) |
|
112 | - ->search($request['search']) |
|
113 | - ->exclude() |
|
114 | - ->exclude($request['exclude']) |
|
115 | - ->renderResults(); |
|
116 | - wp_send_json_success([ |
|
117 | - 'empty' => '<div>'.__('Nothing found.', 'site-reviews').'</div>', |
|
118 | - 'items' => $results, |
|
119 | - ]); |
|
120 | - } |
|
103 | + /** |
|
104 | + * @return void |
|
105 | + */ |
|
106 | + public function routerSearchTranslations(array $request) |
|
107 | + { |
|
108 | + if (empty($request['exclude'])) { |
|
109 | + $request['exclude'] = []; |
|
110 | + } |
|
111 | + $results = glsr(Translation::class) |
|
112 | + ->search($request['search']) |
|
113 | + ->exclude() |
|
114 | + ->exclude($request['exclude']) |
|
115 | + ->renderResults(); |
|
116 | + wp_send_json_success([ |
|
117 | + 'empty' => '<div>'.__('Nothing found.', 'site-reviews').'</div>', |
|
118 | + 'items' => $results, |
|
119 | + ]); |
|
120 | + } |
|
121 | 121 | |
122 | - /** |
|
123 | - * @return void |
|
124 | - */ |
|
125 | - public function routerSubmitReview(array $request) |
|
126 | - { |
|
127 | - $command = glsr(PublicController::class)->routerSubmitReview($request); |
|
128 | - $redirect = trim(strval(get_post_meta($command->post_id, 'redirect_to', true))); |
|
129 | - $redirect = apply_filters('site-reviews/review/redirect', $redirect, $command); |
|
130 | - $data = [ |
|
131 | - 'errors' => glsr()->sessionGet($command->form_id.'errors', false), |
|
132 | - 'message' => glsr()->sessionGet($command->form_id.'message', ''), |
|
133 | - 'recaptcha' => glsr()->sessionGet($command->form_id.'recaptcha', false), |
|
134 | - 'redirect' => $redirect, |
|
135 | - ]; |
|
136 | - if (false === $data['errors']) { |
|
137 | - glsr()->sessionClear(); |
|
138 | - wp_send_json_success($data); |
|
139 | - } |
|
140 | - wp_send_json_error($data); |
|
141 | - } |
|
122 | + /** |
|
123 | + * @return void |
|
124 | + */ |
|
125 | + public function routerSubmitReview(array $request) |
|
126 | + { |
|
127 | + $command = glsr(PublicController::class)->routerSubmitReview($request); |
|
128 | + $redirect = trim(strval(get_post_meta($command->post_id, 'redirect_to', true))); |
|
129 | + $redirect = apply_filters('site-reviews/review/redirect', $redirect, $command); |
|
130 | + $data = [ |
|
131 | + 'errors' => glsr()->sessionGet($command->form_id.'errors', false), |
|
132 | + 'message' => glsr()->sessionGet($command->form_id.'message', ''), |
|
133 | + 'recaptcha' => glsr()->sessionGet($command->form_id.'recaptcha', false), |
|
134 | + 'redirect' => $redirect, |
|
135 | + ]; |
|
136 | + if (false === $data['errors']) { |
|
137 | + glsr()->sessionClear(); |
|
138 | + wp_send_json_success($data); |
|
139 | + } |
|
140 | + wp_send_json_error($data); |
|
141 | + } |
|
142 | 142 | |
143 | - /** |
|
144 | - * @return void |
|
145 | - */ |
|
146 | - public function routerFetchPagedReviews(array $request) |
|
147 | - { |
|
148 | - $urlQuery = []; |
|
149 | - parse_str(parse_url(Arr::get($request, 'url'), PHP_URL_QUERY), $urlQuery); |
|
150 | - $args = [ |
|
151 | - 'paged' => Arr::get($urlQuery, glsr()->constant('PAGED_QUERY_VAR'), 1), |
|
152 | - 'pagedUrl' => home_url(parse_url(Arr::get($request, 'url'), PHP_URL_PATH)), |
|
153 | - 'pagination' => 'ajax', |
|
154 | - 'schema' => false, |
|
155 | - ]; |
|
156 | - $atts = (array) json_decode(Arr::get($request, 'atts')); |
|
157 | - $html = glsr(SiteReviews::class)->build(wp_parse_args($args, $atts)); |
|
158 | - return wp_send_json_success([ |
|
159 | - 'pagination' => $html->getPagination(), |
|
160 | - 'reviews' => $html->getReviews(), |
|
161 | - ]); |
|
162 | - } |
|
143 | + /** |
|
144 | + * @return void |
|
145 | + */ |
|
146 | + public function routerFetchPagedReviews(array $request) |
|
147 | + { |
|
148 | + $urlQuery = []; |
|
149 | + parse_str(parse_url(Arr::get($request, 'url'), PHP_URL_QUERY), $urlQuery); |
|
150 | + $args = [ |
|
151 | + 'paged' => Arr::get($urlQuery, glsr()->constant('PAGED_QUERY_VAR'), 1), |
|
152 | + 'pagedUrl' => home_url(parse_url(Arr::get($request, 'url'), PHP_URL_PATH)), |
|
153 | + 'pagination' => 'ajax', |
|
154 | + 'schema' => false, |
|
155 | + ]; |
|
156 | + $atts = (array) json_decode(Arr::get($request, 'atts')); |
|
157 | + $html = glsr(SiteReviews::class)->build(wp_parse_args($args, $atts)); |
|
158 | + return wp_send_json_success([ |
|
159 | + 'pagination' => $html->getPagination(), |
|
160 | + 'reviews' => $html->getReviews(), |
|
161 | + ]); |
|
162 | + } |
|
163 | 163 | |
164 | - /** |
|
165 | - * @return void |
|
166 | - */ |
|
167 | - public function routerTogglePinned(array $request) |
|
168 | - { |
|
169 | - $isPinned = $this->execute(new TogglePinned($request)); |
|
170 | - wp_send_json_success([ |
|
171 | - 'notices' => glsr(Notice::class)->get(), |
|
172 | - 'pinned' => $isPinned, |
|
173 | - ]); |
|
174 | - } |
|
164 | + /** |
|
165 | + * @return void |
|
166 | + */ |
|
167 | + public function routerTogglePinned(array $request) |
|
168 | + { |
|
169 | + $isPinned = $this->execute(new TogglePinned($request)); |
|
170 | + wp_send_json_success([ |
|
171 | + 'notices' => glsr(Notice::class)->get(), |
|
172 | + 'pinned' => $isPinned, |
|
173 | + ]); |
|
174 | + } |
|
175 | 175 | } |
@@ -8,97 +8,97 @@ |
||
8 | 8 | |
9 | 9 | class TaxonomyController |
10 | 10 | { |
11 | - /** |
|
12 | - * @return void |
|
13 | - * @action Application::TAXONOMY._add_form_fields |
|
14 | - * @action Application::TAXONOMY._edit_form |
|
15 | - */ |
|
16 | - public function disableParents() |
|
17 | - { |
|
18 | - global $wp_taxonomies; |
|
19 | - $wp_taxonomies[Application::TAXONOMY]->hierarchical = false; |
|
20 | - } |
|
11 | + /** |
|
12 | + * @return void |
|
13 | + * @action Application::TAXONOMY._add_form_fields |
|
14 | + * @action Application::TAXONOMY._edit_form |
|
15 | + */ |
|
16 | + public function disableParents() |
|
17 | + { |
|
18 | + global $wp_taxonomies; |
|
19 | + $wp_taxonomies[Application::TAXONOMY]->hierarchical = false; |
|
20 | + } |
|
21 | 21 | |
22 | - /** |
|
23 | - * @return void |
|
24 | - * @action Application::TAXONOMY._term_edit_form_top |
|
25 | - * @action Application::TAXONOMY._term_new_form_tag |
|
26 | - */ |
|
27 | - public function enableParents() |
|
28 | - { |
|
29 | - global $wp_taxonomies; |
|
30 | - $wp_taxonomies[Application::TAXONOMY]->hierarchical = true; |
|
31 | - } |
|
22 | + /** |
|
23 | + * @return void |
|
24 | + * @action Application::TAXONOMY._term_edit_form_top |
|
25 | + * @action Application::TAXONOMY._term_new_form_tag |
|
26 | + */ |
|
27 | + public function enableParents() |
|
28 | + { |
|
29 | + global $wp_taxonomies; |
|
30 | + $wp_taxonomies[Application::TAXONOMY]->hierarchical = true; |
|
31 | + } |
|
32 | 32 | |
33 | - /** |
|
34 | - * @return void |
|
35 | - * @action restrict_manage_posts |
|
36 | - */ |
|
37 | - public function renderTaxonomyFilter() |
|
38 | - { |
|
39 | - if (!is_object_in_taxonomy(glsr_current_screen()->post_type, Application::TAXONOMY)) { |
|
40 | - return; |
|
41 | - } |
|
42 | - echo glsr(Builder::class)->label(__('Filter by category', 'site-reviews'), [ |
|
43 | - 'class' => 'screen-reader-text', |
|
44 | - 'for' => Application::TAXONOMY, |
|
45 | - ]); |
|
46 | - wp_dropdown_categories([ |
|
47 | - 'depth' => 3, |
|
48 | - 'hide_empty' => true, |
|
49 | - 'hide_if_empty' => true, |
|
50 | - 'hierarchical' => true, |
|
51 | - 'name' => Application::TAXONOMY, |
|
52 | - 'orderby' => 'name', |
|
53 | - 'selected' => $this->getSelected(), |
|
54 | - 'show_count' => false, |
|
55 | - 'show_option_all' => $this->getShowOptionAll(), |
|
56 | - 'taxonomy' => Application::TAXONOMY, |
|
57 | - 'value_field' => 'slug', |
|
58 | - ]); |
|
59 | - } |
|
33 | + /** |
|
34 | + * @return void |
|
35 | + * @action restrict_manage_posts |
|
36 | + */ |
|
37 | + public function renderTaxonomyFilter() |
|
38 | + { |
|
39 | + if (!is_object_in_taxonomy(glsr_current_screen()->post_type, Application::TAXONOMY)) { |
|
40 | + return; |
|
41 | + } |
|
42 | + echo glsr(Builder::class)->label(__('Filter by category', 'site-reviews'), [ |
|
43 | + 'class' => 'screen-reader-text', |
|
44 | + 'for' => Application::TAXONOMY, |
|
45 | + ]); |
|
46 | + wp_dropdown_categories([ |
|
47 | + 'depth' => 3, |
|
48 | + 'hide_empty' => true, |
|
49 | + 'hide_if_empty' => true, |
|
50 | + 'hierarchical' => true, |
|
51 | + 'name' => Application::TAXONOMY, |
|
52 | + 'orderby' => 'name', |
|
53 | + 'selected' => $this->getSelected(), |
|
54 | + 'show_count' => false, |
|
55 | + 'show_option_all' => $this->getShowOptionAll(), |
|
56 | + 'taxonomy' => Application::TAXONOMY, |
|
57 | + 'value_field' => 'slug', |
|
58 | + ]); |
|
59 | + } |
|
60 | 60 | |
61 | - /** |
|
62 | - * @param int $postId |
|
63 | - * @param array $terms |
|
64 | - * @param array $newTTIds |
|
65 | - * @param string $taxonomy |
|
66 | - * @param bool $append |
|
67 | - * @param array $oldTTIds |
|
68 | - * @return void |
|
69 | - * @action set_object_terms |
|
70 | - */ |
|
71 | - public function restrictTermSelection($postId, $terms, $newTTIds, $taxonomy, $append, $oldTTIds) |
|
72 | - { |
|
73 | - if (Application::TAXONOMY != $taxonomy || count($newTTIds) <= 1) { |
|
74 | - return; |
|
75 | - } |
|
76 | - $diff = array_diff($newTTIds, $oldTTIds); |
|
77 | - if (empty($newTerm = array_shift($diff))) { |
|
78 | - $newTerm = array_shift($newTTIds); |
|
79 | - } |
|
80 | - if ($newTerm) { |
|
81 | - wp_set_object_terms($postId, intval($newTerm), $taxonomy); |
|
82 | - } |
|
83 | - } |
|
61 | + /** |
|
62 | + * @param int $postId |
|
63 | + * @param array $terms |
|
64 | + * @param array $newTTIds |
|
65 | + * @param string $taxonomy |
|
66 | + * @param bool $append |
|
67 | + * @param array $oldTTIds |
|
68 | + * @return void |
|
69 | + * @action set_object_terms |
|
70 | + */ |
|
71 | + public function restrictTermSelection($postId, $terms, $newTTIds, $taxonomy, $append, $oldTTIds) |
|
72 | + { |
|
73 | + if (Application::TAXONOMY != $taxonomy || count($newTTIds) <= 1) { |
|
74 | + return; |
|
75 | + } |
|
76 | + $diff = array_diff($newTTIds, $oldTTIds); |
|
77 | + if (empty($newTerm = array_shift($diff))) { |
|
78 | + $newTerm = array_shift($newTTIds); |
|
79 | + } |
|
80 | + if ($newTerm) { |
|
81 | + wp_set_object_terms($postId, intval($newTerm), $taxonomy); |
|
82 | + } |
|
83 | + } |
|
84 | 84 | |
85 | - /** |
|
86 | - * @return string |
|
87 | - */ |
|
88 | - protected function getSelected() |
|
89 | - { |
|
90 | - global $wp_query; |
|
91 | - return Arr::get($wp_query->query, Application::TAXONOMY); |
|
92 | - } |
|
85 | + /** |
|
86 | + * @return string |
|
87 | + */ |
|
88 | + protected function getSelected() |
|
89 | + { |
|
90 | + global $wp_query; |
|
91 | + return Arr::get($wp_query->query, Application::TAXONOMY); |
|
92 | + } |
|
93 | 93 | |
94 | - /** |
|
95 | - * @return string |
|
96 | - */ |
|
97 | - protected function getShowOptionAll() |
|
98 | - { |
|
99 | - $taxonomy = get_taxonomy(Application::TAXONOMY); |
|
100 | - return $taxonomy |
|
101 | - ? ucfirst(strtolower($taxonomy->labels->all_items)) |
|
102 | - : ''; |
|
103 | - } |
|
94 | + /** |
|
95 | + * @return string |
|
96 | + */ |
|
97 | + protected function getShowOptionAll() |
|
98 | + { |
|
99 | + $taxonomy = get_taxonomy(Application::TAXONOMY); |
|
100 | + return $taxonomy |
|
101 | + ? ucfirst(strtolower($taxonomy->labels->all_items)) |
|
102 | + : ''; |
|
103 | + } |
|
104 | 104 | } |
@@ -9,113 +9,113 @@ |
||
9 | 9 | |
10 | 10 | class SettingsController extends Controller |
11 | 11 | { |
12 | - /** |
|
13 | - * @param mixed $input |
|
14 | - * @return array |
|
15 | - * @callback register_setting |
|
16 | - */ |
|
17 | - public function callbackRegisterSettings($input) |
|
18 | - { |
|
19 | - $settings = Arr::consolidateArray($input); |
|
20 | - if (1 === count($settings) && array_key_exists('settings', $settings)) { |
|
21 | - $options = array_replace_recursive(glsr(OptionManager::class)->all(), $input); |
|
22 | - $options = $this->sanitizeGeneral($input, $options); |
|
23 | - $options = $this->sanitizeSubmissions($input, $options); |
|
24 | - $options = $this->sanitizeTranslations($input, $options); |
|
25 | - $options = apply_filters('site-reviews/settings/callback', $options, $settings); |
|
26 | - if (filter_input(INPUT_POST, 'option_page') == Application::ID.'-settings') { |
|
27 | - glsr(Notice::class)->addSuccess(__('Settings updated.', 'site-reviews')); |
|
28 | - } |
|
29 | - return $options; |
|
30 | - } |
|
31 | - return $input; |
|
32 | - } |
|
12 | + /** |
|
13 | + * @param mixed $input |
|
14 | + * @return array |
|
15 | + * @callback register_setting |
|
16 | + */ |
|
17 | + public function callbackRegisterSettings($input) |
|
18 | + { |
|
19 | + $settings = Arr::consolidateArray($input); |
|
20 | + if (1 === count($settings) && array_key_exists('settings', $settings)) { |
|
21 | + $options = array_replace_recursive(glsr(OptionManager::class)->all(), $input); |
|
22 | + $options = $this->sanitizeGeneral($input, $options); |
|
23 | + $options = $this->sanitizeSubmissions($input, $options); |
|
24 | + $options = $this->sanitizeTranslations($input, $options); |
|
25 | + $options = apply_filters('site-reviews/settings/callback', $options, $settings); |
|
26 | + if (filter_input(INPUT_POST, 'option_page') == Application::ID.'-settings') { |
|
27 | + glsr(Notice::class)->addSuccess(__('Settings updated.', 'site-reviews')); |
|
28 | + } |
|
29 | + return $options; |
|
30 | + } |
|
31 | + return $input; |
|
32 | + } |
|
33 | 33 | |
34 | - /** |
|
35 | - * @return void |
|
36 | - * @action admin_init |
|
37 | - */ |
|
38 | - public function registerSettings() |
|
39 | - { |
|
40 | - register_setting(Application::ID.'-settings', OptionManager::databaseKey(), [ |
|
41 | - 'sanitize_callback' => [$this, 'callbackRegisterSettings'], |
|
42 | - ]); |
|
43 | - } |
|
34 | + /** |
|
35 | + * @return void |
|
36 | + * @action admin_init |
|
37 | + */ |
|
38 | + public function registerSettings() |
|
39 | + { |
|
40 | + register_setting(Application::ID.'-settings', OptionManager::databaseKey(), [ |
|
41 | + 'sanitize_callback' => [$this, 'callbackRegisterSettings'], |
|
42 | + ]); |
|
43 | + } |
|
44 | 44 | |
45 | - /** |
|
46 | - * @return array |
|
47 | - */ |
|
48 | - protected function sanitizeGeneral(array $input, array $options) |
|
49 | - { |
|
50 | - $inputForm = $input['settings']['general']; |
|
51 | - if (!$this->hasMultilingualIntegration($inputForm['support']['multilingual'])) { |
|
52 | - $options['settings']['general']['support']['multilingual'] = ''; |
|
53 | - } |
|
54 | - if ('' == trim($inputForm['notification_message'])) { |
|
55 | - $options['settings']['general']['notification_message'] = glsr()->defaults['settings']['general']['notification_message']; |
|
56 | - } |
|
57 | - $options['settings']['general']['notifications'] = Arr::get($inputForm, 'notifications', []); |
|
58 | - return $options; |
|
59 | - } |
|
45 | + /** |
|
46 | + * @return array |
|
47 | + */ |
|
48 | + protected function sanitizeGeneral(array $input, array $options) |
|
49 | + { |
|
50 | + $inputForm = $input['settings']['general']; |
|
51 | + if (!$this->hasMultilingualIntegration($inputForm['support']['multilingual'])) { |
|
52 | + $options['settings']['general']['support']['multilingual'] = ''; |
|
53 | + } |
|
54 | + if ('' == trim($inputForm['notification_message'])) { |
|
55 | + $options['settings']['general']['notification_message'] = glsr()->defaults['settings']['general']['notification_message']; |
|
56 | + } |
|
57 | + $options['settings']['general']['notifications'] = Arr::get($inputForm, 'notifications', []); |
|
58 | + return $options; |
|
59 | + } |
|
60 | 60 | |
61 | - /** |
|
62 | - * @return array |
|
63 | - */ |
|
64 | - protected function sanitizeSubmissions(array $input, array $options) |
|
65 | - { |
|
66 | - $inputForm = $input['settings']['submissions']; |
|
67 | - $options['settings']['submissions']['required'] = isset($inputForm['required']) |
|
68 | - ? $inputForm['required'] |
|
69 | - : []; |
|
70 | - return $options; |
|
71 | - } |
|
61 | + /** |
|
62 | + * @return array |
|
63 | + */ |
|
64 | + protected function sanitizeSubmissions(array $input, array $options) |
|
65 | + { |
|
66 | + $inputForm = $input['settings']['submissions']; |
|
67 | + $options['settings']['submissions']['required'] = isset($inputForm['required']) |
|
68 | + ? $inputForm['required'] |
|
69 | + : []; |
|
70 | + return $options; |
|
71 | + } |
|
72 | 72 | |
73 | - /** |
|
74 | - * @return array |
|
75 | - */ |
|
76 | - protected function sanitizeTranslations(array $input, array $options) |
|
77 | - { |
|
78 | - if (isset($input['settings']['strings'])) { |
|
79 | - $options['settings']['strings'] = array_values(array_filter($input['settings']['strings'])); |
|
80 | - $allowedTags = [ |
|
81 | - 'a' => ['class' => [], 'href' => [], 'target' => []], |
|
82 | - 'span' => ['class' => []], |
|
83 | - ]; |
|
84 | - array_walk($options['settings']['strings'], function (&$string) use ($allowedTags) { |
|
85 | - if (isset($string['s2'])) { |
|
86 | - $string['s2'] = wp_kses($string['s2'], $allowedTags); |
|
87 | - } |
|
88 | - if (isset($string['p2'])) { |
|
89 | - $string['p2'] = wp_kses($string['p2'], $allowedTags); |
|
90 | - } |
|
91 | - }); |
|
92 | - } |
|
93 | - return $options; |
|
94 | - } |
|
73 | + /** |
|
74 | + * @return array |
|
75 | + */ |
|
76 | + protected function sanitizeTranslations(array $input, array $options) |
|
77 | + { |
|
78 | + if (isset($input['settings']['strings'])) { |
|
79 | + $options['settings']['strings'] = array_values(array_filter($input['settings']['strings'])); |
|
80 | + $allowedTags = [ |
|
81 | + 'a' => ['class' => [], 'href' => [], 'target' => []], |
|
82 | + 'span' => ['class' => []], |
|
83 | + ]; |
|
84 | + array_walk($options['settings']['strings'], function (&$string) use ($allowedTags) { |
|
85 | + if (isset($string['s2'])) { |
|
86 | + $string['s2'] = wp_kses($string['s2'], $allowedTags); |
|
87 | + } |
|
88 | + if (isset($string['p2'])) { |
|
89 | + $string['p2'] = wp_kses($string['p2'], $allowedTags); |
|
90 | + } |
|
91 | + }); |
|
92 | + } |
|
93 | + return $options; |
|
94 | + } |
|
95 | 95 | |
96 | - /** |
|
97 | - * @return bool |
|
98 | - */ |
|
99 | - protected function hasMultilingualIntegration($integration) |
|
100 | - { |
|
101 | - if (!in_array($integration, ['polylang', 'wpml'])) { |
|
102 | - return false; |
|
103 | - } |
|
104 | - $integrationClass = 'GeminiLabs\SiteReviews\Modules\\'.ucfirst($integration); |
|
105 | - if (!glsr($integrationClass)->isActive()) { |
|
106 | - glsr(Notice::class)->addError(sprintf( |
|
107 | - __('Please install/activate the %s plugin to enable integration.', 'site-reviews'), |
|
108 | - constant($integrationClass.'::PLUGIN_NAME') |
|
109 | - )); |
|
110 | - return false; |
|
111 | - } elseif (!glsr($integrationClass)->isSupported()) { |
|
112 | - glsr(Notice::class)->addError(sprintf( |
|
113 | - __('Please update the %s plugin to v%s or greater to enable integration.', 'site-reviews'), |
|
114 | - constant($integrationClass.'::PLUGIN_NAME'), |
|
115 | - constant($integrationClass.'::SUPPORTED_VERSION') |
|
116 | - )); |
|
117 | - return false; |
|
118 | - } |
|
119 | - return true; |
|
120 | - } |
|
96 | + /** |
|
97 | + * @return bool |
|
98 | + */ |
|
99 | + protected function hasMultilingualIntegration($integration) |
|
100 | + { |
|
101 | + if (!in_array($integration, ['polylang', 'wpml'])) { |
|
102 | + return false; |
|
103 | + } |
|
104 | + $integrationClass = 'GeminiLabs\SiteReviews\Modules\\'.ucfirst($integration); |
|
105 | + if (!glsr($integrationClass)->isActive()) { |
|
106 | + glsr(Notice::class)->addError(sprintf( |
|
107 | + __('Please install/activate the %s plugin to enable integration.', 'site-reviews'), |
|
108 | + constant($integrationClass.'::PLUGIN_NAME') |
|
109 | + )); |
|
110 | + return false; |
|
111 | + } elseif (!glsr($integrationClass)->isSupported()) { |
|
112 | + glsr(Notice::class)->addError(sprintf( |
|
113 | + __('Please update the %s plugin to v%s or greater to enable integration.', 'site-reviews'), |
|
114 | + constant($integrationClass.'::PLUGIN_NAME'), |
|
115 | + constant($integrationClass.'::SUPPORTED_VERSION') |
|
116 | + )); |
|
117 | + return false; |
|
118 | + } |
|
119 | + return true; |
|
120 | + } |
|
121 | 121 | } |
@@ -14,346 +14,346 @@ |
||
14 | 14 | |
15 | 15 | class ListTableController extends Controller |
16 | 16 | { |
17 | - /** |
|
18 | - * @return void |
|
19 | - * @action admin_action_approve |
|
20 | - */ |
|
21 | - public function approve() |
|
22 | - { |
|
23 | - if (Application::ID != filter_input(INPUT_GET, 'plugin')) { |
|
24 | - return; |
|
25 | - } |
|
26 | - check_admin_referer('approve-review_'.($postId = $this->getPostId())); |
|
27 | - wp_update_post([ |
|
28 | - 'ID' => $postId, |
|
29 | - 'post_status' => 'publish', |
|
30 | - ]); |
|
31 | - wp_safe_redirect(wp_get_referer()); |
|
32 | - exit; |
|
33 | - } |
|
17 | + /** |
|
18 | + * @return void |
|
19 | + * @action admin_action_approve |
|
20 | + */ |
|
21 | + public function approve() |
|
22 | + { |
|
23 | + if (Application::ID != filter_input(INPUT_GET, 'plugin')) { |
|
24 | + return; |
|
25 | + } |
|
26 | + check_admin_referer('approve-review_'.($postId = $this->getPostId())); |
|
27 | + wp_update_post([ |
|
28 | + 'ID' => $postId, |
|
29 | + 'post_status' => 'publish', |
|
30 | + ]); |
|
31 | + wp_safe_redirect(wp_get_referer()); |
|
32 | + exit; |
|
33 | + } |
|
34 | 34 | |
35 | - /** |
|
36 | - * @param array $messages |
|
37 | - * @return array |
|
38 | - * @filter bulk_post_updated_messages |
|
39 | - */ |
|
40 | - public function filterBulkUpdateMessages($messages, array $counts) |
|
41 | - { |
|
42 | - $messages = Arr::consolidateArray($messages); |
|
43 | - $messages[Application::POST_TYPE] = [ |
|
44 | - 'updated' => _n('%s review updated.', '%s reviews updated.', $counts['updated'], 'site-reviews'), |
|
45 | - 'locked' => _n('%s review not updated, somebody is editing it.', '%s reviews not updated, somebody is editing them.', $counts['locked'], 'site-reviews'), |
|
46 | - 'deleted' => _n('%s review permanently deleted.', '%s reviews permanently deleted.', $counts['deleted'], 'site-reviews'), |
|
47 | - 'trashed' => _n('%s review moved to the Trash.', '%s reviews moved to the Trash.', $counts['trashed'], 'site-reviews'), |
|
48 | - 'untrashed' => _n('%s review restored from the Trash.', '%s reviews restored from the Trash.', $counts['untrashed'], 'site-reviews'), |
|
49 | - ]; |
|
50 | - return $messages; |
|
51 | - } |
|
35 | + /** |
|
36 | + * @param array $messages |
|
37 | + * @return array |
|
38 | + * @filter bulk_post_updated_messages |
|
39 | + */ |
|
40 | + public function filterBulkUpdateMessages($messages, array $counts) |
|
41 | + { |
|
42 | + $messages = Arr::consolidateArray($messages); |
|
43 | + $messages[Application::POST_TYPE] = [ |
|
44 | + 'updated' => _n('%s review updated.', '%s reviews updated.', $counts['updated'], 'site-reviews'), |
|
45 | + 'locked' => _n('%s review not updated, somebody is editing it.', '%s reviews not updated, somebody is editing them.', $counts['locked'], 'site-reviews'), |
|
46 | + 'deleted' => _n('%s review permanently deleted.', '%s reviews permanently deleted.', $counts['deleted'], 'site-reviews'), |
|
47 | + 'trashed' => _n('%s review moved to the Trash.', '%s reviews moved to the Trash.', $counts['trashed'], 'site-reviews'), |
|
48 | + 'untrashed' => _n('%s review restored from the Trash.', '%s reviews restored from the Trash.', $counts['untrashed'], 'site-reviews'), |
|
49 | + ]; |
|
50 | + return $messages; |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * @param array $columns |
|
55 | - * @return array |
|
56 | - * @filter manage_.Application::POST_TYPE._posts_columns |
|
57 | - */ |
|
58 | - public function filterColumnsForPostType($columns) |
|
59 | - { |
|
60 | - $columns = Arr::consolidateArray($columns); |
|
61 | - $postTypeColumns = glsr()->postTypeColumns[Application::POST_TYPE]; |
|
62 | - foreach ($postTypeColumns as $key => &$value) { |
|
63 | - if (!array_key_exists($key, $columns) || !empty($value)) { |
|
64 | - continue; |
|
65 | - } |
|
66 | - $value = $columns[$key]; |
|
67 | - } |
|
68 | - if (count(glsr(Database::class)->getReviewsMeta('review_type')) < 2) { |
|
69 | - unset($postTypeColumns['review_type']); |
|
70 | - } |
|
71 | - return array_filter($postTypeColumns, 'strlen'); |
|
72 | - } |
|
53 | + /** |
|
54 | + * @param array $columns |
|
55 | + * @return array |
|
56 | + * @filter manage_.Application::POST_TYPE._posts_columns |
|
57 | + */ |
|
58 | + public function filterColumnsForPostType($columns) |
|
59 | + { |
|
60 | + $columns = Arr::consolidateArray($columns); |
|
61 | + $postTypeColumns = glsr()->postTypeColumns[Application::POST_TYPE]; |
|
62 | + foreach ($postTypeColumns as $key => &$value) { |
|
63 | + if (!array_key_exists($key, $columns) || !empty($value)) { |
|
64 | + continue; |
|
65 | + } |
|
66 | + $value = $columns[$key]; |
|
67 | + } |
|
68 | + if (count(glsr(Database::class)->getReviewsMeta('review_type')) < 2) { |
|
69 | + unset($postTypeColumns['review_type']); |
|
70 | + } |
|
71 | + return array_filter($postTypeColumns, 'strlen'); |
|
72 | + } |
|
73 | 73 | |
74 | - /** |
|
75 | - * @param string $status |
|
76 | - * @param WP_Post $post |
|
77 | - * @return string |
|
78 | - * @filter post_date_column_status |
|
79 | - */ |
|
80 | - public function filterDateColumnStatus($status, $post) |
|
81 | - { |
|
82 | - if (Application::POST_TYPE == Arr::get($post, 'post_type')) { |
|
83 | - $status = __('Submitted', 'site-reviews'); |
|
84 | - } |
|
85 | - return $status; |
|
86 | - } |
|
74 | + /** |
|
75 | + * @param string $status |
|
76 | + * @param WP_Post $post |
|
77 | + * @return string |
|
78 | + * @filter post_date_column_status |
|
79 | + */ |
|
80 | + public function filterDateColumnStatus($status, $post) |
|
81 | + { |
|
82 | + if (Application::POST_TYPE == Arr::get($post, 'post_type')) { |
|
83 | + $status = __('Submitted', 'site-reviews'); |
|
84 | + } |
|
85 | + return $status; |
|
86 | + } |
|
87 | 87 | |
88 | - /** |
|
89 | - * @param array $hidden |
|
90 | - * @param WP_Screen $post |
|
91 | - * @return array |
|
92 | - * @filter default_hidden_columns |
|
93 | - */ |
|
94 | - public function filterDefaultHiddenColumns($hidden, $screen) |
|
95 | - { |
|
96 | - if (Arr::get($screen, 'id') == 'edit-'.Application::POST_TYPE) { |
|
97 | - $hidden = Arr::consolidateArray($hidden); |
|
98 | - $hidden = ['reviewer']; |
|
99 | - } |
|
100 | - return $hidden; |
|
101 | - } |
|
88 | + /** |
|
89 | + * @param array $hidden |
|
90 | + * @param WP_Screen $post |
|
91 | + * @return array |
|
92 | + * @filter default_hidden_columns |
|
93 | + */ |
|
94 | + public function filterDefaultHiddenColumns($hidden, $screen) |
|
95 | + { |
|
96 | + if (Arr::get($screen, 'id') == 'edit-'.Application::POST_TYPE) { |
|
97 | + $hidden = Arr::consolidateArray($hidden); |
|
98 | + $hidden = ['reviewer']; |
|
99 | + } |
|
100 | + return $hidden; |
|
101 | + } |
|
102 | 102 | |
103 | - /** |
|
104 | - * @param array $postStates |
|
105 | - * @param WP_Post $post |
|
106 | - * @return array |
|
107 | - * @filter display_post_states |
|
108 | - */ |
|
109 | - public function filterPostStates($postStates, $post) |
|
110 | - { |
|
111 | - $postStates = Arr::consolidateArray($postStates); |
|
112 | - if (Application::POST_TYPE == Arr::get($post, 'post_type') && array_key_exists('pending', $postStates)) { |
|
113 | - $postStates['pending'] = __('Unapproved', 'site-reviews'); |
|
114 | - } |
|
115 | - return $postStates; |
|
116 | - } |
|
103 | + /** |
|
104 | + * @param array $postStates |
|
105 | + * @param WP_Post $post |
|
106 | + * @return array |
|
107 | + * @filter display_post_states |
|
108 | + */ |
|
109 | + public function filterPostStates($postStates, $post) |
|
110 | + { |
|
111 | + $postStates = Arr::consolidateArray($postStates); |
|
112 | + if (Application::POST_TYPE == Arr::get($post, 'post_type') && array_key_exists('pending', $postStates)) { |
|
113 | + $postStates['pending'] = __('Unapproved', 'site-reviews'); |
|
114 | + } |
|
115 | + return $postStates; |
|
116 | + } |
|
117 | 117 | |
118 | - /** |
|
119 | - * @param array $actions |
|
120 | - * @param WP_Post $post |
|
121 | - * @return array |
|
122 | - * @filter post_row_actions |
|
123 | - */ |
|
124 | - public function filterRowActions($actions, $post) |
|
125 | - { |
|
126 | - if (Application::POST_TYPE != Arr::get($post, 'post_type') || 'trash' == $post->post_status) { |
|
127 | - return $actions; |
|
128 | - } |
|
129 | - unset($actions['inline hide-if-no-js']); //Remove Quick-edit |
|
130 | - $rowActions = [ |
|
131 | - 'approve' => esc_attr__('Approve', 'site-reviews'), |
|
132 | - 'unapprove' => esc_attr__('Unapprove', 'site-reviews'), |
|
133 | - ]; |
|
134 | - $newActions = []; |
|
135 | - foreach ($rowActions as $key => $text) { |
|
136 | - $newActions[$key] = glsr(Builder::class)->a($text, [ |
|
137 | - 'aria-label' => sprintf(esc_attr_x('%s this review', 'Approve the review', 'site-reviews'), $text), |
|
138 | - 'class' => 'glsr-change-status', |
|
139 | - 'href' => wp_nonce_url( |
|
140 | - admin_url('post.php?post='.$post->ID.'&action='.$key.'&plugin='.Application::ID), |
|
141 | - $key.'-review_'.$post->ID |
|
142 | - ), |
|
143 | - ]); |
|
144 | - } |
|
145 | - return $newActions + Arr::consolidateArray($actions); |
|
146 | - } |
|
118 | + /** |
|
119 | + * @param array $actions |
|
120 | + * @param WP_Post $post |
|
121 | + * @return array |
|
122 | + * @filter post_row_actions |
|
123 | + */ |
|
124 | + public function filterRowActions($actions, $post) |
|
125 | + { |
|
126 | + if (Application::POST_TYPE != Arr::get($post, 'post_type') || 'trash' == $post->post_status) { |
|
127 | + return $actions; |
|
128 | + } |
|
129 | + unset($actions['inline hide-if-no-js']); //Remove Quick-edit |
|
130 | + $rowActions = [ |
|
131 | + 'approve' => esc_attr__('Approve', 'site-reviews'), |
|
132 | + 'unapprove' => esc_attr__('Unapprove', 'site-reviews'), |
|
133 | + ]; |
|
134 | + $newActions = []; |
|
135 | + foreach ($rowActions as $key => $text) { |
|
136 | + $newActions[$key] = glsr(Builder::class)->a($text, [ |
|
137 | + 'aria-label' => sprintf(esc_attr_x('%s this review', 'Approve the review', 'site-reviews'), $text), |
|
138 | + 'class' => 'glsr-change-status', |
|
139 | + 'href' => wp_nonce_url( |
|
140 | + admin_url('post.php?post='.$post->ID.'&action='.$key.'&plugin='.Application::ID), |
|
141 | + $key.'-review_'.$post->ID |
|
142 | + ), |
|
143 | + ]); |
|
144 | + } |
|
145 | + return $newActions + Arr::consolidateArray($actions); |
|
146 | + } |
|
147 | 147 | |
148 | - /** |
|
149 | - * @param array $columns |
|
150 | - * @return array |
|
151 | - * @filter manage_edit-.Application::POST_TYPE._sortable_columns |
|
152 | - */ |
|
153 | - public function filterSortableColumns($columns) |
|
154 | - { |
|
155 | - $columns = Arr::consolidateArray($columns); |
|
156 | - $postTypeColumns = glsr()->postTypeColumns[Application::POST_TYPE]; |
|
157 | - unset($postTypeColumns['cb']); |
|
158 | - foreach ($postTypeColumns as $key => $value) { |
|
159 | - if (Str::startsWith('taxonomy', $key)) { |
|
160 | - continue; |
|
161 | - } |
|
162 | - $columns[$key] = $key; |
|
163 | - } |
|
164 | - return $columns; |
|
165 | - } |
|
148 | + /** |
|
149 | + * @param array $columns |
|
150 | + * @return array |
|
151 | + * @filter manage_edit-.Application::POST_TYPE._sortable_columns |
|
152 | + */ |
|
153 | + public function filterSortableColumns($columns) |
|
154 | + { |
|
155 | + $columns = Arr::consolidateArray($columns); |
|
156 | + $postTypeColumns = glsr()->postTypeColumns[Application::POST_TYPE]; |
|
157 | + unset($postTypeColumns['cb']); |
|
158 | + foreach ($postTypeColumns as $key => $value) { |
|
159 | + if (Str::startsWith('taxonomy', $key)) { |
|
160 | + continue; |
|
161 | + } |
|
162 | + $columns[$key] = $key; |
|
163 | + } |
|
164 | + return $columns; |
|
165 | + } |
|
166 | 166 | |
167 | - /** |
|
168 | - * Customize the post_type status text. |
|
169 | - * @param string $translation |
|
170 | - * @param string $single |
|
171 | - * @param string $plural |
|
172 | - * @param int $number |
|
173 | - * @param string $domain |
|
174 | - * @return string |
|
175 | - * @filter ngettext |
|
176 | - */ |
|
177 | - public function filterStatusText($translation, $single, $plural, $number, $domain) |
|
178 | - { |
|
179 | - if ($this->canModifyTranslation($domain)) { |
|
180 | - $strings = [ |
|
181 | - 'Published' => __('Approved', 'site-reviews'), |
|
182 | - 'Pending' => __('Unapproved', 'site-reviews'), |
|
183 | - ]; |
|
184 | - foreach ($strings as $search => $replace) { |
|
185 | - if (false === strpos($single, $search)) { |
|
186 | - continue; |
|
187 | - } |
|
188 | - $translation = $this->getTranslation([ |
|
189 | - 'number' => $number, |
|
190 | - 'plural' => str_replace($search, $replace, $plural), |
|
191 | - 'single' => str_replace($search, $replace, $single), |
|
192 | - ]); |
|
193 | - } |
|
194 | - } |
|
195 | - return $translation; |
|
196 | - } |
|
167 | + /** |
|
168 | + * Customize the post_type status text. |
|
169 | + * @param string $translation |
|
170 | + * @param string $single |
|
171 | + * @param string $plural |
|
172 | + * @param int $number |
|
173 | + * @param string $domain |
|
174 | + * @return string |
|
175 | + * @filter ngettext |
|
176 | + */ |
|
177 | + public function filterStatusText($translation, $single, $plural, $number, $domain) |
|
178 | + { |
|
179 | + if ($this->canModifyTranslation($domain)) { |
|
180 | + $strings = [ |
|
181 | + 'Published' => __('Approved', 'site-reviews'), |
|
182 | + 'Pending' => __('Unapproved', 'site-reviews'), |
|
183 | + ]; |
|
184 | + foreach ($strings as $search => $replace) { |
|
185 | + if (false === strpos($single, $search)) { |
|
186 | + continue; |
|
187 | + } |
|
188 | + $translation = $this->getTranslation([ |
|
189 | + 'number' => $number, |
|
190 | + 'plural' => str_replace($search, $replace, $plural), |
|
191 | + 'single' => str_replace($search, $replace, $single), |
|
192 | + ]); |
|
193 | + } |
|
194 | + } |
|
195 | + return $translation; |
|
196 | + } |
|
197 | 197 | |
198 | - /** |
|
199 | - * @param string $columnName |
|
200 | - * @param string $postType |
|
201 | - * @return void |
|
202 | - * @action bulk_edit_custom_box |
|
203 | - */ |
|
204 | - public function renderBulkEditFields($columnName, $postType) |
|
205 | - { |
|
206 | - if ('assigned_to' == $columnName && Application::POST_TYPE == $postType) { |
|
207 | - glsr()->render('partials/editor/bulk-edit-assigned-to'); |
|
208 | - } |
|
209 | - } |
|
198 | + /** |
|
199 | + * @param string $columnName |
|
200 | + * @param string $postType |
|
201 | + * @return void |
|
202 | + * @action bulk_edit_custom_box |
|
203 | + */ |
|
204 | + public function renderBulkEditFields($columnName, $postType) |
|
205 | + { |
|
206 | + if ('assigned_to' == $columnName && Application::POST_TYPE == $postType) { |
|
207 | + glsr()->render('partials/editor/bulk-edit-assigned-to'); |
|
208 | + } |
|
209 | + } |
|
210 | 210 | |
211 | - /** |
|
212 | - * @param string $postType |
|
213 | - * @return void |
|
214 | - * @action restrict_manage_posts |
|
215 | - */ |
|
216 | - public function renderColumnFilters($postType) |
|
217 | - { |
|
218 | - glsr(Columns::class)->renderFilters($postType); |
|
219 | - } |
|
211 | + /** |
|
212 | + * @param string $postType |
|
213 | + * @return void |
|
214 | + * @action restrict_manage_posts |
|
215 | + */ |
|
216 | + public function renderColumnFilters($postType) |
|
217 | + { |
|
218 | + glsr(Columns::class)->renderFilters($postType); |
|
219 | + } |
|
220 | 220 | |
221 | - /** |
|
222 | - * @param string $column |
|
223 | - * @param string $postId |
|
224 | - * @return void |
|
225 | - * @action manage_posts_custom_column |
|
226 | - */ |
|
227 | - public function renderColumnValues($column, $postId) |
|
228 | - { |
|
229 | - glsr(Columns::class)->renderValues($column, $postId); |
|
230 | - } |
|
221 | + /** |
|
222 | + * @param string $column |
|
223 | + * @param string $postId |
|
224 | + * @return void |
|
225 | + * @action manage_posts_custom_column |
|
226 | + */ |
|
227 | + public function renderColumnValues($column, $postId) |
|
228 | + { |
|
229 | + glsr(Columns::class)->renderValues($column, $postId); |
|
230 | + } |
|
231 | 231 | |
232 | - /** |
|
233 | - * @param int $postId |
|
234 | - * @return void |
|
235 | - * @action save_post_.Application::POST_TYPE |
|
236 | - */ |
|
237 | - public function saveBulkEditFields($postId) |
|
238 | - { |
|
239 | - if (!current_user_can('edit_posts')) { |
|
240 | - return; |
|
241 | - } |
|
242 | - $assignedTo = filter_input(INPUT_GET, 'assigned_to'); |
|
243 | - if ($assignedTo && get_post($assignedTo)) { |
|
244 | - glsr(Database::class)->update($postId, 'assigned_to', $assignedTo); |
|
245 | - } |
|
246 | - } |
|
232 | + /** |
|
233 | + * @param int $postId |
|
234 | + * @return void |
|
235 | + * @action save_post_.Application::POST_TYPE |
|
236 | + */ |
|
237 | + public function saveBulkEditFields($postId) |
|
238 | + { |
|
239 | + if (!current_user_can('edit_posts')) { |
|
240 | + return; |
|
241 | + } |
|
242 | + $assignedTo = filter_input(INPUT_GET, 'assigned_to'); |
|
243 | + if ($assignedTo && get_post($assignedTo)) { |
|
244 | + glsr(Database::class)->update($postId, 'assigned_to', $assignedTo); |
|
245 | + } |
|
246 | + } |
|
247 | 247 | |
248 | - /** |
|
249 | - * @return void |
|
250 | - * @action pre_get_posts |
|
251 | - */ |
|
252 | - public function setQueryForColumn(WP_Query $query) |
|
253 | - { |
|
254 | - if (!$this->hasPermission($query)) { |
|
255 | - return; |
|
256 | - } |
|
257 | - $this->setMetaQuery($query, [ |
|
258 | - 'rating', 'review_type', |
|
259 | - ]); |
|
260 | - $this->setOrderby($query); |
|
261 | - } |
|
248 | + /** |
|
249 | + * @return void |
|
250 | + * @action pre_get_posts |
|
251 | + */ |
|
252 | + public function setQueryForColumn(WP_Query $query) |
|
253 | + { |
|
254 | + if (!$this->hasPermission($query)) { |
|
255 | + return; |
|
256 | + } |
|
257 | + $this->setMetaQuery($query, [ |
|
258 | + 'rating', 'review_type', |
|
259 | + ]); |
|
260 | + $this->setOrderby($query); |
|
261 | + } |
|
262 | 262 | |
263 | - /** |
|
264 | - * @return void |
|
265 | - * @action admin_action_unapprove |
|
266 | - */ |
|
267 | - public function unapprove() |
|
268 | - { |
|
269 | - if (Application::ID != filter_input(INPUT_GET, 'plugin')) { |
|
270 | - return; |
|
271 | - } |
|
272 | - check_admin_referer('unapprove-review_'.($postId = $this->getPostId())); |
|
273 | - wp_update_post([ |
|
274 | - 'ID' => $postId, |
|
275 | - 'post_status' => 'pending', |
|
276 | - ]); |
|
277 | - wp_safe_redirect(wp_get_referer()); |
|
278 | - exit; |
|
279 | - } |
|
263 | + /** |
|
264 | + * @return void |
|
265 | + * @action admin_action_unapprove |
|
266 | + */ |
|
267 | + public function unapprove() |
|
268 | + { |
|
269 | + if (Application::ID != filter_input(INPUT_GET, 'plugin')) { |
|
270 | + return; |
|
271 | + } |
|
272 | + check_admin_referer('unapprove-review_'.($postId = $this->getPostId())); |
|
273 | + wp_update_post([ |
|
274 | + 'ID' => $postId, |
|
275 | + 'post_status' => 'pending', |
|
276 | + ]); |
|
277 | + wp_safe_redirect(wp_get_referer()); |
|
278 | + exit; |
|
279 | + } |
|
280 | 280 | |
281 | - /** |
|
282 | - * Check if the translation string can be modified. |
|
283 | - * @param string $domain |
|
284 | - * @return bool |
|
285 | - */ |
|
286 | - protected function canModifyTranslation($domain = 'default') |
|
287 | - { |
|
288 | - $screen = glsr_current_screen(); |
|
289 | - return 'default' == $domain |
|
290 | - && 'edit' == $screen->base |
|
291 | - && Application::POST_TYPE == $screen->post_type; |
|
292 | - } |
|
281 | + /** |
|
282 | + * Check if the translation string can be modified. |
|
283 | + * @param string $domain |
|
284 | + * @return bool |
|
285 | + */ |
|
286 | + protected function canModifyTranslation($domain = 'default') |
|
287 | + { |
|
288 | + $screen = glsr_current_screen(); |
|
289 | + return 'default' == $domain |
|
290 | + && 'edit' == $screen->base |
|
291 | + && Application::POST_TYPE == $screen->post_type; |
|
292 | + } |
|
293 | 293 | |
294 | - /** |
|
295 | - * Get the modified translation string. |
|
296 | - * @return string |
|
297 | - */ |
|
298 | - protected function getTranslation(array $args) |
|
299 | - { |
|
300 | - $defaults = [ |
|
301 | - 'number' => 0, |
|
302 | - 'plural' => '', |
|
303 | - 'single' => '', |
|
304 | - 'text' => '', |
|
305 | - ]; |
|
306 | - $args = (object) wp_parse_args($args, $defaults); |
|
307 | - $translations = get_translations_for_domain(Application::ID); |
|
308 | - return $args->text |
|
309 | - ? $translations->translate($args->text) |
|
310 | - : $translations->translate_plural($args->single, $args->plural, $args->number); |
|
311 | - } |
|
294 | + /** |
|
295 | + * Get the modified translation string. |
|
296 | + * @return string |
|
297 | + */ |
|
298 | + protected function getTranslation(array $args) |
|
299 | + { |
|
300 | + $defaults = [ |
|
301 | + 'number' => 0, |
|
302 | + 'plural' => '', |
|
303 | + 'single' => '', |
|
304 | + 'text' => '', |
|
305 | + ]; |
|
306 | + $args = (object) wp_parse_args($args, $defaults); |
|
307 | + $translations = get_translations_for_domain(Application::ID); |
|
308 | + return $args->text |
|
309 | + ? $translations->translate($args->text) |
|
310 | + : $translations->translate_plural($args->single, $args->plural, $args->number); |
|
311 | + } |
|
312 | 312 | |
313 | - /** |
|
314 | - * @return bool |
|
315 | - */ |
|
316 | - protected function hasPermission(WP_Query $query) |
|
317 | - { |
|
318 | - global $pagenow; |
|
319 | - return is_admin() |
|
320 | - && $query->is_main_query() |
|
321 | - && Application::POST_TYPE == $query->get('post_type') |
|
322 | - && 'edit.php' == $pagenow; |
|
323 | - } |
|
313 | + /** |
|
314 | + * @return bool |
|
315 | + */ |
|
316 | + protected function hasPermission(WP_Query $query) |
|
317 | + { |
|
318 | + global $pagenow; |
|
319 | + return is_admin() |
|
320 | + && $query->is_main_query() |
|
321 | + && Application::POST_TYPE == $query->get('post_type') |
|
322 | + && 'edit.php' == $pagenow; |
|
323 | + } |
|
324 | 324 | |
325 | - /** |
|
326 | - * @return void |
|
327 | - */ |
|
328 | - protected function setMetaQuery(WP_Query $query, array $metaKeys) |
|
329 | - { |
|
330 | - foreach ($metaKeys as $key) { |
|
331 | - if (!($value = filter_input(INPUT_GET, $key))) { |
|
332 | - continue; |
|
333 | - } |
|
334 | - $metaQuery = (array) $query->get('meta_query'); |
|
335 | - $metaQuery[] = [ |
|
336 | - 'key' => Str::prefix('_', $key), |
|
337 | - 'value' => $value, |
|
338 | - ]; |
|
339 | - $query->set('meta_query', $metaQuery); |
|
340 | - } |
|
341 | - } |
|
325 | + /** |
|
326 | + * @return void |
|
327 | + */ |
|
328 | + protected function setMetaQuery(WP_Query $query, array $metaKeys) |
|
329 | + { |
|
330 | + foreach ($metaKeys as $key) { |
|
331 | + if (!($value = filter_input(INPUT_GET, $key))) { |
|
332 | + continue; |
|
333 | + } |
|
334 | + $metaQuery = (array) $query->get('meta_query'); |
|
335 | + $metaQuery[] = [ |
|
336 | + 'key' => Str::prefix('_', $key), |
|
337 | + 'value' => $value, |
|
338 | + ]; |
|
339 | + $query->set('meta_query', $metaQuery); |
|
340 | + } |
|
341 | + } |
|
342 | 342 | |
343 | - /** |
|
344 | - * @return void |
|
345 | - */ |
|
346 | - protected function setOrderby(WP_Query $query) |
|
347 | - { |
|
348 | - $orderby = $query->get('orderby'); |
|
349 | - $columns = glsr()->postTypeColumns[Application::POST_TYPE]; |
|
350 | - unset($columns['cb'], $columns['title'], $columns['date']); |
|
351 | - if (in_array($orderby, array_keys($columns))) { |
|
352 | - if ('reviewer' == $orderby) { |
|
353 | - $orderby = '_author'; |
|
354 | - } |
|
355 | - $query->set('meta_key', $orderby); |
|
356 | - $query->set('orderby', 'meta_value'); |
|
357 | - } |
|
358 | - } |
|
343 | + /** |
|
344 | + * @return void |
|
345 | + */ |
|
346 | + protected function setOrderby(WP_Query $query) |
|
347 | + { |
|
348 | + $orderby = $query->get('orderby'); |
|
349 | + $columns = glsr()->postTypeColumns[Application::POST_TYPE]; |
|
350 | + unset($columns['cb'], $columns['title'], $columns['date']); |
|
351 | + if (in_array($orderby, array_keys($columns))) { |
|
352 | + if ('reviewer' == $orderby) { |
|
353 | + $orderby = '_author'; |
|
354 | + } |
|
355 | + $query->set('meta_key', $orderby); |
|
356 | + $query->set('orderby', 'meta_value'); |
|
357 | + } |
|
358 | + } |
|
359 | 359 | } |
@@ -8,97 +8,97 @@ |
||
8 | 8 | |
9 | 9 | class NoticeController extends Controller |
10 | 10 | { |
11 | - const USER_META_KEY = '_glsr_notices'; |
|
11 | + const USER_META_KEY = '_glsr_notices'; |
|
12 | 12 | |
13 | - /** |
|
14 | - * @return void |
|
15 | - * @action admin_notices |
|
16 | - */ |
|
17 | - public function filterAdminNotices() |
|
18 | - { |
|
19 | - $screen = glsr_current_screen(); |
|
20 | - $this->renderWelcomeNotice($screen->post_type); |
|
21 | - $this->renderRebusifyNotice($screen->post_type); |
|
22 | - $this->renderAddonsNotice($screen->id); |
|
23 | - } |
|
13 | + /** |
|
14 | + * @return void |
|
15 | + * @action admin_notices |
|
16 | + */ |
|
17 | + public function filterAdminNotices() |
|
18 | + { |
|
19 | + $screen = glsr_current_screen(); |
|
20 | + $this->renderWelcomeNotice($screen->post_type); |
|
21 | + $this->renderRebusifyNotice($screen->post_type); |
|
22 | + $this->renderAddonsNotice($screen->id); |
|
23 | + } |
|
24 | 24 | |
25 | - /** |
|
26 | - * @return void |
|
27 | - */ |
|
28 | - public function routerDismissNotice(array $request) |
|
29 | - { |
|
30 | - if ($key = Arr::get($request, 'notice')) { |
|
31 | - $this->dismissNotice($key); |
|
32 | - } |
|
33 | - } |
|
25 | + /** |
|
26 | + * @return void |
|
27 | + */ |
|
28 | + public function routerDismissNotice(array $request) |
|
29 | + { |
|
30 | + if ($key = Arr::get($request, 'notice')) { |
|
31 | + $this->dismissNotice($key); |
|
32 | + } |
|
33 | + } |
|
34 | 34 | |
35 | - /** |
|
36 | - * @param string $key |
|
37 | - * @return void |
|
38 | - */ |
|
39 | - protected function dismissNotice($key) |
|
40 | - { |
|
41 | - $this->setUserMeta($key, glsr()->version('major')); |
|
42 | - } |
|
35 | + /** |
|
36 | + * @param string $key |
|
37 | + * @return void |
|
38 | + */ |
|
39 | + protected function dismissNotice($key) |
|
40 | + { |
|
41 | + $this->setUserMeta($key, glsr()->version('major')); |
|
42 | + } |
|
43 | 43 | |
44 | - /** |
|
45 | - * @param string $key |
|
46 | - * @param mixed $fallback |
|
47 | - * @return mixed |
|
48 | - */ |
|
49 | - protected function getUserMeta($key, $fallback) |
|
50 | - { |
|
51 | - $meta = get_user_meta(get_current_user_id(), static::USER_META_KEY, true); |
|
52 | - return Arr::get($meta, $key, $fallback); |
|
53 | - } |
|
44 | + /** |
|
45 | + * @param string $key |
|
46 | + * @param mixed $fallback |
|
47 | + * @return mixed |
|
48 | + */ |
|
49 | + protected function getUserMeta($key, $fallback) |
|
50 | + { |
|
51 | + $meta = get_user_meta(get_current_user_id(), static::USER_META_KEY, true); |
|
52 | + return Arr::get($meta, $key, $fallback); |
|
53 | + } |
|
54 | 54 | |
55 | - /** |
|
56 | - * @param string $screenId |
|
57 | - * @return void |
|
58 | - */ |
|
59 | - protected function renderAddonsNotice($screenId) |
|
60 | - { |
|
61 | - if (Application::POST_TYPE.'_page_addons' == $screenId) { |
|
62 | - echo glsr()->render('partials/notices/addons'); |
|
63 | - } |
|
64 | - } |
|
55 | + /** |
|
56 | + * @param string $screenId |
|
57 | + * @return void |
|
58 | + */ |
|
59 | + protected function renderAddonsNotice($screenId) |
|
60 | + { |
|
61 | + if (Application::POST_TYPE.'_page_addons' == $screenId) { |
|
62 | + echo glsr()->render('partials/notices/addons'); |
|
63 | + } |
|
64 | + } |
|
65 | 65 | |
66 | - /** |
|
67 | - * @param string $screenPostType |
|
68 | - * @return void |
|
69 | - */ |
|
70 | - protected function renderRebusifyNotice($screenPostType) |
|
71 | - { |
|
72 | - if (Application::POST_TYPE == $screenPostType |
|
73 | - && version_compare(glsr()->version('major'), $this->getUserMeta('rebusify', 0), '>') |
|
74 | - && !glsr(OptionManager::class)->getBool('settings.general.rebusify')) { |
|
75 | - echo glsr()->render('partials/notices/rebusify'); |
|
76 | - } |
|
77 | - } |
|
66 | + /** |
|
67 | + * @param string $screenPostType |
|
68 | + * @return void |
|
69 | + */ |
|
70 | + protected function renderRebusifyNotice($screenPostType) |
|
71 | + { |
|
72 | + if (Application::POST_TYPE == $screenPostType |
|
73 | + && version_compare(glsr()->version('major'), $this->getUserMeta('rebusify', 0), '>') |
|
74 | + && !glsr(OptionManager::class)->getBool('settings.general.rebusify')) { |
|
75 | + echo glsr()->render('partials/notices/rebusify'); |
|
76 | + } |
|
77 | + } |
|
78 | 78 | |
79 | - /** |
|
80 | - * @param string $screenPostType |
|
81 | - * @return void |
|
82 | - */ |
|
83 | - protected function renderWelcomeNotice($screenPostType) |
|
84 | - { |
|
85 | - if (Application::POST_TYPE == $screenPostType |
|
86 | - && version_compare(glsr()->version('major'), $this->getUserMeta('welcome', 0), '>')) { |
|
87 | - echo glsr()->render('partials/notices/welcome'); |
|
88 | - } |
|
89 | - } |
|
79 | + /** |
|
80 | + * @param string $screenPostType |
|
81 | + * @return void |
|
82 | + */ |
|
83 | + protected function renderWelcomeNotice($screenPostType) |
|
84 | + { |
|
85 | + if (Application::POST_TYPE == $screenPostType |
|
86 | + && version_compare(glsr()->version('major'), $this->getUserMeta('welcome', 0), '>')) { |
|
87 | + echo glsr()->render('partials/notices/welcome'); |
|
88 | + } |
|
89 | + } |
|
90 | 90 | |
91 | - /** |
|
92 | - * @param string $key |
|
93 | - * @param mixed $fallback |
|
94 | - * @return mixed |
|
95 | - */ |
|
96 | - protected function setUserMeta($key, $value) |
|
97 | - { |
|
98 | - $userId = get_current_user_id(); |
|
99 | - $meta = (array) get_user_meta($userId, static::USER_META_KEY, true); |
|
100 | - $meta = array_filter(wp_parse_args($meta, [])); |
|
101 | - $meta[$key] = $value; |
|
102 | - update_user_meta($userId, static::USER_META_KEY, $meta); |
|
103 | - } |
|
91 | + /** |
|
92 | + * @param string $key |
|
93 | + * @param mixed $fallback |
|
94 | + * @return mixed |
|
95 | + */ |
|
96 | + protected function setUserMeta($key, $value) |
|
97 | + { |
|
98 | + $userId = get_current_user_id(); |
|
99 | + $meta = (array) get_user_meta($userId, static::USER_META_KEY, true); |
|
100 | + $meta = array_filter(wp_parse_args($meta, [])); |
|
101 | + $meta[$key] = $value; |
|
102 | + update_user_meta($userId, static::USER_META_KEY, $meta); |
|
103 | + } |
|
104 | 104 | } |
@@ -13,139 +13,139 @@ |
||
13 | 13 | |
14 | 14 | class ReviewController extends Controller |
15 | 15 | { |
16 | - /** |
|
17 | - * @param int $postId |
|
18 | - * @param array $terms |
|
19 | - * @param array $newTTIds |
|
20 | - * @param string $taxonomy |
|
21 | - * @param bool $append |
|
22 | - * @param array $oldTTIds |
|
23 | - * @return void |
|
24 | - * @action set_object_terms |
|
25 | - */ |
|
26 | - public function onAfterChangeCategory($postId, $terms, $newTTIds, $taxonomy, $append, $oldTTIds) |
|
27 | - { |
|
28 | - sort($newTTIds); |
|
29 | - sort($oldTTIds); |
|
30 | - if ($newTTIds === $oldTTIds || !$this->isReviewPostId($postId)) { |
|
31 | - return; |
|
32 | - } |
|
33 | - $review = glsr_get_review($postId); |
|
34 | - $ignoredIds = array_intersect($oldTTIds, $newTTIds); |
|
35 | - $decreasedIds = array_diff($oldTTIds, $ignoredIds); |
|
36 | - $increasedIds = array_diff($newTTIds, $ignoredIds); |
|
37 | - if ($review->term_ids = glsr(Database::class)->getTermIds($decreasedIds, 'term_taxonomy_id')) { |
|
38 | - glsr(CountsManager::class)->decreaseTermCounts($review); |
|
39 | - } |
|
40 | - if ($review->term_ids = glsr(Database::class)->getTermIds($increasedIds, 'term_taxonomy_id')) { |
|
41 | - glsr(CountsManager::class)->increaseTermCounts($review); |
|
42 | - } |
|
43 | - } |
|
16 | + /** |
|
17 | + * @param int $postId |
|
18 | + * @param array $terms |
|
19 | + * @param array $newTTIds |
|
20 | + * @param string $taxonomy |
|
21 | + * @param bool $append |
|
22 | + * @param array $oldTTIds |
|
23 | + * @return void |
|
24 | + * @action set_object_terms |
|
25 | + */ |
|
26 | + public function onAfterChangeCategory($postId, $terms, $newTTIds, $taxonomy, $append, $oldTTIds) |
|
27 | + { |
|
28 | + sort($newTTIds); |
|
29 | + sort($oldTTIds); |
|
30 | + if ($newTTIds === $oldTTIds || !$this->isReviewPostId($postId)) { |
|
31 | + return; |
|
32 | + } |
|
33 | + $review = glsr_get_review($postId); |
|
34 | + $ignoredIds = array_intersect($oldTTIds, $newTTIds); |
|
35 | + $decreasedIds = array_diff($oldTTIds, $ignoredIds); |
|
36 | + $increasedIds = array_diff($newTTIds, $ignoredIds); |
|
37 | + if ($review->term_ids = glsr(Database::class)->getTermIds($decreasedIds, 'term_taxonomy_id')) { |
|
38 | + glsr(CountsManager::class)->decreaseTermCounts($review); |
|
39 | + } |
|
40 | + if ($review->term_ids = glsr(Database::class)->getTermIds($increasedIds, 'term_taxonomy_id')) { |
|
41 | + glsr(CountsManager::class)->increaseTermCounts($review); |
|
42 | + } |
|
43 | + } |
|
44 | 44 | |
45 | - /** |
|
46 | - * @param string $oldStatus |
|
47 | - * @param string $newStatus |
|
48 | - * @param WP_Post $post |
|
49 | - * @return void |
|
50 | - * @action transition_post_status |
|
51 | - */ |
|
52 | - public function onAfterChangeStatus($newStatus, $oldStatus, $post) |
|
53 | - { |
|
54 | - if (Application::POST_TYPE != Arr::get($post, 'post_type') || in_array($oldStatus, ['new', $newStatus])) { |
|
55 | - return; |
|
56 | - } |
|
57 | - $review = glsr_get_review($post); |
|
58 | - if ('publish' == $post->post_status) { |
|
59 | - glsr(CountsManager::class)->increase($review); |
|
60 | - } else { |
|
61 | - glsr(CountsManager::class)->decrease($review); |
|
62 | - } |
|
63 | - } |
|
45 | + /** |
|
46 | + * @param string $oldStatus |
|
47 | + * @param string $newStatus |
|
48 | + * @param WP_Post $post |
|
49 | + * @return void |
|
50 | + * @action transition_post_status |
|
51 | + */ |
|
52 | + public function onAfterChangeStatus($newStatus, $oldStatus, $post) |
|
53 | + { |
|
54 | + if (Application::POST_TYPE != Arr::get($post, 'post_type') || in_array($oldStatus, ['new', $newStatus])) { |
|
55 | + return; |
|
56 | + } |
|
57 | + $review = glsr_get_review($post); |
|
58 | + if ('publish' == $post->post_status) { |
|
59 | + glsr(CountsManager::class)->increase($review); |
|
60 | + } else { |
|
61 | + glsr(CountsManager::class)->decrease($review); |
|
62 | + } |
|
63 | + } |
|
64 | 64 | |
65 | - /** |
|
66 | - * @return void |
|
67 | - * @action site-reviews/review/created |
|
68 | - */ |
|
69 | - public function onAfterCreate(Review $review) |
|
70 | - { |
|
71 | - if ('publish' !== $review->status) { |
|
72 | - return; |
|
73 | - } |
|
74 | - glsr(CountsManager::class)->increaseCounts($review); |
|
75 | - glsr(CountsManager::class)->increasePostCounts($review); |
|
76 | - } |
|
65 | + /** |
|
66 | + * @return void |
|
67 | + * @action site-reviews/review/created |
|
68 | + */ |
|
69 | + public function onAfterCreate(Review $review) |
|
70 | + { |
|
71 | + if ('publish' !== $review->status) { |
|
72 | + return; |
|
73 | + } |
|
74 | + glsr(CountsManager::class)->increaseCounts($review); |
|
75 | + glsr(CountsManager::class)->increasePostCounts($review); |
|
76 | + } |
|
77 | 77 | |
78 | - /** |
|
79 | - * @param int $postId |
|
80 | - * @return void |
|
81 | - * @action before_delete_post |
|
82 | - */ |
|
83 | - public function onBeforeDelete($postId) |
|
84 | - { |
|
85 | - if (!$this->isReviewPostId($postId)) { |
|
86 | - return; |
|
87 | - } |
|
88 | - $review = glsr_get_review($postId); |
|
89 | - if ('trash' !== $review->status) { // do not run for trashed posts |
|
90 | - glsr(CountsManager::class)->decrease($review); |
|
91 | - } |
|
92 | - } |
|
78 | + /** |
|
79 | + * @param int $postId |
|
80 | + * @return void |
|
81 | + * @action before_delete_post |
|
82 | + */ |
|
83 | + public function onBeforeDelete($postId) |
|
84 | + { |
|
85 | + if (!$this->isReviewPostId($postId)) { |
|
86 | + return; |
|
87 | + } |
|
88 | + $review = glsr_get_review($postId); |
|
89 | + if ('trash' !== $review->status) { // do not run for trashed posts |
|
90 | + glsr(CountsManager::class)->decrease($review); |
|
91 | + } |
|
92 | + } |
|
93 | 93 | |
94 | - /** |
|
95 | - * @param int $metaId |
|
96 | - * @param int $postId |
|
97 | - * @param string $metaKey |
|
98 | - * @param mixed $metaValue |
|
99 | - * @return void |
|
100 | - * @action update_postmeta |
|
101 | - */ |
|
102 | - public function onBeforeUpdate($metaId, $postId, $metaKey, $metaValue) |
|
103 | - { |
|
104 | - if (!$this->isReviewPostId($postId)) { |
|
105 | - return; |
|
106 | - } |
|
107 | - $metaKey = Str::removePrefix('_', $metaKey); |
|
108 | - if (!in_array($metaKey, ['assigned_to', 'rating', 'review_type'])) { |
|
109 | - return; |
|
110 | - } |
|
111 | - $review = glsr_get_review($postId); |
|
112 | - if ($review->$metaKey == $metaValue) { |
|
113 | - return; |
|
114 | - } |
|
115 | - $method = Helper::buildMethodName($metaKey, 'onBeforeChange'); |
|
116 | - call_user_func([$this, $method], $review, $metaValue); |
|
117 | - } |
|
94 | + /** |
|
95 | + * @param int $metaId |
|
96 | + * @param int $postId |
|
97 | + * @param string $metaKey |
|
98 | + * @param mixed $metaValue |
|
99 | + * @return void |
|
100 | + * @action update_postmeta |
|
101 | + */ |
|
102 | + public function onBeforeUpdate($metaId, $postId, $metaKey, $metaValue) |
|
103 | + { |
|
104 | + if (!$this->isReviewPostId($postId)) { |
|
105 | + return; |
|
106 | + } |
|
107 | + $metaKey = Str::removePrefix('_', $metaKey); |
|
108 | + if (!in_array($metaKey, ['assigned_to', 'rating', 'review_type'])) { |
|
109 | + return; |
|
110 | + } |
|
111 | + $review = glsr_get_review($postId); |
|
112 | + if ($review->$metaKey == $metaValue) { |
|
113 | + return; |
|
114 | + } |
|
115 | + $method = Helper::buildMethodName($metaKey, 'onBeforeChange'); |
|
116 | + call_user_func([$this, $method], $review, $metaValue); |
|
117 | + } |
|
118 | 118 | |
119 | - /** |
|
120 | - * @param string|int $assignedTo |
|
121 | - * @return void |
|
122 | - */ |
|
123 | - public function onBeforeChangeAssignedTo(Review $review, $assignedTo) |
|
124 | - { |
|
125 | - glsr(CountsManager::class)->decreasePostCounts($review); |
|
126 | - $review->assigned_to = $assignedTo; |
|
127 | - glsr(CountsManager::class)->increasePostCounts($review); |
|
128 | - } |
|
119 | + /** |
|
120 | + * @param string|int $assignedTo |
|
121 | + * @return void |
|
122 | + */ |
|
123 | + public function onBeforeChangeAssignedTo(Review $review, $assignedTo) |
|
124 | + { |
|
125 | + glsr(CountsManager::class)->decreasePostCounts($review); |
|
126 | + $review->assigned_to = $assignedTo; |
|
127 | + glsr(CountsManager::class)->increasePostCounts($review); |
|
128 | + } |
|
129 | 129 | |
130 | - /** |
|
131 | - * @param string|int $rating |
|
132 | - * @return void |
|
133 | - */ |
|
134 | - public function onBeforeChangeRating(Review $review, $rating) |
|
135 | - { |
|
136 | - glsr(CountsManager::class)->decrease($review); |
|
137 | - $review->rating = $rating; |
|
138 | - glsr(CountsManager::class)->increase($review); |
|
139 | - } |
|
130 | + /** |
|
131 | + * @param string|int $rating |
|
132 | + * @return void |
|
133 | + */ |
|
134 | + public function onBeforeChangeRating(Review $review, $rating) |
|
135 | + { |
|
136 | + glsr(CountsManager::class)->decrease($review); |
|
137 | + $review->rating = $rating; |
|
138 | + glsr(CountsManager::class)->increase($review); |
|
139 | + } |
|
140 | 140 | |
141 | - /** |
|
142 | - * @param string $reviewType |
|
143 | - * @return void |
|
144 | - */ |
|
145 | - public function onBeforeChangeReviewType(Review $review, $reviewType) |
|
146 | - { |
|
147 | - glsr(CountsManager::class)->decrease($review); |
|
148 | - $review->review_type = $reviewType; |
|
149 | - glsr(CountsManager::class)->increase($review); |
|
150 | - } |
|
141 | + /** |
|
142 | + * @param string $reviewType |
|
143 | + * @return void |
|
144 | + */ |
|
145 | + public function onBeforeChangeReviewType(Review $review, $reviewType) |
|
146 | + { |
|
147 | + glsr(CountsManager::class)->decrease($review); |
|
148 | + $review->review_type = $reviewType; |
|
149 | + glsr(CountsManager::class)->increase($review); |
|
150 | + } |
|
151 | 151 | } |
@@ -16,222 +16,222 @@ |
||
16 | 16 | |
17 | 17 | class AdminController extends Controller |
18 | 18 | { |
19 | - /** |
|
20 | - * @return void |
|
21 | - * @action admin_enqueue_scripts |
|
22 | - */ |
|
23 | - public function enqueueAssets() |
|
24 | - { |
|
25 | - $command = new EnqueueAdminAssets([ |
|
26 | - 'pointers' => [[ |
|
27 | - 'content' => __('You can pin exceptional reviews so that they are always shown first.', 'site-reviews'), |
|
28 | - 'id' => 'glsr-pointer-pinned', |
|
29 | - 'position' => [ |
|
30 | - 'edge' => 'right', |
|
31 | - 'align' => 'middle', |
|
32 | - ], |
|
33 | - 'screen' => Application::POST_TYPE, |
|
34 | - 'target' => '#misc-pub-pinned', |
|
35 | - 'title' => __('Pin Your Reviews', 'site-reviews'), |
|
36 | - ]], |
|
37 | - ]); |
|
38 | - $this->execute($command); |
|
39 | - } |
|
40 | - |
|
41 | - /** |
|
42 | - * @return array |
|
43 | - * @filter plugin_action_links_site-reviews/site-reviews.php |
|
44 | - */ |
|
45 | - public function filterActionLinks(array $links) |
|
46 | - { |
|
47 | - $links['documentation'] = glsr(Builder::class)->a(__('Help', 'site-reviews'), [ |
|
48 | - 'href' => admin_url('edit.php?post_type='.Application::POST_TYPE.'&page=documentation'), |
|
49 | - ]); |
|
50 | - $links['settings'] = glsr(Builder::class)->a(__('Settings', 'site-reviews'), [ |
|
51 | - 'href' => admin_url('edit.php?post_type='.Application::POST_TYPE.'&page=settings'), |
|
52 | - ]); |
|
53 | - return $links; |
|
54 | - } |
|
55 | - |
|
56 | - /** |
|
57 | - * @param array $capabilities |
|
58 | - * @param string $capability |
|
59 | - * @return array |
|
60 | - * @filter map_meta_cap |
|
61 | - */ |
|
62 | - public function filterCreateCapability($capabilities, $capability) |
|
63 | - { |
|
64 | - if ($capability == 'create_'.Application::POST_TYPE) { |
|
65 | - $capabilities[] = 'do_not_allow'; |
|
66 | - } |
|
67 | - return $capabilities; |
|
68 | - } |
|
69 | - |
|
70 | - /** |
|
71 | - * @param array $items |
|
72 | - * @return array |
|
73 | - * @filter dashboard_glance_items |
|
74 | - */ |
|
75 | - public function filterDashboardGlanceItems($items) |
|
76 | - { |
|
77 | - $postCount = wp_count_posts(Application::POST_TYPE); |
|
78 | - if (empty($postCount->publish)) { |
|
79 | - return $items; |
|
80 | - } |
|
81 | - $text = _n('%s Review', '%s Reviews', $postCount->publish, 'site-reviews'); |
|
82 | - $text = sprintf($text, number_format_i18n($postCount->publish)); |
|
83 | - $items = Arr::consolidateArray($items); |
|
84 | - $items[] = current_user_can(get_post_type_object(Application::POST_TYPE)->cap->edit_posts) |
|
85 | - ? glsr(Builder::class)->a($text, [ |
|
86 | - 'class' => 'glsr-review-count', |
|
87 | - 'href' => 'edit.php?post_type='.Application::POST_TYPE, |
|
88 | - ]) |
|
89 | - : glsr(Builder::class)->span($text, [ |
|
90 | - 'class' => 'glsr-review-count', |
|
91 | - ]); |
|
92 | - return $items; |
|
93 | - } |
|
94 | - |
|
95 | - /** |
|
96 | - * @param array $plugins |
|
97 | - * @return array |
|
98 | - * @filter mce_external_plugins |
|
99 | - */ |
|
100 | - public function filterTinymcePlugins($plugins) |
|
101 | - { |
|
102 | - if (current_user_can('edit_posts') || current_user_can('edit_pages')) { |
|
103 | - $plugins = Arr::consolidateArray($plugins); |
|
104 | - $plugins['glsr_shortcode'] = glsr()->url('assets/scripts/mce-plugin.js'); |
|
105 | - } |
|
106 | - return $plugins; |
|
107 | - } |
|
108 | - |
|
109 | - /** |
|
110 | - * @return void |
|
111 | - * @action admin_init |
|
112 | - */ |
|
113 | - public function registerTinymcePopups() |
|
114 | - { |
|
115 | - $command = new RegisterTinymcePopups([ |
|
116 | - 'site_reviews' => esc_html__('Recent Reviews', 'site-reviews'), |
|
117 | - 'site_reviews_form' => esc_html__('Submit a Review', 'site-reviews'), |
|
118 | - 'site_reviews_summary' => esc_html__('Summary of Reviews', 'site-reviews'), |
|
119 | - ]); |
|
120 | - $this->execute($command); |
|
121 | - } |
|
122 | - |
|
123 | - /** |
|
124 | - * @param string $editorId |
|
125 | - * @return void|null |
|
126 | - * @action media_buttons |
|
127 | - */ |
|
128 | - public function renderTinymceButton($editorId) |
|
129 | - { |
|
130 | - $allowedEditors = apply_filters('site-reviews/tinymce/editor-ids', ['content'], $editorId); |
|
131 | - if ('post' != glsr_current_screen()->base || !in_array($editorId, $allowedEditors)) { |
|
132 | - return; |
|
133 | - } |
|
134 | - $shortcodes = []; |
|
135 | - foreach (glsr()->mceShortcodes as $shortcode => $values) { |
|
136 | - $shortcodes[$shortcode] = $values; |
|
137 | - } |
|
138 | - if (empty($shortcodes)) { |
|
139 | - return; |
|
140 | - } |
|
141 | - glsr()->render('partials/editor/tinymce', [ |
|
142 | - 'shortcodes' => $shortcodes, |
|
143 | - ]); |
|
144 | - } |
|
145 | - |
|
146 | - /** |
|
147 | - * @return void |
|
148 | - */ |
|
149 | - public function routerClearConsole() |
|
150 | - { |
|
151 | - glsr(Console::class)->clear(); |
|
152 | - glsr(Notice::class)->addSuccess(__('Console cleared.', 'site-reviews')); |
|
153 | - } |
|
154 | - |
|
155 | - /** |
|
156 | - * @return void |
|
157 | - */ |
|
158 | - public function routerFetchConsole() |
|
159 | - { |
|
160 | - glsr(Notice::class)->addSuccess(__('Console reloaded.', 'site-reviews')); |
|
161 | - } |
|
162 | - |
|
163 | - /** |
|
164 | - * @param bool $showNotice |
|
165 | - * @return void |
|
166 | - */ |
|
167 | - public function routerCountReviews($showNotice = true) |
|
168 | - { |
|
169 | - glsr(CountsManager::class)->countAll(); |
|
170 | - glsr(OptionManager::class)->set('last_review_count', current_time('timestamp')); |
|
171 | - if ($showNotice) { |
|
172 | - glsr(Notice::class)->clear()->addSuccess(__('Recalculated rating counts.', 'site-reviews')); |
|
173 | - } |
|
174 | - } |
|
175 | - |
|
176 | - /** |
|
177 | - * @return void |
|
178 | - */ |
|
179 | - public function routerDownloadConsole() |
|
180 | - { |
|
181 | - $this->download(Application::ID.'-console.txt', glsr(Console::class)->get()); |
|
182 | - } |
|
183 | - |
|
184 | - /** |
|
185 | - * @return void |
|
186 | - */ |
|
187 | - public function routerDownloadSystemInfo() |
|
188 | - { |
|
189 | - $this->download(Application::ID.'-system-info.txt', glsr(System::class)->get()); |
|
190 | - } |
|
191 | - |
|
192 | - /** |
|
193 | - * @return void |
|
194 | - */ |
|
195 | - public function routerExportSettings() |
|
196 | - { |
|
197 | - $this->download(Application::ID.'-settings.json', glsr(OptionManager::class)->json()); |
|
198 | - } |
|
199 | - |
|
200 | - /** |
|
201 | - * @return void |
|
202 | - */ |
|
203 | - public function routerImportSettings() |
|
204 | - { |
|
205 | - $file = $_FILES['import-file']; |
|
206 | - if (UPLOAD_ERR_OK !== $file['error']) { |
|
207 | - return glsr(Notice::class)->addError($this->getUploadError($file['error'])); |
|
208 | - } |
|
209 | - if ('application/json' !== $file['type'] || !Str::endsWith('.json', $file['name'])) { |
|
210 | - return glsr(Notice::class)->addError(__('Please use a valid Site Reviews settings file.', 'site-reviews')); |
|
211 | - } |
|
212 | - $settings = json_decode(file_get_contents($file['tmp_name']), true); |
|
213 | - if (empty($settings)) { |
|
214 | - return glsr(Notice::class)->addWarning(__('There were no settings found to import.', 'site-reviews')); |
|
215 | - } |
|
216 | - glsr(OptionManager::class)->set(glsr(OptionManager::class)->normalize($settings)); |
|
217 | - glsr(Notice::class)->addSuccess(__('Settings imported.', 'site-reviews')); |
|
218 | - } |
|
219 | - |
|
220 | - /** |
|
221 | - * @param int $errorCode |
|
222 | - * @return string |
|
223 | - */ |
|
224 | - protected function getUploadError($errorCode) |
|
225 | - { |
|
226 | - $errors = [ |
|
227 | - UPLOAD_ERR_INI_SIZE => __('The uploaded file exceeds the upload_max_filesize directive in php.ini.', 'site-reviews'), |
|
228 | - UPLOAD_ERR_FORM_SIZE => __('The uploaded file is too big.', 'site-reviews'), |
|
229 | - UPLOAD_ERR_PARTIAL => __('The uploaded file was only partially uploaded.', 'site-reviews'), |
|
230 | - UPLOAD_ERR_NO_FILE => __('No file was uploaded.', 'site-reviews'), |
|
231 | - UPLOAD_ERR_NO_TMP_DIR => __('Missing a temporary folder.', 'site-reviews'), |
|
232 | - UPLOAD_ERR_CANT_WRITE => __('Failed to write file to disk.', 'site-reviews'), |
|
233 | - UPLOAD_ERR_EXTENSION => __('A PHP extension stopped the file upload.', 'site-reviews'), |
|
234 | - ]; |
|
235 | - return Arr::get($errors, $errorCode, __('Unknown upload error.', 'site-reviews')); |
|
236 | - } |
|
19 | + /** |
|
20 | + * @return void |
|
21 | + * @action admin_enqueue_scripts |
|
22 | + */ |
|
23 | + public function enqueueAssets() |
|
24 | + { |
|
25 | + $command = new EnqueueAdminAssets([ |
|
26 | + 'pointers' => [[ |
|
27 | + 'content' => __('You can pin exceptional reviews so that they are always shown first.', 'site-reviews'), |
|
28 | + 'id' => 'glsr-pointer-pinned', |
|
29 | + 'position' => [ |
|
30 | + 'edge' => 'right', |
|
31 | + 'align' => 'middle', |
|
32 | + ], |
|
33 | + 'screen' => Application::POST_TYPE, |
|
34 | + 'target' => '#misc-pub-pinned', |
|
35 | + 'title' => __('Pin Your Reviews', 'site-reviews'), |
|
36 | + ]], |
|
37 | + ]); |
|
38 | + $this->execute($command); |
|
39 | + } |
|
40 | + |
|
41 | + /** |
|
42 | + * @return array |
|
43 | + * @filter plugin_action_links_site-reviews/site-reviews.php |
|
44 | + */ |
|
45 | + public function filterActionLinks(array $links) |
|
46 | + { |
|
47 | + $links['documentation'] = glsr(Builder::class)->a(__('Help', 'site-reviews'), [ |
|
48 | + 'href' => admin_url('edit.php?post_type='.Application::POST_TYPE.'&page=documentation'), |
|
49 | + ]); |
|
50 | + $links['settings'] = glsr(Builder::class)->a(__('Settings', 'site-reviews'), [ |
|
51 | + 'href' => admin_url('edit.php?post_type='.Application::POST_TYPE.'&page=settings'), |
|
52 | + ]); |
|
53 | + return $links; |
|
54 | + } |
|
55 | + |
|
56 | + /** |
|
57 | + * @param array $capabilities |
|
58 | + * @param string $capability |
|
59 | + * @return array |
|
60 | + * @filter map_meta_cap |
|
61 | + */ |
|
62 | + public function filterCreateCapability($capabilities, $capability) |
|
63 | + { |
|
64 | + if ($capability == 'create_'.Application::POST_TYPE) { |
|
65 | + $capabilities[] = 'do_not_allow'; |
|
66 | + } |
|
67 | + return $capabilities; |
|
68 | + } |
|
69 | + |
|
70 | + /** |
|
71 | + * @param array $items |
|
72 | + * @return array |
|
73 | + * @filter dashboard_glance_items |
|
74 | + */ |
|
75 | + public function filterDashboardGlanceItems($items) |
|
76 | + { |
|
77 | + $postCount = wp_count_posts(Application::POST_TYPE); |
|
78 | + if (empty($postCount->publish)) { |
|
79 | + return $items; |
|
80 | + } |
|
81 | + $text = _n('%s Review', '%s Reviews', $postCount->publish, 'site-reviews'); |
|
82 | + $text = sprintf($text, number_format_i18n($postCount->publish)); |
|
83 | + $items = Arr::consolidateArray($items); |
|
84 | + $items[] = current_user_can(get_post_type_object(Application::POST_TYPE)->cap->edit_posts) |
|
85 | + ? glsr(Builder::class)->a($text, [ |
|
86 | + 'class' => 'glsr-review-count', |
|
87 | + 'href' => 'edit.php?post_type='.Application::POST_TYPE, |
|
88 | + ]) |
|
89 | + : glsr(Builder::class)->span($text, [ |
|
90 | + 'class' => 'glsr-review-count', |
|
91 | + ]); |
|
92 | + return $items; |
|
93 | + } |
|
94 | + |
|
95 | + /** |
|
96 | + * @param array $plugins |
|
97 | + * @return array |
|
98 | + * @filter mce_external_plugins |
|
99 | + */ |
|
100 | + public function filterTinymcePlugins($plugins) |
|
101 | + { |
|
102 | + if (current_user_can('edit_posts') || current_user_can('edit_pages')) { |
|
103 | + $plugins = Arr::consolidateArray($plugins); |
|
104 | + $plugins['glsr_shortcode'] = glsr()->url('assets/scripts/mce-plugin.js'); |
|
105 | + } |
|
106 | + return $plugins; |
|
107 | + } |
|
108 | + |
|
109 | + /** |
|
110 | + * @return void |
|
111 | + * @action admin_init |
|
112 | + */ |
|
113 | + public function registerTinymcePopups() |
|
114 | + { |
|
115 | + $command = new RegisterTinymcePopups([ |
|
116 | + 'site_reviews' => esc_html__('Recent Reviews', 'site-reviews'), |
|
117 | + 'site_reviews_form' => esc_html__('Submit a Review', 'site-reviews'), |
|
118 | + 'site_reviews_summary' => esc_html__('Summary of Reviews', 'site-reviews'), |
|
119 | + ]); |
|
120 | + $this->execute($command); |
|
121 | + } |
|
122 | + |
|
123 | + /** |
|
124 | + * @param string $editorId |
|
125 | + * @return void|null |
|
126 | + * @action media_buttons |
|
127 | + */ |
|
128 | + public function renderTinymceButton($editorId) |
|
129 | + { |
|
130 | + $allowedEditors = apply_filters('site-reviews/tinymce/editor-ids', ['content'], $editorId); |
|
131 | + if ('post' != glsr_current_screen()->base || !in_array($editorId, $allowedEditors)) { |
|
132 | + return; |
|
133 | + } |
|
134 | + $shortcodes = []; |
|
135 | + foreach (glsr()->mceShortcodes as $shortcode => $values) { |
|
136 | + $shortcodes[$shortcode] = $values; |
|
137 | + } |
|
138 | + if (empty($shortcodes)) { |
|
139 | + return; |
|
140 | + } |
|
141 | + glsr()->render('partials/editor/tinymce', [ |
|
142 | + 'shortcodes' => $shortcodes, |
|
143 | + ]); |
|
144 | + } |
|
145 | + |
|
146 | + /** |
|
147 | + * @return void |
|
148 | + */ |
|
149 | + public function routerClearConsole() |
|
150 | + { |
|
151 | + glsr(Console::class)->clear(); |
|
152 | + glsr(Notice::class)->addSuccess(__('Console cleared.', 'site-reviews')); |
|
153 | + } |
|
154 | + |
|
155 | + /** |
|
156 | + * @return void |
|
157 | + */ |
|
158 | + public function routerFetchConsole() |
|
159 | + { |
|
160 | + glsr(Notice::class)->addSuccess(__('Console reloaded.', 'site-reviews')); |
|
161 | + } |
|
162 | + |
|
163 | + /** |
|
164 | + * @param bool $showNotice |
|
165 | + * @return void |
|
166 | + */ |
|
167 | + public function routerCountReviews($showNotice = true) |
|
168 | + { |
|
169 | + glsr(CountsManager::class)->countAll(); |
|
170 | + glsr(OptionManager::class)->set('last_review_count', current_time('timestamp')); |
|
171 | + if ($showNotice) { |
|
172 | + glsr(Notice::class)->clear()->addSuccess(__('Recalculated rating counts.', 'site-reviews')); |
|
173 | + } |
|
174 | + } |
|
175 | + |
|
176 | + /** |
|
177 | + * @return void |
|
178 | + */ |
|
179 | + public function routerDownloadConsole() |
|
180 | + { |
|
181 | + $this->download(Application::ID.'-console.txt', glsr(Console::class)->get()); |
|
182 | + } |
|
183 | + |
|
184 | + /** |
|
185 | + * @return void |
|
186 | + */ |
|
187 | + public function routerDownloadSystemInfo() |
|
188 | + { |
|
189 | + $this->download(Application::ID.'-system-info.txt', glsr(System::class)->get()); |
|
190 | + } |
|
191 | + |
|
192 | + /** |
|
193 | + * @return void |
|
194 | + */ |
|
195 | + public function routerExportSettings() |
|
196 | + { |
|
197 | + $this->download(Application::ID.'-settings.json', glsr(OptionManager::class)->json()); |
|
198 | + } |
|
199 | + |
|
200 | + /** |
|
201 | + * @return void |
|
202 | + */ |
|
203 | + public function routerImportSettings() |
|
204 | + { |
|
205 | + $file = $_FILES['import-file']; |
|
206 | + if (UPLOAD_ERR_OK !== $file['error']) { |
|
207 | + return glsr(Notice::class)->addError($this->getUploadError($file['error'])); |
|
208 | + } |
|
209 | + if ('application/json' !== $file['type'] || !Str::endsWith('.json', $file['name'])) { |
|
210 | + return glsr(Notice::class)->addError(__('Please use a valid Site Reviews settings file.', 'site-reviews')); |
|
211 | + } |
|
212 | + $settings = json_decode(file_get_contents($file['tmp_name']), true); |
|
213 | + if (empty($settings)) { |
|
214 | + return glsr(Notice::class)->addWarning(__('There were no settings found to import.', 'site-reviews')); |
|
215 | + } |
|
216 | + glsr(OptionManager::class)->set(glsr(OptionManager::class)->normalize($settings)); |
|
217 | + glsr(Notice::class)->addSuccess(__('Settings imported.', 'site-reviews')); |
|
218 | + } |
|
219 | + |
|
220 | + /** |
|
221 | + * @param int $errorCode |
|
222 | + * @return string |
|
223 | + */ |
|
224 | + protected function getUploadError($errorCode) |
|
225 | + { |
|
226 | + $errors = [ |
|
227 | + UPLOAD_ERR_INI_SIZE => __('The uploaded file exceeds the upload_max_filesize directive in php.ini.', 'site-reviews'), |
|
228 | + UPLOAD_ERR_FORM_SIZE => __('The uploaded file is too big.', 'site-reviews'), |
|
229 | + UPLOAD_ERR_PARTIAL => __('The uploaded file was only partially uploaded.', 'site-reviews'), |
|
230 | + UPLOAD_ERR_NO_FILE => __('No file was uploaded.', 'site-reviews'), |
|
231 | + UPLOAD_ERR_NO_TMP_DIR => __('Missing a temporary folder.', 'site-reviews'), |
|
232 | + UPLOAD_ERR_CANT_WRITE => __('Failed to write file to disk.', 'site-reviews'), |
|
233 | + UPLOAD_ERR_EXTENSION => __('A PHP extension stopped the file upload.', 'site-reviews'), |
|
234 | + ]; |
|
235 | + return Arr::get($errors, $errorCode, __('Unknown upload error.', 'site-reviews')); |
|
236 | + } |
|
237 | 237 | } |
@@ -9,308 +9,308 @@ |
||
9 | 9 | |
10 | 10 | final class Application extends Container |
11 | 11 | { |
12 | - const CAPABILITY = 'edit_others_posts'; |
|
13 | - const CRON_EVENT = 'site-reviews/schedule/session/purge'; |
|
14 | - const ID = 'site-reviews'; |
|
15 | - const PAGED_QUERY_VAR = 'reviews-page'; |
|
16 | - const POST_TYPE = 'site-review'; |
|
17 | - const PREFIX = 'glsr_'; |
|
18 | - const TAXONOMY = 'site-review-category'; |
|
12 | + const CAPABILITY = 'edit_others_posts'; |
|
13 | + const CRON_EVENT = 'site-reviews/schedule/session/purge'; |
|
14 | + const ID = 'site-reviews'; |
|
15 | + const PAGED_QUERY_VAR = 'reviews-page'; |
|
16 | + const POST_TYPE = 'site-review'; |
|
17 | + const PREFIX = 'glsr_'; |
|
18 | + const TAXONOMY = 'site-review-category'; |
|
19 | 19 | |
20 | - public $defaults; |
|
21 | - public $deprecated = []; |
|
22 | - public $file; |
|
23 | - public $languages; |
|
24 | - public $mceShortcodes = []; //defined elsewhere |
|
25 | - public $name; |
|
26 | - public $reviewTypes; |
|
27 | - public $schemas = []; //defined elsewhere |
|
28 | - public $version; |
|
20 | + public $defaults; |
|
21 | + public $deprecated = []; |
|
22 | + public $file; |
|
23 | + public $languages; |
|
24 | + public $mceShortcodes = []; //defined elsewhere |
|
25 | + public $name; |
|
26 | + public $reviewTypes; |
|
27 | + public $schemas = []; //defined elsewhere |
|
28 | + public $version; |
|
29 | 29 | |
30 | - public function __construct() |
|
31 | - { |
|
32 | - static::$instance = $this; |
|
33 | - $this->file = realpath(trailingslashit(dirname(__DIR__)).static::ID.'.php'); |
|
34 | - $plugin = get_file_data($this->file, [ |
|
35 | - 'languages' => 'Domain Path', |
|
36 | - 'name' => 'Plugin Name', |
|
37 | - 'version' => 'Version', |
|
38 | - ], 'plugin'); |
|
39 | - array_walk($plugin, function ($value, $key) { |
|
40 | - $this->$key = $value; |
|
41 | - }); |
|
42 | - } |
|
30 | + public function __construct() |
|
31 | + { |
|
32 | + static::$instance = $this; |
|
33 | + $this->file = realpath(trailingslashit(dirname(__DIR__)).static::ID.'.php'); |
|
34 | + $plugin = get_file_data($this->file, [ |
|
35 | + 'languages' => 'Domain Path', |
|
36 | + 'name' => 'Plugin Name', |
|
37 | + 'version' => 'Version', |
|
38 | + ], 'plugin'); |
|
39 | + array_walk($plugin, function ($value, $key) { |
|
40 | + $this->$key = $value; |
|
41 | + }); |
|
42 | + } |
|
43 | 43 | |
44 | - /** |
|
45 | - * @return void |
|
46 | - */ |
|
47 | - public function activate() |
|
48 | - { |
|
49 | - $this->make(DefaultsManager::class)->set(); |
|
50 | - $this->scheduleCronJob(); |
|
51 | - $this->upgrade(); |
|
52 | - } |
|
44 | + /** |
|
45 | + * @return void |
|
46 | + */ |
|
47 | + public function activate() |
|
48 | + { |
|
49 | + $this->make(DefaultsManager::class)->set(); |
|
50 | + $this->scheduleCronJob(); |
|
51 | + $this->upgrade(); |
|
52 | + } |
|
53 | 53 | |
54 | - /** |
|
55 | - * @return void |
|
56 | - */ |
|
57 | - public function catchFatalError() |
|
58 | - { |
|
59 | - $error = error_get_last(); |
|
60 | - if (E_ERROR !== $error['type'] || false === strpos($error['message'], $this->path())) { |
|
61 | - return; |
|
62 | - } |
|
63 | - glsr_log()->error($error['message']); |
|
64 | - } |
|
54 | + /** |
|
55 | + * @return void |
|
56 | + */ |
|
57 | + public function catchFatalError() |
|
58 | + { |
|
59 | + $error = error_get_last(); |
|
60 | + if (E_ERROR !== $error['type'] || false === strpos($error['message'], $this->path())) { |
|
61 | + return; |
|
62 | + } |
|
63 | + glsr_log()->error($error['message']); |
|
64 | + } |
|
65 | 65 | |
66 | - /** |
|
67 | - * @param string $name |
|
68 | - * @return array |
|
69 | - */ |
|
70 | - public function config($name) |
|
71 | - { |
|
72 | - $configFile = $this->path('config/'.$name.'.php'); |
|
73 | - $config = file_exists($configFile) |
|
74 | - ? include $configFile |
|
75 | - : []; |
|
76 | - return apply_filters('site-reviews/config/'.$name, $config); |
|
77 | - } |
|
66 | + /** |
|
67 | + * @param string $name |
|
68 | + * @return array |
|
69 | + */ |
|
70 | + public function config($name) |
|
71 | + { |
|
72 | + $configFile = $this->path('config/'.$name.'.php'); |
|
73 | + $config = file_exists($configFile) |
|
74 | + ? include $configFile |
|
75 | + : []; |
|
76 | + return apply_filters('site-reviews/config/'.$name, $config); |
|
77 | + } |
|
78 | 78 | |
79 | - /** |
|
80 | - * @param string $property |
|
81 | - * @return string |
|
82 | - */ |
|
83 | - public function constant($property, $className = 'static') |
|
84 | - { |
|
85 | - $constant = $className.'::'.$property; |
|
86 | - return defined($constant) |
|
87 | - ? apply_filters('site-reviews/const/'.$property, constant($constant)) |
|
88 | - : ''; |
|
89 | - } |
|
79 | + /** |
|
80 | + * @param string $property |
|
81 | + * @return string |
|
82 | + */ |
|
83 | + public function constant($property, $className = 'static') |
|
84 | + { |
|
85 | + $constant = $className.'::'.$property; |
|
86 | + return defined($constant) |
|
87 | + ? apply_filters('site-reviews/const/'.$property, constant($constant)) |
|
88 | + : ''; |
|
89 | + } |
|
90 | 90 | |
91 | - /** |
|
92 | - * @return void |
|
93 | - */ |
|
94 | - public function deactivate() |
|
95 | - { |
|
96 | - $this->unscheduleCronJob(); |
|
97 | - } |
|
91 | + /** |
|
92 | + * @return void |
|
93 | + */ |
|
94 | + public function deactivate() |
|
95 | + { |
|
96 | + $this->unscheduleCronJob(); |
|
97 | + } |
|
98 | 98 | |
99 | - /** |
|
100 | - * @param string $view |
|
101 | - * @return void|string |
|
102 | - */ |
|
103 | - public function file($view) |
|
104 | - { |
|
105 | - $view.= '.php'; |
|
106 | - $filePaths = []; |
|
107 | - if (Str::startsWith('templates/', $view)) { |
|
108 | - $filePaths[] = $this->themePath(Str::removePrefix('templates/', $view)); |
|
109 | - } |
|
110 | - $filePaths[] = $this->path($view); |
|
111 | - $filePaths[] = $this->path('views/'.$view); |
|
112 | - foreach ($filePaths as $file) { |
|
113 | - if (!file_exists($file)) { |
|
114 | - continue; |
|
115 | - } |
|
116 | - return $file; |
|
117 | - } |
|
118 | - } |
|
99 | + /** |
|
100 | + * @param string $view |
|
101 | + * @return void|string |
|
102 | + */ |
|
103 | + public function file($view) |
|
104 | + { |
|
105 | + $view.= '.php'; |
|
106 | + $filePaths = []; |
|
107 | + if (Str::startsWith('templates/', $view)) { |
|
108 | + $filePaths[] = $this->themePath(Str::removePrefix('templates/', $view)); |
|
109 | + } |
|
110 | + $filePaths[] = $this->path($view); |
|
111 | + $filePaths[] = $this->path('views/'.$view); |
|
112 | + foreach ($filePaths as $file) { |
|
113 | + if (!file_exists($file)) { |
|
114 | + continue; |
|
115 | + } |
|
116 | + return $file; |
|
117 | + } |
|
118 | + } |
|
119 | 119 | |
120 | - /** |
|
121 | - * @return array |
|
122 | - */ |
|
123 | - public function getDefaults() |
|
124 | - { |
|
125 | - if (empty($this->defaults)) { |
|
126 | - $this->defaults = $this->make(DefaultsManager::class)->get(); |
|
127 | - $this->upgrade(); |
|
128 | - } |
|
129 | - return apply_filters('site-reviews/get/defaults', $this->defaults); |
|
130 | - } |
|
120 | + /** |
|
121 | + * @return array |
|
122 | + */ |
|
123 | + public function getDefaults() |
|
124 | + { |
|
125 | + if (empty($this->defaults)) { |
|
126 | + $this->defaults = $this->make(DefaultsManager::class)->get(); |
|
127 | + $this->upgrade(); |
|
128 | + } |
|
129 | + return apply_filters('site-reviews/get/defaults', $this->defaults); |
|
130 | + } |
|
131 | 131 | |
132 | - /** |
|
133 | - * @return string |
|
134 | - */ |
|
135 | - public function getPermission($page = '') |
|
136 | - { |
|
137 | - $permissions = [ |
|
138 | - 'addons' => 'install_plugins', |
|
139 | - 'settings' => 'manage_options', |
|
140 | - // 'welcome' => 'activate_plugins', |
|
141 | - ]; |
|
142 | - return Arr::get($permissions, $page, $this->constant('CAPABILITY')); |
|
143 | - } |
|
132 | + /** |
|
133 | + * @return string |
|
134 | + */ |
|
135 | + public function getPermission($page = '') |
|
136 | + { |
|
137 | + $permissions = [ |
|
138 | + 'addons' => 'install_plugins', |
|
139 | + 'settings' => 'manage_options', |
|
140 | + // 'welcome' => 'activate_plugins', |
|
141 | + ]; |
|
142 | + return Arr::get($permissions, $page, $this->constant('CAPABILITY')); |
|
143 | + } |
|
144 | 144 | |
145 | - /** |
|
146 | - * @return bool |
|
147 | - */ |
|
148 | - public function hasPermission($page = '') |
|
149 | - { |
|
150 | - $isAdmin = $this->isAdmin(); |
|
151 | - return !$isAdmin || ($isAdmin && current_user_can($this->getPermission($page))); |
|
152 | - } |
|
145 | + /** |
|
146 | + * @return bool |
|
147 | + */ |
|
148 | + public function hasPermission($page = '') |
|
149 | + { |
|
150 | + $isAdmin = $this->isAdmin(); |
|
151 | + return !$isAdmin || ($isAdmin && current_user_can($this->getPermission($page))); |
|
152 | + } |
|
153 | 153 | |
154 | - /** |
|
155 | - * @return void |
|
156 | - */ |
|
157 | - public function init() |
|
158 | - { |
|
159 | - $this->make(Actions::class)->run(); |
|
160 | - $this->make(Filters::class)->run(); |
|
161 | - } |
|
154 | + /** |
|
155 | + * @return void |
|
156 | + */ |
|
157 | + public function init() |
|
158 | + { |
|
159 | + $this->make(Actions::class)->run(); |
|
160 | + $this->make(Filters::class)->run(); |
|
161 | + } |
|
162 | 162 | |
163 | - /** |
|
164 | - * @return bool |
|
165 | - */ |
|
166 | - public function isAdmin() |
|
167 | - { |
|
168 | - return is_admin() && !wp_doing_ajax(); |
|
169 | - } |
|
163 | + /** |
|
164 | + * @return bool |
|
165 | + */ |
|
166 | + public function isAdmin() |
|
167 | + { |
|
168 | + return is_admin() && !wp_doing_ajax(); |
|
169 | + } |
|
170 | 170 | |
171 | - /** |
|
172 | - * @param string $file |
|
173 | - * @return string |
|
174 | - */ |
|
175 | - public function path($file = '', $realpath = true) |
|
176 | - { |
|
177 | - $path = plugin_dir_path($this->file); |
|
178 | - if (!$realpath) { |
|
179 | - $path = trailingslashit(WP_PLUGIN_DIR).basename(dirname($this->file)); |
|
180 | - } |
|
181 | - $path = trailingslashit($path).ltrim(trim($file), '/'); |
|
182 | - return apply_filters('site-reviews/path', $path, $file); |
|
183 | - } |
|
171 | + /** |
|
172 | + * @param string $file |
|
173 | + * @return string |
|
174 | + */ |
|
175 | + public function path($file = '', $realpath = true) |
|
176 | + { |
|
177 | + $path = plugin_dir_path($this->file); |
|
178 | + if (!$realpath) { |
|
179 | + $path = trailingslashit(WP_PLUGIN_DIR).basename(dirname($this->file)); |
|
180 | + } |
|
181 | + $path = trailingslashit($path).ltrim(trim($file), '/'); |
|
182 | + return apply_filters('site-reviews/path', $path, $file); |
|
183 | + } |
|
184 | 184 | |
185 | - /** |
|
186 | - * @return void |
|
187 | - */ |
|
188 | - public function registerAddons() |
|
189 | - { |
|
190 | - do_action('site-reviews/addon/register', $this); |
|
191 | - } |
|
185 | + /** |
|
186 | + * @return void |
|
187 | + */ |
|
188 | + public function registerAddons() |
|
189 | + { |
|
190 | + do_action('site-reviews/addon/register', $this); |
|
191 | + } |
|
192 | 192 | |
193 | - /** |
|
194 | - * @return void |
|
195 | - */ |
|
196 | - public function registerLanguages() |
|
197 | - { |
|
198 | - load_plugin_textdomain(static::ID, false, |
|
199 | - trailingslashit(plugin_basename($this->path()).'/'.$this->languages) |
|
200 | - ); |
|
201 | - } |
|
193 | + /** |
|
194 | + * @return void |
|
195 | + */ |
|
196 | + public function registerLanguages() |
|
197 | + { |
|
198 | + load_plugin_textdomain(static::ID, false, |
|
199 | + trailingslashit(plugin_basename($this->path()).'/'.$this->languages) |
|
200 | + ); |
|
201 | + } |
|
202 | 202 | |
203 | - /** |
|
204 | - * @return void |
|
205 | - */ |
|
206 | - public function registerReviewTypes() |
|
207 | - { |
|
208 | - $types = apply_filters('site-reviews/addon/types', []); |
|
209 | - $this->reviewTypes = wp_parse_args($types, [ |
|
210 | - 'local' => __('Local', 'site-reviews'), |
|
211 | - ]); |
|
212 | - } |
|
203 | + /** |
|
204 | + * @return void |
|
205 | + */ |
|
206 | + public function registerReviewTypes() |
|
207 | + { |
|
208 | + $types = apply_filters('site-reviews/addon/types', []); |
|
209 | + $this->reviewTypes = wp_parse_args($types, [ |
|
210 | + 'local' => __('Local', 'site-reviews'), |
|
211 | + ]); |
|
212 | + } |
|
213 | 213 | |
214 | - /** |
|
215 | - * @param string $view |
|
216 | - * @return void |
|
217 | - */ |
|
218 | - public function render($view, array $data = []) |
|
219 | - { |
|
220 | - $view = apply_filters('site-reviews/render/view', $view, $data); |
|
221 | - $file = apply_filters('site-reviews/views/file', $this->file($view), $view, $data); |
|
222 | - if (!file_exists($file)) { |
|
223 | - glsr_log()->error('File not found: '.$file); |
|
224 | - return; |
|
225 | - } |
|
226 | - $data = apply_filters('site-reviews/views/data', $data, $view); |
|
227 | - extract($data); |
|
228 | - include $file; |
|
229 | - } |
|
214 | + /** |
|
215 | + * @param string $view |
|
216 | + * @return void |
|
217 | + */ |
|
218 | + public function render($view, array $data = []) |
|
219 | + { |
|
220 | + $view = apply_filters('site-reviews/render/view', $view, $data); |
|
221 | + $file = apply_filters('site-reviews/views/file', $this->file($view), $view, $data); |
|
222 | + if (!file_exists($file)) { |
|
223 | + glsr_log()->error('File not found: '.$file); |
|
224 | + return; |
|
225 | + } |
|
226 | + $data = apply_filters('site-reviews/views/data', $data, $view); |
|
227 | + extract($data); |
|
228 | + include $file; |
|
229 | + } |
|
230 | 230 | |
231 | - /** |
|
232 | - * @return void |
|
233 | - */ |
|
234 | - public function scheduleCronJob() |
|
235 | - { |
|
236 | - if (wp_next_scheduled(static::CRON_EVENT)) { |
|
237 | - return; |
|
238 | - } |
|
239 | - wp_schedule_event(time(), 'twicedaily', static::CRON_EVENT); |
|
240 | - } |
|
231 | + /** |
|
232 | + * @return void |
|
233 | + */ |
|
234 | + public function scheduleCronJob() |
|
235 | + { |
|
236 | + if (wp_next_scheduled(static::CRON_EVENT)) { |
|
237 | + return; |
|
238 | + } |
|
239 | + wp_schedule_event(time(), 'twicedaily', static::CRON_EVENT); |
|
240 | + } |
|
241 | 241 | |
242 | - /** |
|
243 | - * @param string $file |
|
244 | - * @return string |
|
245 | - */ |
|
246 | - public function themePath($file = '') |
|
247 | - { |
|
248 | - return get_stylesheet_directory().'/'.static::ID.'/'.ltrim(trim($file), '/'); |
|
249 | - } |
|
242 | + /** |
|
243 | + * @param string $file |
|
244 | + * @return string |
|
245 | + */ |
|
246 | + public function themePath($file = '') |
|
247 | + { |
|
248 | + return get_stylesheet_directory().'/'.static::ID.'/'.ltrim(trim($file), '/'); |
|
249 | + } |
|
250 | 250 | |
251 | - /** |
|
252 | - * @return void |
|
253 | - */ |
|
254 | - public function unscheduleCronJob() |
|
255 | - { |
|
256 | - wp_unschedule_event(intval(wp_next_scheduled(static::CRON_EVENT)), static::CRON_EVENT); |
|
257 | - } |
|
251 | + /** |
|
252 | + * @return void |
|
253 | + */ |
|
254 | + public function unscheduleCronJob() |
|
255 | + { |
|
256 | + wp_unschedule_event(intval(wp_next_scheduled(static::CRON_EVENT)), static::CRON_EVENT); |
|
257 | + } |
|
258 | 258 | |
259 | - /** |
|
260 | - * @return void |
|
261 | - */ |
|
262 | - public function upgrade() |
|
263 | - { |
|
264 | - $this->make(Upgrader::class)->run(); |
|
265 | - } |
|
259 | + /** |
|
260 | + * @return void |
|
261 | + */ |
|
262 | + public function upgrade() |
|
263 | + { |
|
264 | + $this->make(Upgrader::class)->run(); |
|
265 | + } |
|
266 | 266 | |
267 | - /** |
|
268 | - * @param mixed $upgrader |
|
269 | - * @return void |
|
270 | - * @action upgrader_process_complete |
|
271 | - */ |
|
272 | - public function upgraded($upgrader, array $data) |
|
273 | - { |
|
274 | - if (array_key_exists('plugins', $data) |
|
275 | - && in_array(plugin_basename($this->file), $data['plugins']) |
|
276 | - && 'update' === $data['action'] |
|
277 | - && 'plugin' === $data['type'] |
|
278 | - ) { |
|
279 | - $this->upgrade(); |
|
280 | - } |
|
281 | - } |
|
267 | + /** |
|
268 | + * @param mixed $upgrader |
|
269 | + * @return void |
|
270 | + * @action upgrader_process_complete |
|
271 | + */ |
|
272 | + public function upgraded($upgrader, array $data) |
|
273 | + { |
|
274 | + if (array_key_exists('plugins', $data) |
|
275 | + && in_array(plugin_basename($this->file), $data['plugins']) |
|
276 | + && 'update' === $data['action'] |
|
277 | + && 'plugin' === $data['type'] |
|
278 | + ) { |
|
279 | + $this->upgrade(); |
|
280 | + } |
|
281 | + } |
|
282 | 282 | |
283 | - /** |
|
284 | - * @param string $path |
|
285 | - * @return string |
|
286 | - */ |
|
287 | - public function url($path = '') |
|
288 | - { |
|
289 | - $url = esc_url(plugin_dir_url($this->file).ltrim(trim($path), '/')); |
|
290 | - return apply_filters('site-reviews/url', $url, $path); |
|
291 | - } |
|
283 | + /** |
|
284 | + * @param string $path |
|
285 | + * @return string |
|
286 | + */ |
|
287 | + public function url($path = '') |
|
288 | + { |
|
289 | + $url = esc_url(plugin_dir_url($this->file).ltrim(trim($path), '/')); |
|
290 | + return apply_filters('site-reviews/url', $url, $path); |
|
291 | + } |
|
292 | 292 | |
293 | - /** |
|
294 | - * @param string $versionLevel |
|
295 | - * @return string |
|
296 | - */ |
|
297 | - public function version($versionLevel = '') |
|
298 | - { |
|
299 | - $pattern = '/^v?(\d{1,5})(\.\d++)?(\.\d++)?(.+)?$/i'; |
|
300 | - preg_match($pattern, $this->version, $matches); |
|
301 | - switch ($versionLevel) { |
|
302 | - case 'major': |
|
303 | - $version = Arr::get($matches, 1); |
|
304 | - break; |
|
305 | - case 'minor': |
|
306 | - $version = Arr::get($matches, 1).Arr::get($matches, 2); |
|
307 | - break; |
|
308 | - case 'patch': |
|
309 | - $version = Arr::get($matches, 1).Arr::get($matches, 2).Arr::get($matches, 3); |
|
310 | - break; |
|
311 | - } |
|
312 | - return empty($version) |
|
313 | - ? $this->version |
|
314 | - : $version; |
|
315 | - } |
|
293 | + /** |
|
294 | + * @param string $versionLevel |
|
295 | + * @return string |
|
296 | + */ |
|
297 | + public function version($versionLevel = '') |
|
298 | + { |
|
299 | + $pattern = '/^v?(\d{1,5})(\.\d++)?(\.\d++)?(.+)?$/i'; |
|
300 | + preg_match($pattern, $this->version, $matches); |
|
301 | + switch ($versionLevel) { |
|
302 | + case 'major': |
|
303 | + $version = Arr::get($matches, 1); |
|
304 | + break; |
|
305 | + case 'minor': |
|
306 | + $version = Arr::get($matches, 1).Arr::get($matches, 2); |
|
307 | + break; |
|
308 | + case 'patch': |
|
309 | + $version = Arr::get($matches, 1).Arr::get($matches, 2).Arr::get($matches, 3); |
|
310 | + break; |
|
311 | + } |
|
312 | + return empty($version) |
|
313 | + ? $this->version |
|
314 | + : $version; |
|
315 | + } |
|
316 | 316 | } |